SceneNode.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #ifndef ANKI_SCENE_SCENE_NODE_H
  2. #define ANKI_SCENE_SCENE_NODE_H
  3. #include "anki/scene/Property.h"
  4. #include "anki/scene/Common.h"
  5. #include "anki/util/Object.h"
  6. namespace anki {
  7. class SceneGraph; // Don't include
  8. // Components forward. Don't include
  9. class MoveComponent;
  10. class RenderComponent;
  11. class FrustumComponent;
  12. class SpatialComponent;
  13. class Light;
  14. class RigidBody;
  15. class Path;
  16. /// @addtogroup Scene
  17. /// @{
  18. /// Interface class backbone of scene
  19. class SceneNode
  20. {
  21. public:
  22. /// @name Constructors/Destructor
  23. /// @{
  24. /// The one and only constructor
  25. /// @param name The unique name of the node. If it's nullptr the the node
  26. /// is not searchable
  27. /// @param scene The scene that will register it
  28. explicit SceneNode(
  29. const char* name,
  30. SceneGraph* scene);
  31. /// Unregister node
  32. virtual ~SceneNode();
  33. /// @}
  34. /// @name Accessors
  35. /// @{
  36. /// Return the name. It may be nullptr for nodes that we don't want to
  37. /// track
  38. const char* getName() const
  39. {
  40. return name.length() > 0 ? name.c_str() : nullptr;
  41. }
  42. SceneAllocator<U8> getSceneAllocator() const;
  43. SceneAllocator<U8> getSceneFrameAllocator() const;
  44. SceneGraph& getSceneGraph()
  45. {
  46. return *scene;
  47. }
  48. /// @}
  49. /// @name Accessors of components
  50. /// @{
  51. MoveComponent* getMoveComponent()
  52. {
  53. return sceneNodeProtected.moveC;
  54. }
  55. const MoveComponent* getMoveComponent() const
  56. {
  57. return sceneNodeProtected.moveC;
  58. }
  59. RenderComponent* getRenderComponent()
  60. {
  61. return sceneNodeProtected.renderC;
  62. }
  63. const RenderComponent* getRenderComponent() const
  64. {
  65. return sceneNodeProtected.renderC;
  66. }
  67. FrustumComponent* getFrustumComponent()
  68. {
  69. return sceneNodeProtected.frustumC;
  70. }
  71. const FrustumComponent* getFrustumComponent() const
  72. {
  73. return sceneNodeProtected.frustumC;
  74. }
  75. SpatialComponent* getSpatialComponent()
  76. {
  77. return sceneNodeProtected.spatialC;
  78. }
  79. const SpatialComponent* getSpatialComponent() const
  80. {
  81. return sceneNodeProtected.spatialC;
  82. }
  83. Light* getLight()
  84. {
  85. return sceneNodeProtected.lightC;
  86. }
  87. const Light* getLight() const
  88. {
  89. return sceneNodeProtected.lightC;
  90. }
  91. RigidBody* getRigidBody()
  92. {
  93. return sceneNodeProtected.rigidBodyC;
  94. }
  95. const RigidBody* getRigidBody() const
  96. {
  97. return sceneNodeProtected.rigidBodyC;
  98. }
  99. Path* getPath()
  100. {
  101. return sceneNodeProtected.pathC;
  102. }
  103. const Path* getPath() const
  104. {
  105. return sceneNodeProtected.pathC;
  106. }
  107. /// @}
  108. /// This is called by the scene every frame after logic and before
  109. /// rendering. By default it does nothing
  110. /// @param[in] prevUpdateTime Timestamp of the previous update
  111. /// @param[in] crntTime Timestamp of this update
  112. /// @param[in] frame Frame number
  113. virtual void frameUpdate(F32 prevUpdateTime, F32 crntTime, I frame)
  114. {
  115. (void)prevUpdateTime;
  116. (void)crntTime;
  117. (void)frame;
  118. }
  119. /// Return the last frame the node was updated. It checks all components
  120. U32 getLastUpdateFrame() const;
  121. /// Mark a node for deletion
  122. void markForDeletion()
  123. {
  124. markedForDeletion = true;
  125. }
  126. Bool isMarkedForDeletion()
  127. {
  128. return markedForDeletion;
  129. }
  130. protected:
  131. struct
  132. {
  133. MoveComponent* moveC = nullptr;
  134. RenderComponent* renderC = nullptr;
  135. FrustumComponent* frustumC = nullptr;
  136. SpatialComponent* spatialC = nullptr;
  137. Light* lightC = nullptr;
  138. RigidBody* rigidBodyC = nullptr;
  139. Path* pathC = nullptr;
  140. } sceneNodeProtected;
  141. private:
  142. SceneGraph* scene = nullptr;
  143. SceneString name; ///< A unique name
  144. Bool8 markedForDeletion;
  145. };
  146. /// @}
  147. } // end namespace anki
  148. #endif