using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PropagationRemasteredBeta { public partial class Form1 : Form { Terrain t; Bitmap BufferImage; int frameCount; bool started = false; Stopwatch stopwatch; double totalTime; public Form1() { InitializeComponent(); t = new Terrain(); frameCount = 0; BufferImage = new Bitmap(t.TerrainSize.Width, t.TerrainSize.Height); stopwatch = new Stopwatch(); totalTime = 0; } private void button1_Click(object sender, EventArgs e) { btnStartOneForAll.Enabled = false; StartStop(1); } private void StartStop(int mode) { if (started) { started = false; btnStartNormal.Text = "Start classic"; btnStartOneForAll.Text = "Start one for all"; btnStartOneForAll.Enabled = true; btnStartNormal.Enabled = true; tmrTick.Stop(); } else { started = true; btnStartNormal.Text = "Stop"; btnStartOneForAll.Text = "Stop"; tmrTick.Start(); t = new Terrain(); frameCount = 0; switch (mode) { case 1: t.Generate(); break; case 2: t.GenerateOneForAll(); break; } } } private void Form1_Paint(object sender, PaintEventArgs e) { if (started) { BufferImage = t.Display(); pbxTerrain.Image = BufferImage; stopwatch.Stop(); totalTime = stopwatch.ElapsedMilliseconds; frameCount++; lblFrameCount.Text = frameCount.ToString(); lblTotalTime.Text = totalTime.ToString(); } } private void tmrTick_Tick(object sender, EventArgs e) { //t.Refresh(); stopwatch.Start(); int infecteds; if (t.InfectedCount.Count > 0) { infecteds = t.InfectedCount[t.InfectedCount.Count() - 1]; } else { infecteds = 1; } if (infecteds > 0) { t.Refresh(); } else { StartStop(1); } this.Invalidate(); //refresh all the stats lblMemory.Text = GetMemoryUsage().ToString() + " Mb"; lblelementsCounter.Text = t.DRAWED_ELEMENTS.ToString(); lblInfected.Text = t.InfectedCount[t.InfectedCount.Count() - 1].ToString(); lblImmunes.Text = t.ImmuneCount[t.ImmuneCount.Count() - 1].ToString(); lblSain.Text = t.SainCount[t.SainCount.Count() - 1].ToString(); lblDeaths.Text = t.DeadCount[t.DeadCount.Count() - 1].ToString(); } private double GetMemoryUsage() { var memory = 0.0; using (Process proc = Process.GetCurrentProcess()) { // The proc.PrivateMemorySize64 will returns the private memory usage in byte. // Would like to Convert it to Megabyte? divide it by 2^20 memory = proc.PrivateMemorySize64 / (1024 * 1024); } return memory; } private void btnStartOneForAll_Click(object sender, EventArgs e) { btnStartNormal.Enabled = false; StartStop(2); } } }