Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / source / gameengine / Ketsji / KX_GameObject.cpp
index 577f767..a02fd9c 100644 (file)
@@ -46,6 +46,7 @@ typedef unsigned long uint_ptr;
 
 
 #define KX_INERTIA_INFINITE 10000
+#include "BLI_arithb.h"
 #include "RAS_IPolygonMaterial.h"
 #include "KX_BlenderMaterial.h"
 #include "KX_GameObject.h"
@@ -66,6 +67,7 @@ typedef unsigned long uint_ptr;
 #include "KX_PythonInit.h"
 #include "KX_PyMath.h"
 #include "KX_PythonSeq.h"
+#include "KX_ConvertPhysicsObject.h"
 #include "SCA_IActuator.h"
 #include "SCA_ISensor.h"
 #include "SCA_IController.h"
@@ -86,10 +88,8 @@ static MT_Matrix3x3 dummy_orientation = MT_Matrix3x3(        1.0, 0.0, 0.0,
 
 KX_GameObject::KX_GameObject(
        void* sgReplicationInfo,
-       SG_Callbacks callbacks,
-       PyTypeObject* T
-) : 
-       SCA_IObject(T),
+       SG_Callbacks callbacks)
+       : SCA_IObject(),
        m_bDyna(false),
        m_layer(0),
        m_pBlenderObject(NULL),
@@ -102,7 +102,6 @@ KX_GameObject::KX_GameObject(
        m_bOccluder(false),
        m_pPhysicsController1(NULL),
        m_pGraphicController(NULL),
-       m_pPhysicsEnvironment(NULL),
        m_xray(false),
        m_pHitObject(NULL),
        m_isDeformable(false),
@@ -456,6 +455,22 @@ double*    KX_GameObject::GetOpenGLMatrix()
        return fl;
 }
 
+void KX_GameObject::UpdateBlenderObjectMatrix(Object* blendobj)
+{
+       if (!blendobj)
+               blendobj = m_pBlenderObject;
+       if (blendobj) {
+               const MT_Matrix3x3& rot = NodeGetWorldOrientation();
+               const MT_Vector3& scale = NodeGetWorldScaling();
+               const MT_Vector3& pos = NodeGetWorldPosition();
+               rot.getValue(blendobj->obmat[0]);
+               pos.getValue(blendobj->obmat[3]);
+               VecMulf(blendobj->obmat[0], scale[0]);
+               VecMulf(blendobj->obmat[1], scale[1]);
+               VecMulf(blendobj->obmat[2], scale[2]);
+       }
+}
+
 void KX_GameObject::AddMeshUser()
 {
        for (size_t i=0;i<m_meshes.size();i++)
@@ -466,7 +481,7 @@ void KX_GameObject::AddMeshUser()
        double* fl = GetOpenGLMatrixPtr()->getPointer();
 
        SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
-       RAS_MeshSlot* ms;
+//     RAS_MeshSlot* ms;
        for(mit.begin(); !mit.end(); ++mit)
        {
                (*mit)->m_OpenGLMatrix = fl;
@@ -1385,12 +1400,13 @@ PyMethodDef KX_GameObject::Methods[] = {
        {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS},
        {"setOcclusion",(PyCFunction) KX_GameObject::sPySetOcclusion, METH_VARARGS},
        {"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS},
-       {"getChildren", (PyCFunction)KX_GameObject::sPyGetChildren,METH_NOARGS},
-       {"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS},
+
+
        {"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS},
        {"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS},
-       {"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_O},
+       {"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_VARARGS},
        {"endObject",(PyCFunction) KX_GameObject::sPyEndObject, METH_NOARGS},
+       {"reinstancePhysicsMesh", (PyCFunction)KX_GameObject::sPyReinstancePhysicsMesh,METH_VARARGS},
        
        KX_PYMETHODTABLE(KX_GameObject, rayCastTo),
        KX_PYMETHODTABLE(KX_GameObject, rayCast),
@@ -1399,21 +1415,8 @@ PyMethodDef KX_GameObject::Methods[] = {
        KX_PYMETHODTABLE(KX_GameObject, sendMessage),
        
        // dict style access for props
-       {"has_key",(PyCFunction) KX_GameObject::sPyhas_key, METH_O},
        {"get",(PyCFunction) KX_GameObject::sPyget, METH_VARARGS},
        
-       // deprecated
-       {"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_NOARGS},
-       {"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O},
-       {"setWorldPosition", (PyCFunction) KX_GameObject::sPySetWorldPosition, METH_O},
-       {"getOrientation", (PyCFunction) KX_GameObject::sPyGetOrientation, METH_NOARGS},
-       {"setOrientation", (PyCFunction) KX_GameObject::sPySetOrientation, METH_O},
-       {"getState",(PyCFunction) KX_GameObject::sPyGetState, METH_NOARGS},
-       {"setState",(PyCFunction) KX_GameObject::sPySetState, METH_O},
-       {"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_NOARGS},
-       {"getVisible",(PyCFunction) KX_GameObject::sPyGetVisible, METH_NOARGS},
-       {"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_NOARGS},
-       {"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS},
        {NULL,NULL} //Sentinel
 };
 
@@ -1466,15 +1469,21 @@ bool KX_GameObject::ConvertPythonVectorArgs(PyObject* args,
 }
 */
 
-PyObject* KX_GameObject::PyReplaceMesh(PyObject* value)
+PyObject* KX_GameObject::PyReplaceMesh(PyObject* args)
 {
        KX_Scene *scene = KX_GetActiveScene();
-       RAS_MeshObject* new_mesh;
+       
+       PyObject *value;
+       int use_gfx= 1, use_phys= 0;
+       RAS_MeshObject *new_mesh;
+       
+       if (!PyArg_ParseTuple(args,"O|ii:replaceMesh", &value, &use_gfx, &use_phys))
+               return NULL;
        
        if (!ConvertPythonToMesh(value, &new_mesh, false, "gameOb.replaceMesh(value): KX_GameObject"))
                return NULL;
        
-       scene->ReplaceMesh(this, new_mesh);
+       scene->ReplaceMesh(this, new_mesh, (bool)use_gfx, (bool)use_phys);
        Py_RETURN_NONE;
 }
 
@@ -1488,17 +1497,32 @@ PyObject* KX_GameObject::PyEndObject()
 
 }
 
-
-PyObject* KX_GameObject::PyGetPosition()
+PyObject* KX_GameObject::PyReinstancePhysicsMesh(PyObject* args)
 {
-       ShowDeprecationWarning("getPosition()", "the position property");
-       return PyObjectFrom(NodeGetWorldPosition());
+       KX_GameObject *gameobj= NULL;
+       RAS_MeshObject *mesh= NULL;
+       
+       PyObject *gameobj_py= NULL;
+       PyObject *mesh_py= NULL;
+
+       if (    !PyArg_ParseTuple(args,"|OO:reinstancePhysicsMesh",&gameobj_py, &mesh_py) ||
+                       (gameobj_py && !ConvertPythonToGameObject(gameobj_py, &gameobj, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject")) || 
+                       (mesh_py && !ConvertPythonToMesh(mesh_py, &mesh, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject"))
+               ) {
+               return NULL;
+       }
+       
+       /* gameobj and mesh can be NULL */
+       if(KX_ReInstanceBulletShapeFromMesh(this, gameobj, mesh))
+               Py_RETURN_TRUE;
+
+       Py_RETURN_FALSE;
 }
 
 static PyObject *Map_GetItem(PyObject *self_v, PyObject *item)
 {
        KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(self_v);
-       const char *attr_str= PyString_AsString(item);
+       const char *attr_str= _PyUnicode_AsString(item);
        CValue* resultattr;
        PyObject* pyconvert;
        
@@ -1532,7 +1556,7 @@ static PyObject *Map_GetItem(PyObject *self_v, PyObject *item)
 static int Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val)
 {
        KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(self_v);
-       const char *attr_str= PyString_AsString(key);
+       const char *attr_str= _PyUnicode_AsString(key);
        if(attr_str==NULL)
                PyErr_Clear();
        
@@ -1564,7 +1588,7 @@ static int Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val)
                int set= 0;
                
                /* as CValue */
-               if(attr_str && BGE_PROXY_CHECK_TYPE(val)==0) /* dont allow GameObjects for eg to be assigned to CValue props */
+               if(attr_str && PyObject_TypeCheck(val, &PyObjectPlus::Type)==0) /* dont allow GameObjects for eg to be assigned to CValue props */
                {
                        CValue* vallie = self->ConvertPythonToValue(val, ""); /* error unused */
                        
@@ -1626,7 +1650,7 @@ static int Seq_Contains(PyObject *self_v, PyObject *value)
                return -1;
        }
        
-       if(PyString_Check(value) && self->GetProperty(PyString_AsString(value)))
+       if(PyUnicode_Check(value) && self->GetProperty(_PyUnicode_AsString(value)))
                return 1;
        
        if (self->m_attr_dict && PyDict_GetItem(self->m_attr_dict, value))
@@ -1654,50 +1678,37 @@ PySequenceMethods KX_GameObject::Sequence = {
 };
 
 PyTypeObject KX_GameObject::Type = {
-#if (PY_VERSION_HEX >= 0x02060000)
        PyVarObject_HEAD_INIT(NULL, 0)
-#else
-       /* python 2.5 and below */
-       PyObject_HEAD_INIT( NULL )  /* required py macro */
-       0,                          /* ob_size */
-#endif
-               "KX_GameObject",
-               sizeof(PyObjectPlus_Proxy),
-               0,
-               py_base_dealloc,
-               0,
-               0,
-               0,
-               0,
-               py_base_repr,
-               0,
-               &Sequence,
-               &Mapping,
-               0,0,0,
-               py_base_getattro,
-               py_base_setattro,
-               0,
-               Py_TPFLAGS_DEFAULT,
-               0,0,0,0,0,0,0,
-               Methods
-};
-
-
-
-
-
-
-PyParentObject KX_GameObject::Parents[] = {
-       &KX_GameObject::Type,
-               &SCA_IObject::Type,
-               &CValue::Type,
-               NULL
+       "KX_GameObject",
+       sizeof(PyObjectPlus_Proxy),
+       0,
+       py_base_dealloc,
+       0,
+       0,
+       0,
+       0,
+       py_base_repr,
+       0,
+       &Sequence,
+       &Mapping,
+       0,0,0,
+       NULL,
+       NULL,
+       0,
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+       0,0,0,0,0,0,0,
+       Methods,
+       0,
+       0,
+       &SCA_IObject::Type,
+       0,0,0,0,0,0,
+       py_base_new
 };
 
 PyObject* KX_GameObject::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
-       return PyString_FromString(self->GetName().ReadPtr());
+       return PyUnicode_FromString(self->GetName().ReadPtr());
 }
 
 PyObject* KX_GameObject::pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
@@ -1803,10 +1814,10 @@ int KX_GameObject::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *at
 
 PyObject* KX_GameObject::pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
-       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
 #ifdef USE_MATHUTILS
-       return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_GLOBAL);
+       return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_GLOBAL);
 #else
+       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
        return PyObjectFrom(self->NodeGetWorldPosition());
 #endif
 }
@@ -1825,10 +1836,10 @@ int KX_GameObject::pyattr_set_worldPosition(void *self_v, const KX_PYATTRIBUTE_D
 
 PyObject* KX_GameObject::pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
-       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
 #ifdef USE_MATHUTILS   
-       return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_LOCAL);
+       return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_LOCAL);
 #else  
+       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
        return PyObjectFrom(self->NodeGetLocalPosition());
 #endif
 }
@@ -1847,10 +1858,10 @@ int KX_GameObject::pyattr_set_localPosition(void *self_v, const KX_PYATTRIBUTE_D
 
 PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
-       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
 #ifdef USE_MATHUTILS
-       return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_INERTIA_LOCAL);
+       return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_INERTIA_LOCAL);
 #else
+       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
        if (self->GetPhysicsController())
                return PyObjectFrom(self->GetPhysicsController()->GetLocalInertia());
        return Py_BuildValue("fff", 0.0f, 0.0f, 0.0f);
@@ -1860,7 +1871,7 @@ PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIB
 PyObject* KX_GameObject::pyattr_get_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 #ifdef USE_MATHUTILS
-       return newMatrixObject_cb((PyObject *)self_v, 3, 3, mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_GLOBAL);
+       return newMatrixObject_cb(BGE_PROXY_FROM_REF(self_v), 3, 3, mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_GLOBAL);
 #else
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
        return PyObjectFrom(self->NodeGetWorldOrientation());
@@ -1885,7 +1896,7 @@ int KX_GameObject::pyattr_set_worldOrientation(void *self_v, const KX_PYATTRIBUT
 PyObject* KX_GameObject::pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 #ifdef USE_MATHUTILS
-       return newMatrixObject_cb((PyObject *)self_v, 3, 3, mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_LOCAL);
+       return newMatrixObject_cb(BGE_PROXY_FROM_REF(self_v), 3, 3, mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_LOCAL);
 #else
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
        return PyObjectFrom(self->NodeGetLocalOrientation());
@@ -1908,21 +1919,21 @@ int KX_GameObject::pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUT
 
 PyObject* KX_GameObject::pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
-       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
 #ifdef USE_MATHUTILS
-       return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_GLOBAL);
+       return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_GLOBAL);
 #else
+       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
        return PyObjectFrom(self->NodeGetWorldScaling());
 #endif
 }
 
 PyObject* KX_GameObject::pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
-       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
 #ifdef USE_MATHUTILS
-       return newVectorObject_cb((PyObject *)self_v, 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_LOCAL);
+       return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_LOCAL);
 #else
-       return PyObjectFrom(self->NodeGetLocalScale());
+       KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
+       return PyObjectFrom(self->NodeGetLocalScaling());
 #endif
 }
 
@@ -1970,13 +1981,13 @@ PyObject* KX_GameObject::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
        int state = 0;
        state |= self->GetState();
-       return PyInt_FromLong(state);
+       return PyLong_FromSsize_t(state);
 }
 
 int KX_GameObject::pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
 {
        KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
-       int state_i = PyInt_AsLong(value);
+       int state_i = PyLong_AsSsize_t(value);
        unsigned int state = 0;
        
        if (state_i == -1 && PyErr_Occurred()) {
@@ -2047,128 +2058,6 @@ PyObject* KX_GameObject::pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_
        return self->m_attr_dict;
 }
 
-/* We need these because the macros have a return in them */
-PyObject* KX_GameObject::py_getattro__internal(PyObject *attr)
-{
-       py_getattro_up(SCA_IObject);
-}
-
-int KX_GameObject::py_setattro__internal(PyObject *attr, PyObject *value)      // py_setattro method
-{
-       py_setattro_up(SCA_IObject);
-}
-
-
-PyObject* KX_GameObject::py_getattro(PyObject *attr)
-{
-       PyObject *object= py_getattro__internal(attr);
-       
-       if (object==NULL && m_attr_dict)
-       {
-               /* backup the exception incase the attr doesnt exist in the dict either */
-               PyObject *err_type, *err_value, *err_tb;
-               PyErr_Fetch(&err_type, &err_value, &err_tb);
-               
-               object= PyDict_GetItem(m_attr_dict, attr);
-               if (object) {
-                       Py_INCREF(object);
-                       
-                       PyErr_Clear();
-                       Py_XDECREF( err_type );
-                       Py_XDECREF( err_value );
-                       Py_XDECREF( err_tb );
-               }
-               else {
-                       PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */
-               }
-       }
-       return object;
-}
-
-PyObject* KX_GameObject::py_getattro_dict() {
-       //py_getattro_dict_up(SCA_IObject);
-       PyObject *dict= py_getattr_dict(SCA_IObject::py_getattro_dict(), Type.tp_dict);
-       if(dict==NULL)
-               return NULL;
-       
-       /* normally just return this but KX_GameObject has some more items */
-
-       
-       /* Not super fast getting as a list then making into dict keys but its only for dir() */
-       PyObject *list= ConvertKeysToPython();
-       if(list)
-       {
-               int i;
-               for(i=0; i<PyList_Size(list); i++)
-                       PyDict_SetItem(dict, PyList_GET_ITEM(list, i), Py_None);
-       }
-       else
-               PyErr_Clear();
-       
-       Py_DECREF(list);
-       
-       /* Add m_attr_dict if we have it */
-       if(m_attr_dict)
-               PyDict_Update(dict, m_attr_dict);
-       
-       return dict;
-}
-
-int KX_GameObject::py_setattro(PyObject *attr, PyObject *value)        // py_setattro method
-{
-       int ret= py_setattro__internal(attr, value);
-       
-       if (ret==PY_SET_ATTR_SUCCESS) {
-               /* remove attribute in our own dict to avoid double ups */
-               /* NOTE: Annoying that we also do this for setting builtin attributes like mass and visibility :/ */
-               if (m_attr_dict) {
-                       if (PyDict_DelItem(m_attr_dict, attr) != 0)
-                               PyErr_Clear();
-               }
-       }
-       
-       if (ret==PY_SET_ATTR_COERCE_FAIL) {
-               /* CValue attribute exists, remove CValue and add PyDict value */
-               RemoveProperty(PyString_AsString(attr));
-               ret= PY_SET_ATTR_MISSING;
-       }
-       
-       if (ret==PY_SET_ATTR_MISSING) {
-               /* Lazy initialization */
-               if (m_attr_dict==NULL)
-                       m_attr_dict = PyDict_New();
-               
-               if (PyDict_SetItem(m_attr_dict, attr, value)==0) {
-                       PyErr_Clear();
-                       ret= PY_SET_ATTR_SUCCESS;
-               }
-               else {
-                       PyErr_Format(PyExc_AttributeError, "gameOb.myAttr = value: KX_GameObject, failed assigning value to internal dictionary");
-                       ret= PY_SET_ATTR_FAIL;
-               }
-       }
-       
-       return ret;     
-}
-
-
-int    KX_GameObject::py_delattro(PyObject *attr)
-{
-       ShowDeprecationWarning("del ob.attr", "del ob['attr'] for user defined properties");
-       
-       char *attr_str= PyString_AsString(attr); 
-       
-       if (RemoveProperty(attr_str)) // XXX - should call CValues instead but its only 2 lines here
-               return PY_SET_ATTR_SUCCESS;
-       
-       if (m_attr_dict && (PyDict_DelItem(m_attr_dict, attr) == 0))
-               return PY_SET_ATTR_SUCCESS;
-       
-       PyErr_Format(PyExc_AttributeError, "del gameOb.myAttr: KX_GameObject, attribute \"%s\" dosnt exist", attr_str);
-       return PY_SET_ATTR_MISSING;
-}
-
-
 PyObject* KX_GameObject::PyApplyForce(PyObject* args)
 {
        int local = 0;
@@ -2309,41 +2198,6 @@ PyObject* KX_GameObject::PySetOcclusion(PyObject* args)
        Py_RETURN_NONE;
 }
 
-PyObject* KX_GameObject::PyGetVisible()
-{
-       ShowDeprecationWarning("getVisible()", "the visible property");
-       return PyInt_FromLong(m_bVisible);      
-}
-
-PyObject* KX_GameObject::PyGetState()
-{
-       ShowDeprecationWarning("getState()", "the state property");
-       int state = 0;
-       state |= GetState();
-       return PyInt_FromLong(state);
-}
-
-PyObject* KX_GameObject::PySetState(PyObject* value)
-{
-       ShowDeprecationWarning("setState()", "the state property");
-       int state_i = PyInt_AsLong(value);
-       unsigned int state = 0;
-       
-       if (state_i == -1 && PyErr_Occurred()) {
-               PyErr_SetString(PyExc_TypeError, "expected an int bit field");
-               return NULL;
-       }
-       
-       state |= state_i;
-       if ((state & ((1<<30)-1)) == 0) {
-               PyErr_SetString(PyExc_AttributeError, "The state bitfield was not between 0 and 30 (1<<0 and 1<<29)");
-               return NULL;
-       }
-       SetState(state);
-       
-       Py_RETURN_NONE;
-}
-
 PyObject* KX_GameObject::PyGetVelocity(PyObject* args)
 {
        // only can get the velocity if we have a physics object connected to us...
@@ -2362,14 +2216,6 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* args)
        }
 }
 
-
-
-PyObject* KX_GameObject::PyGetMass()
-{
-       ShowDeprecationWarning("getMass()", "the mass property");
-       return PyFloat_FromDouble((GetPhysicsController() != NULL) ? GetPhysicsController()->GetMass() : 0.0f);
-}
-
 PyObject* KX_GameObject::PyGetReactionForce()
 {
        // only can get the velocity if we have a physics object connected to us...
@@ -2406,18 +2252,6 @@ PyObject* KX_GameObject::PyDisableRigidBody()
 }
 
 
-
-PyObject* KX_GameObject::PyGetParent()
-{
-       ShowDeprecationWarning("getParent()", "the parent property");
-       KX_GameObject* parent = this->GetParent();
-       if (parent) {
-               parent->Release(); /* self->GetParent() AddRef's */
-               return parent->GetProxy();
-       }
-       Py_RETURN_NONE;
-}
-
 PyObject* KX_GameObject::PySetParent(PyObject* args)
 {
        KX_Scene *scene = KX_GetActiveScene();
@@ -2443,41 +2277,6 @@ PyObject* KX_GameObject::PyRemoveParent()
        Py_RETURN_NONE;
 }
 
-PyObject* KX_GameObject::PyGetChildren()
-{
-       ShowDeprecationWarning("getChildren()", "the children property");
-       
-       return GetChildren()->NewProxy(true);
-}
-
-PyObject* KX_GameObject::PyGetChildrenRecursive()
-{
-       ShowDeprecationWarning("getChildrenRecursive()", "the childrenRecursive property");
-       
-       return GetChildrenRecursive()->NewProxy(true);
-}
-
-PyObject* KX_GameObject::PyGetMesh(PyObject* args)
-{
-       ShowDeprecationWarning("getMesh()", "the meshes property (now a list of meshes)");
-       
-       int mesh = 0;
-
-       if (!PyArg_ParseTuple(args, "|i:getMesh", &mesh))
-               return NULL; // python sets a simple error
-       
-       if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0)
-       {
-               KX_MeshProxy* meshproxy = new KX_MeshProxy(m_meshes[mesh]);
-               return meshproxy->NewProxy(true); // XXX Todo Python own.
-       }
-       
-       Py_RETURN_NONE;
-}
-
-
-
-
 
 PyObject* KX_GameObject::PySetCollisionMargin(PyObject* value)
 {
@@ -2541,29 +2340,6 @@ PyObject* KX_GameObject::PyRestoreDynamics()
 }
 
 
-
-PyObject* KX_GameObject::PyGetOrientation() //keywords
-{
-       ShowDeprecationWarning("getOrientation()", "the orientation property");
-       return PyObjectFrom(NodeGetWorldOrientation());
-}
-
-
-
-PyObject* KX_GameObject::PySetOrientation(PyObject* value)
-{
-       ShowDeprecationWarning("setOrientation()", "the orientation property");
-       MT_Matrix3x3 rot;
-       
-       /* if value is not a sequence PyOrientationTo makes an error */
-       if (!PyOrientationTo(value, rot, "gameOb.setOrientation(sequence): KX_GameObject, "))
-               return NULL;
-
-       NodeSetLocalOrientation(rot);
-       NodeUpdateGS(0.f);
-       Py_RETURN_NONE;
-}
-
 PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* args)
 {
        PyObject* pyvect;
@@ -2596,33 +2372,6 @@ PyObject* KX_GameObject::PyGetAxisVect(PyObject* value)
        return NULL;
 }
 
-PyObject* KX_GameObject::PySetPosition(PyObject* value)
-{
-       ShowDeprecationWarning("setPosition()", "the localPosition property");
-       MT_Point3 pos;
-       if (PyVecTo(value, pos))
-       {
-               NodeSetLocalPosition(pos);
-               NodeUpdateGS(0.f);
-               Py_RETURN_NONE;
-       }
-
-       return NULL;
-}
-
-PyObject* KX_GameObject::PySetWorldPosition(PyObject* value)
-{
-       ShowDeprecationWarning("setWorldPosition()", "the worldPosition property");
-       MT_Point3 pos;
-       if (PyVecTo(value, pos))
-       {
-               NodeSetWorldPosition(pos);
-               NodeUpdateGS(0.f);
-               Py_RETURN_NONE;
-       }
-
-       return NULL;
-}
 
 PyObject* KX_GameObject::PyGetPhysicsId()
 {
@@ -2632,7 +2381,7 @@ PyObject* KX_GameObject::PyGetPhysicsId()
        {
                physid= (uint_ptr)ctrl->GetUserData();
        }
-       return PyInt_FromLong((long)physid);
+       return PyLong_FromSsize_t((long)physid);
 }
 
 PyObject* KX_GameObject::PyGetPropertyNames()
@@ -2788,14 +2537,11 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
                }
        }
        MT_Point3 fromPoint = NodeGetWorldPosition();
+       
        if (dist != 0.0f)
-       {
-               MT_Vector3 toDir = toPoint-fromPoint;
-               toDir.normalize();
-               toPoint = fromPoint + (dist) * toDir;
-       }
-
-       PHY_IPhysicsEnvironment* pe = GetPhysicsEnvironment();
+               toPoint = fromPoint + dist * (toPoint-fromPoint).safe_normalized();
+       
+       PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment();
        KX_IPhysicsController *spc = GetPhysicsController();
        KX_GameObject *parent = GetParent();
        if (!spc && parent)
@@ -2922,7 +2668,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
                return none_tuple_3();
        }
        
-       PHY_IPhysicsEnvironment* pe = GetPhysicsEnvironment();
+       PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment();
        KX_IPhysicsController *spc = GetPhysicsController();
        KX_GameObject *parent = GetParent();
        if (!spc && parent)
@@ -2987,7 +2733,7 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage,
        char* to = (char *)"";
        const STR_String& from = GetName();
 
-       if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to))
+       if (!PyArg_ParseTuple(args, "s|ss:sendMessage", &subject, &body, &to))
                return NULL;
        
        scene->GetNetworkScene()->SendMessage(to, from, subject, body);
@@ -3008,8 +2754,8 @@ PyObject* KX_GameObject::Pyget(PyObject *args)
                return NULL;
        
        
-       if(PyString_Check(key)) {
-               CValue *item = GetProperty(PyString_AsString(key));
+       if(PyUnicode_Check(key)) {
+               CValue *item = GetProperty(_PyUnicode_AsString(key));
                if (item) {
                        ret = item->ConvertValueToPython();
                        if(ret)
@@ -3028,14 +2774,6 @@ PyObject* KX_GameObject::Pyget(PyObject *args)
        return def;
 }
 
-/* Matches python dict.has_key() */
-PyObject* KX_GameObject::Pyhas_key(PyObject* value)
-{
-       // the ONLY error case is invalid data, this is checked by the macro'd static function
-       // that calls this one. but make sure Seq_Contains doesnt add extra errors later on.
-       return PyBool_FromLong(Seq_Contains((PyObject *)this, value));
-}
-
 /* --------------------------------------------------------------------- 
  * Some stuff taken from the header
  * --------------------------------------------------------------------- */
@@ -3078,13 +2816,13 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py
                }
        }
        
-       if (PyString_Check(value)) {
-               *object = (KX_GameObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String( PyString_AsString(value) ));
+       if (PyUnicode_Check(value)) {
+               *object = (KX_GameObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String( _PyUnicode_AsString(value) ));
                
                if (*object) {
                        return true;
                } else {
-                       PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_GameObject in this scene", error_prefix, PyString_AsString(value));
+                       PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_GameObject in this scene", error_prefix, _PyUnicode_AsString(value));
                        return false;
                }
        }