コード例 #1
0
ファイル: Shape.cs プロジェクト: csiro-robotics/3rdEyeScene
        /// <summary>
        /// Read an <see cref="UpdateMessage"/> for this shape.
        /// </summary>
        /// <param name="packet">The buffer from which the reader reads.</param>
        /// <param name="reader">The stream to read message data from.</param>
        /// <returns><c>true</c> if the message is successfully read.</returns>
        /// <remarks>
        /// Respects the <see cref="UpdateFlag"/> values, only modifying requested data.
        /// </remarks>
        public virtual bool ReadUpdate(PacketBuffer packet, BinaryReader reader)
        {
            UpdateMessage up = new UpdateMessage();

            if (up.Read(reader))
            {
                if ((up.Flags & (ushort)UpdateFlag.UpdateMode) == 0)
                {
                    // Full update.
                    _data.Attributes = up.Attributes;
                }
                else
                {
                    // Partial update.
                    if ((up.Flags & (short)UpdateFlag.Position) != 0)
                    {
                        _data.Attributes.X = up.Attributes.X;
                        _data.Attributes.Y = up.Attributes.Y;
                        _data.Attributes.Z = up.Attributes.Z;
                    }
                    if ((up.Flags & (short)UpdateFlag.Rotation) != 0)
                    {
                        _data.Attributes.RotationX = up.Attributes.RotationX;
                        _data.Attributes.RotationY = up.Attributes.RotationY;
                        _data.Attributes.RotationZ = up.Attributes.RotationZ;
                        _data.Attributes.RotationW = up.Attributes.RotationW;
                    }
                    if ((up.Flags & (short)UpdateFlag.Scale) != 0)
                    {
                        _data.Attributes.ScaleX = up.Attributes.ScaleX;
                        _data.Attributes.ScaleY = up.Attributes.ScaleY;
                        _data.Attributes.ScaleZ = up.Attributes.ScaleZ;
                    }
                    if ((up.Flags & (short)UpdateFlag.Colour) != 0)
                    {
                        _data.Attributes.Colour = up.Attributes.Colour;
                    }
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Message handler.
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        public override Error ReadMessage(PacketBuffer packet, BinaryReader reader)
        {
            switch ((ObjectMessageID)packet.Header.MessageID)
            {
            default:
            case ObjectMessageID.Null:
                return(new Error(ErrorCode.InvalidMessageID, packet.Header.MessageID));

            case ObjectMessageID.Create:
                // Read the create message details.
                CreateMessage create = new CreateMessage();
                if (!create.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, packet.Header.MessageID));
                }
                return(HandleMessage(create, packet, reader));

            case ObjectMessageID.Update:
                // Read the create message details.
                UpdateMessage update = new UpdateMessage();
                if (!update.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, packet.Header.MessageID));
                }
                return(HandleMessage(update, packet, reader));

            case ObjectMessageID.Destroy:
                // Read the create message details.
                DestroyMessage destroy = new DestroyMessage();
                if (!destroy.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, packet.Header.MessageID));
                }
                return(HandleMessage(destroy));
            }
        }
コード例 #3
0
        /// <summary>
        /// Message routing function.
        /// </summary>
        /// <param name="messageID">The ID of the message.</param>
        /// <param name="packet">Packet buffer used to decode the message.</param>
        /// <param name="reader">The reader from which additional message data may be read.</param>
        /// <returns>An error code on failure.</returns>
        /// <remarks>
        /// The default implementation handles the following messages:
        /// Routes the following messages:
        /// <list type="bullet">
        /// <item><see cref="ObjectMessageID.Create"/></item>
        /// <item><see cref="ObjectMessageID.Update"/></item>
        /// <item><see cref="ObjectMessageID.Destroy"/></item>
        /// <item><see cref="ObjectMessageID.Data"/></item>
        /// </list>
        /// </remarks>
        protected virtual Error HandleMessage(ushort messageID, PacketBuffer packet, BinaryReader reader)
        {
            switch ((ObjectMessageID)messageID)
            {
            default:
            case ObjectMessageID.Null:
                return(new Error(ErrorCode.InvalidMessageID, messageID));

            case ObjectMessageID.Create:
                // Read the create message details.
                CreateMessage create = new CreateMessage();
                if (!create.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, messageID));
                }
                if (!FilterMessage(messageID, create.ObjectID, create.Category))
                {
                    return(new Error());
                }
                return(HandleMessage(create, packet, reader));

            case ObjectMessageID.Update:
                // Read the create message details.
                UpdateMessage update = new UpdateMessage();
                if (!update.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, messageID));
                }
                if (!FilterMessage(messageID, update.ObjectID, 0))
                {
                    return(new Error());
                }
                return(HandleMessage(update, packet, reader));

            case ObjectMessageID.Destroy:
                // Read the create message details.
                DestroyMessage destroy = new DestroyMessage();
                if (!destroy.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, messageID));
                }
                if (!FilterMessage(messageID, destroy.ObjectID, 0))
                {
                    return(new Error());
                }
                return(HandleMessage(destroy, packet, reader));

            case ObjectMessageID.Data:
                // Read the create message details.
                DataMessage data = new DataMessage();
                if (!data.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, messageID));
                }
                if (!FilterMessage(messageID, data.ObjectID, 0))
                {
                    return(new Error());
                }
                return(HandleMessage(data, packet, reader));
            }

            //return new Error();
        }