Fold target contact reads into presentation

This commit is contained in:
Meta Vens 2026-06-29 12:05:25 +01:00
commit 4999c4f978
6 changed files with 199 additions and 207 deletions

View file

@ -21,7 +21,6 @@ public class ActionGameManager : MonoBehaviour
private AetheriaUnityObservedZoneContextFactory _observedZoneContextFactory;
private AetheriaUnityPilotFrameController _pilotFrameController;
private AetheriaUnityPilotOperationController _pilotOperationController;
private AetheriaUnityObservedTargetQuery _observedTargetQuery;
private AetheriaUnityObservedFrameApplier _observedFrameApplier;
private AetheriaUnityEntityBlueprintMaterializer _entityBlueprintMaterializer;
private AetheriaUnityMenuShell _menuShell;
@ -85,8 +84,6 @@ public class ActionGameManager : MonoBehaviour
_observedEntityIndex,
() => _viewDirection,
() => CurrentEntity);
private AetheriaUnityObservedTargetQuery ObservedTargetQuery =>
_observedTargetQuery ??= new AetheriaUnityObservedTargetQuery(_observedEntityIndex);
private AetheriaUnityObservedFrameApplier ObservedFrameApplier =>
_observedFrameApplier ??= new AetheriaUnityObservedFrameApplier(
ResolveDaemonObserver,
@ -113,7 +110,7 @@ public class ActionGameManager : MonoBehaviour
GameplayUI = GameplayUI,
ResolveCurrentEntity = () => CurrentEntity,
IsCurrentEntityUndocked = IsCurrentEntityObservedUndocked,
ResolveObservedTarget = entity => ObservedTargetQuery.GetObservedTarget(entity),
ResolveObservedTarget = entity => _targetPresentation.GetObservedTarget(entity),
SetPaused = paused => GameplayLoopShell.Paused = paused,
EnablePlayerInput = EnablePlayerInput,
DisablePlayerInput = DisablePlayerInput,
@ -293,7 +290,6 @@ public class ActionGameManager : MonoBehaviour
private void OnDisable()
{
_gameplayInputShell?.Dispose();
_observedTargetQuery = null;
AetheriaUnityRuntimeClientProvider.Dispose();
}
@ -307,8 +303,7 @@ public class ActionGameManager : MonoBehaviour
SceneWiring.ConfigureTargetPresentation(
_targetPresentation,
boot.RuntimeCatalog,
_observedEntityIndex,
ObservedTargetQuery);
_observedEntityIndex);
SceneWiring.ConfigureInventoryDragSession(_dragSession);
SceneWiring.ConfigureActionBarPresentation(
_actionBarPresentation,

View file

@ -78,8 +78,7 @@ public sealed class AetheriaUnityGameplaySceneWiring
public void ConfigureTargetPresentation(
AetheriaUnityTargetPresentation presentation,
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
AetheriaUnityObservedEntityIndex observedEntityIndex,
AetheriaUnityObservedTargetQuery observedTargetQuery)
AetheriaUnityObservedEntityIndex observedEntityIndex)
{
if (presentation == null)
return;
@ -99,10 +98,22 @@ public sealed class AetheriaUnityGameplaySceneWiring
observedEntityIndex.TryResolveEntityByDaemonIndex(daemonEntityIndex, out var entity)
? entity
: null;
presentation.ResolveTarget = observedTargetQuery.GetObservedTarget;
presentation.ResolveInfoGathered = observedTargetQuery.GetObservedInfoGathered;
presentation.ResolveHostileContact = observedTargetQuery.IsObservedHostileContact;
presentation.ResolveVisibleContacts = observedTargetQuery.GetObservedVisibleContacts;
presentation.ResolveZoneContacts = ReadZoneContacts;
}
private static AetheriaRuntimeZoneContactsDocument ReadZoneContacts()
{
try
{
return AetheriaUnityRuntimeClientProvider
.RuntimeState("unity-target-presentation")
.CurrentZoneContacts();
}
catch (Exception ex)
{
Debug.LogWarning($"Failed to read Aetheria zone contacts for target presentation: {ex.Message}");
return null;
}
}
public void ConfigureInventoryDragSession(AetheriaUnityDragSession dragSession)

View file

