[openjk] 05/15: Shared: Fix Sys_QueEvent overflow on mouse events

Simon McVittie smcv at debian.org
Thu Jun 15 10:28:40 UTC 2017


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian/master
in repository openjk.

commit c9e1de88ab965adfb547aec2ae0d7a804ba7b4f8
Author: Ensiform <ensiform at gmail.com>
Date:   Sat May 13 22:21:02 2017 -0500

    Shared: Fix Sys_QueEvent overflow on mouse events
    
    This was a bug that is introduced in all known tech3 engines using SDL even the original SDL unix ports by TTimo.  But is mostly only noticeable on newer machines and with high DPI mice.
    
    What this patch does is consolodates mouse events into one event when sent together to avoid the spam.  Coincidentally we can probably even reduce the queue size because I doubt it would ever reach half of what it is at now.
    
    Fix comes from https://github.com/ec-/Quake3e eugene (ec-). Multiple commits across code/qcommon/common.c so I'm not going to list the exact hashes.
---
 shared/sys/sys_event.cpp | 71 ++++++++++++++++++++++++++++++------------------
 shared/sys/sys_public.h  |  3 +-
 2 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/shared/sys/sys_event.cpp b/shared/sys/sys_event.cpp
index 39dc5c5..6bf884f 100644
--- a/shared/sys/sys_event.cpp
+++ b/shared/sys/sys_event.cpp
@@ -38,7 +38,26 @@ EVENT LOOP
 #define	MASK_QUED_EVENTS	( MAX_QUED_EVENTS - 1 )
 
 static sysEvent_t	eventQue[MAX_QUED_EVENTS] = {};
-static int			eventHead = 0, eventTail = 0;
+static sysEvent_t	*lastEvent = nullptr;
+static uint32_t		eventHead = 0, eventTail = 0;
+
+static const char *Sys_EventName( sysEventType_t evType ) {
+
+	static const char *evNames[SE_MAX] = {
+		"SE_NONE",
+		"SE_KEY",
+		"SE_CHAR",
+		"SE_MOUSE",
+		"SE_JOYSTICK_AXIS",
+		"SE_CONSOLE"
+	};
+
+	if ( evType >= SE_MAX ) {
+		return "SE_UNKNOWN";
+	} else {
+		return evNames[evType];
+	}
+}
 
 sysEvent_t Sys_GetEvent( void ) {
 	sysEvent_t	ev;
@@ -85,47 +104,47 @@ Ptr should either be null, or point to a block of data that can
 be freed by the game later.
 ================
 */
-void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr ) {
+void Sys_QueEvent( int evTime, sysEventType_t evType, int value, int value2, int ptrLength, void *ptr ) {
 	sysEvent_t	*ev;
-#ifndef _DEBUG
-	static bool printedWarning = false;
-#endif
+
+	if ( evTime == 0 ) {
+		evTime = Sys_Milliseconds();
+	}
+
+	// try to combine all sequential mouse moves in one event
+	if ( evType == SE_MOUSE && lastEvent && lastEvent->evType == SE_MOUSE ) {
+		// try to reuse already processed item
+		if ( eventTail == eventHead ) {
+			lastEvent->evValue = value;
+			lastEvent->evValue2 = value2;
+			eventTail--;
+		} else {
+			lastEvent->evValue += value;
+			lastEvent->evValue2 += value2;
+		}
+		lastEvent->evTime = evTime;
+		return;
+	}
 
 	ev = &eventQue[ eventHead & MASK_QUED_EVENTS ];
 
 	if ( eventHead - eventTail >= MAX_QUED_EVENTS ) {
-		// Spam less often from Com_PushEvent
-#ifndef _DEBUG
-		if ( !printedWarning ) {
-			Com_Printf( "Sys_QueEvent: overflow (event type %i) (value: %i) (value2: %i)\n", type, value, value2 );
-			printedWarning = true;
-		}
-#else
-		Com_Printf( "Sys_QueEvent: overflow (event type %i) (value: %i) (value2: %i)\n", type, value, value2 );
-#endif
+		Com_Printf( "Sys_QueEvent(%s,time=%i): overflow\n", Sys_EventName(evType), evTime );
 		// we are discarding an event, but don't leak memory
 		if ( ev->evPtr ) {
 			Z_Free( ev->evPtr );
 		}
 		eventTail++;
 	}
-#ifndef _DEBUG
-	else
-	{
-		printedWarning = false;
-	}
-#endif
 
 	eventHead++;
 
-	if ( time == 0 ) {
-		time = Sys_Milliseconds();
-	}
-
-	ev->evTime = time;
-	ev->evType = type;
+	ev->evTime = evTime;
+	ev->evType = evType;
 	ev->evValue = value;
 	ev->evValue2 = value2;
 	ev->evPtrLength = ptrLength;
 	ev->evPtr = ptr;
+
+	lastEvent = ev;
 }
diff --git a/shared/sys/sys_public.h b/shared/sys/sys_public.h
index f9ba3e6..15ca164 100644
--- a/shared/sys/sys_public.h
+++ b/shared/sys/sys_public.h
@@ -67,7 +67,8 @@ typedef enum {
 	SE_CHAR,	// evValue is an ascii char
 	SE_MOUSE,	// evValue and evValue2 are reletive signed x / y moves
 	SE_JOYSTICK_AXIS,	// evValue is an axis number and evValue2 is the current state (-127 to 127)
-	SE_CONSOLE	// evPtr is a char*
+	SE_CONSOLE,	// evPtr is a char*
+	SE_MAX
 } sysEventType_t;
 
 typedef struct sysEvent_s {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git



More information about the Pkg-games-commits mailing list