37 lines
806 B
C#
37 lines
806 B
C#
using SpaceGame.Simulation.Api.Contracts;
|
|
|
|
namespace SpaceGame.Simulation.Api.Simulation;
|
|
|
|
public sealed class WorldService(IWebHostEnvironment environment)
|
|
{
|
|
private readonly object _sync = new();
|
|
private readonly ScenarioLoader _loader = new(environment.ContentRootPath);
|
|
private readonly SimulationEngine _engine = new();
|
|
private SimulationWorld _world = new ScenarioLoader(environment.ContentRootPath).Load();
|
|
|
|
public WorldSnapshot GetSnapshot()
|
|
{
|
|
lock (_sync)
|
|
{
|
|
return _engine.BuildSnapshot(_world);
|
|
}
|
|
}
|
|
|
|
public void Tick(float deltaSeconds)
|
|
{
|
|
lock (_sync)
|
|
{
|
|
_engine.Tick(_world, deltaSeconds);
|
|
}
|
|
}
|
|
|
|
public WorldSnapshot Reset()
|
|
{
|
|
lock (_sync)
|
|
{
|
|
_world = _loader.Load();
|
|
return _engine.BuildSnapshot(_world);
|
|
}
|
|
}
|
|
}
|