From e08c9e9c3cb33bbe10cbd14c2291e857a8eb24a5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 27 Jun 2026 13:55:00 +0100 Subject: [PATCH] Expose Aetheria domain state from Verse client --- ...ltmesh-ergonomics-staged-migration-plan.md | 5 +- .../scripts/verify-stage7d-unity-parity.ps1 | 11 +++ .../Tests/DaemonRuntimeDocumentTests.cs | 34 +++++++- .../Runtime/AetheriaClient.cs | 78 +---------------- .../Runtime/AetheriaRuntimeVerseClient.cs | 87 +++++++++++++++++++ docs/aetheria-verse-client-contract.md | 8 +- 6 files changed, 143 insertions(+), 80 deletions(-) diff --git a/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md b/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md index 1390584f3..1fb79860e 100644 --- a/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md +++ b/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md @@ -268,7 +268,10 @@ Gates: ## Stage 3A: Collapse State Access To Typed Reactive Handles -Status: not started; current Unity and RTS clients still perform byzantine protocol walks. +Status: started; `AetheriaRuntimeVerseClient.Aetheria()` now exposes the first +C# domain facade for current, station, and zone projected documents, and +`AetheriaClient` delegates to that shared facade. Unity and RTS clients still +perform byzantine protocol walks in several menus/renderers. Goal: every client-facing state access becomes a single CultMesh document, collection, query, or pointer call. The caller names the domain state it wants and gets a typed reactive value. It does not manually inspect daemon frames, current-state projections, station rows, record keys, local facade indexes, or transport route details. diff --git a/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 b/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 index ae20066f4..58b24943d 100644 --- a/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 +++ b/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 @@ -534,6 +534,8 @@ $tickRunner = Read-Text "Packages\org.gamecult.aetheria.state\Runtime\AetheriaRu Assert-Contains $tickRunner "ProjectTradeValuePolicySurfaceDocument(stateFilePath)" "Daemon editor surface must publish the trade-value policy designer surface." $client = Read-Text "Packages\org.gamecult.aetheria.state\Runtime\AetheriaClient.cs" +Assert-Contains $client "AetheriaClientState State" "AetheriaClient must expose the semantic typed state facade." +Assert-Contains $client "Aetheria()" "AetheriaClient must expose the canonical domain facade entrypoint." Assert-Contains $client "ObjectsViewportAsync" "AetheriaClient must expose objects viewport facade." Assert-Contains $client "GravityViewportAsync" "AetheriaClient must expose gravity viewport facade." Assert-Contains $client "CurrentZoneAsync" "AetheriaClient must expose current-zone facade." @@ -545,6 +547,15 @@ Assert-Contains $client "SectorMapAsync" "AetheriaClient must expose sector-map Assert-Contains $client "ZoneDetailsAsync" "AetheriaClient must expose zone-details facade." Assert-Contains $client "ZoneRenderAsync" "AetheriaClient must expose zone-render facade." +$verseClient = Read-Text "Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeVerseClient.cs" +Assert-Contains $verseClient "AetheriaClientState Aetheria()" "AetheriaRuntimeVerseClient must expose the shared domain state facade." +Assert-Contains $verseClient "CreateAetheriaStateFacade" "AetheriaRuntimeVerseClient must own projected state facade creation." + +$clientState = Read-Text "Packages\org.gamecult.aetheria.state\Runtime\AetheriaClientState.cs" +Assert-Contains $clientState "CultMeshBoundLiveFeed" "Aetheria state documents must bind through CultMesh live feeds." +Assert-Contains $clientState "LatestAsync()" "Aetheria state documents must support one-shot typed reads." +Assert-Contains $clientState "Watch()" "Aetheria state documents must support reactive typed reads." + $projection = Read-Text "Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeRtsProjection.cs" Assert-Contains $projection "ProjectZoneDetails" "Shared projection code must own the zone-details feed." Assert-Contains $projection "ProjectZoneContacts" "Shared projection code must own the zone-contacts feed." diff --git a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs index 5f0136a74..8619220d2 100644 --- a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs +++ b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs @@ -166,7 +166,7 @@ public class DaemonRuntimeDocumentTests .GetAwaiter() .GetResult(); - var currentEntity = client.State.Current.Entity.LatestAsync().GetAwaiter().GetResult(); + var currentEntity = client.Aetheria().Current.Entity.LatestAsync().GetAwaiter().GetResult(); var legacyCurrentEntity = client.CurrentEntityAsync().GetAwaiter().GetResult(); Assert.AreEqual("aetheria.current.entity", client.State.Current.Entity.DocumentId); @@ -181,6 +181,38 @@ public class DaemonRuntimeDocumentTests source.SourceId == "catalog:aetheria.runtime")); } + [Test] + public void AetheriaRuntimeVerseClientExposesDomainStateFacade() + { + var statePath = Path.Combine( + Path.GetTempPath(), + "aetheria-verse-domain-state-facade-tests", + Path.GetRandomFileName(), + "state.cc"); + var frame = AetheriaRuntimeDaemonFrameDocument.Create( + RunWithTwoEntities(), + "daemon", + "session-state", + 8, + 1.5, + 0.02); + PublishLatestFrameThroughVerseClient(statePath, frame); + + using var verse = AetheriaRuntimeVerseClient + .OpenAsync(statePath, "tool-test", pullOnOpen: true) + .GetAwaiter() + .GetResult(); + + var aetheria = verse.Aetheria(); + var currentEntity = aetheria.Current.Entity.LatestAsync().GetAwaiter().GetResult(); + + Assert.AreEqual("aetheria.current.entity", aetheria.Current.Entity.DocumentId); + Assert.AreEqual("zone.0.entity.0", currentEntity.EntityKey); + Assert.AreEqual("Player", currentEntity.Entity?.Name); + Assert.IsTrue(aetheria.Current.Entity.Sources.Any(source => + source.SourceId == AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString())); + } + [Test] public void TickRunnerAppliesObservedCommandsAndPublishesFrame() { diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs index d4c412fe4..3a3004d06 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading.Tasks; using GameCult.Eve.Surface; using GameCult.Mesh; -using R3; #nullable enable @@ -29,7 +28,7 @@ namespace GameCult.Aetheria.State.Verse _operations = new AetheriaRuntimeDaemonOperationsClient(SendOperation); _control = new AetheriaControl(_operations); _ui = new AetheriaUi(this); - _state = CreateStateFacade(); + _state = _verse.Aetheria(); } public string StatePath => _verse.StatePath; @@ -38,6 +37,8 @@ namespace GameCult.Aetheria.State.Verse public AetheriaUi Ui => _ui; public AetheriaClientState State => _state; + public AetheriaClientState Aetheria() => State; + internal AetheriaRuntimeDaemonOperationsClient Operations => _operations; public static async Task OpenAsync( @@ -385,79 +386,6 @@ namespace GameCult.Aetheria.State.Verse return frame; } - private AetheriaClientState CreateStateFacade() - { - var frameChanges = _verse.WatchLatestFrames() - .Where(change => change.Document != null) - .Select(change => change.Document!); - - return new AetheriaClientState( - ProjectedDocument( - "aetheria.current.zone", - frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectCurrentZone(frame)), - AetheriaRuntimeDaemonSchemas.CurrentZone), - ProjectedDocument( - "aetheria.current.entity", - frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectCurrentEntity(frame)), - AetheriaRuntimeDaemonSchemas.CurrentEntity), - ProjectedDocument( - "aetheria.current.docking", - frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectCurrentDocking(frame)), - AetheriaRuntimeDaemonSchemas.CurrentDocking), - ProjectedDocument( - "aetheria.zone.contacts", - frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectZoneContacts(frame)), - AetheriaRuntimeDaemonSchemas.ZoneContacts), - ProjectedDocument( - "aetheria.station.refit", - ProjectStationRefitAsync, - AetheriaRuntimeDaemonSchemas.StationRefit, - CultMesh.ProjectionSource("catalog:aetheria.runtime"), - CultMesh.ProjectionSource("loadout-templates:aetheria.runtime")), - ProjectedDocument( - "aetheria.sector.map", - frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectSectorMap(frame)), - AetheriaRuntimeDaemonSchemas.SectorMap), - ProjectedDocument( - "aetheria.zone.render", - frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectZoneRender(frame)), - AetheriaRuntimeDaemonSchemas.ZoneRender)); - - AetheriaRuntimeProjectedDocument ProjectedDocument( - string documentId, - Func> project, - string schemaId, - params CultMeshProjectionSource[] additionalSources) - { - var sources = new[] - { - CultMesh.ProjectionSource( - AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString(), - AetheriaRuntimeDaemonSchemas.Frame, - "latest authoritative daemon frame") - } - .Concat(additionalSources ?? Array.Empty()) - .Append(CultMesh.ProjectionSource(documentId, schemaId, "projected Aetheria client document")) - .ToArray(); - - return AetheriaRuntimeProjectedDocument.Create( - documentId, - RuntimeId, - async () => await project(await RequireFrameAsync().ConfigureAwait(false)).ConfigureAwait(false), - frameChanges, - project, - sources); - } - - async Task ProjectStationRefitAsync( - AetheriaRuntimeDaemonFrameDocument frame) - { - var loadoutTemplates = await _verse.GetLoadoutTemplatesAsync().ConfigureAwait(false); - var catalog = _verse.OpenRuntimeCatalog(); - return AetheriaRuntimeRtsProjection.ProjectStationRefit(frame, loadoutTemplates, catalog); - } - } - private void ThrowIfDisposed() { if (_disposed) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs index 58cde72b0..f6b84f4ed 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs @@ -280,6 +280,12 @@ namespace GameCult.Aetheria.State.Verse return AetheriaRuntimeCatalogStore.OpenReadOnly(StatePath); } + public AetheriaClientState Aetheria() + { + ThrowIfDisposed(); + return CreateAetheriaStateFacade(); + } + public Task GetPlayerSettingsAsync() { ThrowIfDisposed(); @@ -700,6 +706,87 @@ namespace GameCult.Aetheria.State.Verse throw new ObjectDisposedException(nameof(AetheriaRuntimeVerseClient)); } + private AetheriaClientState CreateAetheriaStateFacade() + { + var frameChanges = WatchLatestFrames() + .Where(change => change.Document != null) + .Select(change => change.Document!); + + return new AetheriaClientState( + ProjectedDocument( + "aetheria.current.zone", + frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectCurrentZone(frame)), + AetheriaRuntimeDaemonSchemas.CurrentZone), + ProjectedDocument( + "aetheria.current.entity", + frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectCurrentEntity(frame)), + AetheriaRuntimeDaemonSchemas.CurrentEntity), + ProjectedDocument( + "aetheria.current.docking", + frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectCurrentDocking(frame)), + AetheriaRuntimeDaemonSchemas.CurrentDocking), + ProjectedDocument( + "aetheria.zone.contacts", + frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectZoneContacts(frame)), + AetheriaRuntimeDaemonSchemas.ZoneContacts), + ProjectedDocument( + "aetheria.station.refit", + ProjectStationRefitAsync, + AetheriaRuntimeDaemonSchemas.StationRefit, + CultMesh.ProjectionSource("catalog:aetheria.runtime"), + CultMesh.ProjectionSource("loadout-templates:aetheria.runtime")), + ProjectedDocument( + "aetheria.sector.map", + frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectSectorMap(frame)), + AetheriaRuntimeDaemonSchemas.SectorMap), + ProjectedDocument( + "aetheria.zone.render", + frame => Task.FromResult(AetheriaRuntimeRtsProjection.ProjectZoneRender(frame)), + AetheriaRuntimeDaemonSchemas.ZoneRender)); + + AetheriaRuntimeProjectedDocument ProjectedDocument( + string documentId, + Func> project, + string schemaId, + params CultMeshProjectionSource[] additionalSources) + { + var sources = new[] + { + CultMesh.ProjectionSource( + AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString(), + AetheriaRuntimeDaemonSchemas.Frame, + "latest authoritative daemon frame") + } + .Concat(additionalSources ?? Array.Empty()) + .Append(CultMesh.ProjectionSource(documentId, schemaId, "projected Aetheria client document")) + .ToArray(); + + return AetheriaRuntimeProjectedDocument.Create( + documentId, + RuntimeId, + async () => await project(await RequireFrameAsync().ConfigureAwait(false)).ConfigureAwait(false), + frameChanges, + project, + sources); + } + + async Task ProjectStationRefitAsync( + AetheriaRuntimeDaemonFrameDocument frame) + { + var loadoutTemplates = await GetLoadoutTemplatesAsync().ConfigureAwait(false); + var catalog = OpenRuntimeCatalog(); + return AetheriaRuntimeRtsProjection.ProjectStationRefit(frame, loadoutTemplates, catalog); + } + } + + private async Task RequireFrameAsync() + { + var frame = await GetLatestFrameAsync().ConfigureAwait(false); + if (frame == null) + throw new InvalidOperationException("Aetheria Verse client has no daemon frame yet."); + return frame; + } + private CultMeshMutableStatePointer Document(CultRecordKey key) where T : class { return CultMesh.MutableStatePointer( diff --git a/docs/aetheria-verse-client-contract.md b/docs/aetheria-verse-client-contract.md index 0c8daa49f..728819337 100644 --- a/docs/aetheria-verse-client-contract.md +++ b/docs/aetheria-verse-client-contract.md @@ -52,7 +52,8 @@ menus, HUDs, renderers, RTS panels, and tools should move toward semantic handles: ```csharp -var aetheria = client.Aetheria(); +using var verse = await AetheriaRuntimeVerseClient.OpenAsync(statePath, "tool-client"); +var aetheria = verse.Aetheria(); using var inventory = aetheria.Current.Inventory.Watch(RenderInventory); using var docking = aetheria.Current.Docking.Watch(RenderDocking); @@ -96,8 +97,9 @@ The alternative idea of "Unity runs CultMesh using the same state assembly, but not the daemon assembly" is exactly what this contract supports. The Unity side references the runtime state package, opens `AetheriaRuntimeVerseClient`, and uses CultMesh reactive wrappers to observe daemon state as if it were native -state. The client document handles now delegate to shared CultMesh mutable state -pointers instead of a private Aetheria wrapper. +state. `AetheriaRuntimeVerseClient.Aetheria()` now exposes the first shared C# +domain facade for projected current/station/zone documents, and `AetheriaClient` +delegates to that same facade instead of owning a private projection wrapper. ## Eve Surface Boundary