Ocular Engine
SceneManager.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_CORE_SCENE_MANAGER__H__
19 #define __H__OCULAR_CORE_SCENE_MANAGER__H__
20 
21 #include "Scene.hpp"
22 #include "SceneObject.hpp"
23 #include "SceneTreeType.hpp"
24 #include "Renderer/Renderer.hpp"
25 #include "ComponentFactory.hpp"
26 #include "FileIO/File.hpp"
27 #include "Math/Geometry/Frustum.hpp"
28 
29 #include <unordered_map>
30 
31 //------------------------------------------------------------------------------------------
32 
37 namespace Ocular
38 {
39  // Forward Declaration
40 
41  class Engine;
42 
47  namespace Core
48  {
65  {
66  friend class Engine;
67  friend class SceneObject;
68  friend class ARoutine;
69 
70  public:
71 
72  SceneManager();
73  ~SceneManager();
74 
75  //------------------------------------------------------------------------------
76  // SceneObject Methods
77 
86  SceneObject* createObject(std::string const& name = "Unnamed", SceneObject* parent = nullptr);
87 
91  template<class T>
92  T* createObject(std::string const& name = "Unnamed", SceneObject* parent = nullptr)
93  {
94  T* result = new T(name, parent);
95  addObject(result);
96 
97  return result;
98  }
99 
112  SceneObject* createObjectOfType(std::string const& type, std::string const& name = "Unnamed", SceneObject* parent = nullptr);
113 
121  SceneObject* duplicateObject(SceneObject const* object);
122 
132  void destroyObject(SceneObject* object);
133 
147  void destroyObject(std::string const& name, bool removeAll = false);
148 
158  void destroyObject(UUID const& uuid);
159 
172  SceneObject* findObject(std::string const& name) const;
173 
180  void findObjects(std::string const& name, std::vector<SceneObject*>& objects) const;
181 
188  SceneObject* findObject(UUID const& uuid) const;
189 
193  void findTopObjects(std::vector<SceneObject*>& object) const;
194 
199  void updateUUID(UUID const& uuid);
200 
211  void getVisibleSceneObjects(std::vector<SceneObject*>& objects, Math::Frustum const& frustum);
212 
222  void triggerObjectDirty(UUID const& uuid, bool staticObject);
223 
224  //------------------------------------------------------------------------------
225  // Scene Methods
226 
238  void createScene(std::string const& name, SceneTreeType staticType = SceneTreeType::BoundingVolumeHierarchyCPU, SceneTreeType dynamicType = SceneTreeType::BoundingVolumeHierarchyCPU);
239 
253  bool loadScene(File const& file);
254 
261  bool saveScene(File const& file);
262 
266  bool isSceneActive() const;
267 
271  ComponentFactory<ARoutine>& getRoutineFactory();
272 
276  ComponentFactory<ARenderable>& getRenderableFactory();
277 
281  ComponentFactory<SceneObject>& getSceneObjectFactory();
282 
286  ComponentFactory<Renderer>& getRendererFactory();
287 
288  protected:
289 
290  void loadPersistentObjects();
291 
296  void addObject(SceneObject* object, SceneObject* parent = nullptr);
297 
301  void unloadScene();
302 
307  void update();
308 
312  void render();
313 
318  void objectActiveChanged(SceneObject* object);
319 
324  void objectVisibleChanged(SceneObject* object);
325 
330  void objectStaticChanged(SceneObject* object);
331 
336  void objectAddedRoutine(ARoutine* routine);
337 
342  void objectRemovedRoutine(ARoutine* routine);
343 
350  void objectParentChanged(SceneObject* object, SceneObject* oldParent);
351 
352  private:
353 
354  void deleteObject(SceneObject* object);
355 
356  std::unordered_map<std::string, SceneObject*> m_Objects;
357  Scene* m_Scene;
358 
359  ComponentFactory<ARoutine> m_RoutineFactory;
360  ComponentFactory<ARenderable> m_RenderableFactory;
361  ComponentFactory<SceneObject> m_SceneObjectFactory;
362  ComponentFactory<Renderer> m_RendererFactory;
363  };
364  }
368 }
373 //------------------------------------------------------------------------------------------
374 
375 #endif
bool saveScene(File const &file)
Definition: SceneManager.cpp:327
Definition: OcularEngine.hpp:49
SceneObject * findObject(std::string const &name) const
Definition: SceneManager.cpp:163
void objectRemovedRoutine(ARoutine *routine)
Definition: SceneManager.cpp:508
void update()
Definition: SceneManager.cpp:454
void objectVisibleChanged(SceneObject *object)
Definition: SceneManager.cpp:478
void createScene(std::string const &name, SceneTreeType staticType=SceneTreeType::BoundingVolumeHierarchyCPU, SceneTreeType dynamicType=SceneTreeType::BoundingVolumeHierarchyCPU)
Definition: SceneManager.cpp:277
Definition: SceneManager.hpp:64
Definition: ComponentFactory.hpp:43
Definition: Frustum.hpp:57
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
void getVisibleSceneObjects(std::vector< SceneObject * > &objects, Math::Frustum const &frustum)
Definition: SceneManager.cpp:261
Definition: ARoutine.hpp:59
SceneObject * createObject(std::string const &name="Unnamed", SceneObject *parent=nullptr)
Definition: SceneManager.cpp:51
Definition: Scene.hpp:70
SceneObject * duplicateObject(SceneObject const *object)
Definition: SceneManager.cpp:69
void objectParentChanged(SceneObject *object, SceneObject *oldParent)
Definition: SceneManager.cpp:519
void destroyObject(SceneObject *object)
Definition: SceneManager.cpp:101
void render()
Definition: SceneManager.cpp:462
void findTopObjects(std::vector< SceneObject * > &object) const
Definition: SceneManager.cpp:212
void objectStaticChanged(SceneObject *object)
Definition: SceneManager.cpp:486
void objectAddedRoutine(ARoutine *routine)
Definition: SceneManager.cpp:497
void updateUUID(UUID const &uuid)
Definition: SceneManager.cpp:228
Definition: SceneObject.hpp:93
bool loadScene(File const &file)
Definition: SceneManager.cpp:301
Definition: UUID.hpp:45
void findObjects(std::string const &name, std::vector< SceneObject * > &objects) const
Definition: SceneManager.cpp:185
Definition: File.hpp:41
bool isSceneActive() const
Definition: SceneManager.cpp:339
void objectActiveChanged(SceneObject *object)
Definition: SceneManager.cpp:470
void addObject(SceneObject *object, SceneObject *parent=nullptr)
Definition: SceneManager.cpp:386
SceneObject * createObjectOfType(std::string const &type, std::string const &name="Unnamed", SceneObject *parent=nullptr)
Definition: SceneManager.cpp:56
void triggerObjectDirty(UUID const &uuid, bool staticObject)
Definition: SceneManager.cpp:269