From 4ee0628a5a44b9c3d120563685b1560bbb611801 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 16 Jun 2026 17:19:58 +0100 Subject: [PATCH] Own Continue current entity by typed state key --- .voidbot/state/aetheria.cc | Bin 187247 -> 188419 bytes Aetheria.State.Smoke/Program.cs | 12 +++-- Aetheria.State.Unity.Smoke/Program.cs | 19 ++++--- Aetheria.State.Verify/Program.cs | 19 +++++++ .../AetheriaRuntimeCommitLogApplier.cs | 13 +++++ .../AetheriaRuntimeStateDocuments.cs | 4 ++ Aetheria.State/README.md | 3 ++ Assets/Scripts/Gameplay/ActionGameManager.cs | 50 +++++++++++++++--- .../Runtime/AetheriaRuntimeCatalogSnapshot.cs | 3 ++ .../Runtime/AetheriaRuntimeCatalogStore.cs | 4 +- .../AetheriaRuntimeStateCommitDocument.cs | 3 ++ docs/aetheria-perfect-machine-map.md | 6 ++- 12 files changed, 114 insertions(+), 22 deletions(-) diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index 47052ae88e6e6874f2e96896dc898e8b7452a7cd..9bd61e2bdd4c524e4cc01ff96b4e709d3d033c4f 100644 GIT binary patch delta 1129 zcmZux&ubGw6lS-f*cN)KNDtzG*KA1AlGcg`ZMBwy*ieK9dzj2llA*gZ>&$HGdI?g* zgCg1-7DNw)`WsO^*rR&TYg;^({s|t$qc`8|X6vsW!Y*Ild*6HC``&(kKeYC7=Bw23kwXN$ z^N>1Xl~dXMQNP%6r+XNZRB0h80*cUcQJrxY=@vzSha)OcS_ai4q@#ek5Ke@25tPj% zF0}c>KwN1V5)A>$0~CtT>xC!8!_41XtA-pYjWvagRm3TEI|@yweV$L+oTm}OD&b9f zL=7R)-;-pGp3X9Bg3~m6&afe-5D|WWHLEiZMmGt}4Ji`biwe&)i5Uk0OqxfvG9!DyE?p`Omygx8 zkV@=AIN@{@s3j zscuatJWETa7}%ez1cGsmZ~*cWSgS}mf}T=`SO~&J&!>k76n|T=PYzcWOO>hKb(YF; zvEMp&?oXt)sc}dd|o9N;3Q6dlP=H6ws?Dg!`j;4u-neSLGA8N-)Qf= qCyL2=$LrhnhYTtevkyU-LFE+6?bZpO$/1" && @@ -735,12 +737,12 @@ try run.FactionRelationships[0].Standing == 3 && zone?.EntityKeys.Length == 1 && zone.Orbits.Length == 1 && - zone.Orbits[0].OrbitId == "aetheria.orbit:legacy:smoke:orbit" && - zone.Orbits[0].ParentId == "aetheria.orbit:legacy:smoke:parent-orbit" && + zone.Orbits[0].OrbitKey == "aetheria.orbit:legacy:smoke:orbit" && + zone.Orbits[0].ParentOrbitKey == "aetheria.orbit:legacy:smoke:parent-orbit" && zone.Orbits[0].FixedPosition.X == 5.0 && zone.Bodies.Length == 1 && - zone.Bodies[0].BodyId == "aetheria.body:legacy:smoke:body" && - zone.Bodies[0].OrbitId == "aetheria.orbit:legacy:smoke:orbit" && + zone.Bodies[0].BodyKey == "aetheria.body:legacy:smoke:body" && + zone.Bodies[0].OrbitKey == "aetheria.orbit:legacy:smoke:orbit" && zone.Bodies[0].Kind == "asteroid_belt" && zone.Bodies[0].Resources.Length == 1 && zone.Bodies[0].Resources[0].ItemKey == "aetheria.item_definition:legacy:smoke:ore" && @@ -884,6 +886,7 @@ try packageRuns.Count != 1 || packageRuns[0].RunId != "smoke-run" || packageRuns[0].GenerationSeed != 424242 || + packageRuns[0].CurrentEntityKey != "global:aetheria.run_state.smoke-run.zone.0.entity.0.v1" || packageRuns[0].ZoneKeys.Count != 1 || packageRuns[0].ActionBarBindings.Count != 2 || packageRuns[0].ActionBarBindings[1].TargetKey != "aetheria.item_definition:legacy:smoke:weapon" || @@ -894,12 +897,12 @@ try packageZones[0].Name != "Unity Smoke Zone" || packageZones[0].EntityKeys.Count != 1 || packageZones[0].Orbits.Count != 1 || - packageZones[0].Orbits[0].OrbitId != "aetheria.orbit:legacy:smoke:orbit" || - packageZones[0].Orbits[0].ParentId != "aetheria.orbit:legacy:smoke:parent-orbit" || + packageZones[0].Orbits[0].OrbitKey != "aetheria.orbit:legacy:smoke:orbit" || + packageZones[0].Orbits[0].ParentOrbitKey != "aetheria.orbit:legacy:smoke:parent-orbit" || packageZones[0].Orbits[0].FixedPositionX != 5.0 || packageZones[0].Bodies.Count != 1 || - packageZones[0].Bodies[0].BodyId != "aetheria.body:legacy:smoke:body" || - packageZones[0].Bodies[0].OrbitId != "aetheria.orbit:legacy:smoke:orbit" || + packageZones[0].Bodies[0].BodyKey != "aetheria.body:legacy:smoke:body" || + packageZones[0].Bodies[0].OrbitKey != "aetheria.orbit:legacy:smoke:orbit" || packageZones[0].Bodies[0].ResourceCount != 1 || packageZones[0].Bodies[0].AsteroidCount != 1 || packageZones[0].Bodies[0].DamagedAsteroidCount != 1 || diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index f7258cb58..17e531c77 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -1904,6 +1904,8 @@ static void RequireMainMenuContinueRunState(string root) "RestoreEntityGraphFromTypedRun(continuingRun)", "ReadEntitySnapshots(RuntimeStateFilePath)", "entity.RecordKey", + "run.CurrentEntityKey", + "ResolveCurrentEntityRecordKey(run, zoneEntityKeyPrefix)", "ReplaceZoneEntitiesFromTypedSnapshots", "Zone.Agents.Clear()", "FlattenEntityGraph(Zone)", @@ -1937,6 +1939,23 @@ static void RequireMainMenuContinueRunState(string root) string.Join(", ", missingGameplaySymbols)); } + var forbiddenGameplaySymbols = new[] + { + "if (run == null ||\r\n run.CurrentZoneIndex < 0 ||\r\n run.CurrentZoneEntityIndex < 0)", + "var currentEntityKey = $\"{zoneEntityKeyPrefix}{run.CurrentZoneEntityIndex}.v1\"" + }; + + var forbiddenGameplayHits = forbiddenGameplaySymbols + .Where(symbol => actionGameManager.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + + if (forbiddenGameplayHits.Length > 0) + { + throw new InvalidOperationException( + "ActionGameManager still reconstructs Continue current-entity ownership from integer slot state: " + + string.Join(", ", forbiddenGameplayHits)); + } + var requiredPackageSymbols = new[] { "public string RecordKey", diff --git a/Aetheria.State/AetheriaRuntimeCommitLogApplier.cs b/Aetheria.State/AetheriaRuntimeCommitLogApplier.cs index 9ba45d730..8314ab535 100644 --- a/Aetheria.State/AetheriaRuntimeCommitLogApplier.cs +++ b/Aetheria.State/AetheriaRuntimeCommitLogApplier.cs @@ -282,9 +282,22 @@ public static class AetheriaRuntimeCommitLogApplier if (zoneKeys.Count > 0) run.ZoneKeys = zoneKeys.ToArray(); + run.CurrentEntityKey = string.IsNullOrWhiteSpace(checkpoint.CurrentEntityKey) + ? LegacyCurrentEntityKey(run.RunId, checkpoint.CurrentZoneIndex, checkpoint.CurrentZoneEntityIndex) + : checkpoint.CurrentEntityKey; await node.PutRunStateAsync(RunKey(run.RunId), run).ConfigureAwait(false); } + private static string LegacyCurrentEntityKey(string runId, int zoneIndex, int entityIndex) + { + if (string.IsNullOrWhiteSpace(runId) || zoneIndex < 0 || entityIndex < 0) + { + return ""; + } + + return EntityKey(runId, zoneIndex, entityIndex).ToString(); + } + private static AetheriaDroppedPickupSnapshot[] ToDroppedPickups( IReadOnlyList? pickups) { diff --git a/Aetheria.State/Documents/AetheriaRuntimeStateDocuments.cs b/Aetheria.State/Documents/AetheriaRuntimeStateDocuments.cs index 8c8c95da0..770370c12 100644 --- a/Aetheria.State/Documents/AetheriaRuntimeStateDocuments.cs +++ b/Aetheria.State/Documents/AetheriaRuntimeStateDocuments.cs @@ -234,6 +234,10 @@ public sealed class AetheriaRunState [Key(11)] public uint GenerationSeed { get; set; } + + [Key(12)] + [CultReference(typeof(AetheriaEntitySnapshot))] + public string CurrentEntityKey { get; set; } = ""; } [CultDocument("aetheria.zone_state", "aetheria.zone_state.v1")] diff --git a/Aetheria.State/README.md b/Aetheria.State/README.md index eb7c2e015..9a63eb8ac 100644 --- a/Aetheria.State/README.md +++ b/Aetheria.State/README.md @@ -325,6 +325,9 @@ smoke proves a typed run can reference a typed zone, the zone can preserve orbit/body rows and reference typed entity snapshots, and entity snapshots can preserve equipment slots, weapon groups, and simulation stat grids without reviving `PlayerSettings.msgpack`, `.loadout`, or `.zone` serialization. +The run document also carries `CurrentEntityKey`, so Continue restore binds the +saved player entity by exact typed record identity instead of reconstructing it +from a transient entity-slot index. `Aetheria.State.Verify` opens a materialized state file and checks that the typed migration ledger matches the actual item, corporation, and name-file diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 0cf9629ac..20a80791b 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -601,14 +601,17 @@ public class ActionGameManager : MonoBehaviour private AetheriaRuntimeRunCheckpointCommit ProjectRunCheckpoint() { var entityGraph = FlattenEntityGraph(Zone); + var runId = IsTutorial ? "tutorial" : "local"; + var currentZoneIndex = ZoneIndex(Zone?.GalaxyZone); return new AetheriaRuntimeRunCheckpointCommit { - RunId = IsTutorial ? "tutorial" : "local", + RunId = runId, IsTutorial = IsTutorial, EntranceZoneIndex = ZoneIndex(CurrentGalaxy?.Entrance), ExitZoneIndex = ZoneIndex(CurrentGalaxy?.Exit), - CurrentZoneIndex = ZoneIndex(Zone?.GalaxyZone), + CurrentZoneIndex = currentZoneIndex, CurrentZoneEntityIndex = IndexOfEntity(entityGraph, CurrentEntity), + CurrentEntityKey = CurrentEntityRecordKey(runId, currentZoneIndex, entityGraph, CurrentEntity), GenerationSeed = CurrentGalaxy?.GenerationSeed ?? 0, DiscoveredZoneIndices = CurrentGalaxy?.DiscoveredZones .Select(ZoneIndex) @@ -2494,15 +2497,19 @@ public class ActionGameManager : MonoBehaviour private void RestoreEntityGraphFromTypedRun(AetheriaRuntimeRunStateSnapshot run) { - if (run == null || - run.CurrentZoneIndex < 0 || - run.CurrentZoneEntityIndex < 0) + if (run == null || run.CurrentZoneIndex < 0) { return; } var zoneEntityKeyPrefix = $"global:aetheria.run_state.{run.RunId}.zone.{run.CurrentZoneIndex}.entity."; - var currentEntityKey = $"{zoneEntityKeyPrefix}{run.CurrentZoneEntityIndex}.v1"; + var currentEntityKey = ResolveCurrentEntityRecordKey(run, zoneEntityKeyPrefix); + if (string.IsNullOrWhiteSpace(currentEntityKey)) + { + Debug.LogWarning($"Typed run {run.RunId} does not identify a current entity for restored zone {zoneEntityKeyPrefix}."); + return; + } + AetheriaRuntimeEntitySnapshot[] entitySnapshots; try { @@ -2526,6 +2533,37 @@ public class ActionGameManager : MonoBehaviour ReplaceZoneEntitiesFromTypedSnapshots(entitySnapshots, currentEntityKey); } + private static string CurrentEntityRecordKey( + string runId, + int currentZoneIndex, + IReadOnlyList entityGraph, + Entity currentEntity) + { + if (string.IsNullOrWhiteSpace(runId) || currentZoneIndex < 0 || currentEntity == null) + { + return ""; + } + + var currentZoneEntityIndex = IndexOfEntity(entityGraph, currentEntity); + return currentZoneEntityIndex < 0 + ? "" + : $"global:aetheria.run_state.{runId}.zone.{currentZoneIndex}.entity.{currentZoneEntityIndex}.v1"; + } + + private static string ResolveCurrentEntityRecordKey( + AetheriaRuntimeRunStateSnapshot run, + string zoneEntityKeyPrefix) + { + if (!string.IsNullOrWhiteSpace(run.CurrentEntityKey)) + { + return run.CurrentEntityKey; + } + + return run.CurrentZoneEntityIndex < 0 + ? "" + : $"{zoneEntityKeyPrefix}{run.CurrentZoneEntityIndex}.v1"; + } + private void ReplaceZoneEntitiesFromTypedSnapshots( IReadOnlyList entitySnapshots, string currentEntityKey) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs index df0865a7a..c5a85ad1b 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogSnapshot.cs @@ -691,6 +691,7 @@ namespace GameCult.Aetheria.State.Unity int exitZoneIndex, int currentZoneIndex, int currentZoneEntityIndex, + string currentEntityKey, IReadOnlyList discoveredZoneIndices, IReadOnlyList zoneKeys, IReadOnlyList actionBarBindings, @@ -704,6 +705,7 @@ namespace GameCult.Aetheria.State.Unity ExitZoneIndex = exitZoneIndex; CurrentZoneIndex = currentZoneIndex; CurrentZoneEntityIndex = currentZoneEntityIndex; + CurrentEntityKey = currentEntityKey; DiscoveredZoneIndices = discoveredZoneIndices; ZoneKeys = zoneKeys; ActionBarBindings = actionBarBindings; @@ -718,6 +720,7 @@ namespace GameCult.Aetheria.State.Unity public int ExitZoneIndex { get; } public int CurrentZoneIndex { get; } public int CurrentZoneEntityIndex { get; } + public string CurrentEntityKey { get; } public IReadOnlyList DiscoveredZoneIndices { get; } public IReadOnlyList ZoneKeys { get; } public IReadOnlyList ActionBarBindings { get; } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs index 397b8d596..e47eaea05 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeCatalogStore.cs @@ -463,7 +463,8 @@ namespace GameCult.Aetheria.State.Unity var factionRelationships = ReadFieldFactionRelationships(ref reader, fields, 9); var updatedAtUtc = ReadFieldString(ref reader, fields, 10); var generationSeed = ReadFieldUInt32(ref reader, fields, 11); - SkipRemaining(ref reader, fields, 12); + var currentEntityKey = ReadFieldString(ref reader, fields, 12); + SkipRemaining(ref reader, fields, 13); return new AetheriaRuntimeRunStateSnapshot( runId, isTutorial, @@ -471,6 +472,7 @@ namespace GameCult.Aetheria.State.Unity exitZoneIndex, currentZoneIndex, currentZoneEntityIndex, + currentEntityKey, discoveredZoneIndices, zoneKeys, actionBarBindings, diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateCommitDocument.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateCommitDocument.cs index 3fcecec4b..fb84faafa 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateCommitDocument.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateCommitDocument.cs @@ -247,6 +247,9 @@ namespace GameCult.Aetheria.State.Unity [Key(10)] public uint GenerationSeed { get; set; } + + [Key(11)] + public string CurrentEntityKey { get; set; } = ""; } [MessagePackObject] diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index c5367460a..8f1a6503e 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -992,8 +992,10 @@ First Aetheria surfaces to publish: hull-conductivity axes, then reconnects target/contact rows among restored entities, restores child/docking relationships from typed child keys and docking-bay assignments, restores typed weapon and behavior runtime rows - into live behavior instances, and binds the saved current entity as the - player ship or docked current ship. + into live behavior instances, and binds the saved current entity by + `AetheriaRunState.CurrentEntityKey` so Continue restore follows exact typed + entity identity instead of reconstructing the player ship from an integer + slot. - Done: project run checkpoint entity snapshots from the flattened live entity graph, not only `Zone.Entities`, so docked child ships can receive typed entity records and stable child/docking references instead of