Make game viewport authority runtime-neutral

This commit is contained in:
Meta Vens 2026-07-05 19:56:18 +01:00
commit 911bb72f69
45 changed files with 424 additions and 369 deletions

View file

@ -252,9 +252,9 @@ public sealed class AetheriaRenderSplatRasterizer : MonoBehaviour
Graphics.ExecuteCommandBuffer(_commandBuffer);
}
private static Matrix4x4 BuildViewportToClip(AetheriaRuntimeRtsViewportBounds viewport)
private static Matrix4x4 BuildViewportToClip(AetheriaRuntimeViewportBounds viewport)
{
viewport ??= new AetheriaRuntimeRtsViewportBounds();
viewport ??= new AetheriaRuntimeViewportBounds();
var minX = (float)math.min(viewport.MinX, viewport.MaxX);
var minY = (float)math.min(viewport.MinY, viewport.MaxY);
var maxX = (float)math.max(viewport.MinX, viewport.MaxX);

View file

@ -43,9 +43,9 @@ public sealed class AetheriaSceneRenderSplatSource : MonoBehaviour
[SerializeField]
private AetheriaSceneRenderSplatFixture[] fixtures = Array.Empty<AetheriaSceneRenderSplatFixture>();
public AetheriaRuntimeRenderSplatsViewportDocument BuildDocument(AetheriaRuntimeRtsViewportBounds viewport)
public AetheriaRuntimeRenderSplatsViewportDocument BuildDocument(AetheriaRuntimeViewportBounds viewport)
{
viewport ??= new AetheriaRuntimeRtsViewportBounds();
viewport ??= new AetheriaRuntimeViewportBounds();
var normalizedViewport = Normalize(viewport);
var layers = BuildLayers();
var layerIndices = new Dictionary<string, int>(StringComparer.Ordinal);
@ -70,9 +70,9 @@ public sealed class AetheriaSceneRenderSplatSource : MonoBehaviour
};
}
private static AetheriaRuntimeRtsViewportBounds Normalize(AetheriaRuntimeRtsViewportBounds viewport)
private static AetheriaRuntimeViewportBounds Normalize(AetheriaRuntimeViewportBounds viewport)
{
return new AetheriaRuntimeRtsViewportBounds
return new AetheriaRuntimeViewportBounds
{
MinX = Math.Min(viewport.MinX, viewport.MaxX),
MinY = Math.Min(viewport.MinY, viewport.MaxY),

View file

@ -2,15 +2,15 @@ using System;
using GameCult.Aetheria.State.Verse;
using GameCult.Mesh;
public sealed class AetheriaUnityRtsViewportDocuments : IDisposable
public sealed class AetheriaUnityGameViewportDocuments : IDisposable
{
private readonly CultMeshReactiveDocument<AetheriaRuntimeZoneContactsDocument> _contacts;
private readonly CultMeshReactiveDocument<AetheriaRuntimeObjectsViewportDocument> _objectsViewport;
private readonly CultMeshReactiveDocument<AetheriaRuntimeRenderSplatsViewportDocument> _renderSplatsViewport;
private AetheriaUnityRtsViewportDocuments(
private AetheriaUnityGameViewportDocuments(
AetheriaClientState state,
AetheriaRuntimeRtsViewportBounds viewport,
AetheriaRuntimeViewportBounds viewport,
bool bindContacts,
bool bindObjects,
bool bindRenderSplats)
@ -26,17 +26,17 @@ public sealed class AetheriaUnityRtsViewportDocuments : IDisposable
_renderSplatsViewport = bindRenderSplats ? state.RenderSplatsViewport(viewport).Reactive() : null;
}
public AetheriaRuntimeRtsViewportBounds Viewport { get; }
public AetheriaRuntimeViewportBounds Viewport { get; }
public AetheriaRuntimeZoneContactsDocument CurrentContacts => _contacts?.Current;
public AetheriaRuntimeObjectsViewportDocument CurrentObjectsViewport => _objectsViewport?.Current;
public AetheriaRuntimeRenderSplatsViewportDocument CurrentRenderSplatsViewport => _renderSplatsViewport?.Current;
public static AetheriaUnityRtsViewportDocuments OpenMap(
public static AetheriaUnityGameViewportDocuments OpenMap(
AetheriaClientState state,
AetheriaRuntimeRtsViewportBounds viewport)
AetheriaRuntimeViewportBounds viewport)
{
return new AetheriaUnityRtsViewportDocuments(
return new AetheriaUnityGameViewportDocuments(
state,
viewport,
bindContacts: false,
@ -44,11 +44,11 @@ public sealed class AetheriaUnityRtsViewportDocuments : IDisposable
bindRenderSplats: true);
}
public static AetheriaUnityRtsViewportDocuments OpenZonePresentation(
public static AetheriaUnityGameViewportDocuments OpenZonePresentation(
AetheriaClientState state,
AetheriaRuntimeRtsViewportBounds viewport)
AetheriaRuntimeViewportBounds viewport)
{
return new AetheriaUnityRtsViewportDocuments(
return new AetheriaUnityGameViewportDocuments(
state,
viewport,
bindContacts: true,
@ -56,11 +56,11 @@ public sealed class AetheriaUnityRtsViewportDocuments : IDisposable
bindRenderSplats: false);
}
public static AetheriaUnityRtsViewportDocuments OpenRenderSplats(
public static AetheriaUnityGameViewportDocuments OpenRenderSplats(
AetheriaClientState state,
AetheriaRuntimeRtsViewportBounds viewport)
AetheriaRuntimeViewportBounds viewport)
{
return new AetheriaUnityRtsViewportDocuments(
return new AetheriaUnityGameViewportDocuments(
state,
viewport,
bindContacts: false,
@ -68,7 +68,7 @@ public sealed class AetheriaUnityRtsViewportDocuments : IDisposable
bindRenderSplats: true);
}
public bool Matches(AetheriaRuntimeRtsViewportBounds viewport)
public bool Matches(AetheriaRuntimeViewportBounds viewport)
{
return SameViewport(Viewport, viewport);
}
@ -81,8 +81,8 @@ public sealed class AetheriaUnityRtsViewportDocuments : IDisposable
}
public static bool SameViewport(
AetheriaRuntimeRtsViewportBounds left,
AetheriaRuntimeRtsViewportBounds right)
AetheriaRuntimeViewportBounds left,
AetheriaRuntimeViewportBounds right)
{
if (left == null || right == null)
return false;

View file

@ -26,7 +26,7 @@ public sealed class AetheriaUnityRenderSplatViewportSource : MonoBehaviour
private bool renderInLateUpdate = true;
private float _nextRefreshTime;
private AetheriaUnityRtsViewportDocuments _viewportDocuments;
private AetheriaUnityGameViewportDocuments _viewportDocuments;
private AetheriaRuntimeRenderSplatsViewportDocument _fallbackRenderSplatsViewport;
private string _lastWarningMessage = "";
@ -150,19 +150,19 @@ public sealed class AetheriaUnityRenderSplatViewportSource : MonoBehaviour
}
private static AetheriaRuntimeRenderSplatsViewportDocument EmptyRenderSplatsViewport(
AetheriaRuntimeRtsViewportBounds viewport)
AetheriaRuntimeViewportBounds viewport)
{
return new AetheriaRuntimeRenderSplatsViewportDocument
{
PublishedAtUtc = DateTimeOffset.UtcNow.ToString("O"),
Viewport = viewport ?? new AetheriaRuntimeRtsViewportBounds()
Viewport = viewport ?? new AetheriaRuntimeViewportBounds()
};
}
private AetheriaRuntimeRtsViewportBounds ResolveViewportBounds()
private AetheriaRuntimeViewportBounds ResolveViewportBounds()
{
var halfSize = size * 0.5f;
return new AetheriaRuntimeRtsViewportBounds
return new AetheriaRuntimeViewportBounds
{
MinX = position.x - halfSize.x,
MinY = position.y - halfSize.y,

View file

@ -77,25 +77,25 @@ public static class AetheriaUnityRuntimeClientProvider
return RuntimeClient(stateBoot, runtimeId).State;
}
public static AetheriaUnityRtsViewportDocuments MapViewportDocuments(
AetheriaRuntimeRtsViewportBounds viewport,
public static AetheriaUnityGameViewportDocuments MapViewportDocuments(
AetheriaRuntimeViewportBounds viewport,
string runtimeId = "")
{
return AetheriaUnityRtsViewportDocuments.OpenMap(RuntimeState(runtimeId), viewport);
return AetheriaUnityGameViewportDocuments.OpenMap(RuntimeState(runtimeId), viewport);
}
public static AetheriaUnityRtsViewportDocuments ZonePresentationDocuments(
AetheriaRuntimeRtsViewportBounds viewport,
public static AetheriaUnityGameViewportDocuments ZonePresentationDocuments(
AetheriaRuntimeViewportBounds viewport,
string runtimeId = "")
{
return AetheriaUnityRtsViewportDocuments.OpenZonePresentation(RuntimeState(runtimeId), viewport);
return AetheriaUnityGameViewportDocuments.OpenZonePresentation(RuntimeState(runtimeId), viewport);
}
public static AetheriaUnityRtsViewportDocuments RenderSplatViewportDocuments(
AetheriaRuntimeRtsViewportBounds viewport,
public static AetheriaUnityGameViewportDocuments RenderSplatViewportDocuments(
AetheriaRuntimeViewportBounds viewport,
string runtimeId = "")
{
return AetheriaUnityRtsViewportDocuments.OpenRenderSplats(RuntimeState(runtimeId), viewport);
return AetheriaUnityGameViewportDocuments.OpenRenderSplats(RuntimeState(runtimeId), viewport);
}
public static AetheriaUnityDaemonRenderDocuments DaemonRenderDocuments(

View file

@ -181,7 +181,7 @@ public class DaemonRuntimeDocumentTests
.LatestAsync()
.GetAwaiter()
.GetResult();
var viewport = new AetheriaRuntimeRtsViewportBounds
var viewport = new AetheriaRuntimeViewportBounds
{
MinX = -100,
MinY = -100,
@ -228,7 +228,7 @@ public class DaemonRuntimeDocumentTests
using var zoneDetailsReactive = client.State.ZoneDetails(0).Reactive();
using var selectedObjectReactive = client.State.SelectedObject(0).Reactive();
using var inventoryReactive = client.State.Inventory(0).Reactive();
using var mapViewportReactive = client.State.RtsViewport(viewport).Reactive();
using var mapViewportReactive = client.State.GameViewport(viewport).Reactive();
using var objectsViewportReactive = client.State.ObjectsViewport(viewport).Reactive();
using var gravityViewportReactive = client.State.GravityViewport(viewport).Reactive();
using var renderSplatsViewportReactive = client.State.RenderSplatsViewport(viewport).Reactive();
@ -307,7 +307,7 @@ public class DaemonRuntimeDocumentTests
Assert.AreEqual(AetheriaRuntimeVerseHostSettingsDocument.SchemaId, verseHostSettings.Schema);
Assert.AreEqual(AetheriaRuntimeVerseHostSettingsDocument.SchemaId, verseHostSettingsReactive.Current.Schema);
Assert.AreEqual(AetheriaRuntimeDaemonSchemas.ObjectsViewport, objectsViewport.Schema);
Assert.AreEqual(AetheriaRuntimeDaemonSchemas.RtsViewport, mapViewportReactive.Current.Schema);
Assert.AreEqual(AetheriaRuntimeDaemonSchemas.GameViewport, mapViewportReactive.Current.Schema);
Assert.AreEqual(AetheriaRuntimeDaemonSchemas.ObjectsViewport, objectsViewportReactive.Current.Schema);
Assert.AreEqual(AetheriaRuntimeDaemonSchemas.GravityViewport, gravityViewportReactive.Current.Schema);
Assert.AreEqual(AetheriaRuntimeDaemonSchemas.RenderSplatsViewport, renderSplatsViewportReactive.Current.Schema);
@ -1875,7 +1875,7 @@ public class DaemonRuntimeDocumentTests
0.02,
renderSettings: renderSettings);
var zoneRender = AetheriaRuntimeRtsDocuments.ZoneRender(frame);
var zoneRender = AetheriaRuntimeGameDocuments.ZoneRender(frame);
Assert.AreEqual(1, zoneRender.WormholeExits.Count);
Assert.AreEqual(0.8 * 25, zoneRender.WormholeExits[0].PositionX, 0.0001);
@ -1946,15 +1946,15 @@ public class DaemonRuntimeDocumentTests
77,
12.1,
0.1);
var viewport = new AetheriaRuntimeRtsViewportBounds
var viewport = new AetheriaRuntimeViewportBounds
{
MinX = -100,
MinY = -100,
MaxX = 140,
MaxY = 100
};
var zoneRender = AetheriaRuntimeRtsDocuments.ZoneRender(frame);
var objectsViewport = AetheriaRuntimeRtsDocuments.ObjectsViewport(frame, viewport);
var zoneRender = AetheriaRuntimeGameDocuments.ZoneRender(frame);
var objectsViewport = AetheriaRuntimeGameDocuments.ObjectsViewport(frame, viewport);
Assert.AreEqual(zone.Projectiles.Count, zoneRender.Projectiles.Count);
Assert.IsTrue(objectsViewport.Objects.Any(obj =>

View file

@ -41,7 +41,7 @@ public class MapRenderer : MonoBehaviour
private RenderTexture _mapTexture;
private int2 _size;
private bool _init;
private AetheriaUnityRtsViewportDocuments _viewportDocuments;
private AetheriaUnityGameViewportDocuments _viewportDocuments;
private float _nextViewportRefreshTime;
private readonly List<RawImage> _rtsIconPool = new List<RawImage>();
@ -183,7 +183,7 @@ public class MapRenderer : MonoBehaviour
if (RtsIconRoot == null)
return;
var objects = _viewportDocuments?.CurrentObjectsViewport?.Objects ?? Array.Empty<AetheriaRuntimeRtsViewportObject>();
var objects = _viewportDocuments?.CurrentObjectsViewport?.Objects ?? Array.Empty<AetheriaRuntimeViewportObject>();
for (var i = 0; i < objects.Count; i++)
{
var icon = ResolveRtsIcon(i);
@ -219,7 +219,7 @@ public class MapRenderer : MonoBehaviour
return _rtsIconPool[index];
}
private void ApplyRtsIcon(RawImage icon, AetheriaRuntimeRtsViewportObject obj)
private void ApplyRtsIcon(RawImage icon, AetheriaRuntimeViewportObject obj)
{
if (icon == null || obj == null)
return;
@ -257,7 +257,7 @@ public class MapRenderer : MonoBehaviour
(v - 0.5f) * rootRect.height);
}
private static Color ResolveIconColor(AetheriaRuntimeRtsViewportObject obj)
private static Color ResolveIconColor(AetheriaRuntimeViewportObject obj)
{
var color = obj.Controlled
? new Color(0.3f, 0.9f, 1.0f, 1.0f)
@ -290,13 +290,13 @@ public class MapRenderer : MonoBehaviour
RtsIconRoot.gameObject.SetActive(active);
}
private AetheriaRuntimeRtsViewportBounds ResolveViewportBounds()
private AetheriaRuntimeViewportBounds ResolveViewportBounds()
{
var screenHeight = _size.y <= 0 ? Math.Max(1, Screen.height) : _size.y;
var screenWidth = _size.x <= 0 ? Math.Max(1, Screen.width) : _size.x;
var halfHeight = screenHeight * Scale * .5f;
var halfWidth = screenWidth * Scale * .5f;
return new AetheriaRuntimeRtsViewportBounds
return new AetheriaRuntimeViewportBounds
{
MinX = Position.x - halfWidth,
MinY = Position.y - halfHeight,

View file

@ -423,7 +423,7 @@ public class SectorMap : MonoBehaviour
return new AetheriaRuntimeRenderSplatsViewportDocument
{
Schema = AetheriaRuntimeDaemonSchemas.RenderSplatsViewport,
Viewport = new AetheriaRuntimeRtsViewportBounds
Viewport = new AetheriaRuntimeViewportBounds
{
MinX = minX - padding,
MinY = minY - padding,

View file

@ -1,4 +1,4 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
@ -250,10 +250,10 @@ public class VolumeSampling : MonoBehaviour
: Vector2.zero;
}
private static AetheriaRuntimeRtsViewportBounds BuildViewportBounds(Vector2 center, Vector2 size)
private static AetheriaRuntimeViewportBounds BuildViewportBounds(Vector2 center, Vector2 size)
{
var halfSize = size * 0.5f;
return new AetheriaRuntimeRtsViewportBounds
return new AetheriaRuntimeViewportBounds
{
MinX = center.x - halfSize.x,
MinY = center.y - halfSize.y,

View file

@ -120,7 +120,7 @@ public class ZoneRenderer : MonoBehaviour
Array.Empty<AetheriaRuntimeZoneRenderAsteroidBeltPose>();
private IReadOnlyList<AetheriaRuntimeBodySnapshotCommit> _zoneRenderBodies =
Array.Empty<AetheriaRuntimeBodySnapshotCommit>();
private AetheriaUnityRtsViewportDocuments _zonePresentationDocuments;
private AetheriaUnityGameViewportDocuments _zonePresentationDocuments;
public Dictionary<int, (GameObject gravity, CompassIcon icon)> WormholeInstances = new Dictionary<int, (GameObject, CompassIcon)>();
private List<ItemPickup> _loot = new List<ItemPickup>();
@ -768,9 +768,9 @@ public class ZoneRenderer : MonoBehaviour
center.y + range);
}
private static AetheriaRuntimeRtsViewportBounds ToViewportBounds(AetheriaRuntimeXzRect viewport)
private static AetheriaRuntimeViewportBounds ToViewportBounds(AetheriaRuntimeXzRect viewport)
{
return new AetheriaRuntimeRtsViewportBounds
return new AetheriaRuntimeViewportBounds
{
MinX = viewport.MinX,
MinY = viewport.MinZ,
@ -892,7 +892,7 @@ public class ZoneRenderer : MonoBehaviour
if (!TryCollectDaemonPresentationEntityIndicesFromSoa(viewport))
{
var objects = ResolveObjectsViewport(viewport);
foreach (var entity in objects?.Objects ?? Array.Empty<AetheriaRuntimeRtsViewportObject>())
foreach (var entity in objects?.Objects ?? Array.Empty<AetheriaRuntimeViewportObject>())
{
if (entity != null && entity.EntityIndex >= 0)
_daemonPresentationEntityIndices.Add(entity.EntityIndex);