Skip to content

Commit ea394e5

Browse files
authored
Merge pull request #787 from Roeterdink/ImproveDebugPoolInfo
Improve debug output for turntable pools
2 parents 2c69046 + e0ad658 commit ea394e5

File tree

2 files changed

+246
-20
lines changed

2 files changed

+246
-20
lines changed

Source/Orts.Simulation/Simulation/Timetables/TTPool.cs

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// This code processes the Timetable definition and converts it into playable train information
1919
//
20-
// #DEBUG_POOLINFO
20+
// #define DEBUG_POOLINFO
2121
//
2222

2323
using System;
@@ -1000,8 +1000,17 @@ public int GetPoolExitIndex(TTTrain train)
10001000

10011001
#if DEBUG_POOLINFO
10021002
var sob = new StringBuilder();
1003-
sob.AppendFormat("Pool {0} : error : train {1} ({2}) allready stored in pool \n", PoolName, train.Number, train.Name);
1004-
sob.AppendFormat(" stored units : {0}", thisStorage.StoredUnits.Count);
1003+
DateTime baseDT = new DateTime();
1004+
DateTime actTime = baseDT.AddSeconds(train.AI.clockTime);
1005+
1006+
sob.AppendFormat("{0} : Pool {1} : error : train {2} ({3}) allready stored in pool \n", actTime.ToString("HH:mm:ss"),PoolName, train.Number, train.Name);
1007+
1008+
int totalno = 0;
1009+
foreach (PoolDetails selStorage in StoragePool)
1010+
{
1011+
totalno += selStorage.StoredUnits.Count;
1012+
}
1013+
sob.AppendFormat(" stored units {0} : {1} (total {2})", PoolName, thisStorage.StoredUnits.Count, totalno);
10051014
File.AppendAllText(@"C:\temp\PoolAnal.csv", sob.ToString() + "\n");
10061015
#endif
10071016
}
@@ -1083,8 +1092,18 @@ public void AddUnit(TTTrain train, bool claimOnly)
10831092

10841093
#if DEBUG_POOLINFO
10851094
var sob = new StringBuilder();
1086-
sob.AppendFormat("Pool {0} : train {1} ({2}) added\n", PoolName, train.Number, train.Name);
1087-
sob.AppendFormat(" stored units : {0}\n", thisPool.StoredUnits.Count);
1095+
DateTime baseDT = new DateTime();
1096+
DateTime actTime = baseDT.AddSeconds(train.AI.clockTime);
1097+
1098+
sob.AppendFormat("{0} : Pool {1} : train {2} ({3}) added\n", actTime.ToString("HH:mm:ss"),PoolName, train.Number, train.Name);
1099+
1100+
int totalno = 0;
1101+
foreach (PoolDetails selStorage in StoragePool)
1102+
{
1103+
totalno += selStorage.StoredUnits.Count;
1104+
}
1105+
1106+
sob.AppendFormat(" stored units {0} : {1} (total {2})", PoolName, thisPool.StoredUnits.Count, totalno);
10881107
File.AppendAllText(@"C:\temp\PoolAnal.csv", sob.ToString() + "\n");
10891108
#endif
10901109

