Add world delta streaming and viewer smoothing

This commit is contained in:
2026-03-12 19:03:13 -04:00
parent 2fb90162ef
commit 9849dbae61
10 changed files with 966 additions and 177 deletions

View File

@@ -13,6 +13,7 @@ public sealed class SimulationWorld
public required List<ShipRuntime> Ships { get; init; }
public required List<FactionRuntime> Factions { get; init; }
public required Dictionary<string, ShipDefinition> ShipDefinitions { get; init; }
public int TickIntervalMs { get; init; } = 200;
public DateTimeOffset GeneratedAtUtc { get; set; }
}
@@ -30,6 +31,7 @@ public sealed class ResourceNodeRuntime
public required string ItemId { get; init; }
public float OreRemaining { get; set; }
public float MaxOre { get; init; }
public string LastDeltaSignature { get; set; } = string.Empty;
}
public sealed class StationRuntime
@@ -43,6 +45,7 @@ public sealed class StationRuntime
public float RefinedStock { get; set; }
public float ProcessTimer { get; set; }
public HashSet<string> DockedShipIds { get; } = [];
public string LastDeltaSignature { get; set; } = string.Empty;
}
public sealed class ShipRuntime
@@ -53,6 +56,7 @@ public sealed class ShipRuntime
public required string FactionId { get; init; }
public required Vector3 Position { get; set; }
public required Vector3 TargetPosition { get; set; }
public Vector3 Velocity { get; set; } = Vector3.Zero;
public string State { get; set; } = "idle";
public ShipOrderRuntime? Order { get; set; }
public required DefaultBehaviorRuntime DefaultBehavior { get; set; }
@@ -63,6 +67,7 @@ public sealed class ShipRuntime
public float Health { get; set; }
public List<string> History { get; } = [];
public string LastSignature { get; set; } = string.Empty;
public string LastDeltaSignature { get; set; } = string.Empty;
}
public sealed class FactionRuntime
@@ -75,6 +80,7 @@ public sealed class FactionRuntime
public float GoodsProduced { get; set; }
public int ShipsBuilt { get; set; }
public int ShipsLost { get; set; }
public string LastDeltaSignature { get; set; } = string.Empty;
}
public sealed class ShipOrderRuntime
@@ -131,4 +137,16 @@ public readonly record struct Vector3(float X, float Y, float Z)
Y + ((target.Y - Y) * t),
Z + ((target.Z - Z) * t));
}
public Vector3 Subtract(Vector3 other) => new(X - other.X, Y - other.Y, Z - other.Z);
public Vector3 Divide(float value)
{
if (value == 0f)
{
return Zero;
}
return new(X / value, Y / value, Z / value);
}
}