Blender V2.61 - r43446

KX_Scene.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #ifndef __KX_SCENE_H
00033 #define __KX_SCENE_H
00034 
00035 
00036 #include "KX_PhysicsEngineEnums.h"
00037 
00038 #include <vector>
00039 #include <set>
00040 #include <list>
00041 
00042 #include "CTR_Map.h"
00043 #include "CTR_HashedPtr.h"
00044 #include "SG_IObject.h"
00045 #include "SCA_IScene.h"
00046 #include "MT_Transform.h"
00047 
00048 #include "RAS_FramingManager.h"
00049 #include "RAS_Rect.h"
00050 
00051 
00052 #include "PyObjectPlus.h"
00053 #include "RAS_2DFilterManager.h"
00054 
00058 struct SM_MaterialProps;
00059 struct SM_ShapeProps;
00060 struct Scene;
00061 
00062 class CTR_HashedPtr;
00063 class CListValue;
00064 class CValue;
00065 class SCA_LogicManager;
00066 class SCA_KeyboardManager;
00067 class SCA_TimeEventManager;
00068 class SCA_MouseManager;
00069 class SCA_ISystem;
00070 class SCA_IInputDevice;
00071 class NG_NetworkDeviceInterface;
00072 class NG_NetworkScene;
00073 class SG_IObject;
00074 class SG_Node;
00075 class SG_Tree;
00076 class KX_WorldInfo;
00077 class KX_Camera;
00078 class KX_GameObject;
00079 class KX_LightObject;
00080 class RAS_BucketManager;
00081 class RAS_MaterialBucket;
00082 class RAS_IPolyMaterial;
00083 class RAS_IRasterizer;
00084 class RAS_IRenderTools;
00085 class SCA_JoystickManager;
00086 class btCollisionShape;
00087 class KX_BlenderSceneConverter;
00088 struct KX_ClientObjectInfo;
00089 class KX_ObstacleSimulation;
00090 
00091 #ifdef WITH_CXX_GUARDEDALLOC
00092 #include "MEM_guardedalloc.h"
00093 #endif
00094 
00095 /* for ID freeing */
00096 #define IS_TAGGED(_id) ((_id) && (((ID *)_id)->flag & LIB_DOIT))
00097 
00102 class KX_Scene : public PyObjectPlus, public SCA_IScene
00103 {
00104     Py_Header
00105 
00106 #ifdef WITH_PYTHON
00107     PyObject*   m_attr_dict;
00108     PyObject*   m_draw_call_pre;
00109     PyObject*   m_draw_call_post;
00110 #endif
00111 
00112     struct CullingInfo {
00113         int m_layer;
00114         CullingInfo(int layer) : m_layer(layer) {}
00115     };
00116 
00117 protected:
00118     RAS_BucketManager*  m_bucketmanager;
00119     CListValue*         m_tempObjectList;
00120 
00126     CListValue* m_euthanasyobjects;
00127 
00128     CListValue*         m_objectlist;
00129     CListValue*         m_parentlist; // all 'root' parents
00130     CListValue*         m_lightlist;
00131     CListValue*         m_inactivelist; // all objects that are not in the active layer
00132     CListValue*         m_animatedlist; // all animated objects
00133     
00134     SG_QList            m_sghead;       // list of nodes that needs scenegraph update
00135                                         // the Dlist is not object that must be updated
00136                                         // the Qlist is for objects that needs to be rescheduled
00137                                         // for updates after udpate is over (slow parent, bone parent)
00138 
00139 
00143     list<class KX_Camera*>       m_cameras;
00144 
00148     list<class KX_FontObject*>       m_fonts;
00149 
00150 
00154     SCA_LogicManager*       m_logicmgr;
00155     SCA_KeyboardManager*    m_keyboardmgr;
00156     SCA_MouseManager*       m_mousemgr;
00157     SCA_TimeEventManager*   m_timemgr;
00158 
00159     // Scene converter where many scene entities are registered
00160     // Used to deregister objects that are deleted
00161     class KX_BlenderSceneConverter*     m_sceneConverter;
00165     //e_PhysicsEngine m_physicsEngine; //who needs this ?
00166     class PHY_IPhysicsEnvironment*      m_physicsEnvironment;
00167 
00171     bool m_isclearingZbuffer;
00172 
00176     STR_String  m_sceneName;
00177     
00181     KX_WorldInfo* m_worldinfo;
00182 
00190     NG_NetworkDeviceInterface*  m_networkDeviceInterface;
00191     NG_NetworkScene* m_networkScene;
00192 
00198     SG_Node* m_rootnode;
00199 
00203     KX_Camera* m_active_camera;
00204 
00210     CTR_Map	<CTR_HashedPtr, void*> m_map_gameobject_to_replica;
00211 
00218     std::vector<KX_GameObject*> m_logicHierarchicalGameObjects;
00219     
00228     std::set<CValue*>   m_groupGameObjects;
00229     
00236     SCA_ISystem* m_kxsystem;
00237 
00241     int m_ueberExecutionPriority;
00242 
00247     bool m_suspend;
00248 
00252     float m_activity_box_radius;
00253 
00257     bool m_activity_culling;
00258     
00262     bool m_dbvt_culling;
00263     
00267     int m_dbvt_occlusion_res;
00268 
00273     RAS_FrameSettings m_frame_settings;
00274 
00279     RAS_Rect m_viewport;
00280     
00284     void MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty, KX_Camera*cam,int layer=0);
00285     void MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool visible, KX_Camera*cam,int layer=0);
00286     void MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj, KX_Camera*cam, int layer=0);
00287     static void PhysicsCullingCallback(KX_ClientObjectInfo* objectInfo, void* cullingInfo);
00288 
00289     double              m_suspendedtime;
00290     double              m_suspendeddelta;
00291 
00292     struct Scene* m_blenderScene;
00293 
00294     RAS_2DFilterManager m_filtermanager;
00295 
00296     KX_ObstacleSimulation* m_obstacleSimulation;
00297 
00298 public: 
00299     KX_Scene(class SCA_IInputDevice* keyboarddevice,
00300         class SCA_IInputDevice* mousedevice,
00301         class NG_NetworkDeviceInterface* ndi,
00302         const STR_String& scenename,
00303         struct Scene* scene,
00304         class RAS_ICanvas* canvas);
00305 
00306     virtual 
00307     ~KX_Scene();
00308 
00309     RAS_BucketManager* GetBucketManager();
00310     RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial* polymat, bool &bucketCreated);
00311     void RenderBuckets(const MT_Transform& cameratransform,
00312                         RAS_IRasterizer* rasty,
00313                         RAS_IRenderTools* rendertools);
00314 
00318     static bool KX_ScenegraphUpdateFunc(SG_IObject* node,void* gameobj,void* scene);
00319     static bool KX_ScenegraphRescheduleFunc(SG_IObject* node,void* gameobj,void* scene);
00320     void UpdateParents(double curtime);
00321     void DupliGroupRecurse(CValue* gameobj, int level);
00322     bool IsObjectInGroup(CValue* gameobj)
00323     { 
00324         return (m_groupGameObjects.empty() || 
00325                 m_groupGameObjects.find(gameobj) != m_groupGameObjects.end());
00326     }
00327     SCA_IObject* AddReplicaObject(CValue* gameobj,
00328                                   CValue* locationobj,
00329                                   int lifespan=0);
00330     KX_GameObject* AddNodeReplicaObject(SG_IObject* node,
00331                                         CValue* gameobj);
00332     void RemoveNodeDestructObject(SG_IObject* node,
00333                                   CValue* gameobj);
00334     void RemoveObject(CValue* gameobj);
00335     void DelayedRemoveObject(CValue* gameobj);
00336     
00337     int NewRemoveObject(CValue* gameobj);
00338     void ReplaceMesh(CValue* gameobj,
00339                      void* meshob, bool use_gfx, bool use_phys);
00340 
00341     void AddAnimatedObject(CValue* gameobj);
00342     void RemoveAnimatedObject(CValue* gameobj);
00343 
00348     void LogicBeginFrame(double curtime);
00349     void LogicUpdateFrame(double curtime, bool frame);
00350     void UpdateAnimations(double curtime);
00351 
00352         void                        
00353     LogicEndFrame(
00354     );
00355 
00356         CListValue*             
00357     GetTempObjectList(
00358     );
00359 
00360         CListValue*
00361     GetObjectList(
00362     );
00363 
00364         CListValue*             
00365     GetInactiveList(
00366     );
00367 
00368         CListValue*             
00369     GetRootParentList(
00370     );
00371 
00372         CListValue*             
00373     GetLightList(
00374     );
00375 
00376         SCA_LogicManager*       
00377     GetLogicManager(
00378     );
00379 
00380         SCA_TimeEventManager*   
00381     GetTimeEventManager(
00382     );
00383 
00386         list<class KX_FontObject*>*
00387     GetFonts(
00388     );
00389 
00391         KX_FontObject*              
00392     FindFont(
00393         KX_FontObject*
00394     );
00395 
00397         void                    
00398     AddFont(
00399         KX_FontObject*
00400     );
00401 
00402 
00405         list<class KX_Camera*>*
00406     GetCameras(
00407     );
00408  
00409 
00411         KX_Camera*              
00412     FindCamera(
00413         KX_Camera*
00414     );
00415 
00417         KX_Camera*              
00418     FindCamera(
00419         STR_String&
00420     );
00421 
00423         void                    
00424     AddCamera(
00425         KX_Camera*
00426     );
00427 
00429         KX_Camera*              
00430     GetActiveCamera(
00431     );
00432 
00438         void                    
00439     SetActiveCamera(
00440         class KX_Camera*
00441     );
00442 
00447         void
00448     SetCameraOnTop(
00449         class KX_Camera*
00450     );
00451 
00456         void                    
00457     SetCanvasDesignWidth(
00458         unsigned int width
00459     );
00464         void                    
00465     SetCanvasDesignHeight(
00466         unsigned int height
00467     );
00472         unsigned int            
00473     GetCanvasDesignWidth(
00474         void
00475     ) const;
00476 
00481         unsigned int            
00482     GetCanvasDesignHeight(
00483         void
00484     ) const;
00485 
00490         void
00491     SetFramingType(
00492         RAS_FrameSettings & frame_settings
00493     );
00494 
00502     const
00503         RAS_FrameSettings &
00504     GetFramingType(
00505     ) const;
00506 
00511     void SetSceneViewport(const RAS_Rect &viewport);
00512 
00518     const RAS_Rect& GetSceneViewport() const;
00519     
00523     void SetNetworkDeviceInterface(NG_NetworkDeviceInterface* newInterface);
00524     void SetNetworkScene(NG_NetworkScene *newScene);
00525     void SetWorldInfo(class KX_WorldInfo* wi);
00526     KX_WorldInfo* GetWorldInfo();
00527     void CalculateVisibleMeshes(RAS_IRasterizer* rasty, KX_Camera *cam, int layer=0);
00528     void UpdateMeshTransformations();
00529     KX_Camera* GetpCamera();
00530     NG_NetworkDeviceInterface* GetNetworkDeviceInterface();
00531     NG_NetworkScene* GetNetworkScene();
00532     KX_BlenderSceneConverter *GetSceneConverter() { return m_sceneConverter; }
00533 
00538     void ReplicateLogic(class KX_GameObject* newobj);
00539     static SG_Callbacks m_callbacks;
00540 
00541     const STR_String& GetName();
00542     
00543     // Suspend the entire scene.
00544     void Suspend();
00545 
00546     // Resume a suspended scene.
00547     void Resume();
00548     
00549     // Update the activity box settings for objects in this scene, if needed.
00550     void UpdateObjectActivity(void);
00551 
00552     // Enable/disable activity culling.
00553     void SetActivityCulling(bool b);
00554 
00555     // Set the radius of the activity culling box.
00556     void SetActivityCullingRadius(float f);
00557     bool IsSuspended();
00558     bool IsClearingZBuffer();
00559     void EnableZBufferClearing(bool isclearingZbuffer);
00560     // use of DBVT tree for camera culling
00561     void SetDbvtCulling(bool b) { m_dbvt_culling = b; };
00562     bool GetDbvtCulling() { return m_dbvt_culling; };
00563     void SetDbvtOcclusionRes(int i) { m_dbvt_occlusion_res = i; };
00564     int GetDbvtOcclusionRes() { return m_dbvt_occlusion_res; };
00565     
00566     void SetSceneConverter(class KX_BlenderSceneConverter* sceneConverter);
00567 
00568     class PHY_IPhysicsEnvironment*      GetPhysicsEnvironment()
00569     {
00570         return m_physicsEnvironment;
00571     }
00572 
00573     void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment*   physEnv);
00574 
00575     void    SetGravity(const MT_Vector3& gravity);
00576 
00577     short GetAnimationFPS();
00578     
00582     void SetNodeTree(SG_Tree* root);
00583 
00587     void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
00588     void Render2DFilters(RAS_ICanvas* canvas);
00589 
00590     KX_ObstacleSimulation* GetObstacleSimulation() {return m_obstacleSimulation;};
00591 
00592 #ifdef WITH_PYTHON
00593     /* --------------------------------------------------------------------- */
00594     /* Python interface ---------------------------------------------------- */
00595     /* --------------------------------------------------------------------- */
00596 
00597     KX_PYMETHOD_DOC(KX_Scene, addObject);
00598     KX_PYMETHOD_DOC(KX_Scene, end);
00599     KX_PYMETHOD_DOC(KX_Scene, restart);
00600     KX_PYMETHOD_DOC(KX_Scene, replace);
00601     KX_PYMETHOD_DOC(KX_Scene, suspend);
00602     KX_PYMETHOD_DOC(KX_Scene, resume);
00603     KX_PYMETHOD_DOC(KX_Scene, get);
00604     KX_PYMETHOD_DOC(KX_Scene, drawObstacleSimulation);
00605 
00606 
00607     /* attributes */
00608     static PyObject*    pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00609     static PyObject*    pyattr_get_objects(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00610     static PyObject*    pyattr_get_objects_inactive(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00611     static PyObject*    pyattr_get_lights(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00612     static PyObject*    pyattr_get_cameras(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00613     static PyObject*    pyattr_get_active_camera(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00614     static int          pyattr_set_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00615     static PyObject*    pyattr_get_drawing_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00616     static int          pyattr_set_drawing_callback_pre(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00617     static PyObject*    pyattr_get_drawing_callback_post(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00618     static int          pyattr_set_drawing_callback_post(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
00619 
00620     virtual PyObject* py_repr(void) { return PyUnicode_From_STR_String(GetName()); }
00621     
00622     /* getitem/setitem */
00623     static PyMappingMethods Mapping;
00624     static PySequenceMethods    Sequence;
00625 
00629     void RunDrawingCallbacks(PyObject* cb_list);
00630     
00631     PyObject* GetPreDrawCB() { return m_draw_call_pre; };
00632     PyObject* GetPostDrawCB() { return m_draw_call_post; };
00633 #endif
00634 
00638     void setSuspendedTime(double suspendedtime);
00642     double getSuspendedTime();
00647     void setSuspendedDelta(double suspendeddelta);
00652     double getSuspendedDelta();
00656     struct Scene *GetBlenderScene() { return m_blenderScene; }
00657 
00658     bool MergeScene(KX_Scene *other);
00659 
00660 
00661     //void PrintStats(int verbose_level) {
00662     //  m_bucketmanager->PrintStats(verbose_level)
00663     //}
00664 };
00665 
00666 typedef std::vector<KX_Scene*> KX_SceneList;
00667 
00668 #endif //__KX_SCENE_H
00669