2019-06-15 00:51:06 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2019-06-16 01:05:56 +00:00
|
|
|
namespace Encompass
|
|
|
|
{
|
2019-10-24 19:48:36 +00:00
|
|
|
/// <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
|
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
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;
|
2019-06-14 03:28:26 +00:00
|
|
|
|
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-12-28 21:53:02 +00:00
|
|
|
TrackingManager trackingManager,
|
2019-06-19 21:14:44 +00:00
|
|
|
MessageManager messageManager,
|
2019-11-21 21:53:33 +00:00
|
|
|
TimeManager timeManager,
|
2019-06-19 21:14:44 +00:00
|
|
|
RenderManager renderManager
|
2019-06-16 01:05:56 +00:00
|
|
|
)
|
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
_enginesInOrder = enginesInOrder;
|
|
|
|
_entityManager = entityManager;
|
|
|
|
_componentManager = componentManager;
|
|
|
|
_trackingManager = trackingManager;
|
|
|
|
_messageManager = messageManager;
|
|
|
|
_timeManager = timeManager;
|
|
|
|
_renderManager = renderManager;
|
2019-06-14 03:28:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 19:48:36 +00:00
|
|
|
/// <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>
|
2019-06-24 19:14:37 +00:00
|
|
|
public void Update(double dt)
|
2019-06-16 01:05:56 +00:00
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
_trackingManager.UpdateTracking();
|
|
|
|
_messageManager.ProcessDelayedMessages(dt);
|
|
|
|
_timeManager.Update(dt);
|
2019-10-24 19:48:36 +00:00
|
|
|
|
2020-03-20 07:09:57 +00:00
|
|
|
foreach (var engine in _enginesInOrder)
|
2019-06-16 01:05:56 +00:00
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
if (engine._usesTimeDilation)
|
2019-11-21 21:53:33 +00:00
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
engine.Update(dt * _timeManager.TimeDilationFactor);
|
2019-11-21 21:53:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
engine.Update(dt);
|
|
|
|
}
|
2020-03-17 22:29:16 +00:00
|
|
|
|
|
|
|
engine.ClearNewlyCreatedEntities();
|
2019-06-15 00:51:06 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 07:09:57 +00:00
|
|
|
_messageManager.ClearMessages();
|
|
|
|
_entityManager.PruneEmptyEntities();
|
|
|
|
_entityManager.DestroyMarkedEntities(_enginesInOrder);
|
2019-06-19 23:13:02 +00:00
|
|
|
|
2020-03-20 07:09:57 +00:00
|
|
|
_componentManager.RemoveMarkedComponents();
|
|
|
|
_componentManager.WriteComponents();
|
2019-06-14 03:28:26 +00:00
|
|
|
}
|
2019-06-19 21:14:44 +00:00
|
|
|
|
2019-10-24 19:48:36 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Causes the Renderers to draw.
|
|
|
|
/// </summary>
|
2021-03-24 00:37:47 +00:00
|
|
|
public void Draw(double dt, double alpha)
|
2019-06-19 21:14:44 +00:00
|
|
|
{
|
2021-03-24 00:37:47 +00:00
|
|
|
_renderManager.Draw(dt, alpha);
|
2019-06-19 21:14:44 +00:00
|
|
|
}
|
2019-06-14 03:28:26 +00:00
|
|
|
}
|
|
|
|
}
|