Main.cpp 4.8 KB

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