overhauled route search algorithm:
now using breadth-first search instead of depth-first search
This commit is contained in:
@@ -27,7 +27,6 @@ import de.srsoftware.web4rail.tags.Window;
|
||||
import de.srsoftware.web4rail.threads.DelayedExecution;
|
||||
|
||||
public class Contact extends Tile{
|
||||
private static Logger LOG = LoggerFactory.getLogger(Contact.class);
|
||||
private static final String ADDRESS = "address";
|
||||
private static final HashMap<Integer, Contact> contactsByAddr = new HashMap<Integer, Contact>();
|
||||
private boolean state = false;
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class Turnout extends Tile implements Device{
|
||||
@Override
|
||||
public Object click(boolean shift) throws IOException {
|
||||
LOG.debug(getClass().getSimpleName()+".click()");
|
||||
if (!shift) init();
|
||||
init();
|
||||
return super.click(shift);
|
||||
}
|
||||
|
||||
@@ -159,9 +159,13 @@ public abstract class Turnout extends Tile implements Device{
|
||||
return state;
|
||||
}
|
||||
|
||||
public Reply state(State newState) {
|
||||
public Reply state(State newState,boolean shift) {
|
||||
Train lockingTrain = lockingTrain();
|
||||
if (isSet(lockingTrain) && newState != state) return new Reply(415, t("{} locked by {}!",this,lockingTrain));
|
||||
|
||||
if (isSet(lockingTrain)) {
|
||||
if (newState != state && !shift) return new Reply(415, t("{} locked by {}!",this,lockingTrain));
|
||||
// shift allows to switch locked turnouts...
|
||||
} else if (shift) return new Reply(200,"OK"); // shift on a non-locked turnout skips the switch process
|
||||
if (address == 0) {
|
||||
sleep(300);
|
||||
state = newState;
|
||||
|
||||
@@ -15,7 +15,7 @@ public abstract class TurnoutL extends Turnout {
|
||||
@Override
|
||||
public Object click(boolean shift) throws IOException {
|
||||
Object o = super.click(shift);
|
||||
if (!shift) state(state == State.STRAIGHT ? State.LEFT : State.STRAIGHT);
|
||||
state(state == State.STRAIGHT ? State.LEFT : State.STRAIGHT,shift);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,12 @@ public abstract class TurnoutR extends Turnout {
|
||||
@Override
|
||||
public Object click(boolean shift) throws IOException {
|
||||
Object o = super.click(shift);
|
||||
if (!shift) state(state == State.STRAIGHT ? State.RIGHT : State.STRAIGHT);
|
||||
state(state == State.STRAIGHT ? State.RIGHT : State.STRAIGHT,shift);
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String commandFor(State newState) {
|
||||
|
||||
switch (newState) {
|
||||
case RIGHT:
|
||||
return "SET {} GA "+address+" "+portB+" 1 "+delay;
|
||||
|
||||
Reference in New Issue
Block a user