BGE bug fix (good for 2.47): automatic detection that target object of AddObject...
authorBenoit Bolsee <benoit.bolsee@online.be>
Sat, 12 Jul 2008 12:10:27 +0000 (12:10 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Sat, 12 Jul 2008 12:10:27 +0000 (12:10 +0000)
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h

index 9aed5b1d51024429c5ad93ffd0c7b7a38df48722..1cc1b2e27a39af20c7f7eb80ad8c15e775716185 100644 (file)
@@ -539,7 +539,7 @@ void BL_ConvertActuators(char* maggiename,
                                                
                                                // does the 'original' for replication exists, and 
                                                // is it in a non-active layer ?
-                                               CValue* originalval = NULL;
+                                               SCA_IObject* originalval = NULL;
                                                if (editobact->ob && !(editobact->ob->lay & activeLayerBitInfo))
                                                        originalval = converter->FindGameObject(editobact->ob);
                                                
index 76ce086ab97451917d324fd37e48b16bf886da5d..e5ee4cbddf10ae5caf2293c2159c3a3850f6075b 100644 (file)
@@ -48,7 +48,7 @@
 /* ------------------------------------------------------------------------- */
 
 KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj,
-                                                                                                  CValue* original,
+                                                                                                  SCA_IObject *original,
                                                                                                   int time,
                                                                                                   SCA_IScene* scene,
                                                                                                   const MT_Vector3& linvel,
@@ -61,6 +61,9 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj,
        m_linear_velocity(linvel),
        m_localFlag(local)
 {
+       if (m_OriginalObject)
+               m_OriginalObject->RegisterActuator(this);
+
        m_lastCreatedObject = NULL;
        m_timeProp = time;
 } 
@@ -69,6 +72,8 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj,
 
 KX_SCA_AddObjectActuator::~KX_SCA_AddObjectActuator()
 { 
+       if (m_OriginalObject)
+               m_OriginalObject->UnregisterActuator(this);
        if (m_lastCreatedObject)
                m_lastCreatedObject->Release();
 } 
@@ -108,12 +113,29 @@ CValue* KX_SCA_AddObjectActuator::GetReplica()
 
        // this will copy properties and so on...
        replica->ProcessReplica();
-       replica->m_lastCreatedObject=NULL;
        CValue::AddDataToReplica(replica);
 
        return replica;
 }
 
+void KX_SCA_AddObjectActuator::ProcessReplica()
+{
+       if (m_OriginalObject)
+               m_OriginalObject->RegisterActuator(this);
+       m_lastCreatedObject=NULL;
+       SCA_IActuator::ProcessReplica();
+}
+
+bool KX_SCA_AddObjectActuator::UnlinkObject(SCA_IObject* clientobj)
+{
+       if (clientobj == m_OriginalObject)
+       {
+               // this object is being deleted, we cannot continue to track it.
+               m_OriginalObject = NULL;
+               return true;
+       }
+       return false;
+}
 
 
 /* ------------------------------------------------------------------------- */
@@ -181,7 +203,11 @@ PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* self,
        PyObject* gameobj;
        if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj))
        {
-               m_OriginalObject = (CValue*)gameobj;
+               if (m_OriginalObject != NULL)
+                       m_OriginalObject->UnregisterActuator(this);
+               m_OriginalObject = (SCA_IObject*)gameobj;
+               if (m_OriginalObject)
+                       m_OriginalObject->RegisterActuator(this);
                Py_Return;
        }
        PyErr_Clear();
@@ -189,8 +215,11 @@ PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* self,
        char* objectname;
        if (PyArg_ParseTuple(args, "s", &objectname))
        {
-               m_OriginalObject= (CValue*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));;
-               
+               if (m_OriginalObject != NULL)
+                       m_OriginalObject->UnregisterActuator(this);
+               m_OriginalObject = (SCA_IObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));;
+               if (m_OriginalObject)
+                       m_OriginalObject->RegisterActuator(this);
                Py_Return;
        }
        
index 2126a64630313cec6739d13fe078bf64b456169e..42123b94a6854e4012cf3dea4d34ed5074ef8122 100644 (file)
@@ -53,7 +53,7 @@ class KX_SCA_AddObjectActuator : public SCA_IActuator
        int     m_timeProp;
 
        /// Original object reference (object to replicate)     
-       CValue* m_OriginalObject;
+       SCA_IObject*    m_OriginalObject;
 
        /// Object will be added to the following scene
        SCA_IScene*     m_scene;
@@ -75,7 +75,7 @@ public:
 
        KX_SCA_AddObjectActuator(
                SCA_IObject *gameobj,
-               CValue* original,
+               SCA_IObject *original,
                int time,
                SCA_IScene* scene,
                const MT_Vector3& linvel,
@@ -89,6 +89,12 @@ public:
        GetReplica(
        ) ;
 
+       virtual void 
+       ProcessReplica();
+
+       virtual bool 
+       UnlinkObject(SCA_IObject* clientobj);
+
        virtual bool 
        Update();