[Scummvm-cvs-logs] scummvm master -> bd64c5078c3d07bb9cf80ef8e72f151bec8beec4

bluegr md5 at scummvm.org
Tue Feb 15 14:54:16 CET 2011


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:
bd64c5078c SCI: Cleaned up kMapKeyToDir and removed an incorrect heuristic


Commit: bd64c5078c3d07bb9cf80ef8e72f151bec8beec4
    https://github.com/scummvm/scummvm/commit/bd64c5078c3d07bb9cf80ef8e72f151bec8beec4
Author: md5 (md5 at scummvm.org)
Date: 2011-02-15T05:46:15-08:00

Commit Message:
SCI: Cleaned up kMapKeyToDir and removed an incorrect heuristic

The heuristic in question was used to detect the pseudo mouse control
functionality, however the change in controls seems to have occurred with the
transition to cursor views. Fixes keypad control in Conquest of the Longbow.
Moreover, the code also checked for key scan code 76 when checking for the middle
keypad button, which seems to be a mistake, as that case never occurred.

Changed paths:
    engines/sci/engine/kevent.cpp
    engines/sci/event.cpp
    engines/sci/event.h



diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index 58de38b..e5a9931 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -38,8 +38,6 @@
 
 namespace Sci {
 
-#define SCI_VARIABLE_GAME_SPEED 3
-
 reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) {
 	int mask = argv[0].toUint16();
 	reg_t obj = argv[1];
@@ -188,57 +186,42 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) {
 	return s->r_acc;
 }
 
+struct KeyDirMapping {
+	uint16 key;
+	uint16 direction;
+};
+
+const KeyDirMapping keyToDirMap[] = {
+	{ SCI_KEY_HOME,   8 }, { SCI_KEY_UP,     1 }, { SCI_KEY_PGUP,   2 },
+	{ SCI_KEY_LEFT,   7 }, { SCI_KEY_CENTER, 0 }, { SCI_KEY_RIGHT,  3 },
+	{ SCI_KEY_END,    6 }, { SCI_KEY_DOWN,   5 }, { SCI_KEY_PGDOWN, 4 },
+};
+
 reg_t kMapKeyToDir(EngineState *s, int argc, reg_t *argv) {
 	reg_t obj = argv[0];
 	SegManager *segMan = s->_segMan;
 
 	if (readSelectorValue(segMan, obj, SELECTOR(type)) == SCI_EVENT_KEYBOARD) { // Keyboard
-		int mover = -1;
-		switch (readSelectorValue(segMan, obj, SELECTOR(message))) {
-		case SCI_KEY_HOME:
-			mover = 8;
-			break;
-		case SCI_KEY_UP:
-			mover = 1;
-			break;
-		case SCI_KEY_PGUP:
-			mover = 2;
-			break;
-		case SCI_KEY_LEFT:
-			mover = 7;
-			break;
-		case SCI_KEY_CENTER:
-		case 76:
-			mover = 0;
-			break;
-		case SCI_KEY_RIGHT:
-			mover = 3;
-			break;
-		case SCI_KEY_END:
-			mover = 6;
-			break;
-		case SCI_KEY_DOWN:
-			mover = 5;
-			break;
-		case SCI_KEY_PGDOWN:
-			mover = 4;
-			break;
-		default:
-			break;
+		uint16 message = readSelectorValue(segMan, obj, SELECTOR(message));
+		uint16 eventType = SCI_EVENT_DIRECTION;
+		// Check if the game is using cursor views. These games allowed control
+		// of the mouse cursor via the keyboard controls (the so called
+		// "PseudoMouse" functionality in script 933).
+		if (g_sci->_features->detectSetCursorType() == SCI_VERSION_1_1)
+			eventType |= SCI_EVENT_KEYBOARD;
+
+		for (int i = 0; i < 9; i++) {
+			if (keyToDirMap[i].key == message) {
+				writeSelectorValue(segMan, obj, SELECTOR(type), eventType);
+				writeSelectorValue(segMan, obj, SELECTOR(message), keyToDirMap[i].direction);
+				return TRUE_REG;	// direction mapped
+			}
 		}
 
-		if (mover >= 0) {
-			if (g_sci->getEventManager()->getUsesNewKeyboardDirectionType())
-				writeSelectorValue(segMan, obj, SELECTOR(type), SCI_EVENT_KEYBOARD | SCI_EVENT_DIRECTION);
-			else
-				writeSelectorValue(segMan, obj, SELECTOR(type), SCI_EVENT_DIRECTION);
-			writeSelectorValue(segMan, obj, SELECTOR(message), mover);
-			return make_reg(0, 1);
-		} else
-			return NULL_REG;
+		return NULL_REG;	// unknown direction
 	}
 
-	return s->r_acc;
+	return s->r_acc;	// no keyboard event to map, leave accumulator unchanged
 }
 
 reg_t kGlobalToLocal(EngineState *s, int argc, reg_t *argv) {
diff --git a/engines/sci/event.cpp b/engines/sci/event.cpp
index 0c17db6..d607a53 100644
--- a/engines/sci/event.cpp
+++ b/engines/sci/event.cpp
@@ -36,31 +36,11 @@
 namespace Sci {
 
 EventManager::EventManager(bool fontIsExtended) : _fontIsExtended(fontIsExtended), _modifierStates(0) {
-
-	if (getSciVersion() >= SCI_VERSION_1_MIDDLE) {
-		_usesNewKeyboardDirectionType = true;
-	} else if (getSciVersion() <= SCI_VERSION_01) {
-		_usesNewKeyboardDirectionType = false;
-	} else {
-		// they changed this somewhere inbetween SCI1EGA/EARLY
-		_usesNewKeyboardDirectionType = false;
-
-		// We are looking if script 933 exists, that one has the PseudoMouse class in it that handles it
-		//  The good thing is that PseudoMouse seems to only exists in games that use the new method
-		if (g_sci->getResMan()->testResource(ResourceId(kResourceTypeScript, 933)))
-			_usesNewKeyboardDirectionType = true;
-		// Checking the keyboard driver size in here would also be a valid method, but the driver is only available
-		//  in PC versions of the game
-	}
 }
 
 EventManager::~EventManager() {
 }
 
-bool EventManager::getUsesNewKeyboardDirectionType() {
-	return _usesNewKeyboardDirectionType;
-}
-
 struct ScancodeRow {
 	int offset;
 	const char *keys;
diff --git a/engines/sci/event.h b/engines/sci/event.h
index fade7dd..7c83476 100644
--- a/engines/sci/event.h
+++ b/engines/sci/event.h
@@ -116,7 +116,6 @@ public:
 
 	void updateScreen();
 	SciEvent getSciEvent(unsigned int mask);
-	bool getUsesNewKeyboardDirectionType();
 
 private:
 	SciEvent getScummVMEvent();
@@ -124,8 +123,6 @@ private:
 	const bool _fontIsExtended;
 	int _modifierStates;
 	Common::List<SciEvent> _events;
-
-	bool _usesNewKeyboardDirectionType;
 };
 
 } // End of namespace Sci






More information about the Scummvm-git-logs mailing list