MapFileSerializer.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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 "data/QGearsSerializer.h"
  18. namespace QGears {
  19. class WorldMapFile;
  20. /**
  21. * Handles map file serialization.
  22. */
  23. class MapFileSerializer : public Serializer{
  24. public:
  25. /**
  26. * Block header of map files.
  27. */
  28. struct BlockHeader{
  29. /**
  30. * Offset in this block of the compressed data.
  31. *
  32. * At the compressed data offset we have another uint32 which
  33. * is the size of the uncompressed data.
  34. */
  35. uint32 compressed_data_offsets[16];
  36. };
  37. /**
  38. * Block header of a mesh section in map files.
  39. */
  40. struct BlockMeshHeader{
  41. /**
  42. * Number of BlockTriangle's in the mesh.
  43. */
  44. uint16 triengle_count;
  45. /**
  46. * Number of vertices and normals.
  47. */
  48. uint16 vertex_count;
  49. };
  50. /**
  51. * A vertex.
  52. */
  53. struct Vertex{
  54. /**
  55. * X coordinate.
  56. */
  57. sint16 x;
  58. /**
  59. * Y coordinate.
  60. */
  61. sint16 y;
  62. /**
  63. * Z coordinate.
  64. */
  65. sint16 z;
  66. /**
  67. * Fill space to fit the structure in 32 bit.
  68. */
  69. uint16 unused;
  70. };
  71. /**
  72. * A normal.
  73. */
  74. struct Normal{
  75. /**
  76. * X coordinate.
  77. */
  78. sint16 x;
  79. /**
  80. * Y coordinate.
  81. */
  82. sint16 y;
  83. /**
  84. * Z coordinate.
  85. */
  86. sint16 z;
  87. /**
  88. * Fill space to fit the structure in 32 bit.
  89. */
  90. uint16 unused;
  91. };
  92. /**
  93. * A triangle block in a map file.
  94. */
  95. struct BlockTriangle{
  96. /**
  97. * Index of the first vertex of the triangle.
  98. */
  99. uint8 vertex_0_index;
  100. /**
  101. * Index of the second vertex of the triangle.
  102. */
  103. uint8 vertex_1_index;
  104. /**
  105. * Index of the third vertex of the triangle.
  106. */
  107. uint8 vertex_2_index;
  108. /**
  109. * Triangle walkability.
  110. *
  111. * Only 5 bits are valid.
  112. *
  113. * @todo Document walkability modes.
  114. */
  115. uint8 walkability_info_;
  116. /**
  117. * Unknown data.
  118. *
  119. * Only 3 bits are valid.
  120. *
  121. * @todo Find out what this is for.
  122. */
  123. uint8 unknown;
  124. /**
  125. * First side vector U component.
  126. */
  127. uint8 vertex_0_u;
  128. /**
  129. * First side vector V component.
  130. */
  131. uint8 vertex_0_v;
  132. /**
  133. * Second side vector U component.
  134. */
  135. uint8 vertex_1_u;
  136. /**
  137. * Second side vector V component.
  138. */
  139. uint8 vertex_1_v;
  140. /**
  141. * Third side vector U component.
  142. */
  143. uint8 vertex_2_u;
  144. /**
  145. * Third side vector V component.
  146. */
  147. uint8 vertex_2_v;
  148. /**
  149. * Triangle texture info.
  150. *
  151. * Only 9 bits are valid.
  152. */
  153. uint16 TextureInfo;
  154. /**
  155. * Triangle location.
  156. *
  157. * Only 7 bits are valid.
  158. */
  159. uint16 Location;
  160. };
  161. /**
  162. * Type of walkmesh triangle.
  163. *
  164. * Determines the triangle walkability under different conditions.
  165. */
  166. enum TriangleWalkMapTypes{
  167. /**
  168. * Grass.
  169. *
  170. * Most things can go here.
  171. */
  172. GRASS = 0,
  173. /**
  174. * Forest.
  175. *
  176. * No landing here, but anything else goes.
  177. */
  178. FOREST = 1,
  179. /**
  180. * Mountain.
  181. *
  182. * Chocobos and flying machines only.
  183. */
  184. MOUNTAIN = 2,
  185. /**
  186. * Deep water.
  187. *
  188. * Only gold chocobo and submarine can go here.
  189. */
  190. SEA_DEEP_WATER = 3,
  191. /**
  192. * River crossing.
  193. *
  194. * Buggy, Tiny Bronco and water-capable chocobos.
  195. */
  196. RIVER_CROSSING = 4,
  197. /**
  198. * River.
  199. *
  200. * Tiny Bronco and chocobos.
  201. */
  202. RIVER = 5,
  203. /**
  204. * Shallow water.
  205. *
  206. * Only Tiny Bronco and chocobos.
  207. */
  208. WATER = 6,
  209. /**
  210. * Swamp.
  211. *
  212. * The Midgar zolom can only move in swamp areas.
  213. */
  214. SWAMP = 7,
  215. /**
  216. * Desert.
  217. *
  218. * No landing.
  219. */
  220. DESERT = 8,
  221. /**
  222. * Wasteland.
  223. *
  224. * Found around Midgar, Wutai and misc other. No landing.
  225. */
  226. WASTELAND = 9,
  227. /**
  228. * Snow.
  229. *
  230. * Leaves footprints, no landing.
  231. */
  232. SNOW = 10,
  233. /**
  234. * Riverside.
  235. *
  236. * Beach-like area where river and land meet.
  237. */
  238. RIVERSIDE = 11,
  239. /**
  240. * Cliff.
  241. *
  242. * Sharp drop, usually where the player can be on either side.
  243. */
  244. CLIFF = 12,
  245. /**
  246. * Corel bridge.
  247. *
  248. * Tiny bridge over the waterfall from Costa del Sol to Corel.
  249. */
  250. COREL_BRIDGE = 13,
  251. /**
  252. * Bridges in Wutai.
  253. *
  254. * Rickety rope bridges south of Wutai.
  255. */
  256. WUTAI_BRIDGE = 14,
  257. /**
  258. * Unused.
  259. *
  260. * It doesn't seem to be used anywhere in the original data.
  261. */
  262. UNUSED_1 = 15,
  263. /**
  264. * Hill side.
  265. *
  266. * This is the tiny walkable part at the foot of a mountain.
  267. */
  268. HILL_SIDE = 16,
  269. /**
  270. * Beach.
  271. *
  272. * Where land and shallow water meet.
  273. */
  274. BEACH = 17,
  275. /**
  276. * Submarine pens.
  277. *
  278. * The only place where the submarine can be boarded.
  279. */
  280. SUBMARINE_PEN = 18,
  281. /**
  282. * Cosmo Canyon area.
  283. *
  284. * The ground in cosmo canyon has this type, walkability seems
  285. * to be the same as {@see Wasteland} (no landing).
  286. */
  287. CANYON = 19,
  288. /**
  289. * Mountain pass.
  290. *
  291. * The small path through the mountains connecting Costa del
  292. * Sol and Corel.
  293. */
  294. MOUNTAIN_PASS = 20,
  295. /**
  296. * Unknown.
  297. *
  298. * Present around bridges, may have some special meaning.
  299. */
  300. UNKNOWN_1 = 21,
  301. /**
  302. * Waterfall.
  303. *
  304. * River type where the Tiny Bronco can't go.
  305. */
  306. WATERFALL = 22,
  307. /**
  308. * Unused.
  309. *
  310. * It doesn't seem to be used anywhere in the original data.
  311. */
  312. UNUSED_2 = 23,
  313. /**
  314. * Gold Saucer desert.
  315. *
  316. * Special desert type for the Gold Saucer desert.
  317. */
  318. GOLD_SAUCER_DESERT = 24,
  319. /**
  320. * Jungle.
  321. *
  322. * Same walkability as {@see FOREST}, used in southern parts of
  323. * the map.
  324. */
  325. JUNGLE = 25,
  326. /**
  327. * Deep sea.
  328. *
  329. * Special type of deep water, only used in one small spot next
  330. * to HP-MP cave, possibly related to the underwater
  331. * map/submarine.
  332. */
  333. SEA = 26,
  334. /**
  335. * The northernd cave.
  336. *
  337. * Inside part of the crater, where the Highwind can descend.
  338. */
  339. NORTHERND_CAVE = 27,
  340. /**
  341. * Borders of the Gold Saucer desert.
  342. *
  343. * Narrow strip of land surrounding the golden saucer desert.
  344. * Probably related to the "quicksand" script.
  345. */
  346. GOLD_SAUCER_DESERT_BORDER = 28,
  347. /**
  348. * Bridge heads.
  349. *
  350. * Small area at both ends of every bridge. May have some
  351. * special meaning.
  352. */
  353. BRIDGE_HEAD = 29,
  354. /**
  355. * Entrances.
  356. *
  357. * Special type that can be set unwalkable from the script.
  358. */
  359. BACK_ENTRANCE = 30,
  360. /**
  361. * Unused.
  362. *
  363. * It doesn't seem to be used anywhere in the original data.
  364. */
  365. UNUSED_3 = 31
  366. };
  367. /**
  368. * Constructor.
  369. */
  370. MapFileSerializer();
  371. /**
  372. * Destructor.
  373. */
  374. virtual ~MapFileSerializer();
  375. /**
  376. * Imports and parses a map file.
  377. *
  378. * @param stream[in] Map file contents.
  379. * @param dest[in] Unused
  380. */
  381. void ImportMapFile(Ogre::DataStreamPtr& stream, WorldMapFile& dest);
  382. /**
  383. * Part of a file block.
  384. */
  385. struct BlockPart{
  386. /**
  387. * Block part header.
  388. */
  389. BlockMeshHeader header;
  390. /**
  391. * List of triangles in the block part.
  392. */
  393. std::vector<BlockTriangle> triangles;
  394. /**
  395. * List of vertices in the block part.
  396. */
  397. std::vector<Vertex> vertices;
  398. /**
  399. * List of normals in the block part.
  400. */
  401. std::vector<Normal> normals;
  402. };
  403. /**
  404. * A file block.
  405. */
  406. struct Block{
  407. /**
  408. * List of meshes in the block.
  409. */
  410. std::vector<BlockPart> meshes;
  411. };
  412. /**
  413. * The list of file blocks.
  414. */
  415. std::vector<Block> blocks;
  416. };
  417. }