Skip to content

Commit f52de67

Browse files
committed
Automatic merge of T1.5.1-351-gc9abcd22b and 8 pull requests
- Pull request #570 at 14abf7a: Experimental glTF 2.0 support with PBR lighting - Pull request #732 at 1edb2e5: Improvements for air brakes - Pull request #751 at 00981a2: Web interface to control cab controls with external hardware - Pull request #767 at 82c5f1c: Refine sunrise and sunset - Pull request #799 at eb92d81: Consolidated wind simulation - Pull request #803 at 7157e08: Various adjustments to steam adhesion - Pull request #809 at f67822a: Some on-screen messages not suppressed, Bug #2008012 - Pull request #813 at a8e9d9b: Refactored garbage generators
10 parents 3c5bb31 + c9abcd2 + 14abf7a + 1edb2e5 + 00981a2 + 82c5f1c + eb92d81 + 7157e08 + f67822a + a8e9d9b commit f52de67

File tree

19 files changed

+835
-529
lines changed

19 files changed

+835
-529
lines changed

Source/ORTS.Common/Conversions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ public static class FormatStrings
573573
public static string kN = Catalog.GetString("kN");
574574
public static string lbf = Catalog.GetString("lbf");
575575
public static string klbf = Catalog.GetString("klbf");
576+
public static string deg = Catalog.GetString("°");
576577

577578
/// <summary>
578579
/// Formatted unlocalized speed string, used in reports and logs.
@@ -814,6 +815,11 @@ public static string FormatPressure(float pressure, PressureUnit inputUnit, Pres
814815
return String.Format(CultureInfo.CurrentCulture, format, pressureOut);
815816
}
816817

818+
public static string FormatAngleDeg(float angleDeg)
819+
{
820+
return String.Format(CultureInfo.CurrentCulture, "{0:F0} {1}", angleDeg, deg);
821+
}
822+
817823
/// <summary>
818824
/// Converts duration in floating-point seconds to whole hours, minutes and seconds (rounded down).
819825
/// </summary>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ public void AIUpdate(float elapsedClockSeconds, double clockTime, bool preUpdate
722722

723723
if (Cars[0] is MSTSLocomotive leadingLoco)
724724
{
725-
var isRainingOrSnowing = Simulator.Weather.PricipitationIntensityPPSPM2 > 0;
725+
var isRainingOrSnowing = Simulator.Weather.PrecipitationIntensityPPSPM2 > 0;
726726
if (leadingLoco.Wiper && !isRainingOrSnowing)
727727
leadingLoco.SignalEvent(Event.WiperOff);
728728
else if (!leadingLoco.Wiper && isRainingOrSnowing)

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -2111,14 +2111,14 @@ public virtual void physicsUpdate(float elapsedClockSeconds)
21112111
public void UpdateWindComponents()
21122112
{
21132113
// Gets wind direction and speed, and determines HUD display values for the train as a whole.
2114-
//These will be representative of the train whilst it is on a straight track, but each wagon will vary when going around a curve.
2114+
// These will be representative of the train whilst it is on a straight track, but each wagon will vary when going around a curve.
21152115
// Note both train and wind direction will be positive between 0 (north) and 180 (south) through east, and negative between 0 (north) and 180 (south) through west
21162116
// Wind and train direction to be converted to an angle between 0 and 360 deg.
21172117
// Calculate Wind speed and direction, and train direction
21182118
// Update the value of the Wind Speed and Direction for the train
2119-
PhysicsWindDirectionDeg = MathHelper.ToDegrees(Simulator.Weather.WindDirection);
2120-
PhysicsWindSpeedMpS = Simulator.Weather.WindSpeed;
2121-
float TrainSpeedMpS = Math.Abs(SpeedMpS);
2119+
PhysicsWindDirectionDeg = MathHelper.ToDegrees(Simulator.Weather.WindInstantaneousDirectionRad);
2120+
PhysicsWindSpeedMpS = Simulator.Weather.WindInstantaneousSpeedMpS;
2121+
var speedMpS = Math.Abs(SpeedMpS);
21222122

21232123
// If a westerly direction (ie -ve) convert to an angle between 0 and 360
21242124
if (PhysicsWindDirectionDeg < 0)
@@ -2127,7 +2127,7 @@ public void UpdateWindComponents()
21272127
if (PhysicsTrainLocoDirectionDeg < 0)
21282128
PhysicsTrainLocoDirectionDeg += 360;
21292129

2130-
// calculate angle between train and eind direction
2130+
// Calculate angle between train and wind direction
21312131
if (PhysicsWindDirectionDeg > PhysicsTrainLocoDirectionDeg)
21322132
ResultantWindComponentDeg = PhysicsWindDirectionDeg - PhysicsTrainLocoDirectionDeg;
21332133
else if (PhysicsTrainLocoDirectionDeg > PhysicsWindDirectionDeg)
@@ -2143,9 +2143,8 @@ public void UpdateWindComponents()
21432143
if (ResultantWindComponentDeg > 180)
21442144
ResultantWindComponentDeg = 360 - ResultantWindComponentDeg;
21452145

2146-
float WindAngleRad = MathHelper.ToRadians(ResultantWindComponentDeg);
2147-
2148-
WindResultantSpeedMpS = (float)Math.Sqrt(TrainSpeedMpS * TrainSpeedMpS + PhysicsWindSpeedMpS * PhysicsWindSpeedMpS + 2.0f * TrainSpeedMpS * PhysicsWindSpeedMpS * (float)Math.Cos(WindAngleRad));
2146+
var windAngleRad = MathHelper.ToRadians(ResultantWindComponentDeg);
2147+
WindResultantSpeedMpS = (float)Math.Sqrt(speedMpS * speedMpS + PhysicsWindSpeedMpS * PhysicsWindSpeedMpS + 2.0f * speedMpS * PhysicsWindSpeedMpS * (float)Math.Cos(windAngleRad));
21492148
}
21502149

21512150

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -3136,7 +3136,7 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
31363136
{
31373137
var fogBaseFrictionCoefficientFactor = 1.0f;
31383138
var pricBaseFrictionCoefficientFactor = 1.0f;
3139-
float pric = Simulator.Weather.PricipitationIntensityPPSPM2 * 1000;
3139+
float pric = Simulator.Weather.PrecipitationIntensityPPSPM2 * 1000;
31403140
// precipitation will calculate a base coefficient value between 60% (light rain) and 90% (heavy rain) - this will be a factor that is used to adjust the base value
31413141
// assume linear value between upper and lower precipitation values. Limits are set in the weather module, ie Rain = 0.01ppm (10) and Snow = 0.005ppm (5)
31423142
float precGrad = (0.2f - 0) / (10f - 5f);
@@ -3152,7 +3152,7 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
31523152
}
31533153

31543154
// Adjust adhesion for impact of fog - default = 20000m = 20km
3155-
float fog = Simulator.Weather.FogDistance;
3155+
float fog = Simulator.Weather.VisibilityM;
31563156
if (fog < 20000) // as fog thickens then decrease adhesion
31573157
{
31583158
fogBaseFrictionCoefficientFactor = Math.Min((fog * 2.75e-4f + 0.6f), 1.0f); // If fog is less then 2km then it will impact friction, decrease adhesion to 60% (same as light rain transition)

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

+52-58
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ public class MSTSWagon : TrainCar
127127
float TenderWagonMaxCoalMassKG;
128128
float TenderWagonMaxWaterMassKG;
129129

130-
// Wind Impacts
131-
float WagonDirectionDeg;
132-
float WagonResultantWindComponentDeg;
133-
float WagonWindResultantSpeedMpS;
134-
135130
protected float FrictionC1; // MSTS Friction parameters
136131
protected float FrictionE1; // MSTS Friction parameters
137132
protected float FrictionV2; // MSTS Friction parameters
@@ -2879,130 +2874,129 @@ private void UpdateWindForce()
28792874
// Lateral resistance - due to wheel flange being pushed against rail due to side wind.
28802875
// Calculation based upon information provided in AREA 1942 Proceedings - https://archive.org/details/proceedingsofann431942amer - pg 56
28812876

2882-
if (!CarTunnelData.FrontPositionBeyondStartOfTunnel.HasValue && AbsSpeedMpS > 2.2352) // Only calculate wind resistance if option selected in options menu, and not in a tunnel, and speed is sufficient for wind effects (>5mph)
2877+
// Only calculate wind resistance if option selected in options menu, and not in a tunnel, and speed is sufficient for wind effects (>5mph)
2878+
if (!CarTunnelData.FrontPositionBeyondStartOfTunnel.HasValue && AbsSpeedMpS > 2.2352)
28832879
{
2884-
28852880
// Wagon Direction
2886-
float direction = (float)Math.Atan2(WorldPosition.XNAMatrix.M13, WorldPosition.XNAMatrix.M11);
2887-
WagonDirectionDeg = MathHelper.ToDegrees((float)direction);
2881+
var directionRad = (float)Math.Atan2(WorldPosition.XNAMatrix.M13, WorldPosition.XNAMatrix.M11);
2882+
var directionDeg = MathHelper.ToDegrees(directionRad);
28882883

28892884
// If car is flipped, then the car's direction will be reversed by 180 compared to the rest of the train, and thus for calculation purposes only,
28902885
// it is necessary to reverse the "assumed" direction of the car back again. This shouldn't impact the visual appearance of the car.
28912886
if (Flipped)
28922887
{
2893-
WagonDirectionDeg += 180.0f; // Reverse direction of car
2894-
if (WagonDirectionDeg > 360) // If this results in an angle greater then 360, then convert it back to an angle between 0 & 360.
2895-
{
2896-
WagonDirectionDeg -= 360;
2897-
}
2888+
// Reverse direction of car
2889+
directionDeg += 180.0f;
2890+
2891+
// If this results in an angle greater then 360, then convert it back to an angle between 0 & 360.
2892+
if (directionDeg > 360)
2893+
directionDeg -= 360;
28982894
}
28992895

29002896
// If a westerly direction (ie -ve) convert to an angle between 0 and 360
2901-
if (WagonDirectionDeg < 0)
2902-
WagonDirectionDeg += 360;
2903-
2904-
float TrainSpeedMpS = Math.Abs(SpeedMpS);
2897+
if (directionDeg < 0)
2898+
directionDeg += 360;
29052899

29062900
// Find angle between wind and direction of train
2907-
if (Train.PhysicsWindDirectionDeg > WagonDirectionDeg)
2908-
WagonResultantWindComponentDeg = Train.PhysicsWindDirectionDeg - WagonDirectionDeg;
2909-
else if (WagonDirectionDeg > Train.PhysicsWindDirectionDeg)
2910-
WagonResultantWindComponentDeg = WagonDirectionDeg - Train.PhysicsWindDirectionDeg;
2911-
else
2912-
WagonResultantWindComponentDeg = 0.0f;
2901+
var resultantWindComponentDeg = 0.0f;
2902+
if (Train.PhysicsWindDirectionDeg > directionDeg)
2903+
resultantWindComponentDeg = Train.PhysicsWindDirectionDeg - directionDeg;
2904+
else if (directionDeg > Train.PhysicsWindDirectionDeg)
2905+
resultantWindComponentDeg = directionDeg - Train.PhysicsWindDirectionDeg;
29132906

29142907
// Correct wind direction if it is greater then 360 deg, then correct to a value less then 360
2915-
if (Math.Abs(WagonResultantWindComponentDeg) > 360)
2916-
WagonResultantWindComponentDeg = WagonResultantWindComponentDeg - 360.0f;
2908+
if (Math.Abs(resultantWindComponentDeg) > 360)
2909+
resultantWindComponentDeg -= 360.0f;
29172910

29182911
// Wind angle should be kept between 0 and 180 the formulas do not cope with angles > 180. If angle > 180, denotes wind of "other" side of train
2919-
if (WagonResultantWindComponentDeg > 180)
2920-
WagonResultantWindComponentDeg = 360 - WagonResultantWindComponentDeg;
2912+
if (resultantWindComponentDeg > 180)
2913+
resultantWindComponentDeg = 360 - resultantWindComponentDeg;
29212914

2922-
float ResultantWindComponentRad = MathHelper.ToRadians(WagonResultantWindComponentDeg);
2915+
var resultantWindComponentRad = MathHelper.ToRadians(resultantWindComponentDeg);
29232916

29242917
// Find the resultand wind vector for the combination of wind and train speed
2925-
WagonWindResultantSpeedMpS = (float)Math.Sqrt(TrainSpeedMpS * TrainSpeedMpS + Train.PhysicsWindSpeedMpS * Train.PhysicsWindSpeedMpS + 2.0f * TrainSpeedMpS * Train.PhysicsWindSpeedMpS * (float)Math.Cos(ResultantWindComponentRad));
2918+
var windResultantSpeedMpS = (float)Math.Sqrt(AbsSpeedMpS * AbsSpeedMpS + Train.PhysicsWindSpeedMpS * Train.PhysicsWindSpeedMpS + 2.0f * AbsSpeedMpS * Train.PhysicsWindSpeedMpS * (float)Math.Cos(resultantWindComponentRad));
29262919

29272920
// Calculate Drag Resistance
29282921
// The drag resistance will be the difference between the STILL firction calculated using the standard Davies equation,
29292922
// and that produced using the wind resultant speed (combination of wind speed and train speed)
2930-
float TempStillDragResistanceForceN = AbsSpeedMpS * AbsSpeedMpS * DavisCNSSpMM;
2931-
float TempCombinedDragResistanceForceN = WagonWindResultantSpeedMpS * WagonWindResultantSpeedMpS * DavisCNSSpMM; // R3 of Davis formula taking into account wind
2932-
float WindDragResistanceForceN = 0.0f;
2923+
var tempStillDragResistanceForceN = AbsSpeedMpS * AbsSpeedMpS * DavisCNSSpMM;
2924+
var tempCombinedDragResistanceForceN = windResultantSpeedMpS * windResultantSpeedMpS * DavisCNSSpMM; // R3 of Davis formula taking into account wind
2925+
float windDragResistanceForceN;
29332926

29342927
// Find the difference between the Still and combined resistances
29352928
// This difference will be added or subtracted from the overall friction force depending upon the estimated wind direction.
2936-
// Wind typically headon to train - increase resistance - +ve differential
2937-
if (TempCombinedDragResistanceForceN > TempStillDragResistanceForceN)
2929+
if (tempCombinedDragResistanceForceN > tempStillDragResistanceForceN)
29382930
{
2939-
WindDragResistanceForceN = TempCombinedDragResistanceForceN - TempStillDragResistanceForceN;
2931+
// Wind typically headon to train - increase resistance - +ve differential
2932+
windDragResistanceForceN = tempCombinedDragResistanceForceN - tempStillDragResistanceForceN;
29402933
}
2941-
else // wind typically following train - reduce resistance - -ve differential
2934+
else
29422935
{
2943-
WindDragResistanceForceN = TempStillDragResistanceForceN - TempCombinedDragResistanceForceN;
2944-
WindDragResistanceForceN *= -1.0f; // Convert to negative number to allow subtraction from ForceN
2936+
// Wind typically following train - reduce resistance - -ve differential
2937+
windDragResistanceForceN = tempStillDragResistanceForceN - tempCombinedDragResistanceForceN;
2938+
windDragResistanceForceN *= -1.0f; // Convert to negative number to allow subtraction from ForceN
29452939
}
29462940

29472941
// Calculate Lateral Resistance
29482942

29492943
// Calculate lateral resistance due to wind
29502944
// Resistance is due to the wheel flanges being pushed further onto rails when a cross wind is experienced by a train
2951-
float A = Train.PhysicsWindSpeedMpS / AbsSpeedMpS;
2952-
float C = (float)Math.Sqrt((1 + (A * A) + 2.0f * A * Math.Cos(ResultantWindComponentRad)));
2953-
float WindConstant = 8.25f;
2954-
float TrainSpeedMpH = Me.ToMi(pS.TopH(AbsSpeedMpS));
2955-
float WindSpeedMpH = Me.ToMi(pS.TopH(Train.PhysicsWindSpeedMpS));
2945+
var a = Train.PhysicsWindSpeedMpS / AbsSpeedMpS;
2946+
var c = (float)Math.Sqrt((1 + (a * a) + 2.0f * a * Math.Cos(resultantWindComponentRad)));
2947+
var windConstant = 8.25f;
2948+
var speedMpH = Me.ToMi(pS.TopH(AbsSpeedMpS));
29562949

2957-
float WagonFrontalAreaFt2 = Me2.ToFt2(WagonFrontalAreaM2);
2950+
var wagonFrontalAreaFt2 = Me2.ToFt2(WagonFrontalAreaM2);
29582951

2959-
LateralWindForceN = N.FromLbf(WindConstant * A * (float)Math.Sin(ResultantWindComponentRad) * DavisDragConstant * WagonFrontalAreaFt2 * TrainSpeedMpH * TrainSpeedMpH * C);
2952+
LateralWindForceN = N.FromLbf(windConstant * a * (float)Math.Sin(resultantWindComponentRad) * DavisDragConstant * wagonFrontalAreaFt2 * speedMpH * speedMpH * c);
29602953

2961-
float LateralWindResistanceForceN = N.FromLbf(WindConstant * A * (float)Math.Sin(ResultantWindComponentRad) * DavisDragConstant * WagonFrontalAreaFt2 * TrainSpeedMpH * TrainSpeedMpH * C * Train.WagonCoefficientFriction);
2954+
var lateralWindResistanceForceN = N.FromLbf(windConstant * a * (float)Math.Sin(resultantWindComponentRad) * DavisDragConstant * wagonFrontalAreaFt2 * speedMpH * speedMpH * c * Train.WagonCoefficientFriction);
29622955

29632956
// if this car is a locomotive, but not the lead one then recalculate the resistance with lower C value as drag will not be as high on trailing locomotives
29642957
if (WagonType == WagonTypes.Engine && Train.LeadLocomotive != this)
29652958
{
2966-
LateralWindResistanceForceN *= TrailLocoResistanceFactor;
2959+
lateralWindResistanceForceN *= TrailLocoResistanceFactor;
29672960
}
29682961

29692962
// Test to identify whether a tender is attached to the leading engine, if not then the resistance should also be derated as for the locomotive
2970-
bool IsLeadTender = false;
2963+
var isLeadTender = false;
29712964
if (WagonType == WagonTypes.Tender)
29722965
{
2973-
bool PrevCarLead = false;
2966+
var prevCarLead = false;
29742967
foreach (var car in Train.Cars)
29752968
{
29762969
// If this car is a tender and the previous car is the lead locomotive then set the flag so that resistance will be reduced
2977-
if (car == this && PrevCarLead)
2970+
if (car == this && prevCarLead)
29782971
{
2979-
IsLeadTender = true;
2972+
isLeadTender = true;
29802973
break; // If the tender has been identified then break out of the loop, otherwise keep going until whole train is done.
29812974
}
2975+
29822976
// Identify whether car is a lead locomotive or not. This is kept for when the next iteration (next car) is checked.
29832977
if (Train.LeadLocomotive == car)
29842978
{
2985-
PrevCarLead = true;
2979+
prevCarLead = true;
29862980
}
29872981
else
29882982
{
2989-
PrevCarLead = false;
2983+
prevCarLead = false;
29902984
}
29912985
}
29922986

29932987
// If tender is coupled to a trailing locomotive then reduce resistance
2994-
if (!IsLeadTender)
2988+
if (!isLeadTender)
29952989
{
2996-
LateralWindResistanceForceN *= TrailLocoResistanceFactor;
2990+
lateralWindResistanceForceN *= TrailLocoResistanceFactor;
29972991
}
29982992
}
2999-
WindForceN = LateralWindResistanceForceN + WindDragResistanceForceN;
2993+
2994+
WindForceN = lateralWindResistanceForceN + windDragResistanceForceN;
30002995
}
30012996
else
30022997
{
30032998
WindForceN = 0.0f; // Set to zero if wind resistance is not to be calculated
30042999
}
3005-
30063000
}
30073001

30083002
private void UpdateTenderLoad()

0 commit comments

Comments
 (0)