MCPcopy Create free account
hub / github.com/OpenMW/openmw / serializeUserdata

Function serializeUserdata

components/lua/serialization.cpp:135–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133 }
134
135 static void serializeUserdata(
136 BinaryData& out, const sol::userdata& data, const UserdataSerializer* customSerializer)
137 {
138 if (data.is<osg::Vec2f>())
139 {
140 appendType(out, SerializedType::VEC2);
141 osg::Vec2f v = data.as<osg::Vec2f>();
142 appendValue<double>(out, v.x());
143 appendValue<double>(out, v.y());
144 return;
145 }
146 if (data.is<osg::Vec3f>())
147 {
148 appendType(out, SerializedType::VEC3);
149 osg::Vec3f v = data.as<osg::Vec3f>();
150 appendValue<double>(out, v.x());
151 appendValue<double>(out, v.y());
152 appendValue<double>(out, v.z());
153 return;
154 }
155 if (data.is<TransformM>())
156 {
157 appendType(out, SerializedType::TRANSFORM_M);
158 osg::Matrixf matrix = data.as<TransformM>().mM;
159 for (int i = 0; i < 4; i++)
160 for (int j = 0; j < 4; j++)
161 appendValue<double>(out, matrix(i, j));
162 return;
163 }
164 if (data.is<TransformQ>())
165 {
166 appendType(out, SerializedType::TRANSFORM_Q);
167 osg::Quat quat = data.as<TransformQ>().mQ;
168 for (int i = 0; i < 4; i++)
169 appendValue<double>(out, quat[i]);
170 return;
171 }
172 if (data.is<osg::Vec4f>())
173 {
174 appendType(out, SerializedType::VEC4);
175 osg::Vec4f v = data.as<osg::Vec4f>();
176 appendValue<double>(out, v.x());
177 appendValue<double>(out, v.y());
178 appendValue<double>(out, v.z());
179 appendValue<double>(out, v.w());
180 return;
181 }
182 if (data.is<Misc::Color>())
183 {
184 appendType(out, SerializedType::COLOR);
185 Misc::Color v = data.as<Misc::Color>();
186 appendValue<float>(out, v.r());
187 appendValue<float>(out, v.g());
188 appendValue<float>(out, v.b());
189 appendValue<float>(out, v.a());
190 return;
191 }
192 if (customSerializer && customSerializer->serialize(out, data))

Callers 1

serializeFunction · 0.85

Calls 6

appendTypeFunction · 0.85
rMethod · 0.80
gMethod · 0.80
bMethod · 0.80
aMethod · 0.80
serializeMethod · 0.45

Tested by

no test coverage detected