Convert masses of HashSet<string> to BitSet<DamageType>
This commit is contained in:
@@ -332,7 +332,7 @@ namespace OpenRA
|
||||
health.InflictDamage(this, attacker, damage, false);
|
||||
}
|
||||
|
||||
public void Kill(Actor attacker, HashSet<string> damageTypes = null)
|
||||
public void Kill(Actor attacker, BitSet<DamageType> damageTypes = default(BitSet<DamageType>))
|
||||
{
|
||||
if (Disposed || health == null)
|
||||
return;
|
||||
|
||||
@@ -41,6 +41,24 @@ namespace OpenRA.Primitives
|
||||
return bits;
|
||||
}
|
||||
|
||||
public static BitSetIndex GetBitsNoAlloc(string[] values)
|
||||
{
|
||||
// Map strings to existing bits; do not allocate missing values new bits
|
||||
BitSetIndex bits = 0;
|
||||
|
||||
lock (Bits)
|
||||
{
|
||||
foreach (var value in values)
|
||||
{
|
||||
BitSetIndex valueBit;
|
||||
if (Bits.TryGetValue(value, out valueBit))
|
||||
bits |= valueBit;
|
||||
}
|
||||
}
|
||||
|
||||
return bits;
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetStrings(BitSetIndex bits)
|
||||
{
|
||||
var values = new List<string>();
|
||||
@@ -69,6 +87,11 @@ namespace OpenRA.Primitives
|
||||
public BitSet(params string[] values) : this(BitSetAllocator<T>.GetBits(values)) { }
|
||||
BitSet(BitSetIndex bits) { this.bits = bits; }
|
||||
|
||||
public static BitSet<T> FromStringsNoAlloc(string[] values)
|
||||
{
|
||||
return new BitSet<T>(BitSetAllocator<T>.GetBitsNoAlloc(values)) { };
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return BitSetAllocator<T>.GetStrings(bits).JoinWith(",");
|
||||
|
||||
@@ -33,6 +33,11 @@ namespace OpenRA.Traits
|
||||
Dead = 32
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Type tag for DamageTypes <see cref="Primitives.BitSet{T}"/>.
|
||||
/// </summary>
|
||||
public sealed class DamageType { DamageType() { } }
|
||||
|
||||
public interface IHealth
|
||||
{
|
||||
DamageState DamageState { get; }
|
||||
@@ -42,7 +47,7 @@ namespace OpenRA.Traits
|
||||
bool IsDead { get; }
|
||||
|
||||
void InflictDamage(Actor self, Actor attacker, Damage damage, bool ignoreModifiers);
|
||||
void Kill(Actor self, Actor attacker, HashSet<string> damageTypes);
|
||||
void Kill(Actor self, Actor attacker, BitSet<DamageType> damageTypes);
|
||||
}
|
||||
|
||||
// depends on the order of pips in WorldRenderer.cs!
|
||||
@@ -77,9 +82,9 @@ namespace OpenRA.Traits
|
||||
public class Damage
|
||||
{
|
||||
public readonly int Value;
|
||||
public readonly HashSet<string> DamageTypes;
|
||||
public readonly BitSet<DamageType> DamageTypes;
|
||||
|
||||
public Damage(int damage, HashSet<string> damageTypes)
|
||||
public Damage(int damage, BitSet<DamageType> damageTypes)
|
||||
{
|
||||
Value = damage;
|
||||
DamageTypes = damageTypes;
|
||||
@@ -88,7 +93,7 @@ namespace OpenRA.Traits
|
||||
public Damage(int damage)
|
||||
{
|
||||
Value = damage;
|
||||
DamageTypes = new HashSet<string>();
|
||||
DamageTypes = default(BitSet<DamageType>);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user