當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。