Skip to content

Commit b92a7bf

Browse files
committed
Automatic merge of T1.5.1-687-gd279e384a and 17 pull requests
- Pull request #570 at c59c788: Experimental glTF 2.0 support with PBR lighting - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #865 at 67014b7: Dispatcher window improvements - Pull request #874 at f8dbeab: Dynamic brake controller refactoring - Pull request #875 at 43bf33e: Bug fix for https://bugs.launchpad.net/or/+bug/2036346 Player train switching doesn't work with 3D cabs - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #878 at 25f5e06: Implement Polach Adhesion - Pull request #882 at d8a1c4d: Blueprint/train car operations UI window - Pull request #883 at edcc2dd: SwitchPanel disconnect/connect handling - Pull request #885 at c81447b: feat: Add notifications to Menu - Pull request #886 at 7c4922e: Scene viewer extension to TrackViewer - Pull request #887 at 4665bda: docs: Document projects, assemblies, namespaces - Pull request #888 at d7daf62: docs: Document player application model - Pull request #889 at 43341cf: No speed update - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #893 at bf8876b: Signal errors - Pull request #894 at 794fddf: Correct Decrease Colour
19 parents ea1ee0b + d279e38 + c59c788 + d00beb9 + 67014b7 + f8dbeab + 43bf33e + f92de76 + 25f5e06 + d8a1c4d + edcc2dd + c81447b + 7c4922e + 4665bda + d7daf62 + 43341cf + 1f5ba4c + bf8876b + 794fddf commit b92a7bf

File tree

5 files changed

+157
-24
lines changed

5 files changed

+157
-24
lines changed

