2
0

SceneComponent.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/scene/Common.h>
  7. #include <anki/core/Timestamp.h>
  8. #include <anki/util/Functions.h>
  9. #include <anki/util/Bitset.h>
  10. namespace anki
  11. {
  12. /// @addtogroup scene
  13. /// @{
  14. /// Scene node component
  15. class SceneComponent
  16. {
  17. public:
  18. // The type of the components
  19. enum class Type : U16
  20. {
  21. NONE,
  22. FRUSTUM,
  23. MOVE,
  24. RENDER,
  25. SPATIAL,
  26. LIGHT,
  27. LENS_FLARE,
  28. BODY,
  29. SECTOR_PORTAL,
  30. REFLECTION_PROBE,
  31. REFLECTION_PROXY,
  32. PLAYER_CONTROLLER,
  33. LAST_COMPONENT_ID = PLAYER_CONTROLLER
  34. };
  35. /// Construct the scene component.
  36. SceneComponent(Type type, SceneNode* node)
  37. : m_node(node)
  38. , m_type(type)
  39. {
  40. }
  41. virtual ~SceneComponent()
  42. {
  43. }
  44. Type getType() const
  45. {
  46. return m_type;
  47. }
  48. Timestamp getTimestamp() const
  49. {
  50. return m_timestamp;
  51. }
  52. Timestamp getGlobalTimestamp() const;
  53. /// Do some updating
  54. /// @param[in,out] node Scene node of this component.
  55. /// @param prevTime Previous update time.
  56. /// @param crntTime Current update time.
  57. /// @param[out] updated true if an update happened.
  58. virtual ANKI_USE_RESULT Error update(
  59. SceneNode& node, F32 prevTime, F32 crntTime, Bool& updated)
  60. {
  61. updated = false;
  62. return ErrorCode::NONE;
  63. }
  64. /// Called if SceneComponent::update returned true.
  65. virtual ANKI_USE_RESULT Error onUpdate(
  66. SceneNode& node, F32 prevTime, F32 crntTime)
  67. {
  68. return ErrorCode::NONE;
  69. }
  70. /// Called only by the SceneGraph
  71. ANKI_USE_RESULT Error updateReal(
  72. SceneNode& node, F32 prevTime, F32 crntTime, Bool& updated);
  73. void setAutomaticCleanup(Bool enable)
  74. {
  75. m_flags.enableBits(AUTOMATIC_CLEANUP, enable);
  76. }
  77. Bool getAutomaticCleanup() const
  78. {
  79. return m_flags.bitsEnabled(AUTOMATIC_CLEANUP);
  80. }
  81. SceneNode& getSceneNode()
  82. {
  83. return *m_node;
  84. }
  85. const SceneNode& getSceneNode() const
  86. {
  87. return *m_node;
  88. }
  89. SceneAllocator<U8> getAllocator() const;
  90. SceneGraph& getSceneGraph();
  91. const SceneGraph& getSceneGraph() const;
  92. protected:
  93. SceneNode* m_node = nullptr;
  94. Timestamp m_timestamp; ///< Indicates when an update happened
  95. private:
  96. enum Flags
  97. {
  98. AUTOMATIC_CLEANUP = 1 << 0
  99. };
  100. Type m_type;
  101. Bitset<U8> m_flags;
  102. };
  103. /// @}
  104. } // end namespace anki