From 9eb3de757a997becb8406417a4bf613f4cb04900 Mon Sep 17 00:00:00 2001 From: hgn Date: Fri, 7 Jul 2023 22:06:10 +0100 Subject: [PATCH] basic replayable replays --- camera.h | 2 +- menu.h | 4 - player.c | 122 +++-------------------- player.h | 78 +++++---------- player_common.c | 71 +++++++------- player_drive.c | 2 +- player_render.c | 255 +++++++++++++++++++++++------------------------- player_replay.c | 105 +++++++++++++++++--- player_replay.h | 39 +++++++- player_skate.c | 195 ++++++++++++++++++------------------ player_skate.h | 54 +++++----- player_walk.c | 2 +- skaterift.c | 18 ++-- skaterift.h | 4 +- 14 files changed, 469 insertions(+), 482 deletions(-) diff --git a/camera.h b/camera.h index f028f82..314eafe 100644 --- a/camera.h +++ b/camera.h @@ -1,7 +1,7 @@ #ifndef CAMERA_H #define CAMERA_H -#include "common.h" +#include "skaterift.h" typedef struct camera camera; diff --git a/menu.h b/menu.h index fcf2da4..9f62242 100644 --- a/menu.h +++ b/menu.h @@ -14,7 +14,6 @@ struct { int active, credits_open; - f32 factive; int disable_open; u32 page, /* current page index */ @@ -283,9 +282,6 @@ static void menu_update(void) } } - menu.factive = vg_lerpf( menu.factive, menu.active, - vg.time_frame_delta * 6.0f ); - if( !menu.active ) return; enum menu_input_mode prev_mode = menu.input_mode; diff --git a/player.c b/player.c index 33b1c1e..25e4b77 100644 --- a/player.c +++ b/player.c @@ -78,12 +78,6 @@ void player__create( player_instance *inst ) q_identity( inst->rb.q ); m4x3_identity( inst->rb.to_world ); m4x3_identity( inst->rb.to_local ); - - inst->rewind_length = 0; - inst->rewind_buffer = - vg_linear_alloc( vg_mem.rtmemory, - sizeof(struct rewind_frame) * PLAYER_REWIND_FRAMES ); - } /* @@ -117,79 +111,25 @@ void player__bind( player_instance *player ) * ---------------------------------------------------------------------------- */ -VG_STATIC void player_save_rewind_frame( player_instance *player ) -{ - if( player->rewind_length < PLAYER_REWIND_FRAMES ){ - struct rewind_frame *fr = - &player->rewind_buffer[ player->rewind_length ++ ]; - - v2_copy( player->cam.angles, fr->ang ); - v3_copy( player->cam.pos, fr->pos ); - - if( player->rewind_length >= 2 ){ - player->rewind_total_length += - v3_dist( player->rewind_buffer[player->rewind_length-1].pos, - player->rewind_buffer[player->rewind_length-2].pos ); - } - } -} - PLAYER_API -void player__pre_update( player_instance *player ) -{ - if( player->rewinding ){ - return; - } - +void player__pre_update( player_instance *player ){ if( button_down( k_srbind_reset ) && !player->immobile ){ - f64 delta = world_static.time - world_static.last_use; - - if( (delta <= RESET_MAX_TIME) && (world_static.last_use != 0.0) ){ - player->rewinding = 1; - player->rewind_sound_wait = 1; - player->rewind_time = (double)player->rewind_length - 0.0001; - player_save_rewind_frame( player ); - - audio_lock(); - audio_oneshot( &audio_rewind[0], 1.0f, 0.0f ); - audio_unlock(); - - /* based on testing. DONT CHANGE! - * - * time taken: y = (x^(4/5)) * 74.5 - * inverse : x = (2/149)^(4/5) * y^(4/5) - */ - - float constant = powf( 2.0f/149.0f, 4.0f/5.0f ), - curve = powf( player->rewind_total_length, 4.0f/5.0f ); - - player->rewind_predicted_time = constant * curve; - player->rewind_start = vg.time; - player->subsystem = player->subsystem_gate; - player->rb = player->rb_gate_storage; - v3_copy( player->angles_storage, player->angles ); - - if( _player_restore[ player->subsystem ] ) - _player_restore[ player->subsystem ]( player ); + if( player->subsystem == k_player_subsystem_dead ){ + localplayer_cmd_respawn( 0, NULL ); } else{ - if( player->subsystem == k_player_subsystem_dead ){ - localplayer_cmd_respawn( 0, NULL ); - } - else{ - /* cant do that */ - audio_lock(); - audio_oneshot( &audio_rewind[4], 1.0f, 0.0f ); - audio_unlock(); - } + /* cant do that */ + audio_lock(); + audio_oneshot( &audio_rewind[4], 1.0f, 0.0f ); + audio_unlock(); } } if( button_down( k_srbind_camera ) && !player->immobile ){ - if( player->camera_mode == k_cam_firstperson ) - player->camera_mode = k_cam_thirdperson; + if( player->cam_control.camera_mode == k_cam_firstperson ) + player->cam_control.camera_mode = k_cam_thirdperson; else - player->camera_mode = k_cam_firstperson; + player->cam_control.camera_mode = k_cam_firstperson; } if( _player_pre_update[ player->subsystem ] ) @@ -197,32 +137,15 @@ void player__pre_update( player_instance *player ) } PLAYER_API -void player__update( player_instance *player ) -{ - if( player->rewinding ) - return; - +void player__update( player_instance *player ){ if( _player_update[ player->subsystem ] ) _player_update[ player->subsystem ]( player ); } PLAYER_API -void player__post_update( player_instance *player ) -{ - if( player->rewinding ) - return; - +void player__post_update( player_instance *player ){ if( _player_post_update[ player->subsystem ] ) _player_post_update[ player->subsystem ]( player ); - - if((player->subsystem != k_player_subsystem_dead) && !player->gate_waiting){ - player->rewind_accum += vg.time_frame_delta; - - if( player->rewind_accum > 0.25f ){ - player->rewind_accum -= 0.25f; - player_save_rewind_frame( player ); - } - } } /* @@ -237,10 +160,10 @@ void player__pass_gate( player_instance *player, ent_gate *gate ) player->gate_waiting = gate; world_routes_activate_entry_gate( world_current_instance(), gate ); - m4x3_mulv( gate->transport, player->tpv_lpf, player->tpv_lpf ); - m3x3_mulv( gate->transport, player->cam_velocity_smooth, - player->cam_velocity_smooth ); - + struct player_cam_controller *cc = &player->cam_control; + m4x3_mulv( gate->transport, cc->tpv_lpf, cc->tpv_lpf ); + m3x3_mulv( gate->transport, cc->cam_velocity_smooth, + cc->cam_velocity_smooth ); m3x3_copy( player->basis, player->basis_gate ); v4f q; @@ -250,16 +173,7 @@ void player__pass_gate( player_instance *player, ent_gate *gate ) q_m3x3( player->qbasis, player->basis ); m3x3_transpose( player->basis, player->invbasis ); - player->subsystem_gate = player->subsystem; - player->rb_gate_storage = player->rb; - v3_copy( player->angles, player->angles_storage ); - player->rewind_length = 0; - player->rewind_total_length = 0.0f; - player->rewind_gate = gate; - player->rewind_accum = 0.0f; - m4x3_mulv( gate->transport, player->cam.pos, player->cam.pos ); - player_save_rewind_frame( player ); if( gate->type == k_gate_type_nonlocel ) world_static.active_world = gate->target; @@ -352,10 +266,6 @@ PLAYER_API void player__spawn( player_instance *player, ent_spawn *rp ){ player->subsystem = k_player_subsystem_walk; player->immobile = 0; player->gate_waiting = NULL; - player->rewind_length = 0; - player->rewind_accum = 0.0f; - player->rewind_gate = NULL; - player->rewinding = 0; world_static.last_use = 0.0; global_skateshop_exit(); diff --git a/player.h b/player.h index 77c63db..ecf595d 100644 --- a/player.h +++ b/player.h @@ -1,6 +1,8 @@ #ifndef PLAYER_H #define PLAYER_H +#include "skaterift.h" + enum player_subsystem{ k_player_subsystem_walk = 0, k_player_subsystem_skate = 1, @@ -8,6 +10,25 @@ enum player_subsystem{ k_player_subsystem_drive = 3 }; +struct player_cam_controller { + enum camera_mode{ + k_cam_firstperson = 1, + k_cam_thirdperson = 0 + } + camera_mode; + f32 camera_type_blend; + + v3f fpv_offset, /* expressed relative to rigidbody */ + tpv_offset, + tpv_offset_extra, + fpv_viewpoint, /* expressed relative to neck bone inverse final*/ + fpv_offset_smooth, + fpv_viewpoint_smooth, + tpv_offset_smooth, + tpv_lpf, + cam_velocity_smooth; +}; + #include "player_ragdoll.h" #include "player_render.h" #include "player_model.h" @@ -27,8 +48,8 @@ static i32 k_invert_y = 0; struct player_instance{ /* transform definition */ - rigidbody rb, rb_gate_storage; - v3f angles, angles_storage; + rigidbody rb; + v3f angles; v4f qbasis; m3x3f basis, invbasis, basis_gate; @@ -39,23 +60,7 @@ struct player_instance{ * --------------------------- */ camera cam; - - enum camera_mode{ - k_cam_firstperson = 1, - k_cam_thirdperson = 0 - } - camera_mode; - float camera_type_blend; - - v3f fpv_offset, /* expressed relative to rigidbody */ - tpv_offset, - tpv_offset_extra, - fpv_viewpoint, /* expressed relative to neck bone inverse final */ - fpv_offset_smooth, - fpv_viewpoint_smooth, - tpv_offset_smooth, - tpv_lpf, - cam_velocity_smooth; + struct player_cam_controller cam_control; v3f cam_override_pos; v3f cam_override_angles; @@ -71,7 +76,6 @@ struct player_instance{ cam_velocity_influence_smooth; v3f cam_land_punch, cam_land_punch_v; - ent_gate *gate_waiting; int immobile; @@ -92,25 +96,6 @@ struct player_instance{ struct board_pose board_pose; - /* - * Rewind (OLD SYSTEM) - * ---------------------------------------------------- - */ - int rewinding, rewind_sound_wait; - - struct rewind_frame{ - v3f pos; - v3f ang; - } - *rewind_buffer; - u32 rewind_length; - float rewind_accum; - ent_gate *rewind_gate; - - float rewind_total_length, rewind_predicted_time, - dist_accum; - double rewind_start, rewind_time; - /* * Replay * ------------------------------------------------- @@ -122,9 +107,7 @@ struct player_instance{ * ------------------------------------------------- */ - enum player_subsystem - subsystem, - subsystem_gate; + enum player_subsystem subsystem; /* .. prev */ struct player_skate _skate; struct player_walk _walk; @@ -219,17 +202,6 @@ void( *_player_post_animate[])( player_instance *player ) = player__drive_post_animate }; - -__attribute__((deprecated)) -VG_STATIC -void( *_player_restore[] )( player_instance *player ) = -{ - player__walk_restore, - player__skate_restore, - NULL, - NULL -}; - VG_STATIC void( *_player_store_state[] )( player_instance *player ) = { diff --git a/player_common.c b/player_common.c index 5e1c88d..2ebec6c 100644 --- a/player_common.c +++ b/player_common.c @@ -59,24 +59,20 @@ VG_STATIC void player_camera_portal_correction( player_instance *player ) } } -VG_STATIC void player__cam_iterate( player_instance *player ) -{ +VG_STATIC void player__cam_iterate( player_instance *player ){ struct player_avatar *av = player->playeravatar; + struct player_cam_controller *cc = &player->cam_control; if( player->subsystem == k_player_subsystem_walk ){ - v3_copy( (v3f){-0.1f,1.8f,0.0f}, player->fpv_viewpoint ); - v3_copy( (v3f){0.0f,0.0f,0.0f}, player->fpv_offset ); - v3_copy( (v3f){0.0f,1.4f,0.0f}, player->tpv_offset ); + v3_copy( (v3f){-0.1f,1.8f,0.0f}, cc->fpv_viewpoint ); + v3_copy( (v3f){0.0f,0.0f,0.0f}, cc->fpv_offset ); + v3_copy( (v3f){0.0f,1.4f,0.0f}, cc->tpv_offset ); } else{ - v3_copy( (v3f){-0.15f,1.75f,0.0f}, player->fpv_viewpoint ); -#if 0 - v3_copy( (v3f){-0.35f,0.0f,0.0f}, player->fpv_offset ); -#endif - v3_copy( (v3f){0.0f,0.0f,0.0f}, player->fpv_offset ); - v3_copy( (v3f){0.0f,1.4f,0.0f}, player->tpv_offset ); - v3_add( player->tpv_offset_extra, player->tpv_offset, - player->tpv_offset ); + v3_copy( (v3f){-0.15f,1.75f,0.0f}, cc->fpv_viewpoint ); + v3_copy( (v3f){0.0f,0.0f,0.0f}, cc->fpv_offset ); + v3_copy( (v3f){0.0f,1.4f,0.0f}, cc->tpv_offset ); + v3_add( cc->tpv_offset_extra, cc->tpv_offset, cc->tpv_offset ); } player->cam_velocity_constant = 0.25f; @@ -99,30 +95,30 @@ VG_STATIC void player__cam_iterate( player_instance *player ) player->cam_velocity_constant, vg.time_frame_delta * 8.0f ); - enum camera_mode target_mode = player->camera_mode; + enum camera_mode target_mode = cc->camera_mode; if( player->subsystem == k_player_subsystem_dead ) target_mode = k_cam_thirdperson; - player->camera_type_blend = - vg_lerpf( player->camera_type_blend, - (target_mode == k_cam_firstperson)? 1.0f: 0.0f, + cc->camera_type_blend = + vg_lerpf( cc->camera_type_blend, + (target_mode == k_cam_firstperson)? 1.0f: 0.0f, 5.0f * vg.time_frame_delta ); - v3_lerp( player->fpv_viewpoint_smooth, player->fpv_viewpoint, - vg.time_frame_delta * 8.0f, player->fpv_viewpoint_smooth ); + v3_lerp( cc->fpv_viewpoint_smooth, cc->fpv_viewpoint, + vg.time_frame_delta * 8.0f, cc->fpv_viewpoint_smooth ); - v3_lerp( player->fpv_offset_smooth, player->fpv_offset, - vg.time_frame_delta * 8.0f, player->fpv_offset_smooth ); + v3_lerp( cc->fpv_offset_smooth, cc->fpv_offset, + vg.time_frame_delta * 8.0f, cc->fpv_offset_smooth ); - v3_lerp( player->tpv_offset_smooth, player->tpv_offset, - vg.time_frame_delta * 8.0f, player->tpv_offset_smooth ); + v3_lerp( cc->tpv_offset_smooth, cc->tpv_offset, + vg.time_frame_delta * 8.0f, cc->tpv_offset_smooth ); /* fov -- simple blend */ float fov_skate = vg_lerpf( 97.0f, 135.0f, k_fov ), fov_walk = vg_lerpf( 90.0f, 110.0f, k_fov ); - player->cam.fov = vg_lerpf( fov_walk, fov_skate, player->camera_type_blend ); + player->cam.fov = vg_lerpf( fov_walk, fov_skate, cc->camera_type_blend ); /* * first person camera @@ -131,25 +127,24 @@ VG_STATIC void player__cam_iterate( player_instance *player ) /* position */ v3f fpv_pos, fpv_offset; m4x3_mulv( av->sk.final_mtx[ av->id_head-1 ], - player->fpv_viewpoint_smooth, fpv_pos ); - m3x3_mulv( player->rb.to_world, player->fpv_offset_smooth, fpv_offset ); + cc->fpv_viewpoint_smooth, fpv_pos ); + m3x3_mulv( player->rb.to_world, cc->fpv_offset_smooth, fpv_offset ); v3_add( fpv_offset, fpv_pos, fpv_pos ); /* angles */ v3f velocity_angles; - v3_lerp( player->cam_velocity_smooth, player->rb.v, 4.0f*vg.time_frame_delta, - player->cam_velocity_smooth ); + v3_lerp( cc->cam_velocity_smooth, player->rb.v, 4.0f*vg.time_frame_delta, + cc->cam_velocity_smooth ); v3f velocity_local; - m3x3_mulv( player->invbasis, player->cam_velocity_smooth, velocity_local ); + m3x3_mulv( player->invbasis, cc->cam_velocity_smooth, velocity_local ); player_vector_angles( velocity_angles, velocity_local, player->cam_velocity_coefficient_smooth, player->cam_velocity_constant_smooth ); - float inf_fpv = player->cam_velocity_influence_smooth * - player->camera_type_blend, + float inf_fpv = player->cam_velocity_influence_smooth * cc->camera_type_blend, inf_tpv = player->cam_velocity_influence_smooth * - (1.0f-player->camera_type_blend); + (1.0f-cc->camera_type_blend); camera_lerp_angles( player->angles, velocity_angles, inf_fpv, @@ -191,19 +186,19 @@ VG_STATIC void player__cam_iterate( player_instance *player ) v3f pco; v4f pq; rb_extrapolate( &player->rb, pco, pq ); - v3_lerp( player->tpv_lpf, pco, 20.0f*vg.time_frame_delta, player->tpv_lpf ); + v3_lerp( cc->tpv_lpf, pco, 20.0f*vg.time_frame_delta, cc->tpv_lpf ); /* now move into world */ v3f tpv_pos, tpv_offset, tpv_origin; /* origin */ - q_mulv( pq, player->tpv_offset_smooth, tpv_origin ); - v3_add( tpv_origin, player->tpv_lpf, tpv_origin ); + q_mulv( pq, cc->tpv_offset_smooth, tpv_origin ); + v3_add( tpv_origin, cc->tpv_lpf, tpv_origin ); /* offset */ m3x3_mulv( player->basis, camera_follow_dir, camera_follow_dir ); v3_muls( camera_follow_dir, 1.8f, tpv_offset ); - v3_muladds( tpv_offset, player->cam_velocity_smooth, -0.025f, tpv_offset ); + v3_muladds( tpv_offset, cc->cam_velocity_smooth, -0.025f, tpv_offset ); v3_add( tpv_origin, tpv_offset, tpv_pos ); f32 t; v3f n; @@ -215,7 +210,7 @@ VG_STATIC void player__cam_iterate( player_instance *player ) /* * Blend cameras */ - v3_lerp( tpv_pos, fpv_pos, player->camera_type_blend, player->cam.pos ); + v3_lerp( tpv_pos, fpv_pos, cc->camera_type_blend, player->cam.pos ); v3_copy( player->angles, player->cam.angles ); /* Camera shake */ @@ -286,7 +281,7 @@ VG_STATIC void player_look( player_instance *player, v3f angles ) { if( vg_ui.wants_mouse ) return; - float sensitivity = 1.0f-menu.factive; + float sensitivity = skaterift.time_rate; angles[2] = 0.0f; diff --git a/player_drive.c b/player_drive.c index 2423d35..216ec89 100644 --- a/player_drive.c +++ b/player_drive.c @@ -41,7 +41,7 @@ VG_STATIC void player__drive_animate( player_instance *player, VG_STATIC void player__drive_post_animate( player_instance *player ) { - if( player->camera_mode == k_cam_firstperson ) + if( player->cam_control.camera_mode == k_cam_firstperson ) player->cam_velocity_influence = 0.0f; else player->cam_velocity_influence = 1.0f; diff --git a/player_render.c b/player_render.c index d687370..851b98f 100644 --- a/player_render.c +++ b/player_render.c @@ -137,8 +137,7 @@ VG_STATIC void player_model_unload( struct player_model *board ){ dynamic_model_unload( &board->mdl ); } -VG_STATIC void player__pre_render( player_instance *player ) -{ +VG_STATIC void player_animate( player_instance *player ){ if( _player_animate[ player->subsystem ] ){ player_animation res; res.type = k_player_animation_type_fk; @@ -173,145 +172,74 @@ VG_STATIC void player__pre_render( player_instance *player ) if( _player_post_animate[ player->subsystem ] ) _player_post_animate[ player->subsystem ]( player ); +} - struct player_avatar *av = player->playeravatar; - struct player_board *board = - addon_cache_item_if_loaded( k_addon_type_board, - player->board_view_slot ); - - v3f vp0, vp1; +VG_STATIC void player__pre_render( player_instance *player ){ + player->cam_override_strength = 0.0f; + player_animate( player ); - if( board ){ - v3_copy((v3f){0.0f,0.1f, board->truck_positions[0][2]}, vp0 ); - v3_copy((v3f){0.0f,0.1f, board->truck_positions[1][2]}, vp1 ); - } - else{ - v3_zero( vp0 ); - v3_zero( vp1 ); - } + /* dev playbacker */ + if( k_replay_test ){ + f64 speed = 1.0; + f64 target = player->replay.cursor; - struct ub_world_lighting *ubo = &world_current_instance()->ub_lighting; - m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp0, ubo->g_board_0 ); - m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp1, ubo->g_board_1 ); + if( vg_getkey( SDLK_9 ) ){ + target -= vg.time_frame_delta * speed; + player->replay.control = k_replay_control_scrub; + replay_seek( &player->replay, target ); + } + if( vg_getkey( SDLK_0 ) ){ + target += vg.time_frame_delta * speed; + player->replay.control = k_replay_control_scrub; + replay_seek( &player->replay, target ); + } - if( player->immobile ){ - player__cam_iterate( player ); - return; - } + if( vg_getkey( SDLK_7 ) ) + player->replay.control = k_replay_control_play; -#if 0 - if( player->rewinding ){ - if( player->rewind_time <= 0.0f ){ - double taken = vg.time - player->rewind_start; - vg_success( "Rewind took (rt, pt, tl): %f, %f, %f\n", - taken, player->rewind_predicted_time, - player->rewind_total_length ); - - player->rewinding = 0; - player->rewind_length = 1; - player->rewind_total_length = 0.0f; - player->rewind_accum = 0.0f; - world_render.sky_target_rate = 1.0; - world_static.time = world_static.last_use; + if( player->replay.control == k_replay_control_play ){ + target += vg.time_frame_delta; + replay_seek( &player->replay, target ); } - else{ - world_render.sky_target_rate = -100.0; - - float budget = vg.time_delta, - overall_length = player->rewind_length; - - for( int i=0; (i<10)&&(player->rewind_time>0.0f)&&(budget>0.0f); i++ ){ - /* Interpolate frames */ - int i0 = floorf( player->rewind_time ), - i1 = VG_MIN( i0+1, player->rewind_length-1 ); - - struct rewind_frame *fr = &player->rewind_buffer[i0], - *fr1 = &player->rewind_buffer[i1]; - - float dist = vg_maxf( v3_dist( fr->pos, fr1->pos ), 0.001f ), - subl = vg_fractf( player->rewind_time ) + 0.001f, - - sramp = 3.0f-(1.0f/(0.4f+0.4f*player->rewind_time)), - speed = sramp*28.0f + 0.5f*player->rewind_time, - mod = speed * (budget / dist), - - advl = vg_minf( mod, subl ), - advt = (advl / mod) * budget; - - player->dist_accum += speed * advt; - player->rewind_time -= advl; - budget -= advt; - } - player->rewind_time = vg_maxf( 0.0f, player->rewind_time ); + if( vg_getkey( SDLK_8 ) ){ + replay_frame *prev = replay_find_recent_stateframe( &player->replay ); - float current_time = vg.time - player->rewind_start, - remaining = player->rewind_predicted_time - current_time; + if( prev ){ + /* TODO: Make gamestate_apply function / swap ... */ + replay_gamestate *gs = replay_frame_gamestate( prev, 0 ); - if( player->rewind_sound_wait ){ - if( player->rewind_predicted_time >= 6.5f ){ - if( remaining <= 6.5f ){ - audio_lock(); - audio_oneshot( &audio_rewind[3], 1.0f, 0.0f ); - audio_unlock(); - player->rewind_sound_wait = 0; - } + if( gs->system == k_player_subsystem_walk ){ + memcpy( &player->_walk.state, &gs->walk, + sizeof(struct player_walk_state) ); } - else if( player->rewind_predicted_time >= 2.5f ){ - if( remaining <= 2.5f ){ - audio_lock(); - audio_oneshot( &audio_rewind[2], 1.0f, 0.0f ); - audio_unlock(); - player->rewind_sound_wait = 0; - } - } - else if( player->rewind_predicted_time >= 1.5f ){ - if( remaining <= 1.5f ){ - audio_lock(); - audio_oneshot( &audio_rewind[1], 1.0f, 0.0f ); - audio_unlock(); - player->rewind_sound_wait = 0; - } + else if( gs->system == k_player_subsystem_skate ){ + memcpy( &player->_skate.state, &gs->skate, + sizeof(struct player_skate_state) ); } + player->subsystem = gs->system; + + memcpy( &player->rb, &gs->rb, sizeof(rigidbody) ); + v3_copy( gs->angles, player->angles ); + v3_copy( prev->cam_pos, player->cam.pos ); + v3_copy( prev->cam_angles, player->cam_override_angles ); + player->cam.fov = prev->cam_fov; + memcpy( &player->cam_control, &gs->cam_control, + sizeof(struct player_cam_controller) ); + + /* chop end off replay */ + prev->r = NULL; + player->replay.statehead = prev; + player->replay.head = prev; + player->replay.cursor_frame = prev; + player->replay.cursor = prev->time; + vg.time = prev->time; + + k_replay_test = 0; + player__pre_render( player ); + return; } - - int i0 = floorf( player->rewind_time ), - i1 = VG_MIN( i0+1, player->rewind_length-1 ); - - struct rewind_frame *fr = &player->rewind_buffer[i0], - *fr1 = &player->rewind_buffer[i1]; - - float sub = vg_fractf(player->rewind_time); - - v3_lerp( fr->pos, fr1->pos, sub, player->cam_override_pos ); - player->cam_override_angles[0] = - vg_alerpf( fr->ang[0], fr1->ang[0], sub ); - player->cam_override_angles[1] = - vg_lerpf ( fr->ang[1], fr1->ang[1], sub ); - player->cam_override_fov = player->cam.fov; - - float blend = player->rewind_time * 0.25f; - player->cam_override_strength = vg_clampf( blend, 0.0f, 1.0f ); } - } - else player->cam_override_strength = 0.0f; -#else - player->cam_override_strength = 0.0f; -#endif - - player__cam_iterate( player ); - - /* dev playbacker */ - if( k_replay_test ){ - f64 speed = 1.0; - f64 target = player->replay.cursor; - - if( vg_getkey( SDLK_9 ) ) - target -= vg.time_frame_delta * speed; - if( vg_getkey( SDLK_0 ) ) - target += vg.time_frame_delta * speed; - - replay_seek( &player->replay, target ); player_animation res; replay_frame *frame = player->replay.cursor_frame; @@ -320,6 +248,10 @@ VG_STATIC void player__pre_render( player_instance *player ) memcpy( &res, &frame->anim, sizeof(frame->anim) ); memcpy( &frame->board_pose, &player->board_pose, sizeof(player->board_pose) ); + v3_copy( frame->cam_pos, player->cam_override_pos ); + v3_copy( frame->cam_angles, player->cam_override_angles ); + player->cam_override_fov = frame->cam_fov; + player->cam_override_strength = 1.0f; } else return; @@ -329,10 +261,28 @@ VG_STATIC void player__pre_render( player_instance *player ) else { /* replay recorder */ replay_buffer *replay = &player->replay; - f64 delta = vg.time - replay->cursor; - if( delta > (1.0/30.0) ){ + + f64 delta = 9999999.9, + statedelta = 9999999.9; + + if( replay->head ) + delta = vg.time - replay->head->time; + + if( replay->statehead ) + statedelta = vg.time - replay->statehead->time; + + const f64 k_replay_rate = 1.0/30.0, + k_gamestate_rate = 0.5; + + u16 gamestates = 0; + if( statedelta > k_gamestate_rate /* or switching */ ){ + gamestates = 1; + } + + if( (delta > k_replay_rate) || gamestates ){ + replay_frame *frame = replay_newframe( replay, gamestates, 0 ); replay->cursor = vg.time; - replay_frame *frame = replay_newframe( replay ); + replay->cursor_frame = frame; player_animation *res = &frame->anim; v3_zero( res->root_co ); @@ -345,8 +295,51 @@ VG_STATIC void player__pre_render( player_instance *player ) memcpy( &frame->board_pose, &player->board_pose, sizeof(player->board_pose) ); frame->time = vg.time; + v3_copy( player->cam.pos, frame->cam_pos ); + v3_copy( player->cam.angles, frame->cam_angles ); + frame->cam_fov = player->cam.fov; + + if( gamestates ){ + replay_gamestate *gs = replay_frame_gamestate( frame, 0 ); + gs->system = player->subsystem; + + if( player->subsystem == k_player_subsystem_walk ){ + memcpy( &gs->walk, &player->_walk.state, + sizeof(struct player_walk_state) ); + } + else if( player->subsystem == k_player_subsystem_skate ){ + memcpy( &gs->skate, &player->_skate.state, + sizeof(struct player_skate_state) ); + } + + memcpy( &gs->rb, &player->rb, sizeof(rigidbody) ); + memcpy( &gs->cam_control, &player->cam_control, + sizeof(struct player_cam_controller) ); + v3_copy( player->angles, gs->angles ); + } } } + + player__cam_iterate( player ); + + /* shadowing/ao info */ + struct player_avatar *av = player->playeravatar; + struct player_board *board = + addon_cache_item_if_loaded( k_addon_type_board, + player->board_view_slot ); + v3f vp0, vp1; + if( board ){ + v3_copy((v3f){0.0f,0.1f, board->truck_positions[0][2]}, vp0 ); + v3_copy((v3f){0.0f,0.1f, board->truck_positions[1][2]}, vp1 ); + } + else{ + v3_zero( vp0 ); + v3_zero( vp1 ); + } + + struct ub_world_lighting *ubo = &world_current_instance()->ub_lighting; + m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp0, ubo->g_board_0 ); + m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp1, ubo->g_board_1 ); } VG_STATIC void render_board( camera *cam, world_instance *world, diff --git a/player_replay.c b/player_replay.c index 83b9b83..f0487f4 100644 --- a/player_replay.c +++ b/player_replay.c @@ -10,19 +10,40 @@ VG_STATIC void local_replay_init( u32 bytes ){ vg_console_reg_var( "k_replay_test", &k_replay_test, k_var_dtype_i32, 0 ); } +replay_gamestate *replay_frame_gamestate( replay_frame *frame, u16 index ){ + void *baseptr = frame; + + replay_gamestate *array = (baseptr + vg_align8( sizeof(replay_frame))); + return &array[ index ]; +} + +replay_sfx *replay_frame_sfx( replay_frame *frame, u16 index ){ + void *gsarr = replay_frame_gamestate( frame, 0 ); + u32 gssize = frame->gamestate_count * sizeof(replay_gamestate); + + replay_sfx *array = (gsarr + vg_align8(gssize)); + return &array[index]; +} + +u32 _replay_frame_size( u16 gamestate_count, u16 sfx_count ){ + return vg_align8( sizeof( replay_frame ) ) + + vg_align8( gamestate_count * sizeof(replay_gamestate) ) + + vg_align8( sfx_count * sizeof(replay_sfx) ); +} + u32 replay_frame_size( replay_frame *frame ){ - /* eventually it will be a dynamic size */ - return vg_align8( sizeof( replay_frame ) ); + return _replay_frame_size( frame->gamestate_count, frame->sfx_count ); } -VG_STATIC replay_frame *replay_newframe( replay_buffer *replay ){ +VG_STATIC replay_frame *replay_newframe( replay_buffer *replay, + u16 gamestate_count, u16 sfx_count ){ replay_frame *frame = NULL; if( replay->head ){ assert( replay->head ); u32 headsize = replay_frame_size( replay->head ), nextpos = ((void *)replay->head - replay->data) + headsize, - nextsize = vg_align8( sizeof(replay_frame) ); + nextsize = _replay_frame_size( gamestate_count, sfx_count ); if( nextsize > replay->size ){ vg_error( "Keyframe too big\n" ); @@ -38,36 +59,39 @@ check_again:; if( tailpos >= nextpos ){ if( nextpos + nextsize > tailpos ){ - if( replay->cursor_frame == replay->tail ){ + /* remove links */ + if( replay->cursor_frame == replay->tail ) replay->cursor_frame = NULL; - } + if( replay->statehead == replay->tail ) + replay->statehead = NULL; + /* pop node */ replay->tail = replay->tail->r; if( replay->tail ) { replay->tail->l = NULL; goto check_again; } - else{ + else replay->head = NULL; - } } } frame = replay->data + nextpos; - if( replay->head ){ + if( replay->head ) replay->head->r = frame; - } } - else { + else frame = replay->data; - } + frame->gamestate_count = gamestate_count; + frame->sfx_count = sfx_count; frame->l = replay->head; frame->r = NULL; replay->head = frame; if( !replay->tail ) replay->tail = frame; + if( gamestate_count ) replay->statehead = frame; return frame; } @@ -94,7 +118,7 @@ VG_STATIC void replay_seek( replay_buffer *replay, f64 t ){ dir = vg_signf( dir ); u32 i=0; - for( ; i<100; i++ ){ + for( ; i<1024; i++ ){ if( dir < 0.0 ) if( t > replay->cursor_frame->time ) break; @@ -108,11 +132,27 @@ VG_STATIC void replay_seek( replay_buffer *replay, f64 t ){ if( t < next->time ) break; replay->cursor_frame = next; + replay->cursor = next->time; + + if( i == 1023 ) return; } replay->cursor = t; } +VG_STATIC replay_frame *replay_find_recent_stateframe( replay_buffer *replay ){ + replay_frame *frame = replay->cursor_frame; + + u32 i=0; + for( ; i<4096; i++ ){ + if( !frame ) return frame; + if( frame->gamestate_count ) return frame; + frame = frame->l; + } + + return NULL; +} + VG_STATIC void replay_debug_info( player_instance *player ){ player__debugtext( 2, "replay info" ); @@ -125,6 +165,13 @@ VG_STATIC void replay_debug_info( player_instance *player ){ player__debugtext( 1, "head @%u | tail @%u\n", head, tail ); + if( replay->statehead ){ + u32 state = (void *)replay->statehead - replay->data; + player__debugtext( 1, "gs @%u\n", state ); + } + else + player__debugtext( 1, "gs @NULL\n" ); + f64 start = replay->cursor, end = replay->cursor; if( replay->tail ) start = replay->tail->time; @@ -149,14 +196,42 @@ VG_STATIC void replay_imgui( player_instance *player ){ char buffer[ 128 ]; + /* mainbar */ ui_px height = 20, - cwidth = 8; + cwidth = 2; ui_rect bar = { 0, vg.window_y - height, vg.window_x, height }; ui_fill( bar, ui_colour( k_ui_bg ) ); + /* cursor frame block */ + if( replay->cursor_frame ){ + if( replay->cursor_frame->r ){ + f64 l = (replay->cursor_frame->r->time-replay->cursor_frame->time)/len, + s = (replay->cursor_frame->time - start) / len; + ui_rect box = { s*(f64)vg.window_x, bar[1]-2, + VG_MAX(4,(ui_px)l), bar[3]+2 }; + ui_fill( box, ui_colour( k_ui_bg+4 ) ); + } + } + + /* cursor */ ui_rect cusor = { cur * (f64)vg.window_x - (cwidth/2), bar[1], cwidth, bar[3] }; - ui_fill( cusor, ui_colour( k_ui_bg+4 ) ); + ui_fill( cusor, ui_colour( k_ui_bg+7 ) ); + + /* latest state marker */ + if( replay->statehead ){ + f64 t = (replay->statehead->time - start) / len; + ui_rect tag = { t*(f64)vg.window_x, bar[1]-8, 2, bar[3]+8 }; + ui_fill( tag, ui_colour( k_ui_green+k_ui_brighter ) ); + } + + /* previous state marker */ + replay_frame *prev = replay_find_recent_stateframe( replay ); + if( prev ){ + f64 t = (prev->time - start) / len; + ui_rect tag = { t*(f64)vg.window_x, bar[1]-8, 2, bar[3]+8 }; + ui_fill( tag, ui_colour( k_ui_yellow+k_ui_brighter ) ); + } cusor[1] -= height; cusor[2] = 200; diff --git a/player_replay.h b/player_replay.h index 1befaad..2c18d4c 100644 --- a/player_replay.h +++ b/player_replay.h @@ -9,13 +9,21 @@ static i32 k_replay_test = 0; typedef struct replay_buffer replay_buffer; typedef struct replay_frame replay_frame; +typedef struct replay_gamestate replay_gamestate; +typedef struct replay_sfx replay_sfx; struct replay_buffer { void *data; u32 size; /* bytes */ - replay_frame *head, *tail, *cursor_frame; + enum replay_control { + k_replay_control_scrub, + k_replay_control_play, + } + control; + replay_frame *head, *tail, *cursor_frame, + *statehead; f64 cursor; }; @@ -23,15 +31,40 @@ struct replay_frame { player_animation anim; struct board_pose board_pose; + v3f cam_pos, cam_angles; + f32 cam_fov; + f64 time; replay_frame *l, *r; - /* eventually, sound events, player iframes and stuff? */ + u16 gamestate_count, sfx_count; +}; + +struct replay_gamestate { + enum player_subsystem system; + rigidbody rb; + v3f angles; + + struct player_cam_controller cam_control; + + union { + struct player_skate_state skate; + struct player_walk_state walk; + }; +}; + +struct replay_sfx { + u32 none; }; VG_STATIC void replay_debug_info( player_instance *player ); -VG_STATIC replay_frame *replay_newframe( replay_buffer *replay ); +VG_STATIC replay_frame *replay_newframe( replay_buffer *replay, + u16 gamestate_count, u16 sfx_count ); VG_STATIC void replay_imgui( player_instance *player ); VG_STATIC void replay_seek( replay_buffer *replay, f64 t ); +replay_gamestate *replay_frame_gamestate( replay_frame *frame, u16 index ); +replay_sfx *replay_frame_sfx( replay_frame *frame, u16 index ); +VG_STATIC replay_frame *replay_find_recent_stateframe( replay_buffer *replay ); + #endif /* PLAYER_REPLAY_H */ diff --git a/player_skate.c b/player_skate.c index a796b7c..1ef19a1 100644 --- a/player_skate.c +++ b/player_skate.c @@ -476,7 +476,7 @@ void player__approximate_best_trajectory( player_instance *player ) float a = v2_dot( v0, v1 ); float a_min = cosf( VG_PIf * 0.185f ); - if( s->grind_cooldown ) + if( s->state.grind_cooldown ) a_min = cosf( VG_PIf * 0.05f ); /* check speed */ @@ -722,15 +722,15 @@ VG_STATIC void skate_apply_trick_model( player_instance *player ) v3f Fd, Fs, F; v3f strength = { 3.7f, 3.6f, 8.0f }; - v3_muls( s->board_trick_residualv, -4.0f , Fd ); - v3_muls( s->board_trick_residuald, -10.0f, Fs ); + v3_muls( s->state.board_trick_residualv, -4.0f , Fd ); + v3_muls( s->state.board_trick_residuald, -10.0f, Fs ); v3_add( Fd, Fs, F ); v3_mul( strength, F, F ); - v3_muladds( s->board_trick_residualv, F, k_rb_delta, - s->board_trick_residualv ); - v3_muladds( s->board_trick_residuald, s->board_trick_residualv, - k_rb_delta, s->board_trick_residuald ); + v3_muladds( s->state.board_trick_residualv, F, k_rb_delta, + s->state.board_trick_residualv ); + v3_muladds( s->state.board_trick_residuald, s->state.board_trick_residualv, + k_rb_delta, s->state.board_trick_residuald ); if( s->state.activity <= k_skate_activity_air_to_grind ){ if( v3_length2( s->state.trick_vel ) < 0.0001f ) @@ -763,7 +763,7 @@ VG_STATIC void skate_apply_trick_model( player_instance *player ) s->state.trick_euler[0] = roundf( s->state.trick_euler[0] ); s->state.trick_euler[1] = roundf( s->state.trick_euler[1] ); s->state.trick_euler[2] = roundf( s->state.trick_euler[2] ); - v3_copy( s->state.trick_vel, s->board_trick_residualv ); + v3_copy( s->state.trick_vel, s->state.board_trick_residualv ); v3_zero( s->state.trick_vel ); } @@ -961,7 +961,7 @@ VG_STATIC void skate_apply_jump_model( player_instance *player ) v3_normalize( jumpdir ); }else{ v3_copy( s->state.up_dir, jumpdir ); - s->grind_cooldown = 30; + s->state.grind_cooldown = 30; s->state.activity = k_skate_activity_ground; v2f steer; @@ -974,7 +974,7 @@ VG_STATIC void skate_apply_jump_model( player_instance *player ) q_axis_angle( qtilt, s->grind_dir, tilt ); q_mulv( qtilt, jumpdir, jumpdir ); } - s->surface_cooldown = 10; + s->state.surface_cooldown = 10; float force = k_jump_force*s->state.jump_charge; v3_muladds( player->rb.v, jumpdir, force, player->rb.v ); @@ -1195,7 +1195,7 @@ VG_STATIC void player__skate_post_update( player_instance *player ) slide = 0.0f; } - f32 gate = 1.0f-menu.factive, + f32 gate = skaterift.time_rate, vol_main = sqrtf( (1.0f-air)*attn*(1.0f-slide) * 0.4f ) * gate, vol_air = sqrtf( air *attn * 0.5f ) * gate, vol_slide = sqrtf( (1.0f-air)*attn*slide * 0.25f ) * gate; @@ -1962,13 +1962,13 @@ VG_STATIC enum skate_activity skate_availible_grind( player_instance *player ) { struct player_skate *s = &player->_skate; - if( s->grind_cooldown > 100 ){ + if( s->state.grind_cooldown > 100 ){ vg_fatal_error( "wth!\n" ); } /* debounces this state manager a little bit */ - if( s->grind_cooldown ){ - s->grind_cooldown --; + if( s->state.grind_cooldown ){ + s->state.grind_cooldown --; return k_skate_activity_undefined; } @@ -2058,8 +2058,8 @@ VG_STATIC enum skate_activity skate_availible_grind( player_instance *player ) if( new_activity == k_skate_activity_undefined ){ if( s->state.activity >= k_skate_activity_grind_any ){ - s->grind_cooldown = 15; - s->surface_cooldown = 10; + s->state.grind_cooldown = 15; + s->state.surface_cooldown = 10; } } else if( new_activity == k_skate_activity_grind_boardslide ){ @@ -2203,8 +2203,8 @@ VG_STATIC void player__skate_update( player_instance *player ) m3x3_mulv( player->rb.to_local, axel, s->truckv0[i] ); } - if( s->surface_cooldown ){ - s->surface_cooldown --; + if( s->state.surface_cooldown ){ + s->state.surface_cooldown --; contact_count = 0; } @@ -2537,7 +2537,7 @@ begin_collision:; } f32 amt = k_cam_punch; - if( player->camera_mode == k_cam_firstperson ){ + if( player->cam_control.camera_mode == k_cam_firstperson ){ amt *= 0.25f; } @@ -2586,8 +2586,6 @@ begin_collision:; q_mul( transport_rotation, s->state.smoothed_rotation, s->state.smoothed_rotation ); rb_update_transform( &player->rb ); - - s->state_gate_storage = s->state; player__pass_gate( player, gate ); } @@ -2675,6 +2673,7 @@ VG_STATIC void player__skate_animate( player_instance *player, player_animation *dest ) { struct player_skate *s = &player->_skate; + struct player_skate_state *state = &player->_skate.state; struct player_avatar *av = player->playeravatar; struct skeleton *sk = &av->sk; @@ -2703,19 +2702,22 @@ VG_STATIC void player__skate_animate( player_instance *player, kicks = (vg_randf64()-0.5f)*2.0f*kickspeed, sign = vg_signf( kicks ); - s->wobble[0] = vg_lerpf( s->wobble[0], kicks*kicks*sign, 6.0f*vg.time_delta); - s->wobble[1] = vg_lerpf( s->wobble[1], s->wobble[0], 2.4f*vg.time_delta); + state->wobble[0] = vg_lerpf( state->wobble[0], kicks*kicks*sign, + 6.0f*vg.time_delta); + state->wobble[1] = vg_lerpf( state->wobble[1], state->wobble[0], + 2.4f*vg.time_delta); offset[0] *= 0.26f; - offset[0] += s->wobble[1]*3.0f; + offset[0] += state->wobble[1]*3.0f; offset[1] *= -0.3f; offset[2] *= 0.01f; - offset[0]=vg_clampf(offset[0],-0.8f,0.8f)*(1.0f-fabsf(s->blend_slide)*0.9f); + offset[0]=vg_clampf(offset[0],-0.8f,0.8f) + *(1.0f-fabsf(state->blend_slide)*0.9f); offset[1]=vg_clampf(offset[1],-0.5f,0.0f); - v3_muls( offset, 0.3f, player->tpv_offset_extra ); + v3_muls( offset, 0.3f, player->cam_control.tpv_offset_extra ); /* * Animation blending @@ -2728,7 +2730,8 @@ VG_STATIC void player__skate_animate( player_instance *player, if( s->state.activity == k_skate_activity_ground ) desired = vg_clampf( fabsf( s->state.slip ), 0.0f, 1.0f ); - s->blend_slide = vg_lerpf( s->blend_slide, desired, 2.4f*vg.time_delta); + state->blend_slide = + vg_lerpf( state->blend_slide, desired, 2.4f*vg.time_delta); } /* movement information */ @@ -2743,10 +2746,14 @@ VG_STATIC void player__skate_animate( player_instance *player, if( s->state.activity >= k_skate_activity_grind_any ) wdist = 0.0f; - s->blend_z = vg_lerpf( s->blend_z, dirz, 2.4f*vg.time_delta ); - s->blend_x = vg_lerpf( s->blend_x, dirx, 0.6f*vg.time_delta ); - s->blend_fly = vg_lerpf( s->blend_fly, fly, 3.4f*vg.time_delta ); - s->blend_weight= vg_lerpf( s->blend_weight, wdist, 9.0f*vg.time_delta ); + state->blend_z = + vg_lerpf( state->blend_z, dirz, 2.4f*vg.time_delta ); + state->blend_x = + vg_lerpf( state->blend_x, dirx, 0.6f*vg.time_delta ); + state->blend_fly = + vg_lerpf( state->blend_fly, fly, 3.4f*vg.time_delta ); + state->blend_weight = + vg_lerpf( state->blend_weight, wdist, 9.0f*vg.time_delta ); } mdl_keyframe apose[32], bpose[32]; @@ -2754,10 +2761,11 @@ VG_STATIC void player__skate_animate( player_instance *player, { /* when the player is moving fast he will crouch down a little bit */ float stand = 1.0f - vg_clampf( curspeed * 0.03f, 0.0f, 1.0f ); - s->blend_stand = vg_lerpf( s->blend_stand, stand, 6.0f*vg.time_delta ); + state->blend_stand = + vg_lerpf( state->blend_stand, stand, 6.0f*vg.time_delta ); /* stand/crouch */ - float dir_frame = s->blend_z * (15.0f/30.0f), + float dir_frame = state->blend_z * (15.0f/30.0f), stand_blend = offset[1]*-2.0f; v2f steer; @@ -2770,7 +2778,7 @@ VG_STATIC void player__skate_animate( player_instance *player, f32 slide_dir = vg_signf(v3_dot(player->rb.v,player->rb.to_world[0])); s->state.delayed_slip_dir = slide_dir; } - lean1 = s->blend_slide * s->state.delayed_slip_dir; + lean1 = state->blend_slide * s->state.delayed_slip_dir; if( fabsf(lean1)>fabsf(lean2) ) lean = lean1; else lean = lean2; @@ -2790,13 +2798,13 @@ VG_STATIC void player__skate_animate( player_instance *player, skeleton_lerp_pose( sk, apose, bpose, stand_blend, apose ); /* sliding */ - float slide_frame = s->blend_x * (15.0f/30.0f); + float slide_frame = state->blend_x * (15.0f/30.0f); skeleton_sample_anim( sk, s->anim_slide, slide_frame, bpose ); - skeleton_lerp_pose( sk, apose, bpose, s->blend_slide, apose ); + skeleton_lerp_pose( sk, apose, bpose, state->blend_slide, apose ); /* pushing */ double push_time = vg.time - s->state.start_push; - s->blend_push = vg_lerpf( s->blend_push, + state->blend_push = vg_lerpf( state->blend_push, (vg.time - s->state.cur_push) < 0.125, 6.0f*vg.time_delta ); @@ -2805,16 +2813,17 @@ VG_STATIC void player__skate_animate( player_instance *player, else skeleton_sample_anim( sk, s->anim_push_reverse, push_time, bpose ); - skeleton_lerp_pose( sk, apose, bpose, s->blend_push, apose ); + skeleton_lerp_pose( sk, apose, bpose, state->blend_push, apose ); /* trick setup */ float jump_start_frame = 14.0f/30.0f; float charge = s->state.jump_charge; - s->blend_jump = vg_lerpf( s->blend_jump, charge, 8.4f*vg.time_delta ); + state->blend_jump = + vg_lerpf( state->blend_jump, charge, 8.4f*vg.time_delta ); float setup_frame = charge * jump_start_frame, - setup_blend = vg_minf( s->blend_jump, 1.0f ); + setup_blend = vg_minf( state->blend_jump, 1.0f ); float jump_frame = (vg.time - s->state.jump_time) + jump_start_frame; if( jump_frame >= jump_start_frame && jump_frame <= (40.0f/30.0f) ) @@ -2835,9 +2844,10 @@ VG_STATIC void player__skate_animate( player_instance *player, float target = -steer[1]; - s->blend_airdir = vg_lerpf( s->blend_airdir, target, 2.4f*vg.time_delta ); + state->blend_airdir = + vg_lerpf( state->blend_airdir, target, 2.4f*vg.time_delta ); - float air_frame = (s->blend_airdir*0.5f+0.5f) * (15.0f/30.0f); + float air_frame = (state->blend_airdir*0.5f+0.5f) * (15.0f/30.0f); skeleton_sample_anim( sk, s->anim_air, air_frame, apose ); static v2f grab_choice; @@ -2860,7 +2870,8 @@ VG_STATIC void player__skate_animate( player_instance *player, skeleton_lerp_pose( sk, apose, bpose, s->state.grabbing, air_pose ); } - skeleton_lerp_pose( sk, ground_pose, air_pose, s->blend_fly, dest->pose ); + skeleton_lerp_pose( sk, ground_pose, air_pose, + state->blend_fly, dest->pose ); mdl_keyframe *kf_board = &dest->pose[av->id_board-1], @@ -2884,19 +2895,22 @@ VG_STATIC void player__skate_animate( player_instance *player, } float grind=s->state.activity >= k_skate_activity_grind_any? 1.0f: 0.0f; - s->blend_grind = vg_lerpf( s->blend_grind, grind, 5.0f*vg.time_delta ); - s->blend_grind_balance=vg_lerpf( s->blend_grind_balance, - grind_frame, 5.0f*vg.time_delta ); + state->blend_grind = + vg_lerpf( state->blend_grind, grind, 5.0f*vg.time_delta ); + state->blend_grind_balance = + vg_lerpf( state->blend_grind_balance, + grind_frame, 5.0f*vg.time_delta ); - grind_frame = s->blend_grind_balance * (15.0f/30.0f); + grind_frame = state->blend_grind_balance * (15.0f/30.0f); skeleton_sample_anim( sk, s->anim_grind, grind_frame, apose ); skeleton_sample_anim( sk, s->anim_grind_jump, grind_frame, bpose ); - skeleton_lerp_pose( sk, apose, bpose, s->blend_jump, grind_pose ); + skeleton_lerp_pose( sk, apose, bpose, state->blend_jump, grind_pose ); } - skeleton_lerp_pose( sk, dest->pose, grind_pose, s->blend_grind, dest->pose ); + skeleton_lerp_pose( sk, dest->pose, grind_pose, + state->blend_grind, dest->pose ); - float add_grab_mod = 1.0f - s->blend_fly; + float add_grab_mod = 1.0f - state->blend_fly; /* additive effects */ { @@ -2940,7 +2954,7 @@ VG_STATIC void player__skate_animate( player_instance *player, float yaw_counter_rotate = v3_dot(yaw_ref,yaw_smooth); yaw_counter_rotate = vg_clampf(yaw_counter_rotate,-1.0f,1.0f); yaw_counter_rotate = acosf( yaw_counter_rotate ); - yaw_counter_rotate *= 1.0f-s->blend_fly; + yaw_counter_rotate *= 1.0f-state->blend_fly; v3f ndir; m3x3_mulv( player->rb.to_local, s->state.up_dir, ndir ); @@ -2985,7 +2999,7 @@ VG_STATIC void player__skate_animate( player_instance *player, v4f qtrickr, qyawr, qpitchr, qrollr; v3f eulerr; - v3_muls( s->board_trick_residuald, VG_TAUf, eulerr ); + v3_muls( state->board_trick_residuald, VG_TAUf, eulerr ); q_axis_angle( qyawr, (v3f){0.0f,1.0f,0.0f}, eulerr[0] * 0.5f ); q_axis_angle( qpitchr, (v3f){1.0f,0.0f,0.0f}, eulerr[1] ); @@ -3024,46 +3038,46 @@ VG_STATIC void player__skate_animate( player_instance *player, if( board ){ /* foot weight distribution */ - if( s->blend_weight > 0.0f ){ + if( state->blend_weight > 0.0f ){ kf_foot_l->co[2] = vg_lerpf( kf_foot_l->co[2], board->truck_positions[k_board_truck_back][2]+0.3f, - 0.5f*s->blend_weight ); + 0.5f*state->blend_weight ); } else{ kf_foot_r->co[2] = vg_lerpf( kf_foot_r->co[2], board->truck_positions[k_board_truck_front][2]-0.3f, - -0.5f*s->blend_weight ); + -0.5f*state->blend_weight ); } } float slapm = vg_maxf( 1.0f-v3_length2( s->state.trick_vel ), 0.0f ); - s->subslap = vg_lerpf( s->subslap, slapm, vg.time_delta*10.0f ); + state->subslap = vg_lerpf( state->subslap, slapm, vg.time_delta*10.0f ); kf_foot_l->co[1] += s->state.slap; kf_foot_r->co[1] += s->state.slap; kf_knee_l->co[1] += s->state.slap; kf_knee_r->co[1] += s->state.slap; - kf_board->co[1] += s->state.slap * s->subslap; + kf_board->co[1] += s->state.slap * state->subslap; kf_hip->co[1] += s->state.slap * 0.25f; f32 l = ((s->state.activity < k_skate_activity_ground) && v3_length2(s->state.trick_vel) > 0.1f )? 1: 0; - s->blend_trick_foot = vg_lerpf( s->blend_trick_foot, l, - 8.4f*vg.time_delta ); + state->blend_trick_foot = vg_lerpf( state->blend_trick_foot, l, + 8.4f*vg.time_delta ); if( s->state.trick_type == k_trick_type_kickflip ){ - kf_foot_l->co[0] += s->blend_trick_foot * 0.2f; + kf_foot_l->co[0] += state->blend_trick_foot * 0.2f; } else if( s->state.trick_type == k_trick_type_shuvit ){ - kf_foot_l->co[0] += s->blend_trick_foot * 0.1f; - kf_foot_r->co[0] -= s->blend_trick_foot * 0.15f; + kf_foot_l->co[0] += state->blend_trick_foot * 0.1f; + kf_foot_r->co[0] -= state->blend_trick_foot * 0.15f; } else if( s->state.trick_type == k_trick_type_treflip ){ - kf_foot_l->co[0] += s->blend_trick_foot * 0.2f; - kf_foot_r->co[0] -= s->blend_trick_foot * 0.15f; + kf_foot_l->co[0] += state->blend_trick_foot * 0.2f; + kf_foot_r->co[0] -= state->blend_trick_foot * 0.15f; } @@ -3095,7 +3109,8 @@ VG_STATIC void player__skate_animate( player_instance *player, *kf_hand_r = &dest->pose[av->id_ik_hand_r-1]; float warble = perlin1d( vg.time, 2.0f, 2, 300 ); - warble *= vg_maxf(s->blend_grind,fabsf(s->blend_weight)) * 0.3f; + warble *= vg_maxf(state->blend_grind, + fabsf(state->blend_weight)) * 0.3f; v4f qrot; q_axis_angle( qrot, (v3f){0.8f,0.7f,0.6f}, warble ); @@ -3170,30 +3185,30 @@ VG_STATIC void player__skate_post_animate( player_instance *player ) s->state.head_position ); } -VG_STATIC void player__skate_reset_animator( player_instance *player ) -{ +VG_STATIC void player__skate_reset_animator( player_instance *player ){ struct player_skate *s = &player->_skate; + struct player_skate_state *state = &s->state; if( s->state.activity <= k_skate_activity_air_to_grind ) - s->blend_fly = 1.0f; + state->blend_fly = 1.0f; else - s->blend_fly = 0.0f; - - s->blend_slide = 0.0f; - s->blend_z = 0.0f; - s->blend_x = 0.0f; - s->blend_grind = 0.0f; - s->blend_grind_balance = 0.0f; - s->blend_stand = 0.0f; - s->blend_push = 0.0f; - s->blend_jump = 0.0f; - s->blend_airdir = 0.0f; - s->blend_weight = 0.0f; - s->subslap = 0.0f; - v2_zero( s->wobble ); - - v3_zero( s->board_trick_residuald ); - v3_zero( s->board_trick_residualv ); + state->blend_fly = 0.0f; + + state->blend_slide = 0.0f; + state->blend_z = 0.0f; + state->blend_x = 0.0f; + state->blend_grind = 0.0f; + state->blend_grind_balance = 0.0f; + state->blend_stand = 0.0f; + state->blend_push = 0.0f; + state->blend_jump = 0.0f; + state->blend_airdir = 0.0f; + state->blend_weight = 0.0f; + state->subslap = 0.0f; + v2_zero( state->wobble ); + + v3_zero( state->board_trick_residuald ); + v3_zero( state->board_trick_residualv ); v3_zero( s->truckv0[0] ); v3_zero( s->truckv0[1] ); } @@ -3227,8 +3242,8 @@ VG_STATIC void player__skate_clear_mechanics( player_instance *player ) v3_zero( s->state.trick_vel ); v3_zero( s->state.trick_euler ); v3_zero( s->state.cog_v ); - s->grind_cooldown = 0; - s->surface_cooldown = 0; + s->state.grind_cooldown = 0; + s->state.surface_cooldown = 0; v3_muladds( player->rb.co, player->rb.to_world[1], 1.0f, s->state.cog ); v3_copy( player->rb.to_world[1], s->state.up_dir ); v3_copy( player->rb.to_world[1], s->surface_picture ); @@ -3253,10 +3268,4 @@ VG_STATIC void player__skate_reset( player_instance *player, s->state.head_position[1] = 1.8f; } -VG_STATIC void player__skate_restore( player_instance *player ) -{ - struct player_skate *s = &player->_skate; - s->state = s->state_gate_storage; -} - #endif /* PLAYER_SKATE_C */ diff --git a/player_skate.h b/player_skate.h index 9fbc563..c3ec0e6 100644 --- a/player_skate.h +++ b/player_skate.h @@ -24,8 +24,10 @@ struct player_skate{ activity, activity_prev; - f32 reverse, slip, delayed_slip_dir; + u32 grind_cooldown, + surface_cooldown; + f32 reverse, slip, delayed_slip_dir; int manual_direction; /* tricks */ @@ -70,37 +72,37 @@ struct player_skate{ air_init_co; v4f smoothed_rotation; + + /* animator controls which require persistence */ + v3f board_trick_residualv, + board_trick_residuald; + f32 blend_slide, + blend_z, + blend_x, + blend_fly, + blend_grind, + blend_grind_balance, + blend_stand, + blend_push, + blend_jump, + blend_airdir, + blend_weight, + blend_trick_foot, + subslap; + v2f wobble; } - state, - state_gate_storage; + state; - /* animation /audio */ + /* animation /audio + * --------------------------------------------------------------*/ struct skeleton_anim *anim_stand, *anim_highg, *anim_slide, *anim_air, *anim_grind, *anim_grind_jump, *anim_push, *anim_push_reverse, *anim_ollie, *anim_ollie_reverse, *anim_grabs, *anim_stop; - v3f - board_trick_residualv, - board_trick_residuald; - - float blend_slide, - blend_z, - blend_x, - blend_fly, - blend_grind, - blend_grind_balance, - blend_stand, - blend_push, - blend_jump, - blend_airdir, - blend_weight, - blend_trick_foot, - subslap; /* vectors representing the direction of the axels in localspace */ v3f truckv0[2]; - v2f wobble; audio_channel *aud_main, *aud_slide, *aud_air; enum mdl_surface_prop surface, audio_surface; @@ -116,7 +118,6 @@ struct player_skate{ k_skate_sample_metal_scrape_generic } main_sample_type; - player_pose holdout; /* @@ -124,8 +125,7 @@ struct player_skate{ * ---------------------------------------------------- */ - float substep, - substep_delta; + float substep, substep_delta; struct jump_info{ v3f log[50]; @@ -160,11 +160,7 @@ struct player_skate{ grind_vec, grind_dir; - u32 grind_cooldown, - surface_cooldown; - float grind_strength; - struct grind_limit{ v3f ra, n; float p; diff --git a/player_walk.c b/player_walk.c index dea80e5..21390c2 100644 --- a/player_walk.c +++ b/player_walk.c @@ -88,7 +88,7 @@ VG_STATIC void player_walk_drop_in_to_skate( player_instance *player ) v3_muladds( player->rb.co, player->rb.to_world[1], 1.0f, s->state.cog ); v3_copy( init_velocity, s->state.cog_v ); v3_copy( init_velocity, player->rb.v ); - v3_copy( init_velocity, player->cam_velocity_smooth ); + v3_copy( init_velocity, player->cam_control.cam_velocity_smooth ); v3_copy( (v3f){1.0f,0.0f,0.0f}, s->state.trick_euler ); } diff --git a/skaterift.c b/skaterift.c index cbefd25..3fec7e0 100644 --- a/skaterift.c +++ b/skaterift.c @@ -294,8 +294,7 @@ VG_STATIC void vg_update_fixed(void) vehicle_update_fixed(); } -VG_STATIC void vg_update_post(void) -{ +VG_STATIC void vg_update_post(void){ if( skaterift.op == k_async_op_clientloading ) return; player__post_update( &localplayer ); @@ -321,7 +320,11 @@ VG_STATIC void vg_update_post(void) v3_copy( localplayer.rb.v, vg_audio.external_lister_velocity ); audio_unlock(); - vg.time_rate = 1.0f-menu.factive; + f32 target = 1.0f-(f32)(menu.active||k_replay_test); + skaterift.time_rate = vg_lerpf( skaterift.time_rate, target, + vg.time_frame_delta * 6.0f ); + + vg.time_rate = skaterift.time_rate; vehicle_update_post(); } @@ -351,9 +354,12 @@ VG_STATIC void present_view_with_post_processing(void) (vg.time_frame_delta*60.0) ); shader_blitblur_uInverseRatio( inverse ); - v2f menu_blurring; - v2_muls( (v2f){ 0.04f, 0.001f }, menu.factive, menu_blurring ); - shader_blitblur_uOverrideDir( menu_blurring ); + v2f override; + if( menu.active ) + v2_muls( (v2f){ 0.04f, 0.001f }, 1.0f-skaterift.time_rate, override ); + else + v2_zero( override ); + shader_blitblur_uOverrideDir( override ); render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); render_fb_bind_texture( gpipeline.fb_main, 1, 1 ); diff --git a/skaterift.h b/skaterift.h index 2366203..aee794e 100644 --- a/skaterift.h +++ b/skaterift.h @@ -24,8 +24,10 @@ struct{ k_async_op_write_savedata, } op; + + f32 time_rate; } -static skaterift = { .op = k_async_op_clientloading }; +static skaterift = { .op = k_async_op_clientloading, .time_rate = 1.0f }; /* Skaterift api */ static void skaterift_change_world_start( void ); -- 2.25.1