encompass-cs/encompass-cs/World.cs

75 lines
2.4 KiB
C#

using System.Collections.Generic;
namespace Encompass
{
/// <summary>
/// The World is a collection of Engines, Renderers, Entities, Components, and Messages that compose the simulation.
/// </summary>
public class World
{
private readonly List<Engine> enginesInOrder;
private readonly EntityManager entityManager;
private readonly ComponentManager componentManager;
private readonly TrackingManager trackingManager;
private readonly MessageManager messageManager;
private readonly TimeManager timeManager;
private readonly RenderManager renderManager;
internal World(
List<Engine> enginesInOrder,
EntityManager entityManager,
ComponentManager componentManager,
TrackingManager trackingManager,
MessageManager messageManager,
TimeManager timeManager,
RenderManager renderManager
)
{
this.enginesInOrder = enginesInOrder;
this.entityManager = entityManager;
this.componentManager = componentManager;
this.trackingManager = trackingManager;
this.messageManager = messageManager;
this.timeManager = timeManager;
this.renderManager = renderManager;
}
/// <summary>
/// Drives the simulation. Should be called from your game engine's update loop.
/// </summary>
/// <param name="dt">The time in seconds that has passed since the previous frame.</param>
public void Update(double dt)
{
trackingManager.UpdateTracking();
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(enginesInOrder);
componentManager.RemoveMarkedComponents();
componentManager.WriteComponents();
}
/// <summary>
/// Causes the Renderers to draw.
/// </summary>
public void Draw()
{
renderManager.Draw();
}
}
}