r1158 - in branches/unified-sdl: . code/qcommon code/sdl code/sys

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Sep 5 12:07:30 EDT 2007


Author: tma
Date: 2007-09-05 12:07:30 -0400 (Wed, 05 Sep 2007)
New Revision: 1158

Modified:
   branches/unified-sdl/README
   branches/unified-sdl/code/qcommon/common.c
   branches/unified-sdl/code/qcommon/qcommon.h
   branches/unified-sdl/code/sdl/sdl_input.c
   branches/unified-sdl/code/sys/sys_local.h
   branches/unified-sdl/code/sys/sys_main.c
Log:
* Move Sys event queueing into Com, since it's not really system specific
* Move Idling code from main to Sys_Idle
* Clean up sys_local.h
* static-ise and rearrange some IN_ functions


Modified: branches/unified-sdl/README
===================================================================
--- branches/unified-sdl/README	2007-09-05 14:28:06 UTC (rev 1157)
+++ branches/unified-sdl/README	2007-09-05 16:07:30 UTC (rev 1158)
@@ -132,6 +132,7 @@
   com_altivec                       - enable use of altivec on PowerPC systems
   s_backend                         - read only, indicates the current sound
                                       backend
+  s_muteWhenMinimized               - mute sound when minimized
   in_joystickNo                     - select which joystick to use
   cl_consoleHistory                 - read only, stores the console history
   cl_platformSensitivity            - read only, indicates the mouse input

Modified: branches/unified-sdl/code/qcommon/common.c
===================================================================
--- branches/unified-sdl/code/qcommon/common.c	2007-09-05 14:28:06 UTC (rev 1157)
+++ branches/unified-sdl/code/qcommon/common.c	2007-09-05 16:07:30 UTC (rev 1158)
@@ -1920,6 +1920,125 @@
 }
 
 /*
+========================================================================
+
+EVENT LOOP
+
+========================================================================
+*/
+
+#define MAX_QUEUED_EVENTS  256
+#define MASK_QUEUED_EVENTS ( MAX_QUEUED_EVENTS - 1 )
+
+static sysEvent_t  eventQueue[ MAX_QUEUED_EVENTS ];
+static int         eventHead = 0;
+static int         eventTail = 0;
+static byte        sys_packetReceived[ MAX_MSGLEN ];
+
+/*
+================
+Com_QueueEvent
+
+A time of 0 will get the current time
+Ptr should either be null, or point to a block of data that can
+be freed by the game later.
+================
+*/
+void Com_QueueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr )
+{
+	sysEvent_t  *ev;
+
+	ev = &eventQueue[ eventHead & MASK_QUEUED_EVENTS ];
+
+	if ( eventHead - eventTail >= MAX_QUEUED_EVENTS )
+	{
+		Com_Printf("Com_QueueEvent: overflow\n");
+		// we are discarding an event, but don't leak memory
+		if ( ev->evPtr )
+		{
+			Z_Free( ev->evPtr );
+		}
+		eventTail++;
+	}
+
+	eventHead++;
+
+	if ( time == 0 )
+	{
+		time = Sys_Milliseconds();
+	}
+
+	ev->evTime = time;
+	ev->evType = type;
+	ev->evValue = value;
+	ev->evValue2 = value2;
+	ev->evPtrLength = ptrLength;
+	ev->evPtr = ptr;
+}
+
+/*
+================
+Com_GetSystemEvent
+
+================
+*/
+sysEvent_t Com_GetSystemEvent( void )
+{
+	sysEvent_t  ev;
+	char        *s;
+	msg_t       netmsg;
+	netadr_t    adr;
+
+	// return if we have data
+	if ( eventHead > eventTail )
+	{
+		eventTail++;
+		return eventQueue[ ( eventTail - 1 ) & MASK_QUEUED_EVENTS ];
+	}
+
+	// check for console commands
+	s = Sys_ConsoleInput();
+	if ( s )
+	{
+		char  *b;
+		int   len;
+
+		len = strlen( s ) + 1;
+		b = Z_Malloc( len );
+		strcpy( b, s );
+		Com_QueueEvent( 0, SE_CONSOLE, 0, 0, len, b );
+	}
+
+	// check for network packets
+	MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) );
+	if ( Sys_GetPacket ( &adr, &netmsg ) )
+	{
+		netadr_t  *buf;
+		int       len;
+
+		// copy out to a seperate buffer for qeueing
+		len = sizeof( netadr_t ) + netmsg.cursize;
+		buf = Z_Malloc( len );
+		*buf = adr;
+		memcpy( buf+1, netmsg.data, netmsg.cursize );
+		Com_QueueEvent( 0, SE_PACKET, 0, 0, len, buf );
+	}
+
+	// return if we have data
+	if ( eventHead > eventTail )
+	{
+		eventTail++;
+		return eventQueue[ ( eventTail - 1 ) & MASK_QUEUED_EVENTS ];
+	}
+
+	// create an empty event to return
+	memset( &ev, 0, sizeof( ev ) );
+	ev.evTime = Sys_Milliseconds();
+
+	return ev;
+}
+
+/*
 =================
 Com_GetRealEvent
 =================
@@ -1942,7 +2061,7 @@
 			}
 		}
 	} else {
-		ev = Sys_GetEvent();
+		ev = Com_GetSystemEvent();
 
 		// write the journal value out if needed
 		if ( com_journal->integer == 1 ) {
@@ -2379,6 +2498,10 @@
 		Sys_Error ("Error during initialization");
 	}
 
+	// Clear queues
+	Com_Memset( &eventQueue[ 0 ], 0, MAX_QUEUED_EVENTS * sizeof( sysEvent_t ) );
+	Com_Memset( &sys_packetReceived[ 0 ], 0, MAX_MSGLEN * sizeof( byte ) );
+
   // do this before anything else decides to push events
   Com_InitPushEvent();
 

Modified: branches/unified-sdl/code/qcommon/qcommon.h
===================================================================
--- branches/unified-sdl/code/qcommon/qcommon.h	2007-09-05 14:28:06 UTC (rev 1157)
+++ branches/unified-sdl/code/qcommon/qcommon.h	2007-09-05 16:07:30 UTC (rev 1158)
@@ -715,6 +715,30 @@
 // centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
 #define	MAXPRINTMSG	4096
 
+
+typedef enum {
+	// SE_NONE must be zero
+	SE_NONE = 0,	// evTime is still valid
+	SE_KEY,		// evValue is a key code, evValue2 is the down flag
+	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_PACKET	// evPtr is a netadr_t followed by data bytes to evPtrLength
+} sysEventType_t;
+
+typedef struct {
+	int				evTime;
+	sysEventType_t	evType;
+	int				evValue, evValue2;
+	int				evPtrLength;	// bytes of data pointed to by evPtr, for journaling
+	void			*evPtr;			// this must be manually freed if not NULL
+} sysEvent_t;
+
+void		Com_QueueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr );
+int			Com_EventLoop( void );
+sysEvent_t	Com_GetSystemEvent( void );
+
 char		*CopyString( const char *in );
 void		Info_Print( const char *s );
 
@@ -724,7 +748,7 @@
 void 		QDECL Com_DPrintf( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2)));
 void 		QDECL Com_Error( int code, const char *fmt, ... ) __attribute__ ((format (printf, 2, 3)));
 void 		Com_Quit_f( void );
-int			Com_EventLoop( void );
+
 int			Com_Milliseconds( void );	// will be journaled properly
 unsigned	Com_BlockChecksum( const void *buffer, int length );
 char		*Com_MD5File(const char *filename, int length, const char *prefix, int prefix_len);
@@ -942,27 +966,6 @@
 	MAX_JOYSTICK_AXIS
 } joystickAxis_t;
 
-typedef enum {
-	// SE_NONE must be zero
-	SE_NONE = 0,	// evTime is still valid
-	SE_KEY,		// evValue is a key code, evValue2 is the down flag
-	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_PACKET	// evPtr is a netadr_t followed by data bytes to evPtrLength
-} sysEventType_t;
-
-typedef struct {
-	int				evTime;
-	sysEventType_t	evType;
-	int				evValue, evValue2;
-	int				evPtrLength;	// bytes of data pointed to by evPtr, for journaling
-	void			*evPtr;			// this must be manually freed if not NULL
-} sysEvent_t;
-
-sysEvent_t	Sys_GetEvent( void );
-
 void	Sys_Init (void);
 
 // general development dll loading for virtual machine testing
@@ -1007,6 +1010,7 @@
 void	Sys_SetErrorText( const char *text );
 
 void	Sys_SendPacket( int length, const void *data, netadr_t to );
+qboolean Sys_GetPacket( netadr_t *net_from, msg_t *net_message );
 
 qboolean	Sys_StringToAdr( const char *s, netadr_t *a );
 //Does NOT parse port numbers, only base addresses.
@@ -1022,6 +1026,7 @@
 char	*Sys_DefaultHomePath(void);
 const char *Sys_Dirname( char *path );
 const char *Sys_Basename( char *path );
+char *Sys_ConsoleInput(void);
 
 char **Sys_ListFiles( const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs );
 void	Sys_FreeFileList( char **list );

Modified: branches/unified-sdl/code/sdl/sdl_input.c
===================================================================
--- branches/unified-sdl/code/sdl/sdl_input.c	2007-09-05 14:28:06 UTC (rev 1157)
+++ branches/unified-sdl/code/sdl/sdl_input.c	2007-09-05 16:07:30 UTC (rev 1158)
@@ -56,11 +56,11 @@
 static cvar_t *in_disablemacosxmouseaccel;
 static double originalMouseSpeed = -1.0;
 #endif
-cvar_t *in_nograb;
+static cvar_t *in_nograb;
 
-cvar_t *in_joystick          = NULL;
-cvar_t *in_joystickDebug     = NULL;
-cvar_t *in_joystickThreshold = NULL;
+static cvar_t *in_joystick          = NULL;
+static cvar_t *in_joystickDebug     = NULL;
+static cvar_t *in_joystickThreshold = NULL;
 
 /*
 ===============
@@ -214,7 +214,7 @@
 IN_GetIOHandle
 ===============
 */
