- resolve the single Doom specific dependency in the VM by using a callback.

This commit is contained in:
Christoph Oelckers 2020-04-06 21:57:47 +02:00
parent c9b2399cd0
commit a6d982ed04
4 changed files with 7 additions and 3 deletions

View file

@ -52,7 +52,7 @@ static int CastS2Co(FString *b) { return V_GetColor(nullptr, *b); }
static void CastCo2S(FString *a, int b) { PalEntry c(b); a->Format("%02x %02x %02x", c.r, c.g, c.b); }
static int CastS2So(FString *b) { return FSoundID(*b); }
static void CastSo2S(FString* a, int b) { *a = soundEngine->GetSoundName(b); }
static void CastSID2S(FString* a, unsigned int b) { *a = "";/* (b >= sprites.Size()) ? "TNT1" : sprites[b].name;*/ }
static void CastSID2S(FString* a, unsigned int b) { VM_CastSpriteIDToString(a, b); }
static void CastTID2S(FString *a, int b) { auto tex = TexMan.GetTexture(*(FTextureID*)&b); *a = (tex == nullptr) ? "(null)" : tex->GetName().GetChars(); }
void JitCompiler::EmitCAST()

View file

@ -56,6 +56,8 @@ extern FMemArena ClassDataAllocator;
void JitRelease();
extern void (*VM_CastSpriteIDToString)(FString* a, unsigned int b);
typedef unsigned char VM_UBYTE;
typedef signed char VM_SBYTE;

View file

@ -46,6 +46,9 @@
extern cycle_t VMCycles[10];
extern int VMCalls[10];
// THe sprite ID to string cast is game specific so let's do it with a callback to remove the dependency and allow easier reuse.
void (*VM_CastSpriteIDToString)(FString* a, unsigned int b) = [](FString* a, unsigned int b) { a->Format("%d", b); };
// intentionally implemented in a different source file to prevent inlining.
#if 0
void ThrowVMException(VMException *x);

View file

@ -1711,7 +1711,6 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
return 0;
}
static double DoFLOP(int flop, double v)
{
switch(flop)
@ -1843,7 +1842,7 @@ static void DoCast(const VMRegisters &reg, const VMFrame *f, int a, int b, int c
case CAST_SID2S:
ASSERTS(a); ASSERTD(b);
reg.s[a] = "";// unsigned(reg.d[b]) >= sprites.Size() ? "TNT1" : sprites[reg.d[b]].name;
VM_CastSpriteIDToString(&reg.s[a], reg.d[b]);
break;
case CAST_TID2S: