Skip to content

Commit 1321417

Browse files
authored
Merge pull request #639 from twpol/feature/correct-random
fix: Use correct randomness source for viewer weather
2 parents e465222 + 26c4dbf commit 1321417

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

Source/Orts.Simulation/MultiPlayer/ClientComm.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public void Receive(object client)
8888
while (true)
8989
{
9090
bytesRead = 0;
91-
//System.Threading.Thread.Sleep(Program.Random.Next(50, 200));
9291
try
9392
{
9493
//blocks until a client sends a message

Source/Orts.Simulation/MultiPlayer/OnlinePlayer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public void Receive(object client)
106106

107107
while (true)
108108
{
109-
//System.Threading.Thread.Sleep(Program.Random.Next(50, 200));
110109

111110
bytesRead = 0;
112111

Source/RunActivity/Viewer3D/Weather.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public WeatherControl(Viewer viewer)
107107
UpdateSoundSources();
108108
UpdateVolume();
109109
// We have a pause in weather change, depending from randomization level
110-
dynamicWeather.stableWeatherTimer = ( 4.0f - Viewer.Settings.ActWeatherRandomizationLevel) * 600 + Simulator.Random.Next(300) - 150;
110+
dynamicWeather.stableWeatherTimer = ( 4.0f - Viewer.Settings.ActWeatherRandomizationLevel) * 600 + Viewer.Random.Next(300) - 150;
111111
weatherChangeOn = true;
112112
}
113113

@@ -262,14 +262,14 @@ private bool RandomizeInitialWeather()
262262
CheckDesertZone();
263263
if (DesertZone) return false;
264264
// First define overcast
265-
var randValue = Simulator.Random.Next(170);
265+
var randValue = Viewer.Random.Next(170);
266266
var intermValue = randValue >= 50 ? (float)(randValue - 50f) : (float)randValue;
267267
Weather.OvercastFactor = intermValue >= 20 ? (float)(intermValue - 20f)/100f: (float)intermValue/100f; // give more probability to less overcast
268268
Viewer.Simulator.WeatherType = Orts.Formats.Msts.WeatherType.Clear;
269269
// Then check if we are in precipitation zone
270270
if (Weather.OvercastFactor > 0.5)
271271
{
272-
randValue = Simulator.Random.Next(75);
272+
randValue = Viewer.Random.Next(75);
273273
if (randValue > 40)
274274
{
275275
Weather.PricipitationIntensityPPSPM2 = (float)(randValue - 40f) / 1000f;
@@ -288,7 +288,7 @@ private bool RandomizeInitialWeather()
288288
}
289289
else Weather.PricipitationIntensityPPSPM2 = 0;
290290
// and now define visibility
291-
randValue = Simulator.Random.Next(2000);
291+
randValue = Viewer.Random.Next(2000);
292292
if (Weather.PricipitationIntensityPPSPM2 > 0 || Weather.OvercastFactor > 0.7f )
293293
// use first digit to define power of ten and the other three to define the multiplying number
294294
Weather.FogDistance = Math.Max ( 100, (float)Math.Pow(10 , ((int)(randValue / 1000) + 2)) * (float)((randValue % 1000 + 1) / 100f));
@@ -772,9 +772,9 @@ public void WeatherChange_NextRandomization(ElapsedTime elapsedTime, WeatherCont
772772
{
773773
// define how much time transition will last
774774
var weatherChangeTimer = (4 - weatherControl.Viewer.Settings.ActWeatherRandomizationLevel) * 600 +
775-
Simulator.Random.Next((4 - weatherControl.Viewer.Settings.ActWeatherRandomizationLevel) * 600);
775+
Viewer.Random.Next((4 - weatherControl.Viewer.Settings.ActWeatherRandomizationLevel) * 600);
776776
// begin with overcast
777-
var randValue = Simulator.Random.Next(170);
777+
var randValue = Viewer.Random.Next(170);
778778
var intermValue = randValue >= 50 ? (float)(randValue - 50f) : (float)randValue;
779779
ORTSOvercast = intermValue >= 20 ? (float)(intermValue - 20f) / 100f : (float)intermValue / 100f; // give more probability to less overcast
780780
ORTSOvercastTransitionTimeS = weatherChangeTimer;
@@ -783,7 +783,7 @@ public void WeatherChange_NextRandomization(ElapsedTime elapsedTime, WeatherCont
783783
// Then check if we are in precipitation zone
784784
if (ORTSOvercast > 0.5)
785785
{
786-
randValue = Simulator.Random.Next(75);
786+
randValue = Viewer.Random.Next(75);
787787
if (randValue > 40)
788788
{
789789
ORTSPrecipitationIntensity = (float)(randValue - 40f) / 1000f;
@@ -821,7 +821,7 @@ public void WeatherChange_NextRandomization(ElapsedTime elapsedTime, WeatherCont
821821
}
822822

823823
// and now define visibility
824-
randValue = Simulator.Random.Next(2000);
824+
randValue = Viewer.Random.Next(2000);
825825
if (ORTSPrecipitationIntensity > 0 || ORTSOvercast > 0.7f)
826826
// use first digit to define power of ten and the other three to define the multiplying number
827827
ORTSFog = Math.Max(100, (float)Math.Pow(10, ((int)(randValue / 1000) + 2)) * (float)((randValue % 1000 + 1) / 100f));

0 commit comments

Comments
 (0)