Routenplaner scheint nun endlich sauber zu funktionieren.
Es müssen natürlich wieder einige Dinge nachimplementiert werden.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.3.73</version>
|
||||
<version>1.4.0</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -392,13 +392,14 @@ public class Route extends BaseClass {
|
||||
public void finish(Train train) {
|
||||
LOG.debug("{}.finish()",this);
|
||||
train.endRoute(endBlock,endDirection);
|
||||
free();
|
||||
freeIgnoring(null);
|
||||
train = null;
|
||||
}
|
||||
|
||||
private void free() {
|
||||
private void freeIgnoring(Vector<Tile> skipTiles) {
|
||||
Train train = context.train();
|
||||
Vector<Tile> reversedPath = reverse(path());
|
||||
if (isSet(skipTiles)) reversedPath.removeAll(skipTiles);
|
||||
for (Tile tile : reversedPath) {
|
||||
if (isSet(train) && !train.onTrace(tile)) tile.free(train);
|
||||
}
|
||||
@@ -693,6 +694,8 @@ public class Route extends BaseClass {
|
||||
nextRoutePrepper = null;
|
||||
});
|
||||
nextRoutePrepper.onFail(() -> {
|
||||
Route rt = nextRoutePrepper.route(); // Nachfolgeroute kann ja schon reserviert sein, oder gar schon teilweise vorbereitet!
|
||||
if (isSet(rt)) rt.resetIgnoring(this); // angefangene Route freigeben ohne Teile der aktuellen Route freizugeben
|
||||
nextRoutePrepper = null;
|
||||
});
|
||||
return nextRoutePrepper.prepareRoute();
|
||||
@@ -766,7 +769,7 @@ public class Route extends BaseClass {
|
||||
|
||||
public boolean reserveFor(Context newContext) {
|
||||
LOG.debug("{}.reserverFor({})",this,newContext);
|
||||
// if (isSet(context)) return false; // route already has context!
|
||||
|
||||
context = newContext;
|
||||
for (Tile tile : path) {
|
||||
if (newContext.invalidated() || !tile.reserveFor(newContext)) {
|
||||
@@ -777,15 +780,18 @@ public class Route extends BaseClass {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean reset() {
|
||||
LOG.debug("{}.reset()",this);
|
||||
public void reset() {
|
||||
resetIgnoring(null);
|
||||
}
|
||||
|
||||
public void resetIgnoring(Route otherRoute) {
|
||||
LOG.debug("{}.resetIgnoring({})",this,otherRoute);
|
||||
resetNext();
|
||||
setSignals(Signal.RED);
|
||||
Train train = context.train();
|
||||
free();
|
||||
freeIgnoring(isSet(otherRoute) ? otherRoute.path : null);
|
||||
train.drop(this);
|
||||
context = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void resetNext() {
|
||||
|
||||
@@ -721,9 +721,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
public String quitAutopilot() {
|
||||
if (isSet(routePrepper)) routePrepper.stop();
|
||||
// if (isSet(route)) route.resetNext();
|
||||
autopilot = false;
|
||||
return t("Autopilot already was disabled!");
|
||||
try {
|
||||
return autopilot ? t("Autopilot disabled") : t("Autopilot already was disabled!");
|
||||
} finally {
|
||||
autopilot = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -916,7 +918,19 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
});
|
||||
|
||||
routePrepper.onFail(() -> {
|
||||
Route failedRoute = routePrepper.route();
|
||||
routePrepper = null;
|
||||
if (isSet(failedRoute)) failedRoute.reset();
|
||||
LOG.debug("Starting {} failed due to unavailable route!",this);
|
||||
if (autopilot) new DelayedExecution(250,this) {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
if (autopilot) {
|
||||
Train.this.start(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
routePrepper.start();
|
||||
|
||||
@@ -162,6 +162,13 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fail() {
|
||||
notify(failListeners);
|
||||
// if (isSet(route) route.reset();
|
||||
route = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onFail(EventListener l) {
|
||||
failListeners.add(l);
|
||||
}
|
||||
@@ -181,28 +188,16 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
||||
|
||||
|
||||
public boolean prepareRoute() {
|
||||
try {
|
||||
if (isNull(context) || context.invalidated()) return false;
|
||||
route = chooseRoute(context);
|
||||
if (isNull(route)) return false;
|
||||
context.route(route);
|
||||
notify(foundListeners);
|
||||
if (!route.reserveFor(context)) {
|
||||
route.reset();
|
||||
route = null;
|
||||
return false;
|
||||
}
|
||||
notify(lockedListeners);
|
||||
if (!route.prepareAndLock()) {
|
||||
route.reset();
|
||||
route = null;
|
||||
return false;
|
||||
}
|
||||
notify(preparedListeners);
|
||||
return true;
|
||||
} finally {
|
||||
if (isNull(route)) notify(failListeners);
|
||||
}
|
||||
if (isNull(context) || context.invalidated()) return fail();
|
||||
route = chooseRoute(context);
|
||||
if (isNull(route)) return fail();
|
||||
context.route(route);
|
||||
notify(foundListeners);
|
||||
if (!route.reserveFor(context)) return fail();
|
||||
notify(lockedListeners);
|
||||
if (!route.prepareAndLock()) return fail();
|
||||
notify(preparedListeners);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ public abstract class Block extends StretchableTile{
|
||||
|
||||
@Override
|
||||
public boolean free(Train train) {
|
||||
LOG.debug("{}.free()");
|
||||
LOG.debug("{}.free({})",this,train);
|
||||
Train firstTrain = trains.first();
|
||||
if (isNull(firstTrain)) return true;
|
||||
if (firstTrain != train) return false;
|
||||
|
||||
Reference in New Issue
Block a user