diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-09-02 10:12:19 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-09-02 10:12:19 +0400 |
commit | 84dcfa181b0722655ceba3930a2daa0e27e72f93 (patch) | |
tree | bb39eccc758e18c3a65d3101306f71b008e8eaf1 /source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp | |
parent | 81ad271d157c70433b36af31581261ae8c2098a4 (diff) |
BGE Bugfix, SDL joysticks arrow keys didnt work when 2 joysticks were being used at the same time.
The event queue was running for every joystick sensor without checking if the events were for that joystick.
seperating the event queue for each joystick is overkill so instead deal with all joysticks events in once function.
Also removed some unused functions
Diffstat (limited to 'source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp')
-rw-r--r-- | source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp index ab523470e21..1e064f55397 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp @@ -30,41 +30,75 @@ -void SCA_Joystick::OnAxisMotion(void) +void SCA_Joystick::OnAxisMotion(SDL_Event* sdl_event) { pFillAxes(); - m_axisnum = m_private->m_event.jaxis.axis; - m_axisvalue = m_private->m_event.jaxis.value; + m_axisnum = sdl_event->jaxis.axis; + m_axisvalue = sdl_event->jaxis.value; m_istrig = 1; } -void SCA_Joystick::OnHatMotion(void) +void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event) { - m_hatdir = m_private->m_event.jhat.value; - m_hatnum = m_private->m_event.jhat.hat; + m_hatdir = sdl_event->jhat.value; + m_hatnum = sdl_event->jhat.hat; m_istrig = 1; } -void SCA_Joystick::OnButtonUp(void) +void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event) { m_buttonnum = -2; } -void SCA_Joystick::OnButtonDown(void) +void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event) { m_buttonmax = GetNumberOfButtons(); - if(m_private->m_event.jbutton.button >= 1 || m_private->m_event.jbutton.button <= m_buttonmax) + if(sdl_event->jbutton.button >= 1 || sdl_event->jbutton.button <= m_buttonmax) { m_istrig = 1; - m_buttonnum = m_private->m_event.jbutton.button; + m_buttonnum = sdl_event->jbutton.button; } } -void SCA_Joystick::OnNothing(void) +void SCA_Joystick::OnNothing(SDL_Event* sdl_event) { m_istrig = 0; } + +/* only handle events for 1 joystick */ + +void SCA_Joystick::HandleEvents(void) +{ + SDL_Event sdl_event; + + if(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? */ + switch(sdl_event.type) + { + case SDL_JOYAXISMOTION: + SCA_Joystick::m_instance[sdl_event.jaxis.which]->OnAxisMotion(&sdl_event); + break; + case SDL_JOYHATMOTION: + SCA_Joystick::m_instance[sdl_event.jhat.which]->OnHatMotion(&sdl_event); + break; + case SDL_JOYBUTTONUP: + SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonUp(&sdl_event); + break; + case SDL_JOYBUTTONDOWN: + SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonDown(&sdl_event); + break; + case SDL_JOYBALLMOTION: + SCA_Joystick::m_instance[sdl_event.jball.which]->OnBallMotion(&sdl_event); + break; + default: + printf("SCA_Joystick::HandleEvents, Unknown SDL event, this should not happen\n"); + break; + } + } +} |