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/BsRTTIType.h"
7#include "Scene/BsGameObjectHandle.h"
8#include "Scene/BsGameObjectManager.h"
9#include "Utility/BsUtility.h"
10
11namespace bs
12{
13 /** @cond RTTI */
14 /** @addtogroup RTTI-Impl-Core
15 * @{
16 */
17
18 class BS_CORE_EXPORT GameObjectHandleRTTI : public RTTIType<GameObjectHandleBase, IReflectable, GameObjectHandleRTTI>
19 {
20 private:
21 UINT64& getInstanceId(GameObjectHandleBase* obj)
22 {
23 static UINT64 invalidId = 0;
24
25 if (obj->mData->mPtr != nullptr)
26 return obj->mData->mPtr->mInstanceId;
27
28 return invalidId;
29 }
30
31 void setInstanceId(GameObjectHandleBase* obj, UINT64& value) { mOriginalInstanceId = value; }
32
33 public:
34 GameObjectHandleRTTI()
35 {
36 addPlainField("mInstanceID", 0, &GameObjectHandleRTTI::getInstanceId, &GameObjectHandleRTTI::setInstanceId);
37 }
38
39 void onDeserializationEnded(IReflectable* obj, SerializationContext* context) override
40 {
41 if(context == nullptr || !rtti_is_of_type<CoreSerializationContext>(context))
42 return;
43
44 auto coreContext = static_cast<CoreSerializationContext*>(context);
45 if(coreContext->goState)
46 {
47 GameObjectHandleBase* gameObjectHandle = static_cast<GameObjectHandleBase*>(obj);
48 coreContext->goState->registerUnresolvedHandle(mOriginalInstanceId, *gameObjectHandle);
49 }
50 }
51
52 const String& getRTTIName() override
53 {
54 static String name = "GameObjectHandleBase";
55 return name;
56 }
57
58 UINT32 getRTTIId() override
59 {
60 return TID_GameObjectHandleBase;
61 }
62
63 SPtr<IReflectable> newRTTIObject() override
64 {
65 SPtr<GameObjectHandleBase> obj = bs_shared_ptr<GameObjectHandleBase>(new (bs_alloc<GameObjectHandleBase>()) GameObjectHandleBase());
66
67 return obj;
68 }
69
70 private:
71 UINT64 mOriginalInstanceId;
72 };
73
74 /** @} */
75 /** @endcond */
76}
77