Skip to content

Commit 589ee8d

Browse files
committed
Automatic merge of T1.5.1-372-g5db5c7824 and 9 pull requests
- Pull request #570 at de7a14f: Experimental glTF 2.0 support with PBR lighting - Pull request #732 at 22f66dc: Improvements for air brakes - Pull request #751 at 00981a2: Web interface to control cab controls with external hardware - Pull request #799 at dc03850: Consolidated wind simulation - Pull request #803 at 7157e08: Various adjustments to steam adhesion - Pull request #813 at 244875d: Refactored garbage generators - Pull request #815 at a5cc165: chore: Add GitHub automatic release notes configuration - Pull request #816 at eae646d: Bug fix for https://bugs.launchpad.net/or/+bug/2014992 EOT can't be dismounted after train reversal - Pull request #818 at 18fd051: Allow independent drive axles for locomotives
11 parents 6e1f4e7 + 5db5c78 + de7a14f + 22f66dc + 00981a2 + dc03850 + 7157e08 + 244875d + a5cc165 + eae646d + 18fd051 commit 589ee8d

File tree

8 files changed

+56
-39
lines changed

8 files changed

+56
-39
lines changed

Source/Orts.Simulation/Simulation/AIs/AITrain.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public enum AI_START_MOVEMENT
129129
public static float minStopDistanceM = 3.0f; // minimum clear distance for stopping at signal in station
130130
public static float signalApproachDistanceM = 20.0f; // final approach to signal
131131

132+
private readonly List<ObjectItemInfo> processedList = new List<ObjectItemInfo>(); // internal processing list for CheckSignalObjects()
133+
132134
#if WITH_PATH_DEBUG
133135
// Only for EnhancedActCompatibility
134136
public string currentAIState = "";
@@ -1164,10 +1166,12 @@ public void CheckSignalObjects()
11641166
}
11651167

11661168
float validSpeed = AllowedMaxSpeedMpS;
1167-
List<ObjectItemInfo> processedList = new List<ObjectItemInfo>();
1169+
processedList.Clear();
11681170

1169-
foreach (ObjectItemInfo thisInfo in SignalObjectItems.Where(item => !item.speed_isWarning))
1171+
foreach (ObjectItemInfo thisInfo in SignalObjectItems)
11701172
{
1173+
if (thisInfo.speed_isWarning)
1174+
continue;
11711175

11721176
// check speedlimit
11731177
if (CheckTrain)

Source/Orts.Simulation/Simulation/Physics/Train.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public TrainCar LastCar
9696
}
9797
public Traveller RearTDBTraveller; // positioned at the back of the last car in the train
9898
public Traveller FrontTDBTraveller; // positioned at the front of the train by CalculatePositionOfCars
99+
Traveller CalculatorTraveller; // CalculatePositionOfCars uses it for the calculations
99100
public float Length; // length of train from FrontTDBTraveller to RearTDBTraveller
100101
public float MassKg; // weight of the train
101102
public float SpeedMpS; // meters per second +ve forward, -ve when backing
@@ -420,6 +421,8 @@ public enum END_AUTHORITY
420421

421422
public bool nextRouteReady = false; // indication to activity.cs that a reversal has taken place
422423

424+
readonly List<int[]> sectionList = new List<int[]>(); // internally used in UpdateSectionState()
425+
423426
// Deadlock Info :
424427
// list of sections where deadlock begins
425428
// per section : list with trainno and end section
@@ -4383,7 +4386,9 @@ public void CalculatePositionOfCars(float elapsedTime, float distance)
43834386

43844387
// TODO : check if train moved back into previous section
43854388

4386-
var traveller = new Traveller(RearTDBTraveller);
4389+
CalculatorTraveller = CalculatorTraveller ?? new Traveller(RearTDBTraveller);
4390+
var traveller = CalculatorTraveller;
4391+
traveller.Copy(RearTDBTraveller);
43874392
// The traveller location represents the back of the train.
43884393
var length = 0f;
43894394

