Fix init & clarification in CJoystick classes
authorKarlson2k <k2k@narod.ru>
Fri, 6 Jul 2012 16:52:04 +0000 (20:52 +0400)
committerKarlson2k <k2k@narod.ru>
Sun, 8 Jul 2012 20:35:52 +0000 (00:35 +0400)
xbmc/input/SDLJoystick.cpp
xbmc/input/SDLJoystick.h
xbmc/input/windows/WINJoystick.cpp
xbmc/input/windows/WINJoystick.h

index 9ad993c..4eedbb8 100644 (file)
@@ -36,7 +36,7 @@ CJoystick g_Joystick; // global
 
 CJoystick::CJoystick()
 {
-  Reset();
+  Reset(true);
   m_NumAxes = 0;
   m_AxisId = 0;
   m_JoyId = 0;
@@ -44,8 +44,6 @@ CJoystick::CJoystick()
   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;
index e7803d1..1d283ad 100644 (file)
@@ -57,7 +57,7 @@ public:
   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();
index 2e05e7e..e0a11f7 100644 (file)
@@ -53,7 +53,7 @@ extern HWND g_hWnd;
 
 CJoystick::CJoystick()
 {
-  Reset();
+  Reset(true);
   m_NumAxes = 0;
   m_AxisId = 0;
   m_JoyId = 0;
@@ -61,8 +61,6 @@ CJoystick::CJoystick()
   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;
index c06686f..6d7064f 100644 (file)
@@ -47,7 +47,7 @@ public:
   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();