improved clearing event queue after fading and after door/envelope requests
authorHolger Schemel <info@artsoft.org>
Wed, 12 Sep 2018 17:59:18 +0000 (19:59 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 12 Sep 2018 18:24:23 +0000 (20:24 +0200)
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.

src/-transparent [new file with mode: 0644]
src/events.c
src/events.h
src/tools.c

diff --git a/src/-transparent b/src/-transparent
new file mode 100644 (file)
index 0000000..14a435c
Binary files /dev/null and b/src/-transparent differ
index 8e368b6..b610ff8 100644 (file)
@@ -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;
index 9672029..2a4228c 100644 (file)
@@ -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);
index a11f692..4bd3b8d 100644 (file)
@@ -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);
 }