示例#1
0
        public float UnpackFloat(PropertyInfo info, Bitstream stream) {
            var flags = info.Flags;

            if (flags.HasFlag(PropertyInfo.MultiFlag.Coord)) {
                return UnpackFloatCoord(stream);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CoordMp)) {
                return UnpackFloatCoordMp(stream, FloatType.None);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CoordMpLowPrecision)) {
                return UnpackFloatCoordMp(stream, FloatType.LowPrecision);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CoordMpIntegral)) {
                return UnpackFloatCoordMp(stream, FloatType.Integral);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.NoScale)) {
                return UnpackFloatNoScale(stream);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.Normal)) {
                return UnpackFloatNormal(stream);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CellCoord)) {
                return UnpackFloatCellCoord(info, stream, FloatType.None);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CellCoordLowPrecision)) {
                return UnpackFloatCellCoord(info, stream, FloatType.LowPrecision);
            } else if (flags.HasFlag(PropertyInfo.MultiFlag.CellCoordIntegral)) {
                return UnpackFloatCellCoord(info, stream, FloatType.Integral);
            } else {
                uint dividend = stream.ReadBits(info.NumBits);
                uint divisor = (uint) (1 << info.NumBits) - 1;

                float f = ((float) dividend) / divisor;
                float range = info.HighValue - info.LowValue;

                return f * range + info.LowValue;
            }
        }
示例#2
0
        public uint UnpackInt(PropertyInfo info, Bitstream stream) {
            var flags = info.Flags;

            if (flags.HasFlag(PropertyInfo.MultiFlag.EncodedAgainstTickcount)) {
                if (flags.HasFlag(PropertyInfo.MultiFlag.Unsigned)) {
                    return stream.ReadVarUInt();
                } else {
                    uint value = stream.ReadVarUInt();
                    return unchecked((uint) ((-(value & 1)) ^ (value >> 1)));
                }
            } else {
                byte numBits = info.NumBits;

                uint isUnsigned = Convert.ToUInt32(flags.HasFlag(PropertyInfo.MultiFlag.Unsigned));
                uint signer = (0x80000000 >> (32 - numBits)) & unchecked((uint) (isUnsigned - 1));

                uint value = stream.ReadBits(numBits) ^ signer;
                return value - signer;
            }
        }
示例#3
0
        public void UnpackArray(uint tick, List<Property> elements, PropertyInfo info, Bitstream stream) {
            byte countBits = (byte) (Util.Log2(info.NumElements + 1));
            uint count = stream.ReadBits(countBits);

            if (elements.Count > count) {
                elements.RemoveRange(0, elements.Count - (int) count);
            } else {
                while (elements.Count < count) {
                    elements.Add(Property.For(info.ArrayProp));
                }
            }

            foreach (var element in elements) {
                element.Update(tick, this, stream);
            }
        }
示例#4
0
        public ulong UnpackInt64(PropertyInfo info, Bitstream stream) {
            if (info.Flags.HasFlag(PropertyInfo.MultiFlag.EncodedAgainstTickcount)) {
                log.DebugFormat(
                    "{0}.{1} is encoded against tick count", 
                    info.DtName, info.VarName);
                return stream.ReadVarUInt();
            } else {
                bool negate = false;
                byte secondBits = (byte) (info.NumBits - 32);

                if (!info.Flags.HasFlag(PropertyInfo.MultiFlag.Unsigned)) {
                    --secondBits;

                    if (stream.ReadBool()) {
                        negate = true;
                    }
                }

                Preconditions.CheckArgument(info.NumBits >= secondBits);

                ulong a = stream.ReadBits(32);
                ulong b = stream.ReadBits(secondBits);
                ulong value = (b << 32) | a;

                if (negate) {
                    value = unchecked((ulong) ((long) value * -1));
                }

                return value;
            }
        }
示例#5
0
        public string UnpackString(PropertyInfo info, Bitstream stream) {
            uint length = stream.ReadBits(9);

            Preconditions.CheckArgument(length <= MAX_STRING_LENGTH);

            byte[] buffer = new byte[length];
            stream.Read(buffer, 0, (int) length);

            return new String((from byte b in buffer select (char) b).ToArray<char>());
        }
示例#6
0
 public VectorXy UnpackVectorXy(PropertyInfo info, Bitstream stream) {
     var x = UnpackFloat(info, stream);
     var y = UnpackFloat(info, stream);
     return new VectorXy(x, y);
 }
示例#7
0
        public Vector UnpackVector(PropertyInfo info, Bitstream stream) {
            float x = UnpackFloat(info, stream);
            float y = UnpackFloat(info, stream);
            float z;

            if (info.Flags.HasFlag(PropertyInfo.MultiFlag.Normal)) {
                bool sign = stream.ReadBool();

                float f = x * x + y * y;

                if (1 >= f) {
                    z = 0;
                } else {
                    z = (float) Math.Sqrt(1 - f);
                }

                if (sign) {
                    z *= -1;
                }
            } else {
                z = UnpackFloat(info, stream);
            }

            return new Vector(x, y, z);
        }
示例#8
0
        private float UnpackFloatCellCoord(PropertyInfo info, Bitstream stream, FloatType type) {
            uint value = stream.ReadBits(info.NumBits);
            float f = value;

            if ((value >> 31) > 0) {
                f *= -1;
            }

            if (type == FloatType.None) {
                uint fraction = stream.ReadBits(5);

                return f + 0.03125f * fraction;
            } else if (type == FloatType.LowPrecision) {
                uint fraction = stream.ReadBits(3);

                return f + 0.125f * fraction;
            } else if (type == FloatType.Integral) {
                return f;
            } else {
                throw new InvalidOperationException("Unknown float type");
            }
        }
示例#9
0
 private string QualifyProperty(string table, PropertyInfo property) {
     return String.Format("{0}.{1}", table, property.VarName);
 }