4 * ***** BEGIN GPL/BL DUAL 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. The Blender
10 * Foundation also sells licenses for use in proprietary software under
11 * the Blender License. See http://www.blender.org/BL/ for information
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): none yet.
30 * ***** END GPL/BL DUAL LICENSE BLOCK *****
36 #include "KX_PhysicsEngineEnums.h"
38 #include "MT_CmMatrix4x4.h"
44 #include "GEN_HashedPtr.h"
45 #include "SG_IObject.h"
46 #include "SCA_IScene.h"
47 #include "MT_Transform.h"
48 #include "SND_Scene.h"
49 #include "RAS_FramingManager.h"
52 #include "PyObjectPlus.h"
55 * @section Forward declarations
57 struct SM_MaterialProps;
63 class SCA_LogicManager;
64 class SCA_KeyboardManager;
65 class SCA_TimeEventManager;
66 class SCA_MouseManager;
68 class SCA_IInputDevice;
70 class SND_IAudioDevice;
71 class NG_NetworkDeviceInterface;
72 class NG_NetworkScene;
80 class RAS_BucketManager;
81 class RAS_BucketManager;
82 class RAS_MaterialBucket;
83 class RAS_IPolyMaterial;
84 class RAS_IRasterizer;
85 class RAS_IRenderTools;
86 class SCA_JoystickManager;
88 * The KX_Scene holds all data for an independent scene. It relates
89 * KX_Objects to the specific objects in the modules.
91 class KX_Scene : public PyObjectPlus, public SCA_IScene
95 RAS_BucketManager* m_bucketmanager;
96 CListValue* m_tempObjectList;
99 * The list of objects which have been removed during the
100 * course of one frame. They are actually destroyed in
101 * LogicEndFrame() via a call to RemoveObject().
103 CListValue* m_euthanasyobjects;
105 CListValue* m_objectlist;
106 CListValue* m_parentlist; // all 'root' parents
107 CListValue* m_lightlist;
110 * The tree of objects in the scene.
112 SG_Tree* m_objecttree;
115 * The set of cameras for this scene
117 set<class KX_Camera*> m_cameras;
120 * Various SCA managers used by the scene
122 SCA_LogicManager* m_logicmgr;
123 SCA_KeyboardManager* m_keyboardmgr;
124 SCA_MouseManager* m_mousemgr;
125 SCA_TimeEventManager* m_timemgr;
128 * physics engine abstraction
131 e_PhysicsEngine m_physicsEngine;
132 class PHY_IPhysicsEnvironment* m_physicsEnvironment;
135 * Does this scene clear the z-buffer?
137 bool m_isclearingZbuffer;
140 * The name of the scene
142 STR_String m_sceneName;
145 * stores the worldsettings for a scene
147 KX_WorldInfo* m_worldinfo;
150 * @section Different scenes, linked to ketsji scene
157 SND_Scene* m_soundScene;
158 SND_IAudioDevice* m_adi;
163 NG_NetworkDeviceInterface* m_networkDeviceInterface;
164 NG_NetworkScene* m_networkScene;
167 * A temoprary variable used to parent objects together on
168 * replication. Don't get confused by the name it is not
169 * the scene's root node!
174 * The active camera for the scene
176 KX_Camera* m_active_camera;
179 * The projection and view matrices of this scene
180 * The projection matrix is computed externally by KX_Engine
181 * The view mat is stored as a side effect of GetViewMatrix()
182 * and is totally unnessary.
184 MT_CmMatrix4x4 m_projectionmat;
185 MT_CmMatrix4x4 m_viewmat;
187 /** Desired canvas width set at design time. */
188 unsigned int m_canvasDesignWidth;
189 /** Desired canvas height set at design time. */
190 unsigned int m_canvasDesignHeight;
193 * Another temporary variable outstaying its welcome
194 * used in AddReplicaObject to map game objects to their
195 * replicas so pointers can be updated.
197 GEN_Map <GEN_HashedPtr, void*> m_map_gameobject_to_replica;
200 * Another temporary variable outstaying its welcome
201 * used in AddReplicaObject to keep a record of all added
202 * objects. Logic can only be updated when all objects
203 * have been updated. This stores a list of the new objects.
205 std::vector<KX_GameObject*> m_logicHierarchicalGameObjects;
208 * Pointer to system variable passed in in constructor
209 * only used in constructor so we do not need to keep it
210 * around in this class.
213 SCA_ISystem* m_kxsystem;
216 * The execution priority of replicated object actuators?
218 int m_ueberExecutionPriority;
221 * Activity 'bubble' settings :
222 * Suspend (freeze) the entire scene.
227 * Radius in Manhattan distance of the box for activity culling.
229 float m_activity_box_radius;
232 * Toggle to enable or disable activity culling.
234 bool m_activity_culling;
237 * The framing settings used by this scene
240 RAS_FrameSettings m_frame_settings;
243 * This scenes viewport into the game engine
244 * canvas.Maintained externally, initially [0,0] -> [0,0]
249 * Visibility testing functions.
251 void MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty);
252 void MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool visible);
253 void MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj);
256 * This stores anything from python
258 PyObject* m_attrlist;
261 KX_Scene(class SCA_IInputDevice* keyboarddevice,
262 class SCA_IInputDevice* mousedevice,
263 class NG_NetworkDeviceInterface* ndi,
264 class SND_IAudioDevice* adi,
265 const STR_String& scenename );
270 RAS_BucketManager* GetBucketManager();
271 RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial* polymat);
272 void RenderBuckets(const MT_Transform& cameratransform,
273 RAS_IRasterizer* rasty,
274 RAS_IRenderTools* rendertools);
276 * Update all transforms according to the scenegraph.
278 void UpdateParents(double curtime);
279 SCA_IObject* AddReplicaObject(CValue* gameobj,
282 KX_GameObject* AddNodeReplicaObject(SG_IObject* node,
284 void RemoveNodeDestructObject(SG_IObject* node,
286 void RemoveObject(CValue* gameobj);
287 void DelayedRemoveObject(CValue* gameobj);
288 void NewRemoveObject(CValue* gameobj);
289 void ReplaceMesh(CValue* gameobj,
292 * @section Logic stuff
293 * Initiate an update of the logic system.
295 void LogicBeginFrame(double curtime);
296 void LogicUpdateFrame(double curtime, bool frame);
318 SCA_TimeEventManager*
323 /** Find a camera in the scene by pointer. */
329 /** Find a scene in the scene by name. */
335 /** Add a camera to this scene. */
341 /** Find the currently active camera. */
347 * Set this camera to be the active camera in the scene. If the
348 * camera is not present in the camera list, it will be added
356 /** Return the viewmatrix as used by the last frame. */
362 * Return the projectionmatrix as used by the last frame. This is
369 /** Sets the projection matrix. */
376 * Activates new desired canvas width set at design time.
377 * @param width The new desired width.
380 SetCanvasDesignWidth(
384 * Activates new desired canvas height set at design time.
385 * @param width The new desired height.
388 SetCanvasDesignHeight(
392 * Returns the current desired canvas width set at design time.
393 * @return The desired width.
396 GetCanvasDesignWidth(
401 * Returns the current desired canvas height set at design time.
402 * @return The desired height.
405 GetCanvasDesignHeight(
410 * Set the framing options for this scene
415 RAS_FrameSettings & frame_settings
419 * Return a const reference to the framing
420 * type set by the above call.
421 * The contents are not guarenteed to be sensible
422 * if you don't call the above function.
431 * Store the current scene's viewport on the
432 * game engine canvas.
434 void SetSceneViewport(const RAS_Rect &viewport);
437 * Get the current scene's viewport on the
438 * game engine canvas. This maintained
439 * externally in KX_GameEngine
441 const RAS_Rect& GetSceneViewport() const;
444 * @section Accessors to different scenes of this scene
446 void SetNetworkDeviceInterface(NG_NetworkDeviceInterface* newInterface);
447 void SetNetworkScene(NG_NetworkScene *newScene);
448 void SetWorldInfo(class KX_WorldInfo* wi);
449 KX_WorldInfo* GetWorldInfo();
450 void CalculateVisibleMeshes(RAS_IRasterizer* rasty);
451 void UpdateMeshTransformations();
452 KX_Camera* GetpCamera();
453 SND_Scene* GetSoundScene();
454 NG_NetworkDeviceInterface* GetNetworkDeviceInterface();
455 NG_NetworkScene* GetNetworkScene();
458 * Replicate the logic bricks associated to this object.
461 void ReplicateLogic(class KX_GameObject* newobj);
462 static SG_Callbacks m_callbacks;
464 const STR_String& GetName();
466 // Suspend the entire scene.
469 // Resume a suspended scene.
472 // Update the activity box settings for objects in this scene, if needed.
473 void UpdateObjectActivity(void);
475 // Enable/disable activity culling.
476 void SetActivityCulling(bool b);
478 // Set the radius of the activity culling box.
479 void SetActivityCullingRadius(float f);
481 bool IsClearingZBuffer();
482 void EnableZBufferClearing(bool isclearingZbuffer);
484 class PHY_IPhysicsEnvironment* GetPhysicsEnvironment()
486 return m_physicsEnvironment;
489 void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv);
491 void SetGravity(const MT_Vector3& gravity);
494 * Sets the node tree for this scene.
496 void SetNodeTree(SG_Tree* root);
498 KX_PYMETHOD_DOC(KX_Scene, getLightList);
499 KX_PYMETHOD_DOC(KX_Scene, getObjectList);
500 KX_PYMETHOD_DOC(KX_Scene, getName);
502 KX_PYMETHOD_DOC(KX_Scene, getActiveCamera);
503 KX_PYMETHOD_DOC(KX_Scene, getActiveCamera);
504 KX_PYMETHOD_DOC(KX_Scene, findCamera);
506 KX_PYMETHOD_DOC(KX_Scene, getGravity);
508 KX_PYMETHOD_DOC(KX_Scene, setActivityCulling);
509 KX_PYMETHOD_DOC(KX_Scene, setActivityCullingRadius);
511 KX_PYMETHOD_DOC(KX_Scene, setSceneViewport);
512 KX_PYMETHOD_DOC(KX_Scene, setSceneViewport);
515 virtual PyObject* _getattr(const STR_String& attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */
516 virtual int _setattr(const STR_String &attr, PyObject *pyvalue);
517 virtual int _delattr(const STR_String &attr);
520 typedef std::vector<KX_Scene*> KX_SceneList;
522 #endif //__KX_SCENE_H