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 );
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 ),
}
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 )
{
}
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;
}
}
}
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;
+ }
}
}
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 )