Remove reactive state session wrappers
This commit is contained in:
parent
391e0e5939
commit
c5d92cbf53
8 changed files with 121 additions and 484 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using GameCult.Mesh;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class AetheriaDaemonObserver : MonoBehaviour
|
||||
|
|
@ -20,7 +21,9 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
|
|||
private float _nextPollTime;
|
||||
private AetheriaDaemonSoaMemoryMap _soaMemoryMap;
|
||||
private AetheriaDaemonRenderNativeView _renderNativeView;
|
||||
private AetheriaRuntimeObservedDaemonSession _observedDaemon;
|
||||
private CultMeshReactiveDocument<AetheriaRuntimeDaemonFrameDocument> _daemonFrame;
|
||||
private CultMeshReactiveDocument<AetheriaRuntimeDaemonSoaViewDocument> _daemonSoaView;
|
||||
private CultMeshReactiveDocument<AetheriaRuntimeZoneRenderDocument> _zoneRender;
|
||||
|
||||
public AetheriaRuntimeObservedDaemonState LastObservedState { get; private set; }
|
||||
public AetheriaRuntimeDaemonObservationResult LastObservation { get; private set; }
|
||||
|
|
@ -100,8 +103,14 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
|
|||
{
|
||||
try
|
||||
{
|
||||
_observedDaemon ??= ResolveClient()?.State?.ObserveDaemon();
|
||||
return _observedDaemon?.Current;
|
||||
EnsureObservedDaemonDocuments();
|
||||
return AetheriaRuntimeObservedDaemonState.TryCreateCurrent(
|
||||
_daemonFrame,
|
||||
_daemonSoaView,
|
||||
_zoneRender,
|
||||
out var observed)
|
||||
? observed
|
||||
: null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -109,6 +118,37 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private void EnsureObservedDaemonDocuments()
|
||||
{
|
||||
if (_daemonFrame != null && _zoneRender != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var state = ResolveClient()?.State;
|
||||
if (state == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_daemonFrame ??= state.ReactiveDaemonFrame();
|
||||
_daemonSoaView ??= TryReactiveDaemonSoaView(state);
|
||||
_zoneRender ??= state.ReactiveZoneRender();
|
||||
}
|
||||
|
||||
private static CultMeshReactiveDocument<AetheriaRuntimeDaemonSoaViewDocument> TryReactiveDaemonSoaView(
|
||||
AetheriaClientState state)
|
||||
{
|
||||
try
|
||||
{
|
||||
return state.ReactiveDaemonSoaView();
|
||||
}
|
||||
catch (System.Collections.Generic.KeyNotFoundException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private AetheriaClient ResolveClient()
|
||||
{
|
||||
var stateBoot = AetheriaRuntimeStateBoot.Inspect(AetheriaUnityRuntimePaths.GameDataDirectory);
|
||||
|
|
@ -159,7 +199,11 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
|
|||
|
||||
private void DisposeObservedDaemonSession()
|
||||
{
|
||||
_observedDaemon?.Dispose();
|
||||
_observedDaemon = null;
|
||||
_daemonFrame?.Dispose();
|
||||
_daemonFrame = null;
|
||||
_daemonSoaView?.Dispose();
|
||||
_daemonSoaView = null;
|
||||
_zoneRender?.Dispose();
|
||||
_zoneRender = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2263,8 +2263,16 @@ public class DaemonRuntimeDocumentTests
|
|||
.OpenAsync(statePath, "unity-reactive-observer-test", pullOnOpen: true)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
using var observedSession = client.State.ObserveDaemon();
|
||||
var observed = observedSession.Current;
|
||||
using var observedFrame = client.State.ReactiveDaemonFrame();
|
||||
using var observedSoaView = client.State.ReactiveDaemonSoaView();
|
||||
using var observedZoneRender = client.State.ReactiveZoneRender();
|
||||
var observed = AetheriaRuntimeObservedDaemonState.TryCreateCurrent(
|
||||
observedFrame,
|
||||
observedSoaView,
|
||||
observedZoneRender,
|
||||
out var currentObserved)
|
||||
? currentObserved
|
||||
: null;
|
||||
var sampledObserved = client.State.CurrentObservedDaemon();
|
||||
Assert.IsNotNull(observed);
|
||||
Assert.IsNotNull(sampledObserved);
|
||||
|
|
|
|||
Loading…
Reference in a new issue