[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37522] branches/soc-2011-cucumber/source/ gameengine: Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.

Daniel Stokes kupomail at gmail.com
Wed Jun 15 21:33:47 CEST 2011


Revision: 37522
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37522
Author:   kupoman
Date:     2011-06-15 19:33:46 +0000 (Wed, 15 Jun 2011)
Log Message:
-----------
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API

Modified Paths:
--------------
    branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
    branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h
    branches/soc-2011-cucumber/source/gameengine/GameLogic/SCA_IInputDevice.h
    branches/soc-2011-cucumber/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
    branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_KetsjiEngine.h
    branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_PythonInit.cpp

Modified: branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp	2011-06-15 18:59:22 UTC (rev 37521)
+++ branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp	2011-06-15 19:33:46 UTC (rev 37522)
@@ -211,7 +211,6 @@
 		
 		// create the inputdevices
 		KX_BlenderKeyboardDevice* keyboarddevice = new KX_BlenderKeyboardDevice();
-		keyboarddevice->SetExitKey(startscene->gm.exitkey);
 
 		KX_BlenderMouseDevice* mousedevice = new KX_BlenderMouseDevice();
 		
@@ -236,6 +235,7 @@
 		ketsjiengine->SetNetworkDevice(networkdevice);
 		ketsjiengine->SetUseFixedTime(usefixed);
 		ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
+		KX_KetsjiEngine::SetExitKey(ConvertKeyCode(startscene->gm.exitkey));
 
 #ifdef WITH_PYTHON
 		CValue::SetDeprecationWarnings(nodepwarnings);

Modified: branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp	2011-06-15 18:59:22 UTC (rev 37521)
+++ branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp	2011-06-15 19:33:46 UTC (rev 37522)
@@ -37,6 +37,7 @@
 #endif 
 
 #include "KX_BlenderKeyboardDevice.h"
+#include "KX_KetsjiEngine.h"
 
 KX_BlenderKeyboardDevice::KX_BlenderKeyboardDevice()
 	: m_hookesc(false)
@@ -107,7 +108,7 @@
 
 		if (val == KM_PRESS)
 		{
-			if (kxevent == m_exit_key && val != 0 && !m_hookesc)
+			if (kxevent == KX_KetsjiEngine::GetExitKey() && val != 0 && !m_hookesc)
 				result = true;
 			if (kxevent == KX_PAUSEKEY && val && (IsPressed(KX_LEFTCTRLKEY) || IsPressed(KX_RIGHTCTRLKEY)))
 				result = true;
@@ -168,8 +169,3 @@
 {
 	m_hookesc = true;
 }
-
-void KX_BlenderKeyboardDevice::SetExitKey(short key)
-{
-	m_exit_key = ToNative(key);
-}

Modified: branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h	2011-06-15 18:59:22 UTC (rev 37521)
+++ branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h	2011-06-15 19:33:46 UTC (rev 37522)
@@ -52,7 +52,6 @@
 	virtual bool	ConvertBlenderEvent(unsigned short incode,short val);
 	virtual void	NextFrame();
 	virtual void	HookEscape();
-	virtual void	SetExitKey(short key);
 private:
 	short		m_exit_key;
 

Modified: branches/soc-2011-cucumber/source/gameengine/GameLogic/SCA_IInputDevice.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/GameLogic/SCA_IInputDevice.h	2011-06-15 18:59:22 UTC (rev 37521)
+++ branches/soc-2011-cucumber/source/gameengine/GameLogic/SCA_IInputDevice.h	2011-06-15 19:33:46 UTC (rev 37522)
@@ -286,7 +286,6 @@
 	*/
 	int				m_currentTable; 
 	void			ClearStatusTable(int tableid);
-	short			m_exitkey;
 
 public:
 	virtual bool	IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
@@ -317,11 +316,7 @@
 	*/
 	virtual void	NextFrame();
 
-	//Exit Key get/set
-	virtual void	SetExitKey(short key){m_exitkey=key;};
-	virtual short	GetExitKey(){return m_exitkey;};
 
-
 #ifdef WITH_CXX_GUARDEDALLOC
 public:
 	void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SCA_InputEvent"); }

Modified: branches/soc-2011-cucumber/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/GamePlayer/ghost/GPG_Application.cpp	2011-06-15 18:59:22 UTC (rev 37521)
+++ branches/soc-2011-cucumber/source/gameengine/GamePlayer/ghost/GPG_Application.cpp	2011-06-15 19:33:46 UTC (rev 37522)
@@ -622,7 +622,7 @@
 		
 		
 
-		m_keyboard->SetExitKey(ConvertKeyCode(gm->exitkey));
+		KX_KetsjiEngine::SetExitKey(ConvertKeyCode(gm->exitkey));
 #ifdef WITH_PYTHON
 		CValue::SetDeprecationWarnings(nodepwarnings);
 #else
@@ -902,7 +902,7 @@
 		GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
 		GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData);
 
