Ejemplo n.º 1
0
        private void UnpackSystem(BitPacker pack)
        {
            CRC            = pack.UnpackUnsignedBits(32);
            PartFlags      = pack.UnpackUnsignedBits(32);
            Pattern        = (SourcePattern)pack.ByteValue;
            MaxAge         = pack.UnpackFixed(false, 8, 8);
            StartAge       = pack.UnpackFixed(false, 8, 8);
            InnerAngle     = pack.UnpackFixed(false, 3, 5);
            OuterAngle     = pack.UnpackFixed(false, 3, 5);
            BurstRate      = pack.UnpackFixed(false, 8, 8);
            BurstRadius    = pack.UnpackFixed(false, 8, 8);
            BurstSpeedMin  = pack.UnpackFixed(false, 8, 8);
            BurstSpeedMax  = pack.UnpackFixed(false, 8, 8);
            BurstPartCount = pack.ByteValue;
            float x = pack.UnpackFixed(true, 8, 7);
            float y = pack.UnpackFixed(true, 8, 7);
            float z = pack.UnpackFixed(true, 8, 7);

            AngularVelocity = new Vector3(x, y, z);
            x = pack.UnpackFixed(true, 8, 7);
            y = pack.UnpackFixed(true, 8, 7);
            z = pack.UnpackFixed(true, 8, 7);
            PartAcceleration = new Vector3(x, y, z);
            Texture          = pack.UuidValue;
            Target           = pack.UuidValue;
        }
Ejemplo n.º 2
0
        public void Test1()
        {
            byte[] bytes = BitConverter.GetBytes(0xAA);

            BitPacker packer = new BitPacker(bytes);

            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());

            bytes  = BitConverter.GetBytes(0x0A);
            packer = new BitPacker(bytes);
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
        }
Ejemplo n.º 3
0
        protected virtual ISerializableWispObject DeserializeWispObject(ArraySegment <byte> value)
        {
            Pointer p = new Pointer();

            p.Position = value.Offset + 3;
            return(BitPacker.GetSerializableWispObject(value.Array, p));
        }
Ejemplo n.º 4
0
        public void Test1()
        {
            byte[] bytes = BitConverter.GetBytes(0xAA);

            BitPacker packer = new BitPacker(bytes);
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());

            bytes = BitConverter.GetBytes(0x0A);
            packer = new BitPacker(bytes);
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsFalse(packer.GetBoolean());
        }
Ejemplo n.º 5
0
        public static LayerData ToLayerMessage(List <LayerPatch> patches, LayerData.LayerDataType type, int offset, int length, out int outlength)
        {
            outlength = 0;
            var layer = new LayerData
            {
                LayerType = type
            };
            bool extended = false;

            switch (type)
            {
            case LayerData.LayerDataType.CloudExtended:
            case LayerData.LayerDataType.LandExtended:
            case LayerData.LayerDataType.WaterExtended:
            case LayerData.LayerDataType.WindExtended:
                extended = true;
                break;
            }

            var header = new GroupHeader
            {
                Stride    = STRIDE,
                PatchSize = LAYER_PATCH_NUM_XY_ENTRIES,
                Type      = type
            };
            var data    = new byte[1500];
            var bitpack = new BitPacker(data, 0);

            bitpack.PackBits(header.Stride, 16);
            bitpack.PackBits(header.PatchSize, 8);
            bitpack.PackBits((uint)header.Type, 8);
            int remainingbits = 1300 * 8; /* 1300 is a bit more than 2 perfectly bad compressed layer patches, wind needs two per packet */

            for (int i = 0; i < length; i++)
            {
                int patchno = i + offset;
                if (patches[patchno].Data.Length != LAYER_PATCH_NUM_XY_ENTRIES * LAYER_PATCH_NUM_XY_ENTRIES)
                {
                    throw new ArgumentException("Patch data must be a 16x16 array");
                }

                if (CompressPatch(bitpack, patches[patchno], extended, ref remainingbits))
                {
                    ++outlength;
                }
                else
                {
                    break;
                }
            }

            bitpack.PackBits(END_OF_PATCHES, 8);

            layer.Data = new byte[bitpack.NumBytes];
            Buffer.BlockCopy(bitpack.Data, 0, layer.Data, 0, bitpack.NumBytes);

            return(layer);
        }
Ejemplo n.º 6
0
 private void UnpackLegacyData(BitPacker pack)
 {
     PartDataFlags   = (ParticleDataFlags)pack.UnpackUnsignedBits(32);
     PartMaxAge      = pack.UnpackFixed(false, 8, 8);
     PartStartColor  = pack.ColorValue;
     PartEndColor    = pack.ColorValue;
     PartStartScaleX = pack.UnpackFixed(false, 3, 5);
     PartStartScaleY = pack.UnpackFixed(false, 3, 5);
     PartEndScaleX   = pack.UnpackFixed(false, 3, 5);
     PartEndScaleY   = pack.UnpackFixed(false, 3, 5);
 }
Ejemplo n.º 7
0
 private void PackLegacyData(BitPacker pack)
 {
     pack.PackBits((uint)PartDataFlags, 32);
     pack.PackFixed(PartMaxAge, false, 8, 8);
     pack.ColorValue = PartStartColor;
     pack.ColorValue = PartEndColor;
     pack.PackFixed(PartStartScaleX, false, 3, 5);
     pack.PackFixed(PartStartScaleY, false, 3, 5);
     pack.PackFixed(PartEndScaleX, false, 3, 5);
     pack.PackFixed(PartEndScaleY, false, 3, 5);
 }
Ejemplo n.º 8
0
        public void TestEndian()
        {
            uint intValue = 0xAABBCCDD;

            BitPacker.SwapEndian(ref intValue);
            Assert.AreEqual(0xDDCCBBAA, intValue);

            ushort ushortValue = 0xAABB;

            BitPacker.SwapEndian(ref ushortValue);
            Assert.AreEqual(0xBBAA, ushortValue);
        }
Ejemplo n.º 9
0
        public LayerPatch(double defaultHeight)
        {
            PackedData = new BitPacker(PackedDataBytes);

            for (int y = 0; y < 16; ++y)
            {
                for (int x = 0; x < 16; ++x)
                {
                    Data[y, x] = (float)defaultHeight;
                }
            }
        }
Ejemplo n.º 10
0
        public void HandleAuthSession(ref IPacketReader packet, ref IWorldManager manager)
        {
            Authenticator.PacketCrypt.Initialised = true;

            packet.Position = 58;
            int addonsize        = packet.ReadInt32();
            int decompressedSize = packet.ReadInt32();

            byte[] addonData = this.GetAddonInfo(packet);

            // get account name
            packet.Position = 62 + addonsize;
            var    bitUnpack = new BitUnpacker(packet);
            int    nameLen   = bitUnpack.GetBits <int>(12);
            string name      = packet.ReadString(nameLen).ToUpper();

            Account account = new Account(name);

            account.Load <Character>();
            manager.Account = account;

            PacketWriter writer  = new PacketWriter(Sandbox.Instance.Opcodes[global::Opcodes.SMSG_AUTH_RESPONSE], "SMSG_AUTH_RESPONSE");
            var          bitPack = new BitPacker(writer);

            bitPack.Write(0); // IsInQueue
            bitPack.Write(1); // HasAccountData
            bitPack.Flush();
            writer.WriteUInt8(0);
            writer.WriteUInt8(4);
            writer.WriteUInt32(0);
            writer.WriteUInt32(0);
            writer.WriteUInt8(4);
            writer.WriteUInt32(0);
            writer.WriteUInt8(0xC);
            manager.Send(writer);

            // create addoninfo packet
            var addonPacketInfo     = new PacketReader(addonData, false);
            var addonPacketResponse = new PacketWriter(Sandbox.Instance.Opcodes[global::Opcodes.SMSG_ADDON_INFO], "SMSG_ADDON_INFO");

            this.WriteAddonInfo(addonPacketInfo, addonPacketResponse, decompressedSize);
            manager.Send(addonPacketResponse);

            // Tutorial Flags : REQUIRED
            PacketWriter tutorial = new PacketWriter(Sandbox.Instance.Opcodes[global::Opcodes.SMSG_TUTORIAL_FLAGS], "SMSG_TUTORIAL_FLAGS");

            for (int i = 0; i < 8; i++)
            {
                tutorial.WriteUInt32(0);
            }
            manager.Send(tutorial);
        }
Ejemplo n.º 11
0
        protected virtual ArraySegment <byte> SerializeWispObject(ISerializableWispObject value)
        {
            byte[] buff = new byte[512];
            buff[0] = 255;
            buff[1] = 128;
            buff[2] = 255;

            Pointer p = new Pointer();

            p.Position = 3;
            BitPacker.AddSerializableWispObject(ref buff, p, value);
            return(new ArraySegment <byte>(buff, 0, p.Position));
        }
Ejemplo n.º 12
0
        public List <IPacket> Receive(byte[] pData)
        {
            FrameSerializer.BitPacking = BitPacker.FromArray(pData);
            uint crcValue = FrameSerializer.BitPacking.ReadValue(CrcCheck.HashSize);             // CRC

#if TRACE_LOG
            Log("Read CRC : " + crcValue + " (" + CrcCheck.HashSize + "Bits)");
#endif
            dCrcParameters.Check = crcValue;

            byte[] dataCrcCalculation = FrameSerializer.BitPacking.GetByteBuffer();
            if (CrcCheck.IsRight(dataCrcCalculation))
            {
                CurrentSequence = (ushort)FrameSerializer.BitPacking.ReadValue(SEQUENCE_SIZE);          // Sequence
#if TRACE_LOG
                Log("Read Sequence : " + Sequence + " (" + SEQUENCE_SIZE + "Bits)");
#endif
                Debug.Assert(!Program.StopOnSequence.HasValue || CurrentSequence != Program.StopOnSequence.Value);
                List <IPacket> result = new List <IPacket>();
                int            id     = 0;

                // Read the packets until an error occur or if the BitLenght is less than a byte.
                // This is because when the data are sent they are always rounded at the superior byte and the end of a packet is filled with 0's.
                while (FrameSerializer.BitPacking.BitLength >= 8 && !FrameSerializer.Error)
                {
#if TRACE_LOG
                    Log("Packet ID : ");
#endif
                    FrameSerializer.Serialize(ref id, 0, dFactory.Count() - 1);                  // Packet ID

                    IPacket packet = dFactory.CreateInstance <IPacket>(id);
                    packet.Header = new PacketHeader(crcValue, CurrentSequence);
#if TRACE_LOG
                    Log("Packet Data : ");
#endif
                    if (packet.Serialize(FrameSerializer))                                       // Data
                    {
                        result.Add(packet);
                    }
                }
                return(result);
            }
            else
            {
#if TRACE_LOG
                Log("Refused packet !");
#endif
            }
            return(null);
        }
Ejemplo n.º 13
0
    /// Set a pixel in the display.
    public void SetPixel(int x, int y, byte colorIndex)
    {
        // TODO Move it somewhere else.
        if (!isInitialized)
        {
            Initialize();
        }

        colorIndex = (byte)(colorIndex % numColors);
        int pixelNum = (y * resolution.x) + x;

        BitPacker.Pack(colorIndex, pixelNum, colorIndicesCPU);

        dirtyColorIndices = true;
    }
