r1189 - in trunk/code: client sdl

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Oct 2 10:14:45 EDT 2007


Author: tma
Date: 2007-10-02 10:14:45 -0400 (Tue, 02 Oct 2007)
New Revision: 1189

Modified:
   trunk/code/client/cl_cgame.c
   trunk/code/client/cl_console.c
   trunk/code/client/cl_input.c
   trunk/code/client/cl_keys.c
   trunk/code/client/cl_main.c
   trunk/code/client/cl_scrn.c
   trunk/code/client/cl_ui.c
   trunk/code/client/client.h
   trunk/code/sdl/sdl_input.c
Log:
* Fix bug that prevented key up events getting to cgame/ui when not in game
* Use Key_[GS]etCatcher everywhere to set keycatcher
* Clear all key states when the catcher changes


Modified: trunk/code/client/cl_cgame.c
===================================================================
--- trunk/code/client/cl_cgame.c	2007-10-01 07:56:32 UTC (rev 1188)
+++ trunk/code/client/cl_cgame.c	2007-10-02 14:14:45 UTC (rev 1189)
@@ -387,7 +387,7 @@
 ====================
 */
 void CL_ShutdownCGame( void ) {
-	cls.keyCatchers &= ~KEYCATCH_CGAME;
+	Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_CGAME );
 	cls.cgameStarted = qfalse;
 	if ( !cgvm ) {
 		return;
@@ -607,7 +607,8 @@
   case CG_KEY_GETCATCHER:
 		return Key_GetCatcher();
   case CG_KEY_SETCATCHER:
-		Key_SetCatcher( args[1] );
+		// Don't allow the cgame module to close the console
+		Key_SetCatcher( args[1] | ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) );
     return 0;
   case CG_KEY_GETKEY:
 		return Key_GetKey( VMA(1) );

Modified: trunk/code/client/cl_console.c
===================================================================
--- trunk/code/client/cl_console.c	2007-10-01 07:56:32 UTC (rev 1188)
+++ trunk/code/client/cl_console.c	2007-10-02 14:14:45 UTC (rev 1189)
@@ -72,7 +72,7 @@
 */
 void Con_ToggleConsole_f (void) {
 	// Can't toggle the console when it's the only thing available
-	if ( cls.state == CA_DISCONNECTED && cls.keyCatchers == KEYCATCH_CONSOLE ) {
+	if ( cls.state == CA_DISCONNECTED && Key_GetCatcher( ) == KEYCATCH_CONSOLE ) {
 		return;
 	}
 
@@ -80,7 +80,7 @@
 	g_consoleField.widthInChars = g_console_field_width;
 
 	Con_ClearNotify ();
-	cls.keyCatchers ^= KEYCATCH_CONSOLE;
+	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_CONSOLE );
 }
 
 /*
@@ -94,7 +94,7 @@
 	Field_Clear( &chatField );
 	chatField.widthInChars = 30;
 
-	cls.keyCatchers ^= KEYCATCH_MESSAGE;
+	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
 }
 
 /*
@@ -107,7 +107,7 @@
 	chat_team = qtrue;
 	Field_Clear( &chatField );
 	chatField.widthInChars = 25;
-	cls.keyCatchers ^= KEYCATCH_MESSAGE;
+	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
 }
 
 /*
@@ -124,7 +124,7 @@
 	chat_team = qfalse;
 	Field_Clear( &chatField );
 	chatField.widthInChars = 30;
-	cls.keyCatchers ^= KEYCATCH_MESSAGE;
+	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
 }
 
 /*
@@ -141,7 +141,7 @@
 	chat_team = qfalse;
 	Field_Clear( &chatField );
 	chatField.widthInChars = 30;
-	cls.keyCatchers ^= KEYCATCH_MESSAGE;
+	Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
 }
 
 /*
@@ -477,7 +477,7 @@
 void Con_DrawInput (void) {
 	int		y;
 
-	if ( cls.state != CA_DISCONNECTED && !(cls.keyCatchers & KEYCATCH_CONSOLE ) ) {
+	if ( cls.state != CA_DISCONNECTED && !(Key_GetCatcher( ) & KEYCATCH_CONSOLE ) ) {
 		return;
 	}
 
@@ -524,7 +524,7 @@
 			continue;
 		text = con.text + (i % con.totallines)*con.linewidth;
 
-		if (cl.snap.ps.pm_type != PM_INTERMISSION && cls.keyCatchers & (KEYCATCH_UI | KEYCATCH_CGAME) ) {
+		if (cl.snap.ps.pm_type != PM_INTERMISSION && Key_GetCatcher( ) & (KEYCATCH_UI | KEYCATCH_CGAME) ) {
 			continue;
 		}
 
@@ -544,12 +544,12 @@
 
 	re.SetColor( NULL );
 
-	if (cls.keyCatchers & (KEYCATCH_UI | KEYCATCH_CGAME) ) {
+	if (Key_GetCatcher( ) & (KEYCATCH_UI | KEYCATCH_CGAME) ) {
 		return;
 	}
 
 	// draw the chat line
-	if ( cls.keyCatchers & KEYCATCH_MESSAGE )
+	if ( Key_GetCatcher( ) & KEYCATCH_MESSAGE )
 	{
 		if (chat_team)
 		{
@@ -697,7 +697,7 @@
 
 	// if disconnected, render console full screen
 	if ( cls.state == CA_DISCONNECTED ) {
-		if ( !( cls.keyCatchers & (KEYCATCH_UI | KEYCATCH_CGAME)) ) {
+		if ( !( Key_GetCatcher( ) & (KEYCATCH_UI | KEYCATCH_CGAME)) ) {
 			Con_DrawSolidConsole( 1.0 );
 			return;
 		}
@@ -724,7 +724,7 @@
 */
 void Con_RunConsole (void) {
 	// decide on the destination height of the console
-	if ( cls.keyCatchers & KEYCATCH_CONSOLE )
+	if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE )
 		con.finalFrac = 0.5;		// half screen
 	else
 		con.finalFrac = 0;				// none visible
@@ -779,7 +779,7 @@
 	}
 	Field_Clear( &g_consoleField );
 	Con_ClearNotify ();
-	cls.keyCatchers &= ~KEYCATCH_CONSOLE;
+	Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_CONSOLE );
 	con.finalFrac = 0;				// none visible
 	con.displayFrac = 0;
 }

Modified: trunk/code/client/cl_input.c
===================================================================
--- trunk/code/client/cl_input.c	2007-10-01 07:56:32 UTC (rev 1188)
+++ trunk/code/client/cl_input.c	2007-10-02 14:14:45 UTC (rev 1189)
@@ -351,9 +351,9 @@
 =================
 */
 void CL_MouseEvent( int dx, int dy, int time ) {
-	if ( cls.keyCatchers & KEYCATCH_UI ) {
+	if ( Key_GetCatcher( ) & KEYCATCH_UI ) {
 		VM_Call( uivm, UI_MOUSE_EVENT, dx, dy );
-	} else if (cls.keyCatchers & KEYCATCH_CGAME) {
+	} else if (Key_GetCatcher( ) & KEYCATCH_CGAME) {
 		VM_Call (cgvm, CG_MOUSE_EVENT, dx, dy);
 	} else {
 		cl.mouseDx[cl.mouseIndex] += dx;
@@ -487,13 +487,13 @@
 		in_buttons[i].wasPressed = qfalse;
 	}
 
-	if ( cls.keyCatchers ) {
+	if ( Key_GetCatcher( ) ) {
 		cmd->buttons |= BUTTON_TALK;
 	}
 
 	// allow the game to know if any key at all is
 	// currently pressed, even if it isn't bound to anything
-	if ( anykeydown && !cls.keyCatchers ) {
+	if ( anykeydown && Key_GetCatcher( ) == 0 ) {
 		cmd->buttons |= BUTTON_ANY;
 	}
 }

Modified: trunk/code/client/cl_keys.c
===================================================================
--- trunk/code/client/cl_keys.c	2007-10-01 07:56:32 UTC (rev 1188)
+++ trunk/code/client/cl_keys.c	2007-10-02 14:14:45 UTC (rev 1189)
@@ -720,7 +720,7 @@
 
 
 	if (key == K_ESCAPE) {
-		cls.keyCatchers &= ~KEYCATCH_MESSAGE;
+		Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_MESSAGE );
 		Field_Clear( &chatField );
 		return;
 	}
@@ -742,7 +742,7 @@
 
 			CL_AddReliableCommand( buffer );
 		}
-		cls.keyCatchers &= ~KEYCATCH_MESSAGE;
+		Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_MESSAGE );
 		Field_Clear( &chatField );
 		return;
 	}
