[Scummvm-git-logs] scummvm master -> 942aee68d98eab5909dbea8a15bc5bf2e01a2844

antoniou79 noreply at scummvm.org
Tue Feb 15 21:46:30 UTC 2022


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:
942aee68d9 BLADERUNNER: Further optimization for key input


Commit: 942aee68d98eab5909dbea8a15bc5bf2e01a2844
    https://github.com/scummvm/scummvm/commit/942aee68d98eab5909dbea8a15bc5bf2e01a2844
Author: antoniou79 (a.antoniou79 at gmail.com)
Date: 2022-02-15T23:44:28+02:00

Commit Message:
BLADERUNNER: Further optimization for key input

Support for repeated input for symbols and extended ASCII keys

Also keypad return works now just like the Enter key, and SHIFT+key when spammed results in the correct key being repeated.

Changed paths:
    engines/bladerunner/bladerunner.cpp
    engines/bladerunner/ui/kia_section_save.cpp
    engines/bladerunner/ui/ui_input_box.cpp
    engines/bladerunner/ui/ui_input_box.h


diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp
index 180ef3fbd52..65b76f7f1bc 100644
--- a/engines/bladerunner/bladerunner.cpp
+++ b/engines/bladerunner/bladerunner.cpp
@@ -1266,18 +1266,22 @@ void BladeRunnerEngine::walkingReset() {
 // namely, Esc, Return and Space during normal gameplay.
 // "Space" spamming results in McCoy quickly switching between combat mode and normal mode, 
 // which is not very useful but it's the original's behavior.
-// Spamming Space, backspace, latin letter keys and a few symbols is allowed
+// Spamming Space, backspace, latin letter keys and symbols is allowed
 // in KIA mode, particularly in the Save Panel when writing the name for a save game.
+// For simplicity, we allow everything after the 0x20 (space ascii code) up to 0xFF.
+// The UIInputBox::charIsValid() will filter out any unsupported characters.
 // F-keys are not repeated.
 bool BladeRunnerEngine::isAllowedRepeatedKey(const Common::KeyState &currKeyState) {
 	return  currKeyState.keycode == Common::KEYCODE_ESCAPE
 	    ||  currKeyState.keycode == Common::KEYCODE_RETURN
+	    ||  currKeyState.keycode == Common::KEYCODE_KP_ENTER
 	    ||  currKeyState.keycode == Common::KEYCODE_BACKSPACE
 	    ||  currKeyState.keycode == Common::KEYCODE_SPACE
+	    ||  currKeyState.keycode == Common::KEYCODE_KP_MINUS
+	    ||  currKeyState.keycode == Common::KEYCODE_KP_PLUS
+	    ||  currKeyState.keycode == Common::KEYCODE_KP_EQUALS
 	    || (currKeyState.keycode != Common::KEYCODE_INVALID
-	        && (   (currKeyState.ascii >= 'a' && currKeyState.ascii <= 'z')
-	            || (currKeyState.ascii >= 'A' && currKeyState.ascii <= 'Z')
-	            || (currKeyState.ascii >= '0' && currKeyState.ascii <= '9')));
+	        && (currKeyState.ascii > 0x20 && currKeyState.ascii <= 0xFF));
 }
 
 void BladeRunnerEngine::handleEvents() {
@@ -1311,8 +1315,8 @@ void BladeRunnerEngine::handleEvents() {
 			if (!event.kbdRepeat) {
 				// Only for some keys, allow repeated firing emulation
 				// First hit (fire) has a bigger delay (kKeyRepeatInitialDelay) before repeated events are fired from the same key
-				if (isAllowedRepeatedKey(event.kbd.keycode)) {
-					_currentKeyDown = event.kbd.keycode;
+				if (isAllowedRepeatedKey(event.kbd)) {
+					_currentKeyDown = event.kbd;
 					_keyRepeatTimeLast =  _time->currentSystem();
 					_keyRepeatTimeDelay = kKeyRepeatInitialDelay;
 				}
@@ -1388,7 +1392,9 @@ void BladeRunnerEngine::handleKeyUp(Common::Event &event) {
 
 void BladeRunnerEngine::handleKeyDown(Common::Event &event) {
 	if (_vqaIsPlaying
-	    && (event.kbd.keycode == Common::KEYCODE_RETURN || event.kbd.keycode == Common::KEYCODE_ESCAPE)) {
+	    && (event.kbd.keycode == Common::KEYCODE_RETURN
+	        || event.kbd.keycode == Common::KEYCODE_KP_ENTER
+	        || event.kbd.keycode == Common::KEYCODE_ESCAPE)) {
 		// Note: Original only uses the Esc key here
 		_vqaStopIsRequested = true;
 		_vqaIsPlaying = false;
@@ -1397,12 +1403,16 @@ void BladeRunnerEngine::handleKeyDown(Common::Event &event) {
 	}
 
 	if (_vqaStopIsRequested
-	    && (event.kbd.keycode == Common::KEYCODE_RETURN || event.kbd.keycode == Common::KEYCODE_ESCAPE)) {
+	    && (event.kbd.keycode == Common::KEYCODE_RETURN
+	        || event.kbd.keycode == Common::KEYCODE_KP_ENTER
+	        || event.kbd.keycode == Common::KEYCODE_ESCAPE)) {
 		 return;
 	}
 
 	if (_actorIsSpeaking
-	    && (event.kbd.keycode == Common::KEYCODE_RETURN || event.kbd.keycode == Common::KEYCODE_ESCAPE)) {
+	    && (event.kbd.keycode == Common::KEYCODE_RETURN
+	        || event.kbd.keycode == Common::KEYCODE_KP_ENTER
+	        || event.kbd.keycode == Common::KEYCODE_ESCAPE)) {
 		// Note: Original only uses the Return key here
 		_actorSpeakStopIsRequested = true;
 		_actorIsSpeaking = false;
@@ -1411,7 +1421,9 @@ void BladeRunnerEngine::handleKeyDown(Common::Event &event) {
 	}
 
 	if (_actorSpeakStopIsRequested
-	    && (event.kbd.keycode == Common::KEYCODE_RETURN || event.kbd.keycode == Common::KEYCODE_ESCAPE)) {
+	    && (event.kbd.keycode == Common::KEYCODE_RETURN
+	        || event.kbd.keycode == Common::KEYCODE_KP_ENTER
+	        || event.kbd.keycode == Common::KEYCODE_ESCAPE)) {
 		 return;
 	}
 
diff --git a/engines/bladerunner/ui/kia_section_save.cpp b/engines/bladerunner/ui/kia_section_save.cpp
index 8cc26cf5b00..79471507060 100644
--- a/engines/bladerunner/ui/kia_section_save.cpp
+++ b/engines/bladerunner/ui/kia_section_save.cpp
@@ -237,12 +237,12 @@ void KIASectionSave::handleKeyDown(const Common::KeyState &kbd) {
 		}
 		_uiContainer->handleKeyDown(kbd);
 	} else if (_state == kStateOverwrite) {
-		if (kbd.keycode == Common::KEYCODE_RETURN) {
+		if (kbd.keycode == Common::KEYCODE_RETURN || kbd.keycode == Common::KEYCODE_KP_ENTER) {
 			save();
 			changeState(kStateNormal);
 		}
 	} else if (_state == kStateDelete) {
-		if (kbd.keycode == Common::KEYCODE_RETURN) {
+		if (kbd.keycode == Common::KEYCODE_RETURN || kbd.keycode == Common::KEYCODE_KP_ENTER) {
 			deleteSave();
 			changeState(kStateNormal);
 		}
diff --git a/engines/bladerunner/ui/ui_input_box.cpp b/engines/bladerunner/ui/ui_input_box.cpp
index 9aca44b1275..3dbf9f5ae3b 100644
--- a/engines/bladerunner/ui/ui_input_box.cpp
+++ b/engines/bladerunner/ui/ui_input_box.cpp
@@ -95,13 +95,14 @@ void UIInputBox::handleKeyDown(const Common::KeyState &kbd) {
 		// The values that the KeyState::ascii field receives from the SDL backend are actually ISO 8859-1 encoded. They need to be
 		// reencoded to DOS so as to match the game font encoding (although we currently use UIInputBox::charIsValid() to block most
 		// extra characters, so it might not make much of a difference).
-		char kc = Common::U32String(Common::String::format("%c", kbd.ascii), Common::kISO8859_1).encode(Common::kDos850).firstChar();
+		uint8 kc = (uint8)(Common::U32String(Common::String::format("%c", kbd.ascii), Common::kISO8859_1).encode(Common::kDos850).firstChar());
 		if (_isVisible) {
 			if (charIsValid(kc) && _text.size() < _maxLength) {
 				_text += kc;
 			} else if (kbd.keycode == Common::KEYCODE_BACKSPACE) {
 				_text.deleteLastChar();
-			} else if (kbd.keycode == Common::KEYCODE_RETURN && !_text.empty()) {
+			} else if ((kbd.keycode == Common::KEYCODE_RETURN || kbd.keycode == Common::KEYCODE_KP_ENTER)
+			           && !_text.empty()) {
 				if (_valueChangedCallback) {
 					_valueChangedCallback(_callbackData, this);
 				}
@@ -110,7 +111,17 @@ void UIInputBox::handleKeyDown(const Common::KeyState &kbd) {
 	}
 }
 
-bool UIInputBox::charIsValid(char kc) {
+bool UIInputBox::charIsValid(uint8 kc) {
+	// The in-game font for text input is KIA6PT which follows IBM PC Code page 437 (CCSID 437)
+	// This code page is identical to Code page 850 for the first 128 codes.
+	// This method is:
+	// 1) filtering out characters not allowed in a DOS filename.
+	//    Note, however, that it does allow ',', '.', ';', '=', '[' and ']'
+	//    TODO Is that a bug?
+	// 2) allowing codes for glyphs that exist in KIA6PT up to code 0xA8 (glyph '¿')
+	//    and also the extra codes for 0xAD (glyph '¡') and 0xE1 (glyph 'ß')
+	//    (in order for these extra extended ASCII codes to be included,
+	//     the comparisons in the return clause should be between uint values).
 	return kc >= ' '
 		&& kc != '<'
 		&& kc != '>'
@@ -121,7 +132,7 @@ bool UIInputBox::charIsValid(char kc) {
 		&& kc != '|'
 		&& kc != '?'
 		&& kc != '*'
-		&& kc <= '~';// || kc == '¡' || kc == 'ß');
+		&& (kc <= (uint8)'\xA8' || kc == (uint8)'\xAD' || kc == (uint8)'\xE1');
 }
 
 } // End of namespace BladeRunner
diff --git a/engines/bladerunner/ui/ui_input_box.h b/engines/bladerunner/ui/ui_input_box.h
index c64e77b6a38..a5ac570ca7c 100644
--- a/engines/bladerunner/ui/ui_input_box.h
+++ b/engines/bladerunner/ui/ui_input_box.h
@@ -57,7 +57,7 @@ public:
 	void handleKeyDown(const Common::KeyState &kbd) override;
 
 private:
-	bool charIsValid(char kc);
+	bool charIsValid(uint8 kc);
 };
 
 } // End of namespace BladeRunner




More information about the Scummvm-git-logs mailing list