Skip to content

Commit

Permalink
Fix readonly for SpecialBounceHit virtual
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 authored and coelckers committed Feb 23, 2024
1 parent 144caa0 commit d848a57
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
20 changes: 17 additions & 3 deletions src/common/objects/dobjtype.cpp
Expand Up @@ -669,7 +669,7 @@ PClass *PClass::FindClassTentative(FName name)
//
//==========================================================================

int PClass::FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc, bool exactReturnType)
int PClass::FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc, bool exactReturnType, bool ignorePointerReadOnly)
{
auto proto = variant->Proto;
for (unsigned i = 0; i < Virtuals.Size(); i++)
Expand All @@ -689,8 +689,22 @@ int PClass::FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction
{
if (proto->ArgumentTypes[a] != vproto->ArgumentTypes[a])
{
fail = true;
break;
if(ignorePointerReadOnly && proto->ArgumentTypes[a]->isPointer() && vproto->ArgumentTypes[a]->isPointer())
{
PPointer *ppa = proto->ArgumentTypes[a]->toPointer();
PPointer *ppb = vproto->ArgumentTypes[a]->toPointer();

if(ppa->PointedType != ppb->PointedType)
{
fail = true;
break;
}
}
else
{
fail = true;
break;
}
}
}
if (fail) continue;
Expand Down
2 changes: 1 addition & 1 deletion src/common/objects/dobjtype.h
Expand Up @@ -43,7 +43,7 @@ class PClass
void InitializeSpecials(void* addr, void* defaults, TArray<FTypeAndOffset> PClass::* Inits);
void WriteAllFields(FSerializer &ar, const void *addr) const;
bool ReadAllFields(FSerializer &ar, void *addr) const;
int FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc, bool exactReturnType);
int FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc, bool exactReturnType, bool ignorePointerReadOnly);
PSymbol *FindSymbol(FName symname, bool searchparents) const;
PField *AddField(FName name, PType *type, uint32_t flags, int fileno = 0);
void InitializeDefaults();
Expand Down
14 changes: 8 additions & 6 deletions src/common/scripting/backend/codegen.cpp
Expand Up @@ -291,30 +291,32 @@ bool AreCompatiblePointerTypes(PType *dest, PType *source, bool forcompare)
if (!forcompare && fromtype->IsConst && !totype->IsConst) return false;
// A type is always compatible to itself.
if (fromtype == totype) return true;
// Pointers to different types are only compatible if both point to an object and the source type is a child of the destination type.
if (source->isObjectPointer() && dest->isObjectPointer())
{
{ // Pointers to different types are only compatible if both point to an object and the source type is a child of the destination type.
auto fromcls = static_cast<PObjectPointer*>(source)->PointedClass();
auto tocls = static_cast<PObjectPointer*>(dest)->PointedClass();
if (forcompare && tocls->IsDescendantOf(fromcls)) return true;
return (fromcls->IsDescendantOf(tocls));
}
// The same rules apply to class pointers. A child type can be assigned to a variable of a parent type.
if (source->isClassPointer() && dest->isClassPointer())
{
else if (source->isClassPointer() && dest->isClassPointer())
{ // The same rules apply to class pointers. A child type can be assigned to a variable of a parent type.
auto fromcls = static_cast<PClassPointer*>(source)->ClassRestriction;
auto tocls = static_cast<PClassPointer*>(dest)->ClassRestriction;
if (forcompare && tocls->IsDescendantOf(fromcls)) return true;
return (fromcls->IsDescendantOf(tocls));
}
if(source->isFunctionPointer() && dest->isFunctionPointer())
else if(source->isFunctionPointer() && dest->isFunctionPointer())
{
auto from = static_cast<PFunctionPointer*>(source);
auto to = static_cast<PFunctionPointer*>(dest);
if(from->PointedType == TypeVoid) return false;

return to->PointedType == TypeVoid || (AreCompatibleFnPtrTypes((PPrototype *)to->PointedType, (PPrototype *)from->PointedType) && from->ArgFlags == to->ArgFlags && FScopeBarrier::CheckSidesForFunctionPointer(from->Scope, to->Scope));
}
else if(source->isRealPointer() && dest->isRealPointer())
{
return fromtype->PointedType == totype->PointedType;
}
}
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/common/scripting/frontend/zcc_compile.cpp
Expand Up @@ -2764,7 +2764,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
// [ZZ] unspecified virtual function inherits old scope. virtual function scope can't be changed.
sym->Variants[0].Implementation->VarFlags = sym->Variants[0].Flags;
}

