Port Python updates from Tuhopuu2:
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Sat, 17 Jul 2004 05:28:23 +0000 (05:28 +0000)
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Sat, 17 Jul 2004 05:28:23 +0000 (05:28 +0000)
getType/setType to action/sound actuator (sgefant)
Use a more generic python -> math conversion.

34 files changed:
source/gameengine/Converter/BL_ActionActuator.cpp
source/gameengine/Converter/BL_ActionActuator.h
source/gameengine/Converter/BL_SkinMeshObject.h
source/gameengine/Expressions/PyObjectPlus.h
source/gameengine/GameLogic/SCA_IObject.cpp
source/gameengine/GameLogic/SCA_IObject.h
source/gameengine/GamePlayer/ghost/GPG_Application.cpp
source/gameengine/Ketsji/KX_Camera.cpp
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_Light.cpp
source/gameengine/Ketsji/KX_MeshProxy.cpp
source/gameengine/Ketsji/KX_NearSensor.cpp
source/gameengine/Ketsji/KX_NearSensor.h
source/gameengine/Ketsji/KX_PyMath.cpp
source/gameengine/Ketsji/KX_PyMath.h
source/gameengine/Ketsji/KX_PythonInit.cpp
source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_Scene.h
source/gameengine/Ketsji/KX_SceneActuator.cpp
source/gameengine/Ketsji/KX_SoundActuator.cpp
source/gameengine/Ketsji/KX_SoundActuator.h
source/gameengine/Ketsji/KX_TrackToActuator.cpp
source/gameengine/Ketsji/KX_VertexProxy.cpp
source/gameengine/Ketsji/Makefile
source/gameengine/PyDoc/BL_ActionActuator.py
source/gameengine/PyDoc/GameLogic.py
source/gameengine/PyDoc/KX_GameObject.py
source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py
source/gameengine/PyDoc/KX_SceneActuator.py
source/gameengine/PyDoc/KX_SoundActuator.py
source/gameengine/PyDoc/KX_TrackToActuator.py
source/gameengine/PyDoc/KX_VertexProxy.py
source/gameengine/PyDoc/WhatsNew.py [new file with mode: 0644]

index 3f633ee..52b948b 100644 (file)
@@ -395,7 +395,8 @@ PyMethodDef BL_ActionActuator::Methods[] = {
        {"getProperty", (PyCFunction) BL_ActionActuator::sPyGetProperty, METH_VARARGS, GetProperty_doc},
        {"setChannel", (PyCFunction) BL_ActionActuator::sPySetChannel, METH_VARARGS, SetChannel_doc},
 //     {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_VARARGS},
-       
+       {"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, GetType_doc},    
+       {"setType", (PyCFunction) BL_ActionActuator::sPySetType, METH_VARARGS, SetType_doc},
        {NULL,NULL} //Sentinel
 };
 
@@ -805,3 +806,42 @@ PyObject* BL_ActionActuator::PySetChannel(PyObject* self,
        return Py_None;
 }
 
+/* getType */
+char BL_ActionActuator::GetType_doc[] =
+"getType()\n"
+"\tReturns the operation mode of the actuator.\n";
+PyObject* BL_ActionActuator::PyGetType(PyObject* self,
+                                       PyObject* args, 
+                                       PyObject* kwds) {
+    return Py_BuildValue("h", m_playtype);
+}
+
+/* setType */
+char BL_ActionActuator::SetType_doc[] =
+"setType(mode)\n"
+"\t - mode: Play (0), Flipper (2), LoopStop (3), LoopEnd (4) or Property (6)\n"
+"\tSet the operation mode of the actuator.\n";
+PyObject* BL_ActionActuator::PySetType(PyObject* self,
+                                       PyObject* args,
+                                       PyObject* kwds) {
+       short typeArg;
+                                                                                                             
+    if (!PyArg_ParseTuple(args, "h", &typeArg)) {
+        return NULL;
+    }
+
+       switch (typeArg) {
+       case KX_ACT_ACTION_PLAY:
+       case KX_ACT_ACTION_FLIPPER:
+       case KX_ACT_ACTION_LOOPSTOP:
+       case KX_ACT_ACTION_LOOPEND:
+       case KX_ACT_ACTION_PROPERTY:
+               m_playtype = typeArg;
+               break;
+       default:
+               printf("Invalid type for action actuator: %d\n", typeArg); /* error */
+    }
+       
+    Py_Return;
+}
+
index 9e8054b..ca1f937 100644 (file)
@@ -93,11 +93,21 @@ public:
        KX_PYMETHOD_DOC(BL_ActionActuator,GetFrame);
        KX_PYMETHOD_DOC(BL_ActionActuator,GetProperty);
 //     KX_PYMETHOD(BL_ActionActuator,GetChannel);
-
+       KX_PYMETHOD_DOC(BL_ActionActuator,GetType);
+       KX_PYMETHOD_DOC(BL_ActionActuator,SetType);
 
        virtual PyObject* _getattr(const STR_String& attr);
        void SetBlendTime (float newtime);
 
+       enum ActionActType
+       {
+               KX_ACT_ACTION_PLAY = 0,
+               KX_ACT_ACTION_FLIPPER = 2,
+               KX_ACT_ACTION_LOOPSTOP,
+               KX_ACT_ACTION_LOOPEND,
+               KX_ACT_ACTION_PROPERTY = 6
+       };
+
 protected:
        float   m_blendframe;
        MT_Point3       m_lastpos;
index d753903..b233088 100644 (file)
@@ -91,8 +91,8 @@ public:
 class BL_SkinMeshObject : public RAS_MeshObject
 {
 
-       enum    {       BUCKET_MAX_INDICES = 16384};//2048};//8192};
-       enum    {       BUCKET_MAX_TRIANGLES = 4096};
+//     enum    {       BUCKET_MAX_INDICES = 16384};//2048};//8192};
+//     enum    {       BUCKET_MAX_TRIANGLES = 4096};
 
        KX_ArrayOptimizer*              GetArrayOptimizer(RAS_IPolyMaterial* polymat)
        {
index 8a5e8ef..05c806e 100644 (file)
@@ -111,8 +111,7 @@ inline void Py_Fatal(char *M) {
  */
 #define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \
 char class_name::method_name##_doc[] = doc_string; \
-PyObject* class_name::Py##method_name(PyObject* self, PyObject* args, PyObject* kwds)
-
+PyObject* class_name::Py##method_name(PyObject*, PyObject* args, PyObject*)
 
 
 /*------------------------------
index bd356f0..2be5af0 100644 (file)
@@ -231,7 +231,7 @@ void SCA_IObject::SetCurrentTime(float currentTime) {
 }
        
 
-
+#if 0
 const MT_Point3& SCA_IObject::ConvertPythonPylist(PyObject* pylist)
 {
        bool error = false;
@@ -273,19 +273,7 @@ const MT_Point3& SCA_IObject::ConvertPythonPylist(PyObject* pylist)
        }
        return m_sDummy;
 }
-
-
-
-const MT_Point3& SCA_IObject::ConvertPythonVectorArg(PyObject* args)
-{
-
-       PyObject* pylist;
-       PyArg_ParseTuple(args,"O",&pylist);
-       m_sDummy = ConvertPythonPylist(pylist);
-       return m_sDummy;
-}
-
-
+#endif
 
 void SCA_IObject::Suspend(void)
 {
index b1bb013..f57201b 100644 (file)
@@ -43,6 +43,8 @@ class SCA_ISensor;
 class SCA_IController;
 class SCA_IActuator;
 
+template<class T> T PyVecTo(PyObject*);
+
 typedef std::vector<SCA_ISensor *>       SCA_SensorList;
 typedef std::vector<SCA_IController *>   SCA_ControllerList;
 typedef std::vector<SCA_IActuator *>     SCA_ActuatorList;
@@ -110,8 +112,7 @@ public:
         */
        void Resume(void);
        
-       const class MT_Point3&  ConvertPythonPylist(PyObject* pylist);
-       const class MT_Point3&  ConvertPythonVectorArg(PyObject* args);
+//     const class MT_Point3&  ConvertPythonPylist(PyObject* pylist);
        
        // here come the python forwarded methods
        virtual PyObject* _getattr(const STR_String& attr);
index 4885939..04ac99f 100644 (file)
@@ -108,10 +108,25 @@ static GHOST_ISystem* fSystem = 0;
 static const int kTimerFreq = 10;
 
 GPG_Application::GPG_Application(GHOST_ISystem* system, struct Main *maggie, STR_String startSceneName)
-       : m_maggie(maggie), m_startSceneName(startSceneName), m_exitRequested(0),
-         m_system(system), m_mainWindow(0), m_frameTimer(0), m_cursor(GHOST_kStandardCursorFirstCursor),
-         m_mouse(0), m_keyboard(0), m_rasterizer(0), m_canvas(0), m_rendertools(0), m_kxsystem(0), m_networkdevice(0), m_audiodevice(0), m_sceneconverter(0),
-         m_engineInitialized(0), m_engineRunning(0), m_ketsjiengine(0)
+       : m_startSceneName(startSceneName), 
+         m_maggie(maggie), 
+         m_exitRequested(0),
+         m_system(system), 
+         m_mainWindow(0), 
+         m_frameTimer(0), 
+         m_cursor(GHOST_kStandardCursorFirstCursor),
+         m_engineInitialized(0), 
+         m_engineRunning(0), 
+         m_ketsjiengine(0),
+         m_kxsystem(0), 
+         m_keyboard(0), 
+         m_mouse(0), 
+         m_canvas(0), 
+         m_rendertools(0), 
+         m_rasterizer(0), 
+         m_sceneconverter(0),
+         m_networkdevice(0), 
+         m_audiodevice(0)
 {
        fSystem = system;
 }
index 5d455a7..d32ea26 100644 (file)
@@ -435,13 +435,13 @@ PyObject* KX_Camera::_getattr(const STR_String& attr)
        if (attr == "frustum_culling")
                return PyInt_FromLong(m_frustum_culling); /* new ref */
        if (attr == "projection_matrix")
-               return PyObjectFromMT_Matrix4x4(GetProjectionMatrix()); /* new ref */
+               return PyObjectFrom(GetProjectionMatrix()); /* new ref */
        if (attr == "modelview_matrix")
-               return PyObjectFromMT_Matrix4x4(GetModelviewMatrix()); /* new ref */
+               return PyObjectFrom(GetModelviewMatrix()); /* new ref */
        if (attr == "camera_to_world")
-               return PyObjectFromMT_Matrix4x4(GetCameraToWorld()); /* new ref */
+               return PyObjectFrom(GetCameraToWorld()); /* new ref */
        if (attr == "world_to_camera")
-               return PyObjectFromMT_Matrix4x4(GetWorldToCamera()); /* new ref */
+               return PyObjectFrom(GetWorldToCamera()); /* new ref */
        
        _getattr_up(KX_GameObject);
 }
@@ -483,8 +483,13 @@ int KX_Camera::_setattr(const STR_String &attr, PyObject *pyvalue)
        {
                if (attr == "projection_matrix")
                {
-                       SetProjectionMatrix(MT_Matrix4x4FromPyObject(pyvalue));
-                       return 0;
+                       MT_Matrix4x4 mat;
+                       if (PyMatTo(pyvalue, mat))
+                       {
+                               SetProjectionMatrix(mat);
+                               return 0;
+                       }
+                       return 1;
                }
        }
        return KX_GameObject::_setattr(attr, pyvalue);
@@ -512,14 +517,11 @@ KX_PYMETHODDEF_DOC(KX_Camera, sphereInsideFrustum,
        float radius;
        if (PyArg_ParseTuple(args, "Of", &pycentre, &radius))
        {
-               MT_Point3 centre = MT_Point3FromPyList(pycentre);
-               if (PyErr_Occurred())
+               MT_Point3 centre;
+               if (PyVecTo(pycentre, centre))
                {
-                       PyErr_SetString(PyExc_TypeError, "sphereInsideFrustum: Expected list for argument centre.");
-                       Py_Return;
+                       return PyInt_FromLong(SphereInsideFrustum(centre, radius)); /* new ref */
                }
-               
-               return PyInt_FromLong(SphereInsideFrustum(centre, radius)); /* new ref */
        }
 
        PyErr_SetString(PyExc_TypeError, "sphereInsideFrustum: Expected arguments: (centre, radius)");
@@ -566,9 +568,9 @@ KX_PYMETHODDEF_DOC(KX_Camera, boxInsideFrustum,
                for (unsigned int p = 0; p < 8 ; p++)
                {
                        PyObject *item = PySequence_GetItem(pybox, p); /* new ref */
-                       box[p] = MT_Point3FromPyList(item);
+                       bool error = !PyVecTo(item, box[p]);
                        Py_DECREF(item);
-                       if (PyErr_Occurred())
+                       if (error)
                                return NULL;
                }
                
@@ -595,13 +597,9 @@ KX_PYMETHODDEF_DOC(KX_Camera, pointInsideFrustum,
 "\t\t# Box is outside the frustum !\n"
 )
 {
-       PyObject *pypoint;
-       if (PyArg_ParseTuple(args, "O", &pypoint))
+       MT_Point3 point;
+       if (PyVecArgTo(args, point))
        {
-               MT_Point3 point = MT_Point3FromPyList(pypoint);
-               if (PyErr_Occurred())
-                       return NULL;
-                       
                return PyInt_FromLong(PointInsideFrustum(point)); /* new ref */
        }
        
@@ -615,7 +613,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, getCameraToWorld,
 "\tie: [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n"
 )
 {
-       return PyObjectFromMT_Matrix4x4(GetCameraToWorld()); /* new ref */
+       return PyObjectFrom(GetCameraToWorld()); /* new ref */
 }
 
 KX_PYMETHODDEF_DOC(KX_Camera, getWorldToCamera,
@@ -624,7 +622,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, getWorldToCamera,
 "\tie: [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n"
 )
 {
-       return PyObjectFromMT_Matrix4x4(GetWorldToCamera()); /* new ref */
+       return PyObjectFrom(GetWorldToCamera()); /* new ref */
 }
 
 KX_PYMETHODDEF_DOC(KX_Camera, getProjectionMatrix,
@@ -633,7 +631,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, getProjectionMatrix,
 "\tie: [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n"
 )
 {
-       return PyObjectFromMT_Matrix4x4(GetProjectionMatrix()); /* new ref */
+       return PyObjectFrom(GetProjectionMatrix()); /* new ref */
 }
 
 KX_PYMETHODDEF_DOC(KX_Camera, setProjectionMatrix,
@@ -681,12 +679,12 @@ KX_PYMETHODDEF_DOC(KX_Camera, setProjectionMatrix,
        PyObject *pymat;
        if (PyArg_ParseTuple(args, "O", &pymat))
        {
-               MT_Matrix4x4 mat = MT_Matrix4x4FromPyObject(pymat);
-               if (PyErr_Occurred())
-                       return NULL;
-               
-               SetProjectionMatrix(mat);
-               Py_Return;
+               MT_Matrix4x4 mat;
+               if (PyMatTo(pymat, mat))
+               {
+                       SetProjectionMatrix(mat);
+                       Py_Return;
+               }
        }
 
        PyErr_SetString(PyExc_TypeError, "setProjectionMatrix: Expected 4x4 list as matrix argument.");
index 6a35dfc..3061ceb 100644 (file)
@@ -628,7 +628,7 @@ PyMethodDef KX_GameObject::Methods[] = {
 
 
 
-
+/*
 bool KX_GameObject::ConvertPythonVectorArgs(PyObject* args,
                                                                                        MT_Vector3& pos,
                                                                                        MT_Vector3& pos2)
@@ -642,7 +642,7 @@ bool KX_GameObject::ConvertPythonVectorArgs(PyObject* args,
                
        return error;
 }
-
+*/
 
 
 PyObject* KX_GameObject::sPySetPosition(PyObject* self,
@@ -658,7 +658,7 @@ PyObject* KX_GameObject::PyGetPosition(PyObject* self,
                                                                           PyObject* args, 
                                                                           PyObject* kwds)
 {
-       return PyObjectFromMT_Point3(NodeGetWorldPosition());
+       return PyObjectFrom(NodeGetWorldPosition());
 }
 
 
@@ -706,21 +706,27 @@ PyObject* KX_GameObject::_getattr(const STR_String& attr)
        {       
                KX_GameObject* parent = GetParent();
                if (parent)
+               {
+                       parent->AddRef();
                        return parent;
+               }
                Py_Return;
        }
-       
+
        if (attr == "visible")
                return PyInt_FromLong(m_bVisible);
        
        if (attr == "position")
-               return PyObjectFromMT_Point3(NodeGetWorldPosition());
+               return PyObjectFrom(NodeGetWorldPosition());
        
        if (attr == "orientation")
-               return PyObjectFromMT_Matrix3x3(NodeGetWorldOrientation());
+               return PyObjectFrom(NodeGetWorldOrientation());
        
        if (attr == "scaling")
-               return PyObjectFromMT_Vector3(NodeGetWorldScaling());
+               return PyObjectFrom(NodeGetWorldScaling());
+               
+       if (attr == "name")
+               return PyString_FromString(m_name.ReadPtr());
        
        _getattr_up(SCA_IObject);
 }
@@ -750,25 +756,36 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value)      // _setattr
                        MT_Matrix3x3 rot;
                        if (PyObject_IsMT_Matrix(value, 3))
                        {
-                               rot = MT_Matrix3x3FromPyObject(value);
-                               NodeSetLocalOrientation(rot);
-                               return 0;
+                               if (PyMatTo(value, rot))
+                               {
+                                       NodeSetLocalOrientation(rot);
+                                       return 0;
+                               }
+                               return 1;
                        }
                        
                        if (PySequence_Size(value) == 4)
                        {
-                               MT_Quaternion qrot = MT_QuaternionFromPyList(value);
-                               rot.setRotation(qrot);
-                               NodeSetLocalOrientation(rot);
-                               return 0;
+                               MT_Quaternion qrot;
+                               if (PyVecTo(value, qrot))
+                               {
+                                       rot.setRotation(qrot);
+                                       NodeSetLocalOrientation(rot);
+                                       return 0;
+                               }
+                               return 1;
                        }
                        
                        if (PySequence_Size(value) == 3)
                        {
-                               MT_Vector3 erot = MT_Vector3FromPyList(value);
-                               rot.setEuler(erot);
-                               NodeSetLocalOrientation(rot);
-                               return 0;
+                               MT_Vector3 erot;
+                               if (PyVecTo(value, erot))
+                               {
+                                       rot.setEuler(erot);
+                                       NodeSetLocalOrientation(rot);
+                                       return 0;
+                               }
+                               return 1;
                        }
                        
                        return 1;
@@ -776,15 +793,32 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value)      // _setattr
                
                if (attr == "position")
                {
-                       MT_Point3 pos(MT_Point3FromPyList(value));
-                       NodeSetLocalPosition(pos);
-                       return 0;
+                       MT_Point3 pos;
+                       if (PyVecTo(value, pos))
+                       {
+                               NodeSetLocalPosition(pos);
+                               return 0;
+                       }
+                       return 1;
                }
                
                if (attr == "scaling")
                {
-                       MT_Vector3 scale(MT_Vector3FromPyList(value));
-                       NodeSetLocalScale(scale);
+                       MT_Vector3 scale;
+                       if (PyVecTo(value, scale))
+                       {
+                               NodeSetLocalScale(scale);
+                               return 0;
+                       }
+                       return 1;
+               }
+       }
+       
+       if (PyString_Check(value))
+       {
+               if (attr == "name")
+               {
+                       m_name = PyString_AsString(value);
                        return 0;
                }
        }
@@ -798,7 +832,7 @@ PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self,
                                                                                         PyObject* kwds)
 {
        // only can get the velocity if we have a physics object connected to us...
-       return PyObjectFromMT_Vector3( GetLinearVelocity());
+       return PyObjectFrom(GetLinearVelocity());
 }
 
 
@@ -837,7 +871,7 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* self,
        if (PyArg_ParseTuple(args, "|O", &pypos))
        {
                if (pypos)
-                       point = MT_Point3FromPyList(pypos);
+                       PyVecTo(pypos, point);
        }
        
        if (m_pPhysicsController1)
@@ -845,7 +879,7 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* self,
                velocity = m_pPhysicsController1->GetVelocity(point);
        }
        
-       return PyObjectFromMT_Vector3(velocity);
+       return PyObjectFrom(velocity);
 }
 
 
@@ -872,7 +906,7 @@ PyObject* KX_GameObject::PyGetReactionForce(PyObject* self,
                                                                                        PyObject* kwds)
 {
        // only can get the velocity if we have a physics object connected to us...
-       return PyObjectFromMT_Vector3(GetPhysicsController()->getReactionForce());
+       return PyObjectFrom(GetPhysicsController()->getReactionForce());
 }
 
 
@@ -906,7 +940,10 @@ PyObject* KX_GameObject::PyGetParent(PyObject* self,
 {
        KX_GameObject* parent = this->GetParent();
        if (parent)
+       {
+               parent->AddRef();
                return parent;
+       }
        Py_Return;
 }
 
@@ -942,17 +979,18 @@ PyObject* KX_GameObject::PyApplyImpulse(PyObject* self,
        
        if (PyArg_ParseTuple(args, "OO", &pyattach, &pyimpulse))
        {
-               MT_Point3  attach(MT_Point3FromPyList(pyattach));
-               MT_Vector3 impulse(MT_Vector3FromPyList(pyimpulse));
+               MT_Point3  attach;
+               MT_Vector3 impulse;
        
-               if (m_pPhysicsController1)
+               if (PyVecTo(pyattach, attach) && PyVecTo(pyimpulse, impulse) && m_pPhysicsController1)
                {
                        m_pPhysicsController1->applyImpulse(attach, impulse);
+                       Py_Return;
                }
 
        }
        
-       Py_Return;
+       return NULL;
 }
 
 
@@ -1002,8 +1040,7 @@ PyObject* KX_GameObject::PyGetOrientation(PyObject* self,
                                                                                  PyObject* args,
                                                                                  PyObject* kwds) //keywords
 {
-       const MT_Matrix3x3& orient = NodeGetWorldOrientation();
-       return PyObjectFromMT_Matrix3x3(orient);
+       return PyObjectFrom(NodeGetWorldOrientation());
 }
 
 
@@ -1016,29 +1053,24 @@ PyObject* KX_GameObject::PySetOrientation(PyObject* self,
        bool    error = false;
        int row,col;
        
-       PyArg_ParseTuple(args,"O",&pylist);
-       
-       MT_Matrix3x3 matrix;
-       if (PyObject_IsMT_Matrix(pylist, 3))
+       if (PyArg_ParseTuple(args,"O",&pylist))
        {
-               matrix = MT_Matrix3x3FromPyObject(pylist);
-                       
-               if (!PyErr_Occurred())
+               MT_Matrix3x3 matrix;
+               if (PyObject_IsMT_Matrix(pylist, 3) && PyMatTo(pylist, matrix))
                {
                        NodeSetLocalOrientation(matrix);
+                       Py_Return;
                }
-               
-               Py_Return;
-       }
        
-       MT_Quaternion quat = MT_QuaternionFromPyList(pylist);
-       if (!PyErr_Occurred())
-       {
-               matrix.setRotation(quat);
-               NodeSetLocalOrientation(matrix);
+               MT_Quaternion quat;
+               if (PyVecTo(pylist, quat))
+               {
+                       matrix.setRotation(quat);
+                       NodeSetLocalOrientation(matrix);
+                       Py_Return;
+               }
        }
-       
-       Py_Return;
+       return NULL;
 }
 
 
@@ -1047,14 +1079,14 @@ PyObject* KX_GameObject::PySetPosition(PyObject* self,
                                                                           PyObject* args, 
                                                                           PyObject* kwds)
 {
-       // make a general function for this, it's needed many times
-       PyObject *pypos;
-       if (PyArg_ParseTuple(args, "O", &pypos))
+       MT_Point3 pos;
+       if (PyVecArgTo(args, pos))
        {
-               MT_Point3 pos = MT_Point3FromPyList(pypos);
                NodeSetLocalPosition(pos);
+               Py_Return;
        }
-       Py_Return;
+       
+       return NULL;
 }
 
 PyObject* KX_GameObject::PyGetPhysicsId(PyObject* self,
index f5ec21e..06a52c0 100644 (file)
@@ -191,11 +191,15 @@ int       KX_LightObject::_setattr(const STR_String& attr, PyObject *pyvalue)
        {
                if (attr == "colour" || attr == "color")
                {
-                       MT_Vector3 colour(MT_Vector3FromPyList(pyvalue));
-                       m_lightobj.m_red = colour[0];
-                       m_lightobj.m_green = colour[1];
-                       m_lightobj.m_blue = colour[2];
-                       return 0;
+                       MT_Vector3 colour;
+                       if (PyVecTo(pyvalue, colour))
+                       {
+                               m_lightobj.m_red = colour[0];
+                               m_lightobj.m_green = colour[1];
+                               m_lightobj.m_blue = colour[2];
+                               return 0;
+                       }
+                       return 1;
                }
        }
        
index 4cde3ea..ec0dddd 100644 (file)
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include "KX_MeshProxy.h"
 #include "RAS_IPolygonMaterial.h"
 #include "RAS_MeshObject.h"
-#include "KX_VertexProxy.h"
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "KX_VertexProxy.h"
 
 PyTypeObject KX_MeshProxy::Type = {
        PyObject_HEAD_INIT(&PyType_Type)
index 3c6a5b9..3bb6bad 100644 (file)
@@ -143,10 +143,12 @@ KX_NearSensor::~KX_NearSensor()
 {
        // for nearsensor, the sensor is the 'owner' of sumoobj
        // for touchsensor, it's the parent
-       static_cast<KX_TouchEventManager*>(m_eventmgr)->GetSumoScene()->remove(*m_sumoObj);
-
        if (m_sumoObj)
+       {
+               static_cast<KX_TouchEventManager*>(m_eventmgr)->GetSumoScene()->remove(*m_sumoObj);
                delete m_sumoObj;
+               m_sumoObj = NULL;
+       }
                
        if (m_client_info)
                delete m_client_info;
index d112651..080df58 100644 (file)
@@ -39,7 +39,6 @@
 #include "KX_ClientObjectInfo.h"
 
 class KX_Scene;
-class KX_ClientObjectInfo;
 
 class KX_NearSensor : public KX_TouchSensor
 {
index ba68774..47984aa 100644 (file)
 
 #include "KX_Python.h"
 
-MT_Vector3 MT_Vector3FromPyList(PyObject* pylist)
-{
-       MT_Vector3 vec(0., 0., 0.);
-       bool error=false;
-       if (pylist->ob_type == &CListValue::Type)
-       {
-               CListValue* listval = (CListValue*) pylist;
-               unsigned int numitems = listval->GetCount();
-               if (numitems <= 3)
-               {
-                       for (unsigned int index=0;index<numitems;index++)
-                       {
-                               vec[index] = listval->GetValue(index)->GetNumber();
-                       }
-               }       else
-               {
-                       error = true;
-               }
-               
-       } else
-       {
-               // assert the list is long enough...
-               unsigned int numitems = PySequence_Size(pylist);
-               if (numitems <= 3)
-               {
-                       for (unsigned int index=0;index<numitems;index++)
-                       {
-                               PyObject *item = PySequence_GetItem(pylist,index); /* new ref */
-                               vec[index] = PyFloat_AsDouble(item);
-                               Py_DECREF(item);
-                       }
-               }
-               else
-               {
-                       error = true;
-               }
-
-       }
-       if (error)
-               PyErr_SetString(PyExc_TypeError, "Expected list of three items for vector argument.");
-
-       return vec;
-}
-
-MT_Point3 MT_Point3FromPyList(PyObject* pylist)
-{
-       MT_Point3 point(0., 0., 0.);
-       bool error=false;
-       if (pylist->ob_type == &CListValue::Type)
-       {
-               CListValue* listval = (CListValue*) pylist;
-               unsigned int numitems = listval->GetCount();
-               if (numitems <= 3)
-               {
-                       for (unsigned int index=0;index<numitems;index++)
-                       {
-                               point[index] = listval->GetValue(index)->GetNumber();
-                       }
-               }       else
-               {
-                       error = true;
-               }
-               
-       } else
-       {
-               // assert the list is long enough...
-               unsigned int numitems = PySequence_Size(pylist);
-               if (numitems <= 3)
-               {
-                       for (unsigned int index=0;index<numitems;index++)
-                       {
-                               PyObject *item = PySequence_GetItem(pylist,index); /* new ref */
-                               point[index] = PyFloat_AsDouble(item);
-                               Py_DECREF(item);
-                       }
-               }
-               else
-               {
-                       error = true;
-               }
-
-       }
-       if (error)
-               PyErr_SetString(PyExc_TypeError, "Expected list of three items for point argument.");
-
-       return point;
-}
-
-MT_Point2 MT_Point2FromPyList(PyObject* pylist)
-{
-       MT_Point2 point(0., 0.);
-       bool error=false;
-       if (pylist->ob_type == &CListValue::Type)
-       {
-               CListValue* listval = (CListValue*) pylist;
-               unsigned int numitems = listval->GetCount();
-               if (numitems <= 2)
-               {
-                       for (unsigned int index=0;index<numitems;index++)
-                       {
-                               point[index] = listval->GetValue(index)->GetNumber();
-                       }
-               }       else
-               {
-                       error = true;
-               }
-               
-       } else
-       {
-               // assert the list is long enough...
-               unsigned int numitems = PySequence_Size(pylist);
-               if (numitems <= 2)
-               {
-                       for (unsigned int index=0;index<numitems;index++)
-                       {
-                               PyObject *item = PySequence_GetItem(pylist,index); /* new ref */
-                               point[index] = PyFloat_AsDouble(item);
-                               Py_DECREF(item);
-                       }
-               }
-               else
-               {
-                       error = true;
-               }
-
-       }
-       if (error)
-               PyErr_SetString(PyExc_TypeError, "Expected list of twos items for point argument.");
-
-       return point;
-}
-
-MT_Vector4 MT_Vector4FromPyList(PyObject* pylist)
-{
-       MT_Vector4 vec(0., 0., 0., 1.);
-       bool error=false;
-       if (pylist->ob_type == &CListValue::Type)
-       {
-               CListValue* listval = (CListValue*) pylist;
-               unsigned int numitems = listval->GetCount();
-               if (numitems <= 4)
-               {
-                       for (unsigned index=0;index<numitems;index++)
-                       {
-                               vec[index] = listval->GetValue(index)->GetNumber();
-                       }
-               } else
-               {
-                       error = true;
-               }
-               
-       } else
-       {
-               // assert the list is long enough...
-               unsigned int numitems = PySequence_Size(pylist);
-               if (numitems <= 4)
-               {
-                       for (unsigned index=0;index<numitems;index++)
-                       {
-                               PyObject *item = PySequence_GetItem(pylist,index); /* new ref */
-                               vec[index] = PyFloat_AsDouble(item);
-                               Py_DECREF(item);
-                       }
-               }
-               else
-               {
-                       error = true;
-               }
-       }
-       if (error)
-               PyErr_SetString(PyExc_TypeError, "Expected list of four items for Vector argument.");
-       return vec;
-}
-
-MT_Quaternion MT_QuaternionFromPyList(PyObject* pylist)
-{
-       MT_Quaternion vec(0., 0., 0., 1.);
-       bool error=false;
-       if (pylist->ob_type == &CListValue::Type)
-       {
-               CListValue* listval = (CListValue*) pylist;
-               unsigned int numitems = listval->GetCount();
-               if (numitems <= 4)
-               {
-                       for (unsigned index=0;index<numitems;index++)
-                       {
-                               vec[index] = listval->GetValue(index)->GetNumber();
-                       }
-               } else
-               {
-                       error = true;
-               }
-               
-       } else
-       {
-               // assert the list is long enough...
-               unsigned int numitems = PySequence_Size(pylist);
-               if (numitems <= 4)
-               {
-                       for (unsigned index=0;index<numitems;index++)
-                       {
-                               PyObject *item = PySequence_GetItem(pylist,index); /* new ref */
-                               vec[index] = PyFloat_AsDouble(item);
-                               Py_DECREF(item);
-                       }
-               }
-               else
-               {
-                       error = true;
-               }
-       }
-       if (error)
-               PyErr_SetString(PyExc_TypeError, "Expected list of four items for Quaternion argument.");
-       return vec;
-}
-
-
-MT_Matrix4x4 MT_Matrix4x4FromPyObject(PyObject *pymat)
-{
-       MT_Matrix4x4 mat;
-       bool error = false;
-       mat.setIdentity();
-       if (PySequence_Check(pymat))
-       {
-               unsigned int rows = PySequence_Size(pymat);
-               for (unsigned int y = 0; y < rows && y < 4; y++)
-               {
-                       PyObject *pyrow = PySequence_GetItem(pymat, y); /* new ref */
-                       if (PySequence_Check(pyrow))
-                       {
-                               unsigned int cols = PySequence_Size(pyrow);
-                               for( unsigned int x = 0; x < cols && x < 4; x++)
-                               {
-                                       PyObject *item = PySequence_GetItem(pyrow, x); /* new ref */
-                                       mat[y][x] = PyFloat_AsDouble(item);
-                                       Py_DECREF(item);
-                               }
-                       }
-                       Py_DECREF(pyrow);
-               }
-       }
-        
-       return mat;
-}
-
 bool PyObject_IsMT_Matrix(PyObject *pymat, unsigned int rank)
 {
        if (!pymat)
                return false;
                
        unsigned int x, y;
-       if (pymat->ob_type == &CListValue::Type)
-       {
-               CListValue* listval = (CListValue*) pymat;
-               if (listval->GetCount() == rank)
-               {
-                       for (y = 0; y < rank; y++)
-                       {
-                               CListValue* vecval = (CListValue*)listval->GetValue(y);
-                               if (vecval->GetCount() != rank)
-                                       return false;
-                       }
-                       return true;
-               }
-               return false;
-       } else if (PySequence_Check(pymat))
+       if (PySequence_Check(pymat))
        {
                unsigned int rows = PySequence_Size(pymat);
                if (rows != rank)
@@ -337,58 +78,8 @@ bool PyObject_IsMT_Matrix(PyObject *pymat, unsigned int rank)
        return false;
 }
 
-MT_Matrix3x3 MT_Matrix3x3FromPyObject(PyObject *pymat)
-{
-       MT_Matrix3x3 mat;
-       bool error = false;
-       mat.setIdentity();
-       if (pymat->ob_type == &CListValue::Type)
-       {
-               unsigned int row, col;
-               CListValue* listval = (CListValue*) pymat;
-               if (listval->GetCount() == 3)
-               {
-                       for (row=0;row<3;row++) // each row has a 3-vector [x,y,z]
-                       {
-                               CListValue* vecval = (CListValue*)listval->GetValue(row);
-                               for (col=0;col<3 && col < vecval->GetCount();col++)
-                               {
-                                       mat[row][col] = vecval->GetValue(col)->GetNumber();
-                                       
-                               }
-                       }
-               }
-               else
-               {
-                       error = true;
-                       if (error)
-                               PyErr_SetString(PyExc_TypeError, "Expected list of three items for 3x3 matrix argument.");
 
-               }
-       } else if (PySequence_Check(pymat))
-       {
-               unsigned int rows = PySequence_Size(pymat);
-               for (unsigned int y = 0; y < rows && y < 3; y++)
-               {
-                       PyObject *pyrow = PySequence_GetItem(pymat, y); /* new ref */
-                       if (PySequence_Check(pyrow))
-                       {
-                               unsigned int cols = PySequence_Size(pyrow);
-                               for( unsigned int x = 0; x < cols && x < 3; x++)
-                               {
-                                       PyObject *pyitem = PySequence_GetItem(pyrow, x); /* new ref */
-                                       mat[y][x] = PyFloat_AsDouble(pyitem);
-                                       Py_DECREF(pyitem);
-                               }
-                       }
-                       Py_DECREF(pyrow);
-               }
-       }
-        
-       return mat;
-}
-
-PyObject* PyObjectFromMT_Matrix4x4(const MT_Matrix4x4 &mat)
+PyObject* PyObjectFrom(const MT_Matrix4x4 &mat)
 {
        return Py_BuildValue("[[ffff][ffff][ffff][ffff]]",
                mat[0][0], mat[0][1], mat[0][2], mat[0][3], 
@@ -397,7 +88,7 @@ PyObject* PyObjectFromMT_Matrix4x4(const MT_Matrix4x4 &mat)
                mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
 }
 
-PyObject* PyObjectFromMT_Matrix3x3(const MT_Matrix3x3 &mat)
+PyObject* PyObjectFrom(const MT_Matrix3x3 &mat)
 {
        return Py_BuildValue("[[fff][fff][fff]]",
                mat[0][0], mat[0][1], mat[0][2], 
@@ -405,25 +96,20 @@ PyObject* PyObjectFromMT_Matrix3x3(const MT_Matrix3x3 &mat)
                mat[2][0], mat[2][1], mat[2][2]);
 }
 
-PyObject* PyObjectFromMT_Vector4(const MT_Vector4 &vec)
+PyObject* PyObjectFrom(const MT_Tuple4 &vec)
 {
        return Py_BuildValue("[ffff]", 
                vec[0], vec[1], vec[2], vec[3]);
 }
 
-PyObject* PyObjectFromMT_Vector3(const MT_Vector3 &vec)
+PyObject* PyObjectFrom(const MT_Tuple3 &vec)
 {
        return Py_BuildValue("[fff]", 
                vec[0], vec[1], vec[2]);
 }
 
-PyObject* PyObjectFromMT_Point3(const MT_Point3 &pos)
-{
-       return Py_BuildValue("[fff]",
-               pos[0], pos[1], pos[2]);
-}
-
-PyObject* PyObjectFromMT_Point2(const MT_Point2 &pos)
+PyObject* PyObjectFrom(const MT_Tuple2 &vec)
 {
-       return Py_BuildValue("[ff]", pos[0], pos[1]);
+       return Py_BuildValue("[ff]",
+               vec[0], vec[1]);
 }
index 72793a6..322a9d3 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "MT_Point2.h"
 #include "MT_Point3.h"
+#include "MT_Vector2.h"
 #include "MT_Vector3.h"
 #include "MT_Vector4.h"
 #include "MT_Matrix3x3.h"
 
 #include "KX_Python.h"
 
-/**
- * Converts a python list to an MT_Vector3
- */
-MT_Vector3 MT_Vector3FromPyList(PyObject* pylist);
-
-/**
- * Converts a python list to an MT_Point3
- */
-MT_Point3 MT_Point3FromPyList(PyObject* pylist);
-
-/**
- * Converts a python list to an MT_Vector4
- */
-MT_Vector4 MT_Vector4FromPyList(PyObject* pylist);
+static unsigned int Size(const MT_Matrix4x4&)          { return 4; }
+static unsigned int Size(const MT_Matrix3x3&)          { return 3; }
+static unsigned int Size(const MT_Tuple2&)                { return 2; }
+static unsigned int Size(const MT_Tuple3&)                { return 3; }
+static unsigned int Size(const MT_Tuple4&)                { return 4; }
 
 /**
- * Converts a python list to an MT_Vector2
+ *  Converts the given python matrix to an MT class.
  */
-MT_Point2 MT_Point2FromPyList(PyObject* pylist);
+template<class T>
+bool PyMatTo(PyObject* pymat, T& mat)
+{
+       bool noerror = true;
+       mat.setIdentity();
+       if (PySequence_Check(pymat))
+       {
+               unsigned int rows = PySequence_Size(pymat);
+               for (unsigned int y = 0; y < rows && y < Size(mat); y++)
+               {
+                       PyObject *pyrow = PySequence_GetItem(pymat, y); /* new ref */
+                       if (PySequence_Check(pyrow))
+                       {
+                               unsigned int cols = PySequence_Size(pyrow);
+                               for( unsigned int x = 0; x < cols && x < Size(mat); x++)
+                               {
+                                       PyObject *item = PySequence_GetItem(pyrow, x); /* new ref */
+                                       mat[y][x] = PyFloat_AsDouble(item);
+                                       Py_DECREF(item);
+                               }
+                       } else 
+                               noerror = false;
+                       Py_DECREF(pyrow);
+               }
+       } else 
+               noerror = false;
+        
+       return noerror;
+}
 
 /**
- * Converts a python list to an MT_Quaternion
+ *  Converts a python list to a MT class.
  */
-MT_Quaternion MT_QuaternionFromPyList(PyObject* pylist);
+template<class T>
+bool PyVecTo(PyObject* pyval, T& vec)
+{
+       if (PySequence_Check(pyval))
+       {
+               unsigned int numitems = PySequence_Size(pyval);
+               for (unsigned int x = 0; x < numitems && x < Size(vec); x++)
+               {
+                       PyObject *item = PySequence_GetItem(pyval, x); /* new ref */
+                       vec[x] = PyFloat_AsDouble(item);
+                       Py_DECREF(item);
+               }
+               
+               return true;
+       }
+       
+       return false;
+}
 
 /**
- * Converts a python list of lists to an MT_Matrix4x4.
- * Any object that supports the sequence protocol will work.
- * Only the first four rows and first four columns in each row will be converted.
- * @example The python object [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]
- */
-MT_Matrix4x4 MT_Matrix4x4FromPyObject(PyObject *pymat);
-/**
- * Converts a python list of lists to an MT_Matrix3x3
- * Any object that supports the sequence protocol will work.
- * Only the first three rows and first three columns in each row will be converted.
- * @example The python object [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
+ *  Converts a python argument to an MT class.
+ *  This paramater expects arguments as passed to a python method.
  */
-MT_Matrix3x3 MT_Matrix3x3FromPyObject(PyObject *pymat);
+template<class T>
+bool PyVecArgTo(PyObject* args, T& vec)
+{
+       PyObject* pylist;
+       if (PyArg_ParseTuple(args,"O",&pylist))
+               return PyVecTo(pylist, vec);
+               
+       return false;
+}
 
 /**
  * Converts an MT_Matrix4x4 to a python object.
  */
-PyObject* PyObjectFromMT_Matrix4x4(const MT_Matrix4x4 &mat);
+PyObject* PyObjectFrom(const MT_Matrix4x4 &mat);
 
 /**
  * Converts an MT_Matrix3x3 to a python object.
  */
-PyObject* PyObjectFromMT_Matrix3x3(const MT_Matrix3x3 &mat);
+PyObject* PyObjectFrom(const MT_Matrix3x3 &mat);
 
 /**
- * Converts an MT_Vector3 to a python object.
+ * Converts an MT_Tuple2 to a python object.
  */
-PyObject* PyObjectFromMT_Vector3(const MT_Vector3 &vec);
+PyObject* PyObjectFrom(const MT_Tuple2 &vec);
 
 /**
- * Converts an MT_Vector4 to a python object
+ * Converts an MT_Tuple3 to a python object
  */
-PyObject* PyObjectFromMT_Vector4(const MT_Vector4 &vec);
+PyObject* PyObjectFrom(const MT_Tuple3 &vec);
 
 /**
- * Converts an MT_Vector3 to a python object.
+ * Converts an MT_Tuple4 to a python object.
  */
-PyObject* PyObjectFromMT_Point3(const MT_Point3 &pos);
+PyObject* PyObjectFrom(const MT_Tuple4 &pos);
 
-/**
- * Converts an MT_Point2 to a python object.
- */
-PyObject* PyObjectFromMT_Point2(const MT_Point2 &vec);
 /**
  * True if the given PyObject can be converted to an MT_Matrix
  * @param rank = 3 (for MT_Matrix3x3) or 4 (for MT_Matrix4x4)
index 1b6d55f..3d6995a 100644 (file)
@@ -46,6 +46,8 @@
 #include "SCA_RandomActuator.h"
 #include "KX_ConstraintActuator.h"
 #include "KX_IpoActuator.h"
+#include "KX_SoundActuator.h"
+#include "BL_ActionActuator.h"
 #include "RAS_IRasterizer.h"
 #include "RAS_ICanvas.h"
 #include "MT_Vector3.h"
@@ -86,54 +88,36 @@ static RAS_IRasterizer* gp_Rasterizer = NULL;
 static PyObject* ErrorObject;
 STR_String gPyGetRandomFloat_doc="getRandomFloat returns a random floating point value in the range [0..1)";
 
-static PyObject* gPyGetRandomFloat(PyObject* self,
-                                                                                PyObject* args
-                                                                                PyObject* kwds)
+static PyObject* gPyGetRandomFloat(PyObject*,
+                                       PyObject*
+                                       PyObject*)
 {
        return PyFloat_FromDouble(MT_random());
 }
 
-
-
-
-
-void GlobalConvertPythonVectorArg(PyObject* args, MT_Vector3 &pos)
-{
-       PyObject* pylist;
-       PyArg_ParseTuple(args,"O",&pylist);
-
-       pos = MT_Vector3FromPyList(pylist);
-}
-
-void GlobalConvertPythonVectorArg(PyObject* args, MT_Vector4 &vec)
-{
-       PyObject* pylist;
-       PyArg_ParseTuple(args,"O",&pylist);
-
-       vec = MT_Vector4FromPyList(pylist);
-}
-
-
-static PyObject* gPySetGravity(PyObject* self,
+static PyObject* gPySetGravity(PyObject*,
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
        MT_Vector3 vec = MT_Vector3(0., 0., 0.);
-       GlobalConvertPythonVectorArg(args, vec);
-
-       if (gp_KetsjiScene)
-               gp_KetsjiScene->SetGravity(vec);
+       if (PyVecArgTo(args, vec))
+       {
+               if (gp_KetsjiScene)
+                       gp_KetsjiScene->SetGravity(vec);
+               
+               Py_Return;
+       }
        
-       Py_Return;
+       return NULL;
 }
 
 
 static bool usedsp = false;
 
 // this gets a pointer to an array filled with floats
-static PyObject* gPyGetSpectrum(PyObject* self,
+static PyObject* gPyGetSpectrum(PyObject*,
                                                                PyObject* args, 
-                                                               PyObject* kwds)
+                                                               PyObject*)
 {
        SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
 
@@ -160,9 +144,9 @@ static PyObject* gPyGetSpectrum(PyObject* self,
 
 
 
-static PyObject* gPyStartDSP(PyObject* self,
+static PyObject* gPyStartDSP(PyObject*,
                                                PyObject* args, 
-                                               PyObject* kwds)
+                                               PyObject*)
 {
        SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
 
@@ -180,9 +164,9 @@ static PyObject* gPyStartDSP(PyObject* self,
 
 
 
-static PyObject* gPyStopDSP(PyObject* self,
+static PyObject* gPyStopDSP(PyObject*,
                                           PyObject* args, 
-                                          PyObject* kwds)
+                                          PyObject*)
 {
        SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
 
@@ -229,9 +213,9 @@ static struct PyMethodDef game_methods[] = {
 };
 
 
-static PyObject* gPyGetWindowHeight(PyObject* self
+static PyObject* gPyGetWindowHeight(PyObject*, 
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
        int height = (gp_Canvas ? gp_Canvas->GetHeight() : 0);
 
@@ -241,9 +225,9 @@ static PyObject* gPyGetWindowHeight(PyObject* self,
 
 
 
-static PyObject* gPyGetWindowWidth(PyObject* self
+static PyObject* gPyGetWindowWidth(PyObject*, 
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
                
 
@@ -258,9 +242,9 @@ static PyObject* gPyGetWindowWidth(PyObject* self,
 // temporarility visibility thing, will be moved to rasterizer/renderer later
 bool gUseVisibilityTemp = false;
 
-static PyObject* gPyEnableVisibility(PyObject* self
+static PyObject* gPyEnableVisibility(PyObject*, 
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
        int visible;
        if (PyArg_ParseTuple(args,"i",&visible))
@@ -276,9 +260,9 @@ static PyObject* gPyEnableVisibility(PyObject* self,
 
 
 
-static PyObject* gPyShowMouse(PyObject* self
+static PyObject* gPyShowMouse(PyObject*, 
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
        int visible;
        if (PyArg_ParseTuple(args,"i",&visible))
@@ -299,9 +283,9 @@ static PyObject* gPyShowMouse(PyObject* self,
 
 
 
-static PyObject* gPySetMousePosition(PyObject* self
+static PyObject* gPySetMousePosition(PyObject*, 
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
        int x,y;
        if (PyArg_ParseTuple(args,"ii",&x,&y))
@@ -315,43 +299,49 @@ static PyObject* gPySetMousePosition(PyObject* self,
 
 
 
-static PyObject* gPySetBackgroundColor(PyObject* self
+static PyObject* gPySetBackgroundColor(PyObject*, 
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
        
        MT_Vector4 vec = MT_Vector4(0., 0., 0.3, 0.);
-       GlobalConvertPythonVectorArg(args, vec);
-
-       if (gp_Canvas)
+       if (PyVecArgTo(args, vec))
        {
-               gp_Rasterizer->SetBackColor(vec[0], vec[1], vec[2], vec[3]);
+               if (gp_Canvas)
+               {
+                       gp_Rasterizer->SetBackColor(vec[0], vec[1], vec[2], vec[3]);
+               }
+               Py_Return;
        }
-   Py_Return;
+       
+       return NULL;
 }
 
 
 
-static PyObject* gPySetMistColor(PyObject* self
+static PyObject* gPySetMistColor(PyObject*, 
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
        
        MT_Vector3 vec = MT_Vector3(0., 0., 0.);
-       GlobalConvertPythonVectorArg(args, vec);
-
-       if (gp_Rasterizer)
+       if (PyVecArgTo(args, vec))
        {
-               gp_Rasterizer->SetFogColor(vec[0], vec[1], vec[2]);
+               if (gp_Rasterizer)
+               {
+                       gp_Rasterizer->SetFogColor(vec[0], vec[1], vec[2]);
+               }
+               Py_Return;
        }
-   Py_Return;
+       
+       return NULL;
 }
 
 
 
-static PyObject* gPySetMistStart(PyObject* self
+static PyObject* gPySetMistStart(PyObject*, 
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
 
        float miststart;
@@ -367,9 +357,9 @@ static PyObject* gPySetMistStart(PyObject* self,
 
 
 
-static PyObject* gPySetMistEnd(PyObject* self
+static PyObject* gPySetMistEnd(PyObject*, 
                                                                                 PyObject* args, 
-                                                                                PyObject* kwds)
+                                                                                PyObject*)
 {
 
        float mistend;
@@ -385,9 +375,9 @@ static PyObject* gPySetMistEnd(PyObject* self,
 
 
 
-static PyObject* gPyMakeScreenshot(PyObject* self,
+static PyObject* gPyMakeScreenshot(PyObject*,
                                                                        PyObject* args,
-                                                                       PyObject* kwds)
+                                                                       PyObject*)
 {
        char* filename;
        if (PyArg_ParseTuple(args,"s",&filename))
@@ -506,6 +496,21 @@ PyObject* initGameLogic(KX_Scene* scene) // quick hack to get gravity hook
        KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NORMAL,    SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL);
        KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL, SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL);
 
+       /* 6. Sound actuator                                                      */
+       KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP,              KX_SoundActuator::KX_SOUNDACT_PLAYSTOP);
+       KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND,               KX_SoundActuator::KX_SOUNDACT_PLAYEND);
+       KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP,              KX_SoundActuator::KX_SOUNDACT_LOOPSTOP);
+       KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPEND,               KX_SoundActuator::KX_SOUNDACT_LOOPEND);
+       KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL,     KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL);
+       KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP,     KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP);
+
+       /* 7. Action actuator                                                                                                      */
+       KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PLAY,     BL_ActionActuator::KX_ACT_ACTION_PLAY);
+       KX_MACRO_addTypesToDict(d, KX_ACTIONACT_FLIPPER,     BL_ActionActuator::KX_ACT_ACTION_FLIPPER);
+       KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPSTOP,     BL_ActionActuator::KX_ACT_ACTION_LOOPSTOP);
+       KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPEND,     BL_ActionActuator::KX_ACT_ACTION_LOOPEND);
+       KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PROPERTY,     BL_ActionActuator::KX_ACT_ACTION_PROPERTY);
+       
        // Check for errors
        if (PyErr_Occurred())
     {
index 37d772b..cfa0ad4 100644 (file)
@@ -192,16 +192,22 @@ PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* self,
                                                                                                PyObject* args,
                                                                                                PyObject* kwds)
 {    
-       char* objectname;
-       
-       if (!PyArg_ParseTuple(args, "s", &objectname))
-               return NULL;            
-
-       CValue* gameobj = SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));
+       PyObject* gameobj;
+       if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj))
+       {
+               m_OriginalObject = (CValue*)gameobj;
+               Py_Return;
+       }
        
