Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="frameId"></param>
        /// <param name="prevFrameId"></param>
        /// <param name="snapshot"></param>
        /// <returns></returns>
        public byte[] Decompress(uint prevFrameId, byte[] snapshot)
        {
                        #if DONT_USE_DELTA
            return(NetworkEngine.Decompress(snapshot));
                        #endif


            if (prevFrameId == 0)
            {
                return(NetDeflate.Decompress(snapshot));
            }

            var prevSnapshot = queue.SingleOrDefault(s => s.Frame == prevFrameId);

            if (prevSnapshot == null)
            {
                Log.Warning("Missing snapshot #{0}. Waiting for full snapshot.", prevFrameId);
                return(null);
            }


            var delta   = NetDeflate.Decompress(snapshot);
            var minSize = Math.Min(delta.Length, prevSnapshot.Data.Length);

            var newSnapshot = new byte[delta.Length];

            for (int i = 0; i < minSize; i++)
            {
                newSnapshot[i] = (byte)(delta[i] ^ prevSnapshot.Data[i]);
            }

            if (delta.Length > prevSnapshot.Data.Length)
            {
                for (int i = minSize; i < delta.Length; i++)
                {
                    newSnapshot[i] = delta[i];
                }
            }

            return(newSnapshot);
        }