input internal variables and functions are now static and static inline respectively
parent
664e4561a0
commit
22d0200d84
|
@ -11,10 +11,10 @@ const Uint8* g_key_states = NULL;
|
||||||
input_listener_t g_key_listeners[24];
|
input_listener_t g_key_listeners[24];
|
||||||
input_listener_t* g_key_listeners_endptr = g_key_listeners;
|
input_listener_t* g_key_listeners_endptr = g_key_listeners;
|
||||||
|
|
||||||
int _last_mouse_x=0, _last_mouse_y=0;
|
static int _last_mouse_x = 0, _last_mouse_y = 0;
|
||||||
float _last_screen_mouse_x=0.0, _last_screen_mouse_y=0.0;
|
static float _last_screen_mouse_x = 0.0, _last_screen_mouse_y = 0.0;
|
||||||
uint32_t _mouse_left_seconds = 0;
|
static uint32_t _mouse_left_seconds = 0;
|
||||||
float _scroll_delta=0;
|
static float _scroll_delta = 0;
|
||||||
|
|
||||||
void add_key_listener(SDL_Scancode negative, SDL_Scancode positive,
|
void add_key_listener(SDL_Scancode negative, SDL_Scancode positive,
|
||||||
input_axis_delegate_t delegate) {
|
input_axis_delegate_t delegate) {
|
||||||
|
@ -70,7 +70,8 @@ void input_init() {
|
||||||
g_key_states = SDL_GetKeyboardState(NULL);
|
g_key_states = SDL_GetKeyboardState(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_axis_listener(input_listener_t* listener) {
|
static inline
|
||||||
|
void _process_axis_listener(input_listener_t* listener) {
|
||||||
int val = 0;
|
int val = 0;
|
||||||
if(g_key_states[listener->axis.negative]) {
|
if(g_key_states[listener->axis.negative]) {
|
||||||
val = -1;
|
val = -1;
|
||||||
|
@ -84,13 +85,15 @@ void process_axis_listener(input_listener_t* listener) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_mouse_listener(input_listener_t* listener, float dx, float dy) {
|
static inline
|
||||||
|
void _process_mouse_listener(input_listener_t* listener, float dx, float dy) {
|
||||||
if(dx != 0.0 && dy != 0.0) {
|
if(dx != 0.0 && dy != 0.0) {
|
||||||
listener->mouse.delegate(dx, dy);
|
listener->mouse.delegate(dx, dy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_button_listener(input_listener_t* listener) {
|
static inline
|
||||||
|
void _process_button_listener(input_listener_t* listener) {
|
||||||
uint32_t state = SDL_GetMouseState(NULL, NULL);
|
uint32_t state = SDL_GetMouseState(NULL, NULL);
|
||||||
int is_down = (state & (listener->button.button)) != 0;
|
int is_down = (state & (listener->button.button)) != 0;
|
||||||
if(is_down != listener->button.last) {
|
if(is_down != listener->button.last) {
|
||||||
|
@ -99,7 +102,8 @@ void process_button_listener(input_listener_t* listener) {
|
||||||
listener->button.last = is_down;
|
listener->button.last = is_down;
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_scroll_listener(input_listener_t* listener) {
|
static inline
|
||||||
|
void _process_scroll_listener(input_listener_t* listener) {
|
||||||
if(_scroll_delta != 0) {
|
if(_scroll_delta != 0) {
|
||||||
listener->scroll.delegate(_scroll_delta);
|
listener->scroll.delegate(_scroll_delta);
|
||||||
}
|
}
|
||||||
|
@ -116,16 +120,16 @@ void update_input() {
|
||||||
for(input_listener_t* listener = g_key_listeners; listener != g_key_listeners_endptr; ++listener) {
|
for(input_listener_t* listener = g_key_listeners; listener != g_key_listeners_endptr; ++listener) {
|
||||||
switch(listener->type) {
|
switch(listener->type) {
|
||||||
case INPUT_LISTENER_AXIS:
|
case INPUT_LISTENER_AXIS:
|
||||||
process_axis_listener(listener);
|
_process_axis_listener(listener);
|
||||||
break;
|
break;
|
||||||
case INPUT_LISTENER_MOUSE:
|
case INPUT_LISTENER_MOUSE:
|
||||||
process_mouse_listener(listener, dx, dy);
|
_process_mouse_listener(listener, dx, dy);
|
||||||
break;
|
break;
|
||||||
case INPUT_LISTENER_SCROLL:
|
case INPUT_LISTENER_SCROLL:
|
||||||
process_scroll_listener(listener);
|
_process_scroll_listener(listener);
|
||||||
break;
|
break;
|
||||||
case INPUT_LISTENER_BUTTON:
|
case INPUT_LISTENER_BUTTON:
|
||||||
process_button_listener(listener);
|
_process_button_listener(listener);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue