X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FEngine.cc;h=e97c8b5d1b7edbae52a5b48ebc1072574e697ebe;hp=27406521da79693040a6e8b7bdc9e34dd141528e;hb=33842c860fe18ca8cf087905992885687434320c;hpb=8ad81a8282ce6e9e488a453e6bcd05fbc09715dc diff --git a/src/Moof/Engine.cc b/src/Moof/Engine.cc index 2740652..e97c8b5 100644 --- a/src/Moof/Engine.cc +++ b/src/Moof/Engine.cc @@ -27,15 +27,15 @@ *******************************************************************************/ #include // exit -#include #include #include #include "fastevents.h" -#include #include +#include "Dispatcher.hh" #include "Engine.hh" +#include "Log.hh" #include "Random.hh" #include "Settings.hh" #include "Timer.hh" @@ -54,23 +54,17 @@ public: interface(outer) { #if defined(_WIN32) || defined (_WIN64) || defined(__WIN32__) - if (SDL_Init(SDL_INIT_EVERYTHING) != 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) #else - if (SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_EVENTTHREAD) != 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) != 0) #endif { - std::cerr << "sdl is complaining: " << SDL_GetError() << std::endl; + logError("sdl is complaining: %s", SDL_GetError()); throw Exception(Exception::SDL_ERROR); } if (FE_Init() != 0) { - 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; + logError("fast events error: %s", FE_GetError()); throw Exception(Exception::SDL_ERROR); } alutInit(&argc, argv); @@ -104,7 +98,6 @@ public: video.reset(); alutExit(); - Sound_Quit(); FE_Quit(); SDL_Quit(); } @@ -119,7 +112,7 @@ public: int run() { - Scalar ticksNow = getTicks(); + Scalar ticksNow = Timer::getTicks(); Scalar nextStep = ticksNow; Scalar nextDraw = ticksNow; @@ -135,13 +128,15 @@ public: running = true; do { - Scalar newTicks = getTicks(); + Scalar newTicks = Timer::getTicks(); deltaTime = newTicks - ticksNow; ticksNow = newTicks; if (deltaTime >= 0.25) deltaTime = 0.25; accumulator += deltaTime; + Timer::fireIfExpired(ticksNow); + while (accumulator >= timestep) { dispatchEvents(); @@ -174,7 +169,7 @@ public: if (printFps) { - std::cout << "FPS: " << fps << std::endl; + logInfo("framerate: %d fps", fps); } } @@ -190,7 +185,8 @@ public: } // be a good citizen and give back what you don't need - sleep(std::min(nextStep, nextDraw), true); + Timer::sleep(std::min(std::min(nextStep, nextDraw), + Timer::getNextFire()), true); } while (running);