private Engine(Settings settings) { Instance = this; _settings = settings ?? ConfigurationResolver.Load <Settings>(Path.Combine(ExePath, "settings.json")); if (_settings == null) { SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "No `setting.json`", "A `settings.json` has been created into ClassicUO main folder.\nPlease fill it!", SDL.SDL_GL_GetCurrentWindow()); Log.Message(LogTypes.Trace, "settings.json file not found"); _settings = new Settings(); _settings.Save(); IsQuitted = true; return; } TargetElapsedTime = TimeSpan.FromSeconds(1.0f / MAX_FPS); IsFixedTimeStep = _settings.FixedTimeStep; _graphicDeviceManager = new GraphicsDeviceManager(this); _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents; if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef)) { _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef; } _graphicDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8; _graphicDeviceManager.SynchronizeWithVerticalRetrace = false; _graphicDeviceManager.ApplyChanges(); _isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1"; _window = Window; Window.ClientSizeChanged += (sender, e) => { int width = Window.ClientBounds.Width; int height = Window.ClientBounds.Height; if (_isHighDPI) { width *= 2; height *= 2; } _graphicDeviceManager.PreferredBackBufferWidth = width; _graphicDeviceManager.PreferredBackBufferHeight = height; _graphicDeviceManager.ApplyChanges(); WorldViewportGump gump = _uiManager.GetByLocalSerial <WorldViewportGump>(); if (gump != null && _profileManager.Current.GameWindowFullSize) { gump.ResizeWindow(new Point(WindowWidth, WindowHeight)); } }; Window.AllowUserResizing = true; IsMouseVisible = true; }
private Engine(string[] args) { Instance = this; // By default try to load settings from main settings file _settings = ConfigurationResolver.Load <Settings>(Path.Combine(ExePath, SettingsFile)); // Try to apply any settings passed from the command-line/shortcut to what we loaded from file // NOTE: If nothing was loaded from settings file (file doesn't exist), then it will create // a new settings object and populate it with the passed settings ArgsParser(args, _settings); // If no still no settings after loading a file and parsing command-line settings, // then show an error, generate default settings file and exit if (_settings == null) { SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "No `" + SettingsFile + "`", "A `" + SettingsFile + "` has been created into ClassicUO main folder.\nPlease fill it!", SDL.SDL_GL_GetCurrentWindow()); Log.Message(LogTypes.Trace, SettingsFile + " file not found"); _settings = new Settings(); _settings.Save(); IsQuitted = true; return; } // If settings are invalid, then show an error and exit if (!_settings.IsValid()) { SDL.SDL_ShowSimpleMessageBox( SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "Invalid settings", "Please, check your settings.\nYou should at least set `ultimaonlinedirectory` and `clientversion`.", SDL.SDL_GL_GetCurrentWindow() ); Log.Message(LogTypes.Trace, "Invalid settings"); IsQuitted = true; return; } TargetElapsedTime = TimeSpan.FromSeconds(1.0f / MAX_FPS); IsFixedTimeStep = _settings.FixedTimeStep; _graphicDeviceManager = new GraphicsDeviceManager(this); _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents; if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef)) { _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef; } _graphicDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8; _graphicDeviceManager.SynchronizeWithVerticalRetrace = false; _graphicDeviceManager.ApplyChanges(); _isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1"; _window = Window; Window.ClientSizeChanged += (sender, e) => { int width = Window.ClientBounds.Width; int height = Window.ClientBounds.Height; if (_isHighDPI) { width *= 2; height *= 2; } if (!IsMaximized) { _engine._profileManager.Current.WindowClientBounds = new Point(width, height); } SetPreferredBackBufferSize(width, height); WorldViewportGump gump = _uiManager.GetControl <WorldViewportGump>(); if (gump != null && _profileManager.Current.GameWindowFullSize) { gump.ResizeWindow(new Point(WindowWidth, WindowHeight)); gump.X = -5; gump.Y = -5; } }; Window.AllowUserResizing = true; IsMouseVisible = true; Window.Title = $"ClassicUO - {Version}"; }
private Engine(string[] args) { Instance = this; string settingsFilepath = Settings.GetSettingsFilepath(); Console.WriteLine($"SETTINGS FILE: {settingsFilepath}"); // Check settings file for existence if (!Directory.Exists(Path.GetDirectoryName(settingsFilepath)) || !File.Exists(settingsFilepath)) { Log.Message(LogTypes.Trace, "Settings file not found"); Directory.CreateDirectory(Path.GetDirectoryName(settingsFilepath)); // Make sure we have full path in place _settings = new Settings(); _settings.Save(); SDL.SDL_ShowSimpleMessageBox( SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "No settings", $"A new settings file has been created: {settingsFilepath}\n\n" + "Please, open it with a text editor and at least set `ultimaonlinedirectory` and `clientversion` options.", SDL.SDL_GL_GetCurrentWindow() ); IsQuitted = true; return; } // Firstly, try to load settings from either main or custom settings file // TODO: Wrap it in the `try..catch` block to catch potential JSON parsing errors _settings = ConfigurationResolver.Load <Settings>(settingsFilepath); // Secondly, Try to apply any settings passed from the command-line/shortcut options over those // we loaded from the settings file // NOTE: If nothing was loaded from settings file (file doesn't exist), then it will create // a new settings object and populate it with the passed settings ArgsParser(args, _settings); // If no settings loaded from file, no settings parsed from command-line options, // or if settings are invalid, then show an error and exit if (_settings == null || !_settings.IsValid()) { Log.Message(LogTypes.Trace, "Invalid settings"); SDL.SDL_ShowSimpleMessageBox( SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "Invalid settings", "Please, check your settings.\n\n" + "You should at least set `ultimaonlinedirectory` and `clientversion`.", SDL.SDL_GL_GetCurrentWindow() ); IsQuitted = true; return; } TargetElapsedTime = TimeSpan.FromSeconds(1.0f / Constants.MAX_FPS); IsFixedTimeStep = _settings.FixedTimeStep; _graphicDeviceManager = new GraphicsDeviceManager(this); _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents; if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef)) { _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef; } _graphicDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8; _graphicDeviceManager.SynchronizeWithVerticalRetrace = false; _graphicDeviceManager.ApplyChanges(); _isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1"; _window = Window; Window.ClientSizeChanged += (sender, e) => { int width = Window.ClientBounds.Width; int height = Window.ClientBounds.Height; if (_isHighDPI) { width *= 2; height *= 2; } if (!IsMaximized) { _engine._profileManager.Current.WindowClientBounds = new Point(width, height); } SetPreferredBackBufferSize(width, height); WorldViewportGump gump = _uiManager.GetGump <WorldViewportGump>(); if (gump != null && _profileManager.Current.GameWindowFullSize) { gump.ResizeWindow(new Point(WindowWidth, WindowHeight)); gump.X = -5; gump.Y = -5; } }; Window.AllowUserResizing = true; IsMouseVisible = _settings.RunMouseInASeparateThread; Window.Title = $"ClassicUO - {Version}"; if (Bootstrap.StartMinimized) { SDL.SDL_MinimizeWindow(Window.Handle); } }