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); }
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(); }
/// <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 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 -----"); }
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(); }
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(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 -----"); }
private static void Init() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //DualityApp.PluginManager.PluginsReady += DualityApp_PluginsReady; DualityApp.Init( DualityApp.ExecutionContext.Game, new DefaultAssemblyLoader(), null); // Initialize the plugin manager for the editor. We'll use the same loader as the core. pluginManager.Init(DualityApp.PluginManager.AssemblyLoader); // Need to load editor plugins before initializing the graphics context, so the backend is available pluginManager.LoadPlugins(); // Need to initialize graphics context and default content before instantiating anything that could require any of them InitMainGraphicsContext(); DualityApp.InitPostWindow(); //LoadUserData(); pluginManager.InitPlugins(); // Set up core plugin reloader //corePluginReloader = new ReloadCorePluginDialog(mainForm); mainWindow = new MainWindow(); // Register events mainWindow.Activated += mainWindow_Activated; mainWindow.Deactivate += mainWindow_Deactivate; Scene.Leaving += Scene_Leaving; Scene.Entered += Scene_Entered; Application.Idle += Application_Idle; // Enter a new, empty Scene, which will trigger the usual updates //Scene.SwitchTo(null, true); Scene.SwitchTo(new EditorLevelHandler("prince", "04_carrot1n"), true); mainWindow.Show(); Application.Run(); }
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() { 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; ContentProvider.InitDefaultContent(); // 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(); }
// This gets called when the drawing surface is ready protected override void OnLoad(EventArgs e) { base.OnLoad(e); var logfile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "logfile.txt"); DualityApp.Init(DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game, new[] { "logfile", logfile }); //DualityApp.UserDataChanged += launcherWindow.OnUserDataChanged; // Initialize default content //launcherWindow.MakeCurrent(); Log.Core.Write("OpenGL initialized"); Log.Core.PushIndent(); Log.Editor.Write("Vendor: {0}", GL.GetString(StringName.Vendor)); Log.Editor.Write("Version: {0}", GL.GetString(StringName.Version)); Log.Editor.Write("Renderer: {0}", GL.GetString(StringName.Renderer)); Log.Editor.Write("Shading language version: {0}", GL.GetString(StringName.ShadingLanguageVersion)); Log.Core.PopIndent(); // DualityApp.TargetResolution = new Vector2(view.Size.Width, view.Size.Height); // DualityApp.TargetMode = view.Context.ApplicationInfo. GraphicsMode; /* DEBT: waiting for duality not sure we need to init the default content */ Duality.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(new ContentRef <Scene>(Scene.Load <Scene>(@"Data/SceneTest.Scene.res"))); }
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(); } }
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; } }
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)) { // 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; ContentProvider.InitDefaultContent(); // 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(); } }
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); }
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)) { DualityApp.UserDataChanged += launcherWindow.OnUserDataChanged; // 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(); Log.Core.Write("OpenGL initialized"); Log.Core.PushIndent(); Log.Editor.Write("Vendor: {0}", GL.GetString(StringName.Vendor)); Log.Editor.Write("Version: {0}", GL.GetString(StringName.Version)); Log.Editor.Write("Renderer: {0}", GL.GetString(StringName.Renderer)); Log.Editor.Write("Shading language version: {0}", GL.GetString(StringName.ShadingLanguageVersion)); Log.Core.PopIndent(); if (ValidateMinimumGPUSpec() == false) { DualityApp.Terminate(); DisplayDevice.Default.RestoreResolution(); return; } 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; SetVSyncMode(launcherWindow); launcherWindow.Run(); // Shut down the DualityApp DualityApp.Terminate(); DisplayDevice.Default.RestoreResolution(); } }
private static void Main(string[] args) { ConsoleUtils.TryEnableUnicode(); // Try to render Jazz2 logo if (ConsoleImage.RenderFromManifestResource("ConsoleImage.udl", out int imageTop) && imageTop >= 0) { int width = Console.BufferWidth; // Show version number in the right corner string appVersion = "v" + Game.App.AssemblyVersion; int currentCursorTop = Console.CursorTop; Console.SetCursorPosition(width - appVersion.Length - 2, imageTop + 1); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine(appVersion); Console.ResetColor(); Console.CursorTop = currentCursorTop; } // Override working directory try { Environment.CurrentDirectory = Jazz2.Game.App.AssemblyPath; } catch (Exception ex) { Log.Write(LogType.Warning, "Cannot override working directory: " + ex); } // Process parameters int port; if (!TryRemoveArg(ref args, "/port:", out port)) { port = 0; } string overrideHostname; if (!TryRemoveArg(ref args, "/override-hostname:", out overrideHostname)) { overrideHostname = null; } string name; if (!TryRemoveArg(ref args, "/name:", out name) || string.IsNullOrWhiteSpace(name)) { name = "Unnamed server"; } int minPlayers; if (!TryRemoveArg(ref args, "/min-players:", out minPlayers)) { minPlayers = 0; } int maxPlayers; if (!TryRemoveArg(ref args, "/max-players:", out maxPlayers)) { maxPlayers = 0; } string levelName; if (!TryRemoveArg(ref args, "/level:", out levelName)) { levelName = "unknown/battle2"; } string levelTypeRaw; MultiplayerLevelType levelType; if (!TryRemoveArg(ref args, "/level-type:", out levelTypeRaw) || !Enum.TryParse(levelTypeRaw, out levelType)) { levelType = MultiplayerLevelType.Battle; } string configPath; if (!TryRemoveArg(ref args, "/config:", out configPath)) { if (File.Exists("Jazz2.Server.default")) { configPath = "Jazz2.Server.default"; } else { configPath = null; } } bool startUnloaded = TryRemoveArg(ref args, "/unloaded"); bool isPrivate = TryRemoveArg(ref args, "/private"); bool enableUPnP = TryRemoveArg(ref args, "/upnp"); // Initialization Version v = Assembly.GetEntryAssembly().GetName().Version; byte neededMajor = (byte)v.Major; byte neededMinor = (byte)v.Minor; byte neededBuild = (byte)v.Build; Log.Write(LogType.Info, "Starting server..."); Log.PushIndent(); // Start game server DualityApp.Init(DualityApp.ExecutionContext.Server, null, args); AsyncManager.Init(); gameServer = new GameServer(); if (overrideHostname != null) { try { gameServer.OverrideHostname(overrideHostname); } catch { Log.Write(LogType.Error, "Cannot set override public hostname!"); } } gameServer.Run(configPath, port, name, minPlayers, maxPlayers, isPrivate, enableUPnP, neededMajor, neededMinor, neededBuild); Log.PopIndent(); if (!startUnloaded) { if (gameServer.ActivePlaylistIndex == -1) { gameServer.ChangeLevel(levelName, levelType); } else { gameServer.ChangeLevelFromPlaylist(gameServer.ActivePlaylistIndex); } Log.Write(LogType.Info, "Ready to play!"); } else { Log.Write(LogType.Verbose, "Server is unloaded."); } Log.Write(LogType.Info, ""); // Check for updates Updater.CheckUpdates(OnCheckUpdates); // Processing of console commands ProcessConsoleCommands(); // Shutdown Log.Write(LogType.Info, "Closing..."); gameServer.Dispose(); }