diff options
Diffstat (limited to 'source/gameengine/Ketsji')
27 files changed, 489 insertions, 47 deletions
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index 3af8f765251..1cfab87d78b 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -42,7 +42,7 @@ KX_NetworkMessageActuator::KX_NetworkMessageActuator( const STR_String &subject, int bodyType, const STR_String &body) : - SCA_IActuator(gameobj), + SCA_IActuator(gameobj, KX_ACT_MESSAGE), m_networkscene(networkscene), m_toPropName(toPropName), m_subject(subject), diff --git a/source/gameengine/Ketsji/KX_ArmatureSensor.cpp b/source/gameengine/Ketsji/KX_ArmatureSensor.cpp new file mode 100644 index 00000000000..1b759bda28e --- /dev/null +++ b/source/gameengine/Ketsji/KX_ArmatureSensor.cpp @@ -0,0 +1,205 @@ +/** + * Armature sensor + * + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "DNA_action_types.h" +#include "DNA_constraint_types.h" +#include "BKE_constraint.h" +#include "DNA_sensor_types.h" + +#include "BL_ArmatureObject.h" +#include "KX_ArmatureSensor.h" +#include "SCA_EventManager.h" +#include "SCA_LogicManager.h" + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +KX_ArmatureSensor::KX_ArmatureSensor(class SCA_EventManager* eventmgr, + SCA_IObject* gameobj, + const char *posechannel, + const char *constraintname, + int type, + float value) + : SCA_ISensor(gameobj,eventmgr), + m_constraint(NULL), + m_posechannel(posechannel), + m_constraintname(constraintname), + m_type(type), + m_value(value) +{ + FindConstraint(); +} + +void KX_ArmatureSensor::Init() +{ + m_lastresult = m_invert?true:false; + m_result = false; + m_reset = true; +} + +void KX_ArmatureSensor::FindConstraint() +{ + m_constraint = NULL; + + if (m_gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) { + BL_ArmatureObject* armobj = (BL_ArmatureObject*)m_gameobj; + // get the persistent pose structure + bPose* pose = armobj->GetOrigPose(); + bPoseChannel* pchan; + bConstraint* pcon; + // and locate the constraint + for (pchan = (bPoseChannel*)pose->chanbase.first; pchan; pchan=(bPoseChannel*)pchan->next) { + if (!strcmp(pchan->name, m_posechannel)) { + // now locate the constraint + for (pcon = (bConstraint*)pchan->constraints.first; pcon; pcon=(bConstraint*)pcon->next) { + if (!strcmp(pcon->name, m_constraintname)) { + if (pcon->flag & CONSTRAINT_DISABLE) + /* this constraint is not valid, can't use it */ + break; + m_constraint = pcon; + break; + } + } + break; + } + } + } +} + + +CValue* KX_ArmatureSensor::GetReplica() +{ + KX_ArmatureSensor* replica = new KX_ArmatureSensor(*this); + // m_range_expr must be recalculated on replica! + replica->ProcessReplica(); + return replica; +} + +void KX_ArmatureSensor::ReParent(SCA_IObject* parent) +{ + SCA_ISensor::ReParent(parent); + // must remap the constraint + FindConstraint(); +} + +bool KX_ArmatureSensor::IsPositiveTrigger() +{ + return (m_invert) ? !m_result : m_result; +} + + +KX_ArmatureSensor::~KX_ArmatureSensor() +{ +} + +bool KX_ArmatureSensor::Evaluate() +{ + bool reset = m_reset && m_level; + + m_reset = false; + if (!m_constraint) + return false; + switch (m_type) { + case SENS_ARM_STATE_CHANGED: + m_result = !(m_constraint->flag & CONSTRAINT_OFF); + break; + case SENS_ARM_LIN_ERROR_BELOW: + m_result = (m_constraint->lin_error < m_value); + break; + case SENS_ARM_LIN_ERROR_ABOVE: + m_result = (m_constraint->lin_error > m_value); + break; + case SENS_ARM_ROT_ERROR_BELOW: + m_result = (m_constraint->rot_error < m_value); + break; + case SENS_ARM_ROT_ERROR_ABOVE: + m_result = (m_constraint->rot_error > m_value); + break; + } + if (m_lastresult!=m_result) + { + m_lastresult = m_result; + return true; + } + return (reset) ? true : false; +} + + +/* ------------------------------------------------------------------------- */ +/* Python functions */ +/* ------------------------------------------------------------------------- */ + +/* Integration hooks ------------------------------------------------------- */ +PyTypeObject KX_ArmatureSensor::Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "KX_ArmatureSensor", + sizeof(PyObjectPlus_Proxy), + 0, + py_base_dealloc, + 0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0,0,0,0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + 0,0,0,0,0,0,0, + Methods, + 0, + 0, + &SCA_ISensor::Type, + 0,0,0,0,0,0, + py_base_new +}; + +PyMethodDef KX_ArmatureSensor::Methods[] = { + {NULL,NULL} //Sentinel +}; + +PyAttributeDef KX_ArmatureSensor::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("constraint", KX_ArmatureSensor, pyattr_get_constraint), + KX_PYATTRIBUTE_FLOAT_RW("value",-FLT_MAX,FLT_MAX,KX_ArmatureSensor,m_value), + KX_PYATTRIBUTE_INT_RW("type",0,SENS_ARM_MAXTYPE,false,KX_ArmatureSensor,m_type), + { NULL } //Sentinel +}; + +PyObject* KX_ArmatureSensor::pyattr_get_constraint(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_ArmatureSensor* sensor = static_cast<KX_ArmatureSensor*>(self); + if (sensor->m_gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) { + BL_ArmatureObject* armobj = (BL_ArmatureObject*)sensor->m_gameobj; + BL_ArmatureConstraint* constraint = armobj->GetConstraint(sensor->m_posechannel, sensor->m_constraintname); + if (constraint) + return constraint->GetProxy(); + } + Py_RETURN_NONE; +} diff --git a/source/gameengine/Ketsji/KX_ArmatureSensor.h b/source/gameengine/Ketsji/KX_ArmatureSensor.h new file mode 100644 index 00000000000..2af002afff9 --- /dev/null +++ b/source/gameengine/Ketsji/KX_ArmatureSensor.h @@ -0,0 +1,85 @@ +/** + * Property sensor + * + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __KX_ARMATURESENSOR +#define __KX_ARMATURESENSOR + +struct bConstraint; + +#include "SCA_ISensor.h" +#include "DNA_sensor_types.h" + +class KX_ArmatureSensor : public SCA_ISensor +{ + Py_Header; + //class CExpression* m_rightexpr; + +protected: + +public: + KX_ArmatureSensor(class SCA_EventManager* eventmgr, + SCA_IObject* gameobj, + const char *posechannel, + const char *constraintname, + int type, + float value); + + /** + * For property sensor, it is used to release the pre-calculated expression + * so that self references are removed before the sensor itself is released + */ + virtual ~KX_ArmatureSensor(); + virtual CValue* GetReplica(); + virtual void ReParent(SCA_IObject* parent); + virtual void Init(); + virtual bool Evaluate(); + virtual bool IsPositiveTrigger(); + + // identify the constraint that this actuator controls + void FindConstraint(); + + /* --------------------------------------------------------------------- */ + /* Python interface ---------------------------------------------------- */ + /* --------------------------------------------------------------------- */ + static PyObject* pyattr_get_constraint(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + +private: + struct bConstraint* m_constraint; + STR_String m_posechannel; + STR_String m_constraintname; + int m_type; + float m_value; + bool m_result; + bool m_lastresult; +}; + +#endif + diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 9c00b5991af..99618fab8e3 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -55,7 +55,7 @@ KX_CameraActuator::KX_CameraActuator( float maxhght, bool xytog ): - SCA_IActuator(gameobj), + SCA_IActuator(gameobj, KX_ACT_CAMERA), m_ob (obj), m_height (hght), m_minHeight (minhght), diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index 7f1d2c7d53c..ea0b9f4f1e2 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -56,7 +56,7 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, int time, int option, char *property) : - SCA_IActuator(gameobj), + SCA_IActuator(gameobj, KX_ACT_CONSTRAINT), m_refDirVector(refDir), m_currentTime(0) { diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index 42dc4d8fd24..71980a3347e 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -50,7 +50,7 @@ KX_GameActuator::KX_GameActuator(SCA_IObject *gameobj, const STR_String& loadinganimationname, KX_Scene* scene, KX_KetsjiEngine* ketsjiengine) - : SCA_IActuator(gameobj) + : SCA_IActuator(gameobj, KX_ACT_GAME) { m_mode = mode; m_filename = filename; diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 8193aa8c37b..a02fd9cec1b 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -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" @@ -454,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++) diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 845cead1cdb..4c4eed9ca71 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -158,6 +158,15 @@ public: return &m_OpenGL_4x4Matrix; }; + /** + * Update the blender object obmat field from the object world position + * if blendobj is NULL, update the object pointed by m_pBlenderObject + * The user must take action to restore the matrix before leaving the GE. + * Used in Armature evaluation + */ + void + UpdateBlenderObjectMatrix(Object* blendobj=NULL); + /** * Get a pointer to the game object that is the parent of * this object. Or NULL if there is no parent. The returned diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index b71907be961..d7f800fe5bd 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -71,7 +71,7 @@ KX_IpoActuator::KX_IpoActuator(SCA_IObject* gameobj, bool ipo_as_force, bool ipo_add, bool ipo_local) - : SCA_IActuator(gameobj), + : SCA_IActuator(gameobj, KX_ACT_IPO), m_bNegativeEvent(false), m_startframe (starttime), m_endframe(endtime), diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 4117e493322..e95676ff9d2 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -1783,6 +1783,11 @@ double KX_KetsjiEngine::GetClockTime(void) const return m_clockTime; } +double KX_KetsjiEngine::GetFrameTime(void) const +{ + return m_frameTime; +} + double KX_KetsjiEngine::GetRealTime(void) const { return m_kxsystem->GetTimeInSeconds(); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index acb9e53df8a..373e8bf218c 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -269,6 +269,10 @@ public: * Returns current render frame clock time */ double GetClockTime(void) const; + /** + * Returns current logic frame clock time + */ + double GetFrameTime(void) const; double GetRealTime(void) const; /** diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index 2601ced9c38..924e4a47008 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -55,7 +55,7 @@ KX_ObjectActuator( const short damping, const KX_LocalFlags& flag ) : - SCA_IActuator(gameobj), + SCA_IActuator(gameobj, KX_ACT_OBJECT), m_force(force), m_torque(torque), m_dloc(dloc), diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 20e982f03e0..a4a6b67ad10 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -51,7 +51,7 @@ KX_ParentActuator::KX_ParentActuator(SCA_IObject *gameobj, bool addToCompound, bool ghost, SCA_IObject *ob) - : SCA_IActuator(gameobj), + : SCA_IActuator(gameobj, KX_ACT_PARENT), m_mode(mode), m_addToCompound(addToCompound), m_ghost(ghost), diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 298d485aaaf..bef00fb7a06 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -51,6 +51,7 @@ extern "C" { #include "KX_KetsjiEngine.h" #include "KX_RadarSensor.h" #include "KX_RaySensor.h" +#include "KX_ArmatureSensor.h" #include "KX_SceneActuator.h" #include "KX_GameActuator.h" #include "KX_ParentActuator.h" @@ -65,6 +66,7 @@ extern "C" { #include "KX_SoundActuator.h" #include "KX_StateActuator.h" #include "BL_ActionActuator.h" +#include "BL_ArmatureObject.h" #include "RAS_IRasterizer.h" #include "RAS_ICanvas.h" #include "RAS_BucketManager.h" @@ -1218,6 +1220,53 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_PARENT_SET, KX_ParentActuator::KX_PARENT_SET); KX_MACRO_addTypesToDict(d, KX_PARENT_REMOVE, KX_ParentActuator::KX_PARENT_REMOVE); + /* BL_ArmatureConstraint type */ + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_TRACKTO, CONSTRAINT_TYPE_TRACKTO); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_KINEMATIC); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_ROTLIKE, CONSTRAINT_TYPE_ROTLIKE); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_LOCLIKE, CONSTRAINT_TYPE_LOCLIKE); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_MINMAX, CONSTRAINT_TYPE_MINMAX); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_SIZELIKE, CONSTRAINT_TYPE_SIZELIKE); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_LOCKTRACK, CONSTRAINT_TYPE_LOCKTRACK); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_STRETCHTO, CONSTRAINT_TYPE_STRETCHTO); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_CLAMPTO, CONSTRAINT_TYPE_CLAMPTO); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_TRANSFORM, CONSTRAINT_TYPE_TRANSFORM); + KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_DISTLIMIT, CONSTRAINT_TYPE_DISTLIMIT); + /* BL_ArmatureConstraint ik_type */ + KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_COPYPOSE, CONSTRAINT_IK_COPYPOSE); + KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_DISTANCE, CONSTRAINT_IK_DISTANCE); + /* BL_ArmatureConstraint ik_mode */ + KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_MODE_INSIDE, LIMITDIST_INSIDE); + KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_MODE_OUTSIDE, LIMITDIST_OUTSIDE); + KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_MODE_ONSURFACE, LIMITDIST_ONSURFACE); + /* BL_ArmatureConstraint ik_flag */ + KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_TIP, CONSTRAINT_IK_TIP); + KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_ROT, CONSTRAINT_IK_ROT); + KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_STRETCH, CONSTRAINT_IK_STRETCH); + KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_POS, CONSTRAINT_IK_POS); + /* KX_ArmatureSensor type */ + KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_STATE_CHANGED, SENS_ARM_STATE_CHANGED); + KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_LIN_ERROR_BELOW, SENS_ARM_LIN_ERROR_BELOW); + KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_LIN_ERROR_ABOVE, SENS_ARM_LIN_ERROR_ABOVE); + KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_ROT_ERROR_BELOW, SENS_ARM_ROT_ERROR_BELOW); + KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_ROT_ERROR_ABOVE, SENS_ARM_ROT_ERROR_ABOVE); + + /* BL_ArmatureActuator type */ + KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_RUN, ACT_ARM_RUN); + KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_ENABLE, ACT_ARM_ENABLE); + KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_DISABLE, ACT_ARM_DISABLE); + KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_SETTARGET, ACT_ARM_SETTARGET); + KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_SETWEIGHT, ACT_ARM_SETWEIGHT); + + /* BL_Armature Channel rotation_mode */ + KX_MACRO_addTypesToDict(d, PCHAN_ROT_QUAT, PCHAN_ROT_QUAT); + KX_MACRO_addTypesToDict(d, PCHAN_ROT_XYZ, PCHAN_ROT_XYZ); + KX_MACRO_addTypesToDict(d, PCHAN_ROT_XZY, PCHAN_ROT_XZY); + KX_MACRO_addTypesToDict(d, PCHAN_ROT_YXZ, PCHAN_ROT_YXZ); + KX_MACRO_addTypesToDict(d, PCHAN_ROT_YZX, PCHAN_ROT_YZX); + KX_MACRO_addTypesToDict(d, PCHAN_ROT_ZXY, PCHAN_ROT_ZXY); + KX_MACRO_addTypesToDict(d, PCHAN_ROT_ZYX, PCHAN_ROT_ZYX); + // Check for errors if (PyErr_Occurred()) { diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 61e563791c3..c2c33918172 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -35,6 +35,10 @@ /* Only for Class::Parents */ #include "BL_BlenderShader.h" #include "BL_ShapeActionActuator.h" +#include "BL_ArmatureActuator.h" +#include "BL_ArmatureConstraint.h" +#include "BL_ArmatureObject.h" +#include "BL_ArmatureChannel.h" #include "KX_BlenderMaterial.h" #include "KX_CameraActuator.h" #include "KX_ConstraintActuator.h" @@ -86,7 +90,22 @@ #include "SCA_RandomActuator.h" #include "SCA_IController.h" -static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes, int init_getset) +static void PyType_Attr_Set(PyGetSetDef *attr_getset, PyAttributeDef *attr) +{ + attr_getset->name= (char *)attr->m_name; + attr_getset->doc= NULL; + + attr_getset->get= reinterpret_cast<getter>(PyObjectPlus::py_get_attrdef); + + if(attr->m_access==KX_PYATTRIBUTE_RO) + attr_getset->set= NULL; + else + attr_getset->set= reinterpret_cast<setter>(PyObjectPlus::py_set_attrdef); + + attr_getset->closure= reinterpret_cast<void *>(attr); +} + +static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes, PyAttributeDef *attributesPtr, int init_getset) { PyAttributeDef *attr; @@ -97,29 +116,31 @@ static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *a //if(tp->tp_base==NULL) // printf("Debug: No Parents - '%s'\n" , tp->tp_name); - if(tp->tp_getset==NULL && attributes->m_name) { + if(tp->tp_getset==NULL && ((attributes && attributes->m_name) || (attributesPtr && attributesPtr->m_name))) { PyGetSetDef *attr_getset; int attr_tot= 0; - for(attr= attributes; attr->m_name; attr++, attr_tot++) {}; + if (attributes) { + for(attr= attributes; attr->m_name; attr++, attr_tot++) + attr->m_usePtr = false; + } + if (attributesPtr) { + for(attr= attributesPtr; attr->m_name; attr++, attr_tot++) + attr->m_usePtr = true; + } tp->tp_getset = attr_getset = reinterpret_cast<PyGetSetDef *>(PyMem_Malloc((attr_tot+1) * sizeof(PyGetSetDef))); // XXX - Todo, free - - for(attr= attributes; attr->m_name; attr++, attr_getset++) { - attr_getset->name= (char *)attr->m_name; - attr_getset->doc= NULL; - - attr_getset->get= reinterpret_cast<getter>(PyObjectPlus::py_get_attrdef); - - if(attr->m_access==KX_PYATTRIBUTE_RO) - attr_getset->set= NULL; - else - attr_getset->set= reinterpret_cast<setter>(PyObjectPlus::py_set_attrdef); - - attr_getset->closure= reinterpret_cast<void *>(attr); + if (attributes) { + for(attr= attributes; attr->m_name; attr++, attr_getset++) { + PyType_Attr_Set(attr_getset, attr); + } + } + if (attributesPtr) { + for(attr= attributesPtr; attr->m_name; attr++, attr_getset++) { + PyType_Attr_Set(attr_getset, attr); + } } - memset(attr_getset, 0, sizeof(PyGetSetDef)); } } else { @@ -130,7 +151,8 @@ static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *a } -#define PyType_Ready_Attr(d, n, i) PyType_Ready_ADD(d, &n::Type, n::Attributes, i) +#define PyType_Ready_Attr(d, n, i) PyType_Ready_ADD(d, &n::Type, n::Attributes, NULL, i) +#define PyType_Ready_AttrPtr(d, n, i) PyType_Ready_ADD(d, &n::Type, n::Attributes, n::AttributesPtr, i) void initPyTypes(void) { @@ -151,6 +173,11 @@ void initPyTypes(void) PyType_Ready_Attr(dict, BL_ActionActuator, init_getset); PyType_Ready_Attr(dict, BL_Shader, init_getset); PyType_Ready_Attr(dict, BL_ShapeActionActuator, init_getset); + PyType_Ready_Attr(dict, BL_ArmatureObject, init_getset); + PyType_Ready_Attr(dict, BL_ArmatureActuator, init_getset); + PyType_Ready_Attr(dict, BL_ArmatureConstraint, init_getset); + PyType_Ready_AttrPtr(dict, BL_ArmatureBone, init_getset); + PyType_Ready_AttrPtr(dict, BL_ArmatureChannel, init_getset); PyType_Ready_Attr(dict, CListValue, init_getset); PyType_Ready_Attr(dict, CValue, init_getset); PyType_Ready_Attr(dict, KX_BlenderMaterial, init_getset); diff --git a/source/gameengine/Ketsji/KX_PythonSeq.cpp b/source/gameengine/Ketsji/KX_PythonSeq.cpp index 75a7c9b8aeb..f7ad7acb252 100644 --- a/source/gameengine/Ketsji/KX_PythonSeq.cpp +++ b/source/gameengine/Ketsji/KX_PythonSeq.cpp @@ -31,6 +31,7 @@ #include "KX_PythonSeq.h" #include "KX_GameObject.h" +#include "BL_ArmatureObject.h" #include "SCA_ISensor.h" #include "SCA_IController.h" #include "SCA_IActuator.h" @@ -72,6 +73,10 @@ static Py_ssize_t KX_PythonSeq_len( PyObject * self ) return ((KX_GameObject *)self_plus)->GetControllers().size(); case KX_PYGENSEQ_OB_TYPE_ACTUATORS: return ((KX_GameObject *)self_plus)->GetActuators().size(); + case KX_PYGENSEQ_OB_TYPE_CONSTRAINTS: + return ((BL_ArmatureObject *)self_plus)->GetConstraintNumber(); + case KX_PYGENSEQ_OB_TYPE_CHANNELS: + return ((BL_ArmatureObject *)self_plus)->GetChannelNumber(); default: /* Should never happen */ PyErr_SetString(PyExc_SystemError, "invalid type, internal error"); @@ -139,6 +144,29 @@ static PyObject *KX_PythonSeq_getIndex(PyObject* self, int index) } return linkedactuators[index]->GetProxy(); } + case KX_PYGENSEQ_OB_TYPE_CONSTRAINTS: + { + int nb_constraint = ((BL_ArmatureObject *)self_plus)->GetConstraintNumber(); + if(index<0) + index += nb_constraint; + if(index<0 || index>= nb_constraint) { + PyErr_SetString(PyExc_IndexError, "seq[i]: index out of range"); + return NULL; + } + return ((BL_ArmatureObject *)self_plus)->GetConstraint(index)->GetProxy(); + } + case KX_PYGENSEQ_OB_TYPE_CHANNELS: + { + int nb_channel = ((BL_ArmatureObject *)self_plus)->GetChannelNumber(); + if(index<0) + index += nb_channel; + if(index<0 || index>= nb_channel) { + PyErr_SetString(PyExc_IndexError, "seq[i]: index out of range"); + return NULL; + } + return ((BL_ArmatureObject *)self_plus)->GetChannel(index)->GetProxy(); + } + } PyErr_SetString(PyExc_SystemError, "invalid sequence type, this is a bug"); @@ -206,6 +234,14 @@ static PyObjectPlus * KX_PythonSeq_subscript__internal(PyObject *self, char *key } break; } + case KX_PYGENSEQ_OB_TYPE_CONSTRAINTS: + { + return ((BL_ArmatureObject*)self_plus)->GetConstraint(key); + } + case KX_PYGENSEQ_OB_TYPE_CHANNELS: + { + return ((BL_ArmatureObject*)self_plus)->GetChannel(key); + } } return NULL; diff --git a/source/gameengine/Ketsji/KX_PythonSeq.h b/source/gameengine/Ketsji/KX_PythonSeq.h index 15a016224a9..34243aa9b9c 100644 --- a/source/gameengine/Ketsji/KX_PythonSeq.h +++ b/source/gameengine/Ketsji/KX_PythonSeq.h @@ -39,7 +39,9 @@ enum KX_PYGENSEQ_TYPE { KX_PYGENSEQ_CONT_TYPE_ACTUATORS, KX_PYGENSEQ_OB_TYPE_SENSORS, KX_PYGENSEQ_OB_TYPE_CONTROLLERS, - KX_PYGENSEQ_OB_TYPE_ACTUATORS + KX_PYGENSEQ_OB_TYPE_ACTUATORS, + KX_PYGENSEQ_OB_TYPE_CONSTRAINTS, + KX_PYGENSEQ_OB_TYPE_CHANNELS, }; /* The Main PyType Object defined in Main.c */ diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 099403fc28d..c1e74070d72 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -57,7 +57,7 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj, const float *angvel, bool angv_local) : - SCA_IActuator(gameobj), + SCA_IActuator(gameobj, KX_ACT_ADD_OBJECT), m_OriginalObject(original), m_scene(scene), diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index 646cfb7219f..73c85ad07b3 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -87,7 +87,7 @@ KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj, short dyn_operation, float setmass) : - SCA_IActuator(gameobj), + SCA_IActuator(gameobj, KX_ACT_DYNAMIC), m_dyn_operation(dyn_operation), m_setmass(setmass) { diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp index dd9d8015724..e7dc71d9b27 100644 --- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp @@ -44,7 +44,7 @@ KX_SCA_EndObjectActuator::KX_SCA_EndObjectActuator(SCA_IObject *gameobj, SCA_IScene* scene): - SCA_IActuator(gameobj), + SCA_IActuator(gameobj, KX_ACT_END_OBJECT), m_scene(scene) { // intentionally empty diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index e85b8a32798..e118972edc8 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -122,7 +122,7 @@ KX_SCA_ReplaceMeshActuator::KX_SCA_ReplaceMeshActuator(SCA_IObject *gameobj, bool use_gfx, bool use_phys) : - SCA_IActuator(gameobj), + SCA_IActuator(gameobj, KX_ACT_REPLACE_MESH), m_mesh(mesh), m_scene(scene), m_use_gfx(use_gfx), diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 3483496c3a6..140be3fb3db 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -40,14 +40,15 @@ #include "ListValue.h" #include "SCA_LogicManager.h" #include "SCA_TimeEventManager.h" -#include "SCA_AlwaysEventManager.h" -#include "SCA_RandomEventManager.h" -#include "KX_RayEventManager.h" +//#include "SCA_AlwaysEventManager.h" +//#include "SCA_RandomEventManager.h" +//#include "KX_RayEventManager.h" #include "KX_TouchEventManager.h" #include "SCA_KeyboardManager.h" #include "SCA_MouseManager.h" -#include "SCA_PropertyEventManager.h" +//#include "SCA_PropertyEventManager.h" #include "SCA_ActuatorEventManager.h" +#include "SCA_BasicEventManager.h" #include "KX_Camera.h" #include "SCA_JoystickManager.h" @@ -168,25 +169,27 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_keyboardmgr = new SCA_KeyboardManager(m_logicmgr,keyboarddevice); m_mousemgr = new SCA_MouseManager(m_logicmgr,mousedevice); - SCA_AlwaysEventManager* alwaysmgr = new SCA_AlwaysEventManager(m_logicmgr); - SCA_PropertyEventManager* propmgr = new SCA_PropertyEventManager(m_logicmgr); + //SCA_AlwaysEventManager* alwaysmgr = new SCA_AlwaysEventManager(m_logicmgr); + //SCA_PropertyEventManager* propmgr = new SCA_PropertyEventManager(m_logicmgr); SCA_ActuatorEventManager* actmgr = new SCA_ActuatorEventManager(m_logicmgr); - SCA_RandomEventManager* rndmgr = new SCA_RandomEventManager(m_logicmgr); - KX_RayEventManager* raymgr = new KX_RayEventManager(m_logicmgr); + //SCA_RandomEventManager* rndmgr = new SCA_RandomEventManager(m_logicmgr); + SCA_BasicEventManager* basicmgr = new SCA_BasicEventManager(m_logicmgr); + //KX_RayEventManager* raymgr = new KX_RayEventManager(m_logicmgr); KX_NetworkEventManager* netmgr = new KX_NetworkEventManager(m_logicmgr, ndi); - m_logicmgr->RegisterEventManager(alwaysmgr); - m_logicmgr->RegisterEventManager(propmgr); + //m_logicmgr->RegisterEventManager(alwaysmgr); + //m_logicmgr->RegisterEventManager(propmgr); m_logicmgr->RegisterEventManager(actmgr); m_logicmgr->RegisterEventManager(m_keyboardmgr); m_logicmgr->RegisterEventManager(m_mousemgr); m_logicmgr->RegisterEventManager(m_timemgr); - m_logicmgr->RegisterEventManager(rndmgr); - m_logicmgr->RegisterEventManager(raymgr); + //m_logicmgr->RegisterEventManager(rndmgr); + //m_logicmgr->RegisterEventManager(raymgr); m_logicmgr->RegisterEventManager(netmgr); + m_logicmgr->RegisterEventManager(basicmgr); SYS_SystemHandle hSystem = SYS_GetSystem(); diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index ea1be7bca6c..c7721c480e0 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -50,7 +50,7 @@ KX_SceneActuator::KX_SceneActuator(SCA_IObject *gameobj, KX_KetsjiEngine* ketsjiEngine, const STR_String& nextSceneName, KX_Camera* camera) - : SCA_IActuator(gameobj) + : SCA_IActuator(gameobj, KX_ACT_SCENE) { m_mode = mode; m_scene = scene; diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index e2b4022a312..9d261137497 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -49,7 +49,7 @@ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj, bool is3d, KX_3DSoundSettings settings, KX_SOUNDACT_TYPE type)//, - : SCA_IActuator(gameobj) + : SCA_IActuator(gameobj, KX_ACT_SOUND) { m_sound = sound; m_volume = volume; diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index 4159e9c373d..60812220953 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -40,7 +40,7 @@ KX_StateActuator::KX_StateActuator( int operation, unsigned int mask ) - : SCA_IActuator(gameobj), + : SCA_IActuator(gameobj, KX_ACT_STATE), m_operation(operation), m_mask(mask) { diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index e6c2f86bbce..ace1cf8a6f4 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -60,7 +60,7 @@ KX_TrackToActuator::KX_TrackToActuator(SCA_IObject *gameobj, bool allow3D, int trackflag, int upflag) - : SCA_IActuator(gameobj) + : SCA_IActuator(gameobj, KX_ACT_TRACKTO) { m_time = time; m_allow3D = allow3D; diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 184e127209f..5b0f6e6e9f2 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -41,7 +41,7 @@ KX_VisibilityActuator::KX_VisibilityActuator( bool occlusion, bool recursive ) - : SCA_IActuator(gameobj), + : SCA_IActuator(gameobj, KX_ACT_VISIBILITY), m_visible(visible), m_occlusion(occlusion), m_recursive(recursive) |