BGE: New isDynamicSuspended python attribute
authorPorteries Tristan <republicthunderbolt9@gmail.com>
Fri, 27 Mar 2015 04:52:28 +0000 (05:52 +0100)
committerJorge Bernal <jbernalmartinez@gmail.com>
Fri, 27 Mar 2015 05:11:23 +0000 (06:11 +0100)
This is a new KX_GameObject attribute that it increments the
possibilities of optimization during the game

Additionally the unused m_bSuspendDynamics variable is removed.

Reviewers: moguri, agoose77, lordloki

Reviewed By: agoose77, lordloki

Subscribers: agoose77, lordloki

Differential Revision: https://developer.blender.org/D1091

doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Physics/Bullet/CcdPhysicsController.h
source/gameengine/Physics/common/PHY_IPhysicsController.h

index 8d6996dc4017fbb42f52b690f4c1a6efb80d02fc..abf1b8b9707d6de31055f172def911eee1ff2f1e 100644 (file)
@@ -78,6 +78,12 @@ base class --- :class:`SCA_IObject`
 
          The object must have a physics controller for the mass to be applied, otherwise the mass value will be returned as 0.0.
 
 
          The object must have a physics controller for the mass to be applied, otherwise the mass value will be returned as 0.0.
 
+   .. attribute:: isDynamicsSuspended
+
+      The object's dynamic state (read-only).
+
+      :type: boolean
+
    .. attribute:: linearDamping
 
       The object's linear damping, also known as translational damping. Can be set simultaneously with angular damping using the :py:meth:`setDamping` method.
    .. attribute:: linearDamping
 
       The object's linear damping, also known as translational damping. Can be set simultaneously with angular damping using the :py:meth:`setDamping` method.
index d0c6792cce0f848111695325e8ac9849959bbba5..f876afd01c116ec7b2cf6b8a0670c8fda11b3ace 100644 (file)
@@ -95,7 +95,6 @@ KX_GameObject::KX_GameObject(
       m_previousLodLevel(0),
       m_pBlenderObject(NULL),
       m_pBlenderGroupObject(NULL),
       m_previousLodLevel(0),
       m_pBlenderObject(NULL),
       m_pBlenderGroupObject(NULL),
-      m_bSuspendDynamics(false),
       m_bUseObjectColor(false),
       m_bIsNegativeScaling(false),
       m_objectColor(1.0, 1.0, 1.0, 1.0),
       m_bUseObjectColor(false),
       m_bIsNegativeScaling(false),
       m_objectColor(1.0, 1.0, 1.0, 1.0),
@@ -586,6 +585,13 @@ CValue* KX_GameObject::GetReplica()
        return replica;
 }
 
        return replica;
 }
 
+bool KX_GameObject::IsDynamicsSuspended() const
+{
+       if (m_pPhysicsController)
+               return m_pPhysicsController->IsSuspended();
+       return false;
+}
+
 float KX_GameObject::getLinearDamping() const
 {
        if (m_pPhysicsController)
 float KX_GameObject::getLinearDamping() const
 {
        if (m_pPhysicsController)
@@ -1985,6 +1991,7 @@ PyAttributeDef KX_GameObject::Attributes[] = {
        KX_PYATTRIBUTE_RO_FUNCTION("scene",             KX_GameObject, pyattr_get_scene),
        KX_PYATTRIBUTE_RO_FUNCTION("life",              KX_GameObject, pyattr_get_life),
        KX_PYATTRIBUTE_RW_FUNCTION("mass",              KX_GameObject, pyattr_get_mass,         pyattr_set_mass),
        KX_PYATTRIBUTE_RO_FUNCTION("scene",             KX_GameObject, pyattr_get_scene),
        KX_PYATTRIBUTE_RO_FUNCTION("life",              KX_GameObject, pyattr_get_life),
        KX_PYATTRIBUTE_RW_FUNCTION("mass",              KX_GameObject, pyattr_get_mass,         pyattr_set_mass),
+       KX_PYATTRIBUTE_RO_FUNCTION("isDynamicsSuspended",               KX_GameObject, pyattr_get_dynamics_suspended),
        KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMin",            KX_GameObject, pyattr_get_lin_vel_min, pyattr_set_lin_vel_min),
        KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMax",            KX_GameObject, pyattr_get_lin_vel_max, pyattr_set_lin_vel_max),
        KX_PYATTRIBUTE_RW_FUNCTION("visible",   KX_GameObject, pyattr_get_visible,      pyattr_set_visible),
        KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMin",            KX_GameObject, pyattr_get_lin_vel_min, pyattr_set_lin_vel_min),
        KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMax",            KX_GameObject, pyattr_get_lin_vel_max, pyattr_set_lin_vel_max),
        KX_PYATTRIBUTE_RW_FUNCTION("visible",   KX_GameObject, pyattr_get_visible,      pyattr_set_visible),
@@ -2398,6 +2405,19 @@ int KX_GameObject::pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrd
        return PY_SET_ATTR_SUCCESS;
 }
 
        return PY_SET_ATTR_SUCCESS;
 }
 
+PyObject* KX_GameObject::pyattr_get_dynamics_suspended(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+       KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+
+       // Only objects with a physics controller can be suspended
+       if (!self->GetPhysicsController()) {
+                       PyErr_SetString(PyExc_AttributeError, "This object has not Physics Controller");
+                       return NULL;
+       }
+
+       return PyBool_FromLong(self->IsDynamicsSuspended());
+}
+
 PyObject *KX_GameObject::pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
        KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
 PyObject *KX_GameObject::pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
        KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
index acc635857493cbc9bb6b3c637969347048c03361..8f823e728de4530cfe22b2c8d6ad9d2d5f716f48 100644 (file)
@@ -95,7 +95,6 @@ protected:
        struct Object*                                          m_pBlenderObject;
        struct Object*                                          m_pBlenderGroupObject;
        
        struct Object*                                          m_pBlenderObject;
        struct Object*                                          m_pBlenderGroupObject;
        
-       bool                                                            m_bSuspendDynamics;
        bool                                                            m_bUseObjectColor;
        bool                                                            m_bIsNegativeScaling;
        MT_Vector4                                                      m_objectColor;
        bool                                                            m_bUseObjectColor;
        bool                                                            m_bIsNegativeScaling;
        MT_Vector4                                                      m_objectColor;
@@ -619,6 +618,8 @@ public:
                return m_bDyna; 
        }
 
                return m_bDyna; 
        }
 
+       bool IsDynamicsSuspended() const;
+
        /**
         * Should we record animation for this object?
         */
        /**
         * Should we record animation for this object?
         */
@@ -1039,6 +1040,7 @@ public:
        static PyObject*        pyattr_get_life(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static PyObject*        pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static int                      pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
        static PyObject*        pyattr_get_life(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static PyObject*        pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static int                      pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_dynamics_suspended(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static PyObject*        pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static int                      pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
        static PyObject*        pyattr_get_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static PyObject*        pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static int                      pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
        static PyObject*        pyattr_get_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
index 47bc9cdfbd7bce7fb48ff7ad3486406d20ad95ed..56d67ca2f64a30e674cd4589d710b23aedd513c7 100644 (file)
@@ -712,6 +712,11 @@ protected:
                        return GetConstructionInfo().m_bDyna;
                }
 
                        return GetConstructionInfo().m_bDyna;
                }
 
+               virtual bool IsSuspended() const
+               {
+                       return m_suspended;
+               }
+
                virtual bool IsCompound()
                {
                        return GetConstructionInfo().m_shapeInfo->m_shapeType == PHY_SHAPE_COMPOUND;
                virtual bool IsCompound()
                {
                        return GetConstructionInfo().m_shapeInfo->m_shapeType == PHY_SHAPE_COMPOUND;
index 68763be4db9e6baf66574c80d360e6e109e571b0..b6cd480e655c039aa9a78092cacfd8afdec89cd0 100644 (file)
@@ -133,6 +133,7 @@ class PHY_IPhysicsController : public PHY_IController
 
                virtual bool IsDynamic() = 0;
                virtual bool IsCompound() = 0;
 
                virtual bool IsDynamic() = 0;
                virtual bool IsCompound() = 0;
+               virtual bool IsSuspended() const = 0;
 
                virtual bool ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj) = 0;
 
 
                virtual bool ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj) = 0;