4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
33 #include "KX_PhysicsEngineEnums.h"
35 #include "MT_CmMatrix4x4.h"
42 #include "GEN_HashedPtr.h"
43 #include "SG_IObject.h"
44 #include "SCA_IScene.h"
45 #include "MT_Transform.h"
46 #include "SND_Scene.h"
47 #include "RAS_FramingManager.h"
50 #include "PyObjectPlus.h"
53 * @section Forward declarations
55 struct SM_MaterialProps;
62 class SCA_LogicManager;
63 class SCA_KeyboardManager;
64 class SCA_TimeEventManager;
65 class SCA_MouseManager;
67 class SCA_IInputDevice;
69 class SND_IAudioDevice;
70 class NG_NetworkDeviceInterface;
71 class NG_NetworkScene;
79 class RAS_BucketManager;
80 class RAS_BucketManager;
81 class RAS_MaterialBucket;
82 class RAS_IPolyMaterial;
83 class RAS_IRasterizer;
84 class RAS_IRenderTools;
85 class SCA_JoystickManager;
86 class btCollisionShape;
87 class KX_BlenderSceneConverter;
88 struct KX_ClientObjectInfo;
91 * The KX_Scene holds all data for an independent scene. It relates
92 * KX_Objects to the specific objects in the modules.
94 class KX_Scene : public PyObjectPlus, public SCA_IScene
100 CullingInfo(int layer) : m_layer(layer) {}
104 RAS_BucketManager* m_bucketmanager;
105 CListValue* m_tempObjectList;
108 * The list of objects which have been removed during the
109 * course of one frame. They are actually destroyed in
110 * LogicEndFrame() via a call to RemoveObject().
112 CListValue* m_euthanasyobjects;
114 * The list of objects that couldn't be released during logic update.
115 * for example, AddObject actuator sometimes releases an object that was cached from previous frame
117 CListValue* m_delayReleaseObjects;
119 CListValue* m_objectlist;
120 CListValue* m_parentlist; // all 'root' parents
121 CListValue* m_lightlist;
122 CListValue* m_inactivelist; // all objects that are not in the active layer
125 * The tree of objects in the scene.
127 SG_Tree* m_objecttree;
130 * The set of cameras for this scene
132 list<class KX_Camera*> m_cameras;
134 * Various SCA managers used by the scene
136 SCA_LogicManager* m_logicmgr;
137 SCA_KeyboardManager* m_keyboardmgr;
138 SCA_MouseManager* m_mousemgr;
139 SCA_TimeEventManager* m_timemgr;
141 // Scene converter where many scene entities are registered
142 // Used to deregister objects that are deleted
143 class KX_BlenderSceneConverter* m_sceneConverter;
145 * physics engine abstraction
147 //e_PhysicsEngine m_physicsEngine; //who needs this ?
148 class PHY_IPhysicsEnvironment* m_physicsEnvironment;
151 * Does this scene clear the z-buffer?
153 bool m_isclearingZbuffer;
156 * The name of the scene
158 STR_String m_sceneName;
161 * stores the worldsettings for a scene
163 KX_WorldInfo* m_worldinfo;
166 * @section Different scenes, linked to ketsji scene
173 SND_Scene* m_soundScene;
174 SND_IAudioDevice* m_adi;
179 NG_NetworkDeviceInterface* m_networkDeviceInterface;
180 NG_NetworkScene* m_networkScene;
183 * A temoprary variable used to parent objects together on
184 * replication. Don't get confused by the name it is not
185 * the scene's root node!
190 * The active camera for the scene
192 KX_Camera* m_active_camera;
195 * The projection and view matrices of this scene
196 * The projection matrix is computed externally by KX_Engine
197 * The view mat is stored as a side effect of GetViewMatrix()
198 * and is totally unnessary.
200 MT_CmMatrix4x4 m_projectionmat;
201 MT_CmMatrix4x4 m_viewmat;
203 /** Desired canvas width set at design time. */
204 unsigned int m_canvasDesignWidth;
205 /** Desired canvas height set at design time. */
206 unsigned int m_canvasDesignHeight;
209 * Another temporary variable outstaying its welcome
210 * used in AddReplicaObject to map game objects to their
211 * replicas so pointers can be updated.
213 GEN_Map <GEN_HashedPtr, void*> m_map_gameobject_to_replica;
216 * Another temporary variable outstaying its welcome
217 * used in AddReplicaObject to keep a record of all added
218 * objects. Logic can only be updated when all objects
219 * have been updated. This stores a list of the new objects.
221 std::vector<KX_GameObject*> m_logicHierarchicalGameObjects;
224 * This temporary variable will contain the list of
225 * object that can be added during group instantiation.
226 * objects outside this list will not be added (can
227 * happen with children that are outside the group).
228 * Used in AddReplicaObject. If the list is empty, it
231 std::set<CValue*> m_groupGameObjects;
234 * Pointer to system variable passed in in constructor
235 * only used in constructor so we do not need to keep it
236 * around in this class.
239 SCA_ISystem* m_kxsystem;
242 * The execution priority of replicated object actuators?
244 int m_ueberExecutionPriority;
247 * Activity 'bubble' settings :
248 * Suspend (freeze) the entire scene.
253 * Radius in Manhattan distance of the box for activity culling.
255 float m_activity_box_radius;
258 * Toggle to enable or disable activity culling.
260 bool m_activity_culling;
263 * Toggle to enable or disable culling via DBVT broadphase of Bullet.
268 * The framing settings used by this scene
271 RAS_FrameSettings m_frame_settings;
274 * This scenes viewport into the game engine
275 * canvas.Maintained externally, initially [0,0] -> [0,0]
280 * Visibility testing functions.
282 void MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty, KX_Camera*cam,int layer=0);
283 void MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool visible, KX_Camera*cam,int layer=0);
284 void MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj, KX_Camera*cam, int layer=0);
285 static void PhysicsCullingCallback(KX_ClientObjectInfo* objectInfo, void* cullingInfo);
287 double m_suspendedtime;
288 double m_suspendeddelta;
291 * This stores anything from python
293 PyObject* m_attrlist;
295 struct Scene* m_blenderScene;
298 KX_Scene(class SCA_IInputDevice* keyboarddevice,
299 class SCA_IInputDevice* mousedevice,
300 class NG_NetworkDeviceInterface* ndi,
301 class SND_IAudioDevice* adi,
302 const STR_String& scenename,
303 struct Scene* scene);
308 RAS_BucketManager* GetBucketManager();
309 RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial* polymat, bool &bucketCreated);
310 void RenderBuckets(const MT_Transform& cameratransform,
311 RAS_IRasterizer* rasty,
312 RAS_IRenderTools* rendertools);
314 * Update all transforms according to the scenegraph.
316 void UpdateParents(double curtime);
317 void DupliGroupRecurse(CValue* gameobj, int level);
318 bool IsObjectInGroup(CValue* gameobj)
320 return (m_groupGameObjects.empty() ||
321 m_groupGameObjects.find(gameobj) != m_groupGameObjects.end());
323 SCA_IObject* AddReplicaObject(CValue* gameobj,
326 KX_GameObject* AddNodeReplicaObject(SG_IObject* node,
328 void RemoveNodeDestructObject(SG_IObject* node,
330 void RemoveObject(CValue* gameobj);
331 void DelayedRemoveObject(CValue* gameobj);
333 void DelayedReleaseObject(CValue* gameobj);
335 int NewRemoveObject(CValue* gameobj);
336 void ReplaceMesh(CValue* gameobj,
339 * @section Logic stuff
340 * Initiate an update of the logic system.
342 void LogicBeginFrame(double curtime);
343 void LogicUpdateFrame(double curtime, bool frame);
369 SCA_TimeEventManager*
373 list<class KX_Camera*>*
378 /** Find a camera in the scene by pointer. */
384 /** Find a scene in the scene by name. */
390 /** Add a camera to this scene. */
396 /** Find the currently active camera. */
402 * Set this camera to be the active camera in the scene. If the
403 * camera is not present in the camera list, it will be added
412 * Move this camera to the end of the list so that it is rendered last.
413 * If the camera is not on the list, it will be added
420 /** Return the viewmatrix as used by the last frame. */
426 * Return the projectionmatrix as used by the last frame. This is
433 /** Sets the projection matrix. */
440 * Activates new desired canvas width set at design time.
441 * @param width The new desired width.
444 SetCanvasDesignWidth(
448 * Activates new desired canvas height set at design time.
449 * @param width The new desired height.
452 SetCanvasDesignHeight(
456 * Returns the current desired canvas width set at design time.
457 * @return The desired width.
460 GetCanvasDesignWidth(
465 * Returns the current desired canvas height set at design time.
466 * @return The desired height.
469 GetCanvasDesignHeight(
474 * Set the framing options for this scene
479 RAS_FrameSettings & frame_settings
483 * Return a const reference to the framing
484 * type set by the above call.
485 * The contents are not guarenteed to be sensible
486 * if you don't call the above function.
495 * Store the current scene's viewport on the
496 * game engine canvas.
498 void SetSceneViewport(const RAS_Rect &viewport);
501 * Get the current scene's viewport on the
502 * game engine canvas. This maintained
503 * externally in KX_GameEngine
505 const RAS_Rect& GetSceneViewport() const;
508 * @section Accessors to different scenes of this scene
510 void SetNetworkDeviceInterface(NG_NetworkDeviceInterface* newInterface);
511 void SetNetworkScene(NG_NetworkScene *newScene);
512 void SetWorldInfo(class KX_WorldInfo* wi);
513 KX_WorldInfo* GetWorldInfo();
514 void CalculateVisibleMeshes(RAS_IRasterizer* rasty, KX_Camera *cam, int layer=0);
515 void UpdateMeshTransformations();
516 KX_Camera* GetpCamera();
517 SND_Scene* GetSoundScene();
518 NG_NetworkDeviceInterface* GetNetworkDeviceInterface();
519 NG_NetworkScene* GetNetworkScene();
522 * Replicate the logic bricks associated to this object.
525 void ReplicateLogic(class KX_GameObject* newobj);
526 static SG_Callbacks m_callbacks;
528 const STR_String& GetName();
530 // Suspend the entire scene.
533 // Resume a suspended scene.
536 // Update the activity box settings for objects in this scene, if needed.
537 void UpdateObjectActivity(void);
539 // Enable/disable activity culling.
540 void SetActivityCulling(bool b);
542 // Set the radius of the activity culling box.
543 void SetActivityCullingRadius(float f);
545 bool IsClearingZBuffer();
546 void EnableZBufferClearing(bool isclearingZbuffer);
547 // use of DBVT tree for camera culling
548 void SetDbvtCameraCulling(bool b) { m_dbvt_culling = b; };
549 bool GetDbvtCameraCulling() { return m_dbvt_culling; };
551 void SetSceneConverter(class KX_BlenderSceneConverter* sceneConverter);
553 class PHY_IPhysicsEnvironment* GetPhysicsEnvironment()
555 return m_physicsEnvironment;
558 void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv);
560 void SetGravity(const MT_Vector3& gravity);
563 * Sets the node tree for this scene.
565 void SetNodeTree(SG_Tree* root);
567 KX_PYMETHOD_DOC_NOARGS(KX_Scene, getLightList);
568 KX_PYMETHOD_DOC_NOARGS(KX_Scene, getObjectList);
569 KX_PYMETHOD_DOC_NOARGS(KX_Scene, getName);
570 KX_PYMETHOD_DOC(KX_Scene, addObject);
572 KX_PYMETHOD_DOC(KX_Scene, getActiveCamera);
573 KX_PYMETHOD_DOC(KX_Scene, getActiveCamera);
574 KX_PYMETHOD_DOC(KX_Scene, findCamera);
576 KX_PYMETHOD_DOC(KX_Scene, getGravity);
578 KX_PYMETHOD_DOC(KX_Scene, setActivityCulling);
579 KX_PYMETHOD_DOC(KX_Scene, setActivityCullingRadius);
581 KX_PYMETHOD_DOC(KX_Scene, setSceneViewport);
582 KX_PYMETHOD_DOC(KX_Scene, setSceneViewport);
586 static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
587 static PyObject* pyattr_get_objects(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
588 static PyObject* pyattr_get_active_camera(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
590 /* for dir(), python3 uses __dir__() */
591 static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
594 virtual PyObject* py_getattro(PyObject *attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */
595 virtual int py_setattro(PyObject *attr, PyObject *pyvalue);
596 virtual int py_delattro(PyObject *attr);
597 virtual PyObject* py_repr(void) { return PyString_FromString(GetName().ReadPtr()); }
601 * Sets the time the scene was suspended
603 void setSuspendedTime(double suspendedtime);
605 * Returns the "curtime" the scene was suspended
607 double getSuspendedTime();
609 * Sets the difference between the local time of the scene (when it
610 * was running and not suspended) and the "curtime"
612 void setSuspendedDelta(double suspendeddelta);
614 * Returns the difference between the local time of the scene (when it
615 * was running and not suspended) and the "curtime"
617 double getSuspendedDelta();
619 * Returns the Blender scene this was made from
621 struct Scene *GetBlenderScene() { return m_blenderScene; }
624 typedef std::vector<KX_Scene*> KX_SceneList;
626 #endif //__KX_SCENE_H