Convert and use actuators with no target object set.
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Sun, 19 Sep 2004 01:33:08 +0000 (01:33 +0000)
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Sun, 19 Sep 2004 01:33:08 +0000 (01:33 +0000)
Certain actuators (Add Object/Replace Mesh/Scene/Track To) used to always require a target, or they would not influence the scene.  If the actuator target is always set from Python, this could be annoying.

source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
source/gameengine/Ketsji/KX_SceneActuator.cpp
source/gameengine/Ketsji/KX_TrackToActuator.cpp
source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py
source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py
source/gameengine/PyDoc/KX_SceneActuator.py
source/gameengine/PyDoc/KX_TrackToActuator.py

index 1b65158..ec9a70f 100644 (file)
@@ -405,6 +405,8 @@ void BL_ConvertActuators(char* maggiename,
                                                        tmpsoundact->SetName(bact->name);
                                                        baseact = tmpsoundact;
                                                        soundscene->AddObject(sndobj);
+                                               } else {
+                                                       std::cout << "WARNING: Sound actuator " << bact->name << " failed to load sample." << std::endl;
                                                }
                                        }
                                }
@@ -515,41 +517,26 @@ void BL_ConvertActuators(char* maggiename,
                                                
                                                // does the 'original' for replication exists, and 
                                                // is it in a non-active layer ?
+                                               CValue* originalval = NULL;
                                                if (editobact->ob && !(editobact->ob->lay & activeLayerBitInfo))
-                                               {
-                                                       CValue* originalval = converter->FindGameObject(editobact->ob);
+                                                       originalval = converter->FindGameObject(editobact->ob);
+                                               
+                                               MT_Vector3 linvelvec ( KX_BLENDERTRUNC(editobact->linVelocity[0]),
+                                                       KX_BLENDERTRUNC(editobact->linVelocity[1]),
+                                                       KX_BLENDERTRUNC(editobact->linVelocity[2]));
                                                        
-                                                       if (originalval)
-                                                       {
-                                                               MT_Vector3 linvelvec ( KX_BLENDERTRUNC(editobact->linVelocity[0]),
-                                                                       KX_BLENDERTRUNC(editobact->linVelocity[1]),
-                                                                       KX_BLENDERTRUNC(editobact->linVelocity[2]));
-                                                               KX_SCA_AddObjectActuator* tmpaddact = 
-                                                                       new KX_SCA_AddObjectActuator(
-                                                                       
-                                                                       gameobj, 
-                                                                       originalval,
-                                                                       editobact->time,
-                                                                       scene,
-                                                                       linvelvec.getValue(),
-                                                                       editobact->localflag!=0
-                                                                       
-                                                                       );
+                                               KX_SCA_AddObjectActuator* tmpaddact = 
+                                                       new KX_SCA_AddObjectActuator(
+                                                               gameobj, 
+                                                               originalval,
+                                                               editobact->time,
+                                                               scene,
+                                                               linvelvec.getValue(),
+                                                               editobact->localflag!=0
+                                                               );
                                                                
                                                                //editobact->ob to gameobj
                                                                baseact = tmpaddact;
-                                                       } 
-                                                       else
-                                                       {
-                                                               // let's pretend this never happened
-                                                               exit(0);
-                                                       }
-                                               } else
-                                               {
-                                                       printf ("ERROR: GameObject %s has a AddObjectActuator %s without object (in 'nonactive' layer)\n",
-                                                               objectname.ReadPtr(),
-                                                               uniquename.ReadPtr()    );
-                                               }
                                        }
                                        break;
                                case ACT_EDOB_END_OBJECT:
