Exemple #1
0
 internal static void UpdateGraphicsSettings()
 {
     if (Program.CurrentRoute != null)
     {
         Program.CurrentlyLoading = true;
         Renderer.RenderScene(0.0);
         Program.currentGameWindow.SwapBuffers();
         World.CameraAlignment a = World.CameraCurrentAlignment;
         Textures.UnloadAllTextures();
         if (Program.LoadRoute())
         {
             World.CameraCurrentAlignment = a;
             TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false);
             TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false);
             World.CameraAlignmentDirection = new World.CameraAlignment();
             World.CameraAlignmentSpeed     = new World.CameraAlignment();
             ObjectManager.UpdateVisibility(a.TrackPosition, true);
             ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
         }
         Program.CurrentlyLoading = false;
     }
 }
Exemple #2
0
        // process events
        private static void ProcessEvents()
        {
            SDL.SDL_Event Event;
            double        speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0);

            while (SDL.SDL_PollEvent(out Event) != 0)
            {
                switch (Event.type)
                {
                // quit
                case SDL.SDL_EventType.SDL_QUIT:
                    Quit = true;
                    return;

                // resize
                case SDL.SDL_EventType.SDL_WINDOWEVENT:
                    if (Event.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED)
                    {
                        Renderer.ScreenWidth  = Event.window.data1;
                        Renderer.ScreenHeight = Event.window.data2;
                        UpdateViewport();
                    }
                    break;

                // mouse
                case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:                         // FIXME implement check whether any track is loaded!
                    if (CurrentRoute != null)
                    {
                        switch (Event.button.button)
                        {
                        case (byte)SDL.SDL_BUTTON_LEFT:
                            World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified;
                            CpuReducedMode = false;
                            break;

                        case (byte)SDL.SDL_BUTTON_RIGHT:
                            World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified;
                            CpuReducedMode = false;
                            break;

                        case (byte)SDL.SDL_BUTTON_MIDDLE:
                            Rotate = true;
                            SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_TRUE);
                            CpuReducedMode = false;
                            break;
                        }
                    }
                    break;

                case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:                         // FIXME implement check whether any track is loaded!
                    if (CurrentRoute != null)
                    {
                        if (Event.button.button == SDL.SDL_BUTTON_LEFT || Event.button.button == SDL.SDL_BUTTON_RIGHT)
                        {
                            World.CameraAlignmentDirection.TrackPosition = 0.0;
                        }
                        else if (Event.button.button == SDL.SDL_BUTTON_MIDDLE)
                        {
                            SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_FALSE);
                            World.CameraAlignmentDirection.Pitch = 0.0;
                            World.CameraAlignmentDirection.Yaw   = 0.0;
                            Rotate = false;
                        }
                    }
                    break;

                case SDL.SDL_EventType.SDL_MOUSEMOTION:                         // TODO - rotate
                    if (Rotate && CurrentStation != -1)                         /*
                                                                                 * World.CameraAlignmentDirection.Pitch = speedModified * -World.CameraExteriorTopAngularSpeed * Event.motion.yrel/3;
                                                                                 * World.CameraAlignmentDirection.Yaw   = speedModified *  World.CameraExteriorTopAngularSpeed * Event.motion.xrel/3;*/
                    {
                    }
                    break;

                // key down
                case SDL.SDL_EventType.SDL_KEYDOWN:
                    switch (Event.key.keysym.sym)
                    {
                    case SDL.SDL_Keycode.SDLK_LSHIFT:
                    case SDL.SDL_Keycode.SDLK_RSHIFT:
                        ShiftPressed = true;
                        break;

                    case SDL.SDL_Keycode.SDLK_LCTRL:
                    case SDL.SDL_Keycode.SDLK_RCTRL:
                        ControlPressed = true;
                        break;

                    case SDL.SDL_Keycode.SDLK_LALT:
                    case SDL.SDL_Keycode.SDLK_RALT:
                        AltPressed = true;
                        break;

                    case SDL.SDL_Keycode.SDLK_F5:
                        if (CurrentRoute != null)
                        {
                            CurrentlyLoading = true;
                            Renderer.RenderScene(0.0);
                            SwapBuffers();
                            World.CameraAlignment a = World.CameraCurrentAlignment;
                            if (LoadRoute())
                            {
                                World.CameraCurrentAlignment = a;
                                TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false);
                                TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false);
                                World.CameraAlignmentDirection = new World.CameraAlignment();
                                World.CameraAlignmentSpeed     = new World.CameraAlignment();
                                ObjectManager.UpdateVisibility(a.TrackPosition, true);
                                ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                            }
                            CurrentlyLoading = false;
                        }
                        break;

                    case SDL.SDL_Keycode.SDLK_F7:
                    {
                        OpenFileDialog Dialog = new OpenFileDialog();
                        Dialog.CheckFileExists = true;
                        Dialog.Filter          = "CSV/RW files|*.csv;*.rw|All files|*";
                        if (Dialog.ShowDialog() == DialogResult.OK)
                        {
                            CurrentlyLoading = true;
                            Renderer.RenderScene(0.0);
                            SwapBuffers();
                            CurrentRoute = Dialog.FileName;
                            LoadRoute();
                            ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                            CurrentlyLoading = false;
                            UpdateCaption();
                        }
                    }
                    break;

                    case SDL.SDL_Keycode.SDLK_F9:
                        if (Interface.MessageCount != 0)
                        {
                            formMessages.ShowMessages();
                        }
                        break;

                    case SDL.SDL_Keycode.SDLK_a:
                    case SDL.SDL_Keycode.SDLK_KP_4:
                        World.CameraAlignmentDirection.Position.X = -World.CameraExteriorTopSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_d:
                    case SDL.SDL_Keycode.SDLK_KP_6:
                        World.CameraAlignmentDirection.Position.X = World.CameraExteriorTopSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_2:
                        World.CameraAlignmentDirection.Position.Y = -World.CameraExteriorTopSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_8:
                        World.CameraAlignmentDirection.Position.Y = World.CameraExteriorTopSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_w:
                    case SDL.SDL_Keycode.SDLK_KP_9:
                        if (CurrentRoute != null)
                        {
                            World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified;
                            CpuReducedMode = false;
                        }
                        break;

                    case SDL.SDL_Keycode.SDLK_s:
                    case SDL.SDL_Keycode.SDLK_KP_3:
                        if (CurrentRoute != null)
                        {
                            World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified;
                            CpuReducedMode = false;
                        }
                        break;

                    case SDL.SDL_Keycode.SDLK_LEFT:
                        World.CameraAlignmentDirection.Yaw = -World.CameraExteriorTopAngularSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_RIGHT:
                        World.CameraAlignmentDirection.Yaw = World.CameraExteriorTopAngularSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_UP:
                        World.CameraAlignmentDirection.Pitch = World.CameraExteriorTopAngularSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_DOWN:
                        World.CameraAlignmentDirection.Pitch = -World.CameraExteriorTopAngularSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_DIVIDE:
                        World.CameraAlignmentDirection.Roll = -World.CameraExteriorTopAngularSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_MULTIPLY:
                        World.CameraAlignmentDirection.Roll = World.CameraExteriorTopAngularSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_0:
                        World.CameraAlignmentDirection.Zoom = World.CameraZoomTopSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_PERIOD:
                        World.CameraAlignmentDirection.Zoom = -World.CameraZoomTopSpeed * speedModified;
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_1:
                        Game.ApplyPointOfInterest(-1, true);
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_7:
                        Game.ApplyPointOfInterest(1, true);
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_PAGEUP:
                        JumpToStation(1);
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_PAGEDOWN:
                        JumpToStation(-1);
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_5:
                        World.CameraCurrentAlignment.Yaw      = 0.0;
                        World.CameraCurrentAlignment.Pitch    = 0.0;
                        World.CameraCurrentAlignment.Roll     = 0.0;
                        World.CameraCurrentAlignment.Position = new World.Vector3D(0.0, 2.5, 0.0);
                        World.CameraCurrentAlignment.Zoom     = 0.0;
                        World.CameraAlignmentDirection        = new World.CameraAlignment();
                        World.CameraAlignmentSpeed            = new World.CameraAlignment();
                        World.VerticalViewingAngle            = World.OriginalVerticalViewingAngle;
                        UpdateViewport();
                        World.UpdateAbsoluteCamera(0.0);
                        World.UpdateViewingDistances();
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_f:
                        Renderer.OptionWireframe = !Renderer.OptionWireframe;
                        CpuReducedMode           = false;
                        if (Renderer.OptionWireframe)
                        {
                            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                        }
                        else
                        {
                            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                        } break;

                    case SDL.SDL_Keycode.SDLK_n:
                        Renderer.OptionNormals = !Renderer.OptionNormals;
                        CpuReducedMode         = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_e:
                        Renderer.OptionEvents = !Renderer.OptionEvents;
                        CpuReducedMode        = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_c:
                        CpuAutomaticMode = !CpuAutomaticMode;
                        CpuReducedMode   = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_i:
                        Renderer.OptionInterface = !Renderer.OptionInterface;
                        CpuReducedMode           = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_m:
                        SoundManager.Mute = !SoundManager.Mute;
                        break;

                    case SDL.SDL_Keycode.SDLK_PLUS:
                    case SDL.SDL_Keycode.SDLK_KP_PLUS:
                        if (!JumpToPositionEnabled)
                        {
                            JumpToPositionEnabled = true;
                            JumpToPositionValue   = "+";
                            CpuReducedMode        = false;
                        }
                        break;

                    case SDL.SDL_Keycode.SDLK_MINUS:
                    case SDL.SDL_Keycode.SDLK_KP_MINUS:
                        if (!JumpToPositionEnabled)
                        {
                            JumpToPositionEnabled = true;
                            JumpToPositionValue   = "-";
                            CpuReducedMode        = false;
                        }
                        break;

                    case SDL.SDL_Keycode.SDLK_0:
                    case SDL.SDL_Keycode.SDLK_1:
                    case SDL.SDL_Keycode.SDLK_2:
                    case SDL.SDL_Keycode.SDLK_3:
                    case SDL.SDL_Keycode.SDLK_4:
                    case SDL.SDL_Keycode.SDLK_5:
                    case SDL.SDL_Keycode.SDLK_6:
                    case SDL.SDL_Keycode.SDLK_7:
                    case SDL.SDL_Keycode.SDLK_8:
                    case SDL.SDL_Keycode.SDLK_9:
                        if (!JumpToPositionEnabled)
                        {
                            JumpToPositionEnabled = true;
                            JumpToPositionValue   = string.Empty;
                        }
                        JumpToPositionValue += char.ConvertFromUtf32(48 + Event.key.keysym.sym - SDL.SDL_Keycode.SDLK_0);
                        CpuReducedMode       = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_PERIOD:
                        if (!JumpToPositionEnabled)
                        {
                            JumpToPositionEnabled = true;
                            JumpToPositionValue   = "0.";
                        }
                        else if (JumpToPositionValue.IndexOf('.') == -1)
                        {
                            JumpToPositionValue += ".";
                        }
                        CpuReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_BACKSPACE:
                        if (JumpToPositionEnabled && JumpToPositionValue.Length != 0)
                        {
                            JumpToPositionValue = JumpToPositionValue.Substring(0, JumpToPositionValue.Length - 1);
                            CpuReducedMode      = false;
                        }
                        break;

                    case SDL.SDL_Keycode.SDLK_RETURN:
                        if (JumpToPositionEnabled)
                        {
                            if (JumpToPositionValue.Length != 0)
                            {
                                int direction;
                                if (JumpToPositionValue[0] == '-')
                                {
                                    JumpToPositionValue = JumpToPositionValue.Substring(1);
                                    direction           = -1;
                                }
                                else if (JumpToPositionValue[0] == '+')
                                {
                                    JumpToPositionValue = JumpToPositionValue.Substring(1);
                                    direction           = 1;
                                }
                                else
                                {
                                    direction = 0;
                                }
                                double value;
                                if (double.TryParse(JumpToPositionValue, NumberStyles.Float, CultureInfo.InvariantCulture, out value))
                                {
                                    if (direction != 0)
                                    {
                                        value = World.CameraTrackFollower.TrackPosition + (double)direction * value;
                                    }
                                    TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, value, true, false);
                                    World.CameraCurrentAlignment.TrackPosition = value;
                                    World.UpdateAbsoluteCamera(0.0);
                                    World.UpdateViewingDistances();
                                }
                            }
                            JumpToPositionEnabled = false;
                            CpuReducedMode        = false;
                        }
                        break;

                    case SDL.SDL_Keycode.SDLK_ESCAPE:
                        JumpToPositionEnabled = false;
                        CpuReducedMode        = false;
                        break;
                    }
                    break;

                // key up
                case SDL.SDL_EventType.SDL_KEYUP:
                    switch (Event.key.keysym.sym)
                    {
                    case SDL.SDL_Keycode.SDLK_LSHIFT:
                    case SDL.SDL_Keycode.SDLK_RSHIFT:
                        ShiftPressed = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_LCTRL:
                    case SDL.SDL_Keycode.SDLK_RCTRL:
                        ControlPressed = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_LALT:
                    case SDL.SDL_Keycode.SDLK_RALT:
                        AltPressed = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_a:
                    case SDL.SDL_Keycode.SDLK_KP_4:
                    case SDL.SDL_Keycode.SDLK_d:
                    case SDL.SDL_Keycode.SDLK_KP_6:
                        World.CameraAlignmentDirection.Position.X = 0.0;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_2:
                    case SDL.SDL_Keycode.SDLK_KP_8:
                        World.CameraAlignmentDirection.Position.Y = 0.0;
                        break;

                    case SDL.SDL_Keycode.SDLK_w:
                    case SDL.SDL_Keycode.SDLK_KP_9:
                    case SDL.SDL_Keycode.SDLK_s:
                    case SDL.SDL_Keycode.SDLK_KP_3:
                        World.CameraAlignmentDirection.TrackPosition = 0.0;
                        break;

                    case SDL.SDL_Keycode.SDLK_LEFT:
                    case SDL.SDL_Keycode.SDLK_RIGHT:
                        World.CameraAlignmentDirection.Yaw = 0.0;
                        break;

                    case SDL.SDL_Keycode.SDLK_UP:
                    case SDL.SDL_Keycode.SDLK_DOWN:
                        World.CameraAlignmentDirection.Pitch = 0.0;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_DIVIDE:
                    case SDL.SDL_Keycode.SDLK_KP_MULTIPLY:
                        World.CameraAlignmentDirection.Roll = 0.0;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_0:
                    case SDL.SDL_Keycode.SDLK_KP_PERIOD:
                        World.CameraAlignmentDirection.Zoom = 0.0;
                        break;
                    }
                    break;
                }
            }
        }