@@ -1184,7 +1203,10 @@ virtual public TrainFromPool ExtractTrain(ref TTTrain train, int presentTime)
11841203
{
11851204
#if DEBUG_POOLINFO
11861205
var sob = new StringBuilder();
1187-
sob.AppendFormat("Pool {0} : request for train {1} ({2})", PoolName, train.Number, train.Name);
1206+
DateTime baseDT = new DateTime();
1207+
DateTime actTime = baseDT.AddSeconds(train.AI.clockTime);
1208+
1209+
sob.AppendFormat("{0} : Pool {1} : request for train {2} ({3})", actTime.ToString("HH:mm:ss"), PoolName, train.Number, train.Name);
11881210
File.AppendAllText(@"C:\temp\PoolAnal.csv", sob.ToString() + "\n");
11891211
#endif
11901212
// check if any engines available
@@ -1215,6 +1237,9 @@ virtual public TrainFromPool ExtractTrain(ref TTTrain train, int presentTime)
12151237
{
12161238
#if DEBUG_TRACEINFO
12171239
Trace.TraceInformation("Pool {0} : train {1} : delayed through claimed access\n", PoolName, train.Name);
1240+
#endif
1241+
#if DEBUG_POOLINFO
1242+
Trace.TraceInformation("Pool {0} : train {1} : delayed through claimed access\n", PoolName, train.Name);
12181243
#endif
12191244
return (TrainFromPool.Delayed);
12201245
}
@@ -1319,7 +1344,13 @@ virtual public TrainFromPool ExtractTrain(ref TTTrain train, int presentTime)
13191344
#if DEBUG_POOLINFO
13201345
sob = new StringBuilder();
13211346
sob.AppendFormat("Pool {0} : train {1} ({2}) waiting for incoming train {3} ({4})\n", PoolName, train.Number, train.Name, otherTTTrain.Number, otherTTTrain.Name);
1322-
sob.AppendFormat(" stored units : {0}", reqStorage.StoredUnits.Count);
1347+
1348+
int totalno1 = 0;
1349+
foreach (PoolDetails selStorage in StoragePool)
1350+
{
1351+
totalno1 += selStorage.StoredUnits.Count;
1352+
}
1353+
sob.AppendFormat(" stored units {0} : {1} (total {2})", PoolName, reqStorage.StoredUnits.Count, totalno1);
13231354
File.AppendAllText(@"C:\temp\PoolAnal.csv", sob.ToString() + "\n");
13241355
#endif
13251356
break;
@@ -1344,8 +1375,15 @@ virtual public TrainFromPool ExtractTrain(ref TTTrain train, int presentTime)
13441375
{
13451376
#if DEBUG_POOLINFO
13461377
sob = new StringBuilder();
1347-
sob.AppendFormat("Pool {0} : cannot find train {1} for {2} ({3}) \n", PoolName, selectedTrainNumber, train.Number, train.Name);
1348-
sob.AppendFormat(" stored units : {0}", reqStorage.StoredUnits.Count);
1378+
1379+
sob.AppendFormat("Pool {1} : cannot find train {2} for {3} ({4}) \n", PoolName, selectedTrainNumber, train.Number, train.Name);
1380+
1381+
int totalno2 = 0;
1382+
foreach (PoolDetails selStorage in StoragePool)
1383+
{
1384+
totalno2 += selStorage.StoredUnits.Count;
1385+
}
1386+
sob.AppendFormat(" stored units {0} : {1} (total {2})", PoolName, reqStorage.StoredUnits.Count, totalno2);
13491387
File.AppendAllText(@"C:\temp\PoolAnal.csv", sob.ToString() + "\n");
13501388
#endif
13511389
return (TrainFromPool.Delayed);
@@ -1361,8 +1399,15 @@ virtual public TrainFromPool ExtractTrain(ref TTTrain train, int presentTime)
13611399

13621400
#if DEBUG_POOLINFO
13631401
sob = new StringBuilder();
1402+
13641403
sob.AppendFormat("Pool {0} : train {1} ({2}) extracted as {3} ({4}) \n", PoolName, selectedTrain.Number, selectedTrain.Name, train.Number, train.Name);
1365-
sob.AppendFormat(" stored units : {0}", reqStorage.StoredUnits.Count);
1404+
1405+
int totalno = 0;
1406+
foreach (PoolDetails selStorage in StoragePool)
1407+
{
1408+
totalno += selStorage.StoredUnits.Count;
1409+
}
1410+
sob.AppendFormat(" stored units {0} : {1} (total {2})", PoolName, reqStorage.StoredUnits.Count, totalno);
13661411
File.AppendAllText(@"C:\temp\PoolAnal.csv", sob.ToString() + "\n");
13671412
#endif
13681413

@@ -1504,6 +1549,9 @@ virtual public TrainFromPool ExtractTrain(ref TTTrain train, int presentTime)
15041549
{
15051550
#if DEBUG_TRACEINFO
15061551
Trace.TraceWarning("Failed to extract required train " + train.Name + " from pool " + PoolName + "\n");
1552+
#endif
1553+
#if DEBUG_POOLINFO
1554+
Trace.TraceWarning("Failed to extract required train " + train.Name + " from pool " + PoolName + "\n");
15071555
#endif
15081556
return (TrainFromPool.Failed);
15091557
}

0 commit comments

Comments
 (0)