@@ -561,8 +548,8 @@ void BL_ConvertActuators(char* maggiename,
                                        break;
                                case ACT_EDOB_REPLACE_MESH:
                                        {
+                                               RAS_MeshObject *tmpmesh = NULL;
                                                if (editobact->me)
-                                               {
                                                        RAS_MeshObject *tmpmesh = BL_ConvertMesh(
                                                                editobact->me,
                                                                blenderobject,
@@ -570,31 +557,25 @@ void BL_ConvertActuators(char* maggiename,
                                                                scene,
                                                                converter
                                                                );
-                                                       KX_SCA_ReplaceMeshActuator* tmpreplaceact
-                                                               = new KX_SCA_ReplaceMeshActuator(
+
+                                               KX_SCA_ReplaceMeshActuator* tmpreplaceact
+                                                       = new KX_SCA_ReplaceMeshActuator(
                                                                gameobj,
                                                                tmpmesh,
                                                                scene
                                                                );
                                                        
                                                        baseact = tmpreplaceact;
-                                               }
-                                               else
-                                               {
-                                                       printf ("ERROR: GameObject %s ReplaceMeshActuator %s without object\n",
-                                                               objectname.ReadPtr(),
-                                                               uniquename.ReadPtr());
-                                               }
                                        }
                                        break;
                                case ACT_EDOB_TRACK_TO:
                                        {
+                                               SCA_IObject* originalval = NULL;
                                                if (editobact->ob)
-                                               {
                                                        SCA_IObject* originalval = converter->FindGameObject(editobact->ob);
                                                        
-                                                       KX_TrackToActuator* tmptrackact 
-                                                               = new KX_TrackToActuator(gameobj, 
+                                               KX_TrackToActuator* tmptrackact 
+                                                       = new KX_TrackToActuator(gameobj, 
                                                                originalval,
                                                                editobact->time,
                                                                editobact->flag,
@@ -602,15 +583,6 @@ void BL_ConvertActuators(char* maggiename,
                                                                blenderobject->upflag
                                                                );
                                                        baseact = tmptrackact;
-                                               }
-                                               else
-                                               {
-                                                       printf("ERROR: GameObject %s no object in EditObjectActuator %s\n",
-                                                               objectname.ReadPtr(),
-                                                               uniquename.ReadPtr()    );
-                                                       
-                                                       
-                                               }
                                        }
                                }
                                break;
@@ -674,8 +646,7 @@ void BL_ConvertActuators(char* maggiename,
                case ACT_SCENE:
                        {
                                bSceneActuator *sceneact = (bSceneActuator *) bact->data;
-                               bool scenevalid = true;
-                               STR_String nextSceneName;
+                               STR_String nextSceneName("");
                                
                                KX_SceneActuator* tmpsceneact;
                                int mode = KX_SceneActuator::KX_SCENE_NODEF;
@@ -718,14 +689,6 @@ void BL_ConvertActuators(char* maggiename,
                                                        nextSceneName = sceneact->scene->id.name + 2; // this '2' is necessary to remove prefix 'SC'
                                                }
                                                
-                                               if (!nextSceneName.Length())
-                                               {
-                                                       printf ("ERROR: GameObject %s has a SceneActuator %s (SetScene) without scene\n",
-                                                               objectname.ReadPtr(),
-                                                               uniquename.ReadPtr());
-                                                       scenevalid = false;
-                                                       
-                                               }
                                                break;
                                        }
                                case ACT_SCENE_CAMERA:
@@ -748,16 +711,13 @@ void BL_ConvertActuators(char* maggiename,
                                default:
                                        ; /* flag error */
                                }
-                               if (scenevalid )
-                               {
-                                       tmpsceneact = new KX_SceneActuator(gameobj,
+                               tmpsceneact = new KX_SceneActuator(gameobj,
                                                mode,
                                                scene,
                                                ketsjiEngine,
                                                nextSceneName,
                                                cam);
                                        baseact = tmpsceneact;
-                               }
                                break;
                        }
                case ACT_GAME:
index feaf24f..d972d88 100644 (file)
@@ -263,6 +263,9 @@ PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self,
                                                                                                PyObject* args,
                                                                                                PyObject* kwds)
 {
+       if (!m_OriginalObject)
+               Py_Return;
+
        return PyString_FromString(m_OriginalObject->GetName());
 }
 
index f26e987..84e12ac 100644 (file)
@@ -116,7 +116,7 @@ PyObject* KX_SCA_ReplaceMeshActuator::PySetMesh(PyObject* self,
 
        void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname));
        
-       if (m_mesh) {
+       if (mesh) {
                m_mesh= (class RAS_MeshObject*)mesh;
                Py_Return;
        }
@@ -129,6 +129,9 @@ KX_PYMETHODDEF_DOC(KX_SCA_ReplaceMeshActuator, getMesh,
 "Returns the name of the mesh to be substituted.\n"
 )
 {
+       if (!m_mesh)
+               Py_Return;
+
        return PyString_FromString(const_cast<char *>(m_mesh->GetName().ReadPtr()));
 }
 
index 3ef4968..ddd0672 100644 (file)
@@ -100,6 +100,21 @@ bool KX_SceneActuator::Update(double curtime,double deltatime)
                        m_KetsjiEngine->ReplaceScene(m_scene->GetName(),m_scene->GetName());
                        break;
                }
+       case KX_SCENE_SET_CAMERA:
+               if (m_camera)
+               {
+                       m_scene->SetActiveCamera(m_camera);
+               }
+               break;
+       default:
+               break;
+       }
+       
+       if (!m_nextSceneName.Length())
+               return false;
+       
+       switch (m_mode)
+       {
        case KX_SCENE_SET_SCENE:
                {
                        m_KetsjiEngine->ReplaceScene(m_scene->GetName(),m_nextSceneName);
@@ -132,12 +147,6 @@ bool KX_SceneActuator::Update(double curtime,double deltatime)
                        m_KetsjiEngine->ResumeScene(m_nextSceneName);
                        break;
                }
-       case KX_SCENE_SET_CAMERA:
-               if (m_camera)
-               {
-                       m_scene->SetActiveCamera(m_camera);
-               }
-               break;
        default:
                ; /* do nothing? this is an internal error !!! */
        }
index 7a0d0ad..6880ac5 100644 (file)
@@ -427,6 +427,9 @@ char KX_TrackToActuator::GetObject_doc[] =
 "\tReturns the object to track with the parent of this actuator.\n";
 PyObject* KX_TrackToActuator::PyGetObject(PyObject* self, PyObject* args, PyObject* kwds)
 {
+       if (!m_object)
+               Py_Return;
+
        return PyString_FromString(m_object->GetName());
 }
 
index ef216ae..7d6d1ee 100644 (file)
@@ -29,6 +29,8 @@ class KX_SCA_AddObjectActuator(SCA_IActuator):
                """
                Returns the name of the game object to be added.
                
+               Returns None if no game object has been assigned to be added.
+               
                @rtype: string
                """
        def setTime(time):
index 63100e4..eb00a91 100644 (file)
@@ -66,6 +66,8 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator):
                """
                Returns the name of the mesh that will replace the current one.
                
+               Returns None if no mesh has been scheduled to be added.
+               
                @rtype: string
                """
 
index eba899b..cfb40ae 100644 (file)
@@ -43,6 +43,8 @@ class KX_SceneActuator(SCA_IActuator):
                """
                Returns the name of the scene to change to/overlay/underlay/remove/suspend/resume.
                
+               Returns an empty string ("") if no scene has been set.
+               
                @rtype: string
                """
        def getCamera():
index 8b93a82..39fb99e 100644 (file)
@@ -25,6 +25,8 @@ class KX_TrackToActuator(SCA_IActuator):
                """
                Returns the name of the object to track.
                
+               Returns None if no object has been set to track.
+               
                @rtype: string
                """
        def setTime(time):