Beispiel #1
0
        public void Attach(IEmulator emulator)
        {
            if (!_emulator.IsNull())
            {
                throw new InvalidOperationException("A core has already been attached!");
            }

            if (!emulator.HasSavestates())
            {
                throw new InvalidOperationException($"A core must be able to provide an {nameof(IStatable)} service");
            }

            _emulator = emulator;
            _core     = emulator.AsStatable();

            _decay = new StateManagerDecay(_movie, this);

            _expectedStateSizeInMb = _core.CloneSavestate().Length / (double)(1024 * 1024);
            if (_expectedStateSizeInMb.HawkFloatEquality(0))
            {
                throw new InvalidOperationException("Savestate size can not be zero!");
            }

            // don't erase states if they exist already (already loaded)
            if ((_states == null) || (_states.Capacity == 0))
            {
                _states = new SortedList <int, byte[]>(MaxStates);
            }

            UpdateStateFrequency();
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        public void Attach(IEmulator emulator)
        {
            // TODO: we aren't ready for this, attach is called when converting a bk2 to tasproj and again to officially load the emulator
            //if (!_emulator.IsNull())
            //{
            //	throw new InvalidOperationException("A core has already been attached!");
            //}

            if (!emulator.HasSavestates())
            {
                throw new InvalidOperationException($"A core must be able to provide an {nameof(IStatable)} service");
            }

            _emulator = emulator;
            _core     = emulator.AsStatable();

            _decay = new StateManagerDecay(_movie, this);

            _expectedStateSizeInMb = _core.CloneSavestate().Length / (double)(1024 * 1024);
            if (_expectedStateSizeInMb.HawkFloatEquality(0))
            {
                throw new InvalidOperationException("Savestate size can not be zero!");
            }

            _states = new SortedList <int, byte[]>(MaxStates);

            UpdateStateFrequency();
        }
Beispiel #4
0
        private void RewindConfig_Load(object sender, EventArgs e)
        {
            if (_rewinder.HasBuffer)
            {
                FullnessLabel.Text         = $"{_rewinder.FullnessRatio * 100:0.00}%";
                RewindFramesUsedLabel.Text = _rewinder.Count.ToString();
            }
            else
            {
                FullnessLabel.Text         = "N/A";
                RewindFramesUsedLabel.Text = "N/A";
            }

            RewindSpeedNumeric.Value         = _config.Rewind.SpeedMultiplier;
            DiskBufferCheckbox.Checked       = _config.Rewind.OnDisk;
            RewindIsThreadedCheckbox.Checked = _config.Rewind.IsThreaded;
            _stateSize             = _statableCore.CloneSavestate().Length;
            BufferSizeUpDown.Value = Math.Max(_config.Rewind.BufferSize, BufferSizeUpDown.Minimum);

            _mediumStateSize = _config.Rewind.MediumStateSize;
            _largeStateSize  = _config.Rewind.LargeStateSize;

            UseDeltaCompression.Checked = _config.Rewind.UseDelta;

            SmallSavestateNumeric.Value  = _config.Rewind.FrequencySmall;
            MediumSavestateNumeric.Value = _config.Rewind.FrequencyMedium;
            LargeSavestateNumeric.Value  = _config.Rewind.FrequencyLarge;

            SmallStateEnabledBox.Checked  = _config.Rewind.EnabledSmall;
            MediumStateEnabledBox.Checked = _config.Rewind.EnabledMedium;
            LargeStateEnabledBox.Checked  = _config.Rewind.EnabledLarge;

            SetSmallEnabled();
            SetMediumEnabled();
            SetLargeEnabled();

            SetStateSize();

            var mediumStateSizeKb = _config.Rewind.MediumStateSize / 1024;
            var largeStateSizeKb  = _config.Rewind.LargeStateSize / 1024;

            MediumStateTrackbar.Value = mediumStateSizeKb;
            MediumStateUpDown.Value   = mediumStateSizeKb;
            LargeStateTrackbar.Value  = largeStateSizeKb;
            LargeStateUpDown.Value    = largeStateSizeKb;

            nudCompression.Value = _config.Savestates.CompressionLevelNormal;

            rbStatesBinary.Checked = _config.Savestates.Type == SaveStateType.Binary;
            rbStatesText.Checked   = _config.Savestates.Type == SaveStateType.Text;

            BackupSavestatesCheckbox.Checked       = _config.Savestates.MakeBackups;
            ScreenshotInStatesCheckbox.Checked     = _config.Savestates.SaveScreenshot;
            LowResLargeScreenshotsCheckbox.Checked = !_config.Savestates.NoLowResLargeScreenshots;
            BigScreenshotNumeric.Value             = _config.Savestates.BigScreenshotSize / 1024;

            ScreenshotInStatesCheckbox_CheckedChanged(null, null);
        }
Beispiel #5
0
        public static void SaveStateText(this IStatable core, TextWriter writer)
        {
            if (core is ITextStatable textCore)
            {
                textCore.SaveStateText(writer);
            }

            var temp = core.CloneSavestate();

            temp.SaveAsHexFast(writer);
        }
        private void RewindConfig_Load(object sender, EventArgs e)
        {
            //TODO can this be moved to the ctor post-InitializeComponent?
            var rewinder = _getRewinder();

            if (rewinder?.Active == true)
            {
                FullnessLabel.Text         = $"{rewinder.FullnessRatio * 100:0.00}%";
                RewindFramesUsedLabel.Text = rewinder.Count.ToString();
                _avgStateSize = rewinder.Size * rewinder.FullnessRatio / rewinder.Count;
            }
            else
            {
                FullnessLabel.Text         = "N/A";
                RewindFramesUsedLabel.Text = "N/A";
                _avgStateSize = _statableCore.CloneSavestate().Length;
            }

            RewindEnabledBox.Checked                = _config.Rewind.Enabled;
            UseCompression.Checked                  = _config.Rewind.UseCompression;
            cbDeltaCompression.Checked              = _config.Rewind.UseDelta;
            BufferSizeUpDown.Value                  = Math.Max((decimal)Math.Log(_config.Rewind.BufferSize, 2), BufferSizeUpDown.Minimum);
            TargetFrameLengthRadioButton.Checked    = !_config.Rewind.UseFixedRewindInterval;
            TargetRewindIntervalRadioButton.Checked = _config.Rewind.UseFixedRewindInterval;
            TargetFrameLengthNumeric.Value          = Math.Max(_config.Rewind.TargetFrameLength, TargetFrameLengthNumeric.Minimum);
            TargetRewindIntervalNumeric.Value       = Math.Max(_config.Rewind.TargetRewindInterval, TargetRewindIntervalNumeric.Minimum);
            StateSizeLabel.Text = FormatKB(_avgStateSize);
            CalculateEstimates();

            nudCompression.Value = _config.Savestates.CompressionLevelNormal;

            rbStatesBinary.Checked = _config.Savestates.Type == SaveStateType.Binary;
            rbStatesText.Checked   = _config.Savestates.Type == SaveStateType.Text;

            BackupSavestatesCheckbox.Checked       = _config.Savestates.MakeBackups;
            ScreenshotInStatesCheckbox.Checked     = _config.Savestates.SaveScreenshot;
            LowResLargeScreenshotsCheckbox.Checked = !_config.Savestates.NoLowResLargeScreenshots;
            BigScreenshotNumeric.Value             = _config.Savestates.BigScreenshotSize / 1024;

            ScreenshotInStatesCheckbox_CheckedChanged(null, null);
        }