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 "Image/BsSpriteTexture.h" |
8 | |
9 | namespace bs |
10 | { |
11 | /** @cond RTTI */ |
12 | /** @addtogroup RTTI-Impl-Engine |
13 | * @{ |
14 | */ |
15 | |
16 | class BS_CORE_EXPORT SpriteTextureRTTI : public RTTIType<SpriteTexture, Resource, SpriteTextureRTTI> |
17 | { |
18 | private: |
19 | BS_BEGIN_RTTI_MEMBERS |
20 | BS_RTTI_MEMBER_REFL(mAtlasTexture, 0) |
21 | BS_RTTI_MEMBER_PLAIN(mUVOffset, 1) |
22 | BS_RTTI_MEMBER_PLAIN(mUVScale, 2) |
23 | BS_RTTI_MEMBER_PLAIN(mAnimation, 3) |
24 | BS_RTTI_MEMBER_PLAIN(mPlayback, 4) |
25 | BS_END_RTTI_MEMBERS |
26 | |
27 | public: |
28 | const String& getRTTIName() override |
29 | { |
30 | static String name = "SpriteTexture" ; |
31 | return name; |
32 | } |
33 | |
34 | UINT32 getRTTIId() override |
35 | { |
36 | return TID_SpriteTexture; |
37 | } |
38 | |
39 | SPtr<IReflectable> newRTTIObject() override |
40 | { |
41 | return SpriteTexture::createEmpty(); |
42 | } |
43 | |
44 | private: |
45 | void onDeserializationEnded(IReflectable* obj, SerializationContext* context) override |
46 | { |
47 | SpriteTexture* texture = static_cast<SpriteTexture*>(obj); |
48 | texture->initialize(); |
49 | } |
50 | }; |
51 | |
52 | template<> struct RTTIPlainType<SpriteSheetGridAnimation> |
53 | { |
54 | enum { id = TID_SpriteSheetGridAnimation }; enum { hasDynamicSize = 1 }; |
55 | |
56 | static void toMemory(const SpriteSheetGridAnimation& data, char* memory) |
57 | { |
58 | static constexpr UINT32 VERSION = 0; |
59 | |
60 | const UINT32 size = getDynamicSize(data); |
61 | |
62 | memory = rttiWriteElem(size, memory); |
63 | memory = rttiWriteElem(VERSION, memory); |
64 | memory = rttiWriteElem(data.numRows, memory); |
65 | memory = rttiWriteElem(data.numColumns, memory); |
66 | memory = rttiWriteElem(data.count, memory); |
67 | memory = rttiWriteElem(data.fps, memory); |
68 | } |
69 | |
70 | static UINT32 fromMemory(SpriteSheetGridAnimation& data, char* memory) |
71 | { |
72 | UINT32 size = 0; |
73 | memory = rttiReadElem(size, memory); |
74 | |
75 | UINT32 version = 0; |
76 | memory = rttiReadElem(version, memory); |
77 | |
78 | switch(version) |
79 | { |
80 | case 0: |
81 | { |
82 | memory = rttiReadElem(data.numRows, memory); |
83 | memory = rttiReadElem(data.numColumns, memory); |
84 | memory = rttiReadElem(data.count, memory); |
85 | memory = rttiReadElem(data.fps, memory); |
86 | } |
87 | break; |
88 | default: |
89 | LOGERR("Unknown version. Unable to deserialize." ); |
90 | break; |
91 | } |
92 | |
93 | return size; |
94 | } |
95 | |
96 | static UINT32 getDynamicSize(const SpriteSheetGridAnimation& data) |
97 | { |
98 | UINT32 size = sizeof(UINT32) * 2 + rttiGetElemSize(data.numRows) + rttiGetElemSize(data.numColumns) + |
99 | rttiGetElemSize(data.count) + rttiGetElemSize(data.fps); |
100 | return size; |
101 | } |
102 | }; |
103 | |
104 | /** @} */ |
105 | /** @endcond */ |
106 | } |
107 | |