Beispiel #1
0
        private string DecodeAndEnqueue(string payload)
        {
            OnMessageDecodeStart?.Invoke("Misc");

            string sceneId;
            string message;
            string messageTag;
            PB_SendSceneMessage sendSceneMessage;

            if (!MessageDecoder.DecodePayloadChunk(payload, out sceneId, out message, out messageTag, out sendSceneMessage))
            {
                return(null);
            }

            MessagingBus.QueuedSceneMessage_Scene queuedMessage;

            if (sceneMessagesPool.Count > 0)
            {
                queuedMessage = sceneMessagesPool.Dequeue();
            }
            else
            {
                queuedMessage = new MessagingBus.QueuedSceneMessage_Scene();
            }

            MessageDecoder.DecodeSceneMessage(sceneId, message, messageTag, sendSceneMessage, ref queuedMessage);

            EnqueueSceneMessage(queuedMessage);

            OnMessageDecodeEnds?.Invoke("Misc");

            return("");
        }
Beispiel #2
0
        public void EnqueueSceneMessage(MessagingBus.QueuedSceneMessage_Scene message)
        {
            TryGetScene(message.sceneId, out ParcelScene scene);

            Environment.i.messagingControllersManager.AddControllerIfNotExists(this, message.sceneId);

            Environment.i.messagingControllersManager.Enqueue(scene, message);
        }
