- removed PClass::DeriveData because it is no longer needed.

- fixed: IsVisibleToPlayer and optimized it a bit more.
- moved SourceLumpName to PClass, so that it can also be used for non-actors (there's a lot of non-Actor classes already.)
- separated the serializer for PClassPointer from PPointer. Even though not doable, a pointer to a class type is something entirely different than a class pointer with a restriction so each should handle its own case.
This commit is contained in:
Christoph Oelckers 2017-04-12 09:55:27 +02:00
parent 0e0eca0e0f
commit 5350721ec5
8 changed files with 40 additions and 62 deletions

View file

@ -91,7 +91,7 @@ CCMD (dumpactors)
"25:DoomStrifeChex", "26:HereticStrifeChex", "27:NotHexen", "28:HexenStrifeChex", "29:NotHeretic", "25:DoomStrifeChex", "26:HereticStrifeChex", "27:NotHexen", "28:HexenStrifeChex", "29:NotHeretic",
"30:NotDoom", "31:All", "30:NotDoom", "31:All",
}; };
Printf("%i object class types total\nActor\tEd Num\tSpawnID\tFilter\tSource\n", PClass::AllClasses.Size()); Printf("%u object class types total\nActor\tEd Num\tSpawnID\tFilter\tSource\n", PClass::AllClasses.Size());
for (unsigned int i = 0; i < PClass::AllClasses.Size(); i++) for (unsigned int i = 0; i < PClass::AllClasses.Size(); i++)
{ {
PClass *cls = PClass::AllClasses[i]; PClass *cls = PClass::AllClasses[i];
@ -102,11 +102,11 @@ CCMD (dumpactors)
Printf("%s\t%i\t%i\t%s\t%s\n", Printf("%s\t%i\t%i\t%s\t%s\n",
acls->TypeName.GetChars(), ainfo->DoomEdNum, acls->TypeName.GetChars(), ainfo->DoomEdNum,
ainfo->SpawnID, filters[ainfo->GameFilter & 31], ainfo->SpawnID, filters[ainfo->GameFilter & 31],
acls->ActorInfo()->SourceLumpName.GetChars()); acls->SourceLumpName.GetChars());
} }
else if (cls != NULL) else if (cls != NULL)
{ {
Printf("%s\tn/a\tn/a\tn/a\tEngine (not an actor type)\n", cls->TypeName.GetChars()); Printf("%s\tn/a\tn/a\tn/a\tEngine (not an actor type)\tSource: %s\n", cls->TypeName.GetChars(), cls->SourceLumpName.GetChars());
} }
else else
{ {

View file

@ -1420,18 +1420,9 @@ void PPointer::SetPointer(void *base, unsigned offset, TArray<size_t> *special)
void PPointer::WriteValue(FSerializer &ar, const char *key,const void *addr) const void PPointer::WriteValue(FSerializer &ar, const char *key,const void *addr) const
{ {
if (PointedType->IsKindOf(RUNTIME_CLASS(PClass))) if (PointedType->IsKindOf(RUNTIME_CLASS(PClass)))
{
auto pt = static_cast<PClass*>(PointedType);
if (pt->IsDescendantOf(RUNTIME_CLASS(PClass)))
{
ar(key, *(PClass **)addr);
}
else
{ {
ar(key, *(DObject **)addr); ar(key, *(DObject **)addr);
} }
}
else if (writer != nullptr) else if (writer != nullptr)
{ {
writer(ar, key, addr); writer(ar, key, addr);
@ -1452,17 +1443,8 @@ bool PPointer::ReadValue(FSerializer &ar, const char *key, void *addr) const
{ {
if (PointedType->IsKindOf(RUNTIME_CLASS(PClass))) if (PointedType->IsKindOf(RUNTIME_CLASS(PClass)))
{ {
auto pt = static_cast<PClass*>(PointedType); bool res;
bool res = true;
if (pt->IsDescendantOf(RUNTIME_CLASS(PClass)))
{
::Serialize(ar, key, *(PClass **)addr, (PClass**)nullptr);
}
else
{
::Serialize(ar, key, *(DObject **)addr, nullptr, &res); ::Serialize(ar, key, *(DObject **)addr, nullptr, &res);
}
return res; return res;
} }
else if (reader != nullptr) else if (reader != nullptr)
@ -1550,13 +1532,34 @@ PClassPointer::PClassPointer(PClass *restrict)
{ {
if (restrict) mDescriptiveName.Format("ClassPointer<%s>", restrict->TypeName.GetChars()); if (restrict) mDescriptiveName.Format("ClassPointer<%s>", restrict->TypeName.GetChars());
else mDescriptiveName = "ClassPointer"; else mDescriptiveName = "ClassPointer";
// class pointers do not need write barriers because all classes are stored in the global type table and won't get collected. loadOp = OP_LP;
// This means we can use the cheapoer non-barriered opcodes here.
loadOp = OP_LOS;
storeOp = OP_SP; storeOp = OP_SP;
mVersion = restrict->mVersion; mVersion = restrict->mVersion;
} }
//==========================================================================
//
// PPointer :: WriteValue
//
//==========================================================================
void PClassPointer::WriteValue(FSerializer &ar, const char *key, const void *addr) const
{
ar(key, *(PClass **)addr);
}
//==========================================================================
//
// PPointer :: ReadValue
//
//==========================================================================
bool PClassPointer::ReadValue(FSerializer &ar, const char *key, void *addr) const
{
::Serialize(ar, key, *(PClass **)addr, (PClass**)nullptr);
return false;
}
//========================================================================== //==========================================================================
// //
// PClassPointer - isCompatible // PClassPointer - isCompatible
@ -3304,18 +3307,6 @@ void PClass::InitializeDefaults()
} }
} }
//==========================================================================
//
// PClass :: DeriveData
//
// Copies inheritable data to the child class.
//
//==========================================================================
void PClass::DeriveData(PClass *newclass)
{
}
//========================================================================== //==========================================================================
// //
// PClass :: CreateDerivedClass // PClass :: CreateDerivedClass
@ -3365,7 +3356,6 @@ PClass *PClass::CreateDerivedClass(FName name, unsigned int size)
{ {
type->InitializeDefaults(); type->InitializeDefaults();
type->Virtuals = Virtuals; type->Virtuals = Virtuals;
DeriveData(type);
} }
else else
type->ObjectFlags &= OF_Transient; type->ObjectFlags &= OF_Transient;

View file

@ -429,6 +429,8 @@ public:
class PClass *ClassRestriction; class PClass *ClassRestriction;
bool isCompatible(PType *type); bool isCompatible(PType *type);
void WriteValue(FSerializer &ar, const char *key, const void *addr) const override;
bool ReadValue(FSerializer &ar, const char *key, void *addr) const override;
void SetPointer(void *base, unsigned offset, TArray<size_t> *special = NULL) const override; void SetPointer(void *base, unsigned offset, TArray<size_t> *special = NULL) const override;
virtual bool IsMatch(intptr_t id1, intptr_t id2) const; virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
@ -600,7 +602,6 @@ public:
bool ReadAllFields(FSerializer &ar, void *addr) const; bool ReadAllFields(FSerializer &ar, void *addr) const;
void InitializeDefaults(); void InitializeDefaults();
int FindVirtualIndex(FName name, PPrototype *proto); int FindVirtualIndex(FName name, PPrototype *proto);
virtual void DeriveData(PClass *newclass);
static void StaticInit(); static void StaticInit();
static void StaticShutdown(); static void StaticShutdown();
@ -619,6 +620,7 @@ public:
bool bExported; // This type has been declared in a script bool bExported; // This type has been declared in a script
bool bDecorateClass; // may be subject to some idiosyncracies due to DECORATE backwards compatibility bool bDecorateClass; // may be subject to some idiosyncracies due to DECORATE backwards compatibility
TArray<VMFunction*> Virtuals; // virtual function table TArray<VMFunction*> Virtuals; // virtual function table
FName SourceLumpName;
void (*ConstructNative)(void *); void (*ConstructNative)(void *);

View file

@ -307,18 +307,6 @@ PClassActor::~PClassActor()
{ {
} }
//==========================================================================
//
// PClassActor :: Derive
//
//==========================================================================
void PClassActor::DeriveData(PClass *newclass)
{
assert(newclass->IsKindOf(RUNTIME_CLASS(PClassActor)));
PClassActor *newa = static_cast<PClassActor *>(newclass);
}
//========================================================================== //==========================================================================
// //
// PClassActor :: SetReplacement // PClassActor :: SetReplacement

View file

@ -247,8 +247,7 @@ struct FActorInfo
uint8_t GameFilter = GAME_Any; uint8_t GameFilter = GAME_Any;
uint16_t SpawnID = 0; uint16_t SpawnID = 0;
uint16_t ConversationID = 0; uint16_t ConversationID = 0;
int16_t DoomEdNum = 0; int16_t DoomEdNum = -1;
FString SourceLumpName;
FStateLabels *StateList = nullptr; FStateLabels *StateList = nullptr;
DmgFactors DamageFactors; DmgFactors DamageFactors;
@ -294,7 +293,6 @@ protected:
public: public:
static void StaticInit (); static void StaticInit ();
static void StaticSetActorNums (); static void StaticSetActorNums ();
virtual void DeriveData(PClass *newclass);
PClassActor(); PClassActor();
~PClassActor(); ~PClassActor();

View file

@ -1605,11 +1605,14 @@ bool AActor::IsVisibleToPlayer() const
(signed)(VisibleToTeam-1) != players[consoleplayer].userinfo.GetTeam() ) (signed)(VisibleToTeam-1) != players[consoleplayer].userinfo.GetTeam() )
return false; return false;
auto &vis = GetInfo()->VisibleToPlayerClass;
if (vis.Size() == 0) return true; // early out for the most common case.
const player_t* pPlayer = players[consoleplayer].camera->player; const player_t* pPlayer = players[consoleplayer].camera->player;
if (pPlayer) if (pPlayer)
{ {
for(auto cls : GetInfo()->VisibleToPlayerClass) for(auto cls : vis)
{ {
if (cls && pPlayer->mo->GetClass()->IsDescendantOf(cls)) if (cls && pPlayer->mo->GetClass()->IsDescendantOf(cls))
{ {

View file

@ -1109,7 +1109,7 @@ static PClassActor *ParseActorHeader(FScanner &sc, Baggage *bag)
{ {
PClassActor *info = CreateNewActor(sc, typeName, parentName); PClassActor *info = CreateNewActor(sc, typeName, parentName);
info->ActorInfo()->DoomEdNum = DoomEdNum > 0 ? DoomEdNum : -1; info->ActorInfo()->DoomEdNum = DoomEdNum > 0 ? DoomEdNum : -1;
info->ActorInfo()->SourceLumpName = Wads.GetLumpFullPath(sc.LumpNum); info->SourceLumpName = Wads.GetLumpFullPath(sc.LumpNum);
if (!info->SetReplacement(replaceName)) if (!info->SetReplacement(replaceName))
{ {

View file

@ -625,8 +625,7 @@ void ZCCCompiler::CreateClassTypes()
DPrintf(DMSG_SPAMMY, "Registered %s as native with parent %s\n", me->TypeName.GetChars(), parent->TypeName.GetChars()); DPrintf(DMSG_SPAMMY, "Registered %s as native with parent %s\n", me->TypeName.GetChars(), parent->TypeName.GetChars());
} }
c->cls->Type = me; c->cls->Type = me;
auto ac = dyn_cast<PClassActor>(me); me->SourceLumpName = *c->cls->SourceName;
if (ac != nullptr) ac->ActorInfo()->SourceLumpName = *c->cls->SourceName;
} }
else else
{ {
@ -2194,7 +2193,6 @@ void ZCCCompiler::InitDefaults()
FString mename = ti->TypeName.GetChars(); FString mename = ti->TypeName.GetChars();
ti->InitializeDefaults(); ti->InitializeDefaults();
ti->ParentClass->DeriveData(ti);
} }
} }
else else
@ -2215,7 +2213,6 @@ void ZCCCompiler::InitDefaults()
auto ti = static_cast<PClassActor *>(c->Type()); auto ti = static_cast<PClassActor *>(c->Type());
ti->InitializeDefaults(); ti->InitializeDefaults();
ti->ParentClass->DeriveData(ti);
// We need special treatment for this one field in AActor's defaults which cannot be made visible to DECORATE as a property. // We need special treatment for this one field in AActor's defaults which cannot be made visible to DECORATE as a property.
// It's better to do this here under controlled conditions than deeper down in the class type classes. // It's better to do this here under controlled conditions than deeper down in the class type classes.