Remove SpatialBins.
This commit is contained in:
@@ -184,7 +184,6 @@
|
|||||||
<Compile Include="Traits\World\ResourceType.cs" />
|
<Compile Include="Traits\World\ResourceType.cs" />
|
||||||
<Compile Include="Traits\World\ScreenShaker.cs" />
|
<Compile Include="Traits\World\ScreenShaker.cs" />
|
||||||
<Compile Include="Traits\World\Shroud.cs" />
|
<Compile Include="Traits\World\Shroud.cs" />
|
||||||
<Compile Include="Traits\World\SpatialBins.cs" />
|
|
||||||
<Compile Include="Widgets\BackgroundWidget.cs" />
|
<Compile Include="Widgets\BackgroundWidget.cs" />
|
||||||
<Compile Include="Widgets\ButtonWidget.cs" />
|
<Compile Include="Widgets\ButtonWidget.cs" />
|
||||||
<Compile Include="Widgets\ChatDisplayWidget.cs" />
|
<Compile Include="Widgets\ChatDisplayWidget.cs" />
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
@@ -150,5 +151,30 @@ namespace OpenRA.Traits
|
|||||||
RemovePosition(a, ios);
|
RemovePosition(a, ios);
|
||||||
AddPosition(a, ios);
|
AddPosition(a, ios);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Actor> ActorsInBox(WPos a, WPos b)
|
||||||
|
{
|
||||||
|
var left = Math.Min(a.X, b.X);
|
||||||
|
var top = Math.Min(a.Y, b.Y);
|
||||||
|
var right = Math.Max(a.X, b.X);
|
||||||
|
var bottom = Math.Max(a.Y, b.Y);
|
||||||
|
var i1 = (left / info.BinSize).Clamp(0, cols - 1);
|
||||||
|
var i2 = (right / info.BinSize).Clamp(0, cols - 1);
|
||||||
|
var j1 = (top / info.BinSize).Clamp(0, rows - 1);
|
||||||
|
var j2 = (bottom / info.BinSize).Clamp(0, rows - 1);
|
||||||
|
|
||||||
|
for (var j = j1; j <= j2; j++)
|
||||||
|
{
|
||||||
|
for (var i = i1; i <= i2; i++)
|
||||||
|
{
|
||||||
|
foreach (var actor in actors[j*cols + i])
|
||||||
|
{
|
||||||
|
var c = actor.CenterPosition;
|
||||||
|
if (left <= c.X && c.X <= right && top <= c.Y && c.Y <= bottom)
|
||||||
|
yield return actor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
|
||||||
* available to you under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation. For more information,
|
|
||||||
* see COPYING.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace OpenRA.Traits
|
|
||||||
{
|
|
||||||
class SpatialBinsInfo : ITraitInfo
|
|
||||||
{
|
|
||||||
public readonly int BinSize = 8;
|
|
||||||
public object Create(ActorInitializer init) { return new SpatialBins( init.self, this ); }
|
|
||||||
}
|
|
||||||
|
|
||||||
class SpatialBins : ITick
|
|
||||||
{
|
|
||||||
List<Actor>[,] bins;
|
|
||||||
int scale;
|
|
||||||
|
|
||||||
public SpatialBins(Actor self, SpatialBinsInfo info)
|
|
||||||
{
|
|
||||||
bins = new List<Actor>[
|
|
||||||
self.World.Map.MapSize.X / info.BinSize,
|
|
||||||
self.World.Map.MapSize.Y / info.BinSize];
|
|
||||||
|
|
||||||
scale = Game.CellSize * info.BinSize;
|
|
||||||
|
|
||||||
for (var j = 0; j <= bins.GetUpperBound(1); j++)
|
|
||||||
for (var i = 0; i <= bins.GetUpperBound(0); i++)
|
|
||||||
bins[i, j] = new List<Actor>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Tick(Actor self)
|
|
||||||
{
|
|
||||||
for (var j = 0; j <= bins.GetUpperBound(1); j++)
|
|
||||||
for (var i = 0; i <= bins.GetUpperBound(0); i++)
|
|
||||||
bins[i, j].Clear();
|
|
||||||
|
|
||||||
foreach (var a in self.World.ActorsWithTrait<IOccupySpace>())
|
|
||||||
{
|
|
||||||
var bounds = a.Actor.ExtendedBounds.Value;
|
|
||||||
|
|
||||||
if (bounds.Right <= Game.CellSize * self.World.Map.Bounds.Left) continue;
|
|
||||||
if (bounds.Bottom <= Game.CellSize * self.World.Map.Bounds.Top) continue;
|
|
||||||
if (bounds.Left >= Game.CellSize * self.World.Map.Bounds.Right) continue;
|
|
||||||
if (bounds.Top >= Game.CellSize * self.World.Map.Bounds.Bottom) continue;
|
|
||||||
|
|
||||||
var i1 = Math.Max(0, bounds.Left / scale);
|
|
||||||
var i2 = Math.Min(bins.GetUpperBound(0), bounds.Right / scale);
|
|
||||||
var j1 = Math.Max(0, bounds.Top / scale);
|
|
||||||
var j2 = Math.Min(bins.GetUpperBound(1), bounds.Bottom / scale);
|
|
||||||
|
|
||||||
for (var j = j1; j <= j2; j++)
|
|
||||||
for (var i = i1; i <= i2; i++)
|
|
||||||
bins[i, j].Add(a.Actor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerable<Actor> ActorsInBins(int i1, int i2, int j1, int j2)
|
|
||||||
{
|
|
||||||
j1 = Math.Max(0, j1); j2 = Math.Min(j2, bins.GetUpperBound(1));
|
|
||||||
i1 = Math.Max(0, i1); i2 = Math.Min(i2, bins.GetUpperBound(0));
|
|
||||||
for (var j = j1; j <= j2; j++)
|
|
||||||
for (var i = i1; i <= i2; i++)
|
|
||||||
foreach (var a in bins[i, j])
|
|
||||||
yield return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Actor> ActorsInBox(PPos a, PPos b)
|
|
||||||
{
|
|
||||||
var r = Rectangle.FromLTRB(a.X, a.Y, b.X, b.Y);
|
|
||||||
|
|
||||||
return ActorsInBins(a.X / scale, b.X / scale, a.Y / scale, b.Y / scale)
|
|
||||||
.Distinct()
|
|
||||||
.Where(u => u.IsInWorld && u.ExtendedBounds.Value.IntersectsWith(r));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -32,16 +32,13 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static IEnumerable<Actor> FindActorsInBox(this World world, CPos tl, CPos br)
|
public static IEnumerable<Actor> FindActorsInBox(this World world, CPos tl, CPos br)
|
||||||
{
|
{
|
||||||
|
// TODO: Support diamond boxes for isometric maps?
|
||||||
return world.FindActorsInBox(tl.TopLeft, br.BottomRight);
|
return world.FindActorsInBox(tl.TopLeft, br.BottomRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<Actor> FindActorsInBox(this World world, WPos tl, WPos br)
|
public static IEnumerable<Actor> FindActorsInBox(this World world, WPos tl, WPos br)
|
||||||
{
|
{
|
||||||
var a = PPos.FromWPos(tl);
|
return world.ActorMap.ActorsInBox(tl, br);
|
||||||
var b = PPos.FromWPos(br);
|
|
||||||
var u = PPos.Min(a, b);
|
|
||||||
var v = PPos.Max(a, b);
|
|
||||||
return world.WorldActor.Trait<SpatialBins>().ActorsInBox(u,v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Actor ClosestTo(this IEnumerable<Actor> actors, Actor a)
|
public static Actor ClosestTo(this IEnumerable<Actor> actors, Actor a)
|
||||||
|
|||||||
@@ -365,8 +365,6 @@ World:
|
|||||||
BaseActor: mcv
|
BaseActor: mcv
|
||||||
SupportActors: e1,e1,e1,e1,e1,e2,e2,e2,e3,e3,apc,mtnk
|
SupportActors: e1,e1,e1,e1,e1,e2,e2,e2,e3,e3,apc,mtnk
|
||||||
SpawnMPUnits:
|
SpawnMPUnits:
|
||||||
SpatialBins:
|
|
||||||
BinSize: 4
|
|
||||||
CrateSpawner:
|
CrateSpawner:
|
||||||
Minimum: 1
|
Minimum: 1
|
||||||
Maximum: 6
|
Maximum: 6
|
||||||
|
|||||||
@@ -476,8 +476,6 @@ World:
|
|||||||
Races: ordos
|
Races: ordos
|
||||||
BaseActor: mcvo
|
BaseActor: mcvo
|
||||||
SpawnMPUnits:
|
SpawnMPUnits:
|
||||||
SpatialBins:
|
|
||||||
BinSize: 4
|
|
||||||
PathFinder:
|
PathFinder:
|
||||||
ValidateOrder:
|
ValidateOrder:
|
||||||
DebugPauseState:
|
DebugPauseState:
|
||||||
|
|||||||
@@ -682,8 +682,6 @@ World:
|
|||||||
OuterSupportRadius: 5
|
OuterSupportRadius: 5
|
||||||
MPStartLocations:
|
MPStartLocations:
|
||||||
SpawnMPUnits:
|
SpawnMPUnits:
|
||||||
SpatialBins:
|
|
||||||
BinSize: 4
|
|
||||||
PathFinder:
|
PathFinder:
|
||||||
ValidateOrder:
|
ValidateOrder:
|
||||||
DebugPauseState:
|
DebugPauseState:
|
||||||
|
|||||||
@@ -124,8 +124,6 @@ World:
|
|||||||
BaseActor: mcv
|
BaseActor: mcv
|
||||||
MPStartLocations:
|
MPStartLocations:
|
||||||
SpawnMPUnits:
|
SpawnMPUnits:
|
||||||
SpatialBins:
|
|
||||||
BinSize: 4
|
|
||||||
PathFinder:
|
PathFinder:
|
||||||
ValidateOrder:
|
ValidateOrder:
|
||||||
DebugPauseState:
|
DebugPauseState:
|
||||||
|
|||||||
Reference in New Issue
Block a user