UpdateAnimatedWorldObjects() static private method

static private UpdateAnimatedWorldObjects ( double TimeElapsed, bool ForceUpdate ) : void
TimeElapsed double
ForceUpdate bool
return void
Exemplo n.º 1
0
        internal static void DragFile(object sender, FileDropEventArgs e)
        {
            int n = Files.Length;

            Array.Resize <string>(ref Files, n + 1);
            Files[n] = e.FileName;
            // reset
            ReducedMode      = false;
            LightingRelative = -1.0;
            Game.Reset();
            Textures.UnloadAllTextures();
            //Fonts.Initialize();
            Interface.ClearMessages();
            for (int i = 0; i < Files.Length; i++)
            {
#if !DEBUG
                try
                {
#endif
                if (String.Compare(System.IO.Path.GetFileName(Files[i]), "extensions.cfg", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    UnifiedObject[]    carObjects;
                    UnifiedObject[]    bogieObjects;
                    TrainManager.Train train;
                    ExtensionsCfgParser.ParseExtensionsConfig(Files[i], System.Text.Encoding.UTF8, out carObjects, out bogieObjects, out train, true);
                    double z = 0.0;
                    for (int j = 0; j < carObjects.Length; j++)
                    {
                        ObjectManager.CreateObject(carObjects[j], new Vector3(0.0, 0.0, z),
                                                   new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                   0.0);
                        if (j < train.Cars.Length - 1)
                        {
                            z -= (train.Cars[j].Length + train.Cars[j + 1].Length) / 2;
                        }
                    }
                }
                else
                {
                    UnifiedObject o = ObjectManager.LoadObject(Files[i], System.Text.Encoding.UTF8, false, false, false);
                    ObjectManager.CreateObject(o, Vector3.Zero,
                                               new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                               0.0);
                }
#if !DEBUG
            }
            catch (Exception ex)
            {
                Interface.AddMessage(MessageType.Critical, false,
                                     "Unhandled error (" + ex.Message + ") encountered while processing the file " +
                                     Files[i] + ".");
            }
#endif
            }
            ObjectManager.InitializeVisibility();
            ObjectManager.FinishCreatingObjects();
            ObjectManager.UpdateVisibility(0.0, true);
            ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
        }
Exemplo n.º 2
0
 internal static void FileDrop(object sender, FileDropEventArgs e)
 {
     CurrentlyLoading = true;
     CurrentRouteFile = e.FileName;
     LoadRoute();
     ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
     CurrentlyLoading = false;
     UpdateCaption();
 }
Exemplo n.º 3
0
        //This renders the frame
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            Program.MouseMovement();
            Program.Renderer.FrameRate = RenderFrequency;

            //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 (Program.Renderer.Camera.AlignmentDirection.Position.X != 0.0 | Program.Renderer.Camera.AlignmentDirection.Position.Y != 0.0 | Program.Renderer.Camera.AlignmentDirection.Position.Z != 0.0 | Program.Renderer.Camera.AlignmentDirection.Pitch != 0.0 | Program.Renderer.Camera.AlignmentDirection.Yaw != 0.0 | Program.Renderer.Camera.AlignmentDirection.Roll != 0.0 | Program.Renderer.Camera.AlignmentDirection.TrackPosition != 0.0 | Program.Renderer.Camera.AlignmentDirection.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;
                    }
                }
            }

            if (Program.CurrentRouteFile != null)
            {
                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);
                Program.Renderer.UpdateVisibility(Program.Renderer.CameraTrackFollower.TrackPosition + Program.Renderer.Camera.Alignment.Position.Z);
                Program.Sounds.Update(TimeElapsed, SoundModels.Linear);
            }
            Program.Renderer.Lighting.UpdateLighting(Program.CurrentRoute.SecondsSinceMidnight);
            Program.Renderer.RenderScene(TimeElapsed);
            MessageManager.UpdateMessages();
            SwapBuffers();
        }
Exemplo n.º 4
0
 internal static void FileDrop(object sender, FileDropEventArgs e)
 {
     //Seem to need to flush the WM queue after dropping a file, else it crashes nastily after load on Mono
     Application.DoEvents();
     CurrentlyLoading = true;
     CurrentRouteFile = e.FileName;
     LoadRoute();
     ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
     CurrentlyLoading = false;
     UpdateCaption();
 }
Exemplo n.º 5
0
        //This renders the frame
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            Game.InfoFrameRate = RenderFrequency;
            GL.ClearColor(0.75f, 0.75f, 0.75f, 1.0f);
            //Do not do anything whilst loading
            if (currentlyLoading)
            {
                System.Threading.Thread.Sleep(10);
                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);
            SoundManager.Update(TimeElapsed);
            Renderer.RenderScene(TimeElapsed);
            SwapBuffers();
        }
Exemplo n.º 6
0
        internal static void DragFile(object sender, FileDropEventArgs e)
        {
            int n = Files.Length;

            Array.Resize(ref Files, n + 1);
            Files[n] = e.FileName;
            // reset
            LightingRelative = -1.0;
            Game.Reset();
            RefreshObjects();
            Renderer.InitializeVisibility();
            Renderer.UpdateVisibility(0.0, true);
            ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
            Renderer.ApplyBackgroundColor();
        }
Exemplo n.º 7
0
 protected override void OnLoad(EventArgs e)
 {
     KeyDown    += Program.KeyDown;
     KeyUp      += Program.KeyUp;
     MouseDown  += Program.MouseEvent;
     MouseUp    += Program.MouseEvent;
     MouseWheel += Program.MouseWheelEvent;
     FileDrop   += Program.DragFile;
     Program.Renderer.Camera.Reset(new Vector3(-5.0, 2.5, -25.0));
     Program.Renderer.Initialize(Program.CurrentHost, Interface.CurrentOptions);
     Program.Renderer.Lighting.Initialize();
     Program.Renderer.UpdateViewport();
     Program.Renderer.InitializeVisibility();
     Program.Renderer.UpdateVisibility(0.0, true);
     ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
     Program.RefreshObjects();
 }
Exemplo n.º 8
0
 protected override void OnLoad(EventArgs e)
 {
     KeyDown    += Program.KeyDown;
     KeyUp      += Program.KeyUp;
     MouseDown  += Program.MouseEvent;
     MouseUp    += Program.MouseEvent;
     MouseWheel += Program.MouseWheelEvent;
     FileDrop   += Program.DragFile;
     Program.ResetCamera();
     Renderer.Initialize();
     Renderer.InitializeLighting();
     //SwapBuffers();
     Fonts.Initialize();
     Program.UpdateViewport();
     // command line arguments
     // if (commandLineArgs != null)
     // {
     //     for (int i = 0; i < commandLineArgs.Length; i++)
     //     {
     //         if (!Program.SkipArgs[i] && System.IO.File.Exists(commandLineArgs[i]))
     //         {
     //             try
     //             {
     //                 ObjectManager.UnifiedObject o = ObjectManager.LoadObject(commandLineArgs[i],
     //                     System.Text.Encoding.UTF8, ObjectManager.ObjectLoadMode.Normal, false, false, false,0,0,0);
     //                 ObjectManager.CreateObject(o, new Vector3(0.0, 0.0, 0.0),
     //                     new World.Transformation(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), true,
     //                     0.0, 0.0, 25.0, 0.0);
     //             }
     //             catch (Exception ex)
     //             {
     //                 Interface.AddMessage(Interface.MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + commandLineArgs[i] + ".");
     //             }
     //             Array.Resize<string>(ref Program.Files, Program.Files.Length + 1);
     //             Program.Files[Program.Files.Length - 1] = commandLineArgs[i];
     //         }
     //     }
     // }
     ObjectManager.InitializeVisibility();
     ObjectManager.FinishCreatingObjects();
     ObjectManager.UpdateVisibility(0.0, true);
     ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
     Program.UpdateCaption();
 }
Exemplo n.º 9
0
 internal static void UpdateGraphicsSettings()
 {
     if (CurrentRouteFile != null)
     {
         Program.CurrentlyLoading = true;
         Renderer.RenderScene(0.0);
         Program.currentGameWindow.SwapBuffers();
         CameraAlignment a = Renderer.Camera.Alignment;
         if (Program.LoadRoute())
         {
             Renderer.Camera.Alignment = a;
             Program.Renderer.CameraTrackFollower.UpdateAbsolute(-1.0, true, false);
             Program.Renderer.CameraTrackFollower.UpdateAbsolute(a.TrackPosition, true, false);
             Renderer.Camera.AlignmentDirection = new CameraAlignment();
             Renderer.Camera.AlignmentSpeed     = new CameraAlignment();
             Renderer.UpdateVisibility(a.TrackPosition, true);
             ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
         }
         Program.CurrentlyLoading = false;
     }
 }
Exemplo n.º 10
0
        internal static void DragFile(object sender, FileDropEventArgs e)
        {
            int n = Files.Length;

            Array.Resize <string>(ref Files, n + 1);
            Files[n] = e.FileName;
            // reset
            ReducedMode      = false;
            LightingRelative = -1.0;
            Game.Reset();
            TextureManager.UnuseAllTextures();
            Fonts.Initialize();
            Interface.ClearMessages();
            for (int i = 0; i < Files.Length; i++)
            {
#if !DEBUG
                try
                {
#endif
                ObjectManager.UnifiedObject o = ObjectManager.LoadObject(Files[i], System.Text.Encoding.UTF8,
                                                                         ObjectManager.ObjectLoadMode.Normal, false, false, false);
                ObjectManager.CreateObject(o, new Vector3(0.0, 0.0, 0.0),
                                           new World.Transformation(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                           0.0);
#if !DEBUG
            }
            catch (Exception ex)
            {
                Interface.AddMessage(Interface.MessageType.Critical, false,
                                     "Unhandled error (" + ex.Message + ") encountered while processing the file " +
                                     Files[i] + ".");
            }
#endif
            }
            ObjectManager.InitializeVisibility();
            ObjectManager.FinishCreatingObjects();
            ObjectManager.UpdateVisibility(0.0, true);
            ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
        }
Exemplo n.º 11
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;
     }
 }
Exemplo n.º 12
0
        // process events
        internal static void KeyDown(object sender, KeyboardKeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.LShift:
            case Key.RShift:
                ShiftPressed = true;
                break;

            case Key.F5:
                // reset
                ReducedMode      = false;
                LightingRelative = -1.0;
                Game.Reset();
                TextureManager.UnuseAllTextures();
                Fonts.Initialize();
                Interface.ClearMessages();
                for (int i = 0; i < Files.Length; i++)
                {
#if !DEBUG
                    try {
                                                                                #endif
                    ObjectManager.UnifiedObject o = ObjectManager.LoadObject(Files[i], System.Text.Encoding.UTF8,
                                                                             ObjectManager.ObjectLoadMode.Normal, false, false, false);
                    ObjectManager.CreateObject(o, new Vector3(0.0, 0.0, 0.0),
                                               new World.Transformation(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), true, 0.0,
                                               0.0, 25.0, 0.0);
#if !DEBUG
                }
                catch (Exception ex) {
                    Interface.AddMessage(Interface.MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + Files[i] + ".");
                }
                                                                        #endif
                }
                ObjectManager.InitializeVisibility();
                ObjectManager.UpdateVisibility(0.0, true);
                ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
                break;

            case Key.F7:
            {
                OpenFileDialog Dialog = new OpenFileDialog();
                Dialog.CheckFileExists = true;
                Dialog.Multiselect     = true;
                Dialog.Filter          = "CSV/B3D/X/ANIMATED files|*.csv;*.b3d;*.x;*.animated;*.l3dobj;*.l3dgrp|All files|*";
                if (Dialog.ShowDialog() == DialogResult.OK)
                {
                    Application.DoEvents();
                    string[] f = Dialog.FileNames;
                    int      n = Files.Length;
                    Array.Resize <string>(ref Files, n + f.Length);
                    for (int i = 0; i < f.Length; i++)
                    {
                        Files[n + i] = f[i];
                    }
                    // reset
                    ReducedMode      = false;
                    LightingRelative = -1.0;
                    Game.Reset();
                    TextureManager.UnuseAllTextures();
                    Fonts.Initialize();
                    Interface.ClearMessages();
                    for (int i = 0; i < Files.Length; i++)
                    {
#if !DEBUG
                        try
                        {
#endif
                        ObjectManager.UnifiedObject o = ObjectManager.LoadObject(Files[i], System.Text.Encoding.UTF8,
                                                                                 ObjectManager.ObjectLoadMode.Normal, false, false, false);
                        ObjectManager.CreateObject(o, new Vector3(0.0, 0.0, 0.0),
                                                   new World.Transformation(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                   0.0);
#if !DEBUG
                    }
                    catch (Exception ex)
                    {
                        Interface.AddMessage(Interface.MessageType.Critical, false,
                                             "Unhandled error (" + ex.Message + ") encountered while processing the file " +
                                             Files[i] + ".");
                    }
#endif
                    }
                    ObjectManager.InitializeVisibility();
                    ObjectManager.FinishCreatingObjects();
                    ObjectManager.UpdateVisibility(0.0, true);
                    ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
                }
                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.F9:
                if (Interface.MessageCount != 0)
                {
                    formMessages.ShowMessages();
                    Application.DoEvents();
                }
                break;

            case Key.Delete:
                ReducedMode      = false;
                LightingRelative = -1.0;
                Game.Reset();
                TextureManager.UnuseAllTextures();
                Fonts.Initialize();
                Interface.ClearMessages();
                Files = new string[] {};
                break;

            case Key.Left:
                RotateX     = -1;
                ReducedMode = false;
                break;

            case Key.Right:
                RotateX     = 1;
                ReducedMode = false;
                break;

            case Key.Up:
                RotateY     = -1;
                ReducedMode = false;
                break;

            case Key.Down:
                RotateY     = 1;
                ReducedMode = false;
                break;

            case Key.A:
            case Key.Keypad4:
                MoveX       = -1;
                ReducedMode = false;
                break;

            case Key.D:
            case Key.Keypad6:
                MoveX       = 1;
                ReducedMode = false;
                break;

            case Key.Keypad8:
                MoveY       = 1;
                ReducedMode = false;
                break;

            case Key.Keypad2:
                MoveY       = -1;
                ReducedMode = false;
                break;

            case Key.W:
            case Key.Keypad9:
                MoveZ       = 1;
                ReducedMode = false;
                break;

            case Key.S:
            case Key.Keypad3:
                MoveZ       = -1;
                ReducedMode = false;
                break;

            case Key.Keypad5:
                ResetCamera();
                break;

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

            case Key.N:
            case Key.F2:
                Renderer.OptionNormals = !Renderer.OptionNormals;
                break;

            case Key.L:
            case Key.F3:
                LightingTarget = 1 - LightingTarget;
                ReducedMode    = false;
                break;

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

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

            case Key.G:
            case Key.C:
                Renderer.OptionCoordinateSystem = !Renderer.OptionCoordinateSystem;
                ReducedMode = false;
                break;

            case Key.B:
                if (ShiftPressed)
                {
                    ColorDialog dialog = new ColorDialog();
                    dialog.FullOpen = true;
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        Renderer.BackgroundColor = -1;
                        Renderer.ApplyBackgroundColor(dialog.Color.R, dialog.Color.G, dialog.Color.B);
                    }
                }
                else
                {
                    Renderer.BackgroundColor++;
                    if (Renderer.BackgroundColor >= Renderer.MaxBackgroundColor)
                    {
                        Renderer.BackgroundColor = 0;
                    }
                    Renderer.ApplyBackgroundColor();
                }
                ReducedMode = false;
                break;
            }
        }
