Example #1
0
        public bool AddItem(BaseSnapshotItem obj, int id)
        {
            if (obj == null)
            {
                Debug.Warning("snapshots", "add null object");
                return(false);
            }

            if (SnapshotItems.Count + 1 >= MaxItems)
            {
                Debug.Warning("snapshots", "too many items");
                return(false);
            }

            var itemSize = SnapshotItemsInfo.GetSize(obj.GetType());

            if (SnapshotSize + itemSize >= Snapshot.MaxSize)
            {
                Debug.Warning("snapshots", "too much data");
                return(false);
            }

            var item = new SnapshotItem(id, obj);

            SnapshotSize += itemSize;
            SnapshotItems.Add(item);
            return(true);
        }
Example #2
0
        // TODO
        //private static void UndiffItem(BaseSnapshotItem past, int[] inputData,
        //    int inputOffset, BaseSnapshotItem newItem)
        //{
        //    var pastData = past.ToArray();
        //    var newData = new int[pastData.Length];

        //    for (int i = 0; i < pastData.Length; i++)
        //    {
        //        newData[i] = pastData[i] + inputData[inputOffset + i];
        //    }

        //    newItem.Deserialize(newData, 0);
        //}

        private static int DiffItem(BaseSnapshotItem past, BaseSnapshotItem current,
                                    int[] outputData, int outputOffset)
        {
            var needed      = 0;
            var pastData    = past.ToArray();
            var currentdata = current.ToArray();

            for (int i = 0; i < pastData.Length; i++)
            {
                var @out = currentdata[i] - pastData[i];
                needed |= @out;
                outputData[outputOffset++] = @out;
            }

            return(needed);
        }