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:
@@ -14,6 +14,7 @@ using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Warheads
|
||||
@@ -48,7 +49,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
[Desc("Whether to consider actors in determining whether the explosion should happen. If false, only terrain will be considered.")]
|
||||
public readonly bool ImpactActors = true;
|
||||
|
||||
static readonly string[] TargetTypeAir = new string[] { "Air" };
|
||||
static readonly BitSet<TargetableType> TargetTypeAir = new BitSet<TargetableType>("Air");
|
||||
|
||||
public ImpactType GetImpactType(World world, CPos cell, WPos pos, Actor firedBy)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Warheads
|
||||
@@ -35,10 +36,10 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
public abstract class Warhead : IWarhead
|
||||
{
|
||||
[Desc("What types of targets are affected.")]
|
||||
public readonly HashSet<string> ValidTargets = new HashSet<string> { "Ground", "Water" };
|
||||
public readonly BitSet<TargetableType> ValidTargets = new BitSet<TargetableType>("Ground", "Water");
|
||||
|
||||
[Desc("What types of targets are unaffected.", "Overrules ValidTargets.")]
|
||||
public readonly HashSet<string> InvalidTargets = new HashSet<string>();
|
||||
public readonly BitSet<TargetableType> InvalidTargets;
|
||||
|
||||
[Desc("What diplomatic stances are affected.")]
|
||||
public readonly Stance ValidStances = Stance.Ally | Stance.Neutral | Stance.Enemy;
|
||||
@@ -54,7 +55,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
[Desc("The color used for this warhead's visualization in the world's `WarheadDebugOverlay` trait.")]
|
||||
public readonly Color DebugOverlayColor = Color.Red;
|
||||
|
||||
public bool IsValidTarget(IEnumerable<string> targetTypes)
|
||||
public bool IsValidTarget(BitSet<TargetableType> targetTypes)
|
||||
{
|
||||
return ValidTargets.Overlaps(targetTypes) && !InvalidTargets.Overlaps(targetTypes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user