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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-09-02 10:12:19 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-09-02 10:12:19 +0400
commit84dcfa181b0722655ceba3930a2daa0e27e72f93 (patch)
treebb39eccc758e18c3a65d3101306f71b008e8eaf1 /source
parent81ad271d157c70433b36af31581261ae8c2098a4 (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')
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp102
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.h36
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h8
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp56
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_JoystickPrivate.h4
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickManager.cpp22
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickSensor.cpp4
7 files changed, 74 insertions, 158 deletions
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
index ec0b0303b68..06002060bf1 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
@@ -99,38 +99,6 @@ void SCA_Joystick::ReleaseInstance()
}
}
-void SCA_Joystick::HandleEvents()
-{
- if(m_isinit)
- {
- if(SDL_PollEvent(&m_private->m_event))
- {
- switch(m_private->m_event.type)
- {
- case SDL_JOYAXISMOTION:
- HANDLE_AXISMOTION(OnAxisMotion);
- break;
- case SDL_JOYHATMOTION:
- HANDLE_HATMOTION(OnHatMotion);
- break;
- case SDL_JOYBUTTONUP:
- HANDLE_BUTTONUP(OnButtonUp);
- break;
- case SDL_JOYBUTTONDOWN:
- HANDLE_BUTTONDOWN(OnButtonDown);
- break;
- case SDL_JOYBALLMOTION:
- HANDLE_BALLMOTION(OnBallMotion);
- break;
- default:
- HANDLE_NOEVENT(OnNothing);
- break;
- }
- }
- }
-}
-
-
void SCA_Joystick::cSetPrecision(int val)
{
m_prec = val;
@@ -229,76 +197,6 @@ int SCA_Joystick::pGetHat(int direction)
return 0;
}
-
-bool SCA_Joystick::GetJoyAxisMotion()
-{
- bool result = false;
- if(m_isinit){
- if(SDL_PollEvent(&m_private->m_event)){
- switch(m_private->m_event.type)
- {
- case SDL_JOYAXISMOTION:
- result = true;
- break;
- }
- }
- }
- return result;
-}
-
-
-bool SCA_Joystick::GetJoyButtonPress()
-{
- bool result = false;
- if(m_isinit){
- if(SDL_PollEvent(&m_private->m_event)){
- switch(m_private->m_event.type)
- {
- case SDL_JOYBUTTONDOWN:
- result = true;
- break;
- }
- }
- }
- return result;
-}
-
-
-bool SCA_Joystick::GetJoyButtonRelease()
-{
- bool result = false;
- if(m_isinit)
- {
- if(SDL_PollEvent(&m_private->m_event)){
- switch(m_private->m_event.type)
- {
- case SDL_JOYBUTTONUP:
- result = true;
- break;
- }
- }
- }
- return result;
-}
-
-
-bool SCA_Joystick::GetJoyHatMotion()
-{
- bool result = false;
- if(m_isinit){
- if(SDL_PollEvent(&m_private->m_event)){
- switch(m_private->m_event.type)
- {
- case SDL_JOYHATMOTION:
- result = true;
- break;
- }
- }
- }
- return 0;
-}
-
-
int SCA_Joystick::GetNumberOfAxes()
{
int number;
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
index d318d28e0f7..bcbb43241c2 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
@@ -29,6 +29,7 @@
#define _SCA_JOYSTICK_H_
#include "SCA_JoystickDefines.h"
+#include "SDL.h"
/*
* Basic Joystick class
@@ -104,6 +105,16 @@ class SCA_Joystick
bool m_istrig;
/*
+ * event callbacks
+ */
+ void OnAxisMotion(SDL_Event *sdl_event);
+ void OnHatMotion(SDL_Event *sdl_event);
+ void OnButtonUp(SDL_Event *sdl_event);
+ void OnButtonDown(SDL_Event *sdl_event);
+ void OnNothing(SDL_Event *sdl_event);
+ void OnBallMotion(SDL_Event *sdl_event){}
+
+ /*
* Open the joystick
*/
bool CreateJoystickDevice(void);
@@ -112,17 +123,6 @@ class SCA_Joystick
* Close the joystick
*/
void DestroyJoystickDevice(void);
-
- /*
- * event callbacks
- */
-
- void OnAxisMotion(void);
- void OnHatMotion(void);
- void OnButtonUp(void);
- void OnButtonDown(void);
- void OnNothing(void);
- void OnBallMotion(void){}
/*
* fills the axis mnember values
@@ -158,9 +158,9 @@ class SCA_Joystick
public:
static SCA_Joystick *GetInstance( short int joyindex );
+ static void HandleEvents( void );
void ReleaseInstance();
- void HandleEvents();
/*
*/
@@ -212,16 +212,6 @@ public:
bool IsTrig(void){
return m_istrig;
}
-
-
- /*
- * returns true if an event is being processed
- */
-
- bool GetJoyAxisMotion(void);
- bool GetJoyButtonPress(void);
- bool GetJoyButtonRelease(void);
- bool GetJoyHatMotion(void);
/*
* returns the # of...
@@ -237,7 +227,7 @@ public:
int Connected(void);
};
-
+void Joystick_HandleEvents( void );
#endif
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h
index 8d8f88ecaf2..73ffe1406d9 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h
+++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h
@@ -40,12 +40,4 @@
#define JOYINDEX_MAX 8
-/* function callbacks */
-#define HANDLE_AXISMOTION(fn) ((fn)(), 0L)
-#define HANDLE_HATMOTION(fn) ((fn)(), 0L)
-#define HANDLE_BUTTONUP(fn) ((fn)(), 0L)
-#define HANDLE_BUTTONDOWN(fn) ((fn)(), 0L)
-#define HANDLE_BALLMOTION(fn) ((fn)(), 0L)
-#define HANDLE_NOEVENT(fn) ((fn)(), 0L)
-
#endif
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;
+ }
+ }
+}
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickPrivate.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickPrivate.h
index 23fad3cd55d..bb6bfe2d4cc 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_JoystickPrivate.h
+++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickPrivate.h
@@ -33,10 +33,6 @@ class SCA_Joystick::PrivateData
{
public:
/*
- * SDL events structure
- */
- SDL_Event m_event;
- /*
* The Joystick
*/
SDL_Joystick* m_joystick;
diff --git a/source/gameengine/GameLogic/SCA_JoystickManager.cpp b/source/gameengine/GameLogic/SCA_JoystickManager.cpp
index 08c36326712..a86770a6e0a 100644
--- a/source/gameengine/GameLogic/SCA_JoystickManager.cpp
+++ b/source/gameengine/GameLogic/SCA_JoystickManager.cpp
@@ -44,7 +44,6 @@ SCA_JoystickManager::SCA_JoystickManager(class SCA_LogicManager* logicmgr)
for (i=0; i<JOYINDEX_MAX; i++) {
m_joystick[i] = SCA_Joystick::GetInstance( i );
}
- //m_joystick = NULL;
}
@@ -59,14 +58,21 @@ SCA_JoystickManager::~SCA_JoystickManager()
void SCA_JoystickManager::NextFrame(double curtime,double deltatime)
{
- set<SCA_ISensor*>::iterator it;
- for (it = m_sensors.begin(); it != m_sensors.end(); it++)
- {
- SCA_JoystickSensor* joysensor = (SCA_JoystickSensor*)(*it);
- if(!joysensor->IsSuspended())
+ if (m_sensors.size()==0) {
+ return;
+ }
+ else {
+ set<SCA_ISensor*>::iterator it;
+
+ SCA_Joystick::HandleEvents(); /* Handle all SDL Joystick events */
+
+ for (it = m_sensors.begin(); it != m_sensors.end(); it++)
{
- m_joystick[joysensor->GetJoyIndex()]->HandleEvents();
- joysensor->Activate(m_logicmgr, NULL);
+ SCA_JoystickSensor* joysensor = (SCA_JoystickSensor*)(*it);
+ if(!joysensor->IsSuspended())
+ {
+ joysensor->Activate(m_logicmgr, NULL);
+ }
}
}
}
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
index 456401d48df..b32cbd83285 100644
--- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
@@ -245,10 +245,10 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
}
if (js->IsTrig()) {
- /* This test detects changes with the joystick trigger state.
+ /* The if below detects changes with the joystick trigger state.
* js->IsTrig() will stay true as long as the key is held.
* even though the event from SDL will only be sent once.
- * istrig_js && m_istrig_lastjs - when this is true it means this sensor
+ * (js->IsTrig() && m_istrig_lastjs) - when true it means this sensor
* had the same joystick trigger state last time,
* Setting the result false this time means it wont run the sensors
* controller every time (like a pulse sensor)