@@ -1173,7 +1173,8 @@
 
 
 	// keys can still be used for bound actions
-	if ( down && ( key < 128 || key == K_MOUSE1 ) && ( clc.demoplaying || cls.state == CA_CINEMATIC ) && !cls.keyCatchers) {
+	if ( down && ( key < 128 || key == K_MOUSE1 ) &&
+		( clc.demoplaying || cls.state == CA_CINEMATIC ) && Key_GetCatcher( ) == 0 ) {
 
 		if (Cvar_VariableValue ("com_cameraMode") == 0) {
 			Cvar_Set ("nextdemo","");
@@ -1184,20 +1185,20 @@
 
 	// escape is always handled special
 	if ( key == K_ESCAPE && down ) {
-		if ( cls.keyCatchers & KEYCATCH_MESSAGE ) {
+		if ( Key_GetCatcher( ) & KEYCATCH_MESSAGE ) {
 			// clear message mode
 			Message_Key( key );
 			return;
 		}
 
 		// escape always gets out of CGAME stuff
-		if (cls.keyCatchers & KEYCATCH_CGAME) {
-			cls.keyCatchers &= ~KEYCATCH_CGAME;
+		if (Key_GetCatcher( ) & KEYCATCH_CGAME) {
+			Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_CGAME );
 			VM_Call (cgvm, CG_EVENT_HANDLING, CGAME_EVENT_NONE);
 			return;
 		}
 
-		if ( !( cls.keyCatchers & KEYCATCH_UI ) ) {
+		if ( !( Key_GetCatcher( ) & KEYCATCH_UI ) ) {
 			if ( cls.state == CA_ACTIVE && !clc.demoplaying ) {
 				VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_INGAME );
 			}
@@ -1224,12 +1225,12 @@
 			kb = keys[key].binding;
 
 			CL_AddKeyUpCommands( key, kb, time );
+		}
 
-			if ( cls.keyCatchers & KEYCATCH_UI && uivm ) {
-				VM_Call( uivm, UI_KEY_EVENT, key, down );
-			} else if ( cls.keyCatchers & KEYCATCH_CGAME && cgvm ) {
-				VM_Call( cgvm, CG_KEY_EVENT, key, down );
-			}
+		if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) {
+			VM_Call( uivm, UI_KEY_EVENT, key, down );
+		} else if ( Key_GetCatcher( ) & KEYCATCH_CGAME && cgvm ) {
+			VM_Call( cgvm, CG_KEY_EVENT, key, down );
 		}
 
 		return;
@@ -1237,17 +1238,17 @@
 
 
 	// distribute the key down event to the apropriate handler
-	if ( cls.keyCatchers & KEYCATCH_CONSOLE ) {
+	if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) {
 		Console_Key( key );
-	} else if ( cls.keyCatchers & KEYCATCH_UI ) {
+	} else if ( Key_GetCatcher( ) & KEYCATCH_UI ) {
 		if ( uivm ) {
 			VM_Call( uivm, UI_KEY_EVENT, key, down );
 		} 
-	} else if ( cls.keyCatchers & KEYCATCH_CGAME ) {
+	} else if ( Key_GetCatcher( ) & KEYCATCH_CGAME ) {
 		if ( cgvm ) {
 			VM_Call( cgvm, CG_KEY_EVENT, key, down );
 		} 
-	} else if ( cls.keyCatchers & KEYCATCH_MESSAGE ) {
+	} else if ( Key_GetCatcher( ) & KEYCATCH_MESSAGE ) {
 		Message_Key( key );
 	} else if ( cls.state == CA_DISCONNECTED ) {
 		Console_Key( key );
@@ -1315,15 +1316,15 @@
 	}
 
 	// distribute the key down event to the apropriate handler
-	if ( cls.keyCatchers & KEYCATCH_CONSOLE )
+	if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE )
 	{
 		Field_CharEvent( &g_consoleField, key );
 	}
-	else if ( cls.keyCatchers & KEYCATCH_UI )
+	else if ( Key_GetCatcher( ) & KEYCATCH_UI )
 	{
 		VM_Call( uivm, UI_KEY_EVENT, key | K_CHAR_FLAG, qtrue );
 	}
-	else if ( cls.keyCatchers & KEYCATCH_MESSAGE ) 
+	else if ( Key_GetCatcher( ) & KEYCATCH_MESSAGE ) 
 	{
 		Field_CharEvent( &chatField, key );
 	}
@@ -1355,6 +1356,30 @@
 	}
 }
 
+static int keyCatchers = 0;
+
+/*
+====================
+Key_GetCatcher
+====================
+*/
+int Key_GetCatcher( void ) {
+	return keyCatchers;
+}
+
+/*
+====================
+Key_SetCatcher
+====================
+*/
+void Key_SetCatcher( int catcher ) {
+	// If the catcher state is changing, clear all key states
+	if( catcher != keyCatchers )
+		Key_ClearStates( );
+
+	keyCatchers = catcher;
+}
+
 // This must not exceed MAX_CMD_LINE
 #define			MAX_CONSOLE_SAVE_BUFFER	1024
 #define			CONSOLE_HISTORY_FILE    "q3history"

Modified: trunk/code/client/cl_main.c
===================================================================
--- trunk/code/client/cl_main.c	2007-10-01 07:56:32 UTC (rev 1188)
+++ trunk/code/client/cl_main.c	2007-10-02 14:14:45 UTC (rev 1189)
@@ -652,7 +652,7 @@
 void CL_StartDemoLoop( void ) {
 	// start the demo loop again
 	Cbuf_AddText ("d1\n");
-	cls.keyCatchers = 0;
+	Key_SetCatcher( 0 );
 }
 
 /*
@@ -751,7 +751,7 @@
 void CL_MapLoading( void ) {
 	if ( com_dedicated->integer ) {
 		cls.state = CA_DISCONNECTED;
-		cls.keyCatchers = KEYCATCH_CONSOLE;
+		Key_SetCatcher( KEYCATCH_CONSOLE );
 		return;
 	}
 
@@ -760,7 +760,7 @@
 	}
 
 	Con_Close();
-	cls.keyCatchers = 0;
+	Key_SetCatcher( 0 );
 
 	// if we are already connected to the local host, stay connected
 	if ( cls.state >= CA_CONNECTED && !Q_stricmp( cls.servername, "localhost" ) ) {
@@ -776,7 +776,7 @@
 		CL_Disconnect( qtrue );
 		Q_strncpyz( cls.servername, "localhost", sizeof(cls.servername) );
 		cls.state = CA_CHALLENGING;		// so the connect screen is drawn
-		cls.keyCatchers = 0;
+		Key_SetCatcher( 0 );
 		SCR_UpdateScreen();
 		clc.connectTime = -RETRANSMIT_TIMEOUT;
 		NET_StringToAdr( cls.servername, &clc.serverAddress);
@@ -1205,7 +1205,7 @@
 		cls.state = CA_CONNECTING;
 	}
 
-	cls.keyCatchers = 0;
+	Key_SetCatcher( 0 );
 	clc.connectTime = -99999;	// CL_CheckForResend() will fire immediately
 	clc.connectPacketCount = 0;
 
@@ -2228,7 +2228,7 @@
 		// bring up the cd error dialog if needed
 		cls.cddialog = qfalse;
 		VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_NEED_CD );
-	} else	if ( cls.state == CA_DISCONNECTED && !( cls.keyCatchers & KEYCATCH_UI )
+	} else	if ( cls.state == CA_DISCONNECTED && !( Key_GetCatcher( ) & KEYCATCH_UI )
 		&& !com_sv_running->integer ) {
 		// if disconnected, bring up the menu
 		S_StopAllSounds();
@@ -2857,6 +2857,7 @@
 	recursive = qfalse;
 
 	Com_Memset( &cls, 0, sizeof( cls ) );
+	Key_SetCatcher( 0 );
 
 	Com_Printf( "-----------------------\n" );
 

Modified: trunk/code/client/cl_scrn.c
===================================================================
--- trunk/code/client/cl_scrn.c	2007-10-01 07:56:32 UTC (rev 1188)
+++ trunk/code/client/cl_scrn.c	2007-10-02 14:14:45 UTC (rev 1189)
@@ -490,7 +490,7 @@
 	}
 
 	// the menu draws next
-	if ( cls.keyCatchers & KEYCATCH_UI && uivm ) {
+	if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) {
 		VM_Call( uivm, UI_REFRESH, cls.realtime );
 	}
 

Modified: trunk/code/client/cl_ui.c
===================================================================
--- trunk/code/client/cl_ui.c	2007-10-01 07:56:32 UTC (rev 1188)
+++ trunk/code/client/cl_ui.c	2007-10-02 14:14:45 UTC (rev 1189)
@@ -664,27 +664,6 @@
 
 /*
 ====================
-Key_GetCatcher
-====================
-*/
-int Key_GetCatcher( void ) {
-	return cls.keyCatchers;
-}
-
-/*
-====================
-Ket_SetCatcher
-====================
-*/
-void Key_SetCatcher( int catcher ) {
-	// prevent console from being closed
-	catcher |= cls.keyCatchers & KEYCATCH_CONSOLE;
-	cls.keyCatchers = catcher;
-}
-
-
-/*
-====================
 CLUI_GetCDKey
 ====================
 */
@@ -932,7 +911,8 @@
 		return Key_GetCatcher();
 
 	case UI_KEY_SETCATCHER:
-		Key_SetCatcher( args[1] );
+		// Don't allow the ui module to close the console
+		Key_SetCatcher( args[1] | ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) );
 		return 0;
 
 	case UI_GETCLIPBOARDDATA:
