mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-13 16:07:45 +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_bool__)
|
||||||
xx(__decorate_internal_state__)
|
xx(__decorate_internal_state__)
|
||||||
xx(__decorate_internal_float__)
|
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
|
class FxNop : public FxExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -664,7 +664,7 @@ static bool ParsePropertyParams(FScanner &sc, FPropertyInfo *prop, AActor *defau
|
||||||
{
|
{
|
||||||
conv.i = -1;
|
conv.i = -1;
|
||||||
params.Push(conv);
|
params.Push(conv);
|
||||||
x = new FxDamageValue(new FxIntCast(ParseExpression(sc, bag.Info), true));
|
x = ParseExpression(sc, bag.Info);
|
||||||
sc.MustGetStringName(")");
|
sc.MustGetStringName(")");
|
||||||
conv.exp = x;
|
conv.exp = x;
|
||||||
params.Push(conv);
|
params.Push(conv);
|
||||||
|
|
|
@ -184,6 +184,28 @@ PFunction *FindClassMemberFunction(PClass *selfcls, PClass *funccls, FName name,
|
||||||
return funcsym;
|
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
|
// LoadActors
|
||||||
|
|
|
@ -155,6 +155,7 @@ FName CheckCastKludges(FName in);
|
||||||
void SetImplicitArgs(TArray<PType *> *args, TArray<DWORD> *argflags, TArray<FName> *argnames, PClass *cls, DWORD funcflags);
|
void SetImplicitArgs(TArray<PType *> *args, TArray<DWORD> *argflags, TArray<FName> *argnames, PClass *cls, DWORD funcflags);
|
||||||
PFunction *CreateAnonymousFunction(PClass *containingclass, PType *returntype, int flags);
|
PFunction *CreateAnonymousFunction(PClass *containingclass, PType *returntype, int flags);
|
||||||
PFunction *FindClassMemberFunction(PClass *cls, PClass *funccls, FName name, FScriptPosition &sc, bool *error);
|
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
|
// compatibility reasons, expressions must be enclosed within
|
||||||
// parentheses.
|
// parentheses.
|
||||||
|
|
||||||
// Store this expression here for now. It will be converted to a function
|
|
||||||
// later once all actors have been processed.
|
|
||||||
defaults->DamageVal = dmgval;
|
defaults->DamageVal = dmgval;
|
||||||
|
// Only DECORATE can get here with a valid expression.
|
||||||
if (id == nullptr)
|
CreateDamageFunction(bag.Info, defaults, id, true);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
|
@ -684,10 +684,6 @@ void FFunctionBuildList::Build()
|
||||||
|
|
||||||
for (auto &item : mItems)
|
for (auto &item : mItems)
|
||||||
{
|
{
|
||||||
if (item.PrintableName.CompareNoCase("Middle.StateFunction.3") == 0)
|
|
||||||
{
|
|
||||||
int a = 0;
|
|
||||||
}
|
|
||||||
assert(item.Code != NULL);
|
assert(item.Code != NULL);
|
||||||
|
|
||||||
// We don't know the return type in advance for anonymous functions.
|
// 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->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
|
// a one-name property
|
||||||
propname = FName(namenode->Id);
|
propname = FName(namenode->Id);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (namenode->SiblingNext->SiblingNext == namenode)
|
else if (namenode->SiblingNext->SiblingNext == namenode)
|
||||||
{
|
{
|
||||||
|
@ -1787,6 +1795,7 @@ void ZCCCompiler::ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt *pro
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FPropertyInfo *property = FindProperty(propname);
|
FPropertyInfo *property = FindProperty(propname);
|
||||||
|
|
||||||
if (property != nullptr && property->category != CAT_INFO)
|
if (property != nullptr && property->category != CAT_INFO)
|
||||||
|
|
Loading…
Reference in a new issue