Rewind config - more cleanup - calculate maths correctly

This commit is contained in:
adelikat 2020-06-19 15:53:08 -05:00
parent 32b14641f1
commit 4978fe4b92
2 changed files with 19 additions and 69 deletions

View File

@ -44,8 +44,6 @@
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.EstTimeLabel = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.AverageStoredStateSizeLabel = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.ApproxFramesLabel = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.RewindFramesUsedLabel = new System.Windows.Forms.Label();
@ -135,7 +133,7 @@
this.UseCompression.TabIndex = 5;
this.UseCompression.Text = "Use compression (economizes buffer usage at cost of CPU)";
this.UseCompression.UseVisualStyleBackColor = true;
this.UseCompression.CheckedChanged += new System.EventHandler(this.UseDeltaCompression_CheckedChanged);
this.UseCompression.CheckedChanged += new System.EventHandler(this.UseCompression_CheckedChanged);
//
// label1
//
@ -144,7 +142,7 @@
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(81, 13);
this.label1.TabIndex = 5;
this.label1.Text = "Savestate Size:";
this.label1.Text = "Avg. State Size:";
//
// StateSizeLabel
//
@ -166,7 +164,7 @@
//
// BufferSizeUpDown
//
this.BufferSizeUpDown.Location = new System.Drawing.Point(93, 69);
this.BufferSizeUpDown.Location = new System.Drawing.Point(93, 67);
this.BufferSizeUpDown.Maximum = new decimal(new int[] {
2097512,
0,
@ -218,8 +216,6 @@
//
this.groupBox4.Controls.Add(this.EstTimeLabel);
this.groupBox4.Controls.Add(this.label11);
this.groupBox4.Controls.Add(this.AverageStoredStateSizeLabel);
this.groupBox4.Controls.Add(this.label9);
this.groupBox4.Controls.Add(this.ApproxFramesLabel);
this.groupBox4.Controls.Add(this.label8);
this.groupBox4.Controls.Add(this.RewindFramesUsedLabel);
@ -238,7 +234,7 @@
// EstTimeLabel
//
this.EstTimeLabel.AutoSize = true;
this.EstTimeLabel.Location = new System.Drawing.Point(273, 48);
this.EstTimeLabel.Location = new System.Drawing.Point(273, 32);
this.EstTimeLabel.Name = "EstTimeLabel";
this.EstTimeLabel.Size = new System.Drawing.Size(32, 13);
this.EstTimeLabel.TabIndex = 19;
@ -247,34 +243,16 @@
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(221, 48);
this.label11.Location = new System.Drawing.Point(221, 32);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(54, 13);
this.label11.TabIndex = 18;
this.label11.Text = "Est. Time:";
//
// AverageStoredStateSizeLabel
//
this.AverageStoredStateSizeLabel.AutoSize = true;
this.AverageStoredStateSizeLabel.Location = new System.Drawing.Point(273, 16);
this.AverageStoredStateSizeLabel.Name = "AverageStoredStateSizeLabel";
this.AverageStoredStateSizeLabel.Size = new System.Drawing.Size(41, 13);
this.AverageStoredStateSizeLabel.TabIndex = 17;
this.AverageStoredStateSizeLabel.Text = "0 bytes";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(161, 16);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(114, 13);
this.label9.TabIndex = 16;
this.label9.Text = "Avg Stored State Size:";
//
// ApproxFramesLabel
//
this.ApproxFramesLabel.AutoSize = true;
this.ApproxFramesLabel.Location = new System.Drawing.Point(273, 32);
this.ApproxFramesLabel.Location = new System.Drawing.Point(273, 17);
this.ApproxFramesLabel.Name = "ApproxFramesLabel";
this.ApproxFramesLabel.Size = new System.Drawing.Size(47, 13);
this.ApproxFramesLabel.TabIndex = 15;
@ -283,7 +261,7 @@
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(209, 32);
this.label8.Location = new System.Drawing.Point(209, 17);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(66, 13);
this.label8.TabIndex = 14;
@ -575,8 +553,6 @@
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label ApproxFramesLabel;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label AverageStoredStateSizeLabel;
private System.Windows.Forms.Label EstTimeLabel;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.GroupBox groupBox6;

View File

@ -1,6 +1,5 @@
using System;
using System.Windows.Forms;
using System.Drawing;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
@ -13,7 +12,7 @@ namespace BizHawk.Client.EmuHawk
private readonly Config _config;
private readonly IStatable _statableCore;
private long _stateSize;
private double _avgStateSize;
public RewindConfig(MainForm mainForm, Config config, IStatable statableCore)
{
@ -29,21 +28,22 @@ namespace BizHawk.Client.EmuHawk
{
FullnessLabel.Text = $"{_mainForm.Rewinder.FullnessRatio * 100:0.00}%";
RewindFramesUsedLabel.Text = _mainForm.Rewinder.Count.ToString();
_avgStateSize = _mainForm.Rewinder.Size * _mainForm.Rewinder.FullnessRatio / _mainForm.Rewinder.Count;
}
else
{
FullnessLabel.Text = "N/A";
RewindFramesUsedLabel.Text = "N/A";
_avgStateSize = _statableCore.CloneSavestate().Length;
}
_stateSize = _statableCore.CloneSavestate().Length;
RewindEnabledBox.Checked = _config.Rewind.Enabled;
UseCompression.Checked = _config.Rewind.UseCompression;
BufferSizeUpDown.Value = Math.Max(_config.Rewind.BufferSize, BufferSizeUpDown.Minimum);
UseCompression.Checked = _config.Rewind.UseCompression;
RewindEnabledBox.Checked = _config.Rewind.Enabled;
SetStateSize();
StateSizeLabel.Text = FormatKB(_avgStateSize);
CalculateEstimates();
nudCompression.Value = _config.Savestates.CompressionLevelNormal;
@ -66,7 +66,7 @@ namespace BizHawk.Client.EmuHawk
ScreenshotInStatesCheckbox.Checked;
}
private string FormatKB(long n)
private string FormatKB(double n)
{
double num = n / 1024.0;
@ -79,12 +79,6 @@ namespace BizHawk.Client.EmuHawk
return $"{num:0.00} KB";
}
private void SetStateSize()
{
StateSizeLabel.Text = FormatKB(_stateSize);
CalculateEstimates();
}
private void Cancel_Click(object sender, EventArgs e)
{
Close();
@ -130,33 +124,13 @@ namespace BizHawk.Client.EmuHawk
private void CalculateEstimates()
{
long avgStateSize;
if (UseCompression.Checked || _stateSize == 0)
{
if (_mainForm.Rewinder?.Count > 0)
{
avgStateSize = _mainForm.Rewinder.Size / _mainForm.Rewinder.Count;
}
else
{
avgStateSize = _stateSize;
}
}
else
{
avgStateSize = _stateSize;
}
var bufferSize = (long)BufferSizeUpDown.Value;
bufferSize *= 1024 * 1024;
var estFrames = bufferSize / avgStateSize;
var estFrames = bufferSize / _avgStateSize;
long estFrequency = 0; // TODO
long estTotalFrames = estFrames * estFrequency;
double estTotalFrames = estFrames;
double minutes = estTotalFrames / 60 / 60;
AverageStoredStateSizeLabel.Text = FormatKB(avgStateSize);
ApproxFramesLabel.Text = $"{estFrames:n0} frames";
EstTimeLabel.Text = $"{minutes:n} minutes";
}
@ -166,7 +140,7 @@ namespace BizHawk.Client.EmuHawk
CalculateEstimates();
}
private void UseDeltaCompression_CheckedChanged(object sender, EventArgs e)
private void UseCompression_CheckedChanged(object sender, EventArgs e)
{
CalculateEstimates();
}