Poll advertised entity views for live updates
This commit is contained in:
parent
7bde1011a1
commit
474cadac1c
2 changed files with 39 additions and 3 deletions
|
|
@ -57,6 +57,9 @@ namespace GameCult.Eve.UnityScene
|
|||
private EveAdvertisedSurface? _advertisedSurface;
|
||||
private CultMeshBodyPublicationResolver? _bodyResolver;
|
||||
private DateTime _nextReceiptPollUtc;
|
||||
private DateTime _nextEntityViewPollUtc;
|
||||
private long _lastQueuedEntityViewEpoch = -1;
|
||||
private long _lastQueuedEntityViewSequence = -1;
|
||||
|
||||
public EveUnityCultMeshLiveProviderTransport(
|
||||
string replicaPath,
|
||||
|
|
@ -133,6 +136,7 @@ namespace GameCult.Eve.UnityScene
|
|||
|
||||
public void PumpLiveEvents()
|
||||
{
|
||||
PollCurrentEntityView();
|
||||
while (_liveDocuments.TryDequeue(out var document))
|
||||
{
|
||||
if (document is EveEntitySoaViewDocument entityView)
|
||||
|
|
@ -145,6 +149,36 @@ namespace GameCult.Eve.UnityScene
|
|||
PollPendingReceipts();
|
||||
}
|
||||
|
||||
private void PollCurrentEntityView()
|
||||
{
|
||||
if (DateTime.UtcNow < _nextEntityViewPollUtc)
|
||||
return;
|
||||
_nextEntityViewPollUtc = DateTime.UtcNow.AddMilliseconds(250);
|
||||
var lowered = new EveUnitySceneSurfaceLowerer()
|
||||
.Lower(CurrentSurfaceDocument.SurfaceDocument, CurrentSurfaceDocument.AdvertisedSurface);
|
||||
var pointer = lowered.PlayableWorld?.EntityViewPointerId ?? "";
|
||||
if (string.IsNullOrWhiteSpace(pointer))
|
||||
return;
|
||||
var current = _snapshot!
|
||||
.FetchDocumentsAsync<EveEntitySoaViewDocument>(
|
||||
recordKeys: new[] { pointer },
|
||||
schemaIds: new[] { EveEntitySoaViewDocument.SchemaId })
|
||||
.GetAwaiter().GetResult().FirstOrDefault();
|
||||
if (current != null)
|
||||
QueueEntityView(current);
|
||||
}
|
||||
|
||||
private void QueueEntityView(EveEntitySoaViewDocument document)
|
||||
{
|
||||
if (document.ProducerEpoch < _lastQueuedEntityViewEpoch ||
|
||||
(document.ProducerEpoch == _lastQueuedEntityViewEpoch &&
|
||||
document.Sequence <= _lastQueuedEntityViewSequence))
|
||||
return;
|
||||
_lastQueuedEntityViewEpoch = document.ProducerEpoch;
|
||||
_lastQueuedEntityViewSequence = document.Sequence;
|
||||
_liveDocuments.Enqueue(document);
|
||||
}
|
||||
|
||||
private void PollPendingReceipts()
|
||||
{
|
||||
if (_pendingCommandIds.Count == 0 || DateTime.UtcNow < _nextReceiptPollUtc)
|
||||
|
|
@ -509,7 +543,7 @@ namespace GameCult.Eve.UnityScene
|
|||
schemaIds: new[] { EveEntitySoaViewDocument.SchemaId })
|
||||
.GetAwaiter().GetResult().FirstOrDefault();
|
||||
if (current != null)
|
||||
_liveDocuments.Enqueue(current);
|
||||
QueueEntityView(current);
|
||||
}
|
||||
_subscriptions.SubscribeAsync(
|
||||
"eve-unity-surface",
|
||||
|
|
@ -530,7 +564,9 @@ namespace GameCult.Eve.UnityScene
|
|||
|
||||
private void OnReplicatedDocumentChanged(CultNetReplicatedDocumentChange change)
|
||||
{
|
||||
if (change.Document is EveEntitySoaViewDocument or EveSurfaceDocument or EveCommandReceiptDocument)
|
||||
if (change.Document is EveEntitySoaViewDocument entityView)
|
||||
QueueEntityView(entityView);
|
||||
else if (change.Document is EveSurfaceDocument or EveCommandReceiptDocument)
|
||||
_liveDocuments.Enqueue(change.Document);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "org.gamecult.eve.unity-scene",
|
||||
"displayName": "Eve Unity Scene Lowering",
|
||||
"version": "0.3.14",
|
||||
"version": "0.3.15",
|
||||
"unity": "2021.3",
|
||||
"description": "Provider-agnostic Unity scene shell for gamecult.eve.surface.v1 interactive world surfaces.",
|
||||
"dependencies": {
|
||||
|
|
|
|||
Reference in a new issue