Use reactive observed daemon state

This commit is contained in:
Meta Vens 2026-06-28 10:14:21 +01:00
commit 03295ad7a9
5 changed files with 179 additions and 10 deletions

View file

@ -14747,7 +14747,12 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root)
"AetheriaClientState state",
"state.LatestDaemonFrameAsync()",
"state.LatestDaemonSoaViewAsync()",
"AetheriaRuntimeDaemonSoaViewIndex.Build(soaView)"
"AetheriaRuntimeDaemonSoaViewIndex.Build(soaView)",
"public sealed class AetheriaRuntimeReactiveObservedDaemonState",
"public static async Task<AetheriaRuntimeReactiveObservedDaemonState> CreateAsync(",
"state.LatestFrame.ReactiveAsync(options)",
"state.LatestSoaView.ReactiveAsync(options)",
"public bool TryCurrent(out AetheriaRuntimeObservedDaemonState? observed)"
};
var missingObservedDaemonStateSymbols = requiredObservedDaemonStateSymbols
.Where(symbol => !observedDaemonState.Contains(symbol, StringComparison.Ordinal))
@ -14875,16 +14880,20 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root)
!daemonObserver.Contains("AetheriaUnityRuntimeClientProvider.ResolveClient(", StringComparison.Ordinal) ||
!daemonObserver.Contains("AetheriaRuntimeStateBoot.Inspect(AetheriaUnityRuntimePaths.GameDataDirectory)", StringComparison.Ordinal) ||
!daemonObserver.Contains("AetheriaRuntimeObservedDaemonState", StringComparison.Ordinal) ||
!daemonObserver.Contains(".ReadAsync(client.State)", StringComparison.Ordinal))
!daemonObserver.Contains("AetheriaRuntimeReactiveObservedDaemonState", StringComparison.Ordinal) ||
!daemonObserver.Contains(".ReactiveObservedDaemon()", StringComparison.Ordinal) ||
!daemonObserver.Contains("reactive.TryCurrent(out var observed)", StringComparison.Ordinal) ||
!daemonObserver.Contains("DisposeReactiveObservedDaemonState()", StringComparison.Ordinal))
{
throw new InvalidOperationException(
"AetheriaDaemonObserver no longer composes observed daemon state from managed Aetheria client documents.");
"AetheriaDaemonObserver no longer samples observed daemon state from the managed reactive Aetheria client documents.");
}
if (daemonObserver.Contains("AetheriaRuntimeStateReader.TryReadObservedDaemonState", StringComparison.Ordinal))
if (daemonObserver.Contains("AetheriaRuntimeStateReader.TryReadObservedDaemonState", StringComparison.Ordinal) ||
daemonObserver.Contains(".ReadAsync(client.State)", StringComparison.Ordinal))
{
throw new InvalidOperationException(
"AetheriaDaemonObserver still spelunks observed daemon state through the runtime file reader instead of the Verse client.");
"AetheriaDaemonObserver still spelunks observed daemon state through a one-shot reader instead of the reactive Verse client documents.");
}
if (daemonObserver.Contains("ObserveAsync()", StringComparison.Ordinal))

View file

@ -20,6 +20,7 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
private float _nextPollTime;
private AetheriaDaemonSoaMemoryMap _soaMemoryMap;
private AetheriaDaemonRenderNativeView _renderNativeView;
private AetheriaRuntimeReactiveObservedDaemonState _reactiveObservedDaemonState;
public AetheriaRuntimeObservedDaemonState LastObservedState { get; private set; }
public AetheriaRuntimeDaemonObservationResult LastObservation { get; private set; }
@ -83,6 +84,7 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
public void ResetObservation()
{
_cursor.Reset();
DisposeReactiveObservedDaemonState();
DisposeSoaMemoryMap();
LastObservedState = null;
LastObservation = null;
@ -90,16 +92,16 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
private void OnDisable()
{
DisposeReactiveObservedDaemonState();
DisposeSoaMemoryMap();
}
private AetheriaRuntimeObservedDaemonState ReadObservedDaemonState()
{
var client = ResolveClient();
return AetheriaRuntimeObservedDaemonState
.ReadAsync(client.State)
.GetAwaiter()
.GetResult();
var reactive = ResolveReactiveObservedDaemonState();
return reactive.TryCurrent(out var observed)
? observed
: null;
}
private AetheriaClient ResolveClient()
@ -114,6 +116,19 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
return AetheriaUnityRuntimeClientProvider.ResolveClient(stateBoot, clientId);
}
private AetheriaRuntimeReactiveObservedDaemonState ResolveReactiveObservedDaemonState()
{
if (_reactiveObservedDaemonState != null)
{
return _reactiveObservedDaemonState;
}
_reactiveObservedDaemonState = ResolveClient()
.State
.ReactiveObservedDaemon();
return _reactiveObservedDaemonState;
}
private void RemapSoaView(AetheriaRuntimeObservedDaemonState observed)
{
DisposeSoaMemoryMap();
@ -149,4 +164,10 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
_soaMemoryMap?.Dispose();
_soaMemoryMap = null;
}
private void DisposeReactiveObservedDaemonState()
{
_reactiveObservedDaemonState?.Dispose();
_reactiveObservedDaemonState = null;
}
}

View file

@ -2176,6 +2176,54 @@ public class DaemonRuntimeDocumentTests
Assert.IsFalse(observed.SoaView.Buffers[0].ObserverWritable);
}
[Test]
public void ReactiveObservedDaemonStateSamplesManagedFrameAndSoaDocuments()
{
var statePath = Path.Combine(
Path.GetTempPath(),
"aetheria-reactive-observed-daemon-state-tests",
Path.GetRandomFileName(),
"state.cc");
var frame = AetheriaRuntimeDaemonFrameDocument.Create(
new AetheriaRuntimeRunCheckpointCommit
{
RunId = "reactive-daemon-run",
CurrentZoneIndex = 3,
CurrentEntityKey = "entity:reactive-observer-target"
},
"aetheria-daemon",
"session-reactive-observed",
330,
13.0,
0.02);
var soaView = AetheriaRuntimeDaemonSoaViewDocument.Create(
"aetheria-daemon",
"session-reactive-observed",
330,
331,
Array.Empty<AetheriaRuntimeDaemonSoaBufferDocument>(),
Array.Empty<AetheriaRuntimeDaemonSoaColumnDocument>());
PublishLatestFrameThroughVerseClient(statePath, frame);
PublishLatestSoaViewThroughVerseClient(statePath, soaView);
using var client = AetheriaClient
.OpenAsync(statePath, "unity-reactive-observer-test", pullOnOpen: true)
.GetAwaiter()
.GetResult();
using var observedState = client.State.ReactiveObservedDaemon();
Assert.IsTrue(observedState.TryCurrent(out var observed));
Assert.IsNotNull(observed);
Assert.IsTrue(observed.IsAuthoritative);
Assert.AreEqual("reactive-daemon-run", observed.Run.RunId);
Assert.AreEqual("entity:reactive-observer-target", observed.Run.CurrentEntityKey);
Assert.AreEqual(330, observed.Frame.FrameId);
Assert.AreEqual(331, observed.SoaView.Generation);
Assert.AreEqual(AetheriaRuntimeDaemonSchemas.ZoneRender, observed.ZoneRender.Schema);
Assert.AreEqual(330, observed.ZoneRender.FrameId);
}
[Test]
public void ObservedDaemonStateReadsManagedFrameWithoutSoaDocument()
{

View file

@ -220,6 +220,18 @@ namespace GameCult.Aetheria.State.Verse
return LatestDaemonSoaViewAsync().ConfigureAwait(false).GetAwaiter().GetResult();
}
public Task<AetheriaRuntimeReactiveObservedDaemonState> ReactiveObservedDaemonAsync(
CultMeshReactiveDocumentOptions? options = null)
{
return AetheriaRuntimeReactiveObservedDaemonState.CreateAsync(this, options);
}
public AetheriaRuntimeReactiveObservedDaemonState ReactiveObservedDaemon(
CultMeshReactiveDocumentOptions? options = null)
{
return ReactiveObservedDaemonAsync(options).ConfigureAwait(false).GetAwaiter().GetResult();
}
public Task<AetheriaRuntimeLoadoutTemplatesDocument> LatestLoadoutTemplatesAsync()
{
return LoadoutTemplates.LatestAsync();

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using GameCult.Mesh;
#nullable enable
@ -61,4 +62,82 @@ namespace GameCult.Aetheria.State.Verse
}
}
}
public sealed class AetheriaRuntimeReactiveObservedDaemonState : IDisposable
{
private readonly CultMeshReactiveDocument<AetheriaRuntimeDaemonFrameDocument> _frame;
private readonly CultMeshReactiveDocument<AetheriaRuntimeDaemonSoaViewDocument>? _soaView;
private AetheriaRuntimeReactiveObservedDaemonState(
CultMeshReactiveDocument<AetheriaRuntimeDaemonFrameDocument> frame,
CultMeshReactiveDocument<AetheriaRuntimeDaemonSoaViewDocument>? soaView)
{
_frame = frame ?? throw new ArgumentNullException(nameof(frame));
_soaView = soaView;
}
public static async Task<AetheriaRuntimeReactiveObservedDaemonState> CreateAsync(
AetheriaClientState state,
CultMeshReactiveDocumentOptions? options = null)
{
if (state == null) throw new ArgumentNullException(nameof(state));
var frame = await state.LatestFrame.ReactiveAsync(options).ConfigureAwait(false);
var soaView = await TryCreateSoaViewAsync(state, options).ConfigureAwait(false);
return new AetheriaRuntimeReactiveObservedDaemonState(frame, soaView);
}
public AetheriaRuntimeObservedDaemonState? Current
{
get
{
var frame = _frame.Current;
if (frame == null)
return null;
var soaView = _soaView?.Current;
if (soaView == null ||
!string.Equals(soaView.Schema, AetheriaRuntimeDaemonSchemas.SoaView, StringComparison.Ordinal))
{
soaView = null;
}
return new AetheriaRuntimeObservedDaemonState(frame, soaView);
}
}
public bool TryCurrent(out AetheriaRuntimeObservedDaemonState? observed)
{
observed = null;
try
{
observed = Current;
return observed != null;
}
catch
{
return false;
}
}
public void Dispose()
{
_frame.Dispose();
_soaView?.Dispose();
}
private static async Task<CultMeshReactiveDocument<AetheriaRuntimeDaemonSoaViewDocument>?> TryCreateSoaViewAsync(
AetheriaClientState state,
CultMeshReactiveDocumentOptions? options)
{
try
{
return await state.LatestSoaView.ReactiveAsync(options).ConfigureAwait(false);
}
catch (KeyNotFoundException)
{
return null;
}
}
}
}