From d4ef8416785716ae88f2c373821968b8efab3f70 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Fri, 27 Jul 2018 22:24:51 -0700 Subject: [PATCH] Convert masses of HashSet to BitSet --- OpenRA.Game/Actor.cs | 2 +- OpenRA.Game/Primitives/BitSet.cs | 23 +++++++++++++++++++ OpenRA.Game/Traits/TraitsInterfaces.cs | 13 +++++++---- OpenRA.Mods.Cnc/Activities/Leap.cs | 5 ++-- OpenRA.Mods.Cnc/Traits/Attack/AttackLeap.cs | 3 ++- OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs | 3 +-- OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs | 2 +- OpenRA.Mods.Cnc/Traits/MadTank.cs | 2 +- OpenRA.Mods.Cnc/Traits/Mine.cs | 3 ++- .../Traits/Attack/AttackSuicides.cs | 2 +- OpenRA.Mods.Common/Traits/Buildings/Bridge.cs | 2 +- .../Traits/Buildings/GroundLevelBridge.cs | 3 ++- OpenRA.Mods.Common/Traits/Crushable.cs | 4 ++-- OpenRA.Mods.Common/Traits/DamagedByTerrain.cs | 5 ++-- OpenRA.Mods.Common/Traits/Explodes.cs | 7 +++--- OpenRA.Mods.Common/Traits/GivesBounty.cs | 7 +++--- OpenRA.Mods.Common/Traits/Health.cs | 7 ++---- .../Traits/Infantry/TakeCover.cs | 5 ++-- OpenRA.Mods.Common/Traits/KillsSelf.cs | 4 ++-- OpenRA.Mods.Common/Traits/OwnerLostAction.cs | 4 ++-- OpenRA.Mods.Common/Traits/Parachutable.cs | 3 ++- .../Traits/Player/DeveloperMode.cs | 7 ++---- .../Traits/Render/WithDamageOverlay.cs | 7 +++--- .../Traits/Render/WithDeathAnimation.cs | 3 +-- OpenRA.Mods.Common/Traits/RevealOnDeath.cs | 5 ++-- OpenRA.Mods.Common/Traits/SelfHealing.cs | 4 ++-- .../Traits/Sound/DeathSounds.cs | 7 +++--- OpenRA.Mods.Common/Traits/World/Locomotor.cs | 3 +-- OpenRA.Mods.Common/Warheads/DamageWarhead.cs | 3 ++- 29 files changed, 86 insertions(+), 62 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index d5ec506a26..43b8a7b9ec 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -332,7 +332,7 @@ namespace OpenRA health.InflictDamage(this, attacker, damage, false); } - public void Kill(Actor attacker, HashSet damageTypes = null) + public void Kill(Actor attacker, BitSet damageTypes = default(BitSet)) { if (Disposed || health == null) return; diff --git a/OpenRA.Game/Primitives/BitSet.cs b/OpenRA.Game/Primitives/BitSet.cs index ee24dc1332..6f97ac903b 100644 --- a/OpenRA.Game/Primitives/BitSet.cs +++ b/OpenRA.Game/Primitives/BitSet.cs @@ -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 GetStrings(BitSetIndex bits) { var values = new List(); @@ -69,6 +87,11 @@ namespace OpenRA.Primitives public BitSet(params string[] values) : this(BitSetAllocator.GetBits(values)) { } BitSet(BitSetIndex bits) { this.bits = bits; } + public static BitSet FromStringsNoAlloc(string[] values) + { + return new BitSet(BitSetAllocator.GetBitsNoAlloc(values)) { }; + } + public override string ToString() { return BitSetAllocator.GetStrings(bits).JoinWith(","); diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index dbc8c1c3e5..7625e6ecb8 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -33,6 +33,11 @@ namespace OpenRA.Traits Dead = 32 } + /// + /// Type tag for DamageTypes . + /// + 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 damageTypes); + void Kill(Actor self, Actor attacker, BitSet 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 DamageTypes; + public readonly BitSet DamageTypes; - public Damage(int damage, HashSet damageTypes) + public Damage(int damage, BitSet damageTypes) { Value = damage; DamageTypes = damageTypes; @@ -88,7 +93,7 @@ namespace OpenRA.Traits public Damage(int damage) { Value = damage; - DamageTypes = new HashSet(); + DamageTypes = default(BitSet); } } diff --git a/OpenRA.Mods.Cnc/Activities/Leap.cs b/OpenRA.Mods.Cnc/Activities/Leap.cs index 999cabeff7..f9f83c8a1b 100644 --- a/OpenRA.Mods.Cnc/Activities/Leap.cs +++ b/OpenRA.Mods.Cnc/Activities/Leap.cs @@ -16,6 +16,7 @@ using OpenRA.Activities; using OpenRA.GameRules; using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits.Render; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Cnc.Activities @@ -30,9 +31,9 @@ namespace OpenRA.Mods.Cnc.Activities WPos to; int ticks; WAngle angle; - HashSet damageTypes; + BitSet damageTypes; - public Leap(Actor self, Actor target, Armament a, WDist speed, WAngle angle, HashSet damageTypes) + public Leap(Actor self, Actor target, Armament a, WDist speed, WAngle angle, BitSet damageTypes) { var targetMobile = target.TraitOrDefault(); if (targetMobile == null) diff --git a/OpenRA.Mods.Cnc/Traits/Attack/AttackLeap.cs b/OpenRA.Mods.Cnc/Traits/Attack/AttackLeap.cs index 0d86bef57d..0870602ad7 100644 --- a/OpenRA.Mods.Cnc/Traits/Attack/AttackLeap.cs +++ b/OpenRA.Mods.Cnc/Traits/Attack/AttackLeap.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Cnc.Activities; using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Cnc.Traits @@ -26,7 +27,7 @@ namespace OpenRA.Mods.Cnc.Traits public readonly WAngle Angle = WAngle.FromDegrees(20); [Desc("Types of damage that this trait causes. Leave empty for no damage types.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); public override object Create(ActorInitializer init) { return new AttackLeap(init.Self, this); } } diff --git a/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs b/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs index def78e9ac8..e0fefab194 100644 --- a/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs +++ b/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs @@ -9,7 +9,6 @@ */ #endregion -using System.Collections.Generic; using System.Drawing; using OpenRA.Mods.Cnc.Activities; using OpenRA.Mods.Common.Traits; @@ -25,7 +24,7 @@ namespace OpenRA.Mods.Cnc.Traits public readonly bool ExplodeInstead = false; [Desc("Types of damage that this trait causes to self when 'ExplodeInstead' is true. Leave empty for no damage types.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); public readonly string ChronoshiftSound = "chrono2.aud"; diff --git a/OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs b/OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs index 0ea98608d5..33540f556f 100644 --- a/OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs +++ b/OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Cnc.Traits public readonly int Damage = 1000; [Desc("Apply the damage using these damagetypes.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); [Desc("Actor to transform into when the timer expires during (un)deploy."), ActorReference] public readonly string OriginalActor = "mcv"; diff --git a/OpenRA.Mods.Cnc/Traits/MadTank.cs b/OpenRA.Mods.Cnc/Traits/MadTank.cs index e832f97c6a..a8707f9089 100644 --- a/OpenRA.Mods.Cnc/Traits/MadTank.cs +++ b/OpenRA.Mods.Cnc/Traits/MadTank.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.Cnc.Traits public WeaponInfo DetonationWeaponInfo { get; private set; } [Desc("Types of damage that this trait causes to self while self-destructing. Leave empty for no damage types.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); public object Create(ActorInitializer init) { return new MadTank(init.Self, this); } public void RulesetLoaded(Ruleset rules, ActorInfo ai) diff --git a/OpenRA.Mods.Cnc/Traits/Mine.cs b/OpenRA.Mods.Cnc/Traits/Mine.cs index e24b488381..621215fb66 100644 --- a/OpenRA.Mods.Cnc/Traits/Mine.cs +++ b/OpenRA.Mods.Cnc/Traits/Mine.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Cnc.Traits @@ -48,7 +49,7 @@ namespace OpenRA.Mods.Cnc.Traits if (mobile != null && !info.DetonateClasses.Overlaps(mobile.Info.LocomotorInfo.Crushes)) return; - self.Kill(crusher, mobile != null ? mobile.Info.LocomotorInfo.CrushDamageTypes : new HashSet()); + self.Kill(crusher, mobile != null ? mobile.Info.LocomotorInfo.CrushDamageTypes : default(BitSet)); } bool ICrushable.CrushableBy(Actor self, Actor crusher, HashSet crushClasses) diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackSuicides.cs b/OpenRA.Mods.Common/Traits/Attack/AttackSuicides.cs index 60cdb5c060..76ed652a58 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackSuicides.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackSuicides.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits class AttackSuicidesInfo : ConditionalTraitInfo, Requires { [Desc("Types of damage that this trait causes to self while suiciding. Leave empty for no damage types.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); [VoiceReference] public readonly string Voice = "Action"; diff --git a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs index 264aba225a..91651facc8 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits public WeaponInfo DemolishWeaponInfo { get; private set; } [Desc("Types of damage that this bridge causes to units over/in path of it while being destroyed/repaired. Leave empty for no damage types.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); public object Create(ActorInitializer init) { return new Bridge(init.Self, this); } diff --git a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs index d2bf0da93a..a42f473731 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -31,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits public WeaponInfo DemolishWeaponInfo { get; private set; } [Desc("Types of damage that this bridge causes to units over/in path of it while being destroyed/repaired. Leave empty for no damage types.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); public void RulesetLoaded(Ruleset rules, ActorInfo ai) { diff --git a/OpenRA.Mods.Common/Traits/Crushable.cs b/OpenRA.Mods.Common/Traits/Crushable.cs index 1c06f0f715..f3efd9f5b5 100644 --- a/OpenRA.Mods.Common/Traits/Crushable.cs +++ b/OpenRA.Mods.Common/Traits/Crushable.cs @@ -10,7 +10,7 @@ #endregion using System.Collections.Generic; -using System.Linq; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits Game.Sound.Play(SoundType.World, Info.CrushSound, crusher.CenterPosition); var crusherMobile = crusher.TraitOrDefault(); - self.Kill(crusher, crusherMobile != null ? crusherMobile.Info.LocomotorInfo.CrushDamageTypes : new HashSet()); + self.Kill(crusher, crusherMobile != null ? crusherMobile.Info.LocomotorInfo.CrushDamageTypes : default(BitSet)); } bool ICrushable.CrushableBy(Actor self, Actor crusher, HashSet crushClasses) diff --git a/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs b/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs index 161a3051ef..ad6b3900b4 100644 --- a/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs +++ b/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs @@ -9,9 +9,8 @@ */ #endregion -using System.Collections.Generic; using System.Linq; -using OpenRA.GameRules; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -26,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int DamageInterval = 0; [Desc("Apply the damage using these damagetypes.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); [Desc("Terrain types where the actor will take damage.")] [FieldLoader.Require] public readonly string[] Terrain = { }; diff --git a/OpenRA.Mods.Common/Traits/Explodes.cs b/OpenRA.Mods.Common/Traits/Explodes.cs index 4d8925d53e..4a21de2353 100644 --- a/OpenRA.Mods.Common/Traits/Explodes.cs +++ b/OpenRA.Mods.Common/Traits/Explodes.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; using OpenRA.Mods.Common.Warheads; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -40,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int DamageThreshold = 0; [Desc("DeathType(s) that trigger the explosion. Leave empty to always trigger an explosion.")] - public readonly HashSet DeathTypes = new HashSet(); + public readonly BitSet DeathTypes = default(BitSet); [Desc("Who is counted as source of damage for explosion.", "Possible values are Self and Killer.")] @@ -102,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits if (self.World.SharedRandom.Next(100) > Info.Chance) return; - if (Info.DeathTypes.Count > 0 && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) + if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) return; var weapon = ChooseWeaponForExplosion(self); @@ -141,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits if (Info.DamageThreshold == 0) return; - if (Info.DeathTypes.Count > 0 && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) + if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) return; // Cast to long to avoid overflow when multiplying by the health diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index ec080a982c..7145d07478 100644 --- a/OpenRA.Mods.Common/Traits/GivesBounty.cs +++ b/OpenRA.Mods.Common/Traits/GivesBounty.cs @@ -9,10 +9,9 @@ */ #endregion -using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Effects; -using OpenRA.Mods.Common.Warheads; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -31,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("DeathTypes for which a bounty should be granted.", "Use an empty list (the default) to allow all DeathTypes.")] - public readonly HashSet DeathTypes = new HashSet(); + public readonly BitSet DeathTypes = default(BitSet); public override object Create(ActorInitializer init) { return new GivesBounty(this); } } @@ -79,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits if (!Info.ValidStances.HasStance(e.Attacker.Owner.Stances[self.Owner])) return; - if (Info.DeathTypes.Count > 0 && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) + if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) return; var displayedBounty = GetDisplayedBountyValue(self); diff --git a/OpenRA.Mods.Common/Traits/Health.cs b/OpenRA.Mods.Common/Traits/Health.cs index dfce76a641..a73fd3e176 100644 --- a/OpenRA.Mods.Common/Traits/Health.cs +++ b/OpenRA.Mods.Common/Traits/Health.cs @@ -9,8 +9,8 @@ */ #endregion -using System.Collections.Generic; using System.Linq; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -164,11 +164,8 @@ namespace OpenRA.Mods.Common.Traits } } - public void Kill(Actor self, Actor attacker, HashSet damageTypes = null) + public void Kill(Actor self, Actor attacker, BitSet damageTypes) { - if (damageTypes == null) - damageTypes = new HashSet(); - InflictDamage(self, attacker, new Damage(MaxHP, damageTypes), true); } diff --git a/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs b/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs index 5e547c005b..16c2289456 100644 --- a/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs +++ b/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Warheads; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -27,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits [FieldLoader.Require] [Desc("Damage types that trigger prone state. Defined on the warheads.")] - public readonly HashSet DamageTriggers = new HashSet(); + public readonly BitSet DamageTriggers = default(BitSet); [Desc("Damage modifiers for each damage type (defined on the warheads) while the unit is prone.")] public readonly Dictionary DamageModifiers = new Dictionary(); @@ -83,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits if (!IsProne) return 100; - if (damage.DamageTypes.Count == 0) + if (damage.DamageTypes.IsEmpty) return 100; var modifierPercentages = info.DamageModifiers.Where(x => damage.DamageTypes.Contains(x.Key)).Select(x => x.Value); diff --git a/OpenRA.Mods.Common/Traits/KillsSelf.cs b/OpenRA.Mods.Common/Traits/KillsSelf.cs index 687ad589b3..bed46712fe 100644 --- a/OpenRA.Mods.Common/Traits/KillsSelf.cs +++ b/OpenRA.Mods.Common/Traits/KillsSelf.cs @@ -9,7 +9,7 @@ */ #endregion -using System.Collections.Generic; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int[] Delay = { 0 }; [Desc("Types of damage that this trait causes. Leave empty for no damage types.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); [GrantedConditionReference] [Desc("The condition to grant moments before suiciding.")] diff --git a/OpenRA.Mods.Common/Traits/OwnerLostAction.cs b/OpenRA.Mods.Common/Traits/OwnerLostAction.cs index 892a45f262..bb9b27e5a9 100644 --- a/OpenRA.Mods.Common/Traits/OwnerLostAction.cs +++ b/OpenRA.Mods.Common/Traits/OwnerLostAction.cs @@ -9,8 +9,8 @@ */ #endregion -using System.Collections.Generic; using System.Linq; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Owner = "Neutral"; [Desc("The deathtypes used when 'Action' is 'Kill'.")] - public readonly HashSet DeathTypes = new HashSet(); + public readonly BitSet DeathTypes = default(BitSet); public override object Create(ActorInitializer init) { return new OwnerLostAction(init, this); } } diff --git a/OpenRA.Mods.Common/Traits/Parachutable.cs b/OpenRA.Mods.Common/Traits/Parachutable.cs index beb51caba7..e91e9bdbce 100644 --- a/OpenRA.Mods.Common/Traits/Parachutable.cs +++ b/OpenRA.Mods.Common/Traits/Parachutable.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Effects; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -23,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits public readonly bool KilledOnImpassableTerrain = true; [Desc("Types of damage that this trait causes to self when 'KilledOnImpassableTerrain' is true. Leave empty for no damage types.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); [Desc("Image where Ground/WaterCorpseSequence is looked up.")] public readonly string Image = "explosion"; diff --git a/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs b/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs index a34d072cf5..4f7f8e22df 100644 --- a/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs +++ b/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -220,13 +221,9 @@ namespace OpenRA.Mods.Common.Traits var actor = order.Target.Actor; var args = order.TargetString.Split(' '); - var damageTypes = new HashSet(); - - foreach (var damageType in args) - damageTypes.Add(damageType); + var damageTypes = BitSet.FromStringsNoAlloc(args); actor.Kill(actor, damageTypes); - break; } diff --git a/OpenRA.Mods.Common/Traits/Render/WithDamageOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithDamageOverlay.cs index bd1ec869a3..485422a9bb 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDamageOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDamageOverlay.cs @@ -9,9 +9,8 @@ */ #endregion -using System.Collections.Generic; using OpenRA.Graphics; -using OpenRA.Mods.Common.Warheads; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render @@ -27,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Damage types that this should be used for (defined on the warheads).", "Leave empty to disable all filtering.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); [Desc("Trigger when Undamaged, Light, Medium, Heavy, Critical or Dead.")] public readonly DamageState MinimumDamageState = DamageState.Heavy; @@ -55,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits.Render void INotifyDamage.Damaged(Actor self, AttackInfo e) { - if (info.DamageTypes.Count > 0 && !e.Damage.DamageTypes.Overlaps(info.DamageTypes)) + if (!info.DamageTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(info.DamageTypes)) return; if (isSmoking) return; diff --git a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs index 9495aa15eb..7183409e66 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs @@ -12,7 +12,6 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Effects; -using OpenRA.Mods.Common.Warheads; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render @@ -73,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits.Render palette += self.Owner.InternalName; // Killed by some non-standard means - if (e.Damage.DamageTypes.Count == 0) + if (e.Damage.DamageTypes.IsEmpty) { if (Info.FallbackSequence != null) SpawnDeathAnimation(self, self.CenterPosition, rs.GetImage(self), Info.FallbackSequence, palette); diff --git a/OpenRA.Mods.Common/Traits/RevealOnDeath.cs b/OpenRA.Mods.Common/Traits/RevealOnDeath.cs index f733fd89a3..af1973e5db 100644 --- a/OpenRA.Mods.Common/Traits/RevealOnDeath.cs +++ b/OpenRA.Mods.Common/Traits/RevealOnDeath.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Effects; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -33,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("DeathTypes for which shroud will be revealed.", "Use an empty list (the default) to allow all DeathTypes.")] - public readonly HashSet DeathTypes = new HashSet(); + public readonly BitSet DeathTypes = default(BitSet); public override object Create(ActorInitializer init) { return new RevealOnDeath(init.Self, this); } } @@ -56,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits if (!self.IsInWorld) return; - if (info.DeathTypes.Count > 0 && !attack.Damage.DamageTypes.Overlaps(info.DeathTypes)) + if (!info.DeathTypes.IsEmpty && !attack.Damage.DamageTypes.Overlaps(info.DeathTypes)) return; var owner = self.Owner; diff --git a/OpenRA.Mods.Common/Traits/SelfHealing.cs b/OpenRA.Mods.Common/Traits/SelfHealing.cs index 36022ca4db..555d0dea11 100644 --- a/OpenRA.Mods.Common/Traits/SelfHealing.cs +++ b/OpenRA.Mods.Common/Traits/SelfHealing.cs @@ -9,7 +9,7 @@ */ #endregion -using System.Collections.Generic; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int DamageCooldown = 0; [Desc("Apply the selfhealing using these damagetypes.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); public override object Create(ActorInitializer init) { return new SelfHealing(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs b/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs index 06fc051254..160cc3a378 100644 --- a/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs +++ b/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs @@ -9,8 +9,7 @@ */ #endregion -using System.Collections.Generic; -using OpenRA.Mods.Common.Warheads; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Sound @@ -26,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits.Sound [Desc("Damage types that this should be used for (defined on the warheads).", "If empty, this will be used as the default sound for all death types.")] - public readonly HashSet DeathTypes = new HashSet(); + public readonly BitSet DeathTypes = default(BitSet); public override object Create(ActorInitializer init) { return new DeathSounds(this); } } @@ -41,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits.Sound if (IsTraitDisabled) return; - if (Info.DeathTypes.Count == 0 || e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) + if (!Info.DeathTypes.IsEmpty || e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) self.PlayVoiceLocal(Info.Voice, Info.VolumeMultiplier); } } diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs index ff11e9ef41..65b1a4e1fa 100644 --- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs @@ -12,7 +12,6 @@ using System; using System.Collections.Generic; using System.Linq; -using OpenRA.Mods.Common.Pathfinder; using OpenRA.Primitives; using OpenRA.Traits; @@ -64,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits public readonly HashSet Crushes = new HashSet(); [Desc("Types of damage that are caused while crushing. Leave empty for no damage types.")] - public readonly HashSet CrushDamageTypes = new HashSet(); + public readonly BitSet CrushDamageTypes = default(BitSet); [FieldLoader.LoadUsing("LoadSpeeds", true)] [Desc("Set Water: 0 for ground units and lower the value on rough terrain.")] diff --git a/OpenRA.Mods.Common/Warheads/DamageWarhead.cs b/OpenRA.Mods.Common/Warheads/DamageWarhead.cs index 9ac14f15a2..e8805ce0a7 100644 --- a/OpenRA.Mods.Common/Warheads/DamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/DamageWarhead.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Warheads @@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Warheads public readonly int Damage = 0; [Desc("Types of damage that this warhead causes. Leave empty for no damage types.")] - public readonly HashSet DamageTypes = new HashSet(); + public readonly BitSet DamageTypes = default(BitSet); [Desc("Damage percentage versus each armortype.")] public readonly Dictionary Versus = new Dictionary();