X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world.c;h=9b19387208ad9a47a5c96805b6923a83185af09b;hb=bececcbb7b2e886e72425e7c070e1fdc3aa126dc;hp=def59a36b3edec09d1fe06aa2a9e1a2c4dd34886;hpb=2c91a71533b4ce86b9e7fd708420ae05c74d8f52;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world.c b/world.c index def59a3..9b19387 100644 --- a/world.c +++ b/world.c @@ -2,17 +2,25 @@ * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved */ -#ifndef WORLD_C -#define WORLD_C - +#include "skaterift.h" #include "world.h" #include "network.h" +#include "vg/vg_loader.h" +#include "vg/vg_mem.h" +#include "save.h" +#include "player.h" +#include "ent_traffic.h" + +struct world_static world_static; -static world_instance *world_current_instance(void){ +world_instance *world_current_instance(void) +{ return &world_static.instances[ world_static.active_instance ]; } -static void world_init(void) +static int skaterift_switch_instance_cmd( int argc, const char *argv[] ); + +void world_init(void) { vg_loader_step( world_render_init, NULL ); vg_loader_step( world_sfd_init, NULL ); @@ -24,10 +32,14 @@ static void world_init(void) u32 max_size = 76*1024*1024; world_static.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 ); } -static void world_switch_instance( u32 index ){ - assert( localplayer.subsystem == k_player_subsystem_walk ); +void world_switch_instance( u32 index ) +{ + localplayer.subsystem = k_player_subsystem_walk; if( index >= vg_list_size(world_static.instances) ){ vg_error( "Instance ID out of range (%u)\n", index ); @@ -41,24 +53,29 @@ static void world_switch_instance( u32 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 ){ - world_instance *current = - &world_static.instances[ world_static.active_instance ]; v3_copy( localplayer.rb.co, current->player_co ); - v3_copy( localplayer.angles, current->player_angles ); - current->player_angles[3] = player_get_heading_yaw(); + skaterift_autosave(1); } v3_copy( new->player_co, localplayer.rb.co ); - v3_copy( new->player_angles, localplayer.angles ); - q_axis_angle( localplayer.rb.q, (v3f){0,1,0}, new->player_angles[3] ); world_static.active_instance = index; - player__reset(); } -static int skaterift_switch_instance_cmd( int argc, const char *argv[] ){ +static int skaterift_switch_instance_cmd( int argc, const char *argv[] ) +{ if( argc ) world_switch_instance( atoi(argv[0]) ); else @@ -66,30 +83,20 @@ static int skaterift_switch_instance_cmd( int argc, const char *argv[] ){ return 0; } -static void skaterift_world_get_save_path( enum world_purpose which, - char buf[128] ){ +void skaterift_world_get_save_path( enum world_purpose which, char buf[128] ) +{ addon_reg *reg = world_static.instance_addons[ which ]; - assert( reg ); + + if( !reg ) + vg_fatal_error( "Looking up addon for world without one\n" ); char id[76]; addon_alias_uid( ®->alias, id ); snprintf( buf, 128, "savedata/%s.bkv", id ); } -#include "world_entity.c" -#include "world_gate.c" -#include "world_gen.c" -#include "world_load.c" -#include "world_physics.c" -#include "world_render.c" -#include "world_sfd.c" -#include "world_volumes.c" -#include "world_water.c" -#include "world_audio.c" -#include "world_routes.c" -#include "world_traffic.c" - -static void world_update( world_instance *world, v3f pos ){ +void world_update( world_instance *world, v3f pos ) +{ world_render.sky_time += world_render.sky_rate * vg.time_delta; world_render.sky_rate = vg_lerp( world_render.sky_rate, world_render.sky_target_rate, @@ -97,9 +104,7 @@ static void world_update( world_instance *world, v3f pos ){ world_routes_update_timer_texts( world ); world_routes_update( world ); - world_traffic_update( world, pos ); + ent_traffic_update( world, pos ); world_sfd_update( world, pos ); world_volumes_update( world, pos ); } - -#endif /* WORLD_C */