| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #pragma once
- #include <OgreRoot.h>
- #include <OgreOverlaySystem.h>
- #include <memory>
- #include "TypeDefine.h"
- namespace VGears{
- /**
- * The V-Gears main applicacion
- */
- class Application : public Ogre::Singleton<Application>{
- public:
- /**
- * Constructor.
- *
- * @param[in] pluginsFileName Path to the plugins file.
- * @param[in] resourcesFile Path to the resources file.
- * @param[in] logFileName Path to the log file.
- */
- Application(
- Ogre::String pluginsFileName, Ogre::String resourcesFile, Ogre::String logFileName
- ): plugins_filename_(pluginsFileName),
- resources_filename_(resourcesFile), log_filename_(logFileName)
- {}
- /**
- * Constructor.
- *
- * @param[in] argc Number of command line arguments.
- * @param[in] argv List of command line arguments.
- */
- Application(int argc, char *argv[]);
- /**
- * Destructor.
- */
- virtual ~Application();
- /**
- * Initializes the Ogre rendering system.
- *
- * @param[in] hideWindow True to not show the main window, false to
- * show it.
- * @return True if the system was succesfully initiated, false
- * if there were errors or it was already initialized.
- */
- bool initOgre(bool hideWindow = false);
- /**
- * Retrieves the Ogre system main component.
- *
- * @return Pointer to the Ogre main component.
- */
- Ogre::Root* getRoot(void);
- /**
- * Retrieves the Ogre main window.
- *
- * @return Pointer to the Ogre window.
- */
- Ogre::RenderWindow* getRenderWindow(void);
- /**
- * Retrieves the Ogre resources file name.
- *
- * @return Ogre resource configuration file name.
- */
- const String& getResourcesFilename(void);
- /**
- * Retrieves the Ogre resource manager.
- *
- * @return Pointer to the Ogre resource manager.
- */
- Ogre::ResourceGroupManager* ResMgr() {return res_mgr_;}
- /**
- * Re-finalizes singleton registration after full object construction.
- *
- * Call this method immediately after constructing the Application
- * to ensure the singleton pointer is properly registered after the
- * object's vptr is fully initialized (avoids UBSAN vptr warnings).
- *
- * @param[in] instance Pointer to the Application instance.
- */
- static void FinalizeSingletonRegistration(Application* instance) {
- msSingleton = instance;
- }
- protected:
- /**
- * Retrieves the main window title.
- *
- * @return Th windo title.
- */
- String getWindowTitle(void) const;
- /**
- * Processes command line arguments.
- *
- * @param[in] argc Number of command line arguments.
- * @param[in] argv List of command line arguments.
- * @return True if all arguments were successfully processed, false
- * on error
- */
- bool processCommandLine(int argc, char *argv[]);
- /**
- * Registers an {@see LGPArchiveFactory} with the Ogre archive
- * manager
- */
- void registerArchiveFactories(void);
- /**
- * Loads the resource configuration from the file.
- */
- void loadResourcesConfig(void);
- /**
- * Initializes components.
- *
- * Initializes the TexCodec component and the resource manager.
- */
- void initComponents(void);
- /**
- * Unloads components.
- *
- * Unoads the TexCodec component and the resource manager.
- */
- void destroyComponents(void);
- /**
- * Initializes the resource manager.
- */
- void createResourceManagers(void);
- /**
- * Unloads the resource manager.
- */
- void destroyResourceManagers(void);
- private:
- /**
- * List of resource managers.
- */
- typedef std::vector<std::shared_ptr<Ogre::ResourceManager>>
- ResourceManagerVector;
- /**
- * String for the command line help text.
- */
- static const char* CLI_SECTION_GENERIC;
- /**
- * String for the command line arguments.
- */
- static const char* CLI_HELP;
- /**
- * String for the command line help text.
- */
- static const char* CLI_HELP_DESCRIPTION;
- /**
- * String for the command line arguments.
- */
- static const char* CLI_CONFIG_FILE;
- /**
- * String for the command line help text.
- */
- static const char* CLI_CONFIG_FILE_DESCRIPTION;
- /**
- * String for the command line arguments.
- */
- static const char* CLI_LOG_FILE;
- /**
- * String for the command line help text.
- */
- static const char* CLI_LOG_FILE_DESCRIPTION;
- /**
- * String for the command line arguments.
- */
- static const char* CLI_PLUGINS_FILE;
- /**
- * String for the command line help text.
- */
- static const char* CLI_PLUGINS_FILE_DESCRIPTION;
- /**
- * String for the command line arguments.
- */
- static const char* CLI_RESOURCES_FILE;
- /**
- * String for the command line help text.
- */
- static const char* CLI_RESOURCES_FILE_DESCRIPTION;
- /**
- * Number of arguments assed by command line.
- */
- int _argc = 0;
- /**
- * List of arguments passed by command line.
- */
- char **_argv = nullptr;
- /**
- * Path to the configuration file.
- */
- String config_filename_;
- /**
- * Path to the log file.
- */
- String log_filename_;
- /**
- * Path to the plugin configuration file.
- */
- String plugins_filename_;
- /**
- * Path to the resource configuration file.
- */
- String resources_filename_;
- /**
- * Flag for initialization status.
- */
- bool _initialized = false;
- /**
- * Ogre main component.
- */
- std::unique_ptr<Ogre::Root> _root;
- /**
- *The ogre overlay system.
- */
- std::unique_ptr<Ogre::OverlaySystem> _overlay_system;
- /**
- * The Ogre main window.
- */
- Ogre::RenderWindow* _render_window = nullptr; // Not owned
- /**
- * List of Ogre resource managers.
- */
- ResourceManagerVector _resource_managers;
- /**
- * Ogre resource group manager.
- */
- Ogre::ResourceGroupManager* res_mgr_ = nullptr; // Not owned
- };
- }
|