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:
@@ -17,13 +17,14 @@ using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
public class InfiltratesInfo : ConditionalTraitInfo
|
||||
{
|
||||
public readonly HashSet<string> Types = new HashSet<string>();
|
||||
public readonly BitSet<TargetableType> Types;
|
||||
|
||||
[VoiceReference] public readonly string Voice = "Action";
|
||||
|
||||
@@ -72,14 +73,14 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
if (IsTraitDisabled)
|
||||
return false;
|
||||
|
||||
IEnumerable<string> targetTypes = null;
|
||||
var targetTypes = new BitSet<TargetableType>();
|
||||
if (order.Target.Type == TargetType.FrozenActor)
|
||||
targetTypes = order.Target.FrozenActor.TargetTypes;
|
||||
|
||||
if (order.Target.Type == TargetType.Actor)
|
||||
targetTypes = order.TargetActor.GetEnabledTargetTypes();
|
||||
|
||||
return targetTypes != null && Info.Types.Overlaps(targetTypes);
|
||||
return Info.Types.Overlaps(targetTypes);
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
@@ -133,7 +134,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
if (!info.ValidStances.HasStance(stance))
|
||||
return false;
|
||||
|
||||
return info.Types.Overlaps(target.Info.TraitInfos<ITargetableInfo>().SelectMany(ti => ti.GetTargetTypes()));
|
||||
return info.Types.Overlaps(target.Info.GetAllTargetTypes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user