Exemplo n.º 1
0
        protected override void UpdateInternal(float unscaledDeltaTime)
        {
            while (m_PendingRemoved.TryDequeue(out var stream))
            {
                var streamAsset = (StreamAsset)stream;
                var syncedData  = new SyncedData <StreamAsset>(streamAsset.key, streamAsset);
                m_AssetOutput.SendStreamRemoved(syncedData);
            }

            while (m_PendingAdded.TryDequeue(out var stream))
            {
                var streamAsset = (StreamAsset)stream;
                var syncedData  = new SyncedData <StreamAsset>(streamAsset.key, streamAsset);
                m_AssetOutput.SendStreamAdded(syncedData);
            }

            while (m_PendingModified.TryDequeue(out var stream))
            {
                var streamAsset = (StreamAsset)stream;
                var syncedData  = new SyncedData <StreamAsset>(streamAsset.key, streamAsset);
                m_AssetOutput.SendStreamChanged(syncedData);
            }

            if (m_Task != null && m_Task.IsCompleted)
            {
                m_AssetOutput.SendEnd();
                m_Task = null;

                LogTimes();
            }
        }
        protected override void UpdateInternal(float unscaledDeltaTime)
        {
            if (m_Settings.bypass)
            {
                return;
            }

            lock (m_StreamEvents)
            {
                m_Counter = 0;
                while (m_Counter < m_Settings.limit && m_StreamQueue.TryDequeue(out var stream))
                {
                    if (!m_StreamEvents.TryGetValue(stream, out var eventType))
                    {
                        Debug.LogError($"StreamMessageType not found for {stream.ToString()}");
                    }

                    // do nothing if the original message type has been cancelled, do not count towards limit
                    if (eventType.HasValue)
                    {
                        m_StreamOutput.SendStreamEvent(stream, eventType.Value);
                        ++m_Counter;
                    }

                    m_StreamEvents.Remove(stream);
                }
            }

            if (m_State == State.WaitingToFinish && m_StreamQueue.IsEmpty)
            {
                m_StreamOutput.SendEnd();
                m_State = State.Idle;
            }
        }
Exemplo n.º 3
0
        protected override void UpdateInternal(float unscaledDeltaTime)
        {
            while (m_DownloadResults.TryDequeue(out var result))
            {
                if (result.exception != null)
                {
                    m_Hub.Broadcast(new StreamingErrorEvent(result.streamAsset.key, result.streamAsset.boundingBox, result.exception));
                    continue;
                }

                var streamInstance = new StreamInstance(result.streamAsset.key,
                                                        result.streamInstance, result.streamAsset.boundingBox);

                var key = result.streamAsset.key;

                if (m_Cache.TryGetValue(key, out var previousStreamInstance))
                {
                    if (previousStreamInstance.instance.ObjectId != result.streamInstance.ObjectId)
                    {
                        m_InstanceDataOutput.SendStreamRemoved(new SyncedData <StreamInstance>(key, previousStreamInstance));
                        m_InstanceDataOutput.SendStreamAdded(new SyncedData <StreamInstance>(key, streamInstance));
                    }
                    else
                    {
                        if (m_DirtySyncObject.Contains(key))
                        {
                            m_DirtySyncObject.Remove(key);
                            m_InstanceDataOutput.SendStreamRemoved(new SyncedData <StreamInstance>(key, previousStreamInstance));
                            m_InstanceDataOutput.SendStreamAdded(new SyncedData <StreamInstance>(key, streamInstance));
                        }
                        else
                        {
                            m_InstanceDataOutput.SendStreamChanged(new SyncedData <StreamInstance>(key, streamInstance));
                        }
                    }
                }
                else
                {
                    m_InstanceDataOutput.SendStreamAdded(new SyncedData <StreamInstance>(key, streamInstance));
                }

                m_Cache[key] = streamInstance;

                var syncObjectKey = new StreamKey(streamInstance.key.source, PersistentKey.GetKey <SyncObject>(streamInstance.instance.ObjectId));
                if (!m_Instances.TryGetValue(syncObjectKey, out var instances))
                {
                    m_Instances[syncObjectKey] = instances = new HashSet <StreamAsset>();
                }

                instances.Add(result.streamAsset);
            }

            if (m_State == State.WaitingToFinish && m_DownloadRequests.IsEmpty)
            {
                m_InstanceDataOutput.SendEnd();
                m_State = State.Idle;
            }
        }
Exemplo n.º 4
0
 public void OnEnd()
 {
     m_StreamOutput.SendEnd();
 }
        protected override void UpdateInternal(float unscaledDeltaTime)
        {
            // Postponing instances if there are available models (in order to update model caches first)
            while (m_DownloadedModels.Count == 0 && m_DownloadedInstances.TryDequeue(out var result))
            {
                if (result.exception != null)
                {
                    m_Hub.Broadcast(new StreamingErrorEvent(result.instanceData.instance.key, result.instanceData.instance.boundingBox, result.exception));
                    continue;
                }

                Trace(">>>>>> SENDING " + result.instanceData.instance.instance.Name);

                // TODO Have type dependencies inside the result
                var meshes    = result.downloadedMeshes;
                var textures  = result.downloadedTextures;
                var materials = result.downloadedMaterials;

                foreach (var asset in meshes)
                {
                    m_AddedModels.Add(asset.key);
                    if (!m_MemTracker.ContainsKey(m_MeshesHandle, asset.key))
                    {
                        Trace("        >> Sending " + asset.GetType().Name + " " + asset.asset.Name);
                        m_SyncMeshOutput.SendStreamAdded(new SyncedData <SyncMesh>(asset.key, asset.asset));
                    }
                }

                foreach (var asset in textures)
                {
                    if (m_AddedModels.Add(asset.key))
                    {
                        Trace("        >> Sending " + asset.GetType().Name + " " + asset.asset.Name);
                        m_SyncTextureOutput.SendStreamAdded(new SyncedData <SyncTexture>(asset.key, asset.asset));
                    }
                }

                foreach (var asset in materials)
                {
                    if (m_AddedModels.Add(asset.key))
                    {
                        Trace("        >> Sending " + asset.GetType().Name + " " + asset.asset.Name);
                        m_SyncMaterialOutput.SendStreamAdded(new SyncedData <SyncMaterial>(asset.key, asset.asset));
                    }
                }

                var key = result.instanceData.instance.key;

                if (m_InstanceCache.ContainsKey(key))
                {
                    m_InstanceDataOutput.SendStreamChanged(new SyncedData <StreamInstanceData>(key, result.instanceData));
                }
                else
                {
                    m_InstanceDataOutput.SendStreamAdded(new SyncedData <StreamInstanceData>(key, result.instanceData));
                }

                m_InstanceCache[key] = result.instanceData;

                Trace(">> DONE " + result.instanceData.instance.instance.Name);
            }

            while (m_DownloadedModels.TryDequeue(out var result))
            {
                // Skip without broadcasting error. Errors are broadcasted for each SyncInstance, not for SyncObject or each sub-resource
                if (result.exception != null)
                {
                    continue;
                }

                TrySendAddedOrChanged(result.assetEntry, m_SyncTextureOutput);
                TrySendAddedOrChanged(result.assetEntry, m_SyncMeshOutput);
                TrySendAddedOrChanged(result.assetEntry, m_SyncMaterialOutput);
            }

            if (m_State == State.WaitingToFinish && m_DownloadRequests.IsEmpty && m_DownloadedModels.IsEmpty)
            {
                m_InstanceDataOutput.SendEnd();
                m_State = State.Idle;
            }
        }