[Scummvm-git-logs] scummvm master -> 6dfcb3e558a3a9610b135b0152a76508c4d24e7f

antoniou79 a.antoniou79 at gmail.com
Tue Sep 1 17:13:59 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
6dfcb3e558 BLADERUNNER: Allow Esc and Return keys to fire repeatedly (emulated)


Commit: 6dfcb3e558a3a9610b135b0152a76508c4d24e7f
    https://github.com/scummvm/scummvm/commit/6dfcb3e558a3a9610b135b0152a76508c4d24e7f
Author: antoniou79 (a.antoniou79 at gmail.com)
Date: 2020-09-01T20:13:44+03:00

Commit Message:
BLADERUNNER: Allow Esc and Return keys to fire repeatedly (emulated)

Should resolve ticket #11407

https://bugs.scummvm.org/ticket/11407
However, in our commons/events.h currently there are TODO notes about implementing support for repeated firing of keyboard keys so this could be revisited in the future to use that functionality when implemented

Changed paths:
    engines/bladerunner/bladerunner.cpp
    engines/bladerunner/bladerunner.h


diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp
index eaa2d44c2f..1b127655fb 100644
--- a/engines/bladerunner/bladerunner.cpp
+++ b/engines/bladerunner/bladerunner.cpp
@@ -1284,6 +1284,7 @@ void BladeRunnerEngine::handleEvents() {
 		return;
 	}
 
+	uint32 timeNow = _time->currentSystem();
 	Common::Event event;
 	Common::EventManager *eventMan = _system->getEventManager();
 	while (eventMan->pollEvent(event)) {
@@ -1295,6 +1296,12 @@ void BladeRunnerEngine::handleEvents() {
 		case Common::EVENT_KEYDOWN:
 			// Process the actual key press only and filter out repeats
 			if (!event.kbdRepeat) {
+				// Only for Esc and Return keys, allow repeated firing emulation
+				// First hit (fire) has a bigger delay (kKeyRepeatInitialDelay) before repeated events are fired from the same key
+				if (event.kbd.keycode == Common::KEYCODE_ESCAPE || event.kbd.keycode == Common::KEYCODE_RETURN) {
+					_currentKeyDown = event.kbd.keycode;
+					_keyRepeatTime = timeNow + kKeyRepeatInitialDelay;
+				}
 				handleKeyDown(event);
 			}
 			break;
@@ -1331,9 +1338,24 @@ void BladeRunnerEngine::handleEvents() {
 			; // nothing to do
 		}
 	}
+
+	if ((_currentKeyDown == Common::KEYCODE_ESCAPE || _currentKeyDown == Common::KEYCODE_RETURN) && _keyRepeatTime <= timeNow) {
+		// create a "new" keydown event
+		event.type = Common::EVENT_KEYDOWN;
+		// kbdRepeat field will be unused here since we emulate the kbd repeat behavior anyway, but it's good to set it for consistency
+		event.kbdRepeat = true;
+		event.kbd = _currentKeyDown;
+		_keyRepeatTime = timeNow + kKeyRepeatSustainDelay;
+		handleKeyDown(event);
+	}
 }
 
 void BladeRunnerEngine::handleKeyUp(Common::Event &event) {
+	if (event.kbd.keycode == _currentKeyDown.keycode) {
+		// Only stop firing events if it's the current key
+		_currentKeyDown.keycode = Common::KEYCODE_INVALID;
+	}
+
 	if (!playerHasControl() || _isWalkingInterruptible) {
 		return;
 	}
diff --git a/engines/bladerunner/bladerunner.h b/engines/bladerunner/bladerunner.h
index 8631d4e920..0fb54d5fb3 100644
--- a/engines/bladerunner/bladerunner.h
+++ b/engines/bladerunner/bladerunner.h
@@ -30,6 +30,7 @@
 #include "common/random.h"
 #include "common/sinetables.h"
 #include "common/stream.h"
+#include "common/keyboard.h"
 
 #include "engines/engine.h"
 
@@ -253,6 +254,17 @@ public:
 
 	uint32 _timeOfMainGameLoopTickPrevious;
 
+	// This addon is to emulate keeping a keyboard key pressed (continuous / repeated firing of the event)
+	// -- code is pretty much identical from our common\events.cpp (KeyboardRepeatEventSourceWrapper)
+	// for continuous events (keyDown)
+	enum {
+		kKeyRepeatInitialDelay = 400,
+		kKeyRepeatSustainDelay = 100
+	};
+
+	Common::KeyState _currentKeyDown;
+	uint32 _keyRepeatTime;
+
 private:
 	MIXArchive _archives[kArchiveCount];
 




More information about the Scummvm-git-logs mailing list