-io_connect_t IN_GetIOHandle() // mac os x mouse accel hack
+static io_connect_t IN_GetIOHandle() // mac os x mouse accel hack
 {
 	io_connect_t iohandle = MACH_PORT_NULL;
 	kern_return_t status;
@@ -241,7 +241,7 @@
 IN_ActivateMouse
 ===============
 */
-void IN_ActivateMouse( void )
+static void IN_ActivateMouse( void )
 {
 	if (!mouseAvailable || !SDL_WasInit( SDL_INIT_VIDEO ) )
 		return;
@@ -316,7 +316,7 @@
 IN_DeactivateMouse
 ===============
 */
-void IN_DeactivateMouse( void )
+static void IN_DeactivateMouse( void )
 {
 	if (!mouseAvailable || !SDL_WasInit( SDL_INIT_VIDEO ) )
 		return;
@@ -349,169 +349,6 @@
 	}
 }
 
-/*
-===============
-IN_Init
-===============
-*/
-void IN_Init(void)
-{
-	if( !SDL_WasInit( SDL_INIT_VIDEO ) )
-	{
-		Com_Error( ERR_FATAL, "IN_Init called before SDL_Init( SDL_INIT_VIDEO )\n" );
-		return;
-	}
-
-	Com_DPrintf ("\n------- Input Initialization -------\n");
-
-	// mouse variables
-	in_mouse = Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE);
-	in_nograb = Cvar_Get ("in_nograb", "0", CVAR_ARCHIVE);
-
-	in_joystick = Cvar_Get ("in_joystick", "0", CVAR_ARCHIVE|CVAR_LATCH);
-	in_joystickDebug = Cvar_Get ("in_debugjoystick", "0", CVAR_TEMP);
-	in_joystickThreshold = Cvar_Get ("in_joystickThreshold", "0.15", CVAR_ARCHIVE);
-
-#ifdef MACOS_X_ACCELERATION_HACK
-	in_disablemacosxmouseaccel = Cvar_Get ("in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE);
-#endif
-
-	Cvar_Set( "cl_platformSensitivity", "1.0" );
-
-	SDL_EnableUNICODE(1);
-	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-	keyRepeatEnabled = qtrue;
-
-	if (in_mouse->value)
-		mouseAvailable = qtrue;
-	else
-		mouseAvailable = qfalse;
-
-	IN_StartupJoystick( );
-	Com_DPrintf ("------------------------------------\n");
-}
-
-/*
-===============
-IN_Shutdown
-===============
-*/
-void IN_Shutdown(void)
-{
-	IN_DeactivateMouse();
-
-	mouseAvailable = qfalse;
-
-	if (stick)
-	{
-		SDL_JoystickClose(stick);
-		stick = NULL;
-	}
-
-	SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
-}
-
-/*
-===============
-IN_ProcessEvents
-===============
-*/
-static void IN_ProcessEvents( void )
-{
-	SDL_Event e;
-	const char *p = NULL;
-	int key = 0;
-
-	if( !SDL_WasInit( SDL_INIT_VIDEO ) )
-			return;
-
-	if( cls.keyCatchers == 0 && keyRepeatEnabled )
-	{
-		SDL_EnableKeyRepeat( 0, 0 );
-		keyRepeatEnabled = qfalse;
-	}
-	else if( !keyRepeatEnabled )
-	{
-		SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY,
-			SDL_DEFAULT_REPEAT_INTERVAL );
-		keyRepeatEnabled = qtrue;
-	}
-
-	while (SDL_PollEvent(&e))
-	{
-		switch (e.type)
-		{
-			case SDL_KEYDOWN:
-				IN_PrintKey(&e);
-				p = IN_TranslateSDLToQ3Key(&e.key.keysym, &key);
-				if( key )
-					Sys_QueEvent( 0, SE_KEY, key, qtrue, 0, NULL );
-
-				if( p )
-				{
-					while( *p )
-						Sys_QueEvent( 0, SE_CHAR, *p++, 0, 0, NULL );
-				}
-				break;
-
-			case SDL_KEYUP:
-				IN_TranslateSDLToQ3Key(&e.key.keysym, &key);
-				Sys_QueEvent( 0, SE_KEY, key, qfalse, 0, NULL );
-				break;
-
-			case SDL_MOUSEMOTION:
-				if (mouseActive)
-					Sys_QueEvent( 0, SE_MOUSE, e.motion.xrel, e.motion.yrel, 0, NULL );
-				break;
-
-			case SDL_MOUSEBUTTONDOWN:
-			case SDL_MOUSEBUTTONUP:
-				{
-					unsigned char b;
-					switch (e.button.button)
-					{
-						case 1:   b = K_MOUSE1;     break;
-						case 2:   b = K_MOUSE3;     break;
-						case 3:   b = K_MOUSE2;     break;
-						case 4:   b = K_MWHEELUP;   break;
-						case 5:   b = K_MWHEELDOWN; break;
-						case 6:   b = K_MOUSE4;     break;
-						case 7:   b = K_MOUSE5;     break;
-						default:  b = K_AUX1 + (e.button.button - 8)%16; break;
-					}
-					Sys_QueEvent( 0, SE_KEY, b,
-						( e.type == SDL_MOUSEBUTTONDOWN ? qtrue : qfalse ), 0, NULL );
-				}
-				break;
-
-			case SDL_QUIT:
-				Sys_Quit();
-				break;
-
-			default:
-				break;
-		}
-	}
-}
-
-/*
-===============
-IN_Frame
-===============
-*/
-void IN_Frame (void)
-{
-	IN_JoyMove( );
-
-	// Release the mouse if the console if down and we're windowed
-	if( ( cls.keyCatchers & KEYCATCH_CONSOLE ) && !r_fullscreen->integer )
-		IN_DeactivateMouse( );
-	else
-		IN_ActivateMouse( );
-
-	IN_ProcessEvents( );
-}
-
 // We translate axes movement into keypresses
 static int joy_keys[16] = {
 	K_LEFTARROW, K_RIGHTARROW,
@@ -558,7 +395,7 @@
 IN_StartupJoystick
 ===============
 */
-void IN_StartupJoystick( void )
+static void IN_StartupJoystick( void )
 {
 	int i = 0;
 	int total = 0;
@@ -618,7 +455,7 @@
 IN_JoyMove
 ===============
 */
-void IN_JoyMove( void )
+static void IN_JoyMove( void )
 {
 	qboolean joy_pressed[ARRAYLEN(joy_keys)];
 	unsigned int axes = 0;
@@ -655,7 +492,7 @@
 				balldx *= 2;
 			if (abs(balldy) > 1)
 				balldy *= 2;
-			Sys_QueEvent( 0, SE_MOUSE, balldx, balldy, 0, NULL );
+			Com_QueueEvent( 0, SE_MOUSE, balldx, balldy, 0, NULL );
 		}
 	}
 
@@ -670,7 +507,7 @@
 			qboolean pressed = (SDL_JoystickGetButton(stick, i) != 0);
 			if (pressed != stick_state.buttons[i])
 			{
-				Sys_QueEvent( 0, SE_KEY, K_JOY1 + i, pressed, 0, NULL );
+				Com_QueueEvent( 0, SE_KEY, K_JOY1 + i, pressed, 0, NULL );
 				stick_state.buttons[i] = pressed;
 			}
 		}
@@ -695,32 +532,32 @@
 				// release event
 				switch( ((Uint8 *)&stick_state.oldhats)[i] ) {
 					case SDL_HAT_UP:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 0], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 0], qfalse, 0, NULL );
 						break;
 					case SDL_HAT_RIGHT:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 1], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 1], qfalse, 0, NULL );
 						break;
 					case SDL_HAT_DOWN:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 2], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 2], qfalse, 0, NULL );
 						break;
 					case SDL_HAT_LEFT:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 3], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 3], qfalse, 0, NULL );
 						break;
 					case SDL_HAT_RIGHTUP:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 0], qfalse, 0, NULL );
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 1], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 0], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 1], qfalse, 0, NULL );
 						break;
 					case SDL_HAT_RIGHTDOWN:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 2], qfalse, 0, NULL );
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 1], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 2], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 1], qfalse, 0, NULL );
 						break;
 					case SDL_HAT_LEFTUP:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 0], qfalse, 0, NULL );
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 3], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 0], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 3], qfalse, 0, NULL );
 						break;
 					case SDL_HAT_LEFTDOWN:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 2], qfalse, 0, NULL );
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 3], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 2], qfalse, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 3], qfalse, 0, NULL );
 						break;
 					default:
 						break;
@@ -728,32 +565,32 @@
 				// press event
 				switch( ((Uint8 *)&hats)[i] ) {
 					case SDL_HAT_UP:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 0], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 0], qtrue, 0, NULL );
 						break;
 					case SDL_HAT_RIGHT:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 1], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 1], qtrue, 0, NULL );
 						break;
 					case SDL_HAT_DOWN:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 2], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 2], qtrue, 0, NULL );
 						break;
 					case SDL_HAT_LEFT:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 3], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 3], qtrue, 0, NULL );
 						break;
 					case SDL_HAT_RIGHTUP:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 0], qtrue, 0, NULL );
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 1], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 0], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 1], qtrue, 0, NULL );
 						break;
 					case SDL_HAT_RIGHTDOWN:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 2], qtrue, 0, NULL );
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 1], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 2], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 1], qtrue, 0, NULL );
 						break;
 					case SDL_HAT_LEFTUP:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 0], qtrue, 0, NULL );
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 3], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 0], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 3], qtrue, 0, NULL );
 						break;
 					case SDL_HAT_LEFTDOWN:
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 2], qtrue, 0, NULL );
-						Sys_QueEvent( 0, SE_KEY, hat_keys[4*i + 3], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 2], qtrue, 0, NULL );
+						Com_QueueEvent( 0, SE_KEY, hat_keys[4*i + 3], qtrue, 0, NULL );
 						break;
 					default:
 						break;
