onepad: drop the pad if an error was detected

v2:
init m_no_error in gamepad constructor
This commit is contained in:
Gregory Hainaut 2017-04-14 20:33:33 +02:00
parent 2e09c7faf3
commit 1b369520ed
2 changed files with 12 additions and 0 deletions

View File

@ -11,6 +11,7 @@ class GamePad
public:
GamePad()
: m_deadzone(1500)
, m_no_error(false)
{
}
@ -56,8 +57,14 @@ public:
return m_deadzone;
}
bool IsProperlyInitialized()
{
return m_no_error;
}
protected:
int m_deadzone;
bool m_no_error;
};
extern std::vector<std::unique_ptr<GamePad>> s_vgamePad;

View File

@ -67,6 +67,9 @@ void JoystickInfo::EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>> &vjo
for (int i = 0; i < SDL_NumJoysticks(); ++i) {
vjoysticks.push_back(std::unique_ptr<GamePad>(new JoystickInfo(i)));
// Something goes wrong in the init, let's drop it
if (!vjoysticks.back()->IsProperlyInitialized())
vjoysticks.pop_back();
}
}
@ -193,6 +196,8 @@ JoystickInfo::JoystickInfo(int id)
fprintf(stdout, "onepad: controller (%s) detected%s, GUID:%s\n",
devname, m_haptic ? " with rumble support" : "", guid);
m_no_error = true;
}
const char *JoystickInfo::GetName()