X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_remote.c;h=62eed5a3c62b9cd115c9486a6a5d88ad913e9f08;hb=074fa69f479724f9800849430bad5caf730b01ef;hp=6b66656a078ef995b1f810ad3b9eca00c244af72;hpb=9b4f4aa9105cd7458d6e7dbc859cb72d0add1300;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_remote.c b/player_remote.c index 6b66656..62eed5a 100644 --- a/player_remote.c +++ b/player_remote.c @@ -16,6 +16,47 @@ static void player_remote_clear( struct network_player *player ){ player->subsystem = k_player_subsystem_invalid; } +/* + * re-attatches addon_reg pointers on the remote client if we have the same + * world loaded. + */ +static void relink_remote_player_worlds( u32 client_id ){ + struct network_player *player = &netplayers.list[client_id]; + + player->hub_match = 0; + player->client_match = 0; + + addon_alias q0,q1; + addon_uid_to_alias( player->items[k_netmsg_playeritem_world0], &q0 ); + addon_uid_to_alias( player->items[k_netmsg_playeritem_world1], &q1 ); + + /* + * currently in 10.23, the hub world will always be the same. + * this might but probably wont change in the future + */ + if( world_static.addon_hub ) + if( addon_alias_eq( &q0, &world_static.addon_hub->alias ) ) + player->hub_match = 1; + + if( world_static.addon_client ) + if( addon_alias_eq( &q1, &world_static.addon_client->alias ) ) + player->client_match = 1; +} + +/* + * re-attatches addon_reg pointers on the remote client if we have the mod + * installed locally. + * + * Run if local worlds change + */ +static void relink_all_remote_player_worlds(void){ + for( u32 i=0; iactive ) + relink_remote_player_worlds(i); + } +} + static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){ netmsg_blank *tmp = msg->m_pData; @@ -31,13 +72,6 @@ static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){ /* TODO: interpret the uids */ player->board_view_slot = 0; player->playermodel_view_slot = 0; -#if 0 - addon_cache_create_viewer_from_uid( k_addon_type_board, - playerjoin->board_uid ); - player->playermodel_view_slot = - addon_cache_create_viewer_from_uid( k_addon_type_player, - playerjoin->playermodel_uid ); -#endif struct interp_buffer *buf = &netplayers.interp_data[playerjoin->index]; buf->t = -99999999.9; @@ -122,6 +156,8 @@ static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){ dest->active = 1; dest->timestamp = frame->timestamp; dest->subsystem = frame->subsystem; + dest->instance_id = frame->instance_id; + dest->boundary_hash = frame->boundary_hash; struct network_player *player = &netplayers.list[ frame->client ]; memcpy( &dest->data, frame->animdata, datasize ); @@ -137,26 +173,33 @@ static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){ return; } - vg_info( "Client #%u equiped: [%u] %s\n", - item->client, item->type, item->uid ); + if( item->type_index >= k_netmsg_playeritem_max ){ + vg_warn( "Client #%d invalid equip type %u\n", + (i32)item->client, (u32)item->type_index ); + return; + } struct network_player *player = &netplayers.list[ item->client ]; + char *uid = player->items[ item->type_index ]; - char uid[ ADDON_UID_MAX ]; network_msgstring( item->uid, msg->m_cbSize, sizeof(*item), uid, ADDON_UID_MAX ); - if( item->type == k_addon_type_board ){ + if( item->type_index == k_netmsg_playeritem_board ){ addon_cache_unwatch( k_addon_type_board, player->board_view_slot ); player->board_view_slot = addon_cache_create_viewer_from_uid( k_addon_type_board, uid ); } - else if( item->type == k_addon_type_player ){ + else if( item->type_index == k_netmsg_playeritem_player ){ addon_cache_unwatch( k_addon_type_player, player->playermodel_view_slot ); player->playermodel_view_slot = addon_cache_create_viewer_from_uid( k_addon_type_player, uid ); } + else if( (item->type_index == k_netmsg_playeritem_world0) || + (item->type_index == k_netmsg_playeritem_world1) ){ + relink_remote_player_worlds( item->client ); + } } } @@ -173,9 +216,12 @@ static void remote_player_send_playerframe(void){ u32 size = sizeof(netmsg_playerframe)+sys->animator_size; netmsg_playerframe *frame = alloca(size); frame->inetmsg_id = k_inetmsg_playerframe; - frame->client = 0; + frame->client = 0xff; frame->subsystem = localplayer.subsystem; frame->timestamp = vg.time_real; + frame->boundary_hash = localplayer.boundary_hash; + frame->instance_id = world_static.active_instance; + memcpy( frame->animdata, sys->animator_data, sys->animator_size ); netplayers.up_bytes += size; @@ -303,18 +349,21 @@ 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; - struct skeleton *sk = &localplayer.playeravatar->sk; 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 ); @@ -322,11 +371,38 @@ static void pose_remote_player( u32 index, 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 ]; + } } } @@ -366,7 +442,10 @@ static void animate_remote_player( u32 index ){ abs_max_frame = ifr; } } - } + } + + struct network_player *player = &netplayers.list[ index ]; + player->active_world = NULL; if( minframe && maxframe ){ pose_remote_player( index, minframe, maxframe ); @@ -401,9 +480,10 @@ static void render_remote_players( world_instance *world, camera *cam ){ SDL_AtomicLock( &addon_system.sl_cache_using_resources ); - for( u32 i=0; iactive ) continue; + if( player->active_world != world ) continue; struct player_avatar *av = localplayer.playeravatar; m4x3f *final_mtx = &netplayers.final_mtx[ av->sk.bone_count*i ]; @@ -418,15 +498,15 @@ static void render_remote_players( world_instance *world, camera *cam ){ struct player_board *board = addon_cache_item_if_loaded( k_addon_type_board, player->board_view_slot ); - - /* TODO: Board pose */ -#if 0 render_board( cam, world, board, final_mtx[localplayer.playeravatar->id_board], - &localplayer.pose.board, + &netplayers.board_poses[ i ], k_board_shader_player ); -#endif } SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); } + +/* TODO: Which world is the player in + * nametags with occlusion + */