diff options
author | Tarek Soliman | 2012-02-21 06:57:32 -0600 |
---|---|---|
committer | Tarek Soliman | 2012-02-21 08:20:40 -0600 |
commit | aa42d78658eacc17a36ffe0d86541deffa534f79 (patch) | |
tree | 08f8e39c9b1c2f378c00316087e63a2e3a3aed70 /backends/keymapper | |
parent | d0c655f1fac3f559e0edb11246466304df1dd7f1 (diff) | |
download | scummvm-rg350-aa42d78658eacc17a36ffe0d86541deffa534f79.tar.gz scummvm-rg350-aa42d78658eacc17a36ffe0d86541deffa534f79.tar.bz2 scummvm-rg350-aa42d78658eacc17a36ffe0d86541deffa534f79.zip |
KEYMAPPER: Remove automapping dead code
Diffstat (limited to 'backends/keymapper')
-rw-r--r-- | backends/keymapper/action.cpp | 5 | ||||
-rw-r--r-- | backends/keymapper/action.h | 5 | ||||
-rw-r--r-- | backends/keymapper/hardware-key.h | 12 | ||||
-rw-r--r-- | backends/keymapper/keymap.cpp | 141 | ||||
-rw-r--r-- | backends/keymapper/keymap.h | 11 | ||||
-rw-r--r-- | backends/keymapper/keymapper.cpp | 1 | ||||
-rw-r--r-- | backends/keymapper/types.h | 74 |
7 files changed, 6 insertions, 243 deletions
diff --git a/backends/keymapper/action.cpp b/backends/keymapper/action.cpp index 6ee506e7c3..515ec70e32 100644 --- a/backends/keymapper/action.cpp +++ b/backends/keymapper/action.cpp @@ -28,9 +28,8 @@ namespace Common { -Action::Action(Keymap *boss, const char *i, String des, ActionType typ, - KeyType prefKey, int pri, int flg) - : _boss(boss), description(des), type(typ), preferredKey(prefKey), +Action::Action(Keymap *boss, const char *i, String des, int pri, int flg) + : _boss(boss), description(des), priority(pri), flags(flg), _hwKey(0) { assert(i); assert(_boss); diff --git a/backends/keymapper/action.h b/backends/keymapper/action.h index 308a76aa88..bf3773b7e3 100644 --- a/backends/keymapper/action.h +++ b/backends/keymapper/action.h @@ -27,7 +27,6 @@ #ifdef ENABLE_KEYMAPPER -#include "backends/keymapper/types.h" #include "common/events.h" #include "common/func.h" #include "common/list.h" @@ -54,8 +53,6 @@ struct Action { /** Events to be sent when mapped key is pressed */ List<Event> events; - ActionType type; - KeyType preferredKey; int priority; int group; int flags; @@ -67,8 +64,6 @@ private: public: Action(Keymap *boss, const char *id, String des = "", - ActionType typ = kGenericActionType, - KeyType prefKey = kGenericKeyType, int pri = 0, int flg = 0 ); void addEvent(const Event &evt) { diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h index 071a38968f..8c46ee6358 100644 --- a/backends/keymapper/hardware-key.h +++ b/backends/keymapper/hardware-key.h @@ -27,7 +27,6 @@ #ifdef ENABLE_KEYMAPPER -#include "backends/keymapper/types.h" #include "common/textconsole.h" namespace Common { @@ -50,12 +49,8 @@ struct HardwareKey { */ KeyState key; - KeyType type; - ActionType preferredAction; - - HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "", - KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType) - : key(ky), description(desc), type(typ), preferredAction(prefAct) { + HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "") + : key(ky), description(desc) { assert(i); Common::strlcpy(hwKeyId, i, HWKEY_ID_SIZE); } @@ -69,7 +64,6 @@ struct KeyTableEntry { KeyCode keycode; uint16 ascii; const char *desc; - KeyType preferredAction; bool shiftable; }; @@ -170,7 +164,7 @@ public: snprintf(fullKeyDesc, 100, "%s%s", mod->desc, key->desc); } - addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, mod->flag), fullKeyDesc, key->preferredAction )); + addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, mod->flag), fullKeyDesc)); } } } diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index daf92e1d15..5bee1a246d 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -212,147 +212,6 @@ bool Keymap::isComplete(const HardwareKeySet *hwKeys) { return allMapped || (numberMapped == hwKeys->size()); } -// TODO: -// - current weakness: -// - if an action finds a key with required type but a parent action with -// higher priority is using it, that key is never used -void Keymap::automaticMapping(HardwareKeySet *hwKeys) { -#if 0 //disabling the broken automapper for now - // Create copies of action and key lists. - List<Action *> actions(_actions); - List<const HardwareKey *> keys(hwKeys->getHardwareKeys()); - - List<Action *>::iterator actIt; - List<const HardwareKey *>::iterator keyIt, selectedKey; - - // Remove actions and keys from local lists that have already been mapped. - actIt = actions.begin(); - - while (actIt != actions.end()) { - Action *act = *actIt; - const HardwareKey *key = act->getMappedKey(); - - if (key) { - keys.remove(key); - actIt = actions.erase(actIt); - } else { - ++actIt; - } - } - - // Sort remaining actions by priority. - ActionPriorityComp priorityComp; - sort(actions.begin(), actions.end(), priorityComp); - - // First mapping pass: - // - Match if a key's preferred action type is the same as the action's - // type, or vice versa. - // - Priority is given to: - // - keys that match action types over key types. - // - keys that have not been used by parent maps. - // - If a key has been used by a parent map the new action must have a - // higher priority than the parent action. - // - As soon as the number of skipped actions equals the number of keys - // remaining we stop matching. This means that the second pass will assign keys - // to these higher priority skipped actions. - uint skipped = 0; - actIt = actions.begin(); - - while (actIt != actions.end() && skipped < keys.size()) { - selectedKey = keys.end(); - int matchRank = 0; - Action *act = *actIt; - - for (keyIt = keys.begin(); keyIt != keys.end(); ++keyIt) { - if ((*keyIt)->preferredAction == act->type && act->type != kGenericActionType) { - Action *parentAct = getParentMappedAction((*keyIt)->key); - - if (!parentAct) { - selectedKey = keyIt; - break; - } else if (parentAct->priority <= act->priority && matchRank < 3) { - selectedKey = keyIt; - matchRank = 3; - } - } else if ((*keyIt)->type == act->preferredKey && act->preferredKey != kGenericKeyType && matchRank < 2) { - Action *parentAct = getParentMappedAction((*keyIt)->key); - - if (!parentAct) { - selectedKey = keyIt; - matchRank = 2; - } else if (parentAct->priority <= act->priority && matchRank < 1) { - selectedKey = keyIt; - matchRank = 1; - } - } - } - if (selectedKey != keys.end()) { - // Map action and delete action & key from local lists. - act->mapKey(*selectedKey); - keys.erase(selectedKey); - actIt = actions.erase(actIt); - } else { - // Skip action (will be mapped in next pass). - ++actIt; - ++skipped; - } - } - - // Second mapping pass: - // - Maps any remaining actions to keys - // - priority given to: - // - keys that have no parent action - // - keys whose parent action has lower priority than the new action - // - keys whose parent action has the lowest priority - // - is guaranteed to match a key if they are not all used up - for (actIt = actions.begin(); actIt != actions.end(); ++actIt) { - selectedKey = keys.end(); - - int matchRank = 0; - int lowestPriority = 0; - Action *act = *actIt; - - for (keyIt = keys.begin(); keyIt != keys.end(); ++keyIt) { - Action *parentAct = getParentMappedAction((*keyIt)->key); - - if (!parentAct) { - selectedKey = keyIt; - break; - } else if (matchRank < 2) { - if (parentAct->priority <= act->priority) { - matchRank = 2; - selectedKey = keyIt; - } else if (parentAct->priority < lowestPriority || matchRank == 0) { - matchRank = 1; - lowestPriority = parentAct->priority; - selectedKey = keyIt; - } - } - } - - if (selectedKey != keys.end()) { - act->mapKey(*selectedKey); - keys.erase(selectedKey); - } else {// no match = no keys left - break; - } - } -#endif -} - -Action *Keymap::getParentMappedAction(KeyState key) { - if (_parent) { - Action *act = _parent->getMappedAction(key); - - if (act) - return act; - else - return _parent->getParentMappedAction(key); - } else { - return 0; - } -} - } // End of namespace Common #endif // #ifdef ENABLE_KEYMAPPER diff --git a/backends/keymapper/keymap.h b/backends/keymapper/keymap.h index bbcc4a1926..2e9f08533e 100644 --- a/backends/keymapper/keymap.h +++ b/backends/keymapper/keymap.h @@ -52,7 +52,7 @@ template<> struct Hash<KeyState> class Keymap { public: - Keymap(const String& name, Keymap *parent = 0) : _name(name), _parent(parent) {} + Keymap(const String& name) : _name(name) {} Keymap(const Keymap& km); ~Keymap(); @@ -91,9 +91,6 @@ public: */ void saveMappings(); - - void automaticMapping(HardwareKeySet *hwKeys); - /** * Returns true if all UserAction's in Keymap are mapped, or, * all HardwareKey's from the given set have been used up. @@ -101,7 +98,6 @@ public: bool isComplete(const HardwareKeySet *hwKeys); const String& getName() { return _name; } - Keymap *getParent() { return _parent; } private: friend struct Action; @@ -131,12 +127,7 @@ private: Action *findAction(const char *id); const Action *findAction(const char *id) const; - void internalMapKey(Action *action, HardwareKey *hwKey); - - Action *getParentMappedAction(KeyState key); - String _name; - Keymap *_parent; List<Action *> _actions; HashMap<KeyState, Action *> _keymap; ConfigManager::Domain *_configDomain; diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index 7ada676516..aafdd604a2 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -104,7 +104,6 @@ void Keymapper::initKeymap(Domain &domain, Keymap *map) { map->loadMappings(_hardwareKeys); if (map->isComplete(_hardwareKeys) == false) { - map->automaticMapping(_hardwareKeys); map->saveMappings(); ConfMan.flushToDisk(); } diff --git a/backends/keymapper/types.h b/backends/keymapper/types.h deleted file mode 100644 index ed2e498bd0..0000000000 --- a/backends/keymapper/types.h +++ /dev/null @@ -1,74 +0,0 @@ -/* ScummVM - Graphic Adventure Engine -* -* ScummVM is the legal property of its developers, whose names -* are too numerous to list here. Please refer to the COPYRIGHT -* file distributed with this source distribution. -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -*/ - -#ifndef KEYMAPPER_TYPES_H -#define KEYMAPPER_TYPES_H - -#include "common/scummsys.h" - -#ifdef ENABLE_KEYMAPPER - -namespace Common { - -enum KeyType { - kGenericKeyType, - kDirUpKeyType, - kDirDownKeyType, - kDirLeftKeyType, - kDirRightKeyType, - kActionKeyType, - kTriggerLeftKeyType, - kTriggerRightKeyType, - kStartKeyType, - kSelectKeyType, - /* ... */ - - kKeyTypeMax -}; - -enum ActionType { - kGenericActionType, - - // common actions - kDirUpActionType, - kDirDownActionType, - kDirLeftActionType, - kDirRightActionType, - kLeftClickActionType, - kRightClickActionType, - kSaveActionType, - kMenuActionType, - kQuitActionType, - kVirtualKeyboardActionType, - kKeyRemapActionType, - kVolumeUpActionType, - kVolumeDownActionType, - - - kActionTypeMax -}; - -} // End of namespace Common - -#endif // #ifdef ENABLE_KEYMAPPER - -#endif // #ifndef KEYMAPPER_TYPES_H |