Skip to content
Permalink
Browse files
All: Fix using QVMs in SP and MP AI Game QVM calls
Don't let CGame use trap_GetModelInfo() if CGame or Game are a QVM.
Fix cg_syscalls.asm not matching order in cg_public.h.
Fix arguments for AICAST_VISIBLEFROMPOS and AICAST_CHECKATTACKATPOS.
  • Loading branch information
zturtleman committed Nov 13, 2018
1 parent de4e40d commit ef829a9a8b3465bfa5083494fcfbdd738986e1d1
Showing with 102 additions and 14 deletions.
  1. +31 −2 MP/code/server/sv_bot.c
  2. +1 −1 SP/code/cgame/cg_players.c
  3. +7 −7 SP/code/cgame/cg_syscalls.asm
  4. +12 −1 SP/code/client/cl_cgame.c
  5. +31 −2 SP/code/server/sv_bot.c
  6. +20 −1 SP/code/server/sv_game.c
@@ -572,7 +572,23 @@ BotImport_AICast_VisibleFromPos
*/
qboolean BotImport_AICast_VisibleFromPos( vec3_t srcpos, int srcnum,
vec3_t destpos, int destnum, qboolean updateVisPos ) {
return VM_Call( gvm, AICAST_VISIBLEFROMPOS, srcpos, srcnum, destpos, destnum, updateVisPos );
if ( VM_IsNative( gvm ) ) {
return VM_Call( gvm, AICAST_VISIBLEFROMPOS, srcpos, srcnum, destpos, destnum, updateVisPos );
} else {
qboolean ret;
unsigned gSrcPos;
unsigned gDestPos;

gSrcPos = VM_GetTempMemory( gvm, sizeof(vec3_t), srcpos );
gDestPos = VM_GetTempMemory( gvm, sizeof(vec3_t), destpos );

ret = VM_Call( gvm, AICAST_VISIBLEFROMPOS, gSrcPos, srcnum, gDestPos, destnum, updateVisPos );

VM_FreeTempMemory( gvm, gDestPos, sizeof(vec3_t), destpos );
VM_FreeTempMemory( gvm, gSrcPos, sizeof(vec3_t), srcpos );

return ret;
}
}

/*
@@ -581,7 +597,20 @@ BotImport_AICast_CheckAttackAtPos
===============
*/
qboolean BotImport_AICast_CheckAttackAtPos( int entnum, int enemy, vec3_t pos, qboolean ducking, qboolean allowHitWorld ) {
return VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, pos, ducking, allowHitWorld );
if ( VM_IsNative( gvm ) ) {
return VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, pos, ducking, allowHitWorld );
} else {
qboolean ret;
unsigned gPos;

gPos = VM_GetTempMemory( gvm, sizeof(vec3_t), pos );

ret = VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, gPos, ducking, allowHitWorld );

VM_FreeTempMemory( gvm, gPos, sizeof(vec3_t), pos );

return ret;
}
}
// done.