@@ -787,11 +624,11 @@
 	{
 		for( i = 0; i < 16; i++ ) {
 			if( ( axes & ( 1 << i ) ) && !( stick_state.oldaxes & ( 1 << i ) ) ) {
-				Sys_QueEvent( 0, SE_KEY, joy_keys[i], qtrue, 0, NULL );
+				Com_QueueEvent( 0, SE_KEY, joy_keys[i], qtrue, 0, NULL );
 			}
 
 			if( !( axes & ( 1 << i ) ) && ( stick_state.oldaxes & ( 1 << i ) ) ) {
-				Sys_QueEvent( 0, SE_KEY, joy_keys[i], qfalse, 0, NULL );
+				Com_QueueEvent( 0, SE_KEY, joy_keys[i], qfalse, 0, NULL );
 			}
 		}
 	}
@@ -799,3 +636,166 @@
 	/* Save for future generations. */
 	stick_state.oldaxes = axes;
 }
+
+/*
+===============
+IN_ProcessEvents
+===============
+*/
+static void IN_ProcessEvents( void )
+{
+	SDL_Event e;
+	const char *p = NULL;
+	int key = 0;
+
+	if( !SDL_WasInit( SDL_INIT_VIDEO ) )
+			return;
+
+	if( cls.keyCatchers == 0 && keyRepeatEnabled )
+	{
+		SDL_EnableKeyRepeat( 0, 0 );
+		keyRepeatEnabled = qfalse;
+	}
+	else if( !keyRepeatEnabled )
+	{
+		SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY,
+			SDL_DEFAULT_REPEAT_INTERVAL );
+		keyRepeatEnabled = qtrue;
+	}
+
+	while (SDL_PollEvent(&e))
+	{
+		switch (e.type)
+		{
+			case SDL_KEYDOWN:
+				IN_PrintKey(&e);
+				p = IN_TranslateSDLToQ3Key(&e.key.keysym, &key);
+				if( key )
+					Com_QueueEvent( 0, SE_KEY, key, qtrue, 0, NULL );
+
+				if( p )
+				{
+					while( *p )
+						Com_QueueEvent( 0, SE_CHAR, *p++, 0, 0, NULL );
+				}
+				break;
+
+			case SDL_KEYUP:
+				IN_TranslateSDLToQ3Key(&e.key.keysym, &key);
+				Com_QueueEvent( 0, SE_KEY, key, qfalse, 0, NULL );
+				break;
+
+			case SDL_MOUSEMOTION:
+				if (mouseActive)
+					Com_QueueEvent( 0, SE_MOUSE, e.motion.xrel, e.motion.yrel, 0, NULL );
+				break;
+
+			case SDL_MOUSEBUTTONDOWN:
+			case SDL_MOUSEBUTTONUP:
+				{
+					unsigned char b;
+					switch (e.button.button)
+					{
+						case 1:   b = K_MOUSE1;     break;
+						case 2:   b = K_MOUSE3;     break;
+						case 3:   b = K_MOUSE2;     break;
+						case 4:   b = K_MWHEELUP;   break;
+						case 5:   b = K_MWHEELDOWN; break;
+						case 6:   b = K_MOUSE4;     break;
+						case 7:   b = K_MOUSE5;     break;
+						default:  b = K_AUX1 + (e.button.button - 8)%16; break;
+					}
+					Com_QueueEvent( 0, SE_KEY, b,
+						( e.type == SDL_MOUSEBUTTONDOWN ? qtrue : qfalse ), 0, NULL );
+				}
+				break;
+
+			case SDL_QUIT:
+				Sys_Quit();
+				break;
+
+			default:
+				break;
+		}
+	}
+}
+
+/*
+===============
+IN_Frame
+===============
+*/
+void IN_Frame (void)
+{
+	IN_JoyMove( );
+
+	// Release the mouse if the console if down and we're windowed
+	if( ( cls.keyCatchers & KEYCATCH_CONSOLE ) && !r_fullscreen->integer )
+		IN_DeactivateMouse( );
+	else
+		IN_ActivateMouse( );
+
+	IN_ProcessEvents( );
+}
+
+/*
+===============
+IN_Init
+===============
+*/
+void IN_Init(void)
+{
+	if( !SDL_WasInit( SDL_INIT_VIDEO ) )
+	{
+		Com_Error( ERR_FATAL, "IN_Init called before SDL_Init( SDL_INIT_VIDEO )\n" );
+		return;
+	}
+
+	Com_DPrintf ("\n------- Input Initialization -------\n");
+
+	// mouse variables
+	in_mouse = Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE);
+	in_nograb = Cvar_Get ("in_nograb", "0", CVAR_ARCHIVE);
+
+	in_joystick = Cvar_Get ("in_joystick", "0", CVAR_ARCHIVE|CVAR_LATCH);
+	in_joystickDebug = Cvar_Get ("in_debugjoystick", "0", CVAR_TEMP);
+	in_joystickThreshold = Cvar_Get ("in_joystickThreshold", "0.15", CVAR_ARCHIVE);
+
+#ifdef MACOS_X_ACCELERATION_HACK
+	in_disablemacosxmouseaccel = Cvar_Get ("in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE);
+#endif
+
+	Cvar_Set( "cl_platformSensitivity", "1.0" );
+
+	SDL_EnableUNICODE(1);
+	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+	keyRepeatEnabled = qtrue;
+
+	if (in_mouse->value)
+		mouseAvailable = qtrue;
+	else
+		mouseAvailable = qfalse;
+
+	IN_StartupJoystick( );
+	Com_DPrintf ("------------------------------------\n");
+}
+
+/*
+===============
+IN_Shutdown
+===============
+*/
+void IN_Shutdown(void)
+{
+	IN_DeactivateMouse();
+
+	mouseAvailable = qfalse;
+
+	if (stick)
+	{
+		SDL_JoystickClose(stick);
+		stick = NULL;
+	}
+
+	SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
+}