-       m_OriginalObject= (CValue*)gameobj;
+       char* objectname;
+       if (PyArg_ParseTuple(args, "s", &objectname))
+       {
+               m_OriginalObject= (CValue*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname));;
+               
+               Py_Return;
+       }
        
-       Py_Return;      
+       return NULL;
 }
 
 
index c274f05..c44c941 100644 (file)
@@ -772,7 +772,6 @@ void KX_Scene::AddCamera(KX_Camera* cam)
        m_cameras.insert(cam);
 }
 
-
 KX_Camera* KX_Scene::GetActiveCamera()
 {      
        // NULL if not defined
@@ -808,14 +807,15 @@ void KX_Scene::MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty)
 {
        int intersect = KX_Camera::INTERSECT;
        KX_GameObject *gameobj = node->Client()?(KX_GameObject*) node->Client()->GetSGClientObject():NULL;
+       bool dotest = (gameobj && gameobj->GetVisible()) || node->Left() || node->Right();
        
        /* If the camera is inside the box, assume intersect. */
-       if (!node->inside(GetActiveCamera()->NodeGetWorldPosition()))
+       if (dotest && !node->inside(GetActiveCamera()->NodeGetWorldPosition()))
        {
                MT_Scalar radius = node->Radius();
                MT_Point3 centre = node->Centre();
                
-               intersect = GetActiveCamera()->SphereInsideFrustum(centre, radius);
+               intersect = GetActiveCamera()->SphereInsideFrustum(centre, radius); 
                
                if (intersect == KX_Camera::INTERSECT)
                {
@@ -832,17 +832,7 @@ void KX_Scene::MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty)
                        break;
                case KX_Camera::INTERSECT:
                        if (gameobj)
-                       {
-                               int nummeshes = gameobj->GetMeshCount();
-                               MT_Transform t(GetActiveCamera()->GetWorldToCamera() * gameobj->GetSGNode()->GetWorldTransform());
-                               
-                               for (int m=0;m<nummeshes;m++)
-                               {
-                                       // this adds the vertices to the display list
-                                       (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode(),rasty);
-                               }
-                               gameobj->MarkVisible();
-                       }
+                               MarkVisible(rasty, gameobj);
                        if (node->Left())
                                MarkVisible(node->Left(), rasty);
                        if (node->Right())
@@ -859,19 +849,22 @@ void KX_Scene::MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool vi
        if (node->Client())
        {
                KX_GameObject *gameobj = (KX_GameObject*) node->Client()->GetSGClientObject();
-               if (visible)
+               if (gameobj->GetVisible())
                {
-                       int nummeshes = gameobj->GetMeshCount();
-                       MT_Transform t( GetActiveCamera()->GetWorldToCamera() * gameobj->GetSGNode()->GetWorldTransform());
-
-                       
-                       for (int m=0;m<nummeshes;m++)
+                       if (visible)
                        {
-                               // this adds the vertices to the display list
-                               (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode(),rasty);
+                               int nummeshes = gameobj->GetMeshCount();
+                               MT_Transform t( GetActiveCamera()->GetWorldToCamera() * gameobj->GetSGNode()->GetWorldTransform());
+       
+                               
+                               for (int m=0;m<nummeshes;m++)
+                               {
+                                       // this adds the vertices to the display list
+                                       (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode(),rasty);
+                               }
                        }
+                       gameobj->MarkVisible(visible);
                }
-               gameobj->MarkVisible(visible && gameobj->GetVisible());
        }
        if (node->Left())
                MarkSubTreeVisible(node->Left(), rasty, visible);
@@ -879,62 +872,68 @@ void KX_Scene::MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool vi
                MarkSubTreeVisible(node->Right(), rasty, visible);
 }
 
-
-void KX_Scene::CalculateVisibleMeshes(RAS_IRasterizer* rasty)
+void KX_Scene::MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj)
 {
-// FIXME: When tree is operational
-#if 1
-       // do this incrementally in the future
-       for (int i = 0; i < m_objectlist->GetCount(); i++)
+       // User (Python/Actuator) has forced object invisible...
+       if (!gameobj->GetVisible())
+               return;
+       // If Frustum culling is off, the object is always visible.
+       bool vis = !GetActiveCamera()->GetFrustumCulling();
+       
+       // If the camera is inside this node, then the object is visible.
+       if (!vis)
        {
-               KX_GameObject* gameobj = (KX_GameObject*)m_objectlist->GetValue(i);
-               // If Frustum culling is off, the object is always visible.
-               bool vis = !GetActiveCamera()->GetFrustumCulling();
+               vis = gameobj->GetSGNode()->inside( GetActiveCamera()->GetCameraLocation() );
+       }
                
-               // If the camera is inside this node, then the object is visible.
-               if (!vis)
-               {
-                       vis = gameobj->GetSGNode()->inside( GetActiveCamera()->GetCameraLocation() );
-               }
-                       
-               // Test the object's bound sphere against the view frustum.
-               if (!vis)
+       // Test the object's bound sphere against the view frustum.
+       if (!vis)
+       {
+               MT_Vector3 scale = gameobj->GetSGNode()->GetWorldScaling();
+               MT_Scalar radius = fabs(scale[scale.closestAxis()] * gameobj->GetSGNode()->Radius());
+               switch (GetActiveCamera()->SphereInsideFrustum(gameobj->NodeGetWorldPosition(), radius))
                {
-                       MT_Vector3 scale = gameobj->GetSGNode()->GetWorldScaling();
-                       MT_Scalar radius = fabs(scale[scale.closestAxis()] * gameobj->GetSGNode()->Radius());
-                       switch (GetActiveCamera()->SphereInsideFrustum(gameobj->NodeGetWorldPosition(), radius))
-                       {
-                               case KX_Camera::INSIDE:
-                                       vis = true;
-                                       break;
-                               case KX_Camera::OUTSIDE:
-                                       vis = false;
-                                       break;
-                               case KX_Camera::INTERSECT:
-                                       // Test the object's bound box against the view frustum.
-                                       MT_Point3 box[8];
-                                       gameobj->GetSGNode()->getBBox(box); 
-                                       vis = GetActiveCamera()->BoxInsideFrustum(box) != KX_Camera::OUTSIDE;
-                                       break;
-                       }
+                       case KX_Camera::INSIDE:
+                               vis = true;
+                               break;
+                       case KX_Camera::OUTSIDE:
+                               vis = false;
+                               break;
+                       case KX_Camera::INTERSECT:
+                               // Test the object's bound box against the view frustum.
+                               MT_Point3 box[8];
+                               gameobj->GetSGNode()->getBBox(box); 
+                               vis = GetActiveCamera()->BoxInsideFrustum(box) != KX_Camera::OUTSIDE;
+                               break;
                }
+       }
+       
+       if (vis)
+       {
+               int nummeshes = gameobj->GetMeshCount();
+               MT_Transform t(GetActiveCamera()->GetWorldToCamera() * gameobj->GetSGNode()->GetWorldTransform());
                
-               if (vis)
+               for (int m=0;m<nummeshes;m++)
                {
-                       int nummeshes = gameobj->GetMeshCount();
-                       MT_Transform t(GetActiveCamera()->GetWorldToCamera() * gameobj->GetSGNode()->GetWorldTransform());
-                       
-                       for (int m=0;m<nummeshes;m++)
-                       {
-                               // this adds the vertices to the display list
-                               (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode(),rasty);
-                       }
-                       // Visibility/ non-visibility are marked
-                       // elsewhere now.
-                       gameobj->MarkVisible();
-               } else {
-                       gameobj->MarkVisible(false);
+                       // this adds the vertices to the display list
+                       (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode(),rasty);
                }
+               // Visibility/ non-visibility are marked
+               // elsewhere now.
+               gameobj->MarkVisible();
+       } else {
+               gameobj->MarkVisible(false);
+       }
+}
+
+void KX_Scene::CalculateVisibleMeshes(RAS_IRasterizer* rasty)
+{
+// FIXME: When tree is operational
+#if 1
+       // do this incrementally in the future
+       for (int i = 0; i < m_objectlist->GetCount(); i++)
+       {
+               MarkVisible(rasty, static_cast<KX_GameObject*>(m_objectlist->GetValue(i)));
        }
 #else
        if (GetActiveCamera()->GetFrustumCulling())
index 1df126c..9e69091 100644 (file)
@@ -245,8 +245,12 @@ protected:
         */
        RAS_Rect m_viewport;
        
+       /**
+        * Visibility testing functions.
+        */
        void MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty);
        void MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool visible);
