Example #1
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;
            }
        }
Example #2
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();
            }
        }
Example #3
0
        public void OnStreamEvent(SyncedData <StreamInstanceData> stream, StreamEvent streamEvent)
        {
            var objectKey = new StreamKey(stream.key.source, PersistentKey.GetKey <SyncObject>(stream.data.syncObject.Id));

            if (streamEvent == StreamEvent.Added)
            {
                m_SyncObjects[objectKey] = stream.data.syncObject;
                var syncObjectBinding = ImportInstance(stream.data.instance);

                var key = stream.data.instance.key;
                m_Instances[key]            = syncObjectBinding;
                syncObjectBinding.streamKey = key;

                m_Output.SendStreamAdded(new SyncedData <GameObject>(key, syncObjectBinding.gameObject));
            }
            else if (streamEvent == StreamEvent.Changed)
            {
                var key = stream.data.instance.key;
                // The instance moved, or the name/metadata changed.
                var syncObjectBinding = m_Instances[key];

                ImportersUtils.SetTransform(syncObjectBinding.transform, stream.data.instance.instance.Transform);
                ImportersUtils.SetMetadata(syncObjectBinding.gameObject, stream.data.instance.instance.Metadata);
                syncObjectBinding.gameObject.name = stream.data.instance.instance.Name;

                m_Output.SendStreamChanged(new SyncedData <GameObject>(key, syncObjectBinding.gameObject));
            }
            else if (streamEvent == StreamEvent.Removed)
            {
                var key = stream.data.instance.key;
                // The instance either moved, or the metadata changed.
                var syncObjectBinding = m_Instances[key];

                m_Instances.Remove(key);

                m_Output.SendStreamRemoved(new SyncedData <GameObject>(key, syncObjectBinding.gameObject));

                if (m_Originals.TryGetValue(objectKey, out var original))
                {
                    UntrackDependencies(original.Dependencies);

                    if (original.NbActiveInstances == 1)
                    {
                        m_Originals.Remove(objectKey);
                    }
                    else
                    {
                        --original.NbActiveInstances;
                        m_Originals[objectKey] = original;
                    }
                }

                Object.Destroy(syncObjectBinding.gameObject);
            }
        }
Example #4
0
        void OnStreamAdded(SyncedData <StreamInstance> stream)
        {
            var metadata = stream.data.instance.Metadata;

            if (metadata != null && metadata.Parameters.TryGetValue("Category", out var category))
            {
                if (!m_Instances.TryGetValue(category.Value, out var filter))
                {
                    m_Instances[category.Value] = filter = new FilterData();
                }

                filter.streams.Add(stream);

                if (filter.visible)
                {
                    m_StreamOutput.SendStreamAdded(stream);
                }
            }
            else
            {
                m_StreamOutput.SendStreamAdded(stream);
            }
        }
        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;
            }
        }