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

This commit is contained in:
Porteries Tristan 2015-08-23 14:30:44 +02:00
parent 2672ee77a0
commit 8444f7ba2b
Notes: blender-bot 2023-02-14 11:28:43 +01:00
Referenced by issue #42679, PHY_GetActiveEnvironment() fails while python controls BGE
4 changed files with 26 additions and 7 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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;