Skip to content

Commit 902809c

Browse files
authored
Merge pull request #791 from Roeterdink/CorrectSwitchstand
Correct update for Switchstand signalscript function
2 parents 94da787 + 5bc890b commit 902809c

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

Source/Orts.Simulation/Simulation/Signalling/SIGSCRfile.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,13 @@ public int SH_function_value(SignalHead thisHead, SignalScripts.SCRScripts.SCRSt
14051405
// switchstand
14061406

14071407
case SignalScripts.SCRExternalFunctions.SWITCHSTAND:
1408-
return_value = thisHead.switchstand(parameter1_value, parameter2_value);
1408+
#if DEBUG_PRINT_PROCESS
1409+
if (TDB_debug_ref.Contains(thisHead.TDBIndex) || OBJ_debug_ref.Contains(thisHead.mainSignal.thisRef))
1410+
{
1411+
dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
1412+
}
1413+
#endif
1414+
return_value = thisHead.switchstand(parameter1_value, parameter2_value, dumpfile);
14091415
break;
14101416

14111417
// def_draw_state

Source/Orts.Simulation/Simulation/Signalling/SignalHead.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ public int id_sig_hasnormalsubtype(int sigId, int reqSubtype)
307307
return 0;
308308
}
309309

310-
public int switchstand(int aspect1, int aspect2)
310+
public int switchstand(int aspect1, int aspect2, string dumpfile)
311311
{
312-
return mainSignal.switchstand(aspect1, aspect2);
312+
return mainSignal.switchstand(aspect1, aspect2, dumpfile);
313313
}
314314

315315
/// <summary>

Source/Orts.Simulation/Simulation/Signalling/SignalObject.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ public int this_sig_hasnormalsubtype(int reqSubtype)
11591159
/// <summary>
11601160
/// switchstand : link signal with next switch and set aspect according to switch state
11611161
/// </summary>
1162-
public int switchstand(int aspect1, int aspect2)
1162+
public int switchstand(int aspect1, int aspect2, string dumpfile)
11631163
{
11641164
// if switch index not yet set, find first switch in path
11651165
if (!nextSwitchIndex.HasValue)
@@ -1206,13 +1206,23 @@ public int switchstand(int aspect1, int aspect2)
12061206

12071207
if (!switchFound)
12081208
{
1209+
if (dumpfile.Length > 1)
1210+
{
1211+
File.AppendAllText(dumpfile, "SWITCHSTAND : no switch found /n");
1212+
}
12091213
nextSwitchIndex = -1;
12101214
}
12111215
}
12121216

12131217
if (nextSwitchIndex >= 0)
12141218
{
12151219
TrackCircuitSection switchSection = signalRef.TrackCircuitList[nextSwitchIndex.Value];
1220+
if (dumpfile.Length > 1)
1221+
{
1222+
File.AppendAllText(dumpfile,
1223+
String.Format("SWITCHSTAND : switch found : {0}, switch state {1} \n", switchSection.Index, switchSection.JunctionLastRoute));
1224+
}
1225+
12161226
return switchSection.JunctionLastRoute == 0 ? aspect1 : aspect2;
12171227
}
12181228

Source/Orts.Simulation/Simulation/Signalling/Signals.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,13 +3011,13 @@ public void setSwitch(int nodeIndex, int switchPos, TrackCircuitSection thisSect
30113011
thisNode.TrJunctionNode.SelectedRoute = switchPos;
30123012
thisSection.JunctionLastRoute = switchPos;
30133013

3014-
// update any linked signals
3014+
// update any linked signals - perform state update only (to avoid problems with route setting)
30153015
if (thisSection.LinkedSignals != null)
30163016
{
30173017
foreach (int thisSignalIndex in thisSection.LinkedSignals)
30183018
{
30193019
SignalObject thisSignal = SignalObjects[thisSignalIndex];
3020-
thisSignal.Update();
3020+
thisSignal.StateUpdate();
30213021
}
30223022
}
30233023
}

0 commit comments

Comments
 (0)