Skip to content

Commit f8ecd7b

Browse files
committed
Show signalling debug information for all signal types
1 parent 27bfb9b commit f8ecd7b

File tree

2 files changed

+81
-5
lines changed

2 files changed

+81
-5
lines changed

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

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ public void SetNumSignalHeads()
12471247
/// -6 : end of (sub)route
12481248
/// </summary>
12491249
public TrackCircuitSignalItem Find_Next_Object_InRoute(Train.TCSubpathRoute routePath,
1250-
int routeIndex, float routePosition, float maxDistance, MstsSignalFunction fn_type, Train.TrainRouted thisTrain)
1250+
int routeIndex, float routePosition, float maxDistance, MstsSignalFunction? fn_type, Train.TrainRouted thisTrain)
12511251
{
12521252
ObjectItemInfo.ObjectItemFindState locstate = ObjectItemInfo.ObjectItemFindState.None;
12531253
// local processing state //
@@ -1318,6 +1318,28 @@ public TrackCircuitSignalItem Find_Next_Object_InRoute(Train.TCSubpathRoute rout
13181318
}
13191319
}
13201320
}
1321+
// all function types
1322+
else if (fn_type == null)
1323+
{
1324+
List<TrackCircuitSignalItem> signalList = new List<TrackCircuitSignalItem>();
1325+
1326+
signalList = thisSection.CircuitItems.TrackCircuitSignals[actDirection].Select(x => x.TrackCircuitItem).Aggregate((acc, list) => acc.Concat(list).ToList());
1327+
1328+
signalList.Sort((a, b) => a.SignalLocation < b.SignalLocation ? -1 : a.SignalLocation > b.SignalLocation ? 1 : 0);
1329+
1330+
locstate = ObjectItemInfo.ObjectItemFindState.None;
1331+
1332+
foreach (TrackCircuitSignalItem thisSignal in signalList)
1333+
{
1334+
if (thisSignal.SignalLocation > lengthOffset)
1335+
{
1336+
locstate = ObjectItemInfo.ObjectItemFindState.Object;
1337+
foundObject = thisSignal.SignalRef;
1338+
totalLength += thisSignal.SignalLocation - lengthOffset;
1339+
break;
1340+
}
1341+
}
1342+
}
13211343
// other fn_types
13221344
else
13231345
{
@@ -1549,6 +1571,63 @@ public ObjectItemInfo GetNextObject_InRoute(Train.TrainRouted thisTrain, Train.T
15491571
return returnItem;
15501572
}
15511573

1574+
public ObjectItemInfo GetNextSignal_InRoute(Train.TrainRouted thisTrain, Train.TCSubpathRoute routePath,
1575+
int routeIndex, float routePosition, float maxDistance, Train.TCPosition thisPosition, MstsSignalFunction? requiredSignalFunction = null)
1576+
{
1577+
Train.TCSubpathRoute usedRoute = routePath;
1578+
1579+
// if routeIndex is not valid, build temp route from present position to first node or signal
1580+
if (routeIndex < 0)
1581+
{
1582+
bool thisIsFreight = thisTrain != null ? thisTrain.Train.IsFreight : false;
1583+
1584+
List<int> tempSections = ScanRoute(thisTrain.Train, thisPosition.TCSectionIndex,
1585+
thisPosition.TCOffset, thisPosition.TCDirection,
1586+
true, 200f, false, true, true, false, true, false, false, true, false, thisIsFreight);
1587+
1588+
1589+
Train.TCSubpathRoute tempRoute = new Train.TCSubpathRoute();
1590+
int prevSection = -2;
1591+
1592+
foreach (int sectionIndex in tempSections)
1593+
{
1594+
Train.TCRouteElement thisElement =
1595+
new Train.TCRouteElement(TrackCircuitList[Math.Abs(sectionIndex)],
1596+
sectionIndex > 0 ? 0 : 1, this, prevSection);
1597+
tempRoute.Add(thisElement);
1598+
prevSection = Math.Abs(sectionIndex);
1599+
}
1600+
usedRoute = tempRoute;
1601+
routeIndex = 0;
1602+
}
1603+
1604+
TrackCircuitSignalItem nextSignal = Find_Next_Object_InRoute(usedRoute, routeIndex, routePosition, maxDistance, requiredSignalFunction, thisTrain);
1605+
1606+
if (nextSignal.SignalState == ObjectItemInfo.ObjectItemFindState.Object)
1607+
{
1608+
if (thisTrain != null && nextSignal.SignalRef.enabledTrain != thisTrain)
1609+
{
1610+
nextSignal.SignalState = ObjectItemInfo.ObjectItemFindState.PassedDanger; // do not return OBJECT_FOUND - signal is not valid
1611+
}
1612+
}
1613+
1614+
ObjectItemInfo returnItem;
1615+
if (nextSignal == null)
1616+
{
1617+
returnItem = new ObjectItemInfo(ObjectItemInfo.ObjectItemFindState.None);
1618+
}
1619+
else if (nextSignal.SignalState != ObjectItemInfo.ObjectItemFindState.Object)
1620+
{
1621+
returnItem = new ObjectItemInfo(nextSignal.SignalState);
1622+
}
1623+
else
1624+
{
1625+
returnItem = new ObjectItemInfo(nextSignal.SignalRef, nextSignal.SignalLocation);
1626+
}
1627+
1628+
return returnItem;
1629+
}
1630+
15521631
/// <summary>
15531632
/// Gets the Track Monitor Aspect from the MSTS aspect (for the TCS)
15541633
/// </summary>

Source/RunActivity/Viewer3D/Popups/SignallingDebugWindow.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,11 @@ TrackSectionCacheEntry GetCacheEntry(Traveller position)
293293
thisPosition.SetTCPosition(tn.TCCrossReference, offset, direction);
294294
Train.TCSubpathRoute tempRoute = Owner.Viewer.Simulator.Signals.BuildTempRoute(null, thisPosition.TCSectionIndex, thisPosition.TCOffset, thisPosition.TCDirection, 5000.0f, true, false, false);
295295

296-
ObjectItemInfo thisInfo = Owner.Viewer.Simulator.Signals.GetNextObject_InRoute(null, tempRoute, 0,
297-
thisPosition.TCOffset, -1, ObjectItemInfo.ObjectItemType.Signal, thisPosition);
296+
ObjectItemInfo thisInfo = Owner.Viewer.Simulator.Signals.GetNextSignal_InRoute(null, tempRoute, 0, thisPosition.TCOffset, -1, thisPosition, null);
298297

299298
var signal = thisInfo.ObjectDetails;
300299
if (signal == null)
301300
break;
302-
if (signal.this_sig_lr(MstsSignalFunction.NORMAL) == MstsSignalAspect.UNKNOWN)
303-
break;
304301
var signalDistance = thisInfo.distance_found;
305302

306303
if (signalDistance > 0)

0 commit comments

Comments
 (0)