From 0d54d003752580d04b221e8bd2079b53fd0ea14f Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 22 Mar 2010 19:01:53 +1300 Subject: [PATCH] use spatial index for whatever we can --- OpenRA.Game/Orders/UnitOrderGenerator.cs | 11 +++++------ OpenRA.Game/WorldUtils.cs | 8 +------- mods/cnc/system.yaml | 3 ++- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 3aa2917822..27cb39134e 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -53,14 +53,13 @@ namespace OpenRA.Orders string ChooseCursor(World world, MouseInput mi) { - - var p = Game.controller.MousePosition; - var c = Order(world, p.ToInt2(), mi) - .Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation)) - .FirstOrDefault(a => a != null); - using (new PerfSample("cursor")) { + var p = Game.controller.MousePosition; + var c = Order(world, p.ToInt2(), mi) + .Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation)) + .FirstOrDefault(a => a != null); + return c ?? (world.SelectActorsInBox(Game.CellSize * p, Game.CellSize * p).Any() diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 2df7b8254f..2544476840 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -82,13 +82,7 @@ namespace OpenRA public static IEnumerable FindUnits(this World world, float2 a, float2 b) { - var min = float2.Min(a, b); - var max = float2.Max(a, b); - - var rect = new RectangleF(min.X, min.Y, max.X - min.X, max.Y - min.Y); - - return world.Actors - .Where(x => x.GetBounds(true).IntersectsWith(rect)); + return world.WorldActor.traits.Get().ActorsInBox(a.ToInt2(), b.ToInt2()); } public static IEnumerable FindUnitsInCircle(this World world, float2 a, float r) diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml index 8136d743cc..597b23d94d 100644 --- a/mods/cnc/system.yaml +++ b/mods/cnc/system.yaml @@ -221,4 +221,5 @@ World: SilosNeeded: silos1.aud UnitLost: unitlost.aud NavalUnitLost: unitlost.aud - PrimaryBuildingSelected: pribldg1.aud \ No newline at end of file + PrimaryBuildingSelected: pribldg1.aud + SpatialBins: \ No newline at end of file