From d5f400a06400d5322330cfdbb97a661707b3d150 Mon Sep 17 00:00:00 2001 From: hgn Date: Wed, 4 Oct 2023 11:38:22 +0100 Subject: [PATCH] oneshot synchronization --- player_remote.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- player_remote.h | 1 - skaterift.c | 2 ++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/player_remote.c b/player_remote.c index 3e78d50..9a75394 100644 --- a/player_remote.c +++ b/player_remote.c @@ -166,10 +166,33 @@ static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){ * -------------------------------------------------------------*/ for( u32 i=0; isound_effects; i ++ ){ - /* CHEATING for now */ struct net_sfx sfx; net_sfx_exchange( &ctx, &sfx ); - net_sfx_play( &sfx ); + + f64 t = (frame->timestamp - NETWORK_FRAMERATE) + + (sfx.subframe*NETWORK_FRAMERATE); + + f32 remaining = t - ib->t; + + if( remaining <= 0.0f ) + net_sfx_play( &sfx ); + else{ + struct net_sfx *dst = NULL; + + for( u32 j=0; jsystem == k_player_subsystem_invalid ){ + dst = sj; + break; + } + + if( sj->priority < sfx.priority ) + dst = sj; + } + + *dst = sfx; + dst->subframe = remaining; + } } /* animation @@ -568,6 +591,22 @@ static void render_remote_players( world_instance *world, camera *cam ){ SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); } -/* TODO: Which world is the player in - * nametags with occlusion - */ +static void remote_players_init(void){ + for( u32 i=0; isystem != k_player_subsystem_invalid ){ + si->subframe -= vg.time_frame_delta; + if( si->subframe <= 0.0f ){ + net_sfx_play( si ); + si->system = k_player_subsystem_invalid; + } + } + } +} diff --git a/player_remote.h b/player_remote.h index a35e22c..de3c7a2 100644 --- a/player_remote.h +++ b/player_remote.h @@ -50,7 +50,6 @@ struct { interp_data[ NETWORK_MAX_PLAYERS ]; struct net_sfx sfx_queue[ NETWORK_SFX_QUEUE_LENGTH ]; - u8 sfx_availible[ NETWORK_SFX_QUEUE_LENGTH ]; m4x3f *final_mtx; struct player_board_pose board_poses[ NETWORK_MAX_PLAYERS ]; diff --git a/skaterift.c b/skaterift.c index b07eadb..73dd44e 100644 --- a/skaterift.c +++ b/skaterift.c @@ -111,6 +111,7 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " steam_init(); vg_loader_step( NULL, steam_end ); + vg_loader_step( remote_players_init, NULL ); vg_loader_step( network_init, network_end ); } @@ -351,6 +352,7 @@ static void vg_pre_update(void){ player__pre_update(); world_entity_focus_preupdate(); skaterift_replay_pre_update(); + remote_sfx_pre_update(); world_update( world_current_instance(), localplayer.rb.co ); audio_ambient_sprites_update( world_current_instance(), localplayer.rb.co ); -- 2.25.1