Esempio n. 1
0
        /// <summary>
        /// Allows components to send messages
        /// </summary>
        /// <param name="sender">the component doing the sending</param>
        /// <param name="type">the type of message</param>
        /// <param name="args">message parameters</param>
        public void SendMessage(object sender, ComponentMessageType type, List <ComponentReplyMessage> replies,
                                params object[] args)
        {
            //LogComponentMessage(sender, type, args);

            foreach (Component component in GetComponents())
            {
                //Check to see if the component is still a part of this entity --- collection may change in process.
                if (_components.ContainsValue(component))
                {
                    if (replies != null)
                    {
                        ComponentReplyMessage reply = component.RecieveMessage(sender, type, args);
                        if (reply.MessageType != ComponentMessageType.Empty)
                        {
                            replies.Add(reply);
                        }
                    }
                    else
                    {
                        component.RecieveMessage(sender, type, args);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Recieve a message from another component within the owner entity
        /// </summary>
        /// <param name="sender">the component that sent the message</param>
        /// <param name="type">the message type in CGO.MessageType</param>
        /// <param name="list">parameters list</param>
        public virtual ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
                                                            params object[] list)
        {
            ComponentReplyMessage reply = ComponentReplyMessage.Empty;

            if (sender == this) //Don't listen to our own messages!
            {
                return(reply);
            }

            // Leaving this gap here in case anybody wants to add something later.

            return(reply);
        }
Esempio n. 3
0
        /// <summary>
        /// Recieve a message from another component within the owner entity
        /// </summary>
        /// <param name="sender">the component that sent the message</param>
        /// <param name="type">the message type in CGO.MessageType</param>
        /// <param name="list">parameters list</param>
        public virtual ComponentReplyMessage RecieveMessage(object sender, ComponentMessageType type,
                                                            params object[] list)
        {
            ComponentReplyMessage reply = ComponentReplyMessage.Empty;

            if (sender == this) //Don't listen to our own messages!
            {
                return(reply);
            }

            //Client-only hack
            if (Owner.EntityManager.EngineType == EngineType.Client)
            {
                switch (type)
                {
                case ComponentMessageType.Initialize:
                    Owner.SendComponentInstantiationMessage(this);
                    break;
                }
            }

            return(reply);
        }