70 lines
1.5 KiB
C#
70 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using OpenRa.Game.Effects;
|
|
using OpenRa.Game.Support;
|
|
|
|
namespace OpenRa.Game
|
|
{
|
|
class World
|
|
{
|
|
List<Actor> actors = new List<Actor>();
|
|
List<IEffect> effects = new List<IEffect>();
|
|
List<Action<World>> frameEndActions = new List<Action<World>>();
|
|
|
|
public void Add(Actor a)
|
|
{
|
|
a.IsInWorld = true;
|
|
actors.Add(a);
|
|
ActorAdded(a);
|
|
}
|
|
|
|
public void Remove(Actor a)
|
|
{
|
|
a.IsInWorld = false;
|
|
actors.Remove(a);
|
|
ActorRemoved(a);
|
|
}
|
|
|
|
public void Add(IEffect b) { effects.Add(b); }
|
|
public void Remove(IEffect b) { effects.Remove(b); }
|
|
|
|
public void AddFrameEndTask( Action<World> a ) { frameEndActions.Add( a ); }
|
|
|
|
public event Action<Actor> ActorAdded = _ => { };
|
|
public event Action<Actor> ActorRemoved = _ => { };
|
|
|
|
public void Tick()
|
|
{
|
|
foreach (var a in actors) a.Tick();
|
|
foreach (var e in effects) e.Tick();
|
|
|
|
Game.viewport.Tick();
|
|
|
|
var acts = frameEndActions;
|
|
frameEndActions = new List<Action<World>>();
|
|
foreach (var a in acts) a(this);
|
|
}
|
|
|
|
public IEnumerable<Actor> Actors { get { return actors; } }
|
|
public IEnumerable<IEffect> Effects { get { return effects; } }
|
|
|
|
uint nextAID = 0;
|
|
internal uint NextAID()
|
|
{
|
|
return nextAID++;
|
|
}
|
|
|
|
public int SyncHash()
|
|
{
|
|
using (new PerfSample("synchash"))
|
|
{
|
|
int ret = 0;
|
|
foreach (var a in Actors)
|
|
ret += (int)a.ActorID * Sync.CalculateSyncHash(a);
|
|
|
|
return ret;
|
|
}
|
|
}
|
|
}
|
|
}
|