protected override void OnContextLost(EventArgs e) { base.OnContextLost(e); // Reinitialize core DualityApp.Terminate(); DualityApp.Init(DualityApp.ExecutionContext.Game, null, null); ContentResolver.Current.Init(); viewportWidth = Width; viewportHeight = Height; DualityApp.WindowSize = new Point2(viewportWidth, viewportHeight); INativeWindow window = DualityApp.OpenWindow(new WindowOptions()); ContentResolver.Current.InitPostWindow(); // Reinitialize input TouchButtons = null; InitializeInput(); // Reinitialize the game current = new App(window); current.ShowMainMenu(false); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); viewportWidth = Width; viewportHeight = Height; // ToDo: Create Android-specific AssemblyLoader DualityApp.Init(DualityApp.ExecutionContext.Game, /*new DefaultAssemblyLoader()*/ null, null); DualityApp.WindowSize = new Point2(viewportWidth, viewportHeight); INativeWindow window = DualityApp.OpenWindow(new WindowOptions { ScreenMode = ScreenMode.Window }); FocusableInTouchMode = true; RequestFocus(); InitializeInput(); controller = new Controller(window); controller.ShowMainMenu(); // Run the render loop Run(); }
private static void Main(string[] args) { // Override working directory Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); DualityApp.Init(DualityApp.ExecutionContext.Game, new DefaultAssemblyLoader(), args); ScreenMode newScreenMode; switch (Preferences.Get <int>("Screen", 0)) { default: case 0: newScreenMode = ScreenMode.Window; break; case 1: newScreenMode = ScreenMode.FullWindow; break; } using (INativeWindow window = DualityApp.OpenWindow(new WindowOptions { Title = AssemblyTitle, RefreshMode = (args.Contains("/nv") ? RefreshMode.NoSync : (args.Contains("/mv") ? RefreshMode.ManualSync : RefreshMode.VSync)), Size = LevelRenderSetup.TargetSize, ScreenMode = newScreenMode })) { current = new App(window); current.ShowMainMenu(); window.Run(); } DualityApp.Terminate(); // ToDo: Linux-specific workaround Environment.Exit(0); }
/// <summary> /// Initializes duality but does not yet run it. /// </summary> /// <param name="launcherArgs"></param> public DualityLauncher(LauncherArgs launcherArgs = null) { if (launcherArgs == null) { launcherArgs = new LauncherArgs(); } System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture; // Set up console logging this.AddGlobalOutput(new ConsoleLogOutput()); // Set up file logging try { StreamWriter logfileWriter = new StreamWriter("logfile.txt"); logfileWriter.AutoFlush = true; this.disposables.Push(logfileWriter); this.AddGlobalOutput(new TextWriterLogOutput(logfileWriter)); } catch (Exception e) { Logs.Core.WriteWarning("Text Logfile unavailable: {0}", LogFormat.Exception(e)); } // Set up a global exception handler to log errors AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // Write initial log message before actually booting Duality Logs.Core.Write("Running DualityLauncher with flags: {1}{0}", Environment.NewLine, launcherArgs); // Initialize the Duality core DualityApp.Init( DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game, new DefaultAssemblyLoader(), launcherArgs); // Open up a new window WindowOptions options = new WindowOptions { Size = DualityApp.UserData.Instance.WindowSize, ScreenMode = launcherArgs.IsDebugging ? ScreenMode.Window : DualityApp.UserData.Instance.WindowMode, RefreshMode = launcherArgs.IsProfiling ? RefreshMode.NoSync : DualityApp.UserData.Instance.WindowRefreshMode, Title = DualityApp.AppData.Instance.AppName, SystemCursorVisible = launcherArgs.IsDebugging || DualityApp.UserData.Instance.SystemCursorVisible }; this.window = DualityApp.OpenWindow(options); }
public static async void Main() { DualityApp.Init(DualityApp.ExecutionContext.Game, null, null); // Download all needed files bool assetsLoaded = await DownloadFilesToCache(new[] { "Content/Main.dz", "Content/i18n/en.res", "Content/Tilesets/labrat1n.set", "Content/Tilesets/psych2.set", "Content/Tilesets/diam2.set", "Content/Episodes/share/01_share1.level", "Content/Episodes/share/02_share2.level", "Content/Episodes/share/03_share3.level", "Content/Episodes/share/Episode.res", "Content/Episodes/share/Logo.png" }); if (!assetsLoaded) { using (var app = (JSObject)Runtime.GetGlobalObject("App")) { app.Invoke("loadingFailed"); } return; } i18n.Language = Preferences.Get <string>("Language", "en"); ContentResolver.Current.Init(); INativeWindow window = DualityApp.OpenWindow(new WindowOptions { Title = AssemblyTitle, RefreshMode = RefreshMode.VSync, Size = LevelRenderSetup.TargetSize, ScreenMode = ScreenMode.Window }); ContentResolver.Current.InitPostWindow(); current = new App(window); current.ShowMainMenu(false); using (var app = (JSObject)Runtime.GetGlobalObject("App")) { app.Invoke("ready"); } window.Run(); }
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('/'); Console.WriteLine("Testing Core Assembly: {0}", codeBasePath); Environment.CurrentDirectory = Path.GetDirectoryName(codeBasePath); // Add some Console logs manually for NUnit if (!Log.Core.Outputs.OfType <TextWriterLogOutput>().Any(o => o.Target == Console.Out)) { if (this.consoleLogOutput == null) { this.consoleLogOutput = new TextWriterLogOutput(Console.Out); } Log.AddGlobalOutput(this.consoleLogOutput); } // Initialize Duality DualityApp.Init( DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game, new DefaultPluginLoader(), null); // Manually register pseudo-plugin for the Unit Testing Assembly this.unitTestPlugin = DualityApp.PluginManager.LoadPlugin( typeof(DualityTestsPlugin).Assembly, codeBasePath); // Create a dummy window, to get access to all the device contexts if (this.dummyWindow == null) { WindowOptions options = new WindowOptions { Width = 800, Height = 600 }; this.dummyWindow = DualityApp.OpenWindow(options); } // Load local testing memory TestHelper.LocalTestMemory = Serializer.TryReadObject <TestMemory>(TestHelper.LocalTestMemoryFilePath, typeof(XmlSerializer)); Console.WriteLine("----- Duality environment setup complete -----"); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); // Initialize core // ToDo: Create Android-specific AssemblyLoader DualityApp.Init(DualityApp.ExecutionContext.Game, null, null); // Check if graphics backend is supported if (DualityApp.GraphicsBackend is DummyGraphicsBackend) { MainActivity mainActivity = Context as MainActivity; if (mainActivity != null) { mainActivity.ShowInfoScreen("This device is not powerful enough", "OpenGL ES 3.0 support is required to run this application.", false); } return; } i18n.Language = Preferences.Get <string>("Language", "en"); ContentResolver.Current.Init(); viewportWidth = Width; viewportHeight = Height; DualityApp.WindowSize = new Point2(viewportWidth, viewportHeight); INativeWindow window = DualityApp.OpenWindow(new WindowOptions { ScreenMode = ScreenMode.Immersive }); ContentResolver.Current.InitPostWindow(); // Initialize input FocusableInTouchMode = true; RequestFocus(); InitializeInput(); // Initialize the game current = new App(window); current.PlayCinematics("intro", endOfStream => { current.ShowMainMenu(endOfStream); }); // Run the render loop Run(60); }
public void BeforeTest(ITest details) { Console.WriteLine("----- Beginning Duality environment setup -----"); // Set environment directory to Duality binary directory _oldEnvDir = Environment.CurrentDirectory; var codeBaseUri = typeof(DualityApp).Assembly.CodeBase; var codeBasePath = codeBaseUri.StartsWith("file:") ? codeBaseUri.Remove(0, "file:".Length) : codeBaseUri; codeBasePath = codeBasePath.TrimStart('/'); Console.WriteLine("Testing Core Assembly: {0}", codeBasePath); Environment.CurrentDirectory = Path.GetDirectoryName(codeBasePath); // Add some Console logs manually for NUnit if (_consoleLogOutput == null) { _consoleLogOutput = new TextWriterLogOutput(Console.Out); } Log.AddGlobalOutput(_consoleLogOutput); // Initialize Duality DualityApp.Init( DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game, new DefaultPluginLoader(), null); // Create a dummy window, to get access to all the device contexts if (_dummyWindow == null) { var options = new WindowOptions { Width = 800, Height = 600 }; _dummyWindow = DualityApp.OpenWindow(options); } // Load local testing memory TestHelper.LocalTestMemory = Serializer.TryReadObject <TestMemory>(TestHelper.LocalTestMemoryFilePath, typeof(XmlSerializer)); Console.WriteLine("----- Duality environment setup complete -----"); }
private static void Main(string[] args) { // Override working directory Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); DualityApp.Init(DualityApp.ExecutionContext.Game, new DefaultAssemblyLoader(), args); using (INativeWindow window = DualityApp.OpenWindow(new WindowOptions { Title = AssemblyTitle, RefreshMode = (args.Contains("/nv") ? RefreshMode.NoSync : (args.Contains("/mv") ? RefreshMode.ManualSync : RefreshMode.VSync)), Size = LevelRenderSetup.TargetSize })) { controller = new Controller(window); controller.ShowMainMenu(); window.Run(); } DualityApp.Terminate(); // ToDo: Linux-specific workaround Environment.Exit(0); }
public static void Main() { DualityApp.Init( DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game, new DefaultAssemblyLoader(), null); WindowOptions options = new WindowOptions { Size = new Point2(800, 600), }; using (INativeWindow launcherWindow = DualityApp.OpenWindow(options)) { // 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(); }
public static void Main(string[] args) { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture; bool isDebugging = System.Diagnostics.Debugger.IsAttached || args.Contains(DualityApp.CmdArgDebug); bool isRunFromEditor = args.Contains(DualityApp.CmdArgEditor); bool isProfiling = args.Contains(DualityApp.CmdArgProfiling); if (isDebugging || isRunFromEditor) { ShowConsole(); } // Set up console logging Log.AddGlobalOutput(new ConsoleLogOutput()); // Set up file logging StreamWriter logfileWriter = null; TextWriterLogOutput logfileOutput = null; try { logfileWriter = new StreamWriter("logfile.txt"); logfileWriter.AutoFlush = true; logfileOutput = new TextWriterLogOutput(logfileWriter); Log.AddGlobalOutput(logfileOutput); } catch (Exception e) { Log.Core.WriteWarning("Text Logfile unavailable: {0}", Log.Exception(e)); } // Set up a global exception handler to log errors AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // Write initial log message before actually booting Duality Log.Core.Write("Running DualityLauncher with flags: {1}{0}", Environment.NewLine, new[] { isDebugging ? "Debugging" : null, isProfiling ? "Profiling" : null, isRunFromEditor ? "RunFromEditor" : null }.NotNull().ToString(", ")); // Initialize the Duality core DualityApp.Init( DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game, new DefaultPluginLoader(), args); // Open up a new window WindowOptions options = new WindowOptions { Width = DualityApp.UserData.GfxWidth, Height = DualityApp.UserData.GfxHeight, ScreenMode = isDebugging ? ScreenMode.Window : DualityApp.UserData.GfxMode, RefreshMode = (isDebugging || isProfiling) ? RefreshMode.NoSync : DualityApp.UserData.RefreshMode, Title = DualityApp.AppData.AppName, SystemCursorVisible = isDebugging || DualityApp.UserData.SystemCursorVisible }; using (INativeWindow window = DualityApp.OpenWindow(options)) { // Load the starting Scene Scene.SwitchTo(DualityApp.AppData.StartScene); // Enter the applications update / render loop window.Run(); } // Shut down the Duality core DualityApp.Terminate(); // Clean up the log file if (logfileWriter != null) { Log.RemoveGlobalOutput(logfileOutput); logfileWriter.Flush(); logfileWriter.Close(); logfileWriter = null; logfileOutput = null; } }
private static void Main(string[] args) { // Override working directory try { Environment.CurrentDirectory = AssemblyPath; } catch (Exception ex) { Console.WriteLine("Cannot override current directory: " + ex); } DualityApp.Init(DualityApp.ExecutionContext.Game, new DefaultAssemblyLoader(), args); ScreenMode screenMode; switch (Preferences.Get <int>("Screen", 0)) { default: case 0: screenMode = ScreenMode.Window; break; case 1: screenMode = ScreenMode.FullWindow; break; } RefreshMode refreshMode = (RefreshMode)Preferences.Get <int>("RefreshMode", (int)RefreshMode.VSync); i18n.Language = Preferences.Get <string>("Language", "en"); ContentResolver.Current.Init(); using (INativeWindow window = DualityApp.OpenWindow(new WindowOptions { Title = AssemblyTitle, RefreshMode = refreshMode, Size = LevelRenderSetup.TargetSize, ScreenMode = screenMode })) { ContentResolver.Current.InitPostWindow(); current = new App(window); bool suppressMainMenu = false; #if MULTIPLAYER for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("/connect:", StringComparison.InvariantCulture)) { int idx = args[i].LastIndexOf(':', 10); if (idx == -1) { continue; } int port; if (!int.TryParse(args[i].Substring(idx + 1), NumberStyles.Any, CultureInfo.InvariantCulture, out port)) { continue; } try { System.Net.IPAddress ip = Lidgren.Network.NetUtility.Resolve(args[i].Substring(9, idx - 9)); current.ConnectToServer(new System.Net.IPEndPoint(ip, port)); suppressMainMenu = true; } catch { // Nothing to do... } } } #endif if (!suppressMainMenu) { current.PlayCinematics("intro", endOfStream => { current.ShowMainMenu(endOfStream); }); } window.Run(); } DualityApp.Terminate(); // ToDo: Linux-specific workaround Environment.Exit(0); }