- reactivated some more code after integrating the VM core.

There's a few bits here and there that only have meaning in Doom but they are kept to allow using the same unaltered source files in both engines.
This commit is contained in:
Christoph Oelckers 2020-04-06 23:32:29 +02:00
parent a6d982ed04
commit bb9a077424
9 changed files with 162 additions and 36 deletions

View File

@ -637,6 +637,16 @@ set( NOT_COMPILED_SOURCE_FILES
platform/win32/zutil.natvis
)
set( VM_JIT_SOURCES
common/scripting/jit/jit.cpp
common/scripting/jit/jit_runtime.cpp
common/scripting/jit/jit_call.cpp
common/scripting/jit/jit_flow.cpp
common/scripting/jit/jit_load.cpp
common/scripting/jit/jit_math.cpp
common/scripting/jit/jit_move.cpp
common/scripting/jit/jit_store.cpp
)
# Enable fast math for some sources where performance matters (or where the PCH must not be used.) (This would be good for rendering code, but unfortunately that is hopelessly intermingled with the playsim code in engine.cpp.)
set( FASTMATH_SOURCES
@ -785,14 +795,6 @@ set (PCH_SOURCES
common/scripting/core/vmdisasm.cpp
common/scripting/vm/vmexec.cpp
common/scripting/vm/vmframe.cpp
common/scripting/jit/jit.cpp
common/scripting/jit/jit_call.cpp
common/scripting/jit/jit_flow.cpp
common/scripting/jit/jit_load.cpp
common/scripting/jit/jit_math.cpp
common/scripting/jit/jit_move.cpp
common/scripting/jit/jit_runtime.cpp
common/scripting/jit/jit_store.cpp
common/scripting/interface/stringformat.cpp
core/utility/stats.cpp
@ -846,6 +848,12 @@ set (PCH_SOURCES
core/rendering/hwrenderer/utility/hw_shaderpatcher.cpp
)
if( ${HAVE_VM_JIT} )
set( PCH_SOURCES ${PCH_SOURCES} ${VM_JIT_SOURCES} )
else()
set( NOT_COMPILED_SOURCE_FILES ${NOT_COMPILED_SOURCE_FILES} ${VM_JIT_SOURCES} )
endif()
macro( use_precompiled_header )
if( MSVC )
enable_precompiled_headers( "${ARGV0}/g_pch.h" PCH_SOURCES )

View File

@ -38,6 +38,8 @@
#include "cmdlib.h"
#include "c_dispatch.h"
#include "serializer.h"
#include "vm.h"
#include "types.h"
#include "i_time.h"
#include "printf.h"
@ -60,6 +62,9 @@ ClassReg DObject::RegistrationInfo =
};
_DECLARE_TI(DObject)
// This bit is needed in the playsim - but give it a less crappy name.
DEFINE_FIELD_BIT(DObject,ObjectFlags, bDestroyed, OF_EuthanizeMe)
//==========================================================================
//
@ -314,26 +319,22 @@ void DObject:: Destroy ()
// We cannot call the VM during shutdown because all the needed data has been or is in the process of being deleted.
if (PClass::bVMOperational)
{
#if 0
IFVIRTUAL(DObject, OnDestroy)
{
VMValue params[1] = { (DObject*)this };
VMCall(func, params, 1, nullptr, 0);
}
#endif
}
OnDestroy();
ObjectFlags = (ObjectFlags & ~OF_Fixed) | OF_EuthanizeMe;
}
#if 0
DEFINE_ACTION_FUNCTION(DObject, Destroy)
{
PARAM_SELF_PROLOGUE(DObject);
self->Destroy();
return 0;
}
#endif
//==========================================================================
//
@ -487,7 +488,6 @@ void DObject::CheckIfSerialized () const
}
#if 0
DEFINE_ACTION_FUNCTION(DObject, MSTime)
{
ACTION_RETURN_INT((uint32_t)I_msTime());
@ -512,4 +512,3 @@ void *DObject::ScriptVar(FName field, PType *type)
I_Error("Variable %s not found in %s\n", field.GetChars(), cls->TypeName.GetChars());
return nullptr;
}
#endif

View File

@ -392,7 +392,7 @@ static inline void GC::WriteBarrier(DObject *pointed)
#include "memarena.h"
extern FMemArena ClassDataAllocator;
//#include "symbols.h"
#include "symbols.h"
#include "dobjtype.h"
inline bool DObject::IsKindOf (const PClass *base) const

View File

