# HG changeset patch # User spq@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1216805805 0 # Node ID c512dff398c231b02e3a30752ed7d0fe75f2de80 # Parent af9a5579763e6b8ead9beb2aed2675e70eccbdeb combine events (currently only mouse motion events), that helps reducing lag in clients diff -r af9a5579763e -r c512dff398c2 engine/core/eventchannel/eventmanager.cpp --- a/engine/core/eventchannel/eventmanager.cpp Wed Jul 23 02:28:46 2008 +0000 +++ b/engine/core/eventchannel/eventmanager.cpp Wed Jul 23 09:36:45 2008 +0000 @@ -498,9 +498,30 @@ dispatchWidgetEvent(evt); } + bool EventManager::combineEvents(SDL_Event& event1, const SDL_Event& event2) { + if(event1.type == event2.type) { + switch (event1.type) { + case SDL_MOUSEMOTION: + if(event1.motion.state == event2.motion.state) { + event1.motion.x = event2.motion.x; + event1.motion.y = event2.motion.y; + event1.motion.xrel += event2.motion.xrel; + event1.motion.yrel += event2.motion.yrel; + return true; + } + return false; + } + } + return false; + } + void EventManager::processEvents(){ - SDL_Event event; - while (SDL_PollEvent(&event)) { + SDL_Event event, newevent; + bool has_event = SDL_PollEvent(&event); + while (has_event) { + has_event = SDL_PollEvent(&newevent); + if(has_event && combineEvents(event, newevent)) + continue; dispatchSdlEvent(event); switch (event.type) { case SDL_QUIT: { @@ -570,6 +591,8 @@ } break; } + if(has_event) + event = newevent; } pollTriggers(); diff -r af9a5579763e -r c512dff398c2 engine/core/eventchannel/eventmanager.h --- a/engine/core/eventchannel/eventmanager.h Wed Jul 23 02:28:46 2008 +0000 +++ b/engine/core/eventchannel/eventmanager.h Wed Jul 23 09:36:45 2008 +0000 @@ -112,6 +112,7 @@ void processEvents(); private: + bool combineEvents(SDL_Event& event1, const SDL_Event& event2); void dispatchKeyEvent(KeyEvent& evt); void dispatchMouseEvent(MouseEvent& evt); void dispatchSdlEvent(SDL_Event& evt);