QGearsFLevelFileSerializer.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 "QGearsFLevelFile.h"
  18. #include "QGearsSerializer.h"
  19. namespace QGears{
  20. /**
  21. * Handles the serialization of flevel files.
  22. */
  23. class FLevelFileSerializer : public Serializer{
  24. public:
  25. /**
  26. * Constructor.
  27. */
  28. FLevelFileSerializer();
  29. /**
  30. * Destructor.
  31. */
  32. virtual ~FLevelFileSerializer();
  33. virtual void ImportFLevelFile(
  34. Ogre::DataStreamPtr &stream, FLevelFile* dest
  35. );
  36. enum{
  37. /**
  38. * Scripts section.
  39. */
  40. SECTION_SCRIPT,
  41. /**
  42. * Camera matrix section/
  43. */
  44. SECTION_CAMERA_MATRIX,
  45. /**
  46. * Model section.
  47. */
  48. SECTION_MODEL_LOADER,
  49. /**
  50. * Color palette section/
  51. */
  52. SECTION_PALETTE,
  53. /**
  54. * Walkmesh section.
  55. */
  56. SECTION_WALKMESH,
  57. /**
  58. * Tile map section.
  59. */
  60. SECTION_TILE_MAP,
  61. /**
  62. * Battle encounter section.
  63. */
  64. SECTION_ENCOUNTER,
  65. /**
  66. * Triggers section.
  67. */
  68. SECTION_TRIGGER,
  69. /**
  70. * Background section.
  71. */
  72. SECTION_BACKGROUND,
  73. /**
  74. * @todo Count of what?
  75. */
  76. SECTION_COUNT
  77. };
  78. /**
  79. * A flevel file header.
  80. */
  81. struct Header{
  82. /**
  83. * File format version.
  84. */
  85. uint16 version;
  86. /**
  87. * Number of sections in the file.
  88. */
  89. uint32 section_count;
  90. };
  91. protected:
  92. /**
  93. * Reads the file header and sets instance data..
  94. *
  95. * @param stream[in] Contents of the file.
  96. */
  97. void ReadFileHeader(Ogre::DataStreamPtr &stream);
  98. /**
  99. * Reads a section data.
  100. *
  101. * @param stream[in] Contents of the file.
  102. * @param out_buffer[out] The contents of the section are loaded
  103. * here.
  104. * @param section_size[in] Size of the section to read, in bytes.
  105. */
  106. void ReadSectionData(
  107. Ogre::DataStreamPtr &stream, Ogre::DataStreamPtr &out_buffer,
  108. size_t section_size
  109. );
  110. /**
  111. * Reads a file section.
  112. *
  113. * @param stream[in] Contents of the file.
  114. * @param dest[out] The section data will be loaded here.
  115. * @param section_index[in] Index of the section to read.
  116. */
  117. virtual void ReadSection(
  118. Ogre::DataStreamPtr &stream, FLevelFile* dest,
  119. const size_t section_index
  120. );
  121. /**
  122. * Creates a resource.
  123. *
  124. * @param dest[out] The crteated resource.
  125. * @param extension[in] The resource file extension.
  126. */
  127. template<typename ResourceManagerType>
  128. Ogre::ResourcePtr CreateResource(
  129. FLevelFile *dest, const String &extension
  130. );
  131. /**
  132. * Reads camera matrix data from a flevel file.
  133. *
  134. * @param stream[in] Input stream.
  135. * @param dest[out] The data will be set on this file.
  136. */
  137. void ReadCameraMatrix(
  138. Ogre::DataStreamPtr &stream, FLevelFile* dest
  139. );
  140. /**
  141. * Reads model list data from a flevel file.
  142. *
  143. * @param stream[in] Input stream.
  144. * @param dest[out] The data will be set on this file.
  145. */
  146. void ReadModelList(Ogre::DataStreamPtr &stream, FLevelFile* dest);
  147. /**
  148. * Reads color palette data from a flevel file.
  149. *
  150. * @param stream[in] Input stream.
  151. * @param dest[out] The data will be set on this file.
  152. */
  153. void ReadPalette(Ogre::DataStreamPtr &stream, FLevelFile* dest);
  154. /**
  155. * Reads walkmesh data from a flevel file.
  156. *
  157. * @param stream[in] Input stream.
  158. * @param dest[out] The data will be set on this file.
  159. */
  160. void ReadWalkmesh(Ogre::DataStreamPtr &stream, FLevelFile* dest);
  161. /**
  162. * Reads background data from a flevel file.
  163. *
  164. * @param stream[in] Input stream.
  165. * @param dest[out] The data will be set on this file.
  166. */
  167. void ReadBackground(Ogre::DataStreamPtr &stream, FLevelFile* dest);
  168. /**
  169. * Reads trigger data from a flevel file.
  170. *
  171. * @param stream[in] Input stream.
  172. * @param dest[out] The data will be set on this file.
  173. */
  174. void ReadTriggers(Ogre::DataStreamPtr &stream, FLevelFile* dest);
  175. /**
  176. * @todo Understand and document.
  177. *
  178. * @param stream[in] Input stream.
  179. */
  180. void ReadEnd(Ogre::DataStreamPtr &stream);
  181. /**
  182. * Reads a stream as a vector.
  183. *
  184. * @param stream[in] The input stream.
  185. * @param dest[out] The vector data will be loaded here.
  186. * @param count[in] Data units to copy.
  187. */
  188. template<typename ValueType> void ReadVector(
  189. Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
  190. size_t count
  191. );
  192. /**
  193. * Retrieves the base name of a flevel file.
  194. *
  195. * @param dest[in] Flevel file.
  196. * @return The filename, without path or extension.
  197. */
  198. virtual String GetBaseName(const FLevelFile* dest) const;
  199. /**
  200. * End-of-file tag.
  201. */
  202. static const String TAG_FILE_END;
  203. private:
  204. /**
  205. * The file header.
  206. */
  207. Header header_;
  208. };
  209. }