summaryrefslogtreecommitdiff
path: root/opendc-core/src/main
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2017-09-06 14:53:01 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2017-09-06 15:20:32 +0200
commit823bb2d217e6b35b1811b5f52016d8d9de09435d (patch)
tree20f05d965f13bde7dfcbc7a7e744a367d2442588 /opendc-core/src/main
parent36b36970623a503228c80b7148a83ca95e338334 (diff)
Implement time jumps to next event
This change implements a time jump to the next event in the queue if there are no events scheduled for the current tick.
Diffstat (limited to 'opendc-core/src/main')
-rw-r--r--opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt10
1 files changed, 6 insertions, 4 deletions
diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt
index 6b7407e5..764134e5 100644
--- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt
+++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt
@@ -121,13 +121,15 @@ class OmegaSimulator(override val topology: Topology): Simulator, Iterator<Unit>
while (true) {
val (tick, block) = clock.queue.peek() ?: return
- if (tick > clock.tick)
+ if (tick > clock.tick) {
// Tick has yet to occur
+ // Jump in time to next event
+ clock.tick = tick - 1
break
- else if (tick < clock.tick)
+ } else if (tick < clock.tick) {
// Tick has already occurred
- logger.warn {"tick was not handled correctly"}
-
+ logger.warn { "tick was not handled correctly" }
+ }
clock.queue.poll()
block()
}