Some improvements for SpatiallyPartitioned.
- Tweak the Update and Remove methods to reduce the number of dictionary lookups required. - Change the Update method to an indexer, this allows simplifying callers who wanted to AddOrUpdate a value. - Implement IDictionary<T, Rectangle>, since the class already implements these semantics by providing a backing store of the bounds for each item. - Clean up some naming to use the generic `item` instead of `actor`. - Make the MutateBins action methods static.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
1b2c119b58
commit
ce3ad6fbb3
@@ -217,11 +217,7 @@ namespace OpenRA.Traits
|
||||
var mouseBounds = a.MouseBounds(worldRenderer);
|
||||
if (!mouseBounds.IsEmpty)
|
||||
{
|
||||
if (partitionedMouseActors.Contains(a))
|
||||
partitionedMouseActors.Update(a, mouseBounds.BoundingRect);
|
||||
else
|
||||
partitionedMouseActors.Add(a, mouseBounds.BoundingRect);
|
||||
|
||||
partitionedMouseActors[a] = mouseBounds.BoundingRect;
|
||||
partitionedMouseActorBounds[a] = new ActorBoundsPair(a, mouseBounds);
|
||||
}
|
||||
else
|
||||
@@ -229,12 +225,7 @@ namespace OpenRA.Traits
|
||||
|
||||
var screenBounds = a.ScreenBounds(worldRenderer).Union();
|
||||
if (!screenBounds.Size.IsEmpty)
|
||||
{
|
||||
if (partitionedRenderableActors.Contains(a))
|
||||
partitionedRenderableActors.Update(a, screenBounds);
|
||||
else
|
||||
partitionedRenderableActors.Add(a, screenBounds);
|
||||
}
|
||||
partitionedRenderableActors[a] = screenBounds;
|
||||
else
|
||||
partitionedRenderableActors.Remove(a);
|
||||
}
|
||||
@@ -255,23 +246,13 @@ namespace OpenRA.Traits
|
||||
{
|
||||
var mouseBounds = fa.MouseBounds;
|
||||
if (!mouseBounds.IsEmpty)
|
||||
{
|
||||
if (partitionedMouseFrozenActors[kv.Key].Contains(fa))
|
||||
partitionedMouseFrozenActors[kv.Key].Update(fa, mouseBounds.BoundingRect);
|
||||
else
|
||||
partitionedMouseFrozenActors[kv.Key].Add(fa, mouseBounds.BoundingRect);
|
||||
}
|
||||
partitionedMouseFrozenActors[kv.Key][fa] = mouseBounds.BoundingRect;
|
||||
else
|
||||
partitionedMouseFrozenActors[kv.Key].Remove(fa);
|
||||
|
||||
var screenBounds = fa.ScreenBounds.Union();
|
||||
if (!screenBounds.Size.IsEmpty)
|
||||
{
|
||||
if (partitionedRenderableFrozenActors[kv.Key].Contains(fa))
|
||||
partitionedRenderableFrozenActors[kv.Key].Update(fa, screenBounds);
|
||||
else
|
||||
partitionedRenderableFrozenActors[kv.Key].Add(fa, screenBounds);
|
||||
}
|
||||
partitionedRenderableFrozenActors[kv.Key][fa] = screenBounds;
|
||||
else
|
||||
partitionedRenderableFrozenActors[kv.Key].Remove(fa);
|
||||
}
|
||||
@@ -293,16 +274,16 @@ namespace OpenRA.Traits
|
||||
|
||||
public IEnumerable<Rectangle> RenderBounds(Player viewer)
|
||||
{
|
||||
var bounds = partitionedRenderableActors.ItemBounds
|
||||
.Concat(partitionedRenderableEffects.ItemBounds);
|
||||
var bounds = partitionedRenderableActors.Values
|
||||
.Concat(partitionedRenderableEffects.Values);
|
||||
|
||||
return viewer != null ? bounds.Concat(partitionedRenderableFrozenActors[viewer].ItemBounds) : bounds;
|
||||
return viewer != null ? bounds.Concat(partitionedRenderableFrozenActors[viewer].Values) : bounds;
|
||||
}
|
||||
|
||||
public IEnumerable<Polygon> MouseBounds(Player viewer)
|
||||
{
|
||||
var bounds = partitionedMouseActorBounds.Values.Select(a => a.Bounds);
|
||||
return viewer != null ? bounds.Concat(partitionedMouseFrozenActors[viewer].Items.Select(fa => fa.MouseBounds)) : bounds;
|
||||
return viewer != null ? bounds.Concat(partitionedMouseFrozenActors[viewer].Keys.Select(fa => fa.MouseBounds)) : bounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user