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

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Wed Jul 23 10:45:13 CEST 2008


Revision: 33227
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33227&view=rev
Author:   kenny-d
Date:     2008-07-23 08:45:12 +0000 (Wed, 23 Jul 2008)

Log Message:
-----------
Most of Keymapper class complete
DefaultEventManager now initialises Keymapper and passes key press events to it

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/keymap.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h
    scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.h

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-07-23 07:52:43 UTC (rev 33226)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-07-23 08:45:12 UTC (rev 33227)
@@ -1,7 +1,5 @@
 #include "backends/common/keymap-manager.h"
 
-#define GLOBAL_ID_STR "___GLOBAL"
-
 namespace Common {
 
 
@@ -36,21 +34,61 @@
 
 
 void KeymapManager::registerDefaultGlobalKeymap(Keymap *map) {
+	ConfigManager::Domain *dom = ConfMan.getDomain(ConfigManager::kApplicationDomain);
+	assert(dom);
+	initKeymap(dom, "default", map);
 	_globalDomain.addDefaultKeymap(map);
 }
 
 void KeymapManager::registerGlobalKeymap(const String& name, Keymap *map) {
+	ConfigManager::Domain *dom = ConfMan.getDomain(ConfigManager::kApplicationDomain);
+	assert(dom);
+
+	initKeymap(dom, name, map);
 	_globalDomain.addKeymap(name, map);
 }
 
 void KeymapManager::registerDefaultGameKeymap(Keymap *map) {
+	ConfigManager::Domain *dom = ConfMan.getActiveDomain();
+	assert(dom);
+
+	initKeymap(dom, "default", map);
 	_gameDomain.addDefaultKeymap(map);
 }
 
 void KeymapManager::registerGameKeymap(const String& name, Keymap *map) {
+	ConfigManager::Domain *dom = ConfMan.getActiveDomain();
+	assert(dom);
+
+	initKeymap(dom, name, map);
 	_gameDomain.addKeymap(name, map);
 }
 
+void KeymapManager::initKeymap(ConfigManager::Domain *domain, 
+							   const String& name, 
+							   Keymap *map) {
+	if (!loadKeymap(domain, name, map))
+		return;
+	automaticMap(map);
+}
+
+bool KeymapManager::loadKeymap(ConfigManager::Domain *domain, 
+							   const String& name, 
+							   Keymap *map) {
+	return false;
+}
+
+void KeymapManager::saveKeymap(ConfigManager::Domain *domain, 
+							   const String& name, 
+							   Keymap *map) {
+
+}
+
+
+void KeymapManager::automaticMap(Keymap *map) {
+
+}
+
 void KeymapManager::unregisterAllGameKeymaps() {
 	_gameDomain.deleteAllKeyMaps();
 }

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-07-23 07:52:43 UTC (rev 33226)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-07-23 08:45:12 UTC (rev 33227)
@@ -2,6 +2,7 @@
 #define COMMON_KEYMAP_MANAGER
 
 #include "backends/common/keymap.h"
+#include "common/config-manager.h"
 #include "common/hash-str.h"
 #include "common/hashmap.h"
 
@@ -13,6 +14,7 @@
 	class Domain {
 	public:
 		Domain() : _defaultKeymap(0) {}
+		~Domain() { deleteAllKeyMaps(); }
 
 		void addDefaultKeymap(Keymap *map);
 		void addKeymap(const String& name, Keymap *map);
@@ -42,6 +44,11 @@
 
 private:
 
+	void initKeymap(ConfigManager::Domain *domain, const String& name, Keymap *keymap);
+	bool loadKeymap(ConfigManager::Domain *domain, const String& name, Keymap *keymap);
+	void saveKeymap(ConfigManager::Domain *domain, const String& name, Keymap *keymap);
+	void automaticMap(Keymap *map);
+
 	Domain _globalDomain;
 	Domain _gameDomain;
 };

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp	2008-07-23 07:52:43 UTC (rev 33226)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp	2008-07-23 08:45:12 UTC (rev 33227)
@@ -71,7 +71,7 @@
 	return 0;
 }
 
