From 1d41899f6fa9a034e36c4c43d9d0a7d1500c38a1 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 27 Jun 2026 15:01:23 +0100 Subject: [PATCH] Delegate Aetheria document lookup to CultMesh --- ...ltmesh-ergonomics-staged-migration-plan.md | 4 +- .../scripts/verify-stage7d-unity-parity.ps1 | 9 +- .../Runtime/AetheriaClientState.cs | 89 ++++++++++--------- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md b/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md index 046a1bb36..8d1c27de7 100644 --- a/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md +++ b/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md @@ -340,7 +340,7 @@ const refit = await client.aetheria() Work: -- Keep pushing shared CultMesh typed reactive document and collection handles down until type/schema lookup, including the current Aetheria facade shim for schema-compatible CLR aliases, is owned by CultMesh rather than by the Aetheria facade registry. +- Keep pushing shared CultMesh typed reactive document and collection handles down. Typed document handles and schema-compatible CLR alias lookup now live in CultMesh through `CultMeshDocumentHandle` and `CultMeshDocumentCatalog`; remaining work should remove client-side joins and generated facade gaps rather than rebuilding schema dictionaries in Aetheria. - Generate Aetheria current/station/zone/catalog accessors from schema metadata. - Move derived-state joins, such as current docking bay from current docking plus station refit plus entity records, into generated/internal query executors. - Replace remaining Unity menu/HUD/render calls to `TryResolve*` and `_observedFacadeIndex` with typed handles or generated/internal render adapters. @@ -351,7 +351,7 @@ Work: Gates: - `InventoryMenu`, `InventoryPanel`, `TradeMenu`, `LocalMenu`, `SchematicDisplay`, `SectorRenderer`, `MapRenderer`, and `ZoneRenderer` do not manually join state projections to obtain domain values. -- Shared projected documents are reachable through `client.Aetheria().Document()`, including same-schema CLR aliases, `client.Aetheria().DocumentBySchema(schemaVersion)`, `client.Aetheria().LatestAsync()`, and `client.Watch()` as the C# stepping stone toward CultMesh-native type/schema lookup. +- Shared projected documents are reachable through `client.Aetheria().Document()`, including same-schema CLR aliases, `client.Aetheria().DocumentBySchema(schemaVersion)`, `client.Aetheria().LatestAsync()`, and `client.Watch()`; the underlying type/schema lookup is delegated to CultMesh rather than an Aetheria-owned schema registry. - Client-facing code contains no `_observedFacadeIndex.TryResolve*` outside Unity render adapter internals. - Client-facing code contains no `ResolveClient().Current*Async().GetAwaiter().GetResult()` or equivalent blocking state reads. - `TryGetTypedCurrentDockingBayFacade` and similar transitional helpers are deleted rather than renamed. diff --git a/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 b/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 index c57873570..16a3d3d83 100644 --- a/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 +++ b/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 @@ -596,16 +596,17 @@ Assert-Contains $verseClient "AetheriaClientState Aetheria()" "AetheriaRuntimeVe 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 "CultMeshDocumentHandle" "Aetheria state documents must wrap CultMesh typed document handles." +Assert-Contains $clientState "CultMeshDocumentCatalog" "Aetheria state facade must delegate type/schema lookup to CultMesh." +Assert-Contains $clientState "CultMesh.Documents" "Aetheria state facade must build its projected document catalog through CultMesh." Assert-Contains $clientState "IAetheriaRuntimeProjectedDocument" "Aetheria projected documents must expose schema metadata independent of exact CLR type." Assert-Contains $clientState "_documentsByType" "Aetheria state facade must index projected documents by shared document type." -Assert-Contains $clientState "_documentsBySchema" "Aetheria state facade must index projected documents by shared schema identity." Assert-Contains $clientState "TryGetDocument" "Aetheria state facade must support safe typed document lookup." Assert-Contains $clientState "TryGetDocumentBySchema" "Aetheria state facade must support safe schema document lookup." Assert-Contains $clientState "Document()" "Aetheria state facade must support direct typed document lookup." Assert-Contains $clientState "DocumentBySchema(string schemaVersion)" "Aetheria state facade must support direct schema document lookup." -Assert-Contains $clientState "AsSchemaAlias" "Aetheria state facade must adapt same-schema projected documents across CLR aliases until CultMesh owns alias conversion." -Assert-Contains $clientState "CultDocumentMessagePackSerialization" "Aetheria projected document aliasing must use the canonical CultCache document serializer." +Assert-Contains $clientState "AsSchemaAlias" "Aetheria state facade must expose CultMesh same-schema aliases." +Assert-NotContains $clientState "CultDocumentMessagePackSerialization" "Aetheria projected document aliasing must be owned by CultMesh, not the Aetheria facade." Assert-Contains $clientState "LatestAsync()" "Aetheria state facade must support one-call typed document reads." Assert-Contains $clientState "Watch()" "Aetheria state facade must support reactive typed document lookup." Assert-Contains $clientState "LatestAsync()" "Aetheria state documents must support one-shot typed reads." diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs index a520a9bec..63e784dcc 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; -using GameCult.Caching; using GameCult.Mesh; using R3; @@ -36,6 +36,8 @@ namespace GameCult.Aetheria.State.Verse public CultMeshDocumentHandle Handle => _handle; + public ICultMeshDocumentHandle UntypedHandle => _handle; + public Task LatestAsync() { return _handle.LatestAsync(); @@ -109,13 +111,46 @@ namespace GameCult.Aetheria.State.Verse bool CanReplace { get; } + ICultMeshDocumentHandle UntypedHandle { get; } + AetheriaRuntimeProjectedDocument AsSchemaAlias() where TAlias : class; } + internal sealed class AetheriaRuntimeUntypedProjectedDocument : IAetheriaRuntimeProjectedDocument + { + private readonly ICultMeshDocumentHandle _handle; + + public AetheriaRuntimeUntypedProjectedDocument(ICultMeshDocumentHandle handle) + { + _handle = handle ?? throw new ArgumentNullException(nameof(handle)); + } + + public Type DocumentType => _handle.DocumentType; + + public string DocumentId => _handle.DocumentId; + + public string SchemaName => _handle.SchemaName; + + public string SchemaVersion => _handle.SchemaVersion; + + public CultMeshRouteHint RouteHint => _handle.RouteHint; + + public System.Collections.Generic.IReadOnlyList Sources => _handle.Sources; + + public bool CanReplace => _handle.CanReplace; + + public ICultMeshDocumentHandle UntypedHandle => _handle; + + public AetheriaRuntimeProjectedDocument AsSchemaAlias() where TAlias : class + { + return new AetheriaRuntimeProjectedDocument(_handle.AsSchemaAlias()); + } + } + public sealed class AetheriaClientState { private readonly IReadOnlyDictionary _documentsByType; - private readonly IReadOnlyDictionary _documentsBySchema; + private readonly CultMeshDocumentCatalog _documents; internal AetheriaClientState( AetheriaRuntimeProjectedDocument currentZone, @@ -141,7 +176,10 @@ namespace GameCult.Aetheria.State.Verse [typeof(AetheriaRuntimeSectorMapDocument)] = SectorMap, [typeof(AetheriaRuntimeZoneRenderDocument)] = ZoneRender }; - _documentsBySchema = BuildSchemaIndex(_documentsByType.Values); + _documents = CultMesh.Documents(_documentsByType + .Values + .OfType() + .Select(document => document.UntypedHandle)); } public AetheriaClientCurrentState Current { get; } @@ -158,9 +196,9 @@ namespace GameCult.Aetheria.State.Verse string schemaVersion, out IAetheriaRuntimeProjectedDocument document) { - if (!string.IsNullOrWhiteSpace(schemaVersion) && - _documentsBySchema.TryGetValue(schemaVersion, out document!)) + if (_documents.TryGetDocumentBySchema(schemaVersion, out var handle)) { + document = new AetheriaRuntimeUntypedProjectedDocument(handle); return true; } @@ -181,24 +219,9 @@ namespace GameCult.Aetheria.State.Verse out AetheriaRuntimeProjectedDocument document) where TDocument : class { - if (_documentsByType.TryGetValue(typeof(TDocument), out var untypedDocument) && - untypedDocument is AetheriaRuntimeProjectedDocument typedDocument) + if (_documents.TryGetDocument(out var handle)) { - document = typedDocument; - return true; - } - - var schemaVersion = SchemaVersionFor(typeof(TDocument)); - if (!string.IsNullOrWhiteSpace(schemaVersion) && - _documentsBySchema.TryGetValue(schemaVersion, out var schemaDocument)) - { - if (schemaDocument is AetheriaRuntimeProjectedDocument schemaTypedDocument) - { - document = schemaTypedDocument; - return true; - } - - document = schemaDocument.AsSchemaAlias(); + document = new AetheriaRuntimeProjectedDocument(handle); return true; } @@ -234,28 +257,6 @@ namespace GameCult.Aetheria.State.Verse return Document().Watch(onNext); } - private static IReadOnlyDictionary BuildSchemaIndex( - IEnumerable documents) - { - var index = new Dictionary(StringComparer.Ordinal); - foreach (var document in documents) - { - if (document is not IAetheriaRuntimeProjectedDocument projectedDocument) - continue; - - if (!string.IsNullOrWhiteSpace(projectedDocument.SchemaVersion)) - index[projectedDocument.SchemaVersion] = projectedDocument; - if (!string.IsNullOrWhiteSpace(projectedDocument.SchemaName)) - index[projectedDocument.SchemaName] = projectedDocument; - } - - return index; - } - - private static string SchemaVersionFor(Type documentType) - { - return CultDocumentRegistry.Shared.GetRequired(documentType).SchemaVersion; - } } public sealed class AetheriaClientCurrentState