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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.3.73</version>
|
<version>1.4.0</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -392,13 +392,14 @@ public class Route extends BaseClass {
|
|||||||
public void finish(Train train) {
|
public void finish(Train train) {
|
||||||
LOG.debug("{}.finish()",this);
|
LOG.debug("{}.finish()",this);
|
||||||
train.endRoute(endBlock,endDirection);
|
train.endRoute(endBlock,endDirection);
|
||||||
free();
|
freeIgnoring(null);
|
||||||
train = null;
|
train = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void free() {
|
private void freeIgnoring(Vector<Tile> skipTiles) {
|
||||||
Train train = context.train();
|
Train train = context.train();
|
||||||
Vector<Tile> reversedPath = reverse(path());
|
Vector<Tile> reversedPath = reverse(path());
|
||||||
|
if (isSet(skipTiles)) reversedPath.removeAll(skipTiles);
|
||||||
for (Tile tile : reversedPath) {
|
for (Tile tile : reversedPath) {
|
||||||
if (isSet(train) && !train.onTrace(tile)) tile.free(train);
|
if (isSet(train) && !train.onTrace(tile)) tile.free(train);
|
||||||
}
|
}
|
||||||
@@ -693,6 +694,8 @@ public class Route extends BaseClass {
|
|||||||
nextRoutePrepper = null;
|
nextRoutePrepper = null;
|
||||||
});
|
});
|
||||||
nextRoutePrepper.onFail(() -> {
|
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;
|
nextRoutePrepper = null;
|
||||||
});
|
});
|
||||||
return nextRoutePrepper.prepareRoute();
|
return nextRoutePrepper.prepareRoute();
|
||||||
@@ -766,7 +769,7 @@ public class Route extends BaseClass {
|
|||||||
|
|
||||||
public boolean reserveFor(Context newContext) {
|
public boolean reserveFor(Context newContext) {
|
||||||
LOG.debug("{}.reserverFor({})",this,newContext);
|
LOG.debug("{}.reserverFor({})",this,newContext);
|
||||||
// if (isSet(context)) return false; // route already has context!
|
|
||||||
context = newContext;
|
context = newContext;
|
||||||
for (Tile tile : path) {
|
for (Tile tile : path) {
|
||||||
if (newContext.invalidated() || !tile.reserveFor(newContext)) {
|
if (newContext.invalidated() || !tile.reserveFor(newContext)) {
|
||||||
@@ -777,15 +780,18 @@ public class Route extends BaseClass {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean reset() {
|
public void reset() {
|
||||||
LOG.debug("{}.reset()",this);
|
resetIgnoring(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetIgnoring(Route otherRoute) {
|
||||||
|
LOG.debug("{}.resetIgnoring({})",this,otherRoute);
|
||||||
resetNext();
|
resetNext();
|
||||||
setSignals(Signal.RED);
|
setSignals(Signal.RED);
|
||||||
Train train = context.train();
|
Train train = context.train();
|
||||||
free();
|
freeIgnoring(isSet(otherRoute) ? otherRoute.path : null);
|
||||||
train.drop(this);
|
train.drop(this);
|
||||||
context = null;
|
context = null;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetNext() {
|
public void resetNext() {
|
||||||
|
|||||||
@@ -721,9 +721,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
public String quitAutopilot() {
|
public String quitAutopilot() {
|
||||||
if (isSet(routePrepper)) routePrepper.stop();
|
if (isSet(routePrepper)) routePrepper.stop();
|
||||||
// if (isSet(route)) route.resetNext();
|
try {
|
||||||
autopilot = false;
|
return autopilot ? t("Autopilot disabled") : t("Autopilot already was disabled!");
|
||||||
return t("Autopilot already was disabled!");
|
} finally {
|
||||||
|
autopilot = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -916,7 +918,19 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
routePrepper.onFail(() -> {
|
routePrepper.onFail(() -> {
|
||||||
|
Route failedRoute = routePrepper.route();
|
||||||
routePrepper = null;
|
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();
|
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) {
|
public void onFail(EventListener l) {
|
||||||
failListeners.add(l);
|
failListeners.add(l);
|
||||||
}
|
}
|
||||||
@@ -181,28 +188,16 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
|||||||
|
|
||||||
|
|
||||||
public boolean prepareRoute() {
|
public boolean prepareRoute() {
|
||||||
try {
|
if (isNull(context) || context.invalidated()) return fail();
|
||||||
if (isNull(context) || context.invalidated()) return false;
|
route = chooseRoute(context);
|
||||||
route = chooseRoute(context);
|
if (isNull(route)) return fail();
|
||||||
if (isNull(route)) return false;
|
context.route(route);
|
||||||
context.route(route);
|
notify(foundListeners);
|
||||||
notify(foundListeners);
|
if (!route.reserveFor(context)) return fail();
|
||||||
if (!route.reserveFor(context)) {
|
notify(lockedListeners);
|
||||||
route.reset();
|
if (!route.prepareAndLock()) return fail();
|
||||||
route = null;
|
notify(preparedListeners);
|
||||||
return false;
|
return true;
|
||||||
}
|
|
||||||
notify(lockedListeners);
|
|
||||||
if (!route.prepareAndLock()) {
|
|
||||||
route.reset();
|
|
||||||
route = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
notify(preparedListeners);
|
|
||||||
return true;
|
|
||||||
} finally {
|
|
||||||
if (isNull(route)) notify(failListeners);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ public abstract class Block extends StretchableTile{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean free(Train train) {
|
public boolean free(Train train) {
|
||||||
LOG.debug("{}.free()");
|
LOG.debug("{}.free({})",this,train);
|
||||||
Train firstTrain = trains.first();
|
Train firstTrain = trains.first();
|
||||||
if (isNull(firstTrain)) return true;
|
if (isNull(firstTrain)) return true;
|
||||||
if (firstTrain != train) return false;
|
if (firstTrain != train) return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user