Expose authoritative Eve gameplay surface

This commit is contained in:
Meta Vens 2026-07-10 05:05:27 +01:00
commit 320e7d06c6
4 changed files with 68 additions and 60 deletions

View file

@ -128,7 +128,7 @@ static async Task<AetheriaRuntimeDaemonTickResult> TickAsync(
var sessionId = string.IsNullOrWhiteSpace(currentFrame?.SessionId)
? options.SessionId
: currentFrame.SessionId;
var run = HasPlayableRun(currentFrame?.Run) && HasStarbridgeScenario(currentFrame?.Run)
var run = HasPlayableRun(currentFrame?.Run)
? currentFrame!.Run
: await ReadRuntimeRunCheckpointAsync(node, options.RenderSettings).ConfigureAwait(false) ?? new AetheriaRuntimeRunCheckpointCommit();
ApplyDaemonRenderSettings(run, options.RenderSettings);
@ -187,6 +187,18 @@ static async Task<AetheriaRuntimeDaemonTickResult> TickAsync(
LoadoutTemplates = loadoutTemplates
}
});
if (string.Equals(Environment.GetEnvironmentVariable("AETHERIA_TRACE_EVE_SNAPSHOTS"), "1", StringComparison.Ordinal) &&
result.Frame.AppliedCommandIds.Count > 0)
{
foreach (var entity in (result.Frame.Run?.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
.SelectMany(zone => zone.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
.Where(entity => string.Equals(entity.FactionKey, "player", StringComparison.OrdinalIgnoreCase)))
{
Console.WriteLine(
$"Eve command result entity={entity.EntityIndex} position={entity.PositionX},{entity.PositionZ} " +
$"velocity={entity.VelocityX},{entity.VelocityY}");
}
}
if (options.UseAbstractCombatKernel)
{
AetheriaDaemonCombatKernel.Step(
@ -901,10 +913,18 @@ static async Task InjectEveSurfaceSnapshotAsync(
string surfaceKind)
{
const string EveSurfaceSchema = "gamecult.eve.surface.v1";
var trace = string.Equals(Environment.GetEnvironmentVariable("AETHERIA_TRACE_EVE_SNAPSHOTS"), "1", StringComparison.Ordinal);
if (!SnapshotWants(request, EveSurfaceSchema, recordKey))
return;
var surfaceState = await ReadEveSurfacePublicationAsync(node, surfaceKind).ConfigureAwait(false);
if (trace)
{
Console.WriteLine(
$"Eve snapshot request kind={surfaceKind} schemas=[{string.Join(",", request.SchemaIds ?? Array.Empty<string>())}] " +
$"records=[{string.Join(",", request.RecordKeys ?? Array.Empty<string>())}] surface={(surfaceState == null ? "missing" : surfaceState.Surface.Id)} " +
$"playerPosition={(surfaceState == null ? "missing" : FindControllablePosition(surfaceState.Surface.Root))}");
}
if (surfaceState == null)
return;
@ -921,6 +941,22 @@ static async Task InjectEveSurfaceSnapshotAsync(
.Where(document => !string.Equals(document.RecordKey, surfacePut.Document.RecordKey, StringComparison.Ordinal))
.Concat(new[] { surfacePut.Document })
.ToArray();
if (trace)
Console.WriteLine($"Eve snapshot response schema={surfacePut.Document.SchemaId} record={surfacePut.Document.RecordKey}");
}
static string FindControllablePosition(EveSurfaceComponent component)
{
if (component.Props.TryGetValue("controllable", out var controllable) &&
string.Equals(controllable, "true", StringComparison.OrdinalIgnoreCase))
return component.GetProp("position", "missing");
foreach (var child in component.Children)
{
var position = FindControllablePosition(child);
if (!string.Equals(position, "missing", StringComparison.Ordinal))
return position;
}
return "missing";
}
static Task<EveSurfaceDocument?> ReadEveSurfacePublicationAsync(AetheriaStateNode node, string surfaceKind)

View file

@ -563,16 +563,37 @@ namespace GameCult.Aetheria.State.Verse
if (AetheriaRuntimeRunCheckpointCommit.TryParseEntityKey(
currentEntityKey ?? "",
out var zoneIndex,
out var entityIndex))
out var entityIndex) &&
IsPlayerEntity(zone, entityIndex))
{
return run.EntityRecordKey(zoneIndex, entityIndex);
}
var parsedEntityIndex = TryParseEntityIndex(currentEntityKey ?? "");
if (parsedEntityIndex >= 0)
if (parsedEntityIndex >= 0 && IsPlayerEntity(zone, parsedEntityIndex))
return run.EntityRecordKey(zone?.ZoneIndex ?? run.CurrentZoneIndex, parsedEntityIndex);
return currentEntityKey ?? "";
var player = (zone?.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
.FirstOrDefault(IsControllablePlayerEntity);
return player == null
? currentEntityKey ?? ""
: run.EntityRecordKey(zone?.ZoneIndex ?? run.CurrentZoneIndex, player.EntityIndex);
}
private static bool IsPlayerEntity(AetheriaRuntimeZoneSnapshotCommit zone, int entityIndex)
{
return (zone?.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
.Any(entity => entity != null &&
entity.EntityIndex == entityIndex &&
IsControllablePlayerEntity(entity));
}
private static bool IsControllablePlayerEntity(AetheriaRuntimeEntitySnapshotCommit entity)
{
return entity != null &&
entity.IsActive &&
!string.Equals(entity.Kind, "station", StringComparison.OrdinalIgnoreCase) &&
string.Equals(entity.FactionKey, "player", StringComparison.OrdinalIgnoreCase);
}
private static string ViewportDocumentId(string prefix, AetheriaRuntimeViewportBounds viewport)

View file

@ -43,6 +43,13 @@ public sealed class AetheriaRuntimeDaemonOperationsClient
return submit(client, frame);
});
var accepted = operations.TrySubmitSurfaceCommand(request, out _);
var actorEntityKey = ReadPayloadString(request, "entityId", "");
if (translated != null && !string.IsNullOrWhiteSpace(actorEntityKey))
translated.ActorEntityKey = actorEntityKey;
if (string.Equals(Environment.GetEnvironmentVariable("AETHERIA_TRACE_EVE_SNAPSHOTS"), "1", StringComparison.Ordinal))
Console.WriteLine(
$"Eve command translated command={request.Command} actor={translated?.ActorEntityKey ?? "missing"} " +
$"direction={translated?.DirectionX},{translated?.DirectionY} scalar={translated?.ScalarValue}");
command = translated;
return accepted && command != null;
}

View file

@ -1,56 +0,0 @@
using System;
using System.Collections.Generic;
using GameCult.Caching;
using GameCult.Eve.Surface;
[assembly: CultGeneratedDocumentMetadataProvider(typeof(GameCult.Aetheria.State.Verse.AetheriaRuntimeEveSurfaceDocumentMetadataProvider))]
namespace GameCult.Aetheria.State.Verse
{
public sealed class AetheriaRuntimeEveSurfaceDocumentMetadataProvider : ICultGeneratedDocumentMetadataProvider
{
public IEnumerable<CultGeneratedDocumentDefinition> GetDocumentDefinitions()
{
yield return new CultGeneratedDocumentDefinition(
typeof(EveSurfaceDocument),
"gamecult.eve.surface",
"gamecult.eve.surface.v1",
isGlobal: false,
nameMember: null,
nameAccessor: null,
serializePayload: value => AetheriaRuntimeCultCacheDocumentStore.WriteRuntimeSurfaceDocument(
AetheriaRuntimeSurfaceDocuments.FromPortableSurface((EveSurfaceDocument)value)),
deserializePayload: payload => AetheriaRuntimeSurfaceDocuments.ToPortableSurface(
AetheriaRuntimeCultCacheDocumentStore.ReadRuntimeSurfaceDocument(payload)),
indexAccessors: Array.Empty<CultGeneratedDocumentIndexAccessor>(),
members: new[]
{
Member("Type", 0, "string"),
Member("Schema", 1, "string"),
Member("ProviderId", 2, "string"),
Member("ProviderKind", 3, "string"),
Member("Title", 4, "string"),
Member("Version", 5, "int64"),
Member("UpdatedAtUtc", 6, "string"),
Member("Surface", 7, "object"),
Member("Commands", 8, "array")
});
}
private static CultGeneratedDocumentMemberDefinition Member(
string name,
int slot,
string typeName)
{
return new CultGeneratedDocumentMemberDefinition(
name,
slot,
typeName,
isReference: false,
isMany: false,
targetSchemaName: null,
isName: false,
indexAlias: null);
}
}
}