RioEngine  0.1
My first attempt to create a 3D WYSIWYG Game Engine
qtcustomserialization.hpp
Go to the documentation of this file.
1 //--------------------------------------------------------------- @License begins
2 // RioEngine: The late night Coke -without whores- debugging sessions
3 // 2012-2015 Leopoldo Lomas Flores. Torreon, Coahuila. MEXICO
4 // leopoldolomas [at] gmail
5 // www.rioengine.com
6 // www.leopoldolomas.info
7 // "You have a problem, you face it like a man."
8 //
9 // This is free and unencumbered software released into the public domain.
10 //
11 // Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
12 // software, either in source code form or as a compiled binary, for any purpose,
13 // commercial or non-commercial, and by any means.
14 //
15 // In jurisdictions that recognize copyright laws, the author or authors of this
16 // software dedicate any and all copyright interest in the software to the public
17 // domain. We make this dedication for the benefit of the public at large and to
18 // the detriment of our heirs and successors. We intend this dedication to be
19 // an overt act of relinquishment in perpetuity of all present and future
20 // rights to this software under copyright law.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS
24 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //--------------------------------------------------------------- @License ends
29 
30 #ifndef RIOENGINE_EDITOR_SERIALIZATION_CUSTOMSERIALIZATION_HPP_
31 #define RIOENGINE_EDITOR_SERIALIZATION_CUSTOMSERIALIZATION_HPP_
32 
33 #include <QMetaType>
34 #include "cengine/cgameobject.h"
36 
37 //-----------------------------------------------------------------------------
38 
39 template<class T>
40 void serialize_qobject(QDataStream &out, const void* obj) {
41  out << *(reinterpret_cast<T*>((void*)obj));
42 }
43 
44 //-----------------------------------------------------------------------------
45 
46 template<class T>
47 void deserialize_qobject(QDataStream &in, void* obj) {
48  in >> *(reinterpret_cast<T*>(obj));
49 }
50 
51 //------------------------------------------------------------------- btVector3
52 
53 void vec3_save_operator(QDataStream &out, const void* obj) {
54  btVector3 vec = *(reinterpret_cast<btVector3*>((void*)obj));
55  out << vec.x()
56  << vec.y()
57  << vec.z();
58 }
59 
60 //-----------------------------------------------------------------------------
61 
62 void vec3_load_operator(QDataStream &in, void* dest) {
63  float x, y, z;
64  in >> x >> y >> z;
65  btVector3* dest_vec = static_cast<btVector3*>(dest);
66  *dest_vec = btVector3(x, y, z);
67 }
68 
69 //---------------------------------------------------------------- btQuaternion
70 
71 void quat_save_operator(QDataStream &out, const void* obj) {
72  btQuaternion vec = *(reinterpret_cast<btQuaternion*>((void*)obj));
73  out << vec.x()
74  << vec.y()
75  << vec.z()
76  << vec.w();
77 }
78 
79 //-----------------------------------------------------------------------------
80 
81 void quat_load_operator(QDataStream &in, void* dest) {
82  float x, y, z, w;
83  in >> x >> y >> z >> w;
84  btQuaternion* dest_vec = static_cast<btQuaternion*>(dest);
85  *dest_vec = btQuaternion(x, y, z, w);
86 }
87 
88 // ------------------------------------------------------ QtCustomSerialization
89 
91  public:
93  int id = QMetaType::type("btQuaternion");
94  QMetaType::registerStreamOperators(id,
97 
98  id = QMetaType::type("btVector3");
99  QMetaType::registerStreamOperators(id,
102 
103  id = QMetaType::type("QList<CGameObject>");
104  QMetaType::registerStreamOperators(id,
105  serialize_qobject<QList<CGameObject>>,
106  deserialize_qobject<QList<CGameObject>>);
107 
108  id = QMetaType::type("QList<CLInstanceGeometry>");
109  QMetaType::registerStreamOperators(id,
110  serialize_qobject<QList<CLInstanceGeometry>>,
111  deserialize_qobject<QList<CLInstanceGeometry>>);
112 
113  id = QMetaType::type("QList<CLInstanceMaterial>");
114  QMetaType::registerStreamOperators(id,
115  serialize_qobject<QList<CLInstanceMaterial>>,
116  deserialize_qobject<QList<CLInstanceMaterial>>);
117 
118  id = QMetaType::type("QList<QProperty>");
119  QMetaType::registerStreamOperators(id,
120  serialize_qobject<QList<QProperty>>,
121  deserialize_qobject<QList<QProperty>>);
122  }
123 
124 private:
126 };
127 
128 #endif // RIOENGINE_EDITOR_SERIALIZATION_CUSTOMSERIALIZATION_HPP_
void serialize_qobject(QDataStream &out, const void *obj)
void vec3_load_operator(QDataStream &in, void *dest)
void quat_load_operator(QDataStream &in, void *dest)
void vec3_save_operator(QDataStream &out, const void *obj)
static void registerCustomStreamOperators()
void quat_save_operator(QDataStream &out, const void *obj)
void deserialize_qobject(QDataStream &in, void *obj)