aaaaaaa
authorhgn <hgodden00@gmail.com>
Thu, 23 Oct 2025 00:57:02 +0000 (01:57 +0100)
committerhgn <hgodden00@gmail.com>
Thu, 23 Oct 2025 00:57:02 +0000 (01:57 +0100)
source/engine/engine.kv
source/engine/vg_audio.c
source/engine/vg_audio.h
source/engine/vg_engine.c
source/engine/vg_input.c
source/engine/vg_ui.c
source/engine/vg_ui.h
source/foundation/logging.c
source/graphics/ui.c
source/graphics/vg_graphics.h
source/maths/common_maths.h

index e81bb621f56052b307ca53347a07237003d2dd0b..c29fc6283c54883ba05da393c488be476c18f73b 100644 (file)
@@ -186,7 +186,6 @@ config "bind RIGHT ui_right"
 config "bind UP ui_up"
 config "bind DOWN ui_down"
 config "bind MOUSE_LEFT ui_click"
-
 config "bind LEFT_SHIFT ui_select"
 config "bind RIGHT_SHIFT ui_select"
 
index 876624ff47617db7973b9a39385c9639daa15599..9f177d3c1c079ef1d3e88bca20e804faf121e35a 100644 (file)
@@ -10,7 +10,7 @@
 #include <unistd.h>
 
 SDL_Mutex *_audio_mutex;
-_Thread_local static bool _audio_have_lock = 0;
+_Thread_local static b8 _audio_have_lock = 0;
 static f32 _master_volume = 1.0f;
 
 enum channel_stage
@@ -88,7 +88,7 @@ struct audio_channel
       f32 lfo_attenuation_amount; /* multiply volume by (1 + value) */
 
       f32 spacial_falloff[4]; /* xyz, range */
-      bool pause;
+      b8 pause;
    }
    controls;
 
@@ -100,7 +100,7 @@ struct audio_channel
       u32 cursor;
       i32 volume, pan, 
           spacial_volume, spacial_pan;
-      bool spacial_warm;
+      b8 spacial_warm;
 
       union
       {
@@ -125,14 +125,14 @@ struct
    struct audio_channel channels[ AUDIO_CHANNELS ];
    stb_vorbis_alloc vorbis_decoders[ AUDIO_CHANNELS ];
 
-   bool inspector_open;
+   b8 inspector_open;
 
    struct audio_master_controls
    {
       f32 listener_position[3],
           listener_right_ear_direction[3],
           listener_velocity[3];
-      bool dsp_enabled;
+      b8 dsp_enabled;
       i32 volume_target;
    }
    controls;
@@ -146,7 +146,7 @@ struct
    f32 master_volume_ui;
    i32 dsp_enabled_ui;
 
-   bool working;
+   b8 working;
 
    i32 sdl_output_device;
 }
@@ -180,7 +180,7 @@ static void _audio_assert_lock(void)
 /* clip loading from disk
  * -------------------------------------------------------------------------------
  */
-bool audio_clip_load( struct audio_clip *clip, struct stack_allocator *stack )
+b8 audio_clip_load( struct audio_clip *clip, struct stack_allocator *stack )
 {
    ASSERT_CRITICAL( _thread_has_flags( _get_thread_id(), THREAD_FLAG_ASYNC ) );
 
@@ -516,7 +516,7 @@ void _audio_sync_ui_master_controls(void)
    _audio.controls.dsp_enabled = _audio.dsp_enabled_ui;
 }
 
-void _audio_set_channel_volume( audio_channel_id id, f64 volume, bool instant )
+void _audio_set_channel_volume( audio_channel_id id, f64 volume, b8 instant )
 {
    _audio_assert_lock();
 
@@ -541,7 +541,7 @@ void _audio_set_channel_volume_slew_duration( audio_channel_id id, f64 length_se
    controls->volume_slew_rate_per_sample = (f64)AUDIO_VOLUME_100 / (length_seconds * 44100.0);
 }
 
-void _audio_set_channel_pan( audio_channel_id id, f64 pan, bool instant )
+void _audio_set_channel_pan( audio_channel_id id, f64 pan, b8 instant )
 {
    _audio_assert_lock();
 
@@ -615,7 +615,7 @@ audio_channel_id _audio_crossfade( audio_channel_id id, struct audio_clip *new_c
    return new_id;
 }
 
-bool _audio_is_channel_using_clip( audio_channel_id id, struct audio_clip *clip )
+b8 _audio_is_channel_using_clip( audio_channel_id id, struct audio_clip *clip )
 {
    _audio_assert_lock();
    struct audio_channel *channel = get_audio_channel( id );
@@ -644,7 +644,7 @@ void _audio_fadeout_flagged_audio( u32 flag, f32 length )
    }
 }
 
-bool _audio_flagged_stopped( u32 flag )
+b8 _audio_flagged_stopped( u32 flag )
 {
    _audio_lock();
    for( u32 id=1; id<=AUDIO_CHANNELS; id ++ )
@@ -664,14 +664,14 @@ bool _audio_flagged_stopped( u32 flag )
    return 1;
 }
 
-void _audio_set_channel_pause( audio_channel_id id, bool pause )
+void _audio_set_channel_pause( audio_channel_id id, b8 pause )
 {
    _audio_assert_lock();
    struct audio_channel_controls *controls = get_audio_channel_controls( id );
    controls->pause = pause;
 }
 
-void _audio_set_flagged_pause( u32 flag, bool pause )
+void _audio_set_flagged_pause( u32 flag, b8 pause )
 {
    _audio_assert_lock();
    for( u32 id=1; id<=AUDIO_CHANNELS; id ++ )
@@ -929,8 +929,8 @@ static void audio_channel_mix( audio_channel_id id,
 {
    struct audio_channel_state *state = get_audio_channel_state( id );
 
-   bool is_3d = controls->flags & AUDIO_FLAG_SPACIAL_3D? 1: 0;
-   bool use_doppler = controls->flags & AUDIO_FLAG_NO_DOPPLER? 0: 1;
+   b8 is_3d = controls->flags & AUDIO_FLAG_SPACIAL_3D? 1: 0;
+   b8 use_doppler = controls->flags & AUDIO_FLAG_NO_DOPPLER? 0: 1;
 
    f32 frame_sample_rate = controls->sampling_rate_multiplier;
 
@@ -1281,7 +1281,7 @@ static void _audio_mixer( ma_device *device, void *stream, const void *input__,
 
       if( controls->flags & AUDIO_FLAG_RELINQUISHED )
       {
-         bool die = 0;
+         b8 die = 0;
          if( state->activity == k_channel_activity_end ) die = 1;
          if( state->activity == k_channel_activity_error ) die = 1;
          if( state->volume == 0 ) die = 1;
@@ -1347,7 +1347,7 @@ void _audio_init(void)
 void vg_audio_preupdate(void)
 {
 #if 0
-   bool before_working = _audio.working;
+   b8 before_working = _audio.working;
    _audio.working = 1;
    if( _audio.sdl_output_device == 0 )
       _audio.working = 0;
index 18d025f6357e69463b5ba7e847e8435596c8fac2..083c9f04fad7451cf90917f3776ef52c56a14095 100644 (file)
@@ -66,7 +66,7 @@ struct audio_clip
 void vg_audio_device_init(void);
 void vg_audio_begin(void);
 
-bool audio_clip_load( struct audio_clip *clip, struct stack_allocator *stack );
+b8 audio_clip_load( struct audio_clip *clip, struct stack_allocator *stack );
 u32 audio_clip_loadn( struct audio_clip *arr, u32 count, struct stack_allocator *stack );
 
 void _audio_lock(void);
@@ -81,9 +81,9 @@ u32 _audio_count_channels_in_group( u16 group );
 audio_channel_id _audio_get_first_active_channel_in_group( u16 group );
 void _audio_sidechain_lfo_to_channel( audio_channel_id id, audio_channel_id lfo_id, f32 amount );
 void _audio_set_channel_spacial_falloff( audio_channel_id id, f32 co[3], f32 range );
-void _audio_set_channel_volume( audio_channel_id id, f64 volume, bool instant );
+void _audio_set_channel_volume( audio_channel_id id, f64 volume, b8 instant );
 void _audio_set_channel_volume_slew_duration( audio_channel_id id, f64 length_seconds );
-void _audio_set_channel_pan( audio_channel_id id, f64 pan, bool instant );
+void _audio_set_channel_pan( audio_channel_id id, f64 pan, b8 instant );
 void _audio_set_channel_pan_slew_duration( audio_channel_id id, f64 length_seconds );
 void _audio_set_channel_sampling_rate( audio_channel_id id, f32 rate );
 void _audio_start_channel( audio_channel_id id );
@@ -99,10 +99,10 @@ void _audio_sync_ui_master_controls(void);
 audio_channel_id _audio_crossfade( audio_channel_id id, struct audio_clip *new_clip, f32 transition_seconds );
 void _audio_oneshot_3d( struct audio_clip *clip, f32 co[3], f32 range, f32 volume, u16 group, u32 flags );
 void _audio_oneshot( struct audio_clip *clip, f32 volume, f32 pan, u16 group, u32 flags );
-void _audio_set_channel_pause( audio_channel_id id, bool pause );
+void _audio_set_channel_pause( audio_channel_id id, b8 pause );
 
 /* half measures... Don't expect these functions to stay. */
 void _audio_fadeout_flagged_audio( u32 flag, f32 length );
-bool _audio_flagged_stopped( u32 flag );
-bool _audio_is_channel_using_clip( audio_channel_id id, struct audio_clip *clip );
-void _audio_set_flagged_pause( u32 flag, bool pause );
+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 );
index 6d14fac98e2c396f2ad077c5a9e154f42aa99c4c..493f911323f105b9bcaa6d70be37540cc090a42b 100644 (file)
@@ -36,17 +36,9 @@ static void _engine_set_framerate( f64 hz, b8 vsync )
    _engine.framerate_limit = hz;
 }
 
-#if 0
-void _character_callback( GLFWwindow *window, u32 codepoint )
-{
-   if( _input_layer_filter( 1<<k_input_layer_ui ) )
-      _engine_ui_input_character( codepoint );
-}
-#endif
-
 void _engine_options(void)
 {
-   const c8 *arg;
+   //const c8 *arg;
    if( _option_long( "high-performance", "Turn graphics to lowest quality" ) )
       _engine.quality = k_quality_profile_low;
 
@@ -193,7 +185,7 @@ i32 main( i32 argc, const c8 *argv[] )
       _fatal_exit();
    }
 
-   const c8* glver = glGetString( GL_VERSION );
+   const c8 *glver = (const c8 *)glGetString( GL_VERSION );
    $log( $ok, {"Load setup complete, OpenGL version: "}, {glver} );
 
    glEnable              ( GL_DEBUG_OUTPUT );
@@ -297,6 +289,17 @@ L_new_frame:;
       {
          _input_keyboard_event( (SDL_KeyboardEvent *)&e );
       }
+      else if( e.type == SDL_EVENT_TEXT_INPUT )
+      {
+         SDL_TextInputEvent *ev = (SDL_TextInputEvent*)&e;
+
+         if( _input_layer_filter( 1<<k_input_layer_ui ) )
+         {
+            const u8 *utf8_text = (const u8 *)ev->text;
+            for( u32 i=0; utf8_text[i]; i ++ )
+               _engine_ui_input_character( utf8_text[i] );
+         }
+      }
    }
 
    goto L_new_frame;
index 20b3677393e08623e496b0b2263c47cc43b1c5b3..88e2a07dceff37126a5f934b3fef19f2d3d25724 100644 (file)
@@ -16,7 +16,8 @@ _input_aliases[] =
 {
    { "SHIFT", k_input_device_modifier, .key = SDL_KMOD_LSHIFT },
    { "CONTROL", k_input_device_modifier, .key = SDL_KMOD_LCTRL },
-   { "RETURN", k_input_device_keyboard, .key = SDLK_RETURN },
+   { "ALT", k_input_device_modifier, .key = SDL_KMOD_LALT },
+   { "ENTER", k_input_device_keyboard, .key = SDLK_RETURN },
    { "ESCAPE", k_input_device_keyboard, .key = SDLK_ESCAPE },
    { "BACKSPACE", k_input_device_keyboard, .key = SDLK_BACKSPACE },
    { "TAB", k_input_device_keyboard, .key = SDLK_TAB },
@@ -58,7 +59,7 @@ _input_aliases[] =
    { "RIGHTBRACKET", k_input_device_keyboard, .key = SDLK_RIGHTBRACKET },
    { "CARET", k_input_device_keyboard, .key = SDLK_CARET },
    { "UNDERSCORE", k_input_device_keyboard, .key = SDLK_UNDERSCORE },
-   { "GRAVE", k_input_device_keyboard, .key = SDLK_GRAVE },
+   { "GRAVE_ACCENT", k_input_device_keyboard, .key = SDLK_GRAVE },
    { "A", k_input_device_keyboard, .key = SDLK_A },
    { "B", k_input_device_keyboard, .key = SDLK_B },
    { "C", k_input_device_keyboard, .key = SDLK_C },
@@ -222,13 +223,13 @@ _input_aliases[] =
    { "KP_OCTAL", k_input_device_keyboard, .key = SDLK_KP_OCTAL },
    { "KP_DECIMAL", k_input_device_keyboard, .key = SDLK_KP_DECIMAL },
    { "KP_HEXADECIMAL", k_input_device_keyboard, .key = SDLK_KP_HEXADECIMAL },
-   { "LCTRL", k_input_device_keyboard, .key = SDLK_LCTRL },
-   { "LSHIFT", k_input_device_keyboard, .key = SDLK_LSHIFT },
-   { "LALT", k_input_device_keyboard, .key = SDLK_LALT },
+   { "LEFT_CTRL", k_input_device_keyboard, .key = SDLK_LCTRL },
+   { "LEFT_SHIFT", k_input_device_keyboard, .key = SDLK_LSHIFT },
+   { "LEFT_ALT", k_input_device_keyboard, .key = SDLK_LALT },
    { "LGUI", k_input_device_keyboard, .key = SDLK_LGUI },
-   { "RCTRL", k_input_device_keyboard, .key = SDLK_RCTRL },
-   { "RSHIFT", k_input_device_keyboard, .key = SDLK_RSHIFT },
-   { "RALT", k_input_device_keyboard, .key = SDLK_RALT },
+   { "RIGHT_CTRL", k_input_device_keyboard, .key = SDLK_RCTRL },
+   { "RIGHT_SHIFT", k_input_device_keyboard, .key = SDLK_RSHIFT },
+   { "RIGHT_ALT", k_input_device_keyboard, .key = SDLK_RALT },
    { "RGUI", k_input_device_keyboard, .key = SDLK_RGUI },
    { "MODE", k_input_device_keyboard, .key = SDLK_MODE },
    { "SLEEP", k_input_device_keyboard, .key = SDLK_SLEEP },
index 14ca3cc1e5f62721398f9f3cb9ac9d8bb8e31e3a..c5bd3d485f4ca3f1aa7c623f27867b9b18a9d2ef 100644 (file)
@@ -45,12 +45,6 @@ void _engine_ui_pre_render(void)
    //_graphics_fill_rect( (i16[]){ 0, 0, _engine.w, _engine.h }, (union colour){{0,0,0,255}} );
 }
 
-void _engine_ui_input_character( u32 codepoint )
-{
-   if( (codepoint >= (u32)' ') && (codepoint <= (u32)'~') )
-      _ui_input_text( (const c8[]){ codepoint, 0 } );
-}
-
 void _engine_ui_post_render(void)
 {
    glEnable( GL_BLEND );
@@ -68,4 +62,19 @@ void _engine_ui_post_render(void)
 
    _render_fullscreen_quad();
    glDisable( GL_BLEND );
+
+   static b8 want_text_prev = 0;
+   b8 want_text = _ui_want_text();
+   if( want_text != want_text_prev )
+   {
+      if( want_text ) SDL_StartTextInput( _engine.window_handle );
+      else            SDL_StopTextInput( _engine.window_handle );
+      want_text_prev = want_text;
+   }
+}
+
+void _engine_ui_input_character( u32 codepoint )
+{
+   if( (codepoint >= (u32)' ') && (codepoint <= (u32)'~') )
+      _ui_input_text( (const c8[]){ codepoint, 0 } );
 }
index 34e36ccc2deb838f347e090e81ddb6d2afd16d84..e135aadcb5360e12e75aaad99b367003fe7aad91 100644 (file)
@@ -2,3 +2,5 @@
 
 void _engine_ui_pre_render(void);
 void _engine_ui_post_render(void);
+b8 _engine_ui_want_text_input(void);
+void _engine_ui_input_character( u32 codepoint );
index 17b7d6bdaaf61bb8806e71fc84b5acae5de32964..e6a98c914a56f7f761a6675c834d588e7c947c3f 100644 (file)
@@ -177,7 +177,11 @@ void _log_end_event(void)
 void _log_init(void)
 {
    _log.lock = _mutex_create();
+#ifdef _WIN32
+   _stdout_stream.posix_stream = fopen( "stdout.txt", "w" );
+#else
    _stdout_stream.posix_stream = stdout;
+#endif
    _stdout_stream.offset = 0;
    _stdout_stream.buffer_length = 0;
    _stdout_stream.flags = k_stream_posix | k_stream_write;
index a3160f4023415f700d9bbd7cc8acd8dec1a51184..c196f4fe10ca28e791631884cbf205e07c7c16c3 100644 (file)
@@ -691,3 +691,8 @@ b8 _ui_want_mouse( i16 area[4] )
 
    return 0;
 }
+
+b8 _ui_want_text(void)
+{
+   return _ui.active_control_type == k_ui_control_textbox;
+}
index a3a685dc5c3c7e51adc62102febd6c94eedfbd96..863f1df33676cc1639c0e13e3ae650ec6f6bf7e2 100644 (file)
@@ -96,6 +96,7 @@ void _ui_set_mouse( i16 x, i16 y );
 void _ui_get_mouse_co( i16 out_co[2] );
 void _ui_input_text( const c8 *text );
 b8 _ui_want_mouse( i16 area[4] );
+b8 _ui_want_text(void);
 
 #define UI_PADDING_PX     8
 #define UI_ROW_PADDING_PX 18
index 7fc07f18b944ea7791ef761f7a4de3c4789bd922..aeb54b19e61c62a7ec356e06f8dd77f6ec1e4833 100644 (file)
@@ -1412,3 +1412,9 @@ static inline f32 closest_point_on_segment_2d( f32 co[2], f32 a[2], f32 b[2], f3
    v2_muladds( a, v0, t, d );
    return t;
 }
+
+static void closest_point_aabb( f32 p[3], f32 box[2][3], f32 dest[3] )
+{
+   v3_max( p, box[0], dest );
+   v3_min( dest, box[1], dest );
+}