Exemplo n.º 1
0
        /// <summary>
        /// Read additional index data for the cloud.
        /// </summary>
        /// <param name="reader">Stream to read from</param>
        /// <returns>True on success.</returns>
        /// <remarks>
        /// Reads additional index data if required.
        ///
        /// Fails if the <see cref="DataMessage.ObjectID"/> does not match <see cref="Shape.ID"/>.
        /// </remarks>
        public override bool ReadData(BinaryReader reader)
        {
            DataMessage msg = new DataMessage();

            if (!msg.Read(reader))
            {
                return(false);
            }

            if (msg.ObjectID != ID)
            {
                return(false);
            }

            uint offset    = reader.ReadUInt32();
            uint itemCount = reader.ReadUInt32();

            if (offset + itemCount > 0)
            {
                if (_indices == null || offset + itemCount > _indices.Length)
                {
                    return(false);
                }
            }

            for (uint i = offset; i < offset + itemCount; ++i)
            {
                _indices[i] = reader.ReadUInt32();
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read <see cref="DataMessage"/> and payload generated by <see cref="WriteData(PacketBuffer, ref uint)"/>.
        /// </summary>
        /// <param name="reader">Stream to read from</param>
        /// <returns>True on success.</returns>
        public override bool ReadData(BinaryReader reader)
        {
            DataMessage msg = new DataMessage();

            if (!msg.Read(reader))
            {
                return(false);
            }

            if (ID != msg.ObjectID)
            {
                return(false);
            }

            ArrayComponentAdaptor <Vector3> normalsAdaptor = new ArrayComponentAdaptor <Vector3>(_normals);
            ColoursAdaptor coloursAdaptor = new ColoursAdaptor(_colours);
            int            readComponent  = ReadDataComponent(reader,
                                                              new ArrayComponentAdaptor <Vector3>(_vertices),
                                                              new ArrayComponentAdaptor <int>(_indices),
                                                              normalsAdaptor, coloursAdaptor);

            if (readComponent == -1)
            {
                return(false);
            }

            // Normals and colours may have been (re)allocated. Store the results.
            switch (readComponent & ~(int)(SendDataType.End | SendDataType.ExpectEnd))
            {
            case (int)SendDataType.Normals:
            case (int)SendDataType.UniformNormal:
                // Normals array may have been (re)allocated.
                _normals = normalsAdaptor.Array;
                break;

            case (int)SendDataType.Colours:
                // Colours array may have been (re)allocated.
                _colours = coloursAdaptor.Array;
                break;
            }

            // Check for finalisation.
            // Complete if ((readComponent & (int)SendDataType.End) != 0)

            return(true);
        }
Exemplo n.º 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();
        }