@@ -509,7 +509,7 @@ qboolean CG_ParseAnimationFiles( char *modelname, animModelInfo_t *modelInfo, in
Com_sprintf( filename, sizeof( filename ), "models/players/%s/wolfanim.cfg", modelname );
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( len <= 0 ) {
CG_Printf( "G_ParseAnimationFiles(): file '%s' not found\n", filename ); //----(SA) added
CG_Printf( "CG_ParseAnimationFiles(): file '%s' not found\n", filename ); //----(SA) added
return qfalse;
}
if ( len >= sizeof( text ) - 1 ) {
@@ -100,14 +100,14 @@ equ trap_CIN_DrawCinematic -94
equ trap_CIN_SetExtents -95
equ trap_R_RemapShader -96

equ trap_S_AddRealLoopingSound -97
; trap_S_AddRealLoopingSound ; not currently used (sorry, trying to keep CG_MEMSET @ 100)

equ trap_S_StopLoopingSound -98
equ trap_S_StopStreamingSound -99
equ trap_loadCamera -100
equ trap_startCamera -101
equ trap_stopCamera -102
equ trap_getCameraInfo -103
equ trap_S_StopLoopingSound -97
equ trap_S_StopStreamingSound -98
equ trap_loadCamera -99
equ trap_startCamera -100
equ trap_stopCamera -101
equ trap_getCameraInfo -102

equ memset -111
equ memcpy -112
@@ -829,7 +829,18 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) {
// - NERVE - SMF

case CG_GETMODELINFO:
return SV_GetModelInfo( args[1], VMA( 2 ), VMA( 3 ) );
if ( VM_IsNative( cgvm ) ) {
return SV_GetModelInfo( args[1], VMA( 2 ), VMA( 3 ) );
} else {
// The intention of the syscall is to set a CGame pointer to Game VM memory
// to reduce memory usage and load time. This is not possible for CGame QVM
// due to QVM pointers being an offset in QVM's memory and each QVM using a
// separate memory block. There is additional issues if Game VM is a DLL,
// see SV_GetModelInfo().
// It seems like the best solution is to just make CGame QVM load the animation
// file for itself. --zturtleman
return qfalse;
}

// New in IORTCW
case CG_ALLOC:
@@ -551,7 +551,23 @@ BotImport_AICast_VisibleFromPos
*/
qboolean BotImport_AICast_VisibleFromPos( vec3_t srcpos, int srcnum,
vec3_t destpos, int destnum, qboolean updateVisPos ) {
return VM_Call( gvm, AICAST_VISIBLEFROMPOS, srcpos, srcnum, destpos, destnum, updateVisPos );
if ( VM_IsNative( gvm ) ) {
return VM_Call( gvm, AICAST_VISIBLEFROMPOS, srcpos, srcnum, destpos, destnum, updateVisPos );
} else {
qboolean ret;
unsigned gSrcPos;
unsigned gDestPos;

gSrcPos = VM_GetTempMemory( gvm, sizeof(vec3_t), srcpos );
gDestPos = VM_GetTempMemory( gvm, sizeof(vec3_t), destpos );

ret = VM_Call( gvm, AICAST_VISIBLEFROMPOS, gSrcPos, srcnum, gDestPos, destnum, updateVisPos );

VM_FreeTempMemory( gvm, gDestPos, sizeof(vec3_t), destpos );
VM_FreeTempMemory( gvm, gSrcPos, sizeof(vec3_t), srcpos );

return ret;
}
}

/*
@@ -560,7 +576,20 @@ BotImport_AICast_CheckAttackAtPos
===============
*/
qboolean BotImport_AICast_CheckAttackAtPos( int entnum, int enemy, vec3_t pos, qboolean ducking, qboolean allowHitWorld ) {
return VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, pos, ducking, allowHitWorld );
if ( VM_IsNative( gvm ) ) {
return VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, pos, ducking, allowHitWorld );
} else {
qboolean ret;
unsigned gPos;

gPos = VM_GetTempMemory( gvm, sizeof(vec3_t), pos );

ret = VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, gPos, ducking, allowHitWorld );

VM_FreeTempMemory( gvm, gPos, sizeof(vec3_t), pos );

return ret;
}
}
// done.

@@ -1074,5 +1074,24 @@ qboolean SV_GetModelInfo( int clientNum, char *modelName, animModelInfo_t **mode
if ( !gvm ) {
return qfalse;
}
return VM_Call( gvm, GAME_GETMODELINFO, clientNum, modelName, modelInfo );

if ( VM_IsNative( gvm ) ) {
return VM_Call( gvm, GAME_GETMODELINFO, clientNum, modelName, modelInfo );
} else {
// Setting a pointer to Game QVM animModelInfo_t struct won't work
// as it contains pointers (offset in QVM memory block) that will
// have to be converted to a real pointers for CGame DLL to use it.
// Additionally, there may be different struct alignment.
//
// That would require making a copy for CGame using VM_Alloc()
// (and tracking modelinfo to reuse?) to fix pointers and alignment
// issues. That would need means having to hard code animModelInfo_t.
// Which is a lot of weird hard coding work and iortcw already added
// a fall back for trap_GetModelInfo() in CGame to allow demo playback
// so this is unnecessary.
//
// FIXME: It would be necessary for using Game QVM with vanilla CGame DLL.
// --zturtleman
return qfalse;
}
}

0 comments on commit ef829a9

Please sign in to comment.