From 2050ecc307de9159b50c7f9798e47a366f505f2e Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Sun, 10 Apr 2016 17:36:10 +0200 Subject: BGE: Fix T48071: Global logic manager Previously the logic manager was used as a global variable for SCA_ILogicBrick::m_sCurrentLogicManager, this request to always update it before run any python script and allow call function like ConvertPythonTo[GameObject/Mesh]. The bug showed in T48071 is that as exepted the global m_sCurrentLogicManager is not updated with the proper scene logic manager. Instead of trying to fix it by updating the logic manager everywhere and wait next bug report to add a similar line. The following patch propose a different way: - Every logic brick now contain its logic manager to SCA_ILogicBrick::m_logicManager, this value is set and get by SCA_ILogicBrick::[Set/Get]LogicManager, It's initialized from blender conversion and scene merging. - Function ConvertPythonTo[GameObject/mesh] now take as first argument the logic manager to find name coresponding object or mesh. Only ConvertPythonToCamera doesn't do that because it uses the KX_Scene::FindCamera function. Reviewers: moguri Differential Revision: https://developer.blender.org/D1913 --- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 13 +++++++++++-- source/gameengine/GameLogic/SCA_ILogicBrick.h | 7 ++++--- source/gameengine/GameLogic/SCA_PythonController.cpp | 7 +++---- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'source/gameengine/GameLogic') diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 72a0b392447..d0a6e4540c9 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -35,12 +35,11 @@ #include "SCA_ILogicBrick.h" #include "EXP_PyObjectPlus.h" -SCA_LogicManager* SCA_ILogicBrick::m_sCurrentLogicManager = NULL; - SCA_ILogicBrick::SCA_ILogicBrick(SCA_IObject* gameobj) : CValue(), m_gameobj(gameobj), + m_logicManager(NULL), m_Execute_Priority(0), m_Execute_Ueber_Priority(0), m_bActive(false), @@ -143,6 +142,16 @@ bool SCA_ILogicBrick::LessComparedTo(SCA_ILogicBrick* other) (this->m_Execute_Priority < other->m_Execute_Priority)); } +void SCA_ILogicBrick::SetLogicManager(SCA_LogicManager *logicmgr) +{ + m_logicManager = logicmgr; +} + +SCA_LogicManager *SCA_ILogicBrick::GetLogicManager() +{ + return m_logicManager; +} + void SCA_ILogicBrick::RegisterEvent(CValue* eventval) { if (m_eventval) diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index a3725789227..f9ef18cc348 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -40,12 +40,14 @@ class NG_NetworkScene; class SCA_IScene; +class SCA_LogicManager; class SCA_ILogicBrick : public CValue { Py_Header protected: SCA_IObject* m_gameobj; + SCA_LogicManager *m_logicManager; int m_Execute_Priority; int m_Execute_Ueber_Priority; @@ -127,9 +129,8 @@ public: virtual bool LessComparedTo(SCA_ILogicBrick* other); - /* runtime variable, set when Triggering the python controller */ - static class SCA_LogicManager* m_sCurrentLogicManager; - + virtual void SetLogicManager(SCA_LogicManager *logicmgr); + SCA_LogicManager *GetLogicManager(); /* for moving logic bricks between scenes */ virtual void Replace_IScene(SCA_IScene *val) {} diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index fa30e3a5caf..25936b34fde 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -386,8 +386,7 @@ bool SCA_PythonController::Import() void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) { m_sCurrentController = this; - m_sCurrentLogicManager = logicmgr; - + PyObject *excdict= NULL; PyObject *resultobj= NULL; @@ -478,7 +477,7 @@ PyObject *SCA_PythonController::PyActivate(PyObject *value) if (actu==NULL) return NULL; - m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, true); + m_logicManager->AddActiveActuator((SCA_IActuator*)actu, true); Py_RETURN_NONE; } @@ -493,7 +492,7 @@ PyObject *SCA_PythonController::PyDeActivate(PyObject *value) if (actu==NULL) return NULL; - m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, false); + m_logicManager->AddActiveActuator((SCA_IActuator*)actu, false); Py_RETURN_NONE; } -- cgit v1.2.3