From 2fa8504dd104e0bde32ee487f97fbce4fd6d7104 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 25 May 2009 06:24:23 +0000 Subject: BGE Joystick Hat Bugfix bug reported by blenderage on blenderartist (found other bugs too). - "All Hat Events" didnt work. - Multiple hats didnt work - use a menu with direction names rather then have the user guess. disallow zero as a direction. - Allow up to 4 hats (was 2). - Python api was clamping the axis to 2, maximum is currently JOYAXIS_MAX - 16 - New python attributes hatValues and hatSingle, match axis functions. - Use SDL Axis events to fill in the axis and hat array rather then filling in every axis with SDL_JoystickGetAxis for each axis event. --- source/gameengine/GameLogic/SCA_JoystickSensor.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'source/gameengine/GameLogic/SCA_JoystickSensor.h') diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index e8185d1911e..e6a1d2eef32 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -30,6 +30,7 @@ #define __JOYSENSOR_H #include "SCA_ISensor.h" +#include "./Joystick/SCA_JoystickDefines.h" class SCA_JoystickSensor :public SCA_ISensor { @@ -37,7 +38,7 @@ class SCA_JoystickSensor :public SCA_ISensor class SCA_JoystickManager* m_pJoystickMgr; /** - * Axis 1-or-2, MUST be followed by m_axisf + * Axis 1-JOYAXIS_MAX, MUST be followed by m_axisf */ int m_axis; /** @@ -53,11 +54,11 @@ class SCA_JoystickSensor :public SCA_ISensor */ int m_buttonf; /** - * The actual hat. MUST be followed by m_hatf + * The actual hat 1-JOYHAT_MAX. MUST be followed by m_hatf */ int m_hat; /** - * Flag to find direction 0-11, MUST be an int + * Flag to find direction 1-12, MUST be an int */ int m_hatf; /** @@ -152,6 +153,8 @@ public: static PyObject* pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_hat_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_hat_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); @@ -164,8 +167,8 @@ public: SCA_JoystickSensor* sensor = reinterpret_cast(self); if (sensor->m_axis < 1) sensor->m_axis = 1; - else if (sensor->m_axis > 2) - sensor->m_axis = 2; + else if (sensor->m_axis > JOYAXIS_MAX) + sensor->m_axis = JOYAXIS_MAX; return 0; } static int CheckHat(void *self, const PyAttributeDef*) @@ -173,8 +176,8 @@ public: SCA_JoystickSensor* sensor = reinterpret_cast(self); if (sensor->m_hat < 1) sensor->m_hat = 1; - else if (sensor->m_hat > 2) - sensor->m_hat = 2; + else if (sensor->m_hat > JOYHAT_MAX) + sensor->m_hat = JOYHAT_MAX; return 0; } -- cgit v1.2.3