Beispiel #1
0
        private VarIntPacker(int smallBits, int mediumBits, int largeBits, bool throwIfOverLarge)
        {
            this.throwIfOverLarge = throwIfOverLarge;
            if (smallBits == 0)
            {
                throw new ArgumentException("Small value can not be zero", nameof(smallBits));
            }
            if (smallBits >= mediumBits)
            {
                throw new ArgumentException("Medium value must be greater than small value", nameof(mediumBits));
            }
            if (mediumBits >= largeBits)
            {
                throw new ArgumentException("Large value must be greater than medium value", nameof(largeBits));
            }
            if (largeBits > 64)
            {
                throw new ArgumentException("Large bits must be 64 or less", nameof(largeBits));
            }
            // force medium to also be 62 or less so we can use 1 write call (2 bits to say its medium + 62 value bits
            if (mediumBits > 62)
            {
                throw new ArgumentException("Medium bits must be 62 or less", nameof(mediumBits));
            }

            smallBitCount   = smallBits;
            mediumBitsCount = mediumBits;
            largeBitsCount  = largeBits;

            // mask is also max value for n bits
            smallValue  = BitMask.Mask(smallBits);
            mediumValue = BitMask.Mask(mediumBits);
            largeValue  = BitMask.Mask(largeBits);
        }
Beispiel #2
0
 /// <param name="quaternionBitLength">10 per "smallest 3" is good enough for most people</param>
 public QuaternionPacker(int quaternionBitLength = 10)
 {
     // (this.BitLength - 1) because pack sign by itself
     bitCountPerElement = quaternionBitLength;
     totalBitCount      = 2 + (quaternionBitLength * 3);
     floatPacker        = new FloatPacker(MaxValue, quaternionBitLength);
     readMask           = (uint)BitMask.Mask(bitCountPerElement);
 }
Beispiel #3
0
 /// <param name="quaternionBitLength">10 per "smallest 3" is good enough for most people</param>
 public QuaternionPacker(int quaternionBitLength = 10)
 {
     // (this.BitLength - 1) because pack sign by itself
     _bitCountPerElement = quaternionBitLength;
     _totalBitCount      = 2 + (quaternionBitLength * 3);
     _floatPacker        = new FloatPacker(MAX_VALUE, quaternionBitLength);
     _readMask           = (uint)BitMask.Mask(_bitCountPerElement);
 }