Main.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include <OgreRoot.h>
  2. #include <OgreConfigFile.h>
  3. #include <OgreArchiveManager.h>
  4. #include <OIS.h>
  5. #include "QGearsGameState.h"
  6. #ifdef QGears_SOUND
  7. #include "core/AudioManager.h"
  8. #endif
  9. #include "common/QGearsApplication.h"
  10. #include "core/CameraManager.h"
  11. #include "core/ConfigCmdManager.h"
  12. #include "core/ConfigFile.h"
  13. #include "core/ConfigVarManager.h"
  14. #include "core/Console.h"
  15. #include "core/DebugDraw.h"
  16. #include "core/EntityManager.h"
  17. #include "core/GameFrameListner.h"
  18. #include "core/InputManager.h"
  19. #include "core/Logger.h"
  20. #include "core/ScriptManager.h"
  21. #include "core/Timer.h"
  22. #include "core/UiManager.h"
  23. #include "core/particles/ParticleSystemManager.h"
  24. #include "core/TextManager.h"
  25. #include "core/DialogsManager.h"
  26. #include "data/QGearsLZSFLevelFileManager.h"
  27. #include "common/make_unique.h"
  28. #include <OgreFontManager.h>
  29. #include <OgreOverlayManager.h>
  30. #include <OgreOverlaySystem.h>
  31. #include "modules/worldmap/WorldMapModule.h"
  32. #include "data/worldmap/MapFileManager.h"
  33. #include "data/QGearsLGPArchiveFactory.h"
  34. int
  35. main(int argc, char *argv[])
  36. {
  37. try
  38. {
  39. QGears::Application app(argc, argv);
  40. if (!app.initOgre()) return 0;
  41. Ogre::Root *root(app.getRoot());
  42. Ogre::RenderWindow *window(app.getRenderWindow());
  43. Ogre::SceneManager *scene_manager(nullptr);
  44. auto timer = std::make_unique<Timer>();
  45. auto particle_system_manager = std::make_unique<ParticleSystemManager>();
  46. // set scene camera and viewport for other moduls
  47. // create this before initialize particle because some of them use scene to create themself
  48. scene_manager = root->createSceneManager(Ogre::ST_GENERIC, "Scene");
  49. scene_manager->setAmbientLight(Ogre::ColourValue(1, 1, 1));
  50. scene_manager->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
  51. Ogre::Light *directionalLight(scene_manager->createLight("directionalLight"));
  52. directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
  53. directionalLight->setDiffuseColour(Ogre::ColourValue(0.5, 0.5, 0.5));
  54. directionalLight->setSpecularColour(Ogre::ColourValue(0.0, 0.0, 0.0));
  55. directionalLight->setDirection(Ogre::Vector3(0, 1, 0));
  56. // auto fontManager = std::make_unique<Ogre::FontManager>();
  57. QGears::MapFileManager* worldManager = new QGears::MapFileManager();
  58. Ogre::Root::getSingleton().addResourceLocation(".", "FileSystem");
  59. Ogre::Root::getSingleton().addResourceLocation("./data/wm", "FileSystem", "TEST");
  60. Ogre::Root::getSingleton().addResourceLocation("./data/wm/world_us.lgp", QGears::LGPArchiveFactory::ARCHIVE_TYPE, "TEST");
  61. Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  62. // init it before console because it may use it
  63. auto config_var_manager = std::make_unique<ConfigVarManager>();
  64. auto config_cmd_manager = std::make_unique<ConfigCmdManager>();
  65. auto debug_draw = std::make_unique<DebugDraw>();
  66. // init before GameFrameListener, but after ConfigCmdManager
  67. auto input_manager = std::make_unique<InputManager>();
  68. #ifdef QGears_SOUND
  69. //auto audio_manager = std::make_unique<AudioManager>();
  70. //audio_manager->MusicPlay( "loop1" );
  71. #endif
  72. // create This earlier than DisplayFrameListener cause it can fire event there
  73. auto camera_manager = std::make_unique<CameraManager>();
  74. auto text_manager = std::make_unique<TextManager>();
  75. auto ui_manager = std::make_unique<UiManager>();
  76. auto dialogs_manager = std::make_unique<DialogsManager>();
  77. auto entity_manager = std::make_unique<EntityManager>();
  78. auto console = std::make_unique<Console>();
  79. auto worldMapModule = std::make_unique<QGears::WorldMapModule>();
  80. // init after game managers because it attach them to script
  81. auto script_manager = std::make_unique<ScriptManager>();
  82. // set base listner for usual game moduls
  83. auto frame_listener = std::make_unique<GameFrameListener>(window);
  84. root->addFrameListener(frame_listener.get());
  85. // execute config
  86. {
  87. ConfigFile config;
  88. config.Execute("./data/config.cfg");
  89. }
  90. // init ui and run it scripts
  91. ui_manager->Initialise();
  92. dialogs_manager->Initialise();
  93. // run application cycle
  94. QGears::g_ApplicationState = QGears::G_GAME;
  95. root->startRendering();
  96. // system moduls
  97. // we must remove this first cause this can fire event to console
  98. root->removeFrameListener(frame_listener.get());
  99. // Must destruct before the script manager
  100. entity_manager.reset();
  101. ui_manager.reset();
  102. script_manager.reset();
  103. }
  104. catch (const std::runtime_error& ex)
  105. {
  106. std::cout << "std::runtime_error thrown: " << ex.what() << std::endl;
  107. }
  108. catch (const Ogre::Exception& ex)
  109. {
  110. std::cout << "Ogre::Exception thrown: " << ex.what() << std::endl;
  111. }
  112. return 0;
  113. }