Renamed core components to have the common prefix Core
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / components / BasicCoreComponent.java
diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicCoreComponent.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicCoreComponent.java
new file mode 100644 (file)
index 0000000..9f3da4a
--- /dev/null
@@ -0,0 +1,35 @@
+package net.mograsim.logic.core.components;
+
+import net.mograsim.logic.core.LogicObservable;
+import net.mograsim.logic.core.LogicObserver;
+import net.mograsim.logic.core.timeline.Timeline;
+
+/**
+ * A basic component that recomputes all outputs (with a delay), when it is updated.
+ * 
+ * @author Fabian Stemmler
+ */
+public abstract class BasicCoreComponent extends CoreComponent implements LogicObserver
+{
+       private int processTime;
+
+       /**
+        * 
+        * @param processTime Amount of time this component takes to update its outputs. Must be more than 0, otherwise 1 is assumed.
+        * 
+        * @author Fabian Stemmler
+        */
+       public BasicCoreComponent(Timeline timeline, int processTime)
+       {
+               super(timeline);
+               this.processTime = processTime > 0 ? processTime : 1;
+       }
+
+       @Override
+       public void update(LogicObservable initiator)
+       {
+               timeline.addEvent(e -> compute(), processTime);
+       }
+
+       protected abstract void compute();
+}