Enhance world simulation and API functionality; implement clock management improvements, ensure proper handling of world states during updates, and refine data persistence methods to prevent resurrecting deleted worlds.

This commit is contained in:
Leonid Pershin
2026-08-16 22:02:45 +03:00
parent 9d1e3c29c7
commit 3610ee8051
12 changed files with 352 additions and 80 deletions
@@ -11,8 +11,6 @@ namespace TheLivingWorld.Api.Simulation;
/// </summary>
public sealed class WorldSimulation : IDisposable
{
private static readonly ClockSystem ClockSystem = new();
private readonly object _gate = new();
private readonly World _ecs;
private readonly Entity _clockEntity;
@@ -85,10 +83,11 @@ public sealed class WorldSimulation : IDisposable
if (realElapsed > TimeSpan.Zero)
{
var before = SnapshotClockUnlocked();
// Compare raw ticks: this runs at 10 Hz per world, so snapshotting DTOs just to diff would
// allocate for nothing.
var before = _ecs.Get<GameClock>(_clockEntity).Ticks;
ClockSystem.Execute(_ecs, realElapsed);
var after = SnapshotClockUnlocked();
if (after.GameTime != before.GameTime) _dirty = true;
if (_ecs.Get<GameClock>(_clockEntity).Ticks != before) _dirty = true;
}
_lastTickedAt = DateTimeOffset.UtcNow;