Hopefully handle the "event overflow exploit"

There was an exploit where a keyboard would fire events quicker then
they could be consumed. This would lock the main game loop in the
SDL_PollEvent loop and block rendering until the key in this case was
released. Combning this with an attack meant that you could "farm" one
NPC for multiple kills and massive XP gains. Leaving the player at level
8+ on dungeon level 1. This fix should mitigate such shenanigans.
This commit is contained in:
Linus Probert 2018-05-16 19:09:01 +02:00
parent bc0d194dce
commit a7822331f8
3 changed files with 20 additions and 2 deletions

View File

@ -396,6 +396,7 @@ handle_events(void)
{
static SDL_Event event;
bool quit = false;
int handleCount = 0;
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
@ -407,7 +408,7 @@ handle_events(void)
continue;
if (gGameState == PLAYING) {
if (currentTurn == PLAYER)
if (currentTurn == PLAYER && !player_turn_over(gPlayer))
gPlayer->handle_event(gPlayer,
gRoomMatrix,
&event);
@ -421,6 +422,14 @@ handle_events(void)
menu_handle_event(inGameMenu, &event);
}
pointer_handle_event(gPointer, &event);
handleCount++;
if (handleCount >= 5) {
debug("Flushing event queue");
SDL_PumpEvents();
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
break;
}
}
return quit;
@ -492,7 +501,7 @@ run_game(void)
roommatrix_update_with_player(gRoomMatrix, gPlayer);
if (currentTurn == PLAYER) {
if (gPlayer->stat_data.steps >= gPlayer->stats.speed) {
if (player_turn_over(gPlayer)) {
currentTurn = MONSTER;
player_reset_steps(gPlayer);
}

View File

@ -533,3 +533,9 @@ player_destroy(Player *player)
free(player);
}
bool
player_turn_over(Player *player)
{
return player->stat_data.steps >= player->stats.speed;
}

View File

@ -93,4 +93,7 @@ player_render(Player*, Camera*);
void
player_destroy(Player*);
bool
player_turn_over(Player*);
#endif // PLAYER_H_