From 6929408e937dca64da707a2d61f8cdf6ab857e93 Mon Sep 17 00:00:00 2001 From: hgn Date: Wed, 21 Jun 2023 00:24:03 +0100 Subject: [PATCH] save location & map, lighting qol --- addon.c | 1 - build.c | 3 +- ent_skateshop.c | 28 +++------ menu.h | 12 +++- models_src/rs_menu.mdl | Bin 197176 -> 206168 bytes save.c | 48 +++++++++----- skaterift.c | 138 ++++++++++++++++++++++------------------- skaterift.h | 59 +----------------- skaterift_imgui_dev.c | 20 +++--- workshop.c | 31 ++------- workshop.h | 6 -- world_gate.c | 3 +- world_load.c | 24 +++---- world_load.h | 17 +++-- world_render.c | 20 ++++-- 15 files changed, 168 insertions(+), 242 deletions(-) diff --git a/addon.c b/addon.c index 8067eca..ee3f803 100644 --- a/addon.c +++ b/addon.c @@ -385,7 +385,6 @@ VG_STATIC void addon_mount_content_folder( enum addon_type type, vg_dir dir; if( !vg_dir_open(&dir,path.buffer) ){ vg_error( "vg_dir_open('%s') failed\n", path.buffer ); - vg_async_call( workshop_async_any_complete, NULL, 0 ); return; } diff --git a/build.c b/build.c index 03742ef..acace58 100644 --- a/build.c +++ b/build.c @@ -116,8 +116,7 @@ void build_game( enum compiler compiler ) compiled_something = 1; } -int main( int argc, char *argv[] ) -{ +int main( int argc, char *argv[] ){ time_t uid = time(NULL); char *arg; diff --git a/ent_skateshop.c b/ent_skateshop.c index 16225c7..40e17f7 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -53,20 +53,17 @@ VG_STATIC void world_scan_thread( void *_args ){ addon_mount_content_folder( k_addon_type_world, "maps", ".mdl" ); addon_mount_workshop_items(); vg_async_call( async_addon_reg_update, NULL, 0 ); - skaterift_end_op(); } /* * Asynchronous scan of local disk for worlds */ VG_STATIC void skateshop_op_world_scan(void){ - skaterift_begin_op( k_async_op_world_scan ); vg_loader_start( world_scan_thread, NULL ); } VG_STATIC void board_processview_thread( void *_args ){ addon_cache_load_loop(); - skaterift_end_op(); } VG_STATIC void board_scan_thread( void *_args ){ @@ -78,12 +75,10 @@ VG_STATIC void board_scan_thread( void *_args ){ } VG_STATIC void skateshop_op_board_scan(void){ - skaterift_begin_op( k_async_op_board_scan ); vg_loader_start( board_scan_thread, NULL ); } VG_STATIC void skateshop_op_processview(void){ - skaterift_begin_op( k_async_op_board_scan ); vg_loader_start( board_processview_thread, NULL ); } @@ -158,12 +153,9 @@ VG_STATIC void skateshop_world_preview_loader_thread( void *_data ) VG_STATIC void skateshop_world_preview_loader_thread_and_end( void *_data ){ skateshop_world_preview_loader_thread( _data ); - skaterift_end_op(); } -VG_STATIC void skateshop_load_world_preview( addon_reg *reg ) -{ - skaterift_begin_op( k_async_op_world_load_preview ); +VG_STATIC void skateshop_load_world_preview( addon_reg *reg ){ vg_loader_start( skateshop_world_preview_loader_thread_and_end, reg ); } @@ -216,7 +208,7 @@ VG_STATIC void global_skateshop_preupdate(void) /* input */ if( shop->type == k_skateshop_type_boardshop ){ - if( skaterift.async_op != k_async_op_none ) return; + if( !vg_loader_availible() ) return; gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" ); gui_helper_action( button_display_string( k_srbind_mback ), "exit" ); @@ -266,7 +258,7 @@ VG_STATIC void global_skateshop_preupdate(void) } } else if( shop->type == k_skateshop_type_charshop ){ - if( skaterift.async_op != k_async_op_none ) return; + if( !vg_loader_availible() ) return; gui_helper_action( axis_display_string( k_sraxis_mbrowse_h ), "browse" ); gui_helper_action( button_display_string( k_srbind_mback ), "exit" ); @@ -311,15 +303,12 @@ VG_STATIC void global_skateshop_preupdate(void) int browseable = 0, loadable = 0; - if( addon_count(k_addon_type_world) && - ((skaterift.async_op == k_async_op_none)|| - (skaterift.async_op == k_async_op_world_load_preview))){ + if( addon_count(k_addon_type_world) && vg_loader_availible() ){ gui_helper_action( axis_display_string(k_sraxis_mbrowse_h), "browse" ); browseable = 1; } - if( (skaterift.async_op == k_async_op_none) && - global_skateshop.selected_world_id > 0 ){ + if( vg_loader_availible() && global_skateshop.selected_world_id > 0 ){ gui_helper_action( button_display_string(k_srbind_maccept), "open rift" ); loadable = 1; @@ -350,7 +339,7 @@ VG_STATIC void global_skateshop_preupdate(void) pointcloud_animate( k_pointcloud_anim_hiding ); } - if( skaterift.async_op == k_async_op_none ){ + if( vg_loader_availible() ){ addon_reg *reg = get_addon_from_index( k_addon_type_world, global_skateshop.selected_world_id ); @@ -610,8 +599,7 @@ VG_STATIC void skateshop_render_worldshop(void) info.buffer[info.i] = '\0'; vg_strcat( &info, global_skateshop.render.world_title ); - if( skaterift.async_op == k_async_op_world_loading || - skaterift.async_op == k_async_op_world_preloading ){ + if( !vg_loader_availible() ){ vg_strcat( &subtext, "Loading..." ); } else{ @@ -698,7 +686,7 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call ) vg_info( "skateshop_call\n" ); if( menu.active ) return; - if( skaterift.async_op != k_async_op_none ) return; + if( !vg_loader_availible() ) return; if( call->function == k_ent_function_trigger ){ if( localplayer.subsystem != k_player_subsystem_walk ){ diff --git a/menu.h b/menu.h index b8f509e..fcf2da4 100644 --- a/menu.h +++ b/menu.h @@ -206,13 +206,23 @@ static void menu_trigger_item( ent_menuitem *item ) if( MDL_CONST_PSTREQ( &menu.model, q, "quit" ) ){ vg.window_should_close = 1; } - else if( MDL_CONST_PSTREQ( &menu.model, q, "reset" ) ){ + else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_nearest" ) ){ localplayer_cmd_respawn( 0, NULL ); menu.page_depth = 0; menu.active = 0; menu.page = 0xffffffff; } + else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_home" ) ){ + world_static.active_world = 0; + world_static.active_trigger_volume_count = 0; + localplayer.viewable_world = world_current_instance(); + localplayer_cmd_respawn( 1, (const char *[]){"start"} ); + + menu.page_depth = 0; + menu.active = 0; + menu.page = 0xffffffff; + } else if( MDL_CONST_PSTREQ( &menu.model, q, "credits" ) ){ menu.credits_open = 1; } diff --git a/models_src/rs_menu.mdl b/models_src/rs_menu.mdl index 8d997b5ff4e98cdf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%^TA&H8J_zQ3Sv?)-ieT;sGc}nFj#nnhfQN%+hp@ z?>QXP!~npY#B}je>sVqQ`v6dn`HCD(hH^z_*;d1wHeKaiyt;!Z1P}lS!c6l|3sajW zC=o^gQhEX~Nl}k-O{TR`9}egRh_D>1<4x0hLsiR2Eh{nm`UAoN5dh?%PLrc7N(Jgr Rj%`hk|3vbM{ue&M_y6y!qfP(- delta 489 zcmX|7Jx>Bb5S?AV4!x6uNI;~}go45X3ll>mF*aHmi!<67yufJ)9GK-W*ccK`q*EM! z0Erevjk$yZ8WU?ON=i#xJ4$!Ci<8-%dHdeJ{g{m8;jR3TTG}H3JfUu}QuVyfJ15jm zZrP`L079LUShnYLR9l=hi>$J2QYy-E_tZrzr(0OexU z5u+_@SPUm|MbQYwhEfygaY2B?g&Dx_8QKUr=quzH$gV*~bqu<0Rl^52cI3{Ekbxbc R-RnW?o!a^!z39n={{Srsbu|D0 diff --git a/save.c b/save.c index 40929d9..6ea4e0f 100644 --- a/save.c +++ b/save.c @@ -16,7 +16,14 @@ static void skaterift_write_savedata_thread(void *_){ fwrite( savedata.buf, savedata.len, 1, fp ); fclose( fp ); } - skaterift_end_op(); +} + +static void skaterift_write_addon_alias( vg_msg *msg, const char *key, + addon_alias *alias ){ + if( alias->workshop_id ) + vg_msg_wkvu64( msg, key, alias->workshop_id ); + else + vg_msg_wkvstr( msg, key, alias->foldername ); } static void skaterift_write_viewslot( vg_msg *msg, const char *key, @@ -27,16 +34,13 @@ static void skaterift_write_viewslot( vg_msg *msg, const char *key, addon_cache_entry *entry = vg_pool_item( &cache->pool, cache_id ); addon_reg *reg = entry->reg_ptr; - if( reg ){ - if( reg->alias.workshop_id ) - vg_msg_wkvu64( msg, key, reg->alias.workshop_id ); - else - vg_msg_wkvstr( msg, key, reg->alias.foldername ); - } + if( reg ) + skaterift_write_addon_alias( msg, key, ®->alias ); } -static void skaterift_read_viewslot( vg_msg *msg, const char *key, - enum addon_type type, addon_alias *alias ){ +static void skaterift_read_addon_alias( vg_msg *msg, const char *key, + enum addon_type type, + addon_alias *alias ){ alias->foldername[0] = '\0'; alias->workshop_id = 0; @@ -52,22 +56,32 @@ static void skaterift_read_viewslot( vg_msg *msg, const char *key, } static void skaterift_write_savedata(void){ - if( skaterift.async_op != k_async_op_none ) return; - - skaterift_begin_op( k_async_op_write_savedata ); + if( !vg_loader_availible() ) return; vg_msg sav = {0}; sav.buf = savedata.buf; sav.max = sizeof(savedata.buf); vg_msg_frame( &sav, "player" ); + { + skaterift_write_viewslot( &sav, "board", k_addon_type_board, + localplayer.board_view_slot ); + skaterift_write_viewslot( &sav, "playermodel", k_addon_type_player, + localplayer.playermodel_view_slot ); + } + vg_msg_end_frame( &sav ); - skaterift_write_viewslot( &sav, "board", k_addon_type_board, - localplayer.board_view_slot ); - skaterift_write_viewslot( &sav, "playermodel", k_addon_type_player, - localplayer.playermodel_view_slot ); - + vg_msg_frame( &sav, "world" ); + { + if( world_loader.reg && (world_static.active_world > 0) ){ + skaterift_write_addon_alias( &sav, "alias", &world_loader.reg->alias ); + vg_msg_wkvu32( &sav, "index", world_static.active_world ); + vg_msg_wkvnum( &sav, "position", k_vg_msg_float|k_vg_msg_32b, 3, + localplayer.rb.co ); + } + } vg_msg_end_frame( &sav ); + savedata.len = sav.len; vg_loader_start( skaterift_write_savedata_thread, NULL ); } diff --git a/skaterift.c b/skaterift.c index 5d4e13f..74e6f75 100644 --- a/skaterift.c +++ b/skaterift.c @@ -50,10 +50,6 @@ static struct player_avatar localplayer_avatar; -#if 0 -static struct player_model localplayer_models[3]; -#endif - int main( int argc, char *argv[] ) { vg_mem.use_libc_malloc = 0; @@ -62,13 +58,6 @@ int main( int argc, char *argv[] ) return 0; } -#if 0 -VG_STATIC void highscores_save_at_exit(void) -{ - highscores_serialize_all(); -} -#endif - VG_STATIC void vg_launch_opt(void) { } @@ -85,14 +74,6 @@ vg_info(" | \\/ | | / | | \\ | / | \n" ); vg_info(" ' ' '--' [] '----- '----- ' ' '---' " "SOFTWARE\n" ); - /* 31.05.23 (hgn): this is only a server feature now */ -#if 0 - highscores_init( 2000, 50 ); - if( !highscores_read() ) - highscores_create_db(); - vg_loader_step( NULL, highscores_save_at_exit ); -#endif - steam_init(); vg_loader_step( NULL, steam_end ); vg_loader_step( network_init, network_end ); @@ -100,24 +81,75 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " VG_STATIC void load_playermodels(void) { -#if 0 - player_model_load( &localplayer_models[0], "models/ch_new.mdl" ); - player_model_load( &localplayer_models[1], "models/ch_outlaw.mdl" ); - player_model_load( &localplayer_models[2], "models/ch_jordan.mdl" ); -#endif - /* FIXME: hack */ shader_model_character_view_register(); shader_model_board_view_register(); shader_model_entity_register(); } -VG_STATIC void async_skaterift_player_start( void *payload, u32 size ) -{ +VG_STATIC void async_skaterift_player_start( void *payload, u32 size ){ localplayer.viewable_world = world_current_instance(); localplayer_cmd_respawn( 1, (const char *[]){ "start" } ); } +static void async_call_ready( void *payload, u32 size ){ + skaterift.op = k_async_op_none; +} + +static void skaterift_restore_state(void){ + vg_msg sav = {0}; + sav.buf = savedata.buf; + sav.len = savedata.len; + sav.max = sizeof(savedata.buf); + + vg_msg player = sav; + if( vg_msg_seekframe( &player, "player", 0 ) ){ + addon_alias q; + + /* board */ + skaterift_read_addon_alias( &player, "board", k_addon_type_board, &q ); + u32 reg_id = addon_match( &q ); + if( reg_id != 0xffffffff ){ + localplayer.board_view_slot = + addon_cache_create_viewer( k_addon_type_board, reg_id ); + } + + /* playermodel */ + skaterift_read_addon_alias( &player, "playermodel", + k_addon_type_player, &q ); + reg_id = addon_match( &q ); + + if( reg_id == 0xffffffff ) reg_id = 0; + localplayer.playermodel_view_slot = + addon_cache_create_viewer( k_addon_type_player, reg_id ); + } + + vg_msg world = sav; + if( vg_msg_seekframe( &world, "world", 0 ) ){ + addon_alias q; + + /* world */ + skaterift_read_addon_alias( &world, "alias", k_addon_type_world, &q ); + u32 reg_id = addon_match( &q ); + if( reg_id != 0xffffffff ){ + addon_reg *reg = get_addon_from_index( k_addon_type_world, reg_id ); + + world_loader.generate_point_cloud = 0; + world_loader.reg = reg; + world_loader.state = k_world_loader_load; + skaterift_world_changer_thread(NULL); + + world_static.active_world = vg_msg_seekkvu32( &world, "index", 0 ); + world_static.active_trigger_volume_count = 0; + localplayer.viewable_world = world_current_instance(); + + vg_msg_cmd position = vg_msg_seekkv( &world, "position", 0 ); + vg_msg_convert_num( &position, k_vg_msg_float|k_vg_msg_32b, 3, + localplayer.rb.co ); + } + } +} + VG_STATIC void vg_load(void) { vg_console_reg_cmd( "changeworld", skaterift_change_world_command, NULL ); @@ -162,6 +194,9 @@ VG_STATIC void vg_load(void) world_loader.world_index = 0; world_load_mdl( "maps/mp_spawn/main.mdl" ); + vg_async_call( async_skaterift_player_start, NULL, 0 ); + vg_async_stall(); + /* Completing addon registrations * ------------------------------------- */ @@ -204,11 +239,6 @@ VG_STATIC void vg_load(void) vg_console_load_autos(); menu_link(); - //vg_mem_log( vg_mem.rtmemory, 0, "Root" ); - - vg_async_call( async_skaterift_player_start, NULL, 0 ); - - skaterift_shift_op( k_async_op_board_scan ); addon_mount_content_folder( k_addon_type_player, "playermodels", ".mdl" ); addon_mount_content_folder( k_addon_type_board, "boards", ".mdl" ); @@ -217,34 +247,11 @@ VG_STATIC void vg_load(void) vg_async_stall(); /* and now */ + skaterift_restore_state(); + vg_loader_step( NULL, skaterift_write_savedata ); - vg_msg sav = {0}; - sav.buf = savedata.buf; - sav.len = savedata.len; - sav.max = sizeof(savedata.buf); - - if( vg_msg_seekframe(&sav, "player",0) ){ - addon_alias q; - - /* board */ - skaterift_read_viewslot( &sav, "board", k_addon_type_board, &q ); - u32 reg_id = addon_match( &q ); - if( reg_id != 0xffffffff ){ - localplayer.board_view_slot = - addon_cache_create_viewer( k_addon_type_board, reg_id ); - } - - /* playermodel */ - skaterift_read_viewslot( &sav, "playermodel", k_addon_type_player, &q ); - reg_id = addon_match( &q ); - - if( reg_id == 0xffffffff ) reg_id = 0; - - localplayer.playermodel_view_slot = - addon_cache_create_viewer( k_addon_type_player, reg_id ); - } - - board_processview_thread(NULL); /* END_OP!! */ + board_processview_thread(NULL); + vg_async_call( async_call_ready, NULL, 0 ); } VG_STATIC void draw_origin_axis(void) @@ -259,8 +266,9 @@ VG_STATIC void vg_update(void) { steam_update(); skaterift_preupdate_inputs(); - if( skaterift.async_op == k_async_op_clientloading ) return; - if( skaterift.async_op == k_async_op_world_preloading ){ + if( skaterift.op == k_async_op_clientloading ) return; + + if( world_loader.state == k_world_loader_preload ){ skaterift_change_world_preupdate(); } @@ -277,7 +285,7 @@ VG_STATIC void vg_update(void) VG_STATIC void vg_update_fixed(void) { - if( skaterift.async_op == k_async_op_clientloading ) return; + if( skaterift.op == k_async_op_clientloading ) return; world_routes_fixedupdate( world_current_instance() ); player__update( &localplayer ); @@ -286,7 +294,7 @@ VG_STATIC void vg_update_fixed(void) VG_STATIC void vg_update_post(void) { - if( skaterift.async_op == k_async_op_clientloading ) return; + if( skaterift.op == k_async_op_clientloading ) return; player__post_update( &localplayer ); @@ -460,7 +468,7 @@ VG_STATIC void render_main_game(void) VG_STATIC void vg_render(void) { - if( skaterift.async_op == k_async_op_clientloading ){ + if( skaterift.op == k_async_op_clientloading ){ _vg_loader_render(); return; } @@ -488,7 +496,7 @@ VG_STATIC void vg_render(void) VG_STATIC void vg_gui(void) { - if( skaterift.async_op == k_async_op_clientloading ) return; + if( skaterift.op == k_async_op_clientloading ) return; menu_update(); if( menu.active ){ diff --git a/skaterift.h b/skaterift.h index c9b3fae..bfcaffb 100644 --- a/skaterift.h +++ b/skaterift.h @@ -9,8 +9,6 @@ #define VG_MSG_V1_SUPPORT #define VG_LOG_SOURCE_INFO #include "vg/vg.h" - -#include "common.h" #include "world.h" #include "addon.h" @@ -18,8 +16,6 @@ struct{ enum async_operation{ k_async_op_none, k_async_op_clientloading, - k_async_op_world_preloading, - k_async_op_world_loading, k_async_op_world_scan, k_async_op_world_load_preview, k_async_op_board_scan, @@ -30,63 +26,12 @@ struct{ k_workshop_form_op_downloading_submission, k_workshop_form_op_publishing_update, } - async_op; + op; } -static skaterift = { .async_op = k_async_op_clientloading }; +static skaterift = { .op = k_async_op_clientloading }; /* Skaterift api */ static void skaterift_change_world_start( void ); static int skaterift_change_world_command( int argc, const char *argv[] ); -/* - * Start a new operation or crash if we are already running one. you can avoid - * crashing the game by checking the async status yourself before calling. - */ -VG_STATIC void skaterift_begin_op( enum async_operation op ) -{ - if( vg_thread_purpose() == k_thread_purpose_loader ){ - vg_fatal_error( "Can't do that here\n" ); - } - - if( skaterift.async_op != k_async_op_none ){ - vg_fatal_error( "Async executing op(%d), tried to start op(%d)\n", - skaterift.async_op, op ); - } - - skaterift.async_op = op; - vg_info( "Starting op( %d )\n", op ); -} - -/* - * Switch operation for those who have multiple parts - */ -VG_STATIC void skaterift_shift_op( enum async_operation op ) -{ - if( skaterift.async_op == k_async_op_none ){ - vg_fatal_error( "No current op, cannot shift operation (%d)\n", op ); - } - - skaterift.async_op = op; - vg_info( "Shifting to op( %d )\n", op ); -} - -VG_STATIC void skaterift_end_op(void); -VG_STATIC void async_skaterift_end_op( void *data, u32 size ){ - skaterift_end_op(); -} - -/* - * Finished operation, otheres can now run - */ -VG_STATIC void skaterift_end_op(void) -{ - if( vg_thread_purpose() == k_thread_purpose_loader ){ - vg_async_call( async_skaterift_end_op, NULL, 0 ); - } - else{ - vg_info( "Finishing op( %d )\n", skaterift.async_op ); - skaterift.async_op = k_async_op_none; - } -} - #endif /* SKATERIFT_H */ diff --git a/skaterift_imgui_dev.c b/skaterift_imgui_dev.c index d4365e1..9d69bfc 100644 --- a/skaterift_imgui_dev.c +++ b/skaterift_imgui_dev.c @@ -14,18 +14,14 @@ #define SR_NETWORKED #define VG_DEVWINDOW -#include "common.h" -#if 0 -#include "conf.h" -#include "steam.h" -#include "render.h" -#include "audio.h" -#include "world.h" -#include "font.h" -#include "player.h" -#include "entity.c" -#include "workshop.c" -#endif +#define SKATERIFT_APPID 2103940 + +#define VG_TIMESTEP_FIXED (1.0/60.0) +#define VG_3D +#define VG_GAME +#define VG_MSG_V1_SUPPORT +#define VG_LOG_SOURCE_INFO +#include "vg/vg.h" static int skaterift_loaded = 0; static char g_an_buffer[ 4096 ]; diff --git a/workshop.c b/workshop.c index d0a3883..d9d576d 100644 --- a/workshop.c +++ b/workshop.c @@ -33,7 +33,6 @@ static struct ui_dropdown_opt workshop_form_type_opts[] = { */ VG_STATIC void workshop_quit_form(void) { - skaterift_begin_op( k_async_op_none ); /* safeguard */ player_board_unload( &workshop_form.board_model ); workshop_form.file_intent = k_workshop_form_file_intent_none; @@ -46,7 +45,6 @@ VG_STATIC void workshop_quit_form(void) } workshop_form.page = k_workshop_form_hidden; - skaterift_end_op(); } /* @@ -150,8 +148,6 @@ VG_STATIC void on_workshop_update_result( void *data, void *user ) vg_error( "Error with the submitted file (%d)\n", result->m_eResult ); } - - skaterift_end_op(); } /* @@ -245,7 +241,6 @@ VG_STATIC void on_workshop_createitem( void *data, void *user ) workshop_form.page = k_workshop_form_closing_bad; workshop_form.failure_or_success_string = errstr; - skaterift_end_op(); } } @@ -312,7 +307,6 @@ VG_STATIC void _workshop_form_submit_thread( void *data ) if( !vg_strgood(&folder) ){ vg_error( "addon folder path too long\n" ); - vg_async_call( workshop_async_any_complete, NULL, 0 ); return; } @@ -344,7 +338,6 @@ VG_STATIC void _workshop_form_submit_thread( void *data ) vg_dir dir; if( !vg_dir_open( &dir, folder.buffer ) ){ vg_error( "could not open addon folder '%s'\n", folder.buffer ); - vg_async_call( workshop_async_any_complete, NULL, 0 ); return; } @@ -372,7 +365,6 @@ VG_STATIC void _workshop_form_submit_thread( void *data ) vg_strcat( &descriptor_file, "/addon.inf" ); if( !vg_strgood(&descriptor_file) ){ vg_error( "Addon info path too long\n" ); - vg_async_call( workshop_async_any_complete, NULL, 0 ); return; } @@ -380,7 +372,6 @@ VG_STATIC void _workshop_form_submit_thread( void *data ) if( !fp ){ vg_error( "Could not open addon info file '%s'\n", descriptor_file.buffer ); - vg_async_call( workshop_async_any_complete, NULL, 0 ); return; } fwrite( descriptor_buf, descriptor.cur, 1, fp ); @@ -393,7 +384,6 @@ VG_STATIC void _workshop_form_submit_thread( void *data ) if( !vg_strgood(&preview) ){ vg_error( "preview image path too long\n" ); - vg_async_call( workshop_async_any_complete, NULL, 0 ); return; } @@ -434,8 +424,6 @@ VG_STATIC void workshop_op_submit(void) } } - skaterift_begin_op( k_workshop_form_op_publishing_update ); - player_board_unload( &workshop_form.board_model ); workshop_form.file_intent = k_workshop_form_file_intent_none; @@ -459,15 +447,12 @@ VG_STATIC void workshop_form_loadmodel_async_complete( void *payload, u32 size ) workshop_form.file_intent = k_workshop_form_file_intent_new; vg_success( "workshop async load complete\n" ); - skaterift_end_op(); } /* * Reciever for failure to load */ -VG_STATIC void workshop_form_loadmodel_async_error( void *payload, u32 size ) -{ - skaterift_end_op(); +VG_STATIC void workshop_form_loadmodel_async_error( void *payload, u32 size ){ } /* @@ -533,8 +518,7 @@ VG_STATIC void _workshop_form_load_thread( void *data ) /* * Entry point for load model operation */ -VG_STATIC void workshop_op_load_model(void) -{ +VG_STATIC void workshop_op_load_model(void){ if( workshop_form.submission.type == k_addon_type_world ){ vg_warn( "WORLD LOAD INFO Currently unsupported\n" ); return; @@ -552,7 +536,6 @@ VG_STATIC void workshop_op_load_model(void) return; } - skaterift_begin_op( k_workshop_form_op_loading_model ); vg_loader_start( _workshop_form_load_thread, NULL ); } @@ -583,8 +566,6 @@ VG_STATIC void workshop_form_async_imageload( void *data, u32 len ) stbi_failure_reason() ); ui_start_modal( workshop_form.error_msg, UI_MODAL_BAD ); } - - skaterift_end_op(); } /* @@ -658,7 +639,6 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index ) result_index, &details ) ) { - skaterift_begin_op( k_workshop_form_op_downloading_submission ); workshop_reset_submission_data(); workshop_form.submission.submit_description = 0; workshop_form.submission.submit_file_and_image = 0; @@ -775,7 +755,6 @@ VG_STATIC void workshop_op_download_and_view_submission( int result_index ) } else{ vg_error( "GetQueryUGCResult: Index out of range\n" ); - skaterift_end_op(); } } @@ -1428,7 +1407,7 @@ VG_STATIC void workshop_form_gui(void) ui_rect quit_button; ui_split( title, k_ui_axis_v, title[2]-title[3], 2, title, quit_button ); - if( skaterift.async_op == k_async_op_none ){ + if( vg_loader_availible() ){ if( ui_button_text( quit_button, "X", 1 ) ){ workshop_quit_form(); return; @@ -1441,11 +1420,11 @@ VG_STATIC void workshop_form_gui(void) * escapes here and we show them a basic string */ - if( skaterift.async_op != k_async_op_none ){ + if( !vg_loader_availible() ){ const char *op_string = "The programmer has not bothered to describe " "the current operation that is running."; - switch( skaterift.async_op ){ + switch( skaterift.op ){ case k_workshop_form_op_loading_model: op_string = "Operation in progress: Loading model file."; break; diff --git a/workshop.h b/workshop.h index d7c892f..d4f1b6d 100644 --- a/workshop.h +++ b/workshop.h @@ -130,10 +130,4 @@ VG_STATIC void async_workshop_get_installed_files( void *data, u32 len ); VG_STATIC void workshop_load_metadata( const char *path, struct workshop_file_info *info ); -/* generic reciever */ -VG_STATIC void workshop_async_any_complete( void *data, u32 size ) -{ - skaterift_end_op(); -} - #endif /* WORKSHOP_H */ diff --git a/world_gate.c b/world_gate.c index 7a5360a..771fd83 100644 --- a/world_gate.c +++ b/world_gate.c @@ -246,8 +246,7 @@ VG_STATIC ent_gate *world_intersect_gates( world_instance *world, continue; if( gate->type == k_gate_type_nonlocel ){ - if( skaterift.async_op == k_async_op_world_loading || - skaterift.async_op == k_async_op_world_preloading ){ + if( world_loader.state != k_world_loader_none ){ continue; } } diff --git a/world_load.c b/world_load.c index 1547d22..bbf5c91 100644 --- a/world_load.c +++ b/world_load.c @@ -97,21 +97,14 @@ VG_STATIC void world_load_mdl( const char *path ) world->status = k_world_status_loaded; } -/* - * op: k_async_op_world_loading - * k_async_op_world_preloading - * ----------------------------------------------------------------------------- - */ - -static void async_skaterift_world_loaded( void *payload, u32 size ) -{ - skaterift_end_op(); +static void skaterift_world_change_done( void *payload, u32 size ){ + world_loader.state = k_world_loader_none; } /* * Does a complete world switch using the remaining free slots */ -static void skaterift_world_changer_thread( void *data ){ +static void skaterift_world_changer_thread( void *_ ){ char path_buf[4096]; vg_str path; vg_strnull( &path, path_buf, 4096 ); @@ -127,7 +120,6 @@ static void skaterift_world_changer_thread( void *data ){ vg_str folder = path; if( !vg_strgood( &folder ) ) { vg_error( "Load target too long\n" ); - vg_async_call( workshop_async_any_complete, NULL, 0 ); return; } @@ -137,7 +129,6 @@ static void skaterift_world_changer_thread( void *data ){ vg_dir dir; if( !vg_dir_open(&dir, folder.buffer) ){ vg_error( "opendir('%s') failed\n", folder.buffer ); - vg_async_call( async_skaterift_world_loaded, NULL, 0 ); return; } @@ -193,13 +184,12 @@ static void skaterift_world_changer_thread( void *data ){ } } - vg_async_call( async_skaterift_world_loaded, NULL, 0 ); + vg_async_call( skaterift_world_change_done, NULL, 0 ); } /* holding pattern before we can start loading the new world, since we might be * waiting for audio to stop */ -static void skaterift_change_world_preupdate(void) -{ +static void skaterift_change_world_preupdate(void){ for( u32 i=1; itype == k_gate_type_nonlocel ){ - if( skaterift.async_op != k_async_op_world_loading && - skaterift.async_op != k_async_op_world_preloading ){ - world_instance *dest_world = &world_static.worlds[ gate->target ]; - render_gate( dest_world, gate, cam, layer_depth ); + if( world_loader.state != k_world_loader_none ){ + world->rendering_gate = NULL; + return; } + + world_instance *dest_world = &world_static.worlds[ gate->target ]; + render_gate( dest_world, gate, cam, layer_depth ); } else world->rendering_gate = NULL; @@ -452,8 +454,14 @@ VG_STATIC void render_world_gates( world_instance *world, camera *cam, VG_STATIC void world_prerender( world_instance *world ) { - f32 day_length = vg_maxf(0.1f, fabsf(k_day_length)) * vg_signf(k_day_length); - world->time += vg.time_delta * (1.0/(day_length*60.0)); + + if( mdl_arrcount( &world->ent_light ) ){ + f32 rate = vg_maxf(0.1f, fabsf(k_day_length)) * vg_signf(k_day_length); + world->time += vg.time_delta * (1.0/(rate*60.0)); + } + else{ + world->time = 0.834; + } struct ub_world_lighting *state = &world->ub_lighting; -- 2.25.1