SceneNode.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "anki/scene/SceneNode.h"
  2. #include "anki/scene/SceneGraph.h"
  3. #include "anki/scene/MoveComponent.h"
  4. #include "anki/scene/SpatialComponent.h"
  5. #include "anki/scene/FrustumComponent.h"
  6. namespace anki {
  7. //==============================================================================
  8. SceneNode::SceneNode(const char* name_, SceneGraph* scene_)
  9. : scene(scene_),
  10. name(getSceneAllocator()),
  11. components(getSceneAllocator()),
  12. markedForDeletion(false)
  13. {
  14. ANKI_ASSERT(scene);
  15. components.reserve(2);
  16. if(name_)
  17. {
  18. name = SceneString(name_, scene->getAllocator());
  19. }
  20. }
  21. //==============================================================================
  22. SceneNode::~SceneNode()
  23. {
  24. SceneAllocator<SceneComponent*> alloc = getSceneAllocator();
  25. for(auto comp : components)
  26. {
  27. alloc.deleteInstance(comp);
  28. }
  29. }
  30. //==============================================================================
  31. SceneAllocator<U8> SceneNode::getSceneAllocator() const
  32. {
  33. ANKI_ASSERT(scene);
  34. return scene->getAllocator();
  35. }
  36. //==============================================================================
  37. SceneAllocator<U8> SceneNode::getSceneFrameAllocator() const
  38. {
  39. ANKI_ASSERT(scene);
  40. return scene->getFrameAllocator();
  41. }
  42. //==============================================================================
  43. U32 SceneNode::getLastUpdateFrame() const
  44. {
  45. U32 max = 0;
  46. iterateComponents([&](const SceneComponent& comp)
  47. {
  48. max = std::max(max, comp.getTimestamp());
  49. });
  50. return max;
  51. }
  52. } // end namespace anki