Commit cad83b9a authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Proof of Concept: handle "ElapsedTime" and "Wait" event in...

Proof of Concept: handle "ElapsedTime" and "Wait" event in "UpdateSchemeEventDriven.java" and "UpdateSchemeSequential.java".
parent 94c9fd07
Pipeline #74633 failed with stages
in 170 minutes and 22 seconds
......@@ -2,6 +2,7 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.state.events.types.ElapsedTimeEvent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -41,20 +42,24 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
}
protected void update(@NotNull final PedestrianOSM pedestrian, final double currentTimeInSec) {
VPoint oldPosition = pedestrian.getPosition();
if (pedestrian.getMostImportantEvent() instanceof ElapsedTimeEvent) {
VPoint oldPosition = pedestrian.getPosition();
// for the first step after creation, timeOfNextStep has to be initialized
if (pedestrian.getTimeOfNextStep() == 0) {
pedestrian.setTimeOfNextStep(currentTimeInSec);
}
// for the first step after creation, timeOfNextStep has to be initialized
if (pedestrian.getTimeOfNextStep() == 0) {
pedestrian.setTimeOfNextStep(currentTimeInSec);
}
// this can cause problems if the pedestrian desired speed is 0 (see speed adjuster)
pedestrian.setDurationNextStep(pedestrian.getStepSize() / pedestrian.getDesiredSpeed());
pedestrian.updateNextPosition();
makeStep(topography, pedestrian, pedestrian.getDurationNextStep());
// this can cause problems if the pedestrian desired speed is 0 (see speed adjuster)
pedestrian.setDurationNextStep(pedestrian.getStepSize() / pedestrian.getDesiredSpeed());
pedestrian.updateNextPosition();
makeStep(topography, pedestrian, pedestrian.getDurationNextStep());
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
topography.moveElement(pedestrian, oldPosition);
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
topography.moveElement(pedestrian, oldPosition);
} else {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
}
}
@Override
......
......@@ -2,6 +2,7 @@ package org.vadere.simulator.models.osm.updateScheme;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.state.events.types.ElapsedTimeEvent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -29,18 +30,22 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM {
}
protected void update(@NotNull final PedestrianOSM pedestrian, final double timeStepInSec) {
VPoint oldPosition = pedestrian.getPosition();
pedestrian.clearStrides();
pedestrian.setTimeCredit(pedestrian.getTimeCredit() + timeStepInSec);
pedestrian.setDurationNextStep(pedestrian.getStepSize() / pedestrian.getDesiredSpeed());
while (pedestrian.getTimeCredit() > pedestrian.getDurationNextStep()) {
pedestrian.updateNextPosition();
makeStep(topography, pedestrian, timeStepInSec);
if (pedestrian.getMostImportantEvent() instanceof ElapsedTimeEvent) {
VPoint oldPosition = pedestrian.getPosition();
pedestrian.clearStrides();
pedestrian.setTimeCredit(pedestrian.getTimeCredit() + timeStepInSec);
pedestrian.setDurationNextStep(pedestrian.getStepSize() / pedestrian.getDesiredSpeed());
}
topography.moveElement(pedestrian, oldPosition);
while (pedestrian.getTimeCredit() > pedestrian.getDurationNextStep()) {
pedestrian.updateNextPosition();
makeStep(topography, pedestrian, timeStepInSec);
pedestrian.setDurationNextStep(pedestrian.getStepSize() / pedestrian.getDesiredSpeed());
}
topography.moveElement(pedestrian, oldPosition);
} else {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
}
}
@Override
......
Supports Markdown
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