BsGameObject.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. /**
  18. * @brief Type of object that can be referenced by a GameObject handle.
  19. * Each object has an unique ID and is registered with the GameObjectManager.
  20. */
  21. class BS_CORE_EXPORT GameObject : public IReflectable
  22. {
  23. public:
  24. GameObject();
  25. virtual ~GameObject();
  26. /**
  27. * @brief Returns the unique instance ID of the GameObject.
  28. */
  29. UINT64 getInstanceId() const { return mInstanceData->mInstanceId; }
  30. /**
  31. * @brief Gets the name of the object.
  32. */
  33. const String& getName() const { return mName; }
  34. /**
  35. * @brief Sets the name of the object.
  36. */
  37. void setName(const String& name) { mName = name; }
  38. protected:
  39. friend class GameObjectHandleBase;
  40. friend class GameObjectManager;
  41. /**
  42. * @brief Initializes the GameObject after construction.
  43. */
  44. void initialize(const std::shared_ptr<GameObject>& object, UINT64 instanceId);
  45. protected:
  46. String mName;
  47. private:
  48. std::shared_ptr<GameObjectInstanceData> mInstanceData;
  49. /************************************************************************/
  50. /* RTTI */
  51. /************************************************************************/
  52. public:
  53. friend class GameObjectRTTI;
  54. static RTTITypeBase* getRTTIStatic();
  55. virtual RTTITypeBase* getRTTI() const;
  56. };
  57. }
  58. #include "BsGameObjectHandle.h"
  59. namespace BansheeEngine
  60. {
  61. // Game object handles
  62. typedef GameObjectHandle<GameObject> HGameObject;
  63. typedef GameObjectHandle<SceneObject> HSceneObject;
  64. typedef GameObjectHandle<Component> HComponent;
  65. }