예제 #1
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);
 }
            void UnpackLegacyData(ref BitPack pack)
            {
                PartDataFlags = (ParticleDataFlags)pack.UnpackUInt();
                PartMaxAge    = pack.UnpackFixed(false, 8, 8);
                byte r = pack.UnpackByte();
                byte g = pack.UnpackByte();
                byte b = pack.UnpackByte();
                byte a = pack.UnpackByte();

                PartStartColor = new Color4(r, g, b, a);
                r               = pack.UnpackByte();
                g               = pack.UnpackByte();
                b               = pack.UnpackByte();
                a               = pack.UnpackByte();
                PartEndColor    = new Color4(r, g, b, a);
                PartStartScaleX = pack.UnpackFixed(false, 3, 5);
                PartStartScaleY = pack.UnpackFixed(false, 3, 5);
                PartEndScaleX   = pack.UnpackFixed(false, 3, 5);
                PartEndScaleY   = pack.UnpackFixed(false, 3, 5);
            }
예제 #3
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)
            {
                // TODO: Not sure exactly how many bytes we need here, so partial
                // (truncated) data will cause an exception to be thrown
                if (data.Length > 0)
                {
                    BitPack pack = new BitPack(data, pos);

                    CRC            = pack.UnpackUBits(32);
                    PartFlags      = pack.UnpackUBits(32);
                    Pattern        = (SourcePattern)pack.UnpackByte();
                    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.UnpackByte();
                    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.UnpackUUID();
                    Target           = pack.UnpackUUID();

                    PartDataFlags = (ParticleDataFlags)pack.UnpackUBits(32);
                    PartMaxAge    = pack.UnpackFixed(false, 8, 8);
                    byte r = pack.UnpackByte();
                    byte g = pack.UnpackByte();
                    byte b = pack.UnpackByte();
                    byte a = pack.UnpackByte();
                    PartStartColor = new Color4(r, g, b, a);
                    r               = pack.UnpackByte();
                    g               = pack.UnpackByte();
                    b               = pack.UnpackByte();
                    a               = pack.UnpackByte();
                    PartEndColor    = new Color4(r, g, b, a);
                    PartStartScaleX = pack.UnpackFixed(false, 3, 5);
                    PartStartScaleY = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleX   = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleY   = pack.UnpackFixed(false, 3, 5);
                }
                else
                {
                    CRC               = PartFlags = 0;
                    Pattern           = SourcePattern.None;
                    MaxAge            = StartAge = InnerAngle = OuterAngle = BurstRate = BurstRadius = BurstSpeedMin =
                        BurstSpeedMax = 0.0f;
                    BurstPartCount    = 0;
                    AngularVelocity   = PartAcceleration = Vector3.Zero;
                    Texture           = Target = UUID.Zero;
                    PartDataFlags     = ParticleDataFlags.None;
                    PartMaxAge        = 0.0f;
                    PartStartColor    = PartEndColor = Color4.Black;
                    PartStartScaleX   = PartStartScaleY = PartEndScaleX = PartEndScaleY = 0.0f;
                }
            }
예제 #4
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)
            {
                // TODO: Not sure exactly how many bytes we need here, so partial
                // (truncated) data will cause an exception to be thrown
                if (data.Length > 0)
                {
                    BitPack pack = new BitPack(data, pos);

                    CRC = pack.UnpackUBits(32);
                    PartFlags = pack.UnpackUBits(32);
                    Pattern = (SourcePattern)pack.UnpackByte();
                    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.UnpackByte();
                    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.UnpackUUID();
                    Target = pack.UnpackUUID();

                    PartDataFlags = (ParticleDataFlags)pack.UnpackUBits(32);
                    PartMaxAge = pack.UnpackFixed(false, 8, 8);
                    byte r = pack.UnpackByte();
                    byte g = pack.UnpackByte();
                    byte b = pack.UnpackByte();
                    byte a = pack.UnpackByte();
                    PartStartColor = new Color4(r, g, b, a);
                    r = pack.UnpackByte();
                    g = pack.UnpackByte();
                    b = pack.UnpackByte();
                    a = pack.UnpackByte();
                    PartEndColor = new Color4(r, g, b, a);
                    PartStartScaleX = pack.UnpackFixed(false, 3, 5);
                    PartStartScaleY = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleX = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleY = pack.UnpackFixed(false, 3, 5);
                }
                else
                {
                    CRC = PartFlags = 0;
                    Pattern = SourcePattern.None;
                    MaxAge = StartAge = InnerAngle = OuterAngle = BurstRate = BurstRadius = BurstSpeedMin =
                        BurstSpeedMax = 0.0f;
                    BurstPartCount = 0;
                    AngularVelocity = PartAcceleration = Vector3.Zero;
                    Texture = Target = UUID.Zero;
                    PartDataFlags = ParticleDataFlags.None;
                    PartMaxAge = 0.0f;
                    PartStartColor = PartEndColor = Color4.Black;
                    PartStartScaleX = PartStartScaleY = PartEndScaleX = PartEndScaleY = 0.0f;
                }
            }
예제 #5
0
 void UnpackLegacyData(ref BitPack pack)
 {
     PartDataFlags = (ParticleDataFlags)pack.UnpackUBits(32);
     PartMaxAge = pack.UnpackFixed(false, 8, 8);
     byte r = pack.UnpackByte();
     byte g = pack.UnpackByte();
     byte b = pack.UnpackByte();
     byte a = pack.UnpackByte();
     PartStartColor = new Color4(r, g, b, a);
     r = pack.UnpackByte();
     g = pack.UnpackByte();
     b = pack.UnpackByte();
     a = pack.UnpackByte();
     PartEndColor = new Color4(r, g, b, a);
     PartStartScaleX = pack.UnpackFixed(false, 3, 5);
     PartStartScaleY = pack.UnpackFixed(false, 3, 5);
     PartEndScaleX = pack.UnpackFixed(false, 3, 5);
     PartEndScaleY = pack.UnpackFixed(false, 3, 5);
 }
예제 #6
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

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

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

                    pack.PackBits(SysDataSize, 32);
                    PackSystemBytes(ref 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(ref pack);

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

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

                return bytes;
            }
예제 #7
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)
            {
                PartStartGlow = 0f;
                PartEndGlow = 0f;
                BlendFuncSource = (byte)BlendFunc.SourceAlpha;
                BlendFuncDest = (byte)BlendFunc.OneMinusSourceAlpha;

                CRC = PartFlags = 0;
                Pattern = SourcePattern.None;
                MaxAge = StartAge = InnerAngle = OuterAngle = BurstRate = BurstRadius = BurstSpeedMin =
                    BurstSpeedMax = 0.0f;
                BurstPartCount = 0;
                AngularVelocity = PartAcceleration = Vector3.Zero;
                Texture = Target = UUID.Zero;
                PartDataFlags = ParticleDataFlags.None;
                PartMaxAge = 0.0f;
                PartStartColor = PartEndColor = Color4.Black;
                PartStartScaleX = PartStartScaleY = PartEndScaleX = PartEndScaleY = 0.0f;

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

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

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

                    if ((PartDataFlags & ParticleDataFlags.DataBlend) == ParticleDataFlags.DataBlend)
                    {
                        if (pack.Data.Length - pack.BytePos < 2) return;
                        BlendFuncSource = (byte)pack.UnpackUBits(8);
                        BlendFuncDest = (byte)pack.UnpackUBits(8);
                    }

                }
            }
            /// <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
                }
                byte[]  bytes = new byte[size];
                BitPack pack  = new BitPack(bytes, 0);

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

                    pack.PackBitsFromUInt((uint)SysDataSize);
                    PackSystemBytes(ref 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.PackBitsFromUInt((uint)partSize);
                    PackLegacyData(ref pack);

                    if (HasGlow())
                    {
                        pack.PackBitsFromByte((byte)(PartStartGlow * 255f));
                        pack.PackBitsFromByte((byte)(PartEndGlow * 255f));
                    }

                    if (HasBlendFunc())
                    {
                        pack.PackBitsFromByte(BlendFuncSource);
                        pack.PackBitsFromByte(BlendFuncDest);
                    }
                }

                return(bytes);
            }
            /// <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)
            {
                PartStartGlow   = 0f;
                PartEndGlow     = 0f;
                BlendFuncSource = (byte)BlendFunc.SourceAlpha;
                BlendFuncDest   = (byte)BlendFunc.OneMinusSourceAlpha;

                CRC               = PartFlags = 0;
                Pattern           = SourcePattern.None;
                MaxAge            = StartAge = InnerAngle = OuterAngle = BurstRate = BurstRadius = BurstSpeedMin =
                    BurstSpeedMax = 0.0f;
                BurstPartCount    = 0;
                AngularVelocity   = PartAcceleration = Vector3.Zero;
                Texture           = Target = UUID.Zero;
                PartDataFlags     = ParticleDataFlags.None;
                PartMaxAge        = 0.0f;
                PartStartColor    = PartEndColor = Color4.Black;
                PartStartScaleX   = PartStartScaleY = PartEndScaleX = PartEndScaleY = 0.0f;

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

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

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

                    if ((PartDataFlags & ParticleDataFlags.DataBlend) == ParticleDataFlags.DataBlend)
                    {
                        if (pack.Data.Length - pack.BytePos < 2)
                        {
                            return;
                        }
                        BlendFuncSource = pack.UnpackByte();
                        BlendFuncDest   = pack.UnpackByte();
                    }
                }
            }
예제 #10
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);
        }