mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 15:21:51 +00:00
- removed the FxDamageValue hack and implemented it properly using FxReturnStatement.
- added handling of damage functions for ZScript.
This commit is contained in:
parent
e50315bd31
commit
7c759f9fcf
8 changed files with 37 additions and 36 deletions
|
@ -727,3 +727,5 @@ xx(__decorate_internal_int__)
|
|||
xx(__decorate_internal_bool__)
|
||||
xx(__decorate_internal_state__)
|
||||
xx(__decorate_internal_float__)
|
||||
|
||||
xx(DamageFunction)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -155,6 +155,7 @@ FName CheckCastKludges(FName in);
|
|||
void SetImplicitArgs(TArray<PType *> *args, TArray<DWORD> *argflags, TArray<FName> *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);
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue