Initialize() static private method

Initializes audio. A call to Deinitialize must be made when terminating the program.
static private Initialize ( ) : bool
return bool
コード例 #1
0
ファイル: Program.cs プロジェクト: AlteredCarrot71/OpenBVExp
        /// <summary>Initializes the program. A matching call to deinitialize must be made when the program is terminated.</summary>
        /// <returns>Whether the initialization was successful.</returns>
        private static bool Initialize()
        {
            if (!Plugins.LoadPlugins())
            {
                return(false);
            }
            if (!Screen.Initialize())
            {
                MessageBox.Show("SDL failed to initialize the video subsystem.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return(false);
            }
            if (!Joysticks.Initialize())
            {
                MessageBox.Show("SDL failed to initialize the joystick subsystem.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return(false);
            }
            Sounds.Initialize();
            // begin HACK //
            const double degrees = 0.0174532925199433;

            World.VerticalViewingAngle         = 45.0 * degrees;
            World.HorizontalViewingAngle       = 2.0 * Math.Atan(Math.Tan(0.5 * World.VerticalViewingAngle) * World.AspectRatio);
            World.OriginalVerticalViewingAngle = World.VerticalViewingAngle;
            World.ExtraViewingDistance         = 50.0;
            World.ForwardViewingDistance       = (double)Interface.CurrentOptions.ViewingDistance;
            World.BackwardViewingDistance      = 0.0;
            World.BackgroundImageDistance      = (double)Interface.CurrentOptions.ViewingDistance;
            // end HACK //
            ClearLogFile();
            return(true);
        }
コード例 #2
0
ファイル: Gamewindow.cs プロジェクト: piotrulos/OpenBVE
        protected override void OnLoad(EventArgs e)
        {
            KeyDown   += Program.keyDownEvent;
            KeyUp     += Program.keyUpEvent;
            MouseDown += Program.MouseEvent;
            MouseUp   += Program.MouseEvent;
            FileDrop  += Program.FileDrop;
            Program.ResetCamera();
            World.BackgroundImageDistance = 600.0;
            World.ForwardViewingDistance  = 600.0;
            World.BackwardViewingDistance = 0.0;
            World.ExtraViewingDistance    = 50.0;

            Renderer.Initialize();
            Renderer.InitializeLighting();
            Sounds.Initialize();
            Program.UpdateViewport();
            if (Program.processCommandLineArgs)
            {
                Program.processCommandLineArgs = false;
                for (int i = 0; i < Program.commandLineArguments.Length; i++)
                {
                    if (!Program.SkipArgs[i] && System.IO.File.Exists(Program.commandLineArguments[i]))
                    {
                        currentlyLoading     = true;
                        Program.CurrentRoute = Program.commandLineArguments[i];
                        Program.LoadRoute();
                        Program.UpdateCaption();
                        break;
                    }
                }
            }
        }
コード例 #3
0
        internal static void StartLoopEx(FormMain.MainDialogResult result)
        {
            Sounds.Initialize();
            //Process extra command line arguments supplied
            if (result.InitialStation != null)
            {
                //We have supplied a station name or index to the loader
                Game.InitialStationName = result.InitialStation;
            }
            if (result.StartTime != default(double))
            {
                Game.InitialStationTime = result.StartTime;
            }
            if (result.AIDriver == true)
            {
                Game.InitialAIDriver = true;
            }
            if (result.FullScreen == true)
            {
                Interface.CurrentOptions.FullscreenMode = true;
            }
            if (result.Width != default(double) && result.Height != default(double))
            {
                if (Interface.CurrentOptions.FullscreenMode == true)
                {
                    Interface.CurrentOptions.FullscreenWidth  = result.Width;
                    Interface.CurrentOptions.FullscreenHeight = result.Height;
                }
                else
                {
                    Interface.CurrentOptions.WindowWidth  = result.Width;
                    Interface.CurrentOptions.WindowHeight = result.Height;
                }
            }

            if (Interface.CurrentOptions.FullscreenMode)
            {
                Program.FileSystem.AppendToLogFile("Initialising full-screen game window of size " + Interface.CurrentOptions.FullscreenWidth + " x " + Interface.CurrentOptions.FullscreenHeight);
            }
            else
            {
                Program.FileSystem.AppendToLogFile("Initialising game window of size " + Interface.CurrentOptions.WindowWidth + " x " + Interface.CurrentOptions.WindowHeight);
            }
            try
            {
                Screen.Initialize();
                currentResult = result;
                Program.currentGameWindow.Closing += OpenTKQuit;
                Program.currentGameWindow.Run();
            }
            catch (Exception)
            {
                MessageBox.Show("显示设置配置错误!\n请注意:在全屏模式下,任何非设备默认或最大分辨率的设置可能不受支持。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
        }
コード例 #4
0
ファイル: MainLoop.cs プロジェクト: libl785/OpenBVE
        internal static void StartLoopEx(formMain.MainDialogResult result)
        {
            LibRender.Renderer.currentHost = Program.CurrentHost;
            Sounds.Initialize();
            //Process extra command line arguments supplied
            if (result.InitialStation != null)
            {
                //We have supplied a station name or index to the loader
                Game.InitialStationName = result.InitialStation;
            }
            if (result.StartTime != default(double))
            {
                Game.InitialStationTime = result.StartTime;
            }
            if (result.AIDriver == true)
            {
                Game.InitialAIDriver = true;
            }
            if (result.FullScreen == true)
            {
                Interface.CurrentOptions.FullscreenMode = true;
            }
            if (result.Width != default(double) && result.Height != default(double))
            {
                if (Interface.CurrentOptions.FullscreenMode == true)
                {
                    Interface.CurrentOptions.FullscreenWidth  = result.Width;
                    Interface.CurrentOptions.FullscreenHeight = result.Height;
                }
                else
                {
                    Interface.CurrentOptions.WindowWidth  = result.Width;
                    Interface.CurrentOptions.WindowHeight = result.Height;
                }
            }

            if (Interface.CurrentOptions.FullscreenMode)
            {
                Program.FileSystem.AppendToLogFile("Initialising full-screen game window of size " + Interface.CurrentOptions.FullscreenWidth + " x " + Interface.CurrentOptions.FullscreenHeight);
            }
            else
            {
                Program.FileSystem.AppendToLogFile("Initialising game window of size " + Interface.CurrentOptions.WindowWidth + " x " + Interface.CurrentOptions.WindowHeight);
            }
            Screen.Initialize();
            currentResult = result;
            Program.currentGameWindow.Closing += OpenTKQuit;
            Program.currentGameWindow.Run();
        }
コード例 #5
0
ファイル: MainLoop.cs プロジェクト: City-busz/OpenBVE
//		internal static formRouteInformation RouteInformationForm;
//		internal static Thread RouteInfoThread;
//		internal static bool RouteInfoActive
//		{
//			get
//			{
//				return RouteInformationForm != null && RouteInformationForm.IsHandleCreated && RouteInformationForm.Visible;
//			}
//		}


//		internal static AppDomain RouteInfoFormDomain;

        internal static void StartLoopEx(formMain.MainDialogResult result)
        {
            Sounds.Initialize();
            //Process extra command line arguments supplied
            if (result.InitialStation != null)
            {
                //We have supplied a station name or index to the loader
                Game.InitialStationName = result.InitialStation;
            }
            if (result.StartTime != default(double))
            {
                Game.InitialStationTime = result.StartTime;
            }
            if (result.AIDriver == true)
            {
                Game.InitialAIDriver = true;
            }
            if (result.FullScreen == true)
            {
                Interface.CurrentOptions.FullscreenMode = true;
            }
            if (result.Width != default(double) && result.Height != default(double))
            {
                if (Interface.CurrentOptions.FullscreenMode == true)
                {
                    Interface.CurrentOptions.FullscreenWidth  = result.Width;
                    Interface.CurrentOptions.FullscreenHeight = result.Height;
                }
                else
                {
                    Interface.CurrentOptions.WindowWidth  = result.Width;
                    Interface.CurrentOptions.WindowHeight = result.Height;
                }
            }
            Screen.Initialize();
            currentResult = result;
            GraphicsMode currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8,
                                                                Interface.CurrentOptions.AntiAliasingLevel);

            /*
             * TODO: This should be able to be moved back into the screen initialisation file
             */
            if (Interface.CurrentOptions.FullscreenMode)
            {
                IList <DisplayResolution> resolutions = OpenTK.DisplayDevice.Default.AvailableResolutions;
                bool resolutionFound = false;
                for (int i = 0; i < resolutions.Count; i++)
                {
                    //Test each resolution
                    if (resolutions[i].Width == Interface.CurrentOptions.FullscreenWidth &&
                        resolutions[i].Height == Interface.CurrentOptions.FullscreenHeight &&
                        resolutions[i].BitsPerPixel == Interface.CurrentOptions.FullscreenBits)
                    {
                        try
                        {
                            OpenTK.DisplayDevice.Default.ChangeResolution(resolutions[i]);
                            Program.currentGameWindow = new OpenBVEGame(resolutions[i].Width, resolutions[i].Height, currentGraphicsMode,
                                                                        GameWindowFlags.Default)
                            {
                                Visible     = true,
                                WindowState = WindowState.Fullscreen
                            };
                            resolutionFound = true;
                        }
                        catch
                        {
                            //Our resolution was in the list of available resolutions presented, but the graphics card driver failed to switch
                            MessageBox.Show("Failed to change to the selected full-screen resolution:" + Environment.NewLine +
                                            Interface.CurrentOptions.FullscreenWidth + " x " + Interface.CurrentOptions.FullscreenHeight +
                                            " " + Interface.CurrentOptions.FullscreenBits + "bit color" + Environment.NewLine +
                                            "Please check your resolution settings.", Application.ProductName, MessageBoxButtons.OK,
                                            MessageBoxIcon.Hand);
                            Program.RestartArguments = " ";
                            return;
                        }
                        break;
                    }
                }
                if (resolutionFound == false)
                {
                    //Our resolution was not found at all
                    MessageBox.Show(
                        "The graphics card driver reported that the selected resolution was not supported:" + Environment.NewLine +
                        Interface.CurrentOptions.FullscreenWidth + " x " + Interface.CurrentOptions.FullscreenHeight + " " +
                        Interface.CurrentOptions.FullscreenBits + "bit color" + Environment.NewLine +
                        "Please check your resolution settings.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    Program.RestartArguments = " ";
                    return;
                }
            }
            else
            {
                try
                {
                    Program.currentGameWindow = new OpenBVEGame(Interface.CurrentOptions.WindowWidth,
                                                                Interface.CurrentOptions.WindowHeight, currentGraphicsMode, GameWindowFlags.Default)
                    {
                        Visible = true
                    };
                }
                catch
                {
                    //Windowed mode failed to launch
                    MessageBox.Show("An error occured whilst tring to launch in windowed mode at resolution:" + Environment.NewLine +
                                    Interface.CurrentOptions.WindowWidth + " x " + Interface.CurrentOptions.WindowHeight + " " +
                                    Environment.NewLine +
                                    "Please check your resolution settings.", Application.ProductName, MessageBoxButtons.OK,
                                    MessageBoxIcon.Hand);
                    Program.RestartArguments = " ";
                    return;
                }
            }
            if (Program.currentGameWindow == null)
            {
                //We should never really get an unspecified error here, but it's good manners to handle all cases
                MessageBox.Show("An unspecified error occured whilst attempting to launch the graphics subsystem.",
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                Program.RestartArguments = " ";
                return;
            }

            Program.currentGameWindow.TargetUpdateFrequency = 0;
            Program.currentGameWindow.TargetRenderFrequency = 0;
            Program.currentGameWindow.VSync    = Interface.CurrentOptions.VerticalSynchronization ? VSyncMode.On : VSyncMode.Off;
            Program.currentGameWindow.Closing += OpenTKQuit;
            Program.currentGameWindow.Run();
        }