X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=skaterift.c;h=2edd7dc5231a84d5fa148270f815b124dbeb2e2b;hb=a8ba9cc44e1ae9aeca62fb579a3105c625e59133;hp=1d8e564359ef810e34532e131a876b568f417454;hpb=249fe329869e43961d4e1d4e44f08c6225e195c7;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/skaterift.c b/skaterift.c index 1d8e564..2edd7dc 100644 --- a/skaterift.c +++ b/skaterift.c @@ -11,7 +11,11 @@ * ============================================================================= */ +#if 1 + #define SR_NETWORKED +#define VG_DEVWINDOW + #include "common.h" #include "conf.h" #include "steam.h" @@ -19,33 +23,24 @@ #include "audio.h" #include "world.h" #include "font.h" - - - #include "player.h" -static player_instance localplayer; -VG_STATIC struct player_avatar localplayer_avatar; -VG_STATIC glmesh localplayer_meshes[3]; -vg_tex2d localplayer_texture = { .path = "textures/ch_gradient.qoi" }; -player_instance *tmp_localplayer(void) -{ - return &localplayer; -} +#include "entity.c" +#include "workshop.c" #include "network.h" #include "menu.h" #include "vehicle.h" -static int cl_ui = 1, - cl_light_edit = 0; +static struct player_avatar localplayer_avatar; +static struct player_model localplayer_models[3]; + int main( int argc, char *argv[] ) { vg_mem.use_libc_malloc = 0; vg_set_mem_quota( 160*1024*1024 ); vg_enter( argc, argv, "Voyager Game Engine" ); - return 0; } @@ -56,98 +51,14 @@ VG_STATIC void highscores_save_at_exit(void) VG_STATIC void vg_launch_opt(void) { - -} - -VG_STATIC int __kill( int argc, const char *argv[] ) -{ -#if 0 - player_use_device( &localplayer, &player_device_dead, &localplayer_dead ); -#endif - return 0; -} - -VG_STATIC int __respawn( int argc, const char *argv[] ) -{ - ent_spawn *rp = NULL, *r; - world_instance *world = get_active_world(); - - if( argc == 1 ){ - for( u32 i=0; ient_spawn); i++ ){ - r = mdl_arritm( &world->ent_spawn, i ); - if( !strcmp( mdl_pstr(&world->meta, r->pstr_name),argv[0] ) ){ - rp = r; - break; - } - } - - if( !rp ) - vg_warn( "No spawn named '%s'\n", argv[0] ); - } - - if( !rp ){ - float min_dist = INFINITY; - - for( u32 i=0; ient_spawn); i++ ){ - r = mdl_arritm( &world->ent_spawn, i ); - float d = v3_dist2( r->transform.co, localplayer.rb.co ); - - if( d < min_dist ){ - min_dist = d; - rp = r; - } - } - } - - if( !rp ){ - vg_error( "No spawn found\n" ); - - if( !mdl_arrcount(&world->ent_spawn) ) - return 0; - - rp = mdl_arritm( &world->ent_spawn, 0 ); - } - - player__spawn( &localplayer, rp ); - return 1; } VG_STATIC void vg_preload(void) { g_conf_init(); - common_var_temp(); - - vg_var_push( (struct vg_var){ - .name = "cl_ui", - .data = &cl_ui, - .data_type = k_var_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 0 - }); - - vg_var_push( (struct vg_var){ - .name = "ledit", - .data = &cl_light_edit, - .data_type = k_var_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 0 - }); - - vg_function_push( (struct vg_cmd) { - .name = "respawn", - .function = __respawn, - //.poll_suggest = reset_player_poll - }); - - vg_function_push( (struct vg_cmd) { - .name = "ded", - .function = __kill, - //.poll_suggest = reset_player_poll - }); - vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" ); -vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" ); +vg_info(" 2021-2023 |\\ /| | / | | | | /| \n" ); vg_info(" | \\ / | +-- / +----- +---' | / | \n" ); vg_info(" | \\ / | | / | | \\ | / | \n" ); vg_info(" | \\/ | | / | | \\ | / | \n" ); @@ -167,65 +78,44 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " VG_STATIC void load_playermodels(void) { - vg_linear_clear( vg_mem.scratch ); - - /* - * load in other player models. This may need to be more sophisticated in - * the futre if we have more of these guys - */ - mdl_context ctx_default, - ctx_outlaw, - ctx_jordan; - - mdl_open( &ctx_default, "models/ch_new.mdl", vg_mem.scratch ); - mdl_load_metadata_block( &ctx_default, vg_mem.scratch ); - mdl_load_mesh_block( &ctx_default, vg_mem.scratch ); - mdl_close( &ctx_default ); - - mdl_open( &ctx_outlaw, "models/ch_outlaw.mdl", vg_mem.scratch ); - mdl_load_metadata_block( &ctx_outlaw, vg_mem.scratch ); - mdl_load_mesh_block( &ctx_outlaw, vg_mem.scratch ); - mdl_close( &ctx_outlaw ); - - mdl_open( &ctx_jordan, "models/ch_jordan.mdl", vg_mem.scratch ); - mdl_load_metadata_block( &ctx_jordan, vg_mem.scratch ); - mdl_load_mesh_block( &ctx_jordan, vg_mem.scratch ); - mdl_close( &ctx_jordan ); - - vg_acquire_thread_sync(); - { - mdl_unpack_glmesh( &ctx_default, &localplayer_meshes[0] ); - mdl_unpack_glmesh( &ctx_outlaw, &localplayer_meshes[1] ); - mdl_unpack_glmesh( &ctx_jordan, &localplayer_meshes[2] ); - } - vg_release_thread_sync(); + player_model_load( &localplayer_models[0], "models/ch_new.mdl" ); + player_model_load( &localplayer_models[1], "models/ch_outlaw.mdl" ); + player_model_load( &localplayer_models[2], "models/ch_jordan.mdl" ); /* FIXME: hack */ shader_model_character_view_register(); - vg_acquire_thread_sync(); - { - vg_tex2d_init( (vg_tex2d *[]){ &localplayer_texture }, 1 ); - } - vg_release_thread_sync(); + shader_model_board_view_register(); + shader_model_entity_register(); } void temp_update_playermodel(void){ - player__use_mesh( &localplayer, &localplayer_meshes[cl_playermdl_id] ); + player__use_model( &localplayer, &localplayer_models[cl_playermdl_id] ); +} + +VG_STATIC void async_skaterift_complete( void *payload, u32 size ) +{ + localplayer.viewable_world = get_active_world(); + localplayer_cmd_respawn( 1, (const char *[]){ "start" } ); + + skaterift_end_op(); } VG_STATIC void vg_load(void) { + vg_console_reg_cmd( "changeworld", skaterift_change_world_command, NULL ); + vg_loader_step( render_init, NULL ); vg_loader_step( menu_init, NULL ); vg_loader_step( world_init, NULL ); + vg_loader_step( vehicle_init, NULL ); vg_loader_step( font3d_init, NULL ); font3d_load( &world_global.font, "models/rs_font.mdl", vg_mem.rtmemory ); - //vg_loader_step( player_init, NULL ); - //vg_loader_step( vehicle_init, NULL ); - // - //vg_loader_step( player_model_init, NULL ); + vg_loader_step( player_init, NULL ); + vg_loader_step( player_ragdoll_init, NULL ); + vg_loader_step( workshop_init, NULL ); + vg_loader_step( skateshop_init, NULL ); /* ----------------- */ vg_loader_step( load_playermodels, NULL ); @@ -234,8 +124,7 @@ VG_STATIC void vg_load(void) player__create( &localplayer ); player_avatar_load( &localplayer_avatar, "models/ch_new.mdl" ); player__use_avatar( &localplayer, &localplayer_avatar ); - player__use_mesh( &localplayer, &localplayer_meshes[cl_playermdl_id] ); - player__use_texture( &localplayer, &localplayer_texture ); + player__use_model( &localplayer, &localplayer_models[cl_playermdl_id] ); player__bind( &localplayer ); /* --------------------- */ @@ -244,24 +133,13 @@ VG_STATIC void vg_load(void) vg_loader_step( audio_init, audio_free ); /* 'systems' are completely loaded now */ - - /* load home world */ - //world_load( &world_global.worlds[0], "maps/mp_gridmap.mdl" ); - world_load( &world_global.worlds[0], "maps/mp_mtzero.mdl" ); - -#if 0 - world_load( &world_global.worlds[1], "maps/mp_gridmap.mdl" ); - world_link_nonlocal_gates( 0, 1 ); - world_load( &world_global.worlds[2], "maps/mp_mtzero.mdl" ); - world_link_nonlocal_gates( 0, 2 ); -#endif + /* load home/permanent world */ + world_load( 0, "maps/mp_spawn.mdl" ); vg_console_load_autos(); -} + menu_link(); -VG_STATIC void vg_start(void) -{ - __respawn( 1, (const char *[]){ "start" } ); + vg_async_call( async_skaterift_complete, NULL, 0 ); } VG_STATIC void draw_origin_axis(void) @@ -271,148 +149,65 @@ VG_STATIC void draw_origin_axis(void) vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 0.0f, 1.0f }, 0xff0000ff ); } +static void skaterift_change_world_preupdate(void); VG_STATIC void vg_update(void) { steam_update(); + skaterift_preupdate_inputs(); + if( skaterift.async_op == k_async_op_clientloading ) return; + if( skaterift.async_op == k_async_op_world_preloading ){ + skaterift_change_world_preupdate(); + } - if( vg.is_loaded ){ - draw_origin_axis(); - network_update(); - -#if 0 - if( !gzoomer.inside ) - player_update_pre(); -#endif - - player__pre_update( &localplayer ); - world_update( get_active_world(), localplayer.rb.co ); + draw_origin_axis(); + network_update(); + + player__pre_update( &localplayer ); + global_skateshop_preupdate(); - audio_update(); - } + world_update( get_active_world(), localplayer.rb.co ); + audio_ambient_sprites_update( get_active_world(), localplayer.rb.co ); + //gui_helper_action( localplayer.input_use, "\x7f Hello \x1f""A \x1e\x84" ); } VG_STATIC void vg_update_fixed(void) { - if( vg.is_loaded ){ -#if 0 - if( !gzoomer.inside ) - player_update_fixed(); + if( skaterift.async_op == k_async_op_clientloading ) return; - vehicle_update_fixed(); -#endif - world_routes_fixedupdate( get_active_world() ); - player__update( &localplayer ); - } + world_routes_fixedupdate( get_active_world() ); + player__update( &localplayer ); + vehicle_update_fixed(); } VG_STATIC void vg_update_post(void) { - if( vg.is_loaded ) - { -#if 0 - if( gzoomer.inside ) - { - vehicle_camera(); - } - else - { - player_update_post(); - } -#endif - - player__post_update( &localplayer ); - - - float inr3 = 0.57735027, - inr2 = 0.70710678118; - - v3f sample_directions[] = { - { -1.0f, 0.0f, 0.0f }, - { 1.0f, 0.0f, 0.0f }, - { 0.0f, 0.0f, 1.0f }, - { 0.0f, 0.0f, -1.0f }, - { 0.0f, 1.0f, 0.0f }, - { 0.0f, -1.0f, 0.0f }, - { -inr3, inr3, inr3 }, - { inr3, inr3, inr3 }, - { -inr3, inr3, -inr3 }, - { inr3, inr3, -inr3 }, - { -inr2, 0.0f, inr2 }, - { inr2, 0.0f, inr2 }, - { -inr2, 0.0f, -inr2 }, - { inr2, 0.0f, -inr2 }, - }; - - static int si = 0; - static float distances[16]; - - ray_hit ray; - ray.dist = 5.0f; - - v3f rc, rd, ro; - v3_copy( sample_directions[ si ], rd ); - v3_add( localplayer.rb.co, (v3f){0.0f,1.5f,0.0f}, ro ); - v3_copy( ro, rc ); - - float dist = 200.0f; - - for( int i=0; i<10; i++ ){ - if( ray_world( get_active_world(), rc, rd, &ray ) ){ - dist = (float)i*5.0f + ray.dist; - break; - } - else{ - v3_muladds( rc, rd, ray.dist, rc ); - } - } - - distances[si] = dist; + if( skaterift.async_op == k_async_op_clientloading ) return; + player__post_update( &localplayer ); - for( int i=0; i<14; i++ ){ - if( distances[i] != 200.0f ){ - u32 colours[] = { VG__RED, VG__BLUE, VG__GREEN, - VG__CYAN, VG__YELOW, VG__PINK, - VG__WHITE }; - - u32 colour = colours[i%7]; - - v3f p1; - v3_muladds( ro, sample_directions[i], distances[i], p1 ); - vg_line( ro, p1, colour ); - vg_line_pt3( p1, 0.1f, colour ); - } - } + float dist; + int sample_index; + world_audio_sample_distances( localplayer.rb.co, &sample_index, &dist ); - si ++; - if( si >= 14 ) - si = 0; + audio_lock(); + vg_dsp.echo_distances[sample_index] = dist; + v3f ears = { 1.0f,0.0f,0.0f }; + m3x3_mulv( main_camera.transform, ears, ears ); + v3_copy( ears, vg_audio.external_listener_ears ); + v3_copy( main_camera.transform[3], vg_audio.external_listener_pos ); - /* FIXME: TEMP */ - audio_lock(); - vg_dsp.echo_distances[si] = dist; - - v3f ears = { 1.0f,0.0f,0.0f }; - m3x3_mulv( main_camera.transform, ears, ears ); - v3_copy( ears, vg_audio.external_listener_ears ); - v3_copy( main_camera.transform[3], vg_audio.external_listener_pos ); - - /* TODO: this is transformed back and fourth twice. */ - if( localplayer.gate_waiting ){ - m4x3_mulv( localplayer.gate_waiting->transport, - vg_audio.external_listener_pos, - vg_audio.external_listener_pos ); - } + if( localplayer.gate_waiting ){ + m4x3_mulv( localplayer.gate_waiting->transport, + vg_audio.external_listener_pos, + vg_audio.external_listener_pos ); + } - v3_copy( localplayer.rb.v, vg_audio.external_lister_velocity ); - audio_unlock(); + v3_copy( localplayer.rb.v, vg_audio.external_lister_velocity ); + audio_unlock(); - menu_update(); -#if 0 - vehicle_update_post(); -#endif - } + vg.time_rate = 1.0f-menu.factive; + vehicle_update_post(); } VG_STATIC void vg_framebuffer_resize( int w, int h ) @@ -437,11 +232,12 @@ VG_STATIC void present_view_with_post_processing(void) shader_blitblur_use(); shader_blitblur_uTexMain( 0 ); shader_blitblur_uTexMotion( 1 ); - shader_blitblur_uBlurStrength(cl_blur_strength / (vg.frame_delta*60.0f)); + shader_blitblur_uBlurStrength( cl_blur_strength / + (vg.time_frame_delta*60.0) ); shader_blitblur_uInverseRatio( inverse ); v2f menu_blurring; - v2_muls( (v2f){ 0.04f, 0.001f }, menu_opacity, menu_blurring ); + v2_muls( (v2f){ 0.04f, 0.001f }, menu.factive, menu_blurring ); shader_blitblur_uOverrideDir( menu_blurring ); render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); @@ -495,50 +291,36 @@ VG_STATIC void render_scene(void) return; } + for( u32 i=0; istatus == k_world_status_unloading ){ + if( world_freeable( inst ) ){ + world_free( inst ); + } + return; } } - else - { - ui_text( (ui_px [2]){ 0, 60 }, - "Gamepad not ready", 1, k_text_align_left ); + + vg_info( "worlds cleared, begining load\n" ); + skaterift_shift_op( k_async_op_world_loading ); + + /* finally can start the loader */ + vg_loader_start( skaterift_world_changer_thread, NULL ); +} + +/* places all loaded worlds into unloading state */ +static void skaterift_change_world( const char *world_path ) +{ + vg_info( "switching to %s\n", world_path ); + + if( world_global.active_world != 0 ){ + vg_error( "Cannot change worlds while in non-root world\n" ); + } + else{ + skaterift_begin_op( k_async_op_world_preloading ); + + vg_linear_clear( vg_mem.scratch ); + world_global.load_target = vg_linear_alloc( vg_mem.scratch, 1024 ); + vg_strncpy( world_path, world_global.load_target, + 1024, k_strncpy_overflow_fatal ); + + vg_info( "unloading old worlds\n" ); + world_unlink_nonlocal( &world_global.worlds[0] ); + + for( u32 i=1; istatus == k_world_status_loaded ){ + inst->status = k_world_status_unloading; + world_fadeout_audio( inst ); + } + } } -#endif } + +static int skaterift_change_world_command( int argc, const char *argv[] ) +{ + if( argc == 1 ) + skaterift_change_world( argv[0] ); + + return 0; +} + +#else + +#include "skaterift_imgui_dev.c" + +#endif