stuff
authorhgn <hgodden00@gmail.com>
Wed, 5 Nov 2025 03:53:36 +0000 (03:53 +0000)
committerhgn <hgodden00@gmail.com>
Wed, 5 Nov 2025 03:53:36 +0000 (03:53 +0000)
source/async/sdl_async.c
source/async/vg_async.h
source/engine/engine.kv
source/engine/model_entity.h
source/engine/vg_audio.c
source/engine/vg_audio.h
source/engine/vg_engine.c

index c85fcef833576fc9f9b8533c8ee93b639a2ed171..3c3a79fb6849d411bda7861c1fc5488060cac3e2 100644 (file)
@@ -3,7 +3,7 @@
 #include "generated/threads.c"
 #include "SDL3/SDL.h"
 
-#define ASYNC_DEBUG_GROUP_COUNTS
+//#define ASYNC_DEBUG_GROUP_COUNTS
 
 struct thread_context
 {
index 6b9f006efe1106a3bc7c0f1d320af91bec2afb7a..1d87cd5ad64c0c7082a3ed58b4f8816a51ba62c3 100644 (file)
@@ -20,6 +20,7 @@ struct thread_info *_get_thread_info( enum thread_id thread );
 // TODO THIS SHOULD BE PART OF THE METACOMPILER
 #define ASYNC_GROUP_OPENGL 0x1
 #define ASYNC_GROUP_FIRST_LOAD 0x2
+#define ASYNC_GROUP_WORLD_LOAD 0x4
 
 void           _set_thread_id( enum thread_id id );
 enum thread_id _get_thread_id(void);
index 4a3b3613506e85565ccd5488d2120625a0ae5a63..ca4e2b1a001012381dd882bfc2ea7c8999cb5fe8 100644 (file)
@@ -393,6 +393,14 @@ hook
    event START
    function _dsp_init
 }
+cvar
+{
+   name vg_audio
+   type i32
+   default 0
+   cheat 1
+   description "Show audio info"
+}
 
 add model.c
 add metascene.c
index 5f7f3b27397b0fa7ef056e01d8ab409778a7ec0e..a044aa842da62ad652f238fb754d287027ecf6c0 100644 (file)
@@ -44,6 +44,8 @@ enum entity_alias
    k_ent_waterfall   = 201,
    k_ent_rb2         = 202,
    k_ent_heatpipe    = 203,
+
+   k_ent_viewstone   = 205,
    k_ent_max
 };
 
@@ -320,7 +322,8 @@ struct volume_particles
 
 struct volume_trigger
 {
-   i32 blank, blank2;
+   u32 blank1;
+   i32 blank;
 };
 
 struct volume_interact
@@ -351,7 +354,7 @@ struct ent_volume
    };
 
    u32 flags;
-   u32 deleted0;
+   u32 filter;
    union
    {
       struct volume_trigger trigger;
index 9f177d3c1c079ef1d3e88bca20e804faf121e35a..0a3278837d2d8a4d9e6c683d8af4b6050dc8725e 100644 (file)
@@ -6,6 +6,10 @@
 #include "vg_audio_vorbis.h"
 #include "common_maths.h"
 #include "vg_async.h"
+#include "vg_camera.h"
+#include "vg_graphics.h"
+#include "console_system.h"
+#include "vg_engine.h"
 
 #include <unistd.h>
 
@@ -1028,6 +1032,12 @@ static void audio_channel_mix( audio_channel_id id,
          v_l *= v_s * (1.0-v_p);
          v_r *= v_s * (1.0+v_p);
       }
+      else
+      {
+         f64 v_p = (f64)state->pan / (f64)AUDIO_PAN_RIGHT_100;
+         v_l *= f32_min( 1.0f, (1.0-v_p) );
+         v_r *= f32_min( 1.0f, (1.0+v_p) );
+      }
       
       f32 s_l, s_r;
       if( frame_sample_rate != 1.0f )
@@ -1356,3 +1366,186 @@ void vg_audio_preupdate(void)
          _audio.working = 0;
 #endif
 }