@@ -1124,7 +1104,7 @@
 ====================
 */
 void CL_ShutdownUI( void ) {
-	cls.keyCatchers &= ~KEYCATCH_UI;
+	Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_UI );
 	cls.uiStarted = qfalse;
 	if ( !uivm ) {
 		return;

Modified: trunk/code/client/client.h
===================================================================
--- trunk/code/client/client.h	2007-10-01 07:56:32 UTC (rev 1188)
+++ trunk/code/client/client.h	2007-10-02 14:14:45 UTC (rev 1189)
@@ -270,7 +270,6 @@
 
 typedef struct {
 	connstate_t	state;				// connection status
-	int			keyCatchers;		// bit flags
 
 	qboolean	cddialog;			// bring up the cd needed dialog next frame
 
@@ -442,6 +441,8 @@
 
 float CL_KeyState (kbutton_t *key);
 char *Key_KeynumToString (int keynum);
+int Key_GetCatcher( void );
+void Key_SetCatcher( int catcher );
 
 //
 // cl_parse.c

Modified: trunk/code/sdl/sdl_input.c
===================================================================
--- trunk/code/sdl/sdl_input.c	2007-10-01 07:56:32 UTC (rev 1188)
+++ trunk/code/sdl/sdl_input.c	2007-10-02 14:14:45 UTC (rev 1189)
@@ -651,7 +651,7 @@
 	if( !SDL_WasInit( SDL_INIT_VIDEO ) )
 			return;
 
-	if( cls.keyCatchers == 0 && keyRepeatEnabled )
+	if( Key_GetCatcher( ) == 0 && keyRepeatEnabled )
 	{
 		SDL_EnableKeyRepeat( 0, 0 );
 		keyRepeatEnabled = qfalse;
@@ -730,7 +730,7 @@
 	IN_JoyMove( );
 
 	// Release the mouse if the console if down and we're windowed
-	if( ( cls.keyCatchers & KEYCATCH_CONSOLE ) && !r_fullscreen->integer )
+	if( ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) && !r_fullscreen->integer )
 		IN_DeactivateMouse( );
 	else
 		IN_ActivateMouse( );




More information about the quake3-commits mailing list