Skip to content

Commit dfaedce

Browse files
committed
Automatic merge of T1.5.1-573-g9a8e6af15 and 14 pull requests
- Pull request #757 at 98dd1a7: Unify RailDriver code implementations - Pull request #831 at 3e672a8: poor mans switch panel on tablet - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #841 at 410a585: https://blueprints.launchpad.net/or/+spec/animating-trainset-windows - Pull request #853 at d05f581: Notify out of focus - Pull request #855 at b39e5d8: Adds new route from TrainSimulations - Pull request #857 at 9afc8c3: Adding Air Flow Meters - Pull request #863 at a34b857: Alternate preset 3D cabviewpoints - Pull request #864 at e71bc5a: Fixes for Undesired Emergency Applications - Pull request #865 at 776d6df: Dispatcher window improvements - Pull request #866 at c15333e: Fix Articulation For 0-Axle Train Cars - Pull request #870 at 5cb32fa: Fix water restore - Pull request #873 at cf0ed99: Reduce allocations in signal script - Pull request #874 at d500329: Dynamic brake controller refactoring
16 parents 3b7bd44 + 9a8e6af + 98dd1a7 + 3e672a8 + d00beb9 + 410a585 + d05f581 + b39e5d8 + 9afc8c3 + a34b857 + e71bc5a + 776d6df + c15333e + 5cb32fa + cf0ed99 + d500329 commit dfaedce

File tree

8 files changed

+95
-137
lines changed

8 files changed

+95
-137
lines changed

Source/Orts.Simulation/Common/Scripting/BrakeController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ public void SetUpdateValue(float value)
226226
/// </summary>
227227
public void SetDynamicBrakeIntervention(float value)
228228
{
229-
if (value > 0 && Host.TrainDynamicBrakeIntervention <= 0)
230-
Host.TrainDynamicBrakeCommandStartTime = Host.Simulator.ClockTime;
231229
if (value <= 0)
232230
Host.TrainDynamicBrakeIntervention = -1;
233231
else Host.TrainDynamicBrakeIntervention = Math.Min(value, 1);

Source/Orts.Simulation/Simulation/RollingStocks/MSTSDieselLocomotive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float t,
757757
// Note typically only one of the above will only ever be non-zero at the one time.
758758
// For flipped locomotives the force is "flipped" elsewhere, whereas dynamic brake force is "flipped" below by the direction of the speed.
759759

760-
if (DynamicBrakePercent > 0 && DynamicBrakeForceCurves != null && AbsSpeedMpS > 0)
760+
if (DynamicBrakePercent > 0 && DynamicBrake && DynamicBrakeForceCurves != null && AbsSpeedMpS > 0)
761761
{
762762
float f = DynamicBrakeForceCurves.Get(.01f * DynamicBrakePercent, AbsTractionSpeedMpS);
763763
if (f > 0 && LocomotivePowerSupply.DynamicBrakeAvailable)

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 69 additions & 114 deletions
Large diffs are not rendered by default.

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/BrakeController.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public bool OverchargeButtonPressed
152152
public float FullServReductionPSI { get; private set; }
153153
public float MinReductionPSI { get; private set; }
154154
public float TrainDynamicBrakeIntervention { get; set; } = -1;
155-
public double TrainDynamicBrakeCommandStartTime { get; set; }
155+
InterpolatorDiesel2D DynamicBrakeBlendingTable;
156156

157157
/// <summary>
158158
/// Needed for proper mouse operation in the cabview
@@ -227,6 +227,8 @@ public ScriptedBrakeController(ScriptedBrakeController controller, MSTSLocomotiv
227227
(item) => { Notches.Add(new MSTSNotch(item)); }
228228
);
229229

230+
DynamicBrakeBlendingTable = controller.DynamicBrakeBlendingTable;
231+
230232
Initialize();
231233
}
232234

@@ -321,6 +323,9 @@ public void Parse(string lowercasetoken, STFReader stf)
321323
case "engine(ortsenginebrakecontroller":
322324
ScriptName = stf.ReadStringBlock(null);
323325
break;
326+
case "engine(ortstraindynamicblendingtable":
327+
DynamicBrakeBlendingTable = new InterpolatorDiesel2D(stf, false);
328+
break;
324329
}
325330
}
326331

@@ -335,8 +340,10 @@ public void Initialize()
335340
}
336341
if (Script == null)
337342
{
338-
Script = new MSTSBrakeController() as BrakeController;
339-
(Script as MSTSBrakeController).ForceControllerReleaseGraduated = Simulator.Settings.GraduatedRelease;
343+
var mstsController = new MSTSBrakeController();
344+
mstsController.ForceControllerReleaseGraduated = Simulator.Settings.GraduatedRelease;
345+
mstsController.DynamicBrakeBlendingTable = DynamicBrakeBlendingTable;
346+
Script = mstsController as BrakeController;
340347
}
341348

342349
Script.AttachToHost(this);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/MSTSBrakeController.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717

1818
using System;
19+
using Orts.Parsers.Msts;
1920
using ORTS.Scripting.Api;
2021

