axiseseys
authorhgn <hgodden00@gmail.com>
Sat, 8 Nov 2025 20:42:37 +0000 (20:42 +0000)
committerhgn <hgodden00@gmail.com>
Sat, 8 Nov 2025 20:42:37 +0000 (20:42 +0000)
source/engine/model_entity.h
source/engine/vg_input.c
source/engine/vg_input.h

index be0c9c04dbd935a1edcc482f78490dc4f6f97a9f..4ba5e7e0ce9d77182338be7a8cbe4726bc6e008d 100644 (file)
@@ -748,6 +748,7 @@ enum entity_event_result
 
 enum ent_event_flags
 {
+   k_ent_event_data_void = 0x0,
    k_ent_event_data_const_i32 = 0x1,
    k_ent_event_data_const_f32 = 0x2,
    k_ent_event_data_const_entity_id = 0x4,
index 24acafb7ad03b6c89e472906cf90210c8c1e2c3b..74c57091fcc35f5cdaa5b9cf27d10a84da1c9e32 100644 (file)
@@ -443,11 +443,25 @@ static _input_states[2][k_input_count];
 struct bind
 {
    u16 device, input_index;
-   u32 id;
+   u16 id;
+   i16 polarity;
    u32 modifiers;
 };
 struct stretchy_allocator _bind_allocator;
 
+enum input_id _input_get( const c8 *name )
+{
+   for( i32 i=0; i<k_input_count; i ++ )
+   {
+      struct input_info *input = &_input_infos[ i ];
+      if( compare_buffers( input->name, 0, name, 0 ) )
+      {
+         return i;
+      }
+   }
+   return -1;
+}
+
 i32 _input_bind_ccmd( struct console_arguments *args )
 {
    const c8 *buttons = console_get_argument( args, 0 );
@@ -457,31 +471,30 @@ i32 _input_bind_ccmd( struct console_arguments *args )
       return -1;
    }
 
+   i32 input_polarity = 0;
    const c8 *input_name = console_get_argument( args, 1 );
+
+   if( input_name[0] == '-' ) input_polarity = -1;
+   if( input_name[0] == '+' ) input_polarity = +1;
+   if( input_polarity )
+      input_name ++;
+
    if( !input_name )
    {
       $log( $error, {"Usage: bind <button> <action>"} );
       return -1;
    }
 
-   i32 input_id = -1;
-   for( u32 i=0; i<k_input_count; i ++ )
-   {
-      struct input_info *input = &_input_infos[ i ];
-      if( compare_buffers( input->name, 0, input_name, 0 ) )
-      {
-         input_id = i;
-         break;
-      }
-   }
-
+   i32 input_id = _input_get( input_name );
    if( input_id == -1 )
    {
       $log( $error, {"Don't know an input called '"}, {input_name}, {"'"} );
       return -1;
    }
 
-   struct bind new_bind = { .input_index = input_id };
+   struct bind new_bind = {0};
+   new_bind.input_index = input_id;
+
    while(1)
    {
       i32 plus_index = buffer_first_index( buttons, '+', 0 ),
@@ -499,6 +512,7 @@ i32 _input_bind_ccmd( struct console_arguments *args )
             }
             new_bind.id = alias->key;
             new_bind.device = alias->device_type;
+            new_bind.polarity = input_polarity;
          }
          else if( alias->device_type == k_input_device_modifier )
          {
@@ -593,7 +607,10 @@ void _input_callback_buttonlike( enum input_device device, i32 id, enum input_bu
             }
             else if( input->type == k_input_type_axis )
             {
-               ASSERT_CRITICAL( 0 );
+               if( action == k_button_down )
+                  state->axis.value += (f32)bind->polarity;
+               else if( action == k_button_up )
+                  state->axis.value -= (f32)bind->polarity;
             }
          }
       }
@@ -627,6 +644,11 @@ void _input_update(void)
          back_state->button.release_count = 0;
          back_state->button.hold_count = state->button.hold_count;
       }
+
+      if( input->type == k_input_type_axis )
+      {
+         back_state->axis.value = state->axis.value;
+      }
    }
 }
 
@@ -653,19 +675,55 @@ u8 _input_button_down( enum input_id id, b8 allow_repeats )
    if( _filter_input(id) )
    {
       union input_state *state = _get_input_state( id );
-      return allow_repeats? state->button.repeat_count: state->button.activation_count;
+      struct input_info *input = &_input_infos[ id ];
+      if( (input->type == k_input_type_button) || (input->type == k_input_type_action) )
+         return allow_repeats? state->button.repeat_count: state->button.activation_count;
+      else return 0;
    }
    else return 0;
 }
 
 u8 _input_button_up( enum input_id id )
 {
-   return _filter_input(id) && _get_input_state( id )->button.release_count;
+   if( _filter_input(id) )
+   {
+      union input_state *state = _get_input_state( id );
+      struct input_info *input = &_input_infos[ id ];
+      if( (input->type == k_input_type_button) || (input->type == k_input_type_action) )
+         return state->button.release_count;
+      else return 0;
+   }
+   else return 0;
 }
 
 u8 _input_button( enum input_id id )
 {
-   return _filter_input(id) && _get_input_state( id )->button.hold_count;
+   if( _filter_input(id) )
+   {
+      union input_state *state = _get_input_state( id );
+      struct input_info *input = &_input_infos[ id ];
+      if( (input->type == k_input_type_button) || (input->type == k_input_type_action) )
+         return state->button.hold_count;
+      else if( input->type == k_input_type_axis )
+         return (state->axis.value*state->axis.value) > 0.01f;
+      else return 0.0f;
+   }
+   else return 0;
+}
+
+f32 _input_axis( enum input_id id )
+{
+   if( _filter_input(id) )
+   {
+      union input_state *state = _get_input_state( id );
+      struct input_info *input = &_input_infos[ id ];
+      if( input->type == k_input_type_button )
+         return state->button.hold_count? 1.0f: 0.0f;
+      else if( input->type == k_input_type_axis )
+         return state->axis.value;
+      else return 0.0f;
+   }
+   else return 0.0f;
 }
 
 void _input_layer_whitelist( u32 whitelist )
index b8d423770b92a2c8aa58f058ddfa48a8beefa484..c26b6693925a65abc62670072e469f0ead5de45c 100644 (file)
@@ -12,8 +12,7 @@ enum input_device
 {
    k_input_device_none = 0,
    k_input_device_keyboard,
-   k_input_device_controller,
-   k_input_device_mouse,
+   k_input_device_controller, k_input_device_mouse,
    k_input_device_modifier,
 };
 
@@ -37,9 +36,11 @@ void _input_callback_buttonlike( enum input_device device, i32 id, enum input_bu
 u8 _input_button_down( enum input_id id, b8 allow_repeats );
 u8 _input_button_up( enum input_id id );
 u8 _input_button( enum input_id id );
+f32 _input_axis( enum input_id id );
 
 void _input_layer_whitelist( u32 whitelist );
 b8 _input_layer_filter( u32 mask );
 void _input_string( struct stream *stream, enum input_id id );
+enum input_id _input_get( const c8 *name );
 
 #include "generated/input.h"