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:
parent
bc0d194dce
commit
a7822331f8
13
src/main.c
13
src/main.c
|
@ -396,6 +396,7 @@ handle_events(void)
|
||||||
{
|
{
|
||||||
static SDL_Event event;
|
static SDL_Event event;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
|
int handleCount = 0;
|
||||||
|
|
||||||
while (SDL_PollEvent(&event) != 0) {
|
while (SDL_PollEvent(&event) != 0) {
|
||||||
if (event.type == SDL_QUIT) {
|
if (event.type == SDL_QUIT) {
|
||||||
|
@ -407,7 +408,7 @@ handle_events(void)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (gGameState == PLAYING) {
|
if (gGameState == PLAYING) {
|
||||||
if (currentTurn == PLAYER)
|
if (currentTurn == PLAYER && !player_turn_over(gPlayer))
|
||||||
gPlayer->handle_event(gPlayer,
|
gPlayer->handle_event(gPlayer,
|
||||||
gRoomMatrix,
|
gRoomMatrix,
|
||||||
&event);
|
&event);
|
||||||
|
@ -421,6 +422,14 @@ handle_events(void)
|
||||||
menu_handle_event(inGameMenu, &event);
|
menu_handle_event(inGameMenu, &event);
|
||||||
}
|
}
|
||||||
pointer_handle_event(gPointer, &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;
|
return quit;
|
||||||
|
@ -492,7 +501,7 @@ run_game(void)
|
||||||
|
|
||||||
roommatrix_update_with_player(gRoomMatrix, gPlayer);
|
roommatrix_update_with_player(gRoomMatrix, gPlayer);
|
||||||
if (currentTurn == PLAYER) {
|
if (currentTurn == PLAYER) {
|
||||||
if (gPlayer->stat_data.steps >= gPlayer->stats.speed) {
|
if (player_turn_over(gPlayer)) {
|
||||||
currentTurn = MONSTER;
|
currentTurn = MONSTER;
|
||||||
player_reset_steps(gPlayer);
|
player_reset_steps(gPlayer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -533,3 +533,9 @@ player_destroy(Player *player)
|
||||||
|
|
||||||
free(player);
|
free(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
player_turn_over(Player *player)
|
||||||
|
{
|
||||||
|
return player->stat_data.steps >= player->stats.speed;
|
||||||
|
}
|
||||||
|
|
|
@ -93,4 +93,7 @@ player_render(Player*, Camera*);
|
||||||
void
|
void
|
||||||
player_destroy(Player*);
|
player_destroy(Player*);
|
||||||
|
|
||||||
|
bool
|
||||||
|
player_turn_over(Player*);
|
||||||
|
|
||||||
#endif // PLAYER_H_
|
#endif // PLAYER_H_
|
||||||
|
|
Loading…
Reference in New Issue