add dsp and optional game page
authorhgn <hgodden00@gmail.com>
Thu, 4 Jan 2024 13:18:20 +0000 (13:18 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 4 Jan 2024 13:34:14 +0000 (13:34 +0000)
vg.h
vg_audio.h
vg_settings_menu.h

diff --git a/vg.h b/vg.h
index c4f55c3ce924d070fcea0d34340cbf3d1e2e56e2..2f6ee081884c40299d08ed4f2602d7be3f794439 100644 (file)
--- a/vg.h
+++ b/vg.h
 |   | |      v
 |IMP| |   vg_gui(void)
 |   | |      |
+|   | |      v
+|IMP| |   vg_game_settings_init(void)
+|IMP| |   vg_game_settings_gui( ui_rect panel ) 
+|   | |      |     (optional: #define VG_GAME_SETTINGS)
+|   | |      |
 |   |  '----'
 '___'
 
index 5df5638b0b1660a474df3b450e27b6735e03181f..59ad0574e88acf1ade05b94a422291375812a20f 100644 (file)
@@ -193,7 +193,7 @@ struct vg_audio_system{
    }
    channels[ AUDIO_CHANNELS ];
 
-   int               debug_ui, debug_ui_3d, debug_dsp;
+   int               debug_ui, debug_ui_3d, debug_dsp, dsp_enabled;
 
    v3f               internal_listener_pos,
                      internal_listener_ears,
@@ -206,7 +206,7 @@ struct vg_audio_system{
    float             internal_global_volume,
                      external_global_volume;
 }
-static vg_audio = { .external_global_volume = 1.0f };
+static vg_audio = { .external_global_volume = 1.0f, .dsp_enabled = 1 };
 
 #include "vg/vg_audio_dsp.h"
 
@@ -307,6 +307,8 @@ static void vg_audio_register(void){
                         k_var_dtype_f32, VG_VAR_PERSISTENT );
    vg_console_reg_var( "vg_audio_device", &vg_audio.device_choice,
                         k_var_dtype_str, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "vg_dsp", &vg_audio.dsp_enabled,
+                        k_var_dtype_i32, VG_VAR_PERSISTENT );
 }
 
 static void vg_audio_init(void){
@@ -978,12 +980,12 @@ static void audio_channel_mix( audio_channel *ch, float *buffer )
    vg_profile_end( &_vg_prof_audio_mix );
 }
 
-static void audio_mixer_callback( void *user, u8 *stream, int byte_count )
-{
+static void audio_mixer_callback( void *user, u8 *stream, int byte_count ){
    /*
     * Copy data and move edit flags to commit flags
     * ------------------------------------------------------------- */
    audio_lock();
+   int use_dsp = vg_audio.dsp_enabled;
    
    v3_copy( vg_audio.external_listener_pos, vg_audio.internal_listener_pos );
    v3_copy( vg_audio.external_listener_ears, vg_audio.internal_listener_ears );
@@ -1163,12 +1165,12 @@ static void audio_mixer_callback( void *user, u8 *stream, int byte_count )
       }
    }
 
-   vg_profile_begin( &_vg_prof_dsp );
-
-   for( int i=0; i<frame_count; i++ )
-      vg_dsp_process( pOut32F + i*2, pOut32F + i*2 );
-
-   vg_profile_end( &_vg_prof_dsp );
+   if( use_dsp ){
+      vg_profile_begin( &_vg_prof_dsp );
+      for( int i=0; i<frame_count; i++ )
+         vg_dsp_process( pOut32F + i*2, pOut32F + i*2 );
+      vg_profile_end( &_vg_prof_dsp );
+   }
 
    audio_lock();
 
index fb6a11616c3d688f642fdc16f18819fe1f4f9389..f84fcf127112df98b4ae586dd57ae73c5c829b91 100644 (file)
@@ -4,6 +4,11 @@
 #include "vg.h"
 #include "vg_imgui.h"
 
+#ifdef VG_GAME_SETTINGS
+static void vg_game_settings_gui( ui_rect panel ) ;
+static void vg_game_settings_init(void);
+#endif 
+
 struct ui_enum_opt vg_settings_vsync_enum[] = { 
    { 0, "None" },
    { 1, "On" },
@@ -22,6 +27,11 @@ struct ui_enum_opt vg_settings_screen_mode_enum[] = {
    { 2, "Floating Window" }
 };
 
+struct ui_enum_opt vg_settings_dsp_enum[] = {
+   { 1, "Enabled" },
+   { 0, "Disabled" },
+};
+
 struct {
    struct vg_setting_ranged_i32{
       i32 new_value, *actual_value, min, max;
@@ -37,7 +47,7 @@ struct {
       u32 option_count;
       const char *label;
    }
-   vsync, quality, screenmode, audio_devices;
+   vsync, quality, screenmode, audio_devices, dsp;
    i32 temp_audio_choice;
 
    int windowed_before[4];
@@ -56,7 +66,10 @@ static vg_settings = {
                      .options = vg_settings_screen_mode_enum, .option_count=3 },
    .audio_devices = { .label = "Audio Device",
                       .actual_value = &vg_settings.temp_audio_choice,
-                      .options = NULL, .option_count = 0 }
+                      .options = NULL, .option_count = 0 },
+   .dsp = { .label = "Audio effects (reverb etc.)",
+             .actual_value = &vg_audio.dsp_enabled,
+             .options = vg_settings_dsp_enum, .option_count=2 },
 };
 
 static void vg_settings_ui_draw_diff( ui_rect orig ){
@@ -154,6 +167,32 @@ static void vg_settings_ui_header( ui_rect inout_panel, const char *name ){
    ui_text( rect, name, 1, k_ui_align_middle_center, ui_colour(k_ui_fg+3) );
 }
 
+
+static bool vg_settings_apply_button( ui_rect inout_panel, bool validated ){
+   ui_rect last_row;
+   ui_px height = (vg_ui.font->glyph_height + 18) * k_ui_scale;
+   ui_split( inout_panel, k_ui_axis_h, -height, k_ui_padding, 
+             inout_panel, last_row );
+
+   const char *string = "Apply";
+   if( validated ){
+      if( ui_button( last_row, string ) == 1 )
+         return 1;
+   }
+   else{
+      ui_rect rect;
+      ui_standard_widget( last_row, rect, 1 );
+      ui_fill( rect, ui_colour( k_ui_bg+1 ) );
+      ui_outline( rect, -1, ui_colour( k_ui_red ), 0 );
+
+      ui_rect t = { 0,0, ui_text_line_width( string ), 14 };
+      ui_rect_center( rect, t );
+      ui_text( t, string, 1, k_ui_align_left, ui_colour(k_ui_fg+3) );
+   }
+
+   return 0;
+}
+
 static void vg_settings_video_apply(void){
    if( vg_settings_enum_diff( &vg_settings.screenmode ) ){
       vg.screen_mode = vg_settings.screenmode.new_value;
@@ -231,27 +270,8 @@ static void vg_settings_video_gui( ui_rect panel ){
    ui_standard_widget( panel, duo, 1 );
    vg_settings_enum( &vg_settings.screenmode, duo );
 
-   /* apply */
-   ui_rect last_row;
-   ui_px height = (vg_ui.font->glyph_height + 18) * k_ui_scale;
-   ui_split( panel, k_ui_axis_h, -height, k_ui_padding, 
-             panel, last_row );
-
-   const char *string = "Apply";
-   if( validated ){
-      if( ui_button( last_row, string ) == 1 )
-         vg_settings_video_apply();
-   }
-   else{
-      ui_rect rect;
-      ui_standard_widget( last_row, rect, 1 );
-      ui_fill( rect, ui_colour( k_ui_bg+1 ) );
-      ui_outline( rect, -1, ui_colour( k_ui_red ), 0 );
-
-      ui_rect t = { 0,0, ui_text_line_width( string ), 14 };
-      ui_rect_center( rect, t );
-      ui_text( t, string, 1, k_ui_align_left, ui_colour(k_ui_fg+3) );
-   }
+   if( vg_settings_apply_button( panel, validated ) )
+      vg_settings_video_apply();
 }
 
 static void vg_settings_audio_apply(void){
@@ -287,21 +307,25 @@ static void vg_settings_audio_apply(void){
       *vg_settings.audio_devices.actual_value = 
          vg_settings.audio_devices.new_value;
    }
+
+   audio_lock();
+   if( vg_settings_enum_diff( &vg_settings.dsp ) ){
+      *vg_settings.dsp.actual_value =
+         vg_settings.dsp.new_value;
+   }
+
+   audio_unlock();
 }
 
 static void vg_settings_audio_gui( ui_rect panel ){
    ui_rect rq;
    ui_standard_widget( panel, rq, 1 );
    vg_settings_enum( &vg_settings.audio_devices, rq );
+   
+   ui_standard_widget( panel, rq, 1 );
+   vg_settings_enum( &vg_settings.dsp, rq );
 
-   const char *string = "Apply";
-
-   ui_rect last_row;
-   ui_px height = (vg_ui.font->glyph_height + 18) * k_ui_scale;
-   ui_split( panel, k_ui_axis_h, -height, k_ui_padding, 
-             panel, last_row );
-
-   if( ui_button( last_row, string ) == 1 )
+   if( vg_settings_apply_button( panel, 1 ) )
       vg_settings_audio_apply();
 }
 
@@ -351,6 +375,11 @@ static void vg_settings_open(void){
    }
 
    ui_settings_enum_init( &vg_settings.audio_devices );
+   ui_settings_enum_init( &vg_settings.dsp );
+
+#ifdef VG_GAME_SETTINGS
+   vg_game_settings_init();
+#endif
 }
 
 static void vg_settings_close(void){
@@ -388,15 +417,25 @@ static void vg_settings_gui(void){
 
    ui_rect_pad( panel, (ui_px[2]){ 8, 8 } );
    
+   const char *opts[] = { "video", "audio",
+#ifdef VG_GAME_SETTINGS
+   "game"
+#endif
+   };
+
    static i32 page = 0;
-   ui_tabs( panel, panel, (const char *[]){ "video", "audio", "game" }, 
-            3, &page );
+   ui_tabs( panel, panel, opts, vg_list_size(opts), &page );
 
    if( page == 0 ){
       vg_settings_video_gui( panel );
    }
    else if( page == 1 )
       vg_settings_audio_gui( panel );
+
+#ifdef VG_GAME_SETTINGS
+   else if( page == 2 )
+      vg_game_settings_gui( panel );
+#endif
 }
 
 static int cmd_vg_settings_toggle( int argc, const char *argv[] ){