+       void MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj);
        
        /**
         * This stores anything from python
index 721d01a..9ccb406 100644 (file)
@@ -314,16 +314,21 @@ 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;
+       }
+
        /* one argument: a scene, ignore the rest */
        char *camName;
-       KX_Camera *camOb;
-
        if(!PyArg_ParseTuple(args, "s", &camName))
        {
                return NULL;
        }
 
-       camOb = FindCamera(camName);
+       KX_Camera *camOb = FindCamera(camName);
        if (camOb) m_camera = camOb;
 
        Py_Return;
index 6f959f0..e719025 100644 (file)
@@ -256,7 +256,9 @@ PyMethodDef KX_SoundActuator::Methods[] = {
        {"getLooping",(PyCFunction) KX_SoundActuator::sPyGetLooping,METH_VARARGS,NULL},
        {"setPosition",(PyCFunction) KX_SoundActuator::sPySetPosition,METH_VARARGS,NULL},
        {"setVelocity",(PyCFunction) KX_SoundActuator::sPySetVelocity,METH_VARARGS,NULL},
-       {"setOrientation",(PyCFunction) KX_SoundActuator::sPySetOrientation,METH_VARARGS,NULL}, 
+       {"setOrientation",(PyCFunction) KX_SoundActuator::sPySetOrientation,METH_VARARGS,NULL},
+       {"setType",(PyCFunction) KX_SoundActuator::sPySetType,METH_VARARGS,NULL},
+       {"getType",(PyCFunction) KX_SoundActuator::sPyGetType,METH_VARARGS,NULL},
        {NULL,NULL,NULL,NULL} //Sentinel
 };
 
