コード例 #1
0
        bool ProcessBus(MessagingBus bus)
        {
            if (!bus.enabled || bus.pendingMessagesCount <= 0)
            {
                return(false);
            }

            float startTime = Time.realtimeSinceStartup;

            float timeBudget = timeBudgetCounter;

            //TODO(Brian): We should use the returning yieldReturn IEnumerator and MoveNext() it manually each frame to
            //             account the coroutine processing into the budget. Until we do that we just skip it.
            bus.ProcessQueue(timeBudget, out _);
            RefreshControllerEnabledState(bus.owner);

            timeBudgetCounter -= Time.realtimeSinceStartup - startTime;

            if (timeBudgetCounter <= 0)
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        IEnumerator ProcessMessages()
        {
            while (true)
            {
                if (populateBusesDirty)
                {
                    PopulateBusesToBeProcessed();
                    populateBusesDirty = false;
                }

                timeBudgetCounter = CommonScriptableObjects.rendererState.Get() ? MAX_GLOBAL_MSG_BUDGET : float.MaxValue;

                for (int i = 0; i < busesToProcessCount; ++i)
                {
                    MessagingBus bus = busesToProcess[i];

                    if (ProcessBus(bus))
                    {
                        break;
                    }
                }

                if (pendingInitMessagesCount == 0)
                {
                    UnityGLTF.GLTFSceneImporter.budgetPerFrameInMilliseconds = Mathf.Clamp(timeBudgetCounter, GLTF_BUDGET_MIN, GLTF_BUDGET_MAX) * 1000f;
                }
                else
                {
                    UnityGLTF.GLTFSceneImporter.budgetPerFrameInMilliseconds = 0;
                }

                yield return(null);
            }
        }
コード例 #3
0
        private MessagingBus AddMessageBus(MessagingBusType type)
        {
            var newMessagingBus = new MessagingBus(type, messageHandler, this);

            newMessagingBus.debugTag = debugTag;

            messagingBuses.Add(type, newMessagingBus);
            return(newMessagingBus);
        }
コード例 #4
0
        private MessagingBus AddMessageBus(string id)
        {
            var newMessagingBus = new MessagingBus(id, messageHandler, this);

            newMessagingBus.debugTag = debugTag;

            messagingBuses.Add(id, newMessagingBus);
            return(newMessagingBus);
        }
コード例 #5
0
        public MessagingController(IMessageProcessHandler messageHandler, string debugTag = null)
        {
            this.debugTag       = debugTag;
            this.messageHandler = messageHandler;

            //TODO(Brian): This is too hacky, most of the controllers won't be using this system. Refactor this in the future.
            uiBus     = AddMessageBus(MessagingBusType.UI);
            initBus   = AddMessageBus(MessagingBusType.INIT);
            systemBus = AddMessageBus(MessagingBusType.SYSTEM);

            currentQueueState = QueueState.Init;

            StartBus(MessagingBusType.INIT);
            StartBus(MessagingBusType.UI);
        }
コード例 #6
0
        private IEnumerator RefreshProfilingData()
        {
            while (true)
            {
                int sharedCount       = 0;
                int sharedAttachCount = 0;
                int componentCount    = 0;
                int entityCount       = 0;
                int materialCount     = 0;
                int meshesCount       = 0;

                var loadedScenes = Environment.i.world.state.loadedScenes;

                foreach (var v in loadedScenes)
                {
                    if (v.Value.metricsController != null)
                    {
                        meshesCount   += v.Value.metricsController.GetModel().meshes;
                        materialCount += v.Value.metricsController.GetModel().materials;
                    }

                    sharedCount += v.Value.disposableComponents.Count;

                    foreach (var e in v.Value.disposableComponents)
                    {
                        sharedAttachCount += e.Value.attachedEntities.Count;
                    }

                    entityCount += v.Value.entities.Count;

                    foreach (var e in v.Value.entities)
                    {
                        componentCount += e.Value.components.Count;
                    }
                }

                statsPanel.SetCellText(1, (int)Rows.SHARED_OBJECTS_COUNT, sharedCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.COMPONENT_OBJECTS_COUNT, componentCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.ENTITY_OBJECTS_COUNT, entityCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.MATERIAL_COUNT, materialCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.MESHES_COUNT, meshesCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.GLTF_BEING_LOADED, UnityGLTF.GLTFComponent.downloadingCount.ToString() + " ... In Queue: " + UnityGLTF.GLTFComponent.queueCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.AB_BEING_LOADED, AssetPromise_AB.downloadingCount.ToString() + " ...  In Queue: " + AssetPromise_AB.queueCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.RENDERER_UNLOCK_SEGS, RenderingController.firstActivationTime.ToString(CultureInfo.InvariantCulture));

                string busesLog = "";
                Dictionary <string, int> pendingMessagesCount = new Dictionary <string, int>();
                Dictionary <string, int> messagesReplaced     = new Dictionary <string, int>();

                MessagingControllersManager messagingManager = Environment.i.messaging.manager as MessagingControllersManager;

                using (var controllersIter = messagingManager.messagingControllers.GetEnumerator())
                {
                    while (controllersIter.MoveNext())
                    {
                        using (var iterator = controllersIter.Current.Value.messagingBuses.GetEnumerator())
                        {
                            while (iterator.MoveNext())
                            {
                                //access to pair using iterator.Current
                                MessagingBusType key = iterator.Current.Key;
                                MessagingBus     bus = controllersIter.Current.Value.messagingBuses[key];

                                string keyString = key.ToString();

                                if (!pendingMessagesCount.ContainsKey(keyString))
                                {
                                    pendingMessagesCount[keyString] = 0;
                                }

                                if (!messagesReplaced.ContainsKey(keyString))
                                {
                                    messagesReplaced[keyString] = 0;
                                }

                                pendingMessagesCount[keyString] += bus.pendingMessagesCount;
                                messagesReplaced[keyString]     += bus.unreliableMessagesReplaced;
                            }
                        }
                    }
                }

                busesLog += $"{MessagingBusType.UI.ToString()} bus: {pendingMessagesCount[MessagingBusType.UI.ToString()]} replaced: {messagesReplaced[MessagingBusType.UI.ToString()]}\n";
                busesLog += $"{MessagingBusType.INIT.ToString()} bus: {pendingMessagesCount[MessagingBusType.INIT.ToString()]} replaced: {messagesReplaced[MessagingBusType.INIT.ToString()]}\n";
                busesLog += $"{MessagingBusType.SYSTEM.ToString()} bus: {pendingMessagesCount[MessagingBusType.SYSTEM.ToString()]} replaced: {messagesReplaced[MessagingBusType.SYSTEM.ToString()]}\n";

                statsPanel.SetCellText(1, (int)Rows.MESSAGE_BUSES, busesLog);

                yield return(WaitForSecondsCache.Get(0.2f));
            }
        }
コード例 #7
0
        private IEnumerator RefreshProfilingData()
        {
            while (true)
            {
                int sharedCount       = 0;
                int sharedAttachCount = 0;
                int componentCount    = 0;
                int entityCount       = 0;
                int materialCount     = 0;
                int meshesCount       = 0;

                foreach (var v in SceneController.i.loadedScenes)
                {
                    if (v.Value.metricsController != null)
                    {
                        meshesCount   += v.Value.metricsController.GetModel().meshes;
                        materialCount += v.Value.metricsController.GetModel().materials;
                    }

                    sharedCount += v.Value.disposableComponents.Count;

                    foreach (var e in v.Value.disposableComponents)
                    {
                        sharedAttachCount += e.Value.attachedEntities.Count;
                    }

                    entityCount += v.Value.entities.Count;

                    foreach (var e in v.Value.entities)
                    {
                        componentCount += e.Value.components.Count;
                    }
                }

                statsPanel.SetCellText(1, (int)Rows.SHARED_OBJECTS_COUNT, sharedCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.COMPONENT_OBJECTS_COUNT, componentCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.ENTITY_OBJECTS_COUNT, entityCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.MATERIAL_COUNT, materialCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.MESHES_COUNT, meshesCount.ToString());
                statsPanel.SetCellText(1, (int)Rows.GLTF_BEING_LOADED, UnityGLTF.GLTFComponent.downloadingCount.ToString() + " / " + UnityGLTF.GLTFComponent.queueCount.ToString());

                string busesLog = "";
                Dictionary <string, int> pendingMessagesCount = new Dictionary <string, int>();
                Dictionary <string, int> messagesReplaced     = new Dictionary <string, int>();

                using (var controllersIter = MessagingControllersManager.i.messagingControllers.GetEnumerator())
                {
                    while (controllersIter.MoveNext())
                    {
                        using (var iterator = controllersIter.Current.Value.messagingBuses.GetEnumerator())
                        {
                            while (iterator.MoveNext())
                            {
                                //access to pair using iterator.Current
                                string       key = iterator.Current.Key;
                                MessagingBus bus = controllersIter.Current.Value.messagingBuses[key];

                                if (!pendingMessagesCount.ContainsKey(key))
                                {
                                    pendingMessagesCount[key] = 0;
                                }

                                if (!messagesReplaced.ContainsKey(key))
                                {
                                    messagesReplaced[key] = 0;
                                }

                                pendingMessagesCount[key] += bus.pendingMessagesCount;
                                messagesReplaced[key]     += bus.unreliableMessagesReplaced;
                            }
                        }
                    }
                }

                busesLog += $"{MessagingBusId.UI} bus: {pendingMessagesCount[MessagingBusId.UI]} replaced: {messagesReplaced[MessagingBusId.UI]}\n";
                busesLog += $"{MessagingBusId.INIT} bus: {pendingMessagesCount[MessagingBusId.INIT]} replaced: {messagesReplaced[MessagingBusId.INIT]}\n";
                busesLog += $"{MessagingBusId.SYSTEM} bus: {pendingMessagesCount[MessagingBusId.SYSTEM]} replaced: {messagesReplaced[MessagingBusId.SYSTEM]}\n";

                statsPanel.SetCellText(1, (int)Rows.MESSAGE_BUSES, busesLog);

                yield return(WaitForSecondsCache.Get(0.2f));
            }
        }