2
0

BsGameObject.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsIReflectable.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Contains instance data that is held by all GameObject handles.
  11. */
  12. struct GameObjectInstanceData
  13. {
  14. GameObjectInstanceData()
  15. :mInstanceId(0), object(nullptr)
  16. { }
  17. std::shared_ptr<GameObject> object;
  18. UINT64 mInstanceId;
  19. };
  20. /**
  21. * @brief Type of object that can be referenced by a GameObject handle.
  22. * Each object has an unique ID and is registered with the GameObjectManager.
  23. */
  24. class BS_CORE_EXPORT GameObject : public IReflectable
  25. {
  26. public:
  27. GameObject();
  28. virtual ~GameObject();
  29. /**
  30. * @brief Returns the unique instance ID of the GameObject.
  31. */
  32. UINT64 getInstanceId() const { return mInstanceData->mInstanceId; }
  33. /**
  34. * @brief Gets the name of the object.
  35. */
  36. const String& getName() const { return mName; }
  37. /**
  38. * @brief Sets the name of the object.
  39. */
  40. void setName(const String& name) { mName = name; }
  41. protected:
  42. friend class GameObjectHandleBase;
  43. friend class GameObjectManager;
  44. /**
  45. * @brief Initializes the GameObject after construction.
  46. */
  47. void initialize(const std::shared_ptr<GameObject>& object, UINT64 instanceId);
  48. protected:
  49. String mName;
  50. private:
  51. std::shared_ptr<GameObjectInstanceData> mInstanceData;
  52. /************************************************************************/
  53. /* RTTI */
  54. /************************************************************************/
  55. public:
  56. friend class GameObjectRTTI;
  57. static RTTITypeBase* getRTTIStatic();
  58. virtual RTTITypeBase* getRTTI() const;
  59. };
  60. }
  61. #include "BsGameObjectHandle.h"
  62. namespace BansheeEngine
  63. {
  64. // Game object handles
  65. typedef GameObjectHandle<GameObject> HGameObject;
  66. typedef GameObjectHandle<SceneObject> HSceneObject;
  67. typedef GameObjectHandle<Component> HComponent;
  68. }