@@ -464,7 +466,28 @@ PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyO
        m_soundObject->SetOrientation(ori);
        
        Py_Return;
-}         
+}
+
+PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* kwds)
+{
+       int typeArg;
+
+       if (!PyArg_ParseTuple(args, "i", &typeArg)) {
+               return NULL;
+       }
+
+       if ( (typeArg > KX_SOUNDACT_NODEF)
+         && (typeArg < KX_SOUNDACT_MAX) ) {
+               m_type = (KX_SOUNDACT_TYPE) typeArg;
+       }
+
+       Py_Return;
+}
+
+PyObject* KX_SoundActuator::PyGetType(PyObject* self, PyObject* args, PyObject* kwds)
+{
+       return PyInt_FromLong(m_type);
+}
 
 
 
index 7cdf601..dcb46f1 100644 (file)
@@ -101,6 +101,8 @@ public:
        KX_PYMETHOD(KX_SoundActuator,SetPosition);
        KX_PYMETHOD(KX_SoundActuator,SetVelocity);
        KX_PYMETHOD(KX_SoundActuator,SetOrientation);
+       KX_PYMETHOD(KX_SoundActuator,SetType);
+       KX_PYMETHOD(KX_SoundActuator,GetType);
 };
 
 #endif //__KX_SOUNDACTUATOR
