changeset 428:a1884665aa95

Added the ability to add an event listener to the front of the event listener deque in the event manager. fixes[t:454]
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 22 Feb 2010 21:23:01 +0000
parents 68aa65e5bd9c
children be291458d9b5
files engine/core/eventchannel/command/ec_icommandcontroller.h engine/core/eventchannel/eventchannel.i engine/core/eventchannel/eventmanager.cpp engine/core/eventchannel/eventmanager.h engine/core/eventchannel/key/ec_ikeycontroller.h engine/core/eventchannel/mouse/ec_imousecontroller.h engine/core/eventchannel/sdl/ec_isdleventcontroller.h
diffstat 7 files changed, 130 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/eventchannel/command/ec_icommandcontroller.h	Sat Feb 20 21:41:43 2010 +0000
+++ b/engine/core/eventchannel/command/ec_icommandcontroller.h	Mon Feb 22 21:23:01 2010 +0000
@@ -45,12 +45,18 @@
 	class ICommandController {
 	public:
 
-		/** Adds a listener to the controller
+		/** Adds a listener to the back of the listener deque
 		 * Listener will be notified via the corresponding events
 		 * @param listener listener to add
 		 */
 		virtual void addCommandListener(ICommandListener* listener) = 0;
 
+		/** Adds a listener to the front of the listener deque
+		 * Listener will be notified via the corresponding events
+		 * @param listener listener to add
+		 */
+		virtual void addCommandListenerFront(ICommandListener* listener) = 0;
+
 		/** Removes an added listener from the controller.
 		 * Listener will not be notified anymore via the corresponding events
 		 * @param listener listener to remove
--- a/engine/core/eventchannel/eventchannel.i	Sat Feb 20 21:41:43 2010 +0000
+++ b/engine/core/eventchannel/eventchannel.i	Mon Feb 22 21:23:01 2010 +0000
@@ -179,10 +179,13 @@
 		EventManager();
 		virtual ~EventManager();
 		void addCommandListener(ICommandListener* listener);
+		void addCommandListenerFront(ICommandListener* listener);
 		void removeCommandListener(ICommandListener* listener);
 		void addKeyListener(IKeyListener* listener);
+		void addKeyListenerFront(IKeyListener* listener);
 		void removeKeyListener(IKeyListener* listener);
 		void addMouseListener(IMouseListener* listener);
+		void addMouseListenerFront(IMouseListener* listener);
 		void removeMouseListener(IMouseListener* listener);
 		EventSourceType getEventSourceType();
 		void dispatchCommand(Command& command);
--- a/engine/core/eventchannel/eventmanager.cpp	Sat Feb 20 21:41:43 2010 +0000
+++ b/engine/core/eventchannel/eventmanager.cpp	Mon Feb 22 21:23:01 2010 +0000
@@ -56,12 +56,12 @@
 	}
 
 	template<typename T>
-	void removeListener(std::vector<T>& vec, T& listener) {
+	void removeListener(std::deque<T>& vec, T& listener) {
 		vec.push_back(listener);
 	}
 
 	template<typename T>
-	void addListener(std::vector<T>& vec, T& listener) {
+	void addListener(std::deque<T>& vec, T& listener) {
 		vec.push_back(listener);
 	}
 
@@ -69,6 +69,10 @@
 		addListener<ICommandListener*>(m_pending_commandlisteners, listener);
 	}
 
+	void EventManager::addCommandListenerFront(ICommandListener* listener) {
+		addListener<ICommandListener*>(m_pending_commandlisteners, listener);
+	}
+
 	void EventManager::removeCommandListener(ICommandListener* listener) {
 		removeListener<ICommandListener*>(m_pending_cldeletions, listener);
 	}
@@ -77,6 +81,10 @@
 		addListener<IKeyListener*>(m_pending_keylisteners, listener);
 	}
 
+	void EventManager::addKeyListenerFront(IKeyListener* listener) {
+		addListener<IKeyListener*>(m_pending_keylisteners_front, listener);
+	}
+
 	void EventManager::removeKeyListener(IKeyListener* listener) {
 		removeListener<IKeyListener*>(m_pending_kldeletions, listener);
 	}
@@ -85,6 +93,10 @@
 		addListener<IMouseListener*>(m_pending_mouselisteners, listener);
 	}
 
+	void EventManager::addMouseListenerFront(IMouseListener* listener) {
+		addListener<IMouseListener*>(m_pending_mouselisteners, listener);
+	}
+
 	void EventManager::removeMouseListener(IMouseListener* listener) {
 		removeListener<IMouseListener*>(m_pending_mldeletions, listener);
 	}
@@ -93,13 +105,17 @@
 		addListener<ISdlEventListener*>(m_pending_sdleventlisteners, listener);
 	}
 
+	void EventManager::addSdlEventListenerFront(ISdlEventListener* listener) {
+		addListener<ISdlEventListener*>(m_pending_sdleventlisteners, listener);
+	}
+
 	void EventManager::removeSdlEventListener(ISdlEventListener* listener) {
 		removeListener<ISdlEventListener*>(m_pending_sdldeletions, listener);
 	}
 
 	void EventManager::dispatchCommand(Command& command) {
 		if(!m_pending_commandlisteners.empty()) {
-			std::vector<ICommandListener*>::iterator i = m_pending_commandlisteners.begin();
+			std::deque<ICommandListener*>::iterator i = m_pending_commandlisteners.begin();
 			while (i != m_pending_commandlisteners.end()) {
 				m_commandlisteners.push_back(*i);
 				++i;
@@ -107,10 +123,19 @@
 			m_pending_commandlisteners.clear();
 		}
 
+		if(!m_pending_commandlisteners_front.empty()) {
+			std::deque<ICommandListener*>::iterator i = m_pending_commandlisteners_front.begin();
+			while (i != m_pending_commandlisteners_front.end()) {
+				m_commandlisteners.push_front(*i);
+				++i;
+			}
+			m_pending_commandlisteners_front.clear();
+		}
+
 		if (!m_pending_cldeletions.empty()) {
-			std::vector<ICommandListener*>::iterator i = m_pending_cldeletions.begin();
+			std::deque<ICommandListener*>::iterator i = m_pending_cldeletions.begin();
 			while (i != m_pending_cldeletions.end()) {
-				std::vector<ICommandListener*>::iterator j = m_commandlisteners.begin();
+				std::deque<ICommandListener*>::iterator j = m_commandlisteners.begin();
 				while (j != m_commandlisteners.end()) {
 					if(*j == *i) {
 						m_commandlisteners.erase(j);
@@ -123,7 +148,7 @@
 			m_pending_cldeletions.clear();
 		}
 
-		std::vector<ICommandListener*>::iterator i = m_commandlisteners.begin();
+		std::deque<ICommandListener*>::iterator i = m_commandlisteners.begin();
 		while (i != m_commandlisteners.end()) {
 			(*i)->onCommand(command);
 			if (command.isConsumed()) {
@@ -135,7 +160,7 @@
 
 	void EventManager::dispatchKeyEvent(KeyEvent& evt) {
 		if(!m_pending_keylisteners.empty()) {
-			std::vector<IKeyListener*>::iterator i = m_pending_keylisteners.begin();
+			std::deque<IKeyListener*>::iterator i = m_pending_keylisteners.begin();
 			while (i != m_pending_keylisteners.end()) {
 				m_keylisteners.push_back(*i);
 				++i;
@@ -143,10 +168,19 @@
 			m_pending_keylisteners.clear();
 		}
 
+		if(!m_pending_keylisteners_front.empty()) {
+			std::deque<IKeyListener*>::iterator i = m_pending_keylisteners_front.begin();
+			while (i != m_pending_keylisteners_front.end()) {
+				m_keylisteners.push_front(*i);
+				++i;
+			}
+			m_pending_keylisteners_front.clear();
+		}
+
 		if (!m_pending_kldeletions.empty()) {
-			std::vector<IKeyListener*>::iterator i = m_pending_kldeletions.begin();
+			std::deque<IKeyListener*>::iterator i = m_pending_kldeletions.begin();
 			while (i != m_pending_kldeletions.end()) {
-				std::vector<IKeyListener*>::iterator j = m_keylisteners.begin();
+				std::deque<IKeyListener*>::iterator j = m_keylisteners.begin();
 				while (j != m_keylisteners.end()) {
 					if(*j == *i) {
 						m_keylisteners.erase(j);
@@ -159,7 +193,7 @@
 			m_pending_kldeletions.clear();
 		}
 
-		std::vector<IKeyListener*>::iterator i = m_keylisteners.begin();
+		std::deque<IKeyListener*>::iterator i = m_keylisteners.begin();
 		while (i != m_keylisteners.end()) {
 			switch (evt.getType()) {
 				case KeyEvent::PRESSED:
@@ -177,7 +211,7 @@
 
 	void EventManager::dispatchMouseEvent(MouseEvent& evt) {
 		if(!m_pending_mouselisteners.empty()) {
-			std::vector<IMouseListener*>::iterator i = m_pending_mouselisteners.begin();
+			std::deque<IMouseListener*>::iterator i = m_pending_mouselisteners.begin();
 			while (i != m_pending_mouselisteners.end()) {
 				m_mouselisteners.push_back(*i);
 				++i;
@@ -185,10 +219,19 @@
 			m_pending_mouselisteners.clear();
 		}
 
+		if(!m_pending_mouselisteners_front.empty()) {
+			std::deque<IMouseListener*>::iterator i = m_pending_mouselisteners_front.begin();
+			while (i != m_pending_mouselisteners_front.end()) {
+				m_mouselisteners.push_front(*i);
+				++i;
+			}
+			m_pending_mouselisteners_front.clear();
+		}
+
 		if (!m_pending_mldeletions.empty()) {
-			std::vector<IMouseListener*>::iterator i = m_pending_mldeletions.begin();
+			std::deque<IMouseListener*>::iterator i = m_pending_mldeletions.begin();
 			while (i != m_pending_mldeletions.end()) {
-				std::vector<IMouseListener*>::iterator j = m_mouselisteners.begin();
+				std::deque<IMouseListener*>::iterator j = m_mouselisteners.begin();
 				while (j != m_mouselisteners.end()) {
 					if(*j == *i) {
 						m_mouselisteners.erase(j);
@@ -201,7 +244,7 @@
 			m_pending_mldeletions.clear();
 		}
 
-		std::vector<IMouseListener*>::iterator i = m_mouselisteners.begin();
+		std::deque<IMouseListener*>::iterator i = m_mouselisteners.begin();
 		while (i != m_mouselisteners.end()) {
 			switch (evt.getType()) {
 				case MouseEvent::MOVED:
@@ -244,7 +287,7 @@
 	bool EventManager::dispatchSdlEvent(SDL_Event& evt) {
 		bool ret = false;
 		if (!m_pending_sdleventlisteners.empty()) {
-			std::vector<ISdlEventListener*>::iterator i = m_pending_sdleventlisteners.begin();
+			std::deque<ISdlEventListener*>::iterator i = m_pending_sdleventlisteners.begin();
 			while(i != m_pending_sdleventlisteners.end()) {
 				m_sdleventlisteners.push_back(*i);
 				++i;
@@ -252,10 +295,19 @@
 			m_pending_sdleventlisteners.clear();
 		}
 
+		if (!m_pending_sdleventlisteners_front.empty()) {
+			std::deque<ISdlEventListener*>::iterator i = m_pending_sdleventlisteners_front.begin();
+			while(i != m_pending_sdleventlisteners_front.end()) {
+				m_sdleventlisteners.push_front(*i);
+				++i;
+			}
+			m_pending_sdleventlisteners_front.clear();
+		}
+
 		if (!m_pending_sdldeletions.empty()) {
-			std::vector<ISdlEventListener*>::iterator i = m_pending_sdldeletions.begin();
+			std::deque<ISdlEventListener*>::iterator i = m_pending_sdldeletions.begin();
 			while (i != m_pending_sdldeletions.end()) {
-				std::vector<ISdlEventListener*>::iterator j = m_sdleventlisteners.begin();
+				std::deque<ISdlEventListener*>::iterator j = m_sdleventlisteners.begin();
 				while (j != m_sdleventlisteners.end()) {
 					if(*j == *i) {
 						m_sdleventlisteners.erase(j);
@@ -268,7 +320,7 @@
 			m_pending_sdldeletions.clear();
 		}
 
-		std::vector<ISdlEventListener*>::iterator i = m_sdleventlisteners.begin();
+		std::deque<ISdlEventListener*>::iterator i = m_sdleventlisteners.begin();
 		while (i != m_sdleventlisteners.end()) {
 			ret = ret || (*i)->onSdlEvent(evt);
 			++i;
@@ -468,7 +520,7 @@
 		keyevt.setNumericPad(keysym.sym >= SDLK_KP0 && keysym.sym <= SDLK_KP_EQUALS);
 		keyevt.setKey(Key(static_cast<Key::KeyType>(keysym.sym), keysym.unicode));
 	}
-	
+
 	void EventManager::fillModifiers(InputEvent& evt) {
 		evt.setAltPressed(m_keystatemap[Key::ALT_GR] |
 			m_keystatemap[Key::LEFT_ALT] |
--- a/engine/core/eventchannel/eventmanager.h	Sat Feb 20 21:41:43 2010 +0000
+++ b/engine/core/eventchannel/eventmanager.h	Mon Feb 22 21:23:01 2010 +0000
@@ -24,7 +24,7 @@
 
 // Standard C++ library includes
 //
-#include <vector>
+#include <deque>
 #include <map>
 #include <list>
 
@@ -64,11 +64,11 @@
 
 	/**  Event Manager manages all events related to FIFE
 	 */
-	class EventManager: 
+	class EventManager:
 		public ICommandController,
-		public IKeyController, 
-		public IMouseController, 
-		public ISdlEventController, 
+		public IKeyController,
+		public IMouseController,
+		public ISdlEventController,
 		public IEventSource,
 		public ITriggerController {
 	public:
@@ -81,13 +81,17 @@
 		virtual ~EventManager();
 
 		void addCommandListener(ICommandListener* listener);
+		void addCommandListenerFront(ICommandListener* listener);
 		void removeCommandListener(ICommandListener* listener);
 		void dispatchCommand(Command& command);
 		void addKeyListener(IKeyListener* listener);
+		void addKeyListenerFront(IKeyListener* listener);
 		void removeKeyListener(IKeyListener* listener);
 		void addMouseListener(IMouseListener* listener);
+		void addMouseListenerFront(IMouseListener* listener);
 		void removeMouseListener(IMouseListener* listener);
 		void addSdlEventListener(ISdlEventListener* listener);
+		void addSdlEventListenerFront(ISdlEventListener* listener);
 		void removeSdlEventListener(ISdlEventListener* listener);
 		EventSourceType getEventSourceType();
 
@@ -95,7 +99,7 @@
 		void unregisterTrigger(Trigger& trigger);
 
 		/** Process the SDL event queue.
-		 * This is to be called only by the engine itself once per frame. 
+		 * This is to be called only by the engine itself once per frame.
 		 * It passes appropriate events to their listeners
 		 */
 		void processEvents();
@@ -120,22 +124,26 @@
 		void fillMouseEvent(const SDL_Event& sdlevt, MouseEvent& mouseevt);
 
 		void pollTriggers();
-		
-		std::vector<ICommandListener*> m_commandlisteners;
-		std::vector<ICommandListener*> m_pending_commandlisteners;
-		std::vector<ICommandListener*> m_pending_cldeletions;
+
+		std::deque<ICommandListener*> m_commandlisteners;
+		std::deque<ICommandListener*> m_pending_commandlisteners;
+		std::deque<ICommandListener*> m_pending_commandlisteners_front;
+		std::deque<ICommandListener*> m_pending_cldeletions;
 
-		std::vector<IKeyListener*> m_keylisteners;
-		std::vector<IKeyListener*> m_pending_keylisteners;
-		std::vector<IKeyListener*> m_pending_kldeletions;
+		std::deque<IKeyListener*> m_keylisteners;
+		std::deque<IKeyListener*> m_pending_keylisteners;
+		std::deque<IKeyListener*> m_pending_keylisteners_front;
+		std::deque<IKeyListener*> m_pending_kldeletions;
 
-		std::vector<IMouseListener*> m_mouselisteners;
-		std::vector<IMouseListener*> m_pending_mouselisteners;
-		std::vector<IMouseListener*> m_pending_mldeletions;
+		std::deque<IMouseListener*> m_mouselisteners;
+		std::deque<IMouseListener*> m_pending_mouselisteners;
+		std::deque<IMouseListener*> m_pending_mouselisteners_front;
+		std::deque<IMouseListener*> m_pending_mldeletions;
 
-		std::vector<ISdlEventListener*> m_sdleventlisteners;
-		std::vector<ISdlEventListener*> m_pending_sdleventlisteners;
-		std::vector<ISdlEventListener*> m_pending_sdldeletions;
+		std::deque<ISdlEventListener*> m_sdleventlisteners;
+		std::deque<ISdlEventListener*> m_pending_sdleventlisteners;
+		std::deque<ISdlEventListener*> m_pending_sdleventlisteners_front;
+		std::deque<ISdlEventListener*> m_pending_sdldeletions;
 
 		std::map<int, bool> m_keystatemap;
 		IKeyFilter* m_keyfilter;
--- a/engine/core/eventchannel/key/ec_ikeycontroller.h	Sat Feb 20 21:41:43 2010 +0000
+++ b/engine/core/eventchannel/key/ec_ikeycontroller.h	Mon Feb 22 21:23:01 2010 +0000
@@ -43,12 +43,18 @@
 	class IKeyController {
 	public:
 
-		/** Adds a listener to the controller
+		/** Adds a listener to the back of the listener deque
 		 * Listener will be notified via the corresponding events
 		 * @param listener listener to add
 		 */
 		virtual void addKeyListener(IKeyListener* listener) = 0;
 
+		/** Adds a listener to the front of the listener deque
+		 * Listener will be notified via the corresponding events
+		 * @param listener listener to add
+		 */
+		virtual void addKeyListenerFront(IKeyListener* listener) = 0;
+
 		/** Removes an added listener from the controller.
 		 * Listener will not be notified anymore via the corresponding events
 		 * @param listener listener to remove
--- a/engine/core/eventchannel/mouse/ec_imousecontroller.h	Sat Feb 20 21:41:43 2010 +0000
+++ b/engine/core/eventchannel/mouse/ec_imousecontroller.h	Mon Feb 22 21:23:01 2010 +0000
@@ -36,19 +36,25 @@
 
 namespace FIFE {
 	class IMouseListener;
-	
+
 	/**  Controller provides a way to receive events from the system
 	 * Using this interface, clients can subscribe themselves to receive events
 	 */
 	class IMouseController {
 	public:
 
-		/** Adds a listener to the controller
+		/** Adds a listener to the back of the listener deque
 		 * Listener will be notified via the corresponding events
 		 * @param listener listener to add
 		 */
 		virtual void addMouseListener(IMouseListener* listener) = 0;
 
+		/** Adds a listener to the front of the listener deque
+		 * Listener will be notified via the corresponding events
+		 * @param listener listener to add
+		 */
+		virtual void addMouseListenerFront(IMouseListener* listener) = 0;
+
 		/** Removes an added listener from the controller.
 		 * Listener will not be notified anymore via the corresponding events
 		 * @param listener listener to remove
--- a/engine/core/eventchannel/sdl/ec_isdleventcontroller.h	Sat Feb 20 21:41:43 2010 +0000
+++ b/engine/core/eventchannel/sdl/ec_isdleventcontroller.h	Mon Feb 22 21:23:01 2010 +0000
@@ -43,12 +43,18 @@
 	class ISdlEventController {
 	public:
 
-		/** Adds a listener to the controller
+		/** Adds a listener to the back of the listener deque
 		 * Listener will be notified via the corresponding events
 		 * @param listener listener to add
 		 */
 		virtual void addSdlEventListener(ISdlEventListener* listener) = 0;
 
+		/** Adds a listener to the front of the listener deque
+		 * Listener will be notified via the corresponding events
+		 * @param listener listener to add
+		 */
+		virtual void addSdlEventListenerFront(ISdlEventListener* listener) = 0;
+
 		/** Removes an added listener from the controller.
 		 * Listener will not be notified anymore via the corresponding events
 		 * @param listener listener to remove