CmSceneManager.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "CmSceneManager.h"
  2. #include "CmSceneObject.h"
  3. #include "CmComponent.h"
  4. #include "CmCamera.h"
  5. #include "CmRenderable.h"
  6. namespace CamelotEngine
  7. {
  8. SceneManager::SceneManager()
  9. {
  10. mRootNode = SceneObject::createInternal("SceneRoot");
  11. }
  12. SceneManager::~SceneManager()
  13. {
  14. if(mRootNode != nullptr)
  15. mRootNode->destroy();
  16. }
  17. void SceneManager::update()
  18. {
  19. stack<HSceneObject>::type todo;
  20. todo.push(mRootNode);
  21. while(!todo.empty())
  22. {
  23. HSceneObject currentGO = todo.top();
  24. todo.pop();
  25. vector<HComponent>::type components = currentGO->getComponents();
  26. for(auto iter = components.begin(); iter != components.end(); ++iter)
  27. {
  28. (*iter)->update();
  29. }
  30. for(UINT32 i = 0; i < currentGO->getNumChildren(); i++)
  31. todo.push(currentGO->getChild(i));
  32. }
  33. }
  34. void SceneManager::registerNewGO(const HSceneObject& node)
  35. {
  36. if(mRootNode) // If root node is null, then this new node is the root node
  37. node->setParent(mRootNode);
  38. }
  39. void SceneManager::notifyComponentAdded(const HComponent& component) { }
  40. void SceneManager::notifyComponentRemoved(const HComponent& component) { }
  41. SceneManager& gSceneManager()
  42. {
  43. return SceneManager::instance();
  44. }
  45. }