示例#1
0
        public static float GetFloat(ReadOnlySpan <byte> bytes, FloatIntegerType integerType, double multiplier)
        {
            switch (integerType)
            {
            case FloatIntegerType.UInt:
            {
                var    raw = BinaryPrimitives.ReadUInt32LittleEndian(bytes);
                double d   = raw;
                d *= multiplier;
                return((float)d);
            }

            case FloatIntegerType.UShort:
            {
                var    raw = BinaryPrimitives.ReadUInt16LittleEndian(bytes);
                double d   = raw;
                d *= multiplier;
                return((float)d);
            }

            case FloatIntegerType.Byte:
            {
                var    raw = bytes[0];
                double d   = raw;
                d *= multiplier;
                return((float)d);
            }

            default:
                throw new NotImplementedException();
            }
        }
示例#2
0
        public static float Parse(MutagenFrame frame, FloatIntegerType integerType, double multiplier)
        {
            switch (integerType)
            {
            case FloatIntegerType.UInt:
            {
                var    raw = frame.ReadUInt32();
                double d   = raw;
                d *= multiplier;
                return((float)d);
            }

            case FloatIntegerType.UShort:
            {
                var    raw = frame.ReadUInt16();
                double d   = raw;
                d *= multiplier;
                return((float)d);
            }

            case FloatIntegerType.Byte:
            {
                var    raw = frame.ReadUInt8();
                double d   = raw;
                d *= multiplier;
                return((float)d);
            }

            default:
                throw new NotImplementedException();
            }
        }
示例#3
0
        public override async Task Load(XElement node, bool requireName = true)
        {
            await base.Load(node, requireName);

            var data = this.TryCreateFieldData();

            this.IntegerType = node.GetAttribute("integerType", FloatIntegerType.UInt);
        }
        public static Percent Parse(MutagenFrame frame, FloatIntegerType integerType)
        {
            switch (integerType)
            {
            case FloatIntegerType.UInt:
                return(Percent.FactoryPutInRange(((double)frame.ReadUInt32()) / uint.MaxValue));

            case FloatIntegerType.UShort:
                return(Percent.FactoryPutInRange(((double)frame.ReadUInt16()) / ushort.MaxValue));

            case FloatIntegerType.Byte:
                return(Percent.FactoryPutInRange(((double)frame.ReadUInt8()) / byte.MaxValue));

            default:
                throw new NotImplementedException();
            }
        }
        public static Percent GetPercent(ReadOnlySpan <byte> bytes, FloatIntegerType integerType)
        {
            switch (integerType)
            {
            case FloatIntegerType.UInt:
                return(Percent.FactoryPutInRange(((double)BinaryPrimitives.ReadUInt32LittleEndian(bytes)) / uint.MaxValue));

            case FloatIntegerType.UShort:
                return(Percent.FactoryPutInRange(((double)BinaryPrimitives.ReadUInt16LittleEndian(bytes)) / ushort.MaxValue));

            case FloatIntegerType.Byte:
                return(Percent.FactoryPutInRange(((double)bytes[0]) / byte.MaxValue));

            default:
                throw new NotImplementedException();
            }
        }
        public static void Write(MutagenWriter writer, Percent item, FloatIntegerType integerType)
        {
            switch (integerType)
            {
            case FloatIntegerType.UInt:
                writer.Write((uint)(item * uint.MaxValue));
                return;

            case FloatIntegerType.UShort:
                writer.Write((ushort)(item * ushort.MaxValue));
                return;

            case FloatIntegerType.Byte:
                writer.Write((byte)(item * byte.MaxValue));
                return;

            default:
                throw new NotImplementedException();
            }
        }
示例#7
0
        public static void Write(MutagenWriter writer, float?item, FloatIntegerType integerType, double multiplier)
        {
            if (item == null)
            {
                return;
            }
            switch (integerType)
            {
            case FloatIntegerType.UInt:
                writer.Write((uint)Math.Round(item.Value / multiplier));
                break;

            case FloatIntegerType.UShort:
                writer.Write((ushort)Math.Round(item.Value / multiplier));
                break;

            case FloatIntegerType.Byte:
                writer.Write((byte)Math.Round(item.Value / multiplier));
                break;

            default:
                throw new NotImplementedException();
            }
        }
 public static void Write(
     this PrimitiveBinaryTranslation <float, MutagenFrame, MutagenWriter> transl,
     MutagenWriter writer,
     float?item,
     RecordType header,
     FloatIntegerType integerType,
     double multiplier)
 {
     try
     {
         if (item == null)
         {
             return;
         }
         using (HeaderExport.Subrecord(writer, header))
         {
             FloatBinaryTranslation <MutagenFrame, MutagenWriter> .Instance.Write(writer, item, integerType, multiplier);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
示例#9
0
 public static void Write(MutagenWriter writer, float?item, RecordType header, FloatIntegerType integerType, double multiplier)
 {
     try
     {
         if (item == null)
         {
             return;
         }
         using (HeaderExport.Subrecord(writer, header))
         {
             Write(writer, item, integerType, multiplier);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }
示例#10
0
 public static void Write(MutagenWriter writer, float?item, RecordType header, FloatIntegerType integerType, double multiplier)
 {
     if (item == null)
     {
         return;
     }
     using (HeaderExport.Subrecord(writer, header))
     {
         Write(writer, item, integerType, multiplier);
     }
 }