Merge pull request #3899 from pchote/viewport-regression-fixes
Viewport regression fixes
This commit is contained in:
@@ -138,6 +138,8 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
++RenderFrame;
|
++RenderFrame;
|
||||||
viewport.DrawRegions(worldRenderer, new DefaultInputHandler(orderManager.world));
|
viewport.DrawRegions(worldRenderer, new DefaultInputHandler(orderManager.world));
|
||||||
|
|
||||||
|
if (worldRenderer != null)
|
||||||
Sound.SetListenerPosition(worldRenderer.Position(viewport.CenterLocation.ToInt2()));
|
Sound.SetListenerPosition(worldRenderer.Position(viewport.CenterLocation.ToInt2()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* 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
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
@@ -26,15 +26,21 @@ namespace OpenRA.Traits
|
|||||||
public object Create(ActorInitializer init) { return new ActorMap(init.world, this); }
|
public object Create(ActorInitializer init) { return new ActorMap(init.world, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ActorMap
|
public class ActorMap : ITick
|
||||||
{
|
{
|
||||||
class InfluenceNode
|
class InfluenceNode
|
||||||
{
|
{
|
||||||
public InfluenceNode next;
|
public InfluenceNode Next;
|
||||||
public SubCell subCell;
|
public SubCell SubCell;
|
||||||
public Actor actor;
|
public Actor Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static readonly SubCell[] SubCells =
|
||||||
|
{
|
||||||
|
SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
||||||
|
SubCell.BottomLeft, SubCell.BottomRight
|
||||||
|
};
|
||||||
|
|
||||||
readonly ActorMapInfo info;
|
readonly ActorMapInfo info;
|
||||||
readonly Map map;
|
readonly Map map;
|
||||||
InfluenceNode[,] influence;
|
InfluenceNode[,] influence;
|
||||||
@@ -42,6 +48,11 @@ namespace OpenRA.Traits
|
|||||||
List<Actor>[] actors;
|
List<Actor>[] actors;
|
||||||
int rows, cols;
|
int rows, cols;
|
||||||
|
|
||||||
|
// Position updates are done in one pass
|
||||||
|
// to ensure consistency during a tick
|
||||||
|
List<Actor> addActorPosition;
|
||||||
|
List<Actor> removeActorPosition;
|
||||||
|
|
||||||
public ActorMap(World world, ActorMapInfo info)
|
public ActorMap(World world, ActorMapInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
@@ -54,6 +65,9 @@ namespace OpenRA.Traits
|
|||||||
for (var j = 0; j < rows; j++)
|
for (var j = 0; j < rows; j++)
|
||||||
for (var i = 0; i < cols; i++)
|
for (var i = 0; i < cols; i++)
|
||||||
actors[j * cols + i] = new List<Actor>();
|
actors[j * cols + i] = new List<Actor>();
|
||||||
|
|
||||||
|
addActorPosition = new List<Actor>();
|
||||||
|
removeActorPosition = new List<Actor>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Actor> GetUnitsAt(CPos a)
|
public IEnumerable<Actor> GetUnitsAt(CPos a)
|
||||||
@@ -61,9 +75,9 @@ namespace OpenRA.Traits
|
|||||||
if (!map.IsInMap(a))
|
if (!map.IsInMap(a))
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
for (var i = influence[a.X, a.Y]; i != null; i = i.next)
|
for (var i = influence[a.X, a.Y]; i != null; i = i.Next)
|
||||||
if (!i.actor.Destroyed)
|
if (!i.Actor.Destroyed)
|
||||||
yield return i.actor;
|
yield return i.Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Actor> GetUnitsAt(CPos a, SubCell sub)
|
public IEnumerable<Actor> GetUnitsAt(CPos a, SubCell sub)
|
||||||
@@ -71,9 +85,9 @@ namespace OpenRA.Traits
|
|||||||
if (!map.IsInMap(a))
|
if (!map.IsInMap(a))
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
for (var i = influence[a.X, a.Y]; i != null; i = i.next)
|
for (var i = influence[a.X, a.Y]; i != null; i = i.Next)
|
||||||
if (!i.actor.Destroyed && (i.subCell == sub || i.subCell == SubCell.FullCell))
|
if (!i.Actor.Destroyed && (i.SubCell == sub || i.SubCell == SubCell.FullCell))
|
||||||
yield return i.actor;
|
yield return i.Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasFreeSubCell(CPos a)
|
public bool HasFreeSubCell(CPos a)
|
||||||
@@ -81,8 +95,7 @@ namespace OpenRA.Traits
|
|||||||
if (!AnyUnitsAt(a))
|
if (!AnyUnitsAt(a))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return new[] { SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
return SubCells.Any(b => !AnyUnitsAt(a, b));
|
||||||
SubCell.BottomLeft, SubCell.BottomRight }.Any(b => !AnyUnitsAt(a,b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubCell? FreeSubCell(CPos a)
|
public SubCell? FreeSubCell(CPos a)
|
||||||
@@ -90,11 +103,9 @@ namespace OpenRA.Traits
|
|||||||
if (!HasFreeSubCell(a))
|
if (!HasFreeSubCell(a))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new[] { SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
return SubCells.First(b => !AnyUnitsAt(a, b));
|
||||||
SubCell.BottomLeft, SubCell.BottomRight }.First(b => !AnyUnitsAt(a,b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool AnyUnitsAt(CPos a)
|
public bool AnyUnitsAt(CPos a)
|
||||||
{
|
{
|
||||||
return influence[a.X, a.Y] != null;
|
return influence[a.X, a.Y] != null;
|
||||||
@@ -102,8 +113,8 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public bool AnyUnitsAt(CPos a, SubCell sub)
|
public bool AnyUnitsAt(CPos a, SubCell sub)
|
||||||
{
|
{
|
||||||
for (var i = influence[a.X, a.Y]; i != null; i = i.next)
|
for (var i = influence[a.X, a.Y]; i != null; i = i.Next)
|
||||||
if (i.subCell == sub || i.subCell == SubCell.FullCell)
|
if (i.SubCell == sub || i.SubCell == SubCell.FullCell)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -112,7 +123,7 @@ namespace OpenRA.Traits
|
|||||||
public void AddInfluence(Actor self, IOccupySpace ios)
|
public void AddInfluence(Actor self, IOccupySpace ios)
|
||||||
{
|
{
|
||||||
foreach (var c in ios.OccupiedCells())
|
foreach (var c in ios.OccupiedCells())
|
||||||
influence[c.First.X, c.First.Y] = new InfluenceNode { next = influence[c.First.X, c.First.Y], subCell = c.Second, actor = self };
|
influence[c.First.X, c.First.Y] = new InfluenceNode { Next = influence[c.First.X, c.First.Y], SubCell = c.Second, Actor = self };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveInfluence(Actor self, IOccupySpace ios)
|
public void RemoveInfluence(Actor self, IOccupySpace ios)
|
||||||
@@ -125,25 +136,41 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
if (influenceNode == null)
|
if (influenceNode == null)
|
||||||
return;
|
return;
|
||||||
else if (influenceNode.actor == toRemove)
|
else if (influenceNode.Actor == toRemove)
|
||||||
influenceNode = influenceNode.next;
|
influenceNode = influenceNode.Next;
|
||||||
|
|
||||||
if (influenceNode != null)
|
if (influenceNode != null)
|
||||||
RemoveInfluenceInner(ref influenceNode.next, toRemove);
|
RemoveInfluenceInner(ref influenceNode.Next, toRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddPosition(Actor a, IOccupySpace ios)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
var pos = ios.CenterPosition;
|
// Position updates are done in one pass
|
||||||
|
// to ensure consistency during a tick
|
||||||
|
foreach (var bin in actors)
|
||||||
|
bin.RemoveAll(removeActorPosition.Contains);
|
||||||
|
|
||||||
|
removeActorPosition.Clear();
|
||||||
|
|
||||||
|
foreach (var a in addActorPosition)
|
||||||
|
{
|
||||||
|
var pos = a.OccupiesSpace.CenterPosition;
|
||||||
var i = (pos.X / info.BinSize).Clamp(0, cols - 1);
|
var i = (pos.X / info.BinSize).Clamp(0, cols - 1);
|
||||||
var j = (pos.Y / info.BinSize).Clamp(0, rows - 1);
|
var j = (pos.Y / info.BinSize).Clamp(0, rows - 1);
|
||||||
actors[j * cols + i].Add(a);
|
actors[j * cols + i].Add(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addActorPosition.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddPosition(Actor a, IOccupySpace ios)
|
||||||
|
{
|
||||||
|
addActorPosition.Add(a);
|
||||||
|
}
|
||||||
|
|
||||||
public void RemovePosition(Actor a, IOccupySpace ios)
|
public void RemovePosition(Actor a, IOccupySpace ios)
|
||||||
{
|
{
|
||||||
foreach (var bin in actors)
|
removeActorPosition.Add(a);
|
||||||
bin.Remove(a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePosition(Actor a, IOccupySpace ios)
|
public void UpdatePosition(Actor a, IOccupySpace ios)
|
||||||
@@ -163,6 +190,7 @@ namespace OpenRA.Traits
|
|||||||
var j1 = (top / info.BinSize).Clamp(0, rows - 1);
|
var j1 = (top / info.BinSize).Clamp(0, rows - 1);
|
||||||
var j2 = (bottom / info.BinSize).Clamp(0, rows - 1);
|
var j2 = (bottom / info.BinSize).Clamp(0, rows - 1);
|
||||||
|
|
||||||
|
var actorsInBox = new List<Actor>();
|
||||||
for (var j = j1; j <= j2; j++)
|
for (var j = j1; j <= j2; j++)
|
||||||
{
|
{
|
||||||
for (var i = i1; i <= i2; i++)
|
for (var i = i1; i <= i2; i++)
|
||||||
@@ -170,11 +198,13 @@ namespace OpenRA.Traits
|
|||||||
foreach (var actor in actors[j * cols + i])
|
foreach (var actor in actors[j * cols + i])
|
||||||
{
|
{
|
||||||
var c = actor.CenterPosition;
|
var c = actor.CenterPosition;
|
||||||
if (left <= c.X && c.X <= right && top <= c.Y && c.Y <= bottom)
|
if (actor.IsInWorld && left <= c.X && c.X <= right && top <= c.Y && c.Y <= bottom)
|
||||||
yield return actor;
|
actorsInBox.Add(actor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return actorsInBox.Distinct();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user