-		if (m_keyboard->ToNative(keyData->key) == m_keyboard->GetExitKey() && !m_keyboard->m_hookesc && !m_isEmbedded) {
+		if (m_keyboard->ToNative(keyData->key) == KX_KetsjiEngine::GetExitKey() && !m_keyboard->m_hookesc && !m_isEmbedded) {
 			m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
 		}
 		m_keyboard->ConvertEvent(keyData->key, isDown);

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2011-06-15 18:59:22 UTC (rev 37521)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2011-06-15 19:33:46 UTC (rev 37522)
@@ -106,6 +106,7 @@
 double KX_KetsjiEngine::m_suspendedtime = 0.0;
 double KX_KetsjiEngine::m_suspendeddelta = 0.0;
 double KX_KetsjiEngine::m_average_framerate = 0.0;
+short  KX_KetsjiEngine::m_exitkey = 130; //ESC Key
 
 
 /**
@@ -1827,6 +1828,16 @@
 	return m_average_framerate;
 }
 
+void KX_KetsjiEngine::SetExitKey(short key)
+{
+	m_exitkey = key;
+}
+
+short KX_KetsjiEngine::GetExitKey()
+{
+	return m_exitkey;
+}
+
 void KX_KetsjiEngine::SetTimingDisplay(bool frameRate, bool profile, bool properties)
 {
 	m_show_framerate = frameRate;

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_KetsjiEngine.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_KetsjiEngine.h	2011-06-15 18:59:22 UTC (rev 37521)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_KetsjiEngine.h	2011-06-15 19:33:46 UTC (rev 37522)
@@ -118,6 +118,8 @@
 	static double			m_suspendedtime;
 	static double			m_suspendeddelta;
 
+	static short			m_exitkey; /* Key used to exit the BGE */
+
 	int					m_exitcode;
 	STR_String			m_exitstring;
 		/**
@@ -334,6 +336,10 @@
 	 */
 	static double GetAverageFrameRate();
 
+	static void SetExitKey(short key);
+
+	static short GetExitKey();
+
 	/**
 	 * Activates or deactivates timing information display.
 	 * @param frameRate		Display for frame rate on or off.

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_PythonInit.cpp	2011-06-15 18:59:22 UTC (rev 37521)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_PythonInit.cpp	2011-06-15 19:33:46 UTC (rev 37522)
@@ -411,6 +411,20 @@
 	return PyFloat_FromDouble(KX_KetsjiEngine::GetTicRate());
 }
 
+static PyObject* gPySetExitKey(PyObject*, PyObject* args)
+{
+	short exitkey;
+	if (!PyArg_ParseTuple(args, "h:setExitKey", &exitkey))
+		return NULL;
+	KX_KetsjiEngine::SetExitKey(exitkey);
+	Py_RETURN_NONE;
+}
+
+static PyObject* gPyGetExitKey(PyObject*)
+{
+	return PyLong_FromSsize_t(KX_KetsjiEngine::GetExitKey());
+}
+
 static PyObject* gPySetMaxLogicFrame(PyObject*, PyObject* args)
 {
 	int frame;
@@ -804,6 +818,8 @@
 	{"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, (const char *)"Sets the logic tic rate"},
 	{"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, (const char *)"Gets the physics tic rate"},
 	{"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, (const char *)"Sets the physics tic rate"},
+	{"getExitKey", (PyCFunction) gPyGetExitKey, METH_NOARGS, (const char *)"Gets the key used to exit the game engine"},
+	{"setExitKey", (PyCFunction) gPySetExitKey, METH_VARARGS, (const char *)"Sets the key used to exit the game engine"},
 	{"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, (const char *)"Gets the estimated average frame rate"},
 	{"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (const char *)"Gets a list of blend files in the same directory as the current blend file"},
 	{"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"},




More information about the Bf-blender-cvs mailing list