2 * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
10 #include "vg/vg_loader.h"
11 #include "vg/vg_mem.h"
13 static world_instance
*world_current_instance(void){
14 return &world_static
.instances
[ world_static
.active_instance
];
17 static void world_init(void)
19 vg_loader_step( world_render_init
, NULL
);
20 vg_loader_step( world_sfd_init
, NULL
);
21 vg_loader_step( world_water_init
, NULL
);
22 vg_loader_step( world_gates_init
, NULL
);
23 vg_loader_step( world_routes_init
, NULL
);
25 /* Allocate dynamic world memory arena */
26 u32 max_size
= 76*1024*1024;
27 world_static
.heap
= vg_create_linear_allocator( vg_mem
.rtmemory
, max_size
,
31 static void world_switch_instance( u32 index
){
32 localplayer
.subsystem
= k_player_subsystem_walk
;
34 if( index
>= vg_list_size(world_static
.instances
) ){
35 vg_error( "Instance ID out of range (%u)\n", index
);
39 world_instance
*new = &world_static
.instances
[ index
];
41 if( new->status
!= k_world_status_loaded
){
42 vg_error( "Instance is not loaded (%u)\n", index
);
46 if( skaterift
.demo_mode
){
47 if( world_static
.instance_addons
[index
]->flags
& ADDON_REG_PREMIUM
){
48 vg_error( "Can't switch to a premium world in the demo version\n" );
53 world_instance
*current
=
54 &world_static
.instances
[ world_static
.active_instance
];
56 if( index
!= world_static
.active_instance
){
57 v3_copy( localplayer
.rb
.co
, current
->player_co
);
58 skaterift_autosave(1);
61 v3_copy( new->player_co
, localplayer
.rb
.co
);
63 world_static
.active_instance
= index
;
67 static int skaterift_switch_instance_cmd( int argc
, const char *argv
[] ){
69 world_switch_instance( atoi(argv
[0]) );
71 vg_info( "switch_active_instance <id>\n" );
75 static void skaterift_world_get_save_path( enum world_purpose which
,
77 addon_reg
*reg
= world_static
.instance_addons
[ which
];
80 vg_fatal_error( "Looking up addon for world without one\n" );
83 addon_alias_uid( ®
->alias
, id
);
84 snprintf( buf
, 128, "savedata/%s.bkv", id
);
87 #include "world_entity.c"
88 #include "world_gate.c"
89 #include "world_gen.c"
90 #include "world_load.c"
91 #include "world_physics.c"
92 #include "world_render.c"
93 #include "world_sfd.c"
94 #include "world_volumes.c"
95 #include "world_water.c"
96 #include "world_audio.c"
97 #include "world_routes.c"
99 static void world_update( world_instance
*world
, v3f pos
){
100 world_render
.sky_time
+= world_render
.sky_rate
* vg
.time_delta
;
101 world_render
.sky_rate
= vg_lerp( world_render
.sky_rate
,
102 world_render
.sky_target_rate
,
103 vg
.time_delta
* 5.0 );
105 world_routes_update_timer_texts( world
);
106 world_routes_update( world
);
107 ent_traffic_update( world
, pos
);
108 world_sfd_update( world
, pos
);
109 world_volumes_update( world
, pos
);