BsGameObject.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsIReflectable.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Scene-Internal
  9. * @{
  10. */
  11. /** Flags used for notifying child scene object and components when a transform has been changed. */
  12. enum TransformChangedFlags
  13. {
  14. TCF_None = 0x00, /**< Component will not be notified about any events relating to the transform. */
  15. TCF_Transform = 0x01, /**< Component will be notified when the its position, rotation or scale has changed. */
  16. TCF_Parent = 0x02 /**< Component will be notified when its parent changes. */
  17. };
  18. /** @} */
  19. /** @addtogroup Scene
  20. * @{
  21. */
  22. /**
  23. * Type of object that can be referenced by a GameObject handle. Each object has an unique ID and is registered with
  24. * the GameObjectManager.
  25. */
  26. class BS_CORE_EXPORT GameObject : public IReflectable
  27. {
  28. public:
  29. GameObject();
  30. virtual ~GameObject();
  31. /** Returns the unique instance ID of the GameObject. */
  32. UINT64 getInstanceId() const { return mInstanceData->mInstanceId; }
  33. /**
  34. * Returns an ID that identifies a link between this object and its equivalent in the linked prefab. This will be
  35. * -1 if the object has no prefab link, or if the object is specific to the instance and has no prefab equivalent.
  36. */
  37. UINT32 getLinkId() const { return mLinkId; }
  38. /** Gets the name of the object. */
  39. const String& getName() const { return mName; }
  40. /** Sets the name of the object. */
  41. void setName(const String& name) { mName = name; }
  42. public: // ***** INTERNAL ******
  43. /** @name Internal
  44. * @{
  45. */
  46. /**
  47. * Marks the object as destroyed. Generally this means the object has been queued for destruction but it hasn't
  48. * occurred yet.
  49. */
  50. void _setIsDestroyed() { mIsDestroyed = true; }
  51. /** Checks if the object has been destroyed. */
  52. bool _getIsDestroyed() const { return mIsDestroyed; }
  53. /** Changes the prefab link ID for this object. See getLinkId(). */
  54. void _setLinkId(UINT32 id) { mLinkId = id; }
  55. /**
  56. * Replaces the instance data with another objects instance data. This object will basically become the original
  57. * owner of the provided instance data as far as all game object handles referencing it are concerned.
  58. *
  59. * @note
  60. * No alive objects should ever be sharing the same instance data. This can be used for restoring dead handles.
  61. */
  62. virtual void _setInstanceData(GameObjectInstanceDataPtr& other);
  63. /** Returns instance data that identifies this GameObject and is used for referencing by game object handles. */
  64. virtual GameObjectInstanceDataPtr _getInstanceData() const { return mInstanceData; }
  65. /** @} */
  66. protected:
  67. friend class GameObjectHandleBase;
  68. friend class GameObjectManager;
  69. friend class PrefabDiff;
  70. friend class PrefabUtility;
  71. /** Initializes the GameObject after construction. */
  72. void initialize(const SPtr<GameObject>& object, UINT64 instanceId);
  73. /**
  74. * Destroys this object.
  75. *
  76. * @param[in] handle Game object handle to this object.
  77. * @param[in] immediate If true, the object will be deallocated and become unusable right away. Otherwise the
  78. * deallocation will be delayed to the end of frame (preferred method).
  79. */
  80. virtual void destroyInternal(GameObjectHandleBase& handle, bool immediate = false) = 0;
  81. protected:
  82. String mName;
  83. UINT32 mLinkId;
  84. private:
  85. friend class Prefab;
  86. GameObjectInstanceDataPtr mInstanceData;
  87. bool mIsDestroyed;
  88. /************************************************************************/
  89. /* RTTI */
  90. /************************************************************************/
  91. public:
  92. friend class GameObjectRTTI;
  93. static RTTITypeBase* getRTTIStatic();
  94. virtual RTTITypeBase* getRTTI() const override;
  95. };
  96. /** @} */
  97. }