2 #include "vg/vg_platform.h"
3 #include "vg/vg_console.h"
4 #include "vg/vg_input.h"
7 #include "vg/vg_imgui.h"
26 #define INPUT_BASIC( KB, JS ) \
27 (vg_input_op[]){vg_keyboard, KB, vg_joy_button, JS, vg_end}
29 static vg_input_op
*input_button_list
[] = {
30 [k_srbind_primary
] = (vg_input_op
[]){
31 vg_mouse
, SDL_BUTTON_LEFT
, vg_end
33 [k_srbind_secondary
] = (vg_input_op
[]){
34 vg_mouse
, SDL_BUTTON_RIGHT
, vg_end
36 [k_srbind_tertiary
] = (vg_input_op
[]){
37 vg_mouse
, SDL_BUTTON_MIDDLE
, vg_end
39 [k_srbind_go
] = (vg_input_op
[]){
40 vg_keyboard
, SDLK_SPACE
, vg_end
45 static vg_input_op
*input_axis_list
[] = {
49 static vg_input_op
*input_joy_list
[] = {
50 [k_srjoystick_max
]=NULL
54 float axis_states
[ k_sraxis_max
][2];
55 v2f joystick_states
[ k_srjoystick_max
][2];
56 u8 button_states
[ k_srbind_max
][2];
59 k_input_state_enabled
,
61 k_input_state_resuming
,
68 static int input_filter_generic(void){
69 if( (srinput
.state
!= k_input_state_enabled
) ||
70 vg_console
.enabled
|| vg
.settings_open
)
76 static int buttons_filter_fixed(void){
77 if( input_filter_generic() )
80 if( vg
.engine_stage
== k_engine_stage_update_fixed
)
81 if( vg
.fixed_iterations
> 0 )
87 /* Rising edge of button */
88 static int button_down( enum sr_bind button
){
89 if( buttons_filter_fixed() ) return 0;
91 if( srinput
.button_states
[ button
][0] &&
92 !srinput
.button_states
[ button
][1] )
98 /* Falling edge of button */
99 static int button_up( enum sr_bind button
){
100 if( buttons_filter_fixed() ) return 0;
102 if( !srinput
.button_states
[ button
][0] &&
103 srinput
.button_states
[ button
][1] )
109 /* State of button */
110 static int button_press( enum sr_bind button
){
111 if( input_filter_generic() )
114 srinput
.button_states
[ button
][0];
117 static void joystick_state( enum sr_joystick joystick
, v2f state
){
118 if( input_filter_generic() )
121 v2_copy( srinput
.joystick_states
[ joystick
][0], state
);
124 static float axis_state( enum sr_axis axis
){
125 if( input_filter_generic() )
128 return srinput
.axis_states
[axis
][0];
131 static void skaterift_preupdate_inputs(void){
132 if( srinput
.state
== k_input_state_resuming
)
133 srinput
.state
= k_input_state_enabled
;
135 if( srinput
.state
== k_input_state_resume
)
136 srinput
.state
= k_input_state_resuming
;
138 for( u32 i
=0; i
<k_srbind_max
; i
++ ){
139 srinput
.button_states
[i
][1] = srinput
.button_states
[i
][0];
140 srinput
.button_states
[i
][0] = 0;
143 for( u32 i
=0; i
<k_srjoystick_max
; i
++ ){
144 v2_copy( srinput
.joystick_states
[i
][0], srinput
.joystick_states
[i
][1] );
145 v2_zero( srinput
.joystick_states
[i
][0] );
148 for( u32 i
=0; i
<k_sraxis_max
; i
++ ){
149 srinput
.axis_states
[i
][1] = srinput
.axis_states
[i
][0];
150 srinput
.axis_states
[i
][0] = 0.0f
;
153 for( int i
=0; i
<k_srbind_max
; i
++ ){
154 vg_input_op
*prog
= input_button_list
[i
];
156 vg_exec_input_program( k_vg_input_type_button_u8
, prog
,
157 &srinput
.button_states
[i
][0] );
161 for( int i
=0; i
<k_sraxis_max
; i
++ ){
162 vg_input_op
*prog
= input_axis_list
[i
];
164 vg_exec_input_program( k_vg_input_type_axis_f32
, prog
,
165 &srinput
.axis_states
[i
][0] );
169 for( int i
=0; i
<k_srjoystick_max
; i
++ ){
170 vg_input_op
*prog
= input_joy_list
[i
];
172 vg_exec_input_program( k_vg_input_type_joy_v2f
, prog
,
173 srinput
.joystick_states
[i
][0] );