Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / source / gameengine / Ketsji / KX_SceneActuator.cpp
index 4447ff4..c7721c4 100644 (file)
@@ -49,9 +49,8 @@ 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;
@@ -134,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);
                        }
@@ -223,72 +222,40 @@ KX_Scene* KX_SceneActuator::FindScene(char * sceneName)
 
 /* Integration hooks ------------------------------------------------------- */
 PyTypeObject KX_SceneActuator::Type = {
-       PyObject_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,
-               py_base_getattro,
-               py_base_setattro,
-               0,0,0,0,0,0,0,0,0,
-               Methods
+       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
 };
 
-
-
-PyParentObject KX_SceneActuator::Parents[] =
-{
-       &KX_SceneActuator::Type,
-               &SCA_IActuator::Type,
-               &SCA_ILogicBrick::Type,
-               &CValue::Type,
-               NULL
-};
-
-
-
 PyMethodDef KX_SceneActuator::Methods[] =
 {
-       //Deprecated functions ------>
-       {"setUseRestart", (PyCFunction) KX_SceneActuator::sPySetUseRestart, METH_VARARGS, (PY_METHODCHAR)SetUseRestart_doc},
-       {"setScene",      (PyCFunction) KX_SceneActuator::sPySetScene, METH_VARARGS, (PY_METHODCHAR)SetScene_doc},
-       {"setCamera",     (PyCFunction) KX_SceneActuator::sPySetCamera, METH_VARARGS, (PY_METHODCHAR)SetCamera_doc},
-       {"getUseRestart", (PyCFunction) KX_SceneActuator::sPyGetUseRestart, METH_NOARGS, (PY_METHODCHAR)GetUseRestart_doc},
-       {"getScene",      (PyCFunction) KX_SceneActuator::sPyGetScene, METH_NOARGS, (PY_METHODCHAR)GetScene_doc},
-       {"getCamera",     (PyCFunction) KX_SceneActuator::sPyGetCamera, METH_NOARGS, (PY_METHODCHAR)GetCamera_doc},
-       //<----- Deprecated
        {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_TODO("useRestart"),
-       //KX_PYATTRIBUTE_TODO("mode"),
+       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::py_getattro(PyObject *attr)
-{
-       py_getattro_up(SCA_IActuator);
-}
-
-PyObject* KX_SceneActuator::py_getattro_dict() {
-       py_getattro_dict_up(SCA_IActuator);
-}
-
-int KX_SceneActuator::py_setattro(PyObject *attr, PyObject *value)
-{
-       py_setattro_up(SCA_IActuator);
-}
-
 PyObject* KX_SceneActuator::pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
 {
        KX_SceneActuator* actuator = static_cast<KX_SceneActuator*>(self);
@@ -303,187 +270,21 @@ int KX_SceneActuator::pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_
        KX_SceneActuator* actuator = static_cast<KX_SceneActuator*>(self);
        KX_Camera *camOb;
        
-       if(value==Py_None)
-       {
-               if (actuator->m_camera)
-                       actuator->m_camera->UnregisterActuator(actuator);
-               
+       if (!ConvertPythonToCamera(value, &camOb, true, "actu.camera = value: KX_SceneActuator"))
+               return PY_SET_ATTR_FAIL;
+       
+       if (actuator->m_camera)
+               actuator->m_camera->UnregisterActuator(actuator);
+       
+       if(camOb==NULL) {
                actuator->m_camera= NULL;
-               return 0;
        }
-       
-       if (PyObject_TypeCheck(value, &KX_Camera::Type)) 
-       {
-               KX_Camera *camOb= static_cast<KX_Camera*>BGE_PROXY_REF(value);
-               
-               if(camOb==NULL)
-               {
-                       PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG);
-                       return 1;
-               }
-               
-               if (actuator->m_camera)
-                       actuator->m_camera->UnregisterActuator(actuator);
-               
+       else {  
                actuator->m_camera = camOb;
                actuator->m_camera->RegisterActuator(actuator);
-               return 0;
        }
-
-       if (PyString_Check(value))
-       {
-               char *camName = PyString_AsString(value);
-
-               camOb = actuator->FindCamera(camName);
-               if (camOb) 
-               {
-                       if (actuator->m_camera)
-                               actuator->m_camera->UnregisterActuator(actuator);
-                       actuator->m_camera = camOb;
-                       actuator->m_camera->RegisterActuator(actuator);
-                       return 0;
-               }
-               PyErr_SetString(PyExc_TypeError, "not a valid camera name");
-               return 1;
-       }
-       PyErr_SetString(PyExc_TypeError, "expected a string or a camera object reference");
-       return 1;
-}
-
-
-/* 2. setUseRestart--------------------------------------------------------- */
-const 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* args)
-{
-       ShowDeprecationWarning("setUseRestart()", "(no replacement)");
-       int boolArg;
        
-       if (!PyArg_ParseTuple(args, "i:setUseRestart", &boolArg))
-       {
-               return NULL;
-       }
-       
-       m_restart = boolArg != 0;
-       
-       Py_RETURN_NONE;
-}
-
-
-
-/* 3. getUseRestart:                                                         */
-const char KX_SceneActuator::GetUseRestart_doc[] = 
-"getUseRestart()\n"
-"\tReturn whether the scene will be restarted.\n" ;
-PyObject* KX_SceneActuator::PyGetUseRestart()
-{
-       ShowDeprecationWarning("getUseRestart()", "(no replacement)");
-       return PyInt_FromLong(!(m_restart == 0));
-}
-
-
-
-/* 4. set scene------------------------------------------------------------- */
-const 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* args)
-{
-       ShowDeprecationWarning("setScene()", "the scene property");
-       /* one argument: a scene, ignore the rest */
-       char *scene_name;
-
-       if(!PyArg_ParseTuple(args, "s:setScene", &scene_name))
-       {
-               return NULL;
-       }
-
-       /* Scene switch is done by name. */
-       m_nextSceneName = scene_name;
-
-       Py_RETURN_NONE;
-}
-
-
-
-/* 5. getScene:                                                              */
-const char KX_SceneActuator::GetScene_doc[] = 
-"getScene()\n"
-"\tReturn the name of the scene the actuator wants to switch to.\n" ;
-PyObject* KX_SceneActuator::PyGetScene()
-{
-       ShowDeprecationWarning("getScene()", "the scene property");
-       return PyString_FromString(m_nextSceneName);
+       return PY_SET_ATTR_SUCCESS;
 }
 
-
-
-/* 6. set camera------------------------------------------------------------ */
-const char KX_SceneActuator::SetCamera_doc[] = 
-"setCamera(camera)\n"
-"\t- camera: string\n"
-"\tSet the camera to switch to.\n" ;
-PyObject* KX_SceneActuator::PySetCamera(PyObject* args)
-{
-       ShowDeprecationWarning("setCamera()", "the camera property");
-       PyObject *cam;
-       if (PyArg_ParseTuple(args, "O!:setCamera", &KX_Camera::Type, &cam))
-       {
-               KX_Camera *new_camera;
-               
-               new_camera = static_cast<KX_Camera*>BGE_PROXY_REF(cam);
-               if(new_camera==NULL)
-               {
-                       PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG);
-                       return NULL;
-               }
-               
-               if (m_camera)
-                       m_camera->UnregisterActuator(this);
-               
-               m_camera= new_camera;
-               
-               m_camera->RegisterActuator(this);
-               Py_RETURN_NONE;
-       }
-       PyErr_Clear();
-
-       /* one argument: a scene, ignore the rest */
-       char *camName;
-       if(!PyArg_ParseTuple(args, "s:setCamera", &camName))
-       {
-               return NULL;
-       }
-
-       KX_Camera *camOb = FindCamera(camName);
-       if (camOb) 
-       {
-               if (m_camera)
-                       m_camera->UnregisterActuator(this);
-               m_camera = camOb;
-               m_camera->RegisterActuator(this);
-       }
-
-       Py_RETURN_NONE;
-}
-
-
-
-/* 7. getCamera:                                                             */
-const char KX_SceneActuator::GetCamera_doc[] = 
-"getCamera()\n"
-"\tReturn the name of the camera to switch to.\n" ;
-PyObject* KX_SceneActuator::PyGetCamera()
-{
-       ShowDeprecationWarning("getCamera()", "the camera property");
-       if (m_camera) {
-               return PyString_FromString(m_camera->GetName());
-       }
-       else {
-               Py_RETURN_NONE;
-       }
-}
 /* eof */