encompass-cs/encompass-cs/World.cs

76 lines
2.4 KiB
C#
Raw Normal View History

2019-06-15 00:51:06 +00:00
using System.Collections.Generic;
2019-06-16 01:05:56 +00:00
namespace Encompass
{
/// <summary>
/// The World is a collection of Engines, Renderers, Entities, Components, and Messages that compose the simulation.
/// </summary>
2019-06-16 01:05:56 +00:00
public class World
{
2019-06-20 17:46:15 +00:00
private readonly List<Engine> enginesInOrder;
private readonly EntityManager entityManager;
private readonly ComponentManager componentManager;
private readonly MessageManager messageManager;
private readonly ComponentUpdateManager componentUpdateManager;
private readonly TimeManager timeManager;
2019-06-20 17:46:15 +00:00
private readonly RenderManager renderManager;
2019-06-15 00:51:06 +00:00
internal World(
2019-06-17 00:56:36 +00:00
List<Engine> enginesInOrder,
2019-06-15 00:51:06 +00:00
EntityManager entityManager,
2019-06-16 01:55:35 +00:00
ComponentManager componentManager,
2019-06-19 21:14:44 +00:00
MessageManager messageManager,
ComponentUpdateManager componentUpdateManager,
TimeManager timeManager,
2019-06-19 21:14:44 +00:00
RenderManager renderManager
2019-06-16 01:05:56 +00:00
)
{
2019-06-17 00:56:36 +00:00
this.enginesInOrder = enginesInOrder;
2019-06-15 00:03:56 +00:00
this.entityManager = entityManager;
this.componentManager = componentManager;
2019-06-16 01:55:35 +00:00
this.messageManager = messageManager;
this.componentUpdateManager = componentUpdateManager;
this.timeManager = timeManager;
2019-06-19 21:14:44 +00:00
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)
2019-06-16 01:05:56 +00:00
{
2019-08-20 02:05:18 +00:00
messageManager.ProcessDelayedMessages(dt);
timeManager.Update(dt);
2019-06-17 00:56:36 +00:00
foreach (var engine in enginesInOrder)
2019-06-16 01:05:56 +00:00
{
if (engine.usesTimeDilation)
{
engine.Update(dt * timeManager.TimeDilationFactor);
}
else
{
engine.Update(dt);
}
2019-06-15 00:51:06 +00:00
}
2019-06-16 01:55:35 +00:00
messageManager.ClearMessages();
entityManager.DestroyMarkedEntities();
2019-06-19 23:13:02 +00:00
componentManager.WriteComponents();
2019-12-05 22:59:55 +00:00
componentManager.RemoveMarkedComponents();
componentUpdateManager.Clear();
}
2019-06-19 21:14:44 +00:00
/// <summary>
/// Causes the Renderers to draw.
/// </summary>
2019-06-19 21:14:44 +00:00
public void Draw()
{
renderManager.Draw();
}
}
}