index c02cdbc..becc4c5 100644 (file)
@@ -399,16 +399,23 @@ char KX_TrackToActuator::SetObject_doc[] =
 "\t- object: string\n"
 "\tSet the object to track with the parent of this actuator.\n";
 PyObject* KX_TrackToActuator::PySetObject(PyObject* self, PyObject* args, PyObject* kwds) {
-       char* nameArg;
-       
-       if (!PyArg_ParseTuple(args, "s", &nameArg)) {
-               return NULL;            
+       PyObject* gameobj;
+       if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj))
+       {
+               m_object = (SCA_IObject*)gameobj;
+
+               Py_Return;
        }
-       CValue* gameobj = SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(nameArg));
        
-       m_object= (SCA_IObject*)gameobj;
+       char* objectname;
+       if (PyArg_ParseTuple(args, "s", &objectname))
+       {
+               m_object= static_cast<SCA_IObject*>(SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname)));
+               
+               Py_Return;
+       }
        
-       Py_Return;      
+       return NULL;
 }
 
 
index ae8a555..3afea84 100644 (file)
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
 
-#include "KX_VertexProxy.h"
-#include "RAS_TexVert.h"
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
+#include "KX_VertexProxy.h"
+#include "KX_MeshProxy.h"
+#include "RAS_TexVert.h"
+
 #include "KX_PyMath.h"
 
 PyTypeObject KX_VertexProxy::Type = {
@@ -80,23 +81,22 @@ PyObject*
 KX_VertexProxy::_getattr(const STR_String& attr)
 {
   if (attr == "XYZ")
-       return PyObjectFromMT_Vector3(m_vertex->getLocalXYZ());
+       return PyObjectFrom(MT_Vector3(m_vertex->getLocalXYZ()));
 
   if (attr == "UV")
-       return PyObjectFromMT_Point2(MT_Point2(m_vertex->getUV1()));
+       return PyObjectFrom(MT_Point2(m_vertex->getUV1()));
 
   if (attr == "colour" || attr == "color")
   {
-       unsigned int icol = m_vertex->getRGBA();
-       unsigned char *colp = (unsigned char *) &icol;
+       const unsigned char *colp = m_vertex->getRGBA();
        MT_Vector4 colour(colp[0], colp[1], colp[2], colp[3]);
        colour /= 255.0;
-       return PyObjectFromMT_Vector4(colour);
+       return PyObjectFrom(colour);
   }
   
   if (attr == "normal")
   {
-       return PyObjectFromMT_Vector3(m_vertex->getNormal());
+       return PyObjectFrom(MT_Vector3(m_vertex->getNormal()));
   }
 
   // pos
@@ -109,13 +109,13 @@ KX_VertexProxy::_getattr(const STR_String& attr)
 
   // Col
   if (attr == "r")
-       return PyFloat_FromDouble(((unsigned char*)m_vertex->getRGBA())[0]/255.0);
+       return PyFloat_FromDouble(m_vertex->getRGBA()[0]/255.0);
   if (attr == "g")
-       return PyFloat_FromDouble(((unsigned char*)m_vertex->getRGBA())[1]/255.0);
+       return PyFloat_FromDouble(m_vertex->getRGBA()[1]/255.0);
   if (attr == "b")
-       return PyFloat_FromDouble(((unsigned char*)m_vertex->getRGBA())[2]/255.0);
+       return PyFloat_FromDouble(m_vertex->getRGBA()[2]/255.0);
   if (attr == "a")
-       return PyFloat_FromDouble(((unsigned char*)m_vertex->getRGBA())[3]/255.0);
+       return PyFloat_FromDouble(m_vertex->getRGBA()[3]/255.0);
 
   // UV
   if (attr == "u")
@@ -132,26 +132,46 @@ int    KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue)
   {
        if (attr == "XYZ")
        {
-               m_vertex->SetXYZ(MT_Point3FromPyList(pyvalue));
-               return 0;
+               MT_Point3 vec;
+               if (PyVecTo(pyvalue, vec))
+               {
+                       m_vertex->SetXYZ(vec);
+                       return 0;
+               }
+               return 1;
        }
        
        if (attr == "UV")
        {
-               m_vertex->SetUV(MT_Point2FromPyList(pyvalue));
-               return 0;
+               MT_Point2 vec;
+               if (PyVecTo(pyvalue, vec))
+               {
+                       m_vertex->SetUV(vec);
+                       return 0;
+               }
+               return 1;
        }
        
        if (attr == "colour" || attr == "color")
        {
-               m_vertex->SetRGBA(MT_Vector4FromPyList(pyvalue));
-               return 0;
+               MT_Vector4 vec;
+               if (PyVecTo(pyvalue, vec))
+               {
+                       m_vertex->SetRGBA(vec);
+                       return 0;
+               }
+               return 1;
        }
        
        if (attr == "normal")
        {
-               m_vertex->SetNormal(MT_Vector3FromPyList(pyvalue));
-               return 0;
+               MT_Vector3 vec;
+               if (PyVecTo(pyvalue, vec))
+               {
+                       m_vertex->SetNormal(vec);
+                       return 0;
+               }
+               return 1;
        }
   }
   
@@ -198,7 +218,7 @@ int    KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue)
        }
        
        // col
