summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-23 00:34:49 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-23 00:34:49 +0200
commit0c3dbabb920f2957ca8c36194ebdeec9f80fefe7 (patch)
treeae8a3f7bd83fd3ddda403c5bdb8e17b9d13aefeb
parent3a32a49febe77b2573a7ae378a59b147b9c9c4d2 (diff)
downloadrpgedit-0c3dbabb920f2957ca8c36194ebdeec9f80fefe7.tar
rpgedit-0c3dbabb920f2957ca8c36194ebdeec9f80fefe7.zip
Improve input responsibility
-rw-r--r--src/rpgedit.cpp17
1 files changed, 10 insertions, 7 deletions
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<float, float> pos = map->getPlayerEntity().getPosition();
mapView->render(pos.first, pos.second);
+
+ lastFrameTicks = ticks;
}
}