Improve input responsibility
This commit is contained in:
parent
3a32a49feb
commit
0c3dbabb92
1 changed files with 10 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue