From b453978afc994eec4cd328f7b9348a1e263e097f Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Mon, 19 Jun 2017 17:03:51 +1000 Subject: MindBlow tweaks * MindBlow now lets you reset memory before you start a new program, and kill one that is still executing * The MindBlow site now uses the correct button theme --- ShiftOS.WinForms/Applications/MindBlow.Designer.cs | 157 ++++++++++++--------- ShiftOS.WinForms/Applications/MindBlow.cs | 40 +++++- 2 files changed, 125 insertions(+), 72 deletions(-) (limited to 'ShiftOS.WinForms/Applications') diff --git a/ShiftOS.WinForms/Applications/MindBlow.Designer.cs b/ShiftOS.WinForms/Applications/MindBlow.Designer.cs index da269f6..ad2304d 100644 --- a/ShiftOS.WinForms/Applications/MindBlow.Designer.cs +++ b/ShiftOS.WinForms/Applications/MindBlow.Designer.cs @@ -30,16 +30,18 @@ { this.tabs = new System.Windows.Forms.TabControl(); this.console = new System.Windows.Forms.TabPage(); - this.program = new System.Windows.Forms.TabPage(); - this.monitor = new System.Windows.Forms.TabPage(); this.consoleout = new System.Windows.Forms.TextBox(); - this.programinput = new System.Windows.Forms.TextBox(); - this.load = new System.Windows.Forms.Button(); + this.program = new System.Windows.Forms.TabPage(); + this.run = new System.Windows.Forms.Button(); this.save = new System.Windows.Forms.Button(); - this.memptr = new System.Windows.Forms.Label(); - this.instptr = new System.Windows.Forms.Label(); + this.load = new System.Windows.Forms.Button(); + this.programinput = new System.Windows.Forms.TextBox(); + this.monitor = new System.Windows.Forms.TabPage(); this.memlist = new System.Windows.Forms.ListBox(); - this.run = new System.Windows.Forms.Button(); + this.instptr = new System.Windows.Forms.Label(); + this.memptr = new System.Windows.Forms.Label(); + this.stop = new System.Windows.Forms.Button(); + this.reset = new System.Windows.Forms.Button(); this.tabs.SuspendLayout(); this.console.SuspendLayout(); this.program.SuspendLayout(); @@ -70,8 +72,19 @@ this.console.Text = "Console"; this.console.UseVisualStyleBackColor = true; // + // consoleout + // + this.consoleout.Dock = System.Windows.Forms.DockStyle.Fill; + this.consoleout.Location = new System.Drawing.Point(3, 3); + this.consoleout.Multiline = true; + this.consoleout.Name = "consoleout"; + this.consoleout.ReadOnly = true; + this.consoleout.Size = new System.Drawing.Size(378, 237); + this.consoleout.TabIndex = 0; + // // program // + this.program.Controls.Add(this.stop); this.program.Controls.Add(this.run); this.program.Controls.Add(this.save); this.program.Controls.Add(this.load); @@ -84,64 +97,66 @@ this.program.Text = "Program"; this.program.UseVisualStyleBackColor = true; // - // monitor - // - this.monitor.Controls.Add(this.memlist); - this.monitor.Controls.Add(this.instptr); - this.monitor.Controls.Add(this.memptr); - this.monitor.Location = new System.Drawing.Point(4, 22); - this.monitor.Name = "monitor"; - this.monitor.Size = new System.Drawing.Size(384, 243); - this.monitor.TabIndex = 2; - this.monitor.Text = "Monitor"; - this.monitor.UseVisualStyleBackColor = true; - // - // consoleout + // run // - this.consoleout.Dock = System.Windows.Forms.DockStyle.Fill; - this.consoleout.Location = new System.Drawing.Point(3, 3); - this.consoleout.Multiline = true; - this.consoleout.Name = "consoleout"; - this.consoleout.ReadOnly = true; - this.consoleout.Size = new System.Drawing.Size(378, 237); - this.consoleout.TabIndex = 0; + this.run.Location = new System.Drawing.Point(196, 217); + this.run.Name = "run"; + this.run.Size = new System.Drawing.Size(101, 23); + this.run.TabIndex = 3; + this.run.Text = "Run"; + this.run.UseVisualStyleBackColor = true; + this.run.Click += new System.EventHandler(this.run_Click); // - // programinput + // save // - this.programinput.Location = new System.Drawing.Point(3, 0); - this.programinput.Multiline = true; - this.programinput.Name = "programinput"; - this.programinput.Size = new System.Drawing.Size(378, 218); - this.programinput.TabIndex = 0; + this.save.Location = new System.Drawing.Point(102, 217); + this.save.Name = "save"; + this.save.Size = new System.Drawing.Size(88, 23); + this.save.TabIndex = 2; + this.save.Text = "Save"; + this.save.UseVisualStyleBackColor = true; + this.save.Click += new System.EventHandler(this.save_Click); // // load // this.load.Location = new System.Drawing.Point(6, 217); this.load.Name = "load"; - this.load.Size = new System.Drawing.Size(115, 23); + this.load.Size = new System.Drawing.Size(90, 23); this.load.TabIndex = 1; this.load.Text = "Load"; this.load.UseVisualStyleBackColor = true; this.load.Click += new System.EventHandler(this.load_Click); // - // save + // programinput // - this.save.Location = new System.Drawing.Point(127, 217); - this.save.Name = "save"; - this.save.Size = new System.Drawing.Size(114, 23); - this.save.TabIndex = 2; - this.save.Text = "Save"; - this.save.UseVisualStyleBackColor = true; - this.save.Click += new System.EventHandler(this.save_Click); + this.programinput.Location = new System.Drawing.Point(3, 0); + this.programinput.Multiline = true; + this.programinput.Name = "programinput"; + this.programinput.Size = new System.Drawing.Size(378, 218); + this.programinput.TabIndex = 0; // - // memptr + // monitor // - this.memptr.AutoSize = true; - this.memptr.Location = new System.Drawing.Point(8, 8); - this.memptr.Name = "memptr"; - this.memptr.Size = new System.Drawing.Size(56, 13); - this.memptr.TabIndex = 0; - this.memptr.Text = "Memory: 0"; + this.monitor.Controls.Add(this.reset); + this.monitor.Controls.Add(this.memlist); + this.monitor.Controls.Add(this.instptr); + this.monitor.Controls.Add(this.memptr); + this.monitor.Location = new System.Drawing.Point(4, 22); + this.monitor.Name = "monitor"; + this.monitor.Size = new System.Drawing.Size(384, 243); + this.monitor.TabIndex = 2; + this.monitor.Text = "Monitor"; + this.monitor.UseVisualStyleBackColor = true; + // + // memlist + // + this.memlist.FormattingEnabled = true; + this.memlist.Location = new System.Drawing.Point(11, 37); + this.memlist.Name = "memlist"; + this.memlist.ScrollAlwaysVisible = true; + this.memlist.SelectionMode = System.Windows.Forms.SelectionMode.None; + this.memlist.Size = new System.Drawing.Size(370, 199); + this.memlist.TabIndex = 2; // // instptr // @@ -152,25 +167,35 @@ this.instptr.TabIndex = 1; this.instptr.Text = "Instruction: 0"; // - // memlist + // memptr // - this.memlist.FormattingEnabled = true; - this.memlist.Location = new System.Drawing.Point(11, 37); - this.memlist.Name = "memlist"; - this.memlist.ScrollAlwaysVisible = true; - this.memlist.SelectionMode = System.Windows.Forms.SelectionMode.None; - this.memlist.Size = new System.Drawing.Size(370, 199); - this.memlist.TabIndex = 2; + this.memptr.AutoSize = true; + this.memptr.Location = new System.Drawing.Point(8, 8); + this.memptr.Name = "memptr"; + this.memptr.Size = new System.Drawing.Size(56, 13); + this.memptr.TabIndex = 0; + this.memptr.Text = "Memory: 0"; // - // run + // stop // - this.run.Location = new System.Drawing.Point(247, 217); - this.run.Name = "run"; - this.run.Size = new System.Drawing.Size(131, 23); - this.run.TabIndex = 3; - this.run.Text = "Run"; - this.run.UseVisualStyleBackColor = true; - this.run.Click += new System.EventHandler(this.run_Click); + this.stop.Location = new System.Drawing.Point(303, 217); + this.stop.Name = "stop"; + this.stop.Size = new System.Drawing.Size(75, 23); + this.stop.TabIndex = 4; + this.stop.Text = "Stop"; + this.stop.UseVisualStyleBackColor = true; + this.stop.Click += new System.EventHandler(this.stop_Click); + // + // reset + // + this.reset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.reset.Location = new System.Drawing.Point(306, 8); + this.reset.Name = "reset"; + this.reset.Size = new System.Drawing.Size(75, 23); + this.reset.TabIndex = 3; + this.reset.Text = "Reset"; + this.reset.UseVisualStyleBackColor = true; + this.reset.Click += new System.EventHandler(this.reset_Click); // // MindBlow // @@ -205,5 +230,7 @@ private System.Windows.Forms.Label memptr; private System.Windows.Forms.ListBox memlist; private System.Windows.Forms.Button run; + private System.Windows.Forms.Button stop; + private System.Windows.Forms.Button reset; } } diff --git a/ShiftOS.WinForms/Applications/MindBlow.cs b/ShiftOS.WinForms/Applications/MindBlow.cs index 6cfaea7..15361c2 100644 --- a/ShiftOS.WinForms/Applications/MindBlow.cs +++ b/ShiftOS.WinForms/Applications/MindBlow.cs @@ -59,8 +59,11 @@ namespace ShiftOS.WinForms.Applications { lock (lck) { - buffer[ptr] = (byte)a.KeyChar; - ptr++; + if (ptr < offset + count) + { + buffer[ptr] = (byte)a.KeyChar; + ptr++; + } } }; Desktop.InvokeOnWorkerThread(() => box.KeyPress += handler); @@ -94,7 +97,7 @@ namespace ShiftOS.WinForms.Applications } private static string[] DefaultMem; private BFInterpreter Interpreter; - + private Thread InterpreterThread; private void DoLayout() { memlist.Left = 0; @@ -104,9 +107,11 @@ namespace ShiftOS.WinForms.Applications program.Left = 0; programinput.Width = program.Width; programinput.Height = program.Height - load.Height; - load.Top = save.Top = run.Top = programinput.Height; - load.Width = save.Width = run.Width = save.Left = program.Width / 3; + load.Top = save.Top = run.Top = stop.Top = programinput.Height; + load.Width = save.Width = run.Width = stop.Width = save.Left = program.Width / 4; + load.Left = 0; run.Left = save.Left * 2; + stop.Left = save.Left * 3; } public MindBlow() @@ -168,18 +173,20 @@ namespace ShiftOS.WinForms.Applications private void run_Click(object sender, EventArgs e) { - new Thread(() => + InterpreterThread = new Thread(() => { try { Interpreter.Reset(); Interpreter.Execute(programinput.Text); } + catch (ThreadAbortException) { } // ignore catch (Exception ex) { Desktop.InvokeOnWorkerThread(() => Infobox.Show("Program Error", "An error occurred while executing your program: " + ex.GetType().ToString())); } - }).Start(); + }); + InterpreterThread.Start(); } private void tabs_Selected(object sender, TabControlEventArgs e) @@ -196,5 +203,24 @@ namespace ShiftOS.WinForms.Applications { AppearanceManager.SetupDialog(new FileDialog(new string[] { ".bf" }, FileOpenerStyle.Save, new Action((file) => Objects.ShiftFS.Utils.WriteAllText(file, programinput.Text)))); } + + private void stop_Click(object sender, EventArgs e) + { + if (InterpreterThread != null) + try + { + InterpreterThread.Abort(); + } + catch { } + } + + private void reset_Click(object sender, EventArgs e) + { + if (InterpreterThread != null) + if (InterpreterThread.IsAlive) + Infobox.Show("Cannot Reset", "The program is still running."); + else + Interpreter.Reset(); + } } } -- cgit v1.2.3 From 40b4c29b969f97004ec51c3c22b4b8263fadbef4 Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Mon, 19 Jun 2017 17:30:55 +1000 Subject: Fixed keyboard input & instruction pointer display --- ShiftOS.WinForms/Applications/MindBlow.cs | 8 ++- ShiftOS_TheReturn/BFInterpreter.cs | 105 ++++++++++++++++-------------- 2 files changed, 61 insertions(+), 52 deletions(-) (limited to 'ShiftOS.WinForms/Applications') diff --git a/ShiftOS.WinForms/Applications/MindBlow.cs b/ShiftOS.WinForms/Applications/MindBlow.cs index 15361c2..4fcda03 100644 --- a/ShiftOS.WinForms/Applications/MindBlow.cs +++ b/ShiftOS.WinForms/Applications/MindBlow.cs @@ -22,6 +22,7 @@ namespace ShiftOS.WinForms.Applications { private TextBox box; private KeysConverter kc; + public KeyPressEventHandler handler; public TextBoxStream(TextBox mybox) { kc = new KeysConverter(); @@ -55,7 +56,7 @@ namespace ShiftOS.WinForms.Applications { object lck = new object(); int ptr = offset; - KeyPressEventHandler handler = (o, a) => + handler = (o, a) => { lock (lck) { @@ -98,6 +99,7 @@ namespace ShiftOS.WinForms.Applications private static string[] DefaultMem; private BFInterpreter Interpreter; private Thread InterpreterThread; + private TextBoxStream consolestr; private void DoLayout() { memlist.Left = 0; @@ -121,7 +123,8 @@ namespace ShiftOS.WinForms.Applications for (ushort i = 0; i < 30000; i++) DefaultMem[i] = "0"; memlist.Items.AddRange(DefaultMem); - Interpreter = new BFInterpreter(new TextBoxStream(consoleout), this); + consolestr = new TextBoxStream(consoleout); + Interpreter = new BFInterpreter(consolestr, this); } public void IPtrMoved(int newval) @@ -212,6 +215,7 @@ namespace ShiftOS.WinForms.Applications InterpreterThread.Abort(); } catch { } + consoleout.KeyPress -= consolestr.handler; } private void reset_Click(object sender, EventArgs e) diff --git a/ShiftOS_TheReturn/BFInterpreter.cs b/ShiftOS_TheReturn/BFInterpreter.cs index 985e2ee..da4b44e 100644 --- a/ShiftOS_TheReturn/BFInterpreter.cs +++ b/ShiftOS_TheReturn/BFInterpreter.cs @@ -62,60 +62,65 @@ namespace ShiftOS.Engine Reset(); lst = listener; } - public void Execute(string program) + public void Execute(string program, int offset = 0) { int c = 0; lock (lck) - while (c < program.Length) - switch (program[c++]) + while (c < program.Length) { - case '<': - ptr--; - if (lst != null) - lst.PointerMoved(ptr); - break; - case '>': - ptr++; - if (lst != null) - lst.PointerMoved(ptr); - break; - case '+': - mem[ptr]++; - if (lst != null) - lst.MemChanged(ptr, mem[ptr]); - break; - case '-': - mem[ptr]--; - if (lst != null) - lst.MemChanged(ptr, mem[ptr]); - break; - case '.': - str.WriteByte(mem[ptr]); - break; - case ',': - mem[ptr] = (byte)str.ReadByte(); - if (lst != null) - lst.MemChanged(ptr, mem[ptr]); - break; - case '[': - int b; - int oldc = c; - for (b = 1; b != 0 && c < program.Length; c++) - { - if (program[c] == '[') - b++; - else if (program[c] == ']') - b--; - } - if (b == 0) - { - string block = program.Substring(oldc, c - oldc - 1); - while (mem[ptr] != 0) - Execute(block); - } - break; - case ']': - throw new Exception("Unbalanced brackets"); + switch (program[c++]) + { + case '<': + ptr--; + if (lst != null) + lst.PointerMoved(ptr); + break; + case '>': + ptr++; + if (lst != null) + lst.PointerMoved(ptr); + break; + case '+': + mem[ptr]++; + if (lst != null) + lst.MemChanged(ptr, mem[ptr]); + break; + case '-': + mem[ptr]--; + if (lst != null) + lst.MemChanged(ptr, mem[ptr]); + break; + case '.': + str.WriteByte(mem[ptr]); + break; + case ',': + mem[ptr] = (byte)str.ReadByte(); + if (lst != null) + lst.MemChanged(ptr, mem[ptr]); + break; + case '[': + int b; + int oldc = c; + for (b = 1; b != 0 && c < program.Length; c++) + { + if (program[c] == '[') + b++; + else if (program[c] == ']') + b--; + } + if (b == 0) + { + string block = program.Substring(oldc, c - oldc - 1); + while (mem[ptr] != 0) + Execute(block, offset + oldc); + + } + break; + case ']': + throw new Exception("Unbalanced brackets"); + } + if (lst != null) + lst.IPtrMoved(offset + c); } } public void Execute() -- cgit v1.2.3 From 37e9af7ca62b5bac72a56b2b8e847e5c0a5a1a6b Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Mon, 19 Jun 2017 20:01:38 +1000 Subject: made MindBlow wayyy faster More threads. More responsive. The IBFListener calls don't wait for the WinForms updates to finish now. They put changes onto a few variables using a lock and then activate a dormant thread to actually run those on the worker thread. Once it's done, that dormant thread goes back to waiting for an AutoResetEvent to fire that tells it when there's actually work to do. So it shouldn't chew up any CPU. I found out about this object working on this project and now I want to find everywhere in the game that uses a while loop to wait for stuff, and replace it with this. --- ShiftOS.WinForms/Applications/MindBlow.Designer.cs | 48 ++++++------ ShiftOS.WinForms/Applications/MindBlow.cs | 91 +++++++++++++++++----- 2 files changed, 98 insertions(+), 41 deletions(-) (limited to 'ShiftOS.WinForms/Applications') diff --git a/ShiftOS.WinForms/Applications/MindBlow.Designer.cs b/ShiftOS.WinForms/Applications/MindBlow.Designer.cs index ad2304d..6a8474d 100644 --- a/ShiftOS.WinForms/Applications/MindBlow.Designer.cs +++ b/ShiftOS.WinForms/Applications/MindBlow.Designer.cs @@ -32,16 +32,16 @@ this.console = new System.Windows.Forms.TabPage(); this.consoleout = new System.Windows.Forms.TextBox(); this.program = new System.Windows.Forms.TabPage(); + this.stop = new System.Windows.Forms.Button(); this.run = new System.Windows.Forms.Button(); this.save = new System.Windows.Forms.Button(); this.load = new System.Windows.Forms.Button(); this.programinput = new System.Windows.Forms.TextBox(); this.monitor = new System.Windows.Forms.TabPage(); + this.reset = new System.Windows.Forms.Button(); this.memlist = new System.Windows.Forms.ListBox(); this.instptr = new System.Windows.Forms.Label(); this.memptr = new System.Windows.Forms.Label(); - this.stop = new System.Windows.Forms.Button(); - this.reset = new System.Windows.Forms.Button(); this.tabs.SuspendLayout(); this.console.SuspendLayout(); this.program.SuspendLayout(); @@ -79,6 +79,7 @@ this.consoleout.Multiline = true; this.consoleout.Name = "consoleout"; this.consoleout.ReadOnly = true; + this.consoleout.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.consoleout.Size = new System.Drawing.Size(378, 237); this.consoleout.TabIndex = 0; // @@ -97,6 +98,16 @@ this.program.Text = "Program"; this.program.UseVisualStyleBackColor = true; // + // stop + // + this.stop.Location = new System.Drawing.Point(303, 217); + this.stop.Name = "stop"; + this.stop.Size = new System.Drawing.Size(75, 23); + this.stop.TabIndex = 4; + this.stop.Text = "Stop"; + this.stop.UseVisualStyleBackColor = true; + this.stop.Click += new System.EventHandler(this.stop_Click); + // // run // this.run.Location = new System.Drawing.Point(196, 217); @@ -132,6 +143,7 @@ this.programinput.Location = new System.Drawing.Point(3, 0); this.programinput.Multiline = true; this.programinput.Name = "programinput"; + this.programinput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.programinput.Size = new System.Drawing.Size(378, 218); this.programinput.TabIndex = 0; // @@ -148,6 +160,17 @@ this.monitor.Text = "Monitor"; this.monitor.UseVisualStyleBackColor = true; // + // reset + // + this.reset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.reset.Location = new System.Drawing.Point(306, 8); + this.reset.Name = "reset"; + this.reset.Size = new System.Drawing.Size(75, 23); + this.reset.TabIndex = 3; + this.reset.Text = "Reset"; + this.reset.UseVisualStyleBackColor = true; + this.reset.Click += new System.EventHandler(this.reset_Click); + // // memlist // this.memlist.FormattingEnabled = true; @@ -176,27 +199,6 @@ this.memptr.TabIndex = 0; this.memptr.Text = "Memory: 0"; // - // stop - // - this.stop.Location = new System.Drawing.Point(303, 217); - this.stop.Name = "stop"; - this.stop.Size = new System.Drawing.Size(75, 23); - this.stop.TabIndex = 4; - this.stop.Text = "Stop"; - this.stop.UseVisualStyleBackColor = true; - this.stop.Click += new System.EventHandler(this.stop_Click); - // - // reset - // - this.reset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.reset.Location = new System.Drawing.Point(306, 8); - this.reset.Name = "reset"; - this.reset.Size = new System.Drawing.Size(75, 23); - this.reset.TabIndex = 3; - this.reset.Text = "Reset"; - this.reset.UseVisualStyleBackColor = true; - this.reset.Click += new System.EventHandler(this.reset_Click); - // // MindBlow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); diff --git a/ShiftOS.WinForms/Applications/MindBlow.cs b/ShiftOS.WinForms/Applications/MindBlow.cs index 4fcda03..54167da 100644 --- a/ShiftOS.WinForms/Applications/MindBlow.cs +++ b/ShiftOS.WinForms/Applications/MindBlow.cs @@ -10,6 +10,8 @@ using System.Windows.Forms; using ShiftOS.Engine; using System.IO; using System.Threading; +using System.Collections; +using System.Collections.Concurrent; namespace ShiftOS.WinForms.Applications { @@ -18,6 +20,12 @@ namespace ShiftOS.WinForms.Applications [RequiresUpgrade("mindblow")] public partial class MindBlow : UserControl, IShiftOSWindow, IBFListener { + private bool running = true; + private Action updateMemPtr = null, updateIPtr = null; + private Action[] updateMem = new Action[30000]; + private AutoResetEvent evwaiting = new AutoResetEvent(false); + private object evlock = new object(); + private class TextBoxStream : Stream { private TextBox box; @@ -54,26 +62,20 @@ namespace ShiftOS.WinForms.Applications public override int Read(byte[] buffer, int offset, int count) { - object lck = new object(); int ptr = offset; + var hnd = new AutoResetEvent(false); handler = (o, a) => { - lock (lck) + if (ptr < offset + count) { - if (ptr < offset + count) - { - buffer[ptr] = (byte)a.KeyChar; - ptr++; - } + buffer[ptr] = (byte)a.KeyChar; + ptr++; } + if (ptr >= offset + count) + hnd.Set(); }; Desktop.InvokeOnWorkerThread(() => box.KeyPress += handler); - while (true) - { - lock (lck) - if (ptr >= offset + count) - break; - } + hnd.WaitOne(); Desktop.InvokeOnWorkerThread(() => box.KeyPress -= handler); return count; } @@ -129,12 +131,23 @@ namespace ShiftOS.WinForms.Applications public void IPtrMoved(int newval) { - Desktop.InvokeOnWorkerThread(() => instptr.Text = "Instruction: " + newval.ToString()); + lock (evlock) + { + updateIPtr = () => instptr.Text = "Instruction: " + newval.ToString(); + evwaiting.Set(); + } } public void MemChanged(ushort pos, byte newval) { - Desktop.InvokeOnWorkerThread(() => memlist.Items[pos] = newval.ToString()); + lock (evlock) + { + updateMem[pos] = () => + { + memlist.Items[pos] = newval.ToString(); + }; + evwaiting.Set(); + } } public void MemReset() @@ -149,6 +162,36 @@ namespace ShiftOS.WinForms.Applications public void OnLoad() { DoLayout(); + new Thread(() => + { + while (running) + { + evwaiting.WaitOne(); + try + { + lock (evlock) + { + if (updateIPtr != null) + { + Desktop.InvokeOnWorkerThread(updateIPtr); + updateIPtr = null; + } + if (updateMemPtr != null) + { + Desktop.InvokeOnWorkerThread(updateMemPtr); + updateMemPtr = null; + } + for (int i = 0; i < updateMem.Length; i++) + if (updateMem[i] != null) + { + Desktop.InvokeOnWorkerThread(updateMem[i]); + updateMem[i] = null; + } + } + } catch { } + evwaiting.Reset(); + } + }).Start(); } public void OnSkinLoad() @@ -157,6 +200,9 @@ namespace ShiftOS.WinForms.Applications public bool OnUnload() { + running = false; + evwaiting.Set(); // allow the display loop to die of old age + KillThread(); // mercilessly slaughter the interpreter thread return true; } @@ -166,7 +212,11 @@ namespace ShiftOS.WinForms.Applications public void PointerMoved(ushort newval) { - Desktop.InvokeOnWorkerThread(() => memptr.Text = "Memory: " + newval.ToString()); + lock (evlock) + { + updateMemPtr = () => memptr.Text = "Memory: " + newval.ToString(); + evwaiting.Set(); + } } private void MindBlow_Resize(object sender, EventArgs e) @@ -207,7 +257,7 @@ namespace ShiftOS.WinForms.Applications AppearanceManager.SetupDialog(new FileDialog(new string[] { ".bf" }, FileOpenerStyle.Save, new Action((file) => Objects.ShiftFS.Utils.WriteAllText(file, programinput.Text)))); } - private void stop_Click(object sender, EventArgs e) + private void KillThread() { if (InterpreterThread != null) try @@ -215,7 +265,12 @@ namespace ShiftOS.WinForms.Applications InterpreterThread.Abort(); } catch { } - consoleout.KeyPress -= consolestr.handler; + consoleout.KeyPress -= consolestr.handler; + } + + private void stop_Click(object sender, EventArgs e) + { + KillThread(); } private void reset_Click(object sender, EventArgs e) -- cgit v1.2.3