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:
@@ -365,15 +365,20 @@ namespace OpenRA.Traits
|
||||
bool SpatiallyPartitionable { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates target types as defined on <see cref="Traits.ITargetable"/> are present in a <see cref="Primitives.BitSet{T}"/>.
|
||||
/// </summary>
|
||||
public sealed class TargetableType { TargetableType() { } }
|
||||
|
||||
public interface ITargetableInfo : ITraitInfoInterface
|
||||
{
|
||||
HashSet<string> GetTargetTypes();
|
||||
BitSet<TargetableType> GetTargetTypes();
|
||||
}
|
||||
|
||||
public interface ITargetable
|
||||
{
|
||||
// Check IsTraitEnabled or !IsTraitDisabled first
|
||||
HashSet<string> TargetTypes { get; }
|
||||
BitSet<TargetableType> TargetTypes { get; }
|
||||
bool TargetableBy(Actor self, Actor byActor);
|
||||
bool RequiresForceFire { get; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user