Exemple #3
0
        internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e)
        {
            double speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0);

            switch (e.Key)
            {
            case Key.ShiftLeft:
            case Key.ShiftRight:
                ShiftPressed = true;
                break;

            case Key.ControlLeft:
            case Key.ControlRight:
                ControlPressed = true;
                break;

            case Key.LAlt:
            case Key.RAlt:
                AltPressed = true;
                break;

            case Key.F5:
                if (CurrentRoute != null && CurrentlyLoading == false)
                {
                    CurrentlyLoading         = true;
                    Renderer.OptionInterface = false;
                    if (!Interface.CurrentOptions.LoadingBackground)
                    {
                        Renderer.RenderScene(0.0);
                        currentGameWindow.SwapBuffers();
                        Bitmap     bitmap = new Bitmap(Renderer.ScreenWidth, Renderer.ScreenHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                        BitmapData bData  = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
                        GL.ReadPixels(0, 0, Renderer.ScreenWidth, Renderer.ScreenHeight, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bData.Scan0);
                        bitmap.UnlockBits(bData);
                        bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                        Renderer.TextureLoadingBkg = TextureManager.RegisterTexture(bitmap, false);
                        bitmap.Dispose();
                    }
                    World.CameraAlignment a = World.CameraCurrentAlignment;
                    if (LoadRoute())
                    {
                        World.CameraCurrentAlignment = a;
                        TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false);
                        TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false);
                        World.CameraAlignmentDirection = new World.CameraAlignment();
                        World.CameraAlignmentSpeed     = new World.CameraAlignment();
                        ObjectManager.UpdateVisibility(a.TrackPosition, true);
                        ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                    }

                    CurrentlyLoading         = false;
                    Renderer.OptionInterface = true;
                    TextureManager.UnregisterTexture(ref Renderer.TextureLoadingBkg);
                }
                break;

            case Key.F7:
                if (CurrentlyLoading == true)
                {
                    break;
                }
                OpenFileDialog Dialog = new OpenFileDialog();
                Dialog.CheckFileExists = true;
                Dialog.Filter          = "CSV/RW files|*.csv;*.rw|All files|*";
                if (Dialog.ShowDialog() == DialogResult.OK)
                {
                    Application.DoEvents();
                    CurrentlyLoading = true;
                    CurrentRoute     = Dialog.FileName;
                    LoadRoute();
                    ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                    CurrentlyLoading = false;
                    UpdateCaption();
                }
                else
                {
                    if (Program.CurrentlyRunOnMono)
                    {
                        //HACK: Dialog doesn't close properly when pressing the ESC key under Mono
                        //Avoid calling Application.DoEvents() unless absolutely necessary though!
                        Application.DoEvents();
                    }
                }
                Dialog.Dispose();
                break;

            case Key.F8:
                if (Program.CurrentlyLoading == true)
                {
                    //Don't allow the user to update the settings during loading, bad idea....
                    break;
                }
                if (formOptions.ShowOptions() == DialogResult.OK)
                {
                    UpdateGraphicsSettings();
                }
                Application.DoEvents();
                break;

            case Key.F9:
                if (Interface.MessageCount != 0)
                {
                    formMessages.ShowMessages();
                    Application.DoEvents();
                }
                break;

            case Key.F10:
                Renderer.RenderStatsOverlay = !Renderer.RenderStatsOverlay;
                break;

            case Key.A:
            case Key.Keypad4:
                World.CameraAlignmentDirection.Position.X = -World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.D:
            case Key.Keypad6:
                World.CameraAlignmentDirection.Position.X = World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad2:
                World.CameraAlignmentDirection.Position.Y = -World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad8:
                World.CameraAlignmentDirection.Position.Y = World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.W:
            case Key.Keypad9:
                World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.S:
            case Key.Keypad3:
                World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Left:
                World.CameraAlignmentDirection.Yaw = -World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Right:
                World.CameraAlignmentDirection.Yaw = World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Up:
                World.CameraAlignmentDirection.Pitch = World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Down:
                World.CameraAlignmentDirection.Pitch = -World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadDivide:
                World.CameraAlignmentDirection.Roll = -World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadMultiply:
                World.CameraAlignmentDirection.Roll = World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad0:
                World.CameraAlignmentDirection.Zoom = World.CameraZoomTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadPeriod:
                World.CameraAlignmentDirection.Zoom = -World.CameraZoomTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad1:
                Game.ApplyPointOfInterest(-1, true);
                CpuReducedMode = false;
                break;

            case Key.Keypad7:
                Game.ApplyPointOfInterest(1, true);
                CpuReducedMode = false;
                break;

            case Key.PageUp:
                JumpToStation(1);
                CpuReducedMode = false;
                break;

            case Key.PageDown:
                JumpToStation(-1);
                CpuReducedMode = false;
                break;

            case Key.Keypad5:
                World.CameraCurrentAlignment.Yaw      = 0.0;
                World.CameraCurrentAlignment.Pitch    = 0.0;
                World.CameraCurrentAlignment.Roll     = 0.0;
                World.CameraCurrentAlignment.Position = new Vector3(0.0, 2.5, 0.0);
                World.CameraCurrentAlignment.Zoom     = 0.0;
                World.CameraAlignmentDirection        = new World.CameraAlignment();
                World.CameraAlignmentSpeed            = new World.CameraAlignment();
                World.VerticalViewingAngle            = World.OriginalVerticalViewingAngle;
                UpdateViewport();
                World.UpdateAbsoluteCamera(0.0);
                World.UpdateViewingDistances();
                CpuReducedMode = false;
                break;

            case Key.F:
                Renderer.OptionWireframe = !Renderer.OptionWireframe;
                CpuReducedMode           = false;
                if (Renderer.OptionWireframe)
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                }
                else
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                }
                break;

            case Key.N:
                Renderer.OptionNormals = !Renderer.OptionNormals;
                CpuReducedMode         = false;
                break;

            case Key.E:
                Renderer.OptionEvents = !Renderer.OptionEvents;
                CpuReducedMode        = false;
                break;

            case Key.C:
                CpuAutomaticMode = !CpuAutomaticMode;
                CpuReducedMode   = false;
                break;

            case Key.I:
                Renderer.OptionInterface = !Renderer.OptionInterface;
                CpuReducedMode           = false;
                break;

            case Key.M:
                //SoundManager.Mute = !SoundManager.Mute;
                break;

            case Key.Plus:
            case Key.KeypadPlus:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = "+";
                    CpuReducedMode        = false;
                }
                break;

            case Key.Minus:
            case Key.KeypadMinus:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = "-";
                    CpuReducedMode        = false;
                }
                break;

            case Key.Number0:
            case Key.Number1:
            case Key.Number2:
            case Key.Number3:
            case Key.Number4:
            case Key.Number5:
            case Key.Number6:
            case Key.Number7:
            case Key.Number8:
            case Key.Number9:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = string.Empty;
                }
                JumpToPositionValue += char.ConvertFromUtf32(48 + e.Key - Key.Number0);
                CpuReducedMode       = false;
                break;

            case Key.Period:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = "0.";
                }
                else if (JumpToPositionValue.IndexOf('.') == -1)
                {
                    JumpToPositionValue += ".";
                }
                CpuReducedMode = false;
                break;

            case Key.BackSpace:
                if (JumpToPositionEnabled && JumpToPositionValue.Length != 0)
                {
                    JumpToPositionValue = JumpToPositionValue.Substring(0, JumpToPositionValue.Length - 1);
                    CpuReducedMode      = false;
                }
                break;

            case Key.Enter:
                if (JumpToPositionEnabled)
                {
                    if (JumpToPositionValue.Length != 0)
                    {
                        int direction;
                        if (JumpToPositionValue[0] == '-')
                        {
                            JumpToPositionValue = JumpToPositionValue.Substring(1);
                            direction           = -1;
                        }
                        else if (JumpToPositionValue[0] == '+')
                        {
                            JumpToPositionValue = JumpToPositionValue.Substring(1);
                            direction           = 1;
                        }
                        else
                        {
                            direction = 0;
                        }
                        double value;
                        if (double.TryParse(JumpToPositionValue, NumberStyles.Float, CultureInfo.InvariantCulture,
                                            out value))
                        {
                            if (value < TrackManager.CurrentTrack.Elements[TrackManager.CurrentTrack.Elements.Length - 1].StartingTrackPosition + 100 && value > MinimumJumpToPositionValue - 100)
                            {
                                if (direction != 0)
                                {
                                    value = World.CameraTrackFollower.TrackPosition + (double)direction * value;
                                }
                                TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, value, true, false);
                                World.CameraCurrentAlignment.TrackPosition = value;
                                World.UpdateAbsoluteCamera(0.0);
                                World.UpdateViewingDistances();
                            }
                        }
                    }
                }
                JumpToPositionEnabled = false;
                CpuReducedMode        = false;
                break;

            case Key.Escape:
                JumpToPositionEnabled = false;
                CpuReducedMode        = false;
                break;
            }
        }
