QGearsPFileSerializer.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include "common/TypeDefine.h"
  17. #include "QGearsPFile.h"
  18. #include "QGearsSerializer.h"
  19. namespace QGears{
  20. /**
  21. * Handles the serialization of P files.
  22. */
  23. class PFileSerializer : public Serializer{
  24. public:
  25. /**
  26. * Constructor.
  27. */
  28. PFileSerializer();
  29. /**
  30. * Destructor.
  31. */
  32. virtual ~PFileSerializer();
  33. /**
  34. * Imports a P file.
  35. *
  36. * @param stream[in] The contents of the P file.
  37. * @param dest[out] The formed P file.
  38. */
  39. virtual void ImportPFile(Ogre::DataStreamPtr &stream, PFile* dest);
  40. /**
  41. * The header of a P file.
  42. */
  43. struct Header{
  44. /**
  45. * The file format version.
  46. */
  47. uint32 version;
  48. /**
  49. * Unknown data.
  50. */
  51. uint32 unknown_04;
  52. /**
  53. * Type of vertices.
  54. */
  55. uint32 vertex_type;
  56. /**
  57. * The number of vertices.
  58. */
  59. uint32 num_vertices;
  60. /**
  61. * The number of normals.
  62. */
  63. uint32 num_normals;
  64. /**
  65. * Number of unknown data blocks.
  66. */
  67. uint32 num_unknown1;
  68. /**
  69. * Number of texture coordinates.
  70. */
  71. uint32 num_texture_coordinates;
  72. /**
  73. * Number of vertex colours.
  74. */
  75. uint32 num_vertex_colors;
  76. /**
  77. * Number of edges.
  78. */
  79. uint32 num_edges;
  80. /**
  81. * Number of polygons.
  82. */
  83. uint32 num_polygons;
  84. /**
  85. * Number of unknown data blocks.
  86. */
  87. uint32 num_unknown2;
  88. /**
  89. * Number of unknown data blocks.
  90. */
  91. uint32 num_unknown3;
  92. /**
  93. * Number of materials.
  94. */
  95. uint32 num_materials;
  96. /**
  97. * Number of groups.
  98. */
  99. uint32 num_groups;
  100. /**
  101. * Number of bounding boxes.
  102. */
  103. uint32 num_bboxes;
  104. /**
  105. * @todo Understand and document.
  106. */
  107. uint32 norm_index_table_flag;
  108. /**
  109. * @todo Understand and document.
  110. */
  111. uint32 runtime_data[0x10];
  112. };
  113. typedef PFile::BBoxEntry BBoxEntry;
  114. typedef PFile::Edge Edge;
  115. typedef PFile::Group Group;
  116. typedef PFile::MaterialInformation MaterialInformation;
  117. typedef PFile::PolygonDefinition PolygonDefinition;
  118. typedef PFile::Colour Colour;
  119. protected:
  120. /**
  121. * Reads a file header and sets the instance data.
  122. *
  123. * @param stream[in] The contents of the P file.
  124. */
  125. virtual void ReadFileHeader(Ogre::DataStreamPtr &stream);
  126. /**
  127. * Reads an object as a colour.
  128. *
  129. * @param stream[in] Input data.
  130. * @param dest[out] The formed colour data.
  131. */
  132. virtual void readObject(Ogre::DataStreamPtr &stream, Colour &dest);
  133. /**
  134. * Reads an object as an edge.
  135. *
  136. * @param stream[in] Input data.
  137. * @param dest[out] The formed edge data.
  138. */
  139. virtual void readObject(Ogre::DataStreamPtr &stream, Edge &dest);
  140. /**
  141. * Reads an object as a polygon definition.
  142. *
  143. * @param stream[in] Input data.
  144. * @param dest[out] The formed poligon definition data.
  145. */
  146. virtual void readObject(
  147. Ogre::DataStreamPtr &stream, PolygonDefinition &dest
  148. );
  149. /**
  150. * Reads an object as a group.
  151. *
  152. * @param stream[in] Input data.
  153. * @param dest[out] The formed group data.
  154. */
  155. virtual void readObject(Ogre::DataStreamPtr &stream, Group &dest);
  156. /**
  157. * Reads an object as a bounding box.
  158. *
  159. * @param stream[in] Input data.
  160. * @param dest[out] The formed bounding box data.
  161. */
  162. virtual void readObject(
  163. Ogre::DataStreamPtr &stream, BBoxEntry &dest
  164. );
  165. using Serializer::readObject;
  166. /**
  167. * Reads a stream as a vector.
  168. *
  169. * @param stream[in] The input stream.
  170. * @param dest[out] The vector data will be loaded here.
  171. * @param count[in] Data units to copy.
  172. */
  173. template<typename ValueType> void ReadVector(
  174. Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
  175. size_t count
  176. );
  177. private:
  178. /**
  179. * The file header.
  180. */
  181. Header header_;
  182. };
  183. }