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 "Particles/BsParticleDistribution.h" |
7 | #include "Private/RTTI/BsAnimationCurveRTTI.h" |
8 | |
9 | namespace bs |
10 | { |
11 | /** @cond RTTI */ |
12 | /** @addtogroup RTTI-Impl-Core |
13 | * @{ |
14 | */ |
15 | |
16 | template<> struct RTTIPlainType<ColorDistribution> |
17 | { |
18 | enum { id = TID_ColorDistribution }; enum { hasDynamicSize = 1 }; |
19 | |
20 | /** @copydoc RTTIPlainType::toMemory */ |
21 | static void toMemory(const ColorDistribution& data, char* memory) |
22 | { |
23 | UINT32 size = sizeof(UINT32); |
24 | char* memoryStart = memory; |
25 | memory += sizeof(UINT32); |
26 | |
27 | UINT32 version = 0; // In case the data structure changes |
28 | memory = rttiWriteElem(version, memory, size); |
29 | memory = rttiWriteElem(data.mType, memory, size); |
30 | memory = rttiWriteElem(data.mMinGradient, memory, size); |
31 | memory = rttiWriteElem(data.mMaxGradient, memory, size); |
32 | |
33 | memcpy(memoryStart, &size, sizeof(UINT32)); |
34 | } |
35 | |
36 | /** @copydoc RTTIPlainType::fromMemory */ |
37 | static UINT32 fromMemory(ColorDistribution& data, char* memory) |
38 | { |
39 | UINT32 size = 0; |
40 | memory = rttiReadElem(size, memory); |
41 | |
42 | UINT32 version; |
43 | memory = rttiReadElem(version, memory); |
44 | |
45 | switch(version) |
46 | { |
47 | case 0: |
48 | memory = rttiReadElem(data.mType, memory); |
49 | memory = rttiReadElem(data.mMinGradient, memory); |
50 | memory = rttiReadElem(data.mMaxGradient, memory); |
51 | break; |
52 | default: |
53 | LOGERR("Unknown version of TDistribution<T> data. Unable to deserialize." ); |
54 | break; |
55 | } |
56 | |
57 | return size; |
58 | } |
59 | |
60 | /** @copydoc RTTIPlainType::getDynamicSize */ |
61 | static UINT32 getDynamicSize(const ColorDistribution& data) |
62 | { |
63 | UINT64 dataSize = sizeof(UINT32) + sizeof(UINT32); |
64 | dataSize += rttiGetElemSize(data.mType); |
65 | dataSize += rttiGetElemSize(data.mMinGradient); |
66 | dataSize += rttiGetElemSize(data.mMaxGradient); |
67 | |
68 | assert(dataSize <= std::numeric_limits<UINT32>::max()); |
69 | |
70 | return (UINT32)dataSize; |
71 | } |
72 | }; |
73 | |
74 | template<class T> struct RTTIPlainType<TDistribution<T>> |
75 | { |
76 | enum { id = TID_TDistribution }; enum { hasDynamicSize = 1 }; |
77 | |
78 | /** @copydoc RTTIPlainType::toMemory */ |
79 | static void toMemory(const TDistribution<T>& data, char* memory) |
80 | { |
81 | UINT32 size = sizeof(UINT32); |
82 | char* memoryStart = memory; |
83 | memory += sizeof(UINT32); |
84 | |
85 | UINT32 version = 0; // In case the data structure changes |
86 | memory = rttiWriteElem(version, memory, size); |
87 | memory = rttiWriteElem(data.mType, memory, size); |
88 | memory = rttiWriteElem(data.mMinCurve, memory, size); |
89 | memory = rttiWriteElem(data.mMaxCurve, memory, size); |
90 | |
91 | memcpy(memoryStart, &size, sizeof(UINT32)); |
92 | } |
93 | |
94 | /** @copydoc RTTIPlainType::fromMemory */ |
95 | static UINT32 fromMemory(TDistribution<T>& data, char* memory) |
96 | { |
97 | UINT32 size = 0; |
98 | memory = rttiReadElem(size, memory); |
99 | |
100 | UINT32 version; |
101 | memory = rttiReadElem(version, memory); |
102 | |
103 | switch(version) |
104 | { |
105 | case 0: |
106 | memory = rttiReadElem(data.mType, memory); |
107 | memory = rttiReadElem(data.mMinCurve, memory); |
108 | memory = rttiReadElem(data.mMaxCurve, memory); |
109 | break; |
110 | default: |
111 | LOGERR("Unknown version of TDistribution<T> data. Unable to deserialize." ); |
112 | break; |
113 | } |
114 | |
115 | return size; |
116 | } |
117 | |
118 | /** @copydoc RTTIPlainType::getDynamicSize */ |
119 | static UINT32 getDynamicSize(const TDistribution<T>& data) |
120 | { |
121 | UINT64 dataSize = sizeof(UINT32) + sizeof(UINT32); |
122 | dataSize += rttiGetElemSize(data.mType); |
123 | dataSize += rttiGetElemSize(data.mMinCurve); |
124 | dataSize += rttiGetElemSize(data.mMaxCurve); |
125 | |
126 | assert(dataSize <= std::numeric_limits<UINT32>::max()); |
127 | |
128 | return (UINT32)dataSize; |
129 | } |
130 | }; |
131 | |
132 | /** @} */ |
133 | /** @endcond */ |
134 | } |
135 | |