Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / source / gameengine / Ketsji / KX_SceneActuator.cpp
index 8f7cffd..c7721c4 100644 (file)
@@ -49,22 +49,24 @@ KX_SceneActuator::KX_SceneActuator(SCA_IObject *gameobj,
                                                                   KX_Scene *scene,
                                                                   KX_KetsjiEngine* ketsjiEngine,
                                                                   const STR_String& nextSceneName,
-                                                                  KX_Camera* camera,
-                                                                  PyTypeObject* T)
-                                                                  : SCA_IActuator(gameobj, T)
+                                                                  KX_Camera* camera)
+                                                                  : SCA_IActuator(gameobj, KX_ACT_SCENE)
 {
        m_mode = mode;
        m_scene  = scene;
        m_KetsjiEngine=ketsjiEngine;
        m_camera = camera;
        m_nextSceneName = nextSceneName;
+       if (m_camera)
+               m_camera->RegisterActuator(this);
 } /* End of constructor */
 
 
 
 KX_SceneActuator::~KX_SceneActuator()
 { 
-       // there's nothing to be done here, really....
+       if (m_camera)
+               m_camera->UnregisterActuator(this);
 } /* end of destructor */
 
 
@@ -73,12 +75,37 @@ CValue* KX_SceneActuator::GetReplica()
 {
        KX_SceneActuator* replica = new KX_SceneActuator(*this);
        replica->ProcessReplica();
-       // this will copy properties and so on...
-       CValue::AddDataToReplica(replica);
-       
        return replica;
 }
 
+void KX_SceneActuator::ProcessReplica()
+{
+       if (m_camera)
+               m_camera->RegisterActuator(this);
+       SCA_IActuator::ProcessReplica();
+}
+
+bool KX_SceneActuator::UnlinkObject(SCA_IObject* clientobj)
+{
+       if (clientobj == (SCA_IObject*)m_camera)
+       {
+               // this object is being deleted, we cannot continue to track it.
+               m_camera = NULL;
+               return true;
+       }
+       return false;
+}
+
+void KX_SceneActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map)
+{
+       void **h_obj = (*obj_map)[m_camera];
+       if (h_obj) {
+               if (m_camera)
+                       m_camera->UnregisterActuator(this);
+               m_camera = (KX_Camera*)(*h_obj);
+               m_camera->RegisterActuator(this);
+       }
+}
 
 
 bool KX_SceneActuator::Update()
