From: Holger Schemel Date: Wed, 12 Sep 2018 17:59:18 +0000 (+0200) Subject: improved clearing event queue after fading and after door/envelope requests X-Git-Tag: 4.1.1.0~38 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=ad93f89279233a6adfa0dc0ebe3570c4c614cedb;p=rocksndiamonds.git improved clearing event queue after fading and after door/envelope requests This is an improvement of commit ba20bcc8, which totally cleared the event queue after fading and after door/envelope requests, and which prevented entering multiple key presses by intention (like starting the game and immediately going to pause mode with the very first game frame, by quickly pressing "space" twice in the main menu). This change only removes key presses entered by keyboard auto-repeat during fading or door/envelope animations, effectively preventing accidentally entered multiple key events by pressing a key like "space" or "return" a bit too long (which then triggers auto-repeat), while it keeps multiple key events that were manually entered. --- diff --git a/src/-transparent b/src/-transparent new file mode 100644 index 00000000..14a435cd Binary files /dev/null and b/src/-transparent differ diff --git a/src/events.c b/src/events.c index 8e368b61..b610ff8b 100644 --- a/src/events.c +++ b/src/events.c @@ -347,6 +347,23 @@ void EventLoop(void) } } +void ClearAutoRepeatKeyEvents() +{ + while (PendingEvent()) + { + Event next_event; + + PeekEvent(&next_event); + + /* if event is repeated key press event, remove it from event queue */ + if (next_event.type == EVENT_KEYPRESS && + next_event.key.repeat) + WaitEvent(&next_event); + else + break; + } +} + void ClearEventQueue() { Event event; diff --git a/src/events.h b/src/events.h index 9672029f..2a4228c7 100644 --- a/src/events.h +++ b/src/events.h @@ -18,6 +18,7 @@ boolean NextValidEvent(Event *); void EventLoop(void); void HandleOtherEvents(Event *); +void ClearAutoRepeatKeyEvents(void); void ClearEventQueue(void); void ClearPlayerAction(void); void SleepWhileUnmapped(void); diff --git a/src/tools.c b/src/tools.c index a11f692e..4bd3b8d9 100644 --- a/src/tools.c +++ b/src/tools.c @@ -982,7 +982,7 @@ static void FadeExt(int fade_mask, int fade_mode, int fade_type) redraw_mask &= ~fade_mask; - ClearEventQueue(); + ClearAutoRepeatKeyEvents(); } static void SetScreenStates_BeforeFadingIn() @@ -2803,7 +2803,7 @@ void AnimateEnvelope(int envelope_nr, int anim_mode, int action) SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame); } - ClearEventQueue(); + ClearAutoRepeatKeyEvents(); } void ShowEnvelope(int envelope_nr) @@ -3088,7 +3088,7 @@ void AnimateEnvelopeRequest(int anim_mode, int action) SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame); } - ClearEventQueue(); + ClearAutoRepeatKeyEvents(); } void ShowEnvelopeRequest(char *text, unsigned int req_state, int action) @@ -5429,7 +5429,7 @@ unsigned int MoveDoor(unsigned int door_state) DrawMaskedBorder(REDRAW_DOOR_1); DrawMaskedBorder(REDRAW_DOOR_2); - ClearEventQueue(); + ClearAutoRepeatKeyEvents(); return (door1 | door2); }