Skip to content

Commit

Permalink
- Duke: look up all internally used actor classes at game startup.
Browse files Browse the repository at this point in the history
This allows early validation of the names but is also more efficient.
  • Loading branch information
coelckers committed Mar 27, 2023
1 parent da423f9 commit c685dce
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 215 deletions.
81 changes: 1 addition & 80 deletions source/core/namedef_custom.h
Expand Up @@ -11,85 +11,6 @@ xx(RazeStatusBar)
xx(zoomsize)
xx(AltHud)

// internal Duke actor classes that need direct checking
xx(DukeMasterSwitch)
xx(DukeTouchplate)
xx(DukeSoundController)
xx(DukeRespawnController)
xx(DukeActivator)
xx(DukeActivatorLocked)
xx(DukeLocator)
xx(DukeGenericDestructible)
xx(DukeGlassPieces)
xx(DukeGlassPieces1)
xx(DukeGlassPieces2)
xx(DukeNaturalLightning)
xx(RedneckBowlingPin)
xx(DukeReactor)
xx(DukeFootprints)
xx(RedneckMinecartDef)
xx(RedneckMinecartSound)
xx(RedneckMinecartInner)
xx(RedneckJaildoorDef)
xx(RedneckJaildoorSound)
xx(RedneckGeometryEffect)
xx(RedneckKeyinfoSetter)
xx(DukeSectorEffector)
xx(RedneckGoogooCluster)
xx(DukeAtomicHealth)
xx(RedneckHen)
xx(DukeSmallSmoke)
xx(DukeExplosion2)
xx(DukeWaterBubble)
xx(DukeMoney)
xx(DukeMail)
xx(DukePaper)
xx(RedneckFeather)
xx(DukeSteamBase)
xx(RedneckFire)
xx(DukePlayerOnWater)
xx(RedneckBillyRay)
xx(RedneckBiker)
xx(RedneckCheerleader)
xx(DukeShotSpark)
xx(DukeJibs6)
xx(RedneckMotoHit)
xx(DukeFlamethrowerFlame)
xx(DukeShrinkSpark)
xx(DukeFirefly)
xx(DukeFireball)
xx(DukeBloodSplat3)
xx(DukeBloodSplat1)
xx(DukeBloodSplat2)
xx(DukeBloodSplat4)
xx(DukeBloodPool)
xx(DukeFirelaser)
xx(RedneckFirelaser)
xx(DukeMeleeAttack)
xx(DukeFirstgunSprite)
xx(DukeShotgunSprite)
xx(DukeChaingunSprite)
xx(DukeRPGSprite)
xx(DukePipeBomb)
xx(DukeShrinkerSprite)
xx(DukeDevastatorSprite)
xx(DukeTripBombSprite)
xx(DukeFreezeSprite)
xx(DukeTransporterBeam)
xx(DukeWaterSplash)
xx(DukeShell)
xx(DukeShotgunShell)
xx(DukeRPG)
xx(RedneckDynamiteArrow)
xx(RedneckHulk)
xx(RedneckPig)
xx(RedneckMinion)
xx(RedneckVixen)
xx(RedneckRabbit)
xx(RedneckDoorkey)
xx(RedneckEmptyBike)
xx(RedneckEmptyBoat)

xx(spawnstate)
xx(brokenstate)
xx(breaksound)
Expand All @@ -100,4 +21,4 @@ xx(falladjustz)
xx(aimoffset)
xx(strength)
xx(autoaimangle)
xx(shootzoffset)
xx(shootzoffset)
28 changes: 14 additions & 14 deletions source/games/duke/src/actors.cpp
Expand Up @@ -153,7 +153,7 @@ void RANDOMSCRAP(DDukeActor* origin)
auto vel = krandf(4) + 4;
auto zvel = -krandf(8) - 2;