Exemplo n.º 13
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 (CurrentRouteFile != null && CurrentlyLoading == false)
                {
                    Bitmap bitmap = null;
                    CurrentlyLoading         = true;
                    Renderer.OptionInterface = false;
                    if (!Interface.CurrentOptions.LoadingBackground)
                    {
                        Renderer.RenderScene(0.0);
                        currentGameWindow.SwapBuffers();
                        bitmap = new Bitmap(Renderer.Screen.Width, Renderer.Screen.Height, 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.Screen.Width, Renderer.Screen.Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bData.Scan0);
                        bitmap.UnlockBits(bData);
                        bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                        Renderer.Loading.SetLoadingBkg(Renderer.TextureManager.RegisterTexture(bitmap, new TextureParameters(null, null)));
                    }
                    CameraAlignment a = Renderer.Camera.Alignment;
                    if (LoadRoute())
                    {
                        Renderer.Camera.Alignment = a;
                        Program.Renderer.CameraTrackFollower.UpdateAbsolute(-1.0, true, false);
                        Program.Renderer.CameraTrackFollower.UpdateAbsolute(a.TrackPosition, true, false);
                        Renderer.Camera.AlignmentDirection = new CameraAlignment();
                        Renderer.Camera.AlignmentSpeed     = new CameraAlignment();
                        Renderer.UpdateVisibility(a.TrackPosition, true);
                        ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                    }

                    CurrentlyLoading         = false;
                    Renderer.OptionInterface = true;
                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                    }
                }
                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;
                    CurrentRouteFile = 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:
                Renderer.Camera.AlignmentDirection.Position.X = -CameraProperties.ExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.D:
            case Key.Keypad6:
                Renderer.Camera.AlignmentDirection.Position.X = CameraProperties.ExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad2:
                Renderer.Camera.AlignmentDirection.Position.Y = -CameraProperties.ExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad8:
                Renderer.Camera.AlignmentDirection.Position.Y = CameraProperties.ExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.W:
            case Key.Keypad9:
                Renderer.Camera.AlignmentDirection.TrackPosition = CameraProperties.ExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.S:
            case Key.Keypad3:
                Renderer.Camera.AlignmentDirection.TrackPosition = -CameraProperties.ExteriorTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Left:
                Renderer.Camera.AlignmentDirection.Yaw = -CameraProperties.ExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Right:
                Renderer.Camera.AlignmentDirection.Yaw = CameraProperties.ExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Up:
                Renderer.Camera.AlignmentDirection.Pitch = CameraProperties.ExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Down:
                Renderer.Camera.AlignmentDirection.Pitch = -CameraProperties.ExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadDivide:
                Renderer.Camera.AlignmentDirection.Roll = -CameraProperties.ExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadMultiply:
                Renderer.Camera.AlignmentDirection.Roll = CameraProperties.ExteriorTopAngularSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.Keypad0:
                Renderer.Camera.AlignmentDirection.Zoom = CameraProperties.ZoomTopSpeed * speedModified;
                CpuReducedMode = false;
                break;

            case Key.KeypadPeriod:
                Renderer.Camera.AlignmentDirection.Zoom = -CameraProperties.ZoomTopSpeed * 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:
                Renderer.Camera.Alignment.Yaw        = 0.0;
                Renderer.Camera.Alignment.Pitch      = 0.0;
                Renderer.Camera.Alignment.Roll       = 0.0;
                Renderer.Camera.Alignment.Position   = new Vector3(0.0, 2.5, 0.0);
                Renderer.Camera.Alignment.Zoom       = 0.0;
                Renderer.Camera.AlignmentDirection   = new CameraAlignment();
                Renderer.Camera.AlignmentSpeed       = new CameraAlignment();
                Renderer.Camera.VerticalViewingAngle = Renderer.Camera.OriginalVerticalViewingAngle;
                Renderer.UpdateViewport();
                World.UpdateAbsoluteCamera(0.0);
                Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance);
                CpuReducedMode = false;
                break;

            case Key.F:
                Renderer.OptionWireFrame = !Renderer.OptionWireFrame;
                CpuReducedMode           = false;
                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 < CurrentRoute.Tracks[0].Elements[CurrentRoute.Tracks[0].Elements.Length - 1].StartingTrackPosition + 100 && value > MinimumJumpToPositionValue - 100)
                            {
                                if (direction != 0)
                                {
                                    value = Program.Renderer.CameraTrackFollower.TrackPosition + (double)direction * value;
                                }

                                Program.Renderer.CameraTrackFollower.UpdateAbsolute(value, true, false);
                                Renderer.Camera.Alignment.TrackPosition = value;
                                World.UpdateAbsoluteCamera(0.0);
                                Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance);
                            }
                        }
                    }
                }
                JumpToPositionEnabled = false;
                CpuReducedMode        = false;
                break;

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

            case Key.R:
                Interface.CurrentOptions.IsUseNewRenderer = !Interface.CurrentOptions.IsUseNewRenderer;
                break;
            }
        }
Exemplo n.º 14
0
        // process events
        private static void ProcessEvents()
        {
            SDL.SDL_Event Event;
            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:
                    MouseCenterX         = (short)Event.button.x;
                    MouseCenterY         = (short)Event.button.y;
                    MouseCameraPosition  = World.AbsoluteCameraPosition;
                    MouseCameraDirection = World.AbsoluteCameraDirection;
                    MouseCameraUp        = World.AbsoluteCameraUp;
                    MouseCameraSide      = World.AbsoluteCameraSide;
                    MouseButton          = Event.button.button;
                    break;

                case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
                    MouseButton = 0;
                    break;

                case SDL.SDL_EventType.SDL_MOUSEMOTION:
                    if (MouseButton == SDL.SDL_BUTTON_LEFT)
                    {
                        World.AbsoluteCameraDirection = MouseCameraDirection;
                        World.AbsoluteCameraUp        = MouseCameraUp;
                        World.AbsoluteCameraSide      = MouseCameraSide;
                        {
                            double dx   = 0.0025 * (double)(MouseCenterX - Event.motion.x);
                            double cosa = Math.Cos(dx);
                            double sina = Math.Sin(dx);
                            World.Rotate(ref World.AbsoluteCameraDirection.X, ref World.AbsoluteCameraDirection.Y, ref World.AbsoluteCameraDirection.Z, 0.0, 1.0, 0.0, cosa, sina);
                            World.Rotate(ref World.AbsoluteCameraUp.X, ref World.AbsoluteCameraUp.Y, ref World.AbsoluteCameraUp.Z, 0.0, 1.0, 0.0, cosa, sina);
                            World.Rotate(ref World.AbsoluteCameraSide.X, ref World.AbsoluteCameraSide.Y, ref World.AbsoluteCameraSide.Z, 0.0, 1.0, 0.0, cosa, sina);
                        }
                        {
                            double dy   = 0.0025 * (double)(MouseCenterY - Event.motion.y);
                            double cosa = Math.Cos(dy);
                            double sina = Math.Sin(dy);
                            World.Rotate(ref World.AbsoluteCameraDirection.X, ref World.AbsoluteCameraDirection.Y, ref World.AbsoluteCameraDirection.Z, World.AbsoluteCameraSide.X, World.AbsoluteCameraSide.Y, World.AbsoluteCameraSide.Z, cosa, sina);
                            World.Rotate(ref World.AbsoluteCameraUp.X, ref World.AbsoluteCameraUp.Y, ref World.AbsoluteCameraUp.Z, World.AbsoluteCameraSide.X, World.AbsoluteCameraSide.Y, World.AbsoluteCameraSide.Z, cosa, sina);
                        }
                        ReducedMode = false;
                    }
                    else if (MouseButton == SDL.SDL_BUTTON_RIGHT)
                    {
                        World.AbsoluteCameraPosition = MouseCameraPosition;
                        double dx = -0.025 * (double)(Event.motion.x - MouseCenterX);
                        World.AbsoluteCameraPosition.X += dx * World.AbsoluteCameraSide.X;
                        World.AbsoluteCameraPosition.Y += dx * World.AbsoluteCameraSide.Y;
                        World.AbsoluteCameraPosition.Z += dx * World.AbsoluteCameraSide.Z;
                        double dy = 0.025 * (double)(Event.motion.y - MouseCenterY);
                        World.AbsoluteCameraPosition.X += dy * World.AbsoluteCameraUp.X;
                        World.AbsoluteCameraPosition.Y += dy * World.AbsoluteCameraUp.Y;
                        World.AbsoluteCameraPosition.Z += dy * World.AbsoluteCameraUp.Z;
                        ReducedMode = false;
                    }
                    else if (MouseButton == SDL.SDL_BUTTON_MIDDLE)
                    {
                        World.AbsoluteCameraPosition = MouseCameraPosition;
                        double dx = -0.025 * (double)(Event.motion.x - MouseCenterX);
                        World.AbsoluteCameraPosition.X += dx * World.AbsoluteCameraSide.X;
                        World.AbsoluteCameraPosition.Y += dx * World.AbsoluteCameraSide.Y;
                        World.AbsoluteCameraPosition.Z += dx * World.AbsoluteCameraSide.Z;
                        double dz = -0.025 * (double)(Event.motion.y - MouseCenterY);
                        World.AbsoluteCameraPosition.X += dz * World.AbsoluteCameraDirection.X;
                        World.AbsoluteCameraPosition.Y += dz * World.AbsoluteCameraDirection.Y;
                        World.AbsoluteCameraPosition.Z += dz * World.AbsoluteCameraDirection.Z;
                        ReducedMode = false;
                    }
                    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_F5:
                        // reset
                        ReducedMode      = false;
                        LightingRelative = -1.0;
                        Game.Reset();
                        TextureManager.UnuseAllTextures();
                        Fonts.Initialize();
                        Interface.ClearMessages();
                        for (int i = 0; i < Files.Length; i++)
                        {
                                                                        #if !DEBUG
                            try {
                                                                                #endif
                            ObjectManager.UnifiedObject o = ObjectManager.LoadObject(Files[i], System.Text.Encoding.UTF8, ObjectManager.ObjectLoadMode.Normal, false, false, false);
                            ObjectManager.CreateObject(o, new World.Vector3D(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0, 0.0);
                                                                                #if !DEBUG
                        }
                        catch (Exception ex) {
                            Interface.AddMessage(Interface.MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + Files[i] + ".");
                        }
                                                                        #endif
                        }
                        ObjectManager.InitializeVisibility();
                        ObjectManager.UpdateVisibility(0.0, true);
                        ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
                        break;

                    case SDL.SDL_Keycode.SDLK_F7:
                    {
                        OpenFileDialog Dialog = new OpenFileDialog();
                        Dialog.CheckFileExists = true;
                        Dialog.Multiselect     = true;
                        Dialog.Filter          = "CSV/B3D/X/ANIMATED files|*.csv;*.b3d;*.x;*.animated|All files|*";
                        if (Dialog.ShowDialog() == DialogResult.OK)
                        {
                            string[] f = Dialog.FileNames;
                            int      n = Files.Length;
                            Array.Resize <string>(ref Files, n + f.Length);
                            for (int i = 0; i < f.Length; i++)
                            {
                                Files[n + i] = f[i];
                            }
                            // reset
                            ReducedMode      = false;
                            LightingRelative = -1.0;
                            Game.Reset();
                            TextureManager.UnuseAllTextures();
                            Fonts.Initialize();
                            Interface.ClearMessages();
                            for (int i = 0; i < Files.Length; i++)
                            {
                                                                                        #if !DEBUG
                                try {
                                                                                                #endif
                                ObjectManager.UnifiedObject o = ObjectManager.LoadObject(Files[i], System.Text.Encoding.UTF8, ObjectManager.ObjectLoadMode.Normal, false, false, false);
                                ObjectManager.CreateObject(o, new World.Vector3D(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0, 0.0);
                                                                                                #if !DEBUG
                            }
                            catch (Exception ex) {
                                Interface.AddMessage(Interface.MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + Files[i] + ".");
                            }
                                                                                        #endif
                            }
                            ObjectManager.InitializeVisibility();
                            ObjectManager.FinishCreatingObjects();
                            ObjectManager.UpdateVisibility(0.0, true);
                            ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
                        }
                    } break;

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

                    case SDL.SDL_Keycode.SDLK_DELETE:
                        ReducedMode      = false;
                        LightingRelative = -1.0;
                        Game.Reset();
                        TextureManager.UnuseAllTextures();
                        Fonts.Initialize();
                        Interface.ClearMessages();
                        Files = new string[] { };
                        UpdateCaption();
                        break;

                    case SDL.SDL_Keycode.SDLK_LEFT:
                        RotateX     = -1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_RIGHT:
                        RotateX     = 1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_UP:
                        RotateY     = -1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_DOWN:
                        RotateY     = 1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_a:
                    case SDL.SDL_Keycode.SDLK_KP_4:
                        MoveX       = -1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_d:
                    case SDL.SDL_Keycode.SDLK_KP_6:
                        MoveX       = 1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_8:
                        MoveY       = 1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_2:
                        MoveY       = -1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_w:
                    case SDL.SDL_Keycode.SDLK_KP_9:
                        MoveZ       = 1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_s:
                    case SDL.SDL_Keycode.SDLK_KP_3:
                        MoveZ       = -1;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_5:
                        ResetCamera();
                        break;

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

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

                    case SDL.SDL_Keycode.SDLK_l:
                    case SDL.SDL_Keycode.SDLK_F3:
                        LightingTarget = 1 - LightingTarget;
                        ReducedMode    = false;
                        break;

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

                    case SDL.SDL_Keycode.SDLK_g:
                    case SDL.SDL_Keycode.SDLK_c:
                        Renderer.OptionCoordinateSystem = !Renderer.OptionCoordinateSystem;
                        ReducedMode = false;
                        break;

                    case SDL.SDL_Keycode.SDLK_b:
                        if (ShiftPressed)
                        {
                            ColorDialog dialog = new ColorDialog();
                            dialog.FullOpen = true;
                            if (dialog.ShowDialog() == DialogResult.OK)
                            {
                                Renderer.BackgroundColor = -1;
                                Renderer.ApplyBackgroundColor(dialog.Color.R, dialog.Color.G, dialog.Color.B);
                            }
                        }
                        else
                        {
                            Renderer.BackgroundColor++;
                            if (Renderer.BackgroundColor >= Renderer.MaxBackgroundColor)
                            {
                                Renderer.BackgroundColor = 0;
                            }
                            Renderer.ApplyBackgroundColor();
                        }
                        ReducedMode = 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_LEFT:
                    case SDL.SDL_Keycode.SDLK_RIGHT:
                        RotateX = 0;
                        break;

                    case SDL.SDL_Keycode.SDLK_UP:
                    case SDL.SDL_Keycode.SDLK_DOWN:
                        RotateY = 0;
                        break;

                    case SDL.SDL_Keycode.SDLK_a:
                    case SDL.SDL_Keycode.SDLK_d:
                    case SDL.SDL_Keycode.SDLK_KP_4:
                    case SDL.SDL_Keycode.SDLK_KP_6:
                        MoveX = 0;
                        break;

                    case SDL.SDL_Keycode.SDLK_KP_8:
                    case SDL.SDL_Keycode.SDLK_KP_2:
                        MoveY = 0;
                        break;

                    case SDL.SDL_Keycode.SDLK_w:
                    case SDL.SDL_Keycode.SDLK_s:
                    case SDL.SDL_Keycode.SDLK_KP_9:
                    case SDL.SDL_Keycode.SDLK_KP_3:
                        MoveZ = 0;
                        break;
                    }
                    break;
                }
            }
        }
Exemplo n.º 15
0
        internal static void RefreshObjects()
        {
            LightingRelative = -1.0;
            Game.Reset();
            Interface.LogMessages.Clear();
            for (int i = 0; i < Files.Length; i++)
            {
                try
                {
                    if (String.Compare(System.IO.Path.GetFileName(Files[i]), "extensions.cfg", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        UnifiedObject[]    carObjects, bogieObjects, couplerObjects;
                        double[]           axleLocations, couplerDistances;
                        TrainManager.Train train;
                        ExtensionsCfgParser.ParseExtensionsConfig(Files[i], out carObjects, out bogieObjects, out couplerObjects, out axleLocations, out couplerDistances, out train, true);
                        double z = 0.0;
                        for (int j = 0; j < carObjects.Length; j++)
                        {
                            if (carObjects[j] == null)
                            {
                                continue;
                            }
                            carObjects[j].CreateObject(new Vector3(0.0, 0.0, z), 0.0, 0.0, 0.0);
                            if (j < train.Cars.Length - 1)
                            {
                                z -= (train.Cars[j].Length + train.Cars[j + 1].Length) / 2.0;
                                z -= couplerDistances[j];
                            }
                        }

                        z = 0.0;
                        int trainCar = 0;
                        for (int j = 0; j < bogieObjects.Length; j++)
                        {
                            if (bogieObjects[j] == null)
                            {
                                continue;
                            }

                            bogieObjects[j].CreateObject(new Vector3(0.0, 0.0, z + axleLocations[j]), 0.0, 0.0, 0.0);
                            j++;
                            if (bogieObjects[j] == null)
                            {
                                continue;
                            }

                            bogieObjects[j].CreateObject(new Vector3(0.0, 0.0, z + axleLocations[j]), 0.0, 0.0, 0.0);
                            if (trainCar < train.Cars.Length - 1)
                            {
                                z -= (train.Cars[trainCar].Length + train.Cars[trainCar + 1].Length) / 2.0;
                                z -= couplerDistances[trainCar];
                            }

                            trainCar++;
                        }

                        z = 0.0;
                        for (int j = 0; j < couplerObjects.Length; j++)
                        {
                            z -= train.Cars[j].Length / 2.0;
                            z -= couplerDistances[j] / 2.0;
                            if (couplerObjects[j] == null)
                            {
                                continue;
                            }

                            couplerObjects[j].CreateObject(new Vector3(0.0, 0.0, z), 0.0, 0.0, 0.0);

                            z -= couplerDistances[j] / 2.0;
                            z -= train.Cars[j + 1].Length / 2.0;
                        }
                    }
                    else
                    {
                        UnifiedObject o;
                        Program.CurrentHost.LoadObject(Files[i], System.Text.Encoding.UTF8, out o);
                        o.CreateObject(Vector3.Zero, 0.0, 0.0, 0.0);
                    }
                }
                catch (Exception ex)
                {
                    Interface.AddMessage(MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + Files[i] + ".");
                }
            }

            Renderer.InitializeVisibility();
            Renderer.UpdateVisibility(0.0, true);
            ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
            Renderer.ApplyBackgroundColor();
        }
Exemplo n.º 16
0
        /// <summary>This method is called once the route and train data have been preprocessed, in order to physically setup the simulation</summary>
        private void SetupSimulation()
        {
            if (Loading.Cancel)
            {
                Close();
            }
            Timetable.CreateTimetable();
            //Check if any critical errors have occured during the route or train loading
            for (int i = 0; i < Interface.MessageCount; i++)
            {
                if (Interface.Messages[i].Type == Interface.MessageType.Critical)
                {
                    MessageBox.Show("A critical error has occured:\n\n" + Interface.Messages[i].Text + "\n\nPlease inspect the error log file for further information.", "Load", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    Close();
                }
            }
            Renderer.InitializeLighting();
            Game.LogRouteName = System.IO.Path.GetFileName(MainLoop.currentResult.RouteFile);
            Game.LogTrainName = System.IO.Path.GetFileName(MainLoop.currentResult.TrainFolder);
            Game.LogDateTime  = DateTime.Now;

            if (Interface.CurrentOptions.LoadInAdvance)
            {
                Textures.LoadAllTextures();
            }
            else
            {
                Textures.UnloadAllTextures();
            }
            // camera
            ObjectManager.InitializeVisibility();
            World.CameraTrackFollower.Update(0.0, true, false);
            World.CameraTrackFollower.Update(-0.1, true, false);
            World.CameraTrackFollower.Update(0.1, true, false);
            World.CameraTrackFollower.TriggerType = TrackManager.EventTriggerType.Camera;
            // starting time and track position
            Game.SecondsSinceMidnight = 0.0;
            Game.StartupTime          = 0.0;
            int    PlayerFirstStationIndex = -1;
            double PlayerFirstStationPosition;
            int    os = -1;
            bool   f  = false;

            for (int i = 0; i < Game.Stations.Length; i++)
            {
                if (!String.IsNullOrEmpty(Game.InitialStationName))
                {
                    if (Game.InitialStationName.ToLowerInvariant() == Game.Stations[i].Name.ToLowerInvariant())
                    {
                        PlayerFirstStationIndex = i;
                    }
                }
                if (Game.Stations[i].StopMode == StationStopMode.AllStop | Game.Stations[i].StopMode == StationStopMode.PlayerStop & Game.Stations[i].Stops.Length != 0)
                {
                    if (f == false)
                    {
                        os = i;
                        f  = true;
                    }
                }
            }
            if (PlayerFirstStationIndex == -1)
            {
                PlayerFirstStationIndex = os;
            }
            {
                int s = Game.GetStopIndex(PlayerFirstStationIndex, TrainManager.PlayerTrain.Cars.Length);
                if (s >= 0)
                {
                    PlayerFirstStationPosition = Game.Stations[PlayerFirstStationIndex].Stops[s].TrackPosition;

                    double TrainLength = 0.0;
                    for (int c = 0; c < TrainManager.Trains[TrainManager.PlayerTrain.TrainIndex].Cars.Length; c++)
                    {
                        TrainLength += TrainManager.Trains[TrainManager.PlayerTrain.TrainIndex].Cars[c].Length;
                    }

                    for (int j = 0; j < Game.BufferTrackPositions.Length; j++)
                    {
                        if (PlayerFirstStationPosition > Game.BufferTrackPositions[j] && PlayerFirstStationPosition - TrainLength < Game.BufferTrackPositions[j])
                        {
                            /*
                             * HACK: The initial start position for the player train is stuck on a set of buffers
                             * This means we have to make some one the fly adjustments to the first station stop position
                             */

                            //Set the start position to be the buffer position plus the train length plus 1m
                            PlayerFirstStationPosition = Game.BufferTrackPositions[j] + TrainLength + 1;
                            //Update the station stop location
                            if (s >= 0)
                            {
                                Game.Stations[PlayerFirstStationIndex].Stops[s].TrackPosition = PlayerFirstStationPosition;
                            }
                            else
                            {
                                Game.Stations[PlayerFirstStationIndex].DefaultTrackPosition = PlayerFirstStationPosition;
                            }
                            break;
                        }
                    }
                }
                else
                {
                    PlayerFirstStationPosition = Game.Stations[PlayerFirstStationIndex].DefaultTrackPosition;
                }
                if (Game.InitialStationTime != -1)
                {
                    Game.SecondsSinceMidnight = Game.InitialStationTime;
                    Game.StartupTime          = Game.InitialStationTime;
                }
                else
                {
                    if (Game.Stations[PlayerFirstStationIndex].ArrivalTime < 0.0)
                    {
                        if (Game.Stations[PlayerFirstStationIndex].DepartureTime < 0.0)
                        {
                            Game.SecondsSinceMidnight = 0.0;
                            Game.StartupTime          = 0.0;
                        }
                        else
                        {
                            Game.SecondsSinceMidnight = Game.Stations[PlayerFirstStationIndex].DepartureTime -
                                                        Game.Stations[PlayerFirstStationIndex].StopTime;
                            Game.StartupTime = Game.Stations[PlayerFirstStationIndex].DepartureTime -
                                               Game.Stations[PlayerFirstStationIndex].StopTime;
                        }
                    }
                    else
                    {
                        Game.SecondsSinceMidnight = Game.Stations[PlayerFirstStationIndex].ArrivalTime;
                        Game.StartupTime          = Game.Stations[PlayerFirstStationIndex].ArrivalTime;
                    }
                }
            }
            int    OtherFirstStationIndex    = -1;
            double OtherFirstStationPosition = 0.0;
            double OtherFirstStationTime     = 0.0;

            for (int i = 0; i < Game.Stations.Length; i++)
            {
                if (Game.Stations[i].StopMode == StationStopMode.AllStop | Game.Stations[i].StopMode == StationStopMode.PlayerPass & Game.Stations[i].Stops.Length != 0)
                {
                    OtherFirstStationIndex = i;
                    int s = Game.GetStopIndex(i, TrainManager.PlayerTrain.Cars.Length);
                    if (s >= 0)
                    {
                        OtherFirstStationPosition = Game.Stations[i].Stops[s].TrackPosition;
                    }
                    else
                    {
                        OtherFirstStationPosition = Game.Stations[i].DefaultTrackPosition;
                    }
                    if (Game.Stations[i].ArrivalTime < 0.0)
                    {
                        if (Game.Stations[i].DepartureTime < 0.0)
                        {
                            OtherFirstStationTime = 0.0;
                        }
                        else
                        {
                            OtherFirstStationTime = Game.Stations[i].DepartureTime - Game.Stations[i].StopTime;
                        }
                    }
                    else
                    {
                        OtherFirstStationTime = Game.Stations[i].ArrivalTime;
                    }
                    break;
                }
            }
            if (Game.PrecedingTrainTimeDeltas.Length != 0)
            {
                OtherFirstStationTime -= Game.PrecedingTrainTimeDeltas[Game.PrecedingTrainTimeDeltas.Length - 1];
                if (OtherFirstStationTime < Game.SecondsSinceMidnight)
                {
                    Game.SecondsSinceMidnight = OtherFirstStationTime;
                }
            }
            // initialize trains
            for (int i = 0; i < TrainManager.Trains.Length; i++)
            {
                TrainManager.Trains[i].Initialize();
                int s = i == TrainManager.PlayerTrain.TrainIndex ? PlayerFirstStationIndex : OtherFirstStationIndex;
                if (s >= 0)
                {
                    if (Game.Stations[s].OpenLeftDoors)
                    {
                        for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++)
                        {
                            TrainManager.Trains[i].Cars[j].Doors[0].AnticipatedOpen = true;
                        }
                    }
                    if (Game.Stations[s].OpenRightDoors)
                    {
                        for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++)
                        {
                            TrainManager.Trains[i].Cars[j].Doors[1].AnticipatedOpen = true;
                        }
                    }
                }
                if (Game.Sections.Length != 0)
                {
                    Game.Sections[0].Enter(TrainManager.Trains[i]);
                }
                for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++)
                {
                    double length = TrainManager.Trains[i].Cars[0].Length;
                    TrainManager.Trains[i].Cars[j].Move(-length, 0.01);
                    TrainManager.Trains[i].Cars[j].Move(length, 0.01);
                }
            }
            // score
            Game.CurrentScore.ArrivalStation   = PlayerFirstStationIndex + 1;
            Game.CurrentScore.DepartureStation = PlayerFirstStationIndex;
            Game.CurrentScore.Maximum          = 0;
            for (int i = 0; i < Game.Stations.Length; i++)
            {
                if (i != PlayerFirstStationIndex & Game.PlayerStopsAtStation(i))
                {
                    if (i == 0 || Game.Stations[i - 1].Type != StationType.ChangeEnds)
                    {
                        Game.CurrentScore.Maximum += Game.ScoreValueStationArrival;
                    }
                }
            }
            if (Game.CurrentScore.Maximum <= 0)
            {
                Game.CurrentScore.Maximum = Game.ScoreValueStationArrival;
            }
            // signals
            if (Game.Sections.Length > 0)
            {
                Game.UpdateSection(Game.Sections.Length - 1);
            }
            // move train in position
            for (int i = 0; i < TrainManager.Trains.Length; i++)
            {
                double p;
                if (i == TrainManager.PlayerTrain.TrainIndex)
                {
                    p = PlayerFirstStationPosition;
                }
                else if (TrainManager.Trains[i].State == TrainManager.TrainState.Bogus)
                {
                    p = Game.BogusPretrainInstructions[0].TrackPosition;
                    TrainManager.Trains[i].AI = new Game.BogusPretrainAI(TrainManager.Trains[i]);
                }
                else
                {
                    p = OtherFirstStationPosition;
                }
                for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++)
                {
                    TrainManager.Trains[i].Cars[j].Move(p, 0.01);
                }
            }
            // timetable
            if (Timetable.DefaultTimetableDescription.Length == 0)
            {
                Timetable.DefaultTimetableDescription = Game.LogTrainName;
            }

            // initialize camera
            if (World.CameraRestriction == World.CameraRestrictionMode.NotAvailable)
            {
                World.CameraMode = World.CameraViewMode.InteriorLookAhead;
            }
            //Place the initial camera in the driver car
            TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].UpdateCamera();
            World.CameraTrackFollower.Update(-1.0, true, false);
            ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + World.CameraCurrentAlignment.Position.Z);
            World.CameraSavedExterior = new World.CameraAlignment(new OpenBveApi.Math.Vector3(-2.5, 1.5, -15.0), 0.3, -0.2, 0.0, PlayerFirstStationPosition, 1.0);
            World.CameraSavedTrack    = new World.CameraAlignment(new OpenBveApi.Math.Vector3(-3.0, 2.5, 0.0), 0.3, 0.0, 0.0, TrainManager.PlayerTrain.Cars[0].FrontAxle.Follower.TrackPosition - 10.0, 1.0);
            // signalling sections
            for (int i = 0; i < TrainManager.Trains.Length; i++)
            {
                int s = TrainManager.Trains[i].CurrentSectionIndex;
                Game.Sections[s].Enter(TrainManager.Trains[i]);
            }
            if (Game.Sections.Length > 0)
            {
                Game.UpdateSection(Game.Sections.Length - 1);
            }
            // fast-forward until start time
            {
                Game.MinimalisticSimulation = true;
                const double w = 0.25;
                double       u = Game.StartupTime - Game.SecondsSinceMidnight;
                if (u > 0)
                {
                    while (true)
                    {
                        double v = u < w ? u : w; u -= v;
                        Game.SecondsSinceMidnight += v;
                        TrainManager.UpdateTrains(v);
                        if (u <= 0.0)
                        {
                            break;
                        }
                        TotalTimeElapsedForSectionUpdate += v;
                        if (TotalTimeElapsedForSectionUpdate >= 1.0)
                        {
                            if (Game.Sections.Length > 0)
                            {
                                Game.UpdateSection(Game.Sections.Length - 1);
                            }
                            TotalTimeElapsedForSectionUpdate = 0.0;
                        }
                    }
                }
                Game.MinimalisticSimulation = false;
            }
            // animated objects
            ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
            TrainManager.UpdateTrainObjects(0.0, true);
            //HACK: This function calls a single update on all objects attached to the player's train
            //      but ignores any specified damping so that all needles etc. are in the correct place
            //      for the first frame, rather than spinning wildly to get to the starting point.
            TrainManager.PlayerTrain.UpdateCabObjects();
            // timetable
            if (TrainManager.PlayerTrain.Station >= 0)
            {
                Timetable.UpdateCustomTimetable(Game.Stations[TrainManager.PlayerTrain.Station].TimetableDaytimeTexture, Game.Stations[TrainManager.PlayerTrain.Station].TimetableNighttimeTexture);
                if (Timetable.CustomObjectsUsed != 0 & Timetable.CustomTimetableAvailable && Interface.CurrentOptions.TimeTableStyle != Interface.TimeTableMode.AutoGenerated && Interface.CurrentOptions.TimeTableStyle != Interface.TimeTableMode.None)
                {
                    Timetable.CurrentTimetable = Timetable.TimetableState.Custom;
                }
            }
            //Create AI driver for the player train if specified via the commmand line
            if (Game.InitialAIDriver == true)
            {
                TrainManager.PlayerTrain.AI = new Game.SimpleHumanDriverAI(TrainManager.PlayerTrain);
                if (TrainManager.PlayerTrain.Plugin != null && !TrainManager.PlayerTrain.Plugin.SupportsAI)
                {
                    Game.AddMessage(Interface.GetInterfaceString("notification_aiunable"), MessageManager.MessageDependency.None, Interface.GameMode.Expert,
                                    OpenBveApi.Colors.MessageColor.White, Game.SecondsSinceMidnight + 10.0, null);
                }
            }

            // warnings / errors
            if (Interface.MessageCount != 0)
            {
                int filesNotFound = 0;
                int errors        = 0;
                int warnings      = 0;
                for (int i = 0; i < Interface.MessageCount; i++)
                {
                    if (Interface.Messages[i].FileNotFound)
                    {
                        filesNotFound++;
                    }
                    else if (Interface.Messages[i].Type == Interface.MessageType.Error)
                    {
                        errors++;
                    }
                    else if (Interface.Messages[i].Type == Interface.MessageType.Warning)
                    {
                        warnings++;
                    }
                }
                string NotFound = null;
                string Messages = null;
                if (filesNotFound != 0)
                {
                    NotFound = filesNotFound.ToString() + " file(s) not found";
                    Game.AddMessage(NotFound, MessageManager.MessageDependency.None, Interface.GameMode.Expert, MessageColor.Magenta, Game.SecondsSinceMidnight + 10.0, null);
                }
                if (errors != 0 & warnings != 0)
                {
                    Messages = errors.ToString() + " error(s), " + warnings.ToString() + " warning(s)";
                    Game.AddMessage(Messages, MessageManager.MessageDependency.None, Interface.GameMode.Expert, MessageColor.Magenta, Game.SecondsSinceMidnight + 10.0, null);
                }
                else if (errors != 0)
                {
                    Messages = errors.ToString() + " error(s)";
                    Game.AddMessage(Messages, MessageManager.MessageDependency.None, Interface.GameMode.Expert, MessageColor.Magenta, Game.SecondsSinceMidnight + 10.0, null);
                }
                else
                {
                    Messages = warnings.ToString() + " warning(s)";
                    Game.AddMessage(Messages, MessageManager.MessageDependency.None, Interface.GameMode.Expert, MessageColor.Magenta, Game.SecondsSinceMidnight + 10.0, null);
                }
                Game.RouteInformation.FilesNotFound     = NotFound;
                Game.RouteInformation.ErrorsAndWarnings = Messages;
                //Print the plugin error encountered (If any) for 10s
                //This must be done after the simulation has init, as otherwise the timeout doesn't work
                if (Loading.PluginError != null)
                {
                    Game.AddMessage(Loading.PluginError, MessageManager.MessageDependency.None, Interface.GameMode.Expert, OpenBveApi.Colors.MessageColor.Red, Game.SecondsSinceMidnight + 5.0, null);
                    Game.AddMessage(Interface.GetInterfaceString("errors_plugin_failure2"), MessageManager.MessageDependency.None, Interface.GameMode.Expert, OpenBveApi.Colors.MessageColor.Red, Game.SecondsSinceMidnight + 5.0, null);
                }
            }
            loadComplete          = true;
            RenderRealTimeElapsed = 0.0;
            RenderTimeElapsed     = 0.0;
            World.InitializeCameraRestriction();
            Loading.SimulationSetup = true;
            switch (Game.InitialViewpoint)
            {
            case 1:
                //Switch camera to exterior
                MainLoop.SaveCameraSettings();
                World.CameraMode = World.CameraViewMode.Exterior;
                MainLoop.RestoreCameraSettings();
                for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
                {
                    TrainManager.PlayerTrain.Cars[j].ChangeCarSection(TrainManager.CarSectionType.Exterior);
                }
                //Make bogies visible
                for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
                {
                    TrainManager.PlayerTrain.Cars[j].FrontBogie.ChangeSection(0);
                    TrainManager.PlayerTrain.Cars[j].RearBogie.ChangeSection(0);
                }
                World.CameraAlignmentDirection = new World.CameraAlignment();
                World.CameraAlignmentSpeed     = new World.CameraAlignment();
                MainLoop.UpdateViewport(MainLoop.ViewPortChangeMode.NoChange);
                World.UpdateAbsoluteCamera(0.0);
                World.UpdateViewingDistances();
                break;

            case 2:
                //Switch camera to track
                MainLoop.SaveCameraSettings();
                World.CameraMode = World.CameraViewMode.Track;
                MainLoop.RestoreCameraSettings();
                for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
                {
                    TrainManager.PlayerTrain.Cars[j].ChangeCarSection(TrainManager.CarSectionType.Exterior);
                }

                for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
                {
                    TrainManager.PlayerTrain.Cars[j].FrontBogie.ChangeSection(0);
                    TrainManager.PlayerTrain.Cars[j].RearBogie.ChangeSection(0);
                }

                World.CameraAlignmentDirection = new World.CameraAlignment();
                World.CameraAlignmentSpeed     = new World.CameraAlignment();
                MainLoop.UpdateViewport(MainLoop.ViewPortChangeMode.NoChange);
                World.UpdateAbsoluteCamera(0.0);
                World.UpdateViewingDistances();
                break;

            case 3:
                //Switch camera to flyby
                MainLoop.SaveCameraSettings();
                World.CameraMode = World.CameraViewMode.FlyBy;
                MainLoop.RestoreCameraSettings();
                for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
                {
                    TrainManager.PlayerTrain.Cars[j].ChangeCarSection(TrainManager.CarSectionType.Exterior);
                }

                for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
                {
                    TrainManager.PlayerTrain.Cars[j].FrontBogie.ChangeSection(0);
                    TrainManager.PlayerTrain.Cars[j].RearBogie.ChangeSection(0);
                }

                World.CameraAlignmentDirection = new World.CameraAlignment();
                World.CameraAlignmentSpeed     = new World.CameraAlignment();
                MainLoop.UpdateViewport(MainLoop.ViewPortChangeMode.NoChange);
                World.UpdateAbsoluteCamera(0.0);
                World.UpdateViewingDistances();
                break;

            case 4:
                //Switch camera to flyby
                MainLoop.SaveCameraSettings();
                World.CameraMode = World.CameraViewMode.FlyByZooming;
                MainLoop.RestoreCameraSettings();
                for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
                {
                    TrainManager.PlayerTrain.Cars[j].ChangeCarSection(TrainManager.CarSectionType.Exterior);
                }

                for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
                {
                    TrainManager.PlayerTrain.Cars[j].FrontBogie.ChangeSection(0);
                    TrainManager.PlayerTrain.Cars[j].RearBogie.ChangeSection(0);
                }

                World.CameraAlignmentDirection = new World.CameraAlignment();
                World.CameraAlignmentSpeed     = new World.CameraAlignment();
                MainLoop.UpdateViewport(MainLoop.ViewPortChangeMode.NoChange);
                World.UpdateAbsoluteCamera(0.0);
                World.UpdateViewingDistances();
                break;
            }
        }
Exemplo n.º 17
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            Program.MouseMovement();
            double   timeElapsed = CPreciseTimer.GetElapsedTime();
            DateTime time        = DateTime.Now;

            Game.SecondsSinceMidnight = (double)(3600 * time.Hour + 60 * time.Minute + time.Second) + 0.001 * (double)time.Millisecond;
            lock (Program.LockObj)
            {
                ObjectManager.UpdateAnimatedWorldObjects(timeElapsed, false);
            }
            if (Program.ReducedMode)
            {
                System.Threading.Thread.Sleep(125);
            }
            else
            {
                System.Threading.Thread.Sleep(1);
            }
            bool updatelight = false;
            bool keep        = false;

            // rotate x
            if (Program.RotateX == 0)
            {
                double d = (1.0 + Math.Abs(RotateXSpeed)) * timeElapsed;
                if (RotateXSpeed >= -d & RotateXSpeed <= d)
                {
                    RotateXSpeed = 0.0;
                }
                else
                {
                    RotateXSpeed -= (double)Math.Sign(RotateXSpeed) * d;
                }
            }
            else
            {
                double d = (1.0 + 1.0 - 1.0 / (1.0 + RotateXSpeed * RotateXSpeed)) * timeElapsed;
                double m = 1.0;
                RotateXSpeed += (double)Program.RotateX * d;
                if (RotateXSpeed < -m)
                {
                    RotateXSpeed = -m;
                }
                else if (RotateXSpeed > m)
                {
                    RotateXSpeed = m;
                }
            }
            if (RotateXSpeed != 0.0)
            {
                double cosa = Math.Cos(RotateXSpeed * timeElapsed);
                double sina = Math.Sin(RotateXSpeed * timeElapsed);
                Program.Renderer.Camera.AbsoluteDirection.Rotate(Vector3.Down, cosa, sina);
                Program.Renderer.Camera.AbsoluteUp.Rotate(Vector3.Down, cosa, sina);
                Program.Renderer.Camera.AbsoluteSide.Rotate(Vector3.Down, cosa, sina);
                keep = true;
            }
            // rotate y
            if (Program.RotateY == 0)
            {
                double d = (1.0 + Math.Abs(RotateYSpeed)) * timeElapsed;
                if (RotateYSpeed >= -d & RotateYSpeed <= d)
                {
                    RotateYSpeed = 0.0;
                }
                else
                {
                    RotateYSpeed -= (double)Math.Sign(RotateYSpeed) * d;
                }
            }
            else
            {
                double d = (1.0 + 1.0 - 1.0 / (1.0 + RotateYSpeed * RotateYSpeed)) * timeElapsed;
                double m = 1.0;
                RotateYSpeed += (double)Program.RotateY * d;
                if (RotateYSpeed < -m)
                {
                    RotateYSpeed = -m;
                }
                else if (RotateYSpeed > m)
                {
                    RotateYSpeed = m;
                }
            }
            if (RotateYSpeed != 0.0)
            {
                double cosa = Math.Cos(RotateYSpeed * timeElapsed);
                double sina = Math.Sin(RotateYSpeed * timeElapsed);
                Program.Renderer.Camera.AbsoluteDirection.Rotate(Program.Renderer.Camera.AbsoluteSide, cosa, sina);
                Program.Renderer.Camera.AbsoluteUp.Rotate(Program.Renderer.Camera.AbsoluteSide, cosa, sina);
                keep = true;
            }
            // move x
            if (Program.MoveX == 0)
            {
                double d = (2.5 + Math.Abs(MoveXSpeed)) * timeElapsed;
                if (MoveXSpeed >= -d & MoveXSpeed <= d)
                {
                    MoveXSpeed = 0.0;
                }
                else
                {
                    MoveXSpeed -= (double)Math.Sign(MoveXSpeed) * d;
                }
            }
            else
            {
                double d = (5.0 + 10.0 - 10.0 / (1.0 + MoveXSpeed * MoveXSpeed)) * timeElapsed;
                double m = 25.0;
                MoveXSpeed += (double)Program.MoveX * d;
                if (MoveXSpeed < -m)
                {
                    MoveXSpeed = -m;
                }
                else if (MoveXSpeed > m)
                {
                    MoveXSpeed = m;
                }
            }
            if (MoveXSpeed != 0.0)
            {
                Program.Renderer.Camera.AbsolutePosition += MoveXSpeed * timeElapsed * Program.Renderer.Camera.AbsoluteSide;
                keep = true;
            }
            // move y
            if (Program.MoveY == 0)
            {
                double d = (2.5 + Math.Abs(MoveYSpeed)) * timeElapsed;
                if (MoveYSpeed >= -d & MoveYSpeed <= d)
                {
                    MoveYSpeed = 0.0;
                }
                else
                {
                    MoveYSpeed -= (double)Math.Sign(MoveYSpeed) * d;
                }
            }
            else
            {
                double d = (5.0 + 10.0 - 10.0 / (1.0 + MoveYSpeed * MoveYSpeed)) * timeElapsed;
                double m = 25.0;
                MoveYSpeed += (double)Program.MoveY * d;
                if (MoveYSpeed < -m)
                {
                    MoveYSpeed = -m;
                }
                else if (MoveYSpeed > m)
                {
                    MoveYSpeed = m;
                }
            }
            if (MoveYSpeed != 0.0)
            {
                Program.Renderer.Camera.AbsolutePosition += MoveYSpeed * timeElapsed * Program.Renderer.Camera.AbsoluteUp;
                keep = true;
            }
            // move z
            if (Program.MoveZ == 0)
            {
                double d = (2.5 + Math.Abs(MoveZSpeed)) * timeElapsed;
                if (MoveZSpeed >= -d & MoveZSpeed <= d)
                {
                    MoveZSpeed = 0.0;
                }
                else
                {
                    MoveZSpeed -= (double)Math.Sign(MoveZSpeed) * d;
                }
            }
            else
            {
                double d = (5.0 + 10.0 - 10.0 / (1.0 + MoveZSpeed * MoveZSpeed)) * timeElapsed;
                double m = 25.0;
                MoveZSpeed += (double)Program.MoveZ * d;
                if (MoveZSpeed < -m)
                {
                    MoveZSpeed = -m;
                }
                else if (MoveZSpeed > m)
                {
                    MoveZSpeed = m;
                }
            }
            if (MoveZSpeed != 0.0)
            {
                Program.Renderer.Camera.AbsolutePosition += MoveZSpeed * timeElapsed * Program.Renderer.Camera.AbsoluteDirection;

                keep = true;
            }
            // lighting
            if (Program.LightingRelative == -1)
            {
                Program.LightingRelative = (double)Program.LightingTarget;
                updatelight = true;
            }
            if (Program.LightingTarget == 0)
            {
                if (Program.LightingRelative != 0.0)
                {
                    Program.LightingRelative -= 0.5 * timeElapsed;
                    if (Program.LightingRelative < 0.0)
                    {
                        Program.LightingRelative = 0.0;
                    }
                    updatelight = true;
                    keep        = true;
                }
            }
            else
            {
                if (Program.LightingRelative != 1.0)
                {
                    Program.LightingRelative += 0.5 * timeElapsed;
                    if (Program.LightingRelative > 1.0)
                    {
                        Program.LightingRelative = 1.0;
                    }
                    updatelight = true;
                    keep        = true;
                }
            }
            // continue
            if (Program.ReducedMode)
            {
                ReducedModeEnteringTime = 3.0;
            }
            else
            {
                if (keep)
                {
                    ReducedModeEnteringTime = 3.0;
                }
                else if (ReducedModeEnteringTime <= 0)
                {
                    Program.ReducedMode = true;
                    Program.Renderer.Camera.AbsoluteSide.Y = 0.0;
                    Program.Renderer.Camera.AbsoluteSide.Normalize();
                    Program.Renderer.Camera.AbsoluteDirection.Normalize();
                    Program.Renderer.Camera.AbsoluteUp = Vector3.Cross(Program.Renderer.Camera.AbsoluteDirection, Program.Renderer.Camera.AbsoluteSide);
                }
                else
                {
                    ReducedModeEnteringTime -= timeElapsed;
                }
            }
            if (updatelight)
            {
                Program.Renderer.Lighting.OptionAmbientColor.R = (byte)Math.Round(32.0 + 128.0 * Program.LightingRelative * (2.0 - Program.LightingRelative));
                Program.Renderer.Lighting.OptionAmbientColor.G = (byte)Math.Round(32.0 + 128.0 * 0.5 * (Program.LightingRelative + Program.LightingRelative * (2.0 - Program.LightingRelative)));
                Program.Renderer.Lighting.OptionAmbientColor.B = (byte)Math.Round(32.0 + 128.0 * Program.LightingRelative);
                Program.Renderer.Lighting.OptionDiffuseColor.R = (byte)Math.Round(32.0 + 128.0 * Program.LightingRelative);
                Program.Renderer.Lighting.OptionDiffuseColor.G = (byte)Math.Round(32.0 + 128.0 * Program.LightingRelative);
                Program.Renderer.Lighting.OptionDiffuseColor.B = (byte)Math.Round(32.0 + 128.0 * Math.Sqrt(Program.LightingRelative));
            }
            Program.Renderer.Lighting.Initialize();
            Program.Renderer.RenderScene();
            SwapBuffers();
        }
Exemplo n.º 18
0
        internal static void Main(string[] args)
        {
            Interface.CurrentOptions.UseSound = true;
            Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 1000;
            Interface.CurrentOptions.ObjectOptimizationFullThreshold  = 250;
            // platform and mono
            int p = (int)Environment.OSVersion.Platform;

            if (p == 4 | p == 128)
            {
                // general Unix
                CurrentPlatform = Platform.Linux;
            }
            else if (p == 6)
            {
                // Mac
                CurrentPlatform = Platform.Mac;
            }
            else
            {
                // non-Unix
                CurrentPlatform = Platform.Windows;
            }
            CurrentlyRunOnMono = Type.GetType("Mono.Runtime") != null;
            // file system
            FileSystem = FileSystem.FromCommandLineArgs(args);
            FileSystem.CreateFileSystem();
            SetPackageLookupDirectories();
            // command line arguments
            bool[] SkipArgs = new bool[args.Length];
            if (args.Length != 0)
            {
                string File = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe");
                if (System.IO.File.Exists(File))
                {
                    int Skips = 0;
                    System.Text.StringBuilder NewArgs = new System.Text.StringBuilder();
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (System.IO.File.Exists(args[i]))
                        {
                            if (System.IO.Path.GetExtension(args[i]).Equals(".csv", StringComparison.OrdinalIgnoreCase))
                            {
                                string Text = System.IO.File.ReadAllText(args[i], System.Text.Encoding.UTF8);
                                if (Text.Length == 0 || Text.IndexOf("CreateMeshBuilder", StringComparison.OrdinalIgnoreCase) >= 0)
                                {
                                    if (NewArgs.Length != 0)
                                    {
                                        NewArgs.Append(" ");
                                    }
                                    NewArgs.Append("\"" + args[i] + "\"");
                                    SkipArgs[i] = true;
                                    Skips++;
                                }
                            }
                        }
                        else
                        {
                            SkipArgs[i] = true;
                            Skips++;
                        }
                    }
                    if (NewArgs.Length != 0)
                    {
                        System.Diagnostics.Process.Start(File, NewArgs.ToString());
                    }
                    if (Skips == args.Length)
                    {
                        return;
                    }
                }
            }
            // application
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) != 0)
            {
                MessageBox.Show("SDL failed to initialize the video subsystem.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            // initialize sdl window
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 16);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 8);
            SDL.SDL_ShowCursor(1);

            // initialize camera
            ResetCamera();
            World.BackgroundImageDistance = 600.0;
            World.ForwardViewingDistance  = 600.0;
            World.BackwardViewingDistance = 0.0;
            World.ExtraViewingDistance    = 50.0;
            // create window
            Renderer.ScreenWidth  = 960;
            Renderer.ScreenHeight = 600;
            //int Bits = 32;
            //IntPtr video = Sdl.SDL_SetVideoMode(Renderer.ScreenWidth, Renderer.ScreenHeight, Bits, Sdl.SDL_OPENGL | Sdl.SDL_DOUBLEBUF);
            Window = SDL.SDL_CreateWindow(Application.ProductName,
                                          SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED,
                                          Renderer.ScreenWidth, Renderer.ScreenHeight,
                                          SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE);
            if (Window == IntPtr.Zero)
            {
                MessageBox.Show("SDL failed to create the window.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            // icon
            string iconFile = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder(), "icon.png");

            if (System.IO.File.Exists(iconFile))
            {
                iconBmp  = new Bitmap(iconFile);                // load file
                iconData = iconBmp.LockBits(new Rectangle(0, 0, iconBmp.Width, iconBmp.Height),
                                            System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                            System.Drawing.Imaging.PixelFormat.Format32bppArgb);            // lock data
                iconSurface = SDL.SDL_CreateRGBSurfaceFrom(iconData.Scan0, iconBmp.Width, iconBmp.Height, 32, iconData.Stride,
                                                           0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); // upload to sdl
                SDL.SDL_SetWindowIcon(Window, iconSurface);                                                 // use icon
            }
            GLContext = SDL.SDL_GL_CreateContext(Window);
            tkContext = new GraphicsContext(new ContextHandle(GLContext),
                                            SDL.SDL_GL_GetProcAddress,
                                            SDLGetCurrentContext);
            // anisotropic filtering
            string[] extensions = GL.GetString(StringName.Extensions).Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Interface.CurrentOptions.AnisotropicFilteringMaximum = 0;
            for (int i = 0; i < extensions.Length; i++)
            {
                if (extensions[i] == "GL_EXT_texture_filter_anisotropic")
                {
                    float n;
                    GL.GetFloat((GetPName)ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt, out n);
                    Interface.CurrentOptions.AnisotropicFilteringMaximum = (int)Math.Round((double)n);
                    break;
                }
            }
            if (Interface.CurrentOptions.AnisotropicFilteringMaximum <= 0)
            {
                Interface.CurrentOptions.AnisotropicFilteringMaximum = 0;
                Interface.CurrentOptions.AnisotropicFilteringLevel   = 0;
                Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.AnisotropicFiltering;
            }
            else
            {
                Interface.CurrentOptions.AnisotropicFilteringLevel = Interface.CurrentOptions.AnisotropicFilteringMaximum;
                Interface.CurrentOptions.Interpolation             = TextureManager.InterpolationMode.TrilinearMipmapped;
            }
            Interface.CurrentOptions.TransparencyMode = Renderer.TransparencyMode.Sharp;
            // module initialization
            Renderer.Initialize();
            Renderer.InitializeLighting();
            SoundManager.Initialize();
            GL.ClearColor(0.75f, 0.75f, 0.75f, 1.0f);
            SwapBuffers();
            Fonts.Initialize();
            UpdateViewport();
            // loop
            bool processCommandLineArgs = true;

            timer = new System.Diagnostics.Stopwatch();
            timer.Start();
            while (!Quit)
            {
                ProcessEvents();
                int    a           = (int)timer.ElapsedMilliseconds;
                double TimeElapsed = 0.001 * (double)(a - LastTicks);
                if (CpuReducedMode)
                {
                    System.Threading.Thread.Sleep(250);
                }
                else
                {
                    System.Threading.Thread.Sleep(1);
                    if (ReducedModeEnteringTime == 0)
                    {
                        ReducedModeEnteringTime = a + 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 = a + 2500;
                    }
                    else if (a > ReducedModeEnteringTime & CpuAutomaticMode)
                    {
                        ReducedModeEnteringTime = 0;
                        CpuReducedMode          = true;
                    }
                }
                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);
                SoundManager.Update(TimeElapsed);
                Renderer.RenderScene(TimeElapsed);
                SwapBuffers();
                LastTicks = a;
                // command line arguments
                if (processCommandLineArgs)
                {
                    processCommandLineArgs = false;
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (!SkipArgs[i] && System.IO.File.Exists(args[i]))
                        {
                            CurrentlyLoading = true;
                            Renderer.RenderScene(0.0);
                            SwapBuffers();
                            CurrentRoute = args[i];
                            LoadRoute();
                            CurrentlyLoading = false;
                            UpdateCaption();
                            break;
                        }
                    }
                }
            }
            // quit
            TextureManager.UnuseAllTextures();
            SoundManager.Deinitialize();
            if (iconSurface != IntPtr.Zero)
            {
                SDL.SDL_FreeSurface(iconSurface);                 // free surface
            }
            if (iconBmp != null && iconData != null)
            {
                iconBmp.UnlockBits(iconData);                 // free pixels
                iconBmp.Dispose();
            }
            SDL.SDL_GL_DeleteContext(GLContext);
            SDL.SDL_DestroyWindow(Window);
            SDL.SDL_Quit();
        }
Exemplo n.º 19
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;
                }
            }
        }
Exemplo n.º 20
0
        private void button1_Click(object sender, EventArgs e)
        {
            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 = OpenBveApi.Graphics.InterpolationMode.NearestNeighbor;
                break;

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

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

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

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

            case 5:
                Interface.CurrentOptions.Interpolation = OpenBveApi.Graphics.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 = TransparencyMode.Performance;
                break;

            default:
                Interface.CurrentOptions.TransparencyMode = TransparencyMode.Quality;
                break;
            }
            //Set width and height
            if (Screen.Width != width.Value || Screen.Height != height.Value)
            {
                if (width.Value >= 300)
                {
                    Screen.Width = (int)width.Value;
                    Program.currentGameWindow.Width = (int)width.Value;
                }
                if (height.Value >= 300)
                {
                    Screen.Height = (int)height.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)
            {
                Program.ReducedMode      = false;
                Program.LightingRelative = -1.0;
                Game.Reset();
                LibRender.TextureManager.UnloadAllTextures();
                Interface.ClearMessages();
                for (int i = 0; i < Program.Files.Length; i++)
                {
#if !DEBUG
                    try {
#endif
                    UnifiedObject o = ObjectManager.LoadObject(Program.Files[i], System.Text.Encoding.UTF8, false, false, false);
                    ObjectManager.CreateObject(o, Vector3.Zero,
                                               new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0,
                                               0.0, 25.0, 0.0);
#if !DEBUG
                }
                catch (Exception ex) {
                    Interface.AddMessage(MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + Program.Files[i] + ".");
                }
#endif
                }
                ObjectManager.InitializeVisibility();
                ObjectManager.UpdateVisibility(0.0, true);
                ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
            }
            Renderer.TransparentColorDepthSorting     = Interface.CurrentOptions.TransparencyMode == TransparencyMode.Quality & Interface.CurrentOptions.Interpolation != OpenBveApi.Graphics.InterpolationMode.NearestNeighbor & Interface.CurrentOptions.Interpolation != OpenBveApi.Graphics.InterpolationMode.Bilinear;
            Interface.CurrentOptions.CurrentXParser   = (XParsers)comboBoxNewXParser.SelectedIndex;
            Interface.CurrentOptions.CurrentObjParser = (ObjParsers)comboBoxNewObjParser.SelectedIndex;
            for (int i = 0; i < Plugins.LoadedPlugins.Length; i++)
            {
                if (Plugins.LoadedPlugins[i].Object != null)
                {
                    Plugins.LoadedPlugins[i].Object.SetObjectParser(Interface.CurrentOptions.CurrentXParser);
                    Plugins.LoadedPlugins[i].Object.SetObjectParser(Interface.CurrentOptions.CurrentObjParser);
                }
            }
            Options.SaveOptions();
            this.Close();
        }
Exemplo n.º 21
0
        internal static void Main(string[] args)
        {
            // platform and mono
            int p = (int)Environment.OSVersion.Platform;

            if (p == 4 | p == 128)
            {
                // general Unix
                CurrentPlatform = Platform.Linux;
            }
            else if (p == 6)
            {
                // Mac
                CurrentPlatform = Platform.Mac;
            }
            else
            {
                // non-Unix
                CurrentPlatform = Platform.Windows;
            }
            CurrentlyRunOnMono = Type.GetType("Mono.Runtime") != null;
            // file system
            FileSystem = FileSystem.FromCommandLineArgs(args);
            FileSystem.CreateFileSystem();
            SetPackageLookupDirectories();
            // command line arguments
            bool[] SkipArgs = new bool[args.Length];
            if (args.Length != 0)
            {
                string File = System.IO.Path.Combine(Application.StartupPath, "RouteViewer.exe");
                if (System.IO.File.Exists(File))
                {
                    int Skips = 0;
                    System.Text.StringBuilder NewArgs = new System.Text.StringBuilder();
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (System.IO.File.Exists(args[i]))
                        {
                            if (System.IO.Path.GetExtension(args[i]).Equals(".csv", StringComparison.OrdinalIgnoreCase))
                            {
                                string Text = System.IO.File.ReadAllText(args[i], System.Text.Encoding.UTF8);
                                if (Text.Length != -1 && Text.IndexOf("CreateMeshBuilder", StringComparison.OrdinalIgnoreCase) == -1)
                                {
                                    if (NewArgs.Length != 0)
                                    {
                                        NewArgs.Append(" ");
                                    }
                                    NewArgs.Append("\"" + args[i] + "\"");
                                    SkipArgs[i] = true;
                                    Skips++;
                                }
                            }
                        }
                        else
                        {
                            SkipArgs[i] = true;
                            Skips++;
                        }
                    }
                    if (NewArgs.Length != 0)
                    {
                        System.Diagnostics.Process.Start(File, NewArgs.ToString());
                    }
                    if (Skips == args.Length)
                    {
                        return;
                    }
                }
            }
            // application
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) != 0)
            {
                MessageBox.Show("SDL failed to initialize the video subsystem.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 1000;
            Interface.CurrentOptions.ObjectOptimizationFullThreshold  = 250;
            // initialize sdl window
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 16);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 8);
            SDL.SDL_ShowCursor(1);
            // initialize camera
            ResetCamera();
            // create window
            Renderer.ScreenWidth  = 960;
            Renderer.ScreenHeight = 600;
            // int Bits = 32;
            //Sdl.SDL_SetVideoMode(Renderer.ScreenWidth, Renderer.ScreenHeight, Bits, Sdl.SDL_OPENGL | Sdl.SDL_DOUBLEBUF);
            SDLWindow = SDL.SDL_CreateWindow(Application.ProductName,
                                             SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED,
                                             Renderer.ScreenWidth, Renderer.ScreenHeight,
                                             SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE);
            if (SDLWindow != IntPtr.Zero)
            {
                // create window
                string File = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder(), "icon.png");
                if (System.IO.File.Exists(File))
                {
                    // set up icon
                    iconBmp  = new Bitmap(File);                    // load file
                    iconData = iconBmp.LockBits(new Rectangle(0, 0, iconBmp.Width, iconBmp.Height),
                                                System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                                System.Drawing.Imaging.PixelFormat.Format32bppArgb);            // lock data
                    iconSurface = SDL.SDL_CreateRGBSurfaceFrom(iconData.Scan0, iconBmp.Width, iconBmp.Height, 32, iconData.Stride,
                                                               0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); // upload to sdl
                    SDL.SDL_SetWindowIcon(SDLWindow, iconSurface);                                              // use icon
                    // free is on the end of the program

                    /*
                     * IntPtr bitmap = SDL.SDL_LoadBMP(File);
                     * if (bitmap != IntPtr.Zero) {
                     *      SDL.SDL_Surface Surface = (SDL.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(bitmap, typeof(SDL.SDL_Surface));
                     *      uint ColorKey = SDL.SDL_MapRGB(Surface.format, 0, 0, 255);
                     *      SDL.SDL_SetColorKey(bitmap, 1, ColorKey);
                     *      SDL.SDL_SetWindowIcon(SDLWindow,bitmap);
                     * }
                     */
                }
                GLContext = SDL.SDL_GL_CreateContext(SDLWindow);
                tkContext = new GraphicsContext(new ContextHandle(GLContext),
                                                SDL.SDL_GL_GetProcAddress,
                                                () => new ContextHandle(SDL.SDL_GL_GetCurrentContext()));
                // anisotropic filtering
                string[] extensions = GL.GetString(StringName.Extensions).Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                Interface.CurrentOptions.AnisotropicFilteringMaximum = 0;
                for (int i = 0; i < extensions.Length; i++)
                {
                    if (extensions[i] == "GL_EXT_texture_filter_anisotropic")
                    {
                        float n;
                        GL.GetFloat((GetPName)ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt, out n);
                        Interface.CurrentOptions.AnisotropicFilteringMaximum = (int)Math.Round((double)n);
                        break;
                    }
                }
                if (Interface.CurrentOptions.AnisotropicFilteringMaximum <= 0)
                {
                    Interface.CurrentOptions.AnisotropicFilteringMaximum = 0;
                    Interface.CurrentOptions.AnisotropicFilteringLevel   = 0;
                    Interface.CurrentOptions.Interpolation = TextureManager.InterpolationMode.AnisotropicFiltering;
                }
                else
                {
                    Interface.CurrentOptions.AnisotropicFilteringLevel = Interface.CurrentOptions.AnisotropicFilteringMaximum;
                    Interface.CurrentOptions.Interpolation             = TextureManager.InterpolationMode.TrilinearMipmapped;
                }
                // module initialization
                Renderer.Initialize();
                Renderer.InitializeLighting();
                SDL.SDL_GL_SwapWindow(SDLWindow);
                Fonts.Initialize();
                UpdateViewport();
                // command line arguments
                for (int i = 0; i < args.Length; i++)
                {
                    if (!SkipArgs[i] && System.IO.File.Exists(args[i]))
                    {
                        try {
                            ObjectManager.UnifiedObject o = ObjectManager.LoadObject(args[i], System.Text.Encoding.UTF8, ObjectManager.ObjectLoadMode.Normal, false, false, false);
                            ObjectManager.CreateObject(o, new World.Vector3D(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0, 0.0);
                        } catch (Exception ex) {
                            Interface.AddMessage(Interface.MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + args[i] + ".");
                        }
                        Array.Resize <string>(ref Files, Files.Length + 1);
                        Files[Files.Length - 1] = args[i];
                    }
                }
                ObjectManager.InitializeVisibility();
                ObjectManager.FinishCreatingObjects();
                ObjectManager.UpdateVisibility(0.0, true);
                ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
                UpdateCaption();
                Stopwatch timer = new Stopwatch();
                timer.Start();
                LastTicks = timer.ElapsedMilliseconds;
                // loop
                while (!Quit)
                {
                    long   ticks       = timer.ElapsedMilliseconds;
                    double timeElapsed = 0.001 * (double)(ticks - LastTicks);
                    if (timeElapsed < 0.0001)
                    {
                        timeElapsed = 0.0001;
                    }
                    LastTicks = ticks;
                    DateTime time = DateTime.Now;
                    Game.SecondsSinceMidnight = (double)(3600 * time.Hour + 60 * time.Minute + time.Second) + 0.001 * (double)time.Millisecond;
                    ObjectManager.UpdateAnimatedWorldObjects(timeElapsed, false);
                    ProcessEvents();
                    if (ReducedMode)
                    {
                        System.Threading.Thread.Sleep(125);
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(1);
                    }
                    bool updatelight = false;
                    bool keep        = false;
                    // rotate x
                    if (RotateX == 0)
                    {
                        double d = (1.0 + Math.Abs(RotateXSpeed)) * timeElapsed;
                        if (RotateXSpeed >= -d & RotateXSpeed <= d)
                        {
                            RotateXSpeed = 0.0;
                        }
                        else
                        {
                            RotateXSpeed -= (double)Math.Sign(RotateXSpeed) * d;
                        }
                    }
                    else
                    {
                        double d = (1.0 + 1.0 - 1.0 / (1.0 + RotateXSpeed * RotateXSpeed)) * timeElapsed;
                        double m = 1.0;
                        RotateXSpeed += (double)RotateX * d;
                        if (RotateXSpeed < -m)
                        {
                            RotateXSpeed = -m;
                        }
                        else if (RotateXSpeed > m)
                        {
                            RotateXSpeed = m;
                        }
                    }
                    if (RotateXSpeed != 0.0)
                    {
                        double cosa = Math.Cos(RotateXSpeed * timeElapsed);
                        double sina = Math.Sin(RotateXSpeed * timeElapsed);
                        World.Rotate(ref World.AbsoluteCameraDirection.X, ref World.AbsoluteCameraDirection.Y, ref World.AbsoluteCameraDirection.Z, 0.0, 1.0, 0.0, cosa, sina);
                        World.Rotate(ref World.AbsoluteCameraUp.X, ref World.AbsoluteCameraUp.Y, ref World.AbsoluteCameraUp.Z, 0.0, 1.0, 0.0, cosa, sina);
                        World.Rotate(ref World.AbsoluteCameraSide.X, ref World.AbsoluteCameraSide.Y, ref World.AbsoluteCameraSide.Z, 0.0, 1.0, 0.0, cosa, sina);
                        keep = true;
                    }
                    // rotate y
                    if (RotateY == 0)
                    {
                        double d = (1.0 + Math.Abs(RotateYSpeed)) * timeElapsed;
                        if (RotateYSpeed >= -d & RotateYSpeed <= d)
                        {
                            RotateYSpeed = 0.0;
                        }
                        else
                        {
                            RotateYSpeed -= (double)Math.Sign(RotateYSpeed) * d;
                        }
                    }
                    else
                    {
                        double d = (1.0 + 1.0 - 1.0 / (1.0 + RotateYSpeed * RotateYSpeed)) * timeElapsed;
                        double m = 1.0;
                        RotateYSpeed += (double)RotateY * d;
                        if (RotateYSpeed < -m)
                        {
                            RotateYSpeed = -m;
                        }
                        else if (RotateYSpeed > m)
                        {
                            RotateYSpeed = m;
                        }
                    }
                    if (RotateYSpeed != 0.0)
                    {
                        double cosa = Math.Cos(RotateYSpeed * timeElapsed);
                        double sina = Math.Sin(RotateYSpeed * timeElapsed);
                        World.Rotate(ref World.AbsoluteCameraDirection.X, ref World.AbsoluteCameraDirection.Y, ref World.AbsoluteCameraDirection.Z, World.AbsoluteCameraSide.X, World.AbsoluteCameraSide.Y, World.AbsoluteCameraSide.Z, cosa, sina);
                        World.Rotate(ref World.AbsoluteCameraUp.X, ref World.AbsoluteCameraUp.Y, ref World.AbsoluteCameraUp.Z, World.AbsoluteCameraSide.X, World.AbsoluteCameraSide.Y, World.AbsoluteCameraSide.Z, cosa, sina);
                        keep = true;
                    }
                    // move x
                    if (MoveX == 0)
                    {
                        double d = (2.5 + Math.Abs(MoveXSpeed)) * timeElapsed;
                        if (MoveXSpeed >= -d & MoveXSpeed <= d)
                        {
                            MoveXSpeed = 0.0;
                        }
                        else
                        {
                            MoveXSpeed -= (double)Math.Sign(MoveXSpeed) * d;
                        }
                    }
                    else
                    {
                        double d = (5.0 + 10.0 - 10.0 / (1.0 + MoveXSpeed * MoveXSpeed)) * timeElapsed;
                        double m = 25.0;
                        MoveXSpeed += (double)MoveX * d;
                        if (MoveXSpeed < -m)
                        {
                            MoveXSpeed = -m;
                        }
                        else if (MoveXSpeed > m)
                        {
                            MoveXSpeed = m;
                        }
                    }
                    if (MoveXSpeed != 0.0)
                    {
                        World.AbsoluteCameraPosition.X += MoveXSpeed * timeElapsed * World.AbsoluteCameraSide.X;
                        World.AbsoluteCameraPosition.Y += MoveXSpeed * timeElapsed * World.AbsoluteCameraSide.Y;
                        World.AbsoluteCameraPosition.Z += MoveXSpeed * timeElapsed * World.AbsoluteCameraSide.Z;
                        keep = true;
                    }
                    // move y
                    if (MoveY == 0)
                    {
                        double d = (2.5 + Math.Abs(MoveYSpeed)) * timeElapsed;
                        if (MoveYSpeed >= -d & MoveYSpeed <= d)
                        {
                            MoveYSpeed = 0.0;
                        }
                        else
                        {
                            MoveYSpeed -= (double)Math.Sign(MoveYSpeed) * d;
                        }
                    }
                    else
                    {
                        double d = (5.0 + 10.0 - 10.0 / (1.0 + MoveYSpeed * MoveYSpeed)) * timeElapsed;
                        double m = 25.0;
                        MoveYSpeed += (double)MoveY * d;
                        if (MoveYSpeed < -m)
                        {
                            MoveYSpeed = -m;
                        }
                        else if (MoveYSpeed > m)
                        {
                            MoveYSpeed = m;
                        }
                    }
                    if (MoveYSpeed != 0.0)
                    {
                        World.AbsoluteCameraPosition.X += MoveYSpeed * timeElapsed * World.AbsoluteCameraUp.X;
                        World.AbsoluteCameraPosition.Y += MoveYSpeed * timeElapsed * World.AbsoluteCameraUp.Y;
                        World.AbsoluteCameraPosition.Z += MoveYSpeed * timeElapsed * World.AbsoluteCameraUp.Z;
                        keep = true;
                    }
                    // move z
                    if (MoveZ == 0)
                    {
                        double d = (2.5 + Math.Abs(MoveZSpeed)) * timeElapsed;
                        if (MoveZSpeed >= -d & MoveZSpeed <= d)
                        {
                            MoveZSpeed = 0.0;
                        }
                        else
                        {
                            MoveZSpeed -= (double)Math.Sign(MoveZSpeed) * d;
                        }
                    }
                    else
                    {
                        double d = (5.0 + 10.0 - 10.0 / (1.0 + MoveZSpeed * MoveZSpeed)) * timeElapsed;
                        double m = 25.0;
                        MoveZSpeed += (double)MoveZ * d;
                        if (MoveZSpeed < -m)
                        {
                            MoveZSpeed = -m;
                        }
                        else if (MoveZSpeed > m)
                        {
                            MoveZSpeed = m;
                        }
                    }
                    if (MoveZSpeed != 0.0)
                    {
                        World.AbsoluteCameraPosition.X += MoveZSpeed * timeElapsed * World.AbsoluteCameraDirection.X;
                        World.AbsoluteCameraPosition.Y += MoveZSpeed * timeElapsed * World.AbsoluteCameraDirection.Y;
                        World.AbsoluteCameraPosition.Z += MoveZSpeed * timeElapsed * World.AbsoluteCameraDirection.Z;
                        keep = true;
                    }
                    // lighting
                    if (LightingRelative == -1)
                    {
                        LightingRelative = (double)LightingTarget;
                        updatelight      = true;
                    }
                    if (LightingTarget == 0)
                    {
                        if (LightingRelative != 0.0)
                        {
                            LightingRelative -= 0.5 * timeElapsed;
                            if (LightingRelative < 0.0)
                            {
                                LightingRelative = 0.0;
                            }
                            updatelight = true;
                            keep        = true;
                        }
                    }
                    else
                    {
                        if (LightingRelative != 1.0)
                        {
                            LightingRelative += 0.5 * timeElapsed;
                            if (LightingRelative > 1.0)
                            {
                                LightingRelative = 1.0;
                            }
                            updatelight = true;
                            keep        = true;
                        }
                    }
                    // continue
                    if (ReducedMode)
                    {
                        ReducedModeEnteringTime = (int)(ticks + 3000);
                    }
                    else
                    {
                        if (keep)
                        {
                            ReducedModeEnteringTime = (int)(ticks + 3000);
                        }
                        else if (ticks > ReducedModeEnteringTime)
                        {
                            ReducedMode = true;
                            World.AbsoluteCameraSide.Y = 0.0;
                            World.Normalize(ref World.AbsoluteCameraSide.X, ref World.AbsoluteCameraSide.Y, ref World.AbsoluteCameraSide.Z);
                            World.Normalize(ref World.AbsoluteCameraDirection.X, ref World.AbsoluteCameraDirection.Y, ref World.AbsoluteCameraDirection.Z);
                            World.AbsoluteCameraUp = World.Cross(World.AbsoluteCameraDirection, World.AbsoluteCameraSide);
                        }
                    }
                    if (updatelight)
                    {
                        Renderer.OptionAmbientColor.R = (byte)Math.Round(32.0 + 128.0 * LightingRelative * (2.0 - LightingRelative));
                        Renderer.OptionAmbientColor.G = (byte)Math.Round(32.0 + 128.0 * 0.5 * (LightingRelative + LightingRelative * (2.0 - LightingRelative)));
                        Renderer.OptionAmbientColor.B = (byte)Math.Round(32.0 + 128.0 * LightingRelative);
                        Renderer.OptionDiffuseColor.R = (byte)Math.Round(32.0 + 128.0 * LightingRelative);
                        Renderer.OptionDiffuseColor.G = (byte)Math.Round(32.0 + 128.0 * LightingRelative);
                        Renderer.OptionDiffuseColor.B = (byte)Math.Round(32.0 + 128.0 * Math.Sqrt(LightingRelative));
                        Renderer.InitializeLighting();
                    }
                    Renderer.RenderScene();
                    SDL.SDL_GL_SwapWindow(SDLWindow);
                }
                // quit
                TextureManager.UnuseAllTextures();
                if (iconSurface != IntPtr.Zero)
                {
                    SDL.SDL_FreeSurface(iconSurface);                     // free surface
                }
                if (iconBmp != null && iconData != null)
                {
                    iconBmp.UnlockBits(iconData);                     // free pixels
                    iconBmp.Dispose();
                }
                SDL.SDL_GL_DeleteContext(GLContext);
                SDL.SDL_DestroyWindow(SDLWindow);
                SDL.SDL_Quit();
            }
            else
            {
                MessageBox.Show("SDL failed to create the window.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
Exemplo n.º 22
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)
            {
                Program.ReducedMode      = false;
                Program.LightingRelative = -1.0;
                Game.Reset();
                TextureManager.UnuseAllTextures();
                Fonts.Initialize();
                Interface.ClearMessages();
                for (int i = 0; i < Program.Files.Length; i++)
                {
#if !DEBUG
                    try {
#endif
                    ObjectManager.UnifiedObject o = ObjectManager.LoadObject(Program.Files[i], System.Text.Encoding.UTF8,
                                                                             ObjectManager.ObjectLoadMode.Normal, false, false, false, 0, 0, 0);
                    ObjectManager.CreateObject(o, new World.Vector3D(0.0, 0.0, 0.0),
                                               new World.Transformation(0.0, 0.0, 0.0), new World.Transformation(0.0, 0.0, 0.0), true, 0.0,
                                               0.0, 25.0, 0.0);
#if !DEBUG
                }
                catch (Exception ex) {
                    Interface.AddMessage(Interface.MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + Program.Files[i] + ".");
                }
#endif
                }
                ObjectManager.InitializeVisibility();
                ObjectManager.UpdateVisibility(0.0, true);
                ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
            }
            Renderer.TransparentColorDepthSorting = Interface.CurrentOptions.TransparencyMode == Renderer.TransparencyMode.Smooth & Interface.CurrentOptions.Interpolation != TextureManager.InterpolationMode.NearestNeighbor & Interface.CurrentOptions.Interpolation != TextureManager.InterpolationMode.Bilinear;
            Options.SaveOptions();
            this.Close();
        }
