Use managed RTS viewport document handles
This commit is contained in:
parent
09d92e3d90
commit
ab6387fe1e
7 changed files with 199 additions and 205 deletions
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using GameCult.Mesh;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class AetheriaUnityRenderSplatViewportSource : MonoBehaviour
|
||||
|
|
@ -27,8 +26,7 @@ public sealed class AetheriaUnityRenderSplatViewportSource : MonoBehaviour
|
|||
private bool renderInLateUpdate = true;
|
||||
|
||||
private float _nextRefreshTime;
|
||||
private AetheriaRuntimeRtsViewportBounds _viewport;
|
||||
private CultMeshReactiveDocument<AetheriaRuntimeRenderSplatsViewportDocument> _renderSplatsViewport;
|
||||
private AetheriaUnityRtsViewportDocuments _viewportDocuments;
|
||||
|
||||
public RenderTexture TargetTexture
|
||||
{
|
||||
|
|
@ -65,7 +63,7 @@ public sealed class AetheriaUnityRenderSplatViewportSource : MonoBehaviour
|
|||
return false;
|
||||
|
||||
RefreshDocument(false);
|
||||
var document = _renderSplatsViewport?.Current;
|
||||
var document = _viewportDocuments?.CurrentRenderSplatsViewport;
|
||||
if (document == null)
|
||||
return false;
|
||||
|
||||
|
|
@ -107,7 +105,7 @@ public sealed class AetheriaUnityRenderSplatViewportSource : MonoBehaviour
|
|||
private void RefreshDocument(bool force)
|
||||
{
|
||||
var viewport = ResolveViewportBounds();
|
||||
if (!force && _renderSplatsViewport != null && SameViewport(_viewport, viewport))
|
||||
if (!force && _viewportDocuments != null && _viewportDocuments.Matches(viewport))
|
||||
return;
|
||||
|
||||
if (!force && Time.unscaledTime < _nextRefreshTime)
|
||||
|
|
@ -116,13 +114,10 @@ public sealed class AetheriaUnityRenderSplatViewportSource : MonoBehaviour
|
|||
_nextRefreshTime = Time.unscaledTime + Mathf.Max(0.02f, refreshIntervalSeconds);
|
||||
try
|
||||
{
|
||||
var nextRenderSplatsViewport = AetheriaUnityRuntimeClientProvider
|
||||
.ReactiveRenderSplatsViewport(
|
||||
viewport,
|
||||
"unity-render-splat-viewport");
|
||||
var nextDocuments = AetheriaUnityRuntimeClientProvider
|
||||
.RenderSplatViewportDocuments(viewport, "unity-render-splat-viewport");
|
||||
ClearViewportDocument();
|
||||
_viewport = viewport;
|
||||
_renderSplatsViewport = nextRenderSplatsViewport;
|
||||
_viewportDocuments = nextDocuments;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -144,21 +139,8 @@ public sealed class AetheriaUnityRenderSplatViewportSource : MonoBehaviour
|
|||
|
||||
private void ClearViewportDocument()
|
||||
{
|
||||
_renderSplatsViewport?.Dispose();
|
||||
_renderSplatsViewport = null;
|
||||
}
|
||||
|
||||
private static bool SameViewport(
|
||||
AetheriaRuntimeRtsViewportBounds left,
|
||||
AetheriaRuntimeRtsViewportBounds right)
|
||||
{
|
||||
if (left == null || right == null)
|
||||
return false;
|
||||
|
||||
return Mathf.Approximately(left.MinX, right.MinX) &&
|
||||
Mathf.Approximately(left.MinY, right.MinY) &&
|
||||
Mathf.Approximately(left.MaxX, right.MaxX) &&
|
||||
Mathf.Approximately(left.MaxY, right.MaxY);
|
||||
_viewportDocuments?.Dispose();
|
||||
_viewportDocuments = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
100
Assets/Scripts/Gameplay/AetheriaUnityRtsViewportDocuments.cs
Normal file
100
Assets/Scripts/Gameplay/AetheriaUnityRtsViewportDocuments.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
using System;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using GameCult.Mesh;
|
||||
|
||||
public sealed class AetheriaUnityRtsViewportDocuments : IDisposable
|
||||
{
|
||||
private AetheriaUnityRtsViewportDocuments(
|
||||
AetheriaClientState state,
|
||||
AetheriaRuntimeRtsViewportBounds viewport,
|
||||
bool bindContacts,
|
||||
bool bindObjects,
|
||||
bool bindRenderSplats)
|
||||
{
|
||||
if (state == null)
|
||||
throw new ArgumentNullException(nameof(state));
|
||||
if (viewport == null)
|
||||
throw new ArgumentNullException(nameof(viewport));
|
||||
|
||||
Viewport = viewport;
|
||||
Contacts = bindContacts ? state.ReactiveZoneContacts() : null;
|
||||
ObjectsViewport = bindObjects ? state.ReactiveObjectsViewport(viewport) : null;
|
||||
RenderSplatsViewport = bindRenderSplats ? state.ReactiveRenderSplatsViewport(viewport) : null;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeRtsViewportBounds Viewport { get; }
|
||||
public CultMeshReactiveDocument<AetheriaRuntimeZoneContactsDocument> Contacts { get; }
|
||||
public CultMeshReactiveDocument<AetheriaRuntimeObjectsViewportDocument> ObjectsViewport { get; }
|
||||
public CultMeshReactiveDocument<AetheriaRuntimeRenderSplatsViewportDocument> RenderSplatsViewport { get; }
|
||||
|
||||
public AetheriaRuntimeZoneContactsDocument CurrentContacts => Contacts?.Current;
|
||||
public AetheriaRuntimeObjectsViewportDocument CurrentObjectsViewport => ObjectsViewport?.Current;
|
||||
public AetheriaRuntimeRenderSplatsViewportDocument CurrentRenderSplatsViewport => RenderSplatsViewport?.Current;
|
||||
|
||||
public static AetheriaUnityRtsViewportDocuments OpenMap(
|
||||
AetheriaClientState state,
|
||||
AetheriaRuntimeRtsViewportBounds viewport)
|
||||
{
|
||||
return new AetheriaUnityRtsViewportDocuments(
|
||||
state,
|
||||
viewport,
|
||||
bindContacts: false,
|
||||
bindObjects: true,
|
||||
bindRenderSplats: true);
|
||||
}
|
||||
|
||||
public static AetheriaUnityRtsViewportDocuments OpenZonePresentation(
|
||||
AetheriaClientState state,
|
||||
AetheriaRuntimeRtsViewportBounds viewport)
|
||||
{
|
||||
return new AetheriaUnityRtsViewportDocuments(
|
||||
state,
|
||||
viewport,
|
||||
bindContacts: true,
|
||||
bindObjects: true,
|
||||
bindRenderSplats: false);
|
||||
}
|
||||
|
||||
public static AetheriaUnityRtsViewportDocuments OpenRenderSplats(
|
||||
AetheriaClientState state,
|
||||
AetheriaRuntimeRtsViewportBounds viewport)
|
||||
{
|
||||
return new AetheriaUnityRtsViewportDocuments(
|
||||
state,
|
||||
viewport,
|
||||
bindContacts: false,
|
||||
bindObjects: false,
|
||||
bindRenderSplats: true);
|
||||
}
|
||||
|
||||
public bool Matches(AetheriaRuntimeRtsViewportBounds viewport)
|
||||
{
|
||||
return SameViewport(Viewport, viewport);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Contacts?.Dispose();
|
||||
ObjectsViewport?.Dispose();
|
||||
RenderSplatsViewport?.Dispose();
|
||||
}
|
||||
|
||||
public static bool SameViewport(
|
||||
AetheriaRuntimeRtsViewportBounds left,
|
||||
AetheriaRuntimeRtsViewportBounds right)
|
||||
{
|
||||
if (left == null || right == null)
|
||||
return false;
|
||||
|
||||
return Approximately(left.MinX, right.MinX) &&
|
||||
Approximately(left.MinY, right.MinY) &&
|
||||
Approximately(left.MaxX, right.MaxX) &&
|
||||
Approximately(left.MaxY, right.MaxY);
|
||||
}
|
||||
|
||||
private static bool Approximately(double left, double right)
|
||||
{
|
||||
var scale = Math.Max(1.0, Math.Max(Math.Abs(left), Math.Abs(right)));
|
||||
return Math.Abs(left - right) <= scale * 1e-6;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e763d94f902249349a0f897ef12bd185
|
||||
|
|
@ -175,6 +175,27 @@ public static class AetheriaUnityRuntimeClientProvider
|
|||
return RuntimeState(runtimeId).ReactiveRenderSplatsViewport(viewport);
|
||||
}
|
||||
|
||||
public static AetheriaUnityRtsViewportDocuments MapViewportDocuments(
|
||||
AetheriaRuntimeRtsViewportBounds viewport,
|
||||
string runtimeId = "")
|
||||
{
|
||||
return AetheriaUnityRtsViewportDocuments.OpenMap(RuntimeState(runtimeId), viewport);
|
||||
}
|
||||
|
||||
public static AetheriaUnityRtsViewportDocuments ZonePresentationDocuments(
|
||||
AetheriaRuntimeRtsViewportBounds viewport,
|
||||
string runtimeId = "")
|
||||
{
|
||||
return AetheriaUnityRtsViewportDocuments.OpenZonePresentation(RuntimeState(runtimeId), viewport);
|
||||
}
|
||||
|
||||
public static AetheriaUnityRtsViewportDocuments RenderSplatViewportDocuments(
|
||||
AetheriaRuntimeRtsViewportBounds viewport,
|
||||
string runtimeId = "")
|
||||
{
|
||||
return AetheriaUnityRtsViewportDocuments.OpenRenderSplats(RuntimeState(runtimeId), viewport);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonFrameDocument CurrentDaemonFrame(string runtimeId = "")
|
||||
{
|
||||
return RuntimeState(runtimeId).CurrentDaemonFrame();
|
||||
|
|
|
|||
Loading…
Reference in a new issue