diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index ac9636418..2065c6b3c 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -54,6 +54,11 @@ else if (args.Contains("--tutorial-run", StringComparer.Ordinal)) checks.RunTutorialRun(); Console.WriteLine("Daemon persisted tutorial-run smoke passed."); } +else if (args.Contains("--orbits", StringComparer.Ordinal)) +{ + checks.RunOrbits(); + Console.WriteLine("Daemon dynamic-orbit smoke passed."); +} else { checks.Run(); @@ -92,6 +97,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks public void RunTutorialWorld() => RunCheck(TutorialWorldMaterializesEveryTopologyZone); public void RunTutorialMaterialization() => RunCheck(TutorialPopulationPreservesFossilEntityMechanics); public void RunTutorialRun() => RunCheck(TutorialRunPersistsCanonicalWorldTruth); + public void RunOrbits() => RunCheck(GeneratedOrbitsAdvanceOrbitalWorldTruth); private static void TutorialRunPersistsCanonicalWorldTruth() { @@ -425,6 +431,66 @@ internal sealed class AetheriaDaemonYmirSmokeChecks "one retained Box3D world must advance once for every fixed substep, not once per publication frame"); } + private static void GeneratedOrbitsAdvanceOrbitalWorldTruth() + { + var orbital = Entity(0, 0, "neutral"); + orbital.Kind = "station"; + orbital.OrbitKey = "orbit.station"; + orbital.PositionX = 10; + var orbit = new AetheriaRuntimeOrbitSnapshotCommit + { + OrbitKey = orbital.OrbitKey, + Distance = 10, + Phase = 0, + Period = 10 + }; + var zone = new AetheriaRuntimeZoneSnapshotCommit + { + ZoneIndex = 0, + Entities = [orbital], + Orbits = [orbit] + }; + + AetheriaRuntimeOrbitSimulation.StepZone(zone, [orbital], 2); + + RequireNear(0.2, orbit.Phase, 0.000001, + "the canonical orbit phase must advance by fixed delta divided by authored period"); + var expectedX = Math.Cos(0.2 * Math.PI * 2) * 10; + var expectedZ = Math.Sin(0.2 * Math.PI * 2) * 10; + RequireNear(expectedX, orbital.PositionX, 0.000001, + "orbital entity X must derive from the same advanced orbit observed by render queries"); + RequireNear(expectedZ, orbital.PositionZ, 0.000001, + "orbital entity Z must derive from the same advanced orbit observed by render queries"); + RequireNear((expectedX - 10) / 2, orbital.VelocityX, 0.000001, + "orbital X velocity must be the fixed-step pose delta consumed by Ymir"); + RequireNear(expectedZ / 2, orbital.VelocityY, 0.000001, + "orbital Z velocity must be the fixed-step pose delta consumed by Ymir"); + + var run = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "dynamic-orbit-smoke", + CurrentZoneIndex = 0, + CurrentEntityKey = "zone.0.entity.0", + Zones = [zone] + }; + using var physics = NewPhysics(); + AetheriaRuntimeDaemonSimulation.Step( + run, + new AetheriaRuntimeDaemonIntentState(), + 0.1, + AetheriaRuntimeDaemonSimulationSettings.AetheriaDefault, + physics, + frameId: 1, + simulationTimeSeconds: 2.1); + var integratedPhase = 0.21; + RequireNear(integratedPhase, orbit.Phase, 0.000001, + "the complete daemon step must advance the canonical orbit before Ymir"); + RequireNear(Math.Cos(integratedPhase * Math.PI * 2) * 10, orbital.PositionX, 0.05, + "Ymir must retain the daemon's advanced orbital X pose instead of restoring a stale body transform"); + RequireNear(Math.Sin(integratedPhase * Math.PI * 2) * 10, orbital.PositionZ, 0.05, + "Ymir must retain the daemon's advanced orbital Z pose instead of restoring a stale body transform"); + } + private static void StableEntityIdentitySurvivesCrossZoneReindex() { var departing = Entity(0, 0, "player"); @@ -490,6 +556,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks TutorialTopologyIsDeterministicConnectedAndRoleOwned, GeneratedZoneBodiesPreserveFossilHierarchy, TutorialWorldMaterializesEveryTopologyZone, + GeneratedOrbitsAdvanceOrbitalWorldTruth, VolumeSurfaceKeepsNativeShaderAbiInAssetVariant, YmirMovesProjectileAndReportsStableContact, CompressedTerminusStopsAtAttentionBoundary, diff --git a/Aetheria.State.Daemon/AetheriaDaemonTutorialWorldMaterializer.cs b/Aetheria.State.Daemon/AetheriaDaemonTutorialWorldMaterializer.cs index b0dee9ef3..face963af 100644 --- a/Aetheria.State.Daemon/AetheriaDaemonTutorialWorldMaterializer.cs +++ b/Aetheria.State.Daemon/AetheriaDaemonTutorialWorldMaterializer.cs @@ -92,6 +92,7 @@ public static class AetheriaDaemonTutorialWorldMaterializer ParentOrbitKey = baseOrbit.ParentOrbitKey, Distance = baseOrbit.Distance, Phase = baseOrbit.Phase + MathF.PI / 3 * Sign(random.NextFloat() - 0.5f), + Period = baseOrbit.Distance, FixedPosition = new AetheriaVector2() }; orbits.Add(stationOrbit); @@ -115,6 +116,7 @@ public static class AetheriaDaemonTutorialWorldMaterializer ParentOrbitKey = stationOrbit.ParentOrbitKey, Distance = stationOrbit.Distance, Phase = stationOrbit.Phase + 20f * distanceMultiplier / stationOrbit.Distance, + Period = stationOrbit.Distance, FixedPosition = new AetheriaVector2() }; orbits.Add(turretOrbit); @@ -197,6 +199,7 @@ public static class AetheriaDaemonTutorialWorldMaterializer ParentOrbitKey = orbit.ParentOrbitKey, Distance = orbit.Distance, Phase = orbit.Phase, + Period = orbit.Period, FixedPositionX = orbit.FixedPosition?.X ?? 0, FixedPositionY = orbit.FixedPosition?.Y ?? 0 }).ToArray() diff --git a/Aetheria.State.Daemon/AetheriaDaemonZoneBodyGenerator.cs b/Aetheria.State.Daemon/AetheriaDaemonZoneBodyGenerator.cs index a7a125d1c..14a07625f 100644 --- a/Aetheria.State.Daemon/AetheriaDaemonZoneBodyGenerator.cs +++ b/Aetheria.State.Daemon/AetheriaDaemonZoneBodyGenerator.cs @@ -108,7 +108,8 @@ public static class AetheriaDaemonZoneBodyGenerator ParentOrbitKey = planet.Parent == null ? "" : orbitKeys[nodeIndices[planet.Parent]], FixedPosition = new AetheriaVector2 { X = planet.FixedPosition.x, Y = planet.FixedPosition.y }, Distance = planet.Distance, - Phase = planet.Phase + Phase = planet.Phase, + Period = planet.Distance }).ToArray(); var bodies = new List(); diff --git a/Aetheria.State.Daemon/Program.cs b/Aetheria.State.Daemon/Program.cs index 827f8d0c3..279010e3a 100644 --- a/Aetheria.State.Daemon/Program.cs +++ b/Aetheria.State.Daemon/Program.cs @@ -2830,6 +2830,7 @@ static AetheriaRuntimeOrbitSnapshotCommit ToRuntimeOrbit(AetheriaOrbitSnapshot o ParentOrbitKey = orbit.ParentOrbitKey ?? "", Distance = orbit.Distance, Phase = orbit.Phase, + Period = orbit.Period, FixedPositionX = orbit.FixedPosition?.X ?? 0, FixedPositionY = orbit.FixedPosition?.Y ?? 0 }; diff --git a/Aetheria.State/Documents/AetheriaRuntimeStateDocuments.cs b/Aetheria.State/Documents/AetheriaRuntimeStateDocuments.cs index 59d71d0fa..03660f43f 100644 --- a/Aetheria.State/Documents/AetheriaRuntimeStateDocuments.cs +++ b/Aetheria.State/Documents/AetheriaRuntimeStateDocuments.cs @@ -341,6 +341,9 @@ public sealed class AetheriaOrbitSnapshot [Key(4)] public AetheriaVector2 FixedPosition { get; set; } = new(); + + [Key(5)] + public double Period { get; set; } } [MessagePackObject] diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs index 526e70f42..671fa4be9 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs @@ -2077,7 +2077,7 @@ namespace GameCult.Aetheria.State.Verse towing.ChildEntityIndices = children; station.PositionX = command.PositionX; station.PositionZ = command.PositionZ; var zone = run.Zones.First(value => value.ZoneIndex == actorZone); var orbitKey = $"tow:{command.CommandId}"; - zone.Orbits = (zone.Orbits ?? Array.Empty()).Concat(new[] { new AetheriaRuntimeOrbitSnapshotCommit { OrbitKey = orbitKey, ParentOrbitKey = command.SubjectKey, Distance = command.ScalarValue, FixedPositionX = command.PositionX, FixedPositionY = command.PositionZ } }).ToArray(); + zone.Orbits = (zone.Orbits ?? Array.Empty()).Concat(new[] { new AetheriaRuntimeOrbitSnapshotCommit { OrbitKey = orbitKey, ParentOrbitKey = command.SubjectKey, Distance = command.ScalarValue, Period = Math.Abs(command.ScalarValue), FixedPositionX = command.PositionX, FixedPositionY = command.PositionZ } }).ToArray(); station.OrbitKey = orbitKey; return true; } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs index ca5b704dd..ef2a38900 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs @@ -82,6 +82,7 @@ namespace GameCult.Aetheria.State.Verse catalog, frameId, deltaSeconds); + AetheriaRuntimeOrbitSimulation.StepZone(zone, entities, deltaSeconds); AetheriaRuntimeFlightSimulation.Step( entities, intents?.Movements, diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeOrbitSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeOrbitSimulation.cs new file mode 100644 index 000000000..4d2a7a999 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeOrbitSimulation.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +#nullable enable + +namespace GameCult.Aetheria.State.Verse +{ + /// + /// Advances daemon-owned orbital phase, then projects the same canonical + /// orbit graph into the physical pose and velocity consumed by Ymir and Eve. + /// Period-zero orbits remain fixed compatibility orbits. + /// + public static class AetheriaRuntimeOrbitSimulation + { + public static void StepZone( + AetheriaRuntimeZoneSnapshotCommit? zone, + IReadOnlyList? entities, + double deltaSeconds) + { + if (zone == null || deltaSeconds <= 0) + return; + + foreach (var orbit in zone.Orbits ?? Array.Empty()) + { + if (orbit == null || orbit.Period <= 0.01) + continue; + orbit.Phase = Fraction(orbit.Phase + deltaSeconds / orbit.Period); + } + + var positions = AetheriaRuntimeOrbitQueries.BuildPositions(zone); + foreach (var entity in entities ?? Array.Empty()) + { + if (entity == null || string.IsNullOrWhiteSpace(entity.OrbitKey) || + !positions.TryGetValue(entity.OrbitKey, out var position)) + continue; + + var previousX = entity.PositionX; + var previousZ = entity.PositionZ; + entity.PositionX = position.x; + entity.PositionZ = position.z; + entity.VelocityX = (position.x - previousX) / deltaSeconds; + entity.VelocityY = (position.z - previousZ) / deltaSeconds; + } + } + + private static double Fraction(double value) => value - Math.Floor(value); + } +} diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeOrbitSimulation.cs.meta b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeOrbitSimulation.cs.meta new file mode 100644 index 000000000..6e9bfff79 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeOrbitSimulation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e7b6a4d9f52b49ea924ad2b9728a5d11 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs index 973ee26a6..12a1244f2 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs @@ -779,6 +779,9 @@ namespace GameCult.Aetheria.State.Verse [Key(7)] public string ParentOrbitKey { get; set; } = ""; + + [Key(8)] + public double Period { get; set; } } [MessagePackObject] diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 3c56e05ec..77c6c5225 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -1149,6 +1149,11 @@ the Terminus proof arena cannot award completion. orbit graph before persistence and deterministically distributes generated non-player ships through the fossil half-zone volume. The controlled starter alone enters at the origin; generic clients do not repair spawn positions. +- Orbital motion: each generated orbit carries the fossil + `OrbitPeriod(distance) = distance` result. Every daemon fixed step advances + canonical phase, resolves the shared parent graph, and writes orbital entity + pose and velocity before Ymir. Bodies and Eve read that same advanced graph; + period-zero compatibility orbits remain fixed. - Derived state: wormhole exits derive from adjacency; generic Eve maps, cameras, scene objects, fog, and HUD state lower the persisted run. - Forbidden writers: Unity generators, menu callbacks, scene materializers, and @@ -1160,8 +1165,9 @@ the Terminus proof arena cannot award completion. operation is dead. Celestial-only tutorial graphs are not playable runs. - Verification layer: focused smokes prove deterministic population, resolved orbital references and poses, distributed non-player spawns, - station/turret/agent presence, loadout provenance, all 64 persisted zones, - canonical starter identity, discovery, and adjacency. + fixed-step orbit phase/pose/velocity through Ymir, station/turret/agent + presence, loadout provenance, all 64 persisted zones, canonical starter + identity, discovery, and adjacency. ### Daemon Generated Zone Body Ownership diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index 9a6303f25..ccb9d9721 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -15,7 +15,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. | Organ | Original authority/evidence | Target owner | Eve contract | Runtime lowering | Current status | Required proof | |---|---|---|---|---|---|---| -| Run/session state | `ServerShared`, `ActionGameManager` | Aetheria daemon/CultCache | provider/session advertisement plus run lifecycle bindings | all clients | active/failed lifecycle is daemon-owned and restart-stable: controlled-entity destruction commits the fossil cause, terminal frame, one `run.failed` fact, releases control, rejects later gameplay commands, and freezes the world; Eve receives terminal presentation/input levers without becoming an owner. Terminus keeps persistent requested simulation rate distinct from effective rate: compressed batches inspect authoritative facts after each fixed step, stop at the causal damage/destruction/cargo/thermal/docking/weapon/wormhole/run event, pause effectively without erasing the request, and project the exact cause and executed-step count through Eve. Docked, travelling, fighting, mining, looting, and refitting remain derived world conditions rather than counterfeit durable phases. The distinct tutorial is now daemon-owned and selectable: authored 64-zone topology, bodies, post-body station/turret/agent population, resolved orbital placement, deterministic half-zone NPC distribution, starter entry ship, loadout receipts, discovery, and canonical persistence feed an Aetheria-mode session. New Game submits its Eve operation and waits for the new tutorial sector-map publication. Terminus preserves `TutorialPassed` and cannot impersonate completion | dynamic orbit-period simulation; source-backed tutorial completion rule (none survived in the fossil); replace the post-tutorial Terminus fallback with the authored regular-sector generator; full-daemon death/restart witness, broader attention taxonomy, and multi-client convergence | +| Run/session state | `ServerShared`, `ActionGameManager` | Aetheria daemon/CultCache | provider/session advertisement plus run lifecycle bindings | all clients | active/failed lifecycle is daemon-owned and restart-stable: controlled-entity destruction commits the fossil cause, terminal frame, one `run.failed` fact, releases control, rejects later gameplay commands, and freezes the world; Eve receives terminal presentation/input levers without becoming an owner. Terminus keeps persistent requested simulation rate distinct from effective rate: compressed batches inspect authoritative facts after each fixed step, stop at the causal damage/destruction/cargo/thermal/docking/weapon/wormhole/run event, pause effectively without erasing the request, and project the exact cause and executed-step count through Eve. Docked, travelling, fighting, mining, looting, and refitting remain derived world conditions rather than counterfeit durable phases. The distinct tutorial is now daemon-owned and selectable: authored 64-zone topology, bodies, post-body station/turret/agent population, resolved orbital placement, deterministic half-zone NPC distribution, starter entry ship, loadout receipts, discovery, and canonical persistence feed an Aetheria-mode session. Generated orbit facts carry the fossil distance-derived period; daemon fixed steps advance phase and project the shared graph into orbital pose/velocity before Ymir while Eve and body queries observe the same graph. New Game submits its Eve operation and waits for the new tutorial sector-map publication. Terminus preserves `TutorialPassed` and cannot impersonate completion | source-backed tutorial completion rule (none survived in the fossil); replace the post-tutorial Terminus fallback with the authored regular-sector generator; full-daemon death/restart witness, broader attention taxonomy, and multi-client convergence | | Entity identity/loadout | `ServerShared/Entity*` | daemon | typed entity and inventory surfaces | EveUnity/Electron | daemon-owned hull identity, exact installed placement/rotation and instance state, cargo stacks, weapon membership/held state, equipment wear, executable behavior state, weapon chronology, active-effect state, and loadout-generation provenance survive a hard CultCache close/reopen through the durable latest-frame checkpoint. An advertised generic Eve equip operation now translates into the typed daemon transaction before that checkpoint; its accepted placement survives restart and its consumed station-cargo source does not resurrect. Generic Eve rebuilds weapon and scalar thermostat controls from that restored truth; legacy per-entity documents are bootstrap inputs only when no live frame exists | live client refit witness and multi-client convergence | | Loadout generation | map/faction availability, item cost, hull hardpoints and role constraints | daemon using canonical galaxy, faction knowledge/economy and typed catalog | generated loadout plus provenance/availability facts | Eve inspection and refit surfaces | daemon now uses the fossil candidate filter and seeded weighted selection: manufacturer must be present and allied, ally weight decays by home-zone graph distance, price uses the authored exponent, and hardpoints require matching semantic type, rotated footprint containment, and controller role. Prelude generation retains the fossil exception that allied catalog manufacturers need not own one of the six tutorial home zones; unknown manufacturers remain zero-weight. The April 2021 catalog fossil restores the distinct common `Longinus`, rare AetherDrive-compatible `LonginusX`, and `Djinni` rows with their original IDs, shapes, hardpoints, prices, drag, and prefabs, plus missing Thruster rows required to fill their authored mounts; typed `rarity:rare` tags apply a 0.05 generation multiplier to `LonginusX` and AetherDrive equipment; the generator owns one mutable CultMath stream, fixing the readonly-struct defensive-copy bug that restarted every weighted draw; placement rotation survives durable state and reconnect; generation fills the largest compatible footprint before economic weighting; cargo/capacitor plus station docking equipment must fit remaining hull space; stations pack faction-available inventory largest-first; ordinary ships begin without invented scenario cargo; every generated entity persists a source/selection receipt that reaches Eve as `loadout.item` semantics | multi-zone generated-world parity and exact root-to-zone stream sequencing against the fossil | | Flight intent | `Ship`, `Thruster`, `AetherDrive`, `VelocityConversion`, `VelocityLimit`, input paths | daemon actuator simulation + Ymir integration | analog local helm/look/tractor plus actuator state | generic Eve input and scene lowerers | direct faction-speed velocity ownership is deleted; daemon persists local strafe/forward helm and desired look, allocates ordinary directional thruster banks by authored rotation, derives torque from hull/item placement, compensates lateral torque, gates execution through the shared energy ledger, deposits equipment-cell heat, publishes plume visibility and actuator state, applies hull drag, then runs operational velocity conversion with the fossil exponential damp equation and clamps the result through evaluated velocity limits before giving velocity/direction to Ymir. The evaluated limit remains in durable behavior state for reconnect and Eve inspection. Autonomous tasks translate world travel into the same local helm axes and issue look commands instead of mutating heading. AetherDrive rotor/coupling simulation is additive and explicitly non-default: common `Longinus` and `Djinni` hulls use ordinary thrusters; the rare `LonginusX` replaces those mounts with the single rare `Traction` AetherDrive path | hardpoint-transform direction parity, exact cross-equipment behavior execution ordering, CultMath/float32 parity harness, live production-frequency evidence, generic thrust/turn feedback lowering, and live handling screenshots | diff --git a/docs/renderless-aetheria-architecture.md b/docs/renderless-aetheria-architecture.md index 5c652b4a4..ec3b199e4 100644 --- a/docs/renderless-aetheria-architecture.md +++ b/docs/renderless-aetheria-architecture.md @@ -152,6 +152,10 @@ zone with the fossil station-count curve, Lagrange station orbits, paired defensive turrets, and faction ships. The entrance additionally receives the controlled starter ship. Zone adjacency is the wormhole truth; exits remain a derived render/interaction query rather than counterfeit wormhole entities. +Generated non-player ships are distributed through the fossil half-zone volume. +Generated orbits carry the authored distance-derived period; each fixed daemon +step advances canonical phase and projects orbital entity pose and velocity +before Ymir. Body queries and Eve lower the same orbit graph. New Game now submits its advertised Eve operation, waits for a newly published daemon sector map, and selects the persisted 64-zone tutorial while