Commit 5052f989 authored by Jakob Schöttl's avatar Jakob Schöttl
Browse files

Merge branch 'targetlistener' into develop

parents 2136706f abfe2808
......@@ -12,6 +12,7 @@ import org.vadere.state.scenario.Car;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.TargetListener;
import org.vadere.state.scenario.Topography;
import org.vadere.state.types.TrafficLightPhase;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -63,6 +64,8 @@ public class TargetController {
if (isNextTargetForAgent(agent)
&& hasAgentReachedThisTarget(agent, reachedDistance)) {
notifyListenersTargetReached(agent);
if (target.getWaitingTime() <= 0) {
checkRemove(agent);
} else {
......@@ -160,4 +163,11 @@ public class TargetController {
}
}
}
private void notifyListenersTargetReached(final Agent agent) {
for (TargetListener l : target.getTargetListeners()) {
l.reachedTarget(target, agent);
}
}
}
package org.vadere.state.scenario;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import org.vadere.state.attributes.scenario.AttributesTarget;
......@@ -11,6 +14,9 @@ public class Target implements ScenarioElement, Comparable<Target> {
private final AttributesTarget attributes;
private final Map<Integer, Double> enteringTimes;
/** Collection of listeners - order does not play a role. */
private final Collection<TargetListener> targetListeners = new LinkedList<>();
public Target(AttributesTarget attributes) {
this(attributes, new HashMap<>());
......@@ -122,4 +128,18 @@ public class Target implements ScenarioElement, Comparable<Target> {
return this.getId() - otherTarget.getId();
}
/** Models can register a target listener. */
public void addListener(TargetListener listener) {
targetListeners.add(listener);
}
public boolean removeListener(TargetListener listener) {
return targetListeners.remove(listener);
}
/** Returns an unmodifiable collection. */
public Collection<TargetListener> getTargetListeners() {
return Collections.unmodifiableCollection(targetListeners);
}
}
package org.vadere.state.scenario;
public interface TargetListener {
void reachedTarget(Target target, Agent agent);
}
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