Publish Aetheria world surface for Eve Unity

This commit is contained in:
Meta Vens 2026-07-09 19:20:09 +01:00
commit 8804ba6655
6 changed files with 372 additions and 2 deletions

View file

@ -22,6 +22,7 @@
"org.gamecult.aetheria.state": "file:org.gamecult.aetheria.state",
"org.gamecult.cultmath": "file:../../CultMath",
"org.gamecult.eve.surface": "file:../../Eve/packages/org.gamecult.eve.surface",
"org.gamecult.eve.unity-scene": "file:../../Eve/runtimes/incubating/eve-unity-scene",
"org.gamecult.eve.unity-uitoolkit": "file:../../Eve/packages/org.gamecult.eve.unity-uitoolkit",
"com.unity.modules.accessibility": "1.0.0",
"com.unity.modules.adaptiveperformance": "1.0.0",

View file

@ -0,0 +1,215 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GameCult.Aetheria.State.Verse;
using GameCult.Eve.Surface;
using GameCult.Eve.UnityScene;
using GameCult.Mesh;
using UnityEngine;
using EveSurfaceDocument = GameCult.Eve.Surface.EveSurfaceDocument;
#nullable enable
namespace GameCult.Aetheria.EveRuntime
{
public sealed class AetheriaEveUnitySceneProviderBridge :
IEveUnitySceneProviderSurfaceDocumentSource,
IEveUnityPlayableWorldAssetManifestDocumentSource,
IEveUnitySceneCommandSink,
IDisposable
{
private readonly string _stateFilePathOverride;
private readonly string _surfaceId;
private readonly string _runtimeId;
private CultMeshReactiveDocument<EveSurfaceDocument>? _surfaceState;
private CultMeshReactiveDocument<AetheriaRuntimeCatalogSnapshot>? _catalogState;
private AetheriaRuntimeStateBootReport? _stateBoot;
private AetheriaClientState? _runtimeState;
private event Action<EveUnityPlayableWorldAssetManifestDocument>? AssetManifestDocumentAvailable;
public AetheriaEveUnitySceneProviderBridge(
string stateFilePathOverride = "",
string surfaceId = AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId,
string runtimeId = "unity-scene")
{
_stateFilePathOverride = stateFilePathOverride ?? "";
_surfaceId = string.IsNullOrWhiteSpace(surfaceId)
? AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId
: surfaceId;
_runtimeId = string.IsNullOrWhiteSpace(runtimeId) ? "unity-scene" : runtimeId;
CurrentDocument = CreateSurfaceDocument(AetheriaRuntimeSurfaceDocuments.EmptySurface(_surfaceId), 0);
CurrentDocumentManifest = new EveUnityPlayableWorldAssetManifestDocument(
AetheriaRuntimeVerseRecordKeys.DaemonAssetManifest.ToString(),
Array.Empty<EveUnityPlayableWorldAssetManifestDocumentEntry>(),
"aetheria.daemon");
}
public string SinkKind => "aetheria-daemon-command-boundary";
public EveUnitySceneProviderSurfaceDocument CurrentDocument { get; private set; }
EveUnityPlayableWorldAssetManifestDocument IEveUnityPlayableWorldAssetManifestDocumentSource.CurrentDocument =>
CurrentDocumentManifest;
public EveUnityPlayableWorldAssetManifestDocument CurrentDocumentManifest { get; private set; }
public event Action<EveUnitySceneProviderSurfaceDocument>? DocumentAvailable;
event Action<EveUnityPlayableWorldAssetManifestDocument> IEveUnityPlayableWorldAssetManifestDocumentSource.DocumentAvailable
{
add => AssetManifestDocumentAvailable += value;
remove => AssetManifestDocumentAvailable -= value;
}
public void Refresh()
{
var stateBoot = ResolveStateBoot();
if (!stateBoot.SupportsLocalStateFileRead || !stateBoot.StateFileExists)
return;
var runtimeState = ResolveRuntimeState(stateBoot);
var surface = ReadSurface(runtimeState, stateBoot);
if (surface != null)
{
CurrentDocument = CreateSurfaceDocument(surface, surface.Version);
DocumentAvailable?.Invoke(CurrentDocument);
}
CurrentDocumentManifest = ReadAssetManifest(runtimeState);
AssetManifestDocumentAvailable?.Invoke(CurrentDocumentManifest);
}
public void Submit(EveSurfaceCommandRequest request)
{
if (request == null) throw new ArgumentNullException(nameof(request));
var clientId = string.IsNullOrWhiteSpace(request.ClientId) ? _runtimeId : request.ClientId;
var stateBoot = ResolveStateBoot();
var control = AetheriaEveRuntimeUnityHooks.RequireControl(stateBoot, clientId);
if (control.TrySubmitSurfaceCommand(request, out var daemonEnvelope))
{
Debug.Log(
$"Submitted Aetheria daemon operation from Eve Unity scene: {daemonEnvelope!.Kind} {daemonEnvelope.CommandId}");
return;
}
var envelope = AetheriaEveRuntimeUnityHooks
.RequireUi(stateBoot, _runtimeId)
.SurfaceCommandAsync(request, clientId)
.GetAwaiter()
.GetResult();
Debug.Log($"Submitted Eve Unity scene operation for CultMesh bridge: {envelope.OperationId}");
}
public void Dispose()
{
_surfaceState?.Dispose();
_surfaceState = null;
_catalogState?.Dispose();
_catalogState = null;
}
private AetheriaRuntimeStateBootReport ResolveStateBoot()
{
_stateBoot = AetheriaEveRuntimeUnityHooks.RequireStateBoot(_stateFilePathOverride);
return _stateBoot;
}
private AetheriaClientState ResolveRuntimeState(AetheriaRuntimeStateBootReport stateBoot)
{
_runtimeState = AetheriaEveRuntimeUnityHooks.RequireRuntimeState(stateBoot, _runtimeId);
return _runtimeState;
}
private EveSurfaceDocument? ReadSurface(
AetheriaClientState runtimeState,
AetheriaRuntimeStateBootReport stateBoot)
{
try
{
var handle = runtimeState.EveSurfaceDocument(_surfaceId);
if (handle == null)
return null;
_surfaceState ??= handle.Reactive();
var resolver = AetheriaEveRuntimeUnityHooks.TryCreateStateRefResolver(stateBoot, _runtimeId);
return AetheriaRuntimeSurfaceDocuments.ToEveSurfaceDocument(_surfaceState.Current, resolver);
}
catch (KeyNotFoundException)
{
return null;
}
}
private EveUnityPlayableWorldAssetManifestDocument ReadAssetManifest(AetheriaClientState runtimeState)
{
_catalogState ??= runtimeState.Catalog.Reactive();
var manifest = AetheriaRuntimeAssets.ProjectManifest(
_catalogState.Current,
runId: "",
baseUri: "cultmesh://aetheria.local/assets");
return ToUnityPlayableWorldAssetManifest(manifest);
}
private EveUnitySceneProviderSurfaceDocument CreateSurfaceDocument(
EveSurfaceDocument surface,
long version)
{
return new EveUnitySceneProviderSurfaceDocument(
surface,
new EveUnitySceneProviderSurfaceAdvertisement(
_surfaceId,
"interactive-world",
new EveUnitySceneWorldInteraction(
"provider-authored-world-surface",
"aetheria.daemon.commands",
"aetheria.eve_command_acceptance_status.v1",
"provider-owns-world-state-assets-command-acceptance-and-receipts")),
SourcePointer(),
version);
}
private string SourcePointer()
{
var path = _stateBoot?.StateFilePath ?? _stateFilePathOverride;
return string.IsNullOrWhiteSpace(path)
? AetheriaRuntimeVerseRecordKeys.DaemonGameSurface.ToString()
: $"{path}#{_surfaceId}";
}
private static EveUnityPlayableWorldAssetManifestDocument ToUnityPlayableWorldAssetManifest(
AetheriaRuntimeAssetManifestDocument manifest)
{
var entries = (manifest.Assets ?? Array.Empty<AetheriaRuntimeAssetManifestEntry>())
.Where(entry => entry?.Ref != null && !string.IsNullOrWhiteSpace(entry.Ref.AssetKey))
.Select(entry => new EveUnityPlayableWorldAssetManifestDocumentEntry(
entry.Ref.AssetKey,
EntityKind(entry),
ResourcePath(entry.Ref),
entry.Ref.AssetKey,
"provider-asset-ref"))
.ToArray();
return new EveUnityPlayableWorldAssetManifestDocument(
AetheriaRuntimeVerseRecordKeys.DaemonAssetManifest.ToString(),
entries,
"aetheria.daemon");
}
private static string EntityKind(AetheriaRuntimeAssetManifestEntry entry)
{
return (entry.Tags ?? Array.Empty<string>())
.FirstOrDefault(tag => !string.IsNullOrWhiteSpace(tag) && !string.Equals(tag, "map", StringComparison.OrdinalIgnoreCase) && !string.Equals(tag, "icon", StringComparison.OrdinalIgnoreCase))
?? "";
}
private static string ResourcePath(AetheriaRuntimeAssetRef asset)
{
if (asset.Metadata != null && asset.Metadata.TryGetValue("resourcesPath", out var resourcesPath))
return resourcesPath ?? "";
return string.IsNullOrWhiteSpace(asset.AssetKey)
? ""
: asset.AssetKey.Replace('.', '/');
}
}
}

View file

@ -4,6 +4,7 @@
"references": [
"GameCult.Aetheria.State.Unity",
"GameCult.Eve.Surface",
"GameCult.Eve.UnityScene",
"GameCult.Eve.UnityUIToolkit"
],
"includePlatforms": [],

View file

@ -3,9 +3,10 @@
"displayName": "Aetheria Eve Runtime",
"version": "0.1.0",
"unity": "2021.3",
"description": "Aetheria runtime bridge from typed CultCache Eve surfaces to Unity UI Toolkit projection.",
"description": "Aetheria provider bridge from typed CultCache Eve surfaces to generic Eve Unity lowerers.",
"dependencies": {
"org.gamecult.aetheria.state": "0.1.0",
"org.gamecult.eve.unity-scene": "0.1.0",
"org.gamecult.eve.unity-uitoolkit": "0.1.0"
},
"keywords": [

View file

@ -22,6 +22,11 @@ namespace GameCult.Aetheria.State.Verse
Add(entries, MapIcon("body.planet", "Planet", "Sprites/Icons/Stroked/Planet"));
Add(entries, MapIcon("body.sun", "Sun", "Sprites/Icons/Stroked/Sun"));
Add(entries, MapIcon("body.asteroid", "Asteroid", "Sprites/Icons/Stroked/Planet"));
Add(entries, MapPrefab("prefab.entity.player", "Player Ship", "Prefabs/Ships/Djinni"));
Add(entries, MapPrefab("prefab.entity.ship", "Ship", "Prefabs/Ships/Djinni"));
Add(entries, MapPrefab("prefab.entity.station", "Station", "Prefabs/Stations/AsteroidOutpost"));
Add(entries, MapPrefab("prefab.entity.orbital", "Orbital", "Prefabs/Stations/Zenith"));
Add(entries, MapPrefab("prefab.entity.projectile", "Projectile", "Prefabs/Lightning"));
foreach (var inventoryAsset in InventoryUiAssets())
Add(entries, inventoryAsset);
@ -155,6 +160,18 @@ namespace GameCult.Aetheria.State.Verse
};
}
private static AetheriaRuntimeAssetManifestEntry MapPrefab(
string key,
string label,
string resourcePath)
{
return new AetheriaRuntimeAssetManifestEntry
{
Ref = Prefab(key, resourcePath),
Tags = new[] { "world", "prefab", label }
};
}
private static AetheriaRuntimeAssetRef Sprite(string key, string resourcePath)
{
return CultMeshAssetRef(
@ -173,19 +190,35 @@ namespace GameCult.Aetheria.State.Verse
"image/*");
}
private static AetheriaRuntimeAssetRef Prefab(string key, string resourcePath)
{
return CultMeshAssetRef(
key,
AetheriaRuntimeAssetKinds.Prefab,
resourcePath,
"application/vnd.unity.prefab");
}
private static AetheriaRuntimeAssetRef CultMeshAssetRef(
string key,
string kind,
string resourcePath,
string mimeType)
{
var normalizedResourcePath = NormalizeResourcePath(resourcePath);
return new AetheriaRuntimeAssetRef
{
AssetKey = key ?? "",
Kind = kind ?? "",
Uri = CultMeshAssetUri(key),
Transport = AetheriaRuntimeAssetTransports.CultMesh,
MimeType = mimeType ?? ""
MimeType = mimeType ?? "",
Metadata = string.IsNullOrWhiteSpace(normalizedResourcePath)
? new Dictionary<string, string>()
: new Dictionary<string, string>(StringComparer.Ordinal)
{
["resourcesPath"] = normalizedResourcePath
}
};
}

View file

@ -32,6 +32,7 @@ namespace GameCult.Aetheria.State.Verse
activeMainMenuSurfaceId = NormalizeMainMenuSurfaceId(activeMainMenuSurfaceId);
var surfaceChildren = new List<AetheriaRuntimeSurfaceComponent>
{
PlayableWorldSurface("aetheria.daemon.game.world", run, zone, run.CurrentEntityKey),
GravityFieldSurface("aetheria.daemon.game.field"),
MainMenuOverlay("aetheria.daemon.game.main_menu", activeMainMenuSurfaceId),
Node(
@ -269,6 +270,124 @@ namespace GameCult.Aetheria.State.Verse
return AetheriaRuntimeDaemonSurfaceCommandCatalog.CommandName(kind);
}
private static AetheriaRuntimeSurfaceComponent PlayableWorldSurface(
string id,
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeZoneSnapshotCommit zone,
string currentEntityKey)
{
run ??= new AetheriaRuntimeRunCheckpointCommit();
zone ??= new AetheriaRuntimeZoneSnapshotCommit();
var props = new Dictionary<string, string>(StringComparer.Ordinal)
{
["label"] = string.IsNullOrWhiteSpace(zone.Name) ? "Aetheria World" : zone.Name,
["statePointerId"] = AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString(),
["assetManifest"] = AetheriaRuntimeVerseRecordKeys.DaemonAssetManifest.ToString(),
["inputProfile"] = "arpg.pointer-keyboard.v1",
["cameraRig"] = "arpg.orbital-follow.v1",
["playerEntityId"] = currentEntityKey ?? "",
["movementCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.SetMoveVector),
["focusCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.TargetNearest),
["targetCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.SetTarget),
["actionCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.FireWeaponGroup),
["zoneIndex"] = zone.ZoneIndex.ToString(CultureInfo.InvariantCulture),
["runId"] = run.RunId ?? ""
};
var entities = (zone.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
.Where(candidate => candidate != null && candidate.IsActive)
.Select(candidate => PlayableWorldEntity(candidate, run, zone, currentEntityKey))
.ToArray();
return new AetheriaRuntimeSurfaceComponent(
id,
"world.scene3d",
props,
entities,
AetheriaRuntimeSurfaceStateBindings.FromProps(props),
Array.Empty<AetheriaRuntimeEmbeddedDocumentSlot>(),
Layout(
("position", "absolute"),
("top", "0"),
("right", "0"),
("bottom", "0"),
("left", "0"),
("width", "100%"),
("height", "100%")),
new Dictionary<string, string>
{
["background"] = "transparent"
});
}
private static AetheriaRuntimeSurfaceComponent PlayableWorldEntity(
AetheriaRuntimeEntitySnapshotCommit entity,
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeZoneSnapshotCommit zone,
string currentEntityKey)
{
var entityId = run.EntityRecordKey(zone.ZoneIndex, entity.EntityIndex);
var props = new Dictionary<string, string>(StringComparer.Ordinal)
{
["entityId"] = entityId,
["entityKind"] = entity.Kind ?? "",
["label"] = string.IsNullOrWhiteSpace(entity.Name) ? entityId : entity.Name,
["faction"] = entity.FactionKey ?? "",
["assetRef"] = PlayableWorldAssetRef(entity),
["position"] = FormatPosition(entity),
["rotationY"] = HeadingYaw(entity).ToString("0.###", CultureInfo.InvariantCulture),
["radius"] = PlayableWorldRadius(entity).ToString("0.###", CultureInfo.InvariantCulture),
["selectable"] = "true",
["controllable"] = string.Equals(entityId, currentEntityKey, StringComparison.Ordinal) ? "true" : "false",
["focusCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.TargetNearest),
["moveCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.SetMoveVector),
["targetCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.SetTarget),
["actionCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.FireWeaponGroup)
};
return new AetheriaRuntimeSurfaceComponent(
$"aetheria.daemon.game.world.entity.{entity.EntityIndex}",
"world.entity3d",
props,
Array.Empty<AetheriaRuntimeSurfaceComponent>());
}
private static string PlayableWorldAssetRef(AetheriaRuntimeEntitySnapshotCommit entity)
{
if (entity == null)
return "";
var kind = (entity.Kind ?? "").Trim().ToLowerInvariant();
if (kind.Contains("station"))
return "prefab.entity.station";
if (kind.Contains("projectile"))
return "prefab.entity.projectile";
if (kind.Contains("orbital"))
return "prefab.entity.orbital";
if (string.Equals(entity.FactionKey, "player", StringComparison.OrdinalIgnoreCase))
return "prefab.entity.player";
return "prefab.entity.ship";
}
private static double PlayableWorldRadius(AetheriaRuntimeEntitySnapshotCommit entity)
{
var kind = (entity.Kind ?? "").Trim().ToLowerInvariant();
if (kind.Contains("station"))
return 48.0;
if (kind.Contains("projectile"))
return Math.Max(1.0, entity.Visibility > 0.0 ? entity.Visibility : 3.0);
return 12.0;
}
private static double HeadingYaw(AetheriaRuntimeEntitySnapshotCommit entity)
{
if (entity == null)
return 0.0;
if (Math.Abs(entity.DirectionX) <= 0.0001 && Math.Abs(entity.DirectionY) <= 0.0001)
return 0.0;
return Math.Atan2(entity.DirectionX, entity.DirectionY);
}
private static AetheriaRuntimeSurfaceComponent GravityFieldSurface(string id)
{
var viewport = DefaultViewport();