Skip to content

Commit

Permalink
All: Fix using QVMs in SP and MP AI Game QVM calls
Browse files Browse the repository at this point in the history
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 ef829a9
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 14 deletions.
33 changes: 31 additions & 2 deletions MP/code/server/sv_bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/*
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion SP/code/cgame/cg_players.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
14 changes: 7 additions & 7 deletions SP/code/cgame/cg_syscalls.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion SP/code/client/cl_cgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
33 changes: 31 additions & 2 deletions SP/code/server/sv_bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/*
Expand All @@ -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.

Expand Down
21 changes: 20 additions & 1 deletion SP/code/server/sv_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.