X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fnet.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FBasicCoreComponent.java;fp=plugins%2Fnet.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FBasicCoreComponent.java;h=c82f2b37ddcb6f746dedd42d471dd163d4ccb154;hb=7d05144c25daa53e60fc9ed9fd503546a86567f8;hp=0000000000000000000000000000000000000000;hpb=8bed58cd47f4e53a0a83e066d38864aa6875502f;p=Mograsim.git diff --git a/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicCoreComponent.java b/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicCoreComponent.java new file mode 100644 index 00000000..c82f2b37 --- /dev/null +++ b/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicCoreComponent.java @@ -0,0 +1,43 @@ +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; +import net.mograsim.logic.core.timeline.TimelineEventHandler; + +/** + * 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 final void update(LogicObservable initiator) + { + update(); + } + + public void update() + { + TimelineEventHandler delayedUpdates = compute(); + if (delayedUpdates != null) + timeline.addEvent(delayedUpdates, processTime); + } + + protected abstract TimelineEventHandler compute(); +}