new engine extension to toggle cgame input forwarding

cleaned up CL_CG_GetValue
This commit is contained in:
myT 2017-08-13 04:01:21 +02:00
parent bc83712ec6
commit 1c38742c5a
5 changed files with 31 additions and 16 deletions

View file

@ -289,6 +289,7 @@ void CL_ShutdownCGame()
{
cls.keyCatchers &= ~KEYCATCH_CGAME;
cls.cgameStarted = qfalse;
cls.cgameForwardInput = 0;
if ( !cgvm ) {
return;
}
@ -301,19 +302,19 @@ void CL_ShutdownCGame()
static qbool CL_CG_GetValue( char* value, int valueSize, const char* key )
{
if( Q_stricmp(key, "trap_LocateInteropData") == 0 ) {
Com_sprintf( value, valueSize, "%d", CG_EXT_LOCATEINTEROPDATA );
return qtrue;
}
struct syscall_t { const char* name; int number; };
static const syscall_t syscalls[] = {
{ "trap_LocateInteropData", CG_EXT_LOCATEINTEROPDATA },
{ "trap_R_AddRefEntityToScene2", CG_EXT_R_ADDREFENTITYTOSCENE2 },
{ "trap_R_ForceFixedDLights", CG_EXT_R_FORCEFIXEDDLIGHTS },
{ "trap_SetInputForwarding", CG_EXT_SETINPUTFORWARDING }
};
if( Q_stricmp(key, "trap_R_AddRefEntityToScene2") == 0 ) {
Com_sprintf( value, valueSize, "%d", CG_EXT_R_ADDREFENTITYTOSCENE2 );
return qtrue;
}
if( Q_stricmp(key, "trap_R_ForceFixedDLights") == 0 ) {
Com_sprintf( value, valueSize, "%d", CG_EXT_R_FORCEFIXEDDLIGHTS );
return qtrue;
for ( int i = 0; i < ARRAY_LEN( syscalls ); ++i ) {
if( Q_stricmp(key, syscalls[i].name) == 0 ) {
Com_sprintf( value, valueSize, "%d", syscalls[i].number );
return qtrue;
}
}
return qfalse;
@ -589,6 +590,10 @@ static intptr_t CL_CgameSystemCalls( intptr_t *args )
case CG_EXT_R_FORCEFIXEDDLIGHTS:
return 0; // already the case for CNQ3
case CG_EXT_SETINPUTFORWARDING:
cls.cgameForwardInput = (int)args[1];
return 0;
default:
Com_Error( ERR_DROP, "Bad cgame system trap: %i", args[0] );
}
@ -600,6 +605,8 @@ void CL_InitCGame()
{
int t = Sys_Milliseconds();
cls.cgameForwardInput = 0;
// put away the console
Con_Close();

View file

@ -293,7 +293,7 @@ void CL_MouseEvent( int dx, int dy, int time )
} else if (cls.keyCatchers & KEYCATCH_CGAME) {
VM_Call( cgvm, CG_MOUSE_EVENT, dx, dy );
} else {
if ( cgvm )
if ( cgvm && (cls.cgameForwardInput & 1) )
VM_Call( cgvm, CG_MOUSE_EVENT, dx, dy );
cl.mouseDx[cl.mouseIndex] += dx;
cl.mouseDy[cl.mouseIndex] += dy;

View file

@ -1009,9 +1009,11 @@ void CL_KeyEvent( int key, qbool down, unsigned time )
CL_AddKeyUpCommands( key, kb );
if ( cls.keyCatchers & KEYCATCH_UI && uivm ) {
if ( (cls.keyCatchers & KEYCATCH_UI) && uivm ) {
VM_Call( uivm, UI_KEY_EVENT, key, down );
} else if ( cls.keyCatchers & KEYCATCH_CGAME && cgvm ) {
} else if ( (cls.keyCatchers & KEYCATCH_CGAME) && cgvm ) {
VM_Call( cgvm, CG_KEY_EVENT, key, down );
} else if ( (cls.cgameForwardInput & 2) && cgvm ) {
VM_Call( cgvm, CG_KEY_EVENT, key, down );
}
@ -1032,6 +1034,8 @@ void CL_KeyEvent( int key, qbool down, unsigned time )
}
} else if ( cls.keyCatchers & KEYCATCH_MESSAGE ) {
Message_Key( key );
} else if ( (cls.cgameForwardInput & 2) && cgvm ) {
VM_Call( cgvm, CG_KEY_EVENT, key, down );
} else if ( cls.state == CA_DISCONNECTED ) {
Console_Key( key );
} else {

View file

@ -259,6 +259,9 @@ typedef struct {
qbool uiStarted;
qbool cgameStarted;
// forward input to cgame regardless of keycatcher state?
int cgameForwardInput; // 1=mouse, 2=keys (note: we don't forward the escape key)
int framecount;
int frametime; // msec since last frame

View file

@ -182,7 +182,8 @@ typedef enum {
CG_EXT_GETVALUE = 700,
CG_EXT_LOCATEINTEROPDATA,
CG_EXT_R_ADDREFENTITYTOSCENE2,
CG_EXT_R_FORCEFIXEDDLIGHTS
CG_EXT_R_FORCEFIXEDDLIGHTS,
CG_EXT_SETINPUTFORWARDING
} cgameImport_t;