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/BsAnimationCurve.h" |
8 | |
9 | namespace bs |
10 | { |
11 | /** @cond RTTI */ |
12 | /** @addtogroup RTTI-Impl-Core |
13 | * @{ |
14 | */ |
15 | |
16 | template<class T> struct RTTIPlainType<TKeyframe<T>> |
17 | { |
18 | enum { id = TID_KeyFrame }; enum { hasDynamicSize = 0 }; |
19 | |
20 | /** @copydoc RTTIPlainType::toMemory */ |
21 | static void toMemory(const TKeyframe<T>& data, char* memory) |
22 | { |
23 | memory = rttiWriteElem(data.value, memory); |
24 | memory = rttiWriteElem(data.inTangent, memory); |
25 | memory = rttiWriteElem(data.outTangent, memory); |
26 | memory = rttiWriteElem(data.time, memory); |
27 | } |
28 | |
29 | /** @copydoc RTTIPlainType::fromMemory */ |
30 | static UINT32 fromMemory(TKeyframe<T>& data, char* memory) |
31 | { |
32 | memory = rttiReadElem(data.value, memory); |
33 | memory = rttiReadElem(data.inTangent, memory); |
34 | memory = rttiReadElem(data.outTangent, memory); |
35 | memory = rttiReadElem(data.time, memory); |
36 | |
37 | return sizeof(TKeyframe<T>); |
38 | } |
39 | |
40 | /** @copydoc RTTIPlainType::getDynamicSize */ |
41 | static UINT32 getDynamicSize(const TKeyframe<T>& data) |
42 | { |
43 | assert(false); |
44 | return sizeof(TKeyframe<T>); |
45 | } |
46 | }; |
47 | |
48 | template<class T> struct RTTIPlainType<TAnimationCurve<T>> |
49 | { |
50 | enum { id = TID_AnimationCurve }; enum { hasDynamicSize = 1 }; |
51 | |
52 | /** @copydoc RTTIPlainType::toMemory */ |
53 | static void toMemory(const TAnimationCurve<T>& data, char* memory) |
54 | { |
55 | UINT32 size = sizeof(UINT32); |
56 | char* memoryStart = memory; |
57 | memory += sizeof(UINT32); |
58 | |
59 | UINT32 version = 0; // In case the data structure changes |
60 | memory = rttiWriteElem(version, memory, size); |
61 | memory = rttiWriteElem(data.mStart, memory, size); |
62 | memory = rttiWriteElem(data.mEnd, memory, size); |
63 | memory = rttiWriteElem(data.mLength, memory, size); |
64 | memory = rttiWriteElem(data.mKeyframes, memory, size); |
65 | |
66 | memcpy(memoryStart, &size, sizeof(UINT32)); |
67 | } |
68 | |
69 | /** @copydoc RTTIPlainType::fromMemory */ |
70 | static UINT32 fromMemory(TAnimationCurve<T>& data, char* memory) |
71 | { |
72 | UINT32 size = 0; |
73 | memory = rttiReadElem(size, memory); |
74 | |
75 | UINT32 version; |
76 | memory = rttiReadElem(version, memory); |
77 | |
78 | memory = rttiReadElem(data.mStart, memory); |
79 | memory = rttiReadElem(data.mEnd, memory); |
80 | memory = rttiReadElem(data.mLength, memory); |
81 | memory = rttiReadElem(data.mKeyframes, memory); |
82 | |
83 | return size; |
84 | } |
85 | |
86 | /** @copydoc RTTIPlainType::getDynamicSize */ |
87 | static UINT32 getDynamicSize(const TAnimationCurve<T>& data) |
88 | { |
89 | UINT64 dataSize = sizeof(UINT32) + sizeof(UINT32); |
90 | dataSize += rttiGetElemSize(data.mStart); |
91 | dataSize += rttiGetElemSize(data.mEnd); |
92 | dataSize += rttiGetElemSize(data.mLength); |
93 | dataSize += rttiGetElemSize(data.mKeyframes); |
94 | |
95 | assert(dataSize <= std::numeric_limits<UINT32>::max()); |
96 | |
97 | return (UINT32)dataSize; |
98 | } |
99 | }; |
100 | |
101 | template<class T> struct RTTIPlainType<TNamedAnimationCurve<T>> |
102 | { |
103 | enum { id = TID_NamedAnimationCurve }; enum { hasDynamicSize = 1 }; |
104 | |
105 | /** @copydoc RTTIPlainType::toMemory */ |
106 | static void toMemory(const TNamedAnimationCurve<T>& data, char* memory) |
107 | { |
108 | UINT32 size = sizeof(UINT32); |
109 | char* memoryStart = memory; |
110 | memory += sizeof(UINT32); |
111 | |
112 | memory = rttiWriteElem(data.name, memory, size); |
113 | memory = rttiWriteElem(data.flags, memory, size); |
114 | memory = rttiWriteElem(data.curve, memory, size); |
115 | |
116 | memcpy(memoryStart, &size, sizeof(UINT32)); |
117 | } |
118 | |
119 | /** @copydoc RTTIPlainType::fromMemory */ |
120 | static UINT32 fromMemory(TNamedAnimationCurve<T>& data, char* memory) |
121 | { |
122 | UINT32 size = 0; |
123 | memory = rttiReadElem(size, memory); |
124 | |
125 | memory = rttiReadElem(data.name, memory); |
126 | memory = rttiReadElem(data.flags, memory); |
127 | memory = rttiReadElem(data.curve, memory); |
128 | |
129 | return size; |
130 | } |
131 | |
132 | /** @copydoc RTTIPlainType::getDynamicSize */ |
133 | static UINT32 getDynamicSize(const TNamedAnimationCurve<T>& data) |
134 | { |
135 | UINT64 dataSize = sizeof(UINT32); |
136 | dataSize += rttiGetElemSize(data.name); |
137 | dataSize += rttiGetElemSize(data.flags); |
138 | dataSize += rttiGetElemSize(data.curve); |
139 | |
140 | assert(dataSize <= std::numeric_limits<UINT32>::max()); |
141 | |
142 | return (UINT32)dataSize; |
143 | } |
144 | }; |
145 | |
146 | /** @} */ |
147 | /** @endcond */ |
148 | } |