From a6d982ed04da7ff13ae3fa4a02989baf0836ee3d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 6 Apr 2020 21:57:47 +0200 Subject: [PATCH] - resolve the single Doom specific dependency in the VM by using a callback. --- source/common/scripting/jit/jit_move.cpp | 2 +- source/common/scripting/vm/vm.h | 2 ++ source/common/scripting/vm/vmexec.cpp | 3 +++ source/common/scripting/vm/vmexec.h | 3 +-- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/common/scripting/jit/jit_move.cpp b/source/common/scripting/jit/jit_move.cpp index d6b870646..584de35a1 100644 --- a/source/common/scripting/jit/jit_move.cpp +++ b/source/common/scripting/jit/jit_move.cpp @@ -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() diff --git a/source/common/scripting/vm/vm.h b/source/common/scripting/vm/vm.h index cb5c2dab5..0eeec06b4 100644 --- a/source/common/scripting/vm/vm.h +++ b/source/common/scripting/vm/vm.h @@ -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; diff --git a/source/common/scripting/vm/vmexec.cpp b/source/common/scripting/vm/vmexec.cpp index 088988bd7..6921d3dac 100644 --- a/source/common/scripting/vm/vmexec.cpp +++ b/source/common/scripting/vm/vmexec.cpp @@ -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); diff --git a/source/common/scripting/vm/vmexec.h b/source/common/scripting/vm/vmexec.h index 0e28bee2a..72e0d0199 100644 --- a/source/common/scripting/vm/vmexec.h +++ b/source/common/scripting/vm/vmexec.h @@ -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 ®, 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(®.s[a], reg.d[b]); break; case CAST_TID2S: