public void Clear()
 {
     this.crusher = null;
     this.cx      = new CompressedFloat(null, 0);
     this.cy      = new CompressedFloat(null, 0);
     this.cz      = new CompressedFloat(null, 0);
 }
 public void Set(ElementCrusher crusher, CompressedFloat cx, CompressedFloat cy, CompressedFloat cz)
 {
     this.crusher = crusher;
     this.cx      = cx;
     this.cy      = cy;
     this.cz      = cz;
 }
 public void Set(ElementCrusher crusher, uint cx, uint cy, uint cz)
 {
     this.crusher = crusher;
     this.cx      = new CompressedFloat(crusher.XCrusher, cx);
     this.cy      = new CompressedFloat(crusher.YCrusher, cy);
     this.cz      = new CompressedFloat(crusher.ZCrusher, cz);
 }
 // Constructor
 public CompressedElement(ElementCrusher crusher, CompressedFloat cx, CompressedFloat cy, CompressedFloat cz)        /* : this()*/
 {
     //UnityEngine.Debug.LogWarning("CE Construct");
     this.crusher = crusher;
     this.cx      = cx;
     this.cy      = cy;
     this.cz      = cz;
 }
示例#5
0
        //public RotationType RotationType { get { return (RotationType)crusher.TRSType; } }

        // Constructor
        public RotationElement(bool local = true)
        {
            crusher = new ElementCrusher(TRSType.Quaternion, false)
            {
                local = local
            };
            crusher.qcrusher.Bits = 40;
        }
 // Constructor
 public CompressedElement(ElementCrusher crusher, uint cx, uint cy, uint cz)         /*: this()*/
 {
     UnityEngine.Debug.LogWarning("CE Construct");
     this.crusher = crusher;
     this.cx      = new CompressedFloat(crusher.XCrusher, cx);
     this.cy      = new CompressedFloat(crusher.YCrusher, cy);
     this.cz      = new CompressedFloat(crusher.ZCrusher, cz);
 }
 /// <summary>
 /// Alternative to OverwriteUpperBits that attempts to guess the upperbits by seeing if each axis of the new position would be
 /// closer to the old one if the upper bit is incremented by one, two, three etc. Stops trying when it fails to get a better result.
 /// </summary>
 /// <param name="oldcpos">Last best position test against.</param>
 /// <returns>Returns a corrected CompressPos</returns>
 public static void GuessUpperBits(this CompressedElement newcpos, ElementCrusher ec, CompressedElement oldcpos, BitCullingLevel bcl)
 {
     //var crusher = oldcpos.crusher;
     newcpos.Set(
         ec,
         ec.XCrusher.GuessUpperBits(newcpos[0], oldcpos[0], bcl),
         ec.YCrusher.GuessUpperBits(newcpos[1], oldcpos[1], bcl),
         ec.ZCrusher.GuessUpperBits(newcpos[2], oldcpos[2], bcl)
         );
 }
 public static CompressedElement Extrapolate(ElementCrusher crusher, CompressedElement curr, CompressedElement prev, int divisor = 2)
 {
     return(new CompressedElement
            (
                crusher,
                (uint)(curr.cx + (((long)curr.cx - prev.cx)) / divisor),
                (uint)(curr.cy + (((long)curr.cy - prev.cy)) / divisor),
                (uint)(curr.cz + (((long)curr.cz - prev.cz)) / divisor)
            ));
 }
        //public static CompressedElement operator +(CompressedElement a, CompressedElement b)
        //{
        //	return new CompressedElement(a.crusher, (uint)((long)a.cx + b.cx), (uint)((long)a.cy + b.cy), (uint)((long)a.cz + b.cz));
        //}
        //public static CompressedElement operator -(CompressedElement a, CompressedElement b)
        //{
        //	return new CompressedElement(a.crusher, (uint)((long)a.cx - b.cx), (uint)((long)a.cy - b.cy), (uint)((long)a.cz - b.cz));
        //}
        //public static CompressedElement operator *(CompressedElement a, float b)
        //{
        //	return new CompressedElement(a.crusher, (uint)(a.cx * b), (uint)(a.cy * b), (uint)(a.cz * b));
        //}

        ///<summary>
        /// It may preferable to use the overload that takes and int divisor value than a float, to avoid all float math to possibly reduce jitter.
        /// </summary>
        public static void Extrapolate(ElementCrusher crusher, CompressedElement target, CompressedElement curr, CompressedElement prev, int divisor = 2)
        {
            target.Set
            (
                crusher,
                (uint)(curr.cx + (((long)curr.cx - prev.cx)) / divisor),
                (uint)(curr.cy + (((long)curr.cy - prev.cy)) / divisor),
                (uint)(curr.cz + (((long)curr.cz - prev.cz)) / divisor)
            );
        }
        //public static CompressedElement GuessUpperBits(this CompressedElement newcpos, CompressedElement oldcpos, FloatCrusher[] ec, BitCullingLevel bcl)
        //{
        //	var crusher = oldcpos.crusher;
        //	return new CompressedElement(
        //		crusher,
        //		new CompressedValue(crusher.xcrusher, ec[0].GuessUpperBits(newcpos.cx, oldcpos.cx, bcl), crusher.xcrusher.GetBits(bcl)),
        //		new CompressedValue(crusher.ycrusher, ec[1].GuessUpperBits(newcpos.cx, oldcpos.cx, bcl), crusher.xcrusher.GetBits(bcl)),
        //		new CompressedValue(crusher.zcrusher, ec[2].GuessUpperBits(newcpos.cx, oldcpos.cx, bcl), crusher.xcrusher.GetBits(bcl))
        //		);
        //}

        /// <summary>
        /// Replace the upperbits of the first compressed element with the upper bits of the second, using BitCullingLevel as the separation point.
        /// </summary>
        public static void OverwriteUpperBits(this CompressedElement low, CompressedElement uppers, BitCullingLevel bcl)
        {
            ElementCrusher ec = low.crusher;

            low.Set(
                ec,
                ec.XCrusher.OverwriteUpperBits(low.cx, uppers.cx, bcl),
                ec.YCrusher.OverwriteUpperBits(low.cy, uppers.cy, bcl),
                ec.ZCrusher.OverwriteUpperBits(low.cz, uppers.cz, bcl)
                );
        }
        //public static CompressedElement ZeroLowerBits(this CompressedElement fullpos, FloatCrusher[] ec, BitCullingLevel bcl)
        //{
        //	return new CompressedElement(
        //		fullpos.crusher,
        //		ec[0].ZeroLowerBits(fullpos.cx, bcl),
        //		ec[1].ZeroLowerBits(fullpos.cy, bcl),
        //		ec[2].ZeroLowerBits(fullpos.cz, bcl)
        //		);
        //}
        public static void ZeroUpperBits(this CompressedElement fullpos, CompressedElement target, BitCullingLevel bcl)
        {
            ElementCrusher ec = fullpos.crusher;

            target.Set(
                ec,                 /*fullpos.crusher,*/
                ec.XCrusher.ZeroUpperBits(fullpos.cx, bcl),
                ec.YCrusher.ZeroUpperBits(fullpos.cy, bcl),
                ec.ZCrusher.ZeroUpperBits(fullpos.cz, bcl)
                );
        }
        public static bool TestMatchingUpper(CompressedElement a, CompressedElement b, BitCullingLevel bcl)
        {
            ElementCrusher ec = a.crusher;

            return
                (
                TestMatchingUpper(a.cx, b.cx, ec.XCrusher.GetBits(bcl)) &&
                TestMatchingUpper(a.cy, b.cy, ec.YCrusher.GetBits(bcl)) &&
                TestMatchingUpper(a.cz, b.cz, ec.ZCrusher.GetBits(bcl))
                );
        }
 public static CompressedElement Extrapolate(ElementCrusher crusher, CompressedElement curr, CompressedElement prev, float amount = .5f)
 {
     //int divisor = (int)(1f / amount);
     //return Extrapolate(curr, prev, divisor);
     return(new CompressedElement
            (
                crusher,
                (uint)(curr.cx + ((long)curr.cx - prev.cx) * amount),
                (uint)(curr.cy + ((long)curr.cy - prev.cy) * amount),
                (uint)(curr.cz + ((long)curr.cz - prev.cz) * amount)
            ));
 }
        static WorldVectorCompression()
        {
            Bounds bounds = NSTMapBounds.CombinedWorldBounds;

            axisRanges = new ElementCrusher(TRSType.Position, false)
            {
                xcrusher = new FloatCrusher(bounds.min[0], bounds.max[0], WorldCompressionSettings.Single.minPosResolution, Axis.X, TRSType.Position),
                ycrusher = new FloatCrusher(bounds.min[1], bounds.max[1], WorldCompressionSettings.Single.minPosResolution, Axis.Y, TRSType.Position),
                zcrusher = new FloatCrusher(bounds.min[2], bounds.max[2], WorldCompressionSettings.Single.minPosResolution, Axis.Z, TRSType.Position)
            };

            SetWorldRanges(bounds, true);
        }
