From 3a4c3026f32bd8d07630780c1ac567158c932d2b Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Wed, 7 Oct 2020 23:58:11 +0200 Subject: [PATCH] Introduced sim speed description. Fixes #16 --- .../logic/core/components/CoreClock.java | 5 +++ .../mograsim/plugin/views/SimulationView.java | 35 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreClock.java b/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreClock.java index e186928b..5ae194ba 100644 --- a/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreClock.java +++ b/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreClock.java @@ -44,6 +44,11 @@ public class CoreClock extends CoreComponent implements TimelineEventHandler, Lo notifyObservers(); } + public int getDelta() + { + return delta; + } + public BitVector getOutValues() { return isOn ? BitVector.SINGLE_1 : BitVector.SINGLE_0; diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java index 210e9de7..0dffceb7 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java @@ -4,6 +4,8 @@ import static net.mograsim.logic.model.preferences.RenderPreferences.DRAG_BUTTON import static net.mograsim.logic.model.preferences.RenderPreferences.ZOOM_BUTTON; import static net.mograsim.plugin.preferences.PluginPreferences.SIMULATION_SPEED_PRECISION; +import java.math.BigDecimal; +import java.math.MathContext; import java.util.HashSet; import java.util.Optional; import java.util.Set; @@ -30,6 +32,7 @@ import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInpu import net.mograsim.logic.core.LogicObserver; import net.mograsim.logic.core.components.CoreClock; import net.mograsim.logic.model.LogicUICanvas; +import net.mograsim.logic.model.modeladapter.CoreModelParameters; import net.mograsim.logic.model.preferences.RenderPreferences; import net.mograsim.machine.Machine; import net.mograsim.machine.Memory.MemoryCellModifiedListener; @@ -52,6 +55,7 @@ public class SimulationView extends ViewPart private Button sbseButton; private Scale simSpeedScale; private DoubleInput simSpeedInput; + private Label simSpeedDescription; private Composite contextDependentControlsParent; private Composite canvasParent; private InstructionTable instPreview; @@ -124,7 +128,7 @@ public class SimulationView extends ViewPart { Composite c = new Composite(parent, SWT.NONE); c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - c.setLayout(new GridLayout(7, false)); + c.setLayout(new GridLayout(8, false)); sbseButton = new Button(c, SWT.CHECK); controlsToDisableWhenNoMachinePresent.add(sbseButton); @@ -168,14 +172,43 @@ public class SimulationView extends ViewPart debugTarget.setExecutionSpeed(Math.pow(10, -simSpeedInput.getPrecision())); }); + simSpeedDescription = new Label(c, SWT.NONE); + simSpeedDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + c.layout(); } + private String describeSimSpeed(double speed) + { + CoreModelParameters coreModelParameters = debugTarget.getMachine().getCoreModelParameters(); + // TODO hardcoding this seems not optimal + int ticksPerSecond = 1000000; + + double simulTicksPerRealSecond = speed * ticksPerSecond; + + // TODO internationalize + StringBuilder sb = new StringBuilder(); + sb.append("Per second: "); + sb.append(formatNSignificantDigits(4, simulTicksPerRealSecond / coreModelParameters.wireTravelTime)); + sb.append(" wire travel times; "); + sb.append(formatNSignificantDigits(4, simulTicksPerRealSecond / coreModelParameters.gateProcessTime)); + sb.append(" gate process times; "); + sb.append(formatNSignificantDigits(4, simulTicksPerRealSecond / debugTarget.getMachine().getClock().getDelta() / 2)); + sb.append(" clock cycles"); + return sb.toString(); + } + + private static String formatNSignificantDigits(int digits, double d) + { + return new BigDecimal(d, new MathContext(digits)).toPlainString(); + } + private void speedFactorChanged(double speed) { simSpeedInput.setValue(speed); int closestScalePos = (int) Math.round(Math.log(speed) / SIM_SPEED_SCALE_STEP_FACTOR_LOG + SIM_SPEED_SCALE_STEPS); simSpeedScale.setSelection(Math.min(Math.max(closestScalePos, 0), SIM_SPEED_SCALE_STEPS)); + simSpeedDescription.setText(describeSimSpeed(speed)); } private void addInstructionPreviewControlWidgets(Composite parent) -- 2.17.1