-UserAction *Keymap::getMappedAction(KeyState ks) const {
+UserAction *Keymap::getMappedAction(const KeyState& ks) const {
 	HashMap<KeyState, UserAction*>::iterator it;
 	it = _keymap.find(ks);
 	if (it == _keymap.end())

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h	2008-07-23 07:52:43 UTC (rev 33226)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h	2008-07-23 08:45:12 UTC (rev 33227)
@@ -69,7 +69,7 @@
 	 * @param key the key that is mapped to the required UserAction
 	 * @return a pointer to the UserAction or 0 if no
 	 */
-	UserAction *getMappedAction(KeyState key) const;
+	UserAction *getMappedAction(const KeyState& ks) const;
 
 private:
 	

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp	2008-07-23 07:52:43 UTC (rev 33226)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp	2008-07-23 08:45:12 UTC (rev 33227)
@@ -38,11 +38,11 @@
 		error("Call to Keymapper::initGame when no game loaded\n");
 
 	if (_gameId.size() > 0)
-		deInitGame();
+		cleanupGame();
 	_gameId = ConfMan.getActiveDomainName();
 }
 
-void Keymapper::deInitGame() {
+void Keymapper::cleanupGame() {
 	_keymapMan->unregisterAllGameKeymaps();
 	_gameId.clear();
 }
@@ -51,11 +51,61 @@
 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());
+		warning("Keymap '%s' not registered\n", name.c_str());
 		return false;
 	}
 	_currentMap = new_map;
 	return true;
 }
 
+bool Keymapper::mapKeyDown(const KeyState& key) {
+	return mapKey(key, true);
+}
+
+bool Keymapper::mapKeyUp(const KeyState& key) {
+	return mapKey(key, false);
+}
+
+bool Keymapper::mapKey(const KeyState& key, bool isKeyDown) {
+	if (!_currentMap) return false;
+	UserAction *action = _currentMap->getMappedAction(key);
+	if (!action) return false;
+	List<Event>::iterator it;
+	for (it = action->events.begin(); it != action->events.end(); it++) {
+		Event evt = *it;
+		bool pushEvent = true;
+		switch (evt.type) {
+		case EVENT_KEYDOWN:
+			if (!isKeyDown) evt.type = EVENT_KEYUP;
+			break;
+		case EVENT_KEYUP:
+			if (isKeyDown) evt.type = EVENT_KEYDOWN;
+			break;
+		case EVENT_LBUTTONDOWN:
+			if (!isKeyDown) evt.type = EVENT_LBUTTONUP;
+			break;
+		case EVENT_LBUTTONUP:
+			if (isKeyDown) evt.type = EVENT_LBUTTONDOWN;
+			break;
+		case EVENT_RBUTTONDOWN:
+			if (!isKeyDown) evt.type = EVENT_RBUTTONUP;
+			break;
+		case EVENT_RBUTTONUP:
+			if (isKeyDown) evt.type = EVENT_RBUTTONDOWN;
+			break;
+		case EVENT_MBUTTONDOWN:
+			if (!isKeyDown) evt.type = EVENT_MBUTTONUP;
+			break;
+		case EVENT_MBUTTONUP:
+			if (isKeyDown) evt.type = EVENT_MBUTTONDOWN;
+			break;
+		default:
+			// don't deliver other events on key up
+			if (!isKeyDown) pushEvent = false;
+		}
+		if (pushEvent) _eventMan->pushEvent(evt);
+	}
+	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-23 07:52:43 UTC (rev 33226)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h	2008-07-23 08:45:12 UTC (rev 33227)
@@ -13,19 +13,70 @@
 
 	Keymapper(EventManager *eventMan);
 
+	/**
+	 * Registers a HardwareKeySet with the Keymapper
+	 * @note should only be called once (during backend initialisation)
+	 */
 	void registerHardwareKeySet(HardwareKeySet *keys);
 
+	/**
+	 * Get the HardwareKeySet that is registered with the Keymapper
+	 */
 	const HardwareKeySet *getHardwareKeySet() const;
 
+	/**
+	 * Add a keymap to the global domain.
+	 * If a saved key setup exists for it in the ini file it will be used.
+	 * Else, the key setup will be automatically mapped.
+	 */
 	void addGlobalKeyMap(const String& name, Keymap *keymap);
 
+	/**
+	* Add a keymap to the game domain.
+	* @see addGlobalKeyMap
+	* @note initGame() should be called before any game keymaps are added.
+	*/
 	void addGameKeyMap(const String& name, Keymap *keymap);
 
+	/**
+	 * Initialise the keymapper for a new game
+	 */
 	void initGame();
-	void deInitGame();
 
+	/**
+	 * Cleanup the keymapper after a game has ended
+	 */
+	void cleanupGame();
+
+	/**
+	 * Switch the active keymap.
+	 * @param name name of the new keymap
+	 * @return true if successful
+	 */
 	bool switchKeymap(const String& name);
 
+	/**
+	* @brief Map a key press event.
+	* If the active keymap contains a UserAction mapped to the given key, then 
+	* the UserAction's events are pushed into the EventManager's event queue.
+	* @param key key that was pressed
+	* @param isKeyDown true for key down, false for key up
+	* @return true if key was mapped
+	*/
+	bool mapKey(const KeyState& key, bool isKeyDown);
+
+	/**
+	 * @brief Map a key down event.
+	 * @see mapKey
+	 */
+	bool mapKeyDown(const KeyState& key);
+
+	/**
+	* @brief Map a key up event.
+	* @see mapKey
+	*/
+	bool mapKeyUp(const KeyState& key);
+
 private:
 
 	typedef List<HardwareKey*>::iterator Iterator;

Modified: scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp	2008-07-23 07:52:43 UTC (rev 33226)
+++ scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp	2008-07-23 08:45:12 UTC (rev 33227)
@@ -107,6 +107,7 @@
 	_eventCount = 0;
 	_lastEventCount = 0;
 	_lastMillis = 0;
+	_artificialEventCounter = 0;
 
 	Common::String recordModeString = ConfMan.get("record_mode");
 	if (recordModeString.compareToIgnoreCase("record") == 0) {
@@ -193,7 +194,7 @@
 	}
 
 	_vk = new Common::VirtualKeyboard();
-	_artificialEventCounter = 0;
+	_keyMapper = new Common::Keymapper(this);
 }
 
 DefaultEventManager::~DefaultEventManager() {
@@ -351,18 +352,32 @@
 
 bool DefaultEventManager::pollEvent(Common::Event &event) {
 	uint32 time = _boss->getMillis();
-	bool result;
+	bool result = false;
 	
+	// poll for pushed events
 	if (!_artificialEventQueue.empty()) {
 		// delay the feeding of artificial events
 		if (++_artificialEventCounter % kArtificialEventDelay == 0) {
 			event = _artificialEventQueue.pop();
 			result = true;
 			_artificialEventCounter = 0; 
-		} else
-			result = _boss->pollEvent(event);
-	} else 	
+		}
+	}
+	
+	// poll for event from backend
+	if (!result) {
 		result = _boss->pollEvent(event);
+		if (result) {
+			// send key press events to keymapper
+			if (event.type == Common::EVENT_KEYDOWN) {
+				if (_keyMapper->mapKeyDown(event.kbd))
+					result = false;
+			} else if (event.type == Common::EVENT_KEYUP) {
+				if (_keyMapper->mapKeyUp(event.kbd))
+					result = false;
+			}
+		}
+	}
 
 	if (_recordMode != kPassthrough)  {
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.h	2008-07-23 07:52:43 UTC (rev 33226)
+++ scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.h	2008-07-23 08:45:12 UTC (rev 33227)
@@ -29,6 +29,7 @@
 #include "common/events.h"
 #include "common/queue.h"
 #include "common/savefile.h"
+#include "backends/common/keymapper.h"
 #include "backends/common/virtual-keyboard.h"
 
 /*
@@ -47,11 +48,12 @@
 	OSystem *_boss;
 
 	Common::VirtualKeyboard *_vk;
+	Common::Keymapper *_keyMapper;
 
 	Common::Queue<Common::Event> _artificialEventQueue;
 	int _artificialEventCounter;
 	enum {
-		kArtificialEventDelay = 10
+		kArtificialEventDelay = 5
 	};
 
 	Common::Point _mousePos;


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