@@ -106,7 +133,7 @@ bool KX_SceneActuator::Update()
                {
                        // if no camera is set and the parent object is a camera, use it as the camera
                        SCA_IObject* parent = GetParent();
-                       if (parent->isA(&KX_Camera::Type))
+                       if (parent->GetGameObjectType()==SCA_IObject::OBJ_CAMERA)
                        {
                                m_scene->SetActiveCamera((KX_Camera*)parent);
                        }
@@ -195,171 +222,69 @@ KX_Scene* KX_SceneActuator::FindScene(char * sceneName)
 
 /* Integration hooks ------------------------------------------------------- */
 PyTypeObject KX_SceneActuator::Type = {
-       PyObject_HEAD_INIT(&PyType_Type)
-               0,
-               "KX_SceneActuator",
-               sizeof(KX_SceneActuator),
-               0,
-               PyDestructor,
-               0,
-               __getattr,
-               __setattr,
-               0, //&MyPyCompare,
-               __repr,
-               0, //&cvalue_as_number,
-               0,
-               0,
-               0,
-               0
-};
-
-
-
-PyParentObject KX_SceneActuator::Parents[] =
-{
-       &KX_SceneActuator::Type,
-               &SCA_IActuator::Type,
-               &SCA_ILogicBrick::Type,
-               &CValue::Type,
-               NULL
+       PyVarObject_HEAD_INIT(NULL, 0)
+       "KX_SceneActuator",
+       sizeof(PyObjectPlus_Proxy),
+       0,
+       py_base_dealloc,
+       0,
+       0,
+       0,
+       0,
+       py_base_repr,
+       0,0,0,0,0,0,0,0,0,
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+       0,0,0,0,0,0,0,
+       Methods,
+       0,
+       0,
+       &SCA_IActuator::Type,
+       0,0,0,0,0,0,
+       py_base_new
 };
 
-
-
 PyMethodDef KX_SceneActuator::Methods[] =
 {
-       {"setUseRestart", (PyCFunction) KX_SceneActuator::sPySetUseRestart, METH_VARARGS, SetUseRestart_doc},
-       {"setScene",      (PyCFunction) KX_SceneActuator::sPySetScene, METH_VARARGS, SetScene_doc},
-       {"setCamera",     (PyCFunction) KX_SceneActuator::sPySetCamera, METH_VARARGS, SetCamera_doc},
-       {"getUseRestart", (PyCFunction) KX_SceneActuator::sPyGetUseRestart, METH_VARARGS, GetUseRestart_doc},
-       {"getScene",      (PyCFunction) KX_SceneActuator::sPyGetScene, METH_VARARGS, GetScene_doc},
-       {"getCamera",     (PyCFunction) KX_SceneActuator::sPyGetCamera, METH_VARARGS, GetCamera_doc},
        {NULL,NULL} //Sentinel
 };
 
+PyAttributeDef KX_SceneActuator::Attributes[] = {
+       KX_PYATTRIBUTE_STRING_RW("scene",0,32,true,KX_SceneActuator,m_nextSceneName),
+       KX_PYATTRIBUTE_RW_FUNCTION("camera",KX_SceneActuator,pyattr_get_camera,pyattr_set_camera),
+       KX_PYATTRIBUTE_BOOL_RW("useRestart", KX_SceneActuator, m_restart),
+       KX_PYATTRIBUTE_INT_RW("mode", KX_SCENE_NODEF+1, KX_SCENE_MAX-1, true, KX_SceneActuator, m_mode),
+       { NULL }        //Sentinel
+};
 
-
-PyObject* KX_SceneActuator::_getattr(const STR_String& attr)
+PyObject* KX_SceneActuator::pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
 {
-       _getattr_up(SCA_IActuator);
+       KX_SceneActuator* actuator = static_cast<KX_SceneActuator*>(self);
+       if (!actuator->m_camera)
+               Py_RETURN_NONE;
+       
+       return actuator->m_camera->GetProxy();
 }
 
-
-
-/* 2. setUseRestart--------------------------------------------------------- */
-char KX_SceneActuator::SetUseRestart_doc[] = 
-"setUseRestart(flag)\n"
-"\t- flag: 0 or 1.\n"
-"\tSet flag to 1 to restart the scene.\n" ;
-PyObject* KX_SceneActuator::PySetUseRestart(PyObject* self, 
-                                                                                       PyObject* args, 
-                                                                                       PyObject* kwds)
+int KX_SceneActuator::pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
 {
-       int boolArg;
+       KX_SceneActuator* actuator = static_cast<KX_SceneActuator*>(self);
+       KX_Camera *camOb;
        
-       if (!PyArg_ParseTuple(args, "i", &boolArg))
-       {
-               return NULL;
-       }
+       if (!ConvertPythonToCamera(value, &camOb, true, "actu.camera = value: KX_SceneActuator"))
+               return PY_SET_ATTR_FAIL;
        
-       m_restart = boolArg != 0;
+       if (actuator->m_camera)
+               actuator->m_camera->UnregisterActuator(actuator);
        
-       Py_Return;
-}
-
-
-
-/* 3. getUseRestart:                                                         */
-char KX_SceneActuator::GetUseRestart_doc[] = 
-"getUseRestart()\n"
-"\tReturn whether the scene will be restarted.\n" ;
-PyObject* KX_SceneActuator::PyGetUseRestart(PyObject* self, 
-                                                                                       PyObject* args, 
-                                                                                       PyObject* kwds)
-{
-       return PyInt_FromLong(!(m_restart == 0));
-}
-
-
-
-/* 4. set scene------------------------------------------------------------- */
-char KX_SceneActuator::SetScene_doc[] = 
-"setScene(scene)\n"
-"\t- scene: string\n"
-"\tSet the name of scene the actuator will switch to.\n" ;
-PyObject* KX_SceneActuator::PySetScene(PyObject* self, 
-                                                                          PyObject* args, 
-                                                                          PyObject* kwds)
-{
-       /* one argument: a scene, ignore the rest */
-       char *scene_name;
-
-       if(!PyArg_ParseTuple(args, "s", &scene_name))
-       {
-               return NULL;
+       if(camOb==NULL) {
+               actuator->m_camera= NULL;
        }
-
-       /* Scene switch is done by name. */
-       m_nextSceneName = scene_name;
-
-       Py_Return;
-}
-
-
-
-/* 5. getScene:                                                              */
-char KX_SceneActuator::GetScene_doc[] = 
-"getScene()\n"
-"\tReturn the name of the scene the actuator wants to switch to.\n" ;
-PyObject* KX_SceneActuator::PyGetScene(PyObject* self, 
-                                                                          PyObject* args, 
-                                                                          PyObject* kwds)
-{
-       return PyString_FromString(m_nextSceneName);
-}
-
-
-
-/* 6. set camera------------------------------------------------------------ */
-char KX_SceneActuator::SetCamera_doc[] = 
-"setCamera(camera)\n"
-"\t- camera: string\n"
-"\tSet the camera to switch to.\n" ;
-PyObject* KX_SceneActuator::PySetCamera(PyObject* self, 
-                                                                               PyObject* args, 
-                                                                               PyObject* kwds)
-{
-       PyObject *cam;
-       if (PyArg_ParseTuple(args, "O!", &KX_Camera::Type, &cam))
-       {
-               m_camera = (KX_Camera*) cam;
-               Py_Return;
-       }
-       PyErr_Clear();
-
-       /* one argument: a scene, ignore the rest */
-       char *camName;
-       if(!PyArg_ParseTuple(args, "s", &camName))
-       {
-               return NULL;
+       else {  
+               actuator->m_camera = camOb;
+               actuator->m_camera->RegisterActuator(actuator);
        }
-
-       KX_Camera *camOb = FindCamera(camName);
-       if (camOb) m_camera = camOb;
-
-       Py_Return;
+       
+       return PY_SET_ATTR_SUCCESS;
 }
 
-
-
-/* 7. getCamera:                                                             */
-char KX_SceneActuator::GetCamera_doc[] = 
-"getCamera()\n"
-"\tReturn the name of the camera to switch to.\n" ;
-PyObject* KX_SceneActuator::PyGetCamera(PyObject* self, 
-                                                                               PyObject* args, 
-                                                                               PyObject* kwds)
-{
-       return PyString_FromString(m_camera->GetName());
-}
 /* eof */