From 95afb2af5e436cce5d8f37a912105e9e5d54a856 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 11 Jul 2026 17:50:26 +0100 Subject: [PATCH] Restore daemon cell thermal simulation --- Aetheria.State.Daemon.Smoke/Program.cs | 67 +++++++ ...AetheriaRuntimeDaemonGameSurfaceBuilder.cs | 134 ++++++++++++- .../AetheriaRuntimeDaemonSimulation.cs | 8 +- .../Runtime/AetheriaRuntimeGameDocuments.cs | 4 + .../AetheriaRuntimeGameViewportDocuments.cs | 12 ++ .../AetheriaRuntimeThermalSimulation.cs | 177 ++++++++++++++++++ .../AetheriaRuntimeThermalSimulation.cs.meta | 2 + docs/original-game-migration-matrix.md | 9 +- 8 files changed, 400 insertions(+), 13 deletions(-) create mode 100644 Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeThermalSimulation.cs create mode 100644 Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeThermalSimulation.cs.meta diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index 0679cdc60..8178b49e0 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -12,6 +12,50 @@ internal sealed class AetheriaDaemonYmirSmokeChecks YmirMovesProjectileAndReportsStableContact(); DaemonSimulationAppliesYmirHit(); MissingPhysicsOwnerCannotAdvanceProjectiles(); + ThermalCellsUseFossilConductionAndRadiation(); + } + + private static void ThermalCellsUseFossilConductionAndRadiation() + { + var entity = Entity(7, 0, "player"); + entity.StatGrids = + [ + Grid(AetheriaRuntimeThermalSimulation.TemperatureGrid, 2, 1, 300, 280), + Grid(AetheriaRuntimeThermalSimulation.ThermalMassGrid, 2, 1, 1, 1), + Grid(AetheriaRuntimeThermalSimulation.ConductivityGrid, 2, 1, 1, 1) + ]; + + AetheriaRuntimeThermalSimulation.AddHeat(entity, 20); + RequireNear(310, GridValue(entity, AetheriaRuntimeThermalSimulation.TemperatureGrid, 0), 0.000001, + "heat energy must be divided across cells and thermal mass"); + RequireNear(290, GridValue(entity, AetheriaRuntimeThermalSimulation.TemperatureGrid, 1), 0.000001, + "heat energy must be divided across cells and thermal mass"); + + AetheriaRuntimeThermalSimulation.Step(entity, 0.1); + var expectedHot = (310 / 0.01 + 290) / 101; + expectedHot -= Math.Pow(expectedHot, 3) * 0.00000001 * 0.1; + var expectedCool = (290 / 0.01 + 310) / 101; + expectedCool -= Math.Pow(expectedCool, 3) * 0.00000001 * 0.1; + RequireNear(expectedHot, GridValue(entity, AetheriaRuntimeThermalSimulation.TemperatureGrid, 0), 0.000001, + "hot cell must follow fossil conduction and radiation"); + RequireNear(expectedCool, GridValue(entity, AetheriaRuntimeThermalSimulation.TemperatureGrid, 1), 0.000001, + "cool cell must follow fossil conduction and radiation"); + RequireNear((expectedHot + expectedCool) / 2, Stat(entity, "heat"), 0.000001, + "legacy heat scalar must be derived from cell temperature"); + + var run = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "thermal-projection-smoke", + CurrentZoneIndex = 0, + CurrentEntityKey = "zone.0.entity.7", + Zones = [new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [entity] }] + }; + var document = AetheriaRuntimeGameDocuments.CurrentEntity(new AetheriaRuntimeDaemonFrameDocument { Run = run }); + RequireNear(Stat(entity, "heat"), document.Hud.MeanTemperature, 0.000001, + "Eve current-entity state must publish mean temperature"); + RequireNear(GridValue(entity, AetheriaRuntimeThermalSimulation.TemperatureGrid, 0), document.Hud.MaximumTemperature, 0.000001, + "Eve current-entity state must publish maximum temperature"); + Require(document.Hud.ThermalVisibility > 0, "Eve current-entity state must publish thermal visibility"); } private static void YmirMovesProjectileAndReportsStableContact() @@ -118,6 +162,17 @@ internal sealed class AetheriaDaemonYmirSmokeChecks Values = [value] }; + private static AetheriaRuntimeEntityStatGridCommit Grid(string name, int width, int height, params double[] values) => new() + { + Name = name, + Width = width, + Height = height, + Values = values + }; + + private static double GridValue(AetheriaRuntimeEntitySnapshotCommit entity, string name, int index) => + entity.StatGrids.Single(grid => string.Equals(grid.Name, name, StringComparison.OrdinalIgnoreCase)).Values[index]; + private static double Stat(AetheriaRuntimeEntitySnapshotCommit entity, string name) => entity.StatGrids.Single(grid => string.Equals(grid.Name, name, StringComparison.OrdinalIgnoreCase)).Values[0]; @@ -126,4 +181,16 @@ internal sealed class AetheriaDaemonYmirSmokeChecks if (!EqualityComparer.Default.Equals(expected, actual)) throw new InvalidOperationException($"{message}. Expected {expected}; actual {actual}."); } + + private static void Require(bool condition, string message) + { + if (!condition) + throw new InvalidOperationException(message); + } + + private static void RequireNear(double expected, double actual, double tolerance, string message) + { + if (Math.Abs(expected - actual) > tolerance) + throw new InvalidOperationException($"{message}. Expected {expected}; actual {actual}."); + } } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs index 140f0ad03..9d74ce3e4 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs @@ -31,7 +31,12 @@ namespace GameCult.Aetheria.State.Verse activeMainMenuSurfaceId = NormalizeMainMenuSurfaceId(activeMainMenuSurfaceId); var surfaceChildren = new List { - PlayableWorldSurface("aetheria.daemon.game.world", run, zone, run.CurrentEntityKey), + PlayableWorldSurface( + "aetheria.daemon.game.world", + run, + zone, + run.CurrentEntityKey, + frame.SimulationSettings), GravityFieldSurface("aetheria.daemon.game.field"), MainMenuOverlay("aetheria.daemon.game.main_menu", activeMainMenuSurfaceId), Node( @@ -169,7 +174,12 @@ namespace GameCult.Aetheria.State.Verse }; var entities = (zone.Entities ?? Array.Empty()) .Where(entity => entity != null && entity.IsActive) - .Select(entity => PlayableWorldEntity(entity, run, zone, run.CurrentEntityKey)) + .Select(entity => PlayableWorldEntity( + entity, + run, + zone, + run.CurrentEntityKey, + AetheriaRuntimeDaemonSimulationSettings.AetheriaDefault)) .ToArray(); return new AetheriaRuntimeSurfaceComponent( id, @@ -330,7 +340,8 @@ namespace GameCult.Aetheria.State.Verse string id, AetheriaRuntimeRunCheckpointCommit run, AetheriaRuntimeZoneSnapshotCommit zone, - string currentEntityKey) + string currentEntityKey, + AetheriaRuntimeDaemonSimulationSettings simulationSettings) { run ??= new AetheriaRuntimeRunCheckpointCommit(); zone ??= new AetheriaRuntimeZoneSnapshotCommit(); @@ -342,6 +353,7 @@ namespace GameCult.Aetheria.State.Verse ["assetManifest"] = AetheriaRuntimeVerseRecordKeys.EveAssetCatalog.ToString(), ["inputProfile"] = "arpg.pointer-keyboard.v1", ["cameraRig"] = "arpg.orbital-follow.v1", + ["viewId"] = "pilot", ["playerEntityId"] = playerEntityId, ["movementCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.SetMoveVector), ["focusCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.TargetNearest), @@ -356,7 +368,15 @@ namespace GameCult.Aetheria.State.Verse var entities = (zone.Entities ?? Array.Empty()) .Where(candidate => candidate != null && candidate.IsActive) - .Select(candidate => PlayableWorldEntity(candidate, run, zone, currentEntityKey)) + .Select(candidate => PlayableWorldEntity( + candidate, + run, + zone, + currentEntityKey, + simulationSettings)) + .Concat((zone.Projectiles ?? Array.Empty()) + .Where(projectile => projectile != null && projectile.LifetimeSeconds > 0) + .Select(projectile => PlayableWorldProjectile(projectile, run, zone))) .ToArray(); return new AetheriaRuntimeSurfaceComponent( @@ -384,10 +404,27 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeEntitySnapshotCommit entity, AetheriaRuntimeRunCheckpointCommit run, AetheriaRuntimeZoneSnapshotCommit zone, - string currentEntityKey) + string currentEntityKey, + AetheriaRuntimeDaemonSimulationSettings simulationSettings) { var entityId = run.EntityRecordKey(zone.ZoneIndex, entity.EntityIndex); var playerEntityId = PlayableWorldEntityId(run, zone, currentEntityKey); + var player = FindCurrentEntity(run, zone); + var targetEntityId = entity.TargetEntityIndex < 0 + ? "" + : run.EntityRecordKey(zone.ZoneIndex, entity.TargetEntityIndex); + var hull = EntityStat(entity, "hull"); + var shield = EntityStat(entity, "shield"); + var heat = EntityStat(entity, "heat"); + var minimumTemperature = EntityStat(entity, AetheriaRuntimeThermalSimulation.MinimumTemperatureGrid); + var maximumTemperature = EntityStat(entity, AetheriaRuntimeThermalSimulation.MaximumTemperatureGrid); + var thermalVisibility = EntityStat(entity, "thermal-visibility"); + var maximumHull = MaximumHull(entity, simulationSettings); + var maximumShield = MaximumShield(entity, simulationSettings); + var weaponCooldown = (entity.WeaponStates ?? Array.Empty()) + .Select(state => state?.CooldownProgress ?? 0) + .DefaultIfEmpty(0) + .Max(); var props = new Dictionary(StringComparer.Ordinal) { ["entityId"] = entityId, @@ -398,6 +435,23 @@ namespace GameCult.Aetheria.State.Verse ["position"] = FormatPosition(entity), ["rotationY"] = HeadingYaw(entity).ToString("0.###", CultureInfo.InvariantCulture), ["radius"] = PlayableWorldRadius(entity).ToString("0.###", CultureInfo.InvariantCulture), + ["hull"] = FormatNumber(hull), + ["maximumHull"] = FormatNumber(maximumHull), + ["hullRatio"] = FormatRatio(hull, maximumHull), + ["shield"] = FormatNumber(shield), + ["maximumShield"] = FormatNumber(maximumShield), + ["shieldRatio"] = FormatRatio(shield, maximumShield), + ["heat"] = FormatNumber(heat), + ["meanTemperature"] = FormatNumber(heat), + ["minimumTemperature"] = FormatNumber(minimumTemperature), + ["maximumTemperature"] = FormatNumber(maximumTemperature), + ["thermalVisibility"] = FormatNumber(thermalVisibility), + ["heatstroke"] = FormatRatio(entity.Heatstroke, 1), + ["hypothermia"] = FormatRatio(entity.Hypothermia, 1), + ["visibility"] = FormatNumber(entity.Visibility), + ["targetEntityId"] = targetEntityId, + ["targetedByPlayer"] = player != null && player.TargetEntityIndex == entity.EntityIndex ? "true" : "false", + ["weaponCooldown"] = FormatNumber(weaponCooldown), ["selectable"] = "true", ["controllable"] = string.Equals(entityId, playerEntityId, StringComparison.Ordinal) ? "true" : "false", ["focusCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.TargetNearest), @@ -413,6 +467,44 @@ namespace GameCult.Aetheria.State.Verse Array.Empty()); } + private static AetheriaRuntimeSurfaceComponent PlayableWorldProjectile( + AetheriaRuntimeProjectileCommit projectile, + AetheriaRuntimeRunCheckpointCommit run, + AetheriaRuntimeZoneSnapshotCommit zone) + { + var projectileId = $"{run.RunId}:zone:{zone.ZoneIndex}:projectile:{projectile.ProjectileId}"; + var targetEntityId = projectile.TargetEntityIndex < 0 + ? "" + : run.EntityRecordKey(zone.ZoneIndex, projectile.TargetEntityIndex); + var props = new Dictionary(StringComparer.Ordinal) + { + ["entityId"] = projectileId, + ["entityKind"] = "projectile", + ["label"] = projectile.WeaponKind ?? "Projectile", + ["faction"] = "", + ["assetRef"] = "prefab.entity.projectile", + ["position"] = string.Join(",", new[] + { + projectile.PositionX.ToString("0.###", CultureInfo.InvariantCulture), + "0", + projectile.PositionZ.ToString("0.###", CultureInfo.InvariantCulture) + }), + ["rotationY"] = HeadingDegrees(projectile.VelocityX, projectile.VelocityY).ToString("0.###", CultureInfo.InvariantCulture), + ["radius"] = Math.Max(0.01, projectile.Radius).ToString("0.###", CultureInfo.InvariantCulture), + ["sourceEntityId"] = run.EntityRecordKey(zone.ZoneIndex, projectile.SourceEntityIndex), + ["targetEntityId"] = targetEntityId, + ["damage"] = FormatNumber(projectile.Damage), + ["remainingLifetime"] = FormatNumber(projectile.LifetimeSeconds), + ["selectable"] = "false", + ["controllable"] = "false" + }; + return new AetheriaRuntimeSurfaceComponent( + $"aetheria.daemon.game.world.projectile.{projectile.ProjectileId}", + "world.entity3d", + props, + Array.Empty()); + } + private static string PlayableWorldAssetRef(AetheriaRuntimeEntitySnapshotCommit entity) { if (entity == null) @@ -446,9 +538,39 @@ namespace GameCult.Aetheria.State.Verse return 0.0; if (Math.Abs(entity.DirectionX) <= 0.0001 && Math.Abs(entity.DirectionY) <= 0.0001) return 0.0; - return Math.Atan2(entity.DirectionX, entity.DirectionY); + return HeadingDegrees(entity.DirectionX, entity.DirectionY); } + private static double HeadingDegrees(double x, double y) => + Math.Atan2(x, y) * (180.0 / Math.PI); + + private static double EntityStat(AetheriaRuntimeEntitySnapshotCommit entity, string name) => + (entity.StatGrids ?? Array.Empty()) + .FirstOrDefault(grid => string.Equals(grid?.Name, name, StringComparison.OrdinalIgnoreCase)) + ?.Values?.FirstOrDefault() ?? 0; + + private static double MaximumHull( + AetheriaRuntimeEntitySnapshotCommit entity, + AetheriaRuntimeDaemonSimulationSettings settings) => + string.Equals(entity.Kind, "station", StringComparison.OrdinalIgnoreCase) + ? (string.Equals(entity.FactionKey, "player", StringComparison.OrdinalIgnoreCase) + ? settings.PlayerStationHull + : settings.HostileStationHull) + : string.Equals(entity.FactionKey, "raider", StringComparison.OrdinalIgnoreCase) + ? settings.RaiderEntityHull + : settings.PlayerEntityHull; + + private static double MaximumShield( + AetheriaRuntimeEntitySnapshotCommit entity, + AetheriaRuntimeDaemonSimulationSettings settings) => + string.Equals(entity.Kind, "station", StringComparison.OrdinalIgnoreCase) + ? settings.StationShield + : settings.EntityShield; + + private static string FormatRatio(double value, double maximum) => + (maximum <= 0 ? 0 : Math.Max(0, Math.Min(1, value / maximum))) + .ToString("0.###", CultureInfo.InvariantCulture); + private static AetheriaRuntimeSurfaceComponent GravityFieldSurface(string id) { var viewport = DefaultViewport(); diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs index eb229b63d..10d9a9d35 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs @@ -36,6 +36,8 @@ namespace GameCult.Aetheria.State.Verse continue; EnsureStats(entities, settings); + foreach (var entity in entities) + AetheriaRuntimeThermalSimulation.EnsureState(entity); ApplyMovementIntent(run, entities, intents?.Movement, settings); StepRaiderAi(entities); StepTargetPursuit(entities, settings); @@ -215,7 +217,9 @@ namespace GameCult.Aetheria.State.Verse weaponState.Firing = true; weaponState.CoolingDown = true; weaponState.CooldownProgress = settings.WeaponCooldownSeconds; - SetStat(attacker, Heat, Math.Min(100, GetStat(attacker, Heat) + ResolveProjectileDamage(attacker, settings) * settings.ProjectileHeatScale)); + AetheriaRuntimeThermalSimulation.AddHeat( + attacker, + ResolveProjectileDamage(attacker, settings) * settings.ProjectileHeatScale); } PrepareProjectiles(zone, byIndex, deltaSeconds); @@ -233,7 +237,7 @@ namespace GameCult.Aetheria.State.Verse foreach (var entity in entities) { - SetStat(entity, Heat, Math.Max(0, GetStat(entity, Heat) - settings.HeatDissipationPerSecond * deltaSeconds)); + AetheriaRuntimeThermalSimulation.Step(entity, deltaSeconds); entity.IsActive = IsAlive(entity); if (!entity.IsActive) { diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeGameDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeGameDocuments.cs index b632972a8..22506dd62 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeGameDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeGameDocuments.cs @@ -1604,6 +1604,10 @@ namespace GameCult.Aetheria.State.Verse Hypothermia = entity.Hypothermia, Visibility = entity.Visibility, HullDurabilityRatio = Math.Clamp(Stat(entity, "hull"), 0, 1), + MeanTemperature = Stat(entity, AetheriaRuntimeThermalSimulation.MeanTemperatureGrid), + MinimumTemperature = Stat(entity, AetheriaRuntimeThermalSimulation.MinimumTemperatureGrid), + MaximumTemperature = Stat(entity, AetheriaRuntimeThermalSimulation.MaximumTemperatureGrid), + ThermalVisibility = Stat(entity, "thermal-visibility"), RadiatorTemperatureMinimum = radiatorTemperatures.Length == 0 ? 0 : radiatorTemperatures.Min(), RadiatorTemperatureMaximum = radiatorTemperatures.Length == 0 ? 0 : radiatorTemperatures.Max(), RadiatorCount = radiatorTemperatures.Length, diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeGameViewportDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeGameViewportDocuments.cs index 473f4d59e..17b6a3f7e 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeGameViewportDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeGameViewportDocuments.cs @@ -291,6 +291,18 @@ namespace GameCult.Aetheria.State.Verse [Key(17)] public double AetherDriveMaximumRpm { get; set; } + + [Key(18)] + public double MeanTemperature { get; set; } + + [Key(19)] + public double MinimumTemperature { get; set; } + + [Key(20)] + public double MaximumTemperature { get; set; } + + [Key(21)] + public double ThermalVisibility { get; set; } } [CultDocument("gamecult.aetheria.current_docking", "gamecult.aetheria.current_docking.v1")] diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeThermalSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeThermalSimulation.cs new file mode 100644 index 000000000..11c4d2077 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeThermalSimulation.cs @@ -0,0 +1,177 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +#nullable enable + +namespace GameCult.Aetheria.State.Verse +{ + public static class AetheriaRuntimeThermalSimulation + { + public const string TemperatureGrid = "temperature"; + public const string ThermalMassGrid = "thermal-mass"; + public const string ConductivityGrid = "conductivity"; + public const string MeanTemperatureGrid = "heat"; + public const string MinimumTemperatureGrid = "minimum-temperature"; + public const string MaximumTemperatureGrid = "maximum-temperature"; + + // Canonical values from Assets/Resources/Settings.asset in the fossil baseline. + public const double ConductionMultiplier = 0.01; + public const double RadiationExponent = 3.0; + public const double RadiationMultiplier = 0.00000001; + public const double InitialTemperature = 280.0; + + public static void EnsureState(AetheriaRuntimeEntitySnapshotCommit entity) + { + if (entity == null) + return; + + var grids = (entity.StatGrids ?? Array.Empty()).ToList(); + var temperature = Find(grids, TemperatureGrid); + if (!Valid(temperature)) + { + temperature = Grid(TemperatureGrid, 1, 1, InitialTemperature); + grids.Add(temperature); + } + + EnsureShape(grids, ThermalMassGrid, temperature.Width, temperature.Height, 1.0); + EnsureShape(grids, ConductivityGrid, temperature.Width, temperature.Height, 1.0); + EnsureScalar(grids, MeanTemperatureGrid, Mean(temperature.Values)); + EnsureScalar(grids, MinimumTemperatureGrid, temperature.Values.Min()); + EnsureScalar(grids, MaximumTemperatureGrid, temperature.Values.Max()); + entity.StatGrids = grids; + } + + public static void AddHeat(AetheriaRuntimeEntitySnapshotCommit entity, double energy) + { + if (entity == null || !double.IsFinite(energy) || Math.Abs(energy) < 0.0000001) + return; + + EnsureState(entity); + var grids = entity.StatGrids.ToList(); + var temperature = Find(grids, TemperatureGrid)!; + var thermalMass = Find(grids, ThermalMassGrid)!; + var values = temperature.Values.ToArray(); + var occupied = Enumerable.Range(0, values.Length) + .Where(index => thermalMass.Values[index] > 0) + .ToArray(); + if (occupied.Length == 0) + return; + + var energyPerCell = energy / occupied.Length; + foreach (var index in occupied) + values[index] = Math.Max(0, values[index] + energyPerCell / thermalMass.Values[index]); + temperature.Values = values; + entity.StatGrids = grids; + } + + public static void Step(AetheriaRuntimeEntitySnapshotCommit entity, double deltaSeconds) + { + if (entity == null || deltaSeconds <= 0) + return; + + EnsureState(entity); + var grids = entity.StatGrids.ToList(); + var temperature = Find(grids, TemperatureGrid)!; + var thermalMass = Find(grids, ThermalMassGrid)!; + var conductivity = Find(grids, ConductivityGrid)!; + var current = temperature.Values.ToArray(); + var next = current.ToArray(); + var radiation = 0.0; + + for (var y = 0; y < temperature.Height; y++) + for (var x = 0; x < temperature.Width; x++) + { + var index = Index(x, y, temperature.Width); + if (thermalMass.Values[index] <= 0) + continue; + + var weightedTemperature = current[index] / ConductionMultiplier; + var totalConductivity = 1.0 / ConductionMultiplier; + Accumulate(x - 1, y); + Accumulate(x + 1, y); + Accumulate(x, y - 1); + Accumulate(x, y + 1); + next[index] = weightedTemperature / totalConductivity; + + if (IsBorderCell(x, y, temperature.Width, temperature.Height, thermalMass.Values)) + { + var emitted = Math.Pow(Math.Max(0, next[index]), RadiationExponent) * RadiationMultiplier; + next[index] = Math.Max(0, next[index] - emitted * deltaSeconds); + radiation += emitted; + } + + void Accumulate(int neighborX, int neighborY) + { + if (neighborX < 0 || neighborY < 0 || neighborX >= temperature.Width || neighborY >= temperature.Height) + return; + var neighbor = Index(neighborX, neighborY, temperature.Width); + if (thermalMass.Values[neighbor] <= 0) + return; + var transfer = conductivity.Values[index] * conductivity.Values[neighbor] * + thermalMass.Values[neighbor] / thermalMass.Values[index]; + totalConductivity += transfer; + weightedTemperature += current[neighbor] * transfer; + } + } + + temperature.Values = next; + SetScalar(grids, MeanTemperatureGrid, Mean(next)); + SetScalar(grids, MinimumTemperatureGrid, next.Min()); + SetScalar(grids, MaximumTemperatureGrid, next.Max()); + entity.Visibility = Math.Max(0, entity.Visibility - PreviousThermalVisibility(entity)) + radiation; + SetScalar(grids, "thermal-visibility", radiation); + entity.StatGrids = grids; + } + + private static double PreviousThermalVisibility(AetheriaRuntimeEntitySnapshotCommit entity) => + Find(entity.StatGrids, "thermal-visibility")?.Values.FirstOrDefault() ?? 0; + + private static bool IsBorderCell(int x, int y, int width, int height, IReadOnlyList mass) => + x == 0 || y == 0 || x == width - 1 || y == height - 1 || + mass[Index(x - 1, y, width)] <= 0 || mass[Index(x + 1, y, width)] <= 0 || + mass[Index(x, y - 1, width)] <= 0 || mass[Index(x, y + 1, width)] <= 0; + + private static int Index(int x, int y, int width) => y * width + x; + private static double Mean(IReadOnlyList values) => values.Count == 0 ? 0 : values.Average(); + private static bool Valid(AetheriaRuntimeEntityStatGridCommit? grid) => + grid != null && grid.Width > 0 && grid.Height > 0 && grid.Values.Count == grid.Width * grid.Height; + + private static AetheriaRuntimeEntityStatGridCommit? Find( + IEnumerable grids, + string name) => grids.FirstOrDefault(grid => grid != null && string.Equals(grid.Name, name, StringComparison.OrdinalIgnoreCase)); + + private static void EnsureShape(List grids, string name, int width, int height, double value) + { + var grid = Find(grids, name); + if (grid == null) + grids.Add(Grid(name, width, height, value)); + else if (grid.Width != width || grid.Height != height || grid.Values.Count != width * height) + { + grid.Width = width; + grid.Height = height; + grid.Values = Enumerable.Repeat(value, width * height).ToArray(); + } + } + + private static void EnsureScalar(List grids, string name, double value) + { + if (Find(grids, name) == null) + grids.Add(Grid(name, 1, 1, value)); + } + + private static void SetScalar(List grids, string name, double value) + { + EnsureScalar(grids, name, value); + Find(grids, name)!.Values = new[] { value }; + } + + private static AetheriaRuntimeEntityStatGridCommit Grid(string name, int width, int height, double value) => new() + { + Name = name, + Width = width, + Height = height, + Values = Enumerable.Repeat(value, width * height).ToArray() + }; + } +} diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeThermalSimulation.cs.meta b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeThermalSimulation.cs.meta new file mode 100644 index 000000000..5e276e240 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeThermalSimulation.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: cfd4dce795cd4ec99de55d8ea7b153a4 diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index 1341d4390..fac16139f 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -22,7 +22,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. | Targeting/contacts | sensors + `ActionGameManager` | daemon | contact/target semantics | target HUD and indicators | simplified owner wired/projected; not parity | visibility/nearest/explicit/lock cases | | Projectile flight | weapon/projectile classes | Ymir | projectile entity/event projection | native projectile visual | local substitutes only | remove both Aetheria-local steppers; prove spawn/travel/hit/despawn through one Ymir world | | Shield/hull damage | energy-funded shield, armor cells, equipment and hull | daemon | entity status + damage events | meters, impacts, damage VFX | synthetic scalar owner wired; not parity | typed absorption, penetration, item damage and death causes | -| Thermal/energy | cell conduction and capacitor/reactor/radiator network | daemon | ship/equipment status and warnings | schematic/post effects | reference | cell heat, shared energy and medical thresholds | +| Thermal/energy | cell conduction and capacitor/reactor/radiator network | daemon | ship/equipment status and warnings | schematic/post effects | cell conduction/radiation wired; energy network and medical thresholds remain reference | capacitor/reactor/radiator ordering, shared energy and medical timelines | | Weapons | ServerShared behaviors + Unity effects | daemon + Ymir where spatial | action capability, weapon state, attack events | effects/audio/HUD | one synthetic weapon wired; original engine reference-only | each weapon family | | Destruction/drops | entity death and pickup paths | daemon | death/drop events and world entities | effects and pickups | fragments wired; chronology and original drop transaction absent | exactly-once drops and cleanup | | Tractor/scoop | analog tractor and physical timed pickups | daemon + Ymir | tractor intent, pickup entity and receipt | beam/interaction feedback | command wired; spatial/original pickup semantics absent | ramp, range, failed capacity, lifetime and pickup once | @@ -81,10 +81,9 @@ These are source-confirmed ownership failures, not feature backlog: 1. **Split combat writers.** Normal daemon simulation and the optional abstract combat kernel can both mutate combat state in one tick. Select one combat owner and delete the other's write path. -2. **Physics is not actually delegated.** Aetheria's local - `AetheriaRuntimeYmirProjectilePhysics` reimplements projectile stepping; it - does not use standalone `Ymir.Core`. Ship flight, tractor, gravity, docking - placement, and most collision remain outside Ymir. +2. **Physics delegation is incomplete.** Daemon projectile integration and + contacts now use `Ymir.Core`, but ship flight, tractor, gravity, docking + placement, and the Unity bridge/query path remain outside that authority. 3. **Persisted behavior is not executable behavior.** Snapshot schemas preserve broad equipment/behavior state while active simulation executes one synthetic projectile weapon and simplified raider pursuit.