Modified: branches/unified-sdl/code/sys/sys_local.h
===================================================================
--- branches/unified-sdl/code/sys/sys_local.h	2007-09-05 14:28:06 UTC (rev 1157)
+++ branches/unified-sdl/code/sys/sys_local.h	2007-09-05 16:07:30 UTC (rev 1158)
@@ -23,16 +23,10 @@
 #include "../qcommon/q_shared.h"
 #include "../qcommon/qcommon.h"
 
-// Queue subsystem
-void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr );
-qboolean Sys_GetPacket ( netadr_t *net_from, msg_t *net_message );
-
 // Input subsystem
 void IN_Init (void);
 void IN_Frame (void);
 void IN_Shutdown (void);
-void IN_JoyMove( void );
-void IN_StartupJoystick( void );
 
 // TTY console
 void TTY_Hide( void );

Modified: branches/unified-sdl/code/sys/sys_main.c
===================================================================
--- branches/unified-sdl/code/sys/sys_main.c	2007-09-05 14:28:06 UTC (rev 1157)
+++ branches/unified-sdl/code/sys/sys_main.c	2007-09-05 16:07:30 UTC (rev 1158)
@@ -501,125 +501,42 @@
 }
 
 /*
-========================================================================
-
-EVENT LOOP
-
-========================================================================
+=================
+Sys_Idle
+=================
 */
