WorldmapFileSerializer.h 12 KB

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