2 * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
8 #include "vg/vg_loader.h"
12 #include "ent_traffic.h"
14 struct world_static world_static
;
16 world_instance
*world_current_instance(void)
18 return &world_static
.instances
[ world_static
.active_instance
];
21 static int skaterift_switch_instance_cmd( int argc
, const char *argv
[] );
25 vg_loader_step( world_render_init
, NULL
);
26 vg_loader_step( world_sfd_init
, NULL
);
27 vg_loader_step( world_water_init
, NULL
);
28 vg_loader_step( world_gates_init
, NULL
);
29 vg_loader_step( world_routes_init
, NULL
);
31 /* Allocate dynamic world memory arena */
32 u32 max_size
= 76*1024*1024;
33 world_static
.heap
= vg_create_linear_allocator( vg_mem
.rtmemory
, max_size
,
36 vg_console_reg_cmd( "switch_active_instance",
37 skaterift_switch_instance_cmd
, NULL
);
40 void world_switch_instance( u32 index
)
42 localplayer
.subsystem
= k_player_subsystem_walk
;
44 if( index
>= vg_list_size(world_static
.instances
) ){
45 vg_error( "Instance ID out of range (%u)\n", index
);
49 world_instance
*new = &world_static
.instances
[ index
];
51 if( new->status
!= k_world_status_loaded
){
52 vg_error( "Instance is not loaded (%u)\n", index
);
56 if( skaterift
.demo_mode
){
57 if( world_static
.instance_addons
[index
]->flags
& ADDON_REG_PREMIUM
){
58 vg_error( "Can't switch to a premium world in the demo version\n" );
63 world_instance
*current
=
64 &world_static
.instances
[ world_static
.active_instance
];
66 if( index
!= world_static
.active_instance
){
67 v3_copy( localplayer
.rb
.co
, current
->player_co
);
68 skaterift_autosave(1);
71 v3_copy( new->player_co
, localplayer
.rb
.co
);
73 world_static
.active_instance
= index
;
77 static int skaterift_switch_instance_cmd( int argc
, const char *argv
[] )
80 world_switch_instance( atoi(argv
[0]) );
82 vg_info( "switch_active_instance <id>\n" );
86 void skaterift_world_get_save_path( enum world_purpose which
, char buf
[128] )
88 addon_reg
*reg
= world_static
.instance_addons
[ which
];
91 vg_fatal_error( "Looking up addon for world without one\n" );
94 addon_alias_uid( ®
->alias
, id
);
95 snprintf( buf
, 128, "savedata/%s.bkv", id
);
98 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
);