DataInstaller.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 <string>
  17. #include <vector>
  18. #include <iostream>
  19. #include "common/VGearsApplication.h"
  20. #include "common/FinalFantasy7/FF7NameLookup.h"
  21. #include "data/VGearsTriggersFile.h"
  22. #include "data/VGearsFLevelFile.h"
  23. #include "FieldTextWriter.h"
  24. #include "ModelsAndAnimationsDb.h"
  25. #include "ScopedLgp.h"
  26. #include "SpawnPointDb.h"
  27. // TODO: Separate classes in files.
  28. // TODO: Move implementations to cpp file.
  29. typedef std::set<std::string> MapCollection;
  30. typedef std::map<u16, SpawnPointDb> FieldSpawnPointsMap;
  31. typedef std::map<u16, float> FieldScaleFactorMap;
  32. /**
  33. * The data installer.
  34. */
  35. class DataInstaller{
  36. public:
  37. static float LINE_SCALE_FACTOR;
  38. /**
  39. * Installer constructor
  40. *
  41. * @param input_dir[in] Path to the directory containing the original
  42. * data to parse.
  43. * @param output_dir[in] Path to the directory to write generated data
  44. * to.
  45. * @param write_output_line Pointer to function to write output.
  46. */
  47. DataInstaller(
  48. std::string input_dir, std::string output_dir,
  49. std::function<void(std::string)> write_output_line
  50. );
  51. /**
  52. * Installer destructor.
  53. */
  54. ~DataInstaller();
  55. /**
  56. * Handle the installation progress.
  57. *
  58. * @return Installation progress [0-100].
  59. */
  60. int Progress();
  61. private:
  62. /**
  63. * Calculates the installation progress.
  64. *
  65. * @return Installation progress [0-100]
  66. */
  67. int CalcProgress();
  68. /**
  69. * Creates a directory in the outputh path.
  70. *
  71. * @param dir[in] Path of the directory to create, relative to the
  72. * output path..
  73. * @throws std::runtime_error If the directory can't be created.
  74. */
  75. void CreateDir(const std::string& dir);
  76. /**
  77. * Initializer for {@see CollectionFieldSpawnAndScaleFactors}.
  78. *
  79. * Installation step 1.
  80. */
  81. void InitCollectSpawnAndScaleFactors();
  82. /**
  83. * Reads spawn points and scale factors from flevel files.
  84. *
  85. * Installation step 2.
  86. */
  87. void CollectionFieldSpawnAndScaleFactors();
  88. /**
  89. * Converts FFVII PC fields to V-Gears format.
  90. */
  91. void ConvertFieldsIteration();
  92. /**
  93. * Initializer for {@see WriteMapsXmlIteration}.
  94. *
  95. * Installation step 3.
  96. */
  97. void WriteMapsXmlBegin();
  98. /**
  99. * Saves the game maps to XML files.
  100. *
  101. * Installation step 4.
  102. */
  103. void WriteMapsXmlIteration();
  104. /**
  105. * Cleans up after {@see WriteMapsXmlIteration}.
  106. *
  107. * Installation step 5.
  108. */
  109. void EndWriteMapsXml();
  110. /**
  111. * Initializer for {@see ConvertFieldModelsIteration}.
  112. *
  113. * Installation step 6.
  114. */
  115. void ConvertFieldModelsBegin();
  116. /**
  117. * Converts the field models to V-Gears format.
  118. *
  119. * Installation step 7 and final.
  120. */
  121. void ConvertFieldModelsIteration();
  122. /**
  123. * Installation steps.
  124. */
  125. enum InstallationSteps{
  126. /**
  127. * Installation not started.
  128. */
  129. IDLE = 0,
  130. /**
  131. * Initializer for {@see SPAWN_POINTS_AND_SCALE_FACTORS}.
  132. */
  133. SPAWN_POINTS_AND_SCALE_FACTORS_INIT = 1,
  134. /**
  135. * Step that collects spawn points and sclae factors.
  136. */
  137. SPAWN_POINTS_AND_SCALE_FACTORS = 2,
  138. /**
  139. * Step that convets fields to V-Gears format.
  140. */
  141. CONVERT_FIELDS = 3,
  142. /**
  143. * Initializer for {@see WRITE_MAPS}.
  144. */
  145. WRITE_MAPS_INIT = 4,
  146. /**
  147. * Step that writes XML maps.
  148. */
  149. WRITE_MAPS = 5,
  150. /**
  151. * Clean up after {@see WRITE_MAPS}.
  152. */
  153. WRITE_MAPS_CLEAN = 6,
  154. /**
  155. * Initializer for {@see CONVERT_FIELD_MODELS}.
  156. */
  157. CONVERT_FIELD_MODELS_INIT = 7,
  158. /**
  159. * Step that converts field models.
  160. */
  161. CONVERT_FIELD_MODELS = 8,
  162. /**
  163. * Number of installation steps.
  164. */
  165. STATE_COUNT,
  166. /**
  167. * Installation finished.
  168. */
  169. DONE = 100,
  170. };
  171. /**
  172. * Current installation status.
  173. */
  174. InstallationSteps installation_state_ = IDLE;
  175. /**
  176. * The path to the directory from which to read the PC game data.
  177. */
  178. std::string input_dir_;
  179. /**
  180. * The path to the directory where to sve the V-Gears data.
  181. */
  182. std::string output_dir_;
  183. /**
  184. * The installer application.
  185. *
  186. * It's a singleton so it can't be recreated. It will crash the second
  187. * time round.
  188. */
  189. VGears::Application application_;
  190. /**
  191. * LGP archive with field data.
  192. */
  193. std::unique_ptr<ScopedLgp> fields_lgp_;
  194. /**
  195. * LGP archive with texture data.
  196. */
  197. std::unique_ptr<ScopedLgp> textures_lgp_;
  198. /**
  199. * LGP archive with field model data.
  200. */
  201. std::unique_ptr<ScopedLgp> field_models_lgp_;
  202. /**
  203. * List of flevel files.
  204. */
  205. Ogre::StringVectorPtr flevel_file_list_;
  206. /**
  207. * The list of maps.
  208. */
  209. std::vector<std::string> map_list_;
  210. /**
  211. * Map of the collected spawn points.
  212. */
  213. FieldSpawnPointsMap spawn_points_;
  214. /**
  215. * Map of th collected scale factors.
  216. */
  217. FieldScaleFactorMap scale_factors_;
  218. /**
  219. * ModelsAndAnimationsUsedByConvertedFields
  220. */
  221. ModelsAndAnimationsDb used_models_and_anims_;
  222. /**
  223. * List of converted maps.
  224. */
  225. MapCollection converted_map_list_;
  226. /**
  227. * Iterator for {@see converted_map_list}.
  228. */
  229. MapCollection::iterator converted_map_list_iterator_;
  230. /**
  231. * Iterator counter.
  232. */
  233. size_t iterator_counter_;
  234. /**
  235. * Helper variable to indicate internal progress of installation steps.
  236. */
  237. size_t conversion_step_;
  238. /**
  239. * Helper variable to indicate internal progress of installation steps.
  240. */
  241. size_t progress_step_num_elements_;
  242. /**
  243. * Field currently being processed.
  244. */
  245. VGears::FLevelFilePtr field_;
  246. /**
  247. * List of model files.
  248. */
  249. Ogre::StringVectorPtr field_model_file_list_;
  250. /**
  251. * An XML document.
  252. *
  253. * Internally used during some installation steps.
  254. */
  255. std::unique_ptr<TiXmlDocument> doc_;
  256. /**
  257. * An XML element.
  258. *
  259. * Internally used during some installation steps.
  260. */
  261. std::unique_ptr<TiXmlElement> element_;
  262. /**
  263. * Iterator for {@see used_models_and_anims_}.
  264. */
  265. ModelAnimationMap::iterator model_animation_map_iterator_;
  266. /**
  267. * Function used to print text.
  268. */
  269. std::function<void(std::string)> write_output_line;
  270. /**
  271. * Field text writer.
  272. */
  273. FieldTextWriter field_text_writer_;
  274. /**
  275. * Written materials.
  276. */
  277. std::vector<std::string> materials_;
  278. };