Move docking target selection into daemon operations
This commit is contained in:
parent
0682bbe158
commit
c6f8b95317
7 changed files with 153 additions and 40 deletions
|
|
@ -7276,6 +7276,7 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root)
|
|||
var mainMenuPath = Path.Combine(root, "Assets", "Scripts", "UI", "MainMenu.cs");
|
||||
var galaxyPath = Path.Combine(root, "Assets", "Scripts", "ServerShared", "Galaxy.cs");
|
||||
var daemonDocumentsPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonDocuments.cs");
|
||||
var daemonOperationClientPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonOperationClient.cs");
|
||||
var daemonRuntimeOperationsPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonOperations.cs");
|
||||
var daemonIntentPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonIntentState.cs");
|
||||
var daemonObserverPath = Path.Combine(root, "Assets", "Scripts", "Gameplay", "AetheriaDaemonObserver.cs");
|
||||
|
|
@ -7292,6 +7293,9 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root)
|
|||
var daemonDocuments = File.Exists(daemonDocumentsPath)
|
||||
? File.ReadAllText(daemonDocumentsPath)
|
||||
: throw new InvalidOperationException("Cannot verify Unity observer authority; daemon command documents are missing.");
|
||||
var daemonOperationClient = File.Exists(daemonOperationClientPath)
|
||||
? File.ReadAllText(daemonOperationClientPath)
|
||||
: throw new InvalidOperationException("Cannot verify Unity observer authority; daemon operation client is missing.");
|
||||
var daemonOperationsSource = File.Exists(daemonRuntimeOperationsPath)
|
||||
? File.ReadAllText(daemonRuntimeOperationsPath)
|
||||
: throw new InvalidOperationException("Cannot verify Unity observer authority; daemon operations is missing.");
|
||||
|
|
@ -7533,7 +7537,7 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root)
|
|||
"TryRequestDaemonDock()",
|
||||
"TryRequestDaemonUndock()",
|
||||
"TryRequestDaemonTowToStation()",
|
||||
"observer.Operations.Dock(targetKey)",
|
||||
"observer.Operations.DockNearest(Settings.GameplaySettings.DockingDistance)",
|
||||
"observer.Operations.Undock()",
|
||||
"observer.Operations.TowToStation(",
|
||||
"TowingStation.CultPositionXZ.x",
|
||||
|
|
@ -7597,6 +7601,37 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root)
|
|||
string.Join("; ", dockLocalAuthorityHits));
|
||||
}
|
||||
|
||||
var dockTargetSelectionHits = FindMethodScopedLineHits(
|
||||
actionGameManager,
|
||||
new[] { "FindDaemonDockTarget", "Zone.Entities", "CultPositionXZ - CurrentEntity.CultPositionXZ" })
|
||||
.Where(hit => hit.MethodName == "TryRequestDaemonDock" || hit.MethodName == "FindDaemonDockTarget")
|
||||
.Select(hit => $"ActionGameManager.cs:{hit.LineNumber}: {hit.Line.Trim()}")
|
||||
.ToArray();
|
||||
if (dockTargetSelectionHits.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Unity dock request still selects docking targets from renderer-local zone state instead of daemon acceptance: " +
|
||||
string.Join("; ", dockTargetSelectionHits));
|
||||
}
|
||||
|
||||
var requiredDaemonDockNearestSymbols = new[]
|
||||
{
|
||||
"AetheriaRuntimeDaemonCommandKinds.DockNearest",
|
||||
"public AetheriaRuntimeDaemonCommandEnvelope DockNearest(",
|
||||
"ApplyDockNearestIntent(run, command, context.Intents)",
|
||||
"TryFindNearestDockTarget(run, actorKey, command.ScalarValue, out var targetKey)"
|
||||
};
|
||||
var daemonDockNearestSources = daemonDocuments + "\n" + daemonOperationClient + "\n" + daemonOperationsSource;
|
||||
var missingDaemonDockNearestSymbols = requiredDaemonDockNearestSymbols
|
||||
.Where(symbol => !daemonDockNearestSources.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingDaemonDockNearestSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Daemon no longer owns nearest docking target selection: " +
|
||||
string.Join(", ", missingDaemonDockNearestSymbols));
|
||||
}
|
||||
|
||||
var movementLocalAuthorityHits = FindMethodScopedLineHits(
|
||||
actionGameManager,
|
||||
new[] { "CurrentEntity?.Parent != null" })
|
||||
|
|
|
|||
|
|
@ -3883,21 +3883,14 @@ public class ActionGameManager : MonoBehaviour
|
|||
private bool TryRequestDaemonDock()
|
||||
{
|
||||
var observer = ResolveDaemonObserver();
|
||||
if (observer == null || !observer.HasAuthoritativeState || CurrentEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var target = FindDaemonDockTarget();
|
||||
var targetKey = ResolveEntityRecordKey(target);
|
||||
if (string.IsNullOrWhiteSpace(targetKey))
|
||||
if (observer == null || !observer.HasAuthoritativeState)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
observer.Operations.Dock(targetKey);
|
||||
observer.Operations.DockNearest(Settings.GameplaySettings.DockingDistance);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -3907,36 +3900,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private Entity FindDaemonDockTarget()
|
||||
{
|
||||
if (CurrentEntity == null || Zone == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var dockingDistanceSq = Settings.GameplaySettings.DockingDistance * Settings.GameplaySettings.DockingDistance;
|
||||
Entity closest = null;
|
||||
var closestDistanceSq = float.MaxValue;
|
||||
foreach (var entity in Zone.Entities)
|
||||
{
|
||||
if (entity == null || entity == CurrentEntity)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var distanceSq = CultMath.math.lengthsq(entity.CultPositionXZ - CurrentEntity.CultPositionXZ);
|
||||
if (distanceSq >= dockingDistanceSq || distanceSq >= closestDistanceSq)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
closest = entity;
|
||||
closestDistanceSq = distanceSq;
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
public void RequestUndock()
|
||||
{
|
||||
TryRequestDaemonUndock();
|
||||
|
|
|
|||
|
|
@ -180,6 +180,11 @@ public sealed class AetheriaDaemonOperations
|
|||
return Send((client, observed) => client.Dock(observed, targetEntityKey));
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope DockNearest(double maxDistance)
|
||||
{
|
||||
return Send((client, observed) => client.DockNearest(observed, maxDistance));
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope Undock()
|
||||
{
|
||||
return Send((client, observed) => client.Undock(observed));
|
||||
|
|
|
|||
|
|
@ -2127,6 +2127,47 @@ public class DaemonRuntimeDocumentTests
|
|||
CollectionAssert.DoesNotContain(run.Zones[0].Entities[1].DockingBayAssignments, 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonOperationsSelectsNearestDockTargetFromAuthoritativeSnapshot()
|
||||
{
|
||||
var run = RunWithTwoEntities();
|
||||
var zone = run.Zones[0];
|
||||
zone.Entities[0].PositionX = 0;
|
||||
zone.Entities[0].PositionY = 0;
|
||||
zone.Entities[1].PositionX = 3;
|
||||
zone.Entities[1].PositionY = 4;
|
||||
zone.Entities = zone.Entities
|
||||
.Concat(new[]
|
||||
{
|
||||
new AetheriaRuntimeEntitySnapshotCommit
|
||||
{
|
||||
EntityIndex = 2,
|
||||
Name = "Far Dock",
|
||||
PositionX = 8,
|
||||
PositionY = 0
|
||||
}
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
var dock = AetheriaRuntimeDaemonCommandDocument.Create(
|
||||
AetheriaRuntimeDaemonCommandKinds.DockNearest,
|
||||
"codex",
|
||||
"session-navigation",
|
||||
37,
|
||||
"zone.0.entity.0");
|
||||
dock.ScalarValue = 6.0;
|
||||
|
||||
var result = AetheriaRuntimeDaemonOperations.Execute(run, new[] { dock });
|
||||
|
||||
Assert.AreEqual(1, result.AppliedCommandIds.Count);
|
||||
Assert.AreEqual(1, result.Intents.Docking.Count);
|
||||
Assert.IsTrue(result.Intents.Docking[0].Dock);
|
||||
Assert.AreEqual("global:aetheria.run_state.daemon-command-apply-run.zone.0.entity.1.v1", result.Intents.Docking[0].TargetEntityKey);
|
||||
CollectionAssert.Contains(zone.Entities[1].ChildEntityIndices, 0);
|
||||
CollectionAssert.Contains(zone.Entities[1].DockingBayAssignments, 0);
|
||||
CollectionAssert.DoesNotContain(zone.Entities[2].ChildEntityIndices, 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonOperationsRejectsUndockWhenEntityIsNotDocked()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
PickUpLoot,
|
||||
RestoreLoadout,
|
||||
Dock,
|
||||
DockNearest,
|
||||
Undock,
|
||||
SetDockedCurrentShip,
|
||||
TowToStation,
|
||||
|
|
|
|||
|
|
@ -365,6 +365,14 @@ namespace GameCult.Aetheria.State.Verse
|
|||
command.TargetEntityKey = targetEntityKey ?? "");
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope DockNearest(
|
||||
AetheriaRuntimeObservedDaemonState? observed,
|
||||
double maxDistance)
|
||||
{
|
||||
return Send(AetheriaRuntimeDaemonCommandKinds.DockNearest, observed, command =>
|
||||
command.ScalarValue = maxDistance);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonCommandEnvelope Undock(AetheriaRuntimeObservedDaemonState? observed)
|
||||
{
|
||||
return Send(AetheriaRuntimeDaemonCommandKinds.Undock, observed);
|
||||
|
|
|
|||
|
|
@ -151,6 +151,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return ApplySensorPing(run, command, context.Intents);
|
||||
case AetheriaRuntimeDaemonCommandKinds.Dock:
|
||||
return ApplyDockIntent(run, command, context.Intents);
|
||||
case AetheriaRuntimeDaemonCommandKinds.DockNearest:
|
||||
return ApplyDockNearestIntent(run, command, context.Intents);
|
||||
case AetheriaRuntimeDaemonCommandKinds.Undock:
|
||||
return ApplyUndockIntent(run, command, context.Intents);
|
||||
case AetheriaRuntimeDaemonCommandKinds.EnterWormhole:
|
||||
|
|
@ -913,6 +915,22 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return true;
|
||||
}
|
||||
|
||||
private static bool ApplyDockNearestIntent(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeDaemonCommandDocument command,
|
||||
AetheriaRuntimeDaemonIntentState intents)
|
||||
{
|
||||
var actorKey = ResolveActorEntityKey(run, command);
|
||||
if (string.IsNullOrWhiteSpace(actorKey) ||
|
||||
!TryFindNearestDockTarget(run, actorKey, command.ScalarValue, out var targetKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
command.TargetEntityKey = targetKey;
|
||||
return ApplyDockIntent(run, command, intents);
|
||||
}
|
||||
|
||||
private static bool ApplyUndockIntent(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeDaemonCommandDocument command,
|
||||
|
|
@ -933,6 +951,48 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return true;
|
||||
}
|
||||
|
||||
private static bool TryFindNearestDockTarget(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
string actorEntityKey,
|
||||
double maxDistance,
|
||||
out string targetEntityKey)
|
||||
{
|
||||
targetEntityKey = "";
|
||||
if (!TryResolveEntity(run, actorEntityKey, out var zoneIndex, out var actorIndex, out var actor))
|
||||
return false;
|
||||
|
||||
var zone = (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
|
||||
.FirstOrDefault(candidate => candidate != null && candidate.ZoneIndex == zoneIndex);
|
||||
if (zone == null)
|
||||
return false;
|
||||
|
||||
var maxDistanceSq = maxDistance > 0.0 ? maxDistance * maxDistance : double.PositiveInfinity;
|
||||
var closestDistanceSq = double.PositiveInfinity;
|
||||
var closestIndex = -1;
|
||||
var entities = zone.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>();
|
||||
for (var index = 0; index < entities.Count; index++)
|
||||
{
|
||||
var candidate = entities[index];
|
||||
if (candidate == null || index == actorIndex)
|
||||
continue;
|
||||
|
||||
var deltaX = candidate.PositionX - actor.PositionX;
|
||||
var deltaY = candidate.PositionY - actor.PositionY;
|
||||
var distanceSq = (deltaX * deltaX) + (deltaY * deltaY);
|
||||
if (distanceSq >= maxDistanceSq || distanceSq >= closestDistanceSq)
|
||||
continue;
|
||||
|
||||
closestDistanceSq = distanceSq;
|
||||
closestIndex = index;
|
||||
}
|
||||
|
||||
if (closestIndex < 0)
|
||||
return false;
|
||||
|
||||
targetEntityKey = BuildEntityKey(run.RunId, zoneIndex, closestIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool ApplyDockState(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
string actorEntityKey,
|
||||
|
|
|
|||
Loading…
Reference in a new issue