[Scummvm-cvs-logs] SF.net SVN: scummvm:[43430] scummvm/branches/gsoc2009-16bit/backends

upthorn at users.sourceforge.net upthorn at users.sourceforge.net
Sun Aug 16 09:40:13 CEST 2009


Revision: 43430
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43430&view=rev
Author:   upthorn
Date:     2009-08-16 07:40:13 +0000 (Sun, 16 Aug 2009)

Log Message:
-----------
Replaced KeyStates with ActionKeys in the keymapper, removed SDL ASCII code mismatch workaround hacks, fixed the memory leaks I had previously created.

Modified Paths:
--------------
    scummvm/branches/gsoc2009-16bit/backends/keymapper/action.cpp
    scummvm/branches/gsoc2009-16bit/backends/keymapper/action.h
    scummvm/branches/gsoc2009-16bit/backends/keymapper/hardware-key.h
    scummvm/branches/gsoc2009-16bit/backends/keymapper/keymap.cpp
    scummvm/branches/gsoc2009-16bit/backends/keymapper/keymap.h
    scummvm/branches/gsoc2009-16bit/backends/keymapper/keymapper.cpp
    scummvm/branches/gsoc2009-16bit/backends/keymapper/keymapper.h
    scummvm/branches/gsoc2009-16bit/backends/keymapper/remap-dialog.cpp
    scummvm/branches/gsoc2009-16bit/backends/platform/sdl/hardwarekeys.cpp

Modified: scummvm/branches/gsoc2009-16bit/backends/keymapper/action.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/keymapper/action.cpp	2009-08-16 06:35:32 UTC (rev 43429)
+++ scummvm/branches/gsoc2009-16bit/backends/keymapper/action.cpp	2009-08-16 07:40:13 UTC (rev 43430)
@@ -43,14 +43,21 @@
 	_boss->addAction(this);
 }
 
-void Action::mapKey(const HardwareKey *key) {
+void Action::mapKey(const HardwareKey *key, byte flags) {
 	if (_hwKey)
+	{
 		_boss->unregisterMapping(this);
+		delete _hwKey;
+	}
 
-	_hwKey = key;
-
-	if (_hwKey)
-		_boss->registerMapping(this, _hwKey);
+	if (key) {
+		_hwKey = new HardwareKey(*key);
+		if (flags)
+			_hwKey->key.flags = flags & _hwKey->modMask;
+		if (_hwKey)
+			_boss->registerMapping(this, _hwKey);
+	} else
+		_hwKey = NULL;
 }
 
 const HardwareKey *Action::getMappedKey() const {

Modified: scummvm/branches/gsoc2009-16bit/backends/keymapper/action.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/keymapper/action.h	2009-08-16 06:35:32 UTC (rev 43429)
+++ scummvm/branches/gsoc2009-16bit/backends/keymapper/action.h	2009-08-16 07:40:13 UTC (rev 43430)
@@ -59,7 +59,7 @@
 
 private:
 	/** Hardware key that is mapped to this Action */
-	const HardwareKey *_hwKey;
+	HardwareKey *_hwKey;
 	Keymap *_boss;
 
 public:
@@ -105,7 +105,7 @@
 		return _boss;
 	}
 
-	void mapKey(const HardwareKey *key);
+	void mapKey(const HardwareKey *key, byte flags = 0);
 	const HardwareKey *getMappedKey() const;
 
 };

Modified: scummvm/branches/gsoc2009-16bit/backends/keymapper/hardware-key.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/keymapper/hardware-key.h	2009-08-16 06:35:32 UTC (rev 43429)
+++ scummvm/branches/gsoc2009-16bit/backends/keymapper/hardware-key.h	2009-08-16 07:40:13 UTC (rev 43430)
@@ -49,6 +49,17 @@
 	KeyCode keycode;
 	byte flags;
 
