Beispiel #1
0
        /// <summary>
        /// Data transfer helper for packing <see cref="Vector3"/> data.
        /// </summary>
        /// <param name="packet">The packet buffer in which to compose the transfer message.</param>
        /// <param name="component">The component type.</param>
        /// <param name="items">Data to transfer.</param>
        /// <param name="byteLimit">An advisory byte limit used to restrict how much data should be sent (in bytes).</param>
        /// <param name="progress">Track the transfer progress between calls.</param>
        protected bool Transfer(PacketBuffer packet, MeshMessageType component, Vector3[] items, int byteLimit, ref TransferProgress progress)
        {
            // Compose component message.
            int elementSize          = 12; // 3 * 4 byte floats
            MeshComponentMessage msg = new MeshComponentMessage();

            msg.MeshID   = ID;
            msg.Offset   = (uint)progress.Progress;
            msg.Reserved = 0;
            msg.Count    = (ushort)Math.Min(EstimateTransferCount(elementSize, byteLimit, MeshComponentMessage.Size), (uint)items.Length - msg.Offset);

            packet.Reset((ushort)RoutingID.Mesh, (ushort)component);
            msg.Write(packet);
            uint ii = msg.Offset;

            for (int i = 0; i < msg.Count; ++i, ++ii)
            {
                packet.WriteBytes(BitConverter.GetBytes(items[ii].X), true);
                packet.WriteBytes(BitConverter.GetBytes(items[ii].Y), true);
                packet.WriteBytes(BitConverter.GetBytes(items[ii].Z), true);
            }

            progress.Progress += msg.Count;
            return(progress.Progress == items.Length);
        }
Beispiel #2
0
        /// <summary>
        /// Write a <see cref="MeshComponentMessage"/> to serialise <c>Vector3</c> data.
        /// </summary>
        /// <param name="meshID">Mesh resource ID we are serialising for.</param>
        /// <param name="type">The mesh component type; e.g., <see cref="MeshMessageType.Vertex"/>.</param>
        /// <param name="data">The <c>Vector3</c> data array.</param>
        /// <param name="packet">Packet buffer to compose messages in</param>
        /// <param name="writer">Writer to export completed message packets to.</param>
        /// <param name="blockSize">The maximum number of elements per message.</param>
        /// <remarks>
        /// Writes multiple messages to <paramref name="writer"/> as required to ensure all
        /// <paramref name="data"/> are written.
        /// </remarks>
        protected void WriteMeshComponent(uint meshID, MeshMessageType type, Vector3[] data,
                                          PacketBuffer packet, BinaryWriter writer, uint blockSize)
        {
            if (data == null || data.Length == 0)
            {
                return;
            }

            MeshComponentMessage cmsg = new MeshComponentMessage();

            cmsg.MeshID   = meshID;
            cmsg.Offset   = 0;
            cmsg.Reserved = 0;
            cmsg.Count    = 0;

            while (cmsg.Offset < data.Length)
            {
                Vector3 v;
                cmsg.Count = (ushort)Math.Min(blockSize, (uint)data.Length - cmsg.Offset);
                packet.Reset((ushort)RoutingID, (ushort)type);
                cmsg.Write(packet);
                for (int i = 0; i < cmsg.Count; ++i)
                {
                    v = data[i + cmsg.Offset];
                    packet.WriteBytes(BitConverter.GetBytes(v.x), true);
                    packet.WriteBytes(BitConverter.GetBytes(v.y), true);
                    packet.WriteBytes(BitConverter.GetBytes(v.z), true);
                }

                if (cmsg.Count > 0)
                {
                    packet.FinalisePacket();
                    packet.ExportTo(writer);
                }

                cmsg.Offset += cmsg.Count;
                cmsg.Count   = 0;
            }
        }