CmSceneManager.cpp 1.2 KB

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