VGearsApplication.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 <OgreRoot.h>
  17. #include <OgreOverlaySystem.h>
  18. #include <memory>
  19. #include "TypeDefine.h"
  20. namespace VGears{
  21. /**
  22. * The V-Gears main applicacion
  23. */
  24. class Application : public Ogre::Singleton<Application>{
  25. public:
  26. /**
  27. * Constructor.
  28. *
  29. * @param[in] pluginsFileName Path to the plugins file.
  30. * @param[in] resourcesFile Path to the resources file.
  31. * @param[in] logFileName Path to the log file.
  32. */
  33. Application(
  34. Ogre::String pluginsFileName, Ogre::String resourcesFile, Ogre::String logFileName
  35. ): plugins_filename_(pluginsFileName),
  36. resources_filename_(resourcesFile), log_filename_(logFileName)
  37. {}
  38. /**
  39. * Constructor.
  40. *
  41. * @param[in] argc Number of command line arguments.
  42. * @param[in] argv List of command line arguments.
  43. */
  44. Application(int argc, char *argv[]);
  45. /**
  46. * Destructor.
  47. */
  48. virtual ~Application();
  49. /**
  50. * Initializes the Ogre rendering system.
  51. *
  52. * @param[in] hideWindow True to not show the main window, false to
  53. * show it.
  54. * @return True if the system was succesfully initiated, false
  55. * if there were errors or it was already initialized.
  56. */
  57. bool initOgre(bool hideWindow = false);
  58. /**
  59. * Retrieves the Ogre system main component.
  60. *
  61. * @return Pointer to the Ogre main component.
  62. */
  63. Ogre::Root* getRoot(void);
  64. /**
  65. * Retrieves the Ogre main window.
  66. *
  67. * @return Pointer to the Ogre window.
  68. */
  69. Ogre::RenderWindow* getRenderWindow(void);
  70. /**
  71. * Retrieves the Ogre resources file name.
  72. *
  73. * @return Ogre resource configuration file name.
  74. */
  75. const String& getResourcesFilename(void);
  76. /**
  77. * Retrieves the Ogre resource manager.
  78. *
  79. * @return Pointer to the Ogre resource manager.
  80. */
  81. Ogre::ResourceGroupManager* ResMgr() {return res_mgr_;}
  82. /**
  83. * Re-finalizes singleton registration after full object construction.
  84. *
  85. * Call this method immediately after constructing the Application
  86. * to ensure the singleton pointer is properly registered after the
  87. * object's vptr is fully initialized (avoids UBSAN vptr warnings).
  88. *
  89. * @param[in] instance Pointer to the Application instance.
  90. */
  91. static void FinalizeSingletonRegistration(Application* instance) {
  92. msSingleton = instance;
  93. }
  94. protected:
  95. /**
  96. * Retrieves the main window title.
  97. *
  98. * @return Th windo title.
  99. */
  100. String getWindowTitle(void) const;
  101. /**
  102. * Processes command line arguments.
  103. *
  104. * @param[in] argc Number of command line arguments.
  105. * @param[in] argv List of command line arguments.
  106. * @return True if all arguments were successfully processed, false
  107. * on error
  108. */
  109. bool processCommandLine(int argc, char *argv[]);
  110. /**
  111. * Registers an {@see LGPArchiveFactory} with the Ogre archive
  112. * manager
  113. */
  114. void registerArchiveFactories(void);
  115. /**
  116. * Loads the resource configuration from the file.
  117. */
  118. void loadResourcesConfig(void);
  119. /**
  120. * Initializes components.
  121. *
  122. * Initializes the TexCodec component and the resource manager.
  123. */
  124. void initComponents(void);
  125. /**
  126. * Unloads components.
  127. *
  128. * Unoads the TexCodec component and the resource manager.
  129. */
  130. void destroyComponents(void);
  131. /**
  132. * Initializes the resource manager.
  133. */
  134. void createResourceManagers(void);
  135. /**
  136. * Unloads the resource manager.
  137. */
  138. void destroyResourceManagers(void);
  139. private:
  140. /**
  141. * List of resource managers.
  142. */
  143. typedef std::vector<std::shared_ptr<Ogre::ResourceManager>>
  144. ResourceManagerVector;
  145. /**
  146. * String for the command line help text.
  147. */
  148. static const char* CLI_SECTION_GENERIC;
  149. /**
  150. * String for the command line arguments.
  151. */
  152. static const char* CLI_HELP;
  153. /**
  154. * String for the command line help text.
  155. */
  156. static const char* CLI_HELP_DESCRIPTION;
  157. /**
  158. * String for the command line arguments.
  159. */
  160. static const char* CLI_CONFIG_FILE;
  161. /**
  162. * String for the command line help text.
  163. */
  164. static const char* CLI_CONFIG_FILE_DESCRIPTION;
  165. /**
  166. * String for the command line arguments.
  167. */
  168. static const char* CLI_LOG_FILE;
  169. /**
  170. * String for the command line help text.
  171. */
  172. static const char* CLI_LOG_FILE_DESCRIPTION;
  173. /**
  174. * String for the command line arguments.
  175. */
  176. static const char* CLI_PLUGINS_FILE;
  177. /**
  178. * String for the command line help text.
  179. */
  180. static const char* CLI_PLUGINS_FILE_DESCRIPTION;
  181. /**
  182. * String for the command line arguments.
  183. */
  184. static const char* CLI_RESOURCES_FILE;
  185. /**
  186. * String for the command line help text.
  187. */
  188. static const char* CLI_RESOURCES_FILE_DESCRIPTION;
  189. /**
  190. * Number of arguments assed by command line.
  191. */
  192. int _argc = 0;
  193. /**
  194. * List of arguments passed by command line.
  195. */
  196. char **_argv = nullptr;
  197. /**
  198. * Path to the configuration file.
  199. */
  200. String config_filename_;
  201. /**
  202. * Path to the log file.
  203. */
  204. String log_filename_;
  205. /**
  206. * Path to the plugin configuration file.
  207. */
  208. String plugins_filename_;
  209. /**
  210. * Path to the resource configuration file.
  211. */
  212. String resources_filename_;
  213. /**
  214. * Flag for initialization status.
  215. */
  216. bool _initialized = false;
  217. /**
  218. * Ogre main component.
  219. */
  220. std::unique_ptr<Ogre::Root> _root;
  221. /**
  222. *The ogre overlay system.
  223. */
  224. std::unique_ptr<Ogre::OverlaySystem> _overlay_system;
  225. /**
  226. * The Ogre main window.
  227. */
  228. Ogre::RenderWindow* _render_window = nullptr; // Not owned
  229. /**
  230. * List of Ogre resource managers.
  231. */
  232. ResourceManagerVector _resource_managers;
  233. /**
  234. * Ogre resource group manager.
  235. */
  236. Ogre::ResourceGroupManager* res_mgr_ = nullptr; // Not owned
  237. };
  238. }