- Optimized handling of puffs in the event they're null.

- Only spawn the puff as needed again if the projectile actually spawns.
This commit is contained in:
MajorCooke 2016-07-13 09:48:24 -05:00 committed by Christoph Oelckers
parent 02064437c5
commit 376c9b0306

View file

@ -1666,7 +1666,6 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomBulletAttack)
S_Sound (self, CHAN_WEAPON, self->AttackSound, 1, ATTN_NORM); S_Sound (self, CHAN_WEAPON, self->AttackSound, 1, ATTN_NORM);
for (i = 0; i < numbullets; i++) for (i = 0; i < numbullets; i++)
{ {
bool temp = false;
DAngle angle = bangle; DAngle angle = bangle;
DAngle slope = bslope; DAngle slope = bslope;
@ -1687,32 +1686,39 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomBulletAttack)
damage *= ((pr_cabullet()%3)+1); damage *= ((pr_cabullet()%3)+1);
AActor *puff = P_LineAttack(self, angle, range, slope, damage, NAME_Hitscan, pufftype, laflags); AActor *puff = P_LineAttack(self, angle, range, slope, damage, NAME_Hitscan, pufftype, laflags);
if (!puff) if (missile != nullptr && pufftype != nullptr)
{
temp = true;
puff = P_LineAttack(self, angle, range, slope, 0, NAME_Hitscan, pufftype, laflags | LAF_NOINTERACT);
}
if (puff && missile)
{ {
double x = Spawnofs_xy * angle.Cos(); double x = Spawnofs_xy * angle.Cos();
double y = Spawnofs_xy * angle.Sin(); double y = Spawnofs_xy * angle.Sin();
AActor *proj = P_SpawnMissileXYZ(self->Vec3Offset(x, y, self->GetBobOffset() + Spawnheight), self, puff, missile, false);
DVector3 pos = self->Pos();
self->SetXYZ(self->Vec3Offset(x, y, 0.));
AActor *proj = P_SpawnMissileAngleZSpeed(self, self->Z() + self->GetBobOffset() + Spawnheight, missile, self->Angles.Yaw, 0, GetDefaultByType(missile)->Speed, self, false);
self->SetXYZ(pos);
if (proj) if (proj)
{ {
// FAF_BOTTOM = 1 bool temp = (puff == nullptr);
// Aim for the base of the puff as that's where blood puffs will spawn... roughly. if (!puff)
A_Face(proj, puff, 0., 0., 0., 0., 1);
proj->Vel3DFromAngle(-proj->Angles.Pitch, proj->Speed);
if (temp)
puff->Destroy();
else
{ {
if (flags & CBAF_PUFFTARGET) proj->target = puff; puff = P_LineAttack(self, angle, range, slope, 0, NAME_Hitscan, pufftype, laflags | LAF_NOINTERACT);
if (flags & CBAF_PUFFMASTER) proj->master = puff; }
if (flags & CBAF_PUFFTRACER) proj->tracer = puff; if (puff)
{
// FAF_BOTTOM = 1
// Aim for the base of the puff as that's where blood puffs will spawn... roughly.
A_Face(proj, puff, 0., 0., 0., 0., 1);
proj->Vel3DFromAngle(-proj->Angles.Pitch, proj->Speed);
if (temp)
puff->Destroy();
else
{
if (flags & CBAF_PUFFTARGET) proj->target = puff;
if (flags & CBAF_PUFFMASTER) proj->master = puff;
if (flags & CBAF_PUFFTRACER) proj->tracer = puff;
}
} }
} }
} }
@ -1849,14 +1855,10 @@ enum FB_Flags
FBF_PUFFTRACER = 256, FBF_PUFFTRACER = 256,
}; };
static void FireBulletMissile(AActor *self, PClassActor *missile, AActor *puff, DAngle angle, double Spawnheight, double Spawnofs_xy, int flags, bool temp) static void AimBulletMissile(AActor *proj, AActor *puff, int flags, bool temp)
{ {
if (self && missile && puff) if (proj && puff)
{ {
DAngle ang = self->Angles.Yaw - 90;
DVector2 ofs = ang.ToVector(Spawnofs_xy);
AActor *proj = P_SpawnPlayerMissile(self, ofs.X, ofs.Y, Spawnheight, missile, angle, nullptr, nullptr, false, true);
if (proj) if (proj)
{ {
// FAF_BOTTOM = 1 // FAF_BOTTOM = 1
@ -1865,9 +1867,7 @@ static void FireBulletMissile(AActor *self, PClassActor *missile, AActor *puff,
A_Face(proj, puff, 0., 0., 0., 0., 1); A_Face(proj, puff, 0., 0., 0., 0., 1);
proj->Vel3DFromAngle(-proj->Angles.Pitch, proj->Speed); proj->Vel3DFromAngle(-proj->Angles.Pitch, proj->Speed);
if (temp) if (!temp)
puff->Destroy();
else
{ {
if (flags & FBF_PUFFTARGET) proj->target = puff; if (flags & FBF_PUFFTARGET) proj->target = puff;
if (flags & FBF_PUFFMASTER) proj->master = puff; if (flags & FBF_PUFFMASTER) proj->master = puff;
@ -1875,6 +1875,10 @@ static void FireBulletMissile(AActor *self, PClassActor *missile, AActor *puff,
} }
} }
} }
if (puff && temp)
{
puff->Destroy();
}
} }
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_FireBullets) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_FireBullets)
@ -1928,16 +1932,24 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_FireBullets)
if (!(flags & FBF_NORANDOM)) if (!(flags & FBF_NORANDOM))
damage *= ((pr_cwbullet()%3)+1); damage *= ((pr_cwbullet()%3)+1);
bool temp = false;
AActor *puff = P_LineAttack(self, bangle, range, bslope, damage, NAME_Hitscan, pufftype, laflags); AActor *puff = P_LineAttack(self, bangle, range, bslope, damage, NAME_Hitscan, pufftype, laflags);
if (!puff) if (missile != nullptr)
{ {
temp = true; bool temp = false;
puff = P_LineAttack(self, bangle, range, bslope, 0, NAME_Hitscan, pufftype, laflags | LAF_NOINTERACT); DAngle ang = self->Angles.Yaw - 90;
DVector2 ofs = ang.ToVector(Spawnofs_xy);
AActor *proj = P_SpawnPlayerMissile(self, ofs.X, ofs.Y, Spawnheight, missile, bangle, nullptr, nullptr, false, true);
if (proj)
{
if (!puff)
{
temp = true;
puff = P_LineAttack(self, bangle, range, bslope, 0, NAME_Hitscan, pufftype, laflags | LAF_NOINTERACT);
}
AimBulletMissile(proj, puff, flags, temp);
}
} }
FireBulletMissile(self, missile, puff, bangle, Spawnheight, Spawnofs_xy, flags, temp);
} }
else else
{ {
@ -1964,15 +1976,24 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_FireBullets)
if (!(flags & FBF_NORANDOM)) if (!(flags & FBF_NORANDOM))
damage *= ((pr_cwbullet()%3)+1); damage *= ((pr_cwbullet()%3)+1);
bool temp = false;
AActor *puff = P_LineAttack(self, angle, range, slope, damage, NAME_Hitscan, pufftype, laflags); AActor *puff = P_LineAttack(self, angle, range, slope, damage, NAME_Hitscan, pufftype, laflags);
if (!puff) if (missile != nullptr)
{ {
temp = true; bool temp = false;
puff = P_LineAttack(self, angle, range, slope, 0, NAME_Hitscan, pufftype, laflags | LAF_NOINTERACT); DAngle ang = self->Angles.Yaw - 90;
DVector2 ofs = ang.ToVector(Spawnofs_xy);
AActor *proj = P_SpawnPlayerMissile(self, ofs.X, ofs.Y, Spawnheight, missile, angle, nullptr, nullptr, false, true);
if (proj)
{
if (!puff)
{
temp = true;
puff = P_LineAttack(self, angle, range, slope, 0, NAME_Hitscan, pufftype, laflags | LAF_NOINTERACT);
}
AimBulletMissile(proj, puff, flags, temp);
}
} }
FireBulletMissile(self, missile, puff, angle, Spawnheight, Spawnofs_xy, flags, temp);
} }
} }
return 0; return 0;