diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 6ecf93fc5..18418b602 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -3195,10 +3195,13 @@ static void RequireEveRuntimeBootstrap(string root) "ReadDaemonSurface(statePath)", "ReadDaemonSurface(stateBoot.StateFilePath)", "AetheriaUnityRuntimeClientProvider.ResolveClient(", - "client.State.Daemon.GameSurface.LatestAsync()", - "client.State.Daemon.GameTuiSurface.LatestAsync()", - "client.State.Daemon.EditorSurface.LatestAsync()", - "client.State.Daemon.EditorTuiSurface.LatestAsync()", + "CultMeshReactiveDocument", + "ResolveReactiveDaemonSurfaceState(", + "client.State.Daemon.ReactiveGameSurface()", + "client.State.Daemon.ReactiveGameTuiSurface()", + "client.State.Daemon.ReactiveEditorSurface()", + "client.State.Daemon.ReactiveEditorTuiSurface()", + "DisposeReactiveSurfaceState()", "AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(", "private bool ShouldMountSurface(", "_mountedSurfaceVersion != surface.Version", @@ -3228,10 +3231,14 @@ static void RequireEveRuntimeBootstrap(string root) if (presenter.Contains(".DaemonGameSurfaceAsync()", StringComparison.Ordinal) || presenter.Contains(".DaemonGameTuiSurfaceAsync()", StringComparison.Ordinal) || presenter.Contains(".DaemonEditorSurfaceAsync()", StringComparison.Ordinal) || - presenter.Contains(".DaemonEditorTuiSurfaceAsync()", StringComparison.Ordinal)) + presenter.Contains(".DaemonEditorTuiSurfaceAsync()", StringComparison.Ordinal) || + presenter.Contains("client.State.Daemon.GameSurface.LatestAsync()", StringComparison.Ordinal) || + presenter.Contains("client.State.Daemon.GameTuiSurface.LatestAsync()", StringComparison.Ordinal) || + presenter.Contains("client.State.Daemon.EditorSurface.LatestAsync()", StringComparison.Ordinal) || + presenter.Contains("client.State.Daemon.EditorTuiSurface.LatestAsync()", StringComparison.Ordinal)) { throw new InvalidOperationException( - "Aetheria Eve presenter still reads daemon surfaces through AetheriaClient compatibility helpers instead of managed document handles."); + "Aetheria Eve presenter still reads daemon surfaces through one-shot compatibility helpers instead of managed reactive document handles."); } if (presenter.Contains("new EveUiToolkitSurfaceLowerer", StringComparison.Ordinal)) @@ -7598,6 +7605,10 @@ static void RequireAetheriaManagedStateAccessorsCoverDomainDocuments(string root "public global::Aetheria.State.Documents.EveSurfaceState LatestGameTuiSurface()", "public global::Aetheria.State.Documents.EveSurfaceState LatestEditorSurface()", "public global::Aetheria.State.Documents.EveSurfaceState LatestEditorTuiSurface()", + "public CultMeshReactiveDocument ReactiveGameSurface(", + "public CultMeshReactiveDocument ReactiveGameTuiSurface(", + "public CultMeshReactiveDocument ReactiveEditorSurface(", + "public CultMeshReactiveDocument ReactiveEditorTuiSurface(", "public AetheriaRuntimeRtsViewportDocument LatestMap(AetheriaRuntimeRtsViewportBounds viewport)", "public AetheriaRuntimeGravityViewportDocument LatestGravity(AetheriaRuntimeRtsViewportBounds viewport)", "public AetheriaRuntimeSelectedObjectDocument LatestSelectedObject(int entityIndex)", diff --git a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs index 4a38ddeb3..e80d188f2 100644 --- a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs +++ b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs @@ -1,6 +1,7 @@ using System; using GameCult.Aetheria.State.Verse; using GameCult.Eve.Surface; +using GameCult.Mesh; using UnityEngine; using UnityEngine.UIElements; @@ -33,6 +34,9 @@ namespace GameCult.Aetheria.EveRuntime private string _mountedSurfaceId = ""; private long _mountedSurfaceVersion = -1; private string _mountedSurfaceUpdatedAtUtc = ""; + private CultMeshReactiveDocument? _reactiveSurfaceState; + private string _reactiveSurfaceStatePath = ""; + private string _reactiveSurfaceId = ""; private static readonly AetheriaEveUnitySurfaceChrome RootOnlyChrome = new AetheriaEveUnitySurfaceChrome { UseShell = false, @@ -96,6 +100,11 @@ namespace GameCult.Aetheria.EveRuntime Mount(); } + private void OnDisable() + { + DisposeReactiveSurfaceState(); + } + private void Update() { if (!refreshInUpdate || Time.unscaledTime < _nextRefreshTime) @@ -130,18 +139,46 @@ namespace GameCult.Aetheria.EveRuntime } private global::Aetheria.State.Documents.EveSurfaceState? ReadDaemonSurfaceState(AetheriaClient client) + { + var reactive = ResolveReactiveDaemonSurfaceState(client); + return reactive?.Current; + } + + private CultMeshReactiveDocument? ResolveReactiveDaemonSurfaceState( + AetheriaClient client) + { + if (_reactiveSurfaceState != null && + string.Equals(_reactiveSurfaceStatePath, client.StatePath, StringComparison.Ordinal) && + string.Equals(_reactiveSurfaceId, surfaceId, StringComparison.Ordinal)) + { + return _reactiveSurfaceState; + } + + DisposeReactiveSurfaceState(); + _reactiveSurfaceState = CreateReactiveDaemonSurfaceState(client); + if (_reactiveSurfaceState != null) + { + _reactiveSurfaceStatePath = client.StatePath; + _reactiveSurfaceId = surfaceId ?? ""; + } + + return _reactiveSurfaceState; + } + + private CultMeshReactiveDocument? CreateReactiveDaemonSurfaceState( + AetheriaClient client) { if (string.Equals(surfaceId, AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId, StringComparison.Ordinal)) - return client.State.Daemon.GameSurface.LatestAsync().GetAwaiter().GetResult(); + return client.State.Daemon.ReactiveGameSurface(); if (string.Equals(surfaceId, AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId, StringComparison.Ordinal)) - return client.State.Daemon.GameTuiSurface.LatestAsync().GetAwaiter().GetResult(); + return client.State.Daemon.ReactiveGameTuiSurface(); if (string.Equals(surfaceId, AetheriaRuntimeDaemonEditorSurfaceBuilder.SurfaceId, StringComparison.Ordinal)) - return client.State.Daemon.EditorSurface.LatestAsync().GetAwaiter().GetResult(); + return client.State.Daemon.ReactiveEditorSurface(); if (string.Equals(surfaceId, AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId, StringComparison.Ordinal)) - return client.State.Daemon.EditorTuiSurface.LatestAsync().GetAwaiter().GetResult(); + return client.State.Daemon.ReactiveEditorTuiSurface(); return null; } @@ -229,5 +266,12 @@ namespace GameCult.Aetheria.EveRuntime } } + private void DisposeReactiveSurfaceState() + { + _reactiveSurfaceState?.Dispose(); + _reactiveSurfaceState = null; + _reactiveSurfaceStatePath = ""; + _reactiveSurfaceId = ""; + } } } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs index 283193dba..b0448cade 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs @@ -511,6 +511,18 @@ namespace GameCult.Aetheria.State.Verse return LatestGameSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); } + public Task> ReactiveGameSurfaceAsync( + CultMeshReactiveDocumentOptions? options = null) + { + return GameSurface.ReactiveAsync(options); + } + + public CultMeshReactiveDocument ReactiveGameSurface( + CultMeshReactiveDocumentOptions? options = null) + { + return GameSurface.Reactive(options); + } + public Task LatestGameTuiSurfaceAsync() { return GameTuiSurface.LatestAsync(); @@ -521,6 +533,18 @@ namespace GameCult.Aetheria.State.Verse return LatestGameTuiSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); } + public Task> ReactiveGameTuiSurfaceAsync( + CultMeshReactiveDocumentOptions? options = null) + { + return GameTuiSurface.ReactiveAsync(options); + } + + public CultMeshReactiveDocument ReactiveGameTuiSurface( + CultMeshReactiveDocumentOptions? options = null) + { + return GameTuiSurface.Reactive(options); + } + public Task LatestEditorSurfaceAsync() { return EditorSurface.LatestAsync(); @@ -531,6 +555,18 @@ namespace GameCult.Aetheria.State.Verse return LatestEditorSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); } + public Task> ReactiveEditorSurfaceAsync( + CultMeshReactiveDocumentOptions? options = null) + { + return EditorSurface.ReactiveAsync(options); + } + + public CultMeshReactiveDocument ReactiveEditorSurface( + CultMeshReactiveDocumentOptions? options = null) + { + return EditorSurface.Reactive(options); + } + public Task LatestEditorTuiSurfaceAsync() { return EditorTuiSurface.LatestAsync(); @@ -540,6 +576,18 @@ namespace GameCult.Aetheria.State.Verse { return LatestEditorTuiSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); } + + public Task> ReactiveEditorTuiSurfaceAsync( + CultMeshReactiveDocumentOptions? options = null) + { + return EditorTuiSurface.ReactiveAsync(options); + } + + public CultMeshReactiveDocument ReactiveEditorTuiSurface( + CultMeshReactiveDocumentOptions? options = null) + { + return EditorTuiSurface.Reactive(options); + } } public sealed class AetheriaClientCurrentState