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 8e368b613686a1331f71d396dd47c0daaef87e62..b610ff8b7a05b211daf6393031e0694df00e0a7d 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 9672029fdd4bfc1253edb8812f788ea186807fe6..2a4228c7bfd744224ebdbab403d21dc7296e30a7 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 a11f692eb2d66a2abd495ceab77017d10b0de2ca..4bd3b8d9196f83518af4bf5d4797a8c1b54c741d 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);
 }