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;
|
bool running = true;
|
||||||
uint32_t ticks = SDL_GetTicks();
|
uint32_t ticks = SDL_GetTicks();
|
||||||
|
uint32_t lastFrameTicks = ticks;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
SDL_Event event;
|
int timeout = lastFrameTicks + MIN_FRAME_DELAY - SDL_GetTicks();
|
||||||
while (running) {
|
|
||||||
int timeout = ticks + MIN_FRAME_DELAY - SDL_GetTicks();
|
|
||||||
if (timeout < 0)
|
if (timeout < 0)
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
|
|
||||||
if (!SDL_WaitEventTimeout(&event, timeout))
|
SDL_Event event;
|
||||||
break;
|
if (SDL_WaitEventTimeout(&event, timeout)) {
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
inputHandler.keyPressed(event.key.keysym.scancode);
|
inputHandler.keyPressed(event.key.keysym.scancode);
|
||||||
|
@ -90,8 +88,13 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
|
||||||
|
|
||||||
ticks = newTicks;
|
ticks = newTicks;
|
||||||
|
|
||||||
|
if (!SDL_TICKS_PASSED(SDL_GetTicks(), lastFrameTicks + MIN_FRAME_DELAY))
|
||||||
|
continue;
|
||||||
|
|
||||||
std::pair<float, float> pos = map->getPlayerEntity().getPosition();
|
std::pair<float, float> pos = map->getPlayerEntity().getPosition();
|
||||||
mapView->render(pos.first, pos.second);
|
mapView->render(pos.first, pos.second);
|
||||||
|
|
||||||
|
lastFrameTicks = ticks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue