6 #include "vg/vg_platform.h"
7 #include "vg/vg_console.h"
8 #include "vg/vg_input.h"
28 #define INPUT_BASIC( KB, JS ) \
29 (vg_input_op[]){vg_keyboard, KB, vg_joy_button, JS, vg_end}
31 static vg_input_op
*input_button_list
[] = {
32 [k_srbind_primary
] = (vg_input_op
[]){
33 vg_mouse
, SDL_BUTTON_LEFT
, vg_end
35 [k_srbind_secondary
] = (vg_input_op
[]){
36 vg_mouse
, SDL_BUTTON_RIGHT
, vg_end
38 [k_srbind_tertiary
] = (vg_input_op
[]){
39 vg_mouse
, SDL_BUTTON_MIDDLE
, vg_end
41 [k_srbind_go
] = (vg_input_op
[]){
42 vg_keyboard
, SDLK_SPACE
, vg_end
47 static vg_input_op
*input_axis_list
[] = {
51 static vg_input_op
*input_joy_list
[] = {
52 [k_srjoystick_max
]=NULL
56 float axis_states
[ k_sraxis_max
][2];
57 v2f joystick_states
[ k_srjoystick_max
][2];
58 u8 button_states
[ k_srbind_max
][2];
61 k_input_state_enabled
,
63 k_input_state_resuming
,
70 static int input_filter_generic(void){
71 if( (srinput
.state
!= k_input_state_enabled
) || vg_console
.enabled
)
77 static int buttons_filter_fixed(void){
78 if( input_filter_generic() )
81 if( vg
.engine_stage
== k_engine_stage_update_fixed
)
82 if( vg
.fixed_iterations
> 0 )
88 /* Rising edge of button */
89 static int button_down( enum sr_bind button
){
90 if( buttons_filter_fixed() ) return 0;
92 if( srinput
.button_states
[ button
][0] &&
93 !srinput
.button_states
[ button
][1] )
99 /* Falling edge of button */
100 static int button_up( enum sr_bind button
){
101 if( buttons_filter_fixed() ) return 0;
103 if( !srinput
.button_states
[ button
][0] &&
104 srinput
.button_states
[ button
][1] )
110 /* State of button */
111 static int button_press( enum sr_bind button
){
112 if( input_filter_generic() )
115 srinput
.button_states
[ button
][0];
118 static void joystick_state( enum sr_joystick joystick
, v2f state
){
119 if( input_filter_generic() )
122 v2_copy( srinput
.joystick_states
[ joystick
][0], state
);
125 static float axis_state( enum sr_axis axis
){
126 if( input_filter_generic() )
129 return srinput
.axis_states
[axis
][0];
132 static void skaterift_preupdate_inputs(void){
133 if( srinput
.state
== k_input_state_resuming
)
134 srinput
.state
= k_input_state_enabled
;
136 if( srinput
.state
== k_input_state_resume
)
137 srinput
.state
= k_input_state_resuming
;
139 for( u32 i
=0; i
<k_srbind_max
; i
++ ){
140 srinput
.button_states
[i
][1] = srinput
.button_states
[i
][0];
141 srinput
.button_states
[i
][0] = 0;
144 for( u32 i
=0; i
<k_srjoystick_max
; i
++ ){
145 v2_copy( srinput
.joystick_states
[i
][0], srinput
.joystick_states
[i
][1] );
146 v2_zero( srinput
.joystick_states
[i
][0] );
149 for( u32 i
=0; i
<k_sraxis_max
; i
++ ){
150 srinput
.axis_states
[i
][1] = srinput
.axis_states
[i
][0];
151 srinput
.axis_states
[i
][0] = 0.0f
;
154 for( int i
=0; i
<k_srbind_max
; i
++ ){
155 vg_input_op
*prog
= input_button_list
[i
];
157 vg_exec_input_program( k_vg_input_type_button_u8
, prog
,
158 &srinput
.button_states
[i
][0] );
162 for( int i
=0; i
<k_sraxis_max
; i
++ ){
163 vg_input_op
*prog
= input_axis_list
[i
];
165 vg_exec_input_program( k_vg_input_type_axis_f32
, prog
,
166 &srinput
.axis_states
[i
][0] );
170 for( int i
=0; i
<k_srjoystick_max
; i
++ ){
171 vg_input_op
*prog
= input_joy_list
[i
];
173 vg_exec_input_program( k_vg_input_type_joy_v2f
, prog
,
174 srinput
.joystick_states
[i
][0] );