示例#1
0
文件: Program.cs 项目: ruzli/duality
        public static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;

            isDebugging = System.Diagnostics.Debugger.IsAttached || args.Contains(DualityApp.CmdArgDebug);
            isRunFromEditor = args.Contains(DualityApp.CmdArgEditor);
            isProfiling = args.Contains(DualityApp.CmdArgProfiling);
            if (isDebugging || isRunFromEditor) ShowConsole();

            DualityApp.Init(DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game, args);

            using (DualityLauncher launcherWindow = new DualityLauncher(
                DualityApp.UserData.GfxWidth,
                DualityApp.UserData.GfxHeight,
                DualityApp.DefaultMode,
                DualityApp.AppData.AppName,
                (DualityApp.UserData.GfxMode == ScreenMode.Fullscreen && !isDebugging) ? GameWindowFlags.Fullscreen : GameWindowFlags.Default))
            {
                // Retrieve icon from executable file and set it as window icon
                string executablePath = System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                launcherWindow.Icon = System.Drawing.Icon.ExtractAssociatedIcon(executablePath);

                // Go into native fullscreen mode
                if (DualityApp.UserData.GfxMode == ScreenMode.Native && !isDebugging)
                    launcherWindow.WindowState = WindowState.Fullscreen;

                if (DualityApp.UserData.GfxMode == ScreenMode.FixedWindow)
                    launcherWindow.WindowBorder = WindowBorder.Fixed;
                else if (DualityApp.UserData.GfxMode == ScreenMode.Window)
                    launcherWindow.WindowBorder = WindowBorder.Resizable;

                // Initialize default content
                launcherWindow.MakeCurrent();
                DualityApp.TargetResolution = new Vector2(launcherWindow.ClientSize.Width, launcherWindow.ClientSize.Height);
                DualityApp.TargetMode = launcherWindow.Context.GraphicsMode;
                ContentProvider.InitDefaultContent();

                // Input setup
                DualityApp.Mouse.Source = new GameWindowMouseInputSource(launcherWindow.Mouse, launcherWindow.SetMouseDeviceX, launcherWindow.SetMouseDeviceY);
                DualityApp.Keyboard.Source = new GameWindowKeyboardInputSource(launcherWindow.Keyboard);

                // Load the starting Scene
                Scene.SwitchTo(DualityApp.AppData.StartScene);

                // Run the DualityApp
                launcherWindow.CursorVisible = isDebugging || DualityApp.UserData.SystemCursorVisible;
                launcherWindow.VSync = (isProfiling || isDebugging) ? VSyncMode.Off : VSyncMode.On; // Don't limit frame rate when debugging.
                launcherWindow.Run();

                // Shut down the DualityApp
                DualityApp.Terminate();
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture   = System.Globalization.CultureInfo.InvariantCulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;

            isDebugging     = System.Diagnostics.Debugger.IsAttached || args.Contains(DualityApp.CmdArgDebug);
            isRunFromEditor = args.Contains(DualityApp.CmdArgEditor);
            isProfiling     = args.Contains(DualityApp.CmdArgProfiling);
            if (isDebugging || isRunFromEditor)
            {
                ShowConsole();
            }

            DualityApp.Init(DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game, args);

            using (DualityLauncher launcherWindow = new DualityLauncher(
                       DualityApp.UserData.GfxWidth,
                       DualityApp.UserData.GfxHeight,
                       DualityApp.DefaultMode,
                       DualityApp.AppData.AppName,
                       (DualityApp.UserData.GfxMode == ScreenMode.Fullscreen && !isDebugging) ? GameWindowFlags.Fullscreen : GameWindowFlags.Default))
            {
                // Retrieve icon from executable file and set it as window icon
                string executablePath = System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                launcherWindow.Icon = System.Drawing.Icon.ExtractAssociatedIcon(executablePath);

                // Go into native fullscreen mode
                if (DualityApp.UserData.GfxMode == ScreenMode.Native && !isDebugging)
                {
                    launcherWindow.WindowState = WindowState.Fullscreen;
                }

                if (DualityApp.UserData.GfxMode == ScreenMode.FixedWindow)
                {
                    launcherWindow.WindowBorder = WindowBorder.Fixed;
                }
                else if (DualityApp.UserData.GfxMode == ScreenMode.Window)
                {
                    launcherWindow.WindowBorder = WindowBorder.Resizable;
                }

                // Initialize default content
                launcherWindow.MakeCurrent();
                DualityApp.TargetResolution = new Vector2(launcherWindow.Width, launcherWindow.Height);
                DualityApp.TargetMode       = launcherWindow.Context.GraphicsMode;
                ContentProvider.InitDefaultContent();

                // Input setup
                DualityApp.Mouse.Source    = new OpenTKMouseInputSource(launcherWindow.Mouse, launcherWindow.SetMouseDeviceX, launcherWindow.SetMouseDeviceY);
                DualityApp.Keyboard.Source = new OpenTKKeyboardInputSource(launcherWindow.Keyboard);
                {
                    // Initialize Joystick manually, since launcherWindow.Joysticks doesn't work for some reason
                    launcherWindow.mainJoystickDriver = new OpenTK.Platform.Windows.WinMMJoystick();
                    if (launcherWindow.mainJoystickDriver != null && launcherWindow.mainJoystickDriver.Joysticks != null)
                    {
                        DualityApp.Joysticks.AddSource(launcherWindow.mainJoystickDriver.Joysticks.Select(j => new OpenTKJoystickInputSource(j)));
                    }
                    //DualityApp.Joysticks.AddSource(launcherWindow.Joysticks.Select(j => new OpenTKJoystickInputSource(j)));
                }

                // Load the starting Scene
                Scene.Current = DualityApp.AppData.StartScene.Res;

                // Run the DualityApp
                launcherWindow.CursorVisible = isDebugging || DualityApp.UserData.SystemCursorVisible;
                launcherWindow.VSync         = (isProfiling || isDebugging) ? VSyncMode.Off : VSyncMode.On;         // Don't limit frame rate when debugging.
                launcherWindow.Run();

                // Shut down the DualityApp
                DualityApp.Terminate();
            }
        }