示例#1
0
        private void RemoveChild(BaseEntity childEntity)
        {
            if (childEntity != null)
            {
                MsgParentRemoved msgParentRem = ObjectPool.Aquire <MsgParentRemoved>();
                msgParentRem.UniqueTarget = childEntity.uniqueID;
                this.game.SendMessage(msgParentRem);

                children.Remove(childEntity.UniqueID);
            }
        }
示例#2
0
        private void RemoveAllChildren()
        {
            foreach (Int64 child in this.children.Keys)
            {
                MsgParentRemoved msgParentRem = ObjectPool.Aquire <MsgParentRemoved>();
                msgParentRem.UniqueTarget = child;
                this.game.SendMessage(msgParentRem);
            }

            this.children.Clear();
        }
示例#3
0
        /// <summary>
        /// Send a message directly to an Entity through this method.
        /// This function MUST be called only from QSGame, otherwise it will never mark the message properly for release
        /// and it will leak memory.
        /// </summary>
        /// <param name="message">Message to send</param>
        /// <returns>Returns true if message was handled</returns>
        public virtual bool ExecuteMessage(IMessage message)
        {
            switch (message.Type)
            {
            case MessageType.GetName:
            {
                MsgGetName msgGetName = message as MsgGetName;
                message.TypeCheck(msgGetName);

                msgGetName.Name = this.name;
            }
            break;

            case MessageType.GetParentID:
            {
                MsgGetParentID msgGetID = message as MsgGetParentID;
                message.TypeCheck(msgGetID);

                if (this.parentEntity != null)
                {
                    msgGetID.ParentEntityID = this.parentEntity.UniqueID;
                }
            }
            break;

            case MessageType.SetPosition:
            {
                MsgSetPosition setPositionMsg = message as MsgSetPosition;
                message.TypeCheck(setPositionMsg);

                this.Position = setPositionMsg.Position;
            }
            break;

            case MessageType.ModifyPosition:
            {
                MsgModifyPosition modPosMsg = message as MsgModifyPosition;
                message.TypeCheck(modPosMsg);

                this.Position += modPosMsg.Position;
            }
            break;

            case MessageType.GetPosition:
            {
                MsgGetPosition getPosMsg = message as MsgGetPosition;
                message.TypeCheck(getPosMsg);

                getPosMsg.Position = this.position;
            }
            break;

            case MessageType.SetRotation:
            {
                MsgSetRotation setRotMsg = message as MsgSetRotation;
                message.TypeCheck(setRotMsg);

                this.Rotation = setRotMsg.Rotation;
            }
            break;

            case MessageType.ModifyRotation:
            {
                MsgModifyRotation modRotMsg = message as MsgModifyRotation;
                message.TypeCheck(modRotMsg);

                this.Rotation *= modRotMsg.Rotation;
            }
            break;

            case MessageType.GetRotation:
            {
                MsgGetRotation getRotMsg = message as MsgGetRotation;
                message.TypeCheck(getRotMsg);

                getRotMsg.Rotation = this.rotation;
            }
            break;

            case MessageType.GetVectorForward:
            {
                MsgGetVectorForward getVectorMsg = message as MsgGetVectorForward;
                message.TypeCheck(getVectorMsg);

                getVectorMsg.Forward = this.rotation.Forward;
            }
            break;

            case MessageType.GetVectorUp:
            {
                MsgGetVectorUp getVectorMsg = message as MsgGetVectorUp;
                message.TypeCheck(getVectorMsg);

                getVectorMsg.Up = this.rotation.Up;
            }
            break;

            case MessageType.GetVectorRight:
            {
                MsgGetVectorRight getVectorMsg = message as MsgGetVectorRight;
                message.TypeCheck(getVectorMsg);

                getVectorMsg.Right = this.rotation.Right;
            }
            break;

            case MessageType.LookAtPosition:
            {
                MsgLookAtPosition setPositionMsg = message as MsgLookAtPosition;
                message.TypeCheck(setPositionMsg);

                this.LookAt(setPositionMsg.Position);
            }
            break;

            case MessageType.Pitch:
            {
                MsgModifyPitch camPitchMsg = message as MsgModifyPitch;
                message.TypeCheck(camPitchMsg);

                Pitch(camPitchMsg.PitchAmount);
            }
            break;

            case MessageType.Yaw:
            {
                MsgModifyYaw camYawMsg = message as MsgModifyYaw;
                message.TypeCheck(camYawMsg);

                Yaw(camYawMsg.YawAmount);
            }
            break;

            case MessageType.YawWorldUp:
            {
                MsgModifyYawWorldUp camYawMsg = message as MsgModifyYawWorldUp;
                message.TypeCheck(camYawMsg);

                YawAroundWorldUp(camYawMsg.YawAmount);
            }
            break;

            case MessageType.SetParent:
            {
                MsgSetParent msgSetParent = message as MsgSetParent;
                message.TypeCheck(msgSetParent);

                SetParent(msgSetParent.ParentEntity);
            }
            break;

            case MessageType.RemoveChild:
            {
                MsgRemoveChild msgRemChild = message as MsgRemoveChild;
                message.TypeCheck(msgRemChild);

                RemoveChild(msgRemChild.Child);
            }
            break;

            case MessageType.ParentRemoved:
            {
                MsgParentRemoved msgParentRem = message as MsgParentRemoved;
                message.TypeCheck(msgParentRem);

                if (parentEntity == msgParentRem.Parent)
                {
                    SetParent(null);
                }
            }
            break;

            case MessageType.ParentAdded:
            {
                MsgParentAdded msgParentAdded = message as MsgParentAdded;
                message.TypeCheck(msgParentAdded);

                SetParent(msgParentAdded.Parent);
            }
            break;

            case MessageType.ChildRemoved:
            {
                MsgChildRemoved msgChildRem = message as MsgChildRemoved;
                message.TypeCheck(msgChildRem);

                if (msgChildRem.Child != null)
                {
                    this.children.Remove(msgChildRem.Data.UniqueID);
                }
            }
            break;

            case MessageType.ChildAdded:
            {
                MsgChildAdded msgChildAdd = message as MsgChildAdded;
                message.TypeCheck(msgChildAdd);

                if (msgChildAdd.Child != null && msgChildAdd.Child != this)
                {
                    this.children.Add(msgChildAdd.Data.UniqueID, msgChildAdd.Child);
                }
            }
            break;

            default:
                return(SendMessageThroughComponents(message));
            }

            // For messages handled directly by the Entity but aren't Request Protocol,
            // we still pass them to the Entity's components in case those components care.
            if (message.Protocol != MessageProtocol.Request)
            {
                return(SendMessageThroughComponents(message));
            }

            return(true);
        }