Ejemplo n.º 14
0
        public void Test2()
        {
            byte[] bytes;
            BitPacker packer;

            bytes = BitConverter.GetBytes(0xAFFF);
            packer = new BitPacker(bytes);

            Assert.IsTrue(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.AreEqual(15, packer.GetByte(4));
            Assert.IsTrue(packer.GetBoolean());
            Assert.AreEqual(95, packer.GetByte(7));
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
        }
Ejemplo n.º 15
0
        public void Test2()
        {
            byte[]    bytes;
            BitPacker packer;

            bytes  = BitConverter.GetBytes(0xAFFF);
            packer = new BitPacker(bytes);

            Assert.IsTrue(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
            Assert.AreEqual(15, packer.GetByte(4));
            Assert.IsTrue(packer.GetBoolean());
            Assert.AreEqual(95, packer.GetByte(7));
            Assert.IsFalse(packer.GetBoolean());
            Assert.IsTrue(packer.GetBoolean());
        }
Ejemplo n.º 16
0
        public LayerPatch(LayerPatch p)
        {
            PackedData = new BitPacker(PackedDataBytes);
            X          = p.X;
            Y          = p.Y;

            lock (m_Lock)
            {
                Serial = p.Serial;
                for (int y = 0; y < 16; ++y)
                {
                    for (int x = 0; x < 16; ++x)
                    {
                        Data[y, x] = p.Data[y, x];
                    }
                }
            }
        }
Ejemplo n.º 17
0
        private static bool CompressPatch(BitPacker pack, LayerPatch layerpatch, bool extended, ref int remainingbits)
        {
            lock (layerpatch)
            {
                /* check whether we have to run terrain compression */
                if (layerpatch.Serial != layerpatch.PackedSerial)
                {
                    layerpatch.PackedData.Reset();
                    if (layerpatch.Data.Length != LAYER_PATCH_NUM_XY_ENTRIES * LAYER_PATCH_NUM_XY_ENTRIES)
                    {
                        throw new ArgumentException("Patch data must be a 16x16 array");
                    }

                    var pheader = PrescanPatch(layerpatch);
                    pheader.QuantWBits = 136;
                    if (extended)
                    {
                        pheader.PatchIDs  = layerpatch.Y & 0xFFFF;
                        pheader.PatchIDs += layerpatch.X << 16;
                    }
                    else
                    {
                        pheader.PatchIDs  = layerpatch.Y & 0x1F;
                        pheader.PatchIDs += layerpatch.X << 5;
                    }

                    int[] patch = CompressPatch(layerpatch, pheader, 10);
                    int   wbits = EncodePatchHeader(layerpatch.PackedData, pheader, patch, extended);
                    EncodePatch(layerpatch.PackedData, patch, 0, wbits);
                    layerpatch.PackedSerial = layerpatch.Serial;
                }

                if (layerpatch.PackedData.BitLength <= remainingbits)
                {
                    remainingbits -= layerpatch.PackedData.BitLength;
                    pack.PackBits(layerpatch.PackedData);
                    return(true);
                }
                return(false);
            }
        }
Ejemplo n.º 18
0
 private void PackSystemBytes(BitPacker pack)
 {
     pack.PackBits(CRC, 32);
     pack.PackBits(PartFlags, 32);
     pack.PackBits((uint)Pattern, 8);
     pack.PackFixed(MaxAge, false, 8, 8);
     pack.PackFixed(StartAge, false, 8, 8);
     pack.PackFixed(InnerAngle, false, 3, 5);
     pack.PackFixed(OuterAngle, false, 3, 5);
     pack.PackFixed(BurstRate, false, 8, 8);
     pack.PackFixed(BurstRadius, false, 8, 8);
     pack.PackFixed(BurstSpeedMin, false, 8, 8);
     pack.PackFixed(BurstSpeedMax, false, 8, 8);
     pack.PackBits(BurstPartCount, 8);
     pack.PackFixed((float)AngularVelocity.X, true, 8, 7);
     pack.PackFixed((float)AngularVelocity.Y, true, 8, 7);
     pack.PackFixed((float)AngularVelocity.Z, true, 8, 7);
     pack.PackFixed((float)PartAcceleration.X, true, 8, 7);
     pack.PackFixed((float)PartAcceleration.Y, true, 8, 7);
     pack.PackFixed((float)PartAcceleration.Z, true, 8, 7);
     pack.UuidValue = Texture;
     pack.UuidValue = Target;
 }
Ejemplo n.º 19
0
        public void Test3()
        {
            byte[]    bytes;
            BitPacker packer;

            bytes  = BitConverter.GetBytes(0xAFFF);
            packer = new BitPacker(bytes);

            Assert.AreEqual(15, packer.GetByte(4));
            Assert.AreEqual(15, packer.GetByte(4));
            Assert.AreEqual(0xAF, packer.GetUshort(8));

            bytes  = BitConverter.GetBytes(0x0CD000);
            packer = new BitPacker(bytes);

            Assert.AreEqual(0x00, packer.GetByte(8));
            Assert.AreEqual(0x0CD0, packer.GetUshort(16));

            bytes  = BitConverter.GetBytes(0x000F << 1);
            packer = new BitPacker(bytes);
            Assert.IsFalse(packer.GetBoolean());
            Assert.AreEqual(0xF, packer.GetUshort(8));

            bytes  = BitConverter.GetBytes(0xAABB);
            packer = new BitPacker(bytes);
            Assert.AreEqual(0xAABB, packer.GetUshort(16, BitPacker.Endian.LoHi));

            packer.Reset();
            Assert.AreEqual(0xBBAA, packer.GetUshort(16, BitPacker.Endian.HiLo));

            packer.Reset();
            Assert.AreEqual(0xBBAA, packer.GetUshort(16, BitPacker.Endian.HiLo));

            bytes  = BitConverter.GetBytes(0x0100);
            packer = new BitPacker(bytes);
            Assert.AreEqual(0x0001, packer.GetUshort(16, BitPacker.Endian.HiLo));
        }
Ejemplo n.º 20
0
        public void Test3()
        {
            byte[] bytes;
            BitPacker packer;

            bytes = BitConverter.GetBytes(0xAFFF);
            packer = new BitPacker(bytes);

            Assert.AreEqual(15, packer.GetByte(4));
            Assert.AreEqual(15, packer.GetByte(4));
            Assert.AreEqual(0xAF,packer.GetUshort(8));

            bytes = BitConverter.GetBytes(0x0CD000);
            packer = new BitPacker(bytes);

            Assert.AreEqual(0x00, packer.GetByte(8));
            Assert.AreEqual(0x0CD0, packer.GetUshort(16));

            bytes = BitConverter.GetBytes(0x000F << 1) ;
            packer = new BitPacker(bytes);
            Assert.IsFalse(packer.GetBoolean());
            Assert.AreEqual(0xF, packer.GetUshort(8));

            bytes = BitConverter.GetBytes(0xAABB);
            packer = new BitPacker(bytes);
            Assert.AreEqual(0xAABB, packer.GetUshort(16, BitPacker.Endian.LoHi));

            packer.Reset();
            Assert.AreEqual(0xBBAA, packer.GetUshort(16, BitPacker.Endian.HiLo));

            packer.Reset();
            Assert.AreEqual(0xBBAA, packer.GetUshort(16, BitPacker.Endian.HiLo));

            bytes = BitConverter.GetBytes(0x0100);
            packer = new BitPacker(bytes);
            Assert.AreEqual(0x0001, packer.GetUshort(16, BitPacker.Endian.HiLo));
        }
Ejemplo n.º 21
0
    /// Create all the buffers, set up the Compute Shader etc. Can only be done once. Depends on the resolution
    public void Initialize()
    {
        if (isInitialized)
        {
            throw new Exception("The ScreenView is already initialized!");
        }

        // CPU side data containers.
        colorIndicesCPU = BitPacker.MakeStorageFor4BitValues(resolution.x * resolution.y);
        colorPaletteCPU = CreateDefaultColorPalette();

        // GPU-side data containers.
        colorIndicesGPU = new ComputeBuffer(resolution.x * resolution.y, numBytesPerUint);
        colorPaletteGPU = new ComputeBuffer(numColors, numBytesPerColor);

        targetTexture = CreateTargetTexture();
        SetupComputeShader();
        SetupMaterial();

        dirtyColorPalette = dirtyColorIndices = true;
        isVisibleToPlayer = true;

        isInitialized = true;
    }
Ejemplo n.º 22
0
        private static void EncodePatch(BitPacker output, int[] patch, int postquant, int wbits)
        {
            /* maximum possible length of patch data 640 Bytes */
            int  temp;
            bool eob;

            if (postquant > LAYER_PATCH_NUM_XY_ENTRIES * LAYER_PATCH_NUM_XY_ENTRIES || postquant < 0)
            {
                m_Log.ErrorFormat("Postquant {0} is outside the range of allowed values in EncodePatch()", postquant);
                return;
            }

            if (postquant != 0)
            {
                patch[LAYER_PATCH_NUM_XY_ENTRIES * LAYER_PATCH_NUM_XY_ENTRIES - postquant] = 0;
            }

            for (int i = 0; i < LAYER_PATCH_NUM_XY_ENTRIES * LAYER_PATCH_NUM_XY_ENTRIES; i++)
            {
                eob  = false;
                temp = patch[i];

                if (temp == 0)
                {
                    eob = true;

                    for (int j = i; j < LAYER_PATCH_NUM_XY_ENTRIES * LAYER_PATCH_NUM_XY_ENTRIES - postquant; j++)
                    {
                        if (patch[j] != 0)
                        {
                            eob = false;
                            break;
                        }
                    }

                    if (eob)
                    {
                        output.PackBits(ZERO_EOB, 2);
                        return;
                    }
                    else
                    {
                        output.PackBits(ZERO_CODE, 1);
                    }
                }
                else
                {
                    if (temp < 0)
                    {
                        temp *= -1;

                        if (temp >= (1 << wbits))
                        {
                            temp = (1 << wbits) - 1;
                        }

                        output.PackBits(NEGATIVE_VALUE, 3);
                        output.PackBits(temp, wbits);
                    }
                    else
                    {
                        if (temp >= (1 << wbits))
                        {
                            temp = (1 << wbits) - 1;
                        }

                        output.PackBits(POSITIVE_VALUE, 3);
                        output.PackBits(temp, wbits);
                    }
                }
            }
        }
Ejemplo n.º 23
0
        private static int EncodePatchHeader(BitPacker output, PatchHeader header, int[] patch, bool extended)
        {
            int  temp;
            int  wbits    = (header.QuantWBits & 0x0f) + 2;
            uint maxWbits = (uint)wbits + 5;
            uint minWbits = (uint)wbits >> 1;

            wbits = (int)minWbits;

            for (int i = 0; i < patch.Length; i++)
            {
                temp = patch[i];

                if (temp != 0)
                {
                    // Get the absolute value
                    if (temp < 0)
                    {
                        temp *= -1;
                    }

                    for (int j = (int)maxWbits; j > (int)minWbits; j--)
                    {
                        if ((temp & (1 << j)) != 0)
                        {
                            if (j > wbits)
                            {
                                wbits = j;
                            }
                            break;
                        }
                    }
                }
            }

            wbits++;

            if (wbits > 17)
            {
                wbits = 17;
            }
            else if (wbits < 2)
            {
                wbits = 2;
            }

            header.QuantWBits &= 0xf0;

            header.QuantWBits |= wbits - 2;

            output.PackBits(header.QuantWBits, 8);
            output.FloatValue = header.DCOffset;

            output.PackBits(header.Range, 16);
            if (extended)
            {
                output.PackBits(header.PatchIDs, 32);
            }
            else
            {
                output.PackBits(header.PatchIDs, 10);
            }

            /* Bit Length of Header in VarRegion format: 56 bits => 7 Bytes */

            return(wbits);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Decodes a byte[] array into a ParticleSystem Object
        /// </summary>
        /// <param name="data">ParticleSystem object</param>
        /// <param name="pos">Start position for BitPacker</param>
        public ParticleSystem(byte[] data, int pos)
        {
            BlendFuncSource = BlendFunc.SourceAlpha;
            BlendFuncDest   = BlendFunc.OneMinusSourceAlpha;

            MaxAge           = 0.0f;
            StartAge         = 0.0f;
            InnerAngle       = 0.0f;
            OuterAngle       = 0.0f;
            BurstRate        = 0.0f;
            BurstRadius      = 0.0f;
            BurstSpeedMin    = 0.0f;
            BurstSpeedMax    = 0.0f;
            AngularVelocity  = Vector3.Zero;
            PartAcceleration = Vector3.Zero;
            Texture          = UUID.Zero;
            Target           = UUID.Zero;
            PartStartColor   = ColorAlpha.Black;
            PartEndColor     = ColorAlpha.Black;
            PartStartScaleX  = 0.0f;
            PartStartScaleY  = 0.0f;
            PartEndScaleX    = 0.0f;
            PartEndScaleY    = 0.0f;

            int size = data.Length - pos;
            var pack = new BitPacker(data, pos);

            if (size == LegacyDataBlockSize)
            {
                UnpackSystem(pack);
                UnpackLegacyData(pack);
            }
            else if (size > LegacyDataBlockSize && size <= MaxDataBlockSize)
            {
                int sysSize = pack.UnpackSignedBits(32);
                if (sysSize != SysDataSize)
                {
                    return; // unkown particle system data size
                }
                UnpackSystem(pack);
                /*int dataSize = */ pack.UnpackSignedBits(32);
                UnpackLegacyData(pack);

                if ((PartDataFlags & ParticleDataFlags.DataGlow) == ParticleDataFlags.DataGlow)
                {
                    if (pack.Data.Length - pack.BytePos < 2)
                    {
                        return;
                    }
                    uint glow = pack.UnpackUnsignedBits(8);
                    PartStartGlow = glow / 255f;
                    glow          = pack.UnpackUnsignedBits(8);
                    PartEndGlow   = glow / 255f;
                }

                if ((PartDataFlags & ParticleDataFlags.DataBlend) == ParticleDataFlags.DataBlend)
                {
                    if (pack.Data.Length - pack.BytePos < 2)
                    {
                        return;
                    }
                    BlendFuncSource = (BlendFunc)pack.UnpackUnsignedBits(8);
                    BlendFuncDest   = (BlendFunc)pack.UnpackUnsignedBits(8);
                }
            }
        }
Ejemplo n.º 25
0
 public void SetColorCodeAt(int x, int y, ColorCode colorCode)
 {
     BitPacker.Pack((byte)colorCode, IndexAt(x, y), colorIndicesPacked);
 }
Ejemplo n.º 26
0
 public LayerPatch()
 {
     PackedData = new BitPacker(PackedDataBytes);
 }
Ejemplo n.º 27
0
        void compressFrame()
        {
            //#ifdef TIMELINE_SAMPLE_CODEC_TEST

            //static BDynamicCoderBuf coderBuf(65536);
            //BBitPacker<BDynamicCoderBuf> bitPacker(&coderBuf);
            BDynamicCoderBuf coderBuf  = new BDynamicCoderBuf(65536);
            BitPacker        bitPacker = new BitPacker(coderBuf);


            //#ifdef DUMP_OVERHEAD_TIME_TO_TRACE
            UInt64 startTime = ReadCycleCounter();

            //#endif

            // Reset the compressor's model to empty and compress all the samples to a buffer.
            mComp.resetModel();

            coderBuf.setPos(0);
            bitPacker.encodeStart();

            bool success;

            for (uint i = 0; i < size(mCurFrame); i++)
            {
                /*const BRetiredProfileSample&*/ BRetiredProfileSample sample = mCurFrame[i];
                BASSERT(sample.mSectionID < size(mSections));

                success = mComp.codeSample(bitPacker, ref sample, ref mSections[sample.mSectionID]);
                BASSERT(success);
            }

            /*const*/ uint totalInBytes  = (uint)(size(mCurFrame) * 23 /*sizeof(BRetiredProfileSample)*/);
            /*const*/ uint totalOutBytes = coderBuf.getPos();

            success = bitPacker.encodeEnd();
            BASSERT(success);

            //#if 1
            // Now decompress the samples and compare them to the original samples.
            mDecomp.resetModel();

            coderBuf.setPos(0);

            success = bitPacker.decodeStart();
            BASSERT(success);

            for (uint i = 0; i < size(mCurFrame); i++)
            {
                /*const BRetiredProfileSample&*/ BRetiredProfileSample sample = mCurFrame[i];
                BASSERT(sample.mSectionID < size(mSections));

                BRetiredProfileSample decodedSample = new BRetiredProfileSample();
                success = mDecomp.decodeSample(bitPacker, ref decodedSample, mSections);
                BASSERT(success);


                BASSERT(decodedSample.mSectionID == sample.mSectionID);
                BASSERT(decodedSample.mUserID == sample.mUserID);
                BASSERT(decodedSample.mLevel == sample.mLevel);

                BASSERT(decodedSample.mCPUStartTime == sample.mCPUStartTime);
                BASSERT(decodedSample.mCPUEndTime == sample.mCPUEndTime);
                if (sample.hasGPUTimes())
                {
                    BASSERT(decodedSample.hasGPUTimes());
                    BASSERT(decodedSample.mGPUStartTime == sample.mGPUStartTime);
                    BASSERT(decodedSample.mGPUEndTime == sample.mGPUEndTime);
                }
                else
                {
                    BASSERT(!decodedSample.hasGPUTimes());
                }
            }
            //#endif

            //#ifdef DUMP_OVERHEAD_TIME_TO_TRACE
            UInt64 endTime = ReadCycleCounter();

            /*static UInt64 totalTime;*/
            /*static uint frameCount;*/
            totalTime += (endTime - startTime);
            frameCount++;
            if (frameCount == 60)
            {
                //blogtrace(String.Format("Compress/decompress: %4.3f ms/frame", totalTime / (float)(frameCount) * gpProfileManager->getOOCompCPUFreq() * 1000.0f));

                frameCount = 0;
                totalTime  = 0;
            }

            if (size(mCurFrame) > 0)
            {
                blogtrace(String.Format("Compression samples: %i, Bytes: %i, Compressed bytes: %i, Ave. bytes per sample: %f, Ave. bits per byte: %f",
                                        size(mCurFrame),
                                        totalInBytes,
                                        totalOutBytes,
                                        (float)(totalOutBytes) / size(mCurFrame),
                                        (totalOutBytes * 8.0f) / totalInBytes));
            }
            //#endif

            //#endif TIMELINE_SAMPLE_CODEC_TEST
        }
Ejemplo n.º 28
0
 public void BitPacker_1()
 {
     var buffer = new BitPacker(1);
     var xs     = buffer.UnpackUInts(new byte[] { 0b10110011 });
Ejemplo n.º 29
0
        /// <summary>
        /// Generate byte[] array from particle data
        /// </summary>
        /// <returns>Byte array</returns>
        public byte[] GetBytes()
        {
            int size = LegacyDataBlockSize;

            if (!IsLegacyCompatible())
            {
                size += 8; // two new ints for size
            }
            if (HasGlow())
            {
                size += 2; // two bytes for start and end glow
            }
            if (HasBlendFunc())
            {
                size += 2; // two bytes for start end end blend function
            }

            var bytes = new byte[size];
            var pack  = new BitPacker(bytes, 0);

            if (IsLegacyCompatible())
            {
                PackSystemBytes(pack);
                PackLegacyData(pack);
            }
            else
            {
                if (HasGlow())
                {
                    PartDataFlags |= ParticleDataFlags.DataGlow;
                }
                if (HasBlendFunc())
                {
                    PartDataFlags |= ParticleDataFlags.DataBlend;
                }

                pack.PackBits(SysDataSize, 32);
                PackSystemBytes(pack);
                int partSize = PartDataSize;
                if (HasGlow())
                {
                    partSize += 2; // two bytes for start and end glow
                }
                if (HasBlendFunc())
                {
                    partSize += 2; // two bytes for start end end blend function
                }
                pack.PackBits(partSize, 32);
                PackLegacyData(pack);

                if (HasGlow())
                {
                    pack.PackBits((byte)(PartStartGlow * 255f), 8);
                    pack.PackBits((byte)(PartEndGlow * 255f), 8);
                }

                if (HasBlendFunc())
                {
                    pack.PackBits((byte)BlendFuncSource, 8);
                    pack.PackBits((byte)BlendFuncDest, 8);
                }
            }

            return(bytes);
        }
Ejemplo n.º 30
0
        public void HandleCharEnum(ref IPacketReader packet, ref IWorldManager manager)
        {
            var account = manager.Account;
            var result  = account.Characters.Where(x => x.Build == Sandbox.Instance.Build);

            PacketWriter writer    = new PacketWriter(Sandbox.Instance.Opcodes[global::Opcodes.SMSG_CHAR_ENUM], "SMSG_CHAR_ENUM");
            BitPacker    bitPacker = new BitPacker(writer);

            bitPacker.Write(1);
            bitPacker.Write(0, 23);
            bitPacker.Write(result.Count(), 17);

            foreach (Character c in result)
            {
                bitPacker.Write(0, 3);
                bitPacker.Write(c.Guid & 0xFF);
                bitPacker.Write((c.Guid >> 8) & 0xFF);
                bitPacker.Write(0);
                bitPacker.Write(c.Name.Length, 7);
                bitPacker.Write(0, 4);
                bitPacker.Write((c.Guid >> 16) & 0xFF);
                bitPacker.Write((c.Guid >> 24) & 0xFF);
                bitPacker.Write(0, 5);
            }

            bitPacker.Flush();

            foreach (Character c in result)
            {
                writer.WriteUInt8(c.Gender);
                writer.WriteUInt8((byte)c.Level);

                // items
                for (int i = 0; i < 0x17; i++)
                {
                    writer.WriteUInt32(0);
                    writer.WriteUInt32(0);
                    writer.WriteUInt8(0);
                }

                writer.WriteGUIDByte(c.Guid, 0);
                writer.WriteFloat(c.Location.Z);
                writer.WriteUInt8(c.HairColor);
                writer.WriteUInt32(c.Zone);
                writer.WriteGUIDByte(c.Guid, 3);
                writer.WriteGUIDByte(c.Guid, 1);
                writer.WriteUInt32(0);
                writer.WriteFloat(c.Location.X);
                writer.WriteUInt8(0);
                writer.WriteUInt8(c.HairStyle);
                writer.WriteUInt32(c.Location.Map);
                writer.WriteUInt8(c.Face);
                writer.WriteUInt8(c.Skin);
                writer.Write(System.Text.Encoding.ASCII.GetBytes(c.Name));
                writer.WriteUInt8(c.FacialHair);
                writer.WriteUInt8(c.Class);
                writer.WriteUInt32(0);
                writer.WriteUInt8(c.Race);
                writer.WriteFloat(c.Location.Y);
                writer.WriteGUIDByte(c.Guid, 2);
                writer.WriteUInt32(0); // customise flags
                writer.WriteUInt32(0); // char flags
                writer.WriteUInt32(0);
            }

            manager.Send(writer);
        }
Ejemplo n.º 31
0
 public ColorCode GetColorCodeAt(int x, int y)
 {
     return((ColorCode)BitPacker.Unpack(IndexAt(x, y), colorIndicesPacked));
 }
Ejemplo n.º 32
0
 public ScreenBufferState(Vector2Int size)
 {
     this.size          = size;
     colorIndicesPacked = BitPacker.MakeStorageFor4BitValues(size.x * size.y);
 }