Merge branch 'development' of
[Mograsim.git] / LogicUI / src / era / mi / gui / LogicUIStandalone.java
index 8bbfb1c..8e37be8 100644 (file)
@@ -8,6 +8,9 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;\r
 \r
 import era.mi.gui.model.ViewModel;\r
+import era.mi.gui.modeladapter.LogicModelParameters;\r
+import era.mi.gui.modeladapter.ViewLogicModelAdapter;\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
@@ -19,6 +22,7 @@ import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInpu
 public class LogicUIStandalone\r
 {\r
        private ViewModel model;\r
+       private Timeline timeline;\r
 \r
        private final Display display;\r
        private final Shell shell;\r
@@ -37,6 +41,12 @@ public class LogicUIStandalone
                userInput.buttonZoom = 2;\r
                userInput.enableUserInput();\r
                new ZoomableCanvasOverlay(ui, null).enableScale();\r
+\r
+               // TODO don't do this here\r
+               LogicModelParameters params = new LogicModelParameters();\r
+               params.gateProcessTime = 50;\r
+               params.wireTravelTime = 10;\r
+               timeline = ViewLogicModelAdapter.convert(model, params);\r
        }\r
 \r
        public LogicUICanvas getLogicUICanvas()\r
@@ -50,34 +60,33 @@ public class LogicUIStandalone
        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.executeUntil(timeline.laterThan(System.currentTimeMillis()), System.currentTimeMillis() + 10);         \r
-//                             model.timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);\r
-//                             long sleepTime;\r
-//                             if (model.timeline.hasNext())\r
-//                                     sleepTime = model.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
-//             model.timeline.addEventAddedListener(event ->\r
-//             {\r
-//                     if (event.getTiming() <= System.currentTimeMillis())\r
-//                             simulationThread.interrupt();\r
-//             });\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.executeUntil(timeline.laterThan(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