BsSceneActor.h 3.9 KB

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