-       unsigned int icol = m_vertex->getRGBA();
+       unsigned int icol = *((const unsigned int *)m_vertex->getRGBA());
        unsigned char *cp = (unsigned char*) &icol;
        val *= 255.0;
        if (attr == "r")
@@ -233,132 +253,122 @@ int    KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue)
 KX_VertexProxy::KX_VertexProxy(RAS_TexVert* vertex)
 :m_vertex(vertex)
 {
-       
 }
 
 KX_VertexProxy::~KX_VertexProxy()
 {
-       
 }
 
 
 
 // stuff for cvalue related things
-CValue*                KX_VertexProxy::Calc(VALUE_OPERATOR op, CValue *val) { return NULL;}
-CValue*                KX_VertexProxy::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) { return NULL;}        
+CValue*                KX_VertexProxy::Calc(VALUE_OPERATOR, CValue *) { return NULL;}
+CValue*                KX_VertexProxy::CalcFinal(VALUE_DATA_TYPE, VALUE_OPERATOR, CValue *) { return NULL;}    
 STR_String     sVertexName="vertex";
 const STR_String &     KX_VertexProxy::GetText() {return sVertexName;};
 float          KX_VertexProxy::GetNumber() { return -1;}
 STR_String     KX_VertexProxy::GetName() { return sVertexName;}
-void           KX_VertexProxy::SetName(STR_String name) { };
+void           KX_VertexProxy::SetName(STR_String) { };
 CValue*                KX_VertexProxy::GetReplica() { return NULL;}
-void           KX_VertexProxy::ReplicaSetName(STR_String name) {};
+void           KX_VertexProxy::ReplicaSetName(STR_String) {};
 
 
 // stuff for python integration
        
-PyObject* KX_VertexProxy::PyGetXYZ(PyObject* self, 
+PyObject* KX_VertexProxy::PyGetXYZ(PyObject*, 
+                              PyObject*, 
+                              PyObject*)
+{
+       return PyObjectFrom(MT_Point3(m_vertex->getLocalXYZ()));
+}
+
+PyObject* KX_VertexProxy::PySetXYZ(PyObject*, 
                               PyObject* args, 
-                              PyObject* kwds)
+                              PyObject*)
 {
-       
-       MT_Point3 pos = m_vertex->getLocalXYZ();
-       
-       PyObject* resultlist = PyList_New(3);
-       int index;
-       for (index=0;index<3;index++)
+       MT_Point3 vec;
+       if (PyVecArgTo(args, vec))
        {
-               PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
+               m_vertex->SetXYZ(vec);
+       
+               Py_Return;
        }
-
-       return resultlist;
-
+       
+       return NULL;
 }
 
-PyObject* KX_VertexProxy::PySetXYZ(PyObject* self
-                              PyObject* args
-                              PyObject* kwds)
+PyObject* KX_VertexProxy::PyGetNormal(PyObject*
+                              PyObject*, 
+                              PyObject*)
 {
-
-       MT_Point3 pos = ConvertPythonVectorArg(args);
-       m_vertex->SetXYZ(pos);
-
-
-       Py_Return;
+       return PyObjectFrom(MT_Vector3(m_vertex->getNormal()));
 }
 
-PyObject* KX_VertexProxy::PyGetNormal(PyObject* self
+PyObject* KX_VertexProxy::PySetNormal(PyObject*
                               PyObject* args, 
-                              PyObject* kwds)
+                              PyObject*)
 {
-       
-       MT_Vector3 normal(m_vertex->getNormal());
-       
-       PyObject* resultlist = PyList_New(3);
-       int index;
-       for (index=0;index<3;index++)
+       MT_Vector3 vec;
+       if (PyVecArgTo(args, vec))
        {
-               PyList_SetItem(resultlist,index,PyFloat_FromDouble(normal[index]));
+               m_vertex->SetNormal(vec);
+               
+               Py_Return;
        }
-
-       return resultlist;
-
-}
-
-PyObject* KX_VertexProxy::PySetNormal(PyObject* self, 
-                              PyObject* args, 
-                              PyObject* kwds)
-{
-       MT_Point3 normal = ConvertPythonVectorArg(args);
-       m_vertex->SetNormal(normal);
-       Py_Return;
+       
+       return NULL;
 }
 
 
-PyObject* KX_VertexProxy::PyGetRGBA(PyObject* self,
-                              PyObject* args
-                              PyObject* kwds)
+PyObject* KX_VertexProxy::PyGetRGBA(PyObject*,
+                              PyObject*, 
+                              PyObject*)
 {
-       int rgba = m_vertex->getRGBA();
-       return PyInt_FromLong(rgba);
+       int *rgba = (int *) m_vertex->getRGBA();
+       return PyInt_FromLong(*rgba);
 }
 
-PyObject* KX_VertexProxy::PySetRGBA(PyObject* self
+PyObject* KX_VertexProxy::PySetRGBA(PyObject*, 
                               PyObject* args, 
-                              PyObject* kwds)
+                              PyObject*)
 {
+       float r, g, b, a;
+       if (PyArg_ParseTuple(args, "(ffff)", &r, &g, &b, &a))
+       {
+               m_vertex->SetRGBA(MT_Vector4(r, g, b, a));
+               Py_Return;
+       }
+       
        int rgba;
        if (PyArg_ParseTuple(args,"i",&rgba))
        {
                m_vertex->SetRGBA(rgba);
+               Py_Return;
        }
        Py_Return;
 }
 
 
-PyObject* KX_VertexProxy::PyGetUV(PyObject* self
-                              PyObject* args
-                              PyObject* kwds)
+PyObject* KX_VertexProxy::PyGetUV(PyObject*, 
+                              PyObject*, 
+                              PyObject*)
 {
-       MT_Vector2 uv = m_vertex->getUV1();
-       PyObject* resultlist = PyList_New(2);
-       int index;
-       for (index=0;index<2;index++)
-       {
-               PyList_SetItem(resultlist,index,PyFloat_FromDouble(uv[index]));
-       }
-
-       return resultlist;
-
+       return PyObjectFrom(MT_Vector2(m_vertex->getUV1()));
 }
 
-PyObject* KX_VertexProxy::PySetUV(PyObject* self
+PyObject* KX_VertexProxy::PySetUV(PyObject*, 
                               PyObject* args, 
-                              PyObject* kwds)
+                              PyObject*)
 {
-       MT_Point3 uv = ConvertPythonVectorArg(args);
-       m_vertex->SetUV(MT_Point2(uv[0],uv[1]));
-       Py_Return;
+       MT_Point2 vec;
+       if (PyVecArgTo(args, vec))
+       {
+               m_vertex->SetUV(vec);
+               
+               Py_Return;
+       }
+       
+       return NULL;
 }
 
 
index d5dee04..18a931e 100644 (file)
@@ -53,6 +53,12 @@ CPPFLAGS += -I../Physics/Dummy
 CPPFLAGS += -I../Physics/Sumo
 CPPFLAGS += -I../Physics/BlOde
 CPPFLAGS += -I.
+CPPFLAGS += -I../Converter
+CPPFLAGS += -I../../blender/blenkernel
+CPPFLAGS += -I../../blender/include
+CPPFLAGS += -I../../blender/makesdna
+CPPFLAGS += -I../../blender/imbuf
+CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
 
 ###########################
 
index ba60680..41f4108 100644 (file)
@@ -79,6 +79,22 @@ class BL_ActionActuator(SCA_IActuator):
                @type blendtime: float
                """
 
+       def setType(mode):
+               """
+               Sets the operation mode of the actuator
+
+               @param mode: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND
+               @type mode: integer
+               """
+
+       def getType():
+               """
+               Returns the operation mode of the actuator
+           
+               @rtype: integer
+               @return: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND
+               """
+       
        def getAction():
                """
                getAction() returns the name of the action associated with this actuator.
index d4fccc7..630b2ae 100644 (file)
@@ -8,7 +8,9 @@ Documentation for the GameLogic Module.
                - L{GameKeys}
                - L{Rasterizer}
        
-       All the other modules are accessibly through the methods in GameLogic.
+       All the other modules are accessible through the methods in GameLogic.
+       
+       See L{WhatsNew} for updates, changes and new functionality in the Game Engine Python API.
        
        Examples::
                # To get a controller:
@@ -120,6 +122,20 @@ Documentation for the GameLogic Module.
 @var KX_RANDOMACT_FLOAT_NORMAL:                See L{SCA_RandomActuator}
 @var KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL:          See L{SCA_RandomActuator}
 
+@group Action Actuator: KX_ACTIONACT_PLAY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND, KX_ACTIONACT_PROPERTY
+@var KX_ACTIONACT_PLAY:            See L{BL_ActionActuator}
+@var KX_ACTIONACT_FLIPPER:  See L{BL_ActionActuator}
+@var KX_ACTIONACT_LOOPSTOP: See L{BL_ActionActuator}
+@var KX_ACTIONACT_LOOPEND:  See L{BL_ActionActuator}
+@var KX_ACTIONACT_PROPERTY: See L{BL_ActionActuator}
+
+@group Sound Actuator: KX_SOUNDACT_PLAYSTOP, KX_SOUNDACT_PLAYEND, KX_SOUNDACT_LOOPSTOP, KX_SOUNDACT_LOOPEND, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP
+@var KX_SOUNDACT_PLAYSTOP:                 See L{KX_SoundActuator}
+@var KX_SOUNDACT_PLAYEND:                  See L{KX_SoundActuator}
+@var KKX_SOUNDACT_LOOPSTOP:                See L{KX_SoundActuator}
+@var KX_SOUNDACT_LOOPEND:                  See L{KX_SoundActuator}
+@var KX_SOUNDACT_LOOPBIDIRECTIONAL:        See L{KX_SoundActuator}
+@var KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:    See L{KX_SoundActuator}
 """
 
 
index dd9e4b0..a19e36d 100644 (file)
@@ -7,10 +7,14 @@ class KX_GameObject:
        
        Properties assigned to game objects are accessible as attributes of this class.
        
-       @ivar mass: The object's mass (provided the object has a physics controller). float. read only
+       @ivar name: The object's name.
+       @type name: string.
+       @ivar mass: The object's mass (provided the object has a physics controller). Read only.
+       @type mass: float
        @ivar parent: The object's parent object. (Read only)
        @type parent: L{KX_GameObject}
-       @ivar visible: visibility flag. boolean.
+       @ivar visible: visibility flag.
+       @type visible: boolean
        @ivar position: The object's position. 
        @type position: list [x, y, z]
        @ivar orientation: The object's orientation. 3x3 Matrix.  
index eef08a3..ef216ae 100644 (file)
@@ -6,22 +6,24 @@ class KX_SCA_AddObjectActuator(SCA_IActuator):
        """
        Edit Object Actuator (in Add Object Mode)
        
-       @warning: Add Object actuators will be ignored if at game start, the linked object doesn't exist
+       @warning: An Add Object actuator will be ignored if at game start, the linked object doesn't exist
                  (or is empty) or the linked object is in an active layer.
                  
                  This will genereate a warning in the console:
                  
                  C{ERROR: GameObject I{OBName} has a AddObjectActuator I{ActuatorName} without object (in 'nonactive' layer)}
        """
-       def setObject(name):
+       def setObject(obj):
                """
-               Sets the name of the game object to add.
+               Sets the game object to add.
                
-               A copy of the named object will be added to the scene.
+               A copy of the object will be added to the scene.
                
-               If the named object does not exist, this function is ignored.
+               If the object does not exist, this function is ignored.
                
-               @type name: string
+               obj can either be a L{KX_GameObject} or the name of an object.
+               
+               @type obj: L{KX_GameObject} or string
                """
        def getObject():
                """
index e0eae7a..eba899b 100644 (file)
@@ -27,9 +27,11 @@ class KX_SceneActuator(SCA_IActuator):
                """
        def setCamera(camera):
                """
-               Sets the name of the camera to change to.
+               Sets the camera to change to.
                
-               @type camera: string
+               Camera can be either a L{KX_Camera} or the name of the camera.
+               
+               @type camera: L{KX_Camera} or string
                """
        def getUseRestart():
                """
index 6fbdca8..072af5b 100644 (file)
@@ -127,3 +127,19 @@ class KX_SoundActuator(SCA_IActuator):
                        | o21, o22, o23 |
                        | o31, o32, o33 |
                """
+       
+       def setType(mode):
+               """
+               Sets the operation mode of the actuator.
+               
+               @param mode: KX_SOUNDACT_PLAYSTOP, KX_SOUNDACT_PLAYEND, KX_SOUNDACT_LOOPSTOP, KX_SOUNDACT_LOOPEND, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP
+               @type mode: integer
+               """
+
+       def getType():
+               """
+               Returns the operation mode of the actuator.
+               
+               @rtype: integer
+               @return:  KX_SOUNDACT_PLAYSTOP, KX_SOUNDACT_PLAYEND, KX_SOUNDACT_LOOPSTOP, KX_SOUNDACT_LOOPEND, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP
+               """
index f0333d6..8b93a82 100644 (file)
@@ -18,8 +18,8 @@ class KX_TrackToActuator(SCA_IActuator):
                """
                Sets the object to track.
                
-               @type object: string
-               @param object: the name of the object to track.
+               @type object: L{KX_GameObject} or string
+               @param object: Either a reference to a game object or the name of the object to track.
                """
        def getObject():
                """
index 2802829..8dc2752 100644 (file)
@@ -76,20 +76,20 @@ class KX_VertexProxy:
                """
                Gets the colour of this vertex.
                
-               Example:
-               # Big endian:
-               col = v.getRGBA()
-               red = (col & 0xff000000) >> 24
-               green = (col & 0xff0000) >> 16
-               blue = (col & 0xff00) >> 8
-               alpha = (col & 0xff)
+               The colour is represented as four bytes packed into an integer value.  The colour is 
+               packed as RGBA.
                
-               # Little endian:
-               col = v.getRGBA()
-               alpha = (col & 0xff000000) >> 24
-               blue = (col & 0xff0000) >> 16
-               green = (col & 0xff00) >> 8
-               red = (col & 0xff)
+               Since Python offers no way to get each byte without shifting, you must use the struct module to
+               access colour in an machine independent way.
+               
+               Because of this, it is suggested you use the r, g, b and a attributes or the colour attribute instead.
+               
+               Example::
+                       import struct;
+                       col = struct.unpack('4B', struct.pack('I', v.getRGBA()))
+                       # col = (r, g, b, a)
+                       # black = (  0,   0,   0, 255)
+                       # white = (255, 255, 255, 255)
                
                @rtype: integer
                @return: packed colour. 4 byte integer with one byte per colour channel in RGBA format.
@@ -98,8 +98,20 @@ class KX_VertexProxy:
                """
                Sets the colour of this vertex.
                
-               @type col: integer
-               @param col: the new colour of this vertex in packed format.
+               See getRGBA() for the format of col, and its relevant problems.  Use the r, g, b and a attributes
+               or the colour attribute instead.
+               
+               setRGBA() also accepts a four component list as argument col.  The list represents the colour as [r, g, b, a]
+               with black = [0.0, 0.0, 0.0, 1.0] and white = [1.0, 1.0, 1.0, 1.0]
+               
+               Example::
+                       v.setRGBA(0xff0000ff) # Red
+                       v.setRGBA(0xff00ff00) # Green on little endian, transparent purple on big endian
+                       v.setRGBA([1.0, 0.0, 0.0, 1.0]) # Red
+                       v.setRGBA([0.0, 1.0, 0.0, 1.0]) # Green on all platforms.
+               
+               @type col: integer or list [r, g, b, a]
+               @param col: the new colour of this vertex in packed RGBA format.
                """
        def getNormal():
                """
diff --git a/source/gameengine/PyDoc/WhatsNew.py b/source/gameengine/PyDoc/WhatsNew.py
new file mode 100644 (file)
index 0000000..5e16f08
--- /dev/null
@@ -0,0 +1,19 @@
+# $Id$
+"""
+New Python Functionality in this Version of Blender
+===================================================
+
+This document lists what has been changed in the Game Engine Python API.
+
+Blender 2.34
+------------
+
+       - Added getType() and setType() to L{BL_ActionActuator} and L{KX_SoundActuator} (sgefant)
+       - New Scene module: L{KX_Scene}
+       - New Camera module: L{KX_Camera}
+       - New Light module: L{KX_Light}
+       - Added attributes to L{KX_GameObject}, L{KX_VertexProxy}
+       - L{KX_SCA_AddObjectActuator}.setObject(), L{KX_TrackToActuator}.setObject() and 
+         L{KX_SceneActuator}.setCamera() now accept L{KX_GameObject}s as parameters
+
+"""