@ -264,9 +264,21 @@ void MarkArray(DObject **obj, size_t count)
static void MarkRoot()
{
//int i;
Gray = NULL;
// Mark soft roots.
if (SoftRoots != NULL)
{
DObject **probe = &SoftRoots->ObjNext;
while (*probe != NULL)
{
DObject *soft = *probe;
probe = &soft->ObjNext;
if ((soft->ObjectFlags & (OF_Rooted | OF_EuthanizeMe)) == OF_Rooted)
{
Mark(soft);
}
}
}
// Time to propagate the marks.
State = GCS_Propagate;
StepCount = 0;

View File

@ -208,6 +208,11 @@ public:
return GC::ReadBarrier(pp);
}
T ForceGet() throw() //for situations where the read barrier needs to be skipped.
{
return pp;
}
operator T() throw()
{
return GC::ReadBarrier(pp);

View File

@ -42,6 +42,7 @@
#include "autosegs.h"
#include "v_text.h"
#include "c_cvars.h"
#include "vm.h"
#include "symbols.h"
#include "types.h"
@ -71,8 +72,8 @@ bool PClass::bVMOperational;
// that does not work anymore. WP_NOCHANGE needs to point to a vaild object to work as intended.
// This Object does not need to be garbage collected, though, but it needs to provide the proper structure so that the
// GC can process it.
AActor *WP_NOCHANGE;
//DEFINE_GLOBAL(WP_NOCHANGE);
DObject *WP_NOCHANGE;
DEFINE_GLOBAL(WP_NOCHANGE);
// PRIVATE DATA DEFINITIONS ------------------------------------------------
@ -202,9 +203,7 @@ static int cregcmp (const void *a, const void *b) NO_SANITIZE
void PClass::StaticInit ()
{
#if 0
Namespaces.GlobalNamespace = Namespaces.NewNamespace(0);
#endif
FAutoSegIterator probe(CRegHead, CRegTail);
@ -227,12 +226,10 @@ void PClass::StaticInit ()
// I'm not sure if this is really necessary to maintain any sort of sync.
qsort(&AllClasses[0], AllClasses.Size(), sizeof(AllClasses[0]), cregcmp);
#if 0
// WP_NOCHANGE must point to a valid object, although it does not need to be a weapon.
// A simple DObject is enough to give the GC the ability to deal with it, if subjected to it.
WP_NOCHANGE = (AActor*)Create<DObject>();
WP_NOCHANGE = Create<DObject>();
WP_NOCHANGE->Release();
#endif
}
//==========================================================================
@ -245,12 +242,10 @@ void PClass::StaticInit ()
void PClass::StaticShutdown ()
{
#if 0
if (WP_NOCHANGE != nullptr)
{
delete WP_NOCHANGE;
}
#endif
// delete all variables containing pointers to script functions.
for (auto p : FunctionPtrList)
@ -259,7 +254,7 @@ void PClass::StaticShutdown ()
}
//ScriptUtil::Clear();
FunctionPtrList.Clear();
//VMFunction::DeleteAll();
VMFunction::DeleteAll();
// Make a full garbage collection here so that all destroyed but uncollected higher level objects
// that still exist are properly taken down before the low level data is deleted.
@ -701,7 +696,7 @@ PClass *PClass::FindClassTentative(FName name)
// and returns an index if something matching is found.
//
//==========================================================================
#if 0
int PClass::FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc)
{
auto proto = variant->Proto;
@ -760,7 +755,6 @@ int PClass::FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction
}
return -1;
}
#endif
PSymbol *PClass::FindSymbol(FName symname, bool searchparents) const
{
@ -951,7 +945,6 @@ void PClass::FindFunction(VMFunction **pptr, FName clsname, FName funcname)
FunctionPtrList.Push(pptr);
}
#if 0
unsigned GetVirtualIndex(PClass *cls, const char *funcname)
{
// Look up the virtual function index in the defining class because this may have gotten overloaded in subclasses with something different than a virtual override.
@ -960,6 +953,4 @@ unsigned GetVirtualIndex(PClass *cls, const char *funcname)
auto VIndex = sym->Variants[0].Implementation->VirtualIndex;
return VIndex;
}
#endif

View File

@ -42,9 +42,7 @@ public:
void WriteAllFields(FSerializer &ar, const void *addr) const;
bool ReadAllFields(FSerializer &ar, void *addr) const;
void InitializeDefaults();
#if 0
int FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc);
#endif
PSymbol *FindSymbol(FName symname, bool searchparents) const;
PField *AddField(FName name, PType *type, uint32_t flags);

View File

@ -35,7 +35,6 @@
#include "vmintern.h"
#include "s_soundinternal.h"
//#include "dthinker.h"
#include "types.h"
#include "printf.h"
#include "textureid.h"
@ -56,6 +55,8 @@ PName *TypeName;
PSound *TypeSound;
PColor *TypeColor;
PTextureID *TypeTextureID;
PSpriteID *TypeSpriteID;
PStatePointer *TypeState;
PPointer *TypeFont;
PStateLabel *TypeStateLabel;
PStruct *TypeVector2;
@ -300,8 +301,10 @@ void PType::StaticInit()
TypeTable.AddType(TypeName = new PName, NAME_Name);
TypeTable.AddType(TypeSound = new PSound, NAME_Sound);
TypeTable.AddType(TypeColor = new PColor, NAME_Color);
TypeTable.AddType(TypeState = new PStatePointer, NAME_Pointer);
TypeTable.AddType(TypeStateLabel = new PStateLabel, NAME_Label);
TypeTable.AddType(TypeNullPtr = new PPointer, NAME_Pointer);
TypeTable.AddType(TypeSpriteID = new PSpriteID, NAME_SpriteID);
TypeTable.AddType(TypeTextureID = new PTextureID, NAME_TextureID);
TypeVoidPtr = NewPointer(TypeVoid, false);
@ -360,6 +363,7 @@ void PType::StaticInit()
Namespaces.GlobalNamespace->Symbols.AddSymbol(Create<PSymbolType>(NAME_Name, TypeName));
Namespaces.GlobalNamespace->Symbols.AddSymbol(Create<PSymbolType>(NAME_Sound, TypeSound));
Namespaces.GlobalNamespace->Symbols.AddSymbol(Create<PSymbolType>(NAME_Color, TypeColor));
Namespaces.GlobalNamespace->Symbols.AddSymbol(Create<PSymbolType>(NAME_State, TypeState));
Namespaces.GlobalNamespace->Symbols.AddSymbol(Create<PSymbolType>(NAME_Vector2, TypeVector2));
Namespaces.GlobalNamespace->Symbols.AddSymbol(Create<PSymbolType>(NAME_Vector3, TypeVector3));
}
@ -1074,6 +1078,51 @@ bool PName::ReadValue(FSerializer &ar, const char *key, void *addr) const
}
}
/* PSpriteID ******************************************************************/
//==========================================================================
//
// PName Default Constructor
//
//==========================================================================
PSpriteID::PSpriteID()
: PInt(sizeof(int), true, true)
{
Flags |= TYPE_IntNotInt;
mDescriptiveName = "SpriteID";
}
//==========================================================================
//
// PName :: WriteValue
//
//==========================================================================
void PSpriteID::WriteValue(FSerializer &ar, const char *key, const void *addr) const
{
int32_t val = *(int*)addr;
#ifdef GZDOOM
ar.Sprite(key, val, nullptr);
#endif
}
//==========================================================================
//
// PName :: ReadValue
//
//==========================================================================
bool PSpriteID::ReadValue(FSerializer &ar, const char *key, void *addr) const
{
int32_t val = 0;
#ifdef GZDOOM
ar.Sprite(key, val, nullptr);
#endif
*(int*)addr = val;
return true;
}
/* PTextureID ******************************************************************/
//==========================================================================
@ -1314,7 +1363,7 @@ PObjectPointer::PObjectPointer(PClass *cls, bool isconst)
loadOp = OP_LO;
Flags |= TYPE_ObjectPointer;
// Non-destroyed thinkers are always guaranteed to be linked into the thinker chain so we don't need the write barrier for them.
//if (cls && !cls->IsDescendantOf(RUNTIME_CLASS(DThinker))) storeOp = OP_SO;
if (cls && !cls->IsDescendantOf(NAME_Thinker)) storeOp = OP_SO;
}
//==========================================================================
@ -1391,6 +1440,49 @@ PPointer *NewPointer(PClass *cls, bool isconst)
return static_cast<PPointer *>(ptype);
}
/* PStatePointer **********************************************************/
//==========================================================================
//
// PStatePointer Default Constructor
//
//==========================================================================
PStatePointer::PStatePointer()
{
mDescriptiveName = "Pointer<State>";
PointedType = NewStruct(NAME_State, nullptr, true);
IsConst = true;
}
//==========================================================================
//
// PStatePointer :: WriteValue
//
//==========================================================================
void PStatePointer::WriteValue(FSerializer &ar, const char *key, const void *addr) const
{
#ifdef GZDOOM
ar(key, *(FState **)addr);
#endif
}
//==========================================================================
//
// PStatePointer :: ReadValue
//
//==========================================================================
bool PStatePointer::ReadValue(FSerializer &ar, const char *key, void *addr) const
{
bool res = false;
#ifdef GZDOOM
::Serialize(ar, key, *(FState **)addr, nullptr, &res);
#endif
return res;
}
/* PClassPointer **********************************************************/

View File

@ -356,6 +356,15 @@ public:
bool ReadValue(FSerializer &ar, const char *key,void *addr) const override;
};
class PSpriteID : public PInt
{
public:
PSpriteID();
void WriteValue(FSerializer &ar, const char *key, const void *addr) const override;
bool ReadValue(FSerializer &ar, const char *key, void *addr) const override;
};
class PTextureID : public PInt
{
public:
@ -411,6 +420,16 @@ protected:
void SetOps();
};
class PStatePointer : public PPointer
{
public:
PStatePointer();
void WriteValue(FSerializer &ar, const char *key, const void *addr) const override;
bool ReadValue(FSerializer &ar, const char *key, void *addr) const override;
};
class PObjectPointer : public PPointer
{
public:
@ -590,10 +609,12 @@ extern PName *TypeName;
extern PSound *TypeSound;
extern PColor *TypeColor;
extern PTextureID *TypeTextureID;
extern PSpriteID *TypeSpriteID;
extern PStruct *TypeVector2;
extern PStruct *TypeVector3;
extern PStruct *TypeColorStruct;
extern PStruct *TypeStringStruct;
extern PStatePointer *TypeState;
extern PPointer *TypeFont;
extern PStateLabel *TypeStateLabel;
extern PPointer *TypeNullPtr;