X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FBasicCoreComponent.java;fp=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FBasicCoreComponent.java;h=9f3da4a238464d2d24f378ba83e56784d89478e6;hb=0a04a4ed66ecebd4254541c4977599f6052c115a;hp=0000000000000000000000000000000000000000;hpb=9b4850366c29fbd800ee8df1858c398d8c35a0c0;p=Mograsim.git 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 index 00000000..9f3da4a2 --- /dev/null +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicCoreComponent.java @@ -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(); +}