Renamed core components to have the common prefix Core
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / components / BasicCoreComponent.java
1 package net.mograsim.logic.core.components;
2
3 import net.mograsim.logic.core.LogicObservable;
4 import net.mograsim.logic.core.LogicObserver;
5 import net.mograsim.logic.core.timeline.Timeline;
6
7 /**
8  * A basic component that recomputes all outputs (with a delay), when it is updated.
9  * 
10  * @author Fabian Stemmler
11  */
12 public abstract class BasicCoreComponent extends CoreComponent implements LogicObserver
13 {
14         private int processTime;
15
16         /**
17          * 
18          * @param processTime Amount of time this component takes to update its outputs. Must be more than 0, otherwise 1 is assumed.
19          * 
20          * @author Fabian Stemmler
21          */
22         public BasicCoreComponent(Timeline timeline, int processTime)
23         {
24                 super(timeline);
25                 this.processTime = processTime > 0 ? processTime : 1;
26         }
27
28         @Override
29         public void update(LogicObservable initiator)
30         {
31                 timeline.addEvent(e -> compute(), processTime);
32         }
33
34         protected abstract void compute();
35 }