BsGameObject.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Gets the name of the object.
  33. */
  34. const String& getName() const { return mName; }
  35. /**
  36. * @brief Sets the name of the object.
  37. */
  38. void setName(const String& name) { mName = name; }
  39. /**
  40. * @brief Marks the object as destroyed. Generally this means the object
  41. * has been queued for destruction but it hasn't occurred yet.
  42. *
  43. * @note Internal method.
  44. */
  45. void _setIsDestroyed() { mIsDestroyed = true; }
  46. /**
  47. * @brief Checks if the object has been destroyed.
  48. */
  49. bool _getIsDestroyed() const { return mIsDestroyed; }
  50. /**
  51. * @brief Replaces the instance data with another objects instance data.
  52. * This object will basically become the original owner of the provided
  53. * instance data as far as all game object handles referencing it are concerned.
  54. *
  55. * @note Internal method.
  56. * No alive objects should ever be sharing the same instance data. This can be used
  57. * for restoring dead handles.
  58. */
  59. virtual void _setInstanceData(GameObjectInstanceDataPtr& other);
  60. /**
  61. * @brief Returns instance data that identifies this GameObject and is used for referencing
  62. * by game object handles.
  63. *
  64. * @note Internal method.
  65. */
  66. virtual GameObjectInstanceDataPtr _getInstanceData() const { return mInstanceData; }
  67. protected:
  68. friend class GameObjectHandleBase;
  69. friend class GameObjectManager;
  70. /**
  71. * @brief Initializes the GameObject after construction.
  72. */
  73. void initialize(const std::shared_ptr<GameObject>& object, UINT64 instanceId);
  74. protected:
  75. String mName;
  76. private:
  77. GameObjectInstanceDataPtr mInstanceData;
  78. bool mIsDestroyed;
  79. /************************************************************************/
  80. /* RTTI */
  81. /************************************************************************/
  82. public:
  83. friend class GameObjectRTTI;
  84. static RTTITypeBase* getRTTIStatic();
  85. virtual RTTITypeBase* getRTTI() const;
  86. };
  87. }
  88. #include "BsGameObjectHandle.h"
  89. namespace BansheeEngine
  90. {
  91. // Game object handles
  92. typedef GameObjectHandle<GameObject> HGameObject;
  93. typedef GameObjectHandle<SceneObject> HSceneObject;
  94. typedef GameObjectHandle<Component> HComponent;
  95. }