Exemple #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            TextureManager.InterpolationMode previousInterpolationMode = Interface.CurrentOptions.Interpolation;
            int previousAntialasingLevel = Interface.CurrentOptions.AntialiasingLevel;
            int previousAnsiotropicLevel = Interface.CurrentOptions.AnisotropicFilteringLevel;

            //Interpolation mode
            switch (InterpolationMode.SelectedIndex)
            {
            case 0:
                Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.NearestNeighbor;
                break;

            case 1:
                Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.Bilinear;
                break;

            case 2:
                Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.NearestNeighborMipmapped;
                break;

            case 3:
                Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.BilinearMipmapped;
                break;

            case 4:
                Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.TrilinearMipmapped;
                break;

            case 5:
                Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.AnisotropicFiltering;
                break;
            }
            //Ansiotropic filtering level
            Interface.CurrentOptions.AnisotropicFilteringLevel = (int)AnsiotropicLevel.Value;
            //Antialiasing level
            Interface.CurrentOptions.AntialiasingLevel = (int)AntialiasingLevel.Value;
            if (Interface.CurrentOptions.AntialiasingLevel != previousAntialasingLevel)
            {
                Program.currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntialiasingLevel);
            }
            //Transparency quality
            switch (TransparencyQuality.SelectedIndex)
            {
            case 0:
                Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Sharp;
                break;

            default:
                Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Smooth;
                break;
            }
            //Set width and height
            if (Renderer.ScreenWidth != width.Value || Renderer.ScreenHeight != height.Value)
            {
                Renderer.ScreenWidth             = (int)width.Value;
                Renderer.ScreenHeight            = (int)height.Value;
                Program.currentGameWindow.Width  = (int)width.Value;
                Program.currentGameWindow.Height = (int)height.Value;
                Program.UpdateViewport();
            }
            //Check if interpolation mode or ansiotropic filtering level has changed, and trigger a reload
            if (previousInterpolationMode != Interface.CurrentOptions.Interpolation || previousAnsiotropicLevel != Interface.CurrentOptions.AnisotropicFilteringLevel)
            {
                if (Program.CurrentRoute != null)
                {
                    Program.CurrentlyLoading = true;
                    Renderer.RenderScene(0.0);
                    Program.currentGameWindow.SwapBuffers();
                    World.CameraAlignment a = World.CameraCurrentAlignment;
                    if (Program.LoadRoute())
                    {
                        World.CameraCurrentAlignment = a;
                        TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false);
                        TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false);
                        World.CameraAlignmentDirection = new World.CameraAlignment();
                        World.CameraAlignmentSpeed     = new World.CameraAlignment();
                        ObjectManager.UpdateVisibility(a.TrackPosition, true);
                        ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                    }
                    Program.CurrentlyLoading = false;
                }
            }
            Renderer.TransparentColorDepthSorting = Interface.CurrentOptions.TransparencyMode == Renderer.TransparencyMode.Smooth & Interface.CurrentOptions.Interpolation != TextureManager.InterpolationMode.NearestNeighbor & Interface.CurrentOptions.Interpolation != TextureManager.InterpolationMode.Bilinear;
            Options.SaveOptions();
            this.Dispose();
        }
Exemple #5
0
        internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e)
        {
            double speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0);

            switch (e.Key)
            {
            case Key.ShiftLeft:
            case Key.ShiftRight:
                ShiftPressed = true;
                break;

            case Key.ControlLeft:
            case Key.ControlRight:
                ControlPressed = true;
                break;

            case Key.LAlt:
            case Key.RAlt:
                AltPressed = true;
                break;

            case Key.F5:
                if (CurrentRoute != null)
                {
                    CurrentlyLoading = true;
                    Renderer.RenderScene(0.0);
                    currentGameWindow.SwapBuffers();
                    World.CameraAlignment a = World.CameraCurrentAlignment;
                    if (LoadRoute())
                    {
                        World.CameraCurrentAlignment = a;
                        TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false);
                        TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false);
                        World.CameraAlignmentDirection = new World.CameraAlignment();
                        World.CameraAlignmentSpeed     = new World.CameraAlignment();
                        ObjectManager.UpdateVisibility(a.TrackPosition, true);
                        ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                    }
                    CurrentlyLoading = false;
                }
                break;

            case Key.F7:
                OpenFileDialog Dialog = new OpenFileDialog();
                Dialog.CheckFileExists = true;
                Dialog.Filter          = "CSV/RW files|*.csv;*.rw|All files|*";
                if (Dialog.ShowDialog() == DialogResult.OK)
                {
                    Application.DoEvents();
                    CurrentlyLoading = true;
                    Renderer.RenderScene(0.0);
                    Program.currentGameWindow.SwapBuffers();
                    CurrentRoute = Dialog.FileName;
                    LoadRoute();
                    ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                    CurrentlyLoading = false;
                    UpdateCaption();
                }
                break;

            case Key.F8:
                formOptions.ShowOptions();
                Application.DoEvents();
                break;

            case Key.F9:
                if (Interface.MessageCount != 0)
                {
                    formMessages.ShowMessages();
                    Application.DoEvents();
                }
                break;

            case Key.F10:
                Renderer.RenderStatsOverlay = !Renderer.RenderStatsOverlay;
                break;

            case Key.A:
            case Key.Keypad4:
                World.CameraAlignmentDirection.Position.X = -World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.D:
            case Key.Keypad6:
                World.CameraAlignmentDirection.Position.X = World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad2:
                World.CameraAlignmentDirection.Position.Y = -World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad8:
                World.CameraAlignmentDirection.Position.Y = World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.W:
            case Key.Keypad9:
                World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.S:
            case Key.Keypad3:
                World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Left:
                World.CameraAlignmentDirection.Yaw = -World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Right:
                World.CameraAlignmentDirection.Yaw = World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Up:
                World.CameraAlignmentDirection.Pitch = World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Down:
                World.CameraAlignmentDirection.Pitch = -World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadDivide:
                World.CameraAlignmentDirection.Roll = -World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadMultiply:
                World.CameraAlignmentDirection.Roll = World.CameraExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad0:
                World.CameraAlignmentDirection.Zoom = World.CameraZoomTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadPeriod:
                World.CameraAlignmentDirection.Zoom = -World.CameraZoomTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad1:
                Game.ApplyPointOfInterest(-1, true);
                CpuReducedMode = false;
                break;

            case Key.Keypad7:
                Game.ApplyPointOfInterest(1, true);
                CpuReducedMode = false;
                break;

            case Key.PageUp:
                JumpToStation(1);
                CpuReducedMode = false;
                break;

            case Key.PageDown:
                JumpToStation(-1);
                CpuReducedMode = false;
                break;

            case Key.Keypad5:
                World.CameraCurrentAlignment.Yaw      = 0.0;
                World.CameraCurrentAlignment.Pitch    = 0.0;
                World.CameraCurrentAlignment.Roll     = 0.0;
                World.CameraCurrentAlignment.Position = new World.Vector3D(0.0, 2.5, 0.0);
                World.CameraCurrentAlignment.Zoom     = 0.0;
                World.CameraAlignmentDirection        = new World.CameraAlignment();
                World.CameraAlignmentSpeed            = new World.CameraAlignment();
                World.VerticalViewingAngle            = World.OriginalVerticalViewingAngle;
                UpdateViewport();
                World.UpdateAbsoluteCamera(0.0);
                World.UpdateViewingDistances();
                CpuReducedMode = false;
                break;

            case Key.F:
                Renderer.OptionWireframe = !Renderer.OptionWireframe;
                CpuReducedMode           = false;
                if (Renderer.OptionWireframe)
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                }
                else
                {
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                }
                break;

            case Key.N:
                Renderer.OptionNormals = !Renderer.OptionNormals;
                CpuReducedMode         = false;
                break;

            case Key.E:
                Renderer.OptionEvents = !Renderer.OptionEvents;
                CpuReducedMode        = false;
                break;

            case Key.C:
                CpuAutomaticMode = !CpuAutomaticMode;
                CpuReducedMode   = false;
                break;

            case Key.I:
                Renderer.OptionInterface = !Renderer.OptionInterface;
                CpuReducedMode           = false;
                break;

            case Key.M:
                SoundManager.Mute = !SoundManager.Mute;
                break;

            case Key.Plus:
            case Key.KeypadPlus:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = "+";
                    CpuReducedMode        = false;
                }
                break;

            case Key.Minus:
            case Key.KeypadMinus:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = "-";
                    CpuReducedMode        = false;
                }
                break;

            case Key.Number0:
            case Key.Number1:
            case Key.Number2:
            case Key.Number3:
            case Key.Number4:
            case Key.Number5:
            case Key.Number6:
            case Key.Number7:
            case Key.Number8:
            case Key.Number9:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = string.Empty;
                }
                JumpToPositionValue += char.ConvertFromUtf32(48 + e.Key - Key.Number0);
                CpuReducedMode       = false;
                break;

            case Key.Period:
                if (!JumpToPositionEnabled)
                {
                    JumpToPositionEnabled = true;
                    JumpToPositionValue   = "0.";
                }
                else if (JumpToPositionValue.IndexOf('.') == -1)
                {
                    JumpToPositionValue += ".";
                }
                CpuReducedMode = false;
                break;

            case Key.BackSpace:
                if (JumpToPositionEnabled && JumpToPositionValue.Length != 0)
                {
                    JumpToPositionValue = JumpToPositionValue.Substring(0, JumpToPositionValue.Length - 1);
                    CpuReducedMode      = false;
                }
                break;

            case Key.Enter:
                if (JumpToPositionEnabled)
                {
                    if (JumpToPositionValue.Length != 0)
                    {
                        int direction;
                        if (JumpToPositionValue[0] == '-')
                        {
                            JumpToPositionValue = JumpToPositionValue.Substring(1);
                            direction           = -1;
                        }
                        else if (JumpToPositionValue[0] == '+')
                        {
                            JumpToPositionValue = JumpToPositionValue.Substring(1);
                            direction           = 1;
                        }
                        else
                        {
                            direction = 0;
                        }
                        double value;
                        if (double.TryParse(JumpToPositionValue, NumberStyles.Float, CultureInfo.InvariantCulture,
                                            out value))
                        {
                            if (direction != 0)
                            {
                                value = World.CameraTrackFollower.TrackPosition + (double)direction * value;
                            }
                            TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, value, true, false);
                            World.CameraCurrentAlignment.TrackPosition = value;
                            World.UpdateAbsoluteCamera(0.0);
                            World.UpdateViewingDistances();
                        }
                    }
                    JumpToPositionEnabled = false;
                    CpuReducedMode        = false;
                }
                break;

            case Key.Escape:
                JumpToPositionEnabled = false;
                CpuReducedMode        = false;
                break;
            }
        }