Exemplo n.º 1
0
 public void RestoreWeatherParameters(BinaryReader inf)
 {
     Weather.FogDistance    = inf.ReadSingle();
     Weather.OvercastFactor = inf.ReadSingle();
     Weather.PricipitationIntensityPPSPM2 = inf.ReadSingle();
     Weather.PrecipitationLiquidity       = inf.ReadSingle();
     weatherChangeOn = inf.ReadBoolean();
     if (weatherChangeOn)
     {
         dynamicWeather = new DynamicWeather();
         dynamicWeather.Restore(inf);
     }
     UpdateVolume();
 }
Exemplo n.º 2
0
        public void Update(ElapsedTime elapsedTime)
        {
            if (MPManager.IsClient() && MPManager.Instance().weatherChanged)
            {
                // Multiplayer weather has changed so we need to update our state to match weather, overcastFactor, pricipitationIntensity and fogDistance.
                if (MPManager.Instance().weather >= 0 && MPManager.Instance().weather != (int)Viewer.Simulator.WeatherType)
                {
                    Viewer.Simulator.WeatherType = (Orts.Formats.Msts.WeatherType)MPManager.Instance().weather; UpdateWeatherParameters();
                }
                if (MPManager.Instance().overcastFactor >= 0)
                {
                    Weather.OvercastFactor = MPManager.Instance().overcastFactor;
                }
                if (MPManager.Instance().pricipitationIntensity >= 0)
                {
                    Weather.PricipitationIntensityPPSPM2 = MPManager.Instance().pricipitationIntensity; UpdateVolume();
                }
                if (MPManager.Instance().fogDistance >= 0)
                {
                    Weather.FogDistance = MPManager.Instance().fogDistance;
                }

                // Reset the message now that we've applied all the changes.
                try
                {
                    if ((MPManager.Instance().weather >= 0 && MPManager.Instance().weather != (int)Viewer.Simulator.WeatherType) || MPManager.Instance().overcastFactor >= 0 || MPManager.Instance().pricipitationIntensity >= 0 || MPManager.Instance().fogDistance >= 0)
                    {
                        MPManager.Instance().weatherChanged         = false;
                        MPManager.Instance().weather                = -1;
                        MPManager.Instance().overcastFactor         = -1;
                        MPManager.Instance().pricipitationIntensity = -1;
                        MPManager.Instance().fogDistance            = -1;
                    }
                }
                catch { }
            }

            if (!MPManager.IsClient())
            {
                // The user is able to change the weather for debugging. This will cycle through clear, rain and snow.
                if (UserInput.IsPressed(UserCommands.DebugWeatherChange))
                {
                    switch (Viewer.Simulator.WeatherType)
                    {
                    case Orts.Formats.Msts.WeatherType.Clear:
                        Viewer.Simulator.WeatherType = Orts.Formats.Msts.WeatherType.Rain;
                        break;

                    case Orts.Formats.Msts.WeatherType.Rain:
                        Viewer.Simulator.WeatherType = Orts.Formats.Msts.WeatherType.Snow;
                        break;

                    case Orts.Formats.Msts.WeatherType.Snow:
                        Viewer.Simulator.WeatherType = Orts.Formats.Msts.WeatherType.Clear;
                        break;
                    }
                    // block dynamic weather change after a manual weather change operation
                    weatherChangeOn = false;
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ResetWeatherTargets();
                    }
                    UpdateWeatherParameters();

                    // If we're a multiplayer server, send out the new weather to all clients.
                    if (MPManager.IsServer())
                    {
                        MPManager.Notify((new MSGWeather((int)Viewer.Simulator.WeatherType, -1, -1, -1)).ToString());
                    }
                }

                // Overcast ranges from 0 (completely clear) to 1 (completely overcast).
                if (UserInput.IsDown(UserCommands.DebugOvercastIncrease))
                {
                    Weather.OvercastFactor = MathHelper.Clamp(Weather.OvercastFactor + elapsedTime.RealSeconds / 10, 0, 1);
                    weatherChangeOn        = false;
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ORTSOvercast = -1;
                    }
                }
                if (UserInput.IsDown(UserCommands.DebugOvercastDecrease))
                {
                    Weather.OvercastFactor = MathHelper.Clamp(Weather.OvercastFactor - elapsedTime.RealSeconds / 10, 0, 1);
                    weatherChangeOn        = false;
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ORTSOvercast = -1;
                    }
                }

                // Pricipitation ranges from 0 to max PrecipitationViewer.MaxIntensityPPSPM2 if 32bit.
                // 16bit uses PrecipitationViewer.MaxIntensityPPSPM2_16
                if (Viewer.GraphicsDevice.GraphicsDeviceCapabilities.MaxVertexIndex > 0xFFFF) // 0xFFFF represents 65535 which is the max for 16bit devices.
                {
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationIncrease))
                    {
                        Weather.PricipitationIntensityPPSPM2 = MathHelper.Clamp(Weather.PricipitationIntensityPPSPM2 * 1.05f, PrecipitationViewer.MinIntensityPPSPM2, PrecipitationViewer.MaxIntensityPPSPM2);
                        weatherChangeOn = false;
                        if (dynamicWeather != null)
                        {
                            dynamicWeather.ORTSPrecipitationIntensity = -1;
                        }
                    }
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationDecrease))
                    {
                        Weather.PricipitationIntensityPPSPM2 = MathHelper.Clamp(Weather.PricipitationIntensityPPSPM2 / 1.05f, PrecipitationViewer.MinIntensityPPSPM2, PrecipitationViewer.MaxIntensityPPSPM2);
                        weatherChangeOn = false;
                        if (dynamicWeather != null)
                        {
                            dynamicWeather.ORTSPrecipitationIntensity = -1;
                        }
                    }
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationIncrease) || UserInput.IsDown(UserCommands.DebugPrecipitationDecrease))
                    {
                        UpdateVolume();
                    }
                }
                else
                {
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationIncrease))
                    {
                        Weather.PricipitationIntensityPPSPM2 = MathHelper.Clamp(Weather.PricipitationIntensityPPSPM2 * 1.05f, PrecipitationViewer.MinIntensityPPSPM2, PrecipitationViewer.MaxIntensityPPSPM2_16);
                        weatherChangeOn = false;
                        if (dynamicWeather != null)
                        {
                            dynamicWeather.ORTSPrecipitationIntensity = -1;
                        }
                    }
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationDecrease))
                    {
                        Weather.PricipitationIntensityPPSPM2 = MathHelper.Clamp(Weather.PricipitationIntensityPPSPM2 / 1.05f, PrecipitationViewer.MinIntensityPPSPM2, PrecipitationViewer.MaxIntensityPPSPM2_16);
                        weatherChangeOn = false;
                        if (dynamicWeather != null)
                        {
                            dynamicWeather.ORTSPrecipitationIntensity = -1;
                        }
                    }
                    if (UserInput.IsDown(UserCommands.DebugPrecipitationIncrease) || UserInput.IsDown(UserCommands.DebugPrecipitationDecrease))
                    {
                        UpdateVolume();
                    }
                }
                // Fog ranges from 10m (can't see anything) to 100km (clear arctic conditions).
                if (UserInput.IsDown(UserCommands.DebugFogIncrease))
                {
                    Weather.FogDistance = MathHelper.Clamp(Weather.FogDistance - elapsedTime.RealSeconds * Weather.FogDistance, 10, 100000);
                    weatherChangeOn     = false;
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ORTSFog = -1;
                    }
                }
                if (UserInput.IsDown(UserCommands.DebugFogDecrease))
                {
                    Weather.FogDistance = MathHelper.Clamp(Weather.FogDistance + elapsedTime.RealSeconds * Weather.FogDistance, 10, 100000);
                    if (dynamicWeather != null)
                    {
                        dynamicWeather.ORTSFog = -1;
                    }
                    weatherChangeOn = false;
                }

                UpdateWind(elapsedTime);
            }

            if (!Orts.MultiPlayer.MPManager.IsMultiPlayer())
            {
                // Shift the clock forwards or backwards at 1h-per-second.
                if (UserInput.IsDown(UserCommands.DebugClockForwards))
                {
                    Viewer.Simulator.ClockTime += elapsedTime.RealSeconds * 3600;
                }
                if (UserInput.IsDown(UserCommands.DebugClockBackwards))
                {
                    Viewer.Simulator.ClockTime -= elapsedTime.RealSeconds * 3600;
                }
            }

            // If we're a multiplayer server, send out the new overcastFactor, pricipitationIntensity and fogDistance to all clients.
            if (MPManager.IsServer())
            {
                if (UserInput.IsReleased(UserCommands.DebugOvercastIncrease) || UserInput.IsReleased(UserCommands.DebugOvercastDecrease) ||
                    UserInput.IsReleased(UserCommands.DebugPrecipitationIncrease) || UserInput.IsReleased(UserCommands.DebugPrecipitationDecrease) ||
                    UserInput.IsReleased(UserCommands.DebugFogIncrease) || UserInput.IsReleased(UserCommands.DebugFogDecrease))
                {
                    MPManager.Instance().SetEnvInfo(Weather.OvercastFactor, Weather.FogDistance);
                    MPManager.Notify((new MSGWeather(-1, Weather.OvercastFactor, Weather.PricipitationIntensityPPSPM2, Weather.FogDistance)).ToString());
                }
            }
            if (Program.Simulator != null && Program.Simulator.ActivityRun != null && Program.Simulator.ActivityRun.triggeredEvent != null &&
                Program.Simulator.ActivityRun.triggeredEvent.ORTSWeatherChange != null)
            // Start a weather change sequence in activity mode
            {
                // if not yet weather changes, create the instance
                if (dynamicWeather == null)
                {
                    dynamicWeather = new DynamicWeather();
                }
                dynamicWeather.WeatherChange_Init(Program.Simulator.ActivityRun.triggeredEvent.ORTSWeatherChange, this);
                Program.Simulator.ActivityRun.triggeredEvent = null;
            }
            if (weatherChangeOn)
            // manage the weather change sequence
            {
                dynamicWeather.WeatherChange_Update(elapsedTime, this);
            }
        }