bool exactReturnType = mVersion < MakeVersion(4, 4);
PClass *clstype = forclass? static_cast<PClassType *>(c->Type())->Descriptor : nullptr;
if (varflags & VARF_Virtual)
Expand All @@ -2785,7 +2785,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool

auto parentfunc = clstype->ParentClass? dyn_cast<PFunction>(clstype->ParentClass->VMType->Symbols.FindSymbol(sym->SymbolName, true)) : nullptr;

int virtindex = clstype->FindVirtualIndex(sym->SymbolName, &sym->Variants[0], parentfunc, exactReturnType);
int virtindex = clstype->FindVirtualIndex(sym->SymbolName, &sym->Variants[0], parentfunc, exactReturnType, sym->SymbolName == FName("SpecialBounceHit") && mVersion < MakeVersion(4, 12));
// specifying 'override' is necessary to prevent one of the biggest problem spots with virtual inheritance: Mismatching argument types.
if (varflags & VARF_Override)
{
Expand Down Expand Up @@ -2867,7 +2867,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
}
else if (forclass)
{
int virtindex = clstype->FindVirtualIndex(sym->SymbolName, &sym->Variants[0], nullptr, exactReturnType);
int virtindex = clstype->FindVirtualIndex(sym->SymbolName, &sym->Variants[0], nullptr, exactReturnType, sym->SymbolName == FName("SpecialBounceHit") && mVersion < MakeVersion(4, 12));
if (virtindex != -1)
{
Error(f, "Function %s attempts to override parent function without 'override' qualifier", FName(f->Name).GetChars());
Expand Down
4 changes: 2 additions & 2 deletions wadsrc/static/zscript/actors/actor.zs
Expand Up @@ -565,7 +565,7 @@ class Actor : Thinker native
}

// This is called when a missile bounces off something.
virtual int SpecialBounceHit(Actor bounceMobj, Line bounceLine, SecPlane bouncePlane)
virtual int SpecialBounceHit(Actor bounceMobj, Line bounceLine, readonly<SecPlane> bouncePlane)
{
return MHIT_DEFAULT;
}
Expand Down Expand Up @@ -847,7 +847,7 @@ class Actor : Thinker native
native void PlayPushSound();
native bool BounceActor(Actor blocking, bool onTop);
native bool BounceWall(Line l = null);
native bool BouncePlane(SecPlane plane);
native bool BouncePlane(readonly<SecPlane> plane);
native void PlayBounceSound(bool onFloor);
native bool ReflectOffActor(Actor blocking);

Expand Down
2 changes: 1 addition & 1 deletion wadsrc/static/zscript/mapdata.zs
Expand Up @@ -270,7 +270,7 @@ struct SecPlane native play
native clearscope int PointOnSide(Vector3 pos) const;
native clearscope double ZatPoint (Vector2 v) const;
native clearscope double ZatPointDist(Vector2 v, double dist) const;
native clearscope bool isEqual(Secplane other) const;
native clearscope bool isEqual(readonly<Secplane> other) const;
//native void ChangeHeight(double hdiff);
native clearscope double GetChangedHeight(double hdiff) const;
native clearscope double HeightDiff(double oldd, double newd = 1e37) const;
Expand Down

0 comments on commit d848a57

Please sign in to comment.