public World(Viewer viewer) { Viewer = viewer; PerformanceInitialViewingDistance = Viewer.Settings.ViewingDistance; PerformanceInitialLODBias = Viewer.Settings.LODBias; // Control stuff first. WeatherControl = new WeatherControl(viewer); // Then drawers. if (viewer.Settings.UseMSTSEnv) { MSTSSky = new MSTSSkyDrawer(viewer); } else { Sky = new SkyViewer(viewer); } Precipitation = new PrecipitationViewer(viewer, WeatherControl); Terrain = new TerrainViewer(viewer); Scenery = new SceneryDrawer(viewer); Trains = new TrainDrawer(viewer); RoadCars = new RoadCarViewer(viewer); // Then sound. if (viewer.Settings.SoundDetailLevel > 0) { // Keep it silent while loading. ALSoundSource.MuteAll(); // TODO: This looks kinda evil; do something about it. GameSounds = new SoundSource(viewer, Events.Source.MSTSInGame, viewer.Simulator.RoutePath + "\\Sound\\ingame.sms", true); Viewer.SoundProcess.AddSoundSources(GameSounds.SMSFolder + "\\" + GameSounds.SMSFileName, new List <SoundSourceBase>() { GameSounds }); Sounds = new WorldSounds(viewer); } }
// Check for correctness of parameters and initialize rates of change public void WeatherChange_Init(ORTSWeatherChange eventWeatherChange, WeatherControl weatherControl) { var wChangeOn = false; if (eventWeatherChange.ORTSOvercast >= 0 && eventWeatherChange.ORTSOvercastTransitionTimeS >= 0) { ORTSOvercast = eventWeatherChange.ORTSOvercast; ORTSOvercastTransitionTimeS = eventWeatherChange.ORTSOvercastTransitionTimeS; overcastTimer = (float)ORTSOvercastTransitionTimeS; overcastChangeRate = overcastTimer > 0 ? (MathHelper.Clamp(ORTSOvercast, 0, 1.0f) - weatherControl.Weather.OvercastFactor) / ORTSOvercastTransitionTimeS : 0; wChangeOn = true; } if (eventWeatherChange.ORTSFog >= 0 && eventWeatherChange.ORTSFogTransitionTimeS >= 0) { ORTSFog = eventWeatherChange.ORTSFog; ORTSFogTransitionTimeS = eventWeatherChange.ORTSFogTransitionTimeS; fogTimer = (float)ORTSFogTransitionTimeS; var fogFinalValue = MathHelper.Clamp(ORTSFog, 10, 100000); fogDistanceIncreasing = false; fogChangeRate = fogTimer > 0 ? (fogFinalValue - weatherControl.Weather.FogDistance) / (ORTSFogTransitionTimeS * ORTSFogTransitionTimeS) : 0; if (fogFinalValue > weatherControl.Weather.FogDistance) { fogDistanceIncreasing = true; fogChangeRate = -fogChangeRate; ORTSFog = weatherControl.Weather.FogDistance; } wChangeOn = true; } if (eventWeatherChange.ORTSPrecipitationIntensity >= 0 && eventWeatherChange.ORTSPrecipitationIntensityTransitionTimeS >= 0) { ORTSPrecipitationIntensity = eventWeatherChange.ORTSPrecipitationIntensity; ORTSPrecipitationIntensityTransitionTimeS = eventWeatherChange.ORTSPrecipitationIntensityTransitionTimeS; precipitationIntensityTimer = (float)ORTSPrecipitationIntensityTransitionTimeS; // Pricipitation ranges from 0 to max PrecipitationViewer.MaxIntensityPPSPM2 if 32bit. // 16bit uses PrecipitationViewer.MaxIntensityPPSPM2_16 if (weatherControl.Viewer.GraphicsDevice.GraphicsDeviceCapabilities.MaxVertexIndex > 0xFFFF) { precipitationIntensityChangeRate = precipitationIntensityTimer > 0 ? (MathHelper.Clamp(ORTSPrecipitationIntensity, 0, PrecipitationViewer.MaxIntensityPPSPM2) - weatherControl.Weather.PricipitationIntensityPPSPM2) / ORTSPrecipitationIntensityTransitionTimeS : 0; } else { precipitationIntensityChangeRate = precipitationIntensityTimer > 0 ? (MathHelper.Clamp(ORTSPrecipitationIntensity, 0, PrecipitationViewer.MaxIntensityPPSPM2_16) - weatherControl.Weather.PricipitationIntensityPPSPM2) / ORTSPrecipitationIntensityTransitionTimeS : 0; } wChangeOn = true; } if (eventWeatherChange.ORTSPrecipitationLiquidity >= 0 && eventWeatherChange.ORTSPrecipitationLiquidityTransitionTimeS >= 0) { ORTSPrecipitationLiquidity = eventWeatherChange.ORTSPrecipitationLiquidity; ORTSPrecipitationLiquidityTransitionTimeS = eventWeatherChange.ORTSPrecipitationLiquidityTransitionTimeS; precipitationLiquidityTimer = (float)ORTSPrecipitationLiquidityTransitionTimeS; precipitationLiquidityChangeRate = precipitationLiquidityTimer > 0 ? (MathHelper.Clamp(ORTSPrecipitationLiquidity, 0, 1.0f) - weatherControl.Weather.PrecipitationLiquidity) / ORTSPrecipitationLiquidityTransitionTimeS : 0; wChangeOn = true; } weatherControl.weatherChangeOn = wChangeOn; }
public void DynamicUpdate(WeatherControl weatherControl, Weather weather, Viewer viewer, ref Vector3 wind) { if (!weatherControl.weatherChangeOn || weatherControl.dynamicWeather.precipitationLiquidityTimer <= 0) { return; } ParticleDuration = ParticleBoxHeightM / ((RainVelocityMpS - SnowVelocityMpS) * weather.PrecipitationLiquidity + SnowVelocityMpS) / ParticleVelocityFactor; wind.X = 18 * weather.PrecipitationLiquidity + 2; ParticleDirection = wind; }
public PrecipitationViewer(Viewer viewer, WeatherControl weatherControl) { Viewer = viewer; WeatherControl = weatherControl; Weather = viewer.Simulator.Weather; Material = viewer.MaterialManager.Load("Precipitation"); Pricipitation = new PrecipitationPrimitive(Viewer.GraphicsDevice); Wind = new Vector3(0, 0, 0); Reset(); }
public PrecipitationViewer(Viewer viewer, WeatherControl weatherControl) { IndexesAre32bit = viewer.Settings.IsDirectXFeatureLevelIncluded(ORTS.Settings.UserSettings.DirectXFeature.Level10_0); Viewer = viewer; WeatherControl = weatherControl; Weather = viewer.Simulator.Weather; Material = viewer.MaterialManager.Load("Precipitation"); Pricipitation = new PrecipitationPrimitive(Viewer.GraphicsDevice); Wind = new Vector3(0, 0, 0); Reset(); }
public void WeatherChange_Update(ElapsedTime elapsedTime, WeatherControl weatherControl) { var wChangeOn = false; if (ORTSOvercast >= 0) { overcastTimer -= elapsedTime.ClockSeconds; if (overcastTimer <= 0) { overcastTimer = 0; } else { wChangeOn = true; } weatherControl.Weather.OvercastFactor = ORTSOvercast - overcastTimer * overcastChangeRate; if (overcastTimer == 0) { ORTSOvercast = -1; } } if (ORTSFog >= 0) { fogTimer -= elapsedTime.ClockSeconds; if (fogTimer <= 0) { fogTimer = 0; } else { wChangeOn = true; } if (!fogDistanceIncreasing) { weatherControl.Weather.FogDistance = ORTSFog - fogTimer * fogTimer * fogChangeRate; } else { var fogTimerDifference = ORTSFogTransitionTimeS - fogTimer; weatherControl.Weather.FogDistance = ORTSFog - fogTimerDifference * fogTimerDifference * fogChangeRate; } if (fogTimer == 0) { ORTSFog = -1; } } if (ORTSPrecipitationIntensity >= 0) { precipitationIntensityTimer -= elapsedTime.ClockSeconds; if (precipitationIntensityTimer <= 0) { precipitationIntensityTimer = 0; } else { wChangeOn = true; } var oldPricipitationIntensityPPSPM2 = weatherControl.Weather.PricipitationIntensityPPSPM2; weatherControl.Weather.PricipitationIntensityPPSPM2 = ORTSPrecipitationIntensity - precipitationIntensityTimer * precipitationIntensityChangeRate; if (weatherControl.Weather.PricipitationIntensityPPSPM2 > 0) { if (oldPricipitationIntensityPPSPM2 == 0) { if (weatherControl.Weather.PrecipitationLiquidity > RainSnowLiquidityThreshold) { weatherControl.Viewer.Simulator.WeatherType = WeatherType.Rain; } else { weatherControl.Viewer.Simulator.WeatherType = WeatherType.Snow; } weatherControl.UpdateSoundSources(); } weatherControl.UpdateVolume(); } if (weatherControl.Weather.PricipitationIntensityPPSPM2 == 0) { if (oldPricipitationIntensityPPSPM2 > 0) { weatherControl.Viewer.Simulator.WeatherType = WeatherType.Clear; weatherControl.UpdateSoundSources(); } } if (precipitationIntensityTimer == 0) { ORTSPrecipitationIntensity = -1; } } if (ORTSPrecipitationLiquidity >= 0) { precipitationLiquidityTimer -= elapsedTime.ClockSeconds; if (precipitationLiquidityTimer <= 0) { precipitationLiquidityTimer = 0; } else { wChangeOn = true; } var oldPrecipitationLiquidity = weatherControl.Weather.PrecipitationLiquidity; weatherControl.Weather.PrecipitationLiquidity = ORTSPrecipitationLiquidity - precipitationLiquidityTimer * precipitationLiquidityChangeRate; if (weatherControl.Weather.PrecipitationLiquidity > RainSnowLiquidityThreshold) { if (oldPrecipitationLiquidity <= RainSnowLiquidityThreshold) { weatherControl.Viewer.Simulator.WeatherType = WeatherType.Rain; weatherControl.UpdateSoundSources(); weatherControl.UpdateVolume(); } } if (weatherControl.Weather.PrecipitationLiquidity <= RainSnowLiquidityThreshold) { if (oldPrecipitationLiquidity > RainSnowLiquidityThreshold) { weatherControl.Viewer.Simulator.WeatherType = WeatherType.Snow; weatherControl.UpdateSoundSources(); weatherControl.UpdateVolume(); } } if (precipitationLiquidityTimer == 0) { ORTSPrecipitationLiquidity = -1; } } weatherControl.weatherChangeOn = wChangeOn; }