Perf fixes for low unit-counts. Added sanity checks - not enabled by default.
This commit is contained in:
@@ -54,7 +54,7 @@ namespace OpenRa.Game
|
|||||||
for( int i = 0 ; i < path.Count ; i++ )
|
for( int i = 0 ; i < path.Count ; i++ )
|
||||||
{
|
{
|
||||||
var sl = path[ i ] + offset;
|
var sl = path[ i ] + offset;
|
||||||
if( Game.BuildingInfluence.GetBuildingAt( path[ i ] ) == null & Game.UnitInfluence.GetUnitAt( path[ i ] ) == null )
|
if( i == 0 || Game.BuildingInfluence.GetBuildingAt( path[ i ] ) == null & Game.UnitInfluence.GetUnitAt( path[ i ] ) == null )
|
||||||
{
|
{
|
||||||
queue.Add( new PathDistance( estimator( sl - offset ), sl ) );
|
queue.Add( new PathDistance( estimator( sl - offset ), sl ) );
|
||||||
cellInfo[ sl.X, sl.Y ] = new CellInfo( cost, prev, false );
|
cellInfo[ sl.X, sl.Y ] = new CellInfo( cost, prev, false );
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
fromCell = toCell;
|
fromCell = toCell;
|
||||||
|
Game.UnitInfluence.Update( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QueueActivity( CurrentActivity nextActivity )
|
public void QueueActivity( CurrentActivity nextActivity )
|
||||||
@@ -205,7 +206,7 @@ namespace OpenRa.Game.Traits
|
|||||||
var nextCell = path[ path.Count - 1 ];
|
var nextCell = path[ path.Count - 1 ];
|
||||||
if( !CanEnterCell( nextCell, self ) )
|
if( !CanEnterCell( nextCell, self ) )
|
||||||
{
|
{
|
||||||
if( ( mobile.toCell - destination.Value ).LengthSquared < 4 )
|
if( ( mobile.toCell - destination.Value ).LengthSquared <= 8 )
|
||||||
{
|
{
|
||||||
path.Clear();
|
path.Clear();
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -18,19 +18,38 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
|
SanityCheck();
|
||||||
|
|
||||||
var units = Game.world.Actors
|
var units = Game.world.Actors
|
||||||
.Select( a => a.traits.GetOrDefault<Traits.Mobile>() ).Where( m => m != null );
|
.Select( a => a.traits.GetOrDefault<Traits.Mobile>() ).Where( m => m != null );
|
||||||
|
|
||||||
foreach (var u in units)
|
foreach (var u in units)
|
||||||
Update(u);
|
Update(u);
|
||||||
|
|
||||||
|
SanityCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
[System.Diagnostics.Conditional( "SANITY_CHECKS" )]
|
||||||
|
void SanityCheck()
|
||||||
|
{
|
||||||
|
for( int y = 0 ; y < 128 ; y++ )
|
||||||
|
for( int x = 0 ; x < 128 ; x++ )
|
||||||
|
if( influence[ x, y ] != null && !influence[ x, y ].traits.Get<Mobile>().OccupiedCells().Contains( new int2( x, y ) ) )
|
||||||
|
throw new InvalidOperationException( "UIM: Sanity check failed A" );
|
||||||
|
|
||||||
|
foreach( var a in Game.world.Actors )
|
||||||
|
{
|
||||||
|
if( !a.traits.Contains<Mobile>() )
|
||||||
|
continue;
|
||||||
|
foreach( var cell in a.traits.Get<Mobile>().OccupiedCells() )
|
||||||
|
if( influence[ cell.X, cell.Y ] != a )
|
||||||
|
throw new InvalidOperationException( "UIM: Sanity check failed B" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Actor GetUnitAt( int2 a )
|
public Actor GetUnitAt( int2 a )
|
||||||
{
|
{
|
||||||
var actor = influence[ a.X, a.Y ];
|
return influence[ a.X, a.Y ];
|
||||||
if( actor != null && !actor.traits.Get<Mobile>().OccupiedCells().Contains( a ) )
|
|
||||||
throw new InvalidOperationException( "UIM: Unit is not in influenced square" );
|
|
||||||
return actor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(Mobile a)
|
public void Add(Mobile a)
|
||||||
|
|||||||
Reference in New Issue
Block a user