Skip to content

Commit 3bce395

Browse files
committed
feat: Remove precipitation customisation
1 parent eb92d81 commit 3bce395

File tree

3 files changed

+16
-121
lines changed

3 files changed

+16
-121
lines changed

Source/ORTS.Settings/UserSettings.cs

-6
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,6 @@ public enum DirectXFeature
315315
public bool AdhesionProportionalToWeather { get; set; }
316316
[Default(false)]
317317
public bool NoForcedRedAtStationStops { get; set; }
318-
[Default(100)]
319-
public int PrecipitationBoxHeight { get; set; }
320-
[Default(500)]
321-
public int PrecipitationBoxWidth { get; set; }
322-
[Default(500)]
323-
public int PrecipitationBoxLength { get; set; }
324318
[Default(false)]
325319
public bool CorrectQuestionableBrakingParams { get; set; }
326320
[Default(false)]

Source/RunActivity/Viewer3D/Precipitation.cs

+8-83
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2010, 2011, 2012, 2013, 2014 by the Open Rails project.
1+
// COPYRIGHT 2009 - 2023 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -33,13 +33,7 @@ public class PrecipitationViewer
3333
{
3434
public const float MinIntensityPPSPM2 = 0;
3535

36-
// 16 bit version.
37-
public const float MaxIntensityPPSPM2_16 = 0.010f;
38-
39-
// Default 32 bit version.
40-
public const float MaxIntensityPPSPM2 = 0.035f;
41-
42-
public static bool IndexesAre32bit;
36+
public const float MaxIntensityPPSPM2 = 0.015f;
4337

4438
readonly Viewer Viewer;
4539
readonly Weather Weather;
@@ -51,8 +45,6 @@ public class PrecipitationViewer
5145

5246
public PrecipitationViewer(Viewer viewer)
5347
{
54-
IndexesAre32bit = viewer.Settings.IsDirectXFeatureLevelIncluded(ORTS.Settings.UserSettings.DirectXFeature.Level10_0);
55-
5648
Viewer = viewer;
5749
Weather = viewer.Simulator.Weather;
5850

@@ -114,14 +106,9 @@ public class PrecipitationPrimitive : RenderPrimitive
114106
// This is a fiddle factor because the above values feel too slow. Alternative suggestions welcome.
115107
const float ParticleVelocityFactor = 10.0f;
116108

117-
readonly float ParticleBoxLengthM;
118-
readonly float ParticleBoxWidthM;
119-
readonly float ParticleBoxHeightM;
120-
121-
// 16bit Box Parameters
122-
const float ParticleBoxLengthM_16 = 500;
123-
const float ParticleBoxWidthM_16 = 500;
124-
const float ParticleBoxHeightM_16 = 43;
109+
const float ParticleBoxLengthM = 500;
110+
const float ParticleBoxWidthM = 500;
111+
const float ParticleBoxHeightM = 43;
125112

126113
const int IndicesPerParticle = 6;
127114
const int VerticiesPerParticle = 4;
@@ -170,51 +157,14 @@ struct ParticleVertex
170157
public PrecipitationPrimitive(GraphicsDevice graphicsDevice)
171158
{
172159
// Snow is the slower particle, hence longer duration, hence more particles in total.
173-
// Setting the precipitation box size based on GraphicsDeviceCapabilities.
174-
if (PrecipitationViewer.IndexesAre32bit)
175-
{
176-
ParticleBoxLengthM = (float)Program.Simulator.Settings.PrecipitationBoxLength;
177-
ParticleBoxWidthM = (float)Program.Simulator.Settings.PrecipitationBoxWidth;
178-
ParticleBoxHeightM = (float)Program.Simulator.Settings.PrecipitationBoxHeight;
179-
}
180-
else
181-
{
182-
ParticleBoxLengthM = ParticleBoxLengthM_16;
183-
ParticleBoxWidthM = ParticleBoxWidthM_16;
184-
ParticleBoxHeightM = ParticleBoxHeightM_16;
185-
}
186-
187-
if (PrecipitationViewer.IndexesAre32bit)
188-
{
189-
MaxParticles = (int)(PrecipitationViewer.MaxIntensityPPSPM2 * ParticleBoxLengthM * ParticleBoxWidthM * ParticleBoxHeightM / SnowVelocityMpS / ParticleVelocityFactor);
190-
}
191-
192-
// Processing 16bit device
193-
else
194-
{
195-
MaxParticles = (int)(PrecipitationViewer.MaxIntensityPPSPM2_16 * ParticleBoxLengthM * ParticleBoxWidthM * ParticleBoxHeightM / SnowVelocityMpS / ParticleVelocityFactor);
196-
}
197-
198-
// Checking if graphics device is 16bit.
199-
if (!PrecipitationViewer.IndexesAre32bit)
200-
{
201-
Debug.Assert(MaxParticles * VerticiesPerParticle < ushort.MaxValue, "The maximum number of precipitation verticies must be able to fit in a ushort (16bit unsigned) index buffer.");
202-
}
160+
MaxParticles = (int)(PrecipitationViewer.MaxIntensityPPSPM2 * ParticleBoxLengthM * ParticleBoxWidthM * ParticleBoxHeightM / SnowVelocityMpS / ParticleVelocityFactor);
161+
Debug.Assert(MaxParticles * VerticiesPerParticle < ushort.MaxValue, "The maximum number of precipitation verticies must be able to fit in a ushort (16bit unsigned) index buffer.");
203162

204163
Vertices = new ParticleVertex[MaxParticles * VerticiesPerParticle];
205164
VertexDeclaration = new VertexDeclaration(ParticleVertex.SizeInBytes, ParticleVertex.VertexElements);
206165
VertexStride = Marshal.SizeOf(typeof(ParticleVertex));
207166
VertexBuffer = new DynamicVertexBuffer(graphicsDevice, VertexDeclaration, MaxParticles * VerticiesPerParticle, BufferUsage.WriteOnly);
208-
209-
// Processing either 32bit or 16bit InitIndexBuffer depending on GraphicsDeviceCapabilities.
210-
if (PrecipitationViewer.IndexesAre32bit)
211-
{
212-
IndexBuffer = InitIndexBuffer(graphicsDevice, MaxParticles * IndicesPerParticle);
213-
}
214-
else
215-
{
216-
IndexBuffer = InitIndexBuffer16(graphicsDevice, MaxParticles * IndicesPerParticle);
217-
}
167+
IndexBuffer = InitIndexBuffer(graphicsDevice, MaxParticles * IndicesPerParticle);
218168

219169
Heights = new HeightCache(8);
220170

@@ -227,31 +177,7 @@ void VertexBuffer_ContentLost()
227177
VertexBuffer.SetData(0, Vertices, 0, Vertices.Length, VertexStride, SetDataOptions.NoOverwrite);
228178
}
229179

230-
// IndexBuffer for 32bit process.
231180
static IndexBuffer InitIndexBuffer(GraphicsDevice graphicsDevice, int numIndices)
232-
{
233-
var indices = new uint[numIndices];
234-
var index = 0;
235-
for (var i = 0; i < numIndices; i += IndicesPerParticle)
236-
{
237-
indices[i] = (uint)index;
238-
indices[i + 1] = (uint)(index + 1);
239-
indices[i + 2] = (uint)(index + 2);
240-
241-
indices[i + 3] = (uint)(index + 2);
242-
indices[i + 4] = (uint)(index + 3);
243-
indices[i + 5] = (uint)index;
244-
245-
index += VerticiesPerParticle;
246-
}
247-
248-
var indexBuffer = new IndexBuffer(graphicsDevice, typeof(uint), numIndices, BufferUsage.WriteOnly);
249-
indexBuffer.SetData(indices);
250-
return indexBuffer;
251-
}
252-
253-
// IndexBuffer for computers that still use 16bit graphics.
254-
static IndexBuffer InitIndexBuffer16(GraphicsDevice graphicsDevice, int numIndices)
255181
{
256182
var indices = new ushort[numIndices];
257183
var index = 0;
@@ -347,7 +273,6 @@ public void Update(float currentTime, ElapsedTime elapsedTime, float particlesPe
347273
var tiles = viewer.Tiles;
348274
var scenery = viewer.World.Scenery;
349275
var worldLocation = viewer.Camera.CameraWorldLocation;
350-
//var worldLocation = Program.Viewer.PlayerLocomotive.WorldPosition.WorldLocation; // This is used to test overall precipitation position.
351276

352277
if (TimeParticlesLastEmitted == 0)
353278
{

Source/RunActivity/Viewer3D/Weather.cs

+8-32
Original file line numberDiff line numberDiff line change
@@ -206,29 +206,14 @@ void UpdateSoundSources()
206206

207207
void UpdateVolume()
208208
{
209-
if (PrecipitationViewer.IndexesAre32bit)
209+
foreach (var soundSource in RainSound)
210210
{
211-
foreach (var soundSource in RainSound)
212-
{
213-
soundSource.Volume = Weather.PrecipitationIntensityPPSPM2 / PrecipitationViewer.MaxIntensityPPSPM2;
214-
}
215-
216-
foreach (var soundSource in SnowSound)
217-
{
218-
soundSource.Volume = Weather.PrecipitationIntensityPPSPM2 / PrecipitationViewer.MaxIntensityPPSPM2;
219-
}
211+
soundSource.Volume = Weather.PrecipitationIntensityPPSPM2 / PrecipitationViewer.MaxIntensityPPSPM2;
220212
}
221-
else
222-
{
223-
foreach (var soundSource in RainSound)
224-
{
225-
soundSource.Volume = Weather.PrecipitationIntensityPPSPM2 / PrecipitationViewer.MaxIntensityPPSPM2_16;
226-
}
227213

228-
foreach (var soundSource in SnowSound)
229-
{
230-
soundSource.Volume = Weather.PrecipitationIntensityPPSPM2 / PrecipitationViewer.MaxIntensityPPSPM2_16;
231-
}
214+
foreach (var soundSource in SnowSound)
215+
{
216+
soundSource.Volume = Weather.PrecipitationIntensityPPSPM2 / PrecipitationViewer.MaxIntensityPPSPM2;
232217
}
233218
}
234219

@@ -733,18 +718,9 @@ public void WeatherChange_Init(ORTSWeatherChange eventWeatherChange, WeatherCont
733718
ORTSPrecipitationIntensityTransitionTimeS = eventWeatherChange.ORTSPrecipitationIntensityTransitionTimeS;
734719
precipitationIntensityTimer = (float)ORTSPrecipitationIntensityTransitionTimeS;
735720

736-
// Pricipitation ranges from 0 to max PrecipitationViewer.MaxIntensityPPSPM2 if 32bit.
737-
// 16bit uses PrecipitationViewer.MaxIntensityPPSPM2_16
738-
if (PrecipitationViewer.IndexesAre32bit)
739-
{
740-
precipitationIntensityChangeRate = precipitationIntensityTimer > 0 ? (MathHelper.Clamp(ORTSPrecipitationIntensity, 0, PrecipitationViewer.MaxIntensityPPSPM2)
741-
- weatherControl.Weather.PrecipitationIntensityPPSPM2) / ORTSPrecipitationIntensityTransitionTimeS : 0;
742-
}
743-
else
744-
{
745-
precipitationIntensityChangeRate = precipitationIntensityTimer > 0 ? (MathHelper.Clamp(ORTSPrecipitationIntensity, 0, PrecipitationViewer.MaxIntensityPPSPM2_16)
746-
- weatherControl.Weather.PrecipitationIntensityPPSPM2) / ORTSPrecipitationIntensityTransitionTimeS : 0;
747-
}
721+
// Precipitation ranges from 0 to max PrecipitationViewer.MaxIntensityPPSPM2 if 32bit.
722+
precipitationIntensityChangeRate = precipitationIntensityTimer > 0 ? (MathHelper.Clamp(ORTSPrecipitationIntensity, 0, PrecipitationViewer.MaxIntensityPPSPM2)
723+
- weatherControl.Weather.PrecipitationIntensityPPSPM2) / ORTSPrecipitationIntensityTransitionTimeS : 0;
748724

749725
wChangeOn = true;
750726
}

0 commit comments

Comments
 (0)