public void PrepareFrame(ElapsedTime elapsedTime) { if (UserInput.IsPressed(UserCommand.DebugLockShadows)) { LockShadows = !LockShadows; } if (Game.Settings.DynamicShadows && (RenderProcess.ShadowMapCount > 0) && !LockShadows) { var solarDirection = SolarDirection; solarDirection.Normalize(); if (Vector3.Dot(SteppedSolarDirection, solarDirection) < 0.99999) { SteppedSolarDirection = solarDirection; } var cameraDirection = new Vector3(-XNACameraView.M13, -XNACameraView.M23, -XNACameraView.M33); cameraDirection.Normalize(); var shadowMapAlignAxisX = Vector3.Cross(SteppedSolarDirection, Vector3.UnitY); var shadowMapAlignAxisY = Vector3.Cross(shadowMapAlignAxisX, SteppedSolarDirection); shadowMapAlignAxisX.Normalize(); shadowMapAlignAxisY.Normalize(); ShadowMapX = shadowMapAlignAxisX; ShadowMapY = shadowMapAlignAxisY; for (var shadowMapIndex = 0; shadowMapIndex < RenderProcess.ShadowMapCount; shadowMapIndex++) { var viewingDistance = Game.Settings.ViewingDistance; var shadowMapDiameter = RenderProcess.ShadowMapDiameter[shadowMapIndex]; var shadowMapLocation = XNACameraLocation + RenderProcess.ShadowMapDistance[shadowMapIndex] * cameraDirection; // Align shadow map location to grid so it doesn't "flutter" so much. This basically means aligning it along a // grid based on the size of a shadow texel (shadowMapSize / shadowMapSize) along the axes of the sun direction // and up/left. var shadowMapAlignmentGrid = (float)shadowMapDiameter / Game.Settings.ShadowMapResolution; var shadowMapSize = Game.Settings.ShadowMapResolution; var adjustX = (float)Math.IEEERemainder(Vector3.Dot(shadowMapAlignAxisX, shadowMapLocation), shadowMapAlignmentGrid); var adjustY = (float)Math.IEEERemainder(Vector3.Dot(shadowMapAlignAxisY, shadowMapLocation), shadowMapAlignmentGrid); shadowMapLocation.X -= shadowMapAlignAxisX.X * adjustX; shadowMapLocation.Y -= shadowMapAlignAxisX.Y * adjustX; shadowMapLocation.Z -= shadowMapAlignAxisX.Z * adjustX; shadowMapLocation.X -= shadowMapAlignAxisY.X * adjustY; shadowMapLocation.Y -= shadowMapAlignAxisY.Y * adjustY; shadowMapLocation.Z -= shadowMapAlignAxisY.Z * adjustY; ShadowMapLightView[shadowMapIndex] = Matrix.CreateLookAt(shadowMapLocation + viewingDistance * SteppedSolarDirection, shadowMapLocation, Vector3.Up); ShadowMapLightProj[shadowMapIndex] = Matrix.CreateOrthographic(shadowMapDiameter, shadowMapDiameter, 0, viewingDistance + shadowMapDiameter / 2); ShadowMapLightViewProjShadowProj[shadowMapIndex] = ShadowMapLightView[shadowMapIndex] * ShadowMapLightProj[shadowMapIndex] * new Matrix(0.5f, 0, 0, 0, 0, -0.5f, 0, 0, 0, 0, 1, 0, 0.5f + 0.5f / shadowMapSize, 0.5f + 0.5f / shadowMapSize, 0, 1); ShadowMapCenter[shadowMapIndex] = shadowMapLocation; } } }
public void HandleUserInput(ElapsedTime elapsedTime) { if (UserInput.IsPressed(UserCommand.DebugLogger)) { Viewer.Settings.DataLogger = !Viewer.Settings.DataLogger; if (Viewer.Settings.DataLogger) { DataLoggerStart(Viewer.Settings); } else { DataLoggerStop(); } } }
public static void HandleUserInput() { //In Multiplayer, I maybe the helper, but I can request to be the controller if (UserInput.IsPressed(UserCommands.GameRequestControl)) { MPManager.RequestControl(); } if (UserInput.IsPressed(UserCommands.ControlHorn)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HORN", 1)).ToString()); if (UserInput.IsReleased(UserCommands.ControlHorn)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HORN", 0)).ToString()); if (UserInput.IsPressed(UserCommands.ControlPantograph2)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO2", (++PantoSecondCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlPantograph1)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO1", (++PantoFirstCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlBell)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 1)).ToString()); if (UserInput.IsReleased(UserCommands.ControlBell)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 0)).ToString()); if (UserInput.IsPressed(UserCommands.ControlBellToggle)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", (++BellCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlWiper)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "WIPER", (++WiperCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlDoorLeft)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORL", (++DoorLeftCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlDoorRight)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORR", (++DoorRightCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlMirror)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "MIRRORS", (++MirrorsCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlHeadlightIncrease)) { HeadLightCount++; if (HeadLightCount >= 3) HeadLightCount = 2; MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString()); } if (UserInput.IsPressed(UserCommands.ControlHeadlightDecrease)) { HeadLightCount--; if (HeadLightCount < 0) HeadLightCount = 0; MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString()); } }
public void Draw(GraphicsDevice graphicsDevice) { if (RenderSurface.Width != graphicsDevice.PresentationParameters.BackBufferWidth || RenderSurface.Height != graphicsDevice.PresentationParameters.BackBufferHeight) { ScreenChanged(); } #if DEBUG_RENDER_STATE DebugRenderState(graphicsDevice, "RenderFrame.Draw"); #endif var logging = UserInput.IsPressed(UserCommand.DebugLogRenderFrame); if (logging) { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Draw {"); } if (Game.Settings.DynamicShadows && (RenderProcess.ShadowMapCount > 0) && ShadowMapMaterial != null) { DrawShadows(graphicsDevice, logging); } DrawSimple(graphicsDevice, logging); for (var i = 0; i < (int)RenderPrimitiveSequence.Sentinel; i++) { Game.RenderProcess.PrimitiveCount[i] = RenderItems[i].Values.Sum(l => l.Count); } if (logging) { Console.WriteLine("}"); Console.WriteLine(); } }
public static void Update(Game game) { if (Orts.MultiPlayer.MPManager.IsMultiPlayer() && Orts.MultiPlayer.MPManager.Instance().ComposingText) { return; } if (InputSettings == null) { InputSettings = game.Settings.Input; } LastKeyboardState = KeyboardState; LastMouseState = MouseState; // Make sure we have an "idle" (everything released) keyboard and mouse state if the window isn't active. KeyboardState = game.IsActive ? new KeyboardState(GetKeysWithPrintScreenFix(Keyboard.GetState())) : new KeyboardState(); MouseState = game.IsActive ? Mouse.GetState() : new MouseState(0, 0, LastMouseState.ScrollWheelValue, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released); MouseButtonsSwapped = System.Windows.Forms.SystemInformation.MouseButtonsSwapped; MouseSpeedX = Math.Abs(MouseState.X - LastMouseState.X); MouseSpeedY = Math.Abs(MouseState.Y - LastMouseState.Y); #if DEBUG_RAW_INPUT for (Keys key = 0; key <= Keys.OemClear; key++) { if (LastKeyboardState[key] != KeyboardState[key]) { Console.WriteLine("Keyboard {0} changed to {1}", key, KeyboardState[key]); } } if (LastMouseState.LeftButton != MouseState.LeftButton) { Console.WriteLine("Mouse left button changed to {0}", MouseState.LeftButton); } if (LastMouseState.MiddleButton != MouseState.MiddleButton) { Console.WriteLine("Mouse middle button changed to {0}", MouseState.MiddleButton); } if (LastMouseState.RightButton != MouseState.RightButton) { Console.WriteLine("Mouse right button changed to {0}", MouseState.RightButton); } if (LastMouseState.XButton1 != MouseState.XButton1) { Console.WriteLine("Mouse X1 button changed to {0}", MouseState.XButton1); } if (LastMouseState.XButton2 != MouseState.XButton2) { Console.WriteLine("Mouse X2 button changed to {0}", MouseState.XButton2); } if (LastMouseState.ScrollWheelValue != MouseState.ScrollWheelValue) { Console.WriteLine("Mouse scrollwheel changed by {0}", MouseState.ScrollWheelValue - LastMouseState.ScrollWheelValue); } #endif #if DEBUG_INPUT var newKeys = GetPressedKeys(); var oldKeys = GetPreviousPressedKeys(); foreach (var newKey in newKeys) { if (!oldKeys.Contains(newKey)) { Console.WriteLine("Keyboard {0} pressed", newKey); } } foreach (var oldKey in oldKeys) { if (!newKeys.Contains(oldKey)) { Console.WriteLine("Keyboard {0} released", oldKey); } } if (IsMouseLeftButtonPressed) { Console.WriteLine("Mouse left button pressed"); } if (IsMouseLeftButtonReleased) { Console.WriteLine("Mouse left button released"); } if (IsMouseMiddleButtonPressed) { Console.WriteLine("Mouse middle button pressed"); } if (IsMouseMiddleButtonReleased) { Console.WriteLine("Mouse middle button released"); } if (IsMouseRightButtonPressed) { Console.WriteLine("Mouse right button pressed"); } if (IsMouseRightButtonReleased) { Console.WriteLine("Mouse right button released"); } if (IsMouseWheelChanged) { Console.WriteLine("Mouse scrollwheel changed by {0}", MouseWheelChange); } #endif #if DEBUG_USER_INPUT foreach (UserCommand command in Enum.GetValues(typeof(UserCommand))) { if (UserInput.IsPressed(command)) { Console.WriteLine("Pressed {0} - {1}", command, InputSettings.Commands[(int)command]); } if (UserInput.IsReleased(command)) { Console.WriteLine("Released {0} - {1}", command, InputSettings.Commands[(int)command]); } } #endif }
public static void HandleUserInput() { //In Multiplayer, I maybe the helper, but I can request to be the controller // Horn and bell are managed by UpdateHornAndBell in MSTSLocomotive.cs if (UserInput.IsPressed(UserCommand.GameRequestControl)) { MPManager.RequestControl(); } if (UserInput.IsPressed(UserCommand.ControlPantograph2)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO2", (++PantoSecondCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlPantograph1)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO1", (++PantoFirstCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlPantograph4)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO4", (++PantoFourthCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlPantograph3)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO3", (++PantoThirdCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlWiper)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "WIPER", (++WiperCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlDoorLeft)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORL", (++DoorLeftCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlDoorRight)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORR", (++DoorRightCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlMirror)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "MIRRORS", (++MirrorsCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlHeadlightIncrease)) { HeadLightCount++; if (HeadLightCount >= 3) { HeadLightCount = 2; } MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlHeadlightDecrease)) { HeadLightCount--; if (HeadLightCount < 0) { HeadLightCount = 0; } MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString()); } }
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); } }