public void StopBus(MessagingBusType busType)
 {
     if (messagingBuses.ContainsKey(busType))
     {
         messagingBuses[busType].Stop();
     }
 }
        private MessagingBus AddMessageBus(MessagingBusType type)
        {
            var newMessagingBus = new MessagingBus(type, messageHandler, this);

            newMessagingBus.debugTag = debugTag;

            messagingBuses.Add(type, newMessagingBus);
            return(newMessagingBus);
        }
        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));
            }
        }
 public void ForceEnqueueToGlobal(MessagingBusType busId, QueuedSceneMessage queuedMessage)
 {
     messagingControllers[GLOBAL_MESSAGING_CONTROLLER].ForceEnqueue(busId, queuedMessage);
 }
        public void Enqueue(bool isUiBus, QueuedSceneMessage_Scene queuedMessage, out MessagingBusType busType)
        {
            busType = MessagingBusType.NONE;

            QueueMode queueMode = QueueMode.Reliable;

            // If current scene is the Global Scene, the bus id should be UI
            if (isUiBus)
            {
                busType = MessagingBusType.UI;
            }
            else if (currentQueueState == QueueState.Init)
            {
                busType = MessagingBusType.INIT;
            }
            else
            {
                busType = MessagingBusType.SYSTEM;
            }

            // Check if the message type is an EntityComponentCreateOrUpdate
            if (queuedMessage.payload is Protocol.EntityComponentCreateOrUpdate)
            {
                // We need to extract the entityId and the classId from the tag.
                // The tag format is "entityId_classId", i.e: "E1_2".
                GetEntityIdAndClassIdFromTag(queuedMessage.tag, out int classId);

                // If it is a transform update, the queue mode is Lossy
                if (classId == (int)CLASS_ID_COMPONENT.TRANSFORM)
                {
                    queueMode = QueueMode.Lossy;
                }
            }
            else if (queuedMessage.payload is Protocol.QueryPayload)
            {
                busType   = MessagingBusType.UI;
                queueMode = QueueMode.Lossy;
            }
            else if (queuedMessage.payload is Protocol.SceneReady)
            {
                // When a INIT DONE message is enqueued, the next messages should be
                // enqueued in SYSTEM message bus, but we don't process them until
                // scene started has been processed
                currentQueueState = QueueState.Systems;
            }

            switch (busType)
            {
            case MessagingBusType.INIT:
                initBus.Enqueue(queuedMessage, queueMode);
                break;

            case MessagingBusType.SYSTEM:
                systemBus.Enqueue(queuedMessage, queueMode);
                break;

            case MessagingBusType.UI:
                uiBus.Enqueue(queuedMessage, queueMode);
                break;
            }
        }
 public void ForceEnqueue(MessagingBusType busType, QueuedSceneMessage queuedMessage)
 {
     messagingBuses[busType].Enqueue(queuedMessage);
 }