key listeners are now only triggered if their value changed #18
|
@ -131,12 +131,19 @@ void _handle_key_event(const SDL_Event event) {
|
||||||
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) {
|
||||||
if(listener->type == INPUT_LISTENER_AXIS) {
|
if(listener->type == INPUT_LISTENER_AXIS) {
|
||||||
const SDL_Scancode scode = event.key.keysym.scancode;
|
const SDL_Scancode scode = event.key.keysym.scancode;
|
||||||
|
int changed = 0;
|
||||||
if(listener->axis.positive == scode) {
|
if(listener->axis.positive == scode) {
|
||||||
listener->axis.last_positive = event.key.state == SDL_PRESSED;
|
int new = event.key.state == SDL_PRESSED;
|
||||||
|
changed = new != listener->axis.last_positive;
|
||||||
|
listener->axis.last_positive = new;
|
||||||
}
|
}
|
||||||
if(listener->axis.negative == scode) {
|
else if(listener->axis.negative == scode) {
|
||||||
listener->axis.last_negative = event.key.state == SDL_PRESSED;
|
int new = event.key.state == SDL_PRESSED;
|
||||||
|
changed = new != listener->axis.last_negative;
|
||||||
|
listener->axis.last_negative = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(changed)
|
||||||
listener->axis.delegate(listener->axis.last_positive - listener->axis.last_negative);
|
listener->axis.delegate(listener->axis.last_positive - listener->axis.last_negative);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue