当前位置: 首页>>代码示例>>C#>>正文


C# BitPack.UnpackBits方法代码示例

本文整理汇总了C#中OpenMetaverse.BitPack.UnpackBits方法的典型用法代码示例。如果您正苦于以下问题:C# BitPack.UnpackBits方法的具体用法?C# BitPack.UnpackBits怎么用?C# BitPack.UnpackBits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenMetaverse.BitPack的用法示例。


在下文中一共展示了BitPack.UnpackBits方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BitUnpacking

        public void BitUnpacking()
        {
            byte[] data = new byte[] { 0x80, 0x00, 0x0F, 0x50, 0x83, 0x7D };
            BitPack bitpacker = new BitPack(data, 0);

            int b = bitpacker.UnpackBits(1);
            Assert.IsTrue(b == 1, "Unpacked " + b + " instead of 1");

            b = bitpacker.UnpackBits(1);
            Assert.IsTrue(b == 0, "Unpacked " + b + " instead of 0");

            bitpacker = new BitPack(data, 2);

            b = bitpacker.UnpackBits(4);
            Assert.IsTrue(b == 0, "Unpacked " + b + " instead of 0");

            b = bitpacker.UnpackBits(8);
            Assert.IsTrue(b == 0xF5, "Unpacked " + b + " instead of 0xF5");

            b = bitpacker.UnpackBits(4);
            Assert.IsTrue(b == 0, "Unpacked " + b + " instead of 0");

            b = bitpacker.UnpackBits(10);
            Assert.IsTrue(b == 0x0183, "Unpacked " + b + " instead of 0x0183");
        }
开发者ID:jhs,项目名称:libopenmetaverse,代码行数:25,代码来源:TypeTests.cs

示例2: GetParcelArea

        public static int GetParcelArea(SceneParcel parcel, out Vector3 aabbMin, out Vector3 aabbMax)
        {
            int minX = 64;
            int minY = 64;
            int maxX = 0;
            int maxY = 0;
            int area = 0;

            System.Diagnostics.Debug.Assert(parcel.Bitmap != null);
            System.Diagnostics.Debug.Assert(parcel.Bitmap.Length == 512);

            BitPack bitmap = new BitPack(parcel.Bitmap, 0);
            for (int y = 0; y < 64; y++)
            {
                for (int x = 0; x < 64; x++)
                {
                    if (bitmap.UnpackBits(1) != 0)
                    {
                        int x4 = x * 4;
                        int y4 = y * 4;

                        if (minX > x4) minX = x4;
                        if (minY > y4) minY = y4;
                        if (maxX < x4) maxX = x4;
                        if (maxX < y4) maxY = y4;
                        area += 16;
                    }
                }
            }

            aabbMin = new Vector3(minX, minY, 0f);
            aabbMax = new Vector3(maxX, maxY, 0f);
            return area;
        }
开发者ID:osgrid,项目名称:openmetaverse,代码行数:34,代码来源:ParcelManager.cs

示例3: BitPacking

        public void BitPacking()
        {
            byte[] packedBytes = new byte[12];
            BitPack bitpacker = new BitPack(packedBytes, 0);

            bitpacker.PackBits(0x0ABBCCDD, 32);
            bitpacker.PackBits(25, 5);
            bitpacker.PackFloat(123.321f);
            bitpacker.PackBits(1000, 16);

            bitpacker = new BitPack(packedBytes, 0);

            int b = bitpacker.UnpackBits(32);
            Assert.IsTrue(b == 0x0ABBCCDD, "Unpacked " + b + " instead of 2864434397");

            b = bitpacker.UnpackBits(5);
            Assert.IsTrue(b == 25, "Unpacked " + b + " instead of 25");

            float f = bitpacker.UnpackFloat();
            Assert.IsTrue(f == 123.321f, "Unpacked " + f + " instead of 123.321");

            b = bitpacker.UnpackBits(16);
            Assert.IsTrue(b == 1000, "Unpacked " + b + " instead of 1000");

            packedBytes = new byte[1];
            bitpacker = new BitPack(packedBytes, 0);
            bitpacker.PackBit(true);

            bitpacker = new BitPack(packedBytes, 0);
            b = bitpacker.UnpackBits(1);
            Assert.IsTrue(b == 1, "Unpacked " + b + " instead of 1");

            packedBytes = new byte[1] { Byte.MaxValue };
            bitpacker = new BitPack(packedBytes, 0);
            bitpacker.PackBit(false);

            bitpacker = new BitPack(packedBytes, 0);
            b = bitpacker.UnpackBits(1);
            Assert.IsTrue(b == 0, "Unpacked " + b + " instead of 0");
        }
开发者ID:nooperation,项目名称:libopenmetaverse,代码行数:40,代码来源:TypeTests.cs

示例4: DecodePatch

 public static void DecodePatch(int[] patches, BitPack bitpack, TerrainPatch.Header header, int size)
 {
     for (int n = 0; n < size*size; n++)
     {
         // ?
         int temp = bitpack.UnpackBits(1);
         if (temp != 0)
         {
             // Value or EOB
             temp = bitpack.UnpackBits(1);
             if (temp != 0)
             {
                 // Value
                 temp = bitpack.UnpackBits(1);
                 if (temp != 0)
                 {
                     // Negative
                     temp = bitpack.UnpackBits((int) header.WordBits);
                     patches[n] = temp*-1;
                 }
                 else
                 {
                     // Positive
                     temp = bitpack.UnpackBits((int) header.WordBits);
                     patches[n] = temp;
                 }
             }
             else
             {
                 // Set the rest to zero
                 // TODO: This might not be necessary
                 for (int o = n; o < size*size; o++)
                 {
                     patches[o] = 0;
                 }
                 break;
             }
         }
         else
         {
             patches[n] = 0;
         }
     }
 }
开发者ID:velus,项目名称:opensim,代码行数:44,代码来源:TerrainCompressor.cs

示例5: DecodePatchHeader

        public static TerrainPatch.Header DecodePatchHeader(BitPack bitpack)
        {
            TerrainPatch.Header header = new TerrainPatch.Header {QuantWBits = bitpack.UnpackBits(8)};

            // Quantized word bits
            if (header.QuantWBits == END_OF_PATCHES)
                return header;

            // DC offset
            header.DCOffset = bitpack.UnpackFloat();

            // Range
            header.Range = bitpack.UnpackBits(16);

            // Patch IDs (10 bits)
            header.PatchIDs = bitpack.UnpackBits(10);

            // Word bits
            header.WordBits = (uint) ((header.QuantWBits & 0x0f) + 2);

            return header;
        }
开发者ID:velus,项目名称:opensim,代码行数:22,代码来源:TerrainCompressor.cs

示例6: UpdateParcelOverlay

        private void UpdateParcelOverlay(SceneParcel parcel)
        {
            BitPack bitmap = new BitPack(parcel.Bitmap, 0);

            for (int y = 0; y < 64; y++)
            {
                for (int x = 0; x < 64; x++)
                {
                    if (bitmap.UnpackBits(1) != 0)
                        m_parcelOverlay[y * 64 + x] = parcel.LocalID;
                }
            }
        }
开发者ID:osgrid,项目名称:openmetaverse,代码行数:13,代码来源:ParcelManager.cs

示例7: SplitParcel

        public void SplitParcel(SceneParcel parcel, int startX, int endX, int startY, int endY)
        {
            SceneParcel newParcel = new SceneParcel(parcel);
            newParcel.ID = UUID.Random();
            newParcel.LocalID = System.Threading.Interlocked.Increment(ref m_currentParcelID);
            newParcel.ClaimDate = DateTime.UtcNow;
            newParcel.Dwell = 0f;

            m_parcels.Add(newParcel.ID, newParcel.LocalID, newParcel);

            // Update parcel bitmaps
            BitPack origParcelBitmap = new BitPack(parcel.Bitmap, 0);
            BitPack parcelBitmap = new BitPack(new byte[512], 0);
            BitPack newParcelBitmap = new BitPack(newParcel.Bitmap, 0);

            for (int y = 0; y < 64; y++)
            {
                for (int x = 0; x < 64; x++)
                {
                    bool origParcelBit = (origParcelBitmap.UnpackBits(1) != 0);

                    if (x >= startX && x <= endX && y >= startY && y <= endY)
                    {
                        // Inside the new parcel
                        parcelBitmap.PackBit(false);
                        newParcelBitmap.PackBit(true);
                        m_parcelOverlay[y * 64 + x] = newParcel.LocalID;
                    }
                    else
                    {
                        // Not inside the new parcel
                        parcelBitmap.PackBit(origParcelBit);
                        newParcelBitmap.PackBit(false);
                    }
                }
            }

            // Update parcel landing info
            SceneParcel landingParcel;
            if (TryGetParcel(newParcel.LandingLocation, out landingParcel) && landingParcel == parcel)
            {
                newParcel.Landing = LandingType.None;
                newParcel.LandingLocation = Vector3.Zero;
            }
            else
            {
                parcel.Landing = LandingType.None;
                parcel.LandingLocation = Vector3.Zero;
            }

            // Update max prim counts
            Vector3 aabbMin, aabbMax;
            int area = GetParcelArea(parcel, out aabbMin, out aabbMax);
            parcel.MaxPrims = (int)Math.Round((float)area * m_primsPerSquareMeter);
            area = GetParcelArea(newParcel, out aabbMin, out aabbMax);
            newParcel.MaxPrims = (int)Math.Round((float)area * m_primsPerSquareMeter);

            Serialize();
        }
开发者ID:osgrid,项目名称:openmetaverse,代码行数:59,代码来源:ParcelManager.cs

示例8: LayerDataHandler

        private void LayerDataHandler(Packet packet, Simulator simulator)
        {
            LayerDataPacket layer = (LayerDataPacket)packet;
            BitPack bitpack = new BitPack(layer.LayerData.Data, 0);
            TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader();
            TerrainPatch.LayerType type = (TerrainPatch.LayerType)layer.LayerID.Type;

            // Stride
            header.Stride = bitpack.UnpackBits(16);
            // Patch size
            header.PatchSize = bitpack.UnpackBits(8);
            // Layer type
            header.Type = (TerrainPatch.LayerType)bitpack.UnpackBits(8);

            switch (type)
            {
                case TerrainPatch.LayerType.Land:
                    if (OnLandPatch != null || Client.Settings.STORE_LAND_PATCHES)
                        DecompressLand(simulator, bitpack, header);
                    break;
                case TerrainPatch.LayerType.Water:
                    Logger.Log("Got a Water LayerData packet, implement me!", Helpers.LogLevel.Error, Client);
                    break;
                case TerrainPatch.LayerType.Wind:
                    DecompressWind(simulator, bitpack, header);
                    break;
                case TerrainPatch.LayerType.Cloud:
                    DecompressCloud(simulator, bitpack, header);
                    break;
                default:
                    Logger.Log("Unrecognized LayerData type " + type.ToString(), Helpers.LogLevel.Warning, Client);
                    break;
            }
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:34,代码来源:TerrainManager.cs

示例9: ParticleSystem

            /// <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);
                    }

                }
            }
开发者ID:skidzTweak,项目名称:libopenmetaverse,代码行数:58,代码来源:ParticleSystem.cs


注:本文中的OpenMetaverse.BitPack.UnpackBits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。