From 86fb2873fb13ab08fe29f93651bf6f53d852171e Mon Sep 17 00:00:00 2001 From: MatCat Date: Tue, 23 Feb 2021 20:21:22 -0800 Subject: [PATCH] 0.2.12: Fixed ghost active link, and fixed delay element --- README.md | 4 ++++ js/logicengine.js | 40 +++++++++++++++++++++++++++++++++------- js/main.js | 2 +- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f70bc90..67f2013 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ To be decided, but at this moment this code is open source and free to use for n ## Changelog +### 0.2.12 +* Fixed floating active link when deleting an element while linking +* Fixed the delay element so that it properly buffers all input pulses + ### 0.2.11 * Added Delay element diff --git a/js/logicengine.js b/js/logicengine.js index 7689f98..353bbcc 100644 --- a/js/logicengine.js +++ b/js/logicengine.js @@ -302,6 +302,8 @@ class Element extends CanvasTools { } Delete() { + // if we are active linking stop doing so + if (this.LogicEngine.ActiveLink == this) this.LogicEngine.ActiveLink = false; // Just to clean up connections for (let a = 0; a < this.OutputConnections.length;a++) { this.LogicEngine.RecursionCount = 0; @@ -649,15 +651,25 @@ class DelayElement extends Element { this.Task.Enabled = false; this.Task.LastCall = Date.now(); this.Task.Time = this.Period; + if (this.InputPulses.length > 0) { + this.Task.Enabled = true; + } } else { this.Output = true; this.Task.Enabled = false; - if (this.InputEnd > 0) { - this.Task.Time = this.InputEnd - this.InputStart; + if (this.InputPulses.length > 0) { + this.Task.Time = this.InputPulses[0]; this.Task.Enabled = true; + this.InputPulses.splice(0,1); + } else { + if (this.InputEnd > 0) { + this.Task.Time = this.InputEnd - this.InputStart; + this.Task.Enabled = true; + } } this.Task.LastCall = Date.now(); } + for (let a = 0; a < this.OutputConnections.length; a++) { this.LogicEngine.RecursionCount = 0; this.OutputConnections[a].Element.setInput(this.OutputConnections[a].Input, this.getOutput()); @@ -689,11 +701,24 @@ class DelayElement extends Element { this.Task.LastCall = Date.now(); this.Task.Enabled = true; } else { - this.InputEnd = Date.now(); - if (!this.Task.Enabled) { - this.Task.LastCall = Date.now(); - this.Task.Time = (this.InputEnd - this.InputStart) - (Date.now() - this.InputEnd); - this.Task.Enabled = true; + if (!this.Inputs[Input]) { + this.InputEnd = Date.now(); + if (this.InputPulses.length > 0) { + this.InputPulses.push(this.InputEnd - this.InputStart); + this.InputStart = 0; + this.InputEnd = 0; + } else { + if (!this.Task.Enabled) { + this.Task.LastCall = Date.now(); + this.Task.Time = (this.InputEnd - this.InputStart) - (Date.now() - this.InputEnd); + this.Task.Enabled = true; + } else { + this.InputPulses.push(this.InputEnd - this.InputStart); + } + } + } else { + // We are in a condition where input went true, but the task is already enabled + this.InputStart = Date.now(); } } } @@ -712,6 +737,7 @@ class DelayElement extends Element { this.Properties.push(periodProperty); this.InputStart = 0; this.InputEnd = 0; + this.InputPulses = new Array(); this.Inputs[0] = false; } diff --git a/js/main.js b/js/main.js index 8001ceb..b7960d2 100644 --- a/js/main.js +++ b/js/main.js @@ -2,7 +2,7 @@ MatCat BrowserLogic Simulator */ -let Version = "0.2.11"; +let Version = "0.2.12"; let spanVersion = document.getElementById("version"); spanVersion.innerText = Version; // get the canvas and get the engine object going