NLA SoC: Merge from 2.5
[blender.git] / source / gameengine / Converter / BL_ActionActuator.cpp
index 0c7b99df3879cf21914e2126f119f9f716ce1718..bed99a4f5028cdf13fb470701aaf7a1a202ea4b8 100644 (file)
 #include <config.h>
 #endif
 
+extern "C" {
+#include "BKE_animsys.h"
+#include "BKE_action.h"
+#include "RNA_access.h"
+#include "RNA_define.h"
+}
+
 BL_ActionActuator::~BL_ActionActuator()
 {
        if (m_pose)
@@ -360,10 +367,31 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
                        
                        /* Get the underlying pose from the armature */
                        obj->GetPose(&m_pose);
-                       
+
+// 2.4x function, 
                        /* Override the necessary channels with ones from the action */
                        // XXX extract_pose_from_action(m_pose, m_action, m_localtime);
+                       
+                       
+// 2.5x - replacement for extract_pose_from_action(...) above.
+                       {
+                               struct PointerRNA id_ptr;
+                               Object *arm= obj->GetArmatureObject();
+                               bPose *pose_back= arm->pose;
+                               
+                               arm->pose= m_pose;
+                               RNA_id_pointer_create((ID *)arm, &id_ptr);
+                               animsys_evaluate_action(&id_ptr, m_action, NULL, m_localtime);
+                               
+                               arm->pose= pose_back;
+                       
+// 2.5x - could also do this but looks too high level, constraints use this, it works ok.
+//                             Object workob; /* evaluate using workob */
+//                             what_does_obaction((Scene *)obj->GetScene(), obj->GetArmatureObject(), &workob, m_pose, m_action, NULL, m_localtime);
+                       }
 
+                       // done getting the pose from the action
+                       
                        /* Perform the user override (if any) */
                        if (m_userpose){
                                extract_pose_from_pose(m_pose, m_userpose);
@@ -381,7 +409,7 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
                                
                                /* Find percentages */
                                newweight = (m_blendframe/(float)m_blendin);
-                               // XXX blend_poses(m_pose, m_blendpose, 1.0 - newweight, ACTSTRIPMODE_BLEND);
+                               game_blend_poses(m_pose, m_blendpose, 1.0 - newweight);
 
                                /* Increment current blending percentage */
                                m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
@@ -418,7 +446,7 @@ PyObject* BL_ActionActuator::PyGetAction(PyObject* args,
        ShowDeprecationWarning("getAction()", "the action property");
 
        if (m_action){
-               return PyString_FromString(m_action->id.name+2);
+               return PyUnicode_FromString(m_action->id.name+2);
        }
        Py_RETURN_NONE;
 }
@@ -768,7 +796,7 @@ PyObject* BL_ActionActuator::PySetFrameProperty(PyObject* args,
 }
 
 PyObject* BL_ActionActuator::PyGetChannel(PyObject* value) {
-       char *string= PyString_AsString(value);
+       char *string= _PyUnicode_AsString(value);
        
        if (!string) {
                PyErr_SetString(PyExc_TypeError, "expected a single string");
@@ -860,7 +888,7 @@ PyObject* BL_ActionActuator::PySetType(PyObject* args,
 PyObject* BL_ActionActuator::PyGetContinue() {
        ShowDeprecationWarning("getContinue()", "the continue property");
 
-    return PyInt_FromLong((long)(m_end_reset==0));
+    return PyLong_FromSsize_t((long)(m_end_reset==0));
 }
 
 PyObject* BL_ActionActuator::PySetContinue(PyObject* value) {
@@ -934,9 +962,9 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
        else {
                MT_Vector3 loc;
                MT_Vector3 size;
-               MT_Vector4 quat;
+               MT_Quaternion quat;
                
-               if (!PyVecTo(pyloc, loc) || !PyVecTo(pysize, size) || !PyVecTo(pyquat, quat))
+               if (!PyVecTo(pyloc, loc) || !PyVecTo(pysize, size) || !PyQuatTo(pyquat, quat))
                        return NULL;
                
                // same as above
@@ -949,7 +977,7 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
                // for some reason loc.setValue(pchan->loc) fails
                pchan->loc[0]= loc[0]; pchan->loc[1]= loc[1]; pchan->loc[2]= loc[2];
                pchan->size[0]= size[0]; pchan->size[1]= size[1]; pchan->size[2]= size[2];
-               pchan->quat[0]= quat[0]; pchan->quat[1]= quat[1]; pchan->quat[2]= quat[2]; pchan->quat[3]= quat[3];
+               pchan->quat[0]= quat[3]; pchan->quat[1]= quat[0]; pchan->quat[2]= quat[1]; pchan->quat[3]= quat[2]; /* notice xyzw -> wxyz is intentional */
        }
        
        pchan->flag |= POSE_ROT|POSE_LOC|POSE_SIZE;
@@ -977,19 +1005,15 @@ PyTypeObject BL_ActionActuator::Type = {
                0,
                0,
                py_base_repr,
-               0,0,0,0,0,0,
-               py_base_getattro,
-               py_base_setattro,
                0,0,0,0,0,0,0,0,0,
-               Methods
-};
-
-PyParentObject BL_ActionActuator::Parents[] = {
-       &BL_ActionActuator::Type,
+               Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+               0,0,0,0,0,0,0,
+               Methods,
+               0,
+               0,
                &SCA_IActuator::Type,
-               &SCA_ILogicBrick::Type,
-               &CValue::Type,
-               NULL
+               0,0,0,0,0,0,
+               py_base_new
 };
 
 PyMethodDef BL_ActionActuator::Methods[] = {
@@ -1037,37 +1061,24 @@ PyAttributeDef BL_ActionActuator::Attributes[] = {
        { NULL }        //Sentinel
 };
 
-PyObject* BL_ActionActuator::py_getattro(PyObject *attr) {
-       py_getattro_up(SCA_IActuator);
-}
-
-PyObject* BL_ActionActuator::py_getattro_dict() {
-       py_getattro_dict_up(SCA_IActuator);
-}
-
-int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) {
-       py_setattro_up(SCA_IActuator);
-}
-
-
 PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
        BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
-       return PyString_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
+       return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
 }
 
 int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
 {
        BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
        
-       if (!PyString_Check(value))
+       if (!PyUnicode_Check(value))
        {
                PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action");
                return PY_SET_ATTR_FAIL;
        }
 
        bAction *action= NULL;
-       STR_String val = PyString_AsString(value);
+       STR_String val = _PyUnicode_AsString(value);
        
        if (val != "")
        {