Skip to content

Commit ef829a9

Browse files
committed
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.
1 parent de4e40d commit ef829a9

File tree

6 files changed

+102
-14
lines changed

6 files changed

+102
-14
lines changed

MP/code/server/sv_bot.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,23 @@ BotImport_AICast_VisibleFromPos
572572
*/
573573
qboolean BotImport_AICast_VisibleFromPos( vec3_t srcpos, int srcnum,
574574
vec3_t destpos, int destnum, qboolean updateVisPos ) {
575-
return VM_Call( gvm, AICAST_VISIBLEFROMPOS, srcpos, srcnum, destpos, destnum, updateVisPos );
575+
if ( VM_IsNative( gvm ) ) {
576+
return VM_Call( gvm, AICAST_VISIBLEFROMPOS, srcpos, srcnum, destpos, destnum, updateVisPos );
577+
} else {
578+
qboolean ret;
579+
unsigned gSrcPos;
580+
unsigned gDestPos;
581+
582+
gSrcPos = VM_GetTempMemory( gvm, sizeof(vec3_t), srcpos );
583+
gDestPos = VM_GetTempMemory( gvm, sizeof(vec3_t), destpos );
584+
585+
ret = VM_Call( gvm, AICAST_VISIBLEFROMPOS, gSrcPos, srcnum, gDestPos, destnum, updateVisPos );
586+
587+
VM_FreeTempMemory( gvm, gDestPos, sizeof(vec3_t), destpos );
588+
VM_FreeTempMemory( gvm, gSrcPos, sizeof(vec3_t), srcpos );
589+
590+
return ret;
591+
}
576592
}
577593

578594
/*
@@ -581,7 +597,20 @@ BotImport_AICast_CheckAttackAtPos
581597
===============
582598
*/
583599
qboolean BotImport_AICast_CheckAttackAtPos( int entnum, int enemy, vec3_t pos, qboolean ducking, qboolean allowHitWorld ) {
584-
return VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, pos, ducking, allowHitWorld );
600+
if ( VM_IsNative( gvm ) ) {
601+
return VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, pos, ducking, allowHitWorld );
602+
} else {
603+
qboolean ret;
604+
unsigned gPos;
605+
606+
gPos = VM_GetTempMemory( gvm, sizeof(vec3_t), pos );
607+
608+
ret = VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, gPos, ducking, allowHitWorld );
609+
610+
VM_FreeTempMemory( gvm, gPos, sizeof(vec3_t), pos );
611+
612+
return ret;
613+
}
585614
}
586615
// done.
587616

SP/code/cgame/cg_players.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ qboolean CG_ParseAnimationFiles( char *modelname, animModelInfo_t *modelInfo, in
509509
Com_sprintf( filename, sizeof( filename ), "models/players/%s/wolfanim.cfg", modelname );
510510
len = trap_FS_FOpenFile( filename, &f, FS_READ );
511511
if ( len <= 0 ) {
512-
CG_Printf( "G_ParseAnimationFiles(): file '%s' not found\n", filename ); //----(SA) added
512+
CG_Printf( "CG_ParseAnimationFiles(): file '%s' not found\n", filename ); //----(SA) added
513513
return qfalse;
514514
}
515515
if ( len >= sizeof( text ) - 1 ) {

SP/code/cgame/cg_syscalls.asm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ equ trap_CIN_DrawCinematic -94
100100
equ trap_CIN_SetExtents -95
101101
equ trap_R_RemapShader -96
102102

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

105-
equ trap_S_StopLoopingSound -98
106-
equ trap_S_StopStreamingSound -99
107-
equ trap_loadCamera -100
108-
equ trap_startCamera -101
109-
equ trap_stopCamera -102
110-
equ trap_getCameraInfo -103
105+
equ trap_S_StopLoopingSound -97
106+
equ trap_S_StopStreamingSound -98
107+
equ trap_loadCamera -99
108+
equ trap_startCamera -100
109+
equ trap_stopCamera -101
110+
equ trap_getCameraInfo -102
111111

112112
equ memset -111
113113
equ memcpy -112

SP/code/client/cl_cgame.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,18 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) {
829829
// - NERVE - SMF
830830

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

834845
// New in IORTCW
835846
case CG_ALLOC:

SP/code/server/sv_bot.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,23 @@ BotImport_AICast_VisibleFromPos
551551
*/
552552
qboolean BotImport_AICast_VisibleFromPos( vec3_t srcpos, int srcnum,
553553
vec3_t destpos, int destnum, qboolean updateVisPos ) {
554-
return VM_Call( gvm, AICAST_VISIBLEFROMPOS, srcpos, srcnum, destpos, destnum, updateVisPos );
554+
if ( VM_IsNative( gvm ) ) {
555+
return VM_Call( gvm, AICAST_VISIBLEFROMPOS, srcpos, srcnum, destpos, destnum, updateVisPos );
556+
} else {
557+
qboolean ret;
558+
unsigned gSrcPos;
559+
unsigned gDestPos;
560+
561+
gSrcPos = VM_GetTempMemory( gvm, sizeof(vec3_t), srcpos );
562+
gDestPos = VM_GetTempMemory( gvm, sizeof(vec3_t), destpos );
563+
564+
ret = VM_Call( gvm, AICAST_VISIBLEFROMPOS, gSrcPos, srcnum, gDestPos, destnum, updateVisPos );
565+
566+
VM_FreeTempMemory( gvm, gDestPos, sizeof(vec3_t), destpos );
567+
VM_FreeTempMemory( gvm, gSrcPos, sizeof(vec3_t), srcpos );
568+
569+
return ret;
570+
}
555571
}
556572

557573
/*
@@ -560,7 +576,20 @@ BotImport_AICast_CheckAttackAtPos
560576
===============
561577
*/
562578
qboolean BotImport_AICast_CheckAttackAtPos( int entnum, int enemy, vec3_t pos, qboolean ducking, qboolean allowHitWorld ) {
563-
return VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, pos, ducking, allowHitWorld );
579+
if ( VM_IsNative( gvm ) ) {
580+
return VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, pos, ducking, allowHitWorld );
581+
} else {
582+
qboolean ret;
583+
unsigned gPos;
584+
585+
gPos = VM_GetTempMemory( gvm, sizeof(vec3_t), pos );
586+
587+
ret = VM_Call( gvm, AICAST_CHECKATTACKATPOS, entnum, enemy, gPos, ducking, allowHitWorld );
588+
589+
VM_FreeTempMemory( gvm, gPos, sizeof(vec3_t), pos );
590+
591+
return ret;
592+
}
564593
}
565594
// done.
566595

SP/code/server/sv_game.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,5 +1074,24 @@ qboolean SV_GetModelInfo( int clientNum, char *modelName, animModelInfo_t **mode
10741074
if ( !gvm ) {
10751075
return qfalse;
10761076
}
1077-
return VM_Call( gvm, GAME_GETMODELINFO, clientNum, modelName, modelInfo );
1077+
1078+
if ( VM_IsNative( gvm ) ) {
1079+
return VM_Call( gvm, GAME_GETMODELINFO, clientNum, modelName, modelInfo );
1080+
} else {
1081+
// Setting a pointer to Game QVM animModelInfo_t struct won't work
1082+
// as it contains pointers (offset in QVM memory block) that will
1083+
// have to be converted to a real pointers for CGame DLL to use it.
1084+
// Additionally, there may be different struct alignment.
1085+
//
1086+
// That would require making a copy for CGame using VM_Alloc()
1087+
// (and tracking modelinfo to reuse?) to fix pointers and alignment
1088+
// issues. That would need means having to hard code animModelInfo_t.
1089+
// Which is a lot of weird hard coding work and iortcw already added
1090+
// a fall back for trap_GetModelInfo() in CGame to allow demo playback
1091+
// so this is unnecessary.
1092+
//
1093+
// FIXME: It would be necessary for using Game QVM with vanilla CGame DLL.
1094+
// --zturtleman
1095+
return qfalse;
1096+
}
10781097
}

0 commit comments

Comments
 (0)