Some compile options, some stretchy api, some input backend fixes
authorhgn <hgodden00@gmail.com>
Wed, 8 Oct 2025 23:36:27 +0000 (23:36 +0000)
committerhgn <hgodden00@gmail.com>
Wed, 8 Oct 2025 23:36:27 +0000 (23:36 +0000)
include/common_api.h
include/input_api.h
source/engine/input.c
source/foundation/allocator_stretchy.c
source/tools/metacompiler.c

index 59965004373bf722f739065ce34ff80802e8f229..0657af8142ec045c452b1162f09509074dadeb31 100644 (file)
@@ -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 );
 
index fa5dc52b916025e7c9ca865f6809299763f8b825..5af31f637bcf04ff90d0f3d77bb72b4c708262d8 100644 (file)
@@ -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
index 4cb6c0b4aeacf1463b930e974e6aba59c350fc20..ba79bec5fd3873bdab6246df862c5ee5ba77007c 100644 (file)
@@ -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 ++;
                   }
index 37b9bf4761029cf662529c574b31be3b2ae768f1..86a099a652ba32ebeb90a220e2940979f7ef1f47 100644 (file)
@@ -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 );
+}
index 2412850731589be621c469d2af808d258eaf5a4d..833310692a18d8f73594adb6d16ec0f3fb87b7af 100644 (file)
@@ -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 )