Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-10-07 09:09:24 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-10-07 09:09:24 +0400
commit77484d28d5098de2fd3924df28d846023d7751ec (patch)
tree3ea8a3660c8e9bb18f0421f6d95c0a604fd710c1 /source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
parent8d73ea72a75ce5567fc2a39f2acc2ad5b2543f4c (diff)
joystick update
* use SDL events to trigger the sensor, trigger was being forced every tick. removed workaround for this problem. * added "All Events" option, similar to all keys in the keyboard sensor. This means every event from the joystick will trigger the sensor, however only events from the selected type (axis/button/hat) is used to set the positive state of the sensor. * Added python function sens_joy.GetButtonValues(), returns a list of pressed button indicies. * Removed pressed/released option for joystick buttons, it was the same as the invert option.
Diffstat (limited to 'source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp')
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp110
1 files changed, 45 insertions, 65 deletions
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
index 092956e6489..b50cfe812a9 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
@@ -24,7 +24,9 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+#ifndef DISABLE_SDL
#include <SDL.h>
+#endif
#include "SCA_Joystick.h"
#include "SCA_JoystickPrivate.h"
@@ -40,7 +42,10 @@ SCA_Joystick::SCA_Joystick(short int index)
m_buttonnum(-2),
m_hatdir(-2),
m_isinit(0),
- m_istrig(0)
+ m_istrig(0),
+ m_axismax(-1),
+ m_buttonmax(-1),
+ m_hatmax(-1)
{
#ifndef DISABLE_SDL
m_private = new PrivateData();
@@ -116,12 +121,19 @@ void SCA_Joystick::cSetPrecision(int val)
}
+bool SCA_Joystick::aAnyAxisIsPositive(int axis)
+{
+ bool result;
+ int res = pAxisTest(axis);
+ res > m_prec? result = true: result = false;
+ return result;
+}
+
bool SCA_Joystick::aRightAxisIsPositive(int axis)
{
bool result;
int res = pGetAxis(axis,1);
res > m_prec? result = true: result = false;
- m_istrig = result;
return result;
}
@@ -131,7 +143,6 @@ bool SCA_Joystick::aUpAxisIsPositive(int axis)
bool result;
int res = pGetAxis(axis,0);
res < -m_prec? result = true : result = false;
- m_istrig = result;
return result;
}
@@ -141,7 +152,6 @@ bool SCA_Joystick::aLeftAxisIsPositive(int axis)
bool result;
int res = pGetAxis(axis,1);
res < -m_prec ? result = true : result = false;
- m_istrig = result;
return result;
}
@@ -151,10 +161,18 @@ bool SCA_Joystick::aDownAxisIsPositive(int axis)
bool result;
int res = pGetAxis(axis,0);
res > m_prec ? result = true:result = false;
- m_istrig = result;
return result;
}
+bool SCA_Joystick::aAnyButtonPressIsPositive(void)
+{
+ return (m_buttonnum==-2) ? false : true;
+}
+
+bool SCA_Joystick::aAnyButtonReleaseIsPositive(void)
+{
+ return (m_buttonnum==-2) ? true : false;
+}
bool SCA_Joystick::aButtonPressIsPositive(int button)
{
@@ -163,7 +181,6 @@ bool SCA_Joystick::aButtonPressIsPositive(int button)
#else
bool result;
SDL_JoystickGetButton(m_private->m_joystick, button)? result = true:result = false;
- m_istrig = result;
return result;
#endif
}
@@ -176,7 +193,6 @@ bool SCA_Joystick::aButtonReleaseIsPositive(int button)
#else
bool result;
SDL_JoystickGetButton(m_private->m_joystick, button)? result = false : result = true;
- m_istrig = result;
return result;
#endif
}
@@ -187,27 +203,9 @@ bool SCA_Joystick::aHatIsPositive(int dir)
bool result;
int res = pGetHat(dir);
res == dir? result = true : result = false;
- m_istrig = result;
return result;
}
-
-int SCA_Joystick::pGetButtonPress(int button)
-{
- if(button == m_buttonnum)
- return m_buttonnum;
- return -2;
-}
-
-
-int SCA_Joystick::pGetButtonRelease(int button)
-{
- if(button == m_buttonnum)
- return m_buttonnum;
- return -2;
-}
-
-
int SCA_Joystick::pGetHat(int direction)
{
if(direction == m_hatdir){
@@ -218,52 +216,19 @@ int SCA_Joystick::pGetHat(int direction)
int SCA_Joystick::GetNumberOfAxes()
{
-#ifdef DISABLE_SDL
- return -1;
-#else
- int number;
- if(m_isinit){
- if(m_private->m_joystick){
- number = SDL_JoystickNumAxes(m_private->m_joystick);
- return number;
- }
- }
- return -1;
-#endif
+ return m_axismax;
}
int SCA_Joystick::GetNumberOfButtons()
{
-#ifdef DISABLE_SDL
- return -1;
-#else
- int number;
- if(m_isinit){
- if(m_private->m_joystick){
- number = SDL_JoystickNumButtons(m_private->m_joystick);
- return number;
- }
- }
- return -1;
-#endif
+ return m_buttonmax;
}
int SCA_Joystick::GetNumberOfHats()
{
-#ifdef DISABLE_SDL
- return -1;
-#else
- int number;
- if(m_isinit){
- if(m_private->m_joystick){
- number = SDL_JoystickNumHats(m_private->m_joystick);
- return number;
- }
- }
- return -1;
-#endif
+ return m_hatmax;
}
bool SCA_Joystick::CreateJoystickDevice(void)
@@ -280,9 +245,14 @@ bool SCA_Joystick::CreateJoystickDevice(void)
m_private->m_joystick = SDL_JoystickOpen(m_joyindex);
SDL_JoystickEventState(SDL_ENABLE);
-
- echo("Joystick " << m_joyindex << " initialized");
m_isinit = true;
+
+ echo("Joystick " << m_joyindex << " initialized");
+
+ /* must run after being initialized */
+ m_axismax = SDL_JoystickNumAxes(m_private->m_joystick);
+ m_buttonmax = SDL_JoystickNumButtons(m_private->m_joystick);
+ m_hatmax = SDL_JoystickNumHats(m_private->m_joystick);
}
return true;
#endif
@@ -314,10 +284,10 @@ int SCA_Joystick::Connected(void)
void SCA_Joystick::pFillAxes()
{
#ifndef DISABLE_SDL
- if(GetNumberOfAxes() == 1){
+ if(m_axismax == 1){
m_axis10 = SDL_JoystickGetAxis(m_private->m_joystick, 0);
m_axis11 = SDL_JoystickGetAxis(m_private->m_joystick, 1);
- }else if(GetNumberOfAxes() > 1){
+ }else if(m_axismax > 1){
m_axis10 = SDL_JoystickGetAxis(m_private->m_joystick, 0);
m_axis11 = SDL_JoystickGetAxis(m_private->m_joystick, 1);
m_axis20 = SDL_JoystickGetAxis(m_private->m_joystick, 2);
@@ -340,3 +310,13 @@ int SCA_Joystick::pGetAxis(int axisnum, int udlr)
return 0;
}
+#define MAX2(x,y) ( (x)>(y) ? (x) : (y) )
+int SCA_Joystick::pAxisTest(int axisnum)
+{
+#ifndef DISABLE_SDL
+ if(axisnum == 1)return MAX2(abs(m_axis10), abs(m_axis11));
+ if(axisnum == 2)return MAX2(abs(m_axis20), abs(m_axis21));
+#endif
+ return 0;
+}
+