Skip to content

Commit 097b97c

Browse files
committed
refactor: Improved field names and removed unused field
1 parent 546b4c8 commit 097b97c

File tree

10 files changed

+88
-115
lines changed

10 files changed

+88
-115
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,8 +2116,8 @@ public void UpdateWindComponents()
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;
2119+
PhysicsWindDirectionDeg = MathHelper.ToDegrees(Simulator.Weather.WindDirectionRad);
2120+
PhysicsWindSpeedMpS = Simulator.Weather.WindSpeedMpS.Length();
21212121
float TrainSpeedMpS = Math.Abs(SpeedMpS);
21222122

21232123
// If a westerly direction (ie -ve) convert to an angle between 0 and 360

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3117,7 +3117,7 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
31173117
}
31183118

31193119
// Adjust adhesion for impact of fog - default = 20000m = 20km
3120-
float fog = Simulator.Weather.FogDistance;
3120+
float fog = Simulator.Weather.VisibilityM;
31213121
if (fog < 20000) // as fog thickens then decrease adhesion
31223122
{
31233123
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/Weather.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2010, 2011, 2014, 2015 by the Open Rails project.
1+
// COPYRIGHT 2009 - 2023 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -15,6 +15,7 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717

18+
using System;
1819
using Microsoft.Xna.Framework;
1920

2021
namespace Orts.Simulation
@@ -34,24 +35,20 @@ public class Weather
3435
// Moderate 0.5-1.0km
3536
// Heavy <0.5km
3637

37-
// Overcast factor: 0.0 = almost no clouds; 0.1 = wispy clouds; 1.0 = total overcast.
38-
public float OvercastFactor;
38+
// Fog/visibility distance. Ranges from 10m (can't see anything), 5km (medium), 20km (clear) to 100km (clear arctic).
39+
public float VisibilityM;
40+
41+
// Cloud cover factor: 0.0 = almost no clouds; 0.1 = wispy clouds; 1.0 = total overcast.
42+
public float CloudCoverFactor;
3943

4044
// Precipitation intensity in particles per second per meter^2 (PPSPM2).
4145
public float PrecipitationIntensityPPSPM2;
4246

43-
// Fog/visibility distance. Ranges from 10m (can't see anything), 5km (medium), 20km (clear) to 100km (clear arctic).
44-
public float FogDistance;
45-
46-
// Precipitation liquidity; =1 for rain, =0 for snow; intermediate values possible with dynamic weather;
47+
// Precipitation liquidity; 1 = rain, 0 = snow; intermediate values possible with dynamic weather.
4748
public float PrecipitationLiquidity;
4849

49-
public float CalculatedWindDirection;
50-
5150
public Vector2 WindSpeedMpS;
5251

53-
public float WindSpeed => WindSpeedMpS.Length();
54-
55-
public float WindDirection => CalculatedWindDirection;
52+
public float WindDirectionRad => (float)Math.Atan2(WindSpeedMpS.X, WindSpeedMpS.Y);
5653
}
5754
}

Source/RunActivity/Viewer3D/MSTSSky.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
150150
mstsskymoonPhase = 3; // Moon dog only occurs in winter
151151
// Overcast factor: 0.0=almost no clouds; 0.1=wispy clouds; 1.0=total overcast
152152
//mstsskyovercastFactor = MSTSSkyViewer.World.WeatherControl.overcastFactor;
153-
mstsskyfogDistance = MSTSSkyViewer.Simulator.Weather.FogDistance;
153+
mstsskyfogDistance = MSTSSkyViewer.Simulator.Weather.VisibilityM;
154154
}
155155

156156
MPManager manager = MPManager.Instance();

Source/RunActivity/Viewer3D/Materials.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,16 @@ internal void UpdateShaders()
534534
// End headlight illumination
535535
if (Viewer.Settings.UseMSTSEnv == false)
536536
{
537-
SceneryShader.Overcast = Viewer.Simulator.Weather.OvercastFactor;
538-
SceneryShader.SetFog(Viewer.Simulator.Weather.FogDistance, ref SharedMaterialManager.FogColor);
539-
ParticleEmitterShader.SetFog(Viewer.Simulator.Weather.FogDistance, ref SharedMaterialManager.FogColor);
537+
SceneryShader.Overcast = Viewer.Simulator.Weather.CloudCoverFactor;
538+
SceneryShader.SetFog(Viewer.Simulator.Weather.VisibilityM, ref SharedMaterialManager.FogColor);
539+
ParticleEmitterShader.SetFog(Viewer.Simulator.Weather.VisibilityM, ref SharedMaterialManager.FogColor);
540540
SceneryShader.ViewerPos = Viewer.Camera.XnaLocation(Viewer.Camera.CameraWorldLocation);
541541
}
542542
else
543543
{
544544
SceneryShader.Overcast = Viewer.World.MSTSSky.mstsskyovercastFactor;
545545
SceneryShader.SetFog(Viewer.World.MSTSSky.mstsskyfogDistance, ref SharedMaterialManager.FogColor);
546-
ParticleEmitterShader.SetFog(Viewer.Simulator.Weather.FogDistance, ref SharedMaterialManager.FogColor);
546+
ParticleEmitterShader.SetFog(Viewer.Simulator.Weather.VisibilityM, ref SharedMaterialManager.FogColor);
547547
SceneryShader.ViewerPos = Viewer.Camera.XnaLocation(Viewer.Camera.CameraWorldLocation);
548548
}
549549
}

Source/RunActivity/Viewer3D/Popups/HUDWindow.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,11 +1322,12 @@ void TextPageWeather(TableData table)
13221322
TableSetLabelValueColumns(table, 0, 2);
13231323
TextPageHeading(table, Viewer.Catalog.GetString("WEATHER INFORMATION"));
13241324

1325-
TableAddLabelValue(table, Viewer.Catalog.GetString("Visibility"), Viewer.Catalog.GetStringFmt("{0:N0} m", Viewer.Simulator.Weather.FogDistance));
1326-
TableAddLabelValue(table, Viewer.Catalog.GetString("Cloud cover"), Viewer.Catalog.GetStringFmt("{0:F0} %", Viewer.Simulator.Weather.OvercastFactor * 100));
1325+
TableAddLabelValue(table, Viewer.Catalog.GetString("Visibility"), Viewer.Catalog.GetStringFmt("{0:N0} m", Viewer.Simulator.Weather.VisibilityM));
1326+
TableAddLabelValue(table, Viewer.Catalog.GetString("Cloud cover"), Viewer.Catalog.GetStringFmt("{0:F0} %", Viewer.Simulator.Weather.CloudCoverFactor * 100));
13271327
TableAddLabelValue(table, Viewer.Catalog.GetString("Intensity"), Viewer.Catalog.GetStringFmt("{0:F4} p/s/m^2", Viewer.Simulator.Weather.PrecipitationIntensityPPSPM2));
13281328
TableAddLabelValue(table, Viewer.Catalog.GetString("Liquidity"), Viewer.Catalog.GetStringFmt("{0:F0} %", Viewer.Simulator.Weather.PrecipitationLiquidity * 100));
13291329
TableAddLabelValue(table, Viewer.Catalog.GetString("Wind"), Viewer.Catalog.GetStringFmt("{0:F1},{1:F1} m/s", Viewer.Simulator.Weather.WindSpeedMpS.X, Viewer.Simulator.Weather.WindSpeedMpS.Y));
1330+
// TODO: Move ambient temperature into Orts.Simulation.Weather
13301331
TableAddLabelValue(table, Viewer.Catalog.GetString("Amb Temp"), FormatStrings.FormatTemperature(Viewer.PlayerLocomotive.CarOutsideTempC, Viewer.PlayerLocomotive.IsMetric, false));
13311332
}
13321333

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ int round(float x)
14981498
if (_Shader != null)
14991499
{
15001500
// TODO: Readd ability to control night time lighting.
1501-
float overcast = _Viewer.Settings.UseMSTSEnv ? _Viewer.World.MSTSSky.mstsskyovercastFactor : _Viewer.Simulator.Weather.OvercastFactor;
1501+
float overcast = _Viewer.Settings.UseMSTSEnv ? _Viewer.World.MSTSSky.mstsskyovercastFactor : _Viewer.Simulator.Weather.CloudCoverFactor;
15021502
_Shader.SetData(_Viewer.MaterialManager.sunDirection, _isNightTexture, false, overcast);
15031503
_Shader.SetTextureData(cabRect.Left, cabRect.Top, cabRect.Width, cabRect.Height);
15041504
_Shader.CurrentTechnique.Passes[0].Apply();

Source/RunActivity/Viewer3D/Signals.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime, Matrix xnaT
357357
isDay = Viewer.World.Sky.SolarDirection.Y > 0;
358358
else
359359
isDay = Viewer.World.MSTSSky.mstsskysolarDirection.Y > 0;
360-
bool isPoorVisibility = Viewer.Simulator.Weather.FogDistance < 200;
360+
bool isPoorVisibility = Viewer.Simulator.Weather.VisibilityM < 200;
361361
if (!SignalTypeData.DayLight && isDay && !isPoorVisibility)
362362
continue;
363363

Source/RunActivity/Viewer3D/Sky.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public SkyMaterial(Viewer viewer)
378378
public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderItem> renderItems, ref Matrix XNAViewMatrix, ref Matrix XNAProjectionMatrix)
379379
{
380380
// Adjust Fog color for day-night conditions and overcast
381-
FogDay2Night(Viewer.World.Sky.SolarDirection.Y, Viewer.Simulator.Weather.OvercastFactor);
381+
FogDay2Night(Viewer.World.Sky.SolarDirection.Y, Viewer.Simulator.Weather.CloudCoverFactor);
382382

383383
// TODO: Use a dirty flag to determine if it is necessary to set the texture again
384384
SkyShader.StarMapTexture = Viewer.World.Sky.Latitude > 0 ? StarTextureN : StarTextureS;
@@ -387,8 +387,8 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
387387
SkyShader.LightVector = Viewer.World.Sky.SolarDirection;
388388
SkyShader.Time = (float)Viewer.Simulator.ClockTime / 100000;
389389
SkyShader.MoonScale = SkyPrimitive.RadiusM / 20;
390-
SkyShader.Overcast = Viewer.Simulator.Weather.OvercastFactor;
391-
SkyShader.SetFog(Viewer.Simulator.Weather.FogDistance, ref SharedMaterialManager.FogColor);
390+
SkyShader.Overcast = Viewer.Simulator.Weather.CloudCoverFactor;
391+
SkyShader.SetFog(Viewer.Simulator.Weather.VisibilityM, ref SharedMaterialManager.FogColor);
392392
SkyShader.WindSpeed = Viewer.World.Sky.WindSpeed;
393393
SkyShader.WindDirection = Viewer.World.Sky.WindDirection; // Keep setting this after Time and Windspeed. Calculating displacement here.
394394

0 commit comments

Comments
 (0)