From a64c18c5996fd5ac9601239f91b12275f04f9cd9 Mon Sep 17 00:00:00 2001 From: hgn Date: Wed, 26 Oct 2022 02:39:55 +0100 Subject: [PATCH] yabadabadooo --- audio.h | 14 ++++---- build.sh | 21 +++++++++++- main.c | 6 ++-- model.h | 1 + player.h | 2 +- player_physics.h | 21 +++++++----- scene.h | 3 +- world.h | 89 ++++++++++++++++++++++++++++++++++++++++++++++-- world_gen.h | 39 +++++++++++++++++---- world_routes.h | 3 -- 10 files changed, 166 insertions(+), 33 deletions(-) diff --git a/audio.h b/audio.h index 34ebb3a..eacfbab 100644 --- a/audio.h +++ b/audio.h @@ -23,7 +23,7 @@ audio_clip audio_board[] = }; audio_clip audio_splash = -{ .path = "sound/splash.ogg" }; +{ .path = "sound/splash.ogg", k_audio_source_compressed }; audio_clip audio_jumps[] = { { .path = "sound/jump0.ogg" }, @@ -65,7 +65,7 @@ audio_clip audio_grass[] = { audio_clip audio_ambience[] = { - { .path="sound/town_generic.ogg" } + { .path="sound/town_generic.ogg", k_audio_source_compressed } }; audio_clip audio_gate_pass = { @@ -91,11 +91,11 @@ audio_player audio_rewind_player = }; audio_clip audio_rewind[] = { -{ .path = "sound/rewind_start.ogg" }, -{ .path = "sound/rewind_end_1.5.ogg" }, -{ .path = "sound/rewind_end_2.5.ogg" }, -{ .path = "sound/rewind_end_6.5.ogg" }, -{ .path = "sound/rewind_clack.ogg" }, +{ .path = "sound/rewind_start.ogg", k_audio_source_compressed }, +{ .path = "sound/rewind_end_1.5.ogg", k_audio_source_compressed }, +{ .path = "sound/rewind_end_2.5.ogg", k_audio_source_compressed }, +{ .path = "sound/rewind_end_6.5.ogg", k_audio_source_compressed }, +{ .path = "sound/rewind_clack.ogg", k_audio_source_compressed }, }; audio_clip audio_ui[] = { diff --git a/build.sh b/build.sh index fad6201..9f7f13a 100755 --- a/build.sh +++ b/build.sh @@ -94,6 +94,14 @@ vg_command(){ _linux_options="$_linux_asan $_options_debugmode" _windows_options="$_windows_asan $_options_debugmode" ;; + ltools) + _compiler=$_linux_compiler + _options=$_linux_options + _folder=$_linux_folder + _ext="" + vg_compile_tools + + ;; game) titleit "Creating Linux build" mkdir -p $_linux_folder/cfg @@ -188,13 +196,24 @@ vg_command(){ ./bin/linux/tools/qoiconv $f $dest done ;; + sounds) + titleit "Compiling sounds" + mkdir -p ./bin/content/textures + + for f in ./sound_src/*.wav + do + dest=./bin/content/sounds/"$(basename "$f" .wav).44100.ima_adpcm" + ./bin/linux/tools/audcomp $f $dest + done + ;; + content) logit "Copying content" mkdir -p ./bin/content/models mkdir -p ./bin/content/sound cp ./models_src/* ./bin/content/models/ - cp ./sound_src/* ./bin/content/sound/ + #cp ./sound_src/* ./bin/content/sound/ ;; all) diff --git a/main.c b/main.c index 9bfa794..c900e5e 100644 --- a/main.c +++ b/main.c @@ -20,6 +20,7 @@ #define VG_3D #define VG_STATIC static +//#define VG_STATIC //#define VG_MINIMAL_TEST #ifndef VG_MINIMAL_TEST @@ -72,7 +73,7 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " vg_loader_highwater( NULL, highscores_save_at_exit, NULL ); - vg_sleep_ms(200); + //vg_sleep_ms(200); steam_init(); vg_loader_highwater( NULL, steam_end, NULL ); @@ -90,7 +91,8 @@ VG_STATIC void vg_load(void) vg_loader_highwater( audio_init, audio_free, NULL ); /* 'systems' are completely loaded now */ - world_load( "models/mp_dev.mdl" ); + strcpy( world.world_name, "models/mp_dev.mdl" ); + world_load(); vg_console_load_autos(); } diff --git a/model.h b/model.h index b3650f8..0547e8e 100644 --- a/model.h +++ b/model.h @@ -325,6 +325,7 @@ VG_STATIC void mesh_free( glmesh *mesh ) glDeleteVertexArrays( 1, &mesh->vao ); glDeleteBuffers( 1, &mesh->ebo ); glDeleteBuffers( 1, &mesh->vbo ); + mesh->loaded = 0; } } diff --git a/player.h b/player.h index 5a21afe..0b6db88 100644 --- a/player.h +++ b/player.h @@ -302,7 +302,7 @@ VG_STATIC void player_update_pre(void) { double delta = world.time - world.last_use; - if( delta <= RESET_MAX_TIME ) + if( (delta <= RESET_MAX_TIME) && (world.last_use != 0.0) ) { player.rewinding = 1; player.rewind_sound_wait = 1; diff --git a/player_physics.h b/player_physics.h index 90ea030..ff8d1f7 100644 --- a/player_physics.h +++ b/player_physics.h @@ -633,16 +633,19 @@ VG_STATIC void player_do_motion(void) float horizontal = vg_get_axis("horizontal"), vertical = vg_get_axis("vertical"); - if( (phys->rb.co[1] < 0.0f) && !player.is_dead ) + if( world.water.enabled ) { - audio_lock(); - audio_player_set_flags( &audio_player_extra, AUDIO_FLAG_SPACIAL_3D ); - audio_player_set_position( &audio_player_extra, phys->rb.co ); - audio_player_set_vol( &audio_player_extra, 20.0f ); - audio_player_playclip( &audio_player_extra, &audio_splash ); - audio_unlock(); - - player_kill(); + if( (phys->rb.co[1] < 0.0f) && !player.is_dead ) + { + audio_lock(); + audio_player_set_flags( &audio_player_extra, AUDIO_FLAG_SPACIAL_3D ); + audio_player_set_position( &audio_player_extra, phys->rb.co ); + audio_player_set_vol( &audio_player_extra, 20.0f ); + audio_player_playclip( &audio_player_extra, &audio_splash ); + audio_unlock(); + + player_kill(); + } } if( phys->on_board ) diff --git a/scene.h b/scene.h index 51ce103..b3d5062 100644 --- a/scene.h +++ b/scene.h @@ -36,8 +36,7 @@ VG_STATIC scene *scene_init( void *lin_alloc, u32 max_verts, u32 max_indices ) pscene->max_vertices = max_verts; pscene->max_indices = max_indices; - pscene->submesh.indice_start = 0; - pscene->submesh.indice_count = 0; + memset( &pscene->submesh, 0, sizeof(mdl_submesh) ); v3_fill( pscene->bbx[0], 999999.9f ); v3_fill( pscene->bbx[1], -999999.9f ); diff --git a/world.h b/world.h index 8b1b1dc..fe1a4c1 100644 --- a/world.h +++ b/world.h @@ -94,8 +94,6 @@ VG_STATIC struct gworld u32 indices_head; u32 vertex_head; - float last_notch; - struct route_ui_segment { float length; @@ -113,6 +111,12 @@ VG_STATIC struct gworld v3f render_gate_pos; int active_route_board; + /* This is a small flag we use to changelevel. + * It will not be cleared until all sounds stop playing + */ + int switching_to_new_world; + char world_name[ 64 ]; + /* * Dynamically allocated when world_load is called. * @@ -333,6 +337,47 @@ VG_STATIC int ray_world( v3f pos, v3f dir, ray_hit *hit ); * ----------------------------------------------------------------------------- */ +VG_STATIC int world_stop_sound( int argc, const char *argv[] ) +{ + /* + * None of our world audio runs as one shots, they always have a player. + * Therefore it is safe to delete clip data after the players are + * disconnected + */ + audio_lock(); + for( int i=0; iplayer ) ) + { + u32 cflags = audio_player_get_flags( &at->player ); + audio_player_set_flags( &at->player, cflags | AUDIO_FLAG_KILL ); + } + } + audio_unlock(); + + return 0; +} + +VG_STATIC int world_change_world( int argc, const char *argv[] ) +{ + if( argc == 0 ) + { + vg_info( "%s\n", world.world_name ); + return 0; + } + else + { + vg_info( "Switching world...\n" ); + strcpy( world.world_name, argv[0] ); + world.switching_to_new_world = 1; + world_stop_sound( 0, NULL ); + } + + return 0; +} + VG_STATIC void world_init(void) { vg_convar_push( (struct vg_convar){ @@ -343,6 +388,18 @@ VG_STATIC void world_init(void) .persistent = 0 }); + vg_function_push( (struct vg_cmd) + { + .name = "world_stop_sound", + .function = world_stop_sound + }); + + vg_function_push( (struct vg_cmd) + { + .name = "world", + .function = world_change_world + }); + world.sky_rate = 1.0; world.sky_target_rate = 1.0; @@ -382,10 +439,38 @@ VG_STATIC void world_init(void) /* Allocate dynamic world memory arena */ u32 max_size = 72*1024*1024; world.dynamic_vgl = vg_create_linear_allocator( vg_mem.rtmemory, max_size ); + for( u32 i=0; i<72*1024*1024; i++ ) + ((u8 *)world.dynamic_vgl)[i] = 0xfe; } VG_STATIC void world_update( v3f pos ) { + if( world.switching_to_new_world ) + { + int all_stopped = 1; + + audio_lock(); + for( int i=0; iplayer ) ) + { + all_stopped = 0; + break; + } + } + audio_unlock(); + + if( all_stopped ) + { + world.switching_to_new_world = 0; + world_unload(); + world_load(); + } + } + + world.sky_time += world.sky_rate * vg.time_delta; world.sky_rate = vg_lerp( world.sky_rate, world.sky_target_rate, vg.time_delta * 5.0 ); diff --git a/world_gen.h b/world_gen.h index ccd3eda..40d6f4c 100644 --- a/world_gen.h +++ b/world_gen.h @@ -8,8 +8,7 @@ #include "world.h" /* load world TODO: Put back vg back in loading state while this happens */ -VG_STATIC void world_load( const char *mdl_file ); - +VG_STATIC void world_load(void); VG_STATIC void world_add_all_if_material( m4x3f transform, scene *pscene, @@ -537,13 +536,16 @@ VG_STATIC void world_post_process(void) ortho[3][3] = 1.0f; m4x3_identity( camera ); - glViewport( 0, 0, 1024, 1024 ); glDisable(GL_DEPTH_TEST); + glDisable(GL_BLEND); + glDisable(GL_CULL_FACE); glBindFramebuffer( GL_FRAMEBUFFER, gpipeline.fb_depthmap ); + glViewport( 0, 0, 1024, 1024 ); shader_fscolour_use(); shader_fscolour_uColour( (v4f){-9999.0f,-9999.0f,-9999.0f,-9999.0f} ); render_fsquad(); + /* todo: hmm?? */ glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_MAX); @@ -590,9 +592,34 @@ VG_STATIC void world_unload(void) mesh_free( &world.mesh_route_lines ); mesh_free( &world.mesh_water ); + world.time = 0.0; + world.rewind_from = 0.0; + world.rewind_to = 0.0; + world.last_use = 0.0; + world.active_gate = 0; + world.current_run_version = 2; + world.active_route_board = 0; + v3_zero( world.render_gate_pos ); + + for( int i=0; isegment_start = 0; + uib->segment_count = 0; + uib->fade_start = 0; + uib->fade_count = 0; + uib->fade_timer_start = 0.0; + uib->xpos = 0.0f; + } + /* delete the entire block of memory */ + memset( world.dynamic_vgl, 0xff, 72*1024*1024 ); + vg_linear_clear( world.dynamic_vgl ); + for( u32 i=0; i<72*1024*1024; i++ ) + ((u8 *)world.dynamic_vgl)[i] = 0xff^i; + /* clean dangling pointers */ world.meta = NULL; @@ -635,12 +662,12 @@ VG_STATIC void world_unload(void) world.water.enabled = 0; } -VG_STATIC void world_load( const char *mdl_file ) +VG_STATIC void world_load(void) { world_unload(); - world.meta = mdl_load_full( world.dynamic_vgl, mdl_file ); - vg_info( "Loading world: %s\n", mdl_file ); + world.meta = mdl_load_full( world.dynamic_vgl, world.world_name ); + vg_info( "Loading world: %s\n", world.world_name ); /* dynamic allocations */ world_ents_allocate(); diff --git a/world_routes.h b/world_routes.h index 3124295..97fc557 100644 --- a/world_routes.h +++ b/world_routes.h @@ -221,8 +221,6 @@ VG_STATIC struct route_ui_segment *world_routes_ui_curseg( VG_STATIC void world_routes_ui_newseg( u32 route ) { struct route_ui_bar *pui = &world.ui_bars[route]; - - pui->last_notch = 0.0; glBindVertexArray( pui->vao ); if( pui->segment_count ) @@ -996,7 +994,6 @@ VG_STATIC void world_routes_create_route( mdl_node *pnode ) pui->vertex_head = k_route_ui_max_verts - 200; pui->segment_start = 0; pui->segment_count = 0; - pui->last_notch = 0.0; pui->fade_start = 0; pui->fade_count = 0; pui->fade_timer_start = 0.0; -- 2.25.1