Beispiel #3
0
        public void Enqueue(ParcelScene scene, MessagingBus.QueuedSceneMessage_Scene queuedMessage, out string busId)
        {
            busId = "";

            QueueMode queueMode = QueueMode.Reliable;

            // If current scene is the Global Scene, the bus id should be UI
            if (scene && scene.sceneData.id == SceneController.i.globalSceneId)
            {
                busId = MessagingBusId.UI;
            }
            else if (currentQueueState == MessagingController.QueueState.Init)
            {
                busId = MessagingBusId.INIT;
            }
            else
            {
                busId = MessagingBusId.SYSTEM;
            }

            // Check if the message type is an UpdateEntityComponent
            if (queuedMessage.method == MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE)
            {
                int classId = 0;

                // 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 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.method == MessagingTypes.QUERY)
            {
                busId     = MessagingBusId.UI;
                queueMode = QueueMode.Lossy;
            }
            else if (queuedMessage.method == MessagingTypes.INIT_DONE)
            {
                // 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 = MessagingController.QueueState.Systems;
            }

            messagingBuses[busId].Enqueue(queuedMessage, queueMode);
        }
Beispiel #4
0
        private string EnqueueMessage(MessagingBus.QueuedSceneMessage_Scene queuedMessage)
        {
            ParcelScene scene;

            TryGetScene(queuedMessage.sceneId, out scene);

            // If it doesn't exist, create messaging controller for this scene id
            if (!MessagingControllersManager.i.ContainsController(queuedMessage.sceneId))
            {
                MessagingControllersManager.i.AddController(this, queuedMessage.sceneId);
            }

            string busId = MessagingControllersManager.i.Enqueue(scene, queuedMessage);

            return(busId);
        }
Beispiel #5
0
        public static MessagingBus.QueuedSceneMessage_Scene DecodeSceneMessage(string sceneId, string method, string tag, PB_SendSceneMessage sendSceneMessage, ref MessagingBus.QueuedSceneMessage_Scene queuedMessage)
        {
            queuedMessage.type    = MessagingBus.QueuedSceneMessage.Type.SCENE_MESSAGE;
            queuedMessage.sceneId = sceneId;
            queuedMessage.method  = method;
            queuedMessage.tag     = tag;

            queuedMessage.payload = sendSceneMessage;

            return(queuedMessage);
        }
Beispiel #6
0
        public bool ProcessMessage(MessagingBus.QueuedSceneMessage_Scene msgObject, out CleanableYieldInstruction yieldInstruction)
        {
            string sceneId = msgObject.sceneId;
            string method  = msgObject.method;

            yieldInstruction = null;

            ParcelScene scene;
            bool        res = false;

            if (loadedScenes.TryGetValue(sceneId, out scene))
            {
#if UNITY_EDITOR
                if (debugScenes && scene is GlobalScene && ignoreGlobalScenes)
                {
                    return(false);
                }
#endif
                if (!scene.gameObject.activeInHierarchy)
                {
                    return(true);
                }

#if UNITY_EDITOR
                OnMessageProcessInfoStart?.Invoke(sceneId, method);
#endif
                OnMessageProcessStart?.Invoke(method);

                switch (method)
                {
                case MessagingTypes.ENTITY_CREATE:
                {
                    if (msgObject.payload is Protocol.CreateEntity payload)
                    {
                        scene.CreateEntity(payload.entityId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_REPARENT:
                {
                    if (msgObject.payload is Protocol.SetEntityParent payload)
                    {
                        scene.SetEntityParent(payload.entityId, payload.parentId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE:
                {
                    if (msgObject.payload is Protocol.EntityComponentCreateOrUpdate payload)
                    {
                        scene.EntityComponentCreateOrUpdate(payload.entityId, (CLASS_ID_COMPONENT)payload.classId, payload.json, out yieldInstruction);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_DESTROY:
                {
                    if (msgObject.payload is Protocol.EntityComponentDestroy payload)
                    {
                        scene.EntityComponentRemove(payload.entityId, payload.name);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_ATTACH:
                {
                    if (msgObject.payload is Protocol.SharedComponentAttach payload)
                    {
                        scene.SharedComponentAttach(payload.entityId, payload.id);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_CREATE:
                {
                    if (msgObject.payload is Protocol.SharedComponentCreate payload)
                    {
                        scene.SharedComponentCreate(payload.id, payload.classId);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_DISPOSE:
                {
                    if (msgObject.payload is Protocol.SharedComponentDispose payload)
                    {
                        scene.SharedComponentDispose(payload.id);
                    }
                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_UPDATE:
                {
                    if (msgObject.payload is Protocol.SharedComponentUpdate payload)
                    {
                        scene.SharedComponentUpdate(payload.componentId, payload.json, out yieldInstruction);
                    }
                    break;
                }

                case MessagingTypes.ENTITY_DESTROY:
                {
                    if (msgObject.payload is Protocol.RemoveEntity payload)
                    {
                        scene.RemoveEntity(payload.entityId);
                    }
                    break;
                }

                case MessagingTypes.INIT_DONE:
                {
                    scene.SetInitMessagesDone();
                    break;
                }

                case MessagingTypes.QUERY:
                {
                    if (msgObject.payload is QueryMessage queryMessage)
                    {
                        ParseQuery(queryMessage.payload, scene.sceneData.id);
                    }
                    break;
                }

                case MessagingTypes.OPEN_EXTERNAL_URL:
                {
                    if (msgObject.payload is Protocol.OpenExternalUrl payload)
                    {
                        OnOpenExternalUrlRequest?.Invoke(scene, payload.url);
                    }
                    break;
                }

                case MessagingTypes.OPEN_NFT_DIALOG:
                {
                    if (msgObject.payload is Protocol.OpenNftDialog payload)
                    {
                        OnOpenNFTDialogRequest?.Invoke(payload.contactAddress, payload.tokenId, payload.comment);
                    }
                    break;
                }

                default:
                    Debug.LogError($"Unknown method {method}");
                    return(true);
                }

                OnMessageProcessEnds?.Invoke(method);

#if UNITY_EDITOR
                OnMessageProcessInfoEnds?.Invoke(sceneId, method);
#endif

                res = true;
            }

            else
            {
                res = false;
            }

            sceneMessagesPool.Enqueue(msgObject);

            return(res);
        }
Beispiel #7
0
        public static void DecodeSceneMessage(string sceneId, string method, string tag, PB_SendSceneMessage sendSceneMessage, ref MessagingBus.QueuedSceneMessage_Scene queuedMessage)
        {
            queuedMessage.type    = MessagingBus.QueuedSceneMessage.Type.SCENE_MESSAGE;
            queuedMessage.sceneId = sceneId;
            queuedMessage.method  = method;
            queuedMessage.tag     = tag;

            switch (method)
            {
            case MessagingTypes.INIT_DONE:
                queuedMessage.payload = new Protocol.SceneReady();
                break;

            case MessagingTypes.QUERY:
                QueryMessage query = new QueryMessage();
                DecodeQueryMessage(sendSceneMessage.Query.QueryId, sendSceneMessage.Query.Payload, ref query);
                queuedMessage.payload = query;
                break;

            case MessagingTypes.ENTITY_CREATE:
                queuedMessage.payload = Protocol.CreateEntity.FromPB(sendSceneMessage.CreateEntity);
                break;

            case MessagingTypes.ENTITY_DESTROY:
                queuedMessage.payload = Protocol.RemoveEntity.FromPB(sendSceneMessage.RemoveEntity);
                break;

            case MessagingTypes.ENTITY_REPARENT:
                queuedMessage.payload = Protocol.SetEntityParent.FromPB(sendSceneMessage.SetEntityParent);
                break;

            case MessagingTypes.SHARED_COMPONENT_CREATE:
                queuedMessage.payload = Protocol.SharedComponentCreate.FromPB(sendSceneMessage.ComponentCreated);
                break;

            case MessagingTypes.SHARED_COMPONENT_ATTACH:
                queuedMessage.payload = Protocol.SharedComponentAttach.FromPB(sendSceneMessage.AttachEntityComponent);
                break;

            case MessagingTypes.SHARED_COMPONENT_UPDATE:
                queuedMessage.payload = Protocol.SharedComponentUpdate.FromPB(sendSceneMessage.ComponentUpdated);
                break;

            case MessagingTypes.SHARED_COMPONENT_DISPOSE:
                queuedMessage.payload = Protocol.SharedComponentDispose.FromPB(sendSceneMessage.ComponentDisposed);
                break;

            case MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE:
                queuedMessage.payload = Protocol.EntityComponentCreateOrUpdate.FromPB(sendSceneMessage.UpdateEntityComponent);
                break;

            case MessagingTypes.ENTITY_COMPONENT_DESTROY:
                queuedMessage.payload = Protocol.EntityComponentDestroy.FromPB(sendSceneMessage.ComponentRemoved);
                break;

            case MessagingTypes.OPEN_NFT_DIALOG:
                queuedMessage.payload = Protocol.OpenNftDialog.FromPB(sendSceneMessage.OpenNFTDialog);
                break;

            case MessagingTypes.OPEN_EXTERNAL_URL:
                queuedMessage.payload = Protocol.OpenExternalUrl.FromPB(sendSceneMessage.OpenExternalUrl);
                break;
            }
        }
Beispiel #8
0
        public void Enqueue(ParcelScene scene, MessagingBus.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 (scene && scene is GlobalScene)
            {
                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 Enqueue(ParcelScene scene, MessagingBus.QueuedSceneMessage_Scene queuedMessage)
 {
     messagingControllers[queuedMessage.sceneId].Enqueue(scene, queuedMessage, out MessagingBusType busId);
 }
Beispiel #10
0
        public bool ProcessMessage(MessagingBus.QueuedSceneMessage_Scene msgObject, out CleanableYieldInstruction yieldInstruction)
        {
            string sceneId = msgObject.sceneId;
            string tag     = msgObject.tag;
            string method  = msgObject.method;

            DCL.Interface.PB_SendSceneMessage payload = msgObject.payload;

            yieldInstruction = null;

            ParcelScene scene;
            bool        res = false;

            if (loadedScenes.TryGetValue(sceneId, out scene))
            {
#if UNITY_EDITOR
                if (debugScenes && scene is GlobalScene && ignoreGlobalScenes)
                {
                    return(false);
                }
#endif
                if (!scene.gameObject.activeInHierarchy)
                {
                    return(true);
                }

#if UNITY_EDITOR
                OnMessageProcessInfoStart?.Invoke(sceneId, method);
#endif
                OnMessageProcessStart?.Invoke(method);

                switch (method)
                {
                case MessagingTypes.ENTITY_CREATE:
                    scene.CreateEntity(tag);
                    break;

                case MessagingTypes.ENTITY_REPARENT:
                    scene.SetEntityParent(payload.SetEntityParent.EntityId, payload.SetEntityParent.ParentId);
                    break;

                //NOTE(Brian): EntityComponent messages
                case MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE:
                    scene.EntityComponentCreateOrUpdate(payload.UpdateEntityComponent.EntityId, payload.UpdateEntityComponent.Name, payload.UpdateEntityComponent.ClassId, payload.UpdateEntityComponent.Data, out yieldInstruction);
                    break;

                case MessagingTypes.ENTITY_COMPONENT_DESTROY:
                    scene.EntityComponentRemove(payload.ComponentRemoved.EntityId, payload.ComponentRemoved.Name);
                    break;

                //NOTE(Brian): SharedComponent messages
                case MessagingTypes.SHARED_COMPONENT_ATTACH:
                    scene.SharedComponentAttach(payload.AttachEntityComponent.EntityId, payload.AttachEntityComponent.Id, payload.AttachEntityComponent.Name);
                    break;

                case MessagingTypes.SHARED_COMPONENT_CREATE:
                    scene.SharedComponentCreate(payload.ComponentCreated.Id, payload.ComponentCreated.Name, payload.ComponentCreated.Classid);
                    break;

                case MessagingTypes.SHARED_COMPONENT_DISPOSE:
                    scene.SharedComponentDispose(payload.ComponentDisposed.Id);
                    break;

                case MessagingTypes.SHARED_COMPONENT_UPDATE:
                    scene.SharedComponentUpdate(payload.ComponentUpdated.Id, payload.ComponentUpdated.Json, out yieldInstruction);
                    break;

                case MessagingTypes.ENTITY_DESTROY:
                    scene.RemoveEntity(tag);
                    break;

                case MessagingTypes.INIT_DONE:
                    scene.SetInitMessagesDone();
                    break;

                case MessagingTypes.QUERY:
                    ParseQuery(payload.Query.QueryId, payload.Query.Payload, scene.sceneData.id);
                    break;

                case MessagingTypes.OPEN_EXTERNAL_URL:
                    OnOpenExternalUrlRequest?.Invoke(scene, payload.OpenExternalUrl.Url);
                    break;

                case MessagingTypes.OPEN_NFT_DIALOG:
                    OnOpenNFTDialogRequest?.Invoke(payload.OpenNFTDialog.AssetContractAddress, payload.OpenNFTDialog.TokenId, payload.OpenNFTDialog.Comment);
                    break;

                default:
                    Debug.LogError($"Unknown method {method}");
                    return(true);
                }

                OnMessageProcessEnds?.Invoke(method);

#if UNITY_EDITOR
                OnMessageProcessInfoEnds?.Invoke(sceneId, method);
#endif

                res = true;
            }

            else
            {
                res = false;
            }

            sceneMessagesPool.Enqueue(msgObject);

            return(res);
        }
Beispiel #11
0
 public PendingMessage(string busId, MessagingBus.QueuedSceneMessage_Scene message, QueueMode queueMode)
 {
     this.busId     = busId;
     this.message   = message;
     this.queueMode = queueMode;
 }
Beispiel #12
0
 public string Enqueue(ParcelScene scene, MessagingBus.QueuedSceneMessage_Scene queuedMessage)
 {
     messagingControllers[queuedMessage.sceneId].Enqueue(scene, queuedMessage, out string busId);
     return(busId);
 }