projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Timeline now passed via constructor
[Mograsim.git]
/
era.mi
/
src
/
era
/
mi
/
logic
/
timeline
/
Timeline.java
diff --git
a/era.mi/src/era/mi/logic/timeline/Timeline.java
b/era.mi/src/era/mi/logic/timeline/Timeline.java
index
8107db9
..
c22e1a4
100644
(file)
--- a/
era.mi/src/era/mi/logic/timeline/Timeline.java
+++ b/
era.mi/src/era/mi/logic/timeline/Timeline.java
@@
-20,13
+20,7
@@
public class Timeline
public Timeline(int initCapacity)
{
public Timeline(int initCapacity)
{
- events = new PriorityQueue<InnerEvent>(initCapacity, (a, b) ->
- {
- long difference = a.getTiming() - b.getTiming();
- if (difference == 0)
- return 0;
- return difference < 0 ? -1 : 1;
- });
+ events = new PriorityQueue<InnerEvent>(initCapacity);
eventAddedListener = new ArrayList<>();
}
eventAddedListener = new ArrayList<>();
}
@@
-38,9
+32,9
@@
public class Timeline
public void executeNext()
{
public void executeNext()
{
- InnerEvent first = events.p
oll
();
- currentTime = first.getTiming();
-
first.run(
);
+ InnerEvent first = events.p
eek
();
+ if (first != null)
+
executeUpTo(first.getTiming(), -1
);
}
public void executeAll()
}
public void executeAll()
@@
-53,8
+47,8
@@
public class Timeline
* Executes all events up to a given simulation timestamp. The simulation process can be constrained by a real world timestamp.
*
* @param timestamp the simulation timestamp up to which the events will be processed
* Executes all events up to a given simulation timestamp. The simulation process can be constrained by a real world timestamp.
*
* @param timestamp the simulation timestamp up to which the events will be processed
- * @param stopMillis the System.currentTimeMillis() when simulation definitely needs to stop.
- * @return if it was possible to fulfil the goal in the given real world time.
+ * @param stopMillis the System.currentTimeMillis() when simulation definitely needs to stop.
A value of -1 means no timeout.
+ * @return if it was possible to fulfil
l
the goal in the given real world time.
* @author Christian Femers
*/
public ExecutionResult executeUpTo(long timestamp, long stopMillis)
* @author Christian Femers
*/
public ExecutionResult executeUpTo(long timestamp, long stopMillis)
@@
-90,7
+84,7
@@
public class Timeline
{
if (!hasNext())
return -1;
{
if (!hasNext())
return -1;
- return events.peek().
timing
;
+ return events.peek().
getTiming()
;
}
public void reset()
}
public void reset()
@@
-119,14
+113,12
@@
public class Timeline
{
long timing = currentTime + relativeTiming;
TimelineEvent event = new TimelineEvent(timing);
{
long timing = currentTime + relativeTiming;
TimelineEvent event = new TimelineEvent(timing);
- events.add(new InnerEvent(function, event
, timing
));
+ events.add(new InnerEvent(function, event));
eventAddedListener.forEach(l -> l.accept(event));
}
eventAddedListener.forEach(l -> l.accept(event));
}
- private class InnerEvent
+ private class InnerEvent
implements Runnable, Comparable<InnerEvent>
{
{
-
- final long timing;
private final TimelineEventHandler function;
private final TimelineEvent event;
private final TimelineEventHandler function;
private final TimelineEvent event;
@@
-136,18
+128,18
@@
public class Timeline
* @param function {@link TimelineEventHandler} to be executed when the {@link InnerEvent} occurs
* @param timing Point in the MI simulation {@link Timeline}, at which the {@link InnerEvent} is executed;
*/
* @param function {@link TimelineEventHandler} to be executed when the {@link InnerEvent} occurs
* @param timing Point in the MI simulation {@link Timeline}, at which the {@link InnerEvent} is executed;
*/
- InnerEvent(TimelineEventHandler function, TimelineEvent event
, long timing
)
+ InnerEvent(TimelineEventHandler function, TimelineEvent event)
{
this.function = function;
this.event = event;
{
this.function = function;
this.event = event;
- this.timing = timing;
}
public long getTiming()
{
}
public long getTiming()
{
- return
timing
;
+ return
event.getTiming()
;
}
}
+ @Override
public void run()
{
function.handle(event);
public void run()
{
function.handle(event);
@@
-158,6
+150,15
@@
public class Timeline
{
return event.toString();
}
{
return event.toString();
}
+
+ @Override
+ public int compareTo(InnerEvent o)
+ {
+ long difference = getTiming() - o.getTiming();
+ if (difference == 0)
+ return 0;
+ return difference < 0 ? -1 : 1;
+ }
}
@Override
}
@Override