QGearsApplication.h 7.6 KB

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