From: hgn Date: Sun, 1 Oct 2023 05:38:36 +0000 (+0100) Subject: remote items test X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=730f202673d6ceb2a5199cf244d5c0bddc064fcf;p=carveJwlIkooP6JGAAIwe30JlM.git remote items test --- diff --git a/addon.c b/addon.c index c387edd..4ac9f91 100644 --- a/addon.c +++ b/addon.c @@ -718,7 +718,7 @@ static u16 addon_cache_create_viewer( enum addon_type type, u16 reg_id ){ static u16 addon_cache_create_viewer_from_uid( enum addon_type type, char uid[ADDON_UID_MAX] ){ addon_alias q; - addon_uid_to_alias( uid, &q ); + if( !addon_uid_to_alias( uid, &q ) ) return 0; if( q.type != type ) return 0; u32 reg_id = addon_match( &q ); diff --git a/addon.h b/addon.h index 2b9d9ac..384c9d7 100644 --- a/addon.h +++ b/addon.h @@ -1,14 +1,6 @@ #ifndef ADDON_H #define ADDON_H -#define ADDON_FOLDERNAME_MAX 64 - -/* total count that we have knowledge of */ -#define ADDON_MOUNTED_MAX 128 -#define ADDON_UID_MAX 76 - -#ifndef ADDON_DEFINE_ONLY - #include "skaterift.h" #include "vg/vg_steam_ugc.h" #include "addon_types.h" @@ -104,5 +96,4 @@ static void addon_cache_unwatch( enum addon_type type, u16 cache_id ); static u16 addon_cache_create_viewer_from_uid( enum addon_type type, char uid[ADDON_UID_MAX] ); -#endif #endif /* ADDON_H */ diff --git a/addon_types.h b/addon_types.h index fa8ab96..b916dd0 100644 --- a/addon_types.h +++ b/addon_types.h @@ -9,6 +9,12 @@ enum addon_type{ k_addon_type_max }; +#define ADDON_FOLDERNAME_MAX 64 + +/* total count that we have knowledge of */ +#define ADDON_MOUNTED_MAX 128 +#define ADDON_UID_MAX 76 + #ifdef VG_GAME #include "vg/vg_stdint.h" @@ -25,12 +31,12 @@ static addon_type_infos[] = { [k_addon_type_board] = { .local_content_folder = "boards/", .cache_stride = sizeof(struct player_board), - .cache_count = 10 + .cache_count = 20 }, [k_addon_type_player] = { .local_content_folder = "playermodels/", .cache_stride = sizeof(struct player_model), - .cache_count = 10 + .cache_count = 20 }, [k_addon_type_world] = { .local_content_folder = "maps/" diff --git a/ent_skateshop.c b/ent_skateshop.c index a4cfe22..957c250 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -15,6 +15,7 @@ #include "steam.h" #include "addon.h" #include "save.h" +#include "network.h" /* * Checks string equality but does a hash check first @@ -74,11 +75,30 @@ static void board_scan_thread( void *_args ){ board_processview_thread(NULL); } +/* TODO: migrate to addon.c */ static void skateshop_op_board_scan(void){ vg_loader_start( board_scan_thread, NULL ); } -static void skateshop_op_processview(void){ +/* TODO: migrate to addon.c */ +static void skateshop_autostart_loading(void){ + if( !vg_loader_availible() ) return; + + SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + for( u32 type=0; typepool.count; id++ ){ + addon_cache_entry *entry = vg_pool_item( &cache->pool, id ); + if( entry->state == k_addon_cache_state_load_request ){ + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + goto launch; + } + } + } + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + return; +launch: vg_loader_start( board_processview_thread, NULL ); } @@ -232,7 +252,7 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ if( opage != npage ){ skateshop_update_viewpage(); - skateshop_op_processview(); + //skateshop_op_processview(); } else if( cache_id && button_down( k_srbind_maccept )){ vg_info( "chose board from skateshop (%u)\n", @@ -241,6 +261,7 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ addon_cache_unwatch( k_addon_type_board, localplayer.board_view_slot ); addon_cache_watch( k_addon_type_board, cache_id ); localplayer.board_view_slot = cache_id; + network_send_item( k_addon_type_board ); world_entity_unfocus(); skaterift_autosave(1); @@ -282,10 +303,11 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ if( changed ){ player__use_model( global_skateshop.selected_player_id ); - skateshop_op_processview(); + //skateshop_op_processview(); } if( button_down( k_srbind_maccept ) ){ + network_send_item( k_addon_type_player ); world_entity_unfocus(); } } @@ -308,8 +330,7 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ if( browseable ){ if( button_down( k_srbind_mleft ) ){ - if( global_skateshop.selected_world_id > 0 ) - { + if( global_skateshop.selected_world_id > 0 ){ global_skateshop.selected_world_id --; change = 1; } @@ -368,6 +389,9 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ } if( button_down( k_srbind_mback ) ){ + if( shop->type == k_skateshop_type_charshop ) + network_send_item( k_addon_type_player ); + world_entity_unfocus(); return; } diff --git a/gameserver.c b/gameserver.c index 5ed5612..abd5aaa 100644 --- a/gameserver.c +++ b/gameserver.c @@ -60,10 +60,14 @@ static void gameserver_player_join( int index ){ /* update the joining user about current connections */ - netmsg_playerusername *username = alloca( sizeof(netmsg_playerusername) + - NETWORK_USERNAME_MAX ); + netmsg_playerusername *username = + alloca( sizeof(netmsg_playerusername) + NETWORK_USERNAME_MAX ); username->inetmsg_id = k_inetmsg_playerusername; + netmsg_playeritem *item = + alloca( sizeof(netmsg_playeritem) + ADDON_UID_MAX ); + item->inetmsg_id = k_inetmsg_playeritem; + for( int i=0; iconnection, username, size, k_nSteamNetworkingSend_Reliable, NULL ); + + /* items */ + chs = vg_strncpy( client->item_player, item->uid, ADDON_UID_MAX, + k_strncpy_always_add_null ); + item->type = k_addon_type_player; + size = sizeof(netmsg_playeritem) + chs + 1; + SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( + hSteamNetworkingSockets, joiner->connection, + item, size, k_nSteamNetworkingSend_Reliable, NULL ); + + chs = vg_strncpy( client->item_board, item->uid, ADDON_UID_MAX, + k_strncpy_always_add_null ); + item->type = k_addon_type_board; + size = sizeof(netmsg_playeritem) + chs + 1; + SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( + hSteamNetworkingSockets, joiner->connection, + item, size, k_nSteamNetworkingSend_Reliable, NULL ); } } @@ -337,13 +358,23 @@ static void gameserver_rx_200_300( SteamNetworkingMessage_t *msg ){ } else if( tmp->inetmsg_id == k_inetmsg_playerframe ){ /* propogate */ - netmsg_playerframe *frame = alloca(msg->m_cbSize); memcpy( frame, msg->m_pData, msg->m_cbSize ); frame->client = client_id; gameserver_send_to_all( client_id, frame, msg->m_cbSize, k_nSteamNetworkingSend_Unreliable ); } + else if( tmp->inetmsg_id == k_inetmsg_playeritem ){ + netmsg_playeritem *item = alloca(msg->m_cbSize); + memcpy( item, msg->m_pData, msg->m_cbSize ); + item->client = client_id; + + vg_info( "Client #%u equiped: [%u] %s\n", + item->client, item->type, item->uid ); + + gameserver_send_to_all( client_id, item, msg->m_cbSize, + k_nSteamNetworkingSend_Reliable ); + } } #if 0 diff --git a/gameserver.h b/gameserver.h index a3aa574..26099a6 100644 --- a/gameserver.h +++ b/gameserver.h @@ -21,6 +21,8 @@ struct { int authenticated; HSteamNetConnection connection; char username[ NETWORK_USERNAME_MAX ]; + + char item_board[ ADDON_UID_MAX ], item_player[ ADDON_UID_MAX ]; } clients[ 32 ]; diff --git a/network.c b/network.c index 53ebd4b..4768ece 100644 --- a/network.c +++ b/network.c @@ -147,6 +147,40 @@ static void network_send_username(void){ k_nSteamNetworkingSend_Reliable, NULL ); } +static void network_send_item( enum addon_type type ){ + if( network_client.remote ){ + u16 id = 0; + if( type == k_addon_type_board ) + id = localplayer.board_view_slot; + else if( type == k_addon_type_player ) + id = localplayer.playermodel_view_slot; + + struct addon_cache *cache = &addon_system.cache[type]; + vg_pool *pool = &cache->pool; + + netmsg_playeritem *item = + alloca( sizeof(netmsg_playeritem) + ADDON_UID_MAX ); + item->inetmsg_id = k_inetmsg_playeritem; + item->type = type; + item->client = 0; + + SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + addon_cache_entry *entry = vg_pool_item( pool, id ); + addon_alias_uid( &entry->reg_ptr->alias, item->uid ); + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + + vg_info( "send equip: [%u] %s\n", + item->type, item->uid ); + + u32 chs = strlen(item->uid); + + SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( + hSteamNetworkingSockets, network_client.remote, + item, sizeof(netmsg_playeritem)+chs+1, + k_nSteamNetworkingSend_Reliable, NULL ); + } +} + static void network_disconnect(void){ SteamAPI_ISteamNetworkingSockets_CloseConnection( hSteamNetworkingSockets, network_client.remote, 0, NULL, 0 ); @@ -185,6 +219,8 @@ static void on_server_connect_status( CallbackMsg_t *msg ){ k_nSteamNetworkingSend_Reliable, NULL ); network_send_username(); + network_send_item( k_addon_type_board ); + network_send_item( k_addon_type_player ); } else if( info->m_info.m_eState == k_ESteamNetworkingConnectionState_ClosedByPeer ){ diff --git a/network.h b/network.h index bb019fb..de64d44 100644 --- a/network.h +++ b/network.h @@ -10,6 +10,7 @@ #include "steam.h" #include "network_msg.h" #include "highscores.h" +#include "addon_types.h" static int network_scores_updated = 0; @@ -57,5 +58,6 @@ static network_client = { }; static int packet_minsize( SteamNetworkingMessage_t *msg, u32 size ); +static void network_send_item( enum addon_type type ); #endif /* NETWORK_H */ diff --git a/network_common.h b/network_common.h index 404c000..59d08bd 100644 --- a/network_common.h +++ b/network_common.h @@ -6,9 +6,7 @@ #define NETWORK_USERNAME_MAX 32 -#define ADDON_DEFINE_ONLY - #include "addon.h" -#undef ADDON_DEFINE_ONLY +#include "addon_types.h" static u32 network_msgstring( const char *src, u32 m_cbSize, u32 base_size, diff --git a/network_msg.h b/network_msg.h index 440facd..4490502 100644 --- a/network_msg.h +++ b/network_msg.h @@ -122,7 +122,7 @@ typedef struct netmsg_playeritem netmsg_playeritem; enum{ k_inetmsg_playeritem = 204 }; struct netmsg_playeritem{ u32 inetmsg_id; - u32 index; + u32 client; u8 type; char uid[]; }; diff --git a/player.c b/player.c index 1cd1bec..c478305 100644 --- a/player.c +++ b/player.c @@ -8,6 +8,7 @@ #include "world.h" #include "audio.h" #include "player_replay.h" +#include "network.h" static int localplayer_cmd_respawn( int argc, const char *argv[] ){ ent_spawn *rp = NULL, *r; @@ -163,23 +164,6 @@ static void player_apply_transport_to_cam( m4x3f transport ){ m4x4_mul( world_gates.cam.mtx.v, transport_4, world_gates.cam.mtx.v ); } -#if 0 -__attribute__ ((deprecated)) -static void gate_rotate_angles( ent_gate *gate, v3f angles, v3f d ) -{ - v3_copy( angles, d ); - return; - - v3f fwd_dir = { cosf(angles[0]), - 0.0f, - sinf(angles[0])}; - m3x3_mulv( gate->transport, fwd_dir, fwd_dir ); - - v3_copy( angles, d ); - d[0] = atan2f( fwd_dir[2], fwd_dir[0] ); -} -#endif - static void player__im_gui(void){ if( !k_player_debug_info ) return; diff --git a/player_remote.c b/player_remote.c index b51c857..3d674bc 100644 --- a/player_remote.c +++ b/player_remote.c @@ -2,6 +2,7 @@ #include "skeleton.h" #include "player_render.h" #include "network_common.h" +#include "addon.h" static void player_remote_unwatch( struct network_player *player ){ addon_cache_unwatch( k_addon_type_player, player->playermodel_view_slot ); @@ -126,6 +127,31 @@ static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){ player->subsystem = frame->subsystem; player->down_bytes += msg->m_cbSize; } + else if( tmp->inetmsg_id == k_inetmsg_playeritem ){ + netmsg_playeritem *item = msg->m_pData; + if( !packet_minsize( msg, sizeof(*item)+1 )) return; + + vg_info( "Client #%u equiped: [%u] %s\n", + item->client, item->type, item->uid ); + + struct network_player *player = &netplayers.list[ item->client ]; + + 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 ){ + 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 ){ + 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 ); + } + } } /* @@ -366,14 +392,35 @@ static void animate_remote_players(void){ * 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; iactive ) 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 ); - struct player_model *model = &localplayer.fallback_model; - render_playermodel( cam, world, 0, model, &av->sk, - &netplayers.final_mtx[ av->sk.bone_count*i ] ); + /* TODO: Board pose */ +#if 0 + render_board( cam, world, board, + final_mtx[localplayer.playeravatar->id_board], + &localplayer.pose.board, + k_board_shader_player ); +#endif } + + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); } diff --git a/skaterift.c b/skaterift.c index fc537ce..f089f79 100644 --- a/skaterift.c +++ b/skaterift.c @@ -282,7 +282,7 @@ static void vg_load(void){ skaterift_restore_state(); vg_loader_step( NULL, skaterift_autosave_synchronous ); - board_processview_thread(NULL); + //board_processview_thread(NULL); vg_async_call( async_call_ready, NULL, 0 ); } @@ -307,6 +307,7 @@ static void vg_pre_update(void){ skaterift_change_client_world_preupdate(); draw_origin_axis(); + skateshop_autostart_loading(); network_update(); /* time rate */