Drive entity visibility from daemon contacts
This commit is contained in:
parent
9af4f4f2da
commit
298dda56b3
4 changed files with 143 additions and 23 deletions
|
|
@ -1831,6 +1831,8 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"AetheriaRuntimeDaemonCompassMarker",
|
||||
"public static AetheriaRuntimeDaemonCompassMarker[] QueryCompassMarkers(",
|
||||
"public static int QueryCompassMarkers(",
|
||||
"public static int[] QueryVisibleEntityIndices(",
|
||||
"public static int QueryVisibleEntityIndices(",
|
||||
"BuildEntityMap(zone)"
|
||||
};
|
||||
|
||||
|
|
@ -1944,6 +1946,12 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"ZoneRenderer must query daemon compass markers instead of reading mirrored Unity entity visibility state.");
|
||||
}
|
||||
|
||||
if (zoneRenderer.Contains("VisibleEntities", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"ZoneRenderer must query daemon visible entity indices instead of subscribing to mirrored Unity visibility collections.");
|
||||
}
|
||||
|
||||
var requiredZoneRendererSymbols = new[]
|
||||
{
|
||||
"private AetheriaRuntimeZoneSnapshotCommit _daemonZoneSnapshot;",
|
||||
|
|
@ -1953,6 +1961,9 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"private readonly Dictionary<string, AetheriaRuntimeDaemonAsteroidBeltPose> _daemonAsteroidBeltPosesByBodyKey",
|
||||
"private readonly List<AetheriaRuntimeDaemonCompassMarker> _daemonCompassMarkers",
|
||||
"private readonly Dictionary<int, AetheriaRuntimeDaemonCompassMarker> _daemonCompassMarkersByEntityIndex",
|
||||
"private readonly List<int> _daemonVisibleEntityIndices",
|
||||
"private readonly HashSet<int> _daemonVisibleEntityIndicesSet",
|
||||
"private readonly HashSet<int> _visibleDaemonEntityIndices",
|
||||
"public void LoadZone(Zone zone, AetheriaRuntimeZoneSnapshotCommit daemonZone = null)",
|
||||
"_daemonZoneSnapshot = daemonZone;",
|
||||
"AetheriaRuntimeDaemonRenderQueries.EvaluateGravityTerrainHeight(",
|
||||
|
|
@ -1968,6 +1979,7 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"AetheriaRuntimeDaemonRenderQueries.QueryAsteroidBeltPoses(_daemonZoneSnapshot, _daemonAsteroidBeltPoses);",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryAsteroidInstancePoses(",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryCompassMarkers(",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryVisibleEntityIndices(",
|
||||
"_daemonCompassMarkersByEntityIndex.TryGetValue(entityInstance.Entity.DaemonEntityIndex, out var marker)",
|
||||
"_daemonBodyPosesByBodyKey.TryGetValue(planet.Key, out var pose)",
|
||||
"_daemonAsteroidBeltPosesByBodyKey.TryGetValue(key, out var beltPose)",
|
||||
|
|
|
|||
|
|
@ -1027,6 +1027,62 @@ public class DaemonRuntimeDocumentTests
|
|||
Assert.IsTrue(markers[0].Hostile);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonRenderQueriesPublishVisibleEntityIndicesFromObserverContacts()
|
||||
{
|
||||
var zone = new AetheriaRuntimeZoneSnapshotCommit
|
||||
{
|
||||
Entities = new[]
|
||||
{
|
||||
new AetheriaRuntimeEntitySnapshotCommit
|
||||
{
|
||||
EntityIndex = 10,
|
||||
Contacts = new[]
|
||||
{
|
||||
new AetheriaRuntimeEntityContactCommit
|
||||
{
|
||||
TargetEntityIndex = 11,
|
||||
InfoGathered = 0.7,
|
||||
Visible = true
|
||||
},
|
||||
new AetheriaRuntimeEntityContactCommit
|
||||
{
|
||||
TargetEntityIndex = 12,
|
||||
InfoGathered = 0.3,
|
||||
Visible = true
|
||||
},
|
||||
new AetheriaRuntimeEntityContactCommit
|
||||
{
|
||||
TargetEntityIndex = 13,
|
||||
InfoGathered = 0.9,
|
||||
Visible = false
|
||||
},
|
||||
new AetheriaRuntimeEntityContactCommit
|
||||
{
|
||||
TargetEntityIndex = 99,
|
||||
InfoGathered = 0.9,
|
||||
Visible = true
|
||||
}
|
||||
}
|
||||
},
|
||||
new AetheriaRuntimeEntitySnapshotCommit { EntityIndex = 11 },
|
||||
new AetheriaRuntimeEntitySnapshotCommit { EntityIndex = 12 },
|
||||
new AetheriaRuntimeEntitySnapshotCommit { EntityIndex = 13 }
|
||||
}
|
||||
};
|
||||
|
||||
var visible = new List<int>();
|
||||
var count = AetheriaRuntimeDaemonRenderQueries.QueryVisibleEntityIndices(
|
||||
zone,
|
||||
10,
|
||||
0.5,
|
||||
visible);
|
||||
|
||||
Assert.AreEqual(2, count);
|
||||
Assert.AreEqual(10, visible[0]);
|
||||
Assert.AreEqual(11, visible[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoaViewIndexRejectsInvalidRenderGroups()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Cinemachine;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using Object = UnityEngine.Object;
|
||||
|
|
@ -81,7 +80,6 @@ public class ZoneRenderer : MonoBehaviour
|
|||
private PlanetObject _root;
|
||||
private bool _rootFound;
|
||||
private Entity _perspectiveEntity;
|
||||
private IDisposable[] _perspectiveSubscriptions = new IDisposable[2];
|
||||
private PlanetObject[] _suns;
|
||||
private bool _showAsteroidUI;
|
||||
private AetheriaRuntimeZoneSnapshotCommit _daemonZoneSnapshot;
|
||||
|
|
@ -98,6 +96,9 @@ public class ZoneRenderer : MonoBehaviour
|
|||
new List<AetheriaRuntimeDaemonCompassMarker>();
|
||||
private readonly Dictionary<int, AetheriaRuntimeDaemonCompassMarker> _daemonCompassMarkersByEntityIndex =
|
||||
new Dictionary<int, AetheriaRuntimeDaemonCompassMarker>();
|
||||
private readonly List<int> _daemonVisibleEntityIndices = new List<int>();
|
||||
private readonly HashSet<int> _daemonVisibleEntityIndicesSet = new HashSet<int>();
|
||||
private readonly HashSet<int> _visibleDaemonEntityIndices = new HashSet<int>();
|
||||
|
||||
public Dictionary<Wormhole, (GameObject gravity, CompassIcon icon)> WormholeInstances = new Dictionary<Wormhole, (GameObject, CompassIcon)>();
|
||||
private List<ItemPickup> _loot = new List<ItemPickup>();
|
||||
|
|
@ -111,28 +112,11 @@ public class ZoneRenderer : MonoBehaviour
|
|||
get => _perspectiveEntity;
|
||||
set
|
||||
{
|
||||
//if (_perspectiveEntity == value) return;
|
||||
_perspectiveEntity = value;
|
||||
_perspectiveSubscriptions[0]?.Dispose();
|
||||
_perspectiveSubscriptions[1]?.Dispose();
|
||||
if (value == null)
|
||||
{
|
||||
foreach (var e in EntityInstances.Values)
|
||||
e.FadeOut(EntityFadeTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var entity in EntityInstances.Values)
|
||||
entity.FadeOut(EntityFadeTime);
|
||||
foreach (var entity in value.VisibleEntities)
|
||||
EntityInstances[entity].FadeIn(EntityFadeTime);
|
||||
EntityInstances[value].FadeIn(EntityFadeTime);
|
||||
_perspectiveSubscriptions[0] = value.VisibleEntities.ObserveAdd()
|
||||
.Subscribe(add => EntityInstances[add.Value].FadeIn(EntityFadeTime));
|
||||
_perspectiveSubscriptions[1] = value.VisibleEntities.ObserveRemove()
|
||||
.Where(removeEvent => EntityInstances.ContainsKey(removeEvent.Value))
|
||||
.Subscribe(removeEvent => EntityInstances[removeEvent.Value].FadeOut(EntityFadeTime));
|
||||
}
|
||||
_visibleDaemonEntityIndices.Clear();
|
||||
foreach (var entity in EntityInstances.Values)
|
||||
entity.FadeOut(EntityFadeTime);
|
||||
RefreshDaemonVisibleEntityInstances();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -475,6 +459,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
Shader.SetGlobalFloat("_AsteroidVerticalOffset", ActionGameManager.Instance.Settings.PlanetSettings.AsteroidVerticalOffset);
|
||||
RefreshDaemonBodyPoses();
|
||||
RefreshDaemonAsteroidBeltPoses();
|
||||
RefreshDaemonVisibleEntityInstances();
|
||||
RefreshDaemonCompassMarkers();
|
||||
|
||||
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(MainCamera);
|
||||
|
|
@ -636,6 +621,33 @@ public class ZoneRenderer : MonoBehaviour
|
|||
_daemonCompassMarkersByEntityIndex[marker.TargetEntityIndex] = marker;
|
||||
}
|
||||
|
||||
private void RefreshDaemonVisibleEntityInstances()
|
||||
{
|
||||
AetheriaRuntimeDaemonRenderQueries.QueryVisibleEntityIndices(
|
||||
_daemonZoneSnapshot,
|
||||
PerspectiveEntity?.DaemonEntityIndex ?? -1,
|
||||
Settings.GameplaySettings.TargetDetectionInfoThreshold,
|
||||
_daemonVisibleEntityIndices);
|
||||
_daemonVisibleEntityIndicesSet.Clear();
|
||||
foreach (var entityIndex in _daemonVisibleEntityIndices)
|
||||
_daemonVisibleEntityIndicesSet.Add(entityIndex);
|
||||
|
||||
foreach (var entityInstance in EntityInstances.Values)
|
||||
{
|
||||
var entityIndex = entityInstance.Entity?.DaemonEntityIndex ?? -1;
|
||||
var shouldBeVisible = entityIndex >= 0 && _daemonVisibleEntityIndicesSet.Contains(entityIndex);
|
||||
var isVisible = entityIndex >= 0 && _visibleDaemonEntityIndices.Contains(entityIndex);
|
||||
if (shouldBeVisible && !isVisible)
|
||||
entityInstance.FadeIn(EntityFadeTime);
|
||||
else if (!shouldBeVisible && isVisible)
|
||||
entityInstance.FadeOut(EntityFadeTime);
|
||||
}
|
||||
|
||||
_visibleDaemonEntityIndices.Clear();
|
||||
foreach (var entityIndex in _daemonVisibleEntityIndicesSet)
|
||||
_visibleDaemonEntityIndices.Add(entityIndex);
|
||||
}
|
||||
|
||||
private float GetTerrainHeight(float2 position)
|
||||
{
|
||||
return (float)AetheriaRuntimeDaemonRenderQueries.EvaluateGravityTerrainHeight(
|
||||
|
|
|
|||
|
|
@ -448,6 +448,46 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return markers.Count;
|
||||
}
|
||||
|
||||
public static int[] QueryVisibleEntityIndices(
|
||||
AetheriaRuntimeZoneSnapshotCommit? zone,
|
||||
int observerEntityIndex,
|
||||
double minimumInfoGathered)
|
||||
{
|
||||
var entityIndices = new List<int>();
|
||||
QueryVisibleEntityIndices(zone, observerEntityIndex, minimumInfoGathered, entityIndices);
|
||||
return entityIndices.Count == 0 ? Array.Empty<int>() : entityIndices.ToArray();
|
||||
}
|
||||
|
||||
public static int QueryVisibleEntityIndices(
|
||||
AetheriaRuntimeZoneSnapshotCommit? zone,
|
||||
int observerEntityIndex,
|
||||
double minimumInfoGathered,
|
||||
List<int> entityIndices)
|
||||
{
|
||||
if (entityIndices == null) throw new ArgumentNullException(nameof(entityIndices));
|
||||
entityIndices.Clear();
|
||||
if (zone == null || observerEntityIndex < 0)
|
||||
return 0;
|
||||
|
||||
var entities = BuildEntityMap(zone);
|
||||
if (!entities.TryGetValue(observerEntityIndex, out var observer))
|
||||
return 0;
|
||||
|
||||
entityIndices.Add(observer.EntityIndex);
|
||||
foreach (var contact in observer.Contacts ?? Array.Empty<AetheriaRuntimeEntityContactCommit>())
|
||||
{
|
||||
if (contact != null &&
|
||||
contact.Visible &&
|
||||
contact.InfoGathered > minimumInfoGathered &&
|
||||
entities.ContainsKey(contact.TargetEntityIndex))
|
||||
{
|
||||
entityIndices.Add(contact.TargetEntityIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return entityIndices.Count;
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonRenderGroupDocument[] QueryRenderGroups(
|
||||
AetheriaRuntimeDaemonSoaViewIndex? index,
|
||||
double minX,
|
||||
|
|
|
|||
Loading…
Reference in a new issue