Esempio n. 1
0
        public void Initialize(IStatable statableCore, RewindConfig rewindConfig)
        {
            Uninitialize();

            _statableCore = statableCore;

            int stateSize = _statableCore.CloneSavestate().Length;

            if (stateSize >= rewindConfig.LargeStateSize)
            {
                RewindEnabled   = rewindConfig.EnabledLarge;
                RewindFrequency = rewindConfig.FrequencyLarge;
            }
            else if (stateSize >= rewindConfig.MediumStateSize)
            {
                RewindEnabled   = rewindConfig.EnabledMedium;
                RewindFrequency = rewindConfig.FrequencyMedium;
            }
            else
            {
                RewindEnabled   = rewindConfig.EnabledSmall;
                RewindFrequency = rewindConfig.FrequencySmall;
            }

            _rewindDeltaEnable = rewindConfig.UseDelta;

            if (RewindActive)
            {
                var capacity = rewindConfig.BufferSize * 1024L * 1024L;
                _rewindBuffer = new StreamBlobDatabase(rewindConfig.OnDisk, capacity, BufferManage);
                _rewindThread = new RewindThreader(CaptureInternal, RewindInternal, rewindConfig.IsThreaded);
            }
        }
Esempio n. 2
0
        public bool MatchesSettings(RewindConfig settings)
        {
            long targetSize = settings.BufferSize * 1024 * 1024;
            long size       = 1L << (int)Math.Floor(Math.Log(targetSize, 2));

            return(Size == size &&
                   _useCompression == settings.UseCompression &&
                   _targetFrameLength == settings.TargetFrameLength);
        }
Esempio n. 3
0
        public bool MatchesSettings(RewindConfig settings)
        {
            long targetSize = settings.BufferSize * 1024 * 1024;
            long size       = 1L << (int)Math.Floor(Math.Log(targetSize, 2));

            return(Size == size &&
                   _useCompression == settings.UseCompression &&
                   _fixedRewindInterval == settings.UseFixedRewindInterval &&
                   (_fixedRewindInterval ? _targetRewindInterval == settings.TargetRewindInterval : _targetFrameLength == settings.TargetFrameLength) &&
                   _backingStoreType == settings.BackingStore);
        }
Esempio n. 4
0
        public static ZwinderBuffer Create(BinaryReader reader, RewindConfig rewindConfig, bool hackyV0 = false)
        {
            ZwinderBuffer ret;

            // Initial format had no version number, but I think it's a safe bet no valid file has buffer size 2^56 or more so this should work.
            int version = hackyV0 ? 0 : reader.ReadByte();

            if (version == 0)
            {
                byte[] sizeArr = new byte[8];
                reader.Read(sizeArr, 1, 7);
                var size              = BitConverter.ToInt64(sizeArr, 0);
                var sizeMask          = reader.ReadInt64();
                var targetFrameLength = reader.ReadInt32();
                var useCompression    = reader.ReadBoolean();
                ret = new ZwinderBuffer(new RewindConfig
                {
                    BufferSize             = (int)(size >> 20),
                    UseFixedRewindInterval = false,
                    TargetFrameLength      = targetFrameLength,
                    TargetRewindInterval   = 5,
                    AllowOutOfOrderStates  = false,
                    UseCompression         = useCompression
                });
                if (ret.Size != size || ret._sizeMask != sizeMask)
                {
                    throw new InvalidOperationException("Bad format");
                }
            }
            else if (version == 1)
            {
                ret = new ZwinderBuffer(rewindConfig);
            }
            else
            {
                throw new InvalidOperationException("Bad format");
            }

            ret.LoadStateBodyBinary(reader);
            return(ret);
        }
 private ZwinderBuffer UpdateBuffer(ZwinderBuffer buffer, RewindConfig newConfig, bool keepOldStates)
 {
     if (buffer == null)             // just make a new one, plain and simple
     {
         buffer = new ZwinderBuffer(newConfig);
     }
     else if (!buffer.MatchesSettings(newConfig))             // no need to do anything if these settings are already in use
     {
         if (keepOldStates)
         {
             // force capture all the old states, let the buffer handle decay if they don't all fit
             ZwinderBuffer old = buffer;
             buffer = new ZwinderBuffer(newConfig);
             for (int i = 0; i < old.Count; i++)
             {
                 ZwinderBuffer.StateInformation si = old.GetState(i);
                 // don't allow states that should be reserved to decay here, where we don't attempt re-capture
                 if (_reserveCallback(si.Frame))
                 {
                     AddToReserved(si);
                 }
                 else
                 {
                     buffer.Capture(si.Frame, s => si.GetReadStream().CopyTo(s), null, true);
                 }
             }
             old.Dispose();
         }
         else
         {
             buffer.Dispose();
             buffer = new ZwinderBuffer(newConfig);
         }
     }
     return(buffer);
 }