Drive entity visibility from daemon contacts
This commit is contained in:
parent
9af4f4f2da
commit
298dda56b3
4 changed files with 143 additions and 23 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue