yabadabadooo
authorhgn <hgodden00@gmail.com>
Wed, 26 Oct 2022 01:39:55 +0000 (02:39 +0100)
committerhgn <hgodden00@gmail.com>
Wed, 26 Oct 2022 01:39:55 +0000 (02:39 +0100)
audio.h
build.sh
main.c
model.h
player.h
player_physics.h
scene.h
world.h
world_gen.h
world_routes.h

diff --git a/audio.h b/audio.h
index 34ebb3a4ad3a7866468654fcc932a898d4337d76..eacfbabf6c598abe4a3c07e47ac9dc13c741ae71 100644 (file)
--- 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[] = {
index fad620190cce6a31a17c14c4b1dc5b418e1efe7f..9f7f13a9b03a82a364a163ae84eb4b67f34247bc 100755 (executable)
--- 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 9bfa794c51a1e0b1ad55668aa8ca29b1877fc366..c900e5e2b0de1ea71176b80bd7401375faa211b2 100644 (file)
--- 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 b3650f8009c4a854dc383642c0391fea00fec311..0547e8ecc17d919dc438dd456ef4acfaac48e15e 100644 (file)
--- 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;
    }
 }
 
index 5a21afe662a2248252ecc776ecb7f5820e5ed64b..0b6db882031480bbd9a803f33649955b96c732c2 100644 (file)
--- 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;
index 90ea030a7bd2adab89cd6dc61a9de61155b32f93..ff8d1f7a25a921848254f2a6d1725d39713a316a 100644 (file)
@@ -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 51ce10315c38fdcb47fe84f49eaec103e8445266..b3d5062a86801deedf382a8c03906d6940e1c7fc 100644 (file)
--- 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 8b1b1dc079ff159e06e6197837f0637e4a6a1e46..fe1a4c18a45bcf106703289b6c0b4215cd52f084 100644 (file)
--- 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; i<world.audio_things_count; i++ )
+   {
+      struct world_audio_thing *at = &world.audio_things[i];
+
+      if( audio_player_is_playing( &at->player ) )
+      {
+         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; i<world.audio_things_count; i++ )
+      {
+         struct world_audio_thing *at = &world.audio_things[i];
+
+         if( audio_player_is_playing( &at->player ) )
+         {
+            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 );
index ccd3eda875feb36294f81108447610e2ecf730b2..40d6f4c9653c4473c58de098038ae2948cae9ee7 100644 (file)
@@ -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; i<vg_list_size(world.ui_bars); i++ )
+   {
+      struct route_ui_bar *uib = &world.ui_bars[i];
+      uib->segment_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();
index 312429579a0fcd021d9b3cfe966d85424f9e4919..97fc557b604201517f4240a43a15f4c20cf4715b 100644 (file)
@@ -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;