auto spawned = CreateActor(origin->sector(), origin->spr.pos + offset, PClass::FindActor("DukeScrap"), -8, DVector2(v, v), a, vel, zvel, origin, STAT_MISC);
auto spawned = CreateActor(origin->sector(), origin->spr.pos + offset, DukeScrapClass, -8, DVector2(v, v), a, vel, zvel, origin, STAT_MISC);
if (spawned)
{
spawned->spriteextra = (r4 & 15);
Expand Down Expand Up @@ -624,7 +624,7 @@ void movefallers(void)
{
a2->counter = 1;
a2->spr.cstat &= ~CSTAT_SPRITE_ONE_SIDE;
if (a2->IsKindOf(NAME_DukeSteamBase))
if (a2->IsKindOf(DukeSteamBaseClass))
a2->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
}
}
Expand Down Expand Up @@ -1178,7 +1178,7 @@ void handle_se14(DDukeActor* actor, bool checkstat, PClassActor* RPG)
updatesector(a2->spr.pos, &k);
if (a2->spr.extra >= 0 && k == actor->sector())
{
gutsdir(a2, PClass::FindActor(NAME_DukeJibs6), 72, myconnectindex);
gutsdir(a2, DukeJibs6Class, 72, myconnectindex);
S_PlayActorSound(SQUISHED, actor);
a2->Destroy();
}
Expand Down Expand Up @@ -1338,7 +1338,7 @@ void handle_se30(DDukeActor *actor)
updatesector(a2->spr.pos, &k);
if (a2->spr.extra >= 0 && k == actor->sector())
{
gutsdir(a2, PClass::FindActor(NAME_DukeJibs6), 24, myconnectindex);
gutsdir(a2, DukeJibs6Class, 24, myconnectindex);
S_PlayActorSound(SQUISHED, a2);
a2->Destroy();
}
Expand Down Expand Up @@ -1546,7 +1546,7 @@ void handle_se05(DDukeActor* actor)
{
auto ang = actor->spr.Angles.Yaw;
actor->spr.Angles.Yaw = (actor->spr.pos.XY() - ps[p].GetActor()->spr.pos.XY()).Angle();
shoot(actor, -1, PClass::FindActor(isRR()? NAME_RedneckFirelaser : NAME_DukeFirelaser));
shoot(actor, -1, isRR()? RedneckFirelaserClass : DukeFirelaserClass);
actor->spr.Angles.Yaw = ang;
}

Expand Down Expand Up @@ -2019,7 +2019,7 @@ void handle_se16(DDukeActor* actor)
DDukeActor* a2;
while ((a2 = it.Next()))
{
if (a2->IsKindOf(NAME_DukeReactor) && a2->spritesetindex == 0)
if (a2->IsKindOf(DukeReactorClass) && a2->spritesetindex == 0)
return;
}
if (a2 == nullptr)
Expand Down Expand Up @@ -2770,14 +2770,14 @@ void handle_se35(DDukeActor *actor)
for (int j = 0; j < 8; j++)
{
actor->spr.Angles.Yaw = randomAngle(90);
auto spawned = spawn(actor, PClass::FindActor(NAME_DukeSmallSmoke));
auto spawned = spawn(actor, DukeSmallSmokeClass);
if (spawned)
{
spawned->vel.X = 6 + krandf(8);
ssp(spawned, CLIPMASK0);
SetActor(spawned, spawned->spr.pos);
if (rnd(16))
spawn(actor, PClass::FindActor(NAME_DukeExplosion2));
spawn(actor, DukeExplosion2Class);
}
}

Expand Down Expand Up @@ -2864,7 +2864,7 @@ void handle_se130(DDukeActor *actor, int countmax)

