BsSceneActor.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Scene/BsTransform.h"
  6. namespace bs
  7. {
  8. /** @addtogroup Scene-Internal
  9. * @{
  10. */
  11. /** Signals which portion of a scene actor is dirty. */
  12. enum class ActorDirtyFlag
  13. {
  14. Transform = 1 << 0,
  15. Mobility = 1 << 1,
  16. Active = 1 << 2,
  17. Everything = 1 << 3,
  18. Dependency = 1 << 31
  19. };
  20. /**
  21. * A base class for objects that can be placed in the scene. It has a transform object that allows it to be positioned,
  22. * scaled and rotated, as well a properties that control its mobility (movable vs. immovable) and active status.
  23. *
  24. * In a way scene actors are similar to SceneObject%s, the main difference being that their implementations perform
  25. * some functionality directly, rather than relying on attached Components. Scene actors can be considered as a
  26. * lower-level alternative to SceneObject/Component model. In fact many Components internally just wrap scene actors.
  27. */
  28. class BS_CORE_EXPORT SceneActor
  29. {
  30. public:
  31. SceneActor();
  32. virtual ~SceneActor();
  33. /** Determines the position, rotation and scale of the actor. */
  34. virtual void setTransform(const Transform& transform);
  35. /** @copydoc setTransform */
  36. const Transform& getTransform() const { return mTransform; }
  37. /** Shorthand for getTransform(). */
  38. const Transform& tfrm() const { return mTransform; }
  39. /**
  40. * Determines if the actor is currently active. Deactivated actors act as if they have been destroyed, without
  41. * actually being destroyed.
  42. */
  43. virtual void setActive(bool active);
  44. /** @copydoc setActive */
  45. bool getActive() const { return mActive; }
  46. /**
  47. * Determines the mobility of the actor. This is used primarily as a performance hint to engine systems. Objects
  48. * with more restricted mobility will result in higher performance. Any transform changes to immobile actors will
  49. * be ignored. By default actor's mobility is unrestricted.
  50. */
  51. virtual void setMobility(ObjectMobility mobility);
  52. /** @copydoc setMobility */
  53. ObjectMobility getMobility() const { return mMobility; }
  54. /**
  55. * @name Internal
  56. * @{
  57. */
  58. /**
  59. * Updates the internal actor state by transfering the relevant state from the scene object. The system tracks
  60. * the last state and only performs the update if the scene object was modified since the last call. You can force
  61. * an update by setting the @p force parameter to true.
  62. *
  63. * This method is used by the scene manager to update actors that have been bound to a scene object. Never call this
  64. * method for multiple different scene objects, as actor can only ever be bound to one during its lifetime.
  65. */
  66. virtual void _updateState(const SceneObject& so, bool force = false);
  67. /** @} */
  68. protected:
  69. /**
  70. * Marks the simulation thread object as dirty and notifies the system its data should be synced with its core
  71. * thread counterpart.
  72. */
  73. virtual void _markCoreDirty(ActorDirtyFlag flag = ActorDirtyFlag::Everything) { }
  74. /**
  75. * Writes the contents of this object into the provided data buffer. Buffer must have enough size of hold
  76. * getSyncActorDataSize() bytes. Returns the address after the last written byte.
  77. */
  78. char* syncActorTo(char* data);
  79. /**
  80. * Reads the contents of this object from the provided data buffer. The buffer is expected to be populated by the
  81. * sim thread version of this object by calling syncActorTo(). Returns the address after the last read byte.
  82. */
  83. char* syncActorFrom(char* data);
  84. /** Returns the size of the buffer required to store all data in this object, in bytes. */
  85. UINT32 getActorSyncDataSize() const;
  86. protected:
  87. friend class SceneManager;
  88. Transform mTransform;
  89. ObjectMobility mMobility;
  90. bool mActive;
  91. UINT32 mHash;
  92. };
  93. /** @} */
  94. }