BsGameObject.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 Replaces the instance data with another objects instance data.
  41. * This object will basically become the original owner of the provided
  42. * instance data as far as all game object handles referencing it are concerned.
  43. *
  44. * @note Internal method.
  45. * No alive objects should ever be sharing the same instance data. This can be used
  46. * for restoring dead handles.
  47. */
  48. virtual void _setInstanceData(GameObjectInstanceDataPtr& other);
  49. /**
  50. * @brief Returns instance data that identifies this GameObject and is used for referencing
  51. * by game object handles.
  52. *
  53. * @note Internal method.
  54. */
  55. virtual GameObjectInstanceDataPtr _getInstanceData() const { return mInstanceData; }
  56. protected:
  57. friend class GameObjectHandleBase;
  58. friend class GameObjectManager;
  59. /**
  60. * @brief Initializes the GameObject after construction.
  61. */
  62. void initialize(const std::shared_ptr<GameObject>& object, UINT64 instanceId);
  63. protected:
  64. String mName;
  65. private:
  66. GameObjectInstanceDataPtr mInstanceData;
  67. /************************************************************************/
  68. /* RTTI */
  69. /************************************************************************/
  70. public:
  71. friend class GameObjectRTTI;
  72. static RTTITypeBase* getRTTIStatic();
  73. virtual RTTITypeBase* getRTTI() const;
  74. };
  75. }
  76. #include "BsGameObjectHandle.h"
  77. namespace BansheeEngine
  78. {
  79. // Game object handles
  80. typedef GameObjectHandle<GameObject> HGameObject;
  81. typedef GameObjectHandle<SceneObject> HSceneObject;
  82. typedef GameObjectHandle<Component> HComponent;
  83. }