From 0471cb690fb617223bde65fe87fb37d0578d6c3e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 16 Jun 2026 14:22:52 +0100 Subject: [PATCH] Move body and orbit key ownership into zone runtime --- .voidbot/state/aetheria.cc | Bin 179239 -> 181977 bytes Aetheria.State.Verify/Program.cs | 29 ++++++++- Aetheria.State/README.md | 3 + Assets/Scripts/Gameplay/ActionGameManager.cs | 61 ++++++++++--------- Assets/Scripts/ServerShared/Zone.cs | 36 +++++++++++ Assets/Scripts/UI/MainMenu.cs | 4 +- docs/aetheria-perfect-machine-map.md | 4 +- 7 files changed, 105 insertions(+), 32 deletions(-) diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index 01175fe2c7069c652c6a9bdbca9a4e4e792ca2de..39c0ed70722d182c354fbf479226826065facc1a 100644 GIT binary patch delta 2813 zcmbuBUu+ab9LL=SEq~;nl=i`r3=uIv?|P;DZ4>c6$LOG3i5ZcXodN zzTeNxh1*MRon1P2-hQyJe@k!w)FHmc*L2A7!4&75=)Z**zqw9ezXSkuH9(F$03p3Xi!MP8Flv(AAaG`MZ;##kmaWk znU0tsNR}hwW&=VLBw}8|4iP98`enKL%jX@{kxF|dWXNaXIN>^v07J@|R84+9bFlB1 zO`a^4MHWNY6S`O(zeqehNg2{F~LjV{VASjCEcRgEKdF2=o&gmRW8JPP!{;IF4YYI{LM>x{^ox7|11zp&pN* zfR000t&3tA1#D8U^;-(-!Q&*9Jvx_MBBy$nxj?K`f~G-pl8!a%$$yGN$76hyl*CW> zy>{{=PD+>boNA|6SSuEEde0F~OEghHk-8!&pn9~jdUslLwg~8x85<|B#uO%E)LRUN_ETmGaS~_09TvAWZ2!@t0j12J`LF1g>8@{_@e=@mOV1ognyIN zMTjHeF~A`_XRQcc_JUko|wK)zhor7h8gSyx;1R<&Wc-GP4YN7hg>Xix2`my zOCy&iTJq?S)I@@?$?2jIj$;W_(V7N`F|}^kUcDLKdr+u`5cWA(wQR_ivABqf5EqU( z!_Ugi1F?)@b!H?f24MiP@0!3Gng-#>r6y;r6%9wA#vzheOz0nAA3=lIHx$j8!qYjK zG}HXeWRE4~G#8;Mj-yEPErS|PiZS(FjpIQR`ydX;5gbBno=ad4CF$37C8?R6c89t; zVy&EqqQSw@`t3lw!!W#lC1~6h>L@H; z$L2zBf1zOTtS&ZCYw&zg7pozga#~%xWIx{4*k;+B-IZQJxA*ERsCshF{x-dXZda== h+i#_dc9?sr`sT7-NgwVs7uwp3U)Wa`XP)jD`vAhaxmYSW@c(5^*`&Wz>E?(yC8zVm(GIp@>;s^`Be=Vxg3 z!OoVWo$Vd5mZKem4@pgKiQZkqT3ZhlFjY2I`M<8UHTSFRFrEEzyRkfKEGH*6kYl-T z_iC#>rnTS(e9nA#b(Zdg*fTF+BK4UJ^d>okGBn(WZp%|=nPdsB-IG~5R(HjU6pvr= zd0<&De!{Tefp40DN#Dih=*}h><(eaJz%BPOq2#COGa|!bP)QC$%Fo7?9un5QpQHQgj^V$; zfEQX&GRWqeA>%)X^L3VG0w$@#z=ymd2-YkZt3xkeZ@{WirhPbR zvuTWdgl7$s8;jEcH4M!6g-oor$N01g(Mri|VlSEWl1lgRVY9OCdUR_G*;Urof01i} z^U;vjJj10mkPe3e;eifi!HSwi^fDw_jPxf)hRHGW5M7;tx*8LQT-x?`;cGxm30l1%Tpv;o}v?b+@l5B zF#U>da!U)ews=Zyg;R2W7U*ILc;w%GRk*KjXsY !zoneSource.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + if (missingZoneSymbols.Length > 0) + { + throw new InvalidOperationException( + "Zone runtime body/orbit objects must own typed projection key surfaces: " + + string.Join(", ", missingZoneSymbols)); + } } static void RequireTypedFactionShellLinks(string root) diff --git a/Aetheria.State/README.md b/Aetheria.State/README.md index f706efeb1..a902d7366 100644 --- a/Aetheria.State/README.md +++ b/Aetheria.State/README.md @@ -125,6 +125,9 @@ deleted. Behavior-state runtime commits and readback snapshots carry typed body-key fields for resource scanner targets and mining tool asteroid belts; the old raw body ID commit/readback field names are deleted. Unity still parses those body keys into GUIDs only at the current `Zone` body runtime boundary. +`Zone`, `Planet`, `AsteroidBelt`, and `Orbit` now own the runtime +body/orbit key surfaces used for projection, and `ActionGameManager` no longer +formats body/orbit keys locally while checkpointing state. The package runtime catalog snapshot indexes items by canonical item key; Unity gameplay, HUD, inventory, trade, ship, and zone helper lookups use `ItemKey` directly instead of deriving `ItemId` and searching by legacy GUID. diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 38952938e..81a13ff21 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -354,9 +354,8 @@ public class ActionGameManager : MonoBehaviour if (string.IsNullOrWhiteSpace(bodyKey)) return Guid.Empty; - const string bodyPrefix = "aetheria.body:legacy:"; - var runtimeBodyId = bodyKey.StartsWith(bodyPrefix, StringComparison.OrdinalIgnoreCase) - ? bodyKey.Substring(bodyPrefix.Length) + var runtimeBodyId = bodyKey.StartsWith(Zone.BodyKeyPrefix, StringComparison.OrdinalIgnoreCase) + ? bodyKey.Substring(Zone.BodyKeyPrefix.Length) : bodyKey; return Guid.TryParse(runtimeBodyId, out var id) ? id : Guid.Empty; } @@ -620,7 +619,7 @@ public class ActionGameManager : MonoBehaviour EntranceZoneIndex = ZoneIndex(CurrentGalaxy?.Entrance), ExitZoneIndex = ZoneIndex(CurrentGalaxy?.Exit), CurrentZoneIndex = ZoneIndex(Zone?.GalaxyZone), - CurrentZoneEntityIndex = entityGraph.IndexOf(CurrentEntity), + CurrentZoneEntityIndex = IndexOfEntity(entityGraph, CurrentEntity), GenerationSeed = CurrentGalaxy?.GenerationSeed ?? 0, DiscoveredZoneIndices = CurrentGalaxy?.DiscoveredZones .Select(ZoneIndex) @@ -750,8 +749,8 @@ public class ActionGameManager : MonoBehaviour .OrderBy(orbit => orbit.ID) .Select(orbit => new AetheriaRuntimeOrbitSnapshotCommit { - OrbitKey = OrbitKey(orbit.ID), - ParentOrbitKey = OrbitKey(orbit.Parent), + OrbitKey = orbit.OrbitKey, + ParentOrbitKey = orbit.ParentOrbitKey, Distance = orbit.Distance, Phase = orbit.Phase, FixedPositionX = orbit.FixedPosition.x, @@ -776,10 +775,10 @@ public class ActionGameManager : MonoBehaviour { return new AetheriaRuntimeBodySnapshotCommit { - BodyKey = BodyKey(planet.ID), + BodyKey = planet.BodyKey, Kind = BodyKind(planet), Name = planet.Name, - OrbitKey = OrbitKey(planet.OrbitId), + OrbitKey = planet.OrbitKey, Mass = planet.Mass, Resources = planet.Resources? .OrderBy(pair => pair.Key) @@ -807,10 +806,10 @@ public class ActionGameManager : MonoBehaviour { return new AetheriaRuntimeBodySnapshotCommit { - BodyKey = BodyKey(belt.ID), + BodyKey = belt.BodyKey, Kind = "asteroid_belt", Name = belt.Name, - OrbitKey = OrbitKey(belt.Orbit), + OrbitKey = belt.OrbitKey, Mass = belt.Mass, Resources = belt.Resources? .OrderBy(pair => pair.Key) @@ -944,7 +943,7 @@ public class ActionGameManager : MonoBehaviour DirectionY = entity.Direction.y, VelocityX = entity.Velocity.x, VelocityY = entity.Velocity.y, - TargetEntityIndex = entity.Target?.Value == null ? -1 : entityGraph.IndexOf(entity.Target.Value), + TargetEntityIndex = entity.Target?.Value == null ? -1 : IndexOfEntity(entityGraph, entity.Target.Value), IsActive = entity.Active, HeatsinksEnabled = entity.HeatsinksEnabled, OverrideShutdown = entity.OverrideShutdown, @@ -965,7 +964,7 @@ public class ActionGameManager : MonoBehaviour VisibilitySourceCount = entity.VisibilitySources.Count, Contacts = ProjectEntityContacts(entityGraph, entity), ChildEntityIndices = entity.Children? - .Select(child => entityGraph.IndexOf(child)) + .Select(child => IndexOfEntity(entityGraph, child)) .Where(index => index >= 0) .ToArray() ?? Array.Empty(), WeaponGroups = entity.WeaponGroups? @@ -984,7 +983,7 @@ public class ActionGameManager : MonoBehaviour return entity.EntityInfoGathered .Select(contact => { - var targetIndex = entityGraph.IndexOf(contact.Key); + var targetIndex = IndexOfEntity(entityGraph, contact.Key); entity.EntityHostility.TryGetValue(contact.Key, out var hostile); return new AetheriaRuntimeEntityContactCommit { @@ -998,6 +997,20 @@ public class ActionGameManager : MonoBehaviour .ToArray(); } + private static int IndexOfEntity(IReadOnlyList entityGraph, Entity entity) + { + if (entityGraph == null || entity == null) + return -1; + + for (var index = 0; index < entityGraph.Count; index++) + { + if (ReferenceEquals(entityGraph[index], entity)) + return index; + } + + return -1; + } + private static AetheriaRuntimeCargoBayLoadoutCommit[] ProjectRuntimeCargoBays(IEnumerable bays) where TBay : EquippedCargoBay { @@ -1019,18 +1032,20 @@ public class ActionGameManager : MonoBehaviour private static AetheriaRuntimeBehaviorStateCommit[] ProjectBehaviorStates(Entity entity) { var states = new List(); + var zone = entity.Zone; for (var ownerIndex = 0; ownerIndex < entity.Equipment.Count; ownerIndex++) - states.AddRange(ProjectBehaviorStates("equipment", ownerIndex, entity.Equipment[ownerIndex].Behaviors)); + states.AddRange(ProjectBehaviorStates(zone, "equipment", ownerIndex, entity.Equipment[ownerIndex].Behaviors)); var activeConsumables = entity.ActiveConsumables; for (var ownerIndex = 0; ownerIndex < activeConsumables.Count; ownerIndex++) - states.AddRange(ProjectBehaviorStates("active_consumable", ownerIndex, activeConsumables[ownerIndex].Behaviors)); + states.AddRange(ProjectBehaviorStates(zone, "active_consumable", ownerIndex, activeConsumables[ownerIndex].Behaviors)); return states.ToArray(); } private static IEnumerable ProjectBehaviorStates( + Zone zone, string ownerKind, int ownerIndex, IReadOnlyList behaviors) @@ -1104,7 +1119,7 @@ public class ActionGameManager : MonoBehaviour { state = new AetheriaRuntimeBehaviorStateCommit { - ResourceScannerTargetBodyKey = BodyKey(resourceScanner.ScanTarget), + ResourceScannerTargetBodyKey = zone?.GetBodyKey(resourceScanner.ScanTarget) ?? "", ResourceScannerAsteroidIndex = resourceScanner.Asteroid, ResourceScannerScanTime = resourceScanner.ScanTime, ResourceScannerRange = resourceScanner.Range, @@ -1116,7 +1131,7 @@ public class ActionGameManager : MonoBehaviour { state = new AetheriaRuntimeBehaviorStateCommit { - MiningToolAsteroidBeltKey = BodyKey(miningTool.AsteroidBelt), + MiningToolAsteroidBeltKey = zone?.GetBodyKey(miningTool.AsteroidBelt) ?? "", MiningToolAsteroidIndex = miningTool.Asteroid, MiningToolRange = miningTool.Range }; @@ -1260,7 +1275,7 @@ public class ActionGameManager : MonoBehaviour if (weapon is LockWeapon lockWeapon) { state.LockProgress = lockWeapon.LockProgress; - state.LockTargetEntityIndex = lockWeapon.LockTarget == null ? -1 : entityGraph.IndexOf(lockWeapon.LockTarget); + state.LockTargetEntityIndex = lockWeapon.LockTarget == null ? -1 : IndexOfEntity(entityGraph, lockWeapon.LockTarget); } yield return state; @@ -1389,16 +1404,6 @@ public class ActionGameManager : MonoBehaviour .ToArray() ?? Array.Empty(); } - private static string OrbitKey(Guid id) - { - return id == Guid.Empty ? "" : $"aetheria.orbit:legacy:{id:D}"; - } - - private static string BodyKey(Guid id) - { - return id == Guid.Empty ? "" : $"aetheria.body:legacy:{id:D}"; - } - private static int ZoneIndex(GalaxyZone zone) { return CurrentGalaxy?.Zones == null || zone == null ? -1 : Array.IndexOf(CurrentGalaxy.Zones, zone); diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index 10a0291dd..a9eae6d53 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -16,6 +16,9 @@ using Random = Unity.Mathematics.Random; public class Zone { + public const string OrbitKeyPrefix = "aetheria.orbit:legacy:"; + public const string BodyKeyPrefix = "aetheria.body:legacy:"; + public Action Log; public ReactiveCollection Entities = new ReactiveCollection(); public Dictionary PlanetInstances = new Dictionary(); @@ -102,6 +105,27 @@ public class Zone return agent; } + public static string OrbitKey(Guid id) + { + return id == Guid.Empty ? "" : $"{OrbitKeyPrefix}{id:D}"; + } + + public static string BodyKey(Guid id) + { + return id == Guid.Empty ? "" : $"{BodyKeyPrefix}{id:D}"; + } + + public string GetBodyKey(Guid bodyId) + { + if (bodyId == Guid.Empty) + return ""; + if (PlanetInstances.TryGetValue(bodyId, out var planet)) + return planet.BodyKey; + if (AsteroidBelts.TryGetValue(bodyId, out var belt)) + return belt.BodyKey; + return BodyKey(bodyId); + } + public void Update(float deltaTime) { _time += deltaTime; @@ -367,8 +391,10 @@ public class Planet public Orbit Orbit; protected readonly PlanetSettings Settings; public Guid ID { get; } + public string BodyKey { get; } public string Name { get; } public Guid OrbitId { get; } + public string OrbitKey { get; } public float Mass { get; } public IReadOnlyDictionary Resources { get; } public float BodyRadiusMultiplier { get; } @@ -384,8 +410,10 @@ public class Planet Settings = settings; Orbit = orbit; ID = data.ID; + BodyKey = Zone.BodyKey(data.ID); Name = data.Name ?? ""; OrbitId = data.Orbit; + OrbitKey = Zone.OrbitKey(data.Orbit); Mass = data.Mass; Resources = data.Resources; BodyRadiusMultiplier = data.BodyRadiusMultiplier; @@ -472,8 +500,10 @@ public class AsteroidBelt { private readonly Asteroid[] _asteroids; public Guid ID { get; } + public string BodyKey { get; } public string Name { get; } public Guid Orbit { get; } + public string OrbitKey { get; } public float Mass { get; } public IReadOnlyDictionary Resources { get; } public float BodyRadiusMultiplier { get; } @@ -493,8 +523,10 @@ public class AsteroidBelt { _asteroids = data.Asteroids; ID = data.ID; + BodyKey = Zone.BodyKey(data.ID); Name = data.Name ?? ""; Orbit = data.Orbit; + OrbitKey = Zone.OrbitKey(data.Orbit); Mass = data.Mass; Resources = data.Resources; BodyRadiusMultiplier = data.BodyRadiusMultiplier; @@ -517,7 +549,9 @@ public class AsteroidBelt public class Orbit { public Guid ID { get; } + public string OrbitKey { get; } public Guid Parent { get; } + public string ParentOrbitKey { get; } public float Distance { get; } public float Phase { get; } public float2 FixedPosition { get; } @@ -535,7 +569,9 @@ public class Orbit public Orbit(PlanetSettings settings, OrbitConstructionData data) { ID = data.ID; + OrbitKey = Zone.OrbitKey(data.ID); Parent = data.Parent; + ParentOrbitKey = Zone.OrbitKey(data.Parent); Distance = data.Distance; Phase = data.Phase; FixedPosition = data.FixedPosition; diff --git a/Assets/Scripts/UI/MainMenu.cs b/Assets/Scripts/UI/MainMenu.cs index 5fd3c337e..bc02a5570 100644 --- a/Assets/Scripts/UI/MainMenu.cs +++ b/Assets/Scripts/UI/MainMenu.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using GameCult.Aetheria.State.Unity; @@ -209,7 +210,6 @@ public class MainMenu : MonoBehaviour ActionGameManager.IsTutorial = run.IsTutorial; ActionGameManager.ContinueRunState = run; var generationSeed = run.GenerationSeed == 0 ? NextGenerationSeed() : run.GenerationSeed; - var sectorSettings = run.IsTutorial ? Settings.TutorialGenerationSettings : Settings.SectorGenerationSettings; var backgroundSettings = run.IsTutorial ? Settings.TutorialBackgroundSettings : Settings.SectorBackgroundSettings; backgroundSettings.NoisePosition = generationSeed; @@ -227,7 +227,7 @@ public class MainMenu : MonoBehaviour setState, generationSeed) : new Galaxy( - sectorSettings, + Settings.SectorGenerationSettings, backgroundSettings, Settings.NameGeneratorSettings, ActionGameManager.RuntimeCatalog, diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index bd7bda02f..8ee503789 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -1774,7 +1774,9 @@ First Aetheria surfaces to publish: - `Aetheria.State.Verify` guards behavior body reference naming: resource-scanner and mining-tool runtime state surfaces use `BodyKey` fields; old `*BodyId` readback names and generic legacy reference parsers may not - return. + return. `Zone`, `Planet`, `AsteroidBelt`, and `Orbit` now own the runtime + body/orbit key surfaces consumed by `ActionGameManager` projection, so local + body/orbit key formatters may not return there either. - `Aetheria.State.Verify` guards temporary `Faction` shell links: geoname and boss-hull relationships use typed keys, not legacy GUID projection fields. - `Aetheria.State.Verify` guards temporary `Faction` identity: equality,