+	ActionKey () { 
+		keycode = KEYCODE_INVALID;
+		flags = 0;
+	}
+
+	ActionKey (const KeyState &key) { 
+		keycode = key.keycode;
+		flags = key.flags;
+	}
+
+
 	ActionKey (KeyCode ky, byte f) { 
 		keycode = ky;
 		flags = f;
@@ -75,7 +86,7 @@
 	* The KeyState that is generated by the back-end
 	* when this hardware key is pressed.
 	*/
-	KeyState key;
+	ActionKey key;
 
 	KeyType type;
 	ActionType preferredAction;
@@ -83,7 +94,7 @@
 	// Mask of modifiers that can possibly apply to this key.
 	byte modMask;
 
-	HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "", byte mods = ~0,
+	HardwareKey(const char *i, ActionKey ky = ActionKey(), String desc = "", byte mods = ~0,
 				KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType)
 		: key(ky), description(desc), type(typ), preferredAction(prefAct), modMask(mods) {
 		assert(i);
@@ -150,7 +161,7 @@
 		return 0;
 	}
 
-	const HardwareKey *findHardwareKey(const KeyState& keystate) const {
+	const HardwareKey *findHardwareKey(const ActionKey& keystate) const {
 		List<const HardwareKey*>::const_iterator it;
 
 		for (it = _keys.begin(); it != _keys.end(); it++) {
@@ -170,7 +181,7 @@
 		return 0;
 	}
 
-	const HardwareMod *findHardwareMod(const KeyState& keystate) const {
+	const HardwareMod *findHardwareMod(const ActionKey& keystate) const {
 		List<const HardwareMod*>::const_iterator it;
 
 		for (it = _mods.begin(); it != _mods.end(); it++) {

Modified: scummvm/branches/gsoc2009-16bit/backends/keymapper/keymap.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/keymapper/keymap.cpp	2009-08-16 06:35:32 UTC (rev 43429)
+++ scummvm/branches/gsoc2009-16bit/backends/keymapper/keymap.cpp	2009-08-16 07:40:13 UTC (rev 43430)
@@ -60,7 +60,7 @@
 }
 
 void Keymap::registerMapping(Action *action, const HardwareKey *hwKey) {
-	HashMap<KeyState, Action*>::iterator it;
+	HashMap<ActionKey, Action*>::iterator it;
 
 	it = _keymap.find(hwKey->key);
 
@@ -105,8 +105,8 @@
 	return 0;
 }
 
-Action *Keymap::getMappedAction(const KeyState& ks) const {
-	HashMap<KeyState, Action*>::iterator it;
+Action *Keymap::getMappedAction(const ActionKey& ks) const {
+	HashMap<ActionKey, Action*>::iterator it;
 
 	it = _keymap.find(ks);
 
@@ -157,9 +157,7 @@
 			_configDomain->erase(key);
 			continue;
 		}
-		HardwareKey *mappedKey = new HardwareKey(*hwKey);
-		mappedKey->key.flags = modId;
-		ua->mapKey(mappedKey);
+		ua->mapKey(hwKey,modId);
 	}
 }
 
@@ -335,7 +333,7 @@
 	}
 }
 
-Action *Keymap::getParentMappedAction(KeyState key) {
+Action *Keymap::getParentMappedAction(const ActionKey &key) {
 	if (_parent) {
 		Action *act = _parent->getMappedAction(key);
 

Modified: scummvm/branches/gsoc2009-16bit/backends/keymapper/keymap.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/keymapper/keymap.h	2009-08-16 06:35:32 UTC (rev 43429)
+++ scummvm/branches/gsoc2009-16bit/backends/keymapper/keymap.h	2009-08-16 07:40:13 UTC (rev 43430)
@@ -89,7 +89,7 @@
 	 * @param key	the key that is mapped to the required Action
 	 * @return		a pointer to the Action or 0 if no
 	 */
-	Action *getMappedAction(const KeyState& ks) const;
+	Action *getMappedAction(const ActionKey& ks) const;
 
 	void setConfigDomain(ConfigManager::Domain *dom);
 
@@ -147,12 +147,12 @@
 
 	void internalMapKey(Action *action, HardwareKey *hwKey);
 
-	Action *getParentMappedAction(KeyState key);
+	Action *getParentMappedAction(const ActionKey &key);
 
 	String _name;
 	Keymap *_parent;
 	List<Action*> _actions;
-	HashMap<KeyState, Action*> _keymap;
+	HashMap<ActionKey, Action*> _keymap;
 	ConfigManager::Domain *_configDomain;
 
 };

Modified: scummvm/branches/gsoc2009-16bit/backends/keymapper/keymapper.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/keymapper/keymapper.cpp	2009-08-16 06:35:32 UTC (rev 43429)
+++ scummvm/branches/gsoc2009-16bit/backends/keymapper/keymapper.cpp	2009-08-16 07:40:13 UTC (rev 43430)
@@ -190,33 +190,21 @@
 		return false;
 
 	Action *action = 0;
-
 	if (keyDown) {
-		// HACK: Temporary fix for modifier recognition, get the hwkey's keystate
-		// to correct for keydown and keyup generating different ascii codes in SDL
-		// to be solved more permanently by using a structure other than KeyState
-
-		const HardwareKey *hwkey = findHardwareKey(key);
-		if (!hwkey)
-			return false;
-
-		KeyState k = hwkey->key;
-		k.flags = key.flags & hwkey->modMask;
-
 		// Search for key in active keymap stack
 		for (int i = _activeMaps.size() - 1; i >= 0; --i) {
 			MapRecord mr = _activeMaps[i];
 
-			action = mr.keymap->getMappedAction(k);
+			action = mr.keymap->getMappedAction(key);
 
 			if (action || mr.inherit == false)
 				break;
 		}
 
 		if (action)
-			_keysDown[k] = action;
+			_keysDown[key] = action;
 	} else {
-		HashMap<KeyState, Action*>::iterator it = _keysDown.find(key);
+		HashMap<ActionKey, Action*>::iterator it = _keysDown.find(key);
 
 		if (it != _keysDown.end()) {
 			action = it->_value;
@@ -279,11 +267,11 @@
 	}
 }
 
-const HardwareKey *Keymapper::findHardwareKey(const KeyState& key) {
+const HardwareKey *Keymapper::findHardwareKey(const ActionKey& key) {
 	return (_hardwareKeys) ? _hardwareKeys->findHardwareKey(key) : 0;
 }
 
-const HardwareMod *Keymapper::findHardwareMod(const KeyState& key) {
+const HardwareMod *Keymapper::findHardwareMod(const ActionKey& key) {
 	return (_hardwareKeys) ? _hardwareKeys->findHardwareMod(key) : 0;
 }
 

Modified: scummvm/branches/gsoc2009-16bit/backends/keymapper/keymapper.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/keymapper/keymapper.h	2009-08-16 06:35:32 UTC (rev 43429)
+++ scummvm/branches/gsoc2009-16bit/backends/keymapper/keymapper.h	2009-08-16 07:40:13 UTC (rev 43430)
@@ -168,12 +168,12 @@
 	/**
 	 * Return a HardwareKey pointer for the given key state
 	 */
-	const HardwareKey *findHardwareKey(const KeyState& key);
+	const HardwareKey *findHardwareKey(const ActionKey& key);
 
 	/**
 	 * Return a HardwareMod pointer for the given key state
 	 */
-	const HardwareMod *findHardwareMod(const KeyState& key);
+	const HardwareMod *findHardwareMod(const ActionKey& key);
 
 	Domain& getGlobalDomain() { return _globalDomain; }
 	Domain& getGameDomain() { return _gameDomain; }
@@ -198,7 +198,7 @@
 	bool _enabled;
 
 	Stack<MapRecord> _activeMaps;
-	HashMap<KeyState, Action*> _keysDown;
+	HashMap<ActionKey, Action*> _keysDown;
 
 };
 

Modified: scummvm/branches/gsoc2009-16bit/backends/keymapper/remap-dialog.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/keymapper/remap-dialog.cpp	2009-08-16 06:35:32 UTC (rev 43429)
+++ scummvm/branches/gsoc2009-16bit/backends/keymapper/remap-dialog.cpp	2009-08-16 07:40:13 UTC (rev 43430)
@@ -243,14 +243,9 @@
 		debug( "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags);
 
 		if (hwkey) {
-			//FIXME: this leaks memory and there's no good way to get this pointer again as 
-			//a non-const. this should be done differently when we switch to actionKeys.
-			HardwareKey *mappedkey = new HardwareKey(*hwkey);
-			mappedkey->description = hwkey->description;
-			mappedkey->key.flags = (state.flags & hwkey->modMask);
-
-			_activeRemapAction->mapKey(mappedkey);
+			_activeRemapAction->mapKey(hwkey,state.flags);
 			_activeRemapAction->getParent()->saveMappings();
+
 			_changes = true;
 			stopRemapping();
 		}

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/sdl/hardwarekeys.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/sdl/hardwarekeys.cpp	2009-08-16 06:35:32 UTC (rev 43429)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/sdl/hardwarekeys.cpp	2009-08-16 07:40:13 UTC (rev 43430)
@@ -227,7 +227,7 @@
 		snprintf(fullKeyId, 50, "%s", key->hwId);
 		snprintf(fullKeyDesc, 100, "%s", key->desc);
 
-		keySet->addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, 0), fullKeyDesc, key->modableMask, key->preferredAction));
+		keySet->addHardwareKey(new HardwareKey(fullKeyId, ActionKey(key->keycode, 0), fullKeyDesc, key->modableMask, key->preferredAction));
 	}
 
 	keySetInited = true;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list