X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FMoof%2FEngine.cc;h=27406521da79693040a6e8b7bdc9e34dd141528e;hb=8ad81a8282ce6e9e488a453e6bcd05fbc09715dc;hp=53fca73e9e883cfab1d18aced70cd125391f26d1;hpb=72d4af22710317acffab861421c4364b1780b6fe;p=chaz%2Fyoink diff --git a/src/Moof/Engine.cc b/src/Moof/Engine.cc index 53fca73..2740652 100644 --- a/src/Moof/Engine.cc +++ b/src/Moof/Engine.cc @@ -32,8 +32,9 @@ #include #include "fastevents.h" +#include +#include -#include "Dispatcher.hh" #include "Engine.hh" #include "Random.hh" #include "Settings.hh" @@ -44,35 +45,43 @@ namespace Mf { -class Engine::EngineImpl +class Engine::Impl { public: - EngineImpl(int argc, char* argv[], const std::string& configFile, + Impl(int argc, char* argv[], const std::string& configFile, const std::string& name, const std::string& iconFile, Engine* outer) : - interface(outer), - settings(argc, argv) + interface(outer) { +#if defined(_WIN32) || defined (_WIN64) || defined(__WIN32__) + if (SDL_Init(SDL_INIT_EVERYTHING) != 0) +#else if (SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_EVENTTHREAD) != 0) +#endif { - throw Exception(SDL_GetError()); + std::cerr << "sdl is complaining: " << SDL_GetError() << std::endl; + throw Exception(Exception::SDL_ERROR); } if (FE_Init() != 0) { - throw Exception(FE_GetError()); + std::cerr << "fast events error: " << FE_GetError() << std::endl; + throw Exception(Exception::SDL_ERROR); } + if (Sound_Init() == 0) + { + std::cerr << "sound initialization failed: " << Sound_GetError() + << std::endl; + throw Exception(Exception::SDL_ERROR); + } + alutInit(&argc, argv); + Settings& settings = Settings::getInstance(); + settings.parseArgs(argc, argv); settings.loadFromFile(configFile); long randomSeed; - if (settings.get("engine.rngseed", randomSeed)) - { - setSeed(randomSeed); - } - else - { - setSeed(); - } + if (settings.get("engine.rngseed", randomSeed)) setSeed(randomSeed); + else setSeed(); double ts = 0.01; settings.get("engine.timestep", ts); @@ -85,15 +94,17 @@ public: printFps = false; settings.get("video.printfps", printFps); - video = VideoPtr(new Video(name, iconFile)); + video = Video::alloc(name, iconFile); video->makeActive(); } - ~EngineImpl() + ~Impl() { // the video object must be destroyed before we can shutdown SDL video.reset(); + alutExit(); + Sound_Quit(); FE_Quit(); SDL_Quit(); } @@ -215,9 +226,7 @@ public: Engine* interface; - Settings settings; - Dispatcher dispatcher; - VideoPtr video; + VideoP video; bool running; int exitCode; @@ -232,8 +241,7 @@ public: Engine::Engine(int argc, char* argv[], const std::string& configFile, const std::string& name, const std::string& iconFile) : - impl_(new Engine::EngineImpl(argc, argv, configFile, name, iconFile, this)) -{} + impl_(new Engine::Impl(argc, argv, configFile, name, iconFile, this)) {} Engine::~Engine() {}