Main.cpp 4.3 KB

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