From 1e7fd8e3d7191c627a4625f0c3ee8291a150d621 Mon Sep 17 00:00:00 2001 From: hgn Date: Thu, 20 Feb 2025 03:39:55 +0000 Subject: [PATCH] restore function of skateshops --- skaterift_blender/sr_main.py | 5 +- src/ent_challenge.c | 33 +- src/ent_route.c | 28 +- src/ent_route.h | 3 +- src/ent_skateshop.c | 775 +++++++++++++++++------------------ src/ent_skateshop.h | 12 +- src/entity.c | 3 + src/input.h | 4 +- src/player_skate.c | 3 +- src/player_walk.c | 27 +- src/skaterift.c | 63 +-- src/world.c | 18 +- src/world.h | 8 +- src/world_entity.h | 29 +- src/world_events.c | 32 -- src/world_events.h | 3 - src/world_load.c | 1 + src/world_render.c | 11 +- src/world_render.h | 2 - 19 files changed, 516 insertions(+), 544 deletions(-) delete mode 100644 src/world_events.c delete mode 100644 src/world_events.h diff --git a/skaterift_blender/sr_main.py b/skaterift_blender/sr_main.py index bea93ef..24e9101 100644 --- a/skaterift_blender/sr_main.py +++ b/skaterift_blender/sr_main.py @@ -438,7 +438,7 @@ class ent_skateshop(Structure): ("id_camera",c_uint32), ("_anonymous_union",ent_skateshop_anon_union)] - sr_functions = { 0: 'trigger' } + sr_functions = { 0: 'view', -1: 'unview' } #} class ent_swspreview(Structure): @@ -497,7 +497,8 @@ class ent_challenge(Structure):#{ ("camera",c_uint32), ("status",c_uint32)] #runtime sr_functions = { 0: 'unlock', - 1: 'view/reset' } + 1: 'view', + -1: 'unview' } #} class ent_region(Structure):#{ diff --git a/src/ent_challenge.c b/src/ent_challenge.c index 6181adf..6041377 100644 --- a/src/ent_challenge.c +++ b/src/ent_challenge.c @@ -13,8 +13,7 @@ entity_call_result ent_challenge_call( world_instance *world, ent_call *call ) { if( !challenge->status ) { - vg_info( "challenge( '%s' )\n", - af_str( &world->meta.af, challenge->pstr_alias) ); + vg_info( "challenge( '%s' )\n", af_str( &world->meta.af, challenge->pstr_alias) ); ent_call call; call.data = NULL; call.function = challenge->target_event; @@ -165,3 +164,33 @@ static void ent_challenge_render( ent_challenge *challenge ){ } #endif + +void ent_challenge_update(void) +{ + if( _world.event != k_world_event_challenge ) + return; + + if( _world.challenge_running ) + { + } + else + { + ent_challenge *challenge = _world.active_challenge; + if( challenge->flags & k_ent_challenge_is_story ) + { + if( button_down( k_srbind_maccept ) ) + { + gui_helper_reset( k_gui_helper_mode_clear ); + ent_call call; + call.data = NULL; + call.function = challenge->target_event; + call.id = challenge->target; + entity_call( &_world.main, &call ); + } + } + else + { + /* activate the actual challenge blah blah */ + } + } +} diff --git a/src/ent_route.c b/src/ent_route.c index 5ba4544..7c409f1 100644 --- a/src/ent_route.c +++ b/src/ent_route.c @@ -2,7 +2,7 @@ #include "input.h" #include "gui.h" -struct global_ent_route global_ent_route; +struct global_ent_route _ent_route; entity_call_result ent_route_call( world_instance *world, ent_call *call ) { @@ -10,8 +10,8 @@ entity_call_result ent_route_call( world_instance *world, ent_call *call ) ent_route *route = af_arritm( &world->ent_route, index ); if( call->function == 0 ) - { /* view() */ - if( localplayer.subsystem == k_player_subsystem_walk ) + { + if( localplayer.subsystem == k_player_subsystem_walk ) /* view */ { #if 0 world_entity_set_focus( call->id ); @@ -20,11 +20,11 @@ entity_call_result ent_route_call( world_instance *world, ent_call *call ) gui_helper_clear(); vg_str text; - if( (global_ent_route.helper_weekly = + if( (_ent_route.helper_weekly = gui_new_helper( input_button_list[k_srbind_mleft], &text ))) vg_strcat( &text, "Weekly" ); - if( (global_ent_route.helper_alltime = + if( (_ent_route.helper_alltime = gui_new_helper( input_button_list[k_srbind_mright], &text ))) vg_strcat( &text, "All time" ); @@ -39,13 +39,13 @@ entity_call_result ent_route_call( world_instance *world, ent_call *call ) return k_entity_call_result_unhandled; } -void ent_route_preupdate( ent_focus_context *ctx ) +void ent_route_preupdate(void) { - if( !ctx->active ) + if( _world.event != k_world_event_route_leaderboard ) return; - world_instance *world = ctx->world; - ent_route *route = af_arritm( &world->ent_route, ctx->index ); + world_instance *world = &_world.main; + ent_route *route = _ent_route.looking_at_board; u32 cam_id = 0; @@ -54,18 +54,20 @@ void ent_route_preupdate( ent_focus_context *ctx ) //world_entity_focus_camera( world, cam_id ); - if( button_down( k_srbind_mleft ) ){ + if( button_down( k_srbind_mleft ) ) + { world_sfd.view_weekly = 1; world_sfd_compile_active_scores(); } - if( button_down( k_srbind_mright ) ){ + if( button_down( k_srbind_mright ) ) + { world_sfd.view_weekly = 0; world_sfd_compile_active_scores(); } - global_ent_route.helper_alltime->greyed =!world_sfd.view_weekly; - global_ent_route.helper_weekly->greyed = world_sfd.view_weekly; + _ent_route.helper_alltime->greyed =!world_sfd.view_weekly; + _ent_route.helper_weekly->greyed = world_sfd.view_weekly; if( button_down( k_srbind_mback ) ) { diff --git a/src/ent_route.h b/src/ent_route.h index cbf61b2..b687c3f 100644 --- a/src/ent_route.h +++ b/src/ent_route.h @@ -4,8 +4,9 @@ struct global_ent_route { struct gui_helper *helper_weekly, *helper_alltime; + ent_route *looking_at_board; } extern global_ent_route; entity_call_result ent_route_call( world_instance *world, ent_call *call ); -void ent_route_preupdate( ent_focus_context *ctx ); +void ent_route_preupdate(void); diff --git a/src/ent_skateshop.c b/src/ent_skateshop.c index edbc142..04d0a9f 100644 --- a/src/ent_skateshop.c +++ b/src/ent_skateshop.c @@ -13,64 +13,56 @@ #include "save.h" #include "network.h" -struct global_skateshop global_skateshop = +struct global_skateshop _skateshop = { - .render={.reg_id=0xffffffff,.world_reg=0xffffffff} + .render={.reg_id=0xffffffff,.world_reg=0xffffffff}, }; -/* - * Checks string equality but does a hash check first - */ -static inline int const_str_eq( u32 hash, const char *str, const char *cmp ) +static void skateshop_update_viewpage(void) { - if( hash == vg_strdjb2(cmp) ) - if( !strcmp( str, cmp ) ) - return 1; - return 0; -} - -static void skateshop_update_viewpage(void){ - u32 page = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; + u32 page = _skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; - for( u32 i=0; icache_id ); } - for( u32 i=0; icache_id = addon_cache_create_viewer( k_addon_type_board, - request_id ); + slot->cache_id = addon_cache_create_viewer( k_addon_type_board, request_id ); } } -struct async_preview_load_thread_data{ +struct async_preview_load_thread_data +{ void *data; addon_reg *reg; }; -static void skateshop_async_preview_imageload( void *data, u32 len ){ +static void skateshop_async_preview_imageload( void *data, u32 len ) +{ struct async_preview_load_thread_data *inf = data; if( inf->data ){ - glBindTexture( GL_TEXTURE_2D, global_skateshop.tex_preview ); + glBindTexture( GL_TEXTURE_2D, _skateshop.tex_preview ); glTexSubImage2D( GL_TEXTURE_2D, 0,0,0, WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, inf->data ); glGenerateMipmap( GL_TEXTURE_2D ); stbi_image_free( inf->data ); - skaterift.rt_textures[k_skaterift_rt_workshop_preview] = - global_skateshop.tex_preview; + skaterift.rt_textures[k_skaterift_rt_workshop_preview] = _skateshop.tex_preview; } else { skaterift.rt_textures[k_skaterift_rt_workshop_preview] = vg.tex_missing; } SDL_AtomicLock( &addon_system.sl_cache_using_resources ); - global_skateshop.reg_loaded_preview = inf->reg; + _skateshop.reg_loaded_preview = inf->reg; SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); } @@ -81,13 +73,13 @@ static void skateshop_update_preview_image_thread(void *_args) vg_strnull( &folder, path_buf, sizeof(path_buf) ); SDL_AtomicLock( &addon_system.sl_cache_using_resources ); - addon_reg *reg_preview = global_skateshop.reg_preview; + addon_reg *reg_preview = _skateshop.reg_preview; SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); if( !addon_get_content_folder( reg_preview, &folder, 1 ) ) { SDL_AtomicLock( &addon_system.sl_cache_using_resources ); - global_skateshop.reg_loaded_preview = reg_preview; + _skateshop.reg_loaded_preview = reg_preview; SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); return; } @@ -123,7 +115,7 @@ static void skateshop_update_preview_image_thread(void *_args) vg_error( "Path too long to workshop preview image.\n" ); SDL_AtomicLock( &addon_system.sl_cache_using_resources ); - global_skateshop.reg_loaded_preview = reg_preview; + _skateshop.reg_loaded_preview = reg_preview; SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); } } @@ -134,7 +126,7 @@ void skateshop_world_preview_preupdate(void) if( vg_loader_availible() ) { SDL_AtomicLock( &addon_system.sl_cache_using_resources ); - if( global_skateshop.reg_preview != global_skateshop.reg_loaded_preview ) + if( _skateshop.reg_preview != _skateshop.reg_loaded_preview ) { SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); vg_loader_start( skateshop_update_preview_image_thread, NULL ); @@ -143,25 +135,14 @@ void skateshop_world_preview_preupdate(void) } } -/* - * op/subroutine: k_workshop_op_item_load - * ----------------------------------------------------------------------------- - */ - -/* - * Regular stuff - * ----------------------------------------------------------------------------- - */ - -static void skateshop_init_async(void *_data,u32 size){ - glGenTextures( 1, &global_skateshop.tex_preview ); - glBindTexture( GL_TEXTURE_2D, global_skateshop.tex_preview ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, - WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT, +static void skateshop_init_async(void *_data,u32 size) +{ + glGenTextures( 1, &_skateshop.tex_preview ); + glBindTexture( GL_TEXTURE_2D, _skateshop.tex_preview ); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, WORKSHOP_PREVIEW_WIDTH, WORKSHOP_PREVIEW_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - GL_LINEAR_MIPMAP_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); @@ -183,23 +164,23 @@ static u16 skateshop_selected_cache_id(void) { if( addon_count(k_addon_type_board, 0,ADDON_REG_HIDDEN) ) { - addon_reg *reg = get_addon_from_index( - k_addon_type_board, global_skateshop.selected_board_id, - 0, ADDON_REG_HIDDEN ); + addon_reg *reg = get_addon_from_index( k_addon_type_board, _skateshop.selected_board_id, 0, ADDON_REG_HIDDEN ); return reg->cache_id; } else return 0; } -static void skateshop_server_helper_update(void){ +static void skateshop_server_helper_update(void) +{ vg_str text; - vg_strnull( &text, global_skateshop.helper_toggle->text, - sizeof(global_skateshop.helper_toggle->text) ); + vg_strnull( &text, _skateshop.helper_toggle->text, sizeof(_skateshop.helper_toggle->text) ); - if( skaterift.demo_mode ){ + if( skaterift.demo_mode ) + { vg_strcat( &text, "Not availible in demo" ); } - else { + else + { if( network_client.user_intent == k_server_intent_online ) vg_strcat( &text, "Disconnect" ); else @@ -207,234 +188,285 @@ static void skateshop_server_helper_update(void){ } } -/* - * VG event preupdate - */ -void temp_update_playermodel(void); -void ent_skateshop_preupdate( ent_focus_context *ctx ) +static void board_scan_thread( void *_args ) { - if( !ctx->active ) - return; + addon_mount_content_folder( k_addon_type_board, "boards", ".mdl" ); + addon_mount_workshop_items(); + vg_async_call( async_addon_reg_update, NULL, 0 ); + vg_async_stall(); +} - world_instance *world = ctx->world; - ent_skateshop *shop = af_arritm( &world->ent_skateshop, ctx->index ); +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 ); +} - /* camera positioning */ - ent_camera *ref = af_arritm( &world->ent_camera, - mdl_entity_id_id(shop->id_camera) ); -#if 0 - v3_copy( ref->r, world_static.focus_cam.angles ); -#endif +static void ent_skateshop_helpers_pickable( const char *acceptance ) +{ + vg_str text; - v3f lookat; - if( shop->type == k_skateshop_type_boardshop || - shop->type == k_skateshop_type_worldshop ){ - ent_marker *display = af_arritm( &world->ent_marker, - mdl_entity_id_id(shop->boards.id_display) ); - v3_sub( display->transform.co, localplayer.rb.co, lookat ); - } - else if( shop->type == k_skateshop_type_charshop ) - { - v3_sub( ref->co, localplayer.rb.co, lookat ); + if( gui_new_helper( input_button_list[k_srbind_mback], &text )) + vg_strcat( &text, "Exit" ); + + if( (_skateshop.helper_pick = gui_new_helper( input_button_list[k_srbind_maccept], &text))){ + vg_strcat( &text, acceptance ); } - else if( shop->type == k_skateshop_type_server ){ - ent_prop *prop = af_arritm( &world->ent_prop, - mdl_entity_id_id(shop->server.id_lever) ); - v3_sub( prop->transform.co, localplayer.rb.co, lookat ); + + if( (_skateshop.helper_browse = gui_new_helper( input_axis_list[k_sraxis_mbrowse_h], &text ))){ + vg_strcat( &text, "Browse" ); } - else - vg_fatal_error( "Unknown store (%u)\n", shop->type ); +} - q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f}, - atan2f(lookat[0],lookat[2]) ); +static void skateshop_playermod( bool immobile ) +{ + localplayer.immobile = immobile; + menu.disable_open = immobile; + srinput.state = k_input_state_resume; +} -#if 0 - v3_copy( ref->co, world_static.focus_cam.pos ); - world_static.focus_cam.fov = ref->fov; -#endif +void ent_skateshop_update(void) +{ + if( _world.event != k_world_event_shop ) + return; - /* input */ - if( shop->type == k_skateshop_type_boardshop ){ - if( !vg_loader_availible() ) return; + if( _skateshop.open ) + { + ent_skateshop *shop = _skateshop.current_shop; + world_instance *world = &_world.main; - u16 cache_id = skateshop_selected_cache_id(); - global_skateshop.helper_pick->greyed = !cache_id; + if( button_down( k_srbind_mback ) ) + { + _skateshop.open = 0; - /* - * Controls - * ---------------------- - */ - u32 opage = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; + if( shop->type == k_skateshop_type_charshop ) + network_send_item( k_netmsg_playeritem_player ); - if( button_down( k_srbind_mleft ) ){ - if( global_skateshop.selected_board_id > 0 ){ - global_skateshop.selected_board_id --; - } + gui_helper_reset( k_gui_helper_mode_clear ); + + skateshop_playermod( 0 ); + srinput.state = k_input_state_resume; + return; } - u32 valid_count = addon_count( k_addon_type_board, 0,0 ); - if( button_down( k_srbind_mright ) ) + /* override camera positioning + * ------------------------------------------------------------------------ */ + ent_camera *ref = af_arritm( &world->ent_camera, mdl_entity_id_id(shop->id_camera) ); + v3f lookat = {1,0,0}; + if( (shop->type == k_skateshop_type_boardshop) || (shop->type == k_skateshop_type_worldshop) ) { - if( global_skateshop.selected_board_id+1 < valid_count ) - { - global_skateshop.selected_board_id ++; - } + ent_marker *display = af_arritm( &world->ent_marker, mdl_entity_id_id(shop->boards.id_display) ); + v3_sub( display->transform.co, localplayer.rb.co, lookat ); + } + else if( shop->type == k_skateshop_type_charshop ) + { + v3_sub( ref->co, localplayer.rb.co, lookat ); + } + else if( shop->type == k_skateshop_type_server ) + { + ent_prop *prop = af_arritm( &world->ent_prop, mdl_entity_id_id(shop->server.id_lever) ); + v3_sub( prop->transform.co, localplayer.rb.co, lookat ); } + else + vg_fatal_error( "Unknown store (%u)\n", shop->type ); - u32 npage = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; + q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f}, atan2f(lookat[0],lookat[2]) ); - if( opage != npage ){ - skateshop_update_viewpage(); - } - else if( cache_id && button_down( k_srbind_maccept )){ - vg_info( "chose board from skateshop (%u)\n", - global_skateshop.selected_board_id ); + vg_camera temp; + ent_camera_unpack( ref, &temp ); + world_set_entity_driven_camera( &temp ); - 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_netmsg_playeritem_board ); + /* input */ + if( shop->type == k_skateshop_type_boardshop ) + { + if( !vg_loader_availible() ) + return; - //world_entity_exit_modal(); - //world_entity_clear_focus(); - gui_helper_reset( k_gui_helper_mode_clear ); - return; - } - } - else if( shop->type == k_skateshop_type_charshop ) - { - if( !vg_loader_availible() ) return; + u16 cache_id = skateshop_selected_cache_id(); + _skateshop.helper_pick->greyed = !cache_id; - int changed = 0; - u32 valid_count = addon_count( k_addon_type_player, 0, ADDON_REG_HIDDEN ); + /* + * Controls + * ---------------------- + */ + u32 opage = _skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; - if( button_down( k_srbind_mleft ) ){ - if( global_skateshop.selected_player_id > 0 ){ - global_skateshop.selected_player_id --; + if( button_down( k_srbind_mleft ) ) + { + if( _skateshop.selected_board_id > 0 ) + _skateshop.selected_board_id --; } - else{ - global_skateshop.selected_player_id = valid_count-1; + + u32 valid_count = addon_count( k_addon_type_board, 0,0 ); + if( button_down( k_srbind_mright ) ) + { + if( _skateshop.selected_board_id+1 < valid_count ) + _skateshop.selected_board_id ++; } - changed = 1; - } + u32 npage = _skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX; - if( button_down( k_srbind_mright ) ){ - if( global_skateshop.selected_player_id+1 < valid_count ){ - global_skateshop.selected_player_id ++; + if( opage != npage ) + skateshop_update_viewpage(); + else if( cache_id && button_down( k_srbind_maccept )) + { + vg_info( "chose board from skateshop (%u)\n", _skateshop.selected_board_id ); + + 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_netmsg_playeritem_board ); + gui_helper_reset( k_gui_helper_mode_clear ); + skateshop_playermod( 0 ); + _skateshop.open = 0; + return; } - else{ - global_skateshop.selected_player_id = 0; + } + else if( shop->type == k_skateshop_type_charshop ) + { + if( !vg_loader_availible() ) + return; + + int changed = 0; + u32 valid_count = addon_count( k_addon_type_player, 0, ADDON_REG_HIDDEN ); + + if( button_down( k_srbind_mleft ) ) + { + if( _skateshop.selected_player_id > 0 ) + _skateshop.selected_player_id --; + else + _skateshop.selected_player_id = valid_count-1; + + changed = 1; } - changed = 1; - } + if( button_down( k_srbind_mright ) ) + { + if( _skateshop.selected_player_id+1 < valid_count ) + _skateshop.selected_player_id ++; + else + _skateshop.selected_player_id = 0; - if( changed ) - { - addon_reg *addon = get_addon_from_index( k_addon_type_player, global_skateshop.selected_player_id, - 0, ADDON_REG_HIDDEN ); - u32 real_id = get_index_from_addon( k_addon_type_player, addon,0,0 ); + changed = 1; + } - player__use_model( real_id ); - } + if( changed ) + { + addon_reg *addon = get_addon_from_index( k_addon_type_player, _skateshop.selected_player_id, + 0, ADDON_REG_HIDDEN ); + u32 real_id = get_index_from_addon( k_addon_type_player, addon,0,0 ); + player__use_model( real_id ); + } - if( button_down( k_srbind_maccept ) ){ - network_send_item( k_netmsg_playeritem_player ); - //world_entity_exit_modal(); - //world_entity_clear_focus(); - gui_helper_reset( k_gui_helper_mode_clear ); + if( button_down( k_srbind_maccept ) ) + { + network_send_item( k_netmsg_playeritem_player ); + gui_helper_reset( k_gui_helper_mode_clear ); + skateshop_playermod( 0 ); + _skateshop.open = 0; + } } - } - else if( shop->type == k_skateshop_type_worldshop ) - { + else if( shop->type == k_skateshop_type_worldshop ) + { #if 0 - int browseable = 0, - loadable = 0; + int browseable = 0, + loadable = 0; - u32 valid_count = addon_count( k_addon_type_world, ADDON_REG_HIDDEN ); + u32 valid_count = addon_count( k_addon_type_world, ADDON_REG_HIDDEN ); - if( valid_count && vg_loader_availible() ) - browseable = 1; + if( valid_count && vg_loader_availible() ) + browseable = 1; - if( valid_count && vg_loader_availible() ) - loadable = 1; + if( valid_count && vg_loader_availible() ) + loadable = 1; - global_skateshop.helper_browse->greyed = !browseable; - global_skateshop.helper_pick->greyed = !loadable; - - addon_reg *selected_world = NULL; + _skateshop.helper_browse->greyed = !browseable; + _skateshop.helper_pick->greyed = !loadable; + + addon_reg *selected_world = NULL; - int change = 0; - if( browseable ){ - if( button_down( k_srbind_mleft ) ){ - if( global_skateshop.selected_world_id > 0 ){ - global_skateshop.selected_world_id --; - change = 1; + int change = 0; + if( browseable ){ + if( button_down( k_srbind_mleft ) ){ + if( _skateshop.selected_world_id > 0 ){ + _skateshop.selected_world_id --; + change = 1; + } } - } - if( button_down( k_srbind_mright ) ){ - if( global_skateshop.selected_world_id+1 < valid_count ){ - global_skateshop.selected_world_id ++; - change = 1; + if( button_down( k_srbind_mright ) ){ + if( _skateshop.selected_world_id+1 < valid_count ){ + _skateshop.selected_world_id ++; + change = 1; + } } - } - selected_world = get_addon_from_index( k_addon_type_world, - global_skateshop.selected_world_id, ADDON_REG_HIDDEN ); + selected_world = get_addon_from_index( k_addon_type_world, + _skateshop.selected_world_id, ADDON_REG_HIDDEN ); - if( change || (global_skateshop.reg_preview == NULL) ){ - SDL_AtomicLock( &addon_system.sl_cache_using_resources ); - global_skateshop.reg_preview = selected_world; - SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + if( change || (_skateshop.reg_preview == NULL) ){ + SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + _skateshop.reg_preview = selected_world; + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + } } - } - if( loadable ) - { - if( button_down( k_srbind_maccept ) ) + if( loadable ) { - skaterift_switch_world_start( selected_world ); + if( button_down( k_srbind_maccept ) ) + { + skaterift_switch_world_start( selected_world ); + } } - } #endif - } - else if( shop->type == k_skateshop_type_server ){ - f64 delta = vg.time_real - network_client.last_intent_change; - - if( (delta > 5.0) && (!skaterift.demo_mode) ){ - global_skateshop.helper_pick->greyed = 0; - if( button_down( k_srbind_maccept ) ){ - network_client.user_intent = !network_client.user_intent; - network_client.last_intent_change = vg.time_real; - skateshop_server_helper_update(); - render_server_status_gui(); - } } - else { - global_skateshop.helper_pick->greyed = 1; + else if( shop->type == k_skateshop_type_server ) + { + f64 delta = vg.time_real - network_client.last_intent_change; + + if( (delta > 5.0) && (!skaterift.demo_mode) ) + { + _skateshop.helper_pick->greyed = 0; + if( button_down( k_srbind_maccept ) ) + { + network_client.user_intent = !network_client.user_intent; + network_client.last_intent_change = vg.time_real; + skateshop_server_helper_update(); + render_server_status_gui(); + } + } + else + _skateshop.helper_pick->greyed = 1; } + else + vg_fatal_error( "Unknown store (%u)\n", shop->type ); } - else{ - vg_fatal_error( "Unknown store (%u)\n", shop->type ); - } - - if( button_down( k_srbind_mback ) ) + else { - if( shop->type == k_skateshop_type_charshop ) - network_send_item( k_netmsg_playeritem_player ); + if( vg_loader_availible() ) + { + if( button_down( k_srbind_use ) ) + { + ent_skateshop *shop = _skateshop.current_shop; + if( shop->type == k_skateshop_type_boardshop ) + { + skateshop_update_viewpage(); + vg_loader_start( board_scan_thread, NULL ); + } -#if 0 - world_entity_exit_modal(); - world_entity_clear_focus(); -#endif - gui_helper_reset( k_gui_helper_mode_clear ); - return; + gui_helper_reset( k_gui_helper_mode_clear ); + ent_skateshop_helpers_pickable( "Pick" ); + _skateshop.open = 1; + + skateshop_playermod( 1 ); + } + } } } +#if 0 void skateshop_world_preupdate(void) { world_instance *world = &_world.main; @@ -457,11 +489,12 @@ void skateshop_world_preupdate(void) } } } +#endif -static void skateshop_render_boardshop( ent_skateshop *shop ) +static void skateshop_render_boardshop( ent_skateshop *shop, vg_camera *cam ) { world_instance *world = &_world.main; - u32 slot_count = VG_ARRAY_LEN(global_skateshop.shop_view_slots); + u32 slot_count = VG_ARRAY_LEN(_skateshop.shop_view_slots); ent_marker *mark_rack = af_arritm( &world->ent_marker, mdl_entity_id_id(shop->boards.id_rack)), @@ -472,8 +505,9 @@ static void skateshop_render_boardshop( ent_skateshop *shop ) struct addon_cache *cache = &addon_system.cache[k_addon_type_board]; /* Render loaded boards in the view slots */ - for( u32 i=0; icache_id ) @@ -494,7 +528,7 @@ static void skateshop_render_boardshop( ent_skateshop *shop ) mdl_transform_mul( &mark_rack->transform, &xform, &xform ); - if( entry->reg_index == global_skateshop.selected_board_id ){ + if( entry->reg_index == _skateshop.selected_board_id ){ selected = 1.0f; } @@ -506,8 +540,7 @@ static void skateshop_render_boardshop( ent_skateshop *shop ) struct player_board_pose pose = {0}; m4x3f mmdl; mdl_transform_m4x3( &xform, mmdl ); - render_board( &g_render.cam, world, board, mmdl, - &pose, k_board_shader_entity ); + render_board( cam, world, board, mmdl, &pose, k_board_shader_entity ); fade_out:; float rate = 5.0f*vg.time_delta; @@ -526,7 +559,7 @@ fade_out:; float scale = 0.2f, thickness = 0.03f; - font3d_bind( &gui.font, k_font_shader_default, 0, world, &g_render.cam ); + font3d_bind( &gui.font, k_font_shader_default, 0, world, cam ); shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} ); /* Selection counter @@ -540,17 +573,18 @@ fade_out:; m4x3_mul( mrack, mlocal, mmdl ); u32 valid_count = addon_count(k_addon_type_board,0,0); - if( valid_count ){ + if( valid_count ) + { char buf[16]; vg_str str; vg_strnull( &str, buf, sizeof(buf) ); - vg_strcati32( &str, global_skateshop.selected_board_id+1 ); + vg_strcati32( &str, _skateshop.selected_board_id+1 ); vg_strcatch( &str, '/' ); vg_strcati32( &str, valid_count ); - font3d_simple_draw( 0, buf, &g_render.cam, mmdl ); + font3d_simple_draw( 0, buf, cam, mmdl ); } else{ - font3d_simple_draw( 0, "Nothing installed", &g_render.cam, mmdl ); + font3d_simple_draw( 0, "Nothing installed", cam, mmdl ); } u16 cache_id = skateshop_selected_cache_id(); @@ -559,74 +593,73 @@ fade_out:; if( entry ) reg = entry->reg_ptr; - if( !reg ){ + if( !reg ) + { SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); - global_skateshop.render.item_title = ""; - global_skateshop.render.item_desc = ""; + _skateshop.render.item_title = ""; + _skateshop.render.item_desc = ""; return; } - if( global_skateshop.render.reg_id != global_skateshop.selected_board_id ){ - global_skateshop.render.item_title = ""; - global_skateshop.render.item_desc = ""; + if( _skateshop.render.reg_id != _skateshop.selected_board_id ) + { + _skateshop.render.item_title = ""; + _skateshop.render.item_desc = ""; vg_msg msg; vg_msg_init( &msg, reg->metadata, reg->metadata_len ); if( vg_msg_seekframe( &msg, "workshop" ) ){ const char *title = vg_msg_getkvstr( &msg, "title" ); - if( title ) global_skateshop.render.item_title = title; + if( title ) _skateshop.render.item_title = title; const char *dsc = vg_msg_getkvstr( &msg, "author" ); - if( dsc ) global_skateshop.render.item_desc = dsc; + if( dsc ) _skateshop.render.item_desc = dsc; vg_msg_skip_frame( &msg ); } - global_skateshop.render.reg_id = global_skateshop.selected_board_id; + _skateshop.render.reg_id = _skateshop.selected_board_id; } /* Skin title * ----------------------------------------------------------------- */ m3x3_zero( mlocal ); m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } ); - mlocal[3][0] = -font3d_string_width( 0, global_skateshop.render.item_title ); + mlocal[3][0] = -font3d_string_width( 0, _skateshop.render.item_title ); mlocal[3][0] *= scale*0.5f; mlocal[3][1] = 0.1f; mlocal[3][2] = 0.0f; m4x3_mul( mtext, mlocal, mmdl ); - font3d_simple_draw( 0, global_skateshop.render.item_title, - &g_render.cam, mmdl ); + font3d_simple_draw( 0, _skateshop.render.item_title, cam, mmdl ); /* Author name * ----------------------------------------------------------------- */ scale *= 0.4f; m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } ); - mlocal[3][0] = -font3d_string_width( 0, global_skateshop.render.item_desc ); + mlocal[3][0] = -font3d_string_width( 0, _skateshop.render.item_desc ); mlocal[3][0] *= scale*0.5f; mlocal[3][1] = 0.0f; mlocal[3][2] = 0.0f; m4x3_mul( mtext, mlocal, mmdl ); - font3d_simple_draw( 0, global_skateshop.render.item_desc, - &g_render.cam, mmdl ); + font3d_simple_draw( 0, _skateshop.render.item_desc, cam, mmdl ); SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); } -static void skateshop_render_charshop( ent_skateshop *shop ){ +static void skateshop_render_charshop( ent_skateshop *shop, vg_camera *cam ) +{ } -static void skateshop_render_worldshop( ent_skateshop *shop ){ +static void skateshop_render_worldshop( ent_skateshop *shop, vg_camera *cam ) +{ world_instance *world = &_world.main; - ent_marker *mark_display = af_arritm( &world->ent_marker, - mdl_entity_id_id(shop->worlds.id_display)), - *mark_info = af_arritm( &world->ent_marker, - mdl_entity_id_id(shop->boards.id_info)); - - if( global_skateshop.render.world_reg != global_skateshop.selected_world_id){ - global_skateshop.render.world_title = "missing: workshop.title"; + ent_marker *mark_display = af_arritm( &world->ent_marker, mdl_entity_id_id(shop->worlds.id_display)), + *mark_info = af_arritm( &world->ent_marker, mdl_entity_id_id(shop->boards.id_info)); - addon_reg *reg = get_addon_from_index( k_addon_type_world, - global_skateshop.selected_world_id, 0, ADDON_REG_HIDDEN ); + if( _skateshop.render.world_reg != _skateshop.selected_world_id) + { + _skateshop.render.world_title = "missing: workshop.title"; + addon_reg *reg = get_addon_from_index( k_addon_type_world, _skateshop.selected_world_id, 0, ADDON_REG_HIDDEN ); if( !reg ) goto none; @@ -636,21 +669,19 @@ static void skateshop_render_worldshop( ent_skateshop *shop ){ vg_msg msg; vg_msg_init( &msg, reg->metadata, reg->metadata_len ); - global_skateshop.render.world_loc = vg_msg_getkvstr(&msg,"location"); - global_skateshop.render.world_reg = global_skateshop.selected_world_id; + _skateshop.render.world_loc = vg_msg_getkvstr(&msg,"location"); + _skateshop.render.world_reg = _skateshop.selected_world_id; if( vg_msg_seekframe( &msg, "workshop" ) ) { - global_skateshop.render.world_title = vg_msg_getkvstr(&msg,"title"); + _skateshop.render.world_title = vg_msg_getkvstr(&msg,"title"); vg_msg_skip_frame( &msg ); } - else { + else vg_warn( "No workshop body\n" ); - } - } - else { - global_skateshop.render.world_title = reg->alias.foldername; } + else + _skateshop.render.world_title = reg->alias.foldername; } none:; @@ -664,11 +695,11 @@ none:; u32 valid_count = addon_count(k_addon_type_world,0,ADDON_REG_HIDDEN); if( valid_count ) { - vg_strcati32( &info, global_skateshop.selected_world_id+1 ); + vg_strcati32( &info, _skateshop.selected_world_id+1 ); vg_strcatch( &info, '/' ); vg_strcati32( &info, valid_count ); vg_strcatch( &info, ' ' ); - vg_strcat( &info, global_skateshop.render.world_title ); + vg_strcat( &info, _skateshop.render.world_title ); if( !vg_loader_availible() ) { @@ -676,13 +707,12 @@ none:; } else { - addon_reg *reg = get_addon_from_index( k_addon_type_world, - global_skateshop.selected_world_id, 0, ADDON_REG_HIDDEN ); + addon_reg *reg = get_addon_from_index( k_addon_type_world, _skateshop.selected_world_id, 0, ADDON_REG_HIDDEN ); if( reg->alias.workshop_id ) vg_strcat( &subtext, "(Workshop) " ); - vg_strcat( &subtext, global_skateshop.render.world_loc ); + vg_strcat( &subtext, _skateshop.render.world_loc ); } } else @@ -693,7 +723,7 @@ none:; m4x3f mtext,mlocal,mtextmdl; mdl_transform_m4x3( &mark_info->transform, mtext ); - font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &g_render.cam ); + font3d_bind( &gui.font, k_font_shader_default, 0, NULL, cam ); shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} ); float scale = 0.2f, thickness = 0.015f, scale1 = 0.08f; @@ -704,165 +734,110 @@ none:; mlocal[3][1] = 0.1f; mlocal[3][2] = 0.0f; m4x3_mul( mtext, mlocal, mtextmdl ); - font3d_simple_draw( 0, buftext, &g_render.cam, mtextmdl ); + font3d_simple_draw( 0, buftext, cam, mtextmdl ); m3x3_setdiagonalv3( mlocal, (v3f){ scale1, scale1, thickness } ); mlocal[3][0] = -font3d_string_width( 0, bufsubtext ); mlocal[3][0] *= scale1*0.5f; mlocal[3][1] = -scale1*0.3f; m4x3_mul( mtext, mlocal, mtextmdl ); - font3d_simple_draw( 0, bufsubtext, &g_render.cam, mtextmdl ); + font3d_simple_draw( 0, bufsubtext, cam, mtextmdl ); } -/* - * World: render event - */ -void skateshop_render( ent_skateshop *shop ) +void ent_skateshop_render( vg_camera *cam ) { - if( shop->type == k_skateshop_type_boardshop ) - skateshop_render_boardshop( shop ); - else if( shop->type == k_skateshop_type_charshop ) - skateshop_render_charshop( shop ); - else if( shop->type == k_skateshop_type_worldshop ) - skateshop_render_worldshop( shop ); - else if( shop->type == k_skateshop_type_server ){ - } - else - vg_fatal_error( "Unknown store (%u)\n", shop->type ); -} + bool dont_render_ghost = 0; -void skateshop_render_nonfocused( world_instance *world, vg_camera *cam ) -{ - for( u32 j=0; jent_skateshop ); j ++ ) + if( _world.event == k_world_event_shop ) { - ent_skateshop *shop = af_arritm(&world->ent_skateshop, j ); - - if( shop->type != k_skateshop_type_boardshop ) continue; - - f32 dist2 = v3_dist2( cam->pos, shop->transform.co ), - maxdist = 50.0f; + if( _skateshop.open ) + { + ent_skateshop *shop = _skateshop.current_shop; + if( shop->type == k_skateshop_type_boardshop ) + skateshop_render_boardshop( shop, cam ); + else if( shop->type == k_skateshop_type_charshop ) + skateshop_render_charshop( shop, cam ); + else if( shop->type == k_skateshop_type_worldshop ) + skateshop_render_worldshop( shop, cam ); + else if( shop->type == k_skateshop_type_server ){ + } + else + vg_fatal_error( "Unknown store (%u)\n", shop->type ); - if( dist2 > maxdist*maxdist ) continue; - ent_marker *mark_rack = af_arritm( &world->ent_marker, - mdl_entity_id_id(shop->boards.id_rack)); + dont_render_ghost = 1; + } + } - if( !mark_rack ) - continue; + if( dont_render_ghost == 0 ) + { + world_instance *world = &_world.main; - u32 slot_count = VG_ARRAY_LEN(global_skateshop.shop_view_slots); - for( u32 i=0; ient_skateshop ); j ++ ) { - struct player_board *board = &localplayer.fallback_board; - - mdl_transform xform; - transform_identity( &xform ); + ent_skateshop *shop = af_arritm(&world->ent_skateshop, j ); - xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f; - mdl_transform_mul( &mark_rack->transform, &xform, &xform ); + if( shop->type != k_skateshop_type_boardshop ) + continue; - struct player_board_pose pose = {0}; - m4x3f mmdl; - mdl_transform_m4x3( &xform, mmdl ); - render_board( cam, world, board, mmdl, &pose, k_board_shader_entity ); - } - } -} - -static void ent_skateshop_helpers_pickable( const char *acceptance ) -{ - vg_str text; + f32 dist2 = v3_dist2( cam->pos, shop->transform.co ), + maxdist = 50.0f; - if( gui_new_helper( input_button_list[k_srbind_mback], &text )) - vg_strcat( &text, "Exit" ); + if( dist2 > maxdist*maxdist ) continue; + ent_marker *mark_rack = af_arritm( &world->ent_marker, mdl_entity_id_id(shop->boards.id_rack)); - if( (global_skateshop.helper_pick = gui_new_helper( - input_button_list[k_srbind_maccept], &text))){ - vg_strcat( &text, acceptance ); - } + if( !mark_rack ) + continue; - if( (global_skateshop.helper_browse = gui_new_helper( - input_axis_list[k_sraxis_mbrowse_h], &text ))){ - vg_strcat( &text, "Browse" ); - } -} + u32 slot_count = VG_ARRAY_LEN(_skateshop.shop_view_slots); + for( u32 i=0; itransform, &xform, &xform ); -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 ); + struct player_board_pose pose = {0}; + m4x3f mmdl; + mdl_transform_m4x3( &xform, mmdl ); + render_board( cam, world, board, mmdl, &pose, k_board_shader_entity ); + } + } + } } -/* - * Entity logic: entrance event - */ entity_call_result ent_skateshop_call( world_instance *world, ent_call *call ) { u32 index = mdl_entity_id_id( call->id ); ent_skateshop *shop = af_arritm( &world->ent_skateshop, index ); - vg_info( "skateshop_call\n" ); - if( (skaterift.activity != k_skaterift_default) || - !vg_loader_availible() ) - return k_entity_call_result_invalid; - - if( call->function == k_ent_function_trigger ) + if( call->function == 0 ) /* view() */ { - if( localplayer.subsystem != k_player_subsystem_walk ) - return k_entity_call_result_OK; - - vg_info( "Entering skateshop\n" ); - -#if 0 - world_entity_set_focus( call->id ); - world_entity_focus_modal(); -#endif - gui_helper_reset( k_gui_helper_mode_black_bars ); - - if( shop->type == k_skateshop_type_boardshop ) + if( localplayer.subsystem == k_player_subsystem_walk ) { - skateshop_update_viewpage(); - vg_loader_start( board_scan_thread, NULL ); - ent_skateshop_helpers_pickable( "Pick" ); - } - else if( shop->type == k_skateshop_type_charshop ) - { - ent_skateshop_helpers_pickable( "Pick" ); - } - else if( shop->type == k_skateshop_type_worldshop ) - { - ent_skateshop_helpers_pickable( "Open rift" ); - vg_loader_start( world_scan_thread, NULL ); + if( world_set_event( k_world_event_shop ) ) + { + _skateshop.current_shop = shop; + gui_helper_reset( k_gui_helper_mode_black_bars ); + + vg_str text; + if( gui_new_helper( input_button_list[k_srbind_use], &text )) + vg_strcat( &text, "Open Shop" ); + } } - else if( shop->type == k_skateshop_type_server ) + return k_entity_call_result_OK; + } + else if( call->function == -1 ) /* unview() */ + { + if( world_clear_event( k_world_event_shop ) ) { - vg_str text; - global_skateshop.helper_pick = gui_new_helper( - input_button_list[k_srbind_maccept], &text); - if( gui_new_helper( input_button_list[k_srbind_mback], &text )) - vg_strcat( &text, "exit" ); - skateshop_server_helper_update(); + _skateshop.current_shop = NULL; + gui_helper_reset( k_gui_helper_mode_clear ); } return k_entity_call_result_OK; } - else + else return k_entity_call_result_unhandled; } diff --git a/src/ent_skateshop.h b/src/ent_skateshop.h index 9dad972..c3a869d 100644 --- a/src/ent_skateshop.h +++ b/src/ent_skateshop.h @@ -38,16 +38,18 @@ struct global_skateshop struct gui_helper *helper_browse; - addon_reg *reg_preview, *reg_loaded_preview; GLuint tex_preview; + + ent_skateshop *current_shop; + bool open; } -extern global_skateshop; +extern _skateshop; void skateshop_init(void); -void ent_skateshop_preupdate( ent_focus_context *ctx ); -void skateshop_render( ent_skateshop *shop ); -void skateshop_render_nonfocused( world_instance *world, vg_camera *cam ); +void ent_skateshop_update(void); +void ent_skateshop_render( vg_camera *cam ); + void skateshop_autostart_loading(void); void skateshop_world_preupdate(void); entity_call_result ent_skateshop_call( world_instance *world, ent_call *call ); diff --git a/src/entity.c b/src/entity.c index dad26d2..ea4c388 100644 --- a/src/entity.c +++ b/src/entity.c @@ -14,6 +14,9 @@ #include +/* + * TODO: Does this really need to take a world parameter, now that we're only using one world? + */ void entity_call( world_instance *world, ent_call *call ) { u32 type = mdl_entity_id_type( call->id ), diff --git a/src/input.h b/src/input.h index ff912c1..2eefc26 100644 --- a/src/input.h +++ b/src/input.h @@ -14,6 +14,7 @@ enum sr_bind k_srbind_trick1, k_srbind_trick2, k_srbind_sit, + k_srbind_skate, k_srbind_use, k_srbind_reset, k_srbind_dead_respawn, @@ -78,7 +79,8 @@ static vg_input_op *input_button_list[] = { vg_mouse, SDL_BUTTON_LEFT, vg_mode_mul, vg_mouse, SDL_BUTTON_RIGHT, vg_mode_absmax, vg_joy_button, SDL_CONTROLLER_BUTTON_X, vg_end }, -[k_srbind_use] = INPUT_BASIC( SDLK_e, SDL_CONTROLLER_BUTTON_Y ), +[k_srbind_skate] = INPUT_BASIC( SDLK_e, SDL_CONTROLLER_BUTTON_Y ), +[k_srbind_use] = INPUT_BASIC( SDLK_e, SDL_CONTROLLER_BUTTON_X ), [k_srbind_reset] = INPUT_BASIC( SDLK_r, SDL_CONTROLLER_BUTTON_DPAD_LEFT ), [k_srbind_dead_respawn] = INPUT_BASIC( SDLK_q, SDL_CONTROLLER_BUTTON_DPAD_UP ), diff --git a/src/player_skate.c b/src/player_skate.c index c75b7cc..8d0e086 100644 --- a/src/player_skate.c +++ b/src/player_skate.c @@ -1247,7 +1247,8 @@ void player__skate_pre_update(void){ else return; } - if( button_down(k_srbind_use) && (v3_length2(state->trick_vel) < 0.01f) ){ + if( button_down(k_srbind_skate) && (v3_length2(state->trick_vel) < 0.01f) ) + { localplayer.subsystem = k_player_subsystem_walk; if( (state->activity <= k_skate_activity_air_to_grind) && diff --git a/src/player_walk.c b/src/player_walk.c index 4a19079..b267ea8 100644 --- a/src/player_walk.c +++ b/src/player_walk.c @@ -284,41 +284,46 @@ static void player_walk_pre_sit_up(void){ return; } -static void player_walk_pre_ground(void){ +static void player_walk_pre_ground(void) +{ struct player_walk *w = &player_walk; - if( button_down(k_srbind_sit) ){ + if( button_down(k_srbind_sit) ) + { v3_zero( localplayer.rb.v ); w->state.activity = k_walk_activity_sit; w->state.transition_t = 0.0f; return; } - if( button_down( k_srbind_use ) ){ - if( player_walk_scan_for_drop_in() ){ + if( button_down( k_srbind_skate ) ) + { + if( player_walk_scan_for_drop_in() ) w->state.activity = k_walk_activity_odrop_in; - } - else{ + else w->state.activity = k_walk_activity_oregular; - } w->state.transition_t = 0.0f; } - if( button_down( k_srbind_jump ) ){ + if( button_down( k_srbind_jump ) ) + { w->state.jump_queued = 1; w->state.jump_input_time = vg.time; } } -static void player_walk_pre_air(void){ +static void player_walk_pre_air(void) +{ struct player_walk *w = &player_walk; - if( button_down( k_srbind_use ) ){ + if( button_down( k_srbind_skate ) ) + { w->state.activity = k_walk_activity_oair; w->state.transition_t = 0.0f; } - if( button_down( k_srbind_jump ) ){ + if( button_down( k_srbind_jump ) ) + { w->state.jump_queued = 1; w->state.jump_input_time = vg.time; } diff --git a/src/skaterift.c b/src/skaterift.c index 0bee2f3..5d2f4ed 100644 --- a/src/skaterift.c +++ b/src/skaterift.c @@ -195,27 +195,11 @@ void vg_pre_update(void) if( skaterift.activity & k_skaterift_replay ) target = 0; - v3f listen_co; - v3_copy( localplayer.rb.co, listen_co ); - - if( skaterift.activity & k_skaterift_menu ) - { - if( menu.bg_cam ) - { - v3_copy( menu.bg_cam->co, listen_co ); - } - else target = 0; - } - vg_slewf( &skaterift.time_rate, target, vg.time_frame_delta * (1.0f/0.3f) ); vg.time_rate = vg_smoothstepf( skaterift.time_rate ); + world_update( &_world.main, localplayer.rb.co ); cutscene_update( vg.time_rate * vg.time_frame_delta ); - - /* TODO: how can we compress this? */ - ent_miniworld_preupdate(); - world_events_update(); - //world_entity_focus_preupdate(); if( skaterift.activity != k_skaterift_menu ) { @@ -224,9 +208,17 @@ void vg_pre_update(void) skaterift_replay_pre_update(); remote_sfx_pre_update(); - skateshop_world_preupdate(); - world_update( &_world.main, localplayer.rb.co ); + v3f listen_co; + v3_copy( localplayer.rb.co, listen_co ); + if( skaterift.activity & k_skaterift_menu ) + { + if( menu.bg_cam ) + { + v3_copy( menu.bg_cam->co, listen_co ); + } + else target = 0; + } audio_ambient_sprites_update( &_world.main, listen_co ); } @@ -309,17 +301,27 @@ static void render_scene(void) { } -m4x3f *_TEMP_VAR = NULL; +m4x3f *_TEMP_VAR = NULL; /*FIXME*/ static void skaterift_composite_maincamera(void) { -#if 0 - vg_camera_lerp( &localplayer.cam, &_world.focus_cam, - vg_smoothstepf(_world.focus_strength), &g_render.cam ); -#endif - - vg_camera_copy( &localplayer.cam, &g_render.cam ); + /* world entity driven camera + * ------------------------------------------------------------------------------ */ + if( _world.entity_set_camera ) + { + _world.entity_set_camera = 0; + _world.entity_camera_modulate = vg_minf( 1.0f, _world.entity_camera_modulate+vg.time_frame_delta ); + } + else + { + _world.entity_camera_modulate = vg_maxf( 0.0f, _world.entity_camera_modulate-vg.time_frame_delta ); + } + + vg_camera_lerp( &localplayer.cam, &_world.entity_driven_camera, + vg_smoothstepf(_world.entity_camera_modulate), &g_render.cam ); + /* replay camera + * ------------------------------------------------------------------ */ if( skaterift.activity == k_skaterift_replay ) { if( player_replay.use_freecam ) @@ -338,11 +340,15 @@ static void skaterift_composite_maincamera(void) g_render.cam.nearz = 0.1f; g_render.cam.farz = 2100.0f; + /* menu override camera + * -------------------------------------------------------------------- */ if( (skaterift.activity == k_skaterift_menu) && menu.bg_cam ) { ent_camera_unpack( menu.bg_cam, &g_render.cam ); } + /* cutscene camera TODO: Fix the action camera + * ---------------------------------------------------------------- */ ent_camera *cs_cam = _cutscene_active_camera(); if( cs_cam ) ent_camera_unpack( cs_cam, &g_render.cam ); @@ -486,7 +492,9 @@ static void render_main_game(void) postprocess_to_screen( g_render.fb_main ); skaterift_replay_post_render(); - control_overlay_render(); + + if( gui.helper_count == 0 ) + control_overlay_render(); } void vg_render(void) @@ -608,7 +616,6 @@ void vg_framebuffer_resize( int w, int h ) #include "world_sfd.c" #include "world_volumes.c" #include "world_water.c" -#include "world_events.c" #include "array_file.c" #include "model.c" #include "metascene.c" diff --git a/src/world.c b/src/world.c index 382a9eb..bac09a9 100644 --- a/src/world.c +++ b/src/world.c @@ -38,16 +38,13 @@ void skaterift_world_get_save_path( addon_reg *world_reg, char buf[128] ) void world_update( world_instance *world, v3f pos ) { - world_render.sky_time += world_render.sky_rate * vg.time_delta; - world_render.sky_rate = vg_lerp( world_render.sky_rate, - world_render.sky_target_rate, - vg.time_delta * 5.0 ); - world_routes_update_timer_texts( world ); world_routes_update( world ); ent_traffic_update( world, pos ); world_sfd_update( world, pos ); world_volumes_update( world, pos ); + ent_skateshop_update(); + ent_challenge_update(); } bool world_set_event( enum world_event event ) @@ -60,8 +57,7 @@ bool world_set_event( enum world_event event ) } else { - vg_warn( "World event is currently: %d. " - "Switching to other event(%d) is not allowed. This is a BUG.\n", + vg_warn( "World event is currently: %d. Switching to other event(%d) is not allowed. This is a BUG.\n", _world.event, event ); return 0; } @@ -77,10 +73,14 @@ bool world_clear_event( enum world_event event ) } else { - vg_warn( "World event is currently: %d. " - "Unsetting by other event(%d) is not allowed. This is a BUG\n", + vg_warn( "World event is currently: %d. Unsetting by other event(%d) is not allowed. This is a BUG\n", _world.event, event ); return 0; } } +void world_set_entity_driven_camera( vg_camera *cam ) +{ + vg_camera_copy( cam, &_world.entity_driven_camera ); + _world.entity_set_camera = 1; +} diff --git a/src/world.h b/src/world.h index 89be65e..9683202 100644 --- a/src/world.h +++ b/src/world.h @@ -43,7 +43,6 @@ void skaterift_world_get_save_path( addon_reg *world_reg, char buf[128] ); #include "world_audio.h" #include "world_routes.h" #include "world_routes_ui.h" -#include "world_events.h" /* console variables */ @@ -266,6 +265,8 @@ struct world_static { k_world_event_none = 0, k_world_event_challenge, + k_world_event_shop, + k_world_event_route_leaderboard } event; @@ -275,6 +276,10 @@ struct world_static ent_objective *challenge_target; f32 challenge_timer; /* unused */ + + vg_camera entity_driven_camera; + bool entity_set_camera; + f32 entity_camera_modulate; } extern _world; @@ -285,3 +290,4 @@ void world_update( world_instance *world, v3f pos ); bool world_set_event( enum world_event activity ); bool world_clear_event( enum world_event activity ); +void world_set_entity_driven_camera( vg_camera *cam ); diff --git a/src/world_entity.h b/src/world_entity.h index a03b22e..edc85e1 100644 --- a/src/world_entity.h +++ b/src/world_entity.h @@ -4,19 +4,9 @@ #include "vg/vg_bvh.h" #include "vg/vg_msg.h" -typedef struct ent_focus_context ent_focus_context; -struct ent_focus_context -{ - world_instance *world; - u32 index; /* Array index of the focused entity */ - bool active; -}; - void world_gen_entities_init( world_instance *world ); -ent_spawn *world_find_spawn_by_name( world_instance *world, - const char *name ); -ent_spawn *world_find_closest_spawn( world_instance *world, - v3f position ); +ent_spawn *world_find_spawn_by_name( world_instance *world, const char *name ); +ent_spawn *world_find_closest_spawn( world_instance *world, v3f position ); void world_default_spawn_pos( world_instance *world, v3f pos ); void world_entity_start( world_instance *world, vg_msg *sav ); void world_entity_serialize( world_instance *world, vg_msg *sav ); @@ -29,20 +19,7 @@ void entity_bh_expand_bound( void *user, boxf bound, u32 item_index ); float entity_bh_centroid( void *user, u32 item_index, int axis ); void entity_bh_swap( void *user, u32 ia, u32 ib ); void entity_bh_debug( void *user, u32 item_index ); -void entity_bh_closest( void *user, u32 item_index, v3f point, - v3f closest ); - -#if 0 -void world_entity_set_focus( u32 entity_id ); -void world_entity_focus_modal(void); - -void world_entity_exit_modal(void); -void world_entity_clear_focus(void); - -void world_entity_focus_preupdate(void); -void world_entity_focus_render(void); -void world_entity_focus_camera( world_instance *world, u32 uid ); -#endif +void entity_bh_closest( void *user, u32 item_index, v3f point, v3f closest ); void update_ach_models(void); diff --git a/src/world_events.c b/src/world_events.c deleted file mode 100644 index 5d5f46a..0000000 --- a/src/world_events.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "world.h" -#include "world_events.h" - -void world_events_update(void) -{ - if( _world.event == k_world_event_challenge ) - { - if( _world.challenge_running ) - { - } - else - { - ent_challenge *challenge = _world.active_challenge; - if( challenge->flags & k_ent_challenge_is_story ) - { - if( button_down( k_srbind_maccept ) ) - { - gui_helper_reset( k_gui_helper_mode_clear ); - ent_call call; - call.data = NULL; - call.function = challenge->target_event; - call.id = challenge->target; - entity_call( &_world.main, &call ); - } - } - else - { - /* activate the actual challenge blah blah */ - } - } - } -} diff --git a/src/world_events.h b/src/world_events.h deleted file mode 100644 index d8a77ee..0000000 --- a/src/world_events.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void world_events_update(void); diff --git a/src/world_load.c b/src/world_load.c index 6124964..244912d 100644 --- a/src/world_load.c +++ b/src/world_load.c @@ -463,6 +463,7 @@ void skaterift_load_world_start( addon_reg *reg, bool preview ) g_client.unreadyness ++; _world.loader_state = k_world_loader_saving_current; + _world.event = k_world_event_none; vg_loader_set_user_information( "Saving current world" ); } else diff --git a/src/world_render.c b/src/world_render.c index e91ee0c..49d941e 100644 --- a/src/world_render.c +++ b/src/world_render.c @@ -54,9 +54,6 @@ void world_render_init(void) vg_console_reg_cmd( "set_time", ccmd_set_time, NULL ); vg_console_reg_cmd( "render_portals", ccmd_render_portals, NULL ); - world_render.sky_rate = 1.0; - world_render.sky_target_rate = 1.0; - vg_info( "Loading world resources\n" ); vg_linear_clear( vg_mem.scratch ); @@ -852,7 +849,8 @@ static void render_sky( world_instance *world, vg_camera *cam ) /* * Draw */ - if( world->skybox == k_skybox_default ){ + if( world->skybox == k_skybox_default ) + { shader_model_sky_use(); shader_model_sky_uMdl( identity_matrix ); shader_model_sky_uPv( pv ); @@ -1119,9 +1117,8 @@ void render_world( world_instance *world, vg_camera *cam, if( !viewing_from_gate ) { -#if 0 - world_entity_focus_render(); -#endif + /* other entities */ + ent_skateshop_render( cam ); /* Render SFD's */ u32 closest = 0; diff --git a/src/world_render.h b/src/world_render.h index 2f0437e..f488bc5 100644 --- a/src/world_render.h +++ b/src/world_render.h @@ -33,8 +33,6 @@ struct world_render mdl_submesh skydome_complete_mesh, skydome_squanched_mesh; - double sky_time, sky_rate, sky_target_rate; - v3f render_gate_pos; struct timer_text{ char text[8]; -- 2.25.1