-
-#define MAX_QUED_EVENTS  256
-#define MASK_QUED_EVENTS ( MAX_QUED_EVENTS - 1 )
-
-sysEvent_t  eventQue[ MAX_QUED_EVENTS ];
-int         eventHead = 0;
-int         eventTail = 0;
-byte        sys_packetReceived[ MAX_MSGLEN ];
-
-/*
-================
-Sys_QueEvent
-
-A time of 0 will get the current time
-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 )
+static void Sys_Idle( void )
 {
-	sysEvent_t  *ev;
+#ifndef DEDICATED
+	int appState = SDL_GetAppState( );
+	int sleep = 0;
 
-	ev = &eventQue[ eventHead & MASK_QUED_EVENTS ];
-
-	if ( eventHead - eventTail >= MAX_QUED_EVENTS )
+	// If we have no input focus at all, sleep a bit
+	if( !( appState & ( SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS ) ) )
 	{
-		Com_Printf("Sys_QueEvent: overflow\n");
-		// we are discarding an event, but don't leak memory
-		if ( ev->evPtr )
-		{
-			Z_Free( ev->evPtr );
-		}
-		eventTail++;
+		Cvar_SetValue( "com_unfocused", 1 );
+		sleep += 16;
 	}
+	else
+		Cvar_SetValue( "com_unfocused", 0 );
 
-	eventHead++;
-
-	if ( time == 0 )
+	// If we're minimised, sleep a bit more
+	if( !( appState & SDL_APPACTIVE ) )
 	{
-		time = Sys_Milliseconds();
+		Cvar_SetValue( "com_minimized", 1 );
+		sleep += 32;
 	}
+	else
+		Cvar_SetValue( "com_minimized", 0 );
 
-	ev->evTime = time;
-	ev->evType = type;
-	ev->evValue = value;
-	ev->evValue2 = value2;
-	ev->evPtrLength = ptrLength;
-	ev->evPtr = ptr;
+	if( !com_dedicated->integer && sleep )
+		SDL_Delay( sleep );
+#else
+	// Dedicated server idles via NET_Sleep
+#endif
 }
 
 /*
-================
-Sys_GetEvent
-
-================
-*/
-sysEvent_t Sys_GetEvent( void )
-{
-	sysEvent_t  ev;
-	char        *s;
-	msg_t       netmsg;
-	netadr_t    adr;
-
-	// return if we have data
-	if ( eventHead > eventTail )
-	{
-		eventTail++;
-		return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
-	}
-
-	// check for console commands
-	s = Sys_ConsoleInput();
-	if ( s )
-	{
-		char  *b;
-		int   len;
-
-		len = strlen( s ) + 1;
-		b = Z_Malloc( len );
-		strcpy( b, s );
-		Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b );
-	}
-
-	// check for network packets
-	MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) );
-	if ( Sys_GetPacket ( &adr, &netmsg ) )
-	{
-		netadr_t  *buf;
-		int       len;
-
-		// copy out to a seperate buffer for qeueing
-		len = sizeof( netadr_t ) + netmsg.cursize;
-		buf = Z_Malloc( len );
-		*buf = adr;
-		memcpy( buf+1, netmsg.data, netmsg.cursize );
-		Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf );
-	}
-
-	// return if we have data
-	if ( eventHead > eventTail )
-	{
-		eventTail++;
-		return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ];
-	}
-
-	// create an empty event to return
-	memset( &ev, 0, sizeof( ev ) );
-	ev.evTime = Sys_Milliseconds();
-
-	return ev;
-}
-
-/*
 =================
 Sys_ParseArgs
 =================
@@ -698,10 +615,6 @@
 		Q_strcat( commandLine, sizeof( commandLine ), " " );
 	}
 
-	// Clear queues
-	memset( &eventQue[ 0 ], 0, MAX_QUED_EVENTS * sizeof( sysEvent_t ) );
-	memset( &sys_packetReceived[ 0 ], 0, MAX_MSGLEN * sizeof( byte ) );
-
 	Com_Init( commandLine );
 	NET_Init();
 
@@ -723,35 +636,8 @@
 
 	while( 1 )
 	{
-#ifndef DEDICATED
-		int appState = SDL_GetAppState( );
-		int sleep = 0;
-
-		// If we have no input focus at all, sleep a bit
-		if( !( appState & ( SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS ) ) )
-		{
-			Cvar_SetValue( "com_unfocused", 1 );
-			sleep += 16;
-		}
-		else
-			Cvar_SetValue( "com_unfocused", 0 );
-
-		// If we're minimised, sleep a bit more
-		if( !( appState & SDL_APPACTIVE ) )
-		{
-			Cvar_SetValue( "com_minimized", 1 );
-			sleep += 32;
-		}
-		else
-			Cvar_SetValue( "com_minimized", 0 );
-
-		if( !com_dedicated->integer && sleep )
-			SDL_Delay( sleep );
-#endif
-
-		// Check for input
+		Sys_Idle( );
 		IN_Frame( );
-
 		Com_Frame( );
 	}
 




More information about the quake3-commits mailing list