BsGameObject.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsIReflectable.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Contains instance data that is held by all GameObject handles.
  8. */
  9. struct GameObjectInstanceData
  10. {
  11. GameObjectInstanceData()
  12. :mInstanceId(0), object(nullptr)
  13. { }
  14. std::shared_ptr<GameObject> object;
  15. UINT64 mInstanceId;
  16. };
  17. typedef std::shared_ptr<GameObjectInstanceData> GameObjectInstanceDataPtr;
  18. /**
  19. * @brief Type of object that can be referenced by a GameObject handle.
  20. * Each object has an unique ID and is registered with the GameObjectManager.
  21. */
  22. class BS_CORE_EXPORT GameObject : public IReflectable
  23. {
  24. public:
  25. GameObject();
  26. virtual ~GameObject();
  27. /**
  28. * @brief Returns the unique instance ID of the GameObject.
  29. */
  30. UINT64 getInstanceId() const { return mInstanceData->mInstanceId; }
  31. /**
  32. * @brief Returns an ID that identifies a link between this object and its equivalent
  33. * in the linked prefab. This will be -1 if the object has no prefab link, or if
  34. * the object is specific to the instance and has no prefab equivalent.
  35. */
  36. INT32 getLinkId() const { return mLinkId; }
  37. /**
  38. * @brief Gets the name of the object.
  39. */
  40. const String& getName() const { return mName; }
  41. /**
  42. * @brief Sets the name of the object.
  43. */
  44. void setName(const String& name) { mName = name; }
  45. /**
  46. * @brief Marks the object as destroyed. Generally this means the object
  47. * has been queued for destruction but it hasn't occurred yet.
  48. *
  49. * @note Internal method.
  50. */
  51. void _setIsDestroyed() { mIsDestroyed = true; }
  52. /**
  53. * @brief Checks if the object has been destroyed.
  54. */
  55. bool _getIsDestroyed() const { return mIsDestroyed; }
  56. /**
  57. * @brief Replaces the instance data with another objects instance data.
  58. * This object will basically become the original owner of the provided
  59. * instance data as far as all game object handles referencing it are concerned.
  60. *
  61. * @note Internal method.
  62. * No alive objects should ever be sharing the same instance data. This can be used
  63. * for restoring dead handles.
  64. */
  65. virtual void _setInstanceData(GameObjectInstanceDataPtr& other);
  66. /**
  67. * @brief Returns instance data that identifies this GameObject and is used for referencing
  68. * by game object handles.
  69. *
  70. * @note Internal method.
  71. */
  72. virtual GameObjectInstanceDataPtr _getInstanceData() const { return mInstanceData; }
  73. protected:
  74. friend class GameObjectHandleBase;
  75. friend class GameObjectManager;
  76. friend class PrefabDiff;
  77. friend class PrefabUtility;
  78. /**
  79. * @brief Initializes the GameObject after construction.
  80. */
  81. void initialize(const std::shared_ptr<GameObject>& object, UINT64 instanceId);
  82. protected:
  83. String mName;
  84. INT32 mLinkId;
  85. private:
  86. friend class Prefab;
  87. GameObjectInstanceDataPtr mInstanceData;
  88. bool mIsDestroyed;
  89. /************************************************************************/
  90. /* RTTI */
  91. /************************************************************************/
  92. public:
  93. friend class GameObjectRTTI;
  94. static RTTITypeBase* getRTTIStatic();
  95. virtual RTTITypeBase* getRTTI() const;
  96. };
  97. }
  98. #include "BsGameObjectHandle.h"
  99. namespace BansheeEngine
  100. {
  101. // Game object handles
  102. typedef GameObjectHandle<GameObject> HGameObject;
  103. typedef GameObjectHandle<SceneObject> HSceneObject;
  104. typedef GameObjectHandle<Component> HComponent;
  105. }