X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FBasicComponent.java;fp=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FBasicComponent.java;h=426c6a11daddef394b085a24ce11c36bf07fd08f;hb=07faf07e3acb8b2afdc2bf65a46bc868faaed0f8;hp=0000000000000000000000000000000000000000;hpb=0009789a8df6b8d4562b6e1cbfa75102a7516ea8;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicComponent.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicComponent.java new file mode 100644 index 00000000..426c6a11 --- /dev/null +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/BasicComponent.java @@ -0,0 +1,36 @@ +package net.mograsim.logic.core.components; + +import net.mograsim.logic.core.timeline.Timeline; +import net.mograsim.logic.core.types.BitVector; +import net.mograsim.logic.core.wires.WireObserver; +import net.mograsim.logic.core.wires.Wire.ReadEnd; + +/** + * A basic component that recomputes all outputs (with a delay), when it is updated. + * + * @author Fabian Stemmler + */ +public abstract class BasicComponent extends Component implements WireObserver +{ + 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 BasicComponent(Timeline timeline, int processTime) + { + super(timeline); + this.processTime = processTime > 0 ? processTime : 1; + } + + @Override + public void update(ReadEnd initiator, BitVector oldValues) + { + timeline.addEvent(e -> compute(), processTime); + } + + protected abstract void compute(); +}