Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPorteries Tristan <republicthunderbolt9@gmail.com>2016-04-10 18:36:10 +0300
committerPorteries Tristan <republicthunderbolt9@gmail.com>2016-04-11 00:57:43 +0300
commit2050ecc307de9159b50c7f9798e47a366f505f2e (patch)
treeedda985383ebe538858a255b5b0d68b6c54d6ead /source/gameengine
parent3a80d5e1d0e4952caa76f1d655429375c0da1884 (diff)
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
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Converter/BL_ActionActuator.cpp2
-rw-r--r--source/gameengine/Converter/BL_ArmatureActuator.cpp2
-rw-r--r--source/gameengine/Converter/BL_ArmatureConstraint.cpp6
-rw-r--r--source/gameengine/Converter/BL_ShapeActionActuator.cpp2
-rw-r--r--source/gameengine/Converter/KX_ConvertActuators.cpp1
-rw-r--r--source/gameengine/Converter/KX_ConvertControllers.cpp1
-rw-r--r--source/gameengine/Converter/KX_ConvertSensors.cpp1
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.cpp13
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.h7
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.cpp7
-rw-r--r--source/gameengine/Ketsji/KX_Camera.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_CameraActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp41
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.h2
-rw-r--r--source/gameengine/Ketsji/KX_MeshProxy.cpp6
-rw-r--r--source/gameengine/Ketsji/KX_MeshProxy.h3
-rw-r--r--source/gameengine/Ketsji/KX_ObjectActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_ParentActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_PyConstraintBinding.cpp3
-rw-r--r--source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_Scene.cpp5
-rw-r--r--source/gameengine/Ketsji/KX_SteeringActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_TrackToActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_VehicleWrapper.cpp3
25 files changed, 71 insertions, 52 deletions
diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp
index d9865c1f4fb..d28cdb84275 100644
--- a/source/gameengine/Converter/BL_ActionActuator.cpp
+++ b/source/gameengine/Converter/BL_ActionActuator.cpp
@@ -584,7 +584,7 @@ int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF
if (val != "")
{
- action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
+ action= (bAction*)self->GetLogicManager()->GetActionByName(val);
if (!action)
{
PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, action not found!");
diff --git a/source/gameengine/Converter/BL_ArmatureActuator.cpp b/source/gameengine/Converter/BL_ArmatureActuator.cpp
index e38cb6eadaf..67cc7d2c291 100644
--- a/source/gameengine/Converter/BL_ArmatureActuator.cpp
+++ b/source/gameengine/Converter/BL_ArmatureActuator.cpp
@@ -243,7 +243,7 @@ int BL_ArmatureActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBU
KX_GameObject* &target = (!strcmp(attrdef->m_name, "target")) ? actuator->m_gametarget : actuator->m_gamesubtarget;
KX_GameObject *gameobj;
- if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: BL_ArmatureActuator"))
+ if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: BL_ArmatureActuator"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
if (target != NULL)
diff --git a/source/gameengine/Converter/BL_ArmatureConstraint.cpp b/source/gameengine/Converter/BL_ArmatureConstraint.cpp
index 88d82e21d61..d0c7e061fb7 100644
--- a/source/gameengine/Converter/BL_ArmatureConstraint.cpp
+++ b/source/gameengine/Converter/BL_ArmatureConstraint.cpp
@@ -36,6 +36,7 @@
#include "BL_ArmatureObject.h"
#include "BLI_math.h"
#include "BLI_string.h"
+#include "KX_PythonInit.h"
#ifdef WITH_PYTHON
@@ -360,6 +361,7 @@ int BL_ArmatureConstraint::py_attr_setattr(void *self_v, const struct KX_PYATTRI
int ival;
double dval;
// char* sval;
+ SCA_LogicManager *logicmgr = KX_GetActiveScene()->GetLogicManager();
KX_GameObject *oval;
if (!constraint) {
@@ -387,13 +389,13 @@ int BL_ArmatureConstraint::py_attr_setattr(void *self_v, const struct KX_PYATTRI
return PY_SET_ATTR_SUCCESS;
case BCA_TARGET:
- if (!ConvertPythonToGameObject(value, &oval, true, "constraint.target = value: BL_ArmatureConstraint"))
+ if (!ConvertPythonToGameObject(logicmgr, value, &oval, true, "constraint.target = value: BL_ArmatureConstraint"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
self->SetTarget(oval);
return PY_SET_ATTR_SUCCESS;
case BCA_SUBTARGET:
- if (!ConvertPythonToGameObject(value, &oval, true, "constraint.subtarget = value: BL_ArmatureConstraint"))
+ if (!ConvertPythonToGameObject(logicmgr, value, &oval, true, "constraint.subtarget = value: BL_ArmatureConstraint"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
self->SetSubtarget(oval);
return PY_SET_ATTR_SUCCESS;
diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp
index e8f451213f5..f21db419ebc 100644
--- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp
+++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp
@@ -547,7 +547,7 @@ int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE
if (val != "")
{
- action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
+ action= (bAction*)self->GetLogicManager()->GetActionByName(val);
if (action==NULL)
{
PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, action not found!");
diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp
index 021111b4fe5..455fef0aceb 100644
--- a/source/gameengine/Converter/KX_ConvertActuators.cpp
+++ b/source/gameengine/Converter/KX_ConvertActuators.cpp
@@ -1127,6 +1127,7 @@ void BL_ConvertActuators(const char* maggiename,
uniquename += uniqueval->GetText();
uniqueval->Release();
baseact->SetName(bact->name);
+ baseact->SetLogicManager(logicmgr);
//gameobj->SetProperty(uniquename,baseact);
gameobj->AddActuator(baseact);
diff --git a/source/gameengine/Converter/KX_ConvertControllers.cpp b/source/gameengine/Converter/KX_ConvertControllers.cpp
index e3697087ea9..f55d81adb80 100644
--- a/source/gameengine/Converter/KX_ConvertControllers.cpp
+++ b/source/gameengine/Converter/KX_ConvertControllers.cpp
@@ -214,6 +214,7 @@ void BL_ConvertControllers(
//at some point it should either be implemented globally (and saved as a separate var) or removed.
//gamecontroller->SetName(uniquename);
gamecontroller->SetName(bcontr->name);
+ gamecontroller->SetLogicManager(logicmgr);
gameobj->AddController(gamecontroller);
converter->RegisterGameController(gamecontroller, bcontr);
diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp
index 79fd9cb9254..5e897bb4a62 100644
--- a/source/gameengine/Converter/KX_ConvertSensors.cpp
+++ b/source/gameengine/Converter/KX_ConvertSensors.cpp
@@ -608,6 +608,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
gamesensor->SetLevel(level);
gamesensor->SetTap(tap);
gamesensor->SetName(sens->name);
+ gamesensor->SetLogicManager(logicmgr);
gameobj->AddSensor(gamesensor);
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;
}
diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp
index 361cd65d50a..89aea80bb67 100644
--- a/source/gameengine/Ketsji/KX_Camera.cpp
+++ b/source/gameengine/Ketsji/KX_Camera.cpp
@@ -1035,7 +1035,7 @@ KX_PYMETHODDEF_DOC_O(KX_Camera, getScreenPosition,
{
PyErr_Clear();
- if (ConvertPythonToGameObject(value, &obj, true, ""))
+ if (ConvertPythonToGameObject(GetScene()->GetLogicManager(), value, &obj, true, ""))
{
PyErr_Clear();
vect = MT_Vector3(obj->NodeGetWorldPosition());
diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp
index f065e3f0001..e488bf3c30a 100644
--- a/source/gameengine/Ketsji/KX_CameraActuator.cpp
+++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp
@@ -411,7 +411,7 @@ int KX_CameraActuator::pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF
KX_CameraActuator* self = static_cast<KX_CameraActuator*>(self_v);
KX_GameObject *gameobj;
- if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_CameraActuator"))
+ if (!ConvertPythonToGameObject(self->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_CameraActuator"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
if (self->m_ob)
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index 877e95885a2..69c1af35bd9 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -1597,14 +1597,6 @@ void KX_GameObject::RunCollisionCallbacks(KX_GameObject *collider, const MT_Vect
if (!m_collisionCallbacks || PyList_GET_SIZE(m_collisionCallbacks) == 0)
return;
- /** Current logic controller is set by each python logic bricks before run,
- * but if no python logic brick ran the logic manager can be wrong
- * (if the user use muti scenes) and it will cause problems with function
- * ConvertPythonToGameObject which use the current logic manager for object's name.
- * Note: the scene is already set in logic frame loop.
- */
- SCA_ILogicBrick::m_sCurrentLogicManager = GetScene()->GetLogicManager();
-
PyObject *args[] = {collider->GetProxy(), PyObjectFrom(point), PyObjectFrom(normal)};
RunPythonCallBackList(m_collisionCallbacks, args, 1, ARRAY_SIZE(args));
@@ -2043,7 +2035,8 @@ PyAttributeDef KX_GameObject::Attributes[] = {
PyObject *KX_GameObject::PyReplaceMesh(PyObject *args)
{
KX_Scene *scene = KX_GetActiveScene();
-
+ SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
+
PyObject *value;
int use_gfx= 1, use_phys= 0;
RAS_MeshObject *new_mesh;
@@ -2051,7 +2044,7 @@ PyObject *KX_GameObject::PyReplaceMesh(PyObject *args)
if (!PyArg_ParseTuple(args,"O|ii:replaceMesh", &value, &use_gfx, &use_phys))
return NULL;
- if (!ConvertPythonToMesh(value, &new_mesh, false, "gameOb.replaceMesh(value): KX_GameObject"))
+ if (!ConvertPythonToMesh(logicmgr, value, &new_mesh, false, "gameOb.replaceMesh(value): KX_GameObject"))
return NULL;
scene->ReplaceMesh(this, new_mesh, (bool)use_gfx, (bool)use_phys);
@@ -2072,13 +2065,14 @@ PyObject *KX_GameObject::PyReinstancePhysicsMesh(PyObject *args)
{
KX_GameObject *gameobj= NULL;
RAS_MeshObject *mesh= NULL;
+ SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
PyObject *gameobj_py= NULL;
PyObject *mesh_py= NULL;
if ( !PyArg_ParseTuple(args,"|OO:reinstancePhysicsMesh",&gameobj_py, &mesh_py) ||
- (gameobj_py && !ConvertPythonToGameObject(gameobj_py, &gameobj, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject")) ||
- (mesh_py && !ConvertPythonToMesh(mesh_py, &mesh, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject"))
+ (gameobj_py && !ConvertPythonToGameObject(logicmgr, gameobj_py, &gameobj, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject")) ||
+ (mesh_py && !ConvertPythonToMesh(logicmgr, mesh_py, &mesh, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject"))
) {
return NULL;
}
@@ -3423,6 +3417,7 @@ PyObject *KX_GameObject::PyDisableRigidBody()
PyObject *KX_GameObject::PySetParent(PyObject *args)
{
KX_Scene *scene = KX_GetActiveScene();
+ SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
PyObject *pyobj;
KX_GameObject *obj;
int addToCompound=1, ghost=1;
@@ -3430,7 +3425,7 @@ PyObject *KX_GameObject::PySetParent(PyObject *args)
if (!PyArg_ParseTuple(args,"O|ii:setParent", &pyobj, &addToCompound, &ghost)) {
return NULL; // Python sets a simple error
}
- if (!ConvertPythonToGameObject(pyobj, &obj, true, "gameOb.setParent(obj): KX_GameObject"))
+ if (!ConvertPythonToGameObject(logicmgr, pyobj, &obj, true, "gameOb.setParent(obj): KX_GameObject"))
return NULL;
if (obj)
this->SetParent(scene, obj, addToCompound, ghost);
@@ -3586,9 +3581,10 @@ KX_PYMETHODDEF_DOC_O(KX_GameObject, getDistanceTo,
return PyFloat_FromDouble(NodeGetWorldPosition().distance(b));
}
PyErr_Clear();
-
+
+ SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
KX_GameObject *other;
- if (ConvertPythonToGameObject(value, &other, false, "gameOb.getDistanceTo(value): KX_GameObject"))
+ if (ConvertPythonToGameObject(logicmgr, value, &other, false, "gameOb.getDistanceTo(value): KX_GameObject"))
{
return PyFloat_FromDouble(NodeGetWorldPosition().distance(other->NodeGetWorldPosition()));
}
@@ -3604,6 +3600,7 @@ KX_PYMETHODDEF_DOC_O(KX_GameObject, getVectTo,
MT_Vector3 toDir, locToDir;
MT_Scalar distance;
+ SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
PyObject *returnValue;
if (!PyVecTo(value, toPoint))
@@ -3611,7 +3608,7 @@ KX_PYMETHODDEF_DOC_O(KX_GameObject, getVectTo,
PyErr_Clear();
KX_GameObject *other;
- if (ConvertPythonToGameObject(value, &other, false, "")) /* error will be overwritten */
+ if (ConvertPythonToGameObject(logicmgr, value, &other, false, "")) /* error will be overwritten */
{
toPoint = other->NodeGetWorldPosition();
} else
@@ -3713,6 +3710,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
PyObject *pyarg;
float dist = 0.0f;
char *propName = NULL;
+ SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
if (!PyArg_ParseTuple(args,"O|fs:rayCastTo", &pyarg, &dist, &propName)) {
return NULL; // python sets simple error
@@ -3723,7 +3721,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
KX_GameObject *other;
PyErr_Clear();
- if (ConvertPythonToGameObject(pyarg, &other, false, "")) /* error will be overwritten */
+ if (ConvertPythonToGameObject(logicmgr, pyarg, &other, false, "")) /* error will be overwritten */
{
toPoint = other->NodeGetWorldPosition();
} else
@@ -3829,6 +3827,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
KX_GameObject *other;
int face=0, xray=0, poly=0;
int mask = (1 << OB_MAX_COL_MASKS) - 1;
+ SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
if (!PyArg_ParseTuple(args,"O|Ofsiiii:rayCast", &pyto, &pyfrom, &dist, &propName, &face, &xray, &poly, &mask)) {
return NULL; // Python sets a simple error
@@ -3838,7 +3837,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
{
PyErr_Clear();
- if (ConvertPythonToGameObject(pyto, &other, false, "")) /* error will be overwritten */
+ if (ConvertPythonToGameObject(logicmgr, pyto, &other, false, "")) /* error will be overwritten */
{
toPoint = other->NodeGetWorldPosition();
} else
@@ -3855,7 +3854,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
{
PyErr_Clear();
- if (ConvertPythonToGameObject(pyfrom, &other, false, "")) /* error will be overwritten */
+ if (ConvertPythonToGameObject(logicmgr, pyfrom, &other, false, "")) /* error will be overwritten */
{
fromPoint = other->NodeGetWorldPosition();
} else
@@ -4144,7 +4143,7 @@ PyObject *KX_GameObject::Pyget(PyObject *args)
return def;
}
-bool ConvertPythonToGameObject(PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix)
+bool ConvertPythonToGameObject(SCA_LogicManager *manager, PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix)
{
if (value==NULL) {
PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix);
@@ -4164,7 +4163,7 @@ bool ConvertPythonToGameObject(PyObject *value, KX_GameObject **object, bool py_
}
if (PyUnicode_Check(value)) {
- *object = (KX_GameObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String( _PyUnicode_AsString(value) ));
+ *object = (KX_GameObject*)manager->GetGameObjectByName(STR_String( _PyUnicode_AsString(value) ));
if (*object) {
return true;
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index a25f999026c..9c582d3e27a 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -67,7 +67,7 @@ struct bAction;
#ifdef WITH_PYTHON
/* utility conversion function */
-bool ConvertPythonToGameObject(PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix);
+bool ConvertPythonToGameObject(SCA_LogicManager *logicmgr, PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix);
#endif
#ifdef USE_MATHUTILS
diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp
index c98766c9c81..8da3542b4d6 100644
--- a/source/gameengine/Ketsji/KX_MeshProxy.cpp
+++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp
@@ -43,6 +43,8 @@
#include "KX_PyMath.h"
+#include "SCA_LogicManager.h"
+
#include "EXP_PyObjectPlus.h"
PyTypeObject KX_MeshProxy::Type = {
@@ -405,7 +407,7 @@ PyObject *KX_MeshProxy::pyattr_get_numPolygons(void *self_v, const KX_PYATTRIBUT
}
/* a close copy of ConvertPythonToGameObject but for meshes */
-bool ConvertPythonToMesh(PyObject *value, RAS_MeshObject **object, bool py_none_ok, const char *error_prefix)
+bool ConvertPythonToMesh(SCA_LogicManager *logicmgr, PyObject *value, RAS_MeshObject **object, bool py_none_ok, const char *error_prefix)
{
if (value==NULL) {
PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix);
@@ -425,7 +427,7 @@ bool ConvertPythonToMesh(PyObject *value, RAS_MeshObject **object, bool py_none_
}
if (PyUnicode_Check(value)) {
- *object = (RAS_MeshObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String( _PyUnicode_AsString(value) ));
+ *object = (RAS_MeshObject*)logicmgr->GetMeshByName(STR_String( _PyUnicode_AsString(value) ));
if (*object) {
return true;
diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h
index 4a4358bff3a..dbd7987f785 100644
--- a/source/gameengine/Ketsji/KX_MeshProxy.h
+++ b/source/gameengine/Ketsji/KX_MeshProxy.h
@@ -36,8 +36,9 @@
#include "SCA_IObject.h"
+class SCA_LogicManager;
/* utility conversion function */
-bool ConvertPythonToMesh(PyObject *value, class RAS_MeshObject **object, bool py_none_ok, const char *error_prefix);
+bool ConvertPythonToMesh(SCA_LogicManager *logicmgr, PyObject *value, class RAS_MeshObject **object, bool py_none_ok, const char *error_prefix);
class KX_MeshProxy : public CValue
{
diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp
index 45436693281..8c1dee7940f 100644
--- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp
+++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp
@@ -687,7 +687,7 @@ int KX_ObjectActuator::pyattr_set_reference(void *self, const struct KX_PYATTRIB
KX_ObjectActuator* actuator = static_cast<KX_ObjectActuator*>(self);
KX_GameObject *refOb;
- if (!ConvertPythonToGameObject(value, &refOb, true, "actu.reference = value: KX_ObjectActuator"))
+ if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &refOb, true, "actu.reference = value: KX_ObjectActuator"))
return PY_SET_ATTR_FAIL;
if (actuator->m_reference)
diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp
index 6ffa2593792..0b133400920 100644
--- a/source/gameengine/Ketsji/KX_ParentActuator.cpp
+++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp
@@ -186,7 +186,7 @@ int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE
KX_ParentActuator* actuator = static_cast<KX_ParentActuator*>(self);
KX_GameObject *gameobj;
- if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_ParentActuator"))
+ if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_ParentActuator"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
if (actuator->m_ob != NULL)
diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
index a0084662490..81fe3be1fcf 100644
--- a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
+++ b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
@@ -40,6 +40,7 @@
#include "MT_Matrix3x3.h"
#include "KX_GameObject.h" // ConvertPythonToGameObject()
+#include "KX_PythonInit.h"
#include "EXP_PyObjectPlus.h"
@@ -472,7 +473,7 @@ static PyObject* gPyGetCharacter(PyObject* self,
if (!PyArg_ParseTuple(args,"O", &pyob))
return NULL;
- if (!ConvertPythonToGameObject(pyob, &ob, false, "bge.constraints.getCharacter(value)"))
+ if (!ConvertPythonToGameObject(KX_GetActiveScene()->GetLogicManager(), pyob, &ob, false, "bge.constraints.getCharacter(value)"))
return NULL;
if (PHY_GetActiveEnvironment())
diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
index fdcfd22270b..bb38d8269b7 100644
--- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
@@ -216,7 +216,7 @@ int KX_SCA_AddObjectActuator::pyattr_set_object(void *self, const struct KX_PYAT
KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self);
KX_GameObject *gameobj;
- if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_SCA_AddObjectActuator"))
+ if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SCA_AddObjectActuator"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
if (actuator->m_OriginalObject != NULL)
diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
index 6b6b090c1c4..1bf76de0b40 100644
--- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
@@ -101,7 +101,7 @@ int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYAT
KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self);
RAS_MeshObject* new_mesh;
- if (!ConvertPythonToMesh(value, &new_mesh, true, "actuator.mesh = value: KX_SCA_ReplaceMeshActuator"))
+ if (!ConvertPythonToMesh(actuator->GetLogicManager(), value, &new_mesh, true, "actuator.mesh = value: KX_SCA_ReplaceMeshActuator"))
return PY_SET_ATTR_FAIL;
actuator->m_mesh = new_mesh;
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
index 9eb9066d56f..a5a418b5e78 100644
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ b/source/gameengine/Ketsji/KX_Scene.cpp
@@ -1925,6 +1925,7 @@ static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *from, KX_Sce
brick->Replace_IScene(to);
brick->Replace_NetworkScene(to->GetNetworkScene());
+ brick->SetLogicManager(to->GetLogicManager());
// If we end up replacing a KX_TouchEventManager, we need to make sure
// physics controllers are properly in place. In other words, do this
@@ -2541,8 +2542,8 @@ KX_PYMETHODDEF_DOC(KX_Scene, addObject,
if (!PyArg_ParseTuple(args, "O|Oi:addObject", &pyob, &pyreference, &time))
return NULL;
- if (!ConvertPythonToGameObject(pyob, &ob, false, "scene.addObject(object, reference, time): KX_Scene (first argument)") ||
- !ConvertPythonToGameObject(pyreference, &reference, true, "scene.addObject(object, reference, time): KX_Scene (second argument)"))
+ if (!ConvertPythonToGameObject(m_logicmgr, pyob, &ob, false, "scene.addObject(object, reference, time): KX_Scene (first argument)") ||
+ !ConvertPythonToGameObject(m_logicmgr, pyreference, &reference, true, "scene.addObject(object, reference, time): KX_Scene (second argument)"))
return NULL;
if (!m_inactivelist->SearchValue(ob)) {
diff --git a/source/gameengine/Ketsji/KX_SteeringActuator.cpp b/source/gameengine/Ketsji/KX_SteeringActuator.cpp
index af2a2b30b84..d3a7b665e61 100644
--- a/source/gameengine/Ketsji/KX_SteeringActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SteeringActuator.cpp
@@ -579,7 +579,7 @@ int KX_SteeringActuator::pyattr_set_target(void *self, const struct KX_PYATTRIBU
KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
KX_GameObject *gameobj;
- if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
+ if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
if (actuator->m_target != NULL)
@@ -607,7 +607,7 @@ int KX_SteeringActuator::pyattr_set_navmesh(void *self, const struct KX_PYATTRIB
KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
KX_GameObject *gameobj;
- if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
+ if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
if (dynamic_cast<KX_NavMeshObject *>(gameobj) == NULL) {
diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp
index 74902ab20ee..beccdfaad93 100644
--- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp
+++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp
@@ -411,7 +411,7 @@ int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUT
KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self);
KX_GameObject *gameobj;
- if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_TrackToActuator"))
+ if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_TrackToActuator"))
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
if (actuator->m_object != NULL)
diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
index ee791a44782..c1af6de127e 100644
--- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
+++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
@@ -30,6 +30,7 @@
#include "KX_PyMath.h"
#include "KX_GameObject.h"
#include "KX_MotionState.h"
+#include "KX_PythonInit.h"
KX_VehicleWrapper::KX_VehicleWrapper(
PHY_IVehicle* vehicle,
@@ -82,7 +83,7 @@ PyObject *KX_VehicleWrapper::PyAddWheel(PyObject *args)
if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering))
{
KX_GameObject *gameOb;
- if (!ConvertPythonToGameObject(wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)"))
+ if (!ConvertPythonToGameObject(KX_GetActiveScene()->GetLogicManager(), wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)"))
return NULL;
if (gameOb->GetSGNode())