WorldmapFileSerializer.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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/VGearsSerializer.h"
  18. namespace VGears {
  19. class WorldmapFile;
  20. /**
  21. * Handles map file serialization.
  22. */
  23. class WorldmapFileSerializer : 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 there is a uint32 containing
  33. * the size of the compressed LZS payload.
  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. * Packed mesh function value.
  118. *
  119. * Only 3 bits are valid.
  120. * Values 0-2 mean no script; values 3-7 map to function IDs 0-4.
  121. */
  122. uint8 function_id;
  123. /**
  124. * First side vector U component.
  125. */
  126. uint8 vertex_0_u;
  127. /**
  128. * First side vector V component.
  129. */
  130. uint8 vertex_0_v;
  131. /**
  132. * Second side vector U component.
  133. */
  134. uint8 vertex_1_u;
  135. /**
  136. * Second side vector V component.
  137. */
  138. uint8 vertex_1_v;
  139. /**
  140. * Third side vector U component.
  141. */
  142. uint8 vertex_2_u;
  143. /**
  144. * Third side vector V component.
  145. */
  146. uint8 vertex_2_v;
  147. /**
  148. * Triangle texture info.
  149. *
  150. * Only 9 bits are valid.
  151. */
  152. uint16 TextureInfo;
  153. /**
  154. * Triangle location.
  155. *
  156. * Only 7 bits are valid.
  157. */
  158. uint16 Location;
  159. };
  160. /**
  161. * Type of walkmesh triangle.
  162. *
  163. * Determines the triangle walkability under different conditions.
  164. */
  165. enum TriangleWalkMapTypes{
  166. /**
  167. * Grass.
  168. *
  169. * Most things can go here.
  170. */
  171. GRASS = 0,
  172. /**
  173. * Forest.
  174. *
  175. * No landing here, but anything else goes.
  176. */
  177. FOREST = 1,
  178. /**
  179. * Mountain.
  180. *
  181. * Chocobos and flying machines only.
  182. */
  183. MOUNTAIN = 2,
  184. /**
  185. * Deep water.
  186. *
  187. * Only gold chocobo and submarine can go here.
  188. */
  189. SEA_DEEP_WATER = 3,
  190. /**
  191. * River crossing.
  192. *
  193. * Buggy, Tiny Bronco and water-capable chocobos.
  194. */
  195. RIVER_CROSSING = 4,
  196. /**
  197. * River.
  198. *
  199. * Tiny Bronco and chocobos.
  200. */
  201. RIVER = 5,
  202. /**
  203. * Shallow water.
  204. *
  205. * Only Tiny Bronco and chocobos.
  206. */
  207. WATER = 6,
  208. /**
  209. * Swamp.
  210. *
  211. * The Midgar zolom can only move in swamp areas.
  212. */
  213. SWAMP = 7,
  214. /**
  215. * Desert.
  216. *
  217. * No landing.
  218. */
  219. DESERT = 8,
  220. /**
  221. * Wasteland.
  222. *
  223. * Found around Midgar, Wutai and misc other. No landing.
  224. */
  225. WASTELAND = 9,
  226. /**
  227. * Snow.
  228. *
  229. * Leaves footprints, no landing.
  230. */
  231. SNOW = 10,
  232. /**
  233. * Riverside.
  234. *
  235. * Beach-like area where river and land meet.
  236. */
  237. RIVERSIDE = 11,
  238. /**
  239. * Cliff.
  240. *
  241. * Sharp drop, usually where the player can be on either side.
  242. */
  243. CLIFF = 12,
  244. /**
  245. * Corel bridge.
  246. *
  247. * Tiny bridge over the waterfall from Costa del Sol to Corel.
  248. */
  249. COREL_BRIDGE = 13,
  250. /**
  251. * Bridges in Wutai.
  252. *
  253. * Rickety rope bridges south of Wutai.
  254. */
  255. WUTAI_BRIDGE = 14,
  256. /**
  257. * Unused.
  258. *
  259. * It doesn't seem to be used anywhere in the original data.
  260. */
  261. UNUSED_1 = 15,
  262. /**
  263. * Hill side.
  264. *
  265. * This is the tiny walkable part at the foot of a mountain.
  266. */
  267. HILL_SIDE = 16,
  268. /**
  269. * Beach.
  270. *
  271. * Where land and shallow water meet.
  272. */
  273. BEACH = 17,
  274. /**
  275. * Submarine pens.
  276. *
  277. * The only place where the submarine can be boarded.
  278. */
  279. SUBMARINE_PEN = 18,
  280. /**
  281. * Cosmo Canyon area.
  282. *
  283. * The ground in cosmo canyon has this type, walkability seems
  284. * to be the same as {@see Wasteland} (no landing).
  285. */
  286. CANYON = 19,
  287. /**
  288. * Mountain pass.
  289. *
  290. * The small path through the mountains connecting Costa del
  291. * Sol and Corel.
  292. */
  293. MOUNTAIN_PASS = 20,
  294. /**
  295. * Unknown.
  296. *
  297. * Present around bridges, may have some special meaning.
  298. */
  299. UNKNOWN_1 = 21,
  300. /**
  301. * Waterfall.
  302. *
  303. * River type where the Tiny Bronco can't go.
  304. */
  305. WATERFALL = 22,
  306. /**
  307. * Unused.
  308. *
  309. * It doesn't seem to be used anywhere in the original data.
  310. */
  311. UNUSED_2 = 23,
  312. /**
  313. * Gold Saucer desert.
  314. *
  315. * Special desert type for the Gold Saucer desert.
  316. */
  317. GOLD_SAUCER_DESERT = 24,
  318. /**
  319. * Jungle.
  320. *
  321. * Same walkability as {@see FOREST}, used in southern parts of
  322. * the map.
  323. */
  324. JUNGLE = 25,
  325. /**
  326. * Deep sea.
  327. *
  328. * Special type of deep water, only used in one small spot next
  329. * to HP-MP cave, possibly related to the underwater
  330. * map/submarine.
  331. */
  332. SEA = 26,
  333. /**
  334. * The northernd cave.
  335. *
  336. * Inside part of the crater, where the Highwind can descend.
  337. */
  338. NORTHERND_CAVE = 27,
  339. /**
  340. * Borders of the Gold Saucer desert.
  341. *
  342. * Narrow strip of land surrounding the golden saucer desert.
  343. * Probably related to the "quicksand" script.
  344. */
  345. GOLD_SAUCER_DESERT_BORDER = 28,
  346. /**
  347. * Bridge heads.
  348. *
  349. * Small area at both ends of every bridge. May have some
  350. * special meaning.
  351. */
  352. BRIDGE_HEAD = 29,
  353. /**
  354. * Entrances.
  355. *
  356. * Special type that can be set unwalkable from the script.
  357. */
  358. BACK_ENTRANCE = 30,
  359. /**
  360. * Unused.
  361. *
  362. * It doesn't seem to be used anywhere in the original data.
  363. */
  364. UNUSED_3 = 31
  365. };
  366. /**
  367. * Constructor.
  368. */
  369. WorldmapFileSerializer();
  370. /**
  371. * Destructor.
  372. */
  373. virtual ~WorldmapFileSerializer();
  374. /**
  375. * Imports and parses a map file.
  376. *
  377. * @param[in] stream Map file contents.
  378. * @param[in] dest Resource parameter retained for API compatibility.
  379. */
  380. void ImportWorldmapFile(Ogre::DataStreamPtr& stream, WorldmapFile& dest);
  381. /**
  382. * Part of a file block.
  383. */
  384. struct BlockPart{
  385. /**
  386. * Block part header.
  387. */
  388. BlockMeshHeader header;
  389. /**
  390. * List of triangles in the block part.
  391. */
  392. std::vector<BlockTriangle> triangles;
  393. /**
  394. * List of vertices in the block part.
  395. */
  396. std::vector<Vertex> vertices;
  397. /**
  398. * List of normals in the block part.
  399. */
  400. std::vector<Normal> normals;
  401. };
  402. /**
  403. * A file block.
  404. */
  405. struct Block{
  406. /**
  407. * List of meshes in the block.
  408. */
  409. std::vector<BlockPart> meshes;
  410. };
  411. /**
  412. * The list of file blocks.
  413. */
  414. std::vector<Block> blocks;
  415. };
  416. }