From 7e1fe6c7931ba4492aa10ac5eebc316b74fb5dac Mon Sep 17 00:00:00 2001 From: hgn Date: Mon, 30 Oct 2023 13:40:12 +0000 Subject: [PATCH] remove sub-world concept --- network.c | 6 ++---- network_msg.h | 1 - player.c | 24 ++++++++++-------------- player_remote.c | 36 ++++++++++++++---------------------- player_remote.h | 2 +- save.c | 11 +++++------ world.c | 7 +------ world.h | 17 ++++++++--------- world_load.c | 28 ++++++++++++---------------- world_render.c | 4 ++-- world_routes.c | 13 ++++--------- world_sfd.c | 23 +++-------------------- 12 files changed, 62 insertions(+), 110 deletions(-) diff --git a/network.c b/network.c index 59982b2..b0ae677 100644 --- a/network.c +++ b/network.c @@ -307,10 +307,8 @@ static void network_send_item( enum netmsg_playeritem_type type ){ if( (type == k_netmsg_playeritem_world0) || (type == k_netmsg_playeritem_world1) ){ - addon_reg *reg = world_static.addon_hub; - - if( type == k_netmsg_playeritem_world1 ) - reg = world_static.addon_client; + enum world_purpose purpose = type - k_netmsg_playeritem_world0; + addon_reg *reg = world_static.instance_addons[ purpose ]; if( reg ) addon_alias_uid( ®->alias, item->uid ); diff --git a/network_msg.h b/network_msg.h index ca5557c..2e62521 100644 --- a/network_msg.h +++ b/network_msg.h @@ -130,7 +130,6 @@ struct netmsg_playeritem{ u8 type_index; char uid[]; }; -typedef enum netmsg_playeritem_type netmsg_playeritem_type; enum netmsg_playeritem_type { k_netmsg_playeritem_board = 0, k_netmsg_playeritem_player, diff --git a/player.c b/player.c index 7a31eda..e6b9387 100644 --- a/player.c +++ b/player.c @@ -193,20 +193,16 @@ static void player__im_gui(void){ player__debugtext( 2, "instance #%u", world_static.active_instance ); - char buf_hub[96], - buf_client[96]; - if( world_static.addon_client ) - addon_alias_uid( &world_static.addon_client->alias, buf_client ); - else - strcpy( buf_client, "none" ); - - if( world_static.addon_hub ) - addon_alias_uid( &world_static.addon_hub->alias, buf_hub ); - else - strcpy( buf_hub, "none" ); - - player__debugtext( 1, "hub uid: %s", buf_hub ); - player__debugtext( 1, "client uid: %s", buf_client ); + char buf[96]; + for( u32 i=0; ialias, buf ); + else + strcpy( buf, "none" ); + + player__debugtext( 1, "world #%u: %s", i, buf ); + } + player__debugtext( 2, "director" ); player__debugtext( 1, "activity: %s", (const char *[]){ [k_skaterift_menu] = "menu", diff --git a/player_remote.c b/player_remote.c index b533d38..3b7e6a6 100644 --- a/player_remote.c +++ b/player_remote.c @@ -22,24 +22,24 @@ static void player_remote_clear( struct network_player *player ){ 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 ); + addon_alias q[2]; + addon_uid_to_alias( player->items[k_netmsg_playeritem_world0], &q[0] ); + addon_uid_to_alias( player->items[k_netmsg_playeritem_world1], &q[1] ); /* * 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; + for( u32 i=0; iworld_match[i] = 0; - if( world_static.addon_client ) - if( addon_alias_eq( &q1, &world_static.addon_client->alias ) ) - player->client_match = 1; + if( reg ){ + if( addon_alias_eq( &q[i], &world_static.instance_addons[i]->alias ) ) + player->world_match[i] = 1; + } + } } /* @@ -499,16 +499,8 @@ static void pose_remote_player( u32 index, 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 ]; - } - } + if( player->world_match[ instance_id ] ) + player->active_world = &world_static.instances[ instance_id ]; } /* diff --git a/player_remote.h b/player_remote.h index de3c7a2..021fcf5 100644 --- a/player_remote.h +++ b/player_remote.h @@ -15,7 +15,7 @@ struct { /* this is set IF they exist in a world that we have loaded */ world_instance *active_world; - int hub_match, client_match; + int world_match[ k_world_max ]; /* TODO: Compression with server code */ char username[ NETWORK_USERNAME_MAX ]; diff --git a/save.c b/save.c index a8076c7..90e9c20 100644 --- a/save.c +++ b/save.c @@ -80,9 +80,7 @@ static void skaterift_populate_world_savedata( savedata_file *file, enum world_purpose which ){ file->path[0] = '\0'; file->len = 0; - addon_reg *reg = NULL; - if( which == k_world_purpose_hub ) reg = world_static.addon_hub; - else reg = world_static.addon_client; + addon_reg *reg = world_static.instance_addons[ which ]; if( !reg ){ vg_error( "Tried to save unspecified world (reg was null)\n" ); @@ -127,7 +125,7 @@ static void skaterift_populate_main_savedata( savedata_file *file ){ vg_msg_frame( &sav, "world" ); { - addon_reg *reg = world_static.addon_client; + addon_reg *reg = world_static.instance_addons[ k_world_purpose_client ]; if( reg && (world_static.active_instance > 0) ){ skaterift_write_addon_alias( &sav, "alias", ®->alias ); } @@ -145,7 +143,7 @@ static int skaterift_autosave( int async ){ if( !vg_loader_availible() ) return 0; u32 save_files = 2; - if( world_static.addon_client ) + if( world_static.instance_addons[ k_world_purpose_client ] ) save_files ++; vg_linear_clear( vg_async.buffer ); @@ -163,9 +161,10 @@ static int skaterift_autosave( int async ){ skaterift_populate_main_savedata( &group->files[0] ); skaterift_populate_world_savedata( &group->files[1], k_world_purpose_hub ); - if( world_static.addon_client ) + if( world_static.instance_addons[ k_world_purpose_client ] ){ skaterift_populate_world_savedata( &group->files[2], k_world_purpose_client ); + } if( async ) vg_loader_start( (void *)savedata_group_write, group ); diff --git a/world.c b/world.c index 14200d9..af9466c 100644 --- a/world.c +++ b/world.c @@ -37,11 +37,7 @@ static void world_set_active_instance( u32 index ){ static void skaterift_world_get_save_path( enum world_purpose which, char buf[128] ){ - addon_reg *reg; - - if( which == k_world_purpose_hub ) reg = world_static.addon_hub; - else reg = world_static.addon_client; - + addon_reg *reg = world_static.instance_addons[ which ]; assert( reg ); char id[76]; @@ -49,7 +45,6 @@ static void skaterift_world_get_save_path( enum world_purpose which, snprintf( buf, 128, "savedata/%s.bkv", id ); } - #include "world_entity.c" #include "world_gate.c" #include "world_gen.c" diff --git a/world.h b/world.h index d35f064..76d43d6 100644 --- a/world.h +++ b/world.h @@ -17,10 +17,10 @@ enum world_geo_type{ }; enum world_purpose{ - k_world_purpose_hub, - k_world_purpose_client -} -purpose; + k_world_purpose_hub = 0, + k_world_purpose_client = 1, + k_world_max +}; typedef struct world_instance world_instance; @@ -209,8 +209,10 @@ struct world_static { u32 active_trigger_volumes[8]; u32 active_trigger_volume_count; - world_instance instances[4]; - i32 active_instance; + addon_reg *instance_addons[ k_world_max ]; + world_instance instances[ k_world_max ]; + + enum world_purpose active_instance; u32 focused_entity; /* like skateshop, challenge.. */ f32 focus_strength; camera focus_cam; @@ -219,9 +221,6 @@ struct world_static { ent_objective *challenge_target; f32 challenge_timer; - addon_reg *addon_hub, - *addon_client; - enum world_loader_state{ k_world_loader_none, k_world_loader_preload, diff --git a/world_load.c b/world_load.c index 70ca783..455d30d 100644 --- a/world_load.c +++ b/world_load.c @@ -130,11 +130,9 @@ struct world_load_args { */ static void skaterift_world_load_thread( void *_args ){ struct world_load_args *args = _args; - enum world_purpose purpose = args->purpose; - addon_reg *reg = args->reg; - if( purpose == k_world_purpose_hub ) world_static.addon_hub = reg; - else world_static.addon_client = reg; + addon_reg *reg = args->reg; + world_static.instance_addons[ args->purpose ] = reg; char path_buf[4096]; vg_str path; @@ -149,7 +147,7 @@ static void skaterift_world_load_thread( void *_args ){ return; } - char worlds[3][4096]; + char worlds[k_world_max-1][4096]; u32 i=0; vg_dir dir; @@ -172,7 +170,7 @@ static void skaterift_world_load_thread( void *_args ){ if( !ext ) continue; if( strcmp(ext,".mdl") ) continue; - if( i == 3 ){ + if( i == k_world_max-1 ){ vg_warn( "There are too many .mdl files in the map folder!(3)\n" ); break; } @@ -199,7 +197,7 @@ static void skaterift_world_load_thread( void *_args ){ } u32 instance_start = 0, instance_count = 1; - if( purpose == k_world_purpose_client ) instance_start = 1; + if( args->purpose == k_world_purpose_client ) instance_start = 1; world_instance_load_mdl( instance_start, worlds[first_index] ); @@ -221,7 +219,7 @@ static void skaterift_world_load_thread( void *_args ){ data->instance_start = instance_start; data->instance_count = instance_count; - skaterift_world_get_save_path( purpose, data->save.path ); + skaterift_world_get_save_path( args->purpose, data->save.path ); savedata_file_read( &data->save ); vg_async_dispatch( final_call, skaterift_world_load_done ); @@ -231,7 +229,7 @@ static void skaterift_world_load_thread( void *_args ){ /* holding pattern before we can start loading the new world, since we might be * waiting for audio to stop */ static void skaterift_change_client_world_preupdate(void){ - for( u32 i=1; istatus == k_world_status_unloading ){ @@ -250,7 +248,7 @@ static void skaterift_change_client_world_preupdate(void){ struct world_load_args *args = vg_linear_alloc( vg_async.buffer, sizeof(struct world_load_args) ); args->purpose = k_world_purpose_client; - args->reg = world_static.addon_client; + args->reg = world_static.instance_addons[ k_world_purpose_client ]; /* this is replaces the already correct reg but we have to set it again * TOO BAD */ @@ -265,7 +263,7 @@ static void skaterift_change_world_start( addon_reg *reg ){ if( world_static.active_instance != 0 ) vg_error( "Cannot change worlds while in non-root world\n" ); else{ - if( world_static.addon_client == reg ){ + if( world_static.instance_addons[ k_world_purpose_client ] == reg ){ vg_warn( "World is already loaded\n" ); return; } @@ -290,7 +288,7 @@ static void skaterift_change_world_start( addon_reg *reg ){ } } - world_static.addon_client = reg; + world_static.instance_addons[ k_world_purpose_client ] = reg; network_send_item( k_netmsg_playeritem_world1 ); relink_all_remote_player_worlds(); } @@ -355,8 +353,7 @@ static int world_freeable( world_instance *world ){ /* * Free all resources for world instance */ -static void world_free( world_instance *world ) -{ +static void world_free( world_instance *world ){ vg_info( "Free world @%p\n", world ); /* free meshes */ @@ -395,8 +392,7 @@ static void world_free( world_instance *world ) * reset the world structure without deallocating persistent buffers * TODO: Make this a memset(0), and have persistent items live in a static loc */ -static void world_init_blank( world_instance *world ) -{ +static void world_init_blank( world_instance *world ){ memset( &world->meta, 0, sizeof(mdl_context) ); world->textures = NULL; diff --git a/world_render.c b/world_render.c index 022556d..e6c709a 100644 --- a/world_render.c +++ b/world_render.c @@ -25,7 +25,7 @@ static int ccmd_set_time( int argc, const char *argv[] ){ static void async_world_render_init( void *payload, u32 size ) { vg_info( "Allocate uniform buffers\n" ); - for( int i=0; i<4; i++ ){ + for( int i=0; iubo_bind_point = i; @@ -39,7 +39,7 @@ static void async_world_render_init( void *payload, u32 size ) } vg_info( "Allocate frame buffers\n" ); - for( int i=0; i<4; i++ ){ + for( int i=0; iheightmap; diff --git a/world_routes.c b/world_routes.c index b271faa..87b21c8 100644 --- a/world_routes.c +++ b/world_routes.c @@ -126,14 +126,11 @@ static void world_routes_time_lap( world_instance *world, ent_route *route ) } } - addon_alias *alias = &world_static.addon_hub->alias; - if( world_static.active_instance ) - alias = &world_static.addon_client->alias; + addon_alias *alias = + &world_static.instance_addons[ world_static.active_instance ]->alias; - /* TODO: we should probably generate this once. and also ditch - * sub-worlds */ char mod_uid[ ADDON_UID_MAX ]; - addon_alias_uid( &world_static.addon_client->alias, mod_uid ); + addon_alias_uid( alias, mod_uid ); network_publish_laptime( mod_uid, mdl_pstr( &world->meta, route->pstr_name ), lap_time ); @@ -887,9 +884,7 @@ static void world_gen_routes_generate( u32 instance_id ){ vg_info( "Distributed %u points over %fkm^2!\n", pcbuf->count, area/1e6f ); - world_write_preview( instance_id? world_static.addon_client: - world_static.addon_hub, - pcbuf ); + world_write_preview( world_static.instance_addons[ instance_id ], pcbuf ); vg_async_dispatch( call_pointcloud, async_pointcloud_sub ); } diff --git a/world_sfd.c b/world_sfd.c index b40d57a..9310aee 100644 --- a/world_sfd.c +++ b/world_sfd.c @@ -40,8 +40,7 @@ static f32 sfd_encode_glyph( char c ){ return (float)value; } -static void sfd_encode( u32 row, const char *str ) -{ +static void sfd_encode( u32 row, const char *str ){ int end=0; u32 row_h = world_sfd.h -1 -row; @@ -80,9 +79,8 @@ static void world_sfd_update( world_instance *world, v3f pos ){ world_sfd.active_route_board = closest; ent_route *route = mdl_arritm( &world->ent_route, closest ); - addon_reg *world_reg = world_static.addon_hub; - if( world_static.active_instance ) - world_reg = world_static.addon_client; + addon_reg *world_reg = + world_static.instance_addons[ world_static.active_instance ]; char mod_uid[ ADDON_UID_MAX ]; addon_alias_uid( &world_reg->alias, mod_uid ); @@ -91,21 +89,6 @@ static void world_sfd_update( world_instance *world, v3f pos ){ mod_uid, mdl_pstr( &world->meta, route->pstr_name ), 0 ); -#if 0 - u32 id = route->anon.official_track_id; - - if( id != 0xffffffff ){ - struct netmsg_board *local_board = - &scoreboard_client_data.boards[id]; - - for( int i=0; i<13; i++ ){ - sfd_encode( i, &local_board->data[27*i] ); - } - }else{ - sfd_encode( 0, mdl_pstr( &world->meta, route->pstr_name ) ); - sfd_encode( 1, "No data" ); - } -#endif } } -- 2.25.1