diff --git a/src/namedef.h b/src/namedef.h index 9735578744..3587643e8a 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -727,3 +727,5 @@ xx(__decorate_internal_int__) xx(__decorate_internal_bool__) xx(__decorate_internal_state__) xx(__decorate_internal_float__) + +xx(DamageFunction) diff --git a/src/scripting/codegeneration/codegen.h b/src/scripting/codegeneration/codegen.h index d099daa22c..f6468e61f0 100644 --- a/src/scripting/codegeneration/codegen.h +++ b/src/scripting/codegeneration/codegen.h @@ -1531,25 +1531,6 @@ public: // //========================================================================== -class FxDamageValue : public FxExpression -{ - FxExpression *val; - -public: - - FxDamageValue(FxExpression *v); - ~FxDamageValue(); - FxExpression *Resolve(FCompileContext&); - - ExpEmit Emit(VMFunctionBuilder *build); -}; - -//========================================================================== -// -// -// -//========================================================================== - class FxNop : public FxExpression { public: diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index bd4885c87b..b344a12283 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -664,7 +664,7 @@ static bool ParsePropertyParams(FScanner &sc, FPropertyInfo *prop, AActor *defau { conv.i = -1; params.Push(conv); - x = new FxDamageValue(new FxIntCast(ParseExpression(sc, bag.Info), true)); + x = ParseExpression(sc, bag.Info); sc.MustGetStringName(")"); conv.exp = x; params.Push(conv); diff --git a/src/scripting/thingdef.cpp b/src/scripting/thingdef.cpp index 183c3f69ee..8c42e8987d 100644 --- a/src/scripting/thingdef.cpp +++ b/src/scripting/thingdef.cpp @@ -184,6 +184,28 @@ PFunction *FindClassMemberFunction(PClass *selfcls, PClass *funccls, FName name, return funcsym; } +//========================================================================== +// +// CreateDamageFunction +// +// creates a damage function from the given expression +// +//========================================================================== + +void CreateDamageFunction(PClassActor *info, AActor *defaults, FxExpression *id, bool fromDecorate) +{ + if (id == nullptr) + { + defaults->DamageFunc = nullptr; + } + else + { + auto dmg = new FxReturnStatement(new FxIntCast(id, true), id->ScriptPosition); + auto funcsym = CreateAnonymousFunction(info, TypeSInt32, VARF_Method); + defaults->DamageFunc = FunctionBuildList.AddFunction(funcsym, dmg, FStringf("%s.DamageFunction", info->TypeName.GetChars()), fromDecorate); + } +} + //========================================================================== // // LoadActors diff --git a/src/scripting/thingdef.h b/src/scripting/thingdef.h index 44a441bee9..b2d34231de 100644 --- a/src/scripting/thingdef.h +++ b/src/scripting/thingdef.h @@ -155,6 +155,7 @@ FName CheckCastKludges(FName in); void SetImplicitArgs(TArray *args, TArray *argflags, TArray *argnames, PClass *cls, DWORD funcflags); PFunction *CreateAnonymousFunction(PClass *containingclass, PType *returntype, int flags); PFunction *FindClassMemberFunction(PClass *cls, PClass *funccls, FName name, FScriptPosition &sc, bool *error); +void CreateDamageFunction(PClassActor *info, AActor *defaults, FxExpression *id, bool fromDecorate); //========================================================================== // diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index d3fb452cbf..6f1455e435 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -647,19 +647,9 @@ DEFINE_PROPERTY(damage, X, Actor) // compatibility reasons, expressions must be enclosed within // parentheses. - // Store this expression here for now. It will be converted to a function - // later once all actors have been processed. defaults->DamageVal = dmgval; - - if (id == nullptr) - { - defaults->DamageFunc = nullptr; - } - else - { - auto funcsym = CreateAnonymousFunction(bag.Info, TypeSInt32, VARF_Method); - defaults->DamageFunc = FunctionBuildList.AddFunction(funcsym, id, FStringf("%s.DamageFunction", bag.Info->TypeName.GetChars()), !bag.fromZScript); - } + // Only DECORATE can get here with a valid expression. + CreateDamageFunction(bag.Info, defaults, id, true); } //========================================================================== diff --git a/src/scripting/vm/vmbuilder.cpp b/src/scripting/vm/vmbuilder.cpp index c72c2b5670..7f8a643c68 100644 --- a/src/scripting/vm/vmbuilder.cpp +++ b/src/scripting/vm/vmbuilder.cpp @@ -684,10 +684,6 @@ void FFunctionBuildList::Build() for (auto &item : mItems) { - if (item.PrintableName.CompareNoCase("Middle.StateFunction.3") == 0) - { - int a = 0; - } assert(item.Code != NULL); // We don't know the return type in advance for anonymous functions. diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index afc74e75e5..f0f884f68e 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -1773,8 +1773,16 @@ void ZCCCompiler::ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt *pro if (namenode->SiblingNext == namenode) { + if (namenode->Id == NAME_DamageFunction) + { + auto x = ConvertNode(prop->Values); + CreateDamageFunction(cls, (AActor *)bag.Info->Defaults, x, false); + return; + } + // a one-name property propname = FName(namenode->Id); + } else if (namenode->SiblingNext->SiblingNext == namenode) { @@ -1787,6 +1795,7 @@ void ZCCCompiler::ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt *pro return; } + FPropertyInfo *property = FindProperty(propname); if (property != nullptr && property->category != CAT_INFO)