Skip to content
Permalink
Browse files

gambatte_qt/framework: fix broken js event filtering

do continue while false==true ...
  • Loading branch information...
sinamas committed Nov 3, 2013
1 parent eb74667 commit e3235268b1329b8e7b32a5d57f03364266bbdc9a
Showing with 39 additions and 39 deletions.
  1. +39 −39 gambatte_qt/src/framework/src/joysticklock.cpp
@@ -19,55 +19,55 @@
#include "joysticklock.h"
#include <map>

static int pollJsEvent(SDL_Event *const ev, int const insensitivity) {
static bool acceptEvent(SDL_Event &ev, int const insensitivity) {
if (ev.type != SDL_JOYAXISMOTION)
return true;

enum { threshold = 8192 };
typedef std::map<unsigned, int> Map;
static Map axisState;
Map::iterator const at =
axisState.insert(Map::value_type(ev.id, SdlJoystick::axis_centered)).first;
switch (at->second) {
case SdlJoystick::axis_centered:
if (ev.value >= threshold + insensitivity)
ev.value = SdlJoystick::axis_positive;
else if (ev.value <= -(threshold + insensitivity))
ev.value = SdlJoystick::axis_negative;
else
return false;

int evValid;
break;
case SdlJoystick::axis_positive:
if (ev.value >= threshold - insensitivity)
return false;

do {
evValid = SDL_PollEvent(ev);
if (evValid && ev->type == SDL_JOYAXISMOTION) {
enum { threshold = 8192 };
Map::iterator const at =
axisState.insert(Map::value_type(ev->id, SdlJoystick::axis_centered)).first;
switch (at->second) {
case SdlJoystick::axis_centered:
if (ev->value >= threshold + insensitivity)
ev->value = SdlJoystick::axis_positive;
else if (ev->value <= -(threshold + insensitivity))
ev->value = SdlJoystick::axis_negative;
else
continue;
ev.value = ev.value <= -(threshold + insensitivity)
? SdlJoystick::axis_negative
: SdlJoystick::axis_centered;
break;
case SdlJoystick::axis_negative:
if (ev.value <= -(threshold - insensitivity))
return false;

break;
case SdlJoystick::axis_positive:
if (ev->value >= threshold - insensitivity)
continue;
ev.value = ev.value >= threshold + insensitivity
? SdlJoystick::axis_positive
: SdlJoystick::axis_centered;
break;
}

ev->value = ev->value <= -(threshold + insensitivity)
? SdlJoystick::axis_negative
: SdlJoystick::axis_centered;
break;
case SdlJoystick::axis_negative:
if (ev->value <= -(threshold - insensitivity))
continue;
at->second = ev.value;
return true;
}

ev->value = ev->value >= threshold + insensitivity
? SdlJoystick::axis_positive
: SdlJoystick::axis_centered;
break;
}
int SdlJoystick::Locked::pollEvent(SDL_Event *ev, int insensitivity) {
int evValid;

at->second = ev->value;
}
} while (false);
do {
evValid = SDL_PollEvent(ev);
} while (evValid && !acceptEvent(*ev, insensitivity));

return evValid;
}

int SdlJoystick::Locked::pollEvent(SDL_Event *ev, int insensitivity) {
return pollJsEvent(ev, insensitivity);
}

QMutex SdlJoystick::mutex_;

0 comments on commit e323526

Please sign in to comment.
You can’t perform that action at this time.