示例#15
0
        public override void Initialize()
        {
            base.Initialize();

            if (worldBoundsGroups.Count == 0)
            {
                worldBoundsGroups.Add(new WorldBoundsGroup());
            }

            defaultWorldBoundsCrusher = worldBoundsGroups[0].crusher;

            foreach (var wbs in worldBoundsGroups)
            {
                wbs.RecalculateWorldCombinedBounds();
            }
        }
示例#16
0
        // Construct
        public Frame(NetworkSyncTransform nst, int frameid, Vector3 pos, CompressedElement compPos)         //, PositionElement[] positionElements, RotationElement[] rotationElements)
        {
            this.rootPosCrusher = WorldBoundsSO.single.worldBoundsGroups[0].crusher;
            this.nst            = nst;
            this.ee             = nst.nstElementsEngine;

            this.rootPos = pos;
            this.compPos.CopyFrom(compPos);
            this.state      = nst.State;
            this.frameid    = frameid;
            this.customData = new byte[128];              //TODO: Make this size a user setting

            this.checkSceneIndex  = HeaderSettings.Single.includeSceneIndex;
            this.sceneIndex       = NSTSceneManager.CurrentSceneIndex;
            this.rootBitCullLevel = BitCullingLevel.NoCulling;

            this.rootRotElementFrame = nst.rootRotationElement.frames[frameid];
        }
        /// <summary>
        /// Return the smallest bit culling level that will be able to communicate the changes between two compressed elements.
        /// </summary>
        public static BitCullingLevel FindBestBitCullLevel(CompressedElement a, CompressedElement b, BitCullingLevel maxCulling)
        {
            ElementCrusher ec = a.crusher;

            if (ec == null)
            {
                UnityEngine.Debug.Log("NUL CE CRUSHER FindBestBitCullLevel");
                return(BitCullingLevel.NoCulling);
            }

            /// Quats can't cull upper bits, so its an all or nothing. Either the bits match or they don't
            if (ec.TRSType == TRSType.Quaternion)
            {
                if ((ulong)a.cQuat == (ulong)b.cQuat)
                {
                    return(BitCullingLevel.DropAll);
                }
                else
                {
                    return(BitCullingLevel.NoCulling);
                }
            }

            if (maxCulling == BitCullingLevel.NoCulling || !TestMatchingUpper(a, b, BitCullingLevel.DropThird))
            {
                return(BitCullingLevel.NoCulling);
            }

            if (maxCulling == BitCullingLevel.DropThird || !TestMatchingUpper(a, b, BitCullingLevel.DropHalf))
            {
                return(BitCullingLevel.DropThird);
            }

            if (maxCulling == BitCullingLevel.DropHalf || !TestMatchingUpper(a, b, BitCullingLevel.DropAll))
            {
                return(BitCullingLevel.DropHalf);
            }

            // both values are the same
            return(BitCullingLevel.DropAll);
        }
 // Constructor for uniform scale
 /// <summary>
 /// A uint argument indicates compressed uniform scale. A ulong argument indicates a compressed quaternion.
 /// Be sure to cast ulongs down to uint, or your scale we be treated as quaternion values for this constructor.
 /// </summary>
 /// <param name="crusher"></param>
 /// <param name="cUniform"></param>
 /// <param name="ubits"></param>
 public CompressedElement(ElementCrusher crusher, uint cUniform)         /*: this()*/
 {
     UnityEngine.Debug.LogWarning("CE Construct");
     this.crusher  = crusher;
     this.cUniform = new CompressedFloat(crusher.UCrusher, cUniform);
 }
 // Constructor for Quaternion rotation
 /// <summary>
 /// A uint argument indicates compressed uniform scale. A ulong argument indicates a compressed quaternion.
 /// </summary>
 /// <param name="crusher"></param>
 /// <param name="cQuat"></param>
 /// <param name="qbits"></param>
 public CompressedElement(ElementCrusher crusher, ulong cQuat)        /* : this()*/
 {
     UnityEngine.Debug.LogWarning("CE Construct");
     this.crusher = crusher;
     this.cQuat   = new CompressedQuat(crusher.QCrusher, cQuat);
 }
 public void Set(ElementCrusher crusher, uint cUniform)         /*: this()*/
 {
     this.crusher  = crusher;
     this.cUniform = new CompressedFloat(crusher.UCrusher, cUniform);
 }
 public static CompressedElement ZeroLowerBits(this CompressedElement fullpos, ElementCrusher ec, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                ec,          //fullpos.crusher,
                ec[0].ZeroLowerBits(fullpos.cx, bcl),
                ec[1].ZeroLowerBits(fullpos.cy, bcl),
                ec[2].ZeroLowerBits(fullpos.cz, bcl)
                ));
 }
 public static CompressedElement OverwriteUpperBits(this CompressedElement low, CompressedElement up, ElementCrusher ec, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                ec,
                ec[0].OverwriteUpperBits(low.cx, up.cx, bcl),
                ec[1].OverwriteUpperBits(low.cy, up.cy, bcl),
                ec[2].OverwriteUpperBits(low.cz, up.cz, bcl)
                ));
 }
 public void Set(ElementCrusher crusher, ulong cQuat)        /* : this()*/
 {
     this.crusher = crusher;
     this.cQuat   = new CompressedQuat(crusher.QCrusher, cQuat);
 }
        public static BitCullingLevel GetGuessableBitCullLevel(CompressedElement oldComp, CompressedElement newComp, ElementCrusher ec, BitCullingLevel maxCullLvl)
        {
            for (BitCullingLevel lvl = maxCullLvl; lvl > 0; lvl--)
            {
                oldComp.ZeroLowerBits(uppers, lvl);
                newComp.ZeroUpperBits(lowers, lvl);

                if ((uppers.cx | lowers.cx) == newComp.cx &&
                    (uppers.cy | lowers.cy) == newComp.cy &&
                    (uppers.cz | lowers.cz) == newComp.cz)
                {
                    return(lvl);
                }
            }
            return(BitCullingLevel.NoCulling);
        }
 public static bool TestMatchingUpper(CompressedElement a, CompressedElement b, ElementCrusher ec, BitCullingLevel bcl)
 {
     return
         (
         TestMatchingUpper(a.cx, b.cx, ec[0].GetBits(bcl)) &&
         TestMatchingUpper(a.cy, b.cy, ec[1].GetBits(bcl)) &&
         TestMatchingUpper(a.cz, b.cz, ec[2].GetBits(bcl))
         );
 }