Use a BitSet for representing target types.
- Rename Bits<T> to BitSet<T>. - Implement set based helpers for BitSet<T>. - When representing TargetTypes of ITargetable in various traits, use a BitSet<TargetableType> instead of HashSet<string> for better performance & reduced memory usage. - Fix FieldLoader to trim input values when generating a BitSet<T>. - Require T in BitSet<T> and BitSetAllocator<T> to be a class since it's just a marker value. This allows the JIT to instantiate generic code for these classes once, as they don't benefit from specialized code for T. (Typically JITs will generate shared code for all reference types, and unique code for every value type encountered).
This commit is contained in:
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -45,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (IsTraitDisabled)
|
||||
yield break;
|
||||
|
||||
yield return new TargetTypeOrderTargeter(new HashSet<string> { "DetonateAttack" }, "DetonateAttack", 5, "attack", true, false) { ForceAttack = false };
|
||||
yield return new TargetTypeOrderTargeter(new BitSet<TargetableType>("DetonateAttack"), "DetonateAttack", 5, "attack", true, false) { ForceAttack = false };
|
||||
yield return new DeployOrderTargeter("Detonate", 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
continue;
|
||||
|
||||
// Check whether we can auto-target this actor
|
||||
var targetTypes = actor.GetEnabledTargetTypes().ToArray();
|
||||
var targetTypes = actor.GetEnabledTargetTypes();
|
||||
var validPriorities = activePriorities.Where(ati =>
|
||||
{
|
||||
// Already have a higher priority target
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -18,10 +18,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class AutoTargetPriorityInfo : ConditionalTraitInfo, Requires<AutoTargetInfo>
|
||||
{
|
||||
[Desc("Target types that can be AutoTargeted.")]
|
||||
public readonly HashSet<string> ValidTargets = new HashSet<string> { "Ground", "Water", "Air" };
|
||||
public readonly BitSet<TargetableType> ValidTargets = new BitSet<TargetableType>("Ground", "Water", "Air");
|
||||
|
||||
[Desc("Target types that can't be AutoTargeted.", "Overrules ValidTargets.")]
|
||||
public readonly HashSet<string> InvalidTargets = new HashSet<string>();
|
||||
public readonly BitSet<TargetableType> InvalidTargets;
|
||||
|
||||
[Desc("ValidTargets with larger priorities will be AutoTargeted before lower priorities.")]
|
||||
public readonly int Priority = 1;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly int MaxRadius = 4;
|
||||
|
||||
[Desc("The list of unit target types we are allowed to duplicate.")]
|
||||
public readonly HashSet<string> ValidTargets = new HashSet<string> { "Ground", "Water" };
|
||||
public readonly BitSet<TargetableType> ValidTargets = new BitSet<TargetableType>("Ground", "Water");
|
||||
|
||||
[Desc("Which factions this crate action can occur for.")]
|
||||
public readonly HashSet<string> ValidFactions = new HashSet<string>();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -19,8 +20,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class TargetableInfo : ConditionalTraitInfo, ITargetableInfo
|
||||
{
|
||||
[Desc("Target type. Used for filtering (in)valid targets.")]
|
||||
public readonly HashSet<string> TargetTypes = new HashSet<string>();
|
||||
public HashSet<string> GetTargetTypes() { return TargetTypes; }
|
||||
public readonly BitSet<TargetableType> TargetTypes;
|
||||
public BitSet<TargetableType> GetTargetTypes() { return TargetTypes; }
|
||||
|
||||
public bool RequiresForceFire = false;
|
||||
|
||||
@@ -53,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return cloaks.All(c => c.IsTraitDisabled || c.IsVisible(self, viewer.Owner));
|
||||
}
|
||||
|
||||
public virtual HashSet<string> TargetTypes { get { return Info.TargetTypes; } }
|
||||
public virtual BitSet<TargetableType> TargetTypes { get { return Info.TargetTypes; } }
|
||||
|
||||
public bool RequiresForceFire { get { return Info.RequiresForceFire; } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user