if (rnd(64))
{
auto k = spawn(actor, PClass::FindActor(NAME_DukeExplosion2));
auto k = spawn(actor, DukeExplosion2Class);
if (k)
{
double s = 0.03125 + (krand() & 7) * REPEAT_SCALE;
Expand Down Expand Up @@ -3378,20 +3378,20 @@ void fall_common(DDukeActor *actor, int playernum, int DRONE, int(*fallspecial)(
goto SKIPJIBS;
if (sphit)
{
spawnguts(actor, PClass::FindActor(NAME_DukeJibs6), 5);
spawnguts(actor, DukeJibs6Class, 5);
S_PlayActorSound(SQUISHED, actor);
}
else
{
spawnguts(actor, PClass::FindActor(NAME_DukeJibs6), 15);
spawnguts(actor, DukeJibs6Class, 15);
S_PlayActorSound(SQUISHED, actor);
spawn(actor, PClass::FindActor(NAME_DukeBloodPool));
spawn(actor, DukeBloodPoolClass);
}
}

SKIPJIBS:

actor->attackertype = PClass::FindActor(NAME_DukeShotSpark);
actor->attackertype = DukeShotSparkClass;
actor->hitextra = 1;
actor->vel.Z = 0;
}
Expand Down Expand Up @@ -3591,7 +3591,7 @@ void spawndebris(DDukeActor* g_ac, int dnum, int count)
auto zvel = -krandf(8);
DVector2 scale(0.5 + (krand() & 15) * REPEAT_SCALE, 0.5 + (krand() & 15) * REPEAT_SCALE);

auto spawned = CreateActor(g_ac->sector(), g_ac->spr.pos + offs, PClass::FindActor("DukeScrap"), g_ac->spr.shade, scale, a, vel, zvel, g_ac, STAT_MISC);
auto spawned = CreateActor(g_ac->sector(), g_ac->spr.pos + offs, DukeScrapClass, g_ac->spr.shade, scale, a, vel, zvel, g_ac, STAT_MISC);
if (spawned)
{
spawned->spriteextra = dnum + s;
Expand Down
40 changes: 20 additions & 20 deletions source/games/duke/src/actors_d.cpp
Expand Up @@ -131,7 +131,7 @@ int ifsquished(DDukeActor* actor, int p)

if (actor->spr.pal == 1)
{
actor->attackertype = PClass::FindActor(NAME_DukeShotSpark);
actor->attackertype = DukeShotSparkClass;
actor->hitextra = 1;
return false;
}
Expand Down Expand Up @@ -277,7 +277,7 @@ void hitradius_d(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int h
{
int p = act2->spr.yint;

if (act2->attackertype->TypeName == NAME_DukeFlamethrowerFlame && Owner->isPlayer())
if (act2->attackertype == DukeFlamethrowerFlameClass && Owner->isPlayer())
{
ps[p].numloogs = -1 - actor->spr.yint;
}
Expand Down Expand Up @@ -386,17 +386,17 @@ int movesprite_ex_d(DDukeActor* actor, const DVector3& change, unsigned int clip

void lotsofmoney_d(DDukeActor *actor, int n)
{
lotsofstuff(actor, n, PClass::FindActor(NAME_DukeMoney));
lotsofstuff(actor, n, DukeMoneyClass);
}

void lotsofmail_d(DDukeActor *actor, int n)
{
lotsofstuff(actor, n, PClass::FindActor(NAME_DukeMail));
lotsofstuff(actor, n, DukeMailClass);
}

void lotsofpaper_d(DDukeActor *actor, int n)
{
lotsofstuff(actor, n, PClass::FindActor(NAME_DukePaper));
lotsofstuff(actor, n, DukePaperClass);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -457,10 +457,10 @@ int ifhitbyweapon_d(DDukeActor *actor)
else
{
if (actor->hitextra == 0)
if (actor->attackertype->TypeName == NAME_DukeShrinkSpark && actor->spr.scale.X < 0.375)
if (actor->attackertype == DukeShrinkSparkClass && actor->spr.scale.X < 0.375)
return -1;

if (actor->attackertype->TypeName == NAME_DukeFirefly && actor->spr.scale.X < 0.75)
if (actor->attackertype == DukeFireflyClass && actor->spr.scale.X < 0.75)
{
return -1;
}
Expand All @@ -483,7 +483,7 @@ int ifhitbyweapon_d(DDukeActor *actor)

if (ud.multimode < 2
|| actor->attackertype == nullptr
|| actor->attackertype->TypeName != NAME_DukeFlamethrowerFlame
|| actor->attackertype != DukeFlamethrowerFlameClass
|| actor->hitextra >= 0
|| actor->spr.extra > 0
|| !actor->isPlayer()
Expand Down Expand Up @@ -557,7 +557,7 @@ void movetransports_d(void)
{
if (act->spr.pal == 0)
{
spawn(act, PClass::FindActor(NAME_DukeTransporterBeam));
spawn(act, DukeTransporterBeamClass);
S_PlayActorSound(TELEPORTER, act);
}

Expand Down Expand Up @@ -586,7 +586,7 @@ void movetransports_d(void)

if (act->spr.pal == 0)
{
auto k = spawn(Owner, PClass::FindActor(NAME_DukeTransporterBeam));
auto k = spawn(Owner, DukeTransporterBeamClass);
if (k) S_PlayActorSound(TELEPORTER, k);
}

Expand Down Expand Up @@ -667,12 +667,12 @@ void movetransports_d(void)
SetActor(act2, act2->spr.pos);

if ((krand() & 255) < 32)
spawn(act2, PClass::FindActor(NAME_DukeWaterSplash));
spawn(act2, DukeWaterSplashClass);

if (sectlotag == 1)
for (int l = 0; l < 9; l++)
{
auto q = spawn(ps[p].GetActor(), PClass::FindActor(NAME_DukeWaterBubble));
auto q = spawn(ps[p].GetActor(), DukeWaterBubbleClass);
if (q) q->spr.pos.Z += krandf(64);
}
}
Expand Down Expand Up @@ -729,7 +729,7 @@ void movetransports_d(void)

if (sectlotag > 0)
{
auto k = spawn(act2, PClass::FindActor(NAME_DukeWaterSplash));
auto k = spawn(act2, DukeWaterSplashClass);
if (k && sectlotag == 1 && act2->spr.statnum == 4)
{
k->vel.X = act2->vel.X * 0.5;
Expand All @@ -752,10 +752,10 @@ void movetransports_d(void)

if (act->spr.pal == 0)
{
auto k = spawn(act, PClass::FindActor(NAME_DukeTransporterBeam));
auto k = spawn(act, DukeTransporterBeamClass);
if (k) S_PlayActorSound(TELEPORTER, k);

k = spawn(Owner, PClass::FindActor(NAME_DukeTransporterBeam));
k = spawn(Owner, DukeTransporterBeamClass);
if (k) S_PlayActorSound(TELEPORTER, k);
}

Expand Down Expand Up @@ -850,7 +850,7 @@ void handle_se06_d(DDukeActor* actor)
act2->temp_data[4] = actor->temp_data[4];
}
}
handle_se14(actor, true, PClass::FindActor(NAME_DukeRPG));
handle_se14(actor, true, DukeRPGClass);
}


Expand Down Expand Up @@ -896,7 +896,7 @@ static void handle_se28(DDukeActor* actor)
DukeStatIterator it(STAT_DEFAULT);
while (auto act2 = it.Next())
{
if (act2->GetClass()->TypeName == NAME_DukeNaturalLightning && act2->spr.hitag == actor->spr.hitag)
if (act2->GetClass() == DukeNaturalLightningClass && act2->spr.hitag == actor->spr.hitag)
act2->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
}
}
Expand All @@ -913,12 +913,12 @@ static void handle_se28(DDukeActor* actor)
DukeStatIterator it(STAT_DEFAULT);
while (auto act2 = it.Next())
{
if (act2->GetClass()->TypeName == NAME_DukeNaturalLightning && act2->spr.hitag == actor->spr.hitag)
if (act2->GetClass() == DukeNaturalLightningClass && act2->spr.hitag == actor->spr.hitag)
{
if (rnd(32) && (actor->temp_data[2] & 1))
{
act2->spr.cstat &= ~CSTAT_SPRITE_INVISIBLE;
spawn(act2, PClass::FindActor(NAME_DukeSmallSmoke));
spawn(act2, DukeSmallSmokeClass);

double x;
int p = findplayer(actor, &x);
Expand Down Expand Up @@ -970,7 +970,7 @@ void moveeffectors_d(void) //STATNUM 3
break;

case SE_14_SUBWAY_CAR:
handle_se14(act, true, PClass::FindActor(NAME_DukeRPG));
handle_se14(act, true, DukeRPGClass);
break;

case SE_30_TWO_WAY_TRAIN:
Expand Down

0 comments on commit c685dce

Please sign in to comment.