@@ -4458,7 +4463,7 @@ public void CalculatePositionOfCars(float elapsedTime, float distance)
44584463
car.UpdateFreightAnimationDiscretePositions();
44594464
}
44604465

4461-
FrontTDBTraveller = traveller;
4466+
(FrontTDBTraveller, CalculatorTraveller) = (CalculatorTraveller, FrontTDBTraveller);
44624467
Length = length;
44634468
travelled += distance;
44644469
} // CalculatePositionOfCars
@@ -6526,7 +6531,7 @@ public void ObtainRequiredActions(int backward)
65266531
public void UpdateSectionState(int backward)
65276532
{
65286533

6529-
List<int[]> sectionList = new List<int[]>();
6534+
sectionList.Clear();
65306535

65316536
int lastIndex = PreviousPosition[0].RouteListIndex;
65326537
int presentIndex = PresentPosition[0].RouteListIndex;
@@ -20030,6 +20035,7 @@ public RoughReversalInfo(int subPathIndex, float reverseReversalOffset, int reve
2003020035

2003120036
public class DistanceTravelledActions : LinkedList<DistanceTravelledItem>
2003220037
{
20038+
readonly List<DistanceTravelledItem> itemList = new List<DistanceTravelledItem>();
2003320039

2003420040
//================================================================================================//
2003520041
//
@@ -20116,7 +20122,7 @@ public void InsertClearSection(float distance, int sectionIndex)
2011620122

2011720123
public List<DistanceTravelledItem> GetActions(float distance)
2011820124
{
20119-
List<DistanceTravelledItem> itemList = new List<DistanceTravelledItem>();
20125+
itemList.Clear();
2012020126

2012120127
bool itemsCollected = false;
2012220128
LinkedListNode<DistanceTravelledItem> nextNode = this.First;
@@ -20141,7 +20147,7 @@ public List<DistanceTravelledItem> GetActions(float distance)
2014120147

2014220148
public List<DistanceTravelledItem> GetAuxActions(Train thisTrain, float distance)
2014320149
{
20144-
List<DistanceTravelledItem> itemList = new List<DistanceTravelledItem>();
20150+
itemList.Clear();
2014520151
LinkedListNode<DistanceTravelledItem> nextNode = this.First;
2014620152

2014720153
while (nextNode != null)
@@ -20164,7 +20170,7 @@ public List<DistanceTravelledItem> GetAuxActions(Train thisTrain, float distance
2016420170

2016520171
public List<DistanceTravelledItem> GetActions(float distance, Type reqType)
2016620172
{
20167-
List<DistanceTravelledItem> itemList = new List<DistanceTravelledItem>();
20173+
itemList.Clear();
2016820174

2016920175
bool itemsCollected = false;
2017020176
LinkedListNode<DistanceTravelledItem> nextNode = this.First;

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

+5-9
Original file line numberDiff line numberDiff line change
@@ -2007,22 +2007,18 @@ public override void Update(float elapsedClockSeconds)
20072007
if (RemoteControlGroup != -1)
20082008
{
20092009
if (!LocomotivePowerSupply.MainPowerSupplyOn)
2010-
{
20112010
Train.SignalEvent(PowerSupplyEvent.RaisePantograph, 1);
20122011

2013-
if (this is MSTSDieselLocomotive)
2012+
if (this is MSTSDieselLocomotive dieselLocomotive)
2013+
{
2014+
for (var i = 0; i < dieselLocomotive.DieselEngines.Count; i++)
20142015
{
2015-
foreach (DieselEngine de in (this as MSTSDieselLocomotive).DieselEngines)
2016+
var de = dieselLocomotive.DieselEngines[i];
2017+
if (!LocomotivePowerSupply.MainPowerSupplyOn)
20162018
{
20172019
if (de.State != DieselEngineState.Running)
20182020
de.Initialize();
20192021
}
2020-
}
2021-
}
2022-
if (this is MSTSDieselLocomotive)
2023-
{
2024-
foreach (DieselEngine de in (this as MSTSDieselLocomotive).DieselEngines)
2025-
{
20262022
if (de.GearBox != null)
20272023
de.GearBox.GearBoxOperation = GearBoxOperation.Automatic;
20282024
}

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ public override void Update(float elapsedClockSeconds)
18641864

18651865
AuxWagonType = "AuxiliaryTender";
18661866
}
1867-
else
1867+
else if (AuxWagonType == "")
18681868
{
18691869
AuxWagonType = WagonType.ToString();
18701870
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/LocomotivePowerSupply.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ public float ElectricTrainSupplyPowerW
5555
{
5656
get
5757
{
58-
return Train.Cars.OfType<MSTSWagon>()
59-
.Where(wagon => wagon.PassengerCarPowerSupply != null)
60-
.Where(wagon => wagon.PassengerCarPowerSupply.ElectricTrainSupplyConnectedLocomotives.Contains(Locomotive))
61-
.Select(wagon => wagon.PassengerCarPowerSupply.ElectricTrainSupplyPowerW / wagon.PassengerCarPowerSupply.ElectricTrainSupplyConnectedLocomotives.Count())
62-
.Sum();
58+
float result = 0;
59+
foreach (var car in Train.Cars)
60+
{
61+
if (car == null) continue;
62+
if (!(car is MSTSWagon wagon)) continue;
63+
if (!(wagon.PassengerCarPowerSupply?.ElectricTrainSupplyConnectedLocomotives.Contains(Locomotive) ?? false)) continue;
64+
result += wagon.PassengerCarPowerSupply.ElectricTrainSupplyPowerW / wagon.PassengerCarPowerSupply.ElectricTrainSupplyConnectedLocomotives.Count();
65+
}
66+
return result;
6367
}
6468
}
6569

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,11 @@ public enum Permission
138138

139139
public bool CallOnEnabled = false; // set if signal script file uses CallOn functionality
140140

141+
private readonly List<int> passedSections = new List<int>();
141142
private readonly List<int> SectionsWithAlternativePath = new List<int>();
142143
private readonly List<int> SectionsWithAltPathSet = new List<int>();
144+
private readonly static List<int> sectionsInRoute = new List<int>();
145+
private static readonly ObjectSpeedInfo DefaultSpeedInfo = new ObjectSpeedInfo(-1, -1, false, false, 0, false);
143146

144147
public bool enabled
145148
{
@@ -906,11 +909,11 @@ public MstsSignalAspect this_sig_lr(SignalFunction function, ref bool sigfound)
906909
public ObjectSpeedInfo this_sig_speed(SignalFunction function)
907910
{
908911
var sigAsp = MstsSignalAspect.STOP;
909-
var set_speed = new ObjectSpeedInfo(-1, -1, false, false, 0, false);
912+
var set_speed = DefaultSpeedInfo;
910913

911-
foreach (SignalHead sigHead in SignalHeads.Where(sigHead => sigHead.Function == function))
914+
foreach (SignalHead sigHead in SignalHeads)
912915
{
913-
if (sigHead.state >= sigAsp && sigHead.CurrentSpeedInfo != null)
916+
if (sigHead.Function == function && sigHead.state >= sigAsp && sigHead.CurrentSpeedInfo != null)
914917
{
915918
sigAsp = sigHead.state;
916919
set_speed = sigHead.CurrentSpeedInfo;
@@ -1292,7 +1295,7 @@ public bool route_set(int req_mainnode, uint req_jnnode)
12921295
int sectionIndex = -1;
12931296
bool passedTrackJn = false;
12941297

1295-
List<int> passedSections = new List<int>();
1298+
passedSections.Clear();
12961299
passedSections.Add(thisSection.Index);
12971300

12981301
routeset = req_mainnode == thisSection.OriginalIndex;
@@ -2157,7 +2160,7 @@ public bool requestClearSignal(Train.TCSubpathRoute RoutePart, Train.TrainRouted
21572160
// copy sections upto next normal signal
21582161
// check for loop
21592162

2160-
List<int> sectionsInRoute = new List<int>();
2163+
sectionsInRoute.Clear();
21612164

21622165
for (int iNode = foundFirstSection; iNode < RoutePart.Count && foundLastSection < 0; iNode++)
21632166
{

Source/Orts.Simulation/Simulation/Signalling/TrackCircuitState.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class TrackCircuitState
3636
public int RemoteReserved; // remote reserved (number only) //
3737
public bool Forced; // forced by human dispatcher //
3838

39+
List<Train.TrainRouted> TrainOccupyList; // used for allocation-free returning of the TrainOccuping() result //
40+
3941
public TrackCircuitState()
4042
{
4143
TrainOccupy = new TrainOccupyState();
@@ -253,12 +255,13 @@ public void Save(BinaryWriter outf)
253255
/// </summary>
254256
public List<Train.TrainRouted> TrainsOccupying()
255257
{
256-
List<Train.TrainRouted> reqList = new List<Train.TrainRouted>();
258+
TrainOccupyList = TrainOccupyList ?? new List<Train.TrainRouted>();
259+
TrainOccupyList.Clear();
257260
foreach (KeyValuePair<Train.TrainRouted, int> thisTCT in TrainOccupy)
258261
{
259-
reqList.Add(thisTCT.Key);
262+
TrainOccupyList.Add(thisTCT.Key);
260263
}
261-
return (reqList);
264+
return (TrainOccupyList);
262265
}
263266

264267
/// <summary>
@@ -267,15 +270,16 @@ public void Save(BinaryWriter outf)
267270
/// </summary>
268271
public List<Train.TrainRouted> TrainsOccupying(int reqDirection)
269272
{
270-
List<Train.TrainRouted> reqList = new List<Train.TrainRouted>();
273+
TrainOccupyList = TrainOccupyList ?? new List<Train.TrainRouted>();
274+
TrainOccupyList.Clear();
271275
foreach (KeyValuePair<Train.TrainRouted, int> thisTCT in TrainOccupy)
272276
{
273277
if (thisTCT.Value == reqDirection)
274278
{
275-
reqList.Add(thisTCT.Key);
279+
TrainOccupyList.Add(thisTCT.Key);
276280
}
277281
}
278-
return (reqList);
282+
return (TrainOccupyList);
279283
}
280284

281285
/// <summary>

Source/Orts.Simulation/Simulation/Traveller.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public enum TravellerDirection : byte
4747
// experimentally to match MSTS's 'capture range'.
4848
const float MaximumCenterlineOffset = 2.5f;
4949

50-
readonly TrackSectionsFile TSectionDat;
51-
readonly TrackNode[] TrackNodes;
50+
TrackSectionsFile TSectionDat;
51+
TrackNode[] TrackNodes;
5252
TravellerDirection direction = TravellerDirection.Forward;
5353
float trackOffset; // Offset into track (vector) section; meters for straight sections, radians for curved sections.
5454
TrackNode trackNode;
@@ -333,8 +333,6 @@ public Traveller(TrackSectionsFile tSectionDat, TrackNode[] trackNodes, TrackNod
333333
public Traveller(Traveller copy)
334334
{
335335
if (copy == null) throw new ArgumentNullException("copy");
336-
TSectionDat = copy.TSectionDat;
337-
TrackNodes = copy.TrackNodes;
338336
Copy(copy);
339337
}
340338

@@ -600,8 +598,10 @@ private static bool InitTrackSectionSucceeded(Traveller traveller, WorldLocation
600598

601599

602600

603-
void Copy(Traveller copy)
601+
public void Copy(Traveller copy)
604602
{
603+
TSectionDat = copy.TSectionDat;
604+
TrackNodes = copy.TrackNodes;
605605
locationSet = copy.locationSet;
606606
location.TileX = copy.location.TileX;
607607
location.TileZ = copy.location.TileZ;

0 commit comments

Comments
 (0)