From 8c4620f3d3d5cb533f3d1bf5c526c6ffc0355aaa Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 28 May 2009 13:44:32 +0000 Subject: [#18840] Joystick sensor lag if(SDL_PollEvent(&sdl_event)) // if -> while fixed it removed 'm_buttonnum' was misleading, wasn't used as you expect. Added gravity to variable to world to be used by collada. --- .../gameengine/GameLogic/Joystick/SCA_Joystick.cpp | 20 +++++++----- .../gameengine/GameLogic/Joystick/SCA_Joystick.h | 11 +------ .../GameLogic/Joystick/SCA_JoystickDefines.h | 1 + .../GameLogic/Joystick/SCA_JoystickEvents.cpp | 37 ++++++++++------------ 4 files changed, 30 insertions(+), 39 deletions(-) (limited to 'source/gameengine/GameLogic/Joystick') diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp index 7c4ebb4c330..d83179d4f80 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp @@ -38,7 +38,6 @@ SCA_Joystick::SCA_Joystick(short int index) : m_joyindex(index), m_prec(3200), - m_buttonnum(-2), m_axismax(-1), m_buttonmax(-1), m_hatmax(-1), @@ -68,6 +67,7 @@ SCA_Joystick::~SCA_Joystick() } SCA_Joystick *SCA_Joystick::m_instance[JOYINDEX_MAX]; +int SCA_Joystick::m_joynum = 0; int SCA_Joystick::m_refCount = 0; SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex ) @@ -88,6 +88,9 @@ SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex ) echo("Error-Initializing-SDL: " << SDL_GetError()); return NULL; } + + m_joynum = SDL_NumJoysticks(); + for (i=0; iCreateJoystickDevice(); @@ -155,12 +158,13 @@ bool SCA_Joystick::aAxisIsPositive(int axis_single) bool SCA_Joystick::aAnyButtonPressIsPositive(void) { - return (m_buttonnum==-2) ? false : true; -} - -bool SCA_Joystick::aAnyButtonReleaseIsPositive(void) -{ - return (m_buttonnum==-2) ? true : false; + /* this is needed for the "all events" option + * so we know if there are no buttons pressed */ + for (int i=0; im_joystick, i)) + return true; + + return false; } bool SCA_Joystick::aButtonPressIsPositive(int button) @@ -217,7 +221,7 @@ bool SCA_Joystick::CreateJoystickDevice(void) return false; #else if(m_isinit == false){ - if (m_joyindex>=SDL_NumJoysticks()) { + if (m_joyindex>=m_joynum) { // don't print a message, because this is done anyway //echo("Joystick-Error: " << SDL_NumJoysticks() << " avaiable joystick(s)"); diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h index 5822f8e8ff8..6324b898247 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h @@ -44,6 +44,7 @@ class SCA_Joystick { static SCA_Joystick *m_instance[JOYINDEX_MAX]; + static int m_joynum; static int m_refCount; class PrivateData; @@ -67,11 +68,6 @@ class SCA_Joystick */ int m_prec; - /* - * button values stored here - */ - int m_buttonnum; - /* * max # of buttons avail */ @@ -146,7 +142,6 @@ public: bool aAxisIsPositive(int axis_single); /* check a single axis only */ bool aAnyButtonPressIsPositive(void); - bool aAnyButtonReleaseIsPositive(void); bool aButtonPressIsPositive(int button); bool aButtonReleaseIsPositive(int button); bool aHatIsPositive(int hatnum, int dir); @@ -160,10 +155,6 @@ public: int GetAxisPosition(int index){ return m_axis_array[index]; } - - int GetButton(void){ - return m_buttonnum; - } int GetHat(int index){ return m_hat_array[index]; diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h index c7a9a5114df..70619ff337a 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h @@ -40,6 +40,7 @@ #define JOYINDEX_MAX 8 #define JOYAXIS_MAX 16 +#define JOYBUT_MAX 18 #define JOYHAT_MAX 4 #define JOYAXIS_RIGHT 0 diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp index 3ca8d7d2329..66193a2f4b9 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp @@ -42,7 +42,7 @@ void SCA_Joystick::OnAxisMotion(SDL_Event* sdl_event) m_istrig_axis = 1; } - +/* See notes below in the event loop */ void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event) { if(sdl_event->jhat.hat >= JOYAXIS_MAX) @@ -52,30 +52,20 @@ void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event) m_istrig_hat = 1; } +/* See notes below in the event loop */ void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event) { m_istrig_button = 1; - - /* this is needed for the "all events" option - * so we know if there are no buttons pressed */ - int i; - for (i=0; im_joystick, i)) { - m_buttonnum = i; - return; - } - } - m_buttonnum = -2; } void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event) { - if(sdl_event->jbutton.button <= m_buttonmax) /* unsigned int so always above 0 */ - { - m_istrig_button = 1; - m_buttonnum = sdl_event->jbutton.button; - } + //if(sdl_event->jbutton.button > m_buttonmax) /* unsigned int so always above 0 */ + // return; + // sdl_event->jbutton.button; + + m_istrig_button = 1; } @@ -84,22 +74,27 @@ void SCA_Joystick::OnNothing(SDL_Event* sdl_event) m_istrig_axis = m_istrig_button = m_istrig_hat = 0; } -/* only handle events for 1 joystick */ - void SCA_Joystick::HandleEvents(void) { SDL_Event sdl_event; int i; - for (i=0; iOnNothing(&sdl_event); } - if(SDL_PollEvent(&sdl_event)) + while(SDL_PollEvent(&sdl_event)) { /* Note! m_instance[sdl_event.jaxis.which] * will segfault if over JOYINDEX_MAX, not too nice but what are the chances? */ + + /* Note!, with buttons, this wont care which button is pressed, + * only to set 'm_istrig_button', actual pressed buttons are detected by SDL_JoystickGetButton */ + + /* Note!, if you manage to press and release a button within 1 logic tick + * it wont work as it should */ + switch(sdl_event.type) { case SDL_JOYAXISMOTION: -- cgit v1.2.3