scene_graph_manager.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2012-2014 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "scene_graph_manager.h"
  6. #include "scene_graph.h"
  7. #include "array.h"
  8. #include "memory.h"
  9. namespace crown
  10. {
  11. SceneGraphManager::SceneGraphManager()
  12. : m_graphs(default_allocator())
  13. {
  14. }
  15. SceneGraphManager::~SceneGraphManager()
  16. {
  17. }
  18. SceneGraph* SceneGraphManager::create_scene_graph()
  19. {
  20. uint32_t index = array::size(m_graphs);
  21. SceneGraph* sg = CE_NEW(default_allocator(), SceneGraph)(default_allocator(), index);
  22. array::push_back(m_graphs, sg);
  23. return sg;
  24. }
  25. void SceneGraphManager::destroy_scene_graph(SceneGraph* sg)
  26. {
  27. CE_ASSERT_NOT_NULL(sg);
  28. m_graphs[sg->m_index] = m_graphs[array::size(m_graphs) - 1];
  29. m_graphs[sg->m_index]->m_index = sg->m_index;
  30. array::pop_back(m_graphs);
  31. CE_DELETE(default_allocator(), sg);
  32. }
  33. void SceneGraphManager::update()
  34. {
  35. for (uint32_t i = 0; i < array::size(m_graphs); i++)
  36. {
  37. m_graphs[i]->update();
  38. }
  39. }
  40. } // namespace crown