Exemple #1
0
        public void BeforeTest(TestDetails details)
        {
            Console.WriteLine("----- Beginning Duality environment setup -----");

            // Set environment directory to Duality binary directory
            this.oldEnvDir = Environment.CurrentDirectory;
            string codeBaseURI  = typeof(DualityApp).Assembly.CodeBase;
            string codeBasePath = codeBaseURI.StartsWith("file:") ? codeBaseURI.Remove(0, "file:".Length) : codeBaseURI;

            codeBasePath = codeBasePath.TrimStart('/');
            Environment.CurrentDirectory = Path.GetDirectoryName(codeBasePath);

            // Add some Console logs manually for NUnit
            if (!Log.Game.Outputs.OfType <ConsoleLogOutput>().Any())
            {
                if (this.consoleLogOutput == null)
                {
                    this.consoleLogOutput = new ConsoleLogOutput();
                }
                Log.Game.AddOutput(this.consoleLogOutput);
                Log.Core.AddOutput(this.consoleLogOutput);
                Log.Editor.AddOutput(this.consoleLogOutput);
            }

            // Initialize Duality
            DualityApp.Init(DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game);

            // Manually register pseudo-plugin for the Unit Testing Assembly
            this.unitTestPlugin = DualityApp.LoadPlugin(typeof(DualityTestsPlugin).Assembly, codeBasePath);

            // Create a dummy window, to get access to all the device contexts
            if (this.dummyWindow == null)
            {
                this.dummyWindow = new GameWindow(800, 600);
                this.dummyWindow.Context.LoadAll();
                this.dummyWindow.Visible = true;
                this.dummyWindow.Context.Update(this.dummyWindow.WindowInfo);
                this.dummyWindow.MakeCurrent();
                this.dummyWindow.ProcessEvents();
                DualityApp.TargetResolution = new Vector2(this.dummyWindow.Width, this.dummyWindow.Height);
                DualityApp.TargetMode       = this.dummyWindow.Context.GraphicsMode;
                DualityApp.InitGraphics();
            }

            // Load local testing memory
            TestHelper.LocalTestMemory = Formatter.TryReadObject <TestMemory>(TestHelper.LocalTestMemoryFilePath, FormattingMethod.Xml);

            Console.WriteLine("----- Duality environment setup complete -----");
        }
Exemple #2
0
        public static void Main()
        {
            DualityApp.Init(DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game);
            using (DualityDebuggingTester launcherWindow = new DualityDebuggingTester(
                       DualityApp.UserData.GfxWidth,
                       DualityApp.UserData.GfxHeight,
                       DualityApp.DefaultMode,
                       DualityApp.AppData.AppName,
                       GameWindowFlags.Default))
            {
                // Initialize default content
                launcherWindow.MakeCurrent();
                DualityApp.TargetResolution = new Vector2(launcherWindow.Width, launcherWindow.Height);
                DualityApp.TargetMode       = launcherWindow.Context.GraphicsMode;
                DualityApp.InitGraphics();

                // Run tests
                BitmapDebuggerVisualizer.TestShow(Pixmap.DualityIcon.Res);
                BitmapDebuggerVisualizer.TestShow(Pixmap.DualityIcon.Res.MainLayer);
                BitmapDebuggerVisualizer.TestShow(Texture.DualityIcon.Res);
                BitmapDebuggerVisualizer.TestShow(Font.GenericMonospace10.Res.Material.MainTexture.Res);
            }
            DualityApp.Terminate();
        }
Exemple #3
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);

            int  windowWidth  = DualityApp.UserData.GfxWidth;
            int  windowHeight = DualityApp.UserData.GfxHeight;
            bool isFullscreen = (DualityApp.UserData.GfxMode == ScreenMode.Fullscreen || DualityApp.UserData.GfxMode == ScreenMode.Native) && !isDebugging;

            if (DualityApp.UserData.GfxMode == ScreenMode.Native && !isDebugging)
            {
                windowWidth  = DisplayDevice.Default.Width;
                windowHeight = DisplayDevice.Default.Height;
            }

            using (DualityLauncher launcherWindow = new DualityLauncher(
                       windowWidth,
                       windowHeight,
                       DualityApp.DefaultMode,
                       DualityApp.AppData.AppName,
                       isFullscreen ? GameWindowFlags.Fullscreen : GameWindowFlags.Default))
            {
                DualityApp.UserDataChanged += launcherWindow.OnUserDataChanged;

                // Retrieve icon from executable file and set it as window icon
                string executablePath = System.IO.Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().Location);
                if (System.IO.File.Exists(executablePath))
                {
                    launcherWindow.Icon = System.Drawing.Icon.ExtractAssociatedIcon(executablePath);
                }

                // Go into native fullscreen mode
                if (DualityApp.UserData.GfxMode == ScreenMode.FullWindow && !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;
                }

                // Specify additional window settings and initialize default content
                launcherWindow.MakeCurrent();
                launcherWindow.CursorVisible = isDebugging || DualityApp.UserData.SystemCursorVisible;
                launcherWindow.VSync         = (isProfiling || isDebugging || DualityApp.UserData.RefreshMode != RefreshMode.VSync) ? VSyncMode.Off : VSyncMode.On;
                DualityApp.TargetResolution  = new Vector2(launcherWindow.ClientSize.Width, launcherWindow.ClientSize.Height);
                DualityApp.TargetMode        = launcherWindow.Context.GraphicsMode;
                DualityApp.InitGraphics();

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

                // Debug Logs
                Log.Core.Write("Graphics window initialized: {0}Mode: {1}{0}VSync: {2}{0}SwapInterval: {3}{0}Flags: {4}{0}",
                               Environment.NewLine,
                               launcherWindow.Context.GraphicsMode,
                               launcherWindow.VSync,
                               launcherWindow.Context.SwapInterval,
                               new[] { isDebugging ? "Debugging" : null, isProfiling ? "Profiling" : null, isRunFromEditor ? "RunFromEditor" : null }.NotNull().ToString(", "));

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

                // Run the DualityApp
                launcherWindow.Run();

                // Shut down the DualityApp
                DualityApp.Terminate();
                DisplayDevice.Default.RestoreResolution();
            }
        }