Report authoritative SoA entity state
This commit is contained in:
parent
93551237fa
commit
838a5ac923
3 changed files with 87 additions and 6 deletions
|
|
@ -24,6 +24,8 @@ namespace GameCult.Eve.UnityScene
|
|||
_sink = sink ?? throw new ArgumentNullException(nameof(sink));
|
||||
}
|
||||
|
||||
public int ActiveEntities => _known.Count;
|
||||
|
||||
public void Apply(EveEntitySoaViewDocument document)
|
||||
{
|
||||
using var view = EveUnityEntitySoaView.Open(document);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ namespace GameCult.Eve.UnityScene
|
|||
|
||||
public EveUnitySceneProjection? ActiveProjection => _client.ActiveProjection;
|
||||
|
||||
public EveUnityPlayableWorldPresentation? LastPresentation => _client.LastPresentation;
|
||||
public EveUnityPlayableWorldPresentation? LastPresentation => ComposePresentation(_client.LastPresentation);
|
||||
|
||||
public EveUnitySceneCommandReceipt? LastReceipt => _client.LastReceipt;
|
||||
|
||||
|
|
@ -109,15 +109,17 @@ namespace GameCult.Eve.UnityScene
|
|||
public EveUnityPlayableWorldPresentation Connect()
|
||||
{
|
||||
EnsureAssetManifestConnected();
|
||||
var presentation = _client.Connect();
|
||||
_client.Connect();
|
||||
EnsureEntityViewsConnected();
|
||||
return presentation;
|
||||
return ComposePresentation(_client.LastPresentation)!;
|
||||
}
|
||||
|
||||
public EveUnityPlayableWorldPresentation Refresh()
|
||||
{
|
||||
EnsureAssetManifestConnected();
|
||||
return _client.Refresh();
|
||||
EnsureEntityViewsConnected();
|
||||
_client.Refresh();
|
||||
return ComposePresentation(_client.LastPresentation)!;
|
||||
}
|
||||
|
||||
public EveSurfaceCommandRequest SubmitMoveIntent(
|
||||
|
|
@ -207,6 +209,22 @@ namespace GameCult.Eve.UnityScene
|
|||
}
|
||||
|
||||
private void OnEntityViewAvailable(EveEntitySoaViewDocument document) => _entityPresenter.Apply(document);
|
||||
|
||||
private EveUnityPlayableWorldPresentation? ComposePresentation(
|
||||
EveUnityPlayableWorldPresentation? surfacePresentation)
|
||||
{
|
||||
if (surfacePresentation == null || _entityViews?.CurrentEntityView == null)
|
||||
return surfacePresentation;
|
||||
|
||||
return new EveUnityPlayableWorldPresentation(
|
||||
surfacePresentation.WorldRootId,
|
||||
surfacePresentation.PlayerEntityId,
|
||||
surfacePresentation.InputProfile,
|
||||
surfacePresentation.CameraRig,
|
||||
surfacePresentation.UpsertedEntities,
|
||||
surfacePresentation.RemovedEntities,
|
||||
_entityPresenter.ActiveEntities);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class EveUnityLivePlayableWorldAssetProvider : IEveUnityNativeAssetProvider
|
||||
|
|
|
|||
|
|
@ -419,6 +419,52 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
Assert.That(runtime.LastReceipt.ShouldRefreshProviderSurface, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PlayableWorldRuntimeReportsAuthoritativeSoaEntityCountOnConnect()
|
||||
{
|
||||
var location = $"eve-unity-runtime-soa-{Guid.NewGuid():N}";
|
||||
using var mapped = MemoryMappedFile.CreateNew(location, 16);
|
||||
using (var writer = mapped.CreateViewAccessor())
|
||||
{
|
||||
writer.Write(0, 4f);
|
||||
writer.Write(4, 5f);
|
||||
writer.Write(8, 6f);
|
||||
writer.Write(12, 41);
|
||||
}
|
||||
var entityView = new EveEntitySoaViewDocument
|
||||
{
|
||||
ProviderId = "aetheria",
|
||||
ViewId = "pilot",
|
||||
Generation = 1,
|
||||
Backend = "memory_mapped_file",
|
||||
Buffers = new[] { new EveEntitySoaBuffer { BufferId = "hot", Backend = "memory_mapped_file", Location = location, ByteLength = 16, Generation = 1 } },
|
||||
Columns = new[]
|
||||
{
|
||||
new EveEntitySoaColumn { ColumnId = "position", Semantic = "transform.position", BufferId = "hot", ScalarType = "float3", ElementStride = 12, ElementCount = 1 },
|
||||
new EveEntitySoaColumn { ColumnId = "entity-index", Semantic = "entity.index", BufferId = "hot", ScalarType = "int32", ByteOffset = 12, ElementStride = 4, ElementCount = 1 }
|
||||
}
|
||||
};
|
||||
var surfaceDocuments = new FakeProviderSurfaceDocumentSource(
|
||||
new EveUnitySceneProviderSurfaceDocument(
|
||||
PlayableArpgDocument(),
|
||||
Advertisement("aetheria.daemon.game"),
|
||||
"cultmesh://aetheria/eve/surfaces/aetheria.daemon.game",
|
||||
1),
|
||||
entityView);
|
||||
var sceneSink = new FakePlayableWorldSceneSink();
|
||||
|
||||
using var runtime = new EveUnityPlayableWorldRuntime(
|
||||
surfaceDocuments,
|
||||
new FakeCommandSink("cultmesh-command-sink"),
|
||||
sceneSink);
|
||||
|
||||
var presentation = runtime.Connect();
|
||||
|
||||
Assert.That(presentation.ActiveEntities, Is.EqualTo(1));
|
||||
Assert.That(runtime.LastPresentation!.ActiveEntities, Is.EqualTo(1));
|
||||
Assert.That(sceneSink.Upserts.Exists(entry => entry.entity.EntityId == "entity:41"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LiveProviderBridgeFeedsPlayableWorldRuntimeThroughTransportPorts()
|
||||
{
|
||||
|
|
@ -1544,22 +1590,37 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
}
|
||||
}
|
||||
|
||||
private sealed class FakeProviderSurfaceDocumentSource : IEveUnitySceneProviderSurfaceDocumentSource
|
||||
private sealed class FakeProviderSurfaceDocumentSource :
|
||||
IEveUnitySceneProviderSurfaceDocumentSource,
|
||||
IEveUnityEntitySoaViewDocumentSource
|
||||
{
|
||||
public FakeProviderSurfaceDocumentSource(EveUnitySceneProviderSurfaceDocument currentDocument)
|
||||
public FakeProviderSurfaceDocumentSource(
|
||||
EveUnitySceneProviderSurfaceDocument currentDocument,
|
||||
EveEntitySoaViewDocument? currentEntityView = null)
|
||||
{
|
||||
CurrentDocument = currentDocument;
|
||||
CurrentEntityView = currentEntityView;
|
||||
}
|
||||
|
||||
public EveUnitySceneProviderSurfaceDocument CurrentDocument { get; private set; }
|
||||
|
||||
public event Action<EveUnitySceneProviderSurfaceDocument>? DocumentAvailable;
|
||||
|
||||
public EveEntitySoaViewDocument? CurrentEntityView { get; private set; }
|
||||
|
||||
public event Action<EveEntitySoaViewDocument>? EntityViewAvailable;
|
||||
|
||||
public void Publish(EveUnitySceneProviderSurfaceDocument document)
|
||||
{
|
||||
CurrentDocument = document;
|
||||
DocumentAvailable?.Invoke(document);
|
||||
}
|
||||
|
||||
public void PublishEntityView(EveEntitySoaViewDocument document)
|
||||
{
|
||||
CurrentEntityView = document;
|
||||
EntityViewAvailable?.Invoke(document);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class FakeCommandReceiptSource : IEveUnitySceneCommandReceiptSource
|
||||
|
|
|
|||
Reference in a new issue