@ -1,101 +0,0 @@
/* 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/. */
using System;
using System.Linq;
using GameCult.Aetheria.State.Verse;
public sealed class AetheriaUnityObservedTargetQuery
{
private readonly AetheriaUnityObservedEntityIndex _entityIndex;
public AetheriaUnityObservedTargetQuery(AetheriaUnityObservedEntityIndex entityIndex)
{
_entityIndex = entityIndex ?? throw new ArgumentNullException(nameof(entityIndex));
}
public Entity GetObservedTarget(Entity observer)
{
if (TryQueryEntityTarget(observer, out var targetEntityIndex) &&
_entityIndex.TryResolveEntityByDaemonIndex(targetEntityIndex, out var targetEntity))
{
return targetEntity;
}
return null;
}
public float GetObservedInfoGathered(Entity observer, Entity target)
{
return TryQueryEntityContact(observer, target, out var contact)
? (float)contact.InfoGathered
: 0f;
}
public bool IsObservedHostileContact(Entity observer, Entity target)
{
return TryQueryEntityContact(observer, target, out var contact) && contact.Hostile;
}
public AetheriaRuntimeZoneContactRow[] GetObservedVisibleContacts(
Entity observer,
double minimumInfoGathered,
bool visibleOnly)
{
var contacts = ReadZoneContacts();
if (observer == null || contacts == null)
return Array.Empty<AetheriaRuntimeZoneContactRow>();
return (contacts.Contacts ?? Array.Empty<AetheriaRuntimeZoneContactRow>())
.Where(contact =>
contact.ObserverEntityIndex == observer.DaemonEntityIndex &&
contact.InfoGathered > minimumInfoGathered &&
(!visibleOnly || contact.Visible))
.ToArray();
}
private bool TryQueryEntityContact(
Entity observer,
Entity target,
out AetheriaRuntimeZoneContactRow contact)
{
contact = default;
if (observer == null || target == null)
return false;
contact = (ReadZoneContacts()?.Contacts ?? Array.Empty<AetheriaRuntimeZoneContactRow>())
.FirstOrDefault(row =>
row.ObserverEntityIndex == observer.DaemonEntityIndex &&
row.TargetEntityIndex == target.DaemonEntityIndex);
return contact != null;
}
private bool TryQueryEntityTarget(
Entity observer,
out int targetEntityIndex)
{
targetEntityIndex = -1;
if (observer == null)
return false;
targetEntityIndex = (ReadZoneContacts()?.Targets ?? Array.Empty<AetheriaRuntimeZoneTargetRow>())
.FirstOrDefault(row => row.EntityIndex == observer.DaemonEntityIndex)
?.TargetEntityIndex ?? -1;
return targetEntityIndex >= 0;
}
private AetheriaRuntimeZoneContactsDocument ReadZoneContacts()
{
try
{
return AetheriaUnityRuntimeClientProvider
.RuntimeState("unity-observed-target-query")
.CurrentZoneContacts();
}
catch
{
return null;
}
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 735b01f66e370d741bd3a5130eb166c7

View file

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GameCult.Aetheria.State.Verse;
using UnityEngine;
using UnityEngine.UI;
@ -30,14 +31,11 @@ public sealed class AetheriaUnityTargetPresentation
public Image TargetShieldsFill { get; set; }
public AetheriaRuntimeCatalogSnapshot RuntimeCatalog { get; set; }
public Func<int, Entity> ResolveEntity { get; set; }
public Func<Entity, Entity> ResolveTarget { get; set; }
public Func<Entity, Entity, float> ResolveInfoGathered { get; set; }
public Func<Entity, Entity, bool> ResolveHostileContact { get; set; }
public Func<Entity, double, bool, AetheriaRuntimeZoneContactRow[]> ResolveVisibleContacts { get; set; }
public Func<AetheriaRuntimeZoneContactsDocument> ResolveZoneContacts { get; set; }
public Entity Tick(Entity currentEntity, float time)
{
var observedTarget = ResolveTarget?.Invoke(currentEntity);
var observedTarget = GetObservedTarget(currentEntity);
ReconcileVisibleTargetIndicators(currentEntity);
UpdateVisibleIndicatorPresentation(
_visibleHostileIndicators,
@ -63,10 +61,10 @@ public sealed class AetheriaUnityTargetPresentation
if (currentEntity != null && ZoneRenderer != null)
{
var renderSettings = ZoneRenderer.RenderSettings;
var contacts = ResolveVisibleContacts?.Invoke(
var contacts = GetObservedVisibleContacts(
currentEntity,
renderSettings.TargetDetectionInfoThreshold,
true) ?? Array.Empty<AetheriaRuntimeZoneContactRow>();
true);
foreach (var contact in contacts)
{
@ -113,7 +111,7 @@ public sealed class AetheriaUnityTargetPresentation
return;
}
var observedTarget = ResolveTarget?.Invoke(currentEntity);
var observedTarget = GetObservedTarget(currentEntity);
ViewDot.Target = entityInstance.LookAtPoint.position;
if (observedTarget != null && TargetIndicator != null)
TargetIndicator.Target = observedTarget.Position;
@ -132,7 +130,7 @@ public sealed class AetheriaUnityTargetPresentation
{
var showLockingIndicator = targetLock.Lock > .01f &&
observedTarget != null &&
ResolveHostileContact?.Invoke(currentEntity, observedTarget) == true;
IsObservedHostileContact(currentEntity, observedTarget);
indicator.gameObject.SetActive(showLockingIndicator);
if (!showLockingIndicator)
continue;
@ -166,7 +164,7 @@ public sealed class AetheriaUnityTargetPresentation
continue;
}
var infoGathered = ResolveInfoGathered?.Invoke(indicator.Key, currentEntity) ?? 0f;
var infoGathered = GetObservedInfoGathered(indicator.Key, currentEntity);
indicator.Value.Fill.fillAmount = (float)renderSettings.NormalizeDetectionProgress(infoGathered);
indicator.Value.Fill.enabled = !blinkSpottedTargets ||
renderSettings.ResolveTargetSpottedFillEnabled(infoGathered, time);
@ -179,8 +177,8 @@ public sealed class AetheriaUnityTargetPresentation
return;
var renderSettings = ZoneRenderer.RenderSettings;
var targetInfoGathered = ResolveInfoGathered?.Invoke(currentEntity, target) ?? 0f;
var visibilityToTarget = ResolveInfoGathered?.Invoke(target, currentEntity) ?? 0f;
var targetInfoGathered = GetObservedInfoGathered(currentEntity, target);
var visibilityToTarget = GetObservedInfoGathered(target, currentEntity);
TargetVisibilityFill.fillAmount = (float)renderSettings.NormalizeTargetVisibilityFill(targetInfoGathered);
VisibilityToTargetFill.fillAmount = (float)renderSettings.NormalizeVisibilityToTargetFill(visibilityToTarget);
var targetHull = RuntimeCatalog?.FindItem(target.Hull, x => x.ItemKey);
@ -228,4 +226,71 @@ public sealed class AetheriaUnityTargetPresentation
indicator.GetComponent<Prototype>().ReturnToPool();
indicators.Clear();
}
public Entity GetObservedTarget(Entity observer)
{
if (TryQueryEntityTarget(observer, out var targetEntityIndex))
return ResolveEntity?.Invoke(targetEntityIndex);
return null;
}
private float GetObservedInfoGathered(Entity observer, Entity target)
{
return TryQueryEntityContact(observer, target, out var contact)
? (float)contact.InfoGathered
: 0f;
}
private bool IsObservedHostileContact(Entity observer, Entity target)
{
return TryQueryEntityContact(observer, target, out var contact) && contact.Hostile;
}
private AetheriaRuntimeZoneContactRow[] GetObservedVisibleContacts(
Entity observer,
double minimumInfoGathered,
bool visibleOnly)
{
var contacts = ResolveZoneContacts?.Invoke();
if (observer == null || contacts == null)
return Array.Empty<AetheriaRuntimeZoneContactRow>();
return (contacts.Contacts ?? Array.Empty<AetheriaRuntimeZoneContactRow>())
.Where(contact =>
contact.ObserverEntityIndex == observer.DaemonEntityIndex &&
contact.InfoGathered > minimumInfoGathered &&
(!visibleOnly || contact.Visible))
.ToArray();
}
private bool TryQueryEntityContact(
Entity observer,
Entity target,
out AetheriaRuntimeZoneContactRow contact)
{
contact = default;
if (observer == null || target == null)
return false;
contact = (ResolveZoneContacts?.Invoke()?.Contacts ?? Array.Empty<AetheriaRuntimeZoneContactRow>())
.FirstOrDefault(row =>
row.ObserverEntityIndex == observer.DaemonEntityIndex &&
row.TargetEntityIndex == target.DaemonEntityIndex);
return contact != null;
}
private bool TryQueryEntityTarget(
Entity observer,
out int targetEntityIndex)
{
targetEntityIndex = -1;
if (observer == null)
return false;
targetEntityIndex = (ResolveZoneContacts?.Invoke()?.Targets ?? Array.Empty<AetheriaRuntimeZoneTargetRow>())
.FirstOrDefault(row => row.EntityIndex == observer.DaemonEntityIndex)
?.TargetEntityIndex ?? -1;
return targetEntityIndex >= 0;
}
}