# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1266873781 0 # Node ID a1884665aa95fadfb4a1af1771a2f0ca5d5f6125 # Parent 68aa65e5bd9cc547ee6cb95fd830965643aabe1a Added the ability to add an event listener to the front of the event listener deque in the event manager. fixes[t:454] diff -r 68aa65e5bd9c -r a1884665aa95 engine/core/eventchannel/command/ec_icommandcontroller.h --- 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 diff -r 68aa65e5bd9c -r a1884665aa95 engine/core/eventchannel/eventchannel.i --- 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); diff -r 68aa65e5bd9c -r a1884665aa95 engine/core/eventchannel/eventmanager.cpp --- 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 - void removeListener(std::vector& vec, T& listener) { + void removeListener(std::deque& vec, T& listener) { vec.push_back(listener); } template - void addListener(std::vector& vec, T& listener) { + void addListener(std::deque& vec, T& listener) { vec.push_back(listener); } @@ -69,6 +69,10 @@ addListener(m_pending_commandlisteners, listener); } + void EventManager::addCommandListenerFront(ICommandListener* listener) { + addListener(m_pending_commandlisteners, listener); + } + void EventManager::removeCommandListener(ICommandListener* listener) { removeListener(m_pending_cldeletions, listener); } @@ -77,6 +81,10 @@ addListener(m_pending_keylisteners, listener); } + void EventManager::addKeyListenerFront(IKeyListener* listener) { + addListener(m_pending_keylisteners_front, listener); + } + void EventManager::removeKeyListener(IKeyListener* listener) { removeListener(m_pending_kldeletions, listener); } @@ -85,6 +93,10 @@ addListener(m_pending_mouselisteners, listener); } + void EventManager::addMouseListenerFront(IMouseListener* listener) { + addListener(m_pending_mouselisteners, listener); + } + void EventManager::removeMouseListener(IMouseListener* listener) { removeListener(m_pending_mldeletions, listener); } @@ -93,13 +105,17 @@ addListener(m_pending_sdleventlisteners, listener); } + void EventManager::addSdlEventListenerFront(ISdlEventListener* listener) { + addListener(m_pending_sdleventlisteners, listener); + } + void EventManager::removeSdlEventListener(ISdlEventListener* listener) { removeListener(m_pending_sdldeletions, listener); } void EventManager::dispatchCommand(Command& command) { if(!m_pending_commandlisteners.empty()) { - std::vector::iterator i = m_pending_commandlisteners.begin(); + std::deque::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::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::iterator i = m_pending_cldeletions.begin(); + std::deque::iterator i = m_pending_cldeletions.begin(); while (i != m_pending_cldeletions.end()) { - std::vector::iterator j = m_commandlisteners.begin(); + std::deque::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::iterator i = m_commandlisteners.begin(); + std::deque::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::iterator i = m_pending_keylisteners.begin(); + std::deque::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::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::iterator i = m_pending_kldeletions.begin(); + std::deque::iterator i = m_pending_kldeletions.begin(); while (i != m_pending_kldeletions.end()) { - std::vector::iterator j = m_keylisteners.begin(); + std::deque::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::iterator i = m_keylisteners.begin(); + std::deque::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::iterator i = m_pending_mouselisteners.begin(); + std::deque::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::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::iterator i = m_pending_mldeletions.begin(); + std::deque::iterator i = m_pending_mldeletions.begin(); while (i != m_pending_mldeletions.end()) { - std::vector::iterator j = m_mouselisteners.begin(); + std::deque::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::iterator i = m_mouselisteners.begin(); + std::deque::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::iterator i = m_pending_sdleventlisteners.begin(); + std::deque::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::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::iterator i = m_pending_sdldeletions.begin(); + std::deque::iterator i = m_pending_sdldeletions.begin(); while (i != m_pending_sdldeletions.end()) { - std::vector::iterator j = m_sdleventlisteners.begin(); + std::deque::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::iterator i = m_sdleventlisteners.begin(); + std::deque::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(keysym.sym), keysym.unicode)); } - + void EventManager::fillModifiers(InputEvent& evt) { evt.setAltPressed(m_keystatemap[Key::ALT_GR] | m_keystatemap[Key::LEFT_ALT] | diff -r 68aa65e5bd9c -r a1884665aa95 engine/core/eventchannel/eventmanager.h --- 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 +#include #include #include @@ -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 m_commandlisteners; - std::vector m_pending_commandlisteners; - std::vector m_pending_cldeletions; + + std::deque m_commandlisteners; + std::deque m_pending_commandlisteners; + std::deque m_pending_commandlisteners_front; + std::deque m_pending_cldeletions; - std::vector m_keylisteners; - std::vector m_pending_keylisteners; - std::vector m_pending_kldeletions; + std::deque m_keylisteners; + std::deque m_pending_keylisteners; + std::deque m_pending_keylisteners_front; + std::deque m_pending_kldeletions; - std::vector m_mouselisteners; - std::vector m_pending_mouselisteners; - std::vector m_pending_mldeletions; + std::deque m_mouselisteners; + std::deque m_pending_mouselisteners; + std::deque m_pending_mouselisteners_front; + std::deque m_pending_mldeletions; - std::vector m_sdleventlisteners; - std::vector m_pending_sdleventlisteners; - std::vector m_pending_sdldeletions; + std::deque m_sdleventlisteners; + std::deque m_pending_sdleventlisteners; + std::deque m_pending_sdleventlisteners_front; + std::deque m_pending_sdldeletions; std::map m_keystatemap; IKeyFilter* m_keyfilter; diff -r 68aa65e5bd9c -r a1884665aa95 engine/core/eventchannel/key/ec_ikeycontroller.h --- 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 diff -r 68aa65e5bd9c -r a1884665aa95 engine/core/eventchannel/mouse/ec_imousecontroller.h --- 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 diff -r 68aa65e5bd9c -r a1884665aa95 engine/core/eventchannel/sdl/ec_isdleventcontroller.h --- 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