more.
This commit is contained in:
@@ -41,14 +41,19 @@ namespace OpenRa.Collections
|
|||||||
|
|
||||||
public class CachedView<T,U> : Set<U>
|
public class CachedView<T,U> : Set<U>
|
||||||
{
|
{
|
||||||
public CachedView( Set<T> set, Func<T,bool> include, Func<T,U> store )
|
public CachedView( Set<T> set, Func<T, bool> include, Func<T, U> store )
|
||||||
|
: this( set, include, x => new[] { store( x ) } )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public CachedView( Set<T> set, Func<T,bool> include, Func<T,IEnumerable<U>> store )
|
||||||
{
|
{
|
||||||
foreach( var t in set )
|
foreach( var t in set )
|
||||||
if( include( t ) )
|
if( include( t ) )
|
||||||
Add( store( t ) );
|
store( t ).Do( x => Add( x ) );
|
||||||
|
|
||||||
set.OnAdd += obj => { if( include( obj ) ) Add( store( obj ) ); };
|
set.OnAdd += obj => { if( include( obj ) ) store( obj ).Do( x => Add( x ) ); };
|
||||||
set.OnRemove += obj => { if( include( obj ) ) Remove( store( obj ) ); };
|
set.OnRemove += obj => { if( include( obj ) ) store( obj ).Do( x => Remove( x ) ); };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace OpenRa
|
namespace OpenRa
|
||||||
{
|
{
|
||||||
public static class Exts
|
public static class Exts
|
||||||
@@ -7,5 +9,11 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
return string.Format(fmt, args);
|
return string.Format(fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Do<T>( this IEnumerable<T> e, Action<T> fn )
|
||||||
|
{
|
||||||
|
foreach( var ee in e )
|
||||||
|
fn( ee );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,9 +52,6 @@ namespace OpenRa
|
|||||||
currentActivity = a.Tick(this) ?? new Idle();
|
currentActivity = a.Tick(this) ?? new Idle();
|
||||||
if (a == currentActivity || currentActivity is Idle) break;
|
if (a == currentActivity || currentActivity is Idle) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var tick in traits.WithInterface<ITick>())
|
|
||||||
tick.Tick(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsIdle
|
public bool IsIdle
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ namespace OpenRa
|
|||||||
if (IsBridge(w, w.Map.MapTiles[i, j].tile))
|
if (IsBridge(w, w.Map.MapTiles[i, j].tile))
|
||||||
ConvertBridgeToActor(w, i, j);
|
ConvertBridgeToActor(w, i, j);
|
||||||
|
|
||||||
foreach (var br in w.Actors.SelectMany(a => a.traits.WithInterface<Bridge>()))
|
foreach (var br in w.Queries.WithTraitMultiple<Bridge>())
|
||||||
br.FinalizeBridges(w);
|
br.Trait.FinalizeBridges(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ConvertBridgeToActor(World w, int i, int j)
|
static void ConvertBridgeToActor(World w, int i, int j)
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ namespace OpenRa.Graphics
|
|||||||
|
|
||||||
public void DrawRegions( World world )
|
public void DrawRegions( World world )
|
||||||
{
|
{
|
||||||
world.WorldRenderer.palette.Update(world.Actors.SelectMany(
|
world.WorldRenderer.palette.Update(world.Queries.WithTraitMultiple<IPaletteModifier>().Select(t=>t.Trait));
|
||||||
a => a.traits.WithInterface<IPaletteModifier>()));
|
|
||||||
|
|
||||||
float2 r1 = new float2(2, -2) / screenSize;
|
float2 r1 = new float2(2, -2) / screenSize;
|
||||||
float2 r2 = new float2(-1, 1);
|
float2 r2 = new float2(-1, 1);
|
||||||
|
|||||||
@@ -62,11 +62,10 @@ namespace OpenRa.Traits
|
|||||||
if (!a.traits.Get<IOccupySpace>().OccupiedCells().Contains( new int2( x, y ) ) )
|
if (!a.traits.Get<IOccupySpace>().OccupiedCells().Contains( new int2( x, y ) ) )
|
||||||
throw new InvalidOperationException( "UIM: Sanity check failed A" );
|
throw new InvalidOperationException( "UIM: Sanity check failed A" );
|
||||||
|
|
||||||
foreach( Actor a in self.World.Actors )
|
foreach( var t in self.World.Queries.WithTraitMultiple<IOccupySpace>() )
|
||||||
foreach( var ios in a.traits.WithInterface<IOccupySpace>() )
|
foreach( var cell in t.Trait.OccupiedCells() )
|
||||||
foreach( var cell in ios.OccupiedCells() )
|
if (!influence[cell.X, cell.Y].Contains(t.Actor))
|
||||||
if (!influence[cell.X, cell.Y].Contains(a))
|
throw new InvalidOperationException( "UIM: Sanity check failed B" );
|
||||||
throw new InvalidOperationException( "UIM: Sanity check failed B" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Actor> GetUnitsAt( int2 a )
|
public IEnumerable<Actor> GetUnitsAt( int2 a )
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ namespace OpenRa
|
|||||||
players[i] = new Player(this, i, Game.LobbyInfo.Clients.FirstOrDefault(a => a.Index == i));
|
players[i] = new Player(this, i, Game.LobbyInfo.Clients.FirstOrDefault(a => a.Index == i));
|
||||||
Timer.Time( "worldActor, players: {0}" );
|
Timer.Time( "worldActor, players: {0}" );
|
||||||
|
|
||||||
|
Queries = new AllQueries( this );
|
||||||
|
Timer.Time( "queries: {0}" );
|
||||||
|
|
||||||
Bridges.MakeBridges(this);
|
Bridges.MakeBridges(this);
|
||||||
PathFinder = new PathFinder(this);
|
PathFinder = new PathFinder(this);
|
||||||
Timer.Time( "bridge, pathing: {0}" );
|
Timer.Time( "bridge, pathing: {0}" );
|
||||||
@@ -79,8 +82,6 @@ namespace OpenRa
|
|||||||
Minimap = new Minimap(this, Game.renderer);
|
Minimap = new Minimap(this, Game.renderer);
|
||||||
Timer.Time( "renderer, minimap: {0}" );
|
Timer.Time( "renderer, minimap: {0}" );
|
||||||
|
|
||||||
Queries = new AllQueries( this );
|
|
||||||
Timer.Time( "queries: {0}" );
|
|
||||||
Timer.Time( "----end World.ctor" );
|
Timer.Time( "----end World.ctor" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +125,8 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var a in actors) a.Tick();
|
foreach (var a in actors) a.Tick();
|
||||||
|
Queries.WithTraitMultiple<ITick>().Do( x => x.Trait.Tick( x.Actor ) );
|
||||||
|
|
||||||
foreach (var e in effects) e.Tick( this );
|
foreach (var e in effects) e.Tick( this );
|
||||||
|
|
||||||
Game.viewport.Tick();
|
Game.viewport.Tick();
|
||||||
@@ -190,7 +193,21 @@ namespace OpenRa
|
|||||||
x => x.traits.Contains<T>(),
|
x => x.traits.Contains<T>(),
|
||||||
x => new TraitPair<T> { Actor = x, Trait = x.traits.Get<T>() } );
|
x => new TraitPair<T> { Actor = x, Trait = x.traits.Get<T>() } );
|
||||||
hasTrait.Add( ret );
|
hasTrait.Add( ret );
|
||||||
return ret; }
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CachedView<Actor, TraitPair<T>> WithTraitMultiple<T>()
|
||||||
|
{
|
||||||
|
var ret = hasTrait.GetOrDefault<CachedView<Actor, TraitPair<T>>>();
|
||||||
|
if( ret != null )
|
||||||
|
return ret;
|
||||||
|
ret = new CachedView<Actor, TraitPair<T>>(
|
||||||
|
world.actors,
|
||||||
|
x => x.traits.Contains<T>(),
|
||||||
|
x => x.traits.WithInterface<T>().Select( t => new TraitPair<T> { Actor = x, Trait = t } ) );
|
||||||
|
hasTrait.Add( ret );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public struct TraitPair<T>
|
public struct TraitPair<T>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user