Exemplo n.º 23
0
        /// <summary>Jumps a train to a new station</summary>
        /// <param name="train">The train</param>
        /// <param name="stationIndex">The zero-based index of the station</param>
        internal static void JumpTrain(Train train, int stationIndex)
        {
            train.SafetySystems.PassAlarm.Halt();
            int currentTrackElement = train.Cars[0].FrontAxle.Follower.LastTrackElement;

            if (train.IsPlayerTrain)
            {
                for (int i = 0; i < ObjectManager.AnimatedWorldObjects.Length; i++)
                {
                    var obj = ObjectManager.AnimatedWorldObjects[i] as OpenBveApi.Objects.TrackFollowingObject;
                    if (obj != null)
                    {
                        //Track followers should be reset if we jump between stations
                        obj.FrontAxleFollower.TrackPosition = ObjectManager.AnimatedWorldObjects[i].TrackPosition + obj.FrontAxlePosition;
                        obj.FrontAxleFollower.TrackPosition = ObjectManager.AnimatedWorldObjects[i].TrackPosition + obj.RearAxlePosition;
                        obj.FrontAxleFollower.UpdateWorldCoordinates(false);
                        obj.RearAxleFollower.UpdateWorldCoordinates(false);
                    }
                }
            }
            train.StationState = TrainStopState.Jumping;
            int stopIndex = Program.CurrentRoute.Stations[stationIndex].GetStopIndex(train.NumberOfCars);

            if (stopIndex >= 0)
            {
                if (train.IsPlayerTrain)
                {
                    if (train.Plugin != null)
                    {
                        train.Plugin.BeginJump((OpenBveApi.Runtime.InitializationModes)Game.TrainStart);
                    }
                }
                for (int h = 0; h < train.Cars.Length; h++)
                {
                    train.Cars[h].CurrentSpeed = 0.0;
                }
                double d = Program.CurrentRoute.Stations[stationIndex].Stops[stopIndex].TrackPosition - train.Cars[0].FrontAxle.Follower.TrackPosition + train.Cars[0].FrontAxle.Position - 0.5 * train.Cars[0].Length;
                if (train.IsPlayerTrain)
                {
                    SoundsBase.SuppressSoundEvents = true;
                }
                while (d != 0.0)
                {
                    double x;
                    if (Math.Abs(d) > 1.0)
                    {
                        x = (double)Math.Sign(d);
                    }
                    else
                    {
                        x = d;
                    }
                    for (int h = 0; h < train.Cars.Length; h++)
                    {
                        train.Cars[h].Move(x);
                    }
                    if (Math.Abs(d) >= 1.0)
                    {
                        d -= x;
                    }
                    else
                    {
                        break;
                    }
                }
                if (train.IsPlayerTrain)
                {
                    TrainManager.UnderailTrains();
                    SoundsBase.SuppressSoundEvents = false;
                }
                if (train.Handles.EmergencyBrake.Driver)
                {
                    train.ApplyNotch(0, false, 0, true);
                }
                else
                {
                    train.ApplyNotch(0, false, train.Handles.Brake.MaximumNotch, false);
                    train.ApplyAirBrakeHandle(TrainManager.AirBrakeHandleState.Service);
                }
                if (Program.CurrentRoute.Sections.Length > 0)
                {
                    Program.CurrentRoute.UpdateAllSections();
                }
                if (train.IsPlayerTrain)
                {
                    if (Game.CurrentScore.ArrivalStation <= stationIndex)
                    {
                        Game.CurrentScore.ArrivalStation = stationIndex + 1;
                    }
                }
                if (train.IsPlayerTrain)
                {
                    if (Program.CurrentRoute.Stations[stationIndex].ArrivalTime >= 0.0)
                    {
                        Program.CurrentRoute.SecondsSinceMidnight = Program.CurrentRoute.Stations[stationIndex].ArrivalTime;
                    }
                    else if (Program.CurrentRoute.Stations[stationIndex].DepartureTime >= 0.0)
                    {
                        Program.CurrentRoute.SecondsSinceMidnight = Program.CurrentRoute.Stations[stationIndex].DepartureTime - Program.CurrentRoute.Stations[stationIndex].StopTime;
                    }
                }
                for (int i = 0; i < train.Cars.Length; i++)
                {
                    train.Cars[i].Doors[0].AnticipatedOpen = Program.CurrentRoute.Stations[stationIndex].OpenLeftDoors;
                    train.Cars[i].Doors[1].AnticipatedOpen = Program.CurrentRoute.Stations[stationIndex].OpenRightDoors;
                }
                if (train.IsPlayerTrain)
                {
                    Game.CurrentScore.DepartureStation = stationIndex;
                    Program.Renderer.CurrentInterface  = InterfaceType.Normal;
                }
                ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                TrainManager.UpdateTrainObjects(0.0, true);
                if (train.IsPlayerTrain)
                {
                    if (train.Plugin != null)
                    {
                        train.Plugin.EndJump();
                    }
                }
                train.StationState = TrainStopState.Pending;
                if (train.IsPlayerTrain)
                {
                    train.LastStation = stationIndex;
                }
                int newTrackElement = train.Cars[0].FrontAxle.Follower.LastTrackElement;
                if (newTrackElement < currentTrackElement)
                {
                    for (int i = newTrackElement; i < currentTrackElement; i++)
                    {
                        for (int j = 0; j < Program.CurrentHost.Tracks[0].Elements[i].Events.Length; j++)
                        {
                            Program.CurrentHost.Tracks[0].Elements[i].Events[j].Reset();
                        }
                    }
                }
            }
        }
Exemplo n.º 24
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();
        }
Exemplo n.º 25
0
        //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 { }
        }
Exemplo n.º 26
0
        private void CloseButton_Click(object sender, EventArgs e)
        {
            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 = OpenBveApi.Graphics.InterpolationMode.NearestNeighbor;
                break;

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

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

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

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

            case 5:
                Interface.CurrentOptions.Interpolation = OpenBveApi.Graphics.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 = TransparencyMode.Performance;
                break;

            default:
                Interface.CurrentOptions.TransparencyMode = TransparencyMode.Quality;
                break;
            }

            //Set width and height
            if (Program.Renderer.Screen.Width != width.Value || Program.Renderer.Screen.Height != height.Value)
            {
                if (width.Value >= 300)
                {
                    Program.Renderer.Screen.Width   = (int)width.Value;
                    Program.currentGameWindow.Width = (int)width.Value;
                }

                if (height.Value >= 300)
                {
                    Program.Renderer.Screen.Height   = (int)height.Value;
                    Program.currentGameWindow.Height = (int)height.Value;
                }

                Program.Renderer.UpdateViewport();
            }

            //Check if interpolation mode or ansiotropic filtering level has changed, and trigger a reload
            if (previousInterpolationMode != Interface.CurrentOptions.Interpolation || previousAnsiotropicLevel != Interface.CurrentOptions.AnisotropicFilteringLevel)
            {
                Program.LightingRelative = -1.0;
                Game.Reset();
                for (int i = 0; i < Program.Files.Length; i++)
                {
                    try
                    {
                        UnifiedObject o;
                        Program.CurrentHost.LoadObject(Program.Files[i], System.Text.Encoding.UTF8, out o);
                        o.CreateObject(Vector3.Zero, 0.0, 0.0, 0.0);
                    }
                    catch (Exception ex)
                    {
                        Interface.AddMessage(MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + Program.Files[i] + ".");
                    }
                }

                Program.Renderer.InitializeVisibility();
                Program.Renderer.UpdateVisibility(0.0, true);
                ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
            }

            Interface.CurrentOptions.CurrentXParser   = (XParsers)comboBoxNewXParser.SelectedIndex;
            Interface.CurrentOptions.CurrentObjParser = (ObjParsers)comboBoxNewObjParser.SelectedIndex;
            for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++)
            {
                if (Program.CurrentHost.Plugins[i].Object != null)
                {
                    Program.CurrentHost.Plugins[i].Object.SetObjectParser(Interface.CurrentOptions.CurrentXParser);
                    Program.CurrentHost.Plugins[i].Object.SetObjectParser(Interface.CurrentOptions.CurrentObjParser);
                }
            }

            if (checkBoxOptimizeObjects.Checked)
            {
                Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 1000;
                Interface.CurrentOptions.ObjectOptimizationFullThreshold  = 250;
            }
            else
            {
                Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 0;
                Interface.CurrentOptions.ObjectOptimizationFullThreshold  = 0;
            }
            Options.SaveOptions();
            this.Close();
        }
Exemplo n.º 27
0
        //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 (Program.Renderer.CurrentInterface != InterfaceType.Normal)
            {
                MainLoop.UpdateControlRepeats(0.0);
                MainLoop.ProcessKeyboard();
                MainLoop.ProcessControls(0.0);
                if (Program.Renderer.CurrentInterface == InterfaceType.Pause)
                {
                    System.Threading.Thread.Sleep(10);
                }
                //Renderer.UpdateLighting();
                Program.Renderer.RenderScene(TimeElapsed, RealTimeElapsed);
                Program.currentGameWindow.SwapBuffers();
                if (MainLoop.Quit != MainLoop.QuitMode.ContinueGame)
                {
                    Close();
                    if (Program.CurrentHost.MonoRuntime && MainLoop.Quit == MainLoop.QuitMode.QuitProgram)
                    {
                        Environment.Exit(0);
                    }
                }
                //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)
            {
                Program.Renderer.FrameRate = RenderFrequency;
                TotalTimeElapsedForInfo    = 0.0;
            }


            if (Program.Renderer.PreviousInterface != InterfaceType.Normal)
            {
                // Update animated objects with zero elapsed time (NOT time elapsed in menu)
                // and set again to avoid glitching
                ObjectManager.UpdateAnimatedWorldObjects(0.0, false);
                Program.Renderer.CurrentInterface = 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 (Program.Renderer.Camera.CurrentMode == CameraViewMode.Interior | Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead | Program.Renderer.Camera.CurrentMode == CameraViewMode.Exterior)
            {
                //Update the in-car camera based upon the current driver car (Cabview or passenger view)
                TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.CameraCar].UpdateCamera();
            }

            if (Program.Renderer.Camera.CurrentRestriction == CameraRestrictionMode.NotAvailable || Program.Renderer.Camera.CurrentRestriction == CameraRestrictionMode.Restricted3D)
            {
                TrainManager.PlayerTrain.DriverBody.Update(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);
            }
            Program.TrainManager.UpdateTrainObjects(TimeElapsed, false);
            if (Program.Renderer.Camera.CurrentMode == CameraViewMode.Interior | Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead | Program.Renderer.Camera.CurrentMode == CameraViewMode.Exterior)
            {
                Program.Renderer.UpdateVisibility(Program.Renderer.CameraTrackFollower.TrackPosition + Program.Renderer.Camera.Alignment.Position.Z);
                int d = TrainManager.PlayerTrain.DriverCar;
                Program.Renderer.Camera.CurrentSpeed = TrainManager.PlayerTrain.Cars[d].CurrentSpeed;
            }
            else
            {
                Program.Renderer.Camera.CurrentSpeed = 0.0;
            }

            Program.Renderer.Camera.AlignmentDirection = new CameraAlignment();
            if (MainLoop.Quit != MainLoop.QuitMode.ContinueGame)
            {
                Program.currentGameWindow.Exit();
                if (Program.CurrentHost.MonoRuntime && MainLoop.Quit == MainLoop.QuitMode.QuitProgram)
                {
                    Environment.Exit(0);
                }
            }

            if (Program.CurrentRoute.DynamicLighting)
            {
                Program.Renderer.Lighting.UpdateLighting(Program.CurrentRoute.SecondsSinceMidnight, Program.CurrentRoute.LightDefinitions);
            }
            Program.Renderer.RenderScene(TimeElapsed, RealTimeElapsed);
            Program.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();
            MainLoop.UpdateMouse(RealTimeElapsed);
            MainLoop.ProcessControls(TimeElapsed);
            if (JoystickManager.AttachedJoysticks.ContainsKey(JoystickManager.Raildriver.Guid))
            {
                var railDriver = JoystickManager.AttachedJoysticks[JoystickManager.Raildriver.Guid] as JoystickManager.Raildriver;
                if (railDriver != null)
                {
                    if (Interface.CurrentOptions.RailDriverMPH)
                    {
                        railDriver.SetDisplay((int)(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Specs.PerceivedSpeed * 2.23694));
                    }
                    else
                    {
                        railDriver.SetDisplay((int)(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Specs.PerceivedSpeed * 3.6));
                    }
                }
            }

            RenderRealTimeElapsed = 0.0;
            RenderTimeElapsed     = 0.0;



#if DEBUG
            MainLoop.CheckForOpenGlError("MainLoop");
#endif
            if (Interface.CurrentOptions.UnloadUnusedTextures)
            {
                Textures.UnloadUnusedTextures(TimeElapsed);
            }
            // finish
            try
            {
                Interface.SaveLogs();
            }
            catch { }
        }
Exemplo n.º 28
0
        /// <summary>This method is called once the route and train data have been preprocessed, in order to physically setup the simulation</summary>
        private void SetupSimulation()
        {
            if (Loading.Cancel)
            {
                Close();
            }
            Timetable.CreateTimetable();
            //Check if any critical errors have occured during the route or train loading
            for (int i = 0; i < Interface.MessageCount; i++)
            {
                if (Interface.Messages[i].Type == Interface.MessageType.Critical)
                {
                    MessageBox.Show("A critical error has occured:\n\n" + Interface.Messages[i].Text + "\n\nPlease inspect the error log file for further information.", "Load", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    Close();
                }
            }
            Renderer.InitializeLighting();
            Game.LogRouteName = System.IO.Path.GetFileName(MainLoop.currentResult.RouteFile);
            Game.LogTrainName = System.IO.Path.GetFileName(MainLoop.currentResult.TrainFolder);
            Game.LogDateTime  = DateTime.Now;

            if (Interface.CurrentOptions.LoadInAdvance)
            {
                Textures.LoadAllTextures();
            }
            else
            {
                Textures.UnloadAllTextures();
            }
            // camera
            ObjectManager.InitializeVisibility();
            TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, 0.0, true, false);
            TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -0.1, true, false);
            TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, 0.1, true, false);
            World.CameraTrackFollower.TriggerType = TrackManager.EventTriggerType.Camera;
            // starting time and track position
            Game.SecondsSinceMidnight = 0.0;
            Game.StartupTime          = 0.0;
            int    PlayerFirstStationIndex    = -1;
            double PlayerFirstStationPosition = 0.0;

            for (int i = 0; i < Game.Stations.Length; i++)
            {
                if (Game.Stations[i].StopMode == Game.StationStopMode.AllStop | Game.Stations[i].StopMode == Game.StationStopMode.PlayerStop & Game.Stations[i].Stops.Length != 0)
                {
                    PlayerFirstStationIndex = i;
                    int s = Game.GetStopIndex(i, TrainManager.PlayerTrain.Cars.Length);
                    if (s >= 0)
                    {
                        PlayerFirstStationPosition = Game.Stations[i].Stops[s].TrackPosition;

                        double TrainLength = 0.0;
                        for (int c = 0; c < TrainManager.Trains[TrainManager.PlayerTrain.TrainIndex].Cars.Length; c++)
                        {
                            TrainLength += TrainManager.Trains[TrainManager.PlayerTrain.TrainIndex].Cars[c].Length;
                        }

                        for (int j = 0; j < Game.BufferTrackPositions.Length; j++)
                        {
                            if (PlayerFirstStationPosition > Game.BufferTrackPositions[j] && PlayerFirstStationPosition - TrainLength < Game.BufferTrackPositions[j])
                            {
                                /*
                                 * HACK: The initial start position for the player train is stuck on a set of buffers
                                 * This means we have to make some one the fly adjustments to the first station stop position
                                 */

                                //Set the start position to be the buffer position plus the train length plus 1m
                                PlayerFirstStationPosition = Game.BufferTrackPositions[j] + TrainLength + 1;
                                //Update the station stop location
                                if (s >= 0)
                                {
                                    Game.Stations[PlayerFirstStationIndex].Stops[s].TrackPosition = PlayerFirstStationPosition;
                                }
                                else
                                {
                                    Game.Stations[PlayerFirstStationIndex].DefaultTrackPosition = PlayerFirstStationPosition;
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        PlayerFirstStationPosition = Game.Stations[i].DefaultTrackPosition;
                    }
                    if (Game.Stations[i].ArrivalTime < 0.0)
                    {
                        if (Game.Stations[i].DepartureTime < 0.0)
                        {
                            Game.SecondsSinceMidnight = 0.0;
                            Game.StartupTime          = 0.0;
                        }
                        else
                        {
                            Game.SecondsSinceMidnight = Game.Stations[i].DepartureTime - Game.Stations[i].StopTime;
                            Game.StartupTime          = Game.Stations[i].DepartureTime - Game.Stations[i].StopTime;
                        }
                    }
                    else
                    {
                        Game.SecondsSinceMidnight = Game.Stations[i].ArrivalTime;
                        Game.StartupTime          = Game.Stations[i].ArrivalTime;
                    }
                    break;
                }
            }
            int    OtherFirstStationIndex    = -1;
            double OtherFirstStationPosition = 0.0;
            double OtherFirstStationTime     = 0.0;

            for (int i = 0; i < Game.Stations.Length; i++)
            {
                if (Game.Stations[i].StopMode == Game.StationStopMode.AllStop | Game.Stations[i].StopMode == Game.StationStopMode.PlayerPass & Game.Stations[i].Stops.Length != 0)
                {
                    OtherFirstStationIndex = i;
                    int s = Game.GetStopIndex(i, TrainManager.PlayerTrain.Cars.Length);
                    if (s >= 0)
                    {
                        OtherFirstStationPosition = Game.Stations[i].Stops[s].TrackPosition;
                    }
                    else
                    {
                        OtherFirstStationPosition = Game.Stations[i].DefaultTrackPosition;
                    }
                    if (Game.Stations[i].ArrivalTime < 0.0)
                    {
                        if (Game.Stations[i].DepartureTime < 0.0)
                        {
                            OtherFirstStationTime = 0.0;
                        }
                        else
                        {
                            OtherFirstStationTime = Game.Stations[i].DepartureTime - Game.Stations[i].StopTime;
                        }
                    }
                    else
                    {
                        OtherFirstStationTime = Game.Stations[i].ArrivalTime;
                    }
                    break;
                }
            }
            if (Game.PrecedingTrainTimeDeltas.Length != 0)
            {
                OtherFirstStationTime -= Game.PrecedingTrainTimeDeltas[Game.PrecedingTrainTimeDeltas.Length - 1];
                if (OtherFirstStationTime < Game.SecondsSinceMidnight)
                {
                    Game.SecondsSinceMidnight = OtherFirstStationTime;
                }
            }
            // initialize trains
            for (int i = 0; i < TrainManager.Trains.Length; i++)
            {
                TrainManager.InitializeTrain(TrainManager.Trains[i]);
                int s = i == TrainManager.PlayerTrain.TrainIndex ? PlayerFirstStationIndex : OtherFirstStationIndex;
                if (s >= 0)
                {
                    if (Game.Stations[s].OpenLeftDoors)
                    {
                        for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++)
                        {
                            TrainManager.Trains[i].Cars[j].Specs.AnticipatedLeftDoorsOpened = true;
                        }
                    }
                    if (Game.Stations[s].OpenRightDoors)
                    {
                        for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++)
                        {
                            TrainManager.Trains[i].Cars[j].Specs.AnticipatedRightDoorsOpened = true;
                        }
                    }
                }
                if (Game.Sections.Length != 0)
                {
                    Game.Sections[0].Enter(TrainManager.Trains[i]);
                }
                for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++)
                {
                    double length = TrainManager.Trains[i].Cars[0].Length;
                    TrainManager.MoveCar(TrainManager.Trains[i], j, -length, 0.01);
                    TrainManager.MoveCar(TrainManager.Trains[i], j, length, 0.01);
                }
            }
            // score
            Game.CurrentScore.ArrivalStation   = PlayerFirstStationIndex + 1;
            Game.CurrentScore.DepartureStation = PlayerFirstStationIndex;
            Game.CurrentScore.Maximum          = 0;
            for (int i = 0; i < Game.Stations.Length; i++)
            {
                if (i != PlayerFirstStationIndex & Game.PlayerStopsAtStation(i))
                {
                    if (i == 0 || Game.Stations[i - 1].StationType != Game.StationType.ChangeEnds)
                    {
                        Game.CurrentScore.Maximum += Game.ScoreValueStationArrival;
                    }
                }
            }
            if (Game.CurrentScore.Maximum <= 0)
            {
                Game.CurrentScore.Maximum = Game.ScoreValueStationArrival;
            }
            // signals
            if (Game.Sections.Length > 0)
            {
                Game.UpdateSection(Game.Sections.Length - 1);
            }
            // move train in position
            for (int i = 0; i < TrainManager.Trains.Length; i++)
            {
                double p;
                if (i == TrainManager.PlayerTrain.TrainIndex)
                {
                    p = PlayerFirstStationPosition;
                }
                else if (TrainManager.Trains[i].State == TrainManager.TrainState.Bogus)
                {
                    p = Game.BogusPretrainInstructions[0].TrackPosition;
                    TrainManager.Trains[i].AI = new Game.BogusPretrainAI(TrainManager.Trains[i]);
                }
                else
                {
                    p = OtherFirstStationPosition;
                }
                for (int j = 0; j < TrainManager.Trains[i].Cars.Length; j++)
                {
                    TrainManager.MoveCar(TrainManager.Trains[i], j, p, 0.01);
                }
            }
            // timetable
            if (Timetable.DefaultTimetableDescription.Length == 0)
            {
                Timetable.DefaultTimetableDescription = Game.LogTrainName;
            }

            // initialize camera
            if (World.CameraRestriction == World.CameraRestrictionMode.NotAvailable)
            {
                World.CameraMode = World.CameraViewMode.InteriorLookAhead;
            }
            //Place the initial camera in the driver car
            TrainManager.UpdateCamera(TrainManager.PlayerTrain, TrainManager.PlayerTrain.DriverCar);
            TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false);
            ObjectManager.UpdateVisibility(World.CameraTrackFollower.TrackPosition + World.CameraCurrentAlignment.Position.Z);
            World.CameraSavedInterior = new World.CameraAlignment();
            World.CameraSavedExterior = new World.CameraAlignment(new OpenBveApi.Math.Vector3(-2.5, 1.5, -15.0), 0.3, -0.2, 0.0, PlayerFirstStationPosition, 1.0);
            World.CameraSavedTrack    = new World.CameraAlignment(new OpenBveApi.Math.Vector3(-3.0, 2.5, 0.0), 0.3, 0.0, 0.0, TrainManager.PlayerTrain.Cars[0].FrontAxle.Follower.TrackPosition - 10.0, 1.0);
            // signalling sections
            for (int i = 0; i < TrainManager.Trains.Length; i++)
            {
                int s = TrainManager.Trains[i].CurrentSectionIndex;
                Game.Sections[s].Enter(TrainManager.Trains[i]);
            }
            if (Game.Sections.Length > 0)
            {
                Game.UpdateSection(Game.Sections.Length - 1);
            }
            // fast-forward until start time
            {
                Game.MinimalisticSimulation = true;
                const double w = 0.25;
                double       u = Game.StartupTime - Game.SecondsSinceMidnight;
                if (u > 0)
                {
                    while (true)
                    {
                        double v = u < w ? u : w; u -= v;
                        Game.SecondsSinceMidnight += v;
                        TrainManager.UpdateTrains(v);
                        if (u <= 0.0)
                        {
                            break;
                        }
                        TotalTimeElapsedForSectionUpdate += v;
                        if (TotalTimeElapsedForSectionUpdate >= 1.0)
                        {
                            if (Game.Sections.Length > 0)
                            {
                                Game.UpdateSection(Game.Sections.Length - 1);
                            }
                            TotalTimeElapsedForSectionUpdate = 0.0;
                        }
                    }
                }
                Game.MinimalisticSimulation = false;
            }
            // animated objects
            ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
            TrainManager.UpdateTrainObjects(0.0, true);
            // timetable
            if (TrainManager.PlayerTrain.Station >= 0)
            {
                Timetable.UpdateCustomTimetable(Game.Stations[TrainManager.PlayerTrain.Station].TimetableDaytimeTexture, Game.Stations[TrainManager.PlayerTrain.Station].TimetableNighttimeTexture);
                if (Timetable.CustomObjectsUsed != 0 & Timetable.CustomTimetableAvailable && Interface.CurrentOptions.TimeTableStyle != Interface.TimeTableMode.AutoGenerated && Interface.CurrentOptions.TimeTableStyle != Interface.TimeTableMode.None)
                {
                    Timetable.CurrentTimetable = Timetable.TimetableState.Custom;
                }
            }

            // warnings / errors
            if (Interface.MessageCount != 0)
            {
                int filesNotFound = 0;
                int errors        = 0;
                int warnings      = 0;
                for (int i = 0; i < Interface.MessageCount; i++)
                {
                    if (Interface.Messages[i].FileNotFound)
                    {
                        filesNotFound++;
                    }
                    else if (Interface.Messages[i].Type == Interface.MessageType.Error)
                    {
                        errors++;
                    }
                    else if (Interface.Messages[i].Type == Interface.MessageType.Warning)
                    {
                        warnings++;
                    }
                }
                string NotFound = null;
                string Messages = null;
                if (filesNotFound != 0)
                {
                    NotFound = filesNotFound.ToString() + " file(s) not found";
                    Game.AddDebugMessage(NotFound, 10.0);
                }
                if (errors != 0 & warnings != 0)
                {
                    Messages = errors.ToString() + " error(s), " + warnings.ToString() + " warning(s)";
                    Game.AddDebugMessage(Messages, 10.0);
                }
                else if (errors != 0)
                {
                    Messages = errors.ToString() + " error(s)";
                    Game.AddDebugMessage(Messages, 10.0);
                }
                else
                {
                    Messages = warnings.ToString() + " warning(s)";
                    Game.AddDebugMessage(Messages, 10.0);
                }
                Game.RouteInformation.FilesNotFound     = NotFound;
                Game.RouteInformation.ErrorsAndWarnings = Messages;
                //Print the plugin error encountered (If any) for 10s
                //This must be done after the simulation has init, as otherwise the timeout doesn't work
                if (Loading.PluginError != null)
                {
                    Game.AddMessage(Loading.PluginError, Game.MessageDependency.None, Interface.GameMode.Expert, OpenBveApi.Colors.MessageColor.Red, Game.SecondsSinceMidnight + 5.0);
                    Game.AddMessage(Interface.GetInterfaceString("errors_plugin_failure2"), Game.MessageDependency.None, Interface.GameMode.Expert, OpenBveApi.Colors.MessageColor.Red, Game.SecondsSinceMidnight + 5.0);
                }
            }
            loadComplete          = true;
            RenderRealTimeElapsed = 0.0;
            RenderTimeElapsed     = 0.0;
            World.InitializeCameraRestriction();
        }
