Reconcile target indicators from daemon contacts
This commit is contained in:
parent
f9694b8695
commit
e0063a622e
3 changed files with 161 additions and 50 deletions
|
|
@ -1840,6 +1840,8 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"public static int QueryVisibleEntityIndices(",
|
||||
"AetheriaRuntimeDaemonEntityContact",
|
||||
"public static bool TryQueryEntityContact(",
|
||||
"public static AetheriaRuntimeDaemonEntityContact[] QueryEntityContacts(",
|
||||
"public static int QueryEntityContacts(",
|
||||
"AetheriaRuntimeDaemonWormholeExit",
|
||||
"public static AetheriaRuntimeDaemonWormholeExit[] QueryWormholeExits(",
|
||||
"public static int QueryWormholeExits(",
|
||||
|
|
@ -7715,6 +7717,8 @@ static void RequireMainMenuContinueRunState(string root)
|
|||
"drive.RestoreRuntimeState(",
|
||||
"resourceScanner.RestoreRuntimeState(",
|
||||
"AetheriaRuntimeDaemonRenderQueries.TryQueryEntityContact(",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryEntityContacts(",
|
||||
"ReconcileVisibleTargetIndicators();",
|
||||
"GetObservedInfoGathered(CurrentEntity, target)",
|
||||
"IsObservedHostileContact(CurrentEntity, CurrentEntity.Target.Value)",
|
||||
"_observedEntityFacadesByRecordKey",
|
||||
|
|
@ -7748,7 +7752,13 @@ static void RequireMainMenuContinueRunState(string root)
|
|||
"TargetVisibilityFill.fillAmount = Mathf.Lerp(.25f, .75f, (CurrentEntity.EntityInfoGathered[target] - threshold) / (1 - threshold));",
|
||||
"VisibilityToTargetFill.fillAmount = Mathf.Lerp(.25f, .75f, target.EntityInfoGathered[CurrentEntity] / threshold);",
|
||||
"indicator.Key.EntityInfoGathered[CurrentEntity]",
|
||||
"CurrentEntity.Target.Value.IsHostileTo(CurrentEntity)"
|
||||
"CurrentEntity.Target.Value.IsHostileTo(CurrentEntity)",
|
||||
"CurrentEntity.VisibleEnemies.ObserveAdd()",
|
||||
"CurrentEntity.VisibleEnemies.ObserveRemove()",
|
||||
"CurrentEntity.VisibleFriendlies.ObserveAdd()",
|
||||
"CurrentEntity.VisibleFriendlies.ObserveRemove()",
|
||||
"foreach (var hostile in CurrentEntity.VisibleEnemies)",
|
||||
"foreach (var friendly in CurrentEntity.VisibleFriendlies)"
|
||||
};
|
||||
|
||||
var forbiddenGameplayHits = forbiddenGameplaySymbols
|
||||
|
|
|
|||
|
|
@ -459,6 +459,10 @@ public class ActionGameManager : MonoBehaviour
|
|||
private (LockWeapon targetLock, PlaceUIElementWorldspace indicator, Rotate spin)[] _lockingIndicators;
|
||||
private Dictionary<Entity, VisibleTargetIndicator> _visibleHostileIndicators = new Dictionary<Entity, VisibleTargetIndicator>();
|
||||
private Dictionary<Entity, VisibleTargetIndicator> _visibleFriendlyIndicators = new Dictionary<Entity, VisibleTargetIndicator>();
|
||||
private readonly List<AetheriaRuntimeDaemonEntityContact> _observedVisibleContacts = new List<AetheriaRuntimeDaemonEntityContact>();
|
||||
private readonly HashSet<Entity> _observedHostileIndicatorTargets = new HashSet<Entity>();
|
||||
private readonly HashSet<Entity> _observedFriendlyIndicatorTargets = new HashSet<Entity>();
|
||||
private readonly List<Entity> _staleIndicatorTargets = new List<Entity>();
|
||||
private List<IDisposable> _shipSubscriptions = new List<IDisposable>();
|
||||
private List<IDisposable> _targetSubscriptions = new List<IDisposable>();
|
||||
private float _severeHeatstrokePhase;
|
||||
|
|
@ -3171,6 +3175,85 @@ public class ActionGameManager : MonoBehaviour
|
|||
return target != null && target.IsHostileTo(observer);
|
||||
}
|
||||
|
||||
private void ReconcileVisibleTargetIndicators()
|
||||
{
|
||||
_observedHostileIndicatorTargets.Clear();
|
||||
_observedFriendlyIndicatorTargets.Clear();
|
||||
|
||||
if (CurrentEntity != null)
|
||||
{
|
||||
AetheriaRuntimeDaemonRenderQueries.QueryEntityContacts(
|
||||
FindCurrentDaemonZoneSnapshot(),
|
||||
CurrentEntity.DaemonEntityIndex,
|
||||
Settings.GameplaySettings.TargetDetectionInfoThreshold,
|
||||
true,
|
||||
_observedVisibleContacts);
|
||||
|
||||
foreach (var contact in _observedVisibleContacts)
|
||||
{
|
||||
if (!TryGetObservedEntityFacade(contact.TargetEntityIndex, out var target) ||
|
||||
ReferenceEquals(target, CurrentEntity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (contact.Hostile)
|
||||
_observedHostileIndicatorTargets.Add(target);
|
||||
else
|
||||
_observedFriendlyIndicatorTargets.Add(target);
|
||||
}
|
||||
}
|
||||
|
||||
ReconcileVisibleTargetIndicators(
|
||||
_visibleHostileIndicators,
|
||||
_observedHostileIndicatorTargets,
|
||||
HostileTargetIndicator);
|
||||
ReconcileVisibleTargetIndicators(
|
||||
_visibleFriendlyIndicators,
|
||||
_observedFriendlyIndicatorTargets,
|
||||
FriendlyTargetIndicator);
|
||||
}
|
||||
|
||||
private void ReconcileVisibleTargetIndicators(
|
||||
Dictionary<Entity, VisibleTargetIndicator> indicators,
|
||||
HashSet<Entity> desiredTargets,
|
||||
VisibleTargetIndicator prototype)
|
||||
{
|
||||
_staleIndicatorTargets.Clear();
|
||||
foreach (var indicator in indicators)
|
||||
{
|
||||
if (!desiredTargets.Contains(indicator.Key))
|
||||
_staleIndicatorTargets.Add(indicator.Key);
|
||||
}
|
||||
|
||||
foreach (var staleTarget in _staleIndicatorTargets)
|
||||
{
|
||||
indicators[staleTarget].GetComponent<Prototype>().ReturnToPool();
|
||||
indicators.Remove(staleTarget);
|
||||
}
|
||||
|
||||
foreach (var target in desiredTargets)
|
||||
{
|
||||
if (!indicators.ContainsKey(target))
|
||||
indicators.Add(target, prototype.Instantiate<VisibleTargetIndicator>());
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryGetObservedEntityFacade(int daemonEntityIndex, out Entity entity)
|
||||
{
|
||||
foreach (var observedEntity in _observedEntityFacadesByRecordKey.Values)
|
||||
{
|
||||
if (observedEntity != null && observedEntity.DaemonEntityIndex == daemonEntityIndex)
|
||||
{
|
||||
entity = observedEntity;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
entity = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RequestTowToStation()
|
||||
{
|
||||
TryRequestDaemonTowToStation();
|
||||
|
|
@ -3314,41 +3397,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
}));
|
||||
|
||||
foreach (var hostile in CurrentEntity.VisibleEnemies)
|
||||
{
|
||||
var indicator = HostileTargetIndicator.Instantiate<VisibleTargetIndicator>();
|
||||
_visibleHostileIndicators.Add(hostile, indicator);
|
||||
}
|
||||
|
||||
_shipSubscriptions.Add(CurrentEntity.VisibleEnemies.ObserveAdd().Subscribe(addEvent =>
|
||||
{
|
||||
var indicator = HostileTargetIndicator.Instantiate<VisibleTargetIndicator>();
|
||||
_visibleHostileIndicators.Add(addEvent.Value, indicator);
|
||||
}));
|
||||
|
||||
_shipSubscriptions.Add(CurrentEntity.VisibleEnemies.ObserveRemove().Subscribe(removeEvent =>
|
||||
{
|
||||
_visibleHostileIndicators[removeEvent.Value].GetComponent<Prototype>().ReturnToPool();
|
||||
_visibleHostileIndicators.Remove(removeEvent.Value);
|
||||
}));
|
||||
|
||||
foreach (var friendly in CurrentEntity.VisibleFriendlies)
|
||||
{
|
||||
var indicator = FriendlyTargetIndicator.Instantiate<VisibleTargetIndicator>();
|
||||
_visibleFriendlyIndicators.Add(friendly, indicator);
|
||||
}
|
||||
|
||||
_shipSubscriptions.Add(CurrentEntity.VisibleFriendlies.ObserveAdd().Subscribe(addEvent =>
|
||||
{
|
||||
var indicator = FriendlyTargetIndicator.Instantiate<VisibleTargetIndicator>();
|
||||
_visibleFriendlyIndicators.Add(addEvent.Value, indicator);
|
||||
}));
|
||||
|
||||
_shipSubscriptions.Add(CurrentEntity.VisibleFriendlies.ObserveRemove().Subscribe(removeEvent =>
|
||||
{
|
||||
_visibleFriendlyIndicators[removeEvent.Value].GetComponent<Prototype>().ReturnToPool();
|
||||
_visibleFriendlyIndicators.Remove(removeEvent.Value);
|
||||
}));
|
||||
ReconcileVisibleTargetIndicators();
|
||||
|
||||
_lockingIndicators = CurrentEntity.GetBehaviors<LockWeapon>()
|
||||
.Select(x =>
|
||||
|
|
@ -3428,6 +3477,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
// ItemManager.Time = _time;
|
||||
if(CurrentEntity !=null && CurrentEntity.Parent==null)
|
||||
{
|
||||
ReconcileVisibleTargetIndicators();
|
||||
foreach (var indicator in _visibleHostileIndicators)
|
||||
{
|
||||
indicator.Value.gameObject.SetActive(indicator.Key!=CurrentEntity.Target.Value);
|
||||
|
|
|
|||
|
|
@ -581,26 +581,56 @@ namespace GameCult.Aetheria.State.Verse
|
|||
if (contact == null || contact.TargetEntityIndex != targetEntityIndex)
|
||||
continue;
|
||||
|
||||
var deltaX = target.PositionX - observer.PositionX;
|
||||
var deltaZ = target.PositionZ - observer.PositionZ;
|
||||
var distance = Math.Sqrt(deltaX * deltaX + deltaZ * deltaZ);
|
||||
entityContact = new AetheriaRuntimeDaemonEntityContact(
|
||||
observer.EntityIndex,
|
||||
target.EntityIndex,
|
||||
target.PositionX,
|
||||
target.PositionZ,
|
||||
deltaX,
|
||||
deltaZ,
|
||||
distance,
|
||||
contact.InfoGathered,
|
||||
contact.Hostile,
|
||||
contact.Visible);
|
||||
entityContact = BuildEntityContact(observer, target, contact);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonEntityContact[] QueryEntityContacts(
|
||||
AetheriaRuntimeZoneSnapshotCommit? zone,
|
||||
int observerEntityIndex,
|
||||
double minimumInfoGathered,
|
||||
bool visibleOnly)
|
||||
{
|
||||
var contacts = new List<AetheriaRuntimeDaemonEntityContact>();
|
||||
QueryEntityContacts(zone, observerEntityIndex, minimumInfoGathered, visibleOnly, contacts);
|
||||
return contacts.Count == 0 ? Array.Empty<AetheriaRuntimeDaemonEntityContact>() : contacts.ToArray();
|
||||
}
|
||||
|
||||
public static int QueryEntityContacts(
|
||||
AetheriaRuntimeZoneSnapshotCommit? zone,
|
||||
int observerEntityIndex,
|
||||
double minimumInfoGathered,
|
||||
bool visibleOnly,
|
||||
List<AetheriaRuntimeDaemonEntityContact> contacts)
|
||||
{
|
||||
if (contacts == null) throw new ArgumentNullException(nameof(contacts));
|
||||
contacts.Clear();
|
||||
if (zone == null || observerEntityIndex < 0)
|
||||
return 0;
|
||||
|
||||
var entities = BuildEntityMap(zone);
|
||||
if (!entities.TryGetValue(observerEntityIndex, out var observer))
|
||||
return 0;
|
||||
|
||||
foreach (var contact in observer.Contacts ?? Array.Empty<AetheriaRuntimeEntityContactCommit>())
|
||||
{
|
||||
if (contact == null ||
|
||||
contact.InfoGathered <= minimumInfoGathered ||
|
||||
visibleOnly && !contact.Visible ||
|
||||
!entities.TryGetValue(contact.TargetEntityIndex, out var target))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
contacts.Add(BuildEntityContact(observer, target, contact));
|
||||
}
|
||||
|
||||
return contacts.Count;
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonWormholeExit[] QueryWormholeExits(
|
||||
AetheriaRuntimeRunCheckpointCommit? run,
|
||||
AetheriaRuntimeZoneSnapshotCommit? zone,
|
||||
|
|
@ -768,6 +798,27 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return entities;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeDaemonEntityContact BuildEntityContact(
|
||||
AetheriaRuntimeEntitySnapshotCommit observer,
|
||||
AetheriaRuntimeEntitySnapshotCommit target,
|
||||
AetheriaRuntimeEntityContactCommit contact)
|
||||
{
|
||||
var deltaX = target.PositionX - observer.PositionX;
|
||||
var deltaZ = target.PositionZ - observer.PositionZ;
|
||||
var distance = Math.Sqrt(deltaX * deltaX + deltaZ * deltaZ);
|
||||
return new AetheriaRuntimeDaemonEntityContact(
|
||||
observer.EntityIndex,
|
||||
target.EntityIndex,
|
||||
target.PositionX,
|
||||
target.PositionZ,
|
||||
deltaX,
|
||||
deltaZ,
|
||||
distance,
|
||||
contact.InfoGathered,
|
||||
contact.Hostile,
|
||||
contact.Visible);
|
||||
}
|
||||
|
||||
private static Dictionary<int, AetheriaRuntimeZoneSnapshotCommit> BuildZoneMap(AetheriaRuntimeRunCheckpointCommit run)
|
||||
{
|
||||
var zones = new Dictionary<int, AetheriaRuntimeZoneSnapshotCommit>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue