From 0f5befb056cad16d48146a2cc88a400847cff26e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 28 Jun 2026 10:23:14 +0100 Subject: [PATCH] Use reactive loadout snapshot projector --- Aetheria.State.Verify/Program.cs | 25 +++++++-- Assets/Scripts/UI/Menu/InventoryPanel.cs | 19 +++++-- .../Runtime/AetheriaClientState.cs | 12 ++++ ...AetheriaRuntimeLoadoutSnapshotProjector.cs | 56 ++++++++++++++++--- 4 files changed, 95 insertions(+), 17 deletions(-) diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 18418b602..f252aa5ef 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -7592,6 +7592,7 @@ static void RequireAetheriaManagedStateAccessorsCoverDomainDocuments(string root { "public AetheriaRuntimeDaemonFrameDocument LatestDaemonFrame()", "public AetheriaRuntimeDaemonSoaViewDocument LatestDaemonSoaView()", + "public AetheriaRuntimeReactiveLoadoutSnapshotProjector ReactiveLoadoutSnapshotProjector(", "public AetheriaRuntimeLoadoutTemplatesDocument LatestLoadoutTemplates()", "public AetheriaRuntimeStationRefitDocument LatestStationRefit()", "public AetheriaRuntimeZoneRenderDocument LatestZoneRender()", @@ -16333,8 +16334,10 @@ static void RequireInventoryLoadoutSaveRequestAuthority(string root) { "RequestLoadoutTemplateSave(Entity entity)", "TryResolveEntityRecordKey(entity, out var targetEntityKey)", - "AetheriaRuntimeLoadoutSnapshotProjector", - ".ProjectLoadoutTemplateAsync(client.State, targetEntityKey)", + "AetheriaRuntimeReactiveLoadoutSnapshotProjector _loadoutSnapshotProjector", + "ResolveLoadoutSnapshotProjector().ProjectLoadoutTemplate(targetEntityKey)", + ".ReactiveLoadoutSnapshotProjector()", + "_loadoutSnapshotProjector?.Dispose()", ".Ui.SaveLoadoutTemplateAsync(loadout, \"unity-inventory\")" }; var missingInventoryPanelSymbols = requiredInventoryPanelSymbols @@ -16347,19 +16350,23 @@ static void RequireInventoryLoadoutSaveRequestAuthority(string root) string.Join(", ", missingInventoryPanelSymbols)); } - if (inventoryPanel.Contains(".LoadoutTemplateAsync(", StringComparison.Ordinal)) + if (inventoryPanel.Contains(".LoadoutTemplateAsync(", StringComparison.Ordinal) || + inventoryPanel.Contains(".ProjectLoadoutTemplateAsync(client.State, targetEntityKey)", StringComparison.Ordinal)) { throw new InvalidOperationException( - "InventoryPanel still asks AetheriaClient for a document-specific loadout template helper instead of composing from managed typed state."); + "InventoryPanel still asks a one-shot compatibility helper for loadout templates instead of caching the managed reactive loadout projector."); } var requiredLoadoutSnapshotProjectorSymbols = new[] { "ProjectLoadoutTemplateAsync(", "AetheriaClientState state", - "state.Daemon.LatestFrame.LatestAsync()", + "public sealed class AetheriaRuntimeReactiveLoadoutSnapshotProjector", + "state.Daemon.LatestFrame.ReactiveAsync(options)", + "public AetheriaRuntimeLoadoutTemplateCommit ProjectLoadoutTemplate(string entityKey)", "ProjectLoadoutTemplate(", - "frame.Run ?? new AetheriaRuntimeRunCheckpointCommit()" + "frame.Run ?? new AetheriaRuntimeRunCheckpointCommit()", + "public void Dispose()" }; var missingLoadoutSnapshotProjectorSymbols = requiredLoadoutSnapshotProjectorSymbols .Where(symbol => !loadoutSnapshotProjector.Contains(symbol, StringComparison.Ordinal)) @@ -16371,6 +16378,12 @@ static void RequireInventoryLoadoutSaveRequestAuthority(string root) string.Join(", ", missingLoadoutSnapshotProjectorSymbols)); } + if (loadoutSnapshotProjector.Contains("state.Daemon.LatestFrame.LatestAsync()", StringComparison.Ordinal)) + { + throw new InvalidOperationException( + "Loadout template save payloads still perform one-shot daemon frame reads instead of using a reactive typed frame document."); + } + var forbiddenActionSymbols = new[] { "AetheriaRuntimeStateCommitLog.QueueLoadoutTemplate", diff --git a/Assets/Scripts/UI/Menu/InventoryPanel.cs b/Assets/Scripts/UI/Menu/InventoryPanel.cs index dcd9d9ba6..1784eaa33 100644 --- a/Assets/Scripts/UI/Menu/InventoryPanel.cs +++ b/Assets/Scripts/UI/Menu/InventoryPanel.cs @@ -108,6 +108,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler private CultMeshReactiveDocument _currentEntity; private CultMeshReactiveDocument _stationRefit; private AetheriaClientReactiveDockingState _reactiveDockingState; + private AetheriaRuntimeReactiveLoadoutSnapshotProjector _loadoutSnapshotProjector; private int _inventoryEntityIndex = -1; private CultMeshReactiveDocument _inventory; private AetheriaRuntimeStationRefitEntityOption[] _dropdownStationRefitEntities = @@ -1084,10 +1085,7 @@ private void Update() try { var client = ResolveClient(); - var loadout = AetheriaRuntimeLoadoutSnapshotProjector - .ProjectLoadoutTemplateAsync(client.State, targetEntityKey) - .GetAwaiter() - .GetResult(); + var loadout = ResolveLoadoutSnapshotProjector().ProjectLoadoutTemplate(targetEntityKey); if (loadout?.RootEntity == null || string.IsNullOrWhiteSpace(loadout.RootEntity.Hull?.ItemKey ?? "")) return; @@ -1497,6 +1495,7 @@ private void Update() _currentEntity?.Dispose(); _stationRefit?.Dispose(); _reactiveDockingState?.Dispose(); + _loadoutSnapshotProjector?.Dispose(); _observedDockingIndex?.Dispose(); _inventory?.Dispose(); _catalog = null; @@ -1504,6 +1503,7 @@ private void Update() _currentEntity = null; _stationRefit = null; _reactiveDockingState = null; + _loadoutSnapshotProjector = null; _observedDockingIndex = null; _inventory = null; _inventoryEntityIndex = -1; @@ -1548,6 +1548,17 @@ private void Update() return _stationRefit?.Current; } + private AetheriaRuntimeReactiveLoadoutSnapshotProjector ResolveLoadoutSnapshotProjector() + { + if (_loadoutSnapshotProjector != null) + return _loadoutSnapshotProjector; + + _loadoutSnapshotProjector = ResolveClient() + .Aetheria() + .ReactiveLoadoutSnapshotProjector(); + return _loadoutSnapshotProjector; + } + private AetheriaRuntimeInventoryDocument ResolveInventory(int entityIndex) { if (_inventory != null && _inventoryEntityIndex == entityIndex) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs index b0448cade..b397d1052 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs @@ -220,6 +220,18 @@ namespace GameCult.Aetheria.State.Verse return LatestDaemonSoaViewAsync().ConfigureAwait(false).GetAwaiter().GetResult(); } + public Task ReactiveLoadoutSnapshotProjectorAsync( + CultMeshReactiveDocumentOptions? options = null) + { + return AetheriaRuntimeReactiveLoadoutSnapshotProjector.CreateAsync(this, options); + } + + public AetheriaRuntimeReactiveLoadoutSnapshotProjector ReactiveLoadoutSnapshotProjector( + CultMeshReactiveDocumentOptions? options = null) + { + return ReactiveLoadoutSnapshotProjectorAsync(options).ConfigureAwait(false).GetAwaiter().GetResult(); + } + public Task ReactiveObservedDaemonAsync( CultMeshReactiveDocumentOptions? options = null) { diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeLoadoutSnapshotProjector.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeLoadoutSnapshotProjector.cs index f5bc84a0d..c50715438 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeLoadoutSnapshotProjector.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeLoadoutSnapshotProjector.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using GameCult.Mesh; #nullable enable @@ -15,13 +16,10 @@ namespace GameCult.Aetheria.State.Verse { if (state == null) throw new ArgumentNullException(nameof(state)); - var frame = await state.Daemon.LatestFrame.LatestAsync().ConfigureAwait(false); - if (frame == null) - return new AetheriaRuntimeLoadoutTemplateCommit(); - - return ProjectLoadoutTemplate( - frame.Run ?? new AetheriaRuntimeRunCheckpointCommit(), - entityKey ?? ""); + using var projector = await state + .ReactiveLoadoutSnapshotProjectorAsync() + .ConfigureAwait(false); + return projector.ProjectLoadoutTemplate(entityKey); } public static AetheriaRuntimeLoadoutTemplateCommit ProjectLoadoutTemplate( @@ -252,4 +250,48 @@ namespace GameCult.Aetheria.State.Verse return zoneIndex >= 0 && entityIndex >= 0; } } + + public sealed class AetheriaRuntimeReactiveLoadoutSnapshotProjector : IDisposable + { + private readonly CultMeshReactiveDocument _frame; + + private AetheriaRuntimeReactiveLoadoutSnapshotProjector( + CultMeshReactiveDocument frame) + { + _frame = frame ?? throw new ArgumentNullException(nameof(frame)); + } + + public static async Task CreateAsync( + AetheriaClientState state, + CultMeshReactiveDocumentOptions? options = null) + { + if (state == null) throw new ArgumentNullException(nameof(state)); + + var frame = await state.Daemon.LatestFrame.ReactiveAsync(options).ConfigureAwait(false); + return new AetheriaRuntimeReactiveLoadoutSnapshotProjector(frame); + } + + public static AetheriaRuntimeReactiveLoadoutSnapshotProjector Create( + AetheriaClientState state, + CultMeshReactiveDocumentOptions? options = null) + { + return CreateAsync(state, options).ConfigureAwait(false).GetAwaiter().GetResult(); + } + + public AetheriaRuntimeLoadoutTemplateCommit ProjectLoadoutTemplate(string entityKey) + { + var frame = _frame.Current; + if (frame == null) + return new AetheriaRuntimeLoadoutTemplateCommit(); + + return AetheriaRuntimeLoadoutSnapshotProjector.ProjectLoadoutTemplate( + frame.Run ?? new AetheriaRuntimeRunCheckpointCommit(), + entityKey ?? ""); + } + + public void Dispose() + { + _frame.Dispose(); + } + } }