+
+void _audio_gui(void)
+{
+   if( _cvar_vg_audio == 0 )
+      return;
+
+   _audio_lock();
+   i16 panel[4] = {0,0,_engine.w,_engine.h};
+   
+       /* Draw audio stack */
+       for( i32 id=1; id<=AUDIO_CHANNELS; id ++ )
+   {
+      struct audio_channel *channel = get_audio_channel( id );
+
+      i16 row[4];
+      rect_split( panel, 0, 18, 1, row, panel );
+
+      if( channel->stage == k_channel_stage_none )
+      {
+         _graphics_fill_rect( row, (union colour){{ 0x33,0x33,0x33,0x50 }} );
+      }
+      else if( channel->stage == k_channel_stage_allocation )
+      {
+         _graphics_fill_rect( row, (union colour){{ 0x33,0x33,0xff,0x50 }} );
+      }
+      else if( channel->stage == k_channel_stage_active )
+      {
+         char buf[256];
+         struct stream string;
+         stream_open_buffer_write( &string, buf, sizeof(buf), k_stream_null_terminate );
+
+         $v_string( &string, $signed(id) );
+
+         if( channel->group )
+         {
+            $v_string( &string, {" grp"}, $unsigned( channel->group ) );
+         }
+         else
+         {
+            $v_string( &string, {"          "} );
+         }
+
+         $v_string( &string, {" flags:"} );
+         u32 flags = get_audio_channel_controls( id )->flags;
+         string_append_c8( &string, (flags & AUDIO_FLAG_RELINQUISHED)? 'R': '_' );
+         string_append_c8( &string, (flags & AUDIO_FLAG_SPACIAL_3D)? 'S': '_' );
+         string_append_c8( &string, (flags & AUDIO_FLAG_WORLD)? 'W': '_' );
+         string_append_c8( &string, (flags & AUDIO_FLAG_NO_DOPPLER)? '_':'D' );
+         string_append_c8( &string, (flags & AUDIO_FLAG_NO_DSP)? '_':'E' );
+         string_append_c8( &string, (flags & AUDIO_FLAG_LOOP)? 'L':'_' );
+
+         const c8 *formats[] =
+         {
+            "   mono   ",
+            "  stereo  ", 
+            "  vorbis  ",
+            "   none0  ",
+            "   none1  ",
+            "   none2  ",
+            "   none3  ",
+            "   none4  ",
+            "synth:bird",
+            "   none5  ",
+            "   none6  ",
+            "   none7  ",
+            "   none8  ",
+            "   none9  ",
+            "  none10  ",
+            "  none11  ",
+         };
+
+         u32 format_index = (channel->clip->flags & AUDIO_FLAG_FORMAT)>>9;
+         string_append( &string, " format:", 0 );
+         string_append( &string, formats[format_index], 0 );
+
+         const c8 *activties[] =
+         {
+            "wake ",
+            "play ",
+            "pause",
+            "end  ",
+            "error"
+         };
+         $v_string( &string, {" "}, {activties[channel->ui_activity]}, {" "} ); 
+
+         f32 volume = (f32)channel->ui_volume / (f32)AUDIO_VOLUME_100;
+         $v_string( &string, $signed( volume * 100.0f ), {"% "}, {channel->ui_name} );
+
+         i16 row_l[4], row_r[4];
+         rect_split( row, 1, 32, 2, row_l, row_r );
+         
+         i16 indicator_l[4], indicator_r[4];
+         rect_split_ratio( row_l, 1, 0.5f, 1, indicator_l, indicator_r );
+
+         _graphics_fill_rect( indicator_l, (union colour){{0,0,0,255}} );
+         if( volume > 0.01f )
+         {
+            f32 h = volume * (f32)indicator_l[3];
+            i16 vol_bar[4] = { indicator_l[0], indicator_l[1] + indicator_l[3] - h, indicator_l[2], h };
+            _graphics_fill_rect( vol_bar, (union colour){{ 0,255,0, 255 }} );
+            if( flags & AUDIO_FLAG_SPACIAL_3D )
+            {
+               f32 h = ((f32)channel->ui_spacial_volume / (f32)AUDIO_VOLUME_100) * (f32)indicator_l[3];
+               i16 space_bar[4] = { indicator_l[0], indicator_l[1] + indicator_l[3] - h, indicator_l[2], 1 };
+               _graphics_fill_rect( space_bar, (union colour){{ 255,255,255,255 }} );
+            }
+         }
+
+         f32 pan = (f32)channel->ui_pan / (f32)AUDIO_PAN_RIGHT_100;
+         _graphics_fill_rect( indicator_r, (union colour){{ 0x11,0x11,0x11,255 }} );
+         f32 midpoint = (f32)indicator_r[0] + (f32)indicator_r[2] * 0.5f;
+
+         f32 pan_abs = fabsf(pan);
+         if( pan_abs > 0.01f )
+         {
+            i16 bar[4] = { midpoint,indicator_r[1], pan_abs * (f32)indicator_r[2] * 0.5f, indicator_r[3] };
+            if( pan < 0.0f )
+               bar[0] -= (f32)bar[2];
+            _graphics_fill_rect( bar, (union colour){{ 0xff, 0xaa, 0x00, 0xff }} );
+         }
+
+         if( flags & AUDIO_FLAG_SPACIAL_3D )
+         {
+            f32 w = ((f32)channel->ui_spacial_pan / (f32)AUDIO_PAN_RIGHT_100) * (f32)indicator_r[2] * 0.5f;
+            i16 space_bar[4] = { midpoint+w, indicator_r[1], 1, indicator_r[3] };
+            _graphics_fill_rect( space_bar, (union colour){{ 0xff,0xff,0xff,0xff }} );
+         }
+         
+         _graphics_fill_rect( row_r, (union colour){ .word = 0xa0000000 | channel->ui_colour } );
+         _ui_text( row_r, string_get( &string ), k_ui_align_y_center, (union colour){{0xff,0xff,0xff,0xff}} );
+      }
+   }
+      
+#if 0
+#ifdef VG_3D
+      if( vd->view_3d && (ch->flags & AUDIO_FLAG_SPACIAL_3D) )
+      {
+         v4f wpos;
+         v3_copy( ch->spacial_falloff, wpos );
+
+         wpos[3] = 1.0f;
+         m4x4_mulv( vg.pv, wpos, wpos );
+
+         if( wpos[3] > 0.0f )
+         {
+            v2_muls( wpos, (1.0f/wpos[3]) * 0.5f, wpos );
+            v2_add( wpos, (v2f){ 0.5f, 0.5f }, wpos );
+            
+            ui_rect wr;
+            wr[0] = vg_clampf(wpos[0] * vg.window_x, -32000.0f,32000.0f);
+            wr[1] = vg_clampf((1.0f-wpos[1]) * vg.window_y,-32000.0f,32000.0f);
+            wr[2] = 1000;
+            wr[3] = 17;
+            
+            for( int j=0; j<12; j++ )
+            {
+               int collide = 0;
+               for( int k=0; k<overlap_length; k++ )
+               {
+                  ui_px *wk = overlap_buffer[k];
+                  if( ((wr[0] <= wk[0]+wk[2]) && (wr[0]+wr[2] >= wk[0])) &&
+                      ((wr[1] <= wk[1]+wk[3]) && (wr[1]+wr[3] >= wk[1])) )
+                  {
+                     collide = 1;
+                     break;
+                  }
+               }
+
+               if( !collide )
+                  break;
+               else
+                  wr[1] += 18;
+            }
+
+            ui_text( ctx, wr, perf, 1, k_ui_align_middle_left, 0 );
+            rect_copy( wr, overlap_buffer[ overlap_length ++ ] );
+         }
+      }
+#endif
+#endif
+
+   _audio_unlock();
+}
index 083c9f04fad7451cf90917f3776ef52c56a14095..0005b3c5ea7d17c917f89748b95d97d331b4ec6b 100644 (file)
@@ -106,3 +106,5 @@ void _audio_fadeout_flagged_audio( u32 flag, f32 length );
 b8 _audio_flagged_stopped( u32 flag );
 b8 _audio_is_channel_using_clip( audio_channel_id id, struct audio_clip *clip );
 void _audio_set_flagged_pause( u32 flag, b8 pause );
+
+void _audio_gui(void);
index 6f3788ad6f6a1e4262c6f11f431e6874bfa82f7d..e9039eea1a29c7086dedab5af760669af2a472a1 100644 (file)
@@ -7,6 +7,7 @@
 #include "vg_opengl.h"
 #include "vg_engine.h"
 #include "vg_ui.h"
+#include "vg_audio.h"
 
 // TODO: temp
 #include "console_system.h"
@@ -270,6 +271,7 @@ L_new_frame:;
    EVENT_CALL( ENGINE_RENDER );
    _engine_ui_pre_render();
    EVENT_CALL( ENGINE_UI );
+   _audio_gui();
    _engine_ui_post_render();
 
    //glfwSwapBuffers(_engine.window_handle);