public static void Run()
        {
            try
            {
                int numScreens = Screen.AllScreens.Length;
                if (numScreens != 1 && numScreens != 2)
                    throw new NotImplementedException("Only supports single and dual monitor setup!");

                SimulationSettings simSettings = SimulatorResources.GetSimulationSettings();

                if (simSettings.RenderMode == RenderModes.Stereo && numScreens < 2)
                {
                    Console.WriteLine(@"Could not run stereo mode. Can't find two monitors connected?");
                    simSettings.RenderMode = RenderModes.Normal;
                }

                IntPtr rightEyeWindow = IntPtr.Zero;
                if (simSettings.RenderMode == RenderModes.Stereo)
                    rightEyeWindow = SpawnRightEyeWindow();

                // Start the simulator game entry point
                using (var game = new SimulatorGame(simSettings, rightEyeWindow))
                {
                    // Make sure the XNA game window (left eye) displays as a full screen window
                    // just as the one we just created for the right eye
                    var gameForm = (Form) System.Windows.Forms.Control.FromHandle(game.Window.Handle);
                    gameForm.FormBorderStyle = FormBorderStyle.None;
                    gameForm.LostFocus += (sender, e) => game.IsCapturingMouse = false;
                    gameForm.GotFocus += (sender, e) => Game_GotFocus(game);
                    gameForm.MouseClick += (sender, e) =>
                                               {
                                                   if (e.Button == MouseButtons.Right)
                                                       Game_MouseRightClick(game);
                                               };

                    // Name the window according to mode
                    gameForm.Text = (simSettings.RenderMode == RenderModes.Stereo)
                                        ? "A²DS Stereoscopy (left eye)"
                                        : "A²DS";

                    _settingsController = new SettingsController(gameForm);

                    // Hook the settings controller to the simulator by events, so changes in PID settings causes
                    // autopilot to use new PID settings.
                    _settingsController.PIDSettingsChanged +=
                        () => game.SetPIDSetup(_settingsController.CurrentPIDSetup);

                    // Run the game code
                    game.Run();
                }
            }
            catch (Exception e)
            {
                string msg = "Error occured!\n\n" + e;
                Console.WriteLine(e);
                MessageBox.Show(msg);
            }
        }
Exemple #2
0
        public static void Run()
        {
            try
            {
                int numScreens = Screen.AllScreens.Length;
                if (numScreens != 1 && numScreens != 2)
                {
                    throw new NotImplementedException("Only supports single and dual monitor setup!");
                }

                SimulationSettings simSettings = SimulatorResources.GetSimulationSettings();

                if (simSettings.RenderMode == RenderModes.Stereo && numScreens < 2)
                {
                    Console.WriteLine(@"Could not run stereo mode. Can't find two monitors connected?");
                    simSettings.RenderMode = RenderModes.Normal;
                }

                IntPtr rightEyeWindow = IntPtr.Zero;
                if (simSettings.RenderMode == RenderModes.Stereo)
                {
                    rightEyeWindow = SpawnRightEyeWindow();
                }

                // Start the simulator game entry point
                using (var game = new SimulatorGame(simSettings, rightEyeWindow))
                {
                    // Make sure the XNA game window (left eye) displays as a full screen window
                    // just as the one we just created for the right eye
                    var gameForm = (Form)System.Windows.Forms.Control.FromHandle(game.Window.Handle);
                    gameForm.FormBorderStyle = FormBorderStyle.None;
                    gameForm.LostFocus      += (sender, e) => game.IsCapturingMouse = false;
                    gameForm.GotFocus       += (sender, e) => Game_GotFocus(game);
                    gameForm.MouseClick     += (sender, e) =>
                    {
                        if (e.Button == MouseButtons.Right)
                        {
                            Game_MouseRightClick(game);
                        }
                    };

                    // Name the window according to mode
                    gameForm.Text = (simSettings.RenderMode == RenderModes.Stereo)
                                        ? "A²DS Stereoscopy (left eye)"
                                        : "A²DS";

                    _settingsController = new SettingsController(gameForm);

                    // Hook the settings controller to the simulator by events, so changes in PID settings causes
                    // autopilot to use new PID settings.
                    _settingsController.PIDSettingsChanged +=
                        () => game.SetPIDSetup(_settingsController.CurrentPIDSetup);

                    // Run the game code
                    game.Run();
                }
            }
            catch (Exception e)
            {
                string msg = "Error occured!\n\n" + e;
                Console.WriteLine(e);
                MessageBox.Show(msg);
            }
        }