//This renders the frame protected override void OnRenderFrame(FrameEventArgs e) { Program.MouseMovement(); Game.InfoFrameRate = RenderFrequency; GL.ClearColor(0.75f, 0.75f, 0.75f, 1.0f); //Do not do anything whilst loading if (currentlyLoading) { return; } ProcessEvents(); double TimeElapsed = CPreciseTimer.GetElapsedTime(); if (Program.CpuReducedMode) { System.Threading.Thread.Sleep(250); } else { System.Threading.Thread.Sleep(1); if (ReducedModeEnteringTime == 0) { ReducedModeEnteringTime = 2500; } if (World.CameraAlignmentDirection.Position.X != 0.0 | World.CameraAlignmentDirection.Position.Y != 0.0 | World.CameraAlignmentDirection.Position.Z != 0.0 | World.CameraAlignmentDirection.Pitch != 0.0 | World.CameraAlignmentDirection.Yaw != 0.0 | World.CameraAlignmentDirection.Roll != 0.0 | World.CameraAlignmentDirection.TrackPosition != 0.0 | World.CameraAlignmentDirection.Zoom != 0.0) { ReducedModeEnteringTime = 2500; } //Automatically enter reduced CPU mode if appropriate if (Program.CpuAutomaticMode && Program.CpuReducedMode == false) { ReducedModeEnteringTime -= TimeElapsed; if (ReducedModeEnteringTime <= 0) { Program.CpuReducedMode = true; ReducedModeEnteringTime = 0; } } } DateTime d = DateTime.Now; Game.SecondsSinceMidnight = (double)(3600 * d.Hour + 60 * d.Minute + d.Second) + 0.001 * (double)d.Millisecond; ObjectManager.UpdateAnimatedWorldObjects(TimeElapsed, false); World.UpdateAbsoluteCamera(TimeElapsed); ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + World.CameraCurrentAlignment.Position.Z); TextureManager.Update(TimeElapsed); Sounds.Update(TimeElapsed, Sounds.SoundModels.Linear); Renderer.RenderScene(TimeElapsed); SwapBuffers(); }
//This renders the frame protected override void OnRenderFrame(FrameEventArgs e) { if (!firstFrame) { //If the load is not complete, then we shouldn't be running the mainloop return; } double TimeElapsed = RenderTimeElapsed; double RealTimeElapsed = RenderRealTimeElapsed; //Next, check if we're in paused/ in a menu if (Game.CurrentInterface != Game.InterfaceType.Normal) { MainLoop.UpdateControlRepeats(0.0); MainLoop.ProcessKeyboard(); MainLoop.ProcessControls(0.0); if (Game.CurrentInterface == Game.InterfaceType.Pause) { System.Threading.Thread.Sleep(10); } //Renderer.UpdateLighting(); Renderer.RenderScene(TimeElapsed); Program.currentGameWindow.SwapBuffers(); if (MainLoop.Quit) { Close(); } //If the menu state has not changed, don't update the rendered simulation return; } //Use the OpenTK framerate as this is much more accurate //Also avoids running a calculation if (TotalTimeElapsedForInfo >= 0.2) { Game.InfoFrameRate = RenderFrequency; TotalTimeElapsedForInfo = 0.0; } if (Game.PreviousInterface != Game.InterfaceType.Normal) { ObjectManager.UpdateAnimatedWorldObjects(0.0, false); Game.PreviousInterface = Game.InterfaceType.Normal; } else { ObjectManager.UpdateAnimatedWorldObjects(TimeElapsed, false); } //We need to update the camera position in the render sequence //Not doing this means that the camera doesn't move // update in one piece if (World.CameraMode == World.CameraViewMode.Interior | World.CameraMode == World.CameraViewMode.InteriorLookAhead) { //Update the in-car camera based upon the current driver car (Cabview or passenger view) TrainManager.PlayerTrain.Cars[World.CameraCar].UpdateCamera(); } else if (World.CameraMode == World.CameraViewMode.Exterior) { //Update the camera position based upon the relative car position TrainManager.PlayerTrain.Cars[World.CameraCar].UpdateCamera(); } if (World.CameraRestriction == World.CameraRestrictionMode.NotAvailable) { World.UpdateDriverBody(TimeElapsed); } //Check if we are running at an accelerated time factor- //Camera motion speed should be the same whatever the game speed is if (TimeFactor != 1) { World.UpdateAbsoluteCamera(TimeElapsed / TimeFactor); } else { World.UpdateAbsoluteCamera(TimeElapsed); } TrainManager.UpdateTrainObjects(TimeElapsed, false); if (World.CameraMode == World.CameraViewMode.Interior | World.CameraMode == World.CameraViewMode.InteriorLookAhead | World.CameraMode == World.CameraViewMode.Exterior) { ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + World.CameraCurrentAlignment.Position.Z); int d = TrainManager.PlayerTrain.DriverCar; World.CameraSpeed = TrainManager.PlayerTrain.Cars[d].Specs.CurrentSpeed; } else { World.CameraSpeed = 0.0; } World.CameraAlignmentDirection = new World.CameraAlignment(); if (MainLoop.Quit) { Program.currentGameWindow.Exit(); } Renderer.UpdateLighting(); Renderer.RenderScene(TimeElapsed); Sounds.Update(TimeElapsed, Interface.CurrentOptions.SoundModel); Program.currentGameWindow.SwapBuffers(); Game.UpdateBlackBox(); // pause/menu // limit framerate if (MainLoop.LimitFramerate) { System.Threading.Thread.Sleep(10); } MainLoop.UpdateControlRepeats(RealTimeElapsed); MainLoop.ProcessKeyboard(); World.UpdateMouseGrab(TimeElapsed); MainLoop.ProcessControls(TimeElapsed); for (int i = 0; i < JoystickManager.AttachedJoysticks.Length; i++) { var railDriver = JoystickManager.AttachedJoysticks[i] as JoystickManager.Raildriver; if (railDriver != null) { if (Interface.CurrentOptions.RailDriverMPH) { railDriver.SetDisplay((int)(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Specs .CurrentPerceivedSpeed * 2.23694)); } else { railDriver.SetDisplay((int)(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Specs .CurrentPerceivedSpeed * 3.6)); } } } RenderRealTimeElapsed = 0.0; RenderTimeElapsed = 0.0; #if DEBUG MainLoop.CheckForOpenGlError("MainLoop"); #endif if (Interface.CurrentOptions.UnloadUnusedTextures) { Renderer.UnloadUnusedTextures(TimeElapsed); Renderer.LastBoundTexture = null; } // finish try { Interface.SaveLogs(); } catch { } }
// // PROCESS MENU COMMAND // /// <summary>Processes a user command for the current menu</summary> /// <param name="cmd">The command to apply to the current menu</param> /// <param name="timeElapsed">The time elapsed since previous frame</param> internal void ProcessCommand(Translations.Command cmd, double timeElapsed) { if (CurrMenu < 0) { return; } // MenuBack is managed independently from single menu data if (cmd == Translations.Command.MenuBack) { PopMenu(); return; } SingleMenu menu = Menus[CurrMenu]; if (menu.Selection == SelectionNone) // if menu has no selection, do nothing { return; } switch (cmd) { case Translations.Command.MenuUp: // UP if (menu.Selection > 0 && !(menu.Items[menu.Selection - 1] is MenuCaption)) { menu.Selection--; PositionMenu(); } break; case Translations.Command.MenuDown: // DOWN if (menu.Selection < menu.Items.Length - 1) { menu.Selection++; PositionMenu(); } break; // case Translations.Command.MenuBack: // ESC: managed above // break; case Translations.Command.MenuEnter: // ENTER if (menu.Items[menu.Selection] is MenuCommand) { MenuCommand menuItem = (MenuCommand)menu.Items[menu.Selection]; switch (menuItem.Tag) { // menu management commands case MenuTag.MenuBack: // BACK TO PREVIOUS MENU Menu.instance.PopMenu(); break; case MenuTag.MenuJumpToStation: // TO STATIONS MENU Menu.instance.PushMenu(MenuType.JumpToStation); break; case MenuTag.MenuExitToMainMenu: // TO EXIT MENU Menu.instance.PushMenu(MenuType.ExitToMainMenu); break; case MenuTag.MenuQuit: // TO QUIT MENU Menu.instance.PushMenu(MenuType.Quit); break; case MenuTag.MenuControls: // TO CONTROLS MENU Menu.instance.PushMenu(MenuType.Controls); break; case MenuTag.BackToSim: // OUT OF MENU BACK TO SIMULATION Reset(); Game.PreviousInterface = Game.InterfaceType.Menu; Game.CurrentInterface = Game.InterfaceType.Normal; break; // simulation commands case MenuTag.JumpToStation: // JUMP TO STATION Reset(); TrainManager.JumpTrain(TrainManager.PlayerTrain, menuItem.Data); break; case MenuTag.ExitToMainMenu: // BACK TO MAIN MENU Reset(); Program.RestartArguments = Interface.CurrentOptions.GameMode == Interface.GameMode.Arcade ? "/review" : ""; MainLoop.Quit = MainLoop.QuitMode.ExitToMenu; break; case MenuTag.Control: // CONTROL CUSTOMIZATION PushMenu(MenuType.Control, ((MenuCommand)menu.Items[menu.Selection]).Data); isCustomisingControl = true; CustomControlIdx = ((MenuCommand)menu.Items[menu.Selection]).Data; break; case MenuTag.Quit: // QUIT PROGRAMME Reset(); MainLoop.Quit = MainLoop.QuitMode.QuitProgram; break; } } break; case Translations.Command.MiscFullscreen: // fullscreen Screen.ToggleFullscreen(); break; case Translations.Command.MiscMute: // mute Sounds.GlobalMute = !Sounds.GlobalMute; Sounds.Update(timeElapsed, Interface.CurrentOptions.SoundModel); break; } }