Timeline now passed via constructor
authorFabian Stemmler <stemmler@in.tum.de>
Mon, 27 May 2019 18:06:29 +0000 (20:06 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Mon, 27 May 2019 18:06:29 +0000 (20:06 +0200)
The Timeline is now passed into each Component and Wire via the
constructor. It is no longer statically accessed through the Simulation
class. Made SampleERCP and LogicUI compatible with this change.

32 files changed:
LogicUI/src/era/mi/gui/LogicUIStandalone.java
LogicUI/src/era/mi/gui/components/GUIAndGate.java
LogicUI/src/era/mi/gui/components/GUIManualSwitch.java
LogicUI/src/era/mi/gui/components/GUIMerger.java
LogicUI/src/era/mi/gui/components/GUIMux.java
LogicUI/src/era/mi/gui/components/GUINotGate.java
LogicUI/src/era/mi/gui/components/GUIOrGate.java
LogicUI/src/era/mi/gui/components/GUISplitter.java
LogicUI/src/era/mi/gui/examples/RSLatchGUIExample.java
SampleERCP/src/sampleercp/parts/LogicUIPart.java
era.mi/src/era/mi/logic/Simulation.java [deleted file]
era.mi/src/era/mi/logic/components/BasicComponent.java
era.mi/src/era/mi/logic/components/BitDisplay.java
era.mi/src/era/mi/logic/components/Clock.java
era.mi/src/era/mi/logic/components/Component.java
era.mi/src/era/mi/logic/components/Connector.java
era.mi/src/era/mi/logic/components/Demux.java
era.mi/src/era/mi/logic/components/ManualSwitch.java
era.mi/src/era/mi/logic/components/Merger.java
era.mi/src/era/mi/logic/components/Mux.java
era.mi/src/era/mi/logic/components/Splitter.java
era.mi/src/era/mi/logic/components/TriStateBuffer.java
era.mi/src/era/mi/logic/components/gates/AndGate.java
era.mi/src/era/mi/logic/components/gates/MultiInputGate.java
era.mi/src/era/mi/logic/components/gates/NotGate.java
era.mi/src/era/mi/logic/components/gates/OrGate.java
era.mi/src/era/mi/logic/components/gates/XorGate.java
era.mi/src/era/mi/logic/tests/ComponentTest.java
era.mi/src/era/mi/logic/tests/GUITest.java
era.mi/src/era/mi/logic/tests/TestBitDisplay.java
era.mi/src/era/mi/logic/timeline/Timeline.java
era.mi/src/era/mi/logic/wires/Wire.java

index fea7e18..c50af4a 100644 (file)
@@ -1,85 +1,87 @@
-package era.mi.gui;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import era.mi.logic.Simulation;
-import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;
-import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
-
-/**
- * Standalone simulation visualizer.
- * 
- * @author Daniel Kirschten
- */
-public class LogicUIStandalone
-{
-       private final Display display;
-       private final Shell shell;
-       private final LogicUICanvas ui;
-
-       public LogicUIStandalone()
-       {
-               display = new Display();
-               shell = new Shell(display);
-               shell.setLayout(new FillLayout());
-               ui = new LogicUICanvas(shell, SWT.NONE);
-
-               ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
-               userInput.buttonDrag = 3;
-               userInput.buttonZoom = 2;
-               userInput.enableUserInput();
-               new ZoomableCanvasOverlay(ui, null).enableScale();
-       }
-
-       public LogicUICanvas getLogicUICanvas()
-       {
-               return ui;
-       }
-
-       /**
-        * Start the simulation timeline, and open the UI shell. Returns when the shell is closed.
-        */
-       public void run()
-       {
-               AtomicBoolean running = new AtomicBoolean(true);
-               Thread simulationThread = new Thread(() ->
-               {
-                       while (running.get())
-                       {
-                               // always execute to keep timeline from "hanging behind" for too long
-                               Simulation.TIMELINE.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
-                               long sleepTime;
-                               if (Simulation.TIMELINE.hasNext())
-                                       sleepTime = Simulation.TIMELINE.nextEventTime() - System.currentTimeMillis();
-                               else
-                                       sleepTime = 10;
-                               try
-                               {
-                                       if (sleepTime > 0)
-                                               Thread.sleep(sleepTime);
-                               }
-                               catch (InterruptedException e)
-                               {
-                               } // it is normal execution flow to be interrupted
-                       }
-               });
-               simulationThread.start();
-               Simulation.TIMELINE.addEventAddedListener(event ->
-               {
-                       if (event.getTiming() <= System.currentTimeMillis())
-                               simulationThread.interrupt();
-               });
-
-               shell.open();
-               while (!shell.isDisposed())
-                       if (!display.readAndDispatch())
-                               display.sleep();
-               running.set(false);
-               simulationThread.interrupt();
-       }
+package era.mi.gui;\r
+\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.layout.FillLayout;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.Shell;\r
+\r
+import era.mi.logic.timeline.Timeline;\r
+import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;\r
+import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;\r
+\r
+/**\r
+ * Standalone simulation visualizer.\r
+ * \r
+ * @author Daniel Kirschten\r
+ */\r
+public class LogicUIStandalone\r
+{\r
+       private final Display display;\r
+       private final Shell shell;\r
+       private final LogicUICanvas ui;\r
+       private Timeline timeline;\r
+\r
+       public LogicUIStandalone(Timeline timeline)\r
+       {\r
+               this.timeline = timeline;\r
+               display = new Display();\r
+               shell = new Shell(display);\r
+               shell.setLayout(new FillLayout());\r
+               ui = new LogicUICanvas(shell, SWT.NONE);\r
+\r
+               ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);\r
+               userInput.buttonDrag = 3;\r
+               userInput.buttonZoom = 2;\r
+               userInput.enableUserInput();\r
+               new ZoomableCanvasOverlay(ui, null).enableScale();\r
+       }\r
+\r
+       public LogicUICanvas getLogicUICanvas()\r
+       {\r
+               return ui;\r
+       }\r
+\r
+       /**\r
+        * Start the simulation timeline, and open the UI shell. Returns when the shell is closed.\r
+        */\r
+       public void run()\r
+       {\r
+               AtomicBoolean running = new AtomicBoolean(true);\r
+               Thread simulationThread = new Thread(() ->\r
+               {\r
+                       while (running.get())\r
+                       {\r
+                               // always execute to keep timeline from "hanging behind" for too long\r
+                               timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);\r
+                               long sleepTime;\r
+                               if (timeline.hasNext())\r
+                                       sleepTime = timeline.nextEventTime() - System.currentTimeMillis();\r
+                               else\r
+                                       sleepTime = 10;\r
+                               try\r
+                               {\r
+                                       if (sleepTime > 0)\r
+                                               Thread.sleep(sleepTime);\r
+                               }\r
+                               catch (InterruptedException e)\r
+                               {\r
+                               } // it is normal execution flow to be interrupted\r
+                       }\r
+               });\r
+               simulationThread.start();\r
+               timeline.addEventAddedListener(event ->\r
+               {\r
+                       if (event.getTiming() <= System.currentTimeMillis())\r
+                               simulationThread.interrupt();\r
+               });\r
+\r
+               shell.open();\r
+               while (!shell.isDisposed())\r
+                       if (!display.readAndDispatch())\r
+                               display.sleep();\r
+               running.set(false);\r
+               simulationThread.interrupt();\r
+       }\r
 }
