From e7f379168d646338177c987d4e63720b85807f0e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 27 Jun 2026 19:45:25 +0100 Subject: [PATCH] Add CultMesh reactive document access to Aetheria --- .../Tests/DaemonRuntimeDocumentTests.cs | 19 ++++++- Assets/Scripts/Tests/Tests.asmdef | 2 + .../Runtime/AetheriaClient.cs | 16 ++++++ .../Runtime/AetheriaClientState.cs | 14 +++++ .../Runtime/AetheriaRuntimeVerseClient.cs | 54 ++++++++++++++----- 5 files changed, 91 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs index fb302fb2d..c5a34f63f 100644 --- a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs +++ b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs @@ -175,6 +175,12 @@ public class DaemonRuntimeDocumentTests .LatestAsync() .GetAwaiter() .GetResult(); + using var currentEntityReactive = client + .ReactiveAsync() + .GetAwaiter() + .GetResult(); + using var zoneRenderReactive = client.State + .Reactive(); var legacyCurrentEntity = client.CurrentEntityAsync().GetAwaiter().GetResult(); Assert.AreEqual("aetheria.current.entity", client.State.Current.Entity.DocumentId); @@ -198,7 +204,9 @@ public class DaemonRuntimeDocumentTests Assert.AreEqual(AetheriaRuntimeDaemonSchemas.CurrentEntity, currentEntity.Schema); Assert.AreEqual("zone.0.entity.0", currentEntity.EntityKey); Assert.AreEqual(0, currentEntity.EntityIndex); - Assert.AreEqual("Player", currentEntity.Entity?.Name); + Assert.AreEqual("Player", currentEntity.Entity?.DisplayName); + Assert.AreEqual(currentEntity.EntityKey, currentEntityReactive.Current.EntityKey); + Assert.AreEqual(AetheriaRuntimeDaemonSchemas.ZoneRender, zoneRenderReactive.Current.Schema); Assert.AreEqual(currentEntity.EntityKey, currentEntityByType.EntityKey); Assert.AreEqual(currentEntity.EntityKey, currentEntityFromClientType.EntityKey); Assert.AreEqual(legacyCurrentEntity.EntityKey, currentEntity.EntityKey); @@ -232,10 +240,17 @@ public class DaemonRuntimeDocumentTests var aetheria = verse.Aetheria(); var currentEntity = aetheria.Current.Entity.LatestAsync().GetAwaiter().GetResult(); + var latestFrameDocument = verse.Document( + AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest); + using var latestFrameReactive = latestFrameDocument.Reactive(); Assert.AreEqual("aetheria.current.entity", aetheria.Current.Entity.DocumentId); Assert.AreEqual("zone.0.entity.0", currentEntity.EntityKey); - Assert.AreEqual("Player", currentEntity.Entity?.Name); + Assert.AreEqual("Player", currentEntity.Entity?.DisplayName); + Assert.AreEqual(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString(), latestFrameDocument.DocumentId); + Assert.AreEqual(AetheriaRuntimeDaemonSchemas.Frame, latestFrameReactive.Current.Schema); + Assert.AreEqual(8, latestFrameReactive.Current.FrameId); + Assert.IsTrue(latestFrameDocument.CanSet); Assert.IsTrue(aetheria.Current.Entity.Sources.Any(source => source.SourceId == AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString())); } diff --git a/Assets/Scripts/Tests/Tests.asmdef b/Assets/Scripts/Tests/Tests.asmdef index 00f31357b..ef8a1ec79 100644 --- a/Assets/Scripts/Tests/Tests.asmdef +++ b/Assets/Scripts/Tests/Tests.asmdef @@ -8,6 +8,8 @@ "CultMath", "Aetheria.Shared.Unity", "GameCult.Aetheria.State.Unity", + "GameCult.Caching", + "GameCult.Mesh", "GameCult.Eve.Surface" ], "includePlatforms": [ diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs index b1c30b129..20f0f4fc8 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs @@ -74,6 +74,22 @@ namespace GameCult.Aetheria.State.Verse return State.Watch(onNext); } + public Task> ReactiveAsync( + CultMeshReactiveDocumentOptions? options = null) + where TDocument : class + { + ThrowIfDisposed(); + return State.ReactiveAsync(options); + } + + public CultMeshReactiveDocument Reactive( + CultMeshReactiveDocumentOptions? options = null) + where TDocument : class + { + ThrowIfDisposed(); + return State.Reactive(options); + } + internal AetheriaRuntimeDaemonOperationsClient Operations => _operations; public static async Task OpenAsync( diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs index 7737444f8..f75e90c7f 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs @@ -106,6 +106,20 @@ namespace GameCult.Aetheria.State.Verse if (onNext == null) throw new ArgumentNullException(nameof(onNext)); return Document().Watch(onNext); } + + public Task> ReactiveAsync( + CultMeshReactiveDocumentOptions? options = null) + where TDocument : class + { + return Document().ReactiveAsync(options); + } + + public CultMeshReactiveDocument Reactive( + CultMeshReactiveDocumentOptions? options = null) + where TDocument : class + { + return Document().Reactive(options); + } } public sealed class AetheriaClientCurrentState diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs index 7b63b8cc7..46211e5cc 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs @@ -365,74 +365,104 @@ namespace GameCult.Aetheria.State.Verse public CultMeshMutableStatePointer ProviderAdvertisement() { ThrowIfDisposed(); - return Document( + return MutableDocumentPointer( AetheriaRuntimeVerseRecordKeys.DaemonProviderAdvertisement); } public CultMeshMutableStatePointer Health() { ThrowIfDisposed(); - return Document( + return MutableDocumentPointer( AetheriaRuntimeVerseRecordKeys.DaemonHealth); } public CultMeshMutableStatePointer CommandBoundary() { ThrowIfDisposed(); - return Document( + return MutableDocumentPointer( AetheriaRuntimeVerseRecordKeys.DaemonCommandBoundary); } public CultMeshMutableStatePointer LatestFrame() { ThrowIfDisposed(); - return Document( + return MutableDocumentPointer( AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest); } public CultMeshMutableStatePointer LatestSoaView() { ThrowIfDisposed(); - return Document( + return MutableDocumentPointer( AetheriaRuntimeVerseRecordKeys.DaemonSoaViewLatest); } public CultMeshMutableStatePointer StarbridgeScenario() { ThrowIfDisposed(); - return Document( + return MutableDocumentPointer( AetheriaRuntimeVerseRecordKeys.StarbridgeScenarioLatest); } public CultMeshMutableStatePointer StarbridgeSession() { ThrowIfDisposed(); - return Document( + return MutableDocumentPointer( AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest); } public CultMeshMutableStatePointer DaemonGameSurface() { ThrowIfDisposed(); - return Document(AetheriaRuntimeVerseRecordKeys.DaemonGameSurface); + return MutableDocumentPointer(AetheriaRuntimeVerseRecordKeys.DaemonGameSurface); } public CultMeshMutableStatePointer DaemonGameTuiSurface() { ThrowIfDisposed(); - return Document(AetheriaRuntimeVerseRecordKeys.DaemonGameTuiSurface); + return MutableDocumentPointer(AetheriaRuntimeVerseRecordKeys.DaemonGameTuiSurface); } public CultMeshMutableStatePointer DaemonEditorSurface() { ThrowIfDisposed(); - return Document(AetheriaRuntimeVerseRecordKeys.DaemonEditorSurface); + return MutableDocumentPointer(AetheriaRuntimeVerseRecordKeys.DaemonEditorSurface); } public CultMeshMutableStatePointer DaemonEditorTuiSurface() { ThrowIfDisposed(); - return Document(AetheriaRuntimeVerseRecordKeys.DaemonEditorTuiSurface); + return MutableDocumentPointer(AetheriaRuntimeVerseRecordKeys.DaemonEditorTuiSurface); + } + + public CultMeshDocumentHandle Document( + CultRecordKey key, + string? documentId = null) + where TDocument : class + { + ThrowIfDisposed(); + if (string.IsNullOrWhiteSpace(key.Value)) + throw new ArgumentException("Value must be non-empty.", nameof(key)); + var descriptor = CultDocumentRegistry.Shared.GetRequired(); + return CultMesh.Document( + Database, + key, + CultMesh.Verse("aetheria.local", RuntimeId), + documentId, + new[] + { + CultMesh.ProjectionSource(key.ToString(), descriptor.SchemaId, "Aetheria Verse database document") + }, + new CultMeshRouteHint(CultMeshLocalityKind.SharedMemory, "Aetheria Verse database")); + } + + public Task> ReactiveDocumentAsync( + CultRecordKey key, + CultMeshReactiveDocumentOptions? options = null, + string? documentId = null) + where TDocument : class + { + return Document(key, documentId).ReactiveAsync(options); } public Observable> @@ -732,7 +762,7 @@ namespace GameCult.Aetheria.State.Verse return frame; } - private CultMeshMutableStatePointer Document(CultRecordKey key) where T : class + private CultMeshMutableStatePointer MutableDocumentPointer(CultRecordKey key) where T : class { return CultMesh.MutableStatePointer( key.ToString(),