fix for bug #18898: GE perspective 3D View not working properly (missing LENS)
[blender.git] / source / gameengine / Ketsji / KX_GameObject.h
index 20b15787d27732da0332221c3b53c7f87127d749..dbdea97031d2e3663d119935d593e539fe55065a 100644 (file)
 #include "SCA_LogicManager.h" /* for ConvertPythonToGameObject to search object names */
 #define KX_OB_DYNAMIC 1
 
-
 //Forward declarations.
 struct KX_ClientObjectInfo;
 class KX_RayCast;
 class RAS_MeshObject;
 class KX_IPhysicsController;
+class PHY_IGraphicController;
 class PHY_IPhysicsEnvironment;
 struct Object;
 
+/* utility conversion function */
+bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok, const char *error_prefix);
+
 /**
  * KX_GameObject is the main class for dynamic objects.
  */
@@ -74,6 +77,7 @@ protected:
        STR_String                                                      m_text;
        int                                                                     m_layer;
        std::vector<RAS_MeshObject*>            m_meshes;
+       SG_QList                                                        m_meshSlots;    // head of mesh slots of this 
        struct Object*                                          m_pBlenderObject;
        struct Object*                                          m_pBlenderGroupObject;
        
@@ -86,8 +90,10 @@ protected:
        // culled = while rendering, depending on camera
        bool                                                            m_bVisible; 
        bool                                                            m_bCulled; 
+       bool                                                            m_bOccluder;
 
        KX_IPhysicsController*                          m_pPhysicsController1;
+       PHY_IGraphicController*                         m_pGraphicController;
        // used for ray casting
        PHY_IPhysicsEnvironment*                        m_pPhysicsEnvironment;
        STR_String                                                      m_testPropName;
@@ -101,6 +107,28 @@ protected:
 public:
        bool                                                            m_isDeformable;
 
+       /**
+        * Helper function for modules that can't include KX_ClientObjectInfo.h
+        */
+       static KX_GameObject* GetClientObject(KX_ClientObjectInfo* info);
+
+       // Python attributes that wont convert into CValue
+       // 
+       // there are 2 places attributes can be stored, in the CValue,
+       // where attributes are converted into BGE's CValue types
+       // these can be used with property actuators
+       //
+       // For the python API, For types that cannot be converted into CValues (lists, dicts, GameObjects)
+       // these will be put into "m_attr_dict", logic bricks cannot access them.
+       // 
+       // rules for setting attributes.
+       // 
+       // * there should NEVER be a CValue and a m_attr_dict attribute with matching names. get/sets make sure of this.
+       // * if CValue conversion fails, use a PyObject in "m_attr_dict"
+       // * when assigning a value, first see if it can be a CValue, if it can remove the "m_attr_dict" and set the CValue
+       // 
+       PyObject*                                                       m_attr_dict; 
+
        virtual void    /* This function should be virtual - derived classed override it */
        Relink(
                GEN_Map<GEN_HashedPtr, void*> *map
@@ -143,7 +171,7 @@ public:
        /** 
         * Sets the parent of this object to a game object
         */                     
-       void SetParent(KX_Scene *scene, KX_GameObject *obj);
+       void SetParent(KX_Scene *scene, KX_GameObject *obj, bool addToCompound=true, bool ghost=true);
 
        /** 
         * Removes the parent of this object to a game object
@@ -165,11 +193,6 @@ public:
        ~KX_GameObject(
        );
 
-               CValue*                         
-       AddRef() { 
-               /* temporarily to find memleaks */ return CValue::AddRef(); 
-       }
-
        /** 
         * @section Stuff which is here due to poor design.
         * Inherited from CValue and needs an implementation. 
@@ -206,7 +229,7 @@ public:
        /**
         * Inherited from CValue -- does nothing!
         */
-               float                           
+               double
        GetNumber(
        );
 
@@ -218,7 +241,7 @@ public:
        /**
         * Inherited from CValue -- returns the name of this object.
         */
-               STR_String                      
+               STR_String&                     
        GetName(
        );
 
@@ -227,15 +250,7 @@ public:
         */
                void                            
        SetName(
-               STR_String name
-       );
-
-       /**
-        * Inherited from CValue -- does nothing.
-        */
-               void                            
-       ReplicaSetName(
-               STR_String name
+               const char *name
        );
 
        /** 
@@ -252,9 +267,7 @@ public:
         * data owned by this class is deep copied. Called internally
         */
        virtual void                            
-       ProcessReplica(
-               KX_GameObject* replica
-       );
+       ProcessReplica();
 
        /** 
         * Return the linear velocity of the game object.
@@ -279,6 +292,12 @@ public:
                MT_Scalar       
        GetMass();
 
+       /**
+        * Return the local inertia vector of the object
+        */
+               MT_Vector3
+       GetLocalInertia();
+
        /** 
         * Return the angular velocity of the game object.
         */
@@ -350,6 +369,23 @@ public:
 
        }
 
+       /**
+        * @return a pointer to the graphic controller owner by this class 
+        */
+       PHY_IGraphicController* GetGraphicController()
+       {
+               return m_pGraphicController;
+       }
+
+       void SetGraphicController(PHY_IGraphicController* graphiccontroller) 
+       { 
+               m_pGraphicController = graphiccontroller;
+       }
+       /*
+        * @add/remove the graphic controller to the physic system
+        */
+       void ActivateGraphicController(bool recurse);
+
        /**
         * @section Coordinate system manipulation functions
         */
@@ -367,8 +403,7 @@ public:
 
                void                                            
        NodeUpdateGS(
-               double time,
-               bool bInitiator
+               double time
        );
 
        const 
@@ -525,11 +560,11 @@ public:
        static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene);
 
        /**
-        * Only update the transform if it's a non-dynamic object
+        * only used for sensor objects
         */
-               void 
-       UpdateNonDynas(
-       );
+       void SynchronizeTransform();
+
+       static void SynchronizeTransformFunc(SG_IObject* node, void* gameobj, void* scene);
 
        /**
         * Function to set IPO option at start of IPO
@@ -665,19 +700,36 @@ public:
        /**
         * Was this object culled?
         */
-               bool
+       inline bool
        GetCulled(
                void
-       );
+       ) { return m_bCulled; }
 
        /**
         * Set culled flag of this object
         */
-               void
+       inline void
        SetCulled(
                bool c
-       );
+       ) { m_bCulled = c; }
+       
+       /**
+        * Is this object an occluder?
+        */
+       inline bool
+       GetOccluder(
+               void
+       ) { return m_bOccluder; }
 
+       /**
+        * Set occluder flag of this object
+        */
+       void
+       SetOccluder(
+               bool v,
+               bool recursive
+       );
+       
        /**
         * Change the layer of the object (when it is added in another layer
         * than the original layer)
@@ -752,26 +804,37 @@ public:
        }
        
        KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; }
+       
+       CListValue* GetChildren();
+       CListValue* GetChildrenRecursive();
+       
        /**
         * @section Python interface functions.
         */
-
-       virtual 
-               PyObject*                       
-       _getattr(
-               const STR_String& attr
-       );
-       virtual 
-               int 
-       _setattr(
-               const STR_String& attr, 
-               PyObject *value
-       );              // _setattr method
-
+       
+       virtual PyObject* py_getattro(PyObject *attr);
+       virtual PyObject* py_getattro_dict();
+       virtual int py_setattro(PyObject *attr, PyObject *value);               // py_setattro method
+       virtual int                             py_delattro(PyObject *attr);
+       virtual PyObject* py_repr(void)
+       {
+               return PyString_FromString(GetName().ReadPtr());
+       }
+       
+       
+       /* quite annoying that we need these but the bloody 
+        * py_getattro_up and py_setattro_up macro's have a returns in them! */
+       PyObject* py_getattro__internal(PyObject *attr);
+       int py_setattro__internal(PyObject *attr, PyObject *value);             // py_setattro method
+       
+               
        KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition);
        KX_PYMETHOD_O(KX_GameObject,SetPosition);
        KX_PYMETHOD_O(KX_GameObject,SetWorldPosition);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyForce);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyTorque);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyRotation);
+       KX_PYMETHOD_VARARGS(KX_GameObject, ApplyMovement);
        KX_PYMETHOD_VARARGS(KX_GameObject,GetLinearVelocity);
        KX_PYMETHOD_VARARGS(KX_GameObject,SetLinearVelocity);
        KX_PYMETHOD_VARARGS(KX_GameObject,GetAngularVelocity);
@@ -783,6 +846,7 @@ public:
        KX_PYMETHOD_O(KX_GameObject,SetOrientation);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetVisible);
        KX_PYMETHOD_VARARGS(KX_GameObject,SetVisible);
+       KX_PYMETHOD_VARARGS(KX_GameObject,SetOcclusion);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetState);
        KX_PYMETHOD_O(KX_GameObject,SetState);
        KX_PYMETHOD_VARARGS(KX_GameObject,AlignAxisToVect);
@@ -794,7 +858,7 @@ public:
        KX_PYMETHOD_VARARGS(KX_GameObject,ApplyImpulse);
        KX_PYMETHOD_O(KX_GameObject,SetCollisionMargin);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetParent);
-       KX_PYMETHOD_O(KX_GameObject,SetParent);
+       KX_PYMETHOD_VARARGS(KX_GameObject,SetParent);
        KX_PYMETHOD_NOARGS(KX_GameObject,RemoveParent);
        KX_PYMETHOD_NOARGS(KX_GameObject,GetChildren);  
        KX_PYMETHOD_NOARGS(KX_GameObject,GetChildrenRecursive);
@@ -805,8 +869,58 @@ public:
        KX_PYMETHOD_NOARGS(KX_GameObject,EndObject);
        KX_PYMETHOD_DOC(KX_GameObject,rayCastTo);
        KX_PYMETHOD_DOC(KX_GameObject,rayCast);
-       KX_PYMETHOD_DOC(KX_GameObject,getDistanceTo);
-       KX_PYMETHOD_DOC(KX_GameObject,getVectTo);
+       KX_PYMETHOD_DOC_O(KX_GameObject,getDistanceTo);
+       KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo);
+       KX_PYMETHOD_DOC_VARARGS(KX_GameObject, sendMessage);
+       
+       /* Dict access */
+       KX_PYMETHOD_VARARGS(KX_GameObject,get);
+       KX_PYMETHOD_O(KX_GameObject,has_key);
+       
+       /* attributes */
+       static PyObject*        pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_parent(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_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 int                      pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_meshes(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_children(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_children_recursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       
+       /* Experemental! */
+       static PyObject*        pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static PyObject*        pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       
+       /* getitem/setitem */
+       static Py_ssize_t                       Map_Len(PyObject* self);
+       static PyMappingMethods Mapping;
+       static PyObject*                        Map_GetItem(PyObject *self_v, PyObject *item);
+       static int                                      Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val);
        
 private :
 
@@ -825,8 +939,7 @@ private :
 
 };
 
-/* utility conversion function */
-bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok);
+
 
 #endif //__KX_GAMEOBJECT