BsGameObject.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 "BsIReflectable.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Scene
  9. * @{
  10. */
  11. /** @cond INTERNAL */
  12. /** Contains instance data that is held by all GameObject handles. */
  13. struct GameObjectInstanceData
  14. {
  15. GameObjectInstanceData()
  16. :mInstanceId(0), object(nullptr)
  17. { }
  18. std::shared_ptr<GameObject> object;
  19. UINT64 mInstanceId;
  20. };
  21. typedef std::shared_ptr<GameObjectInstanceData> GameObjectInstanceDataPtr;
  22. /** Flags used for notifying child scene object and components when a transform has been changed. */
  23. enum TransformChangedFlags
  24. {
  25. TCF_None = 0x00,
  26. TCF_Transform = 0x01,
  27. TCF_Parent = 0x02
  28. };
  29. /** @endcond */
  30. /**
  31. * Type of object that can be referenced by a GameObject handle. Each object has an unique ID and is registered with
  32. * the GameObjectManager.
  33. */
  34. class BS_CORE_EXPORT GameObject : public IReflectable
  35. {
  36. public:
  37. GameObject();
  38. virtual ~GameObject();
  39. /** Returns the unique instance ID of the GameObject. */
  40. UINT64 getInstanceId() const { return mInstanceData->mInstanceId; }
  41. /**
  42. * Returns an ID that identifies a link between this object and its equivalent in the linked prefab. This will be
  43. * -1 if the object has no prefab link, or if the object is specific to the instance and has no prefab equivalent.
  44. */
  45. UINT32 getLinkId() const { return mLinkId; }
  46. /** Gets the name of the object. */
  47. const String& getName() const { return mName; }
  48. /** Sets the name of the object. */
  49. void setName(const String& name) { mName = name; }
  50. public: // ***** INTERNAL ******
  51. /** @cond INTERNAL */
  52. /**
  53. * Marks the object as destroyed. Generally this means the object has been queued for destruction but it hasn't
  54. * occurred yet.
  55. */
  56. void _setIsDestroyed() { mIsDestroyed = true; }
  57. /** Checks if the object has been destroyed. */
  58. bool _getIsDestroyed() const { return mIsDestroyed; }
  59. /** Changes the prefab link ID for this object. See getLinkId(). */
  60. void _setLinkId(UINT32 id) { mLinkId = id; }
  61. /**
  62. * Replaces the instance data with another objects instance data. This object will basically become the original
  63. * owner of the provided instance data as far as all game object handles referencing it are concerned.
  64. *
  65. * @note
  66. * No alive objects should ever be sharing the same instance data. This can be used for restoring dead handles.
  67. */
  68. virtual void _setInstanceData(GameObjectInstanceDataPtr& other);
  69. /** Returns instance data that identifies this GameObject and is used for referencing by game object handles. */
  70. virtual GameObjectInstanceDataPtr _getInstanceData() const { return mInstanceData; }
  71. /** @endcond */
  72. protected:
  73. friend class GameObjectHandleBase;
  74. friend class GameObjectManager;
  75. friend class PrefabDiff;
  76. friend class PrefabUtility;
  77. /** Initializes the GameObject after construction. */
  78. void initialize(const std::shared_ptr<GameObject>& object, UINT64 instanceId);
  79. /**
  80. * Destroys this object.
  81. *
  82. * @param[in] handle Game object handle to this object.
  83. * @param[in] immediate If true, the object will be deallocated and become unusable right away. Otherwise the
  84. * deallocation will be delayed to the end of frame (preferred method).
  85. */
  86. virtual void destroyInternal(GameObjectHandleBase& handle, bool immediate = false) = 0;
  87. protected:
  88. String mName;
  89. UINT32 mLinkId;
  90. private:
  91. friend class Prefab;
  92. GameObjectInstanceDataPtr mInstanceData;
  93. bool mIsDestroyed;
  94. /************************************************************************/
  95. /* RTTI */
  96. /************************************************************************/
  97. public:
  98. friend class GameObjectRTTI;
  99. static RTTITypeBase* getRTTIStatic();
  100. virtual RTTITypeBase* getRTTI() const override;
  101. };
  102. /** @} */
  103. }
  104. #include "BsGameObjectHandle.h"
  105. namespace BansheeEngine
  106. {
  107. /** @addtogroup Scene
  108. * @{
  109. */
  110. // Game object handles
  111. typedef GameObjectHandle<GameObject> HGameObject;
  112. typedef GameObjectHandle<SceneObject> HSceneObject;
  113. typedef GameObjectHandle<Component> HComponent;
  114. /** @} */
  115. }