Allow property-less flagdefs for non-actors

This commit is contained in:
Ricardo Luís Vaz Silva 2023-10-28 16:38:12 -03:00
parent 1e4f176395
commit 3a83762c51

View file

@ -161,17 +161,14 @@ bool ZCCDoomCompiler::CompileProperties(PClass *type, TArray<ZCC_Property *> &Pr
bool ZCCDoomCompiler::CompileFlagDefs(PClass *type, TArray<ZCC_FlagDef *> &Properties, FName prefix) bool ZCCDoomCompiler::CompileFlagDefs(PClass *type, TArray<ZCC_FlagDef *> &Properties, FName prefix)
{ {
if (!type->IsDescendantOf(RUNTIME_CLASS(AActor))) //[RL0] allow property-less flagdefs for non-actors
{ bool isActor = type->IsDescendantOf(RUNTIME_CLASS(AActor));
Error(Properties[0], "Flags can only be defined for actors");
return false;
}
for (auto p : Properties) for (auto p : Properties)
{ {
PField *field; PField *field;
FName referenced = FName(p->RefName); FName referenced = FName(p->RefName);
if (FName(p->NodeName) == FName("prefix") && fileSystem.GetFileContainer(Lump) == 0) if (isActor && FName(p->NodeName) == FName("prefix") && fileSystem.GetFileContainer(Lump) == 0)
{ {
// only for internal definitions: Allow setting a prefix. This is only for compatiblity with the old DECORATE property parser, but not for general use. // only for internal definitions: Allow setting a prefix. This is only for compatiblity with the old DECORATE property parser, but not for general use.
prefix = referenced; prefix = referenced;
@ -192,11 +189,14 @@ bool ZCCDoomCompiler::CompileFlagDefs(PClass *type, TArray<ZCC_FlagDef *> &Prope
} }
else field = nullptr; else field = nullptr;
FName name = FName(p->NodeName);
if(isActor)
{
FString qualifiedname; FString qualifiedname;
// Store the full qualified name and prepend some 'garbage' to the name so that no conflicts with other symbol types can happen. // Store the full qualified name and prepend some 'garbage' to the name so that no conflicts with other symbol types can happen.
// All these will be removed from the symbol table after the compiler finishes to free up the allocated space. // All these will be removed from the symbol table after the compiler finishes to free up the allocated space.
FName name = FName(p->NodeName);
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
if (i == 0) qualifiedname.Format("@flagdef@%s", name.GetChars()); if (i == 0) qualifiedname.Format("@flagdef@%s", name.GetChars());
@ -211,6 +211,7 @@ bool ZCCDoomCompiler::CompileFlagDefs(PClass *type, TArray<ZCC_FlagDef *> &Prope
Error(p, "Unable to add flag definition %s to class %s", FName(p->NodeName).GetChars(), type->TypeName.GetChars()); Error(p, "Unable to add flag definition %s to class %s", FName(p->NodeName).GetChars(), type->TypeName.GetChars());
} }
} }
}
if (field != nullptr) if (field != nullptr)
type->VMType->AddNativeField(FStringf("b%s", name.GetChars()), TypeSInt32, field->Offset, 0, 1 << p->BitValue); type->VMType->AddNativeField(FStringf("b%s", name.GetChars()), TypeSInt32, field->Offset, 0, 1 << p->BitValue);