From e9c75218d7cea204bcb850e420c247bafaaf3059 Mon Sep 17 00:00:00 2001 From: hgn Date: Thu, 23 Oct 2025 01:57:02 +0100 Subject: [PATCH] aaaaaaa --- source/engine/engine.kv | 1 - source/engine/vg_audio.c | 34 +++++++++++++++++----------------- source/engine/vg_audio.h | 14 +++++++------- source/engine/vg_engine.c | 23 +++++++++++++---------- source/engine/vg_input.c | 17 +++++++++-------- source/engine/vg_ui.c | 21 +++++++++++++++------ source/engine/vg_ui.h | 2 ++ source/foundation/logging.c | 4 ++++ source/graphics/ui.c | 5 +++++ source/graphics/vg_graphics.h | 1 + source/maths/common_maths.h | 6 ++++++ 11 files changed, 79 insertions(+), 49 deletions(-) diff --git a/source/engine/engine.kv b/source/engine/engine.kv index e81bb62..c29fc62 100644 --- a/source/engine/engine.kv +++ b/source/engine/engine.kv @@ -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" diff --git a/source/engine/vg_audio.c b/source/engine/vg_audio.c index 876624f..9f177d3 100644 --- a/source/engine/vg_audio.c +++ b/source/engine/vg_audio.c @@ -10,7 +10,7 @@ #include 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; diff --git a/source/engine/vg_audio.h b/source/engine/vg_audio.h index 18d025f..083c9f0 100644 --- a/source/engine/vg_audio.h +++ b/source/engine/vg_audio.h @@ -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 ); diff --git a/source/engine/vg_engine.c b/source/engine/vg_engine.c index 6d14fac..493f911 100644 --- a/source/engine/vg_engine.c +++ b/source/engine/vg_engine.c @@ -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<text; + for( u32 i=0; utf8_text[i]; i ++ ) + _engine_ui_input_character( utf8_text[i] ); + } + } } goto L_new_frame; diff --git a/source/engine/vg_input.c b/source/engine/vg_input.c index 20b3677..88e2a07 100644 --- a/source/engine/vg_input.c +++ b/source/engine/vg_input.c @@ -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 }, diff --git a/source/engine/vg_ui.c b/source/engine/vg_ui.c index 14ca3cc..c5bd3d4 100644 --- a/source/engine/vg_ui.c +++ b/source/engine/vg_ui.c @@ -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 } ); } diff --git a/source/engine/vg_ui.h b/source/engine/vg_ui.h index 34e36cc..e135aad 100644 --- a/source/engine/vg_ui.h +++ b/source/engine/vg_ui.h @@ -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 ); diff --git a/source/foundation/logging.c b/source/foundation/logging.c index 17b7d6b..e6a98c9 100644 --- a/source/foundation/logging.c +++ b/source/foundation/logging.c @@ -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; diff --git a/source/graphics/ui.c b/source/graphics/ui.c index a3160f4..c196f4f 100644 --- a/source/graphics/ui.c +++ b/source/graphics/ui.c @@ -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; +} diff --git a/source/graphics/vg_graphics.h b/source/graphics/vg_graphics.h index a3a685d..863f1df 100644 --- a/source/graphics/vg_graphics.h +++ b/source/graphics/vg_graphics.h @@ -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 diff --git a/source/maths/common_maths.h b/source/maths/common_maths.h index 7fc07f1..aeb54b1 100644 --- a/source/maths/common_maths.h +++ b/source/maths/common_maths.h @@ -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 ); +} -- 2.25.1