@Override public void handleEvent(Event e) { if (clock.getCurrentTime() == 0) { dispatchSetupEvents(); } if (sc.endOfScenario) { clock.stop(); } } }, Clock.ClockEventType.STARTED);
/** * @return The time step (in simulation time) which is added to current time * at every tick. */ public long getTimeStep() { return clock.getTickLength(); }
/** * Stops the simulation. */ public void stop() { clock.stop(); }
@Override public void handleEvent(@Nullable org.eclipse.swt.widgets.Event event) { clockController.stop(); while (clockController.isTicking()) { // wait until clock actually stops (it finishes its // current tick first). } if (isDisplayOwner && !display.isDisposed()) { display.dispose(); } else if (!isDisplayOwner && !shell.isDisposed()) { shell.dispose(); } } });
/** * @return The current simulation time. */ public long getCurrentTime() { return clock.getCurrentTime(); }
@Override public void run() { if (!canvas.isDisposed()) { if (clock.getTickLength() > TIME_FORMATTER_THRESHOLD) { final StringBuilder sb = new StringBuilder(); sb.append(FORMATTER.print(new Period(0, clock.getCurrentTime()))); if (isRealtime) { sb.append(SPACE); sb.append( ((RealtimeClockController) clock).getClockMode().name()); } timeLabel.setText(sb.toString()); } else { timeLabel.setText(Long.toString(clock.getCurrentTime())); } timeLabel.pack(); canvas.redraw(); } } });
/** * @return true if simulator is playing, false otherwise. */ public boolean isPlaying() { return clock.isTicking(); }
ScenarioController(SimulatorAPI sim, ClockController c, Scenario s, ImmutableMap<Class<? extends TimedEvent>, TimedEventHandler<?>> m, int t) { simulator = sim; clock = c; ticks = t; scenario = s; scenarioQueue = scenario.asQueue(); handlers = m; disp = new EventDispatcher(EventType.values()); final ScenarioController sc = this; clock.getEventAPI().addListener(new Listener() { @Override public void handleEvent(Event e) { if (clock.getCurrentTime() == 0) { dispatchSetupEvents(); } if (sc.endOfScenario) { clock.stop(); } } }, Clock.ClockEventType.STARTED); }
/** * Advances the time a single tick. */ public void tick() { clock.tick(); }
/** * Start the simulation. */ public void start() { if (modelManager.getUserInterface().isPresent()) { modelManager.getUserInterface().get().show(); } else { clock.start(); } }
private void stopClock(TimeLapse timeLapse) { LOGGER.info("scenario finished at virtual time:" + timeLapse.getTime() + "[stopping simulation]"); clock.stop(); }
@Override public void register(Object obj) { LOGGER.info("{} - register({})", clock.getCurrentTime(), obj); modelManager.register(obj); }
/** * Either starts or stops the simulation depending on the current state. */ public void togglePlayPause() { if (!clock.isTicking()) { start(); } else { stop(); } }
ScenarioController(SimulatorAPI sim, ClockController c, Scenario s, ImmutableMap<Class<? extends TimedEvent>, TimedEventHandler<?>> m, int t) { simulator = sim; clock = c; ticks = t; scenario = s; scenarioQueue = scenario.asQueue(); handlers = m; disp = new EventDispatcher(EventType.values()); final ScenarioController sc = this; clock.getEventAPI().addListener(new Listener() { @Override public void handleEvent(Event e) { if (clock.getCurrentTime() == 0) { dispatchSetupEvents(); } if (sc.endOfScenario) { clock.stop(); } } }, Clock.ClockEventType.STARTED); }
controller.getEventAPI().addListener(leh); controller.clock.tick();
@Override public void handleEvent(Event e) { if (clock.getCurrentTime() == 0) { dispatchSetupEvents(); } if (sc.endOfScenario) { clock.stop(); } } }, Clock.ClockEventType.STARTED);
private void stopClock(TimeLapse timeLapse) { LOGGER.info("scenario finished at virtual time:" + timeLapse.getTime() + "[stopping simulation]"); clock.stop(); }