changeset 103:c512dff398c2

combine events (currently only mouse motion events), that helps reducing lag in clients
author spq@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 23 Jul 2008 09:36:45 +0000
parents af9a5579763e
children 2c7101e4d81d
files engine/core/eventchannel/eventmanager.cpp engine/core/eventchannel/eventmanager.h
diffstat 2 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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();
--- 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);