Graf, which would be healthier for speed?
One single function call all the time? (Calls ProcessCooldowns which only performs its stuff if the timer is %3, %2 or %10, all = 0)
Code: Select all
override void Tick()
{
if (isVoodoo() || health <= 0)
{
Super.Tick();
return;
}
if (PentaNoiseWait > 0) PentaNoiseWait--;
if (level.maptime <= 1) InitPlayer();
ProcessCooldowns();
if (GetClass() == "Doom4Player") UpdateHAM();
Super.Tick();
}
void ProcessCooldowns()
{
// Use common denominator.
int timer = level.maptime % 30;
// No need to check for StaticChargeDrain since the upgrade alone
// shuts this off.
if (!(timer % 3))
{
if (!CountInv("StaticUpgrade4"))
{
if (CountInv("StaticUpgrade3"))
{ A_TakeInventory("StaticRifleChargingToken",1); }
else if (CountInv("StaticUpgrade2"))
{ A_TakeInventory("StaticRifleChargingToken",2); }
else
{ A_TakeInventory("StaticRifleChargingToken",4); }
}
A_TakeInventory("PlasmaStunBombCounter",1);
user_lasthp = health + CountInv("BasicArmor");
}
if (!(timer % 2))
{
A_TakeInventory("SGTripleShotTimer",1);
A_TakeInventory("SGGrenadeTimer",1);
}
if (!(timer % 10))
{
if (CountInv("GrenadeCooldown"))
{
A_TakeInventory("GrenadeCooldown",1);
if (!CountInv("GrenadeCooldown"))
{
A_PlaySound("Doom4/Weapon/Grenade/GrenadeRegen");
}
}
}
}
Or multiple functions split up over time?
In this version, ProcessCooldown1, 2, and 3 are only called after 3, 2, and 10 tics passed respectively.
Code: Select all
int CooldownTimer[3];
override void Tick()
{
if (isVoodoo() || health <= 0)
{
Super.Tick();
return;
}
if (PentaNoiseWait > 0) PentaNoiseWait--;
if (level.maptime <= 1) InitPlayer();
static const int CooldownCaps[] = { 3, 2, 10 };
for (int i = 0; i < 3; i++)
{
CooldownTimer[i] = (CooldownTimer[i] + 1) % CooldownCaps[i];
}
if (!CooldownTimer[0]) ProcessCooldown1();
if (!CooldownTimer[1]) ProcessCooldown2();
if (!CooldownTimer[2]) ProcessCooldown3();
if (GetClass() == "Doom4Player") UpdateHAM();
Super.Tick();
}
void ProcessCooldown1()
{
// No need to check for StaticChargeDrain since the upgrade alone
// shuts this off.
if (!CountInv("StaticUpgrade4"))
{
if (CountInv("StaticUpgrade3"))
{ A_TakeInventory("StaticRifleChargingToken",1); }
else if (CountInv("StaticUpgrade2"))
{ A_TakeInventory("StaticRifleChargingToken",2); }
else
{ A_TakeInventory("StaticRifleChargingToken",4); }
}
A_TakeInventory("PlasmaStunBombCounter",1);
user_lasthp = health + CountInv("BasicArmor");
}
void ProcessCooldown2()
{
A_TakeInventory("SGTripleShotTimer",1);
A_TakeInventory("SGGrenadeTimer",1);
}
void ProcessCooldown3()
{
if (CountInv("GrenadeCooldown"))
{
A_TakeInventory("GrenadeCooldown",1);
if (!CountInv("GrenadeCooldown"))
{
A_PlaySound("Doom4/Weapon/Grenade/GrenadeRegen");
}
}
}