Prevent items without size from being added to SpatiallyPartitioned.

Items with no size act unexpectedly as they can fail to be returned when querying partition bins as they do not intersect along the top or left edges of the bin. We prevent such items being added in the first place to avoid this scenario.

As a side effect - we must now prevent any Immobile items that do not have size from being added to the screen map.
This commit is contained in:
RoosterDragon
2016-01-09 16:49:47 +00:00
parent bef6f40759
commit 1bc3a7395f
2 changed files with 14 additions and 2 deletions

View File

@@ -30,14 +30,22 @@ namespace OpenRA.Primitives
itemBoundsBins = Exts.MakeArray(rows * cols, _ => new Dictionary<T, Rectangle>());
}
void ValidateBounds(Rectangle bounds)
{
if (bounds.Width <= 0 || bounds.Height <= 0)
throw new ArgumentException("bounds must be non-empty.", "bounds");
}
public void Add(T item, Rectangle bounds)
{
ValidateBounds(bounds);
itemBounds.Add(item, bounds);
MutateBins(item, bounds, addItem);
}
public void Update(T item, Rectangle bounds)
{
ValidateBounds(bounds);
MutateBins(item, itemBounds[item], removeItem);
MutateBins(item, itemBounds[item] = bounds, addItem);
}

View File

@@ -55,6 +55,8 @@ namespace OpenRA.Mods.Common.Traits
{
self.World.ActorMap.AddInfluence(self, this);
self.World.ActorMap.AddPosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Add(self);
}
@@ -62,6 +64,8 @@ namespace OpenRA.Mods.Common.Traits
{
self.World.ActorMap.RemoveInfluence(self, this);
self.World.ActorMap.RemovePosition(self, this);
if (!self.Bounds.Size.IsEmpty)
self.World.ScreenMap.Remove(self);
}
}