Commit d8e40aa1 authored by Tobias Meuser's avatar Tobias Meuser Committed by Jose Ignacio Monreal Bailey
Browse files

Disabled component reuse per default

parent 70547348
......@@ -59,6 +59,8 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class VehicleMovementModel implements MovementModel, EventHandler, FutureLocationSensor {
private boolean _reuseComponents = false;
private static VehicleMovementModel MOVEMENT;
public static final double SCALING_FACTOR = 1.0;
......@@ -153,6 +155,14 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
this.height = height;
}
public void setReuseComponents(boolean pReuseComponents) {
_reuseComponents = pReuseComponents;
if (_reuseComponents) {
System.err.println("WARNING: Enabling the reuse of components might cause strange behaviors of your simulation!");
}
}
/**
* Adding an additional component to be moved by this movement model
* @param comp The component to be added.
......@@ -161,6 +171,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
public final void addComponent(SimLocationActuator comp) {
components.add(comp);
freeComponents.add(comp);
comp.updateCurrentLocation(new PositionVector(Double.NaN, Double.NaN));
}
/**
......@@ -330,20 +342,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
}
}
freeComponents.forEach((component) -> {
try {
RoutedNetLayer routedNetLayer = component.getHost().getComponent(RoutedNetLayer.class);
for (SimNetInterface netInterface : routedNetLayer.getSimNetworkInterfaces()) {
if (netInterface.isOnline()) {
netInterface.goOffline();
}
}
} catch (ComponentNotAvailableException e) {
e.printStackTrace();
}
component.updateCurrentLocation(new PositionVector(Double.NaN, Double.NaN));
});
// Reschedule next step
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0);
}
......@@ -363,8 +361,23 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
// Nothing to do here
}
freeComponents.add(simLocationActuator);
hostVehicleIDMatching.remove(simLocationActuator.getHost().getId());
try {
RoutedNetLayer routedNetLayer = simLocationActuator.getHost().getComponent(RoutedNetLayer.class);
for (SimNetInterface netInterface : routedNetLayer.getSimNetworkInterfaces()) {
if (netInterface.isOnline()) {
netInterface.goOffline();
}
}
} catch (ComponentNotAvailableException e) {
e.printStackTrace();
}
simLocationActuator.updateCurrentLocation(new PositionVector(Double.NaN, Double.NaN));
if (_reuseComponents) {
freeComponents.add(simLocationActuator);
}
}
}
}
......@@ -393,7 +406,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
idComponentMatcher.put(vehicle, simLocationActuator);
hostVehicleIDMatching.put(simLocationActuator.getHost().getId(), vehicle);
} else {
throw new RuntimeException("Unable to assign new components. Please increase node amount.");
throw new RuntimeException("Unable to assign new components. Please increase node amount" + (_reuseComponents?".":" or enable the reuse of components."));
}
}
return idComponentMatcher.get(vehicle);
......
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