Preserve entity identity across zone travel
This commit is contained in:
parent
a88fa37c63
commit
bc7596855c
4 changed files with 25 additions and 1 deletions
|
|
@ -711,6 +711,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
|
|||
private static void AgentTraversesGalaxyRouteBeforeExecutingTask()
|
||||
{
|
||||
var agent = Entity(0, 0, "workers");
|
||||
agent.EntityId = "worker.cross-zone.stable";
|
||||
agent.AgentTaskCapabilities = [AetheriaRuntimeAgentTaskTypes.Explore];
|
||||
var task = AgentTask("cross-zone", 10);
|
||||
task.ZoneIndex = 2;
|
||||
|
|
@ -753,6 +754,8 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
|
|||
"agent must traverse each galaxy edge through the shared wormhole command boundary");
|
||||
Require(run.Zones.Single(zone => zone.ZoneIndex == 2).Entities.Count == 1,
|
||||
"assigned agent must arrive in the task zone without a parallel teleport owner");
|
||||
RequireEqual("worker.cross-zone.stable", run.Zones.Single(zone => zone.ZoneIndex == 2).Entities.Single().EntityId,
|
||||
"zone transfer must preserve stable entity identity while projection indices change");
|
||||
RequireEqual(AetheriaRuntimeAgentTaskStatuses.Completed, task.Status,
|
||||
"agent must execute the task only after arriving in its destination zone");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2493,7 +2493,7 @@ static async Task<AetheriaRuntimeZoneSnapshotCommit> ToRuntimeZoneAsync(
|
|||
{
|
||||
var entity = await node.MutableDocument<AetheriaEntitySnapshot>(new CultRecordKey(entityKeys[entityIndex])).ReadAsync().ConfigureAwait(false);
|
||||
if (entity != null)
|
||||
entities.Add(ToRuntimeEntity(entity, entityIndex, entityIndices, catalog));
|
||||
entities.Add(ToRuntimeEntity(entityKeys[entityIndex], entity, entityIndex, entityIndices, catalog));
|
||||
}
|
||||
|
||||
return new AetheriaRuntimeZoneSnapshotCommit
|
||||
|
|
@ -2519,6 +2519,7 @@ static async Task<AetheriaRuntimeZoneSnapshotCommit> ToRuntimeZoneAsync(
|
|||
}
|
||||
|
||||
static AetheriaRuntimeEntitySnapshotCommit ToRuntimeEntity(
|
||||
string entityKey,
|
||||
AetheriaEntitySnapshot entity,
|
||||
int entityIndex,
|
||||
IReadOnlyDictionary<string, int> entityIndices,
|
||||
|
|
@ -2527,6 +2528,7 @@ static AetheriaRuntimeEntitySnapshotCommit ToRuntimeEntity(
|
|||
var equipment = ToEntitySlotCommits(entity.Equipment);
|
||||
var runtimeEntity = new AetheriaRuntimeEntitySnapshotCommit
|
||||
{
|
||||
EntityId = entityKey ?? "",
|
||||
EntityIndex = entityIndex,
|
||||
Name = entity.Name ?? "",
|
||||
Kind = entity.Kind ?? "",
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
options ??= new AetheriaRuntimeDaemonTickOptions();
|
||||
options.OperationContext ??= new AetheriaRuntimeDaemonOperationContext();
|
||||
options.OperationContext.Catalog = options.Catalog;
|
||||
EnsureEntityIds(run);
|
||||
EnsureBehaviorStates(run, options.Catalog);
|
||||
|
||||
var observedCommands = (options.ObservedCommands ?? Array.Empty<AetheriaRuntimeDaemonCommandDocument>())
|
||||
|
|
@ -284,6 +285,21 @@ namespace GameCult.Aetheria.State.Verse
|
|||
editorSurface);
|
||||
}
|
||||
|
||||
private static void EnsureEntityIds(AetheriaRuntimeRunCheckpointCommit run)
|
||||
{
|
||||
var used = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var zone in run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
|
||||
foreach (var entity in zone?.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
|
||||
{
|
||||
if (entity == null)
|
||||
continue;
|
||||
if (string.IsNullOrWhiteSpace(entity.EntityId))
|
||||
entity.EntityId = $"aetheria.entity:{(string.IsNullOrWhiteSpace(run.RunId) ? "local" : run.RunId)}:{zone.ZoneIndex}:{entity.EntityIndex}";
|
||||
if (!used.Add(entity.EntityId))
|
||||
throw new InvalidOperationException($"Duplicate runtime entity identity '{entity.EntityId}'.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnsureBehaviorStates(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
|
|
|
|||
|
|
@ -955,6 +955,9 @@ namespace GameCult.Aetheria.State.Verse
|
|||
|
||||
[Key(41)]
|
||||
public double TractorTargetPower { get; set; }
|
||||
|
||||
[Key(42)]
|
||||
public string EntityId { get; set; } = "";
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
|
|||
Loading…
Reference in a new issue