[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14331] trunk/blender/source/gameengine/ GameLogic: BGE bug [#4839] fixed: joystick keeps working after an overlay scene is removed
Benoit Bolsee
benoit.bolsee at online.be
Fri Apr 4 22:39:33 CEST 2008
Revision: 14331
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14331
Author: ben2610
Date: 2008-04-04 22:39:31 +0200 (Fri, 04 Apr 2008)
Log Message:
-----------
BGE bug [#4839] fixed: joystick keeps working after an overlay scene is removed
Modified Paths:
--------------
trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
trunk/blender/source/gameengine/GameLogic/SCA_JoystickManager.cpp
Modified: trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp 2008-04-04 16:32:13 UTC (rev 14330)
+++ trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp 2008-04-04 20:39:31 UTC (rev 14331)
@@ -55,7 +55,35 @@
delete m_private;
}
+SCA_Joystick *SCA_Joystick::m_instance = NULL;
+int SCA_Joystick::m_refCount = 0;
+SCA_Joystick *SCA_Joystick::GetInstance()
+{
+ if (m_instance == 0)
+ {
+ m_instance = new SCA_Joystick();
+ m_instance->CreateJoystickDevice();
+ m_refCount = 1;
+ }
+ else
+ {
+ m_refCount++;
+ }
+ return m_instance;
+}
+
+void SCA_Joystick::ReleaseInstance()
+{
+ if (--m_refCount == 0)
+ {
+ DestroyJoystickDevice();
+ delete m_instance;
+ m_instance = NULL;
+ }
+}
+
+
bool SCA_Joystick::CreateJoystickDevice()
{
bool init = false;
Modified: trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.h 2008-04-04 16:32:13 UTC (rev 14330)
+++ trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.h 2008-04-04 20:39:31 UTC (rev 14331)
@@ -71,12 +71,16 @@
/*
* Basic Joystick class
-
+ * I will make this class a singleton because there should be only one joystick
+ * even if there are more than one scene using it and count how many scene are using it.
+ * The underlying joystick should only be removed when the last scene is removed
*/
class SCA_Joystick
{
+ static SCA_Joystick *m_instance;
+ static int m_refCount;
class PrivateData;
@@ -258,20 +262,22 @@
int pGetHat(int direction);
-
-
-public:
-
SCA_Joystick();
~SCA_Joystick();
-
-
bool CreateJoystickDevice(void);
void DestroyJoystickDevice(void);
+
+public:
+
+ static SCA_Joystick *GetInstance();
+
+ void ReleaseInstance();
+
+
void HandleEvents();
/*
Modified: trunk/blender/source/gameengine/GameLogic/SCA_JoystickManager.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_JoystickManager.cpp 2008-04-04 16:32:13 UTC (rev 14330)
+++ trunk/blender/source/gameengine/GameLogic/SCA_JoystickManager.cpp 2008-04-04 20:39:31 UTC (rev 14331)
@@ -43,15 +43,13 @@
: SCA_EventManager(JOY_EVENTMGR),
m_logicmgr(logicmgr)
{
- m_joystick = new SCA_Joystick();
- m_joystick->CreateJoystickDevice();
+ m_joystick = SCA_Joystick::GetInstance();
}
SCA_JoystickManager::~SCA_JoystickManager()
{
- m_joystick->DestroyJoystickDevice();
- delete m_joystick;
+ m_joystick->ReleaseInstance();
}
More information about the Bf-blender-cvs
mailing list