misc optimization (#6436)
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Content.Shared.Damage
|
||||
/// functions to apply resistance sets and supports basic math operations to modify this dictionary.
|
||||
/// </remarks>
|
||||
[DataDefinition]
|
||||
public class DamageSpecifier
|
||||
public class DamageSpecifier : IEquatable<DamageSpecifier>
|
||||
{
|
||||
[JsonPropertyName("types")]
|
||||
[DataField("types", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, DamageTypePrototype>))]
|
||||
@@ -384,7 +384,21 @@ namespace Content.Shared.Damage
|
||||
return newDamage;
|
||||
}
|
||||
|
||||
public static DamageSpecifier operator -(DamageSpecifier damageSpecA, DamageSpecifier damageSpecB) => damageSpecA + -damageSpecB;
|
||||
// Here we define the subtraction operator explicitly, rather than implicitly via something like X + (-1 * Y).
|
||||
// This is faster because FixedPoint2 multiplication is somewhat involved.
|
||||
public static DamageSpecifier operator -(DamageSpecifier damageSpecA, DamageSpecifier damageSpecB)
|
||||
{
|
||||
DamageSpecifier newDamage = new(damageSpecA);
|
||||
|
||||
foreach (var entry in damageSpecB.DamageDict)
|
||||
{
|
||||
if (!newDamage.DamageDict.TryAdd(entry.Key, -entry.Value))
|
||||
{
|
||||
newDamage.DamageDict[entry.Key] -= entry.Value;
|
||||
}
|
||||
}
|
||||
return newDamage;
|
||||
}
|
||||
|
||||
public static DamageSpecifier operator +(DamageSpecifier damageSpec) => damageSpec;
|
||||
|
||||
@@ -393,6 +407,20 @@ namespace Content.Shared.Damage
|
||||
public static DamageSpecifier operator *(float factor, DamageSpecifier damageSpec) => damageSpec * factor;
|
||||
|
||||
public static DamageSpecifier operator *(FixedPoint2 factor, DamageSpecifier damageSpec) => damageSpec * factor;
|
||||
|
||||
public bool Equals(DamageSpecifier? other)
|
||||
{
|
||||
if (other == null || DamageDict.Count != other.DamageDict.Count)
|
||||
return false;
|
||||
|
||||
foreach (var (key, value) in DamageDict)
|
||||
{
|
||||
if (!other.DamageDict.TryGetValue(key, out var otherValue) || value != otherValue)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Content.Shared.Damage
|
||||
{
|
||||
component.DamagePerGroup = component.Damage.GetDamagePerGroup();
|
||||
component.TotalDamage = component.Damage.Total;
|
||||
component.Dirty();
|
||||
Dirty(component);
|
||||
|
||||
if (EntityManager.TryGetComponent<AppearanceComponent>(component.Owner, out var appearance) && damageDelta != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user