[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15638] trunk/blender/source/gameengine: BGE patch: Relink actuators with target within group when duplicating group; generalize protection against object deletion for all actuators that point to objects .
Benoit Bolsee
benoit.bolsee at online.be
Sat Jul 19 09:45:22 CEST 2008
Revision: 15638
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15638
Author: ben2610
Date: 2008-07-19 09:45:19 +0200 (Sat, 19 Jul 2008)
Log Message:
-----------
BGE patch: Relink actuators with target within group when duplicating group; generalize protection against object deletion for all actuators that point to objects.
Certain actuators hold a pointer to an objects: Property,
SceneCamera, AddObject, Camera, Parent, TractTo. When a
group is duplicated, the actuators that point to objects
within the group will be relinked to point to the
replicated objects and not to the original objects.
This helps to setup self-contained group with a camera
following a character for example.
This feature also works when adding a single object
(and all its children) with the AddObject actuator.
The second part of the patch extends the protection
against object deletion to all the actuators of the above
list (previously, only the TrackTo, AddObject and
Property actuators were protected). In case the target
object of these actuators is deleted, the BGE won't
crash.
Modified Paths:
--------------
trunk/blender/source/gameengine/Converter/BL_DeformableGameObject.h
trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.h
trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.h
trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp
trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.h
trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
trunk/blender/source/gameengine/Ketsji/KX_ParentActuator.cpp
trunk/blender/source/gameengine/Ketsji/KX_ParentActuator.h
trunk/blender/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
trunk/blender/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h
trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
trunk/blender/source/gameengine/Ketsji/KX_SceneActuator.cpp
trunk/blender/source/gameengine/Ketsji/KX_SceneActuator.h
trunk/blender/source/gameengine/Ketsji/KX_TrackToActuator.cpp
trunk/blender/source/gameengine/Ketsji/KX_TrackToActuator.h
Modified: trunk/blender/source/gameengine/Converter/BL_DeformableGameObject.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_DeformableGameObject.h 2008-07-19 05:10:21 UTC (rev 15637)
+++ trunk/blender/source/gameengine/Converter/BL_DeformableGameObject.h 2008-07-19 07:45:19 UTC (rev 15638)
@@ -60,6 +60,7 @@
{
if (m_pDeformer)
m_pDeformer->Relink (map);
+ KX_GameObject::Relink(map);
};
void ProcessReplica(KX_GameObject* replica);
Modified: trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp 2008-07-19 05:10:21 UTC (rev 15637)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp 2008-07-19 07:45:19 UTC (rev 15638)
@@ -503,7 +503,7 @@
case ACT_PROPERTY:
{
bPropertyActuator* propact = (bPropertyActuator*) bact->data;
- CValue* destinationObj = NULL;
+ SCA_IObject* destinationObj = NULL;
/*
here the destinationobject is searched. problem with multiple scenes: other scenes
Modified: trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.cpp 2008-07-19 05:10:21 UTC (rev 15637)
+++ trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.cpp 2008-07-19 07:45:19 UTC (rev 15638)
@@ -82,8 +82,11 @@
m_gameobj = parent;
}
+void SCA_ILogicBrick::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map)
+{
+ // nothing to do
+}
-
CValue* SCA_ILogicBrick::Calc(VALUE_OPERATOR op, CValue *val)
{
CValue* temp = new CBoolValue(false,"");
Modified: trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.h 2008-07-19 05:10:21 UTC (rev 15637)
+++ trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.h 2008-07-19 07:45:19 UTC (rev 15638)
@@ -32,6 +32,8 @@
#include "Value.h"
#include "SCA_IObject.h"
#include "BoolValue.h"
+#include "GEN_Map.h"
+#include "GEN_HashedPtr.h"
class SCA_ILogicBrick : public CValue
{
@@ -59,6 +61,7 @@
SCA_IObject* GetParent();
virtual void ReParent(SCA_IObject* parent);
+ virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map);
// act as a BoolValue (with value IsPositiveTrigger)
virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
Modified: trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.cpp 2008-07-19 05:10:21 UTC (rev 15637)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.cpp 2008-07-19 07:45:19 UTC (rev 15638)
@@ -42,7 +42,7 @@
/* Native functions */
/* ------------------------------------------------------------------------- */
-SCA_PropertyActuator::SCA_PropertyActuator(SCA_IObject* gameobj,CValue* sourceObj,const STR_String& propname,const STR_String& expr,int acttype,PyTypeObject* T )
+SCA_PropertyActuator::SCA_PropertyActuator(SCA_IObject* gameobj,SCA_IObject* sourceObj,const STR_String& propname,const STR_String& expr,int acttype,PyTypeObject* T )
: SCA_IActuator(gameobj,T),
m_type(acttype),
m_propname(propname),
@@ -51,14 +51,14 @@
{
// protect ourselves against someone else deleting the source object
// don't protect against ourselves: it would create a dead lock
- if (m_sourceObj && m_sourceObj != GetParent())
- m_sourceObj->AddRef();
+ if (m_sourceObj)
+ m_sourceObj->RegisterActuator(this);
}
SCA_PropertyActuator::~SCA_PropertyActuator()
{
- if (m_sourceObj && m_sourceObj != GetParent())
- m_sourceObj->Release();
+ if (m_sourceObj)
+ m_sourceObj->UnregisterActuator(this);
}
bool SCA_PropertyActuator::Update()
@@ -185,12 +185,33 @@
// no need to check for self reference like in the constructor:
// the replica will always have a different parent
if (m_sourceObj)
- m_sourceObj->AddRef();
+ m_sourceObj->RegisterActuator(this);
SCA_IActuator::ProcessReplica();
}
+bool SCA_PropertyActuator::UnlinkObject(SCA_IObject* clientobj)
+{
+ if (clientobj == m_sourceObj)
+ {
+ // this object is being deleted, we cannot continue to track it.
+ m_sourceObj = NULL;
+ return true;
+ }
+ return false;
+}
+void SCA_PropertyActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map)
+{
+ void **h_obj = (*obj_map)[m_sourceObj];
+ if (h_obj) {
+ if (m_sourceObj)
+ m_sourceObj->UnregisterActuator(this);
+ m_sourceObj = (SCA_IObject*)(*h_obj);
+ m_sourceObj->RegisterActuator(this);
+ }
+}
+
/* ------------------------------------------------------------------------- */
/* Python functions */
/* ------------------------------------------------------------------------- */
Modified: trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.h 2008-07-19 05:10:21 UTC (rev 15637)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.h 2008-07-19 07:45:19 UTC (rev 15638)
@@ -52,7 +52,7 @@
int m_type;
STR_String m_propname;
STR_String m_exprtxt;
- CValue* m_sourceObj; // for copy property actuator
+ SCA_IObject* m_sourceObj; // for copy property actuator
public:
@@ -60,7 +60,7 @@
SCA_PropertyActuator(
SCA_IObject* gameobj,
- CValue* sourceObj,
+ SCA_IObject* sourceObj,
const STR_String& propname,
const STR_String& expr,
int acttype,
@@ -74,7 +74,9 @@
GetReplica(
);
- void ProcessReplica();
+ virtual void ProcessReplica();
+ virtual bool UnlinkObject(SCA_IObject* clientobj);
+ virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map);
virtual bool
Update();
Modified: trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp 2008-07-19 05:10:21 UTC (rev 15637)
+++ trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp 2008-07-19 07:45:19 UTC (rev 15638)
@@ -49,7 +49,7 @@
KX_CameraActuator::KX_CameraActuator(
SCA_IObject* gameobj,
- CValue *obj,
+ SCA_IObject *obj,
MT_Scalar hght,
MT_Scalar minhght,
MT_Scalar maxhght,
@@ -63,11 +63,14 @@
m_maxHeight (maxhght),
m_x (xytog)
{
+ if (m_ob)
+ m_ob->RegisterActuator(this);
}
KX_CameraActuator::~KX_CameraActuator()
{
- //nothing to do
+ if (m_ob)
+ m_ob->UnregisterActuator(this);
}
CValue*
@@ -81,9 +84,36 @@
return replica;
};
+void KX_CameraActuator::ProcessReplica()
+{
+ if (m_ob)
+ m_ob->RegisterActuator(this);
+ SCA_IActuator::ProcessReplica();
+}
+bool KX_CameraActuator::UnlinkObject(SCA_IObject* clientobj)
+{
+ if (clientobj == m_ob)
+ {
+ // this object is being deleted, we cannot continue to track it.
+ m_ob = NULL;
+ return true;
+ }
+ return false;
+}
+void KX_CameraActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map)
+{
+ void **h_obj = (*obj_map)[m_ob];
+ if (h_obj) {
+ if (m_ob)
+ m_ob->UnregisterActuator(this);
+ m_ob = (SCA_IObject*)(*h_obj);
+ m_ob->RegisterActuator(this);
+ }
+}
+
/* three functions copied from blender arith... don't know if there's an equivalent */
static float Kx_Normalize(float *n)
@@ -181,8 +211,14 @@
bool KX_CameraActuator::Update(double curtime, bool frame)
{
- bool result = true;
+ /* wondering... is it really neccesary/desirable to suppress negative */
+ /* events here? */
+ bool bNegativeEvent = IsNegativeEvent();
+ RemoveAllEvents();
+ if (bNegativeEvent || !m_ob)
+ return false;
+
KX_GameObject *obj = (KX_GameObject*) GetParent();
MT_Point3 from = obj->NodeGetWorldPosition();
MT_Matrix3x3 frommat = obj->NodeGetWorldOrientation();
@@ -195,13 +231,6 @@
float mindistsq, maxdistsq, distsq;
float mat[3][3];
- /* wondering... is it really neccesary/desirable to suppress negative */
- /* events here? */
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent) return false;
-
/* The rules: */
/* CONSTRAINT 1: not implemented */
/* CONSTRAINT 2: can camera see actor? */
@@ -315,7 +344,7 @@
actormat[2][0]= mat[0][2]; actormat[2][1]= mat[1][2]; actormat[2][2]= mat[2][2];
obj->NodeSetLocalOrientation(actormat);
- return result;
+ return true;
}
CValue *KX_CameraActuator::findObject(char *obName)
@@ -404,7 +433,11 @@
PyObject* gameobj;
if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj))
{
- m_ob = (CValue*)gameobj;
+ if (m_ob)
+ m_ob->UnregisterActuator(this);
+ m_ob = (SCA_IObject*)gameobj;
+ if (m_ob)
+ m_ob->RegisterActuator(this);
Py_Return;
}
PyErr_Clear();
@@ -412,10 +445,13 @@
char* objectname;
if (PyArg_ParseTuple(args, "s", &objectname))
{
- CValue *object = (CValue*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));
+ SCA_IObject *object = (SCA_IObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));
if(object)
{
+ if (m_ob != NULL)
+ m_ob->UnregisterActuator(this);
m_ob = object;
+ m_ob->RegisterActuator(this);
Py_Return;
}
}
Modified: trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.h 2008-07-19 05:10:21 UTC (rev 15637)
+++ trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.h 2008-07-19 07:45:19 UTC (rev 15638)
@@ -49,7 +49,7 @@
Py_Header;
private :
/** Object that will be tracked. */
- CValue *m_ob;
+ SCA_IObject *m_ob;
/** height (float), */
//const MT_Scalar m_height;
@@ -87,7 +87,7 @@
SCA_IObject *gameobj,
//const CValue *ob,
- CValue *ob,
+ SCA_IObject *ob,
MT_Scalar hght,
MT_Scalar minhght,
MT_Scalar maxhght,
@@ -103,6 +103,7 @@
/** Methods Inherited from CValue */
CValue* GetReplica();
+ virtual void ProcessReplica();
/** Methods inherited from SCA_IActuator */
@@ -110,7 +111,10 @@
double curtime,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list