reset_event: bpy.props.IntProperty( name="Event/Method" )
time_limit: bpy.props.BoolProperty( name="Time Limit" )
+ is_story: bpy.props.BoolProperty( name="Is story event" )
first: bpy.props.PointerProperty( \
type=bpy.types.Object, name="First Objective", \
layout.prop( data[0], 'camera' )
layout.prop( data[0], 'first' )
layout.prop( data[0], 'time_limit' )
+ layout.prop( data[0], 'is_story' )
SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'target' )
SR_OBJECT_ENT_VOLUME.inspect_target( layout, data, 'reset' )
#}
challenge.flags = 0x00
challenge.camera = sr_entity_id( obj_data.camera )
if obj_data.time_limit: challenge.flags |= 0x01
+ if obj_data.is_story: challenge.flags |= 0x02
challenge.status = 0
sr_ent_push( challenge )
#}
foldername_djb2 = vg_strdjb2( alias->foldername );
u32 count = 0;
- for( u32 i=0; count<addon_system.registry_type_counts[alias->type]; i++ ){
+ for( u32 i=0; count<addon_system.registry_type_counts[alias->type]; i++ )
+ {
addon_reg *reg = &addon_system.registry[i];
- if( reg->alias.type == alias->type ){
-
- if( alias->workshop_id ){
+ if( reg->alias.type == alias->type )
+ {
+ if( alias->workshop_id )
+ {
if( alias->workshop_id == reg->alias.workshop_id )
return count;
}
- else{
- if( reg->foldername_hash == foldername_djb2 ){
- if( !strcmp( reg->alias.foldername, alias->foldername ) ){
+ else
+ {
+ if( reg->foldername_hash == foldername_djb2 )
+ {
+ if( !strcmp( reg->alias.foldername, alias->foldername ) )
return count;
- }
}
}
*/
void addon_alias_uid( addon_alias *alias, char buf[ADDON_UID_MAX] )
{
- if( alias->workshop_id ){
+ if( alias->workshop_id )
+ {
snprintf( buf, 128, "sr%03d-steam-"PRINTF_U64,
alias->type, alias->workshop_id );
}
- else {
+ else
+ {
snprintf( buf, 128, "sr%03d-local-%s",
alias->type, alias->foldername );
}
vg_pool *pool = &cache->pool;
u16 cache_id = addon_cache_fetch( type, reg_id );
- if( !cache_id ){
+ if( !cache_id )
+ {
cache_id = addon_cache_alloc( type, reg_id );
- if( cache_id ){
+ if( cache_id )
+ {
SDL_AtomicLock( &addon_system.sl_cache_using_resources );
addon_cache_entry *entry = vg_pool_item( pool, cache_id );
- if( entry->state == k_addon_cache_state_loaded ){
+ if( entry->state == k_addon_cache_state_loaded )
addon_cache_free_item( type, cache_id );
- }
entry->state = k_addon_cache_state_load_request;
SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
void *af_arritm( array_file_ptr *arr, u32 index )
{
+ if( index >= arr->count )
+ vg_fatal_error( "Index out of range (%u >= %u)\n", index, arr->count );
+
return ((u8 *)arr->data) + index*arr->stride;
}
struct game_client g_client =
{
- .demo_mode = 1
+ .demo_mode = 1,
+ .unreadyness = 2 /* once for client, once for world switcher */
};
static void async_client_ready( void *payload, u32 size )
{
- g_client.loaded = 1;
+ g_client.unreadyness --;
if( network_client.auto_connect )
network_client.user_intent = k_server_intent_online;
struct game_client
{
- bool loaded, demo_mode, nosteam;
+ bool demo_mode, nosteam;
+ u32 unreadyness;
}
extern g_client;
}
else if( call->function == 1 ) /* view() */
{
+ if( localplayer.subsystem == k_player_subsystem_walk )
+ {
+ if( world_set_event( k_world_event_challenge ) )
+ {
+ _world.active_challenge = challenge;
+ gui_helper_reset( 1 );
+ vg_str text;
+ if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
+ vg_strcat( &text, "Start" );
+ }
+ }
+
+ return k_entity_call_result_OK;
+ }
+ else if( call->function == -1 ) /* unview() */
+ {
+ if( world_clear_event( k_world_event_challenge ) )
+ {
+ _world.active_challenge = NULL;
+ gui_helper_reset( k_gui_helper_mode_clear );
+ }
+ return k_entity_call_result_OK;
+
+#if 0
if( (localplayer.subsystem == k_player_subsystem_walk) &&
- (world_static.challenge_target == NULL) )
+ (_world.challenge_target == NULL) )
{
- world_static.challenge_target = NULL;
+ _world.challenge_target = NULL;
world_entity_set_focus( call->id );
world_entity_focus_modal();
vg_strcat( &text, "Exit" );
}
return k_entity_call_result_OK;
+#endif
}
else
return k_entity_call_result_unhandled;
}
+#if 0
void ent_challenge_preupdate( ent_focus_context *ctx )
{
world_instance *world = ctx->world;
f32 max_dist = 100.0f;
if( min_dist2 > max_dist*max_dist ){
- world_static.challenge_target = NULL;
- world_static.challenge_timer = 0.0f;
+ _world.challenge_target = NULL;
+ _world.challenge_timer = 0.0f;
world_entity_clear_focus();
audio_lock();
audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co,
world_entity_focus_camera( world, challenge->camera );
- if( mdl_entity_id_type( challenge->first ) == k_ent_objective ){
- if( button_down( k_srbind_maccept ) ){
+ if( mdl_entity_id_type( challenge->first ) == k_ent_objective )
+ {
+ if( button_down( k_srbind_maccept ) )
+ {
u32 index = mdl_entity_id_id( challenge->first );
- world_static.challenge_target = af_arritm( &world->ent_objective,
+ _world.challenge_target = af_arritm( &world->ent_objective,
index );
- world_static.challenge_timer = 0.0f;
+ _world.challenge_timer = 0.0f;
world_entity_exit_modal();
gui_helper_clear();
return;
}
}
+ else
+ {
+ if( button_down( k_srbind_maccept ) )
+ {
+ ent_call call;
+ call.data = NULL;
+ call.function = challenge->target_event;
+ call.id = challenge->target;
+ entity_call( world, &call );
+ }
+ }
if( button_down( k_srbind_mback ) )
{
- world_static.challenge_target = NULL;
+ _world.challenge_target = NULL;
world_entity_exit_modal();
world_entity_clear_focus();
gui_helper_clear();
static void ent_challenge_render( ent_challenge *challenge ){
}
+#endif
#pragma once
#include "entity.h"
-void ent_challenge_preupdate( ent_focus_context *ctx );
entity_call_result ent_challenge_call( world_instance *world, ent_call *call );
entity_call_result ent_miniworld_call( world_instance *world, ent_call *call )
{
+#if 0
ent_miniworld *miniworld = af_arritm( &world->ent_miniworld,
mdl_entity_id_id(call->id) );
- int world_id = world - world_static.instances;
+ int world_id = world - _world.instances;
if( call->function == 0 ) /* zone() */
{
mdl_transform_m4x3( &miniworld->transform, global_miniworld.mmdl );
global_miniworld.active = miniworld;
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_black_bars );
vg_str text;
if( gui_new_helper( input_button_list[k_srbind_miniworld_resume], &text ))
else if( call->function == 1 )
{
global_miniworld.active = NULL;
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_clear );
if( miniworld->proxy )
{
return k_entity_call_result_OK;
}
else
+#endif
return k_entity_call_result_unhandled;
}
static void miniworld_icon( vg_camera *cam, enum gui_icon icon,
v3f pos, f32 size)
{
+#if 0
m4x3f mmdl;
v3_copy( cam->transform[2], mmdl[2] );
mmdl[2][1] = 0.0f;
mdl_submesh *sm = gui.icons[ icon ];
if( sm )
mdl_draw_submesh( sm );
+#endif
}
void ent_miniworld_render( world_instance *host_world, vg_camera *cam )
{
- if( host_world != &world_static.instances[k_world_purpose_hub] )
+#if 0
+ if( host_world != &_world.instances[k_world_purpose_hub] )
return;
ent_miniworld *miniworld = global_miniworld.active;
if( !miniworld )
return;
- world_instance *dest_world = &world_static.instances[k_world_purpose_client];
+ world_instance *dest_world = &_world.instances[k_world_purpose_client];
int rendering = 1;
if( dest_world->status != k_world_status_loaded )
shader_model_font_uColour( colour );
miniworld_icon( cam, k_gui_icon_rift_run, route->board_transform[3],1.0f);
}
+#endif
}
void ent_miniworld_preupdate(void)
{
+#if 0
world_instance *hub = world_current_instance(),
- *dest = &world_static.instances[k_world_purpose_client];
+ *dest = &_world.instances[k_world_purpose_client];
ent_miniworld *miniworld = global_miniworld.active;
if( (localplayer.subsystem != k_player_subsystem_walk) ||
(global_miniworld.transition) ||
- (world_static.active_instance != k_world_purpose_hub) ||
+ (_world.active_instance != k_world_purpose_hub) ||
(!miniworld) ||
(dest->status != k_world_status_loaded) ||
(skaterift.activity != k_skaterift_default)) {
{
if( skaterift.demo_mode )
{
- if( world_static.instance_addons[1]->flags & ADDON_REG_PREMIUM )
+ if( _world.instance_addons[1]->flags & ADDON_REG_PREMIUM )
{
menu_open( k_menu_page_premium );
return;
world_switch_instance(1);
srinput.state = k_input_state_resume;
menu.disable_open = 0;
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_clear );
audio_lock();
audio_oneshot( &audio_ui[2], 1.0f, 0.0f );
audio_unlock();
}
+#endif
}
void ent_miniworld_goback(void)
{
+#if 0
audio_lock();
audio_oneshot( &audio_ui[2], 1.0f, 0.0f );
audio_unlock();
global_miniworld.cam = g_render.cam;
vg_m4x3_transform_camera( global_miniworld.mmdl, &global_miniworld.cam );
world_switch_instance(0);
+#endif
}
+++ /dev/null
-#include "vg/vg_mem.h"
-#include "ent_npc.h"
-#include "shaders/model_character_view.h"
-#include "input.h"
-#include "player.h"
-#include "gui.h"
-
-struct npc npc_gumpa, npc_slowmo, npc_volc_flight;
-static struct skeleton_anim gumpa_idle;
-static struct skeleton_anim slowmo_momentum, slowmo_slide, slowmo_rewind,
- anim_tutorial_cam;
-static float slowmo_opacity = 0.0f;
-static f64 volc_start_preview = 0.0;
-
-void npc_load_model( struct npc *npc, const char *path )
-{
- vg_linear_clear( vg_mem.scratch );
-
- mdl_context *meta = &npc->meta;
- mdl_open( meta, path, vg_mem.rtmemory );
- mdl_load_metadata_block( meta, vg_mem.rtmemory );
-
- struct skeleton *sk = &npc->skeleton;
- skeleton_setup( sk, meta, 0, vg_mem.rtmemory );
-
- u32 mtx_size = sizeof(m4x3f)*sk->bone_count;
- npc->final_mtx = vg_linear_alloc( vg_mem.rtmemory, mtx_size );
-
- if( meta->texture_count )
- {
- mdl_texture *tex0 = &meta->textures[ 0 ];
- void *data = vg_linear_alloc( vg_mem.scratch, tex0->file.pack_size );
- mdl_fread_pack_file( meta, &tex0->file, data );
-
- vg_tex2d_load_qoi_async( data, tex0->file.pack_size,
- VG_TEX2D_NEAREST|VG_TEX2D_CLAMP,
- &npc->texture );
- }
- else
- {
- npc->texture = vg.tex_missing;
- }
-
- mdl_async_load_glmesh( meta, &npc->mesh, NULL );
- mdl_close( meta );
-}
-
-void npc_init(void)
-{
-#if 0
- npc_load_model( &npc_gumpa, "models/gumpa.mdl" );
- gumpa_idle = skeleton_get_anim( &npc_gumpa.skeleton, "gumpa_idle" );
-
- npc_load_model( &npc_slowmo, "models/slowmos.mdl" );
- slowmo_momentum =
- skeleton_get_anim( &npc_slowmo.skeleton, "slowmo_momentum" );
- slowmo_slide = skeleton_get_anim( &npc_slowmo.skeleton, "slowmo_slide" );
- slowmo_rewind = skeleton_get_anim( &npc_slowmo.skeleton, "slowmo_rewind" );
-
- npc_load_model( &npc_volc_flight, "models/volc_flight.mdl" );
- anim_tutorial_cam =
- skeleton_get_anim( &npc_volc_flight.skeleton, "tutorial" );
-#endif
-}
-
-static struct npc *npc_resolve( u32 id )
-{
- if( id == 1 ) return &npc_gumpa;
- else if( id == 2 ) return &npc_slowmo;
- else if( id == 3 ) return &npc_volc_flight;
- else return NULL;
-}
-
-static entity_call_result npc_slowmo_call( ent_npc *npc, ent_call *call )
-{
- return 0;
-
- if( call->function == 0 )
- {
- gui_helper_clear();
- vg_str text;
-
- if( npc->context == 2 )
- {
- if( gui_new_helper( input_axis_list[k_sraxis_grab], &text ))
- vg_strcat( &text, "Crouch (store energy)" );
- if( gui_new_helper( input_joy_list[k_srjoystick_steer], &text ))
- vg_strcat( &text, "Slide" );
- }
- else if( npc->context == 1 )
- {
- if( gui_new_helper( input_axis_list[k_sraxis_grab], &text ))
- vg_strcat( &text, "Crouch (store energy)" );
- }
- else if( npc->context == 3 )
- {
- if( gui_new_helper( input_button_list[k_srbind_reset], &text ))
- vg_strcat( &text, "Rewind time" );
- if( gui_new_helper( input_button_list[k_srbind_replay_resume], &text ))
- vg_strcat( &text, "Resume" );
- }
- return k_entity_call_result_OK;
- }
- else if( call->function == -1 )
- {
- world_entity_clear_focus();
- gui_helper_clear();
- return k_entity_call_result_OK;
- }
- else
- return k_entity_call_result_unhandled;
-}
-
-entity_call_result ent_npc_call( world_instance *world, ent_call *call )
-{
- return 0;
-
- u32 index = mdl_entity_id_id( call->id );
- ent_npc *npc = af_arritm( &world->ent_npc, index );
-
- if( npc->id == 2 )
- {
- return npc_slowmo_call( npc, call );
- }
- else if( npc->id == 3 )
- {
- if( call->function == 0 )
- {
- world_entity_set_focus( call->id );
- gui_helper_clear();
- vg_str text;
- if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
- vg_strcat( &text, "Preview course" );
- return k_entity_call_result_OK;
- }
- else if( call->function == -1 )
- {
- world_entity_clear_focus();
- gui_helper_clear();
- return k_entity_call_result_OK;
- }
- else
- return k_entity_call_result_unhandled;
- }
- else if( npc->id == 4 )
- {
- if( call->function == 0 )
- {
- gui_helper_clear();
- vg_str text;
- if( gui_new_helper( input_button_list[k_srbind_camera], &text ))
- vg_strcat( &text, "First/Thirdperson" );
- return k_entity_call_result_OK;
- }
- else if( call->function == -1 )
- {
- gui_helper_clear();
- return k_entity_call_result_OK;
- }
- else
- return k_entity_call_result_unhandled;
- }
- else
- {
- if( call->function == 0 )
- {
- world_entity_set_focus( call->id );
- gui_helper_clear();
- vg_str text;
- if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
- vg_strcat( &text, "Talk to ???" );
- return k_entity_call_result_OK;
- }
- else if( call->function == -1 )
- {
- world_entity_clear_focus();
- gui_helper_clear();
- return k_entity_call_result_OK;
- }
- else
- return k_entity_call_result_unhandled;
- }
-}
-
-void ent_npc_preupdate( ent_focus_context *ctx )
-{
- return;
-
- world_instance *world = ctx->world;
- ent_npc *ent = af_arritm( &world->ent_npc, ctx->index );
-
- if( !ctx->active )
- {
- if( button_down(k_srbind_maccept) )
- {
- world_entity_focus_modal();
- gui_helper_clear();
- vg_str text;
- if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
- vg_strcat( &text, "leave" );
-
- volc_start_preview = vg.time;
- }
-
- return;
- }
-
- if( ent->id == 3 )
- {
- player_pose pose;
- struct skeleton *sk = &npc_volc_flight.skeleton;
-
- f64 t = (vg.time - volc_start_preview) * 0.5;
- skeleton_sample_anim_clamped( sk, &anim_tutorial_cam, t, pose.keyframes );
-
-#if 0
- ent_camera *cam = af_arritm( &world->ent_camera,
- mdl_entity_id_id(ent->camera) );
- v3_copy( pose.keyframes[0].co, cam->co );
-
- v4f qp;
- q_axis_angle( qp, (v3f){1,0,0}, VG_TAUf*0.25f );
- q_mul( pose.keyframes[0].q, qp, cam->transform.q );
- q_normalize( cam->transform.q );
-
- v3_add( ent->transform.co, cam->transform.co, cam->transform.co );
-#endif
- }
-
- world_entity_focus_camera( world, ent->camera );
-
- if( button_down( k_srbind_mback ) )
- {
- world_entity_exit_modal();
- world_entity_clear_focus();
- gui_helper_clear();
- }
-}
-
-void npc_update( ent_npc *ent )
-{
- return;
-
- if( ent->id == 3 ) return;
- if( ent->id == 4 ) return;
-
- struct npc *npc_def = npc_resolve( ent->id );
- VG_ASSERT( npc_def );
-
- player_pose pose;
- struct skeleton *sk = &npc_def->skeleton;
- pose.type = k_player_pose_type_ik;
- pose.board.lean = 0.0f;
-
- if( ent->id == 1 )
- {
- skeleton_sample_anim( sk, &gumpa_idle, vg.time, pose.keyframes );
- }
- else if( ent->id == 2 )
- {
- struct skeleton_anim *anim = NULL;
- if( ent->context == 1 ) anim = &slowmo_momentum;
- else if( ent->context == 2 ) anim = &slowmo_slide;
- else if( ent->context == 3 ) anim = &slowmo_rewind;
-
- VG_ASSERT( anim );
-
- f32 t = vg.time*0.5f,
- animtime = fmodf( t*anim->framerate, anim->strip->length ),
- lt = animtime / (f32)anim->strip->length;
- skeleton_sample_anim( sk, anim, t, pose.keyframes );
- slowmo_opacity = vg_clampf(fabsf(lt-0.5f)*9.0f-3.0f,0,1);
- }
-
- v3_copy( ent->transform.co, pose.root_co );
- v4_copy( ent->transform.q, pose.root_q );
- apply_full_skeleton_pose( &npc_def->skeleton, &pose, npc_def->final_mtx );
-}
-
-void npc_render( ent_npc *ent, world_instance *world, vg_camera *cam )
-{
- return;
-
- if( ent->id == 3 ) return;
- if( ent->id == 4 ) return;
-
- struct npc *npc_def = npc_resolve( ent->id );
- VG_ASSERT( npc_def );
-
- shader_model_character_view_use();
-
- glActiveTexture( GL_TEXTURE0 );
- glBindTexture( GL_TEXTURE_2D, npc_def->texture );
- shader_model_character_view_uTexMain( 0 );
- shader_model_character_view_uCamera( cam->transform[3] );
- shader_model_character_view_uPv( cam->mtx.pv );
-
- if( ent->id == 2 )
- {
- shader_model_character_view_uDepthMode( 2 );
- shader_model_character_view_uDitherCutoff( slowmo_opacity );
- }
- else
- {
- shader_model_character_view_uDepthMode( 0 );
- }
-
- WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_character_view );
-
- glUniformMatrix4x3fv( _uniform_model_character_view_uTransforms,
- npc_def->skeleton.bone_count,
- 0,
- (const GLfloat *)npc_def->final_mtx );
-
- mesh_bind( &npc_def->mesh );
- mesh_draw( &npc_def->mesh );
-}
+++ /dev/null
-#pragma once
-#include "player_render.h"
-#include "entity.h"
-
-struct npc
-{
- glmesh mesh;
- GLuint texture;
-
- mdl_context meta;
- struct skeleton skeleton;
-
- m4x3f *final_mtx;
-}
-extern npc_gumpa;
-
-enum npc_id
-{
- k_npc_id_none = 0,
- k_npc_id_gumpa = 1
-};
-
-void npc_load_model( struct npc *npc, const char *path );
-void ent_npc_preupdate( ent_focus_context *context );
-entity_call_result ent_npc_call( world_instance *world, ent_call *call );
-void npc_update( ent_npc *ent );
-void npc_render( ent_npc *ent, world_instance *world, vg_camera *cam );
-void npc_init(void);
static void ent_objective_pass( world_instance *world,
ent_objective *objective ){
- if( objective->id_next ){
- world_static.challenge_timer += objective->filter;
-
+ if( objective->id_next )
+ {
u32 index = mdl_entity_id_id( objective->id_next );
ent_objective *next = af_arritm( &world->ent_objective, index );
- world_static.challenge_target = next;
+ _world.challenge_target = next;
objective->flags |= k_ent_objective_passed;
if( next->filter & k_ent_objective_filter_passthrough )
audio_lock();
audio_oneshot( &audio_challenge[2], 1.0f, 0.0f );
audio_unlock();
- world_static.challenge_target = NULL;
- world_static.challenge_timer = 0.0f;
- world_static.focused_entity = 0;
+ _world.challenge_target = NULL;
+ //_world.focused_entity = 0;
if( objective->id_win ){
ent_call call;
return k_entity_call_result_OK;
}
- if( world_static.challenge_target )
+ if( _world.challenge_target )
{
- if( (world_static.challenge_target == objective) &&
+ if( (_world.challenge_target == objective) &&
ent_objective_check_filter( objective )){
ent_objective_pass( world, objective );
}
30.0f, 1.0f );
audio_unlock();
vg_error( "challenge failed\n" );
- world_static.challenge_target = NULL;
- world_static.challenge_timer = 0.0f;
- world_static.focused_entity = 0;
+ _world.challenge_target = NULL;
+ //_world.focused_entity = 0;
}
}
}
}
- u32 instance_id = world - world_static.instances;
-
- if( world_static.instance_addons[instance_id]->flags & ADDON_REG_MTZERO ){
- if( world_total & k_ent_route_flag_achieve_gold ){
+ if( _world.main.addon->flags & ADDON_REG_MTZERO )
+ {
+ if( world_total & k_ent_route_flag_achieve_gold )
+ {
steam_set_achievement( "MTZERO_GOLD" );
steam_store_achievements();
}
- if( world_total & k_ent_route_flag_achieve_silver ){
+ if( world_total & k_ent_route_flag_achieve_silver )
+ {
steam_set_achievement( "MTZERO_SILVER" );
steam_store_achievements();
}
}
- if( world_static.instance_addons[instance_id]->flags & ADDON_REG_CITY ){
+ if( _world.main.addon->flags & ADDON_REG_CITY )
+ {
steam_set_achievement( "CITY_COMPLETE" );
steam_store_achievements();
}
{ /* view() */
if( localplayer.subsystem == k_player_subsystem_walk )
{
+#if 0
world_entity_set_focus( call->id );
world_entity_focus_modal();
if( gui_new_helper( input_button_list[k_srbind_mback], &text ) )
vg_strcat( &text, "Exit" );
+#endif
}
return k_entity_call_result_OK;
if( __builtin_expect( world->meta.version >= 103, 1 ) )
cam_id = route->id_camera;
- world_entity_focus_camera( world, cam_id );
+ //world_entity_focus_camera( world, cam_id );
if( button_down( k_srbind_mleft ) ){
world_sfd.view_weekly = 1;
if( button_down( k_srbind_mback ) )
{
- world_entity_exit_modal();
- world_entity_clear_focus();
- gui_helper_clear();
+ //world_entity_exit_modal();
+ //world_entity_clear_focus();
+ gui_helper_reset( k_gui_helper_mode_clear );
return;
}
}
/* 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
v3f lookat;
if( shop->type == k_skateshop_type_boardshop ||
q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f},
atan2f(lookat[0],lookat[2]) );
+#if 0
v3_copy( ref->co, world_static.focus_cam.pos );
world_static.focus_cam.fov = ref->fov;
+#endif
/* input */
if( shop->type == k_skateshop_type_boardshop ){
localplayer.board_view_slot = cache_id;
network_send_item( k_netmsg_playeritem_board );
- world_entity_exit_modal();
- world_entity_clear_focus();
- gui_helper_clear();
- skaterift_autosave(1);
+ //world_entity_exit_modal();
+ //world_entity_clear_focus();
+ gui_helper_reset( k_gui_helper_mode_clear );
return;
}
}
if( button_down( k_srbind_maccept ) ){
network_send_item( k_netmsg_playeritem_player );
- world_entity_exit_modal();
- world_entity_clear_focus();
- gui_helper_clear();
+ //world_entity_exit_modal();
+ //world_entity_clear_focus();
+ gui_helper_reset( k_gui_helper_mode_clear );
}
}
- else if( shop->type == k_skateshop_type_worldshop ){
+ else if( shop->type == k_skateshop_type_worldshop )
+ {
+#if 0
int browseable = 0,
loadable = 0;
}
}
- if( loadable ){
- if( button_down( k_srbind_maccept ) ){
- skaterift_change_world_start( selected_world );
+ if( loadable )
+ {
+ 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( shop->type == k_skateshop_type_charshop )
network_send_item( k_netmsg_playeritem_player );
+#if 0
world_entity_exit_modal();
world_entity_clear_focus();
- gui_helper_clear();
+#endif
+ gui_helper_reset( k_gui_helper_mode_clear );
return;
}
}
-void skateshop_world_preupdate( world_instance *world )
+void skateshop_world_preupdate(void)
{
- for( u32 i=0; i<af_arrcount(&world->ent_skateshop); i++ ){
+ world_instance *world = &_world.main;
+ for( u32 i=0; i<af_arrcount(&world->ent_skateshop); i++ )
+ {
ent_skateshop *shop = af_arritm( &world->ent_skateshop, i );
- if( shop->type == k_skateshop_type_server ){
+ if( shop->type == k_skateshop_type_server )
+ {
f32 a = network_client.user_intent;
vg_slewf( &network_client.fintent, a, vg.time_frame_delta );
}
}
-static void skateshop_render_boardshop( ent_skateshop *shop ){
- world_instance *world = world_current_instance();
+static void skateshop_render_boardshop( ent_skateshop *shop )
+{
+ world_instance *world = &_world.main;
u32 slot_count = VG_ARRAY_LEN(global_skateshop.shop_view_slots);
ent_marker *mark_rack = af_arritm( &world->ent_marker,
}
static void skateshop_render_worldshop( ent_skateshop *shop ){
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
ent_marker *mark_display = af_arritm( &world->ent_marker,
mdl_entity_id_id(shop->worlds.id_display)),
vg_info( "Entering skateshop\n" );
+#if 0
world_entity_set_focus( call->id );
world_entity_focus_modal();
- gui_helper_clear();
+#endif
+ gui_helper_reset( k_gui_helper_mode_black_bars );
if( shop->type == k_skateshop_type_boardshop )
{
void skateshop_render( ent_skateshop *shop );
void skateshop_render_nonfocused( world_instance *world, vg_camera *cam );
void skateshop_autostart_loading(void);
-void skateshop_world_preupdate( world_instance *world );
+void skateshop_world_preupdate(void);
entity_call_result ent_skateshop_call( world_instance *world, ent_call *call );
void skateshop_world_preview_preupdate(void);
void ent_tornado_debug(void)
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
for( u32 i=0; i<af_arrcount(&world->ent_marker); i ++ )
{
ent_marker *marker = af_arritm( &world->ent_marker, i );
void ent_tornado_forces( v3f co, v3f cv, v3f out_a )
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
v3_zero( out_a );
for( u32 i=0; i<af_arrcount(&world->ent_marker); i ++ )
void ent_tornado_pre_update(void)
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
for( u32 i=0; i<af_arrcount(&world->ent_marker); i ++ )
{
ent_marker *marker = af_arritm( &world->ent_marker, i );
#include "ent_miniworld.h"
#include "ent_region.h"
#include "ent_glider.h"
-#include "ent_npc.h"
#include "world_water.h"
#include <string.h>
[k_ent_miniworld] = ent_miniworld_call,
[k_ent_region] = ent_region_call,
[k_ent_glider] = ent_glider_call,
- [k_ent_npc] = ent_npc_call,
[k_ent_water] = ent_water_call,
};
};
enum ent_challenge_flag {
- k_ent_challenge_timelimit = 0x1
+ k_ent_challenge_timelimit = 0x1,
+ k_ent_challenge_is_story = 0x2
};
struct ent_challenge{
#define GUI_HELPER_TEXT_LENGTH 32
-struct{
- struct gui_helper{
+struct
+{
+ struct gui_helper
+ {
vg_input_op *binding;
char text[GUI_HELPER_TEXT_LENGTH];
int greyed;
helpers[4];
u32 helper_count;
- int active_positional_helper;
+ enum gui_helper_mode
+ {
+ k_gui_helper_mode_default,
+ k_gui_helper_mode_black_bars,
+ k_gui_helper_mode_clear
+ }
+ helper_mode;
- struct icon_call {
+ struct icon_call
+ {
enum gui_icon icon;
v4f location;
v4f colour;
}
static gui = {.cur_icon_colour = {1.0f,1.0f,1.0f,1.0f},.colour_changed=1};
-static void gui_helper_clear(void){
+static void gui_helper_reset( enum gui_helper_mode mode )
+{
gui.helper_count = 0;
- gui.active_positional_helper = 0;
+ gui.helper_mode = mode;
}
-static struct gui_helper *gui_new_helper( vg_input_op *bind, vg_str *out_text ){
+static struct gui_helper *gui_new_helper( vg_input_op *bind, vg_str *out_text )
+{
if( gui.helper_count >= VG_ARRAY_LEN(gui.helpers) ){
vg_error( "Too many helpers\n" );
return NULL;
static void gui_draw( ui_context *ctx )
{
- if( gui.active_positional_helper &&
- (v3_dist2(localplayer.rb.co,gui.trick_co) > 2.0f) )
- gui_helper_clear();
-
/* helpers
* ----------------------------------------------------------------- */
x += w + 32;
}
+ if( (gui.helper_mode == k_gui_helper_mode_black_bars) && gui.helper_count )
+ {
+ ui_rect box = { x, lwr[1], vg.window_x - x, height };
+ ui_fill( ctx, box, ui_opacity( GUI_COL_DARK, 0.4f ) );
+
+ box[0] = 0;
+ box[1] = 0;
+ box[2] = vg.window_x;
+ ui_fill( ctx, box, ui_opacity( GUI_COL_DARK, 0.4f ) );
+ }
+
vg_ui.frosting = gui.factive*0.015f;
ui_flush( ctx, k_ui_shader_colour, NULL );
vg_ui.frosting = 0.0f;
return 0;
}
-static int gui_showtrick_ccmd( int argc, const char *argv[] )
-{
- if( argc == 1 )
- {
- gui_helper_clear();
- vg_str text;
-
- if( !strcmp( argv[0], "pump" ) ){
- if( gui_new_helper( input_axis_list[k_sraxis_grab], &text ) )
- vg_strcat( &text, "Pump" );
- }
- else if( !strcmp( argv[0], "flip" ) ){
- if( gui_new_helper( input_joy_list[k_srjoystick_steer], &text ) )
- vg_strcat( &text, "Flip" );
- }
- else if( !strcmp( argv[0], "ollie" ) ){
- if( gui_new_helper( input_button_list[k_srbind_jump], &text ) )
- vg_strcat( &text, "Ollie" );
- }
- else if( !strcmp( argv[0], "trick" ) ){
- if( gui_new_helper( input_button_list[k_srbind_trick0], &text ) )
- vg_strcat( &text, "Shuvit" );
- if( gui_new_helper( input_button_list[k_srbind_trick1], &text ) )
- vg_strcat( &text, "Kickflip" );
- if( gui_new_helper( input_button_list[k_srbind_trick2], &text ) )
- vg_strcat( &text, "Tre-Flip" );
- }
- else if( !strcmp( argv[0], "misc" ) ){
- if( gui_new_helper( input_button_list[k_srbind_camera], &text ) )
- vg_strcat( &text, "Camera" );
- if( gui_new_helper( input_button_list[k_srbind_use], &text ) )
- vg_strcat( &text, "Skate/Walk" );
- }
- else return 1;
-
- v3_copy( localplayer.rb.co, gui.trick_co );
- gui.active_positional_helper = 1;
- return 0;
- }
- return 1;
-}
-
static void gui_draw_icon( enum gui_icon icon, v2f co, f32 size )
{
if( gui.icon_draw_count == VG_ARRAY_LEN(gui.icon_draw_buffer) )
{
font3d_load( &gui.font, "models/rs_font.mdl", vg_mem.rtmemory );
vg_console_reg_cmd( "gui_location", gui_location_print_ccmd, NULL );
- vg_console_reg_cmd( "showtrick", gui_showtrick_ccmd, NULL );
/* load icons */
void *alloc = vg_mem.rtmemory;
return *p_row;
}
-static void menu_try_find_cam( i32 id )
-{
- world_instance *world = &world_static.instances[0];
- for( u32 i=0; i<af_arrcount(&world->ent_npc); i ++ )
- {
- ent_npc *fnpc = af_arritm( &world->ent_npc, i );
- if( (fnpc->id == 50) && (fnpc->context == id) )
- {
- if( mdl_entity_id_type(fnpc->camera) == k_ent_camera )
- {
- u32 index = mdl_entity_id_id( fnpc->camera );
- menu.bg_cam = af_arritm( &world->ent_camera, index );
- menu.bg_blur = 0;
- }
- }
- }
-}
-
static void menu_link_modal( const char *url )
{
menu.web_link = url;
if( menu.web_link )
{
- menu_try_find_cam( 3 );
+ //menu_try_find_cam( 3 );
ui_rect panel = { 0,0, 800, 200 },
screen = { 0,0, vg.window_x,vg.window_y };
skaterift.activity = k_skaterift_default;
}
- menu_try_find_cam( 3 );
+ //menu_try_find_cam( 3 );
goto menu_draw;
}
else if( menu.page == k_menu_page_premium )
ui_px x = 8,
y = height+8;
- struct ui_vert *vs =
- ui_fill( ctx, (ui_rect){ x,y, 0,height },
- world_static.active_instance? GUI_COL_DARK: GUI_COL_ACTIVE );
+ struct ui_vert *vs = ui_fill( ctx, (ui_rect){ x,y, 0,height }, GUI_COL_DARK );
char buf[64];
vg_str str;
vg_strnull( &str, buf, sizeof(buf) );
- vg_strcat( &str, "Hub World" );
-
- if( world_static.active_instance )
- {
- vg_strcat( &str, " (" );
- vg_input_string( &str, input_button_list[k_srbind_mhub], 1 );
- vg_strcatch( &str, '\x06' );
- vg_strcatch( &str, '\x00' );
- vg_strcat( &str, "\x1B[0m)" );
- }
+
+ world_instance *world = &_world.main;
+ const char *world_name = af_str( &world->meta.af, world->info.pstr_name );
+ vg_strnull( &str, buf, sizeof(buf) );
+ vg_strcat( &str, world_name );
ui_px w = ui_text( ctx, (ui_rect){ x+8, y, 1000, height }, buf, 1,
k_ui_align_middle_left, 0 );
+
w *= ctx->font->sx;
x += w + 16;
vs[1].co[0] = x + 8;
vs[2].co[0] = x;
- x += 2;
-
- world_instance *world = &world_static.instances[1];
- if( world->status == k_world_status_loaded )
- {
- const char *world_name =
- af_str( &world->meta.af, world->info.pstr_name );
+ x = 8;
+ y += 8 + height;
- vg_strnull( &str, buf, sizeof(buf) );
- vg_strcat( &str, world_name );
+ ui_rect stat_panel = { x,y, 256,vg.window_y-y };
+ u32 c0 = ui_opacity( GUI_COL_DARK, 0.36f );
+ vs = ui_fill( ctx, stat_panel, c0 );
- if( !world_static.active_instance &&
- (vg_input.display_input_method == k_input_method_controller) )
- {
- vg_strcat( &str, " (" );
- vg_input_string( &str, input_button_list[k_srbind_mhub], 1 );
- vg_strcatch( &str, '\x06' );
- vg_strcatch( &str, '\x00' );
- vg_strcat( &str, "\x1B[0m)" );
- }
+ ui_rect_pad( stat_panel, (ui_px[2]){8,0} );
- vs = ui_fill( ctx, (ui_rect){ x,y, 1000,height },
- world_static.active_instance? GUI_COL_ACTIVE: GUI_COL_DARK );
- w = ui_text( ctx, (ui_rect){ x+16,y, 1000,height }, buf,
- 1, k_ui_align_middle_left, 0 );
+ for( u32 i=0; i<af_arrcount( &world->ent_region ); i ++ )
+ {
+ ent_region *region = af_arritm( &world->ent_region, i );
- w = w*ctx->font->sx + 8*3;
- x += w;
+ if( !region->zone_volume )
+ continue;
- if( button_down( k_srbind_mhub ) ||
- ui_button_base( ctx, (ui_rect){0,y,x,height} ) == k_ui_button_click )
- {
- world_switch_instance( world_static.active_instance ^ 0x1 );
- skaterift.activity = k_skaterift_default;
- world_map.view_ready = 0;
- }
+ const char *title = af_str( &world->meta.af, region->pstr_title );
+ ctx->font = &vgf_default_large;
- vs[0].co[0] += 8;
- vs[1].co[0] = x + 8;
- vs[2].co[0] = x;
- }
+ ui_rect title_box;
+ menu_standard_widget( ctx, stat_panel, title_box, 1 );
+
+ stat_panel[0] += 16;
+ stat_panel[2] -= 16;
+ ctx->font = &vgf_default_small;
- x = 8;
- y += 8 + height;
+ ent_volume *volume = af_arritm(&world->ent_volume,
+ mdl_entity_id_id(region->zone_volume));
- if( world_static.active_instance )
- {
- ui_rect stat_panel = { x,y, 256,vg.window_y-y };
- u32 c0 = ui_opacity( GUI_COL_DARK, 0.36f );
- struct ui_vert *vs = ui_fill( ctx, stat_panel, c0 );
+ u32 combined = k_ent_route_flag_achieve_gold |
+ k_ent_route_flag_achieve_silver;
- ui_rect_pad( stat_panel, (ui_px[2]){8,0} );
+ char buf[128];
+ vg_str str;
- for( u32 i=0; i<af_arrcount( &world->ent_region ); i ++ )
+ for( u32 j=0; j<af_arrcount(&world->ent_route); j ++ )
{
- ent_region *region = af_arritm( &world->ent_region, i );
+ ent_route *route = af_arritm(&world->ent_route, j );
- if( !region->zone_volume )
+ v3f local;
+ m4x3_mulv( volume->to_local, route->board_transform[3], local );
+ if( !((fabsf(local[0]) <= 1.0f) &&
+ (fabsf(local[1]) <= 1.0f) &&
+ (fabsf(local[2]) <= 1.0f)) )
+ {
continue;
+ }
- const char *title = af_str( &world->meta.af, region->pstr_title );
- ctx->font = &vgf_default_large;
+ combined &= route->flags;
- ui_rect title_box;
- menu_standard_widget( ctx, stat_panel, title_box, 1 );
-
- stat_panel[0] += 16;
- stat_panel[2] -= 16;
- ctx->font = &vgf_default_small;
+ vg_strnull( &str, buf, sizeof(buf) );
+ vg_strcat( &str, "(Race) " );
+ vg_strcat( &str, af_str( &world->meta.af, route->pstr_name ));
- ent_volume *volume = af_arritm(&world->ent_volume,
- mdl_entity_id_id(region->zone_volume));
+ if( route->flags & k_ent_route_flag_achieve_silver )
+ vg_strcat( &str, " \xb3");
+ if( route->flags & k_ent_route_flag_achieve_gold )
+ vg_strcat( &str, "\xb3");
- u32 combined = k_ent_route_flag_achieve_gold |
- k_ent_route_flag_achieve_silver;
+ ui_rect r;
+ ui_standard_widget( ctx, stat_panel, r, 1 );
+ ui_text( ctx, r, buf, 1, k_ui_align_middle_left,
+ medal_colour( ctx, route->flags ) );
+ }
- char buf[128];
- vg_str str;
+ for( u32 j=0; j<af_arrcount(&world->ent_challenge); j ++ )
+ {
+ ent_challenge *challenge = af_arritm( &world->ent_challenge, j );
- for( u32 j=0; j<af_arrcount(&world->ent_route); j ++ )
+ v3f local;
+ m4x3_mulv( volume->to_local, challenge->transform.co, local );
+ if( !((fabsf(local[0]) <= 1.0f) &&
+ (fabsf(local[1]) <= 1.0f) &&
+ (fabsf(local[2]) <= 1.0f)) )
{
- ent_route *route = af_arritm(&world->ent_route, j );
-
- v3f local;
- m4x3_mulv( volume->to_local, route->board_transform[3], local );
- if( !((fabsf(local[0]) <= 1.0f) &&
- (fabsf(local[1]) <= 1.0f) &&
- (fabsf(local[2]) <= 1.0f)) )
- {
- continue;
- }
-
- combined &= route->flags;
-
- vg_strnull( &str, buf, sizeof(buf) );
- vg_strcat( &str, "(Race) " );
- vg_strcat( &str, af_str( &world->meta.af, route->pstr_name ));
-
- if( route->flags & k_ent_route_flag_achieve_silver )
- vg_strcat( &str, " \xb3");
- if( route->flags & k_ent_route_flag_achieve_gold )
- vg_strcat( &str, "\xb3");
-
- ui_rect r;
- ui_standard_widget( ctx, stat_panel, r, 1 );
- ui_text( ctx, r, buf, 1, k_ui_align_middle_left,
- medal_colour( ctx, route->flags ) );
+ continue;
}
- for( u32 j=0; j<af_arrcount(&world->ent_challenge); j ++ )
+ vg_strnull( &str, buf, sizeof(buf) );
+ vg_strcat( &str, af_str( &world->meta.af,challenge->pstr_alias));
+
+ u32 flags = 0x00;
+ if( challenge->status )
{
- ent_challenge *challenge = af_arritm( &world->ent_challenge, j );
-
- v3f local;
- m4x3_mulv( volume->to_local, challenge->transform.co, local );
- if( !((fabsf(local[0]) <= 1.0f) &&
- (fabsf(local[1]) <= 1.0f) &&
- (fabsf(local[2]) <= 1.0f)) )
- {
- continue;
- }
-
- vg_strnull( &str, buf, sizeof(buf) );
- vg_strcat( &str, af_str( &world->meta.af,challenge->pstr_alias));
-
- u32 flags = 0x00;
- if( challenge->status )
- {
- flags |= k_ent_route_flag_achieve_gold;
- flags |= k_ent_route_flag_achieve_silver;
- vg_strcat( &str, " \xb3\xb3" );
- }
-
- combined &= flags;
-
- ui_rect r;
- ui_standard_widget( ctx, stat_panel, r, 1 );
- ui_text( ctx, r, buf, 1,
- k_ui_align_middle_left, medal_colour( ctx, flags ) );
+ flags |= k_ent_route_flag_achieve_gold;
+ flags |= k_ent_route_flag_achieve_silver;
+ vg_strcat( &str, " \xb3\xb3" );
}
- stat_panel[0] -= 16;
- stat_panel[2] += 16;
-
- u32 title_col = 0;
- if( combined & k_ent_route_flag_achieve_gold )
- title_col = ui_colour( ctx, k_ui_yellow );
- else if( combined & k_ent_route_flag_achieve_silver )
- title_col = ui_colour( ctx, k_ui_fg );
+ combined &= flags;
- menu_heading( ctx, title_box, title, title_col );
+ ui_rect r;
+ ui_standard_widget( ctx, stat_panel, r, 1 );
+ ui_text( ctx, r, buf, 1,
+ k_ui_align_middle_left, medal_colour( ctx, flags ) );
}
- vs[2].co[1] = stat_panel[1];
- vs[3].co[1] = stat_panel[1];
+ stat_panel[0] -= 16;
+ stat_panel[2] += 16;
+
+ u32 title_col = 0;
+ if( combined & k_ent_route_flag_achieve_gold )
+ title_col = ui_colour( ctx, k_ui_yellow );
+ else if( combined & k_ent_route_flag_achieve_silver )
+ title_col = ui_colour( ctx, k_ui_fg );
+
+ menu_heading( ctx, title_box, title, title_col );
}
+
+ vs[2].co[1] = stat_panel[1];
+ vs[3].co[1] = stat_panel[1];
}
else
{
menu_heading( ctx, list, "Info", 0 );
if( menu.guide_sel == 1 )
{
- menu_try_find_cam( 1 );
+ //menu_try_find_cam( 1 );
ui_rect title;
ui_split( inf, k_ui_axis_h, 28*2, 0, title, inf );
if( menu.guide_sel == 3 )
{
- menu_try_find_cam( 2 );
+ //menu_try_find_cam( 2 );
ui_rect title;
ui_split( inf, k_ui_axis_h, 28*2, 0, title, inf );
menu_link_modal(
"https://skaterift.com/index.php?page=movement" );
}
- if( menu.guide_sel == 0 || menu.guide_sel > 3 ) menu_try_find_cam( 3 );
+ //if( menu.guide_sel == 0 || menu.guide_sel > 3 ) menu_try_find_cam( 3 );
if( menu_button( ctx, list, R == 3, "Tricks \xb2" ) )
{
_cutscene.instances[ i ].ref_id = ref_id;
_cutscene.instances[ i ].skinning_data = NULL;
+ _cutscene.instances[ i ].disable_render = 0;
}
/* load model data */
void cutscene_render_instance( struct cs_instance *ins,
world_instance *world, vg_camera *cam )
{
+ if( ins->disable_render )
+ return;
+
struct model_ref *ref = &_cutscene.refs[ ins->ref_id ];
mdl_context *mdl = &ref->mdl;
mesh_bind( &mdl->mesh );
struct cs_instance
{
+ bool disable_render;
u32 ref_id;
m4x3f *skinning_data;
};
static void network_scoreboard_callback( netmsg_request *res, vg_msg *body,
u64 userdata ){
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
world_routes_recv_scoreboard( world, body, userdata, res->status );
if( userdata == world_sfd.active_route_board )
item->client = 0;
if( (type == k_netmsg_playeritem_world0) ||
- (type == k_netmsg_playeritem_world1) ){
-
- enum world_purpose purpose = type - k_netmsg_playeritem_world0;
- addon_reg *reg = world_static.instance_addons[ purpose ];
+ (type == k_netmsg_playeritem_world1) )
+ {
+ addon_reg *reg = _world.main.addon;
if( reg )
addon_alias_uid( ®->alias, item->uid );
else
item->uid[0] = '\0';
}
- else{
+ else
+ {
u16 view_id = 0;
enum addon_type addon_type = k_addon_type_none;
- if( type == k_netmsg_playeritem_board ){
+ if( type == k_netmsg_playeritem_board )
+ {
view_id = localplayer.board_view_slot;
addon_type = k_addon_type_board;
}
- else if( type == k_netmsg_playeritem_player ){
+ else if( type == k_netmsg_playeritem_player )
+ {
view_id = localplayer.playermodel_view_slot;
addon_type = k_addon_type_player;
}
int localplayer_cmd_respawn( int argc, const char *argv[] )
{
ent_spawn *rp = NULL, *r;
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
if( argc == 1 ){
rp = world_find_spawn_by_name( world, argv[0] );
*/
void player__pass_gate( u32 id )
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
skaterift_record_frame( &player_replay.local, 1 );
/* update boundary hash (network animation) */
m4x3_mulv( gate->transport, localplayer.cam.pos, localplayer.cam.pos );
if( gate->flags & k_ent_gate_nonlocal )
- {
- world_default_spawn_pos( world, world->player_co );
- world_static.active_instance = gate->target;
- player__clean_refs();
-
- replay_clear( &player_replay.local );
- }
+ vg_error( "Nonlocal gates are deprecated!\n" );
else
- {
world_routes_activate_entry_gate( world, gate );
- }
v3f v0;
v3_angles_vector( localplayer.angles, v0 );
g_player_debugger[2] = 300;
g_player_debugger[3] = 32;
- player__debugtext( ctx, 2, "instance #%u", world_static.active_instance );
-
char buf[96];
- for( u32 i=0; i<k_world_max; i++ )
- {
- if( world_static.instance_addons[ i ] )
- addon_alias_uid( &world_static.instance_addons[ i ]->alias, buf );
- else
- strcpy( buf, "none" );
-
- player__debugtext( ctx, 1, "world #%u: %s", i, buf );
- }
+ if( _world.main.addon )
+ addon_alias_uid( &_world.main.addon->alias, buf );
+ else
+ strcpy( buf, "none" );
+ player__debugtext( ctx, 1, "world #%u: %s", 0, buf );
player__debugtext( ctx, 2, "director" );
- player__debugtext( ctx, 1, "activity: %s",
+ player__debugtext( ctx, 1, "client activity: %s",
(const char *[]){ [k_skaterift_menu] = "menu",
[k_skaterift_replay] = "replay",
- [k_skaterift_ent_focus] = "ent_focus",
[k_skaterift_default] = "default",
} [skaterift.activity] );
+ player__debugtext( ctx, 1, "world event: %s",
+ (const char *[]){ [k_world_event_none] = "no event",
+ [k_world_event_challenge] = "challenge",
+ } [_world.event] );
+
player__debugtext( ctx, 1, "time_rate: %.4f", skaterift.time_rate );
player__debugtext( ctx, 2, "player" );
void player__clean_refs(void)
{
replay_clear( &player_replay.local );
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_clear );
- world_static.challenge_target = NULL;
- world_static.challenge_timer = 0.0f;
- world_static.active_trigger_volume_count = 0;
- world_static.last_use = 0.0;
+ _world.challenge_target = NULL;
+ _world.challenge_timer = 0.0f;
+ _world.active_trigger_volume_count = 0;
+#if 0
world_entity_exit_modal();
world_entity_clear_focus();
+#endif
localplayer.boundary_hash ^= NETMSG_BOUNDARY_BIT;
-
- for( u32 i=0; i<VG_ARRAY_LEN(world_static.instances); i++ ){
- world_instance *instance = &world_static.instances[i];
- if( instance->status == k_world_status_loaded ){
- world_routes_clear( instance );
- }
- }
+ world_routes_clear( &_world.main );
}
void player__reset(void)
int deferred_frame_record;
int immobile;
-
int rewinded_since_last_gate;
/*
{
player_ragdoll_iter( &localplayer.ragdoll );
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
world_water_player_safe( world, 0.2f );
}
if( (skaterift.activity == k_skaterift_default) &&
button_down(k_srbind_dead_respawn) ){
ent_spawn *spawn = world_find_closest_spawn(
- world_current_instance(), localplayer.rb.co );
+ &_world.main, localplayer.rb.co );
if( spawn ){
v3_copy( spawn->transform.co, localplayer.rb.co );
v3_copy( part->rb.v, player_dead.v_lpf );
v3_copy( part->rb.w, player_dead.w_lpf );
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_black_bars );
vg_str str;
struct gui_helper *h;
- if( (h = gui_new_helper(input_button_list[k_srbind_reset], &str) )){
+ if( (h = gui_new_helper(input_button_list[k_srbind_reset], &str) ))
vg_strcat( &str, "Rewind" );
- if( world_static.active_instance == k_world_purpose_hub )
- h->greyed = 1;
- }
-
if( gui_new_helper(input_button_list[k_srbind_dead_respawn], &str ))
vg_strcat( &str, "Spawn" );
}
/*
* collisions & constraints
*/
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
rb_solver_reset();
bool bottom_hit = 0;
localplayer.glider_orphan = 1;
}
- if( !world_water_player_safe( world_current_instance(), 1.0f ) )
+ if( !world_water_player_safe( &_world.main, 1.0f ) )
return;
}
{
localplayer.subsystem = k_player_subsystem_glide;
localplayer.have_glider = 0;
- world_static.challenge_target = NULL;
- world_static.challenge_timer = 0.0f;
- world_static.focused_entity = 0;
- world_static.last_use = 0.0;
- for( u32 i=0; i<VG_ARRAY_LEN(world_static.instances); i++ ){
- world_instance *instance = &world_static.instances[i];
- if( instance->status == k_world_status_loaded ){
- world_routes_clear( instance );
- }
- }
+ world_routes_clear( &_world.main );
v3_copy( localplayer.rb.co, player_glide.rb.co );
*/
void player_ragdoll_iter( struct player_ragdoll *rd )
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
int run_sim = 0;
ragdoll_frame ++;
player->subsystem = k_player_subsystem_invalid;
}
-/*
- * re-attatches addon_reg pointers on the remote client if we have the same
- * world loaded.
- */
-static void relink_remote_player_worlds( u32 client_id ){
+static void relink_remote_player_worlds( u32 client_id )
+{
struct network_player *player = &netplayers.list[client_id];
- 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
- */
- for( u32 i=0; i<k_world_max; i++ ){
- addon_reg *reg = world_static.instance_addons[ i ];
-
- player->world_match[i] = 0;
+ addon_alias q;
+ addon_uid_to_alias( player->items[k_netmsg_playeritem_world0], &q );
- if( reg ){
- if( addon_alias_eq( &q[i], &world_static.instance_addons[i]->alias ) )
- player->world_match[i] = 1;
- }
- }
+ if( addon_alias_eq( &q, &_world.main.addon->alias ) )
+ player->same_world = 1;
}
/*
*/
void relink_all_remote_player_worlds(void)
{
- for( u32 i=0; i<VG_ARRAY_LEN(netplayers.list); i++ ){
+ for( u32 i=0; i<VG_ARRAY_LEN(netplayers.list); i++ )
+ {
struct network_player *player = &netplayers.list[i];
if( player->active )
relink_remote_player_worlds(i);
frame->inetmsg_id = k_inetmsg_playerframe;
frame->client = 0xff;
frame->subsystem = localplayer.subsystem;
- frame->flags = world_static.active_instance;
+ frame->flags = 0;
bitpack_ctx ctx = {
.mode = k_bitpack_compress,
player_pose pose0, pose1, posed;
sys0->pose( &f0->data, &pose0 );
- u8 instance_id = 0;
-
f32 t = 0.0f;
- if( f1 ){
+ if( f1 )
+ {
t = (buf->t - f0->timestamp) / (f1->timestamp - f0->timestamp);
t = vg_clampf( t, 0.0f, 1.0f );
if( bounds & NETMSG_BOUNDARY_BIT )
t = 1.0f;
- if( bounds & NETMSG_GATE_BOUNDARY_BIT ){
+ if( bounds & NETMSG_GATE_BOUNDARY_BIT )
+ {
/* TODO: Extra work retransforming the root_co, instance_id.. etc */
t = 1.0f;
}
- instance_id = f1->flags & NETMSG_PLAYERFRAME_INSTANCE_ID;
lerp_player_pose( &pose0, &pose1, t, &posed );
effect_blink_apply( &player->effect_data.blink, &posed, vg.time_delta );
memcpy( board_pose, &posed.board, sizeof(*board_pose) );
}
- else {
- instance_id = f0->flags & NETMSG_PLAYERFRAME_INSTANCE_ID;
+ else
+ {
effect_blink_apply( &player->effect_data.blink, &pose0, vg.time_delta );
apply_full_skeleton_pose( sk, &pose0, final_mtx );
if( sys0->effects )
}
else
player->render_glider = 0;
-
- if( player->world_match[ instance_id ] )
- player->active_world = &world_static.instances[ instance_id ];
}
/*
}
struct network_player *player = &netplayers.list[ index ];
- if( player->active != 2 )
- player->active_world = NULL;
- if( minframe && maxframe ){
+ if( minframe && maxframe )
+ {
pose_remote_player( index, minframe, maxframe );
buf->t += vg.time_frame_delta;
}
- else {
+ else
+ {
buf->t = abs_max_time - 0.25;
if( abs_max_frame )
draw_list_count = 0,
gliders = 0;
- for( u32 i=0; i<NETWORK_MAX_PLAYERS; i ++ ){
+ for( u32 i=0; i<NETWORK_MAX_PLAYERS; i ++ )
+ {
struct network_player *player = &netplayers.list[i];
if( !player->active || player->isblocked ) continue;
- if( player->active_world != world ) continue;
+ if( !player->same_world ) continue;
#if 0
if( !player->isfriend &&
- (world-world_static.instances == k_world_purpose_hub)) continue;
+ (world-_world.instances == k_world_purpose_hub)) continue;
#endif
draw_list[draw_list_count ++] = i;
player->isblocked = vg_randu32(&vg.rand) &
vg_randu32(&vg.rand) &
vg_randu32(&vg.rand) & 0x1;
- player->world_match[ 0 ] = vg_randu32(&vg.rand) & 0x1;
- player->world_match[ 1 ] = 0;
- if( player->world_match[0] )
- player->active_world = &world_static.instances[0];
- else
- player->active_world = NULL;
+ player->same_world = vg_randu32(&vg.rand) & 0x1;
- for( int i=0; i<sizeof(player->username)-1; i ++ ){
+ for( int i=0; i<sizeof(player->username)-1; i ++ )
+ {
player->username[i] = 'a' + (vg_randu32(&vg.rand) % 30);
player->username[i+1] = '\0';
struct network_player *player = &netplayers.list[i];
if( !player->active || player->isblocked ) continue;
- int in_same_world = player->active_world == world_current_instance();
- if( !player->isfriend && !in_same_world )
+ if( !player->isfriend && !player->same_world )
continue;
- const char *location = in_same_world? "": "another world";
+ const char *location = player->same_world? "": "another world";
if( player->region_flags & k_ent_region_flag_hasname ){
location = player->region;
}
ui_rect box = { x, y, width, height };
remote_player_gui_info( ctx, box, player->username, location,
- player->isfriend, in_same_world );
+ player->isfriend, player->same_world );
y += height + gap;
}
}
v3f co;
remote_player_position( i, co );
- if( !player->active_world )
+ if( !player->same_world )
continue;
- if( !player->isfriend &&
- (world-world_static.instances == k_world_purpose_hub)) continue;
-
- /* their in our active subworld */
- if( player->active_world != world )
- {
- m4x3_mulv( global_miniworld.mmdl, co, co );
- co[1] -= 2.0f; /* HACK lol */
- }
f32 d2 = v3_dist2( co, localplayer.rb.co );
struct global_netplayers
{
- struct network_player {
+ struct network_player
+ {
int active, isfriend, isblocked;
u64 steamid;
u16 board_view_slot, playermodel_view_slot;
enum player_subsystem subsystem;
- /* this is set IF they exist in a world that we have loaded */
- world_instance *active_world;
- int world_match[ k_world_max ];
- u32 location_pstr; /* TODO: valid if active_world set. */
+ bool same_world;
+ u32 location_pstr;
char username[ NETWORK_USERNAME_MAX ];
char items[k_netmsg_playeritem_max][ADDON_UID_MAX];
v3_zero( vp1 );
}
- struct ub_world_lighting *ubo = &world_current_instance()->ub_lighting;
+ struct ub_world_lighting *ubo = &_world.main.ub_lighting;
v3f *board_mtx = localplayer.final_mtx[ localplayer.id_board ];
m4x3_mulv( board_mtx, vp0, ubo->g_board_0 );
m4x3_mulv( board_mtx, vp1, ubo->g_board_1 );
void player__render( vg_camera *cam )
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
SDL_AtomicLock( &addon_system.sl_cache_using_resources );
struct player_model *model =
replay_gamestate *gs =
replay_frame_data( frame, k_replay_framedata_internal_gamestate );
- gs->current_run_version = world_static.current_run_version;
+ gs->current_run_version = _world.current_run_version;
gs->drowned = localplayer.drowned;
/* permanent block */
replay_frame_data( frame, k_replay_framedata_internal_gamestate );
void *src = replay_frame_data( frame, k_replay_framedata_gamestate );
u16 src_size = frame->data_table[ k_replay_framedata_gamestate ][1];
- world_static.current_run_version = gs->current_run_version;
+ _world.current_run_version = gs->current_run_version;
localplayer.drowned = gs->drowned;
if(frame->system == k_player_subsystem_walk ){
vg.time = frame->time;
}
-static void skaterift_replay_resume(void){
+static void skaterift_replay_resume(void)
+{
replay_frame *prev = replay_find_recent_stateframe(&player_replay.local);
- if( prev ){
+ if( prev )
+ {
player_replay.replay_control = k_replay_control_resume;
player_replay.resume_target = prev;
player_replay.resume_begin = player_replay.local.cursor;
player_replay.resume_transition = 0.0f;
}
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_clear );
}
static void skaterift_replay_update_helpers(void);
else
skaterift.activity = k_skaterift_default;
srinput.state = k_input_state_resume;
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_clear );
}
if( input )
static void replay_show_helpers(void)
{
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_default );
vg_str text;
if( gui_new_helper( input_axis_list[k_sraxis_replay_h], &text ) )
void skaterift_replay_post_render(void)
{
#ifndef SR_ALLOW_REWIND_HUB
- if( world_static.active_instance != k_world_purpose_client )
+ if( _world.active_instance != k_world_purpose_client )
return;
#endif
player_replay.editor_mode ^= 0x1;
if( player_replay.editor_mode )
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_clear );
else
replay_show_helpers();
}
}
ui_info( ctx, panel, "World settings" );
- f32 new_time = world_current_instance()->time;
+ f32 new_time = _world.main.time;
if( ui_slider( ctx, panel, "Time of day", 0, 1, &new_time ) )
- {
- world_current_instance()->time = new_time;
- }
+ _world.main.time = new_time;
ui_info( ctx, panel, "" );
if( ui_button( ctx, panel, "Exit editor (F1)" ) == k_ui_button_click )
* filters to the manifold afterwards
*/
static int skate_collide_smooth( m4x3f mtx, f32 r, rb_ct *man ){
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
int len = 0;
len = rb_sphere__scene( mtx, r, NULL, world->geo_bh, man,
static int skate_grind_scansq( v3f pos, v3f dir, float r,
struct grind_info *inf ){
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
v4f plane;
v3_copy( dir, plane );
void player__approximate_best_trajectory(void)
{
- world_instance *world0 = world_current_instance();
+ world_instance *world0 = &_world.main;
float k_trace_delta = vg.time_fixed_delta * 10.0f;
struct player_skate_state *state = &player_skate.state;
m4x3_mulv( gate->transport, co1, co1 );
m3x3_mulv( gate->transport, launch_v, launch_v);
m4x3_mulv( gate->transport, launch_co, launch_co );
-
- if( gate->flags & k_ent_gate_nonlocal )
- trace_world = &world_static.instances[ gate->target ];
}
}
vg_line_arrow( co, dir, 0.13f, 0xff000000 );
ray_hit hit = { .dist = 2.0f };
- if( ray_world( world_current_instance(), co, dir,
+ if( ray_world( &_world.main, co, dir,
&hit, k_material_flag_ghosts )) {
vg_line( co, hit.pos, 0xff000000 );
vg_line_point( hit.pos, 0.1f, 0xff000000 );
static
int skate_compute_surface_alignment( v3f ra, u32 colour,
v3f surface_normal, v3f axel_dir ){
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
v3f truck, left, right;
m4x3_mulv( localplayer.rb.to_world, ra, truck );
v3_muls( dir, 1.0f/ray.dist, dir );
ray.dist -= 0.025f;
- if( ray_world( world_current_instance(), origin, dir, &ray,
+ if( ray_world( &_world.main, origin, dir, &ray,
k_material_flag_walking ) )
return 0;
void player__skate_update(void){
struct player_skate_state *state = &player_skate.state;
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
if( state->activity == k_skate_activity_handplant )
return;
v3f dir;
v3_muls( mmdl[1], -1.0f, dir );
ray_hit hit = { .dist = 1.5f };
- if(ray_world( world_current_instance(), sample_co, dir, &hit, 0 )){
+ if(ray_world( &_world.main, sample_co, dir, &hit, 0 )){
vg_line_cross( hit.pos, 0xff0000ff, 0.05f );
vg_line( sample_co, hit.pos, 0xffffffff );
}
static int player_walk_scan_for_drop_in(void){
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
v3f dir, center;
q_mulv( localplayer.rb.q, (v3f){0.0f,0.0f,1.0f}, dir );
v3_copy( localplayer.rb.co, w->state.prev_pos );
v3_zero( localplayer.rb.w );
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
if( !world_water_player_safe( world, 0.4f ) ) return;
enum walk_activity prev_state = w->state.activity;
#include "player.h"
static const char *str_skaterift_main_save = "save.bkv";
-static f64 last_autosave;
+static f64 _last_autosave;
void savedata_file_write( savedata_file *file )
{
savedata_file *sav = file;
FILE *fp = fopen( sav->path, "wb" );
- if( fp ){
+ if( fp )
+ {
fwrite( sav->buf, sav->len, 1, fp );
fclose( fp );
vg_success( "savedata written to '%s'\n", sav->path );
}
- else {
+ else
vg_error( "Error writing savedata (%s)\n", sav->path );
- }
}
void savedata_group_write( savedata_group *group )
{
- for( u32 i=0; i<group->file_count; i++ ){
+ for( u32 i=0; i<group->file_count; i++ )
savedata_file_write( &group->files[i] );
- }
}
void savedata_file_read( savedata_file *file )
{
FILE *fp = fopen( file->path, "rb" );
- if( fp ){
+ if( fp )
+ {
file->len = fread( file->buf, 1, sizeof(file->buf), fp );
fclose( fp );
}
- else{
+ else
+ {
file->len = 0;
vg_warn( "Error reading savedata (%s)\n", file->path );
}
skaterift_write_addon_alias( msg, key, ®->alias );
}
-void skaterift_read_addon_alias( vg_msg *msg, const char *key,
- enum addon_type type,
- addon_alias *alias )
+static bool 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;
alias->type = type;
vg_msg_cmd kv;
- if( vg_msg_getkvcmd( msg, key, &kv ) ){
- if( kv.code == k_vg_msg_kvstring ){
+ if( vg_msg_getkvcmd( msg, key, &kv ) )
+ {
+ if( kv.code == k_vg_msg_kvstring )
+ {
vg_strncpy( kv.value, alias->foldername, sizeof(alias->foldername),
k_strncpy_allow_cutoff );
}
else
vg_msg_cast( kv.value, kv.code, &alias->workshop_id, k_vg_msg_u64 );
- }
-}
-static void skaterift_populate_world_savedata( savedata_file *file,
- enum world_purpose which ){
- file->path[0] = '\0';
- file->len = 0;
- addon_reg *reg = world_static.instance_addons[ which ];
-
- if( !reg ){
- vg_error( "Tried to save unspecified world (reg was null)\n" );
- return;
+ return 1;
}
- skaterift_world_get_save_path( which, file->path );
-
- vg_msg sav;
- vg_msg_init( &sav, file->buf, sizeof(file->buf) );
-
- world_instance *instance = &world_static.instances[which];
- world_entity_serialize( instance, &sav );
-
- vg_msg_frame( &sav, "player" );
- {
- vg_msg_wkvnum( &sav, "position", k_vg_msg_float|k_vg_msg_32b, 3,
- (which == world_static.active_instance)?
- localplayer.rb.co:
- instance->player_co );
- }
- vg_msg_end_frame( &sav );
-
- file->len = sav.cur.co;
+ return 0;
}
static void skaterift_populate_main_savedata( savedata_file *file )
localplayer.board_view_slot );
skaterift_write_viewslot( &sav, "playermodel", k_addon_type_player,
localplayer.playermodel_view_slot );
+
+ addon_reg *reg = _world.main.addon;
+ if( reg )
+ skaterift_write_addon_alias( &sav, "location", ®->alias );
+ else
+ vg_error( "Tried to reference un-registered world in save file.\n" );
+ }
+ vg_msg_end_frame( &sav );
+
+ /* script / story information */
+ vg_msg_frame( &sav, "story" );
+ {
+ skaterift_script_write_savedata( &sav );
}
vg_msg_end_frame( &sav );
file->len = sav.cur.co;
}
-void skaterift_read_main_savedata( savedata_file *file )
+static void skaterift_populate_world_savedata( savedata_file *file )
{
- strcpy( file->path, str_skaterift_main_save );
- savedata_file_read( file );
+ file->path[0] = '\0';
+ file->len = 0;
+ addon_reg *reg = _world.main.addon;
+
+ if( !reg )
+ {
+ vg_error( "Tried to save unspecified world (reg was null)\n" );
+ return;
+ }
+
+ skaterift_world_get_save_path( reg, file->path );
+
+ vg_msg sav;
+ vg_msg_init( &sav, file->buf, sizeof(file->buf) );
+
+ world_instance *instance = &_world.main;
+ world_entity_serialize( instance, &sav );
+
+ vg_msg_frame( &sav, "player" );
+ {
+ vg_msg_wkvnum( &sav, "position", k_vg_msg_float|k_vg_msg_32b, 3,
+ localplayer.rb.co );
+ }
+ vg_msg_end_frame( &sav );
+
+ file->len = sav.cur.co;
}
-int skaterift_autosave( int async )
+int skaterift_write_all_savedata( bool async )
{
if( async )
- if( !vg_loader_availible() ) return 0;
-
- u32 save_files = 2;
- if( world_static.instances[k_world_purpose_client].status
- == k_world_status_loaded ){
- save_files ++;
+ {
+ if( !vg_loader_availible() )
+ return 0;
}
- u32 size = sizeof(savedata_group) + sizeof(savedata_file) * save_files;
-
+ u32 save_data_size = sizeof(savedata_group) + sizeof(savedata_file)*2;
savedata_group *group;
if( async )
{
vg_linear_clear( vg_async.buffer );
- size = vg_align8( size );
- group = vg_linear_alloc( vg_async.buffer, size );
+ group = vg_linear_alloc( vg_async.buffer, vg_align8(save_data_size) );
}
else
- group = alloca( size );
+ group = alloca( save_data_size );
+ group->file_count = 2;
- group->file_count = save_files;
skaterift_populate_main_savedata( &group->files[0] );
- skaterift_populate_world_savedata( &group->files[1], k_world_purpose_hub );
-
- if( world_static.instances[ k_world_purpose_client ].status
- == k_world_status_loaded ){
- skaterift_populate_world_savedata( &group->files[2],
- k_world_purpose_client );
- }
+ skaterift_populate_world_savedata( &group->files[1] );
if( async )
vg_loader_start( (void *)savedata_group_write, group );
void skaterift_autosave_synchronous(void)
{
- skaterift_autosave(0);
+ skaterift_write_all_savedata( 0 );
+}
+
+void skaterift_autosave_update( void )
+{
+ if( (vg.time - _last_autosave) > 60.0 )
+ {
+ if( skaterift_write_all_savedata(1) )
+ {
+ _last_autosave = vg.time;
+ }
+ }
}
-void skaterift_autosave_update(void)
+void skaterift_load_mainsave(void)
{
- if( vg.time - last_autosave > 20.0 ){
- if( skaterift_autosave(1) ){
- last_autosave = vg.time;
+ savedata_file sav;
+ strcpy( sav.path, str_skaterift_main_save );
+ savedata_file_read( &sav );
+
+ vg_msg kvsav;
+ vg_msg_init( &kvsav, sav.buf, sizeof(sav.buf) );
+
+ u32 ach;
+ vg_msg_getkvintg( &kvsav, "ach", k_vg_msg_u32, &ach, NULL );
+ skaterift.achievements |= ach;
+
+ u32 board_reg_id = time(NULL) % addon_count( k_addon_type_board, 0 ),
+ player_reg_id = (time(NULL)+44) % addon_count( k_addon_type_player, 0 );
+
+ vg_msg_cursor orig = kvsav.cur;
+ if( vg_msg_seekframe( &kvsav, "player" ) )
+ {
+ addon_alias q;
+ u32 reg_id;
+
+ /* board */
+ if( skaterift_read_addon_alias( &kvsav, "board", k_addon_type_board, &q ) )
+ {
+ reg_id = addon_match( &q );
+ if( reg_id != 0xffffffff )
+ board_reg_id = reg_id;
}
+
+ /* playermodel */
+ if( skaterift_read_addon_alias( &kvsav, "playermodel",
+ k_addon_type_player, &q ) )
+ {
+ reg_id = addon_match( &q );
+ if( reg_id != 0xffffffff )
+ player_reg_id = reg_id;
+ }
+
+ if( skaterift_read_addon_alias( &kvsav, "location", k_addon_type_world, &q ) )
+ {
+ vg_info( "Loading client world from save.\n" );
+
+ reg_id = addon_match( &q );
+ if( reg_id != 0xffffffff )
+ {
+ _world.switch_to_addon =
+ get_addon_from_index( k_addon_type_world, reg_id, 0 );
+ }
+ else
+ {
+ char buf[ADDON_UID_MAX];
+ addon_alias_uid( &q, buf );
+
+ vg_error( "While loading player location from save file, "
+ "couldn't find addon '%s'\n", buf );
+ }
+ }
+ }
+
+ localplayer.board_view_slot =
+ addon_cache_create_viewer( k_addon_type_board, board_reg_id );
+ localplayer.playermodel_view_slot =
+ addon_cache_create_viewer( k_addon_type_player, player_reg_id );
+
+ kvsav.cur = orig;
+
+ if( vg_msg_seekframe( &kvsav, "story" ) )
+ {
+
}
}
void savedata_file_read( savedata_file *file );
void savedata_file_write( savedata_file *file );
void savedata_group_write( savedata_group *group );
-int skaterift_autosave(int async);
void skaterift_autosave_synchronous(void);
void skaterift_autosave_update(void);
-void skaterift_read_addon_alias( vg_msg *msg, const char *key,
- enum addon_type type,
- addon_alias *alias );
-void skaterift_read_main_savedata( savedata_file *file );
+int skaterift_write_all_savedata( bool async );
+void skaterift_load_mainsave(void);
#include "ent_tornado.h"
#include "ent_miniworld.h"
#include "ent_skateshop.h"
-#include "ent_npc.h"
#include "ent_camera.h"
#include "world_map.h"
#include "gui.h"
#include "control_overlay.h"
#include "client.h"
#include "skaterift_script.h"
+#include "ent_challenge.h"
struct skaterift_globals skaterift =
{
.time_rate = 1.0f,
- .hub_world = "maps/dev_hub",
};
void game_launch_opt(void)
{
const char *arg;
if( (arg = vg_long_opt_arg( "world", "Specify path to world to load" )) )
- skaterift.hub_world = arg;
-}
-
-static void async_skaterift_player_start( void *payload, u32 size ){
- world_switch_instance(0);
-}
-
-static void skaterift_restore_state(void)
-{
- savedata_file sav;
- skaterift_read_main_savedata( &sav );
-
- vg_msg kvsav;
- vg_msg_init( &kvsav, sav.buf, sizeof(sav.buf) );
-
- u32 ach;
- vg_msg_getkvintg( &kvsav, "ach", k_vg_msg_u32, &ach, NULL );
- skaterift.achievements |= ach;
-
- u32 board_reg_id = time(NULL) % addon_count( k_addon_type_board, 0 ),
- player_reg_id = (time(NULL)+44) % addon_count( k_addon_type_player, 0 );
-
- vg_msg_cursor orig = kvsav.cur;
- if( vg_msg_seekframe( &kvsav, "player" ) ){
- addon_alias q;
-
- /* board */
- skaterift_read_addon_alias( &kvsav, "board", k_addon_type_board, &q );
- u32 reg_id = addon_match( &q );
- if( reg_id != 0xffffffff )
- board_reg_id = reg_id;
-
- /* playermodel */
- skaterift_read_addon_alias( &kvsav, "playermodel",
- k_addon_type_player, &q );
- reg_id = addon_match( &q );
- if( reg_id != 0xffffffff )
- player_reg_id = reg_id;
- }
-
- localplayer.board_view_slot =
- addon_cache_create_viewer( k_addon_type_board, board_reg_id );
- localplayer.playermodel_view_slot =
- addon_cache_create_viewer( k_addon_type_player, player_reg_id );
-
- kvsav.cur = orig;
+ skaterift.override_load_world = arg;
}
static addon_reg *skaterift_mount_world_unloadable( const char *path, u32 ext ){
return reg;
}
-static void skaterift_load_world_content(void){
+static void skaterift_load_world_content(void)
+{
/* hub world */
- addon_reg *hub = skaterift_mount_world_unloadable( skaterift.hub_world, 0 );
- skaterift_mount_world_unloadable( "maps/mp_spawn",
- ADDON_REG_CITY|ADDON_REG_PREMIUM );
- skaterift_mount_world_unloadable( "maps/mp_mtzero",
- ADDON_REG_MTZERO|ADDON_REG_PREMIUM );
+ _world.default_hub_addon =
+ skaterift_mount_world_unloadable( "maps/dev_hub", 0 );
+ skaterift_mount_world_unloadable( "maps/dev_heaven", 0 );
+ skaterift_mount_world_unloadable( "maps/mp_spawn", ADDON_REG_CITY|ADDON_REG_PREMIUM );
+ skaterift_mount_world_unloadable( "maps/mp_mtzero", ADDON_REG_MTZERO|ADDON_REG_PREMIUM );
skaterift_mount_world_unloadable( "maps/dev_tutorial", 0 );
skaterift_mount_world_unloadable( "maps/dev_flatworld", 0 );
skaterift_mount_world_unloadable( "maps/mp_line1", ADDON_REG_PREMIUM );
-
- world_static.load_state = k_world_loader_load;
-
- struct world_load_args args = {
- .purpose = k_world_purpose_hub,
- .reg = hub
- };
- skaterift_world_load_thread( &args );
}
static void skaterift_load_player_content(void)
void game_load(void)
{
_skaterift_script_init();
- vg_console_reg_cmd( "load_world", skaterift_load_world_command, NULL );
+
+ vg_loader_set_user_information( "Initializing subsystems" );
+
+ vg_console_reg_cmd( "switch_world", skaterift_switch_world_command, NULL );
vg_console_reg_var( "immobile", &localplayer.immobile, k_var_dtype_i32, 0 );
vg_loader_step( menu_init, NULL );
-
vg_loader_step( control_overlay_init, NULL );
vg_loader_step( world_init, NULL );
vg_loader_step( vehicle_init, NULL );
vg_loader_step( player_init, NULL );
vg_loader_step( player_ragdoll_init, NULL );
- vg_loader_step( npc_init, NULL );
vg_loader_step( cutscene_init, NULL );
/* content stuff */
vg_loader_step( skaterift_replay_init, NULL );
vg_loader_step( skaterift_load_player_content, NULL );
+ vg_loader_set_user_information( "Compiling shaders" );
vg_bake_shaders();
- vg_loader_step( audio_init, NULL );
+ vg_loader_set_user_information( "Loading content files" );
+ vg_loader_step( audio_init, NULL );
vg_loader_step( skaterift_load_world_content, NULL );
- vg_async_call( async_skaterift_player_start, NULL, 0 );
- vg_async_stall();
-
vg_console_load_autos();
- addon_mount_content_folder( k_addon_type_player,
- "playermodels", ".mdl" );
+ vg_loader_set_user_information( "Mounting addons" );
+ addon_mount_content_folder( k_addon_type_player, "playermodels", ".mdl" );
addon_mount_content_folder( k_addon_type_board, "boards", ".mdl" );
addon_mount_content_folder( k_addon_type_world, "maps", ".mdl" );
addon_mount_workshop_items();
vg_async_call( async_addon_reg_update, NULL, 0 );
vg_async_stall();
- skaterift_restore_state();
- update_ach_models();
+ /* initializing / loading world. */
+ vg_loader_set_user_information( "Loading savedata" );
+ skaterift_load_mainsave();
+
+ if( !_world.switch_to_addon )
+ {
+ vg_warn( "Falling back to default hub world...\n" );
+ _world.switch_to_addon = _world.default_hub_addon;
+ }
+ world_switcher_thread( NULL );
+ /* add autosave function to exit list */
vg_loader_step( NULL, skaterift_autosave_synchronous );
}
skaterift_preupdate_inputs();
steam_update();
- skaterift_change_client_world_preupdate();
+ world_switcher_update();
- if( !g_client.loaded ) return;
+ if( g_client.unreadyness )
+ return;
//draw_origin_axis();
_skaterift_script_update();
/* TODO: how can we compress this? */
ent_miniworld_preupdate();
- world_entity_focus_preupdate();
+ world_events_update();
+ //world_entity_focus_preupdate();
if( skaterift.activity != k_skaterift_menu )
{
skaterift_replay_pre_update();
remote_sfx_pre_update();
- skateshop_world_preupdate( world_current_instance() );
+ skateshop_world_preupdate();
- world_update( world_current_instance(), localplayer.rb.co );
- audio_ambient_sprites_update( world_current_instance(), listen_co );
+ world_update( &_world.main, localplayer.rb.co );
+ audio_ambient_sprites_update( &_world.main, listen_co );
world_map_pre_update();
}
void vg_fixed_update(void)
{
- if( !g_client.loaded ) return;
+ if( g_client.unreadyness )
+ return;
- world_routes_fixedupdate( world_current_instance() );
+ world_routes_fixedupdate( &_world.main );
player__update();
vehicle_update_fixed();
}
void vg_post_update(void)
{
- if( !g_client.loaded ) return;
+ if( g_client.unreadyness )
+ return;
player__post_update();
player__render( &small_cam );
}
-static world_instance *get_view_world(void)
-{
- if( (skaterift.activity & k_skaterift_menu) &&
- (menu.page == k_menu_page_main) &&
- (menu.main_index == k_menu_main_guide) )
- {
- return &world_static.instances[0];
- }
-
- world_instance *view_world = world_current_instance();
- if( localplayer.gate_waiting &&
- (localplayer.gate_waiting->flags & k_ent_gate_nonlocal) ){
- view_world = &world_static.instances[world_static.active_instance ^ 0x1];
- }
-
- return view_world;
-}
-
static void render_scene(void)
{
/* Draw world */
glEnable( GL_DEPTH_TEST );
- for( u32 i=0; i<VG_ARRAY_LEN(world_static.instances); i++ )
- {
- if( world_static.instances[i].status == k_world_status_loaded )
- {
- world_prerender( &world_static.instances[i] );
- }
- }
+ world_prerender( &_world.main );
if( menu_viewing_map() )
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
v3f bg;
return;
}
- world_instance *view_world = get_view_world();
- render_world( view_world, &g_render.cam, 0, 0, 1, 1 );
+ render_world( &_world.main, &g_render.cam, 0, 0, 1, 1 );
particle_system_update( &particles_grind, vg.time_delta );
//particle_system_debug( &particles_grind );
particle_system_render( &particles_env, &g_render.cam );
player_glide_render_effects( &g_render.cam );
-
- /*
- * render transition
- */
- if( global_miniworld.transition == 0 )
- return;
-
- world_instance *holdout_world = NULL;
- f32 t = 0.0f;
-
- if( global_miniworld.transition == 1 ){
- holdout_world = &world_static.instances[ k_world_purpose_hub ];
- t = global_miniworld.t;
- }
- else{
- holdout_world = &world_static.instances[ k_world_purpose_client ];
- t = 1.0f-global_miniworld.t;
- }
-
- if( holdout_world->status != k_world_status_loaded )
- return;
-
- t = vg_smoothstepf( t );
-
- glEnable( GL_STENCIL_TEST );
- glDisable( GL_DEPTH_TEST );
- glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
- glStencilFunc( GL_ALWAYS, 1, 0xFF );
- glStencilMask( 0xFF );
-
- shader_blit_transition_use();
- shader_blit_transition_uInverseRatio( (v2f){1.0f,1.0f} );
- shader_blit_transition_uT( -(sqrtf(2)+0.5f) * t );
-
- render_fsquad();
- render_world( holdout_world, &global_miniworld.cam, 1, 0, 1, 1 );
}
m4x3f *_TEMP_VAR = NULL;
static void skaterift_composite_maincamera(void)
{
- vg_camera_lerp( &localplayer.cam, &world_static.focus_cam,
- vg_smoothstepf(world_static.focus_strength), &g_render.cam );
+#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 );
if( skaterift.activity == k_skaterift_replay )
{
/* --------------------------------------------------------------------- */
if( !menu_viewing_map() )
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
render_world_cubemaps( world );
-
- ent_gate *nlg = world->rendering_gate;
- if( nlg && (nlg->flags & k_ent_gate_nonlocal) )
- render_world_cubemaps( &world_static.instances[nlg->target] );
}
/* variable res target */
if( !global_miniworld.transition && !menu_viewing_map() )
{
vg_framebuffer_bind( g_render.fb_main, k_render_scale );
- render_world_gates( get_view_world(), &g_render.cam );
+ render_world_gates( &_world.main, &g_render.cam );
}
/* composite */
void vg_render(void)
{
- if( !g_client.loaded )
+ if( g_client.unreadyness )
{
vg_loader_render();
return;
void vg_gui( ui_context *ctx )
{
- if( !g_client.loaded ) return;
+ if( g_client.unreadyness )
+ return;
gui_draw( ctx );
if( k_light_editor )
- imgui_world_light_edit( ctx, world_current_instance() );
+ imgui_world_light_edit( ctx, &_world.main );
vg_ui.tex_bg = g_render.fb_main->attachments[0].id;
vg_framebuffer_inverse_ratio( g_render.fb_main, vg_ui.bg_inverse_ratio );
_cutscene_gui( ctx );
menu_gui( ctx );
player__im_gui( ctx );
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
world_routes_imgui( ctx, world );
skaterift_replay_imgui( ctx );
if( menu_viewing_map() )
{
- remote_players_imgui_world( ctx, world_current_instance(),
- vg.pv, 2000.0f, 0 );
+ remote_players_imgui_world( ctx, &_world.main, vg.pv, 2000.0f, 0 );
remote_players_imgui_lobby( ctx );
}
else
{
remote_players_chat_imgui( ctx ); /* TODO: conditional */
- remote_players_imgui_world( ctx, world_current_instance(),
- vg.pv, 100.0f, 1 );
+ remote_players_imgui_world( ctx, &_world.main, vg.pv, 100.0f, 1 );
}
}
#include "world_sfd.c"
#include "world_volumes.c"
#include "world_water.c"
-#include "ent_npc.c"
+#include "world_events.c"
#include "array_file.c"
#include "model.c"
#include "metascene.c"
f32 time_rate;
enum skaterift_activity {
- k_skaterift_default = 0x00,
+ k_skaterift_default = 0x00, /* regular playing */
k_skaterift_replay = 0x01,
- k_skaterift_ent_focus = 0x02,
k_skaterift_menu = 0x04,
}
activity;
+
GLuint rt_textures[k_skaterift_rt_max];
u32 achievements;
int demo_mode;
- const char *hub_world;
+ const char *override_load_world;
}
extern skaterift;
return 0;
}
+ _cutscene.player_binding->disable_render = 1;
return 1;
}
*index = i;
}
-static bool _skaterift_script_intro( enum escript_event ev, const char *inf )
+static bool _skaterift_generic_script_template(
+ enum escript_event ev,
+ const char *inf,
+
+ const char *metascene_path,
+ struct sr_subtitle subtitles[],
+ bool freeze_player )
{
static u32 state, subtitle_id;
- static struct cs_instance *override_inst;
if( ev == k_escript_event_call )
{
state = k_escript_state_loading;
- override_inst = NULL;
subtitle_id = 0;
- vg_info( "test:state = loading\n" );
+ vg_info( "generic_template:state = loading\n" );
+
+ if( freeze_player )
+ localplayer.immobile = 1;
}
if( ev == k_escript_event_cutscene_marker )
{
- struct sr_subtitle EN[] = {
- { "a1", KCOL_JESUS "Aww hello" },
- { "a2", KCOL_JESUS "welcome to heaven." },
- { "a3", KCOL_JESUS "Not quite your time yet," },
- { "a4", KCOL_JESUS "but if you wanna take a quick look around" },
- { "a5", KCOL_JESUS "then feel free to do so." },
- { "a6", KCOL_JESUS "We've got a great grift shop on the way out!" },
- { NULL, NULL },
- };
- _skaterift_dialogue( EN, &subtitle_id, inf );
-
+ _skaterift_dialogue( subtitles, &subtitle_id, inf );
return 0;
}
if( state == k_escript_state_loading )
{
- if( cmd_cutscene_load( 1, (const char *[]){ "metascenes/intro.ms" } ) )
+ if( cmd_cutscene_load( 1, (const char *[]){ metascene_path } ) )
{
state = k_escript_state_initializing;
- vg_info( "test:state = initializing\n" );
+ vg_info( "generic_template:state = initializing\n" );
}
}
{
_skaterift_script_bind_player();
state = k_escript_state_playing;
- vg_info( "test:state = playing\n" );
+ vg_info( "generic_template:state = playing\n" );
_cutscene_play();
}
}
if( _cutscene.state == k_cutscene_state_done )
{
state = k_escript_state_end;
- vg_info( "test:state = end\n" );
+ vg_info( "generic_template:state = end\n" );
_cutscene_unload();
+
+ if( freeze_player )
+ localplayer.immobile = 0;
+
return 1;
}
}
return 0;
}
+static bool _skaterift_script_intro( enum escript_event ev, const char *inf )
+{
+ struct sr_subtitle EN[] = {
+ { "a1", KCOL_JESUS "Aww hello" },
+ { "a2", KCOL_JESUS "welcome to heaven." },
+ { "a3", KCOL_JESUS "Not quite your time yet," },
+ { "a4", KCOL_JESUS "but if you wanna take a quick look around" },
+ { "a5", KCOL_JESUS "then feel free to do so." },
+ { "a6", KCOL_JESUS "We've got a great grift shop on the way out!" },
+ { NULL, NULL },
+ };
+
+ return _skaterift_generic_script_template( ev, inf,
+ "metascenes/intro.ms", EN, 1 );
+}
+
static bool _skaterift_script_ch1s2( enum escript_event ev, const char *inf )
{
}
static _script = { .script_id = k_escript_script_id_max };
-struct script_binding
+struct script_info
{
const char *alias;
bool( *jump )( enum escript_event ev, const char *inf );
+
+ bool availible;
+ u64 viewed_time;
}
-_script_bindings[] =
+_script_infos[] =
{
[k_escript_script_id_test] = { "test", _skaterift_script_test },
[k_escript_script_id_intro] = { "intro", _skaterift_script_intro },
[k_escript_script_id_ch4s3] = { "ch4s3", _skaterift_script_ch4s3 },
};
+void skaterift_script_write_savedata( vg_msg *sav )
+{
+
+}
+
static int _skaterift_script_hook( int argc, const char *argv[] )
{
if( argc != 1 )
for( u32 i=0; i<k_escript_script_id_max; i ++ )
{
- struct script_binding *bind = &_script_bindings[i];
+ struct script_info *bind = &_script_infos[i];
if( vg_str_eq( argv[0], bind->alias ) )
{
_script.script_id = i;
{
if( _script.script_id != k_escript_script_id_max )
{
- if( _script_bindings[ _script.script_id ].jump( k_escript_event_update,
+ if( _script_infos[ _script.script_id ].jump( k_escript_event_update,
NULL ) )
_script.script_id = k_escript_script_id_max;
}
{
if( _script.script_id != k_escript_script_id_max )
{
- if( _script_bindings[ _script.script_id ].jump(
+ if( _script_infos[ _script.script_id ].jump(
k_escript_event_cutscene_marker, marker) )
_script.script_id = k_escript_script_id_max;
}
void _skaterift_script_update(void);
void _skaterift_script_init(void);
void _skaterift_script_marker( const char *marker );
+void skaterift_script_write_savedata( vg_msg *sav );
v3_muladds( ra, g_render.cam.transform[2], -10.0f, rb );
float t;
- if( spherecast_world( world_current_instance(),
+ if( spherecast_world( &_world.main,
ra, rb, 1.0f, &t, rx, 0 ) != -1 )
{
v3_lerp( ra, rb, t, gzoomer.rb.co );
#if 1
float t;
- if( spherecast_world( world_current_instance(), pa, pb,
+ if( spherecast_world( &_world.main, pa, pb,
k_car_wheel_radius, &t, n, 0 ) == -1 )
{ t = 1.0f;
}
rb_ct manifold[64];
int len = rb_sphere__scene( rb->to_world, 1.0f, NULL,
- world_current_instance()->geo_bh,
+ _world.main.geo_bh,
manifold, 0 );
for( int j=0; j<len; j++ ){
manifold[j].rba = rb;
*/
static void workshop_op_load_model( ui_context *ctx )
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
workshop_form.view_world = world;
if( workshop_form.submission.type == k_addon_type_board )
glEnable( GL_DEPTH_TEST );
glDisable( GL_BLEND );
- render_world( world_current_instance(), &g_render.cam, 0, 0, 1, 1 );
+ render_world( &_world.main, &g_render.cam, 0, 0, 1, 1 );
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
glViewport( 0,0, vg.window_x, vg.window_y );
vg_camera_update_projection( &cam );
vg_camera_finalize( &cam );
- render_playermodel( &cam, world_current_instance(), 0,
+ render_playermodel( &cam, &_world.main, 0,
&workshop_form.player_model, sk, localplayer.final_mtx );
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
#include "player.h"
#include "ent_traffic.h"
-struct world_static world_static;
-
-world_instance *world_current_instance(void)
-{
- return &world_static.instances[ world_static.active_instance ];
-}
-
-static int skaterift_switch_instance_cmd( int argc, const char *argv[] );
+struct world_static _world;
void world_init(void)
{
/* Allocate dynamic world memory arena */
u32 max_size = 76*1024*1024;
- world_static.heap = vg_create_linear_allocator( vg_mem.rtmemory, max_size,
+ _world.heap = vg_create_linear_allocator( vg_mem.rtmemory, max_size,
VG_MEMORY_SYSTEM );
-
- vg_console_reg_cmd( "switch_active_instance",
- skaterift_switch_instance_cmd, NULL );
-}
-
-void world_switch_instance( u32 index )
-{
- localplayer.subsystem = k_player_subsystem_walk;
-
- if( index >= VG_ARRAY_LEN(world_static.instances) ){
- vg_error( "Instance ID out of range (%u)\n", index );
- return;
- }
-
- world_instance *new = &world_static.instances[ index ];
-
- if( new->status != k_world_status_loaded ){
- vg_error( "Instance is not loaded (%u)\n", index );
- return;
- }
-
- if( skaterift.demo_mode ){
- if( world_static.instance_addons[index]->flags & ADDON_REG_PREMIUM ){
- vg_error( "Can't switch to a premium world in the demo version\n" );
- return;
- }
- }
-
- world_instance *current =
- &world_static.instances[ world_static.active_instance ];
-
- if( index != world_static.active_instance ){
- v3_copy( localplayer.rb.co, current->player_co );
- skaterift_autosave(1);
- }
-
- v3_copy( new->player_co, localplayer.rb.co );
-
- world_static.active_instance = index;
- player__reset();
-}
-
-static int skaterift_switch_instance_cmd( int argc, const char *argv[] )
-{
- if( argc )
- world_switch_instance( atoi(argv[0]) );
- else
- vg_info( "switch_active_instance <id>\n" );
- return 0;
}
-void skaterift_world_get_save_path( enum world_purpose which, char buf[128] )
+void skaterift_world_get_save_path( addon_reg *world_reg, char buf[128] )
{
- addon_reg *reg = world_static.instance_addons[ which ];
-
- if( !reg )
- vg_fatal_error( "Looking up addon for world without one\n" );
-
char id[76];
- addon_alias_uid( ®->alias, id );
+ addon_alias_uid( &world_reg->alias, id );
snprintf( buf, 128, "savedata/%s.bkv", id );
}
world_sfd_update( world, pos );
world_volumes_update( world, pos );
}
+
+bool world_set_event( enum world_event event )
+{
+ if( _world.event == k_world_event_none )
+ {
+ vg_info( "Switched to world event: %d\n", event );
+ _world.event = event;
+ return 1;
+ }
+ else
+ {
+ 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;
+ }
+}
+
+bool world_clear_event( enum world_event event )
+{
+ if( _world.event == event )
+ {
+ vg_info( "Cleared world event\n" );
+ _world.event = k_world_event_none;
+ return 1;
+ }
+ else
+ {
+ 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;
+ }
+}
+
/* types
*/
-enum world_geo_type{
+enum world_geo_type
+{
k_world_geo_type_solid = 0,
k_world_geo_type_nonsolid = 1,
k_world_geo_type_water = 2
};
-enum world_purpose{
- k_world_purpose_invalid = -1,
- k_world_purpose_hub = 0,
- k_world_purpose_client = 1,
- k_world_max
-};
-
-struct leaderboard_cache {
+struct leaderboard_cache
+{
enum request_status status;
f64 cache_time;
u8 *data;
typedef struct world_instance world_instance;
-void skaterift_world_get_save_path( enum world_purpose which, char buf[128] );
+void skaterift_world_get_save_path( addon_reg *world_reg, char buf[128] );
/* submodule headers */
#include "world_entity.h"
#include "world_audio.h"
#include "world_routes.h"
#include "world_routes_ui.h"
+#include "world_events.h"
/* console variables */
#define WORLD_SURFACE_HAS_TRAFFIC 0x1
#define WORLD_SURFACE_HAS_PROPS 0x2
-struct world_instance {
- /* Fixed items
- * -------------------------------------------------------
- */
-
- v4f player_co;
-
+struct world_instance
+{
+ addon_reg *addon;
void *heap;
- enum world_status{
- k_world_status_unloaded = 0,
- k_world_status_loading = 1,
- k_world_status_loaded = 2,
- k_world_status_unloading = 3 /* dont spawn sounds and stuff */
- }
- status;
- struct{
+ struct
+ {
boxf depthbounds;
int depth_computed;
ent_miniworld,
ent_prop,
ent_region,
- ent_glider,
- ent_npc;
+ ent_glider;
enum skybox {
k_skybox_default,
struct route_ui *routes_ui;
};
-struct world_static {
+struct world_static
+{
/*
* Allocated as system memory
* --------------------------------------------------------------------------
void *heap;
u32 current_run_version;
- double time, rewind_from, rewind_to, last_use;
+ double time, rewind_from, rewind_to;
u32 active_trigger_volumes[8];
u32 active_trigger_volume_count;
- addon_reg *instance_addons[ k_world_max ];
- world_instance instances[ k_world_max ];
+ world_instance main;
+ addon_reg *default_hub_addon, *switch_to_addon;
- enum world_purpose active_instance;
- u32 focused_entity; /* like skateshop, challenge.. */
- f32 focus_strength;
- vg_camera focus_cam;
-
- /* challenges */
- ent_objective *challenge_target;
- f32 challenge_timer;
-
- enum world_loader_state{
+ enum world_loader_state
+ {
k_world_loader_none,
- k_world_loader_preload,
- k_world_loader_load
+ k_world_loader_saving_current,
+ k_world_loader_unloading_current,
+ k_world_loader_ready,
+ k_world_loader_loading,
+ k_world_loader_done
+ }
+ loader_state;
+
+ enum world_event
+ {
+ k_world_event_none = 0,
+ k_world_event_challenge,
}
- load_state;
+ event;
- bool clear_async_op_when_done;
+ /* World event: Challenges */
+ ent_challenge *active_challenge;
+ bool challenge_running;
+
+ ent_objective *challenge_target;
+ f32 challenge_timer; /* unused */
}
-extern world_static;
+extern _world;
struct world_load_args
{
- enum world_purpose purpose;
addon_reg *reg;
+ world_instance *instance;
+ void *heap;
};
void world_init(void);
-world_instance *world_current_instance(void);
-void world_switch_instance( u32 index );
+
void skaterift_world_load_thread( void *_args );
void world_update( world_instance *world, v3f pos );
+
+bool world_set_event( enum world_event activity );
+bool world_clear_event( enum world_event activity );
#include "audio.h"
#include "world_audio.h"
-/* finds any active playing in world and fades them out, we can only do this
- * while unloading */
void world_fadeout_audio( world_instance *world )
{
- if( world->status != k_world_status_unloading ){
- vg_fatal_error( "World status must be set to 'unloading', to fadeout"
- " audio.\n" );
- }
-
- u8 world_id = (world - world_static.instances) + 1;
-
audio_lock();
- for( u32 i=0; i<AUDIO_CHANNELS; i++ ){
+ for( u32 i=0; i<AUDIO_CHANNELS; i++ )
+ {
audio_channel *ch = &vg_audio.channels[i];
- if( ch->allocated && (ch->world_id == world_id) ){
- ch = audio_channel_fadeout( ch, 1.0f );
- }
+ if( ch->allocated && (ch->flags & AUDIO_FLAG_WORLD) )
+ audio_channel_fadeout( ch, 1.0f );
}
audio_unlock();
}
ray_hit contact;
contact.dist = vg_minf( 16.0f, pos[1] );
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
if( ray_world( world, pos, (v3f){0.0f,-1.0f,0.0f}, &contact,
k_material_flag_ghosts ) ){
float dist = 200.0f;
for( int i=0; i<10; i++ ){
- if( ray_world( world_current_instance(), rc, rd, &ray,
+ if( ray_world( &_world.main, rc, rd, &ray,
k_material_flag_ghosts ) ){
dist = (float)i*5.0f + ray.dist;
break;
#include "ent_traffic.h"
#include "ent_glider.h"
#include "ent_region.h"
-#include "ent_npc.h"
#include "ent_camera.h"
#include "input.h"
#include "player_walk.h"
.cast_ray = NULL
};
+#if 0
void world_entity_set_focus( u32 entity_id )
{
- if( world_static.focused_entity )
+ if( _world.focused_entity )
{
vg_warn( "Entity %u#%u tried to take focus from %u#%u\n",
mdl_entity_id_type( entity_id ),
mdl_entity_id_id( entity_id ),
- mdl_entity_id_type( world_static.focused_entity ),
- mdl_entity_id_id( world_static.focused_entity ) );
+ mdl_entity_id_type( _world.focused_entity ),
+ mdl_entity_id_id( _world.focused_entity ) );
return;
}
- world_static.focused_entity = entity_id;
+ _world.focused_entity = entity_id;
}
void world_entity_focus_modal(void)
if( skaterift.activity != k_skaterift_ent_focus )
{
vg_warn( "Entity %u#%u tried to exit modal when we weren't in one\n",
- mdl_entity_id_type( world_static.focused_entity ),
- mdl_entity_id_id( world_static.focused_entity ) );
+ mdl_entity_id_type( _world.focused_entity ),
+ mdl_entity_id_id( _world.focused_entity ) );
return;
}
if( skaterift.activity == k_skaterift_ent_focus )
{
vg_warn( "Entity %u#%u tried to clear focus before exiting modal\n",
- mdl_entity_id_type( world_static.focused_entity ),
- mdl_entity_id_id( world_static.focused_entity ) );
+ mdl_entity_id_type( _world.focused_entity ),
+ mdl_entity_id_id( _world.focused_entity ) );
return;
}
- world_static.focused_entity = 0;
+ _world.focused_entity = 0;
}
void world_entity_focus_camera( world_instance *world, u32 uid )
{
u32 index = mdl_entity_id_id( uid );
ent_camera *cam = af_arritm( &world->ent_camera, index );
- ent_camera_unpack( cam, &world_static.focus_cam );
+ ent_camera_unpack( cam, &_world.focus_cam );
}
else
{
- vg_camera_copy( &localplayer.cam, &world_static.focus_cam );
+ vg_camera_copy( &localplayer.cam, &_world.focus_cam );
/* TODO ? */
- world_static.focus_cam.nearz = localplayer.cam.nearz;
- world_static.focus_cam.farz = localplayer.cam.farz;
+ _world.focus_cam.nearz = localplayer.cam.nearz;
+ _world.focus_cam.farz = localplayer.cam.farz;
}
}
if( skaterift.activity == k_skaterift_ent_focus )
active = 1;
- vg_slewf( &world_static.focus_strength, active,
+ vg_slewf( &_world.focus_strength, active,
vg.time_frame_delta * (1.0f/0.5f) );
- if( world_static.focused_entity == 0 )
+ if( _world.focused_entity == 0 )
return;
- u32 type = mdl_entity_id_type( world_static.focused_entity ),
- index = mdl_entity_id_id( world_static.focused_entity );
+ u32 type = mdl_entity_id_type( _world.focused_entity ),
+ index = mdl_entity_id_id( _world.focused_entity );
world_instance *world = world_current_instance();
return;
}
- u32 type = mdl_entity_id_type( world_static.focused_entity ),
- index = mdl_entity_id_id( world_static.focused_entity );
+ u32 type = mdl_entity_id_type( _world.focused_entity ),
+ index = mdl_entity_id_id( _world.focused_entity );
if( type == k_ent_skateshop ){
ent_skateshop *skateshop = af_arritm( &world->ent_skateshop, index );
vg_fatal_error( "Programming error\n" );
}
}
+#endif
void world_gen_entities_init( world_instance *world )
{
{ k_ent_volume, &world->ent_volume },
{ k_ent_challenge, &world->ent_challenge },
{ k_ent_glider, &world->ent_glider },
- { k_ent_npc, &world->ent_npc }
};
for( u32 i=0; i<VG_ARRAY_LEN(indexables); i++ )
entity_call_result ent_audio_call( world_instance *world, ent_call *call )
{
- if( world->status == k_world_status_unloading )
- {
- vg_warn( "cannot modify audio while unloading world\n" );
- return k_entity_call_result_invalid;
- }
-
- u8 world_id = (world - world_static.instances) + 1;
u32 index = mdl_entity_id_id( call->id );
ent_audio *audio = af_arritm( &world->ent_audio, index );
float chance = vg_randf64(&vg.rand)*100.0f,
bar = 0.0f;
- for( u32 i=0; i<audio->clip_count; i++ ){
+ for( u32 i=0; i<audio->clip_count; i++ )
+ {
ent_audio_clip *clip = af_arritm( &world->ent_audio_clip,
audio->clip_start+i );
if( audio->behaviour == k_channel_behaviour_unlimited )
{
- audio_oneshot_3d( &clip->_.clip, sound_co,
- audio->transform.s[0],
- audio->volume );
+ audio_channel *ch = audio_get_first_idle_channel();
+
+ if( ch )
+ {
+ audio_channel_init( ch, &clip->_.clip,
+ audio->flags|AUDIO_FLAG_WORLD );
+ audio_channel_set_spacial( ch, sound_co, audio->transform.s[0] );
+ audio_channel_edit_volume( ch, audio->volume, 1 );
+ audio_relinquish_channel( ch );
+ }
}
else if( audio->behaviour == k_channel_behaviour_discard_if_full )
{
if( ch )
{
- audio_channel_init( ch, &clip->_.clip, audio->flags );
+ audio_channel_init( ch, &clip->_.clip,
+ audio->flags | AUDIO_FLAG_WORLD );
audio_channel_group( ch, audio->group );
- audio_channel_world( ch, world_id );
audio_channel_set_spacial( ch, sound_co, audio->transform.s[0] );
audio_channel_edit_volume( ch, audio->volume, 1 );
ch = audio_relinquish_channel( ch );
audio->max_channels );
/* group is full */
- if( !ch ){
+ if( !ch )
+ {
audio_channel *existing =
audio_get_group_first_active_channel( audio->group );
- if( existing ){
- if( existing->source == &clip->_.clip ){
+ if( existing )
+ {
+ if( existing->source == &clip->_.clip )
+ {
audio_unlock();
return k_entity_call_result_OK;
}
if( ch )
{
- audio_channel_init( ch, &clip->_.clip, audio->flags );
+ audio_channel_init( ch, &clip->_.clip,
+ audio->flags | AUDIO_FLAG_WORLD );
audio_channel_group( ch, audio->group );
- audio_channel_world( ch, world_id );
audio_channel_fadein( ch, audio->crossfade );
ch = audio_relinquish_channel( ch );
}
m4x3_expand_aabb_aabb( transform, bound,
(boxf){{-1.0f,-1.0f,-1.0f},{ 1.0f, 1.0f, 1.0f}} );
}
- else if( type == k_ent_npc )
- {
- ent_npc *npc = af_arritm( &world->ent_npc, index );
- box_addpt( bound, npc->transform.co );
- }
else{
vg_fatal_error( "Programming error\n" );
}
ent_glider *glider = af_arritm( &world->ent_glider, index );
return glider->transform.co[axis];
}
- else if( type == k_ent_npc )
- {
- ent_npc *npc = af_arritm( &world->ent_npc, index );
- return npc->transform.co[axis];
- }
else
{
vg_fatal_error( "Programming error\n" );
void update_ach_models(void)
{
- world_instance *hub = &world_static.instances[k_world_purpose_hub];
+#if 0
+ world_instance *hub = &_world.instances[k_world_purpose_hub];
if( hub->status != k_world_status_loaded ) return;
for( u32 i=0; i<af_arrcount( &hub->ent_prop ); i ++ )
prop->flags &= ~0x1;
}
}
+#endif
}
void entity_bh_closest( void *user, u32 item_index, v3f point, v3f closest )
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_focus_preupdate(void);
void world_entity_focus_render(void);
void world_entity_focus_camera( world_instance *world, u32 uid );
+#endif
+
void update_ach_models(void);
extern bh_system bh_system_entity_list;
--- /dev/null
+#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 */
+ }
+ }
+ }
+}
--- /dev/null
+#pragma once
+
+void world_events_update(void);
float d = v3_dot( surface, v0 );
- if( d > 0.00001f ){
+ if( d > 0.00001f )
+ {
float t = v3_dot(delta, surface) / d;
- if( t >= 0.0f && t <= l ){
+ if( t >= 0.0f && t <= l )
+ {
v3f local, rel;
v3_muladds( last, v0, t, local );
v3_sub( gate->co[0], local, rel );
{
v2f xy;
- if( gate_intersect_plane( gate, pos, last, xy ) ){
+ if( gate_intersect_plane( gate, pos, last, xy ) )
+ {
if( (fabsf(xy[0]) <= gate->dimensions[0]) &&
- (fabsf(xy[1]) <= gate->dimensions[1]) ){
+ (fabsf(xy[1]) <= gate->dimensions[1]) )
+ {
return 1;
}
}
*/
u32 world_intersect_gates( world_instance *world, v3f pos, v3f last )
{
- for( u32 i=0; i<af_arrcount(&world->ent_gate); i++ ){
+ for( u32 i=0; i<af_arrcount(&world->ent_gate); i++ )
+ {
ent_gate *gate = af_arritm( &world->ent_gate, i );
- if( !(gate->flags & k_ent_gate_linked) ) continue;
- if( gate->flags & k_ent_gate_locked ) continue;
+ if( !(gate->flags & k_ent_gate_linked) )
+ continue;
- if( gate->flags & k_ent_gate_nonlocal ){
- if( world_static.instances[gate->target].status
- != k_world_status_loaded )
- continue;
- }
+ if( gate->flags & k_ent_gate_locked )
+ continue;
if( gate_intersect( gate, pos, last ) )
return mdl_entity_id( k_ent_gate, i );
}
}
-
-/*
- * detatches any nonlocal gates
- */
-void world_unlink_nonlocal( world_instance *world )
-{
- for( u32 j=0; j<af_arrcount(&world->ent_gate); j ++ )
- {
- ent_gate *gate = af_arritm( &world->ent_gate, j );
-
- if( gate->flags & k_ent_gate_nonlocal )
- {
- gate->flags &= ~k_ent_gate_linked;
- }
- }
-}
-
/*
* This has to be synchronous because main thread looks at gate data for
* rendering, and we modify gates that the main thread has ownership of.
VG_ASSERT( vg_thread_purpose() == k_thread_purpose_main );
world_instance *world = payload;
- u32 world_id = world - world_static.instances;
-
for( u32 j=0; j<af_arrcount(&world->ent_gate); j ++ )
{
ent_gate *gate = af_arritm( &world->ent_gate, j );
gate_transform_update( gate );
-
- if( skaterift.demo_mode )
- if( world_static.instance_addons[world_id]->flags & ADDON_REG_PREMIUM )
- continue;
-
- if( !(gate->flags & k_ent_gate_nonlocal) ) continue;
- if( gate->flags & k_ent_gate_linked ) continue;
-
- const char *key = af_str( &world->meta.af, gate->key );
- vg_info( "key: %s\n", key );
-
- for( u32 i=0; i<VG_ARRAY_LEN(world_static.instances); i++ ){
- world_instance *other = &world_static.instances[i];
- if( other == world ) continue;
- if( other->status != k_world_status_loaded ) continue;
- vg_info( "Checking world %u for key matches\n", i );
-
- for( u32 k=0; k<af_arrcount( &other->ent_gate ); k++ ){
- ent_gate *gate2 = af_arritm( &other->ent_gate, k );
-
- if( !(gate2->flags & k_ent_gate_nonlocal) ) continue;
- if( gate2->flags & k_ent_gate_linked ) continue;
-
- const char *key2 = af_str( &other->meta.af, gate2->key );
- vg_info( " key2: %s\n", key2 );
-
- if( strcmp( key, key2 ) ) continue;
-
- vg_success( "Non-local matching pair '%s' found. (%u:%u)\n",
- key, world_id, i );
-
- gate->flags |= k_ent_gate_linked;
- gate2->flags |= k_ent_gate_linked;
- gate->target = i;
- gate2->target = world_id;
-
- v3_copy( gate->co[0], gate2->co[1] );
- v3_copy( gate2->co[0], gate->co[1] );
- v4_copy( gate->q[0], gate2->q[1] );
- v4_copy( gate2->q[0], gate->q[1] );
-
- if( world->meta.version < 102 ){
- /* LEGACY BEHAVIOUR: v101
- * this would flip both the client worlds portal's entrance and
- * exit. effectively the clients portal would be the opposite
- * to the hub worlds one. new behaviour is to just flip the
- * destinations so the rules are consistent in each world.
- */
- v4f qflip;
- q_axis_angle( qflip, (v3f){0.0f,1.0f,0.0f}, VG_PIf );
- q_mul( gate->q[0], qflip, gate->q[0] );
- q_mul( gate->q[1], qflip, gate->q[1] );
- q_mul( gate2->q[1], qflip, gate2->q[1] );
- }
-
- gate_transform_update( gate );
- gate_transform_update( gate2 );
-
- goto matched;
- }
- } matched:;
}
}
/*
* load the .mdl file located in path as a world instance
*/
-static void world_instance_load_mdl( u32 instance_id, const char *path ){
- world_instance *world = &world_static.instances[ instance_id ];
- world_init_blank( world );
- world->status = k_world_status_loading;
-
- vg_info( "Loading instance[%u]: %s\n", instance_id, path );
-
- void *allocator = NULL;
- if( instance_id == 0 ) allocator = world_static.heap;
- else allocator = world_static.instances[instance_id-1].heap;
-
- u32 heap_availible = vg_linear_remaining( allocator );
- u32 min_overhead = sizeof(vg_linear_allocator);
-
- if( heap_availible < (min_overhead+1024) ){
- vg_fatal_error( "out of memory" );
- }
-
- u32 size = heap_availible - min_overhead;
- void *heap = vg_create_linear_allocator( allocator, size, VG_MEMORY_SYSTEM );
+static void world_instance_load_mdl( world_instance *world, const char *path,
+ void *heap )
+{
+ vg_loader_set_user_information( "Loading world data" );
+ world_init_blank( world );
world->heap = heap;
+
+ vg_info( "Loading world model: %s\n", path );
+
mdl_context *meta = &world->meta;
array_file_context *af = &meta->af;
AF_LOAD_ARRAY_STRUCT( af, &world->ent_prop, ent_prop, heap );
AF_LOAD_ARRAY_STRUCT( af, &world->ent_region, ent_region, heap );
AF_LOAD_ARRAY_STRUCT( af, &world->ent_glider, ent_glider, heap );
- AF_LOAD_ARRAY_STRUCT( af, &world->ent_npc, ent_npc, heap );
array_file_ptr infos;
AF_LOAD_ARRAY_STRUCT( af, &infos, ent_worldinfo, vg_mem.scratch );
world->info.flags = 0;
}
+ vg_loader_set_user_information( "Compiling world details" );
+
time_t seconds = time(NULL) % ((u32)vg_maxf(1.0f,k_day_length)*60);
world->time = ((f64)(seconds)/(k_day_length*60.0));
world->time += (world->info.timezone/24.0);
u64 t0 = SDL_GetPerformanceCounter();
world_gen_generate_meshes( world );
u64 t1 = SDL_GetPerformanceCounter();
- world_gen_routes_generate( instance_id );
+ world_gen_routes_generate( world );
u64 t2 = SDL_GetPerformanceCounter();
world_gen_compute_light_indices( world );
u64 t3 = SDL_GetPerformanceCounter();
vg_info( "wtime:mesh %.2fms route %.2fms ind %.2fms tex %.2fms ent %.2fms\n",
ftime_mesh, ftime_route, ftime_ind, ftime_tex, ftime_ent );
- /* init player position.
- * - this is overriden by the save state when(if) it loads */
- world_default_spawn_pos( world, world->player_co );
-
/* allocate leaderboard buffers */
u32 bs = af_arrcount(&world->ent_route)*sizeof(struct leaderboard_cache);
world->leaderboard_cache = vg_linear_alloc( heap, bs );
world->routes_ui = vg_linear_alloc( heap,
sizeof(struct route_ui)*af_arrcount(&world->ent_route) );
+ vg_loader_set_user_information( "Postprocessing world" );
vg_async_call( async_world_postprocess, world, 0 );
vg_async_stall();
-}
-struct world_load_complete_data{
- savedata_file save;
- enum world_purpose purpose;
-};
+ vg_loader_set_user_information( NULL );
+}
-static void skaterift_world_load_done( void *payload, u32 size )
+static void async_world_loader_done( void *payload, u32 size )
{
- struct world_load_complete_data *data = payload;
- world_instance *world = &world_static.instances[ data->purpose ];
-
- vg_msg sav;
- vg_msg_init( &sav, data->save.buf, data->save.len );
-
- if( data->purpose != k_world_purpose_hub )
- {
- vg_msg player_frame = sav;
- if( vg_msg_seekframe( &player_frame, "player" ) )
- {
- vg_msg_getkvvecf( &player_frame, "position", k_vg_msg_v3f,
- world->player_co, NULL );
- }
- }
-
- world_entity_start( world, &sav );
- world->status = k_world_status_loaded;
- world_static.load_state = k_world_loader_none;
-
- if( world_static.clear_async_op_when_done )
- {
- g_client.loaded = 1;
- world_static.clear_async_op_when_done = 0;
- }
+ _world.loader_state = k_world_loader_done;
}
-/*
- * Does a complete world switch using the remaining free slots
- */
void skaterift_world_load_thread( void *_args )
{
- struct world_load_args args = *((struct world_load_args *)_args);
+ vg_loader_set_user_information( "Scanning world directory" );
- addon_reg *reg = args.reg;
- world_static.instance_addons[ args.purpose ] = reg;
+ struct world_load_args args = *((struct world_load_args *)_args);
+ args.instance->addon = args.reg;
char uid[ADDON_UID_MAX];
- addon_alias_uid( ®->alias, uid );
- vg_info( "LOAD WORLD %s @%d\n", uid, args.purpose );
+ addon_alias_uid( &args.reg->alias, uid );
+ vg_info( "LOAD WORLD %s @%d\n", uid );
char path_buf[4096];
vg_str path;
vg_strnull( &path, path_buf, 4096 );
- addon_get_content_folder( reg, &path, 1 );
+ addon_get_content_folder( args.reg, &path, 1 );
vg_str folder = path;
- if( !vg_strgood( &folder ) ) {
+ if( !vg_strgood( &folder ) )
+ {
vg_error( "Load target too long\n" );
return;
}
- char worlds[k_world_max-1][4096];
- u32 i=0;
+ char mdl_path[4096];
+
+ bool found_any_mdl = 0,
+ found_main_mdl = 0;
vg_dir dir;
- if( !vg_dir_open(&dir, folder.buffer) ){
+ if( !vg_dir_open(&dir, folder.buffer) )
+ {
vg_error( "opendir('%s') failed\n", folder.buffer );
return;
}
- while( vg_dir_next_entry(&dir) ){
- if( vg_dir_entry_type(&dir) == k_vg_entry_type_file ){
+ while( vg_dir_next_entry(&dir) )
+ {
+ if( vg_dir_entry_type(&dir) == k_vg_entry_type_file )
+ {
const char *d_name = vg_dir_entry_name(&dir);
- if( d_name[0] == '.' ) continue;
+ if( d_name[0] == '.' )
+ continue;
vg_str file = folder;
vg_strcat( &file, "/" );
vg_strcat( &file, d_name );
- if( !vg_strgood( &file ) ) continue;
+ if( !vg_strgood( &file ) )
+ continue;
char *ext = vg_strch( &file, '.' );
- if( !ext ) continue;
- if( strcmp(ext,".mdl") ) continue;
+ if( !ext )
+ continue;
+
+ if( strcmp(ext,".mdl") )
+ continue;
- if( i == k_world_max-1 ){
- vg_warn( "There are too many .mdl files in the map folder!(3)\n" );
+ if( !strcmp( d_name, "main.mdl" ) )
+ {
+ found_any_mdl = 1;
+ found_main_mdl = 1;
+ strcpy( mdl_path, file.buffer );
break;
}
-
- strcpy( worlds[i++], file.buffer );
+ else
+ {
+ if( !found_any_mdl )
+ {
+ found_any_mdl = 1;
+ strcpy( mdl_path, file.buffer );
+ }
+ }
}
}
vg_dir_close(&dir);
- if( i == 0 ){
- vg_warn( "There are no .mdl files in the map folder.\n" );
- }
-
- u32 first_index = 0;
- for( u32 j=0; j<i; j++ ){
- vg_str name = { .buffer = worlds[j], .i=strlen(worlds[j]),
- sizeof(worlds[j]) };
- char *fname = vg_strch( &name, '/' );
- if( fname ){
- if( !strcmp( fname+1, "main.mdl" ) ){
- first_index = j;
- }
+ if( found_any_mdl )
+ {
+ if( !found_main_mdl )
+ {
+ vg_warn( "World model file is not called 'main.mdl'\n"
+ "Path: %s\n", mdl_path );
}
}
+ else
+ {
+ vg_fatal_error( "No .mdl files found in the map folder.\n" );
+ }
+
+ world_instance_load_mdl( args.instance, mdl_path, args.heap );
+
+ vg_async_call( async_world_loader_done, NULL, 0 );
+ vg_async_stall();
+}
+
+struct world_savedata_thread_data
+{
+ savedata_file save;
+ world_instance *instance;
+};
- world_instance_load_mdl( args.purpose, worlds[first_index] );
+void async_start_player_from_worldsave( void *payload, u32 size )
+{
+ struct world_savedata_thread_data *data = payload;
- vg_async_item *final_call =
- vg_async_alloc( sizeof(struct world_load_complete_data) );
+ vg_msg sav;
+ vg_msg_init( &sav, data->save.buf, data->save.len );
- struct world_load_complete_data *data = final_call->payload;
- data->purpose = args.purpose;
+ /* start entities in the world */
+ world_entity_start( data->instance, &sav );
+ world_default_spawn_pos( data->instance, localplayer.rb.co );
- skaterift_world_get_save_path( args.purpose, data->save.path );
+ /* start player in the world */
+ vg_msg_init( &sav, data->save.buf, data->save.len );
+ vg_msg player_frame = sav;
+ if( vg_msg_seekframe( &player_frame, "player" ) )
+ {
+ vg_msg_getkvvecf( &player_frame, "position", k_vg_msg_v3f,
+ localplayer.rb.co, NULL );
+ }
+ player__reset();
+}
+
+void load_player_from_world_savedata_thread( void *_args )
+{
+ struct world_load_args *args = _args;
+
+ vg_async_item *call = vg_async_alloc( sizeof(struct world_savedata_thread_data) );
+ struct world_savedata_thread_data *data = call->payload;
+
+ data->instance = args->instance;
+ skaterift_world_get_save_path( args->reg, data->save.path );
savedata_file_read( &data->save );
- vg_async_dispatch( final_call, skaterift_world_load_done );
+ vg_async_dispatch( call, async_start_player_from_worldsave );
vg_async_stall();
}
-void skaterift_change_client_world_preupdate(void)
+void async_world_switcher_done( void *payload, u32 size )
{
- if( world_static.load_state != k_world_loader_preload )
+ _world.switch_to_addon = NULL;
+ g_client.unreadyness --;
+}
+
+void world_switcher_thread( void *_ )
+{
+ struct world_load_args args =
+ {
+ .reg = _world.switch_to_addon,
+ .instance = &_world.main,
+ .heap = _world.heap
+ };
+
+ skaterift_world_load_thread( &args );
+ vg_async_stall();
+
+ load_player_from_world_savedata_thread( &args );
+ vg_async_stall();
+
+ vg_async_call( async_world_switcher_done, NULL, 0 );
+}
+
+void world_switcher_update(void)
+{
+ if( !_world.switch_to_addon )
return;
- /* holding pattern before we can start loading the new world, since we might
- * be waiting for audio to stop */
- for( u32 i=1; i<k_world_max; i++ )
+ if( _world.loader_state == k_world_loader_saving_current )
{
- world_instance *inst = &world_static.instances[i];
-
- if( inst->status == k_world_status_unloading )
+ if( skaterift_write_all_savedata(1) )
{
- if( world_freeable( inst ) )
- {
- world_free( inst );
- }
- return;
+ _world.loader_state = k_world_loader_unloading_current;
+ vg_loader_set_user_information( "Unloading current world" );
}
}
- if( vg_loader_availible() )
+ /* pre-load step aka waiting for audio to end. */
+ if( _world.loader_state == k_world_loader_unloading_current )
{
- vg_info( "worlds cleared, begining load\n" );
- world_static.load_state = k_world_loader_load;
+ bool all_world_audio_stopped = 1;
+ audio_lock();
+ for( u32 i=0; i<AUDIO_CHANNELS; i++ )
+ {
+ audio_channel *ch = &vg_audio.channels[i];
+ if( ch->allocated && (ch->flags & AUDIO_FLAG_WORLD))
+ {
+ if( !audio_channel_finished( ch ) )
+ {
+ all_world_audio_stopped = 0;
+ break;
+ }
+ }
+ }
+ audio_unlock();
+
+ if( !all_world_audio_stopped )
+ return;
- vg_linear_clear( vg_async.buffer );
- 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.instance_addons[ k_world_purpose_client ];
+ world_instance_free_graphics_data( &_world.main );
+ _world.loader_state = k_world_loader_ready;
+ vg_loader_set_user_information( "Waiting for loading thread" );
+ }
- /* this is replaces the already correct reg but we have to set it again
- * TOO BAD */
+ if( _world.loader_state == k_world_loader_ready )
+ {
+ if( vg_loader_availible() )
+ {
+ _world.loader_state = k_world_loader_loading;
- /* finally can start the loader */
- vg_loader_start( skaterift_world_load_thread, args );
+ vg_linear_clear( vg_async.buffer );
+ vg_linear_clear( _world.heap );
+ vg_loader_start( world_switcher_thread, NULL );
+ }
}
}
-/*
- * places all loaded worlds into unloading state, pass NULL to reload the world
- */
-void skaterift_change_world_start( addon_reg *reg )
+void skaterift_switch_world_start( addon_reg *reg )
{
- if( world_static.instance_addons[ k_world_purpose_client ] == reg )
+ if( g_client.unreadyness )
+ {
+ vg_error( "Cannot start changeworld while client is not ready?\n" );
+ return;
+ }
+
+ if( _world.loader_state != k_world_loader_done )
+ {
+ vg_error( "Cannot start changeworld while loader is not done?\n" );
+ return;
+ }
+
+ if( _world.main.addon == reg )
{
vg_warn( "World is already loaded\n" );
return;
if( !reg )
{
- if( world_static.instance_addons[ k_world_purpose_client ] )
+ if( _world.main.addon )
{
- reg = world_static.instance_addons[ k_world_purpose_client ];
- world_static.clear_async_op_when_done = 1;
+ reg = _world.main.addon;
}
- else
+ else
{
- vg_warn( "No client world loaded\n" );
+ vg_error( "Loaded world has no associated addon registration."
+ " Can't reload this!\n" );
return;
}
}
- world_static.load_state = k_world_loader_preload;
-
- if( world_static.active_instance != 0 )
- g_client.loaded = 0;
+ g_client.unreadyness ++;
+ _world.loader_state = k_world_loader_saving_current;
+ vg_loader_set_user_information( "Saving current world" );
char buf[76];
addon_alias_uid( ®->alias, buf );
vg_info( "switching to: %s\n", buf );
- skaterift_autosave(1);
vg_linear_clear( vg_mem.scratch ); /* ?? */
- vg_info( "unloading old worlds\n" );
+ world_fadeout_audio( &_world.main );
- world_instance *client_world =
- &world_static.instances[ k_world_purpose_client ];
-
- if( client_world->status == k_world_status_loaded )
- {
- client_world->status = k_world_status_unloading;
- world_fadeout_audio( client_world );
- }
-
- world_static.instance_addons[ k_world_purpose_client ] = reg;
- network_send_item( k_netmsg_playeritem_world1 );
- relink_all_remote_player_worlds();
- world_unlink_nonlocal( &world_static.instances[k_world_purpose_hub] );
+ _world.switch_to_addon = reg;
}
/* console command for the above function */
-int skaterift_load_world_command( int argc, const char *argv[] )
+int skaterift_switch_world_command( int argc, const char *argv[] )
{
if( !vg_loader_availible() )
{
{
if( !strcmp( argv[0], "reload" ) )
{
- skaterift_change_world_start( NULL );
+ skaterift_switch_world_start( NULL );
return 0;
}
if( reg_id != 0xffffffff )
{
addon_reg *reg = get_addon_from_index( k_addon_type_world, reg_id, 0 );
- skaterift_change_world_start( reg );
+ skaterift_switch_world_start( reg );
}
else
{
return 0;
}
-/*
- * checks:
- * 1. to see if all audios owned by the world have been stopped
- * 2. that this is the least significant world
- */
-int world_freeable( world_instance *world )
-{
- if( world->status != k_world_status_unloading ) return 0;
- u8 world_id = (world - world_static.instances) + 1;
-
- for( u32 i=world_id; i<VG_ARRAY_LEN(world_static.instances); i++ ){
- if( world_static.instances[i].status != k_world_status_unloaded ){
- return 0;
- }
- }
-
- int freeable = 1;
- audio_lock();
- for( u32 i=0; i<AUDIO_CHANNELS; i++ ){
- audio_channel *ch = &vg_audio.channels[i];
-
- if( ch->allocated && (ch->world_id == world_id)){
- if( !audio_channel_finished( ch ) ){
- freeable = 0;
- break;
- }
- }
- }
- audio_unlock();
- return freeable;
-}
-
-/*
- * Free all resources for world instance
- */
-void world_free( world_instance *world )
+void world_instance_free_graphics_data( world_instance *world )
{
- vg_info( "Free world @%p\n", world );
-
/* free meshes */
mesh_free( &world->mesh_route_lines );
mesh_free( &world->mesh_geo );
mesh_free( &world->mesh_no_collide );
- /* glDeleteBuffers silently ignores 0's and names that do not correspond to
- * existing buffer objects.
- * */
glDeleteBuffers( 1, &world->tbo_light_entities );
glDeleteTextures( 1, &world->tex_light_entities );
glDeleteTextures( 1, &world->tex_light_cubes );
/* delete textures and meshes */
glDeleteTextures( world->texture_count-1, world->textures+1 );
- u32 world_index = world - world_static.instances;
- if( world_index ){
- vg_linear_del( world_static.instances[world_index-1].heap,
- vg_linear_header(world->heap) );
- }
-
- for( u32 i=0; i<af_arrcount(&world->ent_cubemap); i++ ){
+ for( u32 i=0; i<af_arrcount(&world->ent_cubemap); i++ )
+ {
ent_cubemap *cm = af_arritm(&world->ent_cubemap,i);
glDeleteTextures( 1, &cm->texture_id );
glDeleteFramebuffers( 1, &cm->framebuffer_id );
glDeleteRenderbuffers( 1, &cm->renderbuffer_id );
}
-
- world->status = k_world_status_unloaded;
}
/*
#include "world.h"
#include "addon.h"
-void world_free( world_instance *world );
-int world_freeable( world_instance *world );
-int skaterift_load_world_command( int argc, const char *argv[] );
-void skaterift_change_world_start( addon_reg *reg );
-void skaterift_change_client_world_preupdate(void);
+int skaterift_switch_world_command( int argc, const char *argv[] );
+void skaterift_switch_world_start( addon_reg *reg );
+void world_switcher_update(void);
+void world_switcher_thread( void *_ );
+void world_instance_free_graphics_data( world_instance *world );
static void world_map_get_plane( v4f plane )
{
- world_instance *world = &world_static.instances[ world_map.world_id ];
+ world_instance *world = &_world.main;
f32 h = localplayer.rb.co[1];
- if( world_map.world_id != world_static.active_instance )
- h = (world->scene_geo.bbx[0][1] + world->scene_geo.bbx[1][1]) * 0.5f;
v4_copy( (v4f){0.0f,1.0f,0.0f,h}, plane );
}
static void world_map_select_close(void)
{
world_map.sel_spawn = world_map.close_spawn;
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_default );
vg_str text;
if( gui_new_helper( input_button_list[k_srbind_maccept], &text ) )
static void world_map_help_normal(void)
{
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_default );
vg_str text;
if( gui_new_helper( input_joy_list[k_srjoystick_steer], &text ) )
if( gui_new_helper( input_button_list[k_srbind_mback], &text ) )
vg_strcat( &text, "Exit" );
-
- if( world_static.instances[1].status == k_world_status_loaded )
- {
- if( gui_new_helper( input_button_list[k_srbind_mhub], &text ) )
- vg_strcat( &text, world_static.active_instance?
- "Go to Hub": "Go to Active World" );
- }
}
void world_map_pre_update(void)
{
if( !world_map.view_ready )
{
- world_map.world_id = world_static.active_instance;
-
- world_instance *world = &world_static.instances[ world_map.world_id ];
+ world_instance *world = &_world.main;
v3f *bbx = world->scene_geo.bbx;
- v3_copy( localplayer.rb.co, world->player_co );
respawn_world_to_plane_pos( localplayer.rb.co, world_map.plane_pos );
world_map.boom_dist = 400.0f;
world_map.home_select = 0;
{
if( world_map.view_ready )
{
- gui_helper_clear();
+ gui_helper_reset( k_gui_helper_mode_clear );
world_map.view_ready = 0;
}
return;
}
- world_instance *world = &world_static.instances[ world_map.world_id ];
+ world_instance *world = &_world.main;
v3f *bbx = world->scene_geo.bbx;
f32 *pos = world_map.plane_pos;
if( world_map.sel_spawn )
{
skaterift.activity = k_skaterift_default;
- world_static.active_instance = world_map.world_id;
srinput.state = k_input_state_resume;
player__spawn( world_map.sel_spawn );
return;
{
v2f plane_pos;
f32 boom_dist;
- u32 world_id;
u32 home_select;
ent_spawn *sel_spawn, *close_spawn;
#include "ent_miniworld.h"
#include "player_remote.h"
#include "ent_skateshop.h"
-#include "ent_npc.h"
#include "shaders/model_entity.h"
struct world_render world_render;
static int ccmd_set_time( int argc, const char *argv[] ){
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
if( argc == 1 )
world->time = atof( argv[0] );
else
static void async_world_render_init( void *payload, u32 size )
{
vg_info( "Allocate uniform buffers\n" );
- for( int i=0; i<k_world_max; i++ )
- {
- world_instance *world = &world_static.instances[i];
- world->ubo_bind_point = i;
- glGenBuffers( 1, &world->ubo_lighting );
- glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
- glBufferData( GL_UNIFORM_BUFFER, sizeof(struct ub_world_lighting),
- NULL, GL_DYNAMIC_DRAW );
+ world_instance *world = &_world.main;
+ world->ubo_bind_point = 0;
- glBindBufferBase( GL_UNIFORM_BUFFER, i, world->ubo_lighting );
- }
+ glGenBuffers( 1, &world->ubo_lighting );
+ glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
+ glBufferData( GL_UNIFORM_BUFFER, sizeof(struct ub_world_lighting),
+ NULL, GL_DYNAMIC_DRAW );
+
+ glBindBufferBase( GL_UNIFORM_BUFFER, 0, world->ubo_lighting );
}
void world_render_init(void)
&world_render.tex_terrain_noise );
vg_info( "Allocate frame buffers\n" );
- for( int i=0; i<k_world_max; i++ )
+ world_instance *world = &_world.main;
+ world->heightmap = vg_framebuffer_allocate( vg_mem.rtmemory, 1, 0 );
+ world->heightmap->display_name = NULL;
+ world->heightmap->fixed_w = 1024;
+ world->heightmap->fixed_h = 1024;
+ world->heightmap->resolution_div = 0;
+ world->heightmap->attachments[0] = (vg_framebuffer_attachment)
{
- world_instance *world = &world_static.instances[i];
- world->heightmap = vg_framebuffer_allocate( vg_mem.rtmemory, 1, 0 );
- world->heightmap->display_name = NULL;
- world->heightmap->fixed_w = 1024;
- world->heightmap->fixed_h = 1024;
- world->heightmap->resolution_div = 0;
- world->heightmap->attachments[0] = (vg_framebuffer_attachment)
- {
- NULL, k_framebuffer_attachment_type_texture,
- .internalformat = GL_RG16F,
- .format = GL_RG,
- .type = GL_FLOAT,
- .attachment = GL_COLOR_ATTACHMENT0
- };
- vg_framebuffer_create( world->heightmap );
- }
+ NULL, k_framebuffer_attachment_type_texture,
+ .internalformat = GL_RG16F,
+ .format = GL_RG,
+ .type = GL_FLOAT,
+ .attachment = GL_COLOR_ATTACHMENT0
+ };
+ vg_framebuffer_create( world->heightmap );
vg_async_call( async_world_render_init, NULL, 0 );
}
static void world_render_challenges( world_instance *world,
struct world_pass *pass, v3f pos )
{
+#if 0
if( !world ) return;
if( skaterift.activity == k_skaterift_replay ) return;
- if( world != world_current_instance() ) return;
+ if( world != &_world.main ) return;
/* sort lists */
f32 radius = 40.0f;
ent_challenge *active_challenge = NULL;
int running = 0;
- if( mdl_entity_id_type( world_static.focused_entity ) == k_ent_challenge )
+ if( mdl_entity_id_type( _world.focused_entity ) == k_ent_challenge )
{
if( (skaterift.activity == k_skaterift_default) &&
- world_static.challenge_target )
+ _world.challenge_target )
{
running = 1;
}
if( !((skaterift.activity != k_skaterift_ent_focus) &&
- !world_static.challenge_target) )
+ !_world.challenge_target) )
{
- world_instance *challenge_world = world_current_instance();
- u32 index = mdl_entity_id_id( world_static.focused_entity );
+ world_instance *challenge_world = &_world.main;
+ u32 index = mdl_entity_id_id( _world.focused_entity );
active_challenge = af_arritm(&challenge_world->ent_challenge, index);
}
}
{
shader_scene_fxglow_uUvOffset( (v2f){ 8.0f/256.0f, 0.0f } );
challenge_list[ challenge_count ++ ] =
- mdl_entity_id_id( world_static.focused_entity );
+ mdl_entity_id_id( _world.focused_entity );
u32 next = active_challenge->first;
while( mdl_entity_id_type(next) == k_ent_objective )
vg_slewf(&objective->transform.s[0], target, vg.time_frame_delta*4.0f);
scale = vg_smoothstepf( objective->transform.s[0] );
- if( (objective == world_static.challenge_target) || passed )
+ if( (objective == _world.challenge_target) || passed )
shader_scene_fxglow_uUvOffset( (v2f){ 16.0f/256.0f, 0.0f } );
else
shader_scene_fxglow_uUvOffset( (v2f){ 8.0f/256.0f, 0.0f } );
shader_scene_font_uColourize( colour );
font3d_simple_draw( 1, buf, &g_render.cam, mmdl );
}
+#endif
}
static void bindpoint_fxglow( world_instance *world,
float closest = INFINITY;
struct ent_gate *gate = NULL;
- for( u32 i=0; i<af_arrcount(&world->ent_gate); i++ ){
+ for( u32 i=0; i<af_arrcount(&world->ent_gate); i++ )
+ {
ent_gate *gi = af_arritm( &world->ent_gate, i );
if( !(gi->flags & k_ent_gate_nonlocal) )
vg_line_point( gi->co[0], 0.25f, VG__BLUE );
- if( dist < closest ){
+ if( dist < closest )
+ {
closest = dist;
gate = gi;
}
world->rendering_gate = gate;
- if( gate ){
- if( gate->flags & k_ent_gate_locked ){
+ if( gate )
+ {
+ if( gate->flags & k_ent_gate_locked )
+ {
world->rendering_gate = NULL;
return;
}
- if( gate->flags & k_ent_gate_nonlocal ){
- if( !(gate->flags & k_ent_gate_linked) ||
- (world_static.load_state != k_world_loader_none) ){
- world->rendering_gate = NULL;
- render_gate_unlinked( world, gate, cam );
- return;
- }
-
- world_instance *dest_world = &world_static.instances[ gate->target ];
- render_gate( world, dest_world, gate, cam );
+ if( gate->flags & k_ent_gate_nonlocal )
+ {
}
else
render_gate( world, world, gate, cam );
bh_iter_init_range( 0, &it, cam->pos, radius+10.0f );
u32 glider_list[4],
- glider_count = 0,
- npc_list[4],
- npc_count = 0;
+ glider_count = 0;
i32 idx;
while( bh_next( world->entity_bh, &it, &idx ) ){
if( glider_count < VG_ARRAY_LEN(glider_list) )
glider_list[ glider_count ++ ] = index;
}
- else if( type == k_ent_npc )
- {
- if( npc_count < VG_ARRAY_LEN(npc_list) )
- npc_list[ npc_count ++ ] = index;
- }
}
shader_model_entity_use();
render_glider_model( cam, world, mdl, k_board_shader_entity );
}
- for( u32 j=0; j<npc_count; j ++ )
- {
- u32 index = npc_list[j];
- ent_npc *npc = af_arritm( &world->ent_npc, npc_list[j] );
- npc_update( npc );
- npc_render( npc, world, cam );
- }
-
cutscene_render( world, cam );
}
render_terrain( world, cam );
if( !viewing_from_gate ){
+#if 0
world_entity_focus_render();
+#endif
/* Render SFD's */
u32 closest = 0;
if( !viewing_from_gate ){
f32 greyout = 0.0f;
- if( mdl_entity_id_type(world_static.focused_entity) == k_ent_challenge )
- greyout = world_static.focus_strength;
+#if 0
+ if( mdl_entity_id_type(_world.focused_entity) == k_ent_challenge )
+ greyout = _world.focus_strength;
+#endif
if( greyout > 0.0f ){
glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
v4f uPlayerPos, uSpawnPos;
v4_zero( uPlayerPos );
v4_zero( uSpawnPos );
- v3_copy( world->player_co, uPlayerPos );
+ v3_copy( (v3f){0,0,0}, uPlayerPos );
if( dest_spawn && (v3_dist2(dest_spawn->transform.co,uPlayerPos) > 0.1f) )
v3_copy( dest_spawn->transform.co, uSpawnPos );
rg->timing_time = 0.0;
}
- world_static.current_run_version += 4;
- world_static.last_use = 0.0;
+ _world.current_run_version += 4;
}
static void world_routes_time_lap( world_instance *world, ent_route *route )
last_cp = cp;
}
- if( world_static.current_run_version == last_version+1 ){
+ if( _world.current_run_version == last_version+1 ){
valid_sections ++;
if( route->checkpoints_count == 1 ){
- route->timing_base = world_static.time;
+ route->timing_base = _world.time;
}
- f32 section = world_static.time - last_time;
+ f32 section = _world.time - last_time;
if( (section < last_cp->best_time) || (last_cp->best_time == 0.0f) ){
last_cp->best_time = section;
}
else valid_sections = 0;
vg_info( "%u %f [%s]\n",
- world_static.current_run_version, world_static.time,
+ _world.current_run_version, _world.time,
!localplayer.rewinded_since_last_gate? "CLEAN": " " );
if( valid_sections==route->checkpoints_count ){
- f64 lap_time = world_static.time - start_time;
+ f64 lap_time = _world.time - start_time;
if( (route->best_laptime == 0.0) || (lap_time < route->best_laptime) ){
route->best_laptime = lap_time;
}
}
- addon_alias *alias =
- &world_static.instance_addons[ world_static.active_instance ]->alias;
+ addon_alias *alias = &_world.main.addon->alias;
char mod_uid[ ADDON_UID_MAX ];
addon_alias_uid( alias, mod_uid );
*/
void world_routes_activate_entry_gate( world_instance *world, ent_gate *rg )
{
- world_static.last_use = world_static.time;
ent_gate *dest = af_arritm( &world->ent_gate, rg->target );
for( u32 i=0; i<af_arrcount(&world->ent_route); i++ ){
}
}
- dest->timing_version = world_static.current_run_version;
- dest->timing_time = world_static.time;
+ dest->timing_version = _world.current_run_version;
+ dest->timing_time = _world.time;
if( localplayer.rewinded_since_last_gate ){
localplayer.rewinded_since_last_gate = 0;
else
dest->flags |= k_ent_gate_clean_pass;
- world_static.current_run_version ++;
+ _world.current_run_version ++;
}
/* draw lines along the paths */
/*
* Create the strips of colour that run through the world along course paths
*/
-void world_gen_routes_generate( u32 instance_id )
+void world_gen_routes_generate( world_instance *world )
{
- world_instance *world = &world_static.instances[ instance_id ];
vg_info( "Generating route meshes\n" );
vg_async_stall();
void world_routes_init(void)
{
- world_static.current_run_version = 200;
- world_static.time = 300.0;
- world_static.last_use = 0.0;
+ _world.current_run_version = 200;
+ _world.time = 300.0;
}
void world_routes_update( world_instance *world )
{
- world_static.time += vg.time_delta;
+ _world.time += vg.time_delta;
for( u32 i=0; i<af_arrcount(&world->ent_route); i++ ){
ent_route *route = af_arritm( &world->ent_route, i );
if( route->valid_checkpoints >= route->checkpoints_count )
{
- double lap_time = world_static.time - route->timing_base,
+ double lap_time = _world.time - route->timing_base,
time_centiseconds = lap_time * 100.0;
if( time_centiseconds > (float)0xfffe ) time_centiseconds = 0.0;
int viewing_from_gate, int viewing_from_hub );
void world_gen_routes_ent_init( world_instance *world );
-void world_gen_routes_generate( u32 instance_id );
+void world_gen_routes_generate( world_instance *world );
void world_routes_update_timer_texts( world_instance *world );
void world_routes_update( world_instance *world );
void world_routes_fixedupdate( world_instance *world );
last_cp = cp;
}
- if( last_version+1 == world_static.current_run_version ){
+ if( last_version+1 == _world.current_run_version ){
struct time_block *block = &blocks[ valid_sections ++ ];
block->clean = localplayer.rewinded_since_last_gate? 0: 1;
- block->length = world_static.time - last_time;
+ block->length = _world.time - last_time;
block->best = last_cp->best_time;
}
else
void world_sfd_compile_active_scores(void)
{
- world_instance *world = world_current_instance();
+ world_instance *world = &_world.main;
struct leaderboard_cache *board = NULL;
const char *name = "Out of range";
struct leaderboard_cache *board = &world->leaderboard_cache[ closest ];
/* request new board if cache expires */
- if( network_connected() ){
+ if( network_connected() )
+ {
f64 delta = vg.time_real - board->cache_time;
- if( (delta > 45.0) || (board->cache_time == 0.0) ){
+ if( (delta > 45.0) || (board->cache_time == 0.0) )
+ {
board->cache_time = vg.time_real;
ent_route *route = af_arritm( &world->ent_route, closest );
- addon_reg *world_reg =
- world_static.instance_addons[ world - world_static.instances ];
+ addon_reg *world_reg = _world.main.addon;
char mod_uid[ ADDON_UID_MAX ];
addon_alias_uid( &world_reg->alias, mod_uid );
{
/* filter and check the existing ones */
u32 j=0;
- for( u32 i=0; i<world_static.active_trigger_volume_count; i++ ){
- i32 idx = world_static.active_trigger_volumes[i];
+ for( u32 i=0; i<_world.active_trigger_volume_count; i++ ){
+ i32 idx = _world.active_trigger_volumes[i];
ent_volume *volume = af_arritm( &world->ent_volume, idx );
v3f local;
(fabsf(local[1]) <= 1.0f) &&
(fabsf(local[2]) <= 1.0f) )
{
- world_static.active_trigger_volumes[ j ++ ] = idx;
+ _world.active_trigger_volumes[ j ++ ] = idx;
boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}};
vg_line_boxf_transformed( volume->to_world, cube, 0xff00ccff );
}
}
}
}
- world_static.active_trigger_volume_count = j;
+ _world.active_trigger_volume_count = j;
static float random_accum = 0.0f;
random_accum += vg.time_delta;
}
}
else{
- for( u32 i=0; i<world_static.active_trigger_volume_count; i++ )
- if( world_static.active_trigger_volumes[i] == index )
+ for( u32 i=0; i<_world.active_trigger_volume_count; i++ )
+ if( _world.active_trigger_volumes[i] == index )
goto next_volume;
- if( world_static.active_trigger_volume_count >
- VG_ARRAY_LEN(world_static.active_trigger_volumes) ) continue;
+ if( _world.active_trigger_volume_count >
+ VG_ARRAY_LEN(_world.active_trigger_volumes) ) continue;
v3f local;
m4x3_mulv( volume->to_local, pos, local );
if( (fabsf(local[0]) <= 1.0f) &&
(fabsf(local[1]) <= 1.0f) &&
- (fabsf(local[2]) <= 1.0f) ){
+ (fabsf(local[2]) <= 1.0f) )
+ {
ent_call basecall;
basecall.function = 0;
basecall.id = id;
basecall.data = NULL;
entity_call( world, &basecall );
- world_static.active_trigger_volumes[
- world_static.active_trigger_volume_count ++ ] = index;
+ _world.active_trigger_volumes[
+ _world.active_trigger_volume_count ++ ] = index;
}
else
vg_line_boxf_transformed( volume->to_world, cube, 0xffcccccc );
vg_framebuffer_bind_texture( g_render.fb_water_beneath, 0, 5 );
shader_scene_water_uTexBack( 5 );
- shader_scene_water_uTime( world_static.time );
+ shader_scene_water_uTime( _world.time );
shader_scene_water_uCamera( cam->transform[3] );
shader_scene_water_uSurfaceY( world->water.height );
glBindTexture( GL_TEXTURE_2D, world_water.tex_water_surf );
shader_scene_water_fast_uTexDudv( 1 );
- shader_scene_water_fast_uTime( world_static.time );
+ shader_scene_water_fast_uTime( _world.time );
shader_scene_water_fast_uCamera( cam->transform[3] );
shader_scene_water_fast_uSurfaceY( world->water.height );