Skip to content

Commit c0fb55d

Browse files
committed
Automatic merge of T1.5.1-1004-g6fd841761e and 21 pull requests
- Pull request #799 at dfc715e: Consolidated wind simulation - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #882 at 8f695a4: Blueprint/train car operations UI window - Pull request #885 at 2728d6d: feat: Add notifications to Menu - Pull request #891 at 9a1d6b2: Auto save - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #900 at c27f32d: DMI updates - Pull request #903 at 3e390b8: Downloading route content (Github, zip) - Pull request #912 at 359cfee: New Triple Valve Features Vol. 2 - Pull request #922 at 0d3e70b: Autopilot for timetable mode - Pull request #946 at 91a03af: Advanced track sounds - Pull request #949 at a4a44b5: Oil Burning Locomotive - Pull request #952 at 8347095: Investigation - Pulsing graphics - Pull request #953 at a519452: Fix Lights Crash on Corrupt Shapes - Pull request #954 at 84c2f4b: Add Support for Multiple Track Profiles - Pull request #956 at 406cba6: Map settings saved - Pull request #959 at 2452cb0: Fix TrackViewer crash on big zoom value - Pull request #960 at c8e2a28: Fix draw state name in scripts - Pull request #962 at 46d0472: Fix pantographs on unpowered cars
23 parents 2f616d0 + 6fd8417 + dfc715e + d00beb9 + f92de76 + 8f695a4 + 2728d6d + 9a1d6b2 + 1f5ba4c + 5866028 + c27f32d + 3e390b8 + 359cfee + 0d3e70b + 91a03af + a4a44b5 + 8347095 + a519452 + 84c2f4b + 406cba6 + 2452cb0 + c8e2a28 + 46d0472 commit c0fb55d

File tree

1 file changed

+30
-16
lines changed
  • Source/Orts.Simulation/Simulation/Signalling

1 file changed

+30
-16
lines changed

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class Signals
6464
public int noSignals;
6565
private int foundSignals;
6666

67-
private static int updatecount;
67+
private static int UpdateIndex;
6868

6969
public List<TrackCircuitSection> TrackCircuitList;
7070
private Dictionary<int, CrossOverItem> CrossoverList = new Dictionary<int, CrossOverItem>();
@@ -553,6 +553,11 @@ private void BuildSignalWorld(Simulator simulator, SignalConfigurationFile sigcf
553553

554554
} //BuildSignalWorld
555555

556+
Stopwatch UpdateTimer = new Stopwatch();
557+
long UpdateCounter = 0;
558+
long UpdateTickTarget = 10000;
559+
// long DebugUpdateCounter = 0;
560+
556561
/// <summary>
557562
/// Update : perform signal updates
558563
/// </summary>
@@ -562,30 +567,39 @@ public void Update(bool preUpdate)
562567

563568
if (foundSignals > 0)
564569
{
565-
566570
// loop through all signals
567571
// update required part
568-
// in preupdate, process all
569-
570-
int totalSignal = foundSignals;
571-
572-
int updatestep = (totalSignal / 20) + 1;
573-
if (preUpdate)
574-
{
575-
updatestep = totalSignal;
576-
}
577-
578-
for (int icount = updatecount; icount < Math.Min(totalSignal, updatecount + updatestep); icount++)
572+
var updates = 0;
573+
var updateStep = 0;
574+
var targetTicks = Stopwatch.GetTimestamp() + UpdateTickTarget;
575+
UpdateTimer.Start();
576+
while (updateStep < foundSignals)
579577
{
580-
SignalObject signal = SignalObjects[icount];
578+
var signal = SignalObjects[(UpdateIndex + updateStep) % foundSignals];
581579
if (signal != null && !signal.noupdate) // to cater for orphans, and skip signals which do not require updates
582580
{
583581
signal.Update();
582+
updates++;
584583
}
584+
updateStep++;
585+
586+
// in preupdate, process all
587+
if (!preUpdate && updates % 10 == 0 && Stopwatch.GetTimestamp() >= targetTicks) break;
585588
}
589+
UpdateCounter += updates;
590+
UpdateTimer.Stop();
586591

587-
updatecount += updatestep;
588-
updatecount = updatecount >= totalSignal ? 0 : updatecount;
592+
if (UpdateIndex + updateStep >= foundSignals)
593+
{
594+
// Calculate how long it takes to update all signals and target 1/20th of that
595+
// Slow adjustment using clamp stops it jumping around too much
596+
var ticksPerSignal = (double)UpdateTimer.ElapsedTicks / UpdateCounter;
597+
UpdateTickTarget = (long)MathHelper.Clamp((float)(ticksPerSignal * foundSignals / 20), UpdateTickTarget - 100, UpdateTickTarget + 100);
598+
// if (++DebugUpdateCounter % 10 == 0) Trace.WriteLine($"Signal update for {UpdateCounter,5} signals took {(double)UpdateTimer.ElapsedTicks * 1000 / Stopwatch.Frequency,9:F6} ms ({ticksPerSignal * 1000 / Stopwatch.Frequency,9:F6} ms/signal); new {(double)UpdateTickTarget * 1000 / Stopwatch.Frequency,6:F6} ms target");
599+
UpdateTimer.Reset();
600+
UpdateCounter = 0;
601+
}
602+
UpdateIndex = (UpdateIndex + updateStep) % foundSignals;
589603
}
590604
}
591605

0 commit comments

Comments
 (0)