Exemplo n.º 29
0
        // process events
        internal static void KeyDown(object sender, KeyboardKeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.LShift:
            case Key.RShift:
                ShiftPressed = true;
                break;

            case Key.F5:
                // reset
                ReducedMode      = false;
                LightingRelative = -1.0;
                Game.Reset();
                Textures.UnloadAllTextures();
                //Fonts.Initialize();
                Interface.ClearMessages();
                for (int i = 0; i < Files.Length; i++)
                {
#if !DEBUG
                    try {
#endif
                    if (String.Compare(System.IO.Path.GetFileName(Files[i]), "extensions.cfg", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        UnifiedObject[]    carObjects;
                        UnifiedObject[]    bogieObjects;
                        double[]           axleLocations;
                        TrainManager.Train train;
                        ExtensionsCfgParser.ParseExtensionsConfig(Files[i], System.Text.Encoding.UTF8, out carObjects, out bogieObjects, out axleLocations, out train, true);
                        if (axleLocations.Length == 0)
                        {
                            axleLocations = new double[train.Cars.Length * 2];
                            for (int j = 0; j < train.Cars.Length; j++)
                            {
                                double ap = train.Cars.Length * 0.4;
                                axleLocations[j] = ap;
                                j++;
                                axleLocations[j] = -ap;
                            }
                        }
                        double z = 0.0;
                        for (int j = 0; j < carObjects.Length; j++)
                        {
                            ObjectManager.CreateObject(carObjects[j], new Vector3(0.0, 0.0, z),
                                                       new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                       0.0);
                            if (j < train.Cars.Length - 1)
                            {
                                z -= (train.Cars[j].Length + train.Cars[j + 1].Length) / 2;
                            }
                        }
                        z = 0.0;
                        for (int j = 0; j < bogieObjects.Length; j++)
                        {
                            ObjectManager.CreateObject(bogieObjects[j], new Vector3(0.0, 0.0, z + axleLocations[j]),
                                                       new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                       0.0);
                            j++;
                            ObjectManager.CreateObject(bogieObjects[j], new Vector3(0.0, 0.0, z - axleLocations[j]),
                                                       new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                       0.0);
                            if (j < train.Cars.Length - 1)
                            {
                                z -= (train.Cars[j].Length + train.Cars[j + 1].Length) / 2;
                            }
                        }
                    }
                    else
                    {
                        UnifiedObject o = ObjectManager.LoadObject(Files[i], System.Text.Encoding.UTF8, false, false, false);
                        ObjectManager.CreateObject(o, Vector3.Zero,
                                                   new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                   0.0);
                    }
#if !DEBUG
                }
                catch (Exception ex) {
                    Interface.AddMessage(MessageType.Critical, false, "Unhandled error (" + ex.Message + ") encountered while processing the file " + Files[i] + ".");
                }
#endif
                }
                ObjectManager.InitializeVisibility();
                ObjectManager.UpdateVisibility(0.0, true);
                ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
                break;

            case Key.F7:
            {
                OpenFileDialog Dialog = new OpenFileDialog
                {
                    CheckFileExists = true,
                    Multiselect     = true,
                    Filter          = @"All supported object files|*.csv;*.b3d;*.x;*.animated;extensions.cfg;*.l3dobj;*.l3dgrp;*.obj;*.s|openBVE Objects|*.csv;*.b3d;*.x;*.animated;extensions.cfg|LokSim 3D Objects|*.l3dobj;*.l3dgrp|Wavefront Objects|*.obj|Microsoft Train Simulator Objects|*.s|All files|*"
                };
                if (Dialog.ShowDialog() == DialogResult.OK)
                {
                    Application.DoEvents();
                    string[] f = Dialog.FileNames;
                    int      n = Files.Length;
                    Array.Resize <string>(ref Files, n + f.Length);
                    for (int i = 0; i < f.Length; i++)
                    {
                        Files[n + i] = f[i];
                    }
                    // reset
                    ReducedMode      = false;
                    LightingRelative = -1.0;
                    Game.Reset();
                    Textures.UnloadAllTextures();
                    Interface.ClearMessages();
                    for (int i = 0; i < Files.Length; i++)
                    {
#if !DEBUG
                        try
                        {
#endif
                        if (String.Compare(System.IO.Path.GetFileName(Files[i]), "extensions.cfg", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            UnifiedObject[]    carObjects;
                            UnifiedObject[]    bogieObjects;
                            double[]           axleLocations;
                            TrainManager.Train train;
                            ExtensionsCfgParser.ParseExtensionsConfig(Files[i], System.Text.Encoding.UTF8, out carObjects, out bogieObjects, out axleLocations, out train, true);
                            if (axleLocations.Length == 0)
                            {
                                axleLocations = new double[train.Cars.Length * 2];
                                for (int j = 0; j < train.Cars.Length; j++)
                                {
                                    double ap = train.Cars.Length * 0.4;
                                    axleLocations[j] = ap;
                                    j++;
                                    axleLocations[j] = -ap;
                                }
                            }
                            double z = 0.0;
                            for (int j = 0; j < carObjects.Length; j++)
                            {
                                ObjectManager.CreateObject(carObjects[j], new Vector3(0.0, 0.0, z),
                                                           new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                           0.0);
                                if (j < train.Cars.Length - 1)
                                {
                                    z -= (train.Cars[j].Length + train.Cars[j + 1].Length) / 2;
                                }
                            }
                            z = 0.0;
                            for (int j = 0; j < bogieObjects.Length; j++)
                            {
                                ObjectManager.CreateObject(bogieObjects[j], new Vector3(0.0, 0.0, z + axleLocations[j]),
                                                           new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                           0.0);
                                j++;
                                ObjectManager.CreateObject(bogieObjects[j], new Vector3(0.0, 0.0, z - axleLocations[j]),
                                                           new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                           0.0);
                                if (j < train.Cars.Length - 1)
                                {
                                    z -= (train.Cars[j].Length + train.Cars[j + 1].Length) / 2;
                                }
                            }
                        }
                        else
                        {
                            UnifiedObject o = ObjectManager.LoadObject(Files[i], System.Text.Encoding.UTF8, false, false, false);
                            ObjectManager.CreateObject(o, Vector3.Zero,
                                                       new Transformation(0.0, 0.0, 0.0), new Transformation(0.0, 0.0, 0.0), true, 0.0, 0.0, 25.0,
                                                       0.0);
                        }
#if !DEBUG
                    }
                    catch (Exception ex)
                    {
                        Interface.AddMessage(MessageType.Critical, false,
                                             "Unhandled error (" + ex.Message + ") encountered while processing the file " +
                                             Files[i] + ".");
                    }
#endif
                    }
                    ObjectManager.InitializeVisibility();
                    ObjectManager.FinishCreatingObjects();
                    ObjectManager.UpdateVisibility(0.0, true);
                    ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
                }
                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.F9:
                if (Interface.MessageCount != 0)
                {
                    formMessages.ShowMessages();
                    Application.DoEvents();
                }
                break;

            case Key.Delete:
                ReducedMode      = false;
                LightingRelative = -1.0;
                Game.Reset();
                Textures.UnloadAllTextures();
                //Fonts.Initialize();
                Interface.ClearMessages();
                Files = new string[] { };
                break;

            case Key.Left:
                RotateX     = -1;
                ReducedMode = false;
                break;

            case Key.Right:
                RotateX     = 1;
                ReducedMode = false;
                break;

            case Key.Up:
                RotateY     = -1;
                ReducedMode = false;
                break;

            case Key.Down:
                RotateY     = 1;
                ReducedMode = false;
                break;

            case Key.A:
            case Key.Keypad4:
                MoveX       = -1;
                ReducedMode = false;
                break;

            case Key.D:
            case Key.Keypad6:
                MoveX       = 1;
                ReducedMode = false;
                break;

            case Key.Keypad8:
                MoveY       = 1;
                ReducedMode = false;
                break;

            case Key.Keypad2:
                MoveY       = -1;
                ReducedMode = false;
                break;

            case Key.W:
            case Key.Keypad9:
                MoveZ       = 1;
                ReducedMode = false;
                break;

            case Key.S:
            case Key.Keypad3:
                MoveZ       = -1;
                ReducedMode = false;
                break;

            case Key.Keypad5:
                ResetCamera();
                break;

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

            case Key.N:
            case Key.F2:
                Renderer.OptionNormals = !Renderer.OptionNormals;
                break;

            case Key.L:
            case Key.F3:
                LightingTarget = 1 - LightingTarget;
                ReducedMode    = false;
                break;

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

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

            case Key.F10:
                formTrain.ShowTrainSettings();
                break;

            case Key.G:
            case Key.C:
                Renderer.OptionCoordinateSystem = !Renderer.OptionCoordinateSystem;
                ReducedMode = false;
                break;

            case Key.B:
                if (ShiftPressed)
                {
                    ColorDialog dialog = new ColorDialog();
                    dialog.FullOpen = true;
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        Renderer.BackgroundColor = -1;
                        Renderer.ApplyBackgroundColor(dialog.Color.R, dialog.Color.G, dialog.Color.B);
                    }
                }
                else
                {
                    Renderer.BackgroundColor++;
                    if (Renderer.BackgroundColor >= Renderer.MaxBackgroundColor)
                    {
                        Renderer.BackgroundColor = 0;
                    }
                    Renderer.ApplyBackgroundColor();
                }
                ReducedMode = false;
                break;
            }
        }
Exemplo n.º 30
0
        /// <summary>Jumps a train to a new station</summary>
        /// <param name="train">The train</param>
        /// <param name="stationIndex">The zero-based index of the station</param>
        internal static void JumpTrain(Train train, int stationIndex)
        {
            if (train == PlayerTrain)
            {
                for (int i = 0; i < ObjectManager.AnimatedWorldObjects.Length; i++)
                {
                    var obj = ObjectManager.AnimatedWorldObjects[i] as ObjectManager.TrackFollowingObject;
                    if (obj != null)
                    {
                        //Track followers should be reset if we jump between stations
                        obj.FrontAxleFollower.TrackPosition = ObjectManager.AnimatedWorldObjects[i].TrackPosition + obj.FrontAxlePosition;
                        obj.FrontAxleFollower.TrackPosition = ObjectManager.AnimatedWorldObjects[i].TrackPosition + obj.RearAxlePosition;
                        obj.FrontAxleFollower.UpdateWorldCoordinates(false);
                        obj.RearAxleFollower.UpdateWorldCoordinates(false);
                    }
                }
            }
            train.StationState = TrainStopState.Jumping;
            int stopIndex = Game.GetStopIndex(stationIndex, train.Cars.Length);

            if (stopIndex >= 0)
            {
                if (train == PlayerTrain)
                {
                    if (train.Plugin != null)
                    {
                        train.Plugin.BeginJump((OpenBveApi.Runtime.InitializationModes)Game.TrainStart);
                    }
                }
                for (int h = 0; h < train.Cars.Length; h++)
                {
                    train.Cars[h].Specs.CurrentSpeed = 0.0;
                }
                double d = Game.Stations[stationIndex].Stops[stopIndex].TrackPosition - train.Cars[0].FrontAxle.Follower.TrackPosition + train.Cars[0].FrontAxle.Position - 0.5 * train.Cars[0].Length;
                if (train == PlayerTrain)
                {
                    TrackManager.SuppressSoundEvents = true;
                }
                while (d != 0.0)
                {
                    double x;
                    if (Math.Abs(d) > 1.0)
                    {
                        x = (double)Math.Sign(d);
                    }
                    else
                    {
                        x = d;
                    }
                    for (int h = 0; h < train.Cars.Length; h++)
                    {
                        train.Cars[h].Move(x, 0.0);
                    }
                    if (Math.Abs(d) >= 1.0)
                    {
                        d -= x;
                    }
                    else
                    {
                        break;
                    }
                }
                if (train == PlayerTrain)
                {
                    TrainManager.UnderailTrains();
                    TrackManager.SuppressSoundEvents = false;
                }
                if (train.Handles.EmergencyBrake.Driver)
                {
                    train.ApplyNotch(0, false, 0, true);
                }
                else
                {
                    train.ApplyNotch(0, false, train.Handles.Brake.MaximumNotch, false);
                    train.ApplyAirBrakeHandle(TrainManager.AirBrakeHandleState.Service);
                }
                if (Game.Sections.Length > 0)
                {
                    Game.UpdateSection(Game.Sections.Length - 1);
                }
                if (train == PlayerTrain)
                {
                    if (Game.CurrentScore.ArrivalStation <= stationIndex)
                    {
                        Game.CurrentScore.ArrivalStation = stationIndex + 1;
                    }
                }
                if (train == PlayerTrain)
                {
                    if (Game.Stations[stationIndex].ArrivalTime >= 0.0)
                    {
                        Game.SecondsSinceMidnight = Game.Stations[stationIndex].ArrivalTime;
                    }
                    else if (Game.Stations[stationIndex].DepartureTime >= 0.0)
                    {
                        Game.SecondsSinceMidnight = Game.Stations[stationIndex].DepartureTime - Game.Stations[stationIndex].StopTime;
                    }
                }
                for (int i = 0; i < train.Cars.Length; i++)
                {
                    train.Cars[i].Doors[0].AnticipatedOpen = Game.Stations[stationIndex].OpenLeftDoors;
                    train.Cars[i].Doors[1].AnticipatedOpen = Game.Stations[stationIndex].OpenRightDoors;
                }
                if (train == PlayerTrain)
                {
                    Game.CurrentScore.DepartureStation = stationIndex;
                    Game.CurrentInterface = Game.InterfaceType.Normal;
                    //Game.Messages = new Game.Message[] { };
                }
                ObjectManager.UpdateAnimatedWorldObjects(0.0, true);
                TrainManager.UpdateTrainObjects(0.0, true);
                if (train == PlayerTrain)
                {
                    if (train.Plugin != null)
                    {
                        train.Plugin.EndJump();
                    }
                }
                train.StationState = TrainStopState.Pending;
            }
        }