Skip to content

Commit

Permalink
Simplified randomizer logic and code
Browse files Browse the repository at this point in the history
  • Loading branch information
dardonkov committed Mar 8, 2021
1 parent bef59f6 commit 7fee65a
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 33 deletions.
Binary file modified .vs/RandomSens/v16/.suo
Binary file not shown.
9 changes: 4 additions & 5 deletions Classes/SensRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace RandomSens.Classes
{
class SensRandomizer
{
public bool isPaused { get; set; }
public bool isStopped { get; set; }
public bool isPaused { get; set; } = false;
internal SensitivityCurve sensitivityCurve { get; private set; }
internal double currentSens { get; private set; }
internal double curveCompletion { get; private set; }
Expand Down Expand Up @@ -39,7 +38,7 @@ public void Start()
{
//sw += 20; // Every cycle takes roughly 20ms so we add 20ms
stopwatch.Start();
if (sensitivityCurve.isFinished || isStopped)
if (sensitivityCurve.isFinished)
{
break;
}
Expand Down Expand Up @@ -82,9 +81,9 @@ internal void Pause()
{
isPaused = true;
}
internal void Stop()
internal void Resume()
{
isStopped=true;
isPaused = false;
}
}
}
8 changes: 4 additions & 4 deletions Form1.Designer.cs → MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 22 additions & 18 deletions Form1.cs → MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using RandomSens.Classes;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Forms;
using RandomSens.Classes;

namespace RandomSens
{
public partial class Form1 : Form
public partial class MainForm : Form
{
internal SensitivityCurve currentSensCurve;
internal SensRandomizer SensRandomizer;
Expand All @@ -25,7 +25,7 @@ public partial class Form1 : Form
internal bool isPaused = true;
internal bool isMinimized = false;

public Form1()
public MainForm()
{
InitializeComponent();
}
Expand Down Expand Up @@ -75,18 +75,18 @@ private void box_Pause_Toggle_KeyDown(object sender, KeyEventArgs e)
box_Pause_Toggle.ReadOnly = true;
this.ActiveControl = null;
}
private void Form1_Load(object sender, EventArgs e)
private void MainForm_Load(object sender, EventArgs e)
{
Load_Default_Settings();
Start_Pause_Listener(); //Start listening for the start/stop hotkey
Create_Curve();
SensRandomizer = new SensRandomizer(currentSensCurve);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{

}
private void Form1_Resize(object sender, EventArgs e)
private void MainForm_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Expand Down Expand Up @@ -307,22 +307,26 @@ private void StartRandomizer()
btn_Regen_Curve.Enabled = false;
btn_Start.Enabled = false;
btn_Pause.Enabled = true;
Update_UI(200);
SensRandomizer.Stop();
SensRandomizer = new SensRandomizer(currentSensCurve);
Task.Run(() =>
Update_UI(200);//Start updating the UI and the graph every 200ms
if (SensRandomizer.isPaused) //If the randomizer is paused - then resume
{
SensRandomizer.Start();
});
SensRandomizer.Resume();
}
else //If its not paused then start it up
{
Task.Run(() =>
{
SensRandomizer.Start();
});
}
}
private void StopRandomizer()
private void PauseRandomizer()
{
isPaused = true;
btn_Regen_Curve.Enabled = true;
btn_Start.Enabled = true;
btn_Pause.Enabled = false;

SensRandomizer.Pause();
SensRandomizer.Pause();
}
private void ToggleRandomizer()
{
Expand All @@ -332,7 +336,7 @@ private void ToggleRandomizer()
}
else
{
StopRandomizer();
PauseRandomizer();
}
this.ActiveControl = null;
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new MainForm());
}
}
}
10 changes: 5 additions & 5 deletions Random-sens.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@
<Compile Include="Classes\LogNormalCurve.cs" />
<Compile Include="Classes\ToggleListener.cs" />
<Compile Include="Classes\SensRandomizer.cs" />
<Compile Include="Form1.cs">
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="interception.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Classes\SensitivityCurve.cs" />
<Compile Include="Classes\SensitivityPoint.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
Binary file modified bin/x64/Release/RandomSens.exe
Binary file not shown.
Binary file modified bin/x64/Release/RandomSens.pdb
Binary file not shown.
Binary file modified obj/x64/Release/Random-sens.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified obj/x64/Release/RandomSens.exe
Binary file not shown.
Binary file modified obj/x64/Release/RandomSens.pdb
Binary file not shown.
Binary file modified obj/x64/Release/TempPE/Properties.Resources.Designer.cs.dll
Binary file not shown.

0 comments on commit 7fee65a

Please sign in to comment.