Only apply non-100 damage modifiers in InflictDamage
Profiling has shown that filtering them out early is cheaper than applying those percentage modifiers anyway. Additionally, profiling shows foreach loops to be cheaper than LINQ here as well.
This commit is contained in:
@@ -168,11 +168,24 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Apply any damage modifiers
|
||||
if (!ignoreModifiers && damage.Value > 0)
|
||||
{
|
||||
var modifiers = damageModifiers
|
||||
.Concat(damageModifiersPlayer)
|
||||
.Select(t => t.GetDamageModifier(attacker, damage));
|
||||
// PERF: Util.ApplyPercentageModifiers has been manually inlined to
|
||||
// avoid unnecessary loop enumerations and allocations
|
||||
var appliedDamage = (decimal)damage.Value;
|
||||
foreach (var dm in damageModifiers)
|
||||
{
|
||||
var modifier = dm.GetDamageModifier(attacker, damage);
|
||||
if (modifier != 100)
|
||||
appliedDamage *= modifier / 100m;
|
||||
}
|
||||
|
||||
damage = new Damage(Util.ApplyPercentageModifiers(damage.Value, modifiers), damage.DamageTypes);
|
||||
foreach (var dm in damageModifiersPlayer)
|
||||
{
|
||||
var modifier = dm.GetDamageModifier(attacker, damage);
|
||||
if (modifier != 100)
|
||||
appliedDamage *= modifier / 100m;
|
||||
}
|
||||
|
||||
damage = new Damage((int)appliedDamage, damage.DamageTypes);
|
||||
}
|
||||
|
||||
hp = (hp - damage.Value).Clamp(0, MaxHP);
|
||||
|
||||
Reference in New Issue
Block a user