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 "Animation/BsAnimationClip.h" |
8 | #include "Private/RTTI/BsAnimationCurveRTTI.h" |
9 | |
10 | namespace bs |
11 | { |
12 | /** @cond RTTI */ |
13 | /** @addtogroup RTTI-Impl-Core |
14 | * @{ |
15 | */ |
16 | |
17 | template<> |
18 | struct RTTIPlainType<AnimationEvent> |
19 | { |
20 | enum { id = TID_AnimationEvent }; enum { hasDynamicSize = 1 }; |
21 | |
22 | /** @copydoc RTTIPlainType::toMemory */ |
23 | static void toMemory(const AnimationEvent& data, char* memory) |
24 | { |
25 | UINT32 size = sizeof(UINT32); |
26 | char* memoryStart = memory; |
27 | memory += sizeof(UINT32); |
28 | |
29 | UINT8 version = 0; |
30 | memory = rttiWriteElem(version, memory, size); |
31 | memory = rttiWriteElem(data.time, memory, size); |
32 | rttiWriteElem(data.name, memory, size); |
33 | |
34 | memcpy(memoryStart, &size, sizeof(UINT32)); |
35 | } |
36 | |
37 | /** @copydoc RTTIPlainType::fromMemory */ |
38 | static UINT32 fromMemory(AnimationEvent& data, char* memory) |
39 | { |
40 | UINT32 size = 0; |
41 | memory = rttiReadElem(size, memory); |
42 | |
43 | UINT8 version; |
44 | memory = rttiReadElem(version, memory); |
45 | assert(version == 0); |
46 | |
47 | memory = rttiReadElem(data.time, memory); |
48 | rttiReadElem(data.name, memory); |
49 | |
50 | return size; |
51 | } |
52 | |
53 | /** @copydoc RTTIPlainType::getDynamicSize */ |
54 | static UINT32 getDynamicSize(const AnimationEvent& data) |
55 | { |
56 | UINT64 dataSize = sizeof(UINT8) + sizeof(UINT32); |
57 | dataSize += rttiGetElemSize(data.time); |
58 | dataSize += rttiGetElemSize(data.name); |
59 | |
60 | assert(dataSize <= std::numeric_limits<UINT32>::max()); |
61 | |
62 | return (UINT32)dataSize; |
63 | } |
64 | }; |
65 | |
66 | class BS_CORE_EXPORT AnimationClipRTTI : public RTTIType <AnimationClip, Resource, AnimationClipRTTI> |
67 | { |
68 | private: |
69 | BS_BEGIN_RTTI_MEMBERS |
70 | BS_RTTI_MEMBER_PLAIN_NAMED(positionCurves, mCurves->position, 0) |
71 | BS_RTTI_MEMBER_PLAIN_NAMED(rotationCurves, mCurves->rotation, 1) |
72 | BS_RTTI_MEMBER_PLAIN_NAMED(scaleCurves, mCurves->scale, 2) |
73 | BS_RTTI_MEMBER_PLAIN_NAMED(genericCurves, mCurves->generic, 3) |
74 | BS_RTTI_MEMBER_PLAIN(mIsAdditive, 4) |
75 | BS_RTTI_MEMBER_PLAIN(mLength, 5) |
76 | BS_RTTI_MEMBER_PLAIN(mEvents, 6) |
77 | BS_RTTI_MEMBER_PLAIN(mSampleRate, 7) |
78 | BS_RTTI_MEMBER_PLAIN_NAMED(rootMotionPos, mRootMotion->position, 8) |
79 | BS_RTTI_MEMBER_PLAIN_NAMED(rootMotionRot, mRootMotion->rotation, 9) |
80 | BS_END_RTTI_MEMBERS |
81 | public: |
82 | void onDeserializationEnded(IReflectable* obj, SerializationContext* context) override |
83 | { |
84 | AnimationClip* clip = static_cast<AnimationClip*>(obj); |
85 | clip->initialize(); |
86 | } |
87 | |
88 | const String& getRTTIName() override |
89 | { |
90 | static String name = "AnimationClip" ; |
91 | return name; |
92 | } |
93 | |
94 | UINT32 getRTTIId() override |
95 | { |
96 | return TID_AnimationClip; |
97 | } |
98 | |
99 | SPtr<IReflectable> newRTTIObject() override |
100 | { |
101 | return AnimationClip::createEmpty(); |
102 | } |
103 | }; |
104 | |
105 | /** @} */ |
106 | /** @endcond */ |
107 | } |
108 | |