Commit 63745910 authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

remove 2 in-code TODOs and rename variables to better match Java conventions

parent 4a8b7a9a
......@@ -17,10 +17,7 @@ import org.vadere.simulator.projects.SimulationResult;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.json.EventInfo;
import org.vadere.state.events.types.ElapsedTimeEvent;
import org.vadere.state.events.types.Event;
import org.vadere.state.events.types.EventTimeframe;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Target;
......@@ -44,8 +41,8 @@ public class Simulation {
private final List<PassiveCallback> passiveCallbacks;
private List<Model> models;
private boolean runSimulation = false;
private boolean paused = false;
private boolean isRunSimulation = false;
private boolean isPaused = false;
/**
* current simulation time (seconds)
*/
......@@ -74,7 +71,9 @@ public class Simulation {
private final CognitionLayer cognitionLayer;
public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore,
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager, SimulationResult simulationResult) {
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager,
SimulationResult simulationResult) {
this.name = name;
this.mainModel = mainModel;
this.scenarioStore = scenarioStore;
......@@ -152,7 +151,7 @@ public class Simulation {
simulationState = initialSimulationState();
topographyController.preLoop(simTimeInSec);
runSimulation = true;
isRunSimulation = true;
simTimeInSec = startTimeInSec;
for (Model m : models) {
......@@ -198,15 +197,15 @@ public class Simulation {
preLoop();
while (runSimulation) {
while (isRunSimulation) {
synchronized (this) {
while (paused) {
while (isPaused) {
try {
wait();
} catch (Exception e) {
paused = false;
isPaused = false;
Thread.currentThread().interrupt();
logger.warn("interrupt while paused.");
logger.warn("interrupt while isPaused.");
}
}
}
......@@ -234,17 +233,16 @@ public class Simulation {
if (runTimeInSec + startTimeInSec > simTimeInSec + 1e-7) {
simTimeInSec += Math.min(attributesSimulation.getSimTimeStepLength(), runTimeInSec + startTimeInSec - simTimeInSec);
} else {
runSimulation = false;
isRunSimulation = false;
}
//remove comment to fasten simulation for evacuation simulations
//if (topography.getElements(Pedestrian.class).size() == 0){
// runSimulation = false;
// isRunSimulation = false;
//}
if (Thread.interrupted()) {
runSimulation = false;
isRunSimulation = false;
simulationResult.setState("Simulation interrupted");
logger.info("Simulation interrupted.");
}
......@@ -281,9 +279,9 @@ public class Simulation {
}
private void updateCallbacks(double simTimeInSec) {
List<Event> events = eventController.getEventsForTime(simTimeInSec);
List<Event> events = eventController.getEventsForTime(simTimeInSec);
// TODO Why are target controllers readded in each simulation loop?
// TODO Why are target controllers readded in each simulation loop?
this.targetControllers.clear();
for (Target target : this.topographyController.getTopography().getTargets()) {
targetControllers.add(new TargetController(this.topographyController.getTopography(), target));
......@@ -317,19 +315,19 @@ public class Simulation {
}
public synchronized void pause() {
paused = true;
isPaused = true;
}
public synchronized boolean isPaused() {
return paused;
return isPaused;
}
public synchronized boolean isRunning() {
return runSimulation && !isPaused();
return isRunSimulation && !isPaused();
}
public synchronized void resume() {
paused = false;
isPaused = false;
notify();
}
......@@ -354,7 +352,7 @@ public class Simulation {
try {
Thread.sleep(waitTime);
} catch (InterruptedException e) {
runSimulation = false;
isRunSimulation = false;
logger.info("Simulation interrupted.");
}
}
......
......@@ -13,9 +13,7 @@ import java.util.Random;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.system.CallbackI;
import org.vadere.simulator.control.PassiveCallback;
import org.vadere.simulator.control.Simulation;
import org.vadere.simulator.models.MainModel;
......@@ -115,7 +113,9 @@ public class ScenarioRun implements Runnable {
sealAllAttributes();
// Run simulation main loop from start time = 0 seconds
simulation = new Simulation(mainModel, 0, scenarioStore.getName(), scenarioStore, passiveCallbacks, random, processorManager, simulationResult);
simulation = new Simulation(mainModel, 0,
scenarioStore.getName(), scenarioStore, passiveCallbacks, random,
processorManager, simulationResult);
}
simulation.run();
simulationResult.setState("SimulationRun completed");
......@@ -132,8 +132,8 @@ public class ScenarioRun implements Runnable {
}
public void simulationFailed(Throwable e) {
e.printStackTrace();
logger.error(e);
e.printStackTrace();
logger.error(e);
}
protected void doAfterSimulation() {
......@@ -174,13 +174,23 @@ public class ScenarioRun implements Runnable {
}
public void pause() {
if (simulation != null) { // TODO throw an illegal state exception if simulation is not running
if(! simulation.isRunning()){
throw new IllegalStateException("Received trigger to pause the simulation, but it is not running!");
}
if (simulation != null) {
simulation.pause();
}
}
public void resume() {
if (simulation != null) { // TODO throw an illegal state exception if simulation is not running
if(simulation.isRunning()){
throw new IllegalStateException("Received trigger to resume the simulation, but it is not paused!");
}
if (simulation != null) {
simulation.resume();
}
}
......@@ -189,7 +199,7 @@ public class ScenarioRun implements Runnable {
try {
// Create output directory
Files.createDirectories(outputPath);
processorManager.setOutputPath(outputPath.toString());
processorManager.setOutputFiles(outputPath.toString());
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
......@@ -200,6 +210,7 @@ public class ScenarioRun implements Runnable {
return scenario.getName();
}
@Deprecated // Deprecated, because it is currently not used in code anymore
public String readyToRunResponse() { // TODO [priority=medium] [task=check] add more conditions
if (scenarioStore.getMainModel() == null) {
return scenarioStore.getName() + ": no mainModel is set";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment