using System; using System.Collections.Generic; using System.Windows.Forms; using OpenRa.Game.Graphics; namespace OpenRa.Game { class World { List actors = new List(); List effects = new List(); List> frameEndActions = new List>(); int lastTime = Environment.TickCount; const int timestep = 40; public void Add(Actor a) { actors.Add(a); ActorAdded(a); } public void Remove(Actor a) { 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 a ) { frameEndActions.Add( a ); } public event Action ActorAdded = _ => { }; public event Action ActorRemoved = a => { a.Health = 0; }; /* make sure everyone sees it as dead */ public void ResetTimer() { lastTime = Environment.TickCount; } public void Update() { int t = Environment.TickCount; int dt = t - lastTime; if (dt >= timestep) { lastTime += timestep; foreach (var a in actors) a.Tick(); foreach (var e in effects) e.Tick(); Renderer.waterFrame += 0.00125f * timestep; Game.viewport.Tick(); } foreach (Action a in frameEndActions) a(this); frameEndActions.Clear(); } public IEnumerable Actors { get { return actors; } } public IEnumerable Effects { get { return effects; } } } }