Skip to content

Commit

Permalink
BLADERUNNER: Allow Esc and Return keys to fire repeatedly (emulated)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
antoniou79 committed Sep 1, 2020
1 parent 1425c39 commit 6dfcb3e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions engines/bladerunner/bladerunner.cpp
Expand Up @@ -1284,6 +1284,7 @@ void BladeRunnerEngine::handleEvents() {
return;
}

uint32 timeNow = _time->currentSystem();
Common::Event event;
Common::EventManager *eventMan = _system->getEventManager();
while (eventMan->pollEvent(event)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions engines/bladerunner/bladerunner.h
Expand Up @@ -30,6 +30,7 @@
#include "common/random.h"
#include "common/sinetables.h"
#include "common/stream.h"
#include "common/keyboard.h"

#include "engines/engine.h"

Expand Down Expand Up @@ -253,6 +254,17 @@ class BladeRunnerEngine : public Engine {

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];

Expand Down

0 comments on commit 6dfcb3e

Please sign in to comment.