From 0c3dbabb920f2957ca8c36194ebdeec9f80fefe7 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 23 Sep 2014 00:34:49 +0200 Subject: Improve input responsibility --- src/rpgedit.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/rpgedit.cpp') diff --git a/src/rpgedit.cpp b/src/rpgedit.cpp index 8dcd472..c507880 100644 --- a/src/rpgedit.cpp +++ b/src/rpgedit.cpp @@ -56,17 +56,15 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *argv[]) bool running = true; uint32_t ticks = SDL_GetTicks(); + uint32_t lastFrameTicks = ticks; while (true) { - SDL_Event event; - while (running) { - int timeout = ticks + MIN_FRAME_DELAY - SDL_GetTicks(); - if (timeout < 0) + int timeout = lastFrameTicks + MIN_FRAME_DELAY - SDL_GetTicks(); + if (timeout < 0) timeout = 0; - if (!SDL_WaitEventTimeout(&event, timeout)) - break; - + SDL_Event event; + if (SDL_WaitEventTimeout(&event, timeout)) { switch (event.type) { case SDL_KEYDOWN: inputHandler.keyPressed(event.key.keysym.scancode); @@ -90,8 +88,13 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *argv[]) ticks = newTicks; + if (!SDL_TICKS_PASSED(SDL_GetTicks(), lastFrameTicks + MIN_FRAME_DELAY)) + continue; + std::pair pos = map->getPlayerEntity().getPosition(); mapView->render(pos.first, pos.second); + + lastFrameTicks = ticks; } } -- cgit v1.2.3