2122
namespace Orts.Simulation.RollingStocks.SubSystems.Controllers
@@ -37,9 +38,10 @@ public class MSTSBrakeController: BrakeController
3738
public bool ForceControllerReleaseGraduated;
3839
bool BrakeControllerInitialised; // flag to allow PreviousNotchPosition to be initially set.
3940
MSTSNotch PreviousNotchPosition;
40-
4141
bool EnforceMinimalReduction = false;
4242

43+
public InterpolatorDiesel2D DynamicBrakeBlendingTable;
44+
4345
public MSTSBrakeController()
4446
{
4547
}
@@ -70,6 +72,10 @@ public override float Update(float elapsedSeconds)
7072
IntermediateValue = NotchController.IntermediateValue;
7173
SetUpdateValue(NotchController.UpdateValue);
7274
CurrentNotch = NotchController.CurrentNotch;
75+
if (DynamicBrakeBlendingTable != null)
76+
{
77+
SetDynamicBrakeIntervention(DynamicBrakeBlendingTable.Get(CurrentValue(), SpeedMpS()));
78+
}
7379
return value;
7480
}
7581

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/MultiPositionController.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,7 @@ public void Update(float elapsedClockSeconds)
351351
{
352352
Locomotive.SetDynamicBrakePercent(Locomotive.DynamicBrakePercent - DynamicBrakeDecreaseStepPerSecond * elapsedClockSeconds);
353353
if (Locomotive.DynamicBrakePercent < 2)
354-
{
355-
Locomotive.SetDynamicBrakePercent(0);
356-
Locomotive.DynamicBrakeChangeActiveState(false);
357-
}
354+
Locomotive.SetDynamicBrakePercent(-1);
358355
}
359356
else
360357
{
@@ -370,10 +367,7 @@ public void Update(float elapsedClockSeconds)
370367
{
371368
Locomotive.SetDynamicBrakePercent(Locomotive.DynamicBrakePercent - DynamicBrakeDecreaseStepPerSecond * 2 * elapsedClockSeconds);
372369
if (Locomotive.DynamicBrakePercent < 2)
373-
{
374-
Locomotive.SetDynamicBrakePercent(0);
375-
Locomotive.DynamicBrakeChangeActiveState(false);
376-
}
370+
Locomotive.SetDynamicBrakePercent(-1);
377371
}
378372
else
379373
{
@@ -525,8 +519,6 @@ public void Update(float elapsedClockSeconds)
525519
}
526520
if (Locomotive.ThrottlePercent < 1 && Locomotive.DynamicBrakePercent < 100)
527521
{
528-
if (Locomotive.DynamicBrakePercent < 0)
529-
Locomotive.DynamicBrakeChangeActiveState(true);
530522
Locomotive.SetDynamicBrakePercent(Locomotive.DynamicBrakePercent + 1f);
531523
}
532524
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/CruiseControl.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,16 +541,14 @@ public void Update(float elapsedClockSeconds)
541541
}
542542
else
543543
{
544-
if (Locomotive.DynamicBrakePercent < 0) Locomotive.DynamicBrakeCommandStartTime = Locomotive.Simulator.ClockTime;
545544
Locomotive.ThrottlePercent = 0;
546-
Locomotive.DynamicBrakePercent = -CCThrottleOrDynBrakePercent;
545+
Locomotive.DynamicBrakePercent = Math.Max(-CCThrottleOrDynBrakePercent, Locomotive.TrainBrakeController?.TrainDynamicBrakeIntervention ?? -1);
547546
}
548547
IsActive = true;
549548
}
550549
if (!IsActive && wasActive)
551550
{
552551
Locomotive.ThrottlePercent = 0;
553-
if (!DynamicBrakePriority) Locomotive.DynamicBrakePercent = -1;
554552
CCIsUsingTrainBrake = false;
555553
Locomotive.ThrottleController.SetPercent(0);
556554
}

Source/Orts.Simulation/Simulation/RollingStocks/TrainCar.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ public float DynamicBrakePercent
484484
{
485485
get
486486
{
487+
float percent = -1;
487488
if (RemoteControlGroup == 0 && Train != null)
488489
{
489490
if (Train.LeadLocomotive is MSTSLocomotive locomotive)
@@ -494,16 +495,17 @@ public float DynamicBrakePercent
494495
}
495496
}
496497

497-
return Train.MUDynamicBrakePercent;
498+
percent = Train.MUDynamicBrakePercent;
498499
}
499500
else if (RemoteControlGroup == 1 && Train != null)
500501
{
501-
return Train.DPDynamicBrakePercent;
502+
percent = Train.DPDynamicBrakePercent;
502503
}
503504
else
504505
{
505-
return LocalDynamicBrakePercent;
506+
percent = LocalDynamicBrakePercent;
506507
}
508+
return Math.Max(percent, this is MSTSLocomotive loco ? loco.DynamicBrakeBlendingPercent : -1);
507509
}
508510
set
509511
{

0 commit comments

Comments
 (0)