added class registration code for Blood

This commit is contained in:
Christoph Oelckers 2023-10-05 21:47:37 +02:00
parent cb443d443c
commit d86e99a2e1
3 changed files with 38 additions and 0 deletions

View file

@ -203,4 +203,11 @@ bool IsUnderwaterSector(sectortype* pSector);
#define AF(func) DBloodActor_##func##_VMPtr
#define xx(n) inline PClassActor* n##Class;
#include "classnames.h"
#undef xx
void RegisterClasses();
END_BLD_NS

View file

@ -598,6 +598,7 @@ void GameInterface::app_init()
PlayerArray[i] = Create<DBloodPlayer>(i);
GC::WriteBarrier(PlayerArray[i]);
}
RegisterClasses();
mirrortile = tileGetTextureID(504);
InitTextureIDs();
@ -736,4 +737,32 @@ inline DBloodPlayer* getPlayer(DBloodActor* actor)
return getPlayer(actor->GetType() - kDudePlayer1);
}
// Register all internally used classes at game startup so that we can find naming errors right away without having them cause bugs later.
void RegisterClasses()
{
#define xx(n) { #n, &n##Class},
static std::pair<const char*, PClassActor**> classreg[] = {
#include "classnames.h"
};
#undef xx
int error = 0;
for (auto& classdef : classreg)
{
auto cls = PClass::FindActor(classdef.first);
if (cls == nullptr || !cls->IsDescendantOf(RUNTIME_CLASS(DBloodActor)))
{
Printf(TEXTCOLOR_RED "%s: Attempt to register unknown actor class\n", classdef.first);
error++;
}
*classdef.second = cls;
}
if (error > 0)
{
I_FatalError("Unable to register %d actor classes", error);
}
}
END_BLD_NS

View file

@ -0,0 +1,2 @@
xx(BloodMissileBase)