+
+/*
+ * write the remote players final_mtx
+ */
+static void pose_remote_player( u32 index,
+ struct interp_frame *f0,
+ struct interp_frame *f1 ){
+
+ struct network_player *player = &netplayers.list[ index ];
+
+ struct interp_buffer *buf = &netplayers.interp_data[ index ];
+ struct player_avatar *av = localplayer.playeravatar;
+ m4x3f *final_mtx = &netplayers.final_mtx[ av->sk.bone_count*index ];
+ struct player_board_pose *board_pose = &netplayers.board_poses[index];
+
+ struct player_subsystem_interface *sys0 = player_subsystems[f0->subsystem],
+ *sys1 = NULL;
+
+ player_pose pose0, pose1, posed;
+ sys0->pose( &f0->data, &pose0 );
+
+ u8 instance_id = 0;
+
+ if( f1 ){
+ f32 t = (buf->t - f0->timestamp) / (f1->timestamp - f0->timestamp);
+ t = vg_clampf( t, 0.0f, 1.0f );
+
+ sys1 = player_subsystems[f1->subsystem];
+ sys1->pose( &f1->data, &pose1 );
+
+ u16 bounds = f0->boundary_hash^f1->boundary_hash;
+
+ if( bounds & NETMSG_BOUNDARY_BIT )
+ t = 1.0f;
+
+ if( bounds & NETMSG_GATE_BOUNDARY_BIT ){
+ /* TODO: Extra work retransforming the root_co, instance_id.. etc */
+ t = 1.0f;
+ }
+
+ instance_id = f1->instance_id;
+
+ lerp_player_pose( &pose0, &pose1, t, &posed );
+ apply_full_skeleton_pose( &av->sk, &posed, final_mtx );
+ memcpy( board_pose, &posed.board, sizeof(*board_pose) );
+ }
+ else {
+ instance_id = f0->instance_id;
+
+ apply_full_skeleton_pose( &av->sk, &pose0, final_mtx );
+ memcpy( board_pose, &pose0.board, sizeof(*board_pose) );
+ }
+
+ if( instance_id ){
+ if( player->client_match ){
+ player->active_world = &world_static.instances[ instance_id ];
+ }
+ }
+ else{
+ if( player->hub_match ){
+ player->active_world = &world_static.instances[ instance_id ];
+ }
+ }
+}
+
+/*
+ * animate remote player and store in final_mtx
+ */
+static void animate_remote_player( u32 index ){
+
+ /*
+ * Trys to keep the cursor inside the buffer
+ */
+ f64 min_time = -999999999.9,
+ max_time = 999999999.9,
+ abs_max_time = -999999999.9;
+
+ struct interp_frame *minframe = NULL,
+ *maxframe = NULL,
+ *abs_max_frame = NULL;
+
+ struct interp_buffer *buf = &netplayers.interp_data[index];
+ for( u32 i=0; i<vg_list_size(buf->frames); i ++ ){
+ struct interp_frame *ifr = &buf->frames[i];
+
+ if( ifr->active ){
+ if( (ifr->timestamp > min_time) && (ifr->timestamp < buf->t) ){
+ min_time = ifr->timestamp;
+ minframe = ifr;
+ }
+
+ if( (ifr->timestamp < max_time) && (ifr->timestamp > buf->t) ){
+ max_time = ifr->timestamp;
+ maxframe = ifr;
+ }
+
+ if( ifr->timestamp > abs_max_time ){
+ abs_max_time = ifr->timestamp;
+ abs_max_frame = ifr;
+ }
+ }
+ }
+
+ struct network_player *player = &netplayers.list[ index ];
+ player->active_world = NULL;
+
+ if( minframe && maxframe ){
+ pose_remote_player( index, minframe, maxframe );
+ buf->t += vg.time_frame_delta;
+ }
+ else {
+ buf->t = abs_max_time - 0.25;
+
+ if( abs_max_frame )
+ pose_remote_player( index, abs_max_frame, NULL );
+ else
+ return;
+ }
+}
+
+/*
+ * Update full final_mtx for all remote players
+ */
+static void animate_remote_players(void){
+ for( u32 i=0; i<vg_list_size(netplayers.list); i ++ ){
+ struct network_player *player = &netplayers.list[i];
+ if( !player->active ) continue;
+
+ animate_remote_player( i );
+ }
+}
+
+/*
+ * Draw remote players
+ */
+static void render_remote_players( world_instance *world, camera *cam ){
+
+ SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+
+ for( u32 i=0; i<NETWORK_MAX_PLAYERS; i ++ ){
+ struct network_player *player = &netplayers.list[i];
+ if( !player->active ) continue;
+ if( player->active_world != world ) continue;
+
+ struct player_avatar *av = localplayer.playeravatar;
+ m4x3f *final_mtx = &netplayers.final_mtx[ av->sk.bone_count*i ];
+
+ struct player_model *model =
+ addon_cache_item_if_loaded( k_addon_type_player,
+ player->playermodel_view_slot );
+
+ if( !model ) model = &localplayer.fallback_model;
+ render_playermodel( cam, world, 0, model, &av->sk, final_mtx );
+
+ struct player_board *board =
+ addon_cache_item_if_loaded( k_addon_type_board,
+ player->board_view_slot );
+ render_board( cam, world, board,
+ final_mtx[localplayer.playeravatar->id_board],
+ &netplayers.board_poses[ i ],
+ k_board_shader_player );
+ }
+
+ SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+}
+
+/* TODO: Which world is the player in
+ * nametags with occlusion
+ */