[Scummvm-cvs-logs] SF.net SVN: scummvm:[33173] scummvm/branches/gsoc2008-vkeybd/backends/ common

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Mon Jul 21 17:55:26 CEST 2008


Revision: 33173
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33173&view=rev
Author:   kenny-d
Date:     2008-07-21 15:55:25 +0000 (Mon, 21 Jul 2008)

Log Message:
-----------
Refactored KeymapManager to use Domain's of Keymaps rather than a single list.
Further development of Keymapper interface: 
- switchKeymap method to change Keymaps
- initGame/deInitGame methods to control loading/unloading of game-specific maps

Modified Paths:
--------------
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-07-21 14:03:37 UTC (rev 33172)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-07-21 15:55:25 UTC (rev 33173)
@@ -4,56 +4,62 @@
 
 namespace Common {
 
-KeymapManager::KeymapManager() {
 
+void KeymapManager::Domain::addDefaultKeymap(Keymap *map) {
+	_defaultKeymap = map;
 }
 
-bool KeymapManager::registerSuperGlobalKeymap(const Keymap& map) {
-	return registerKeymap(GLOBAL_ID_STR, GLOBAL_ID_STR, map);
+void KeymapManager::Domain::addKeymap(const String& name, Keymap *map) {
+	if (_keymaps.contains(name))
+		delete _keymaps[name];
+	_keymaps[name] = map;
 }
 
-bool KeymapManager::registerGlobalKeymap(const String& name, const Keymap& map) {
-	return registerKeymap(name, GLOBAL_ID_STR, map);
+void KeymapManager::Domain::deleteAllKeyMaps() {
+	KeymapMap::iterator it;
+	for (it = _keymaps.begin(); it != _keymaps.end(); it++)
+		delete it->_value;
+	_keymaps.clear();
 }
 
-bool KeymapManager::registerKeymap(const String& name, const String& domain, const Keymap& map) {
-	if (findEntry(name, domain) != _keymaps.end()) {
-		warning("Keymap with given name and domain already exists\n");
-		return false;
-	}
-	Entry *ent = new Entry;
-	ent->_name = name;
-	ent->_domain = domain;
-	ent->_keymap = new Keymap(map);
-	_keymaps.push_back(ent);
-	return true;
+Keymap *KeymapManager::Domain::getDefaultKeymap() {
+	return _defaultKeymap;
 }
 
-bool KeymapManager::unregisterSuperGlobalKeymap() {
-	return unregisterKeymap(GLOBAL_ID_STR, GLOBAL_ID_STR);
+Keymap *KeymapManager::Domain::getKeymap(const String& name) {
+	KeymapMap::iterator it = _keymaps.find(name);
+	if (it != _keymaps.end())
+		return it->_value;
+	else
+		return 0;
 }
 
-bool KeymapManager::unregisterGlobalKeymap(const String& name) {
-	return unregisterKeymap(name, GLOBAL_ID_STR);
+
+void KeymapManager::registerDefaultGlobalKeymap(Keymap *map) {
+	_globalDomain.addDefaultKeymap(map);
 }
 
-bool KeymapManager::unregisterKeymap(const String& name, const String& domain) {
-	Iterator it = findEntry(name, domain);
-	if (it == _keymaps.end())
-		return true;
-	delete (*it)->_keymap;
-	delete *it;
-	_keymaps.erase(it);
-	return true;
+void KeymapManager::registerGlobalKeymap(const String& name, Keymap *map) {
+	_globalDomain.addKeymap(name, map);
 }
 
-KeymapManager::Iterator KeymapManager::findEntry(const String& name, const String& domain) {
-	Iterator it;
-	for (it = _keymaps.begin(); it != _keymaps.end(); it++) {
-		if ((*it)->_name == name && (*it)->_domain == domain)
-			break;
-	}
-	return it;
+void KeymapManager::registerDefaultGameKeymap(Keymap *map) {
+	_gameDomain.addDefaultKeymap(map);
 }
- 
+
+void KeymapManager::registerGameKeymap(const String& name, Keymap *map) {
+	_gameDomain.addKeymap(name, map);
+}
+
+void KeymapManager::unregisterAllGameKeymaps() {
+	_gameDomain.deleteAllKeyMaps();
+}
+
+Keymap *KeymapManager::getKeymap(const String& name) {
+	Keymap *keymap = _gameDomain.getKeymap(name);
+	if (!keymap)
+		_globalDomain.getKeymap(name);
+	return keymap;
+}
+
 } // end of namespace Common
\ No newline at end of file

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-07-21 14:03:37 UTC (rev 33172)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-07-21 15:55:25 UTC (rev 33173)
@@ -2,35 +2,48 @@
 #define COMMON_KEYMAP_MANAGER
 
 #include "backends/common/keymap.h"
-#include "common/list.h"
+#include "common/hash-str.h"
+#include "common/hashmap.h"
 
 namespace Common {
 
 class KeymapManager {
 public:
 
-	KeymapManager();
+	class Domain {
+	public:
+		Domain() : _defaultKeymap(0) {}
 
-	bool registerSuperGlobalKeymap(const Keymap& map);
-	bool registerGlobalKeymap(const String& name, const Keymap& map);
-	bool registerKeymap(const String& name, const String& domain, const Keymap& map);
+		void addDefaultKeymap(Keymap *map);
+		void addKeymap(const String& name, Keymap *map);
 
-	bool unregisterSuperGlobalKeymap();
-	bool unregisterGlobalKeymap(const String& name);
-	bool unregisterKeymap(const String& name, const String& domain);
+		void deleteAllKeyMaps();
 
-private:
+		Keymap *getDefaultKeymap();
+		Keymap *getKeymap(const String& name);
 
-	struct Entry {
-		String _name;
-		String _domain;
-		Keymap *_keymap;
+	private:
+		typedef HashMap<String, Keymap*, 
+			IgnoreCase_Hash, IgnoreCase_EqualTo> KeymapMap;
+
+		Keymap *_defaultKeymap;
+		KeymapMap _keymaps;
 	};
-	typedef List<Entry*>::iterator Iterator;
 
-	Iterator findEntry(const String& name, const String& domain);
+	void registerDefaultGlobalKeymap(Keymap *map);
+	void registerGlobalKeymap(const String& name, Keymap *map);
 
-	List<Entry*> _keymaps;
+	void registerDefaultGameKeymap(Keymap *map);
+	void registerGameKeymap(const String& name, Keymap *map);
+
+	void unregisterAllGameKeymaps();
+
+	Keymap *KeymapManager::getKeymap(const String& name);
+
+private:
+
+	Domain _globalDomain;
+	Domain _gameDomain;
 };
 
 } // end of namespace Common

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp	2008-07-21 14:03:37 UTC (rev 33172)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp	2008-07-21 15:55:25 UTC (rev 33173)
@@ -1,6 +1,6 @@
 #include "backends/common/keymapper.h"
 #include "backends/common/keymap-manager.h"
-
+#include "common/config-manager.h"
 namespace Common {
 
 Keymapper::Keymapper(EventManager *evtMgr) {
@@ -16,16 +16,46 @@
 	_hardwareKeys = keys;
 }
 
-const HardwareKeySet *Keymapper::getHardwareKeySet() {
+const HardwareKeySet *Keymapper::getHardwareKeySet() const {
 	return _hardwareKeys;
 }
 
-void Keymapper::addGlobalKeyMap(const String& name, Keymap& keymap) {
+void Keymapper::addGlobalKeyMap(const String& name, Keymap *keymap) {
 	_keymapMan->registerGlobalKeymap(name, keymap);
 }
 
-void Keymapper::addGameKeyMap(const String& gameid, const String& name, Keymap& keymap) {
-	_keymapMan->registerKeymap(name, gameid, keymap);
+void Keymapper::addGameKeyMap(const String& name, Keymap *keymap) {
+	if (_gameId.size() == 0) {
+		initGame();
+		if (_gameId.size() == 0)
+			return;
+	}
+	_keymapMan->registerGameKeymap(name, keymap);
 }
 
+void Keymapper::initGame() {
+	if (ConfMan.getActiveDomain() == 0)
+		error("Call to Keymapper::initGame when no game loaded\n");
+
+	if (_gameId.size() > 0)
+		deInitGame();
+	_gameId = ConfMan.getActiveDomainName();
+}
+
+void Keymapper::deInitGame() {
+	_keymapMan->unregisterAllGameKeymaps();
+	_gameId.clear();
+}
+
+
+bool Keymapper::switchKeymap(const String& name) {
+	Keymap *new_map = _keymapMan->getKeymap(name);
+	if (!new_map) {
+		warning("Keymap '%s' could not be found\n", name.c_str());
+		return false;
+	}
+	_currentMap = new_map;
+	return true;
+}
+
 } // end of namespace Common

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h	2008-07-21 14:03:37 UTC (rev 33172)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h	2008-07-21 15:55:25 UTC (rev 33173)
@@ -14,10 +14,18 @@
 	Keymapper(EventManager *eventMan);
 
 	void registerHardwareKeySet(HardwareKeySet *keys);
-	const HardwareKeySet *getHardwareKeySet();
-	void addGlobalKeyMap(const String& name, Keymap& keymap);
-	void addGameKeyMap(const String& gameid, const String& name, Keymap& keymap);
 
+	const HardwareKeySet *getHardwareKeySet() const;
+
+	void addGlobalKeyMap(const String& name, Keymap *keymap);
+
+	void addGameKeyMap(const String& name, Keymap *keymap);
+
+	void initGame();
+	void deInitGame();
+
+	bool switchKeymap(const String& name);
+
 private:
 
 	typedef List<HardwareKey*>::iterator Iterator;
@@ -25,6 +33,8 @@
 	EventManager *_eventMan;
 	KeymapManager *_keymapMan;
 
+	String _gameId;
+
 	Keymap *_currentMap;
 
 	const HardwareKeySet *_hardwareKeys;


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