[Bf-blender-cvs] [8444f7b] master: BGE: Fix T42679: Python physics environment not setted for python control script.

Porteries Tristan noreply at git.blender.org
Sun Aug 23 14:34:25 CEST 2015


Commit: 8444f7ba2b2bbcc465b4890e2fe4d473181c0ef1
Author: Porteries Tristan
Date:   Sun Aug 23 14:30:44 2015 +0200
Branches: master
https://developer.blender.org/rB8444f7ba2b2bbcc465b4890e2fe4d473181c0ef1

BGE: Fix T42679: Python physics environment not setted for python control script.

===================================================================

M	source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
M	source/gameengine/GamePlayer/ghost/GPG_Application.cpp
M	source/gameengine/GamePlayer/ghost/GPG_Application.h
M	source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

===================================================================

diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
index 4e07af9..41011cd 100644
--- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
+++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
@@ -544,6 +544,10 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
 				if (python_main) {
 					char *python_code = KX_GetPythonCode(blenderdata, python_main);
 					if (python_code) {
+						// Set python environement variable.
+						KX_SetActiveScene(startscene);
+						PHY_SetActiveEnvironment(startscene->GetPhysicsEnvironment());
+
 						ketsjinextframestate.ketsjiengine = ketsjiengine;
 						ketsjinextframestate.C = C;
 						ketsjinextframestate.win = win;
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
index c3eb07d..2b357f4 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
@@ -112,6 +112,7 @@ GPG_Application::GPG_Application(GHOST_ISystem* system)
 	: m_startSceneName(""), 
 	  m_startScene(0),
 	  m_maggie(0),
+	  m_kxStartScene(NULL),
 	  m_exitRequested(0),
 	  m_system(system), 
 	  m_mainWindow(0), 
@@ -714,7 +715,7 @@ bool GPG_Application::startEngine(void)
 	m_sceneconverter = new KX_BlenderSceneConverter(m_maggie, m_ketsjiengine);
 	if (m_sceneconverter)
 	{
-		STR_String startscenename = m_startSceneName.Ptr();
+		STR_String m_kxStartScenename = m_startSceneName.Ptr();
 		m_ketsjiengine->SetSceneConverter(m_sceneconverter);
 
 		//	if (always_use_expand_framing)
@@ -726,17 +727,17 @@ bool GPG_Application::startEngine(void)
 		if (m_startScene->gm.flag & GAME_NO_MATERIAL_CACHING)
 			m_sceneconverter->SetCacheMaterials(false);
 
-		KX_Scene* startscene = new KX_Scene(m_keyboard,
+		m_kxStartScene = new KX_Scene(m_keyboard,
 			m_mouse,
 			m_networkdevice,
-			startscenename,
+			m_kxStartScenename,
 			m_startScene,
 			m_canvas);
 		
 #ifdef WITH_PYTHON
 			// some python things
 			PyObject *gameLogic, *gameLogic_keys;
-			setupGamePython(m_ketsjiengine, startscene, m_maggie, NULL, &gameLogic, &gameLogic_keys, m_argc, m_argv);
+			setupGamePython(m_ketsjiengine, m_kxStartScene, m_maggie, NULL, &gameLogic, &gameLogic_keys, m_argc, m_argv);
 #endif // WITH_PYTHON
 
 		//initialize Dome Settings
@@ -755,10 +756,10 @@ bool GPG_Application::startEngine(void)
 		loadGamePythonConfig(m_pyGlobalDictString, m_pyGlobalDictString_Length);
 #endif
 		m_sceneconverter->ConvertScene(
-			startscene,
+			m_kxStartScene,
 			m_rasterizer,
 			m_canvas);
-		m_ketsjiengine->AddScene(startscene);
+		m_ketsjiengine->AddScene(m_kxStartScene);
 		
 		// Create a timer that is used to kick the engine
 		if (!m_frameTimer) {
@@ -771,7 +772,7 @@ bool GPG_Application::startEngine(void)
 		// Set the animation playback rate for ipo's and actions
 		// the framerate below should patch with FPS macro defined in blendef.h
 		// Could be in StartEngine set the framerate, we need the scene to do this
-		Scene *scene= startscene->GetBlenderScene(); // needed for macro
+		Scene *scene= m_kxStartScene->GetBlenderScene(); // needed for macro
 		m_ketsjiengine->SetAnimFrameRate(FPS);
 	}
 	
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h
index 2d21b50..b6f545c 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.h
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h
@@ -40,6 +40,7 @@
 #include "KX_KetsjiEngine.h"
 
 class KX_KetsjiEngine;
+class KX_Scene;
 class KX_ISceneConverter;
 class NG_LoopBackNetworkDeviceInterface;
 class RAS_IRasterizer;
@@ -83,6 +84,12 @@ public:
 	int getExitRequested(void);
 	const STR_String& getExitString(void);
 	GlobalSettings* getGlobalSettings(void);
+
+	inline KX_Scene *GetStartScene() const
+	{
+		return m_kxStartScene;
+	}
+
 	bool StartGameEngine(int stereoMode);
 	void StopGameEngine();
 	void EngineNextFrame();
@@ -118,6 +125,7 @@ protected:
 	STR_String				m_startSceneName;
 	struct Scene*			m_startScene;
 	struct Main*			m_maggie;
+	KX_Scene *m_kxStartScene;
 
 	/* Exit state. */
 	int						m_exitRequested;
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 6ff8451..23d5b89 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -43,6 +43,7 @@
 #include "KX_KetsjiEngine.h"
 #include "KX_PythonInit.h"
 #include "KX_PythonMain.h"
+#include "KX_PyConstraintBinding.h" // for PHY_SetActiveEnvironment
 
 /**********************************
 * Begin Blender include block
@@ -1080,6 +1081,11 @@ int main(int argc, char** argv)
 							char *python_code = KX_GetPythonCode(maggie, python_main);
 							if (python_code) {
 #ifdef WITH_PYTHON
+								// Set python environement variable.
+								KX_Scene *startscene = app.GetStartScene();
+								KX_SetActiveScene(startscene);
+								PHY_SetActiveEnvironment(startscene->GetPhysicsEnvironment());
+
 								gpg_nextframestate.system = system;
 								gpg_nextframestate.app = &app;
 								gpg_nextframestate.gs = &gs;




More information about the Bf-blender-cvs mailing list