Beispiel #1
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            double   RealTimeElapsed = CPreciseTimer.GetElapsedTime();
            DateTime time            = DateTime.Now;

            Game.SecondsSinceMidnight = 3600 * time.Hour + 60 * time.Minute + time.Second + 0.001 * time.Millisecond;

            NearestTrain.Apply();

            if (NearestTrain.IsExtensionsCfg)
            {
                double[] decelerationDueToBrake, decelerationDueToMotor;
                Program.TrainManager.Trains[0].UpdateBrakeSystem(RealTimeElapsed, out decelerationDueToBrake, out decelerationDueToMotor);
            }

            TotalTimeElapsedForInfo += RealTimeElapsed;
            RenderRealTimeElapsed   += RealTimeElapsed;
        }
Beispiel #2
0
        internal static void RefreshObjects()
        {
            LightingRelative = -1.0;
            Game.Reset();
            formTrain.Instance?.DisableUI();
            for (int i = 0; i < Files.Count; i++)
            {
                try
                {
                    if (String.Compare(System.IO.Path.GetFileName(Files[i]), "extensions.cfg", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        string currentTrainFolder = System.IO.Path.GetDirectoryName(Files[i]);
                        bool   canLoad            = false;
                        for (int j = 0; j < Program.CurrentHost.Plugins.Length; j++)
                        {
                            if (Program.CurrentHost.Plugins[j].Train != null && Program.CurrentHost.Plugins[j].Train.CanLoadTrain(currentTrainFolder))
                            {
                                Control[] dummyControls = new Control[0];
                                TrainManager.Trains = new[] { new TrainBase(TrainState.Available) };
                                AbstractTrain playerTrain = TrainManager.Trains[0];
                                Program.CurrentHost.Plugins[j].Train.LoadTrain(Encoding.UTF8, currentTrainFolder, ref playerTrain, ref dummyControls);
                                TrainManager.PlayerTrain = TrainManager.Trains[0];
                                canLoad = true;
                                break;
                            }
                        }

                        if (canLoad)
                        {
                            TrainManager.PlayerTrain.Initialize();
                            foreach (var Car in TrainManager.PlayerTrain.Cars)
                            {
                                double length = TrainManager.PlayerTrain.Cars[0].Length;
                                Car.Move(-length);
                                Car.Move(length);
                            }
                            TrainManager.PlayerTrain.PlaceCars(0);
                            for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
                            {
                                TrainManager.PlayerTrain.Cars[j].UpdateTrackFollowers(0, true, false);
                                TrainManager.PlayerTrain.Cars[j].UpdateTopplingCantAndSpring(0.0);
                                TrainManager.PlayerTrain.Cars[j].ChangeCarSection(CarSectionType.Exterior);
                                TrainManager.PlayerTrain.Cars[j].FrontBogie.UpdateTopplingCantAndSpring();
                                TrainManager.PlayerTrain.Cars[j].FrontBogie.ChangeSection(0);
                                TrainManager.PlayerTrain.Cars[j].RearBogie.UpdateTopplingCantAndSpring();
                                TrainManager.PlayerTrain.Cars[j].RearBogie.ChangeSection(0);
                                TrainManager.PlayerTrain.Cars[j].Coupler.ChangeSection(0);
                            }
                        }
                        else
                        {
                            //As we now attempt to load the train as a whole, the most likely outcome is that the train.dat file is MIA
                            Interface.AddMessage(MessageType.Critical, false, "No plugin found capable of loading file " + Files[i] + ".");
                        }
                    }
                    else
                    {
                        UnifiedObject o;
                        if (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] + ".");
                }
            }

            NearestTrain.UpdateSpecs();
            NearestTrain.Apply();
            formTrain.Instance?.EnableUI();

            Renderer.InitializeVisibility();
            Renderer.UpdateViewingDistances(600);
            Renderer.UpdateVisibility(0.0, true);
            ObjectManager.UpdateAnimatedWorldObjects(0.01, true);
            Program.TrainManager.UpdateTrainObjects(0.0, true);
            Renderer.ApplyBackgroundColor();
        }
Beispiel #3
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
                RefreshObjects();
                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;
                    for (int i = 0; i < f.Length; i++)
                    {
                        for (int j = 0; j < Program.CurrentHost.Plugins.Length; j++)
                        {
                            if (Program.CurrentHost.Plugins[j].Route != null && Program.CurrentHost.Plugins[j].Route.CanLoadRoute(f[i]))
                            {
                                // oops, that's actually a routefile- Let's show Route Viewer
                                string File = System.IO.Path.Combine(Application.StartupPath, "RouteViewer.exe");
                                if (System.IO.File.Exists(File))
                                {
                                    System.Diagnostics.Process.Start(File, "\"" + f[i] + "\"");
                                }
                            }

                            if (Program.CurrentHost.Plugins[j].Object != null && Program.CurrentHost.Plugins[j].Object.CanLoadObject(f[i]))
                            {
                                Files.Add(f[i]);
                            }
                        }
                    }
                }
                else
                {
                    if (Program.CurrentHost.MonoRuntime)
                    {
                        //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();
                RefreshObjects();
            }
            break;

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

            case Key.Delete:
                LightingRelative = -1.0;
                Game.Reset();
                Files = new List <string>();
                NearestTrain.UpdateSpecs();
                Renderer.ApplyBackgroundColor();
                break;

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

            case Key.Right:
                RotateX = 1;
                break;

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

            case Key.Down:
                RotateY = 1;
                break;

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

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

            case Key.Keypad8:
                MoveY = 1;
                break;

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

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

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

            case Key.Keypad5:
                Renderer.Camera.Reset(new Vector3(-5.0, 2.5, -25.0));
                break;

            case Key.F:
            case Key.F1:
                Renderer.OptionWireFrame = !Renderer.OptionWireFrame;
                break;

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

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

            case Key.I:
            case Key.F4:
                Renderer.OptionInterface = !Renderer.OptionInterface;
                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;
                break;

            case Key.B:
                if (ShiftPressed)
                {
                    using (ColorDialog dialog = new ColorDialog {
                        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 >= NewRenderer.MaxBackgroundColor)
                    {
                        Renderer.BackgroundColor = 0;
                    }
                    Renderer.ApplyBackgroundColor();
                }
                break;

            case Key.R:
                Renderer.SwitchOpenGLVersion();
                break;

            case Key.F11:
                Renderer.RenderStatsOverlay = !Renderer.RenderStatsOverlay;
                break;
            }
        }
Beispiel #4
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
                RefreshObjects();
                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(ref Files, n + f.Length);
                    for (int i = 0; i < f.Length; i++)
                    {
                        Files[n + i] = f[i];
                    }
                }
                else
                {
                    if (Program.CurrentHost.MonoRuntime)
                    {
                        //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();
                RefreshObjects();
            }
            break;

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

            case Key.Delete:
                LightingRelative = -1.0;
                Game.Reset();
                Files = new string[] {};
                NearestTrain.UpdateSpecs();
                Renderer.ApplyBackgroundColor();
                break;

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

            case Key.Right:
                RotateX = 1;
                break;

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

            case Key.Down:
                RotateY = 1;
                break;

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

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

            case Key.Keypad8:
                MoveY = 1;
                break;

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

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

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

            case Key.Keypad5:
                Renderer.Camera.Reset(new Vector3(-5.0, 2.5, -25.0));
                break;

            case Key.F:
            case Key.F1:
                Renderer.OptionWireFrame = !Renderer.OptionWireFrame;
                break;

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

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

            case Key.I:
            case Key.F4:
                Renderer.OptionInterface = !Renderer.OptionInterface;
                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;
                break;

            case Key.B:
                if (ShiftPressed)
                {
                    using (ColorDialog dialog = new ColorDialog {
                        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 >= NewRenderer.MaxBackgroundColor)
                    {
                        Renderer.BackgroundColor = 0;
                    }
                    Renderer.ApplyBackgroundColor();
                }
                break;

            case Key.R:
                Interface.CurrentOptions.IsUseNewRenderer = !Interface.CurrentOptions.IsUseNewRenderer;
                break;

            case Key.F11:
                Renderer.RenderStatsOverlay = !Renderer.RenderStatsOverlay;
                break;
            }
        }