\ No newline at end of file
index 003d3a4..27cefc0 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Collections;
 import java.util.List;\r
 \r
 import era.mi.logic.components.gates.AndGate;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
@@ -22,9 +23,9 @@ public class GUIAndGate extends AndGate implements BasicGUIComponent
        private final List<ReadEnd> connectedWireEnds;\r
        private final List<Point> wireEndConnectionPoints;\r
 \r
-       public GUIAndGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+       public GUIAndGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
        {\r
-               super(processTime, out, in);\r
+               super(timeline, processTime, out, in);\r
 \r
                List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
                List<Point> wireEndConnectionPointsModifiable = new ArrayList<>();\r
index 610364e..5de11cc 100644 (file)
@@ -7,6 +7,7 @@ import java.util.List;
 import java.util.Map;\r
 \r
 import era.mi.logic.components.ManualSwitch;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.Bit;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
@@ -33,9 +34,9 @@ public class GUIManualSwitch extends ManualSwitch implements BasicGUIComponent
        private final List<ReadEnd> connectedWireEnds;\r
        private final List<Point> wireEndConnectionPoints;\r
 \r
-       public GUIManualSwitch(ReadWriteEnd output)\r
+       public GUIManualSwitch(Timeline timeline, ReadWriteEnd output)\r
        {\r
-               super(output);\r
+               super(timeline, output);\r
 \r
                this.we = output;\r
 \r
index 1919e85..1525d0b 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Collections;
 import java.util.List;\r
 \r
 import era.mi.logic.components.Merger;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
@@ -19,9 +20,9 @@ public class GUIMerger extends Merger implements BasicGUIComponent
        private final List<ReadEnd> connectedWireEnds;\r
        private final List<Point> WireEndConnectionPoints;\r
 \r
-       public GUIMerger(ReadWriteEnd union, ReadEnd... inputs)\r
+       public GUIMerger(Timeline timeline, ReadWriteEnd union, ReadEnd... inputs)\r
        {\r
-               super(union, inputs);\r
+               super(timeline, union, inputs);\r
 \r
                List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
                List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();\r
index 2da1501..7fc1fa9 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Collections;
 import java.util.List;\r
 \r
 import era.mi.logic.components.Mux;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
@@ -18,9 +19,9 @@ public class GUIMux extends Mux implements BasicGUIComponent
        private final List<ReadEnd> connectedWireEnds;\r
        private final List<Point> WireEndConnectionPoints;\r
 \r
-       public GUIMux(int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)\r
+       public GUIMux(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)\r
        {\r
-               super(processTime, out, select, inputs);\r
+               super(timeline, processTime, out, select, inputs);\r
 \r
                double height = inputs.length * 5;\r
                if (height < 10)\r
index 2b61bd1..e860d9b 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Collections;
 import java.util.List;\r
 \r
 import era.mi.logic.components.gates.NotGate;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
@@ -19,9 +20,9 @@ public class GUINotGate extends NotGate implements BasicGUIComponent
        private final List<ReadEnd> connectedWireEnds;\r
        private final List<Point> WireEndConnectionPoints;\r
 \r
-       public GUINotGate(int processTime, ReadEnd in, ReadWriteEnd out)\r
+       public GUINotGate(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out)\r
        {\r
-               super(processTime, in, out);\r
+               super(timeline, processTime, in, out);\r
 \r
                List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
                List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();\r
index ef5daa1..573c640 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Collections;
 import java.util.List;\r
 \r
 import era.mi.logic.components.gates.OrGate;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
@@ -22,9 +23,9 @@ public class GUIOrGate extends OrGate implements BasicGUIComponent
        private final List<ReadEnd> connectedWireEnds;\r
        private final List<Point> WireEndConnectionPoints;\r
 \r
-       public GUIOrGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+       public GUIOrGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
        {\r
-               super(processTime, out, in);\r
+               super(timeline, processTime, out, in);\r
 \r
                List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
                List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();\r
index 392fe83..d229ac1 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Collections;
 import java.util.List;\r
 \r
 import era.mi.logic.components.Splitter;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
@@ -19,9 +20,9 @@ public class GUISplitter extends Splitter implements BasicGUIComponent
        private final List<ReadEnd> connectedWireEnds;\r
        private final List<Point> WireEndConnectionPoints;\r
 \r
-       public GUISplitter(ReadEnd input, ReadWriteEnd... outputs)\r
+       public GUISplitter(Timeline timeline, ReadEnd input, ReadWriteEnd... outputs)\r
        {\r
-               super(input, outputs);\r
+               super(timeline, input, outputs);\r
 \r
                List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
                List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();\r
index b91ebe9..3665952 100644 (file)
@@ -6,7 +6,7 @@ import era.mi.gui.components.GUIManualSwitch;
 import era.mi.gui.components.GUINotGate;\r
 import era.mi.gui.components.GUIOrGate;\r
 import era.mi.gui.wires.WireConnectionPoint;\r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire;\r
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
 \r
@@ -15,30 +15,32 @@ public class RSLatchGUIExample
        private static final int WIRE_DELAY = 10;\r
        private static final int OR_DELAY = 50;\r
        private static final int NOT_DELAY = 50;\r
+       private static final Timeline t = new Timeline(11);\r
 \r
        public static void main(String[] args)\r
        {\r
-               LogicUIStandalone ui = new LogicUIStandalone();\r
+               LogicUIStandalone ui = new LogicUIStandalone(t);\r
                addComponentsAndWires(ui.getLogicUICanvas());\r
                ui.run();\r
        }\r
 \r
        public static void addComponentsAndWires(LogicUICanvas ui)\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire r = new Wire(1, WIRE_DELAY);\r
-               Wire s = new Wire(1, WIRE_DELAY);\r
-               Wire t2 = new Wire(1, WIRE_DELAY);\r
-               Wire t1 = new Wire(1, WIRE_DELAY);\r
-               Wire q = new Wire(1, WIRE_DELAY);\r
-               Wire nq = new Wire(1, WIRE_DELAY);\r
+               Wire r = new Wire(t, 1, WIRE_DELAY);\r
+               Wire s = new Wire(t, 1, WIRE_DELAY);\r
+               Wire t2 = new Wire(t, 1, WIRE_DELAY);\r
+               Wire t1 = new Wire(t, 1, WIRE_DELAY);\r
+               Wire q = new Wire(t, 1, WIRE_DELAY);\r
+               Wire nq = new Wire(t, 1, WIRE_DELAY);\r
 \r
-               GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(r.createReadWriteEnd()), 100, 100);\r
-               GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(s.createReadWriteEnd()), 100, 200);\r
-               GUIOrGate or1 = ui.addComponent(new GUIOrGate(OR_DELAY, t1.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()), 160, 102.5);\r
-               GUIOrGate or2 = ui.addComponent(new GUIOrGate(OR_DELAY, t2.createReadWriteEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()), 160, 192.5);\r
-               GUINotGate not1 = ui.addComponent(new GUINotGate(NOT_DELAY, t1.createReadOnlyEnd(), q.createReadWriteEnd()), 200, 107.5);\r
-               GUINotGate not2 = ui.addComponent(new GUINotGate(NOT_DELAY, t2.createReadOnlyEnd(), nq.createReadWriteEnd()), 200, 197.5);\r
+               GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(t, r.createReadWriteEnd()), 100, 100);\r
+               GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(t, s.createReadWriteEnd()), 100, 200);\r
+               GUIOrGate or1 = ui.addComponent(new GUIOrGate(t, OR_DELAY, t1.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()),\r
+                               160, 102.5);\r
+               GUIOrGate or2 = ui.addComponent(new GUIOrGate(t, OR_DELAY, t2.createReadWriteEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()),\r
+                               160, 192.5);\r
+               GUINotGate not1 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), q.createReadWriteEnd()), 200, 107.5);\r
+               GUINotGate not2 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), nq.createReadWriteEnd()), 200, 197.5);\r
 \r
                WireConnectionPoint p1 = ui.addComponent(new WireConnectionPoint(q, 3), 250, 112.5);\r
                WireConnectionPoint p2 = ui.addComponent(new WireConnectionPoint(nq, 3), 250, 202.5);\r
index c142cb6..481879c 100644 (file)
@@ -9,7 +9,7 @@ import org.eclipse.swt.widgets.Composite;
 
 import era.mi.gui.LogicUICanvas;
 import era.mi.gui.examples.RSLatchGUIExample;
-import era.mi.logic.Simulation;
+import era.mi.logic.timeline.Timeline;
 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
 
 public class LogicUIPart
@@ -20,6 +20,7 @@ public class LogicUIPart
        @PostConstruct
        public void create(Composite parent)
        {
+               Timeline timeline = new Timeline(11);
                LogicUICanvas ui = new LogicUICanvas(parent, SWT.NONE);
                RSLatchGUIExample.addComponentsAndWires(ui);
                ui.addTransformListener((x, y, z) -> part.setDirty(z < 1));
@@ -33,10 +34,10 @@ public class LogicUIPart
                        while (!ui.isDisposed())
                        {
                                // always execute to keep timeline from "hanging behind" for too long
-                               Simulation.TIMELINE.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
+                               timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
                                long sleepTime;
-                               if (Simulation.TIMELINE.hasNext())
-                                       sleepTime = Simulation.TIMELINE.nextEventTime() - System.currentTimeMillis();
+                               if (timeline.hasNext())
+                                       sleepTime = timeline.nextEventTime() - System.currentTimeMillis();
                                else
                                        sleepTime = 10;
                                try
@@ -50,7 +51,7 @@ public class LogicUIPart
                        }
                });
                simulationThread.start();
-               Simulation.TIMELINE.addEventAddedListener(event ->
+               timeline.addEventAddedListener(event ->
                {
                        if (event.getTiming() <= System.currentTimeMillis())
                                simulationThread.interrupt();
diff --git a/era.mi/src/era/mi/logic/Simulation.java b/era.mi/src/era/mi/logic/Simulation.java
deleted file mode 100644 (file)
index 0468ec1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package era.mi.logic;
-
-import era.mi.logic.timeline.Timeline;
-
-public class Simulation
-{
-       public final static Timeline TIMELINE = new Timeline(11);
-
-}
\ No newline at end of file
index f73e0f7..1178568 100644 (file)
@@ -1,6 +1,6 @@
 package era.mi.logic.components;\r
 \r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.BitVector;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.WireObserver;\r
@@ -10,7 +10,7 @@ import era.mi.logic.wires.WireObserver;
  * \r
  * @author Fabian Stemmler\r
  */\r
-public abstract class BasicComponent implements WireObserver, Component\r
+public abstract class BasicComponent extends Component implements WireObserver\r
 {\r
        private int processTime;\r
 \r
@@ -20,15 +20,16 @@ public abstract class BasicComponent implements WireObserver, Component
         * \r
         * @author Fabian Stemmler\r
         */\r
-       public BasicComponent(int processTime)\r
+       public BasicComponent(Timeline timeline, int processTime)\r
        {\r
+               super(timeline);\r
                this.processTime = processTime > 0 ? processTime : 1;\r
        }\r
 \r
        @Override\r
        public void update(ReadEnd initiator, BitVector oldValues)\r
        {\r
-               Simulation.TIMELINE.addEvent(e -> compute(), processTime);\r
+               timeline.addEvent(e -> compute(), processTime);\r
        }\r
 \r
        protected abstract void compute();\r
index 28b5165..1db41c0 100644 (file)
@@ -2,6 +2,7 @@ package era.mi.logic.components;
 \r
 import java.util.List;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.Bit;\r
 import era.mi.logic.types.BitVector;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
@@ -12,9 +13,9 @@ public class BitDisplay extends BasicComponent
        private final ReadEnd in;\r
        private BitVector displayedValue;\r
 \r
-       public BitDisplay(ReadEnd in)\r
+       public BitDisplay(Timeline timeline, ReadEnd in)\r
        {\r
-               super(1);\r
+               super(timeline, 1);\r
                this.in = in;\r
                in.addObserver(this);\r
                compute();\r
index b4528a4..1cf101b 100644 (file)
@@ -2,7 +2,7 @@ package era.mi.logic.components;
 \r
 import java.util.List;\r
 \r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.timeline.TimelineEvent;\r
 import era.mi.logic.timeline.TimelineEventHandler;\r
 import era.mi.logic.types.Bit;\r
@@ -10,7 +10,7 @@ import era.mi.logic.wires.Wire;
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 \r
-public class Clock implements TimelineEventHandler, Component\r
+public class Clock extends Component implements TimelineEventHandler\r
 {\r
        private boolean toggle = false;\r
        private ReadWriteEnd out;\r
@@ -21,8 +21,9 @@ public class Clock implements TimelineEventHandler, Component
         * @param out   {@link Wire} the clock's impulses are fed into\r
         * @param delta ticks between rising and falling edge\r
         */\r
-       public Clock(ReadWriteEnd out, int delta)\r
+       public Clock(Timeline timeline, ReadWriteEnd out, int delta)\r
        {\r
+               super(timeline);\r
                this.delta = delta;\r
                this.out = out;\r
                addToTimeline();\r
@@ -43,7 +44,7 @@ public class Clock implements TimelineEventHandler, Component
 \r
        private void addToTimeline()\r
        {\r
-               Simulation.TIMELINE.addEvent(this, delta);\r
+               timeline.addEvent(this, delta);\r
        }\r
 \r
        @Override\r
index d749a4b..d398aae 100644 (file)
@@ -2,20 +2,27 @@ package era.mi.logic.components;
 \r
 import java.util.List;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 \r
-public interface Component\r
+public abstract class Component\r
 {\r
+       protected Timeline timeline;\r
+\r
+       public Component(Timeline timeline)\r
+       {\r
+               this.timeline = timeline;\r
+       }\r
 \r
        /**\r
         * Returns immutable list of all inputs to the {@link Component} (including e.g. the select bits to a MUX). Intended for visualization\r
         * in the UI.\r
         */\r
-       public List<ReadEnd> getAllInputs();\r
+       public abstract List<ReadEnd> getAllInputs();\r
 \r
        /**\r
         * Returns immutable list of all outputs to the {@link Component}. Intended for visualization in the UI.\r
         */\r
-       public List<ReadWriteEnd> getAllOutputs();\r
+       public abstract List<ReadWriteEnd> getAllOutputs();\r
 }\r
index 4f211bf..558dbb6 100644 (file)
@@ -2,20 +2,21 @@ package era.mi.logic.components;
 \r
 import java.util.List;\r
 \r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.BitVector;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 import era.mi.logic.wires.WireObserver;\r
 \r
-public class Connector implements WireObserver, Component\r
+public class Connector extends Component implements WireObserver\r
 {\r
        private boolean connected;\r
        private final ReadWriteEnd a;\r
        private final ReadWriteEnd b;\r
 \r
-       public Connector(ReadWriteEnd a, ReadWriteEnd b)\r
+       public Connector(Timeline timeline, ReadWriteEnd a, ReadWriteEnd b)\r
        {\r
+               super(timeline);\r
                if (a.length() != b.length())\r
                        throw new IllegalArgumentException(String.format("WireArray width does not match: %d, %d", a.length(), b.length()));\r
                this.a = a;\r
@@ -50,7 +51,7 @@ public class Connector implements WireObserver, Component
        public void update(ReadEnd initiator, BitVector oldValues)\r
        {\r
                if (connected)\r
-                       Simulation.TIMELINE.addEvent(e -> update(initiator), 1);\r
+                       timeline.addEvent(e -> update(initiator), 1);\r
        }\r
 \r
        private void update(ReadEnd initiator)\r
index 0a48cb9..c67756a 100644 (file)
@@ -2,6 +2,7 @@ package era.mi.logic.components;
 \r
 import java.util.List;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
@@ -27,9 +28,9 @@ public class Demux extends BasicComponent
         * @param select  Indexes the output array to which the input is mapped. Must have enough bits to index all outputs.\r
         * @param outputs One of these outputs receives the input signal, depending on the select bits\r
         */\r
-       public Demux(int processTime, ReadEnd in, ReadEnd select, ReadWriteEnd... outputs)\r
+       public Demux(Timeline timeline, int processTime, ReadEnd in, ReadEnd select, ReadWriteEnd... outputs)\r
        {\r
-               super(processTime);\r
+               super(timeline, processTime);\r
                outputSize = in.length();\r
 \r
                this.in = in;\r
index 0b694a4..450fa51 100644 (file)
@@ -2,6 +2,7 @@ package era.mi.logic.components;
 \r
 import java.util.List;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.Bit;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
@@ -12,13 +13,14 @@ import era.mi.logic.wires.Wire.ReadWriteEnd;
  * @author Christian Femers\r
  *\r
  */\r
-public class ManualSwitch implements Component\r
+public class ManualSwitch extends Component\r
 {\r
        private ReadWriteEnd output;\r
        private boolean isOn;\r
 \r
-       public ManualSwitch(ReadWriteEnd output)\r
+       public ManualSwitch(Timeline timeline, ReadWriteEnd output)\r
        {\r
+               super(timeline);\r
                if (output.length() != 1)\r
                        throw new IllegalArgumentException("Switch output can be only a single wire");\r
                this.output = output;\r
index 2c1ffcb..c5d8fdb 100644 (file)
@@ -2,13 +2,14 @@ package era.mi.logic.components;
 \r
 import java.util.List;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.BitVector;\r
 import era.mi.logic.wires.Wire;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 import era.mi.logic.wires.WireObserver;\r
 \r
-public class Merger implements WireObserver, Component\r
+public class Merger extends Component implements WireObserver\r
 {\r
        private ReadWriteEnd out;\r
        private ReadEnd[] inputs;\r
@@ -19,8 +20,9 @@ public class Merger implements WireObserver, Component
         * @param union  The output of merging n {@link Wire}s into one. Must have length = a1.length() + a2.length() + ... + an.length().\r
         * @param inputs The inputs to be merged into the union\r
         */\r
-       public Merger(ReadWriteEnd union, ReadEnd... inputs)\r
+       public Merger(Timeline timeline, ReadWriteEnd union, ReadEnd... inputs)\r
        {\r
+               super(timeline);\r
                this.inputs = inputs;\r
                this.out = union;\r
                this.beginningIndex = new int[inputs.length];\r
index 17ad0dd..818a175 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Arrays;
 import java.util.Collections;\r
 import java.util.List;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
@@ -30,9 +31,9 @@ public class Mux extends BasicComponent
         * @param select Indexes the input array which is to be mapped to the output. Must have enough bits to index all inputs.\r
         * @param inputs One of these inputs is mapped to the output, depending on the select bits\r
         */\r
-       public Mux(int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)\r
+       public Mux(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)\r
        {\r
-               super(processTime);\r
+               super(timeline, processTime);\r
                outputSize = out.length();\r
 \r
                this.inputs = inputs.clone();\r
index 530ad62..b26cb3c 100644 (file)
@@ -2,18 +2,20 @@ package era.mi.logic.components;
 \r
 import java.util.List;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.BitVector;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 import era.mi.logic.wires.WireObserver;\r
 \r
-public class Splitter implements WireObserver, Component\r
+public class Splitter extends Component implements WireObserver\r
 {\r
        private ReadEnd input;\r
        private ReadWriteEnd[] outputs;\r
 \r
-       public Splitter(ReadEnd input, ReadWriteEnd... outputs)\r
+       public Splitter(Timeline timeline, ReadEnd input, ReadWriteEnd... outputs)\r
        {\r
+               super(timeline);\r
                this.input = input;\r
                this.outputs = outputs;\r
                input.addObserver(this);\r
index 7707232..13ca69f 100644 (file)
@@ -2,6 +2,7 @@ package era.mi.logic.components;
 \r
 import java.util.List;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.Bit;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
@@ -11,9 +12,9 @@ public class TriStateBuffer extends BasicComponent
        ReadEnd in, enable;\r
        ReadWriteEnd out;\r
 \r
-       public TriStateBuffer(int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable)\r
+       public TriStateBuffer(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable)\r
        {\r
-               super(processTime);\r
+               super(timeline, processTime);\r
                if (in.length() != out.length())\r
                        throw new IllegalArgumentException(\r
                                        "Tri-state output must have the same amount of bits as the input. Input: " + in.length() + " Output: " + out.length());\r
index 4d0726e..2d35e61 100644 (file)
@@ -1,13 +1,14 @@
 package era.mi.logic.components.gates;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.BitVector.BitVectorMutator;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 \r
 public class AndGate extends MultiInputGate\r
 {\r
-       public AndGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+       public AndGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
        {\r
-               super(processTime, BitVectorMutator::and, out, in);\r
+               super(timeline, processTime, BitVectorMutator::and, out, in);\r
        }\r
 }\r
index 4c985b4..e9920ba 100644 (file)
@@ -3,6 +3,7 @@ package era.mi.logic.components.gates;
 import java.util.List;\r
 \r
 import era.mi.logic.components.BasicComponent;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.BitVector.BitVectorMutator;\r
 import era.mi.logic.types.MutationOperation;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
@@ -15,9 +16,9 @@ public abstract class MultiInputGate extends BasicComponent
        protected final int length;\r
        protected MutationOperation op;\r
 \r
-       protected MultiInputGate(int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in)\r
+       protected MultiInputGate(Timeline timeline, int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in)\r
        {\r
-               super(processTime);\r
+               super(timeline, processTime);\r
                this.op = op;\r
                length = out.length();\r
                this.in = in.clone();\r
index ec1f816..7831cd2 100644 (file)
@@ -3,6 +3,7 @@ package era.mi.logic.components.gates;
 import java.util.List;\r
 \r
 import era.mi.logic.components.BasicComponent;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 \r
@@ -11,9 +12,9 @@ public class NotGate extends BasicComponent
        private ReadEnd in;\r
        private ReadWriteEnd out;\r
 \r
-       public NotGate(int processTime, ReadEnd in, ReadWriteEnd out)\r
+       public NotGate(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out)\r
        {\r
-               super(processTime);\r
+               super(timeline, processTime);\r
                this.in = in;\r
                in.addObserver(this);\r
                this.out = out;\r
index 52dc921..6aebec1 100644 (file)
@@ -1,13 +1,14 @@
 package era.mi.logic.components.gates;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.BitVector.BitVectorMutator;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
 \r
 public class OrGate extends MultiInputGate\r
 {\r
-       public OrGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+       public OrGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
        {\r
-               super(processTime, BitVectorMutator::or, out, in);\r
+               super(timeline, processTime, BitVectorMutator::or, out, in);\r
        }\r
 }\r
index d241469..2067a86 100644 (file)
@@ -1,5 +1,6 @@
 package era.mi.logic.components.gates;\r
 \r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.BitVector.BitVectorMutator;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 import era.mi.logic.wires.Wire.ReadWriteEnd;\r
@@ -11,9 +12,9 @@ import era.mi.logic.wires.Wire.ReadWriteEnd;
  */\r
 public class XorGate extends MultiInputGate\r
 {\r
-       public XorGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+       public XorGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
        {\r
-               super(processTime, BitVectorMutator::xor, out, in);\r
+               super(timeline, processTime, BitVectorMutator::xor, out, in);\r
        }\r
 \r
 }\r
index 54f47d9..831349d 100644 (file)
@@ -8,7 +8,6 @@ import java.util.function.LongConsumer;
 \r
 import org.junit.jupiter.api.Test;\r
 \r
-import era.mi.logic.Simulation;\r
 import era.mi.logic.components.Connector;\r
 import era.mi.logic.components.Demux;\r
 import era.mi.logic.components.Merger;\r
@@ -19,6 +18,7 @@ import era.mi.logic.components.gates.AndGate;
 import era.mi.logic.components.gates.NotGate;\r
 import era.mi.logic.components.gates.OrGate;\r
 import era.mi.logic.components.gates.XorGate;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.Bit;\r
 import era.mi.logic.types.BitVector;\r
 import era.mi.logic.wires.Wire;\r
@@ -27,18 +27,19 @@ import era.mi.logic.wires.Wire.ReadWriteEnd;
 \r
 class ComponentTest\r
 {\r
+       private Timeline t = new Timeline(11);\r
 \r
        @Test\r
        void circuitExampleTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire a = new Wire(1, 1), b = new Wire(1, 1), c = new Wire(1, 10), d = new Wire(2, 1), e = new Wire(1, 1), f = new Wire(1, 1),\r
-                               g = new Wire(1, 1), h = new Wire(2, 1), i = new Wire(2, 1), j = new Wire(1, 1), k = new Wire(1, 1);\r
-               new AndGate(1, f.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
-               new NotGate(1, f.createReadOnlyEnd(), g.createReadWriteEnd());\r
-               new Merger(h.createReadWriteEnd(), c.createReadOnlyEnd(), g.createReadOnlyEnd());\r
-               new Mux(1, i.createReadWriteEnd(), e.createReadOnlyEnd(), h.createReadOnlyEnd(), d.createReadOnlyEnd());\r
-               new Splitter(i.createReadOnlyEnd(), k.createReadWriteEnd(), j.createReadWriteEnd());\r
+               Wire a = new Wire(t, 1, 1), b = new Wire(t, 1, 1), c = new Wire(t, 1, 10), d = new Wire(t, 2, 1), e = new Wire(t, 1, 1),\r
+                               f = new Wire(t, 1, 1), g = new Wire(t, 1, 1), h = new Wire(t, 2, 1), i = new Wire(t, 2, 1), j = new Wire(t, 1, 1),\r
+                               k = new Wire(t, 1, 1);\r
+               new AndGate(t, 1, f.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
+               new NotGate(t, 1, f.createReadOnlyEnd(), g.createReadWriteEnd());\r
+               new Merger(t, h.createReadWriteEnd(), c.createReadOnlyEnd(), g.createReadOnlyEnd());\r
+               new Mux(t, 1, i.createReadWriteEnd(), e.createReadOnlyEnd(), h.createReadOnlyEnd(), d.createReadOnlyEnd());\r
+               new Splitter(t, i.createReadOnlyEnd(), k.createReadWriteEnd(), j.createReadWriteEnd());\r
 \r
                a.createReadWriteEnd().feedSignals(Bit.ZERO);\r
                b.createReadWriteEnd().feedSignals(Bit.ONE);\r
@@ -46,7 +47,7 @@ class ComponentTest
                d.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE);\r
                e.createReadWriteEnd().feedSignals(Bit.ZERO);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertEquals(Bit.ONE, j.getValue());\r
                assertEquals(Bit.ZERO, k.getValue());\r
@@ -55,12 +56,12 @@ class ComponentTest
        @Test\r
        void splitterTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire a = new Wire(3, 1), b = new Wire(2, 1), c = new Wire(3, 1), in = new Wire(8, 1);\r
+               t.reset();\r
+               Wire a = new Wire(t, 3, 1), b = new Wire(t, 2, 1), c = new Wire(t, 3, 1), in = new Wire(t, 8, 1);\r
                in.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
-               new Splitter(in.createReadOnlyEnd(), a.createReadWriteEnd(), b.createReadWriteEnd(), c.createReadWriteEnd());\r
+               new Splitter(t, in.createReadOnlyEnd(), a.createReadWriteEnd(), b.createReadWriteEnd(), c.createReadWriteEnd());\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(a.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO);\r
                assertBitArrayEquals(b.getValues(), Bit.ONE, Bit.ZERO);\r
@@ -70,15 +71,15 @@ class ComponentTest
        @Test\r
        void mergerTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire a = new Wire(3, 1), b = new Wire(2, 1), c = new Wire(3, 1), out = new Wire(8, 1);\r
+               t.reset();\r
+               Wire a = new Wire(t, 3, 1), b = new Wire(t, 2, 1), c = new Wire(t, 3, 1), out = new Wire(t, 8, 1);\r
                a.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO);\r
                b.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO);\r
                c.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE);\r
 \r
-               new Merger(out.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
+               new Merger(t, out.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(out.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
        }\r
@@ -86,23 +87,23 @@ class ComponentTest
        @Test\r
        void triStateBufferTest()\r
        {\r
-               Wire a = new Wire(1, 1), b = new Wire(1, 1), en = new Wire(1, 1), notEn = new Wire(1, 1);\r
-               new NotGate(1, en.createReadOnlyEnd(), notEn.createReadWriteEnd());\r
-               new TriStateBuffer(1, a.createReadOnlyEnd(), b.createReadWriteEnd(), en.createReadOnlyEnd());\r
-               new TriStateBuffer(1, b.createReadOnlyEnd(), a.createReadWriteEnd(), notEn.createReadOnlyEnd());\r
+               Wire a = new Wire(t, 1, 1), b = new Wire(t, 1, 1), en = new Wire(t, 1, 1), notEn = new Wire(t, 1, 1);\r
+               new NotGate(t, 1, en.createReadOnlyEnd(), notEn.createReadWriteEnd());\r
+               new TriStateBuffer(t, 1, a.createReadOnlyEnd(), b.createReadWriteEnd(), en.createReadOnlyEnd());\r
+               new TriStateBuffer(t, 1, b.createReadOnlyEnd(), a.createReadWriteEnd(), notEn.createReadOnlyEnd());\r
 \r
                ReadWriteEnd enI = en.createReadWriteEnd(), aI = a.createReadWriteEnd(), bI = b.createReadWriteEnd();\r
                enI.feedSignals(Bit.ONE);\r
                aI.feedSignals(Bit.ONE);\r
                bI.feedSignals(Bit.Z);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertEquals(Bit.ONE, b.getValue());\r
 \r
                bI.feedSignals(Bit.ZERO);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertEquals(Bit.X, b.getValue());\r
                assertEquals(Bit.ONE, a.getValue());\r
@@ -110,7 +111,7 @@ class ComponentTest
                aI.clearSignals();\r
                enI.feedSignals(Bit.ZERO);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertEquals(Bit.ZERO, a.getValue());\r
 \r
@@ -119,25 +120,26 @@ class ComponentTest
        @Test\r
        void muxTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5), out = new Wire(4, 1);\r
+               t.reset();\r
+               Wire a = new Wire(t, 4, 3), b = new Wire(t, 4, 6), c = new Wire(t, 4, 4), select = new Wire(t, 2, 5), out = new Wire(t, 4, 1);\r
                ReadWriteEnd selectIn = select.createReadWriteEnd();\r
 \r
                selectIn.feedSignals(Bit.ZERO, Bit.ZERO);\r
                a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
                c.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
 \r
-               new Mux(1, out.createReadWriteEnd(), select.createReadOnlyEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
-               Simulation.TIMELINE.executeAll();\r
+               new Mux(t, 1, out.createReadWriteEnd(), select.createReadOnlyEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(),\r
+                               c.createReadOnlyEnd());\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(out.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
                selectIn.feedSignals(Bit.ZERO, Bit.ONE);\r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(out.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
 \r
                selectIn.feedSignals(Bit.ONE, Bit.ONE);\r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(out.getValues(), Bit.Z, Bit.Z, Bit.Z, Bit.Z);\r
 \r
@@ -146,28 +148,29 @@ class ComponentTest
        @Test\r
        void demuxTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5), in = new Wire(4, 1);\r
+               t.reset();\r
+               Wire a = new Wire(t, 4, 3), b = new Wire(t, 4, 6), c = new Wire(t, 4, 4), select = new Wire(t, 2, 5), in = new Wire(t, 4, 1);\r
                ReadWriteEnd selectIn = select.createReadWriteEnd();\r
 \r
                selectIn.feedSignals(Bit.ZERO, Bit.ZERO);\r
                in.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
 \r
-               new Demux(1, in.createReadOnlyEnd(), select.createReadOnlyEnd(), a.createReadWriteEnd(), b.createReadWriteEnd(), c.createReadWriteEnd());\r
-               Simulation.TIMELINE.executeAll();\r
+               new Demux(t, 1, in.createReadOnlyEnd(), select.createReadOnlyEnd(), a.createReadWriteEnd(), b.createReadWriteEnd(),\r
+                               c.createReadWriteEnd());\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(a.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
                assertBitArrayEquals(b.getValues(), Bit.U, Bit.U, Bit.U, Bit.U);\r
                assertBitArrayEquals(c.getValues(), Bit.U, Bit.U, Bit.U, Bit.U);\r
                selectIn.feedSignals(Bit.ZERO, Bit.ONE);\r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(a.getValues(), Bit.Z, Bit.Z, Bit.Z, Bit.Z);\r
                assertBitArrayEquals(b.getValues(), Bit.U, Bit.U, Bit.U, Bit.U);\r
                assertBitArrayEquals(c.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
 \r
                selectIn.feedSignals(Bit.ONE, Bit.ONE);\r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(a.getValues(), Bit.Z, Bit.Z, Bit.Z, Bit.Z);\r
                assertBitArrayEquals(b.getValues(), Bit.U, Bit.U, Bit.U, Bit.U);\r
@@ -178,13 +181,13 @@ class ComponentTest
        @Test\r
        void andTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire a = new Wire(4, 1), b = new Wire(4, 3), c = new Wire(4, 1);\r
-               new AndGate(1, c.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
+               t.reset();\r
+               Wire a = new Wire(t, 4, 1), b = new Wire(t, 4, 3), c = new Wire(t, 4, 1);\r
+               new AndGate(t, 1, c.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
                a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ZERO);\r
                b.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(c.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ZERO);\r
        }\r
@@ -192,13 +195,13 @@ class ComponentTest
        @Test\r
        void orTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire a = new Wire(4, 1), b = new Wire(4, 3), c = new Wire(4, 1);\r
-               new OrGate(1, c.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
+               t.reset();\r
+               Wire a = new Wire(t, 4, 1), b = new Wire(t, 4, 3), c = new Wire(t, 4, 1);\r
+               new OrGate(t, 1, c.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
                a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ZERO);\r
                b.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(c.getValues(), Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ONE);\r
        }\r
@@ -206,14 +209,14 @@ class ComponentTest
        @Test\r
        void xorTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire a = new Wire(3, 1), b = new Wire(3, 2), c = new Wire(3, 1), d = new Wire(3, 1);\r
-               new XorGate(1, d.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
+               t.reset();\r
+               Wire a = new Wire(t, 3, 1), b = new Wire(t, 3, 2), c = new Wire(t, 3, 1), d = new Wire(t, 3, 1);\r
+               new XorGate(t, 1, d.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
                a.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ONE);\r
                b.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE);\r
                c.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(d.getValues(), Bit.ZERO, Bit.ONE, Bit.ONE);\r
        }\r
@@ -221,12 +224,12 @@ class ComponentTest
        @Test\r
        void notTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire a = new Wire(3, 1), b = new Wire(3, 2);\r
-               new NotGate(1, a.createReadOnlyEnd(), b.createReadWriteEnd());\r
+               t.reset();\r
+               Wire a = new Wire(t, 3, 1), b = new Wire(t, 3, 2);\r
+               new NotGate(t, 1, a.createReadOnlyEnd(), b.createReadWriteEnd());\r
                a.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ONE);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertBitArrayEquals(b.getValues(), Bit.ONE, Bit.ZERO, Bit.ZERO);\r
        }\r
@@ -234,33 +237,34 @@ class ComponentTest
        @Test\r
        void rsLatchCircuitTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire r = new Wire(1, 1), s = new Wire(1, 1), t1 = new Wire(1, 15), t2 = new Wire(1, 1), q = new Wire(1, 1), nq = new Wire(1, 1);\r
+               t.reset();\r
+               Wire r = new Wire(t, 1, 1), s = new Wire(t, 1, 1), t1 = new Wire(t, 1, 15), t2 = new Wire(t, 1, 1), q = new Wire(t, 1, 1),\r
+                               nq = new Wire(t, 1, 1);\r
 \r
-               new OrGate(1, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());\r
-               new OrGate(1, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());\r
-               new NotGate(1, t2.createReadOnlyEnd(), q.createReadWriteEnd());\r
-               new NotGate(1, t1.createReadOnlyEnd(), nq.createReadWriteEnd());\r
+               new OrGate(t, 1, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());\r
+               new OrGate(t, 1, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());\r
+               new NotGate(t, 1, t2.createReadOnlyEnd(), q.createReadWriteEnd());\r
+               new NotGate(t, 1, t1.createReadOnlyEnd(), nq.createReadWriteEnd());\r
 \r
                ReadWriteEnd sIn = s.createReadWriteEnd(), rIn = r.createReadWriteEnd();\r
 \r
                sIn.feedSignals(Bit.ONE);\r
                rIn.feedSignals(Bit.ZERO);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertEquals(Bit.ONE, q.getValue());\r
                assertEquals(Bit.ZERO, nq.getValue());\r
 \r
                sIn.feedSignals(Bit.ZERO);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
                assertEquals(Bit.ONE, q.getValue());\r
                assertEquals(Bit.ZERO, nq.getValue());\r
 \r
                rIn.feedSignals(Bit.ONE);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertEquals(Bit.ZERO, q.getValue());\r
                assertEquals(Bit.ONE, nq.getValue());\r
@@ -269,12 +273,12 @@ class ComponentTest
        @Test\r
        void numericValueTest()\r
        {\r
-               Simulation.TIMELINE.reset();\r
+               t.reset();\r
 \r
-               Wire a = new Wire(4, 1);\r
+               Wire a = new Wire(t, 4, 1);\r
                a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ONE, Bit.ONE);\r
 \r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
 \r
                assertEquals(15, a.getUnsignedValue());\r
                assertEquals(-1, a.getSignedValue());\r
@@ -283,29 +287,29 @@ class ComponentTest
        @Test\r
        void multipleInputs()\r
        {\r
-               Simulation.TIMELINE.reset();\r
-               Wire w = new Wire(2, 1);\r
+               t.reset();\r
+               Wire w = new Wire(t, 2, 1);\r
                ReadWriteEnd wI1 = w.createReadWriteEnd(), wI2 = w.createReadWriteEnd();\r
                wI1.feedSignals(Bit.ONE, Bit.Z);\r
                wI2.feedSignals(Bit.Z, Bit.X);\r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
                assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.X);\r
 \r
                wI2.feedSignals(Bit.ZERO, Bit.Z);\r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
                assertBitArrayEquals(w.getValues(), Bit.X, Bit.Z);\r
 \r
                wI2.feedSignals(Bit.Z, Bit.Z);\r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
                assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.Z);\r
 \r
                wI2.feedSignals(Bit.ONE, Bit.Z);\r
                ReadEnd rE = w.createReadOnlyEnd();\r
                rE.addObserver((i, oldValues) -> fail("WireEnd notified observer, although value did not change."));\r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
                rE.close();\r
                wI1.feedSignals(Bit.X, Bit.X);\r
-               Simulation.TIMELINE.executeAll();\r
+               t.executeAll();\r
                wI1.addObserver((i, oldValues) -> fail("WireEnd notified observer, although it was closed."));\r
                wI1.close();\r
                assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.Z);\r
@@ -316,17 +320,17 @@ class ComponentTest
        {\r
                // Nur ein Experiment, was über mehrere 'passive' Bausteine hinweg passieren würde\r
 \r
-               Simulation.TIMELINE.reset();\r
+               t.reset();\r
 \r
-               Wire a = new Wire(1, 2);\r
-               Wire b = new Wire(1, 2);\r
-               Wire c = new Wire(1, 2);\r
+               Wire a = new Wire(t, 1, 2);\r
+               Wire b = new Wire(t, 1, 2);\r
+               Wire c = new Wire(t, 1, 2);\r
                ReadWriteEnd aI = a.createReadWriteEnd();\r
                ReadWriteEnd bI = b.createReadWriteEnd();\r
                ReadWriteEnd cI = c.createReadWriteEnd();\r
 \r
-               TestBitDisplay test = new TestBitDisplay(c.createReadOnlyEnd());\r
-               TestBitDisplay test2 = new TestBitDisplay(a.createReadOnlyEnd());\r
+               TestBitDisplay test = new TestBitDisplay(t, c.createReadOnlyEnd());\r
+               TestBitDisplay test2 = new TestBitDisplay(t, a.createReadOnlyEnd());\r
                LongConsumer print = time -> System.out.format("Time %2d\n   a: %s\n   b: %s\n   c: %s\n", time, a, b, c);\r
 \r
                cI.feedSignals(Bit.ONE);\r
@@ -339,7 +343,7 @@ class ComponentTest
                cI.feedSignals(Bit.Z);\r
                test.assertAfterSimulationIs(print, Bit.Z);\r
 \r
-               new Connector(b.createReadWriteEnd(), c.createReadWriteEnd()).connect();\r
+               new Connector(t, b.createReadWriteEnd(), c.createReadWriteEnd()).connect();\r
                test.assertAfterSimulationIs(print, Bit.Z);\r
                System.err.println("ONE");\r
                bI.feedSignals(Bit.ONE);\r
@@ -351,7 +355,7 @@ class ComponentTest
                bI.feedSignals(Bit.Z);\r
                test.assertAfterSimulationIs(print, Bit.Z);\r
 \r
-               new Connector(a.createReadWriteEnd(), b.createReadWriteEnd()).connect();\r
+               new Connector(t, a.createReadWriteEnd(), b.createReadWriteEnd()).connect();\r
                System.err.println("Z 2");\r
                aI.feedSignals(Bit.Z);\r
                test.assertAfterSimulationIs(print, Bit.Z);\r
index 8ff7384..28798d4 100644 (file)
@@ -15,10 +15,10 @@ import javax.swing.JFrame;
 import javax.swing.JPanel;\r
 import javax.swing.WindowConstants;\r
 \r
-import era.mi.logic.Simulation;\r
 import era.mi.logic.components.ManualSwitch;\r
 import era.mi.logic.components.gates.NotGate;\r
 import era.mi.logic.components.gates.OrGate;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.timeline.Timeline.ExecutionResult;\r
 import era.mi.logic.wires.Wire;\r
 \r
@@ -31,20 +31,22 @@ public class GUITest extends JPanel
        private static final int OR_DELAY = 100;\r
        private static final int NOT_DELAY = 100;\r
 \r
-       Wire r = new Wire(1, WIRE_DELAY);\r
-       Wire s = new Wire(1, WIRE_DELAY);\r
-       Wire t1 = new Wire(1, WIRE_DELAY);\r
-       Wire t2 = new Wire(1, WIRE_DELAY);\r
-       Wire q = new Wire(1, WIRE_DELAY);\r
-       Wire nq = new Wire(1, WIRE_DELAY);\r
+       private Timeline t = new Timeline(11);\r
 \r
-       ManualSwitch rIn = new ManualSwitch(r.createReadWriteEnd());\r
-       ManualSwitch sIn = new ManualSwitch(s.createReadWriteEnd());\r
+       Wire r = new Wire(t, 1, WIRE_DELAY);\r
+       Wire s = new Wire(t, 1, WIRE_DELAY);\r
+       Wire t1 = new Wire(t, 1, WIRE_DELAY);\r
+       Wire t2 = new Wire(t, 1, WIRE_DELAY);\r
+       Wire q = new Wire(t, 1, WIRE_DELAY);\r
+       Wire nq = new Wire(t, 1, WIRE_DELAY);\r
 \r
-       OrGate or1 = new OrGate(OR_DELAY, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());\r
-       OrGate or2 = new OrGate(OR_DELAY, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());\r
-       NotGate not1 = new NotGate(NOT_DELAY, t2.createReadOnlyEnd(), q.createReadWriteEnd());\r
-       NotGate not2 = new NotGate(NOT_DELAY, t1.createReadOnlyEnd(), nq.createReadWriteEnd());\r
+       ManualSwitch rIn = new ManualSwitch(t, r.createReadWriteEnd());\r
+       ManualSwitch sIn = new ManualSwitch(t, s.createReadWriteEnd());\r
+\r
+       OrGate or1 = new OrGate(t, OR_DELAY, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());\r
+       OrGate or2 = new OrGate(t, OR_DELAY, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());\r
+       NotGate not1 = new NotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), q.createReadWriteEnd());\r
+       NotGate not2 = new NotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), nq.createReadWriteEnd());\r
 \r
        Map<ManualSwitch, Rectangle> switchMap = new HashMap<>();\r
 \r
@@ -109,6 +111,11 @@ public class GUITest extends JPanel
                });\r
        }\r
 \r
+       public Timeline getTimeline()\r
+       {\r
+               return t;\r
+       };\r
+\r
        @Override\r
        public void paint(Graphics some_g)\r
        {\r
@@ -275,9 +282,9 @@ public class GUITest extends JPanel
 \r
                while (f.isVisible())\r
                {\r
-                       ExecutionResult er = Simulation.TIMELINE.executeUpTo((lastFrame - begin) * 3, lastFrame + 14);\r
-//                             if (Simulation.TIMELINE.hasNext()) \r
-//                             Simulation.TIMELINE.executeNext();\r
+                       ExecutionResult er = gt.getTimeline().executeUpTo((lastFrame - begin) * 3, lastFrame + 14);\r
+//                             if (t.hasNext()) \r
+//                             t.executeNext();\r
                        if (er != ExecutionResult.NOTHING_DONE)\r
                                gt.repaint(12);\r
                        try\r
index b9de0cc..17a416c 100644 (file)
@@ -4,17 +4,17 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 \r
 import java.util.function.LongConsumer;\r
 \r
-import era.mi.logic.Simulation;\r
 import era.mi.logic.components.BitDisplay;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.Bit;\r
 import era.mi.logic.wires.Wire.ReadEnd;\r
 \r
 public final class TestBitDisplay extends BitDisplay\r
 {\r
 \r
-       public TestBitDisplay(ReadEnd in)\r
+       public TestBitDisplay(Timeline timeline, ReadEnd in)\r
        {\r
-               super(in);\r
+               super(timeline, in);\r
        }\r
 \r
        public void assertDisplays(Bit... expected)\r
@@ -24,16 +24,16 @@ public final class TestBitDisplay extends BitDisplay
 \r
        public void assertAfterSimulationIs(Bit... expected)\r
        {\r
-               Simulation.TIMELINE.executeAll();\r
+               timeline.executeAll();\r
                assertDisplays(expected);\r
        }\r
 \r
        public void assertAfterSimulationIs(LongConsumer r, Bit... expected)\r
        {\r
-               while (Simulation.TIMELINE.hasNext())\r
+               while (timeline.hasNext())\r
                {\r
-                       Simulation.TIMELINE.executeNext();\r
-                       r.accept(Simulation.TIMELINE.getSimulationTime());\r
+                       timeline.executeNext();\r
+                       r.accept(timeline.getSimulationTime());\r
                }\r
                assertDisplays(expected);\r
        }\r
index 88aa197..c22e1a4 100644 (file)
@@ -48,7 +48,7 @@ public class Timeline
         * 
         * @param timestamp  the simulation timestamp up to which the events will be processed
         * @param stopMillis the System.currentTimeMillis() when simulation definitely needs to stop. A value of -1 means no timeout.
-        * @return if it was possible to fulfil the goal in the given real world time.
+        * @return if it was possible to fulfill the goal in the given real world time.
         * @author Christian Femers
         */
        public ExecutionResult executeUpTo(long timestamp, long stopMillis)
index 3a71a36..3d4fd90 100644 (file)
@@ -6,7 +6,7 @@ import static era.mi.logic.types.Bit.Z;
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
 import era.mi.logic.types.Bit;\r
 import era.mi.logic.types.BitVector;\r
 import era.mi.logic.types.BitVector.BitVectorMutator;\r
@@ -24,12 +24,14 @@ public class Wire
        private List<ReadEnd> attached = new ArrayList<ReadEnd>();\r
        public final int length;\r
        private List<ReadWriteEnd> inputs = new ArrayList<ReadWriteEnd>();\r
+       private Timeline timeline;\r
 \r
-       public Wire(int length, int travelTime)\r
+       public Wire(Timeline timeline, int length, int travelTime)\r
        {\r
                if (length < 1)\r
                        throw new IllegalArgumentException(\r
                                        String.format("Tried to create an array of wires with length %d, but a length of less than 1 makes no sense.", length));\r
+               this.timeline = timeline;\r
                this.length = length;\r
                this.travelTime = travelTime;\r
                initValues();\r
@@ -379,7 +381,7 @@ public class Wire
                                                String.format("Attempted to input %d bits instead of %d bits.", newValues.length(), length));\r
                        if (!open)\r
                                throw new RuntimeException("Attempted to write to closed WireArrayEnd.");\r
-                       Simulation.TIMELINE.addEvent(e -> setValues(newValues), travelTime);\r
+                       timeline.addEvent(e -> setValues(newValues), travelTime);\r
                }\r
 \r
                /**\r
@@ -394,7 +396,7 @@ public class Wire
                {\r
                        if (!open)\r
                                throw new RuntimeException("Attempted to write to closed WireArrayEnd.");\r
-                       Simulation.TIMELINE.addEvent(e -> setValues(startingBit, bitVector), travelTime);\r
+                       timeline.addEvent(e -> setValues(startingBit, bitVector), travelTime);\r
                }\r
 \r
                private void setValues(int startingBit, BitVector newValues)\r