From: hgn Date: Wed, 8 Oct 2025 23:36:27 +0000 (+0000) Subject: Some compile options, some stretchy api, some input backend fixes X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=d193e15839bedef8dc4f901260a5e7768922f512;p=vg.git Some compile options, some stretchy api, some input backend fixes --- diff --git a/include/common_api.h b/include/common_api.h index 5996500..0657af8 100644 --- a/include/common_api.h +++ b/include/common_api.h @@ -94,6 +94,7 @@ void stretchy_init( struct stretchy_allocator *stretchy, u32 element_size ); void *stretchy_append( struct stretchy_allocator *stretchy ); void *stretchy_get( struct stretchy_allocator *stretchy, u32 index ); void stretchy_delete( struct stretchy_allocator *stretchy, u32 index ); +void stretchy_shrink( struct stretchy_allocator *stretchy ); u32 stretchy_count( struct stretchy_allocator *stretchy ); void stretchy_free( struct stretchy_allocator *stretchy ); diff --git a/include/input_api.h b/include/input_api.h index fa5dc52..5af31f6 100644 --- a/include/input_api.h +++ b/include/input_api.h @@ -10,7 +10,8 @@ enum input_device k_input_device_none = 0, k_input_device_keyboard, k_input_device_controller, - k_input_device_mouse + k_input_device_mouse, + k_input_device_modifier, }; struct input_info diff --git a/source/engine/input.c b/source/engine/input.c index 4cb6c0b..ba79bec 100644 --- a/source/engine/input.c +++ b/source/engine/input.c @@ -8,7 +8,7 @@ struct input_alias { const c8 *alias; u8 device_type; - u32 key, mod; + u32 key; u32 alias_hash; } _input_aliases[] = @@ -136,10 +136,10 @@ _input_aliases[] = { "RIGHT_ALT", k_input_device_keyboard, .key = GLFW_KEY_RIGHT_ALT }, { "RIGHT_SUPER", k_input_device_keyboard, .key = GLFW_KEY_RIGHT_SUPER }, { "MENU", k_input_device_keyboard, .key = GLFW_KEY_MENU }, - { "SHIFT", k_input_device_keyboard, .mod = GLFW_MOD_SHIFT }, - { "CONTROL", k_input_device_keyboard, .mod = GLFW_MOD_CONTROL }, - { "ALT", k_input_device_keyboard, .mod = GLFW_MOD_ALT }, - { "SUPER", k_input_device_keyboard, .mod = GLFW_MOD_SUPER }, + { "SHIFT", k_input_device_modifier, .key = GLFW_MOD_SHIFT }, + { "CONTROL", k_input_device_modifier, .key = GLFW_MOD_CONTROL }, + { "ALT", k_input_device_modifier, .key = GLFW_MOD_ALT }, + { "SUPER", k_input_device_modifier, .key = GLFW_MOD_SUPER }, }; static struct input_alias *_input_alias_find( const c8 *alias, u32 alias_length ) @@ -223,37 +223,24 @@ i32 _input_bind_ccmd( struct console_arguments *args ) struct input_alias *alias = _input_alias_find( buttons, length ); if( alias ) { - if( new_bind.device ) + if( (alias->device_type == k_input_device_keyboard) || (alias->device_type == k_input_device_mouse) ) { - if( alias->device_type != new_bind.device ) + if( new_bind.device ) { - $log( $error, {"Device mismatch while parsing buttons"} ); + $log( $error, {"Cannot specify more than one normal buttons in bind"} ); return -1; } - } - else + new_bind.id = alias->key; new_bind.device = alias->device_type; - - if( (alias->device_type == k_input_device_keyboard) || (alias->device_type == k_input_device_mouse) ) + } + else if( alias->device_type == k_input_device_modifier ) { - if( alias->key ) - { - if( new_bind.id ) - { - $log( $error, {"Cannot specify more than one normal buttons in bind"} ); - return -1; - } - new_bind.id = alias->key; - } - else //mod + if( new_bind.device ) { - if( new_bind.id ) - { - $log( $error, {"Modifiers must come first"} ); - return -1; - } - new_bind.modifiers |= alias->mod; + $log( $error, {"Modifiers must come first"} ); + return -1; } + new_bind.modifiers |= alias->key; } else { @@ -308,35 +295,30 @@ static void _input_callback_buttonlike( enum input_device device, i32 id, i32 ac if( (input->type == k_input_type_action) || (input->type == k_input_type_button) ) { + bool allow_activation = 1; if( input->type == k_input_type_action ) - { if( bind->modifiers != mods ) - continue; - } + allow_activation = 0; - if( action == GLFW_REPEAT || action == GLFW_PRESS ) - { - ASSERT_CRITICAL( state->button.repeat_count < 255 ); - state->button.repeat_count ++; - } - - if( action == GLFW_PRESS ) + if( allow_activation && (action == GLFW_PRESS) ) { ASSERT_CRITICAL( state->button.activation_count < 255 ); state->button.activation_count ++; - if( input->type == k_input_type_button ) - { - ASSERT_CRITICAL( state->button.hold_count < 255 ); - state->button.hold_count ++; - } + ASSERT_CRITICAL( state->button.hold_count < 255 ); + state->button.hold_count ++; + } + + if( state->button.hold_count && allow_activation && (action == GLFW_REPEAT || action == GLFW_PRESS) ) + { + ASSERT_CRITICAL( state->button.repeat_count < 255 ); + state->button.repeat_count ++; } if( action == GLFW_RELEASE ) { - if( input->type == k_input_type_button ) + if( state->button.hold_count ) { - ASSERT_CRITICAL( state->button.hold_count > 0 ); state->button.hold_count --; state->button.release_count ++; } diff --git a/source/foundation/allocator_stretchy.c b/source/foundation/allocator_stretchy.c index 37b9bf4..86a099a 100644 --- a/source/foundation/allocator_stretchy.c +++ b/source/foundation/allocator_stretchy.c @@ -46,13 +46,9 @@ void stretchy_free( struct stretchy_allocator *stretchy ) } } -void stretchy_delete( struct stretchy_allocator *stretchy, u32 index ) +void stretchy_shrink( struct stretchy_allocator *stretchy ) { - if( (stretchy->count > 1) && (index != stretchy->count-1) ) - { - buffer_copy( stretchy_get( stretchy, stretchy->count-1 ), stretchy->element_size, - stretchy_get( stretchy, index ), stretchy->element_size ); - } + ASSERT_CRITICAL( stretchy->count ); stretchy->count --; i32 i, offset; @@ -64,3 +60,13 @@ void stretchy_delete( struct stretchy_allocator *stretchy, u32 index ) stretchy->segments[i] = NULL; } } + +void stretchy_delete( struct stretchy_allocator *stretchy, u32 index ) +{ + if( (stretchy->count > 1) && (index != stretchy->count-1) ) + { + buffer_copy( stretchy_get( stretchy, stretchy->count-1 ), stretchy->element_size, + stretchy_get( stretchy, index ), stretchy->element_size ); + } + stretchy_shrink( stretchy ); +} diff --git a/source/tools/metacompiler.c b/source/tools/metacompiler.c index 2412850..8333106 100644 --- a/source/tools/metacompiler.c +++ b/source/tools/metacompiler.c @@ -850,9 +850,11 @@ i32 main( i32 argc, const c8 *argv[] ) {" zig cc -Wall -Wno-unused-function -std=c11 -D_DEFAULT_SOURCE -lm \\\n"}, {" -include \"common_api.h\" \\\n"} ); - if( use_tsan ) $v_string( &command_string, {" -fsanitize=thread -lasan \\\n"} ); - if( use_asan ) $v_string( &command_string, {" -fsanitize=address -lasan \\\n"} ); - $v_string( &command_string, { " -O" }, $unsigned( optimise ), {" \\\n"} ); + if( use_tsan ) $v_string( &command_string, {" -fsanitize=thread -lasan -L/lib/x86_64-linux-gnu \\\n"} ); + if( use_asan ) $v_string( &command_string, {" -fsanitize=address -lasan -L/lib/x86_64-linux-gnu \\\n"} ); + $v_string( &command_string, { " -O" }, $unsigned( optimise ) ); + if( optimise == 0 ) $v_string( &command_string, { " -ggdb" } ); + $v_string( &command_string, {" \\\n"} ); $v_string( &command_string, {" -target "}, {string_get(&tripple_string)}, {" "} ); if( platform == k_platform_windows )