Permalink
Browse files

Fix init & clarification in CJoystick classes

  • Loading branch information...
1 parent 9213ab6 commit 27731733d9a155f6d3359437670811882ea2d0d0 @Karlson2k committed Jul 6, 2012
Showing with 47 additions and 10 deletions.
  1. +19 −4 xbmc/input/SDLJoystick.cpp
  2. +1 −1 xbmc/input/SDLJoystick.h
  3. +26 −4 xbmc/input/windows/WINJoystick.cpp
  4. +1 −1 xbmc/input/windows/WINJoystick.h
@@ -36,16 +36,14 @@ CJoystick g_Joystick; // global
CJoystick::CJoystick()
{
- Reset();
+ Reset(true);
m_NumAxes = 0;
m_AxisId = 0;
m_JoyId = 0;
m_ButtonId = 0;
m_HatId = 0;
m_HatState = SDL_HAT_CENTERED;
m_ActiveFlags = JACTIVE_NONE;
- for (int i = 0 ; i<MAX_AXES ; i++)
- m_Amount[i] = 0;
SetDeadzone(0);
}
@@ -108,7 +106,7 @@ void CJoystick::Initialize()
SDL_JoystickEventState(SDL_DISABLE);
}
-void CJoystick::Reset(bool axis)
+void CJoystick::Reset(bool axis /*=false*/)
{
if (axis)
{
@@ -304,7 +302,10 @@ void CJoystick::Update(SDL_Event& joyEvent)
bool CJoystick::GetHat(int &id, int &position,bool consider_repeat)
{
if (!IsHatActive())
+ {
+ id = position = 0;
return false;
+ }
position = m_HatState;
id = m_HatId;
if (!consider_repeat)
@@ -337,7 +338,10 @@ bool CJoystick::GetHat(int &id, int &position,bool consider_repeat)
bool CJoystick::GetButton(int &id, bool consider_repeat)
{
if (!IsButtonActive())
+ {
+ id = 0;
return false;
+ }
if (!consider_repeat)
{
id = m_ButtonId;
@@ -372,6 +376,17 @@ bool CJoystick::GetButton(int &id, bool consider_repeat)
return true;
}
+bool CJoystick::GetAxis (int &id)
+{
+ if (!IsAxisActive())
+ {
+ id = 0;
+ return false;
+ }
+ id = m_AxisId;
+ return true;
+}
+
int CJoystick::GetAxisWithMaxAmount()
{
static int maxAmount;
@@ -57,7 +57,7 @@ class CJoystick
void Update();
void Update(SDL_Event& event);
bool GetButton (int& id, bool consider_repeat=true);
- bool GetAxis (int &id) { if (!IsAxisActive()) return false; id=m_AxisId; return true; }
+ bool GetAxis (int &id);
bool GetHat (int &id, int &position, bool consider_repeat=true);
std::string GetJoystick() { return (m_JoyId>-1)?m_JoystickNames[m_JoyId]:""; }
int GetAxisWithMaxAmount();
@@ -53,16 +53,14 @@ extern HWND g_hWnd;
CJoystick::CJoystick()
{
- Reset();
+ Reset(true);
m_NumAxes = 0;
m_AxisId = 0;
m_JoyId = 0;
m_ButtonId = 0;
m_HatId = 0;
m_HatState = SDL_HAT_CENTERED;
m_ActiveFlags = JACTIVE_NONE;
- for (int i = 0 ; i<MAX_AXES ; i++)
- m_Amount[i] = 0;
SetDeadzone(0);
m_pDI = NULL;
@@ -88,6 +86,13 @@ void CJoystick::ReleaseJoysticks()
m_pJoysticks.clear();
m_JoystickNames.clear();
m_devCaps.clear();
+ m_HatId = 0;
+ m_ButtonId = 0;
+ m_HatState = SDL_HAT_CENTERED;
+ m_ActiveFlags = JACTIVE_NONE;
+ Reset(true);
+ m_lastPressTicks = 0;
+ m_lastTicks = 0;
// Release any DirectInput objects.
SAFE_RELEASE( m_pDI );
}
@@ -208,7 +213,7 @@ void CJoystick::Initialize()
SetDeadzone(g_advancedSettings.m_controllerDeadzone);
}
-void CJoystick::Reset(bool axis)
+void CJoystick::Reset(bool axis /*=true*/)
{
if (axis)
{
@@ -361,7 +366,10 @@ void CJoystick::Update()
bool CJoystick::GetHat(int &id, int &position,bool consider_repeat)
{
if (!IsHatActive())
+ {
+ id = position = 0;
return false;
+ }
position = m_HatState;
id = m_HatId;
if (!consider_repeat)
@@ -392,7 +400,10 @@ bool CJoystick::GetHat(int &id, int &position,bool consider_repeat)
bool CJoystick::GetButton(int &id, bool consider_repeat)
{
if (!IsButtonActive())
+ {
+ id = 0;
return false;
+ }
if (!consider_repeat)
{
id = m_ButtonId;
@@ -425,6 +436,17 @@ bool CJoystick::GetButton(int &id, bool consider_repeat)
return true;
}
+bool CJoystick::GetAxis (int &id)
+{
+ if (!IsAxisActive())
+ {
+ id = 0;
+ return false;
+ }
+ id = m_AxisId;
+ return true;
+}
+
int CJoystick::GetAxisWithMaxAmount()
{
int maxAmount = 0;
@@ -47,7 +47,7 @@ class CJoystick
void ResetAxis(int axisId) { m_Amount[axisId] = 0; }
void Update();
bool GetButton (int& id, bool consider_repeat=true);
- bool GetAxis (int &id) { if (!IsAxisActive()) return false; id=m_AxisId; return true; }
+ bool GetAxis (int &id);
bool GetHat (int &id, int &position, bool consider_repeat=true);
std::string GetJoystick() { return (m_JoyId>-1)?m_JoystickNames[m_JoyId]:""; }
int GetAxisWithMaxAmount();

0 comments on commit 2773173

Please sign in to comment.