Move reticle targeting into daemon operations
This commit is contained in:
parent
1f47ea387b
commit
712c34bf52
7 changed files with 168 additions and 9 deletions
|
|
@ -7689,6 +7689,7 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root)
|
|||
"ApplyTargetCycle(run, command, TargetCycleMode.Nearest)",
|
||||
"ApplyTargetCycle(run, command, TargetCycleMode.Next)",
|
||||
"ApplyTargetCycle(run, command, TargetCycleMode.Previous)",
|
||||
"ApplyTargetReticle(run, command)",
|
||||
"VisibleHostileTargets(zone, actor, actorIndex)",
|
||||
"actor.Contacts ?? Array.Empty<AetheriaRuntimeEntityContactCommit>()",
|
||||
"contact.TargetEntityIndex == targetIndex && contact.Visible"
|
||||
|
|
@ -7708,9 +7709,11 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root)
|
|||
"RequestTargetNearest()",
|
||||
"RequestTargetNext()",
|
||||
"RequestTargetPrevious()",
|
||||
"RequestTargetReticle()",
|
||||
"observer.Operations.TargetNearest()",
|
||||
"observer.Operations.TargetNext()",
|
||||
"observer.Operations.TargetPrevious()"
|
||||
"observer.Operations.TargetPrevious()",
|
||||
"observer.Operations.TargetReticle("
|
||||
};
|
||||
var unityTargetRequestSources = actionGameManager + "\n" + daemonOperations;
|
||||
var missingUnityTargetRequestSymbols = requiredUnityTargetRequestSymbols
|
||||
|
|
@ -7727,6 +7730,7 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root)
|
|||
{
|
||||
".MaxBy(x => CultMath.math.length(x.CultPosition - CurrentEntity.CultPosition))",
|
||||
".OrderBy(x => CultMath.math.length(x.CultPosition - CurrentEntity.CultPosition))",
|
||||
".MaxBy(x => CultMath.math.dot(",
|
||||
"Array.IndexOf(targets"
|
||||
};
|
||||
var unityTargetCycleHits = forbiddenUnityTargetCycleSymbols
|
||||
|
|
|
|||
|
|
@ -2057,12 +2057,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
Input.Player.TargetReticle.performed += context =>
|
||||
{
|
||||
if (!CurrentEntity.VisibleEnemies.Any()) return;
|
||||
var underReticle = CurrentEntity.VisibleEnemies.Where(x => x != CurrentEntity)
|
||||
.MaxBy(x => CultMath.math.dot(
|
||||
CultMath.math.normalize(x.CultPosition - CurrentEntity.CultPosition),
|
||||
CurrentEntity.CultLookDirection));
|
||||
RequestTargetSelection(CurrentEntity.Target.Value == underReticle ? null : underReticle);
|
||||
RequestTargetReticle();
|
||||
};
|
||||
|
||||
Input.Player.TargetNearest.performed += context =>
|
||||
|
|
@ -3744,6 +3739,11 @@ public class ActionGameManager : MonoBehaviour
|
|||
TryRequestDaemonTargetCycle(AetheriaRuntimeDaemonCommandKinds.TargetPrevious);
|
||||
}
|
||||
|
||||
private void RequestTargetReticle()
|
||||
{
|
||||
TryRequestDaemonTargetReticle(_viewDirection);
|
||||
}
|
||||
|
||||
private bool TryRequestDaemonTargetSelection(Entity target)
|
||||
{
|
||||
var observer = ResolveDaemonObserver();
|
||||
|
|
@ -3776,6 +3776,26 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private bool TryRequestDaemonTargetReticle(Vector3 lookDirection)
|
||||
{
|
||||
var observer = ResolveDaemonObserver();
|
||||
if (observer == null || !observer.HasAuthoritativeState)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
observer.Operations.TargetReticle(lookDirection.x, lookDirection.y, lookDirection.z);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to send Aetheria daemon reticle target operation; operation not submitted: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryRequestDaemonTargetCycle(AetheriaRuntimeDaemonCommandKinds command)
|
||||
{
|
||||
var observer = ResolveDaemonObserver();
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ public sealed class AetheriaDaemonOperations
|
|||
return Send((client, observed) => client.TargetPrevious(observed));
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope TargetReticle(double directionX, double directionY, double directionZ)
|
||||
{
|
||||
return Send((client, observed) => client.TargetReticle(observed, directionX, directionY, directionZ));
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope SetMoveVector(
|
||||
double directionX,
|
||||
double directionY,
|
||||
|
|
|
|||
|
|
@ -1144,6 +1144,63 @@ public class DaemonRuntimeDocumentTests
|
|||
Assert.AreEqual(2, zone.Entities[0].TargetEntityIndex);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonOperationsTargetsReticleFromAuthoritativeContacts()
|
||||
{
|
||||
var run = RunWithTwoEntities();
|
||||
var zone = run.Zones[0];
|
||||
zone.Entities[0].PositionX = 0;
|
||||
zone.Entities[0].PositionY = 0;
|
||||
zone.Entities[0].PositionZ = 0;
|
||||
zone.Entities[1].PositionX = 0;
|
||||
zone.Entities[1].PositionY = 0;
|
||||
zone.Entities[1].PositionZ = 5;
|
||||
zone.Entities = zone.Entities
|
||||
.Concat(new[]
|
||||
{
|
||||
new AetheriaRuntimeEntitySnapshotCommit
|
||||
{
|
||||
EntityIndex = 2,
|
||||
Name = "Off Reticle",
|
||||
PositionX = 5,
|
||||
PositionY = 0,
|
||||
PositionZ = 0
|
||||
}
|
||||
})
|
||||
.ToArray();
|
||||
zone.Entities[0].Contacts = new[]
|
||||
{
|
||||
new AetheriaRuntimeEntityContactCommit
|
||||
{
|
||||
TargetEntityIndex = 1,
|
||||
Visible = true,
|
||||
Hostile = true
|
||||
},
|
||||
new AetheriaRuntimeEntityContactCommit
|
||||
{
|
||||
TargetEntityIndex = 2,
|
||||
Visible = true,
|
||||
Hostile = true
|
||||
}
|
||||
};
|
||||
|
||||
var command = AetheriaRuntimeDaemonCommandDocument.Create(
|
||||
AetheriaRuntimeDaemonCommandKinds.TargetReticle,
|
||||
"codex",
|
||||
"session-reticle",
|
||||
18,
|
||||
"zone.0.entity.0");
|
||||
command.PositionZ = 1;
|
||||
|
||||
var targetResult = AetheriaRuntimeDaemonOperations.Execute(run, new[] { command });
|
||||
Assert.AreEqual(1, targetResult.AppliedCommandIds.Count);
|
||||
Assert.AreEqual(1, zone.Entities[0].TargetEntityIndex);
|
||||
|
||||
var toggleResult = AetheriaRuntimeDaemonOperations.Execute(run, new[] { command });
|
||||
Assert.AreEqual(1, toggleResult.AppliedCommandIds.Count);
|
||||
Assert.AreEqual(-1, zone.Entities[0].TargetEntityIndex);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonOperationsMutatesHotEntityControlsInDaemonState()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
TargetNearest,
|
||||
TargetNext,
|
||||
TargetPrevious,
|
||||
TargetReticle,
|
||||
SetMoveVector,
|
||||
SetLookDirection,
|
||||
SetTractorPower,
|
||||
|
|
|
|||
|
|
@ -132,6 +132,20 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return Send(AetheriaRuntimeDaemonCommandKinds.TargetPrevious, observed);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope TargetReticle(
|
||||
AetheriaRuntimeObservedDaemonState? observed,
|
||||
double directionX,
|
||||
double directionY,
|
||||
double directionZ)
|
||||
{
|
||||
return Send(AetheriaRuntimeDaemonCommandKinds.TargetReticle, observed, command =>
|
||||
{
|
||||
command.DirectionX = directionX;
|
||||
command.DirectionY = directionY;
|
||||
command.PositionZ = directionZ;
|
||||
});
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope SetMoveVector(
|
||||
AetheriaRuntimeObservedDaemonState? observed,
|
||||
double directionX,
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return ApplyTargetCycle(run, command, TargetCycleMode.Next);
|
||||
case AetheriaRuntimeDaemonCommandKinds.TargetPrevious:
|
||||
return ApplyTargetCycle(run, command, TargetCycleMode.Previous);
|
||||
case AetheriaRuntimeDaemonCommandKinds.TargetReticle:
|
||||
return ApplyTargetReticle(run, command);
|
||||
case AetheriaRuntimeDaemonCommandKinds.SetLookDirection:
|
||||
return ApplySetLookDirection(run, command);
|
||||
case AetheriaRuntimeDaemonCommandKinds.SetTractorPower:
|
||||
|
|
@ -247,7 +249,57 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return true;
|
||||
}
|
||||
|
||||
private static IEnumerable<(int EntityIndex, double DistanceSq)> VisibleHostileTargets(
|
||||
private static bool ApplyTargetReticle(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeDaemonCommandDocument command)
|
||||
{
|
||||
var actorKey = string.IsNullOrWhiteSpace(command.ActorEntityKey)
|
||||
? run.CurrentEntityKey
|
||||
: command.ActorEntityKey;
|
||||
if (!TryResolveEntity(run, actorKey, out var actorZone, out var actorIndex, out var actor))
|
||||
return false;
|
||||
|
||||
var zone = (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
|
||||
.FirstOrDefault(candidate => candidate != null && candidate.ZoneIndex == actorZone);
|
||||
if (zone == null)
|
||||
return false;
|
||||
|
||||
var lookLength = Math.Sqrt(
|
||||
(command.DirectionX * command.DirectionX) +
|
||||
(command.DirectionY * command.DirectionY) +
|
||||
(command.PositionZ * command.PositionZ));
|
||||
if (lookLength <= double.Epsilon)
|
||||
return false;
|
||||
|
||||
var lookX = command.DirectionX / lookLength;
|
||||
var lookY = command.DirectionY / lookLength;
|
||||
var lookZ = command.PositionZ / lookLength;
|
||||
var scoredTargets = VisibleHostileTargets(zone, actor, actorIndex)
|
||||
.Select(candidate =>
|
||||
{
|
||||
var distance = Math.Sqrt(candidate.DistanceSq);
|
||||
var dot = distance <= double.Epsilon
|
||||
? double.NegativeInfinity
|
||||
: ((candidate.DeltaX / distance) * lookX) +
|
||||
((candidate.DeltaY / distance) * lookY) +
|
||||
((candidate.DeltaZ / distance) * lookZ);
|
||||
return (candidate.EntityIndex, Dot: dot);
|
||||
})
|
||||
.Where(candidate => candidate.Dot > double.NegativeInfinity)
|
||||
.OrderByDescending(candidate => candidate.Dot)
|
||||
.ThenBy(candidate => candidate.EntityIndex)
|
||||
.ToArray();
|
||||
if (scoredTargets.Length == 0)
|
||||
return false;
|
||||
|
||||
var target = scoredTargets[0];
|
||||
actor.TargetEntityIndex = actor.TargetEntityIndex == target.EntityIndex
|
||||
? -1
|
||||
: target.EntityIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IEnumerable<(int EntityIndex, double DistanceSq, double DeltaX, double DeltaY, double DeltaZ)> VisibleHostileTargets(
|
||||
AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
AetheriaRuntimeEntitySnapshotCommit actor,
|
||||
int actorIndex)
|
||||
|
|
@ -271,7 +323,13 @@ namespace GameCult.Aetheria.State.Verse
|
|||
|
||||
var deltaX = target.PositionX - actor.PositionX;
|
||||
var deltaY = target.PositionY - actor.PositionY;
|
||||
yield return (contact.TargetEntityIndex, (deltaX * deltaX) + (deltaY * deltaY));
|
||||
var deltaZ = target.PositionZ - actor.PositionZ;
|
||||
yield return (
|
||||
contact.TargetEntityIndex,
|
||||
(deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ),
|
||||
deltaX,
|
||||
deltaY,
|
||||
deltaZ);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue