From 86a08c7667c83171f12b5bf7e060e94a7865e27a Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Mon, 29 Jun 2020 17:15:42 +0200 Subject: [PATCH 01/11] added a settingscontainer class --- .../Duality/Utility/ISettingsContainer.cs | 11 +++++++ .../Core/Duality/Utility/SettingsContainer.cs | 29 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Source/Core/Duality/Utility/ISettingsContainer.cs create mode 100644 Source/Core/Duality/Utility/SettingsContainer.cs diff --git a/Source/Core/Duality/Utility/ISettingsContainer.cs b/Source/Core/Duality/Utility/ISettingsContainer.cs new file mode 100644 index 000000000..b6fde2db0 --- /dev/null +++ b/Source/Core/Duality/Utility/ISettingsContainer.cs @@ -0,0 +1,11 @@ +using System; + +namespace Duality +{ + public interface ISettingsContainer + { + event EventHandler Changed; + void Load(); + void Save(); + } +} diff --git a/Source/Core/Duality/Utility/SettingsContainer.cs b/Source/Core/Duality/Utility/SettingsContainer.cs new file mode 100644 index 000000000..88d54fa1a --- /dev/null +++ b/Source/Core/Duality/Utility/SettingsContainer.cs @@ -0,0 +1,29 @@ +using System; +using Duality.Serialization; + +namespace Duality +{ + public class SettingsContainer : ISettingsContainer + where TSettings : class, new() + { + public event EventHandler Changed; + public TSettings Value { get; private set; } + private readonly string path; + + public SettingsContainer(string path) + { + this.path = path; + } + + public void Load() + { + this.Value = Serializer.TryReadObject(this.path) ?? new TSettings(); + Changed?.Invoke(this, EventArgs.Empty); + } + + public void Save() + { + Serializer.WriteObject(this.Value, this.path, typeof(XmlSerializer)); + } + } +} From f7a3eb3393dc7e86043aaccc60eb91de18199f2d Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Mon, 29 Jun 2020 17:16:04 +0200 Subject: [PATCH 02/11] Changed DualityProjectSettings to use the settings container class --- Source/Editor/DualityEditor/DualityEditorApp.cs | 13 +++---------- Source/Editor/DualityEditor/Forms/MainForm.cs | 14 +++++++------- .../DualityEditor/Forms/PublishGameDialog.cs | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Source/Editor/DualityEditor/DualityEditorApp.cs b/Source/Editor/DualityEditor/DualityEditorApp.cs index b96e67164..2576d338a 100644 --- a/Source/Editor/DualityEditor/DualityEditorApp.cs +++ b/Source/Editor/DualityEditor/DualityEditorApp.cs @@ -132,17 +132,10 @@ public static bool IsFirstEditorSession get { return firstEditorSession; } } - private static DualityProjectSettings projectSettings = null; - /// - /// [GET / SET] Provides access to Duality's current application data. This is never null. - /// Any kind of data change event is fired as soon as you re-assign this property. Be sure to do that after changing its data. + /// [GET] Provides access to Duality's current application data. This is never null. /// - public static DualityProjectSettings ProjectSettings - { - get { return projectSettings; } - set { projectSettings = value ?? throw new ArgumentNullException($"You cannot assign null to {nameof(ProjectSettings)}"); } - } + public static SettingsContainer ProjectSettings { get; } = new SettingsContainer("ProjectSettings.dat"); public static bool BackupsEnabled { @@ -223,7 +216,7 @@ public static void Init(MainForm mainForm, bool recover) InitMainGraphicsContext(); DualityApp.InitPostWindow(); - ProjectSettings = DualityProjectSettings.Load(); + ProjectSettings.Load(); ProjectSettings.Save(); mainForm.UpdateLaunchAppActions(); diff --git a/Source/Editor/DualityEditor/Forms/MainForm.cs b/Source/Editor/DualityEditor/Forms/MainForm.cs index 6578e562c..47da584e9 100644 --- a/Source/Editor/DualityEditor/Forms/MainForm.cs +++ b/Source/Editor/DualityEditor/Forms/MainForm.cs @@ -493,7 +493,7 @@ private void actionRunApp_Click(object sender, EventArgs e) this.VerifyStartScene(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.FileName = Path.GetFullPath(DualityEditorApp.ProjectSettings.LauncherPath); + startInfo.FileName = Path.GetFullPath(DualityEditorApp.ProjectSettings.Value.LauncherPath); startInfo.Arguments = LauncherArgs.CmdArgEditor; startInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process appProc = System.Diagnostics.Process.Start(startInfo); @@ -507,7 +507,7 @@ private void actionDebugApp_Click(object sender, EventArgs e) this.VerifyStartScene(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.FileName = Path.GetFullPath(DualityEditorApp.ProjectSettings.LauncherPath); + startInfo.FileName = Path.GetFullPath(DualityEditorApp.ProjectSettings.Value.LauncherPath); startInfo.Arguments = LauncherArgs.CmdArgEditor + " " + LauncherArgs.CmdArgDebug; startInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process appProc = System.Diagnostics.Process.Start(startInfo); @@ -521,7 +521,7 @@ private void actionProfileApp_Click(object sender, EventArgs e) this.VerifyStartScene(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.FileName = Path.GetFullPath(DualityEditorApp.ProjectSettings.LauncherPath); + startInfo.FileName = Path.GetFullPath(DualityEditorApp.ProjectSettings.Value.LauncherPath); startInfo.Arguments = LauncherArgs.CmdArgEditor + " " + LauncherArgs.CmdArgProfiling; startInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process appProc = System.Diagnostics.Process.Start(startInfo); @@ -532,10 +532,10 @@ private void actionProfileApp_Click(object sender, EventArgs e) private void actionConfigureLauncher_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); - fileDialog.InitialDirectory = Path.GetDirectoryName(DualityEditorApp.ProjectSettings.LauncherPath); + fileDialog.InitialDirectory = Path.GetDirectoryName(DualityEditorApp.ProjectSettings.Value.LauncherPath); if (string.IsNullOrWhiteSpace(fileDialog.InitialDirectory)) fileDialog.InitialDirectory = Environment.CurrentDirectory; - fileDialog.FileName = Path.GetFileName(DualityEditorApp.ProjectSettings.LauncherPath); + fileDialog.FileName = Path.GetFileName(DualityEditorApp.ProjectSettings.Value.LauncherPath); fileDialog.Filter = "Executable files (*.exe)|*.exe"; fileDialog.FilterIndex = 1; fileDialog.RestoreDirectory = true; @@ -546,7 +546,7 @@ private void actionConfigureLauncher_Click(object sender, EventArgs e) fileDialog.CustomPlaces.Add(Environment.CurrentDirectory); if (fileDialog.ShowDialog(this) == DialogResult.OK) { - DualityEditorApp.ProjectSettings.LauncherPath = PathHelper.MakeFilePathRelative(fileDialog.FileName); + DualityEditorApp.ProjectSettings.Value.LauncherPath = PathHelper.MakeFilePathRelative(fileDialog.FileName); DualityEditorApp.ProjectSettings.Save(); this.UpdateLaunchAppActions(); } @@ -801,7 +801,7 @@ private void UpdateSplitButtonBackupSettings() } public void UpdateLaunchAppActions() { - bool launcherAvailable = File.Exists(DualityEditorApp.ProjectSettings.LauncherPath); + bool launcherAvailable = File.Exists(DualityEditorApp.ProjectSettings.Value.LauncherPath); this.actionRunApp.Enabled = launcherAvailable; this.actionDebugApp.Enabled = launcherAvailable; this.menuRunApp.Enabled = launcherAvailable; diff --git a/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs b/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs index e1f44db9f..7507a94ae 100644 --- a/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs +++ b/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs @@ -204,7 +204,7 @@ public static void PublishProject(string targetDir, bool includeSource, bool inc string shortcutFilePath = Path.Combine(archiveBaseDir, gameDirName + ".bat"); File.WriteAllText( shortcutFilePath, - "cd GameData && start " + PathHelper.MakeFilePathRelative(DualityEditorApp.ProjectSettings.LauncherPath)); + "cd GameData && start " + PathHelper.MakeFilePathRelative(DualityEditorApp.ProjectSettings.Value.LauncherPath)); // Create a shortcut to the editor if (includeEditor) From a43007d6f2c551dcce3ccb241b2848d7d1e41c9c Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Mon, 29 Jun 2020 17:27:57 +0200 Subject: [PATCH 03/11] changed appdata to use the settingscontainer --- Samples/Benchmarks/BenchmarkController.cs | 4 +- Samples/Benchmarks/RenderSetupInfo.cs | 2 +- Source/Core/Duality/Audio/SoundDevice.cs | 8 +-- Source/Core/Duality/Components/Camera.cs | 2 +- .../Components/Physics/PhysicsWorld.cs | 4 +- Source/Core/Duality/DualityApp.cs | 64 ++++--------------- .../Core/Duality/Launcher/DualityLauncher.cs | 2 +- Source/Core/Duality/Resources/Scene.cs | 2 +- .../Editor/DualityEditor/DualityEditorApp.cs | 18 +++--- .../Editor/DualityEditor/FileEventManager.cs | 4 +- Source/Editor/DualityEditor/Forms/MainForm.cs | 22 +++---- .../DualityEditor/Forms/PublishGameDialog.cs | 2 +- .../Backend/Graphics/GraphicsBackend.cs | 2 +- .../CamViewStates/GameViewCamViewState.cs | 10 +-- 14 files changed, 53 insertions(+), 93 deletions(-) diff --git a/Samples/Benchmarks/BenchmarkController.cs b/Samples/Benchmarks/BenchmarkController.cs index 2f93d9a3f..6c1b4fdc7 100644 --- a/Samples/Benchmarks/BenchmarkController.cs +++ b/Samples/Benchmarks/BenchmarkController.cs @@ -199,12 +199,12 @@ public void EnterBenchmarkMode() this.renderSetup = ContentProvider.GetAvailableContent().FirstOrDefault(); // Make sure the benchmark setup is used globally - DualityApp.AppData.RenderingSetup = this.renderSetup.As(); + DualityApp.AppData.Value.RenderingSetup = this.renderSetup.As(); } public void LeaveBenchmarkMode() { // Uninstall the benchmark setup we set globally - DualityApp.AppData.RenderingSetup = null; + DualityApp.AppData.Value.RenderingSetup = null; // Discard local references to content, since we know the controller // itself won't be discarded due to being static diff --git a/Samples/Benchmarks/RenderSetupInfo.cs b/Samples/Benchmarks/RenderSetupInfo.cs index 9c7fb5490..c56045431 100644 --- a/Samples/Benchmarks/RenderSetupInfo.cs +++ b/Samples/Benchmarks/RenderSetupInfo.cs @@ -64,7 +64,7 @@ void ICmpInitializable.OnActivate() { if (DualityApp.ExecContext == DualityApp.ExecutionContext.Game) { - this.renderSetup = DualityApp.AppData.RenderingSetup.As(); + this.renderSetup = DualityApp.AppData.Value.RenderingSetup.As(); this.text = new FormattedText(); this.text.LineAlign = Alignment.Right; this.text.MaxWidth = 200; diff --git a/Source/Core/Duality/Audio/SoundDevice.cs b/Source/Core/Duality/Audio/SoundDevice.cs index 94a11f525..7645283bb 100644 --- a/Source/Core/Duality/Audio/SoundDevice.cs +++ b/Source/Core/Duality/Audio/SoundDevice.cs @@ -116,7 +116,7 @@ public IEnumerable Playing public SoundDevice() { - DualityApp.AppDataChanged += this.DualityApp_AppDataChanged; + DualityApp.AppData.Changed += this.DualityApp_AppDataChanged; UpdateWorldSettings(); } ~SoundDevice() @@ -133,7 +133,7 @@ private void Dispose(bool manually) if (!this.disposed) { this.disposed = true; - DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged; + DualityApp.AppData.Changed -= this.DualityApp_AppDataChanged; // Clear all playing sounds foreach (SoundInstance inst in this.sounds) inst.Dispose(); @@ -225,8 +225,8 @@ private void UpdateListener() private void UpdateWorldSettings() { DualityApp.AudioBackend.UpdateWorldSettings( - DualityApp.AppData.SpeedOfSound, // Already in meters per second / audio units - DualityApp.AppData.SoundDopplerFactor); + DualityApp.AppData.Value.SpeedOfSound, // Already in meters per second / audio units + DualityApp.AppData.Value.SoundDopplerFactor); } /// diff --git a/Source/Core/Duality/Components/Camera.cs b/Source/Core/Duality/Components/Camera.cs index 8a4e8799e..2324c0f09 100644 --- a/Source/Core/Duality/Components/Camera.cs +++ b/Source/Core/Duality/Components/Camera.cs @@ -156,7 +156,7 @@ public RenderSetup ActiveRenderSetup { return this.renderSetup.Res ?? - DualityApp.AppData.RenderingSetup.Res ?? + DualityApp.AppData.Value.RenderingSetup.Res ?? RenderSetup.Default.Res; } } diff --git a/Source/Core/Duality/Components/Physics/PhysicsWorld.cs b/Source/Core/Duality/Components/Physics/PhysicsWorld.cs index 50939c9f0..c2db20077 100644 --- a/Source/Core/Duality/Components/Physics/PhysicsWorld.cs +++ b/Source/Core/Duality/Components/Physics/PhysicsWorld.cs @@ -65,7 +65,7 @@ public float InterpolateAlpha /// public bool IsFixedTimestep { - get { return DualityApp.AppData.PhysicsFixedTime && !this.lowFramerateMode; } + get { return DualityApp.AppData.Value.PhysicsFixedTime && !this.lowFramerateMode; } } @@ -384,7 +384,7 @@ public bool QueryRect(Vector2 worldCoord, Vector2 size, List queriedB private void UpdateNativeSettings() { - Settings.VelocityThreshold = PhysicsUnit.VelocityToPhysical * DualityApp.AppData.PhysicsVelocityThreshold; + Settings.VelocityThreshold = PhysicsUnit.VelocityToPhysical * DualityApp.AppData.Value.PhysicsVelocityThreshold; } } } diff --git a/Source/Core/Duality/DualityApp.cs b/Source/Core/Duality/DualityApp.cs index 9f1a23ce2..9f4ae5d1d 100644 --- a/Source/Core/Duality/DualityApp.cs +++ b/Source/Core/Duality/DualityApp.cs @@ -86,7 +86,6 @@ public enum ExecutionEnvironment private static SoundDevice sound = null; private static ExecutionEnvironment environment = ExecutionEnvironment.Unknown; private static ExecutionContext execContext = ExecutionContext.Terminated; - private static DualityAppData appData = null; private static DualityUserData userData = null; private static List disposeSchedule = new List(); @@ -110,10 +109,7 @@ public static event EventHandler FocusChanged /// Called when the games UserData changes /// public static event EventHandler UserDataChanged = null; - /// - /// Called when the games AppData changes - /// - public static event EventHandler AppDataChanged = null; + /// /// Called when Duality is being terminated by choice (e.g. not because of crashes or similar). /// It is also called in an editor environment. @@ -180,7 +176,7 @@ public static Vector2 TargetViewSize { get { - Point2 forcedRenderSize = DualityApp.AppData.ForcedRenderSize; + Point2 forcedRenderSize = DualityApp.AppData.Value.ForcedRenderSize; if (forcedRenderSize.X > 0 && forcedRenderSize.Y > 0) return forcedRenderSize; else @@ -232,18 +228,9 @@ public static SoundDevice Sound } /// /// [GET / SET] Provides access to Duality's current application data. This is never null. - /// Any kind of data change event is fired as soon as you re-assign this property. Be sure to do that after changing its data. /// - public static DualityAppData AppData - { - get { return appData; } - set - { - appData = value ?? new DualityAppData(); - // We're currently missing direct changes without invoking this setter - OnAppDataChanged(); - } - } + public static SettingsContainer AppData { get; } = new SettingsContainer("AppData.dat"); + /// /// [GET / SET] Provides access to Duality's current user data. This is never null. /// Any kind of data change event is fired as soon as you re-assign this property. Be sure to do that after changing its data. @@ -259,13 +246,6 @@ public static DualityUserData UserData } } /// - /// [GET] Returns the path where this DualityApp's application data is located at. - /// - public static string AppDataPath - { - get { return "AppData.dat"; } - } - /// /// [GET] Returns the path where this DualityApp's user data is located at. /// public static string UserDataPath @@ -364,9 +344,8 @@ public static void Init(ExecutionEnvironment env, ExecutionContext context, IAss InitBackend(out systemBack); // Load application and user data and submit a change event, so all settings are applied - LoadAppData(); + DualityApp.AppData.Load(); LoadUserData(); - OnAppDataChanged(); OnUserDataChanged(); // Initialize the graphics backend @@ -636,8 +615,8 @@ public static void Render(ContentRef target, Rect viewportRect, Ve /// public static void CalculateGameViewport(Point2 windowSize, out Rect windowViewport, out Vector2 renderTargetSize) { - Point2 forcedSize = DualityApp.AppData.ForcedRenderSize; - TargetResize forcedResizeMode = DualityApp.AppData.ForcedRenderResizeMode; + Point2 forcedSize = DualityApp.AppData.Value.ForcedRenderSize; + TargetResize forcedResizeMode = DualityApp.AppData.Value.ForcedRenderResizeMode; renderTargetSize = windowSize; windowViewport = new Rect(renderTargetSize); @@ -704,13 +683,6 @@ public static void RunCleanup() Resource.RunCleanup(); } - /// - /// Triggers Duality to (re)load its . - /// - public static void LoadAppData() - { - appData = Serializer.TryReadObject(AppDataPath) ?? new DualityAppData(); - } /// /// Triggers Duality to (re)load its . /// @@ -720,13 +692,7 @@ public static void LoadUserData() if (!FileOp.Exists(path) || execContext == ExecutionContext.Editor || runFromEditor) path = "DefaultUserData.dat"; userData = Serializer.TryReadObject(path) ?? new DualityUserData(); } - /// - /// Triggers Duality to save its . - /// - public static void SaveAppData() - { - Serializer.WriteObject(appData, AppDataPath, typeof(XmlSerializer)); - } + /// /// Triggers Duality to save its . /// @@ -808,9 +774,8 @@ internal static void InitBackend(out T target, Func string.Equals(s, backend.Id, StringComparison.OrdinalIgnoreCase))) + if (DualityApp.AppData.Value.SkipBackends != null && + DualityApp.AppData.Value.SkipBackends.Any(s => string.Equals(s, backend.Id, StringComparison.OrdinalIgnoreCase))) { Logs.Core.Write("Backend '{0}' skipped because of AppData settings.", backend.Name); continue; @@ -895,11 +860,6 @@ private static void OnUserDataChanged() if (UserDataChanged != null) UserDataChanged(null, EventArgs.Empty); } - private static void OnAppDataChanged() - { - if (AppDataChanged != null) - AppDataChanged(null, EventArgs.Empty); - } private static void OnTerminating() { if (Terminating != null) @@ -911,7 +871,7 @@ private static void pluginManager_PluginsRemoving(object sender, DualityPluginEv // Save user and app data, they'll be reloaded after plugin reload is done, // as they can reference plugin data as well. SaveUserData(); - SaveAppData(); + DualityApp.AppData.Save(); // Dispose static Resources that could reference plugin data VisualLogs.ClearAll(); @@ -959,7 +919,7 @@ private static void pluginManager_PluginsRemoved(object sender, DualityPluginEve CleanEventBindings(plugin.PluginAssembly); // Reload user and app data - LoadAppData(); + DualityApp.AppData.Load(); LoadUserData(); } diff --git a/Source/Core/Duality/Launcher/DualityLauncher.cs b/Source/Core/Duality/Launcher/DualityLauncher.cs index 4d5cd5d26..29ec2e6ee 100644 --- a/Source/Core/Duality/Launcher/DualityLauncher.cs +++ b/Source/Core/Duality/Launcher/DualityLauncher.cs @@ -67,7 +67,7 @@ public DualityLauncher(LauncherArgs launcherArgs = null) Size = DualityApp.UserData.WindowSize, ScreenMode = launcherArgs.IsDebugging ? ScreenMode.Window : DualityApp.UserData.WindowMode, RefreshMode = launcherArgs.IsProfiling ? RefreshMode.NoSync : DualityApp.UserData.WindowRefreshMode, - Title = DualityApp.AppData.AppName, + Title = DualityApp.AppData.Value.AppName, SystemCursorVisible = launcherArgs.IsDebugging || DualityApp.UserData.SystemCursorVisible }; this.window = DualityApp.OpenWindow(options); diff --git a/Source/Core/Duality/Resources/Scene.cs b/Source/Core/Duality/Resources/Scene.cs index 2f5ffb4f2..ba91bf013 100644 --- a/Source/Core/Duality/Resources/Scene.cs +++ b/Source/Core/Duality/Resources/Scene.cs @@ -472,7 +472,7 @@ public void Render(ContentRef target, Rect viewportRect, Vector2 i { // Retrieve the rendering setup that will be used for rendering the scene RenderSetup setup = - DualityApp.AppData.RenderingSetup.Res ?? + DualityApp.AppData.Value.RenderingSetup.Res ?? RenderSetup.Default.Res; // Render the scene diff --git a/Source/Editor/DualityEditor/DualityEditorApp.cs b/Source/Editor/DualityEditor/DualityEditorApp.cs index 2576d338a..cb30d128d 100644 --- a/Source/Editor/DualityEditor/DualityEditorApp.cs +++ b/Source/Editor/DualityEditor/DualityEditorApp.cs @@ -562,7 +562,7 @@ private static void InitMainGraphicsContext() // Currently bound to game-specific settings. Should be decoupled // from them at some point, so the editor can use independent settings. mainGraphicsContext = graphicsBack.CreateContext( - DualityApp.AppData.MultisampleBackBuffer ? + DualityApp.AppData.Value.MultisampleBackBuffer ? DualityApp.UserData.AntialiasingQuality : AAQuality.Off); } @@ -641,7 +641,7 @@ public static string SaveCurrentScene(bool skipYetUnsaved = true) if (IsResourceUnsaved(Scene.Current)) { Scene.Current.Save(); - DualityApp.AppData.Version++; + DualityApp.AppData.Value.Version++; } } else if (!skipYetUnsaved) @@ -649,13 +649,13 @@ public static string SaveCurrentScene(bool skipYetUnsaved = true) string basePath = Path.Combine(DualityApp.DataDirectory, "Scene"); string path = PathHelper.GetFreePath(basePath, Resource.GetFileExtByType()); Scene.Current.Save(path); - DualityApp.AppData.Version++; + DualityApp.AppData.Value.Version++; // If there is no start scene defined, use this one. - if (DualityApp.AppData.StartScene == null) + if (DualityApp.AppData.Value.StartScene == null) { - DualityApp.AppData.StartScene = Scene.Current; - DualityApp.SaveAppData(); + DualityApp.AppData.Value.StartScene = Scene.Current; + DualityApp.AppData.Save(); } } return Scene.Current.Path; @@ -670,7 +670,7 @@ public static void SaveResources() anySaved = true; } unsavedResources.Clear(); - if (anySaved) DualityApp.AppData.Version++; + if (anySaved) DualityApp.AppData.Value.Version++; } public static void FlagResourceUnsaved(IEnumerable res) { @@ -1000,7 +1000,7 @@ private static void OnObjectPropertyChanged(object sender, ObjectPropertyChanged { // This is probably not the best idea for generalized behaviour, but sufficient for now if (args.Objects.OtherObjects.Any(o => o is DualityAppData)) - DualityApp.SaveAppData(); + DualityApp.AppData.Save(); else if (args.Objects.OtherObjects.Any(o => o is DualityUserData)) DualityApp.SaveUserData(); if (args.Objects.OtherObjects.Any(o => o is DualityProjectSettings)) @@ -1257,7 +1257,7 @@ private static void FileEventManager_PluginsChanged(object sender, FileSystemCha if (!corePluginReloader.ReloadSchedule.Contains(fileEvent.Path)) { corePluginReloader.ReloadSchedule.Add(fileEvent.Path); - DualityApp.AppData.Version++; + DualityApp.AppData.Value.Version++; } } corePluginReloader.State = ReloadCorePluginDialog.ReloaderState.WaitForPlugins; diff --git a/Source/Editor/DualityEditor/FileEventManager.cs b/Source/Editor/DualityEditor/FileEventManager.cs index 489f234bf..927aae690 100644 --- a/Source/Editor/DualityEditor/FileEventManager.cs +++ b/Source/Editor/DualityEditor/FileEventManager.cs @@ -668,7 +668,7 @@ private static System.Collections.IEnumerable async_RenameContentRefs(Processing // Rename in static application data state.StateDesc = "DualityApp Data"; yield return null; - DualityApp.LoadAppData(); + DualityApp.AppData.Load(); DualityApp.LoadUserData(); state.Progress += 0.04f; yield return null; @@ -676,7 +676,7 @@ private static System.Collections.IEnumerable async_RenameContentRefs(Processing totalCounter += async_RenameContentRefs_Perform(DualityApp.UserData, renameData); state.Progress += 0.02f; yield return null; - DualityApp.SaveAppData(); + DualityApp.AppData.Save(); DualityApp.SaveUserData(); state.Progress += 0.04f; yield return null; diff --git a/Source/Editor/DualityEditor/Forms/MainForm.cs b/Source/Editor/DualityEditor/Forms/MainForm.cs index 47da584e9..a707b88c4 100644 --- a/Source/Editor/DualityEditor/Forms/MainForm.cs +++ b/Source/Editor/DualityEditor/Forms/MainForm.cs @@ -472,7 +472,7 @@ protected override void OnFormClosing(FormClosingEventArgs e) // Save UserData before quitting DualityEditorApp.SaveUserData(); - DualityApp.SaveAppData(); + DualityApp.AppData.Save(); bool isClosedByUser = isUserCloseReason && @@ -678,11 +678,11 @@ private void UndoRedoManager_StackChanged(object sender, EventArgs e) private System.Collections.IEnumerable async_ChangeDataFormat(ProcessingBigTaskDialog.WorkerInterface state) { state.StateDesc = "DualityApp Data"; yield return null; - DualityApp.LoadAppData(); + DualityApp.AppData.Save(); DualityApp.LoadUserData(); state.Progress += 0.05f; yield return null; - - DualityApp.SaveAppData(); + + DualityApp.AppData.Save(); DualityApp.SaveUserData(); state.Progress += 0.05f; yield return null; @@ -810,27 +810,27 @@ public void UpdateLaunchAppActions() } private void VerifyStartScene() { - if (DualityApp.AppData.StartScene != null) return; + if (DualityApp.AppData.Value.StartScene != null) return; // If there is no StartScene defined, attempt to find one automatically. if (!Scene.Current.IsRuntimeResource) { - DualityApp.AppData.StartScene = Scene.Current; - DualityApp.SaveAppData(); + DualityApp.AppData.Value.StartScene = Scene.Current; + DualityApp.AppData.Save(); } else { ContentRef existingScene = ContentProvider.GetAvailableContent().FirstOrDefault(); if (existingScene != null) { - DualityApp.AppData.StartScene = existingScene; - DualityApp.SaveAppData(); + DualityApp.AppData.Value.StartScene = existingScene; + DualityApp.AppData.Save(); } else if (!Scene.Current.IsEmpty) { DualityEditorApp.SaveCurrentScene(false); - DualityApp.AppData.StartScene = Scene.Current; - DualityApp.SaveAppData(); + DualityApp.AppData.Value.StartScene = Scene.Current; + DualityApp.AppData.Save(); } } } diff --git a/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs b/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs index 7507a94ae..01066b95a 100644 --- a/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs +++ b/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs @@ -129,7 +129,7 @@ private void buttonPublish_Click(object sender, EventArgs e) public static void PublishProject(string targetDir, bool includeSource, bool includeEditor, bool compress, bool createShortcuts, Func targetExistsCallback = null) { // Determine a valid directory name for the game - string gameDirName = PathOp.GetValidFileName(DualityApp.AppData.AppName); + string gameDirName = PathOp.GetValidFileName(DualityApp.AppData.Value.AppName); string targetGameDir = Path.Combine(targetDir, gameDirName); string archiveBaseDir = targetGameDir; diff --git a/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs b/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs index 0a0759836..defe1dfc5 100644 --- a/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs +++ b/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs @@ -410,7 +410,7 @@ private void QueryGraphicsModes() sortedModes.StableSort((a, b) => a.Samples - b.Samples); int highestAALevel = MathF.RoundToInt(MathF.Log(MathF.Max(sortedModes.Max(m => m.Samples), 1.0f), 2.0f)); int targetAALevel = highestAALevel; - if (DualityApp.AppData.MultisampleBackBuffer) + if (DualityApp.AppData.Value.MultisampleBackBuffer) { switch (DualityApp.UserData.AntialiasingQuality) { diff --git a/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs b/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs index 57e20c01c..ce5349937 100644 --- a/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs +++ b/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs @@ -85,7 +85,7 @@ private AAQuality GameAntialiasingQuality { get { - return DualityApp.AppData.MultisampleBackBuffer ? + return DualityApp.AppData.Value.MultisampleBackBuffer ? DualityApp.UserData.AntialiasingQuality : AAQuality.Off; } @@ -99,11 +99,11 @@ private Point2 GameTargetSize get { bool isUsingForcedSize = - DualityApp.AppData.ForcedRenderResizeMode != TargetResize.None && - DualityApp.AppData.ForcedRenderSize.X != 0 && - DualityApp.AppData.ForcedRenderSize.Y != 0; + DualityApp.AppData.Value.ForcedRenderResizeMode != TargetResize.None && + DualityApp.AppData.Value.ForcedRenderSize.X != 0 && + DualityApp.AppData.Value.ForcedRenderSize.Y != 0; return isUsingForcedSize ? - DualityApp.AppData.ForcedRenderSize : + DualityApp.AppData.Value.ForcedRenderSize : DualityApp.UserData.WindowSize; } } From b8ca0c8466c7c544e89c2f4df3f5063ed459278c Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Mon, 29 Jun 2020 17:45:34 +0200 Subject: [PATCH 04/11] changed UserData to use settingscontainer --- .../BasicMenu/Components/MenuChangeVolume.cs | 4 +- Samples/BasicMenu/VolumeRenderer.cs | 2 +- Samples/Physics/PhysicsSampleController.cs | 2 +- Source/Core/Duality/Audio/SoundInstance.cs | 10 +-- .../Backend/Dummy/DummyNativeWindow.cs | 2 +- Source/Core/Duality/DualityApp.cs | 64 ++----------------- .../Core/Duality/Launcher/DualityLauncher.cs | 8 +-- .../Editor/DualityEditor/DualityEditorApp.cs | 12 +--- .../Editor/DualityEditor/FileEventManager.cs | 4 +- Source/Editor/DualityEditor/Forms/MainForm.cs | 6 +- .../Backend/Graphics/GraphicsBackend.cs | 2 +- .../Backend/Graphics/NativeWindow.cs | 12 ++-- .../CamViewStates/GameViewCamViewState.cs | 4 +- 13 files changed, 38 insertions(+), 94 deletions(-) diff --git a/Samples/BasicMenu/Components/MenuChangeVolume.cs b/Samples/BasicMenu/Components/MenuChangeVolume.cs index d15ed6064..17ce395a5 100644 --- a/Samples/BasicMenu/Components/MenuChangeVolume.cs +++ b/Samples/BasicMenu/Components/MenuChangeVolume.cs @@ -22,13 +22,13 @@ public override void DoAction() { base.DoAction(); - float volume = DualityApp.UserData.SoundMasterVol; + float volume = DualityApp.UserData.Value.SoundMasterVol; volume += (this.changeAmount / 10f); // make sure that the volume is between 0 and 1 volume = MathF.Min(MathF.Max(volume, 0), 1); - DualityApp.UserData.SoundMasterVol = volume; + DualityApp.UserData.Value.SoundMasterVol = volume; } } } diff --git a/Samples/BasicMenu/VolumeRenderer.cs b/Samples/BasicMenu/VolumeRenderer.cs index 320af2542..f6a89328f 100644 --- a/Samples/BasicMenu/VolumeRenderer.cs +++ b/Samples/BasicMenu/VolumeRenderer.cs @@ -22,7 +22,7 @@ void ICmpUpdatable.OnUpdate() } // update the volume value - volumeText.Text.SourceText = String.Format("Volume {0:0.0}", DualityApp.UserData.SoundMasterVol); + volumeText.Text.SourceText = String.Format("Volume {0:0.0}", DualityApp.UserData.Value.SoundMasterVol); } } } \ No newline at end of file diff --git a/Samples/Physics/PhysicsSampleController.cs b/Samples/Physics/PhysicsSampleController.cs index b417dc4a3..ee1222a3a 100644 --- a/Samples/Physics/PhysicsSampleController.cs +++ b/Samples/Physics/PhysicsSampleController.cs @@ -101,7 +101,7 @@ void ICmpRenderer.Draw(IDrawDevice device) // When the mouse is hovering over the game area and the system cursor // is disabled, draw a custom cursor as a replacement - if (!DualityApp.UserData.SystemCursorVisible && DualityApp.Mouse.IsAvailable) + if (!DualityApp.UserData.Value.SystemCursorVisible && DualityApp.Mouse.IsAvailable) { canvas.State.ColorTint = (this.dragObj != null) ? this.interactionColor : this.defaultColor; canvas.FillThickLine( diff --git a/Source/Core/Duality/Audio/SoundInstance.cs b/Source/Core/Duality/Audio/SoundInstance.cs index 63c6538ab..18fde640e 100644 --- a/Source/Core/Duality/Audio/SoundInstance.cs +++ b/Source/Core/Duality/Audio/SoundInstance.cs @@ -387,22 +387,22 @@ private float GetTypeVolFactor() switch (this.sound.IsAvailable ? this.sound.Res.Type : SoundType.World) { case SoundType.UserInterface: - optVolFactor = DualityApp.UserData.SoundEffectVol; + optVolFactor = DualityApp.UserData.Value.SoundEffectVol; break; case SoundType.World: - optVolFactor = DualityApp.UserData.SoundEffectVol; + optVolFactor = DualityApp.UserData.Value.SoundEffectVol; break; case SoundType.Speech: - optVolFactor = DualityApp.UserData.SoundSpeechVol; + optVolFactor = DualityApp.UserData.Value.SoundSpeechVol; break; case SoundType.Music: - optVolFactor = DualityApp.UserData.SoundMusicVol; + optVolFactor = DualityApp.UserData.Value.SoundMusicVol; break; default: optVolFactor = 1.0f; break; } - return optVolFactor * DualityApp.UserData.SoundMasterVol * 0.5f; + return optVolFactor * DualityApp.UserData.Value.SoundMasterVol * 0.5f; } private void RegisterPlaying() { diff --git a/Source/Core/Duality/Backend/Dummy/DummyNativeWindow.cs b/Source/Core/Duality/Backend/Dummy/DummyNativeWindow.cs index 9e3fc24d5..fa0f6571e 100644 --- a/Source/Core/Duality/Backend/Dummy/DummyNativeWindow.cs +++ b/Source/Core/Duality/Backend/Dummy/DummyNativeWindow.cs @@ -15,7 +15,7 @@ void INativeWindow.Run() while (DualityApp.ExecContext != DualityApp.ExecutionContext.Terminated) { DualityApp.Update(); - DualityApp.Render(null, new Rect(DualityApp.UserData.WindowSize), DualityApp.UserData.WindowSize); + DualityApp.Render(null, new Rect(DualityApp.UserData.Value.WindowSize), DualityApp.UserData.Value.WindowSize); } } diff --git a/Source/Core/Duality/DualityApp.cs b/Source/Core/Duality/DualityApp.cs index 9f4ae5d1d..c515067a2 100644 --- a/Source/Core/Duality/DualityApp.cs +++ b/Source/Core/Duality/DualityApp.cs @@ -86,7 +86,6 @@ public enum ExecutionEnvironment private static SoundDevice sound = null; private static ExecutionEnvironment environment = ExecutionEnvironment.Unknown; private static ExecutionContext execContext = ExecutionContext.Terminated; - private static DualityUserData userData = null; private static List disposeSchedule = new List(); /// @@ -105,10 +104,6 @@ public static event EventHandler FocusChanged keyboard.NoLongerAvailable -= value; } } - /// - /// Called when the games UserData changes - /// - public static event EventHandler UserDataChanged = null; /// /// Called when Duality is being terminated by choice (e.g. not because of crashes or similar). @@ -233,25 +228,9 @@ public static SoundDevice Sound /// /// [GET / SET] Provides access to Duality's current user data. This is never null. - /// Any kind of data change event is fired as soon as you re-assign this property. Be sure to do that after changing its data. - /// - public static DualityUserData UserData - { - get { return userData; } - set - { - userData = value ?? new DualityUserData(); - // We're currently missing direct changes without invoking this setter - OnUserDataChanged(); - } - } - /// - /// [GET] Returns the path where this DualityApp's user data is located at. /// - public static string UserDataPath - { - get { return "UserData.dat"; } - } + public static SettingsContainer UserData { get; } = new SettingsContainer(execContext == ExecutionContext.Editor ? "DefaultUserData.dat" : "UserData.dat"); + /// /// [GET] Returns the in which this DualityApp is currently running. /// @@ -345,8 +324,7 @@ public static void Init(ExecutionEnvironment env, ExecutionContext context, IAss // Load application and user data and submit a change event, so all settings are applied DualityApp.AppData.Load(); - LoadUserData(); - OnUserDataChanged(); + DualityApp.UserData.Load(); // Initialize the graphics backend InitBackend(out graphicsBack); @@ -425,7 +403,7 @@ public static void Terminate() if (execContext != ExecutionContext.Editor) { OnTerminating(); - SaveUserData(); + DualityApp.UserData.Save(); } // Signal that the game simulation has ended. @@ -683,29 +661,6 @@ public static void RunCleanup() Resource.RunCleanup(); } - /// - /// Triggers Duality to (re)load its . - /// - public static void LoadUserData() - { - string path = UserDataPath; - if (!FileOp.Exists(path) || execContext == ExecutionContext.Editor || runFromEditor) path = "DefaultUserData.dat"; - userData = Serializer.TryReadObject(path) ?? new DualityUserData(); - } - - /// - /// Triggers Duality to save its . - /// - public static void SaveUserData() - { - string path = UserDataPath; - Serializer.WriteObject(userData, UserDataPath, typeof(XmlSerializer)); - if (execContext == ExecutionContext.Editor) - { - Serializer.WriteObject(userData, "DefaultUserData.dat", typeof(XmlSerializer)); - } - } - /// /// Enumerates all currently loaded assemblies that are part of Duality, i.e. Duality itsself and all loaded plugins. /// @@ -774,7 +729,7 @@ internal static void InitBackend(out T target, Func string.Equals(s, backend.Id, StringComparison.OrdinalIgnoreCase))) { Logs.Core.Write("Backend '{0}' skipped because of AppData settings.", backend.Name); @@ -855,11 +810,6 @@ internal static void ShutdownBackend(ref T backend) where T : class, IDuality Logs.Core.PopIndent(); } - private static void OnUserDataChanged() - { - if (UserDataChanged != null) - UserDataChanged(null, EventArgs.Empty); - } private static void OnTerminating() { if (Terminating != null) @@ -870,7 +820,7 @@ private static void pluginManager_PluginsRemoving(object sender, DualityPluginEv { // Save user and app data, they'll be reloaded after plugin reload is done, // as they can reference plugin data as well. - SaveUserData(); + DualityApp.UserData.Save(); DualityApp.AppData.Save(); // Dispose static Resources that could reference plugin data @@ -920,7 +870,7 @@ private static void pluginManager_PluginsRemoved(object sender, DualityPluginEve // Reload user and app data DualityApp.AppData.Load(); - LoadUserData(); + DualityApp.UserData.Load(); } private static void CleanEventBindings(Assembly invalidAssembly) diff --git a/Source/Core/Duality/Launcher/DualityLauncher.cs b/Source/Core/Duality/Launcher/DualityLauncher.cs index 29ec2e6ee..bf19f1a3d 100644 --- a/Source/Core/Duality/Launcher/DualityLauncher.cs +++ b/Source/Core/Duality/Launcher/DualityLauncher.cs @@ -64,11 +64,11 @@ public DualityLauncher(LauncherArgs launcherArgs = null) // Open up a new window WindowOptions options = new WindowOptions { - Size = DualityApp.UserData.WindowSize, - ScreenMode = launcherArgs.IsDebugging ? ScreenMode.Window : DualityApp.UserData.WindowMode, - RefreshMode = launcherArgs.IsProfiling ? RefreshMode.NoSync : DualityApp.UserData.WindowRefreshMode, + Size = DualityApp.UserData.Value.WindowSize, + ScreenMode = launcherArgs.IsDebugging ? ScreenMode.Window : DualityApp.UserData.Value.WindowMode, + RefreshMode = launcherArgs.IsProfiling ? RefreshMode.NoSync : DualityApp.UserData.Value.WindowRefreshMode, Title = DualityApp.AppData.Value.AppName, - SystemCursorVisible = launcherArgs.IsDebugging || DualityApp.UserData.SystemCursorVisible + SystemCursorVisible = launcherArgs.IsDebugging || DualityApp.UserData.Value.SystemCursorVisible }; this.window = DualityApp.OpenWindow(options); } diff --git a/Source/Editor/DualityEditor/DualityEditorApp.cs b/Source/Editor/DualityEditor/DualityEditorApp.cs index cb30d128d..e97fada6d 100644 --- a/Source/Editor/DualityEditor/DualityEditorApp.cs +++ b/Source/Editor/DualityEditor/DualityEditorApp.cs @@ -563,7 +563,7 @@ private static void InitMainGraphicsContext() // from them at some point, so the editor can use independent settings. mainGraphicsContext = graphicsBack.CreateContext( DualityApp.AppData.Value.MultisampleBackBuffer ? - DualityApp.UserData.AntialiasingQuality : + DualityApp.UserData.Value.AntialiasingQuality : AAQuality.Off); } catch (Exception e) @@ -996,15 +996,9 @@ private static void OnObjectPropertyChanged(object sender, ObjectPropertyChanged } // If DualityAppData or DualityUserData is modified, save it - if (args.Objects.OtherObjectCount > 0) + foreach (var settings in args.Objects.OfType()) { - // This is probably not the best idea for generalized behaviour, but sufficient for now - if (args.Objects.OtherObjects.Any(o => o is DualityAppData)) - DualityApp.AppData.Save(); - else if (args.Objects.OtherObjects.Any(o => o is DualityUserData)) - DualityApp.SaveUserData(); - if (args.Objects.OtherObjects.Any(o => o is DualityProjectSettings)) - ProjectSettings.Save(); + settings.Save(); } } diff --git a/Source/Editor/DualityEditor/FileEventManager.cs b/Source/Editor/DualityEditor/FileEventManager.cs index 927aae690..3fef4eb53 100644 --- a/Source/Editor/DualityEditor/FileEventManager.cs +++ b/Source/Editor/DualityEditor/FileEventManager.cs @@ -669,7 +669,7 @@ private static System.Collections.IEnumerable async_RenameContentRefs(Processing // Rename in static application data state.StateDesc = "DualityApp Data"; yield return null; DualityApp.AppData.Load(); - DualityApp.LoadUserData(); + DualityApp.UserData.Load(); state.Progress += 0.04f; yield return null; totalCounter += async_RenameContentRefs_Perform(DualityApp.AppData, renameData); @@ -677,7 +677,7 @@ private static System.Collections.IEnumerable async_RenameContentRefs(Processing state.Progress += 0.02f; yield return null; DualityApp.AppData.Save(); - DualityApp.SaveUserData(); + DualityApp.UserData.Save(); state.Progress += 0.04f; yield return null; // Special case: Current Scene in sandbox mode diff --git a/Source/Editor/DualityEditor/Forms/MainForm.cs b/Source/Editor/DualityEditor/Forms/MainForm.cs index a707b88c4..2e9c06c48 100644 --- a/Source/Editor/DualityEditor/Forms/MainForm.cs +++ b/Source/Editor/DualityEditor/Forms/MainForm.cs @@ -678,12 +678,12 @@ private void UndoRedoManager_StackChanged(object sender, EventArgs e) private System.Collections.IEnumerable async_ChangeDataFormat(ProcessingBigTaskDialog.WorkerInterface state) { state.StateDesc = "DualityApp Data"; yield return null; - DualityApp.AppData.Save(); - DualityApp.LoadUserData(); + DualityApp.AppData.Load(); + DualityApp.UserData.Load(); state.Progress += 0.05f; yield return null; DualityApp.AppData.Save(); - DualityApp.SaveUserData(); + DualityApp.UserData.Save(); state.Progress += 0.05f; yield return null; // Special case: Current Scene in sandbox mode diff --git a/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs b/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs index defe1dfc5..82d3b3d4b 100644 --- a/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs +++ b/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs @@ -412,7 +412,7 @@ private void QueryGraphicsModes() int targetAALevel = highestAALevel; if (DualityApp.AppData.Value.MultisampleBackBuffer) { - switch (DualityApp.UserData.AntialiasingQuality) + switch (DualityApp.UserData.Value.AntialiasingQuality) { case AAQuality.High: targetAALevel = highestAALevel; break; case AAQuality.Medium: targetAALevel = highestAALevel / 2; break; diff --git a/Source/Platform/DefaultOpenTK/Backend/Graphics/NativeWindow.cs b/Source/Platform/DefaultOpenTK/Backend/Graphics/NativeWindow.cs index c03941000..336b1b706 100644 --- a/Source/Platform/DefaultOpenTK/Backend/Graphics/NativeWindow.cs +++ b/Source/Platform/DefaultOpenTK/Backend/Graphics/NativeWindow.cs @@ -176,7 +176,7 @@ internal void HookIntoDuality() { DualityApp.Mouse.Source = new GameWindowMouseInputSource(this.internalWindow); DualityApp.Keyboard.Source = new GameWindowKeyboardInputSource(this.internalWindow); - DualityApp.UserDataChanged += this.OnUserDataChanged; + DualityApp.UserData.Changed += this.OnUserDataChanged; } internal void UnhookFromDuality() { @@ -184,7 +184,7 @@ internal void UnhookFromDuality() DualityApp.Mouse.Source = null; if (DualityApp.Keyboard.Source is GameWindowKeyboardInputSource) DualityApp.Keyboard.Source = null; - DualityApp.UserDataChanged -= this.OnUserDataChanged; + DualityApp.UserData.Changed -= this.OnUserDataChanged; } private void OnUserDataChanged(object sender, EventArgs e) @@ -193,22 +193,22 @@ private void OnUserDataChanged(object sender, EventArgs e) if (DisplayDevice.Default == null) return; // Determine the target state for our window - MouseCursor targetCursor = DualityApp.UserData.SystemCursorVisible ? MouseCursor.Default : MouseCursor.Empty; + MouseCursor targetCursor = DualityApp.UserData.Value.SystemCursorVisible ? MouseCursor.Default : MouseCursor.Empty; WindowState targetWindowState = this.internalWindow.WindowState; WindowBorder targetWindowBorder = this.internalWindow.WindowBorder; Size targetSize = this.internalWindow.ClientSize; - switch (DualityApp.UserData.WindowMode) + switch (DualityApp.UserData.Value.WindowMode) { case ScreenMode.Window: targetWindowState = WindowState.Normal; targetWindowBorder = WindowBorder.Resizable; - targetSize = new Size(DualityApp.UserData.WindowSize.X, DualityApp.UserData.WindowSize.Y); + targetSize = new Size(DualityApp.UserData.Value.WindowSize.X, DualityApp.UserData.Value.WindowSize.Y); break; case ScreenMode.FixedWindow: targetWindowState = WindowState.Normal; targetWindowBorder = WindowBorder.Fixed; - targetSize = new Size(DualityApp.UserData.WindowSize.X, DualityApp.UserData.WindowSize.Y); + targetSize = new Size(DualityApp.UserData.Value.WindowSize.X, DualityApp.UserData.Value.WindowSize.Y); break; case ScreenMode.FullWindow: diff --git a/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs b/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs index ce5349937..277fd9640 100644 --- a/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs +++ b/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs @@ -86,7 +86,7 @@ private AAQuality GameAntialiasingQuality get { return DualityApp.AppData.Value.MultisampleBackBuffer ? - DualityApp.UserData.AntialiasingQuality : + DualityApp.UserData.Value.AntialiasingQuality : AAQuality.Off; } } @@ -104,7 +104,7 @@ private Point2 GameTargetSize DualityApp.AppData.Value.ForcedRenderSize.Y != 0; return isUsingForcedSize ? DualityApp.AppData.Value.ForcedRenderSize : - DualityApp.UserData.WindowSize; + DualityApp.UserData.Value.WindowSize; } } /// From c21bd930e64b9aa4d9a0b623f0b263da89eb900d Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Mon, 29 Jun 2020 17:49:52 +0200 Subject: [PATCH 05/11] cleanup --- .../Utility/DualityProjectSettings.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/Source/Editor/DualityEditor/Utility/DualityProjectSettings.cs b/Source/Editor/DualityEditor/Utility/DualityProjectSettings.cs index 37630cd1f..a3c089536 100644 --- a/Source/Editor/DualityEditor/Utility/DualityProjectSettings.cs +++ b/Source/Editor/DualityEditor/Utility/DualityProjectSettings.cs @@ -1,26 +1,12 @@ -using Duality.Serialization; - -namespace Duality.Editor +namespace Duality.Editor { public class DualityProjectSettings { - private static readonly string ProjectSettingsPath = "ProjectSettings.dat"; - private string launcherPath = "DualityGame.exe"; public string LauncherPath { get { return this.launcherPath; } set { this.launcherPath = value; } } - - public void Save() - { - Serializer.WriteObject(this, ProjectSettingsPath, typeof(XmlSerializer)); - } - - public static DualityProjectSettings Load() - { - return Serializer.TryReadObject(ProjectSettingsPath) ?? new DualityProjectSettings(); - } } } From 85b1e7a97bdd221ce20dd0b8ffee22ca822ebefe Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Mon, 29 Jun 2020 17:50:31 +0200 Subject: [PATCH 06/11] cleanup --- Source/Editor/DualityEditor/DualityEditorApp.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Editor/DualityEditor/DualityEditorApp.cs b/Source/Editor/DualityEditor/DualityEditorApp.cs index e97fada6d..4bb7b7ace 100644 --- a/Source/Editor/DualityEditor/DualityEditorApp.cs +++ b/Source/Editor/DualityEditor/DualityEditorApp.cs @@ -14,7 +14,6 @@ using Duality; using Duality.IO; using Duality.Components; -using Duality.Serialization; using Duality.Resources; using Duality.Drawing; using Duality.Backend; From 1fcd611267222ab71cba125cef46d9385973c47d Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Mon, 29 Jun 2020 17:59:32 +0200 Subject: [PATCH 07/11] Added xml comments --- .../Core/Duality/Utility/SettingsContainer.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/Core/Duality/Utility/SettingsContainer.cs b/Source/Core/Duality/Utility/SettingsContainer.cs index 88d54fa1a..6488ec0b1 100644 --- a/Source/Core/Duality/Utility/SettingsContainer.cs +++ b/Source/Core/Duality/Utility/SettingsContainer.cs @@ -3,24 +3,46 @@ namespace Duality { + /// + /// A container class to abstract all serialization logic away from settings classes. + /// + /// public class SettingsContainer : ISettingsContainer where TSettings : class, new() { + /// + /// Fired when has changed. + /// public event EventHandler Changed; + + /// + /// The settings data. This is null till is called after which it can never be null again. + /// public TSettings Value { get; private set; } + private readonly string path; + /// + /// Creates a new settings container where the data for the settings will be saved and loaded from . + /// + /// public SettingsContainer(string path) { this.path = path; } + /// + /// Loads the data of from file. + /// public void Load() { this.Value = Serializer.TryReadObject(this.path) ?? new TSettings(); Changed?.Invoke(this, EventArgs.Empty); } + /// + /// Saves the data of to file. + /// public void Save() { Serializer.WriteObject(this.Value, this.path, typeof(XmlSerializer)); From 776bb644ba5e3cfdc65aebeef832a81ba07ec5b3 Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Wed, 1 Jul 2020 20:44:57 +0200 Subject: [PATCH 08/11] updated naming of settings files --- .../{ProjectSettings.dat => EditorAppData.dat} | 0 Source/Editor/DualityEditor/DualityEditorApp.cs | 10 +++++----- Source/Editor/DualityEditor/Forms/MainForm.cs | 16 ++++++++-------- .../DualityEditor/Forms/PublishGameDialog.cs | 2 +- ...ualityProjectSettings.cs => EditorAppData.cs} | 2 +- Source/Plugins/EditorBase/EditorBasePlugin.cs | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) rename Source/DualityTemplates/Templates/SolutionTemplate/{ProjectSettings.dat => EditorAppData.dat} (100%) rename Source/Editor/DualityEditor/Utility/{DualityProjectSettings.cs => EditorAppData.cs} (84%) diff --git a/Source/DualityTemplates/Templates/SolutionTemplate/ProjectSettings.dat b/Source/DualityTemplates/Templates/SolutionTemplate/EditorAppData.dat similarity index 100% rename from Source/DualityTemplates/Templates/SolutionTemplate/ProjectSettings.dat rename to Source/DualityTemplates/Templates/SolutionTemplate/EditorAppData.dat diff --git a/Source/Editor/DualityEditor/DualityEditorApp.cs b/Source/Editor/DualityEditor/DualityEditorApp.cs index 4bb7b7ace..5a918e007 100644 --- a/Source/Editor/DualityEditor/DualityEditorApp.cs +++ b/Source/Editor/DualityEditor/DualityEditorApp.cs @@ -33,7 +33,7 @@ public static class DualityEditorApp public const string EditorPrevLogfileName = "logfile_editor_{0}.txt"; public const string EditorPrevLogfileDir = "Temp"; public const string DesignTimeDataFile = "DesignTimeData.dat"; - public const string UserDataFile = "EditorUserData.xml"; + public const string UserDataFile = "EditorUserData.dat"; private const string UserDataDockSeparator = ""; public const string ActionContextMenu = "ContextMenu"; @@ -132,9 +132,9 @@ public static bool IsFirstEditorSession } /// - /// [GET] Provides access to Duality's current application data. This is never null. + /// [GET] Provides access to Duality's current application data. This is never null. /// - public static SettingsContainer ProjectSettings { get; } = new SettingsContainer("ProjectSettings.dat"); + public static SettingsContainer EditorAppData { get; } = new SettingsContainer("EditorAppData.dat"); public static bool BackupsEnabled { @@ -215,8 +215,8 @@ public static void Init(MainForm mainForm, bool recover) InitMainGraphicsContext(); DualityApp.InitPostWindow(); - ProjectSettings.Load(); - ProjectSettings.Save(); + EditorAppData.Load(); + EditorAppData.Save(); mainForm.UpdateLaunchAppActions(); diff --git a/Source/Editor/DualityEditor/Forms/MainForm.cs b/Source/Editor/DualityEditor/Forms/MainForm.cs index 2e9c06c48..093f5b9e9 100644 --- a/Source/Editor/DualityEditor/Forms/MainForm.cs +++ b/Source/Editor/DualityEditor/Forms/MainForm.cs @@ -493,7 +493,7 @@ private void actionRunApp_Click(object sender, EventArgs e) this.VerifyStartScene(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.FileName = Path.GetFullPath(DualityEditorApp.ProjectSettings.Value.LauncherPath); + startInfo.FileName = Path.GetFullPath(DualityEditorApp.EditorAppData.Value.LauncherPath); startInfo.Arguments = LauncherArgs.CmdArgEditor; startInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process appProc = System.Diagnostics.Process.Start(startInfo); @@ -507,7 +507,7 @@ private void actionDebugApp_Click(object sender, EventArgs e) this.VerifyStartScene(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.FileName = Path.GetFullPath(DualityEditorApp.ProjectSettings.Value.LauncherPath); + startInfo.FileName = Path.GetFullPath(DualityEditorApp.EditorAppData.Value.LauncherPath); startInfo.Arguments = LauncherArgs.CmdArgEditor + " " + LauncherArgs.CmdArgDebug; startInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process appProc = System.Diagnostics.Process.Start(startInfo); @@ -521,7 +521,7 @@ private void actionProfileApp_Click(object sender, EventArgs e) this.VerifyStartScene(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.FileName = Path.GetFullPath(DualityEditorApp.ProjectSettings.Value.LauncherPath); + startInfo.FileName = Path.GetFullPath(DualityEditorApp.EditorAppData.Value.LauncherPath); startInfo.Arguments = LauncherArgs.CmdArgEditor + " " + LauncherArgs.CmdArgProfiling; startInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process appProc = System.Diagnostics.Process.Start(startInfo); @@ -532,10 +532,10 @@ private void actionProfileApp_Click(object sender, EventArgs e) private void actionConfigureLauncher_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); - fileDialog.InitialDirectory = Path.GetDirectoryName(DualityEditorApp.ProjectSettings.Value.LauncherPath); + fileDialog.InitialDirectory = Path.GetDirectoryName(DualityEditorApp.EditorAppData.Value.LauncherPath); if (string.IsNullOrWhiteSpace(fileDialog.InitialDirectory)) fileDialog.InitialDirectory = Environment.CurrentDirectory; - fileDialog.FileName = Path.GetFileName(DualityEditorApp.ProjectSettings.Value.LauncherPath); + fileDialog.FileName = Path.GetFileName(DualityEditorApp.EditorAppData.Value.LauncherPath); fileDialog.Filter = "Executable files (*.exe)|*.exe"; fileDialog.FilterIndex = 1; fileDialog.RestoreDirectory = true; @@ -546,8 +546,8 @@ private void actionConfigureLauncher_Click(object sender, EventArgs e) fileDialog.CustomPlaces.Add(Environment.CurrentDirectory); if (fileDialog.ShowDialog(this) == DialogResult.OK) { - DualityEditorApp.ProjectSettings.Value.LauncherPath = PathHelper.MakeFilePathRelative(fileDialog.FileName); - DualityEditorApp.ProjectSettings.Save(); + DualityEditorApp.EditorAppData.Value.LauncherPath = PathHelper.MakeFilePathRelative(fileDialog.FileName); + DualityEditorApp.EditorAppData.Save(); this.UpdateLaunchAppActions(); } } @@ -801,7 +801,7 @@ private void UpdateSplitButtonBackupSettings() } public void UpdateLaunchAppActions() { - bool launcherAvailable = File.Exists(DualityEditorApp.ProjectSettings.Value.LauncherPath); + bool launcherAvailable = File.Exists(DualityEditorApp.EditorAppData.Value.LauncherPath); this.actionRunApp.Enabled = launcherAvailable; this.actionDebugApp.Enabled = launcherAvailable; this.menuRunApp.Enabled = launcherAvailable; diff --git a/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs b/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs index 01066b95a..d099f385d 100644 --- a/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs +++ b/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs @@ -204,7 +204,7 @@ public static void PublishProject(string targetDir, bool includeSource, bool inc string shortcutFilePath = Path.Combine(archiveBaseDir, gameDirName + ".bat"); File.WriteAllText( shortcutFilePath, - "cd GameData && start " + PathHelper.MakeFilePathRelative(DualityEditorApp.ProjectSettings.Value.LauncherPath)); + "cd GameData && start " + PathHelper.MakeFilePathRelative(DualityEditorApp.EditorAppData.Value.LauncherPath)); // Create a shortcut to the editor if (includeEditor) diff --git a/Source/Editor/DualityEditor/Utility/DualityProjectSettings.cs b/Source/Editor/DualityEditor/Utility/EditorAppData.cs similarity index 84% rename from Source/Editor/DualityEditor/Utility/DualityProjectSettings.cs rename to Source/Editor/DualityEditor/Utility/EditorAppData.cs index a3c089536..284b0f51f 100644 --- a/Source/Editor/DualityEditor/Utility/DualityProjectSettings.cs +++ b/Source/Editor/DualityEditor/Utility/EditorAppData.cs @@ -1,6 +1,6 @@ namespace Duality.Editor { - public class DualityProjectSettings + public class EditorAppData { private string launcherPath = "DualityGame.exe"; public string LauncherPath diff --git a/Source/Plugins/EditorBase/EditorBasePlugin.cs b/Source/Plugins/EditorBase/EditorBasePlugin.cs index 4bf68980e..d8b2a5db3 100644 --- a/Source/Plugins/EditorBase/EditorBasePlugin.cs +++ b/Source/Plugins/EditorBase/EditorBasePlugin.cs @@ -151,7 +151,7 @@ private void menuItemUserData_Click(object sender, EventArgs e) private void menuItemProjectSettings_Click(object sender, EventArgs e) { - DualityEditorApp.Select(this, new ObjectSelection(new[] { DualityEditorApp.ProjectSettings })); + DualityEditorApp.Select(this, new ObjectSelection(new[] { DualityEditorApp.EditorAppData })); } private void DualityEditorApp_ObjectPropertyChanged(object sender, ObjectPropertyChangedEventArgs e) From 48d7eb062db03aebade7e41294e08cb86bab3c62 Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Mon, 6 Jul 2020 17:23:32 +0200 Subject: [PATCH 09/11] change settings to use .xml extension --- Source/Core/Duality/DualityApp.cs | 4 ++-- Source/Core/Duality/Utility/SettingsContainer.cs | 4 ++-- Source/DualityTemplates/DualityTemplates.csproj | 8 ++++++++ .../Templates/SolutionTemplate/.gitignore | 4 ++-- .../{EditorAppData.dat => EditorAppData.xml} | 0 Source/Editor/DualityEditor/DualityEditorApp.cs | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) rename Source/DualityTemplates/Templates/SolutionTemplate/{EditorAppData.dat => EditorAppData.xml} (100%) diff --git a/Source/Core/Duality/DualityApp.cs b/Source/Core/Duality/DualityApp.cs index c515067a2..fc6071c12 100644 --- a/Source/Core/Duality/DualityApp.cs +++ b/Source/Core/Duality/DualityApp.cs @@ -224,12 +224,12 @@ public static SoundDevice Sound /// /// [GET / SET] Provides access to Duality's current application data. This is never null. /// - public static SettingsContainer AppData { get; } = new SettingsContainer("AppData.dat"); + public static SettingsContainer AppData { get; } = new SettingsContainer("AppData.xml"); /// /// [GET / SET] Provides access to Duality's current user data. This is never null. /// - public static SettingsContainer UserData { get; } = new SettingsContainer(execContext == ExecutionContext.Editor ? "DefaultUserData.dat" : "UserData.dat"); + public static SettingsContainer UserData { get; } = new SettingsContainer(execContext == ExecutionContext.Editor ? "DefaultUserData.xml" : "UserData.xml"); /// /// [GET] Returns the in which this DualityApp is currently running. diff --git a/Source/Core/Duality/Utility/SettingsContainer.cs b/Source/Core/Duality/Utility/SettingsContainer.cs index 6488ec0b1..79d8aace3 100644 --- a/Source/Core/Duality/Utility/SettingsContainer.cs +++ b/Source/Core/Duality/Utility/SettingsContainer.cs @@ -36,8 +36,8 @@ public SettingsContainer(string path) /// public void Load() { - this.Value = Serializer.TryReadObject(this.path) ?? new TSettings(); - Changed?.Invoke(this, EventArgs.Empty); + this.Value = Serializer.TryReadObject(this.path, typeof(XmlSerializer)) ?? new TSettings(); + this.Changed?.Invoke(this, EventArgs.Empty); } /// diff --git a/Source/DualityTemplates/DualityTemplates.csproj b/Source/DualityTemplates/DualityTemplates.csproj index e5aa0d0d1..136d5683d 100644 --- a/Source/DualityTemplates/DualityTemplates.csproj +++ b/Source/DualityTemplates/DualityTemplates.csproj @@ -45,6 +45,14 @@ + + + + + + + + Never diff --git a/Source/DualityTemplates/Templates/SolutionTemplate/.gitignore b/Source/DualityTemplates/Templates/SolutionTemplate/.gitignore index 3b79cc92f..f4a3fd271 100644 --- a/Source/DualityTemplates/Templates/SolutionTemplate/.gitignore +++ b/Source/DualityTemplates/Templates/SolutionTemplate/.gitignore @@ -5,14 +5,14 @@ # Duality specific files /Temp /Backup -/UserData.dat -/DesignTimeData.dat *.pdb /*.dll /*.exe /*.txt /*.xml /Plugins +!AppData.xml +!EditorAppData.xml # Visual studio specific files /.vs diff --git a/Source/DualityTemplates/Templates/SolutionTemplate/EditorAppData.dat b/Source/DualityTemplates/Templates/SolutionTemplate/EditorAppData.xml similarity index 100% rename from Source/DualityTemplates/Templates/SolutionTemplate/EditorAppData.dat rename to Source/DualityTemplates/Templates/SolutionTemplate/EditorAppData.xml diff --git a/Source/Editor/DualityEditor/DualityEditorApp.cs b/Source/Editor/DualityEditor/DualityEditorApp.cs index 5a918e007..0661a3278 100644 --- a/Source/Editor/DualityEditor/DualityEditorApp.cs +++ b/Source/Editor/DualityEditor/DualityEditorApp.cs @@ -134,7 +134,7 @@ public static bool IsFirstEditorSession /// /// [GET] Provides access to Duality's current application data. This is never null. /// - public static SettingsContainer EditorAppData { get; } = new SettingsContainer("EditorAppData.dat"); + public static SettingsContainer EditorAppData { get; } = new SettingsContainer("EditorAppData.xml"); public static bool BackupsEnabled { From 78585f6ee8832ff36508a4b99dd5006b60a7b1b0 Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Thu, 9 Jul 2020 13:48:36 +0200 Subject: [PATCH 10/11] cleanup sounddevice and instance --- Source/Core/Duality/Audio/SoundDevice.cs | 28 +++++++++++----------- Source/Core/Duality/Audio/SoundInstance.cs | 23 +++++++++--------- Source/Core/Duality/DualityApp.cs | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Source/Core/Duality/Audio/SoundDevice.cs b/Source/Core/Duality/Audio/SoundDevice.cs index 7645283bb..242e6317d 100644 --- a/Source/Core/Duality/Audio/SoundDevice.cs +++ b/Source/Core/Duality/Audio/SoundDevice.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Threading; -using System.Linq; -using System.Diagnostics; using Duality.Resources; using Duality.Components; @@ -23,7 +20,6 @@ public sealed class SoundDevice : IDisposable private int numPlaying3D = 0; private bool mute = false; - /// /// [GET / SET] The current listener object. This is automatically set to an available /// . @@ -113,10 +109,14 @@ public IEnumerable Playing get { return this.sounds; } } + private readonly SettingsContainer appData; + private readonly SettingsContainer userData; - public SoundDevice() + public SoundDevice(SettingsContainer appData, SettingsContainer userData) { - DualityApp.AppData.Changed += this.DualityApp_AppDataChanged; + this.appData = appData; + this.userData = userData; + this.appData.Changed += this.AppDataChanged; UpdateWorldSettings(); } ~SoundDevice() @@ -133,7 +133,7 @@ private void Dispose(bool manually) if (!this.disposed) { this.disposed = true; - DualityApp.AppData.Changed -= this.DualityApp_AppDataChanged; + this.appData.Changed -= this.AppDataChanged; // Clear all playing sounds foreach (SoundInstance inst in this.sounds) inst.Dispose(); @@ -225,8 +225,8 @@ private void UpdateListener() private void UpdateWorldSettings() { DualityApp.AudioBackend.UpdateWorldSettings( - DualityApp.AppData.Value.SpeedOfSound, // Already in meters per second / audio units - DualityApp.AppData.Value.SoundDopplerFactor); + this.appData.Value.SpeedOfSound, // Already in meters per second / audio units + this.appData.Value.SoundDopplerFactor); } /// @@ -236,7 +236,7 @@ private void UpdateWorldSettings() /// A new representing the playing sound. public SoundInstance PlaySound(ContentRef snd) { - SoundInstance inst = new SoundInstance(snd); + SoundInstance inst = new SoundInstance(this.userData, snd); this.sounds.Add(inst); return inst; } @@ -248,7 +248,7 @@ public SoundInstance PlaySound(ContentRef snd) /// A new representing the playing sound. public SoundInstance PlaySound3D(ContentRef snd, Vector3 pos) { - SoundInstance inst = new SoundInstance(snd, pos); + SoundInstance inst = new SoundInstance(this.userData, snd, pos); this.sounds.Add(inst); return inst; } @@ -261,7 +261,7 @@ public SoundInstance PlaySound3D(ContentRef snd, Vector3 pos) /// A new representing the playing sound. public SoundInstance PlaySound3D(ContentRef snd, GameObject attachTo, bool trackVelocity) { - SoundInstance inst = new SoundInstance(snd, attachTo, trackVelocity); + SoundInstance inst = new SoundInstance(this.userData, snd, attachTo, trackVelocity); this.sounds.Add(inst); return inst; } @@ -275,7 +275,7 @@ public SoundInstance PlaySound3D(ContentRef snd, GameObject attachTo, boo /// A new representing the playing sound. public SoundInstance PlaySound3D(ContentRef snd, GameObject attachTo, Vector3 relativePos, bool trackVelocity) { - SoundInstance inst = new SoundInstance(snd, attachTo, trackVelocity); + SoundInstance inst = new SoundInstance(this.userData, snd, attachTo, trackVelocity); inst.Pos = relativePos; this.sounds.Add(inst); return inst; @@ -291,7 +291,7 @@ public void StopAll() } } - private void DualityApp_AppDataChanged(object sender, EventArgs e) + private void AppDataChanged(object sender, EventArgs e) { UpdateWorldSettings(); } diff --git a/Source/Core/Duality/Audio/SoundInstance.cs b/Source/Core/Duality/Audio/SoundInstance.cs index 18fde640e..e8250a41e 100644 --- a/Source/Core/Duality/Audio/SoundInstance.cs +++ b/Source/Core/Duality/Audio/SoundInstance.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Collections.Concurrent; -using System.Threading; using Duality.Resources; using Duality.Backend; @@ -193,6 +190,7 @@ public Vector3 Vel set { this.vel = value; } } + private readonly SettingsContainer userData; ~SoundInstance() { @@ -228,8 +226,9 @@ private void OnDisposed(bool manually) } - internal SoundInstance(ContentRef sound, GameObject attachObj, bool trackVelocity) + internal SoundInstance(SettingsContainer userData, ContentRef sound, GameObject attachObj, bool trackVelocity) { + this.userData = userData; if (attachObj != null && trackVelocity) attachObj.AddComponent(); @@ -238,15 +237,17 @@ internal SoundInstance(ContentRef sound, GameObject attachObj, bool track this.sound = sound; this.audioData = this.sound.IsAvailable ? this.sound.Res.FetchData() : null; } - internal SoundInstance(ContentRef sound, Vector3 pos) + internal SoundInstance(SettingsContainer userData, ContentRef sound, Vector3 pos) { + this.userData = userData; this.pos = pos; this.is3D = true; this.sound = sound; this.audioData = this.sound.IsAvailable ? this.sound.Res.FetchData() : null; } - internal SoundInstance(ContentRef sound) + internal SoundInstance(SettingsContainer userData, ContentRef sound) { + this.userData = userData; this.sound = sound; this.is3D = false; this.audioData = this.sound.IsAvailable ? this.sound.Res.FetchData() : null; @@ -387,22 +388,22 @@ private float GetTypeVolFactor() switch (this.sound.IsAvailable ? this.sound.Res.Type : SoundType.World) { case SoundType.UserInterface: - optVolFactor = DualityApp.UserData.Value.SoundEffectVol; + optVolFactor = this.userData.Value.SoundEffectVol; break; case SoundType.World: - optVolFactor = DualityApp.UserData.Value.SoundEffectVol; + optVolFactor = this.userData.Value.SoundEffectVol; break; case SoundType.Speech: - optVolFactor = DualityApp.UserData.Value.SoundSpeechVol; + optVolFactor = this.userData.Value.SoundSpeechVol; break; case SoundType.Music: - optVolFactor = DualityApp.UserData.Value.SoundMusicVol; + optVolFactor = this.userData.Value.SoundMusicVol; break; default: optVolFactor = 1.0f; break; } - return optVolFactor * DualityApp.UserData.Value.SoundMasterVol * 0.5f; + return optVolFactor * this.userData.Value.SoundMasterVol * 0.5f; } private void RegisterPlaying() { diff --git a/Source/Core/Duality/DualityApp.cs b/Source/Core/Duality/DualityApp.cs index fc6071c12..3fcdd0dec 100644 --- a/Source/Core/Duality/DualityApp.cs +++ b/Source/Core/Duality/DualityApp.cs @@ -331,7 +331,7 @@ public static void Init(ExecutionEnvironment env, ExecutionContext context, IAss // Initialize the audio backend InitBackend(out audioBack); - sound = new SoundDevice(); + sound = new SoundDevice(AppData, UserData); // Initialize all core plugins, this may allocate Resources or establish references between plugins pluginManager.InitPlugins(); From 0387b8ece9d00d9c6dcfb73be52e8ae6c8904192 Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Fri, 10 Jul 2020 19:59:55 +0200 Subject: [PATCH 11/11] PR comments --- .../BasicMenu/Components/MenuChangeVolume.cs | 4 ++-- Samples/BasicMenu/VolumeRenderer.cs | 2 +- Samples/Benchmarks/BenchmarkController.cs | 4 ++-- Samples/Benchmarks/RenderSetupInfo.cs | 2 +- Samples/Physics/PhysicsSampleController.cs | 2 +- Source/Core/Duality/Audio/SoundDevice.cs | 4 ++-- Source/Core/Duality/Audio/SoundInstance.cs | 10 ++++----- .../Backend/Dummy/DummyNativeWindow.cs | 2 +- Source/Core/Duality/Components/Camera.cs | 2 +- .../Components/Physics/PhysicsWorld.cs | 4 ++-- Source/Core/Duality/DualityApp.cs | 10 ++++----- .../Core/Duality/Launcher/DualityLauncher.cs | 10 ++++----- Source/Core/Duality/Resources/Scene.cs | 2 +- .../Duality/Utility/ISettingsContainer.cs | 11 ++++++++++ .../Core/Duality/Utility/SettingsContainer.cs | 12 +++++----- .../Editor/DualityEditor/DualityEditorApp.cs | 16 +++++++------- Source/Editor/DualityEditor/Forms/MainForm.cs | 22 +++++++++---------- .../DualityEditor/Forms/PublishGameDialog.cs | 4 ++-- .../Backend/Graphics/GraphicsBackend.cs | 4 ++-- .../Backend/Graphics/NativeWindow.cs | 8 +++---- .../CamViewStates/GameViewCamViewState.cs | 14 ++++++------ 21 files changed, 80 insertions(+), 69 deletions(-) diff --git a/Samples/BasicMenu/Components/MenuChangeVolume.cs b/Samples/BasicMenu/Components/MenuChangeVolume.cs index 17ce395a5..2207fb6cb 100644 --- a/Samples/BasicMenu/Components/MenuChangeVolume.cs +++ b/Samples/BasicMenu/Components/MenuChangeVolume.cs @@ -22,13 +22,13 @@ public override void DoAction() { base.DoAction(); - float volume = DualityApp.UserData.Value.SoundMasterVol; + float volume = DualityApp.UserData.Instance.SoundMasterVol; volume += (this.changeAmount / 10f); // make sure that the volume is between 0 and 1 volume = MathF.Min(MathF.Max(volume, 0), 1); - DualityApp.UserData.Value.SoundMasterVol = volume; + DualityApp.UserData.Instance.SoundMasterVol = volume; } } } diff --git a/Samples/BasicMenu/VolumeRenderer.cs b/Samples/BasicMenu/VolumeRenderer.cs index f6a89328f..f3e633b4e 100644 --- a/Samples/BasicMenu/VolumeRenderer.cs +++ b/Samples/BasicMenu/VolumeRenderer.cs @@ -22,7 +22,7 @@ void ICmpUpdatable.OnUpdate() } // update the volume value - volumeText.Text.SourceText = String.Format("Volume {0:0.0}", DualityApp.UserData.Value.SoundMasterVol); + volumeText.Text.SourceText = String.Format("Volume {0:0.0}", DualityApp.UserData.Instance.SoundMasterVol); } } } \ No newline at end of file diff --git a/Samples/Benchmarks/BenchmarkController.cs b/Samples/Benchmarks/BenchmarkController.cs index 6c1b4fdc7..64d7b51e6 100644 --- a/Samples/Benchmarks/BenchmarkController.cs +++ b/Samples/Benchmarks/BenchmarkController.cs @@ -199,12 +199,12 @@ public void EnterBenchmarkMode() this.renderSetup = ContentProvider.GetAvailableContent().FirstOrDefault(); // Make sure the benchmark setup is used globally - DualityApp.AppData.Value.RenderingSetup = this.renderSetup.As(); + DualityApp.AppData.Instance.RenderingSetup = this.renderSetup.As(); } public void LeaveBenchmarkMode() { // Uninstall the benchmark setup we set globally - DualityApp.AppData.Value.RenderingSetup = null; + DualityApp.AppData.Instance.RenderingSetup = null; // Discard local references to content, since we know the controller // itself won't be discarded due to being static diff --git a/Samples/Benchmarks/RenderSetupInfo.cs b/Samples/Benchmarks/RenderSetupInfo.cs index c56045431..4d34cc45f 100644 --- a/Samples/Benchmarks/RenderSetupInfo.cs +++ b/Samples/Benchmarks/RenderSetupInfo.cs @@ -64,7 +64,7 @@ void ICmpInitializable.OnActivate() { if (DualityApp.ExecContext == DualityApp.ExecutionContext.Game) { - this.renderSetup = DualityApp.AppData.Value.RenderingSetup.As(); + this.renderSetup = DualityApp.AppData.Instance.RenderingSetup.As(); this.text = new FormattedText(); this.text.LineAlign = Alignment.Right; this.text.MaxWidth = 200; diff --git a/Samples/Physics/PhysicsSampleController.cs b/Samples/Physics/PhysicsSampleController.cs index ee1222a3a..0e1678b6d 100644 --- a/Samples/Physics/PhysicsSampleController.cs +++ b/Samples/Physics/PhysicsSampleController.cs @@ -101,7 +101,7 @@ void ICmpRenderer.Draw(IDrawDevice device) // When the mouse is hovering over the game area and the system cursor // is disabled, draw a custom cursor as a replacement - if (!DualityApp.UserData.Value.SystemCursorVisible && DualityApp.Mouse.IsAvailable) + if (!DualityApp.UserData.Instance.SystemCursorVisible && DualityApp.Mouse.IsAvailable) { canvas.State.ColorTint = (this.dragObj != null) ? this.interactionColor : this.defaultColor; canvas.FillThickLine( diff --git a/Source/Core/Duality/Audio/SoundDevice.cs b/Source/Core/Duality/Audio/SoundDevice.cs index 242e6317d..01546bc38 100644 --- a/Source/Core/Duality/Audio/SoundDevice.cs +++ b/Source/Core/Duality/Audio/SoundDevice.cs @@ -225,8 +225,8 @@ private void UpdateListener() private void UpdateWorldSettings() { DualityApp.AudioBackend.UpdateWorldSettings( - this.appData.Value.SpeedOfSound, // Already in meters per second / audio units - this.appData.Value.SoundDopplerFactor); + this.appData.Instance.SpeedOfSound, // Already in meters per second / audio units + this.appData.Instance.SoundDopplerFactor); } /// diff --git a/Source/Core/Duality/Audio/SoundInstance.cs b/Source/Core/Duality/Audio/SoundInstance.cs index e8250a41e..5c51edd4c 100644 --- a/Source/Core/Duality/Audio/SoundInstance.cs +++ b/Source/Core/Duality/Audio/SoundInstance.cs @@ -388,22 +388,22 @@ private float GetTypeVolFactor() switch (this.sound.IsAvailable ? this.sound.Res.Type : SoundType.World) { case SoundType.UserInterface: - optVolFactor = this.userData.Value.SoundEffectVol; + optVolFactor = this.userData.Instance.SoundEffectVol; break; case SoundType.World: - optVolFactor = this.userData.Value.SoundEffectVol; + optVolFactor = this.userData.Instance.SoundEffectVol; break; case SoundType.Speech: - optVolFactor = this.userData.Value.SoundSpeechVol; + optVolFactor = this.userData.Instance.SoundSpeechVol; break; case SoundType.Music: - optVolFactor = this.userData.Value.SoundMusicVol; + optVolFactor = this.userData.Instance.SoundMusicVol; break; default: optVolFactor = 1.0f; break; } - return optVolFactor * this.userData.Value.SoundMasterVol * 0.5f; + return optVolFactor * this.userData.Instance.SoundMasterVol * 0.5f; } private void RegisterPlaying() { diff --git a/Source/Core/Duality/Backend/Dummy/DummyNativeWindow.cs b/Source/Core/Duality/Backend/Dummy/DummyNativeWindow.cs index fa0f6571e..54885fe5a 100644 --- a/Source/Core/Duality/Backend/Dummy/DummyNativeWindow.cs +++ b/Source/Core/Duality/Backend/Dummy/DummyNativeWindow.cs @@ -15,7 +15,7 @@ void INativeWindow.Run() while (DualityApp.ExecContext != DualityApp.ExecutionContext.Terminated) { DualityApp.Update(); - DualityApp.Render(null, new Rect(DualityApp.UserData.Value.WindowSize), DualityApp.UserData.Value.WindowSize); + DualityApp.Render(null, new Rect(DualityApp.UserData.Instance.WindowSize), DualityApp.UserData.Instance.WindowSize); } } diff --git a/Source/Core/Duality/Components/Camera.cs b/Source/Core/Duality/Components/Camera.cs index 2324c0f09..ed3f7b811 100644 --- a/Source/Core/Duality/Components/Camera.cs +++ b/Source/Core/Duality/Components/Camera.cs @@ -156,7 +156,7 @@ public RenderSetup ActiveRenderSetup { return this.renderSetup.Res ?? - DualityApp.AppData.Value.RenderingSetup.Res ?? + DualityApp.AppData.Instance.RenderingSetup.Res ?? RenderSetup.Default.Res; } } diff --git a/Source/Core/Duality/Components/Physics/PhysicsWorld.cs b/Source/Core/Duality/Components/Physics/PhysicsWorld.cs index c2db20077..63a81f76f 100644 --- a/Source/Core/Duality/Components/Physics/PhysicsWorld.cs +++ b/Source/Core/Duality/Components/Physics/PhysicsWorld.cs @@ -65,7 +65,7 @@ public float InterpolateAlpha /// public bool IsFixedTimestep { - get { return DualityApp.AppData.Value.PhysicsFixedTime && !this.lowFramerateMode; } + get { return DualityApp.AppData.Instance.PhysicsFixedTime && !this.lowFramerateMode; } } @@ -384,7 +384,7 @@ public bool QueryRect(Vector2 worldCoord, Vector2 size, List queriedB private void UpdateNativeSettings() { - Settings.VelocityThreshold = PhysicsUnit.VelocityToPhysical * DualityApp.AppData.Value.PhysicsVelocityThreshold; + Settings.VelocityThreshold = PhysicsUnit.VelocityToPhysical * DualityApp.AppData.Instance.PhysicsVelocityThreshold; } } } diff --git a/Source/Core/Duality/DualityApp.cs b/Source/Core/Duality/DualityApp.cs index 3fcdd0dec..f44cde7d6 100644 --- a/Source/Core/Duality/DualityApp.cs +++ b/Source/Core/Duality/DualityApp.cs @@ -171,7 +171,7 @@ public static Vector2 TargetViewSize { get { - Point2 forcedRenderSize = DualityApp.AppData.Value.ForcedRenderSize; + Point2 forcedRenderSize = DualityApp.AppData.Instance.ForcedRenderSize; if (forcedRenderSize.X > 0 && forcedRenderSize.Y > 0) return forcedRenderSize; else @@ -593,8 +593,8 @@ public static void Render(ContentRef target, Rect viewportRect, Ve /// public static void CalculateGameViewport(Point2 windowSize, out Rect windowViewport, out Vector2 renderTargetSize) { - Point2 forcedSize = DualityApp.AppData.Value.ForcedRenderSize; - TargetResize forcedResizeMode = DualityApp.AppData.Value.ForcedRenderResizeMode; + Point2 forcedSize = DualityApp.AppData.Instance.ForcedRenderSize; + TargetResize forcedResizeMode = DualityApp.AppData.Instance.ForcedRenderResizeMode; renderTargetSize = windowSize; windowViewport = new Rect(renderTargetSize); @@ -729,8 +729,8 @@ internal static void InitBackend(out T target, Func string.Equals(s, backend.Id, StringComparison.OrdinalIgnoreCase))) + if (DualityApp.AppData.Instance?.SkipBackends != null && + DualityApp.AppData.Instance.SkipBackends.Any(s => string.Equals(s, backend.Id, StringComparison.OrdinalIgnoreCase))) { Logs.Core.Write("Backend '{0}' skipped because of AppData settings.", backend.Name); continue; diff --git a/Source/Core/Duality/Launcher/DualityLauncher.cs b/Source/Core/Duality/Launcher/DualityLauncher.cs index bf19f1a3d..1c1047db0 100644 --- a/Source/Core/Duality/Launcher/DualityLauncher.cs +++ b/Source/Core/Duality/Launcher/DualityLauncher.cs @@ -64,11 +64,11 @@ public DualityLauncher(LauncherArgs launcherArgs = null) // Open up a new window WindowOptions options = new WindowOptions { - Size = DualityApp.UserData.Value.WindowSize, - ScreenMode = launcherArgs.IsDebugging ? ScreenMode.Window : DualityApp.UserData.Value.WindowMode, - RefreshMode = launcherArgs.IsProfiling ? RefreshMode.NoSync : DualityApp.UserData.Value.WindowRefreshMode, - Title = DualityApp.AppData.Value.AppName, - SystemCursorVisible = launcherArgs.IsDebugging || DualityApp.UserData.Value.SystemCursorVisible + 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); } diff --git a/Source/Core/Duality/Resources/Scene.cs b/Source/Core/Duality/Resources/Scene.cs index ba91bf013..066039a6e 100644 --- a/Source/Core/Duality/Resources/Scene.cs +++ b/Source/Core/Duality/Resources/Scene.cs @@ -472,7 +472,7 @@ public void Render(ContentRef target, Rect viewportRect, Vector2 i { // Retrieve the rendering setup that will be used for rendering the scene RenderSetup setup = - DualityApp.AppData.Value.RenderingSetup.Res ?? + DualityApp.AppData.Instance.RenderingSetup.Res ?? RenderSetup.Default.Res; // Render the scene diff --git a/Source/Core/Duality/Utility/ISettingsContainer.cs b/Source/Core/Duality/Utility/ISettingsContainer.cs index b6fde2db0..076494c17 100644 --- a/Source/Core/Duality/Utility/ISettingsContainer.cs +++ b/Source/Core/Duality/Utility/ISettingsContainer.cs @@ -4,8 +4,19 @@ namespace Duality { public interface ISettingsContainer { + /// + /// Fired when settings have changed. + /// event EventHandler Changed; + + /// + /// Loads the data of the settings. + /// void Load(); + + /// + /// Saves the data of the settings. + /// void Save(); } } diff --git a/Source/Core/Duality/Utility/SettingsContainer.cs b/Source/Core/Duality/Utility/SettingsContainer.cs index 79d8aace3..020bd1f40 100644 --- a/Source/Core/Duality/Utility/SettingsContainer.cs +++ b/Source/Core/Duality/Utility/SettingsContainer.cs @@ -10,17 +10,17 @@ namespace Duality public class SettingsContainer : ISettingsContainer where TSettings : class, new() { + private readonly string path; + /// - /// Fired when has changed. + /// Fired when has changed. /// public event EventHandler Changed; /// /// The settings data. This is null till is called after which it can never be null again. /// - public TSettings Value { get; private set; } - - private readonly string path; + public TSettings Instance { get; private set; } /// /// Creates a new settings container where the data for the settings will be saved and loaded from . @@ -36,7 +36,7 @@ public SettingsContainer(string path) /// public void Load() { - this.Value = Serializer.TryReadObject(this.path, typeof(XmlSerializer)) ?? new TSettings(); + this.Instance = Serializer.TryReadObject(this.path, typeof(XmlSerializer)) ?? new TSettings(); this.Changed?.Invoke(this, EventArgs.Empty); } @@ -45,7 +45,7 @@ public void Load() /// public void Save() { - Serializer.WriteObject(this.Value, this.path, typeof(XmlSerializer)); + Serializer.WriteObject(this.Instance, this.path, typeof(XmlSerializer)); } } } diff --git a/Source/Editor/DualityEditor/DualityEditorApp.cs b/Source/Editor/DualityEditor/DualityEditorApp.cs index 0661a3278..aea48fb2e 100644 --- a/Source/Editor/DualityEditor/DualityEditorApp.cs +++ b/Source/Editor/DualityEditor/DualityEditorApp.cs @@ -561,8 +561,8 @@ private static void InitMainGraphicsContext() // Currently bound to game-specific settings. Should be decoupled // from them at some point, so the editor can use independent settings. mainGraphicsContext = graphicsBack.CreateContext( - DualityApp.AppData.Value.MultisampleBackBuffer ? - DualityApp.UserData.Value.AntialiasingQuality : + DualityApp.AppData.Instance.MultisampleBackBuffer ? + DualityApp.UserData.Instance.AntialiasingQuality : AAQuality.Off); } catch (Exception e) @@ -640,7 +640,7 @@ public static string SaveCurrentScene(bool skipYetUnsaved = true) if (IsResourceUnsaved(Scene.Current)) { Scene.Current.Save(); - DualityApp.AppData.Value.Version++; + DualityApp.AppData.Instance.Version++; } } else if (!skipYetUnsaved) @@ -648,12 +648,12 @@ public static string SaveCurrentScene(bool skipYetUnsaved = true) string basePath = Path.Combine(DualityApp.DataDirectory, "Scene"); string path = PathHelper.GetFreePath(basePath, Resource.GetFileExtByType()); Scene.Current.Save(path); - DualityApp.AppData.Value.Version++; + DualityApp.AppData.Instance.Version++; // If there is no start scene defined, use this one. - if (DualityApp.AppData.Value.StartScene == null) + if (DualityApp.AppData.Instance.StartScene == null) { - DualityApp.AppData.Value.StartScene = Scene.Current; + DualityApp.AppData.Instance.StartScene = Scene.Current; DualityApp.AppData.Save(); } } @@ -669,7 +669,7 @@ public static void SaveResources() anySaved = true; } unsavedResources.Clear(); - if (anySaved) DualityApp.AppData.Value.Version++; + if (anySaved) DualityApp.AppData.Instance.Version++; } public static void FlagResourceUnsaved(IEnumerable res) { @@ -1250,7 +1250,7 @@ private static void FileEventManager_PluginsChanged(object sender, FileSystemCha if (!corePluginReloader.ReloadSchedule.Contains(fileEvent.Path)) { corePluginReloader.ReloadSchedule.Add(fileEvent.Path); - DualityApp.AppData.Value.Version++; + DualityApp.AppData.Instance.Version++; } } corePluginReloader.State = ReloadCorePluginDialog.ReloaderState.WaitForPlugins; diff --git a/Source/Editor/DualityEditor/Forms/MainForm.cs b/Source/Editor/DualityEditor/Forms/MainForm.cs index 093f5b9e9..b1eefce62 100644 --- a/Source/Editor/DualityEditor/Forms/MainForm.cs +++ b/Source/Editor/DualityEditor/Forms/MainForm.cs @@ -493,7 +493,7 @@ private void actionRunApp_Click(object sender, EventArgs e) this.VerifyStartScene(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.FileName = Path.GetFullPath(DualityEditorApp.EditorAppData.Value.LauncherPath); + startInfo.FileName = Path.GetFullPath(DualityEditorApp.EditorAppData.Instance.LauncherPath); startInfo.Arguments = LauncherArgs.CmdArgEditor; startInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process appProc = System.Diagnostics.Process.Start(startInfo); @@ -507,7 +507,7 @@ private void actionDebugApp_Click(object sender, EventArgs e) this.VerifyStartScene(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.FileName = Path.GetFullPath(DualityEditorApp.EditorAppData.Value.LauncherPath); + startInfo.FileName = Path.GetFullPath(DualityEditorApp.EditorAppData.Instance.LauncherPath); startInfo.Arguments = LauncherArgs.CmdArgEditor + " " + LauncherArgs.CmdArgDebug; startInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process appProc = System.Diagnostics.Process.Start(startInfo); @@ -521,7 +521,7 @@ private void actionProfileApp_Click(object sender, EventArgs e) this.VerifyStartScene(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.FileName = Path.GetFullPath(DualityEditorApp.EditorAppData.Value.LauncherPath); + startInfo.FileName = Path.GetFullPath(DualityEditorApp.EditorAppData.Instance.LauncherPath); startInfo.Arguments = LauncherArgs.CmdArgEditor + " " + LauncherArgs.CmdArgProfiling; startInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process appProc = System.Diagnostics.Process.Start(startInfo); @@ -532,10 +532,10 @@ private void actionProfileApp_Click(object sender, EventArgs e) private void actionConfigureLauncher_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); - fileDialog.InitialDirectory = Path.GetDirectoryName(DualityEditorApp.EditorAppData.Value.LauncherPath); + fileDialog.InitialDirectory = Path.GetDirectoryName(DualityEditorApp.EditorAppData.Instance.LauncherPath); if (string.IsNullOrWhiteSpace(fileDialog.InitialDirectory)) fileDialog.InitialDirectory = Environment.CurrentDirectory; - fileDialog.FileName = Path.GetFileName(DualityEditorApp.EditorAppData.Value.LauncherPath); + fileDialog.FileName = Path.GetFileName(DualityEditorApp.EditorAppData.Instance.LauncherPath); fileDialog.Filter = "Executable files (*.exe)|*.exe"; fileDialog.FilterIndex = 1; fileDialog.RestoreDirectory = true; @@ -546,7 +546,7 @@ private void actionConfigureLauncher_Click(object sender, EventArgs e) fileDialog.CustomPlaces.Add(Environment.CurrentDirectory); if (fileDialog.ShowDialog(this) == DialogResult.OK) { - DualityEditorApp.EditorAppData.Value.LauncherPath = PathHelper.MakeFilePathRelative(fileDialog.FileName); + DualityEditorApp.EditorAppData.Instance.LauncherPath = PathHelper.MakeFilePathRelative(fileDialog.FileName); DualityEditorApp.EditorAppData.Save(); this.UpdateLaunchAppActions(); } @@ -801,7 +801,7 @@ private void UpdateSplitButtonBackupSettings() } public void UpdateLaunchAppActions() { - bool launcherAvailable = File.Exists(DualityEditorApp.EditorAppData.Value.LauncherPath); + bool launcherAvailable = File.Exists(DualityEditorApp.EditorAppData.Instance.LauncherPath); this.actionRunApp.Enabled = launcherAvailable; this.actionDebugApp.Enabled = launcherAvailable; this.menuRunApp.Enabled = launcherAvailable; @@ -810,12 +810,12 @@ public void UpdateLaunchAppActions() } private void VerifyStartScene() { - if (DualityApp.AppData.Value.StartScene != null) return; + if (DualityApp.AppData.Instance.StartScene != null) return; // If there is no StartScene defined, attempt to find one automatically. if (!Scene.Current.IsRuntimeResource) { - DualityApp.AppData.Value.StartScene = Scene.Current; + DualityApp.AppData.Instance.StartScene = Scene.Current; DualityApp.AppData.Save(); } else @@ -823,13 +823,13 @@ private void VerifyStartScene() ContentRef existingScene = ContentProvider.GetAvailableContent().FirstOrDefault(); if (existingScene != null) { - DualityApp.AppData.Value.StartScene = existingScene; + DualityApp.AppData.Instance.StartScene = existingScene; DualityApp.AppData.Save(); } else if (!Scene.Current.IsEmpty) { DualityEditorApp.SaveCurrentScene(false); - DualityApp.AppData.Value.StartScene = Scene.Current; + DualityApp.AppData.Instance.StartScene = Scene.Current; DualityApp.AppData.Save(); } } diff --git a/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs b/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs index d099f385d..5e324ac87 100644 --- a/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs +++ b/Source/Editor/DualityEditor/Forms/PublishGameDialog.cs @@ -129,7 +129,7 @@ private void buttonPublish_Click(object sender, EventArgs e) public static void PublishProject(string targetDir, bool includeSource, bool includeEditor, bool compress, bool createShortcuts, Func targetExistsCallback = null) { // Determine a valid directory name for the game - string gameDirName = PathOp.GetValidFileName(DualityApp.AppData.Value.AppName); + string gameDirName = PathOp.GetValidFileName(DualityApp.AppData.Instance.AppName); string targetGameDir = Path.Combine(targetDir, gameDirName); string archiveBaseDir = targetGameDir; @@ -204,7 +204,7 @@ public static void PublishProject(string targetDir, bool includeSource, bool inc string shortcutFilePath = Path.Combine(archiveBaseDir, gameDirName + ".bat"); File.WriteAllText( shortcutFilePath, - "cd GameData && start " + PathHelper.MakeFilePathRelative(DualityEditorApp.EditorAppData.Value.LauncherPath)); + "cd GameData && start " + PathHelper.MakeFilePathRelative(DualityEditorApp.EditorAppData.Instance.LauncherPath)); // Create a shortcut to the editor if (includeEditor) diff --git a/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs b/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs index 82d3b3d4b..e7a438ac6 100644 --- a/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs +++ b/Source/Platform/DefaultOpenTK/Backend/Graphics/GraphicsBackend.cs @@ -410,9 +410,9 @@ private void QueryGraphicsModes() sortedModes.StableSort((a, b) => a.Samples - b.Samples); int highestAALevel = MathF.RoundToInt(MathF.Log(MathF.Max(sortedModes.Max(m => m.Samples), 1.0f), 2.0f)); int targetAALevel = highestAALevel; - if (DualityApp.AppData.Value.MultisampleBackBuffer) + if (DualityApp.AppData.Instance.MultisampleBackBuffer) { - switch (DualityApp.UserData.Value.AntialiasingQuality) + switch (DualityApp.UserData.Instance.AntialiasingQuality) { case AAQuality.High: targetAALevel = highestAALevel; break; case AAQuality.Medium: targetAALevel = highestAALevel / 2; break; diff --git a/Source/Platform/DefaultOpenTK/Backend/Graphics/NativeWindow.cs b/Source/Platform/DefaultOpenTK/Backend/Graphics/NativeWindow.cs index 336b1b706..50cd33527 100644 --- a/Source/Platform/DefaultOpenTK/Backend/Graphics/NativeWindow.cs +++ b/Source/Platform/DefaultOpenTK/Backend/Graphics/NativeWindow.cs @@ -193,22 +193,22 @@ private void OnUserDataChanged(object sender, EventArgs e) if (DisplayDevice.Default == null) return; // Determine the target state for our window - MouseCursor targetCursor = DualityApp.UserData.Value.SystemCursorVisible ? MouseCursor.Default : MouseCursor.Empty; + MouseCursor targetCursor = DualityApp.UserData.Instance.SystemCursorVisible ? MouseCursor.Default : MouseCursor.Empty; WindowState targetWindowState = this.internalWindow.WindowState; WindowBorder targetWindowBorder = this.internalWindow.WindowBorder; Size targetSize = this.internalWindow.ClientSize; - switch (DualityApp.UserData.Value.WindowMode) + switch (DualityApp.UserData.Instance.WindowMode) { case ScreenMode.Window: targetWindowState = WindowState.Normal; targetWindowBorder = WindowBorder.Resizable; - targetSize = new Size(DualityApp.UserData.Value.WindowSize.X, DualityApp.UserData.Value.WindowSize.Y); + targetSize = new Size(DualityApp.UserData.Instance.WindowSize.X, DualityApp.UserData.Instance.WindowSize.Y); break; case ScreenMode.FixedWindow: targetWindowState = WindowState.Normal; targetWindowBorder = WindowBorder.Fixed; - targetSize = new Size(DualityApp.UserData.Value.WindowSize.X, DualityApp.UserData.Value.WindowSize.Y); + targetSize = new Size(DualityApp.UserData.Instance.WindowSize.X, DualityApp.UserData.Instance.WindowSize.Y); break; case ScreenMode.FullWindow: diff --git a/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs b/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs index 277fd9640..677ab0b9f 100644 --- a/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs +++ b/Source/Plugins/EditorModules/CamView/CamViewStates/GameViewCamViewState.cs @@ -85,8 +85,8 @@ private AAQuality GameAntialiasingQuality { get { - return DualityApp.AppData.Value.MultisampleBackBuffer ? - DualityApp.UserData.Value.AntialiasingQuality : + return DualityApp.AppData.Instance.MultisampleBackBuffer ? + DualityApp.UserData.Instance.AntialiasingQuality : AAQuality.Off; } } @@ -99,12 +99,12 @@ private Point2 GameTargetSize get { bool isUsingForcedSize = - DualityApp.AppData.Value.ForcedRenderResizeMode != TargetResize.None && - DualityApp.AppData.Value.ForcedRenderSize.X != 0 && - DualityApp.AppData.Value.ForcedRenderSize.Y != 0; + DualityApp.AppData.Instance.ForcedRenderResizeMode != TargetResize.None && + DualityApp.AppData.Instance.ForcedRenderSize.X != 0 && + DualityApp.AppData.Instance.ForcedRenderSize.Y != 0; return isUsingForcedSize ? - DualityApp.AppData.Value.ForcedRenderSize : - DualityApp.UserData.Value.WindowSize; + DualityApp.AppData.Instance.ForcedRenderSize : + DualityApp.UserData.Instance.WindowSize; } } ///