| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsCorePrerequisites.h" |
| 6 | #include "Reflection/BsIReflectable.h" |
| 7 | |
| 8 | namespace bs |
| 9 | { |
| 10 | /** @addtogroup Scene-Internal |
| 11 | * @{ |
| 12 | */ |
| 13 | |
| 14 | /** Flags used for notifying child scene object and components when a transform has been changed. */ |
| 15 | enum TransformChangedFlags |
| 16 | { |
| 17 | TCF_None = 0x00, /**< Component will not be notified about any events relating to the transform. */ |
| 18 | TCF_Transform = 0x01, /**< Component will be notified when the its position, rotation or scale has changed. */ |
| 19 | TCF_Parent = 0x02, /**< Component will be notified when its parent changes. */ |
| 20 | TCF_Mobility = 0x04 /**< Component will be notified when mobility state changes. */ |
| 21 | }; |
| 22 | |
| 23 | /** @} */ |
| 24 | /** @addtogroup Scene |
| 25 | * @{ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * Type of object that can be referenced by a GameObject handle. Each object has an unique ID and is registered with |
| 30 | * the GameObjectManager. |
| 31 | */ |
| 32 | class BS_CORE_EXPORT GameObject : public IReflectable |
| 33 | { |
| 34 | public: |
| 35 | GameObject() = default; |
| 36 | virtual ~GameObject() = default; |
| 37 | |
| 38 | /** Returns the unique instance ID of the GameObject. */ |
| 39 | UINT64 getInstanceId() const { return mInstanceData->mInstanceId; } |
| 40 | |
| 41 | /** |
| 42 | * Returns an ID that identifies a link between this object and its equivalent in the linked prefab. This will be |
| 43 | * -1 if the object has no prefab link, or if the object is specific to the instance and has no prefab equivalent. |
| 44 | */ |
| 45 | UINT32 getLinkId() const { return mLinkId; } |
| 46 | |
| 47 | /** Globally unique identifier of the game object that persists scene save/load. */ |
| 48 | const UUID& getUUID() const { return mUUID; } |
| 49 | |
| 50 | /** Gets the name of the object. */ |
| 51 | const String& getName() const { return mName; } |
| 52 | |
| 53 | /** Sets the name of the object. */ |
| 54 | void setName(const String& name) { mName = name; } |
| 55 | |
| 56 | public: // ***** INTERNAL ****** |
| 57 | /** @name Internal |
| 58 | * @{ |
| 59 | */ |
| 60 | |
| 61 | /** |
| 62 | * Marks the object as destroyed. Generally this means the object has been queued for destruction but it hasn't |
| 63 | * occurred yet. |
| 64 | */ |
| 65 | void _setIsDestroyed() { mIsDestroyed = true; } |
| 66 | |
| 67 | /** Checks if the object has been destroyed. */ |
| 68 | bool _getIsDestroyed() const { return mIsDestroyed; } |
| 69 | |
| 70 | /** Changes the prefab link ID for this object. See getLinkId(). */ |
| 71 | void _setLinkId(UINT32 id) { mLinkId = id; } |
| 72 | |
| 73 | /** @copydoc getUUID */ |
| 74 | void _setUUID(const UUID& uuid) { mUUID = uuid; } |
| 75 | |
| 76 | /** |
| 77 | * Replaces the instance data with another objects instance data. This object will basically become the original |
| 78 | * owner of the provided instance data as far as all game object handles referencing it are concerned. |
| 79 | * |
| 80 | * @note |
| 81 | * No alive objects should ever be sharing the same instance data. This can be used for restoring dead handles. |
| 82 | */ |
| 83 | virtual void _setInstanceData(GameObjectInstanceDataPtr& other); |
| 84 | |
| 85 | /** Returns instance data that identifies this GameObject and is used for referencing by game object handles. */ |
| 86 | virtual GameObjectInstanceDataPtr _getInstanceData() const { return mInstanceData; } |
| 87 | |
| 88 | /** @} */ |
| 89 | |
| 90 | protected: |
| 91 | friend class GameObjectHandleBase; |
| 92 | friend class GameObjectManager; |
| 93 | friend class PrefabDiff; |
| 94 | friend class PrefabUtility; |
| 95 | |
| 96 | /** Initializes the GameObject after construction. */ |
| 97 | void initialize(const SPtr<GameObject>& object, UINT64 instanceId); |
| 98 | |
| 99 | /** |
| 100 | * Destroys this object. |
| 101 | * |
| 102 | * @param[in] handle Game object handle to this object. |
| 103 | * @param[in] immediate If true, the object will be deallocated and become unusable right away. Otherwise the |
| 104 | * deallocation will be delayed to the end of frame (preferred method). |
| 105 | */ |
| 106 | virtual void destroyInternal(GameObjectHandleBase& handle, bool immediate = false) = 0; |
| 107 | |
| 108 | protected: |
| 109 | String mName; |
| 110 | UUID mUUID; |
| 111 | UINT32 mLinkId = (UINT32)-1; |
| 112 | |
| 113 | Any mRTTIData; // RTTI only |
| 114 | private: |
| 115 | friend class Prefab; |
| 116 | GameObjectInstanceDataPtr mInstanceData; |
| 117 | bool mIsDestroyed = false; |
| 118 | |
| 119 | /************************************************************************/ |
| 120 | /* RTTI */ |
| 121 | /************************************************************************/ |
| 122 | friend class ComponentRTTI; |
| 123 | friend class SceneObjectRTTI; |
| 124 | |
| 125 | public: |
| 126 | friend class GameObjectRTTI; |
| 127 | static RTTITypeBase* getRTTIStatic(); |
| 128 | RTTITypeBase* getRTTI() const override; |
| 129 | }; |
| 130 | |
| 131 | /** @} */ |
| 132 | } |