Пример #1
0
        protected override void PackToCore(Packer packer, Vector2 vec)
        {
            MemoryStream ms = new MemoryStream();

            Float32Bits.WriteFloat(ms, vec.X);
            Float32Bits.WriteFloat(ms, vec.Y);

            packer.PackExtendedTypeValue(20, ms.ToArray());
        }
Пример #2
0
        private object UnpackExt(BinaryReader reader, int length)
        {
            var extType = reader.ReadByte();

            if (!ExtTypes.Contains(extType))
            {
                throw new InvalidOperationException($"Extension type {extType} not handled.");
            }

            switch (extType)
            {
            case 10:                     // funcref
            case 11:                     // localfuncref
                var funcRefData = reader.ReadBytes(length);

                if (extType == 11)
                {
                    return(CreateRemoteFunctionReference(funcRefData));
                }

                return(CreateFunctionReference(funcRefData, NetSource));

            case 20:                     // vector2
                return(new Vector2(
                           Float32Bits.ReadFloat(reader),
                           Float32Bits.ReadFloat(reader)
                           ));

            case 21:                     // vector3
                return(new Vector3(
                           Float32Bits.ReadFloat(reader),
                           Float32Bits.ReadFloat(reader),
                           Float32Bits.ReadFloat(reader)
                           ));

            case 22:                     // vector4
                return(new Vector4(
                           Float32Bits.ReadFloat(reader),
                           Float32Bits.ReadFloat(reader),
                           Float32Bits.ReadFloat(reader),
                           Float32Bits.ReadFloat(reader)
                           ));

            case 23:                     // quaternion
                return(new Quaternion(
                           Float32Bits.ReadFloat(reader),
                           Float32Bits.ReadFloat(reader),
                           Float32Bits.ReadFloat(reader),
                           Float32Bits.ReadFloat(reader)
                           ));

            default:                     // shouldn't ever happen due to the check above
                return(new object());
            }
        }
Пример #3
0
        public static void WriteFloat(MemoryStream ms, float value)
        {
            Float32Bits bits = new Float32Bits(value);

            if (BitConverter.IsLittleEndian)
            {
                ms.WriteByte(bits.Byte3);
                ms.WriteByte(bits.Byte2);
                ms.WriteByte(bits.Byte1);
                ms.WriteByte(bits.Byte0);
            }
            else
            {
                ms.WriteByte(bits.Byte0);
                ms.WriteByte(bits.Byte1);
                ms.WriteByte(bits.Byte2);
                ms.WriteByte(bits.Byte3);
            }
        }
Пример #4
0
        public static float ReadFloat(BinaryReader reader)
        {
            Float32Bits bits = new Float32Bits(reader.ReadBytes(4), 0);

            return(bits.Value);
        }