fixed tracing bug and brake-time bug

This commit is contained in:
Stephan Richter
2021-02-16 09:16:54 +01:00
parent 8ab3b6d1a0
commit 80553efb29
4 changed files with 15 additions and 15 deletions

View File

@@ -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.43</version> <version>1.3.44</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>

View File

@@ -104,7 +104,7 @@ public class Route extends BaseClass {
timeStep = brakeTimes.get(brakeId); timeStep = brakeTimes.get(brakeId);
if (isNull(timeStep)) timeStep = 256; // if no brake time is available for this train if (isNull(timeStep) || timeStep>1000000) timeStep = 256; // if no brake time is available for this train
Application.threadPool.execute(this); Application.threadPool.execute(this);
} }
@@ -171,7 +171,7 @@ public class Route extends BaseClass {
private void increaseDistance(){ private void increaseDistance(){
long tick = timestamp(); long tick = timestamp();
estimatedDistance += train.speed * (5+tick-latestTick); estimatedDistance += train.speed * (3+tick-latestTick);
latestTick = tick; latestTick = tick;
} }
@@ -446,7 +446,6 @@ public class Route extends BaseClass {
ActionList actions = triggeredActions.get(contact.trigger()); ActionList actions = triggeredActions.get(contact.trigger());
LOG.debug("Contact has id {} / trigger {} and is assigned with {}",contact.id(),contact.trigger(),isNull(actions)?t("nothing"):actions); LOG.debug("Contact has id {} / trigger {} and is assigned with {}",contact.id(),contact.trigger(),isNull(actions)?t("nothing"):actions);
if (isNull(actions)) return; if (isNull(actions)) return;
traceTrainFrom(contact);
actions.fire(context); actions.fire(context);
} }
@@ -809,6 +808,7 @@ public class Route extends BaseClass {
LOG.debug("{}.moveTrainToEndBlock()",this); LOG.debug("{}.moveTrainToEndBlock()",this);
train.set(endBlock); train.set(endBlock);
traceTrainFrom(endBlock);
train.heading(endDirection); train.heading(endDirection);
if (endBlock == train.destination()) { if (endBlock == train.destination()) {
@@ -1059,7 +1059,7 @@ public class Route extends BaseClass {
return getClass().getSimpleName()+"("+(isSet(train)?train+":":"")+name()+")"; return getClass().getSimpleName()+"("+(isSet(train)?train+":":"")+name()+")";
} }
private void traceTrainFrom(Tile newHead) { public void traceTrainFrom(Tile newHead) {
LOG.debug("{}.traceTrainFrom({})",this,newHead); LOG.debug("{}.traceTrainFrom({})",this,newHead);
if (isNull(train)) return; if (isNull(train)) return;
if (newHead instanceof BlockContact) newHead = (Tile) ((BlockContact)newHead).parent(); if (newHead instanceof BlockContact) newHead = (Tile) ((BlockContact)newHead).parent();
@@ -1071,10 +1071,12 @@ public class Route extends BaseClass {
Tile tile = path.elementAt(i-1); Tile tile = path.elementAt(i-1);
if (isNull(remainingLength)) { if (isNull(remainingLength)) {
if (tile == newHead) traceHead = newHead; // wenn wir zuerst newHead finden: newHead als neuen traceHead übernehmen if (tile == newHead) traceHead = newHead; // wenn wir zuerst newHead finden: newHead als neuen traceHead übernehmen
if (tile == traceHead) remainingLength = train.length(); // sobald wir auf den traceHead stoßen: suche beenden if (tile == traceHead) {
remainingLength = train.length(); // sobald wir auf den traceHead stoßen: suche beenden
}
} }
if (isSet(remainingLength)) { if (isSet(remainingLength)) {
if (remainingLength>0) { if (remainingLength>=0) {
newTrace.add(tile); newTrace.add(tile);
remainingLength -= tile.length(); remainingLength -= tile.length();
} else if (Route.freeBehindTrain) { } else if (Route.freeBehindTrain) {

View File

@@ -896,17 +896,13 @@ public class Train extends BaseClass implements Comparable<Train> {
public void setTrace(LinkedList<Tile> newTrace) { public void setTrace(LinkedList<Tile> newTrace) {
LOG.debug("{}.setTrace({})",this,newTrace); LOG.debug("{}.setTrace({})",this,newTrace);
LOG.debug("old trace: {}",trace); LOG.debug("old trace: {}",trace);
if (isSet(trace)) {
trace.removeAll(newTrace); trace.removeAll(newTrace);
for (Tile tile : trace) tile.setTrain(null);
for (Tile tile : trace) {
tile.setTrain(null);
}
};
trace = newTrace; trace = newTrace;
for (Tile tile : trace) tile.setTrain(this); for (Tile tile : trace) tile.setTrain(this);
LOG.debug("new trace of {}: {}",this,trace); LOG.debug("new trace of {}: {}",this,trace);
} }
public void setWaitTime(Range waitTime) { public void setWaitTime(Range waitTime) {
@@ -971,6 +967,7 @@ public class Train extends BaseClass implements Comparable<Train> {
route.set(context); route.set(context);
if (isNull(error) && !route.prepare()) error = t("Was not able to fire all setup actions of route!"); if (isNull(error) && !route.prepare()) error = t("Was not able to fire all setup actions of route!");
} }
if (isNull(route)) return this; // route may have been canceled in between
if (isNull(error) && direction != route.startDirection) turn(); if (isNull(error) && direction != route.startDirection) turn();
if (isNull(error) && !route.start(this)) error = t("Was not able to assign {} to {}!",this,route); if (isNull(error) && !route.start(this)) error = t("Was not able to assign {} to {}!",this,route);

View File

@@ -86,6 +86,7 @@ public class Contact extends Tile{
Route route = route(); Route route = route();
Context context = isSet(route) ? route.context().contact(this) : new Context(this); Context context = isSet(route) ? route.context().contact(this) : new Context(this);
if (isSet(route)) route.traceTrainFrom(this);
actions.fire(context); actions.fire(context);
if (isSet(route)) route.contact(this); if (isSet(route)) route.contact(this);