Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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();
        }