mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 05:21:16 +00:00
backend update from Raze.
Mainly a VMFunction script type and some associated utilities.
This commit is contained in:
parent
06466b9017
commit
79f2fc6553
13 changed files with 79 additions and 3 deletions
|
@ -179,8 +179,6 @@ public: \
|
||||||
|
|
||||||
#include "dobjgc.h"
|
#include "dobjgc.h"
|
||||||
|
|
||||||
class AActor;
|
|
||||||
|
|
||||||
class DObject
|
class DObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -245,6 +243,7 @@ public:
|
||||||
inline DAngle &AngleVar(FName field);
|
inline DAngle &AngleVar(FName field);
|
||||||
inline FString &StringVar(FName field);
|
inline FString &StringVar(FName field);
|
||||||
template<class T> T*& PointerVar(FName field);
|
template<class T> T*& PointerVar(FName field);
|
||||||
|
inline int* IntArray(FName field);
|
||||||
|
|
||||||
// This is only needed for swapping out PlayerPawns and absolutely nothing else!
|
// This is only needed for swapping out PlayerPawns and absolutely nothing else!
|
||||||
virtual size_t PointerSubstitution (DObject *old, DObject *notOld);
|
virtual size_t PointerSubstitution (DObject *old, DObject *notOld);
|
||||||
|
@ -435,6 +434,11 @@ inline int &DObject::IntVar(FName field)
|
||||||
return *(int*)ScriptVar(field, nullptr);
|
return *(int*)ScriptVar(field, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int* DObject::IntArray(FName field)
|
||||||
|
{
|
||||||
|
return (int*)ScriptVar(field, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
inline FTextureID &DObject::TextureIDVar(FName field)
|
inline FTextureID &DObject::TextureIDVar(FName field)
|
||||||
{
|
{
|
||||||
return *(FTextureID*)ScriptVar(field, nullptr);
|
return *(FTextureID*)ScriptVar(field, nullptr);
|
||||||
|
|
|
@ -6358,6 +6358,16 @@ FxExpression *FxIdentifier::Resolve(FCompileContext& ctx)
|
||||||
ABORT(newex);
|
ABORT(newex);
|
||||||
goto foundit;
|
goto foundit;
|
||||||
}
|
}
|
||||||
|
else if (sym->IsKindOf(RUNTIME_CLASS(PFunction)))
|
||||||
|
{
|
||||||
|
if (ctx.Version >= MakeVersion(4, 11, 100))
|
||||||
|
{
|
||||||
|
// VMFunction is only supported since 4.12 and Raze 1.8.
|
||||||
|
newex = new FxConstant(static_cast<PFunction*>(sym)->Variants[0].Implementation, ScriptPosition);
|
||||||
|
goto foundit;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now check in the owning class.
|
// now check in the owning class.
|
||||||
|
@ -6369,6 +6379,15 @@ FxExpression *FxIdentifier::Resolve(FCompileContext& ctx)
|
||||||
newex = FxConstant::MakeConstant(sym, ScriptPosition);
|
newex = FxConstant::MakeConstant(sym, ScriptPosition);
|
||||||
goto foundit;
|
goto foundit;
|
||||||
}
|
}
|
||||||
|
else if (sym->IsKindOf(RUNTIME_CLASS(PFunction)))
|
||||||
|
{
|
||||||
|
if (ctx.Version >= MakeVersion(4, 11, 100))
|
||||||
|
{
|
||||||
|
// VMFunction is only supported since 4.12 and Raze 1.8.
|
||||||
|
newex = new FxConstant(static_cast<PFunction*>(sym)->Variants[0].Implementation, ScriptPosition);
|
||||||
|
goto foundit;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (ctx.Function == nullptr)
|
else if (ctx.Function == nullptr)
|
||||||
{
|
{
|
||||||
ScriptPosition.Message(MSG_ERROR, "Unable to access class member %s from constant declaration", sym->SymbolName.GetChars());
|
ScriptPosition.Message(MSG_ERROR, "Unable to access class member %s from constant declaration", sym->SymbolName.GetChars());
|
||||||
|
|
|
@ -506,6 +506,13 @@ public:
|
||||||
isresolved = true;
|
isresolved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FxConstant(VMFunction* state, const FScriptPosition& pos) : FxExpression(EFX_Constant, pos)
|
||||||
|
{
|
||||||
|
value.pointer = state;
|
||||||
|
ValueType = value.Type = TypeVMFunction;
|
||||||
|
isresolved = true;
|
||||||
|
}
|
||||||
|
|
||||||
FxConstant(const FScriptPosition &pos) : FxExpression(EFX_Constant, pos)
|
FxConstant(const FScriptPosition &pos) : FxExpression(EFX_Constant, pos)
|
||||||
{
|
{
|
||||||
value.pointer = nullptr;
|
value.pointer = nullptr;
|
||||||
|
|
|
@ -147,6 +147,24 @@ VMFunction *FindVMFunction(PClass *cls, const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// Find an action function in AActor's table from a qualified name
|
||||||
|
// This cannot search in structs. sorry. :(
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
VMFunction* FindVMFunction( const char* name)
|
||||||
|
{
|
||||||
|
auto p = strchr(name, '.');
|
||||||
|
if (p == nullptr) return nullptr;
|
||||||
|
std::string clsname(name, p - name);
|
||||||
|
auto cls = PClass::FindClass(clsname.c_str());
|
||||||
|
if (cls == nullptr) return nullptr;
|
||||||
|
return FindVMFunction(cls, p + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// Sorting helpers
|
// Sorting helpers
|
||||||
|
|
|
@ -75,6 +75,7 @@ PStruct *TypeStringStruct;
|
||||||
PStruct* TypeQuaternionStruct;
|
PStruct* TypeQuaternionStruct;
|
||||||
PPointer *TypeNullPtr;
|
PPointer *TypeNullPtr;
|
||||||
PPointer *TypeVoidPtr;
|
PPointer *TypeVoidPtr;
|
||||||
|
PPointer* TypeVMFunction;
|
||||||
|
|
||||||
|
|
||||||
// CODE --------------------------------------------------------------------
|
// CODE --------------------------------------------------------------------
|
||||||
|
@ -322,6 +323,7 @@ void PType::StaticInit()
|
||||||
TypeTable.AddType(TypeTextureID = new PTextureID, NAME_TextureID);
|
TypeTable.AddType(TypeTextureID = new PTextureID, NAME_TextureID);
|
||||||
|
|
||||||
TypeVoidPtr = NewPointer(TypeVoid, false);
|
TypeVoidPtr = NewPointer(TypeVoid, false);
|
||||||
|
TypeVMFunction = NewPointer(NewStruct("VMFunction", nullptr, true));
|
||||||
TypeColorStruct = NewStruct("@ColorStruct", nullptr); //This name is intentionally obfuscated so that it cannot be used explicitly. The point of this type is to gain access to the single channels of a color value.
|
TypeColorStruct = NewStruct("@ColorStruct", nullptr); //This name is intentionally obfuscated so that it cannot be used explicitly. The point of this type is to gain access to the single channels of a color value.
|
||||||
TypeStringStruct = NewStruct("Stringstruct", nullptr, true);
|
TypeStringStruct = NewStruct("Stringstruct", nullptr, true);
|
||||||
TypeQuaternionStruct = NewStruct("QuatStruct", nullptr, true);
|
TypeQuaternionStruct = NewStruct("QuatStruct", nullptr, true);
|
||||||
|
|
|
@ -697,6 +697,8 @@ extern PPointer *TypeFont;
|
||||||
extern PStateLabel *TypeStateLabel;
|
extern PStateLabel *TypeStateLabel;
|
||||||
extern PPointer *TypeNullPtr;
|
extern PPointer *TypeNullPtr;
|
||||||
extern PPointer *TypeVoidPtr;
|
extern PPointer *TypeVoidPtr;
|
||||||
|
extern PPointer* TypeVMFunction;
|
||||||
|
|
||||||
|
|
||||||
inline FString &DObject::StringVar(FName field)
|
inline FString &DObject::StringVar(FName field)
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,6 +57,13 @@ double GetFloatConst(FxExpression *ex, FCompileContext &ctx)
|
||||||
return ex ? static_cast<FxConstant*>(ex)->GetValue().GetFloat() : 0;
|
return ex ? static_cast<FxConstant*>(ex)->GetValue().GetFloat() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VMFunction* GetFuncConst(FxExpression* ex, FCompileContext& ctx)
|
||||||
|
{
|
||||||
|
ex = new FxTypeCast(ex, TypeVMFunction, false);
|
||||||
|
ex = ex->Resolve(ctx);
|
||||||
|
return static_cast<VMFunction*>(ex ? static_cast<FxConstant*>(ex)->GetValue().GetPointer() : nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
const char * ZCCCompiler::GetStringConst(FxExpression *ex, FCompileContext &ctx)
|
const char * ZCCCompiler::GetStringConst(FxExpression *ex, FCompileContext &ctx)
|
||||||
{
|
{
|
||||||
ex = new FxStringCast(ex);
|
ex = new FxStringCast(ex);
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
struct Baggage;
|
struct Baggage;
|
||||||
struct FPropertyInfo;
|
struct FPropertyInfo;
|
||||||
class AActor;
|
|
||||||
class FxExpression;
|
class FxExpression;
|
||||||
typedef TDeletingArray<FxExpression*> FArgumentList;
|
typedef TDeletingArray<FxExpression*> FArgumentList;
|
||||||
|
|
||||||
|
|
|
@ -797,6 +797,7 @@ class AActor;
|
||||||
class PFunction;
|
class PFunction;
|
||||||
|
|
||||||
VMFunction *FindVMFunction(PClass *cls, const char *name);
|
VMFunction *FindVMFunction(PClass *cls, const char *name);
|
||||||
|
VMFunction* FindVMFunction(const char* name);
|
||||||
#define DECLARE_VMFUNC(cls, name) static VMFunction *name; if (name == nullptr) name = FindVMFunction(RUNTIME_CLASS(cls), #name);
|
#define DECLARE_VMFUNC(cls, name) static VMFunction *name; if (name == nullptr) name = FindVMFunction(RUNTIME_CLASS(cls), #name);
|
||||||
|
|
||||||
FString FStringFormat(VM_ARGS, int offset = 0);
|
FString FStringFormat(VM_ARGS, int offset = 0);
|
||||||
|
|
|
@ -66,6 +66,10 @@ public:
|
||||||
bool NextInSection (const char *&key, const char *&value);
|
bool NextInSection (const char *&key, const char *&value);
|
||||||
const char *GetValueForKey (const char *key) const;
|
const char *GetValueForKey (const char *key) const;
|
||||||
void SetValueForKey (const char *key, const char *value, bool duplicates=false);
|
void SetValueForKey (const char *key, const char *value, bool duplicates=false);
|
||||||
|
void SetValueForKey(const char* key, const FString& value, bool duplicates = false)
|
||||||
|
{
|
||||||
|
SetValueForKey(key, value.GetChars(), duplicates);
|
||||||
|
}
|
||||||
|
|
||||||
const char *GetPathName () const { return PathName.GetChars(); }
|
const char *GetPathName () const { return PathName.GetChars(); }
|
||||||
void ChangePathName (const char *path);
|
void ChangePathName (const char *path);
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "v_draw.h"
|
#include "v_draw.h"
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
|
|
||||||
|
class AActor;
|
||||||
|
|
||||||
EXTERN_CVAR(Int, con_scaletext);
|
EXTERN_CVAR(Int, con_scaletext);
|
||||||
inline int active_con_scaletext(F2DDrawer* drawer, bool newconfont = false)
|
inline int active_con_scaletext(F2DDrawer* drawer, bool newconfont = false)
|
||||||
|
|
|
@ -256,6 +256,7 @@ union FPropParam
|
||||||
int i;
|
int i;
|
||||||
double d;
|
double d;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
VMFunction* fu;
|
||||||
FxExpression *exp;
|
FxExpression *exp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -313,6 +314,9 @@ int MatchString (const char *in, const char **strings);
|
||||||
#define PROP_STRING_PARM(var, no) \
|
#define PROP_STRING_PARM(var, no) \
|
||||||
const char *var = params[(no)+1].s;
|
const char *var = params[(no)+1].s;
|
||||||
|
|
||||||
|
#define PROP_NAME_PARM(var, no) \
|
||||||
|
FName var = params[(no)+1].s;
|
||||||
|
|
||||||
#define PROP_EXP_PARM(var, no) \
|
#define PROP_EXP_PARM(var, no) \
|
||||||
FxExpression *var = params[(no)+1].exp;
|
FxExpression *var = params[(no)+1].exp;
|
||||||
|
|
||||||
|
@ -325,6 +329,9 @@ int MatchString (const char *in, const char **strings);
|
||||||
#define PROP_DOUBLE_PARM(var, no) \
|
#define PROP_DOUBLE_PARM(var, no) \
|
||||||
double var = params[(no)+1].d;
|
double var = params[(no)+1].d;
|
||||||
|
|
||||||
|
#define PROP_FUNC_PARM(var, no) \
|
||||||
|
auto var = params[(no)+1].fu;
|
||||||
|
|
||||||
#define PROP_COLOR_PARM(var, no, scriptpos) \
|
#define PROP_COLOR_PARM(var, no, scriptpos) \
|
||||||
int var = params[(no)+1].i== 0? params[(no)+2].i : V_GetColor(params[(no)+2].s, scriptpos);
|
int var = params[(no)+1].i== 0? params[(no)+2].i : V_GetColor(params[(no)+2].s, scriptpos);
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ bool isActor(PContainerType *type);
|
||||||
void AddActorInfo(PClass *cls);
|
void AddActorInfo(PClass *cls);
|
||||||
int GetIntConst(FxExpression* ex, FCompileContext& ctx);
|
int GetIntConst(FxExpression* ex, FCompileContext& ctx);
|
||||||
double GetFloatConst(FxExpression* ex, FCompileContext& ctx);
|
double GetFloatConst(FxExpression* ex, FCompileContext& ctx);
|
||||||
|
VMFunction* GetFuncConst(FxExpression* ex, FCompileContext& ctx);
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -282,6 +283,10 @@ void ZCCDoomCompiler::DispatchProperty(FPropertyInfo *prop, ZCC_PropertyStmt *pr
|
||||||
conv.d = GetFloatConst(ex, ctx);
|
conv.d = GetFloatConst(ex, ctx);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'G':
|
||||||
|
conv.fu = GetFuncConst(ex, ctx);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'Z': // an optional string. Does not allow any numeric value.
|
case 'Z': // an optional string. Does not allow any numeric value.
|
||||||
if (ex->ValueType != TypeString)
|
if (ex->ValueType != TypeString)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue