1 package net.sf.openrocket.simulation.listeners;
3 import java.util.Collection;
4 import java.util.Collections;
6 import net.sf.openrocket.simulation.FlightEvent;
7 import net.sf.openrocket.simulation.SimulationStatus;
10 public class StopSimulationListener extends AbstractSimulationListener {
12 private final int REPORT = 500;
14 private final double stopTime;
15 private final int stopStep;
19 private long startTime = -1;
20 private long time = -1;
22 public StopSimulationListener(double t, int n) {
29 public Collection<FlightEvent> handleEvent(FlightEvent event,
30 SimulationStatus status) {
32 if (event.getType() == FlightEvent.Type.LAUNCH) {
33 System.out.println("Simulation starting.");
34 time = System.nanoTime();
35 startTime = System.nanoTime();
42 public Collection<FlightEvent> stepTaken(SimulationStatus status) {
44 if ((step%REPORT) == 0) {
45 long t = System.nanoTime();
47 System.out.printf("Step %4d, time=%.3f, took %d us/step (avg. %d us/step)\n",
48 step,status.time,(t-time)/1000/REPORT,(t-startTime)/1000/step);
51 if (status.time >= stopTime || step >= stopStep) {
52 System.out.printf("Stopping simulation, step=%d time=%.3f\n",step,status.time);
53 return Collections.singleton(new FlightEvent(FlightEvent.Type.SIMULATION_END,