Source/Orts.Formats.Msts/SignalScripts.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public enum SCRExternalFunctions
7878
NEXT_SIG_ID,
7979
NEXT_NSIG_ID,
8080
OPP_SIG_ID,
81+
OPP_SIG_ID_TRAINPATH,
8182
ID_SIG_ENABLED,
8283
ID_SIG_LR,
8384
SIG_FEATURE,
@@ -2115,6 +2116,7 @@ public SCRStatement(scrReadInfo Statement, IDictionary<string, uint> LocalFloats
21152116
// if only 1 part, it is a single function call without assignment
21162117

21172118
AssignType = SCRTermType.Invalid;
2119+
AssignParameter = -1; // preset assignparameter is not found
21182120

21192121
if (StatementParts.Length == 2)
21202122
{
@@ -2135,6 +2137,13 @@ public SCRStatement(scrReadInfo Statement, IDictionary<string, uint> LocalFloats
21352137
}
21362138
}
21372139

2140+
// check if parameter has been defined
2141+
if (AssignParameter < 0)
2142+
{
2143+
Trace.TraceInformation("Local variable {0} not defined for script {1}", assignPart, Statement.Scriptname);
2144+
AssignParameter = 0;
2145+
}
2146+
21382147
// Term part
21392148
// get positions of allowed operators
21402149

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

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ public void SH_process_script(SignalHead thisHead, SignalScripts.SCRScripts sign
143143
File.AppendAllText(dpe_fileLoc + @"printproc.txt", "\n\nSIGNAL : " + thisHead.TDBIndex.ToString() + "\n");
144144
File.AppendAllText(dpe_fileLoc + @"printproc.txt", "OBJECT : " + thisHead.mainSignal.thisRef.ToString() + "\n");
145145
File.AppendAllText(dpe_fileLoc + @"printproc.txt", "type : " + signalScript.scriptname + "\n");
146-
String fnstring = String.Copy(thisHead.mainSignal.signalRef.Simulator.SIGCFG.ORTSFunctionTypes[thisHead.ORTSsigFunctionIndex]);
147-
File.AppendAllText(dpr_fileLoc + @"printproc.txt", "fntype : " + thisHead.ORTSsigFunctionIndex + " = " + fnstring + "\n\n");
146+
File.AppendAllText(dpr_fileLoc + @"printproc.txt", "fntype : " + thisHead.SignalTypeName + " = " + thisHead.Function + "\n\n");
148147
}
149148
#endif
150149
#if DEBUG_PRINT_PROCESS
@@ -153,9 +152,7 @@ public void SH_process_script(SignalHead thisHead, SignalScripts.SCRScripts sign
153152
File.AppendAllText(dpr_fileLoc + @"printproc.txt", "\n\nSIGNAL : " + thisHead.TDBIndex.ToString() + "\n");
154153
File.AppendAllText(dpr_fileLoc + @"printproc.txt", "OBJECT : " + thisHead.mainSignal.thisRef.ToString() + "\n");
155154
File.AppendAllText(dpr_fileLoc + @"printproc.txt", "type : " + signalScript.scriptname + "\n");
156-
String fnstring = String.Copy(thisHead.mainSignal.signalRef.Simulator.SIGCFG.ORTSFunctionTypes[thisHead.ORTSsigFunctionIndex]);
157-
File.AppendAllText(dpr_fileLoc + @"printproc.txt", "fntype : " + thisHead.ORTSsigFunctionIndex + " = " + fnstring + "\n\n");
158-
155+
File.AppendAllText(dpr_fileLoc + @"printproc.txt", "fntype : " + thisHead.SignalTypeName + " = " + thisHead.Function + "\n\n");
159156
if (thisHead.mainSignal.localStorage.Count > 0)
160157
{
161158
File.AppendAllText(dpr_fileLoc + @"printproc.txt", "\n local storage : \n");
@@ -582,18 +579,18 @@ public int SH_function_value(SignalHead thisHead, SignalScripts.SCRScripts.SCRSt
582579
{
583580
File.AppendAllText(dpe_fileLoc + @"printproc.txt",
584581
" NEXT_SIG_LR : Located signal : " +
585-
thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
582+
thisHead.mainSignal.sigfound[function1].ToString() + "\n");
586583
}
587584
#endif
588585
#if DEBUG_PRINT_PROCESS
589586
if (TDB_debug_ref.Contains(thisHead.TDBIndex) || OBJ_debug_ref.Contains(thisHead.mainSignal.thisRef))
590587
{
591588
var sob = new StringBuilder();
592-
sob.AppendFormat(" NEXT_SIG_LR : Located signal : {0}", thisHead.mainSignal.sigfound[parameter1_value].ToString());
589+
sob.AppendFormat(" NEXT_SIG_LR : Located signal : {0}", thisHead.mainSignal.sigfound[function1].ToString());
593590

594-
if (thisHead.mainSignal.sigfound[parameter1_value] > 0)
591+
if (thisHead.mainSignal.sigfound[function1] > 0)
595592
{
596-
SignalObject otherSignal = thisHead.mainSignal.signalRef.SignalObjects[thisHead.mainSignal.sigfound[parameter1_value]];
593+
SignalObject otherSignal = thisHead.mainSignal.signalRef.SignalObjects[thisHead.mainSignal.sigfound[function1]];
597594
sob.AppendFormat(" (");
598595

599596
foreach (SignalHead otherHead in otherSignal.SignalHeads)
@@ -620,15 +617,15 @@ public int SH_function_value(SignalHead thisHead, SignalScripts.SCRScripts.SCRSt
620617
{
621618
File.AppendAllText(dpe_fileLoc + @"printproc.txt",
622619
" NEXT_SIG_MR : Located signal : " +
623-
thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
620+
thisHead.mainSignal.sigfound[function1].ToString() + "\n");
624621
}
625622
#endif
626623
#if DEBUG_PRINT_PROCESS
627624
if (TDB_debug_ref.Contains(thisHead.TDBIndex) || OBJ_debug_ref.Contains(thisHead.mainSignal.thisRef))
628625
{
629626
File.AppendAllText(dpr_fileLoc + @"printproc.txt",
630627
" NEXT_SIG_MR : Located signal : " +
631-
thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
628+
thisHead.mainSignal.sigfound[function1].ToString() + "\n");
632629
}
633630
#endif
634631
break;
@@ -657,7 +654,7 @@ public int SH_function_value(SignalHead thisHead, SignalScripts.SCRScripts.SCRSt
657654
if (thisHead.mainSignal.enabledTrain != null)
658655
{
659656
SignalObject foundSignal = null;
660-
int dummy = (int)thisHead.opp_sig_lr(parameter1_value, ref foundSignal);
657+
int dummy = (int)thisHead.opp_sig_lr(function1, ref foundSignal);
661658
int foundRef = foundSignal != null ? foundSignal.thisRef : -1;
662659
File.AppendAllText(dpe_fileLoc + @"printproc.txt",
663660
" OPP_SIG_LR : Located signal : " + foundRef.ToString() + "\n");
@@ -667,7 +664,7 @@ public int SH_function_value(SignalHead thisHead, SignalScripts.SCRScripts.SCRSt
667664
if (TDB_debug_ref.Contains(thisHead.TDBIndex) || OBJ_debug_ref.Contains(thisHead.mainSignal.thisRef))
668665
{
669666
SignalObject foundSignal = null;
670-
int dummy = (int)thisHead.opp_sig_lr(parameter1_value, ref foundSignal);
667+
int dummy = (int)thisHead.opp_sig_lr(function1, ref foundSignal);
671668
int foundRef = foundSignal != null ? foundSignal.thisRef : -1;
672669
File.AppendAllText(dpr_fileLoc + @"printproc.txt",
673670
" OPP_SIG_LR : Located signal : " + foundRef.ToString() + "\n");
@@ -861,6 +858,43 @@ public int SH_function_value(SignalHead thisHead, SignalScripts.SCRScripts.SCRSt
861858

862859
break;
863860

861+
// opp_sig_id_trainpath
862+
863+
case SignalScripts.SCRExternalFunctions.OPP_SIG_ID_TRAINPATH:
864+
return_value = (int)thisHead.opp_sig_id_trainpath(function1);
865+
#if DEBUG_PRINT_ENABLED
866+
if (thisHead.mainSignal.enabledTrain != null)
867+
{
868+
File.AppendAllText(dpe_fileLoc + @"printproc.txt",
869+
" OPP_SIG_LR : Located signal : " + return_value + "\n");
870+
}
871+
#endif
872+
#if DEBUG_PRINT_PROCESS
873+
if (TDB_debug_ref.Contains(thisHead.TDBIndex) || OBJ_debug_ref.Contains(thisHead.mainSignal.thisRef))
874+
{
875+
var sob = new StringBuilder();
876+
sob.AppendFormat(" OPP_SIG_LR : Located signal : {0}", return_value.ToString());
877+
878+
if (return_value > 0)
879+
{
880+
SignalObject otherSignal = thisHead.mainSignal.signalRef.SignalObjects[return_value];
881+
sob.AppendFormat(" (");
882+
883+
foreach (SignalHead otherHead in otherSignal.SignalHeads)
884+
{
885+
sob.AppendFormat(" {0} ", otherHead.TDBIndex);
886+
}
887+
888+
sob.AppendFormat(") ");
889+
}
890+
sob.AppendFormat("\n");
891+
892+
File.AppendAllText(dpr_fileLoc + @"printproc.txt", sob.ToString());
893+
}
894+
#endif
895+
896+
break;
897+
864898
// id_sig_enabled
865899

866900
case SignalScripts.SCRExternalFunctions.ID_SIG_ENABLED:
@@ -1332,19 +1366,19 @@ public int SH_function_value(SignalHead thisHead, SignalScripts.SCRScripts.SCRSt
13321366
{
13331367
File.AppendAllText(dpe_fileLoc + @"printproc.txt",
13341368
" NEXT_SIG_LVAR : Located signal : " +
1335-
thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
1369+
thisHead.mainSignal.sigfound[function1].ToString() + "\n");
13361370
File.AppendAllText(dpe_fileLoc + @"printproc.txt", " returned value : " + return_value + "\n");
13371371
}
13381372
#endif
13391373
#if DEBUG_PRINT_PROCESS
13401374
if (TDB_debug_ref.Contains(thisHead.TDBIndex) || OBJ_debug_ref.Contains(thisHead.mainSignal.thisRef))
13411375
{
13421376
var sob = new StringBuilder();
1343-
sob.AppendFormat(" NEXT_SIG_LVAR : Located signal : {0}", thisHead.mainSignal.sigfound[parameter1_value].ToString());
1377+
sob.AppendFormat(" NEXT_SIG_LVAR : Located signal : {0}", thisHead.mainSignal.sigfound[function1].ToString());
13441378

1345-
if (thisHead.mainSignal.sigfound[parameter1_value] > 0)
1379+
if (thisHead.mainSignal.sigfound[function1] > 0)
13461380
{
1347-
SignalObject otherSignal = thisHead.mainSignal.signalRef.SignalObjects[thisHead.mainSignal.sigfound[parameter1_value]];
1381+
SignalObject otherSignal = thisHead.mainSignal.signalRef.SignalObjects[thisHead.mainSignal.sigfound[function1]];
13481382
sob.AppendFormat(" (");
13491383

13501384
foreach (SignalHead otherHead in otherSignal.SignalHeads)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ public int opp_sig_id(SignalFunction function)
244244
{
245245
return mainSignal.opp_sig_id(function);
246246
}
247+
public int opp_sig_id_trainpath(SignalFunction function)
248+
{
249+
return mainSignal.opp_sig_id_trainpath(function);
250+
}
247251

248252
public MstsSignalAspect id_sig_lr(int sigId, SignalFunction function)
249253
{

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

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,15 @@ public int opp_sig_id(SignalFunction function)
10051005
return SONextSignalOpp(function);
10061006
}
10071007

1008+
/// <summary>
1009+
/// opp_sig_id : returns ident of next opposite signal of required type
1010+
/// search using trainpath of enabled train
1011+
/// </summary>
1012+
public int opp_sig_id_trainpath(SignalFunction function)
1013+
{
1014+
return SONextSignalOppTrainpath(function);
1015+
}
1016+
10081017
/// <summary>
10091018
/// this_sig_noSpeedReduction : Returns the setting if speed must be reduced on RESTRICTED or STOP_AND_PROCEED
10101019
/// returns TRUE if speed reduction must be suppressed
@@ -1664,6 +1673,51 @@ public int SONextSignalOpp(SignalFunction function)
16641673
return signalFound;
16651674
}
16661675

1676+
/// <summary>
1677+
/// Find next signal in opp direction using path of enabled train
1678+
/// </summary>
1679+
public int SONextSignalOppTrainpath(SignalFunction function)
1680+
{
1681+
int signalFound = -1;
1682+
1683+
// if enabled train is set
1684+
if (enabledTrain != null)
1685+
{
1686+
var pathposindex = enabledTrain.Train.PresentPosition[1].RouteListIndex;
1687+
1688+
// get route index of signal
1689+
var signalindex = enabledTrain.Train.ValidRoute[enabledTrain.TrainRouteDirectionIndex].GetRouteIndex(TCReference, pathposindex);
1690+
1691+
while (signalFound < 0 && signalindex >= 0)
1692+
{
1693+
int tcindex = enabledTrain.Train.ValidRoute[enabledTrain.TrainRouteDirectionIndex][signalindex].TCSectionIndex;
1694+
int direction = enabledTrain.Train.ValidRoute[enabledTrain.TrainRouteDirectionIndex][signalindex].Direction;
1695+
TrackCircuitSection thisSection = signalRef.TrackCircuitList[tcindex];
1696+
1697+
// check if required type of signal is along this section
1698+
if (function == SignalFunction.NORMAL)
1699+
{
1700+
signalFound = thisSection.EndSignals[direction == 0 ? 1 : 0] != null ? thisSection.EndSignals[direction].thisRef : -1;
1701+
}
1702+
else
1703+
{
1704+
TrackCircuitSignalList thisListrev = thisSection.CircuitItems.TrackCircuitSignals[direction == 0 ? 1 : 0][function];
1705+
if (thisListrev.TrackCircuitItem.Count > 0)
1706+
{
1707+
signalFound = thisListrev.TrackCircuitItem[0].SignalRef.thisRef;
1708+
}
1709+
}
1710+
1711+
if (signalFound < 0)
1712+
{
1713+
signalindex -= 1;
1714+
}
1715+
}
1716+
}
1717+
1718+
return signalFound;
1719+
}
1720+
16671721
/// <summary>
16681722
/// Perform route check and state update
16691723
/// </summary>
@@ -3905,33 +3959,60 @@ public int FindReqNormalSignal(int req_value, string dumpfile)
39053959
{
39063960
int foundSignal = -1;
39073961

3908-
// signal not enabled - no route available
3909-
if (enabledTrain == null)
3962+
Train.TrainRouted acttrain = enabledTrain;
3963+
int reqTC = isSignalNormal() ? TCNextTC : TCReference; // for normal signals, use section beyond signal; for not-normal, use signal section as TCNextTC is not set
3964+
3965+
// not normal signals may not have enabled train - check for train at next normal signal (use section ahead of signal in this case)
3966+
// note - next normal signal may not have the correct normal subtype, so proper search is still required
3967+
if (enabledTrain == null && !isSignalNormal())
3968+
{
3969+
int nextSignalIdent = SONextSignal(SignalFunction.NORMAL);
3970+
3971+
if (!String.IsNullOrEmpty(dumpfile))
3972+
{
3973+
var sob = new StringBuilder();
3974+
sob.AppendFormat("FIND_REQ_NORMAL_SIGNAL : using next normal signal for not enabled none-normal signal, found {0} \n", nextSignalIdent);
3975+
File.AppendAllText(dumpfile, sob.ToString());
3976+
}
3977+
3978+
if (nextSignalIdent >= 0)
3979+
{
3980+
SignalObject nextSignal = signalObjects[nextSignalIdent];
3981+
acttrain = nextSignal.enabledTrain;
3982+
reqTC = TCReference;
3983+
}
3984+
}
3985+
3986+
// no train found - no route available
3987+
if (acttrain == null || acttrain.Train.ValidRoute[acttrain.TrainRouteDirectionIndex] == null)
39103988
{
39113989
if (!String.IsNullOrEmpty(dumpfile))
39123990
{
39133991
var sob = new StringBuilder();
3914-
sob.Append("FIND_REQ_NORMAL_SIGNAL : not found : signal is not enabled");
3992+
sob.Append("FIND_REQ_NORMAL_SIGNAL : not found : signal is not enabled or train has no valid route\n");
39153993
File.AppendAllText(dumpfile, sob.ToString());
39163994
}
39173995
}
39183996
else
39193997
{
3920-
int startIndex = enabledTrain.Train.ValidRoute[enabledTrain.TrainRouteDirectionIndex].GetRouteIndex(TCNextTC, enabledTrain.Train.PresentPosition[0].RouteListIndex);
3998+
int startIndex = acttrain.Train.ValidRoute[acttrain.TrainRouteDirectionIndex].GetRouteIndex(reqTC, acttrain.Train.PresentPosition[0].RouteListIndex);
3999+
4000+
// this signal is not on trains route
39214001
if (startIndex < 0)
39224002
{
39234003
if (!String.IsNullOrEmpty(dumpfile))
39244004
{
39254005
var sob = new StringBuilder();
3926-
sob.AppendFormat("FIND_REQ_NORMAL_SIGNAL : not found : cannot find signal {0} at section {1} in path of train {2}\n", thisRef, TCNextTC, enabledTrain.Train.Name);
4006+
sob.AppendFormat("FIND_REQ_NORMAL_SIGNAL : not found : cannot find signal {0} at section {1} in path of train {2}\n", thisRef, TCNextTC, acttrain.Train.Name);
39274007
File.AppendAllText(dumpfile, sob.ToString());
39284008
}
39294009
}
39304010
else
39314011
{
3932-
for (int iRouteIndex = startIndex; iRouteIndex < enabledTrain.Train.ValidRoute[enabledTrain.TrainRouteDirectionIndex].Count; iRouteIndex++)
4012+
// search through train route until required signal type is found, or until end of route
4013+
for (int iRouteIndex = startIndex; iRouteIndex < acttrain.Train.ValidRoute[acttrain.TrainRouteDirectionIndex].Count; iRouteIndex++)
39334014
{
3934-
Train.TCRouteElement thisElement = enabledTrain.Train.ValidRoute[enabledTrain.TrainRouteDirectionIndex][iRouteIndex];
4015+
Train.TCRouteElement thisElement = acttrain.Train.ValidRoute[acttrain.TrainRouteDirectionIndex][iRouteIndex];
39354016
TrackCircuitSection thisSection = signalRef.TrackCircuitList[thisElement.TCSectionIndex];
39364017
if (thisSection.EndSignals[thisElement.Direction] != null)
39374018
{

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
30783078
// <CSComment> Now speedometer is handled like the other digitals
30793079

30803080
base.PrepareFrame(frame, elapsedTime);
3081+
digital.OldValue = Num;
30813082
}
30823083

30833084
public override void Draw(GraphicsDevice graphicsDevice)
@@ -3151,6 +3152,8 @@ public string GetDigits(out Color DrawColor)
31513152
displayedText = String.Format(Format, Num);
31523153
DrawColor = Color.White;
31533154
}
3155+
digital.OldValue = Num;
3156+
31543157
// <CSComment> Speedometer is now managed like the other digitals
31553158

31563159
return displayedText;
@@ -3227,6 +3230,8 @@ public string GetDigits(out Color DrawColor)
32273230
{
32283231
displayedText = String.Format(Format, Num);
32293232
}
3233+
digital.OldValue = Num;
3234+
32303235
// <CSComment> Speedometer is now managed like the other digitals
32313236

32323237
return displayedText;

0 commit comments

Comments
 (0)