oneshot synchronization
authorhgn <hgodden00@gmail.com>
Wed, 4 Oct 2023 10:38:22 +0000 (11:38 +0100)
committerhgn <hgodden00@gmail.com>
Wed, 4 Oct 2023 10:38:22 +0000 (11:38 +0100)
player_remote.c
player_remote.h
skaterift.c

index 3e78d506488a3f7603c71d5b2d7b3a7c2851cc55..9a753944e899c19189f768d4d69ac7da85cf76ed 100644 (file)
@@ -166,10 +166,33 @@ static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){
        * -------------------------------------------------------------*/
       
       for( u32 i=0; i<frame->sound_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; j<NETWORK_SFX_QUEUE_LENGTH; j ++ ){
+               struct net_sfx *sj = &netplayers.sfx_queue[j];
+               if( sj->system == 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; i<NETWORK_SFX_QUEUE_LENGTH; i ++ ){
+      netplayers.sfx_queue[i].system = k_player_subsystem_invalid;
+   }
+}
+
+static void remote_sfx_pre_update(void){
+   for( u32 i=0; i<NETWORK_SFX_QUEUE_LENGTH; i ++ ){
+      struct net_sfx *si = &netplayers.sfx_queue[i];
+
+      if( si->system != 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;
+         }
+      }
+   }
+}
index a35e22ce1f0e897c032ab12259195dcf2927dfd6..de3c7a297fe2a20d7f4b26e6b62abb1e4d073eae 100644 (file)
@@ -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 ];
index b07eadb318ec7488816f3573830ade349bae2636..73dd44e04cf88a9d86486e812ab082f05c0cb9a3 100644 (file)
@@ -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 );