using System.Collections.Generic;
namespace Encompass
{
///
/// The World is a collection of Engines, Renderers, Entities, Components, and Messages that compose the simulation.
///
public class World
{
private readonly List enginesInOrder;
private readonly EntityManager entityManager;
private readonly ComponentManager componentManager;
private readonly MessageManager messageManager;
private readonly ComponentUpdateManager componentUpdateManager;
private readonly TimeManager timeManager;
private readonly RenderManager renderManager;
internal World(
List enginesInOrder,
EntityManager entityManager,
ComponentManager componentManager,
MessageManager messageManager,
ComponentUpdateManager componentUpdateManager,
TimeManager timeManager,
RenderManager renderManager
)
{
this.enginesInOrder = enginesInOrder;
this.entityManager = entityManager;
this.componentManager = componentManager;
this.messageManager = messageManager;
this.componentUpdateManager = componentUpdateManager;
this.timeManager = timeManager;
this.renderManager = renderManager;
}
///
/// Drives the simulation. Should be called from your game engine's update loop.
///
/// The time in seconds that has passed since the previous frame.
public void Update(double dt)
{
messageManager.ProcessDelayedMessages(dt);
timeManager.Update(dt);
foreach (var engine in enginesInOrder)
{
if (engine.usesTimeDilation)
{
engine.Update(dt * timeManager.TimeDilationFactor);
}
else
{
engine.Update(dt);
}
}
messageManager.ClearMessages();
entityManager.DestroyMarkedEntities();
componentManager.WriteComponents();
componentManager.RemoveMarkedComponents();
componentUpdateManager.Clear();
}
///
/// Causes the Renderers to draw.
///
public void Draw()
{
renderManager.Draw();
}
}
}