Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsonax committed Jul 10, 2020
1 parent 78585f6 commit 0387b8e
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Samples/BasicMenu/Components/MenuChangeVolume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion Samples/BasicMenu/VolumeRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions Samples/Benchmarks/BenchmarkController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ public void EnterBenchmarkMode()
this.renderSetup = ContentProvider.GetAvailableContent<BenchmarkRenderSetup>().FirstOrDefault();

// Make sure the benchmark setup is used globally
DualityApp.AppData.Value.RenderingSetup = this.renderSetup.As<RenderSetup>();
DualityApp.AppData.Instance.RenderingSetup = this.renderSetup.As<RenderSetup>();
}
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
Expand Down
2 changes: 1 addition & 1 deletion Samples/Benchmarks/RenderSetupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void ICmpInitializable.OnActivate()
{
if (DualityApp.ExecContext == DualityApp.ExecutionContext.Game)
{
this.renderSetup = DualityApp.AppData.Value.RenderingSetup.As<BenchmarkRenderSetup>();
this.renderSetup = DualityApp.AppData.Instance.RenderingSetup.As<BenchmarkRenderSetup>();
this.text = new FormattedText();
this.text.LineAlign = Alignment.Right;
this.text.MaxWidth = 200;
Expand Down
2 changes: 1 addition & 1 deletion Samples/Physics/PhysicsSampleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Duality/Audio/SoundDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/Duality/Audio/SoundInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Duality/Backend/Dummy/DummyNativeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Duality/Components/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public RenderSetup ActiveRenderSetup
{
return
this.renderSetup.Res ??
DualityApp.AppData.Value.RenderingSetup.Res ??
DualityApp.AppData.Instance.RenderingSetup.Res ??
RenderSetup.Default.Res;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Duality/Components/Physics/PhysicsWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public float InterpolateAlpha
/// </summary>
public bool IsFixedTimestep
{
get { return DualityApp.AppData.Value.PhysicsFixedTime && !this.lowFramerateMode; }
get { return DualityApp.AppData.Instance.PhysicsFixedTime && !this.lowFramerateMode; }
}


Expand Down Expand Up @@ -384,7 +384,7 @@ public bool QueryRect(Vector2 worldCoord, Vector2 size, List<RigidBody> queriedB

private void UpdateNativeSettings()
{
Settings.VelocityThreshold = PhysicsUnit.VelocityToPhysical * DualityApp.AppData.Value.PhysicsVelocityThreshold;
Settings.VelocityThreshold = PhysicsUnit.VelocityToPhysical * DualityApp.AppData.Instance.PhysicsVelocityThreshold;
}
}
}
10 changes: 5 additions & 5 deletions Source/Core/Duality/DualityApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -593,8 +593,8 @@ public static void Render(ContentRef<RenderTarget> target, Rect viewportRect, Ve
/// <param name="renderTargetSize"></param>
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);
Expand Down Expand Up @@ -729,8 +729,8 @@ internal static void InitBackend<T>(out T target, Func<Type,IEnumerable<TypeInfo
T selectedBackend = null;
foreach (T backend in backends)
{
if (DualityApp.AppData.Value?.SkipBackends != null &&
DualityApp.AppData.Value.SkipBackends.Any(s => 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;
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/Duality/Launcher/DualityLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Duality/Resources/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public void Render(ContentRef<RenderTarget> 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
Expand Down
11 changes: 11 additions & 0 deletions Source/Core/Duality/Utility/ISettingsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ namespace Duality
{
public interface ISettingsContainer
{
/// <summary>
/// Fired when settings have changed.
/// </summary>
event EventHandler Changed;

/// <summary>
/// Loads the data of the settings.
/// </summary>
void Load();

/// <summary>
/// Saves the data of the settings.
/// </summary>
void Save();
}
}
12 changes: 6 additions & 6 deletions Source/Core/Duality/Utility/SettingsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ namespace Duality
public class SettingsContainer<TSettings> : ISettingsContainer
where TSettings : class, new()
{
private readonly string path;

/// <summary>
/// Fired when <see cref="Value"/> has changed.
/// Fired when <see cref="Instance"/> has changed.
/// </summary>
public event EventHandler Changed;

/// <summary>
/// The settings data. This is null till <see cref="Load"/> is called after which it can never be null again.
/// </summary>
public TSettings Value { get; private set; }

private readonly string path;
public TSettings Instance { get; private set; }

/// <summary>
/// Creates a new settings container where the data for the settings will be saved and loaded from <paramref name="path"/>.
Expand All @@ -36,7 +36,7 @@ public SettingsContainer(string path)
/// </summary>
public void Load()
{
this.Value = Serializer.TryReadObject<TSettings>(this.path, typeof(XmlSerializer)) ?? new TSettings();
this.Instance = Serializer.TryReadObject<TSettings>(this.path, typeof(XmlSerializer)) ?? new TSettings();
this.Changed?.Invoke(this, EventArgs.Empty);
}

Expand All @@ -45,7 +45,7 @@ public void Load()
/// </summary>
public void Save()
{
Serializer.WriteObject(this.Value, this.path, typeof(XmlSerializer));
Serializer.WriteObject(this.Instance, this.path, typeof(XmlSerializer));
}
}
}
16 changes: 8 additions & 8 deletions Source/Editor/DualityEditor/DualityEditorApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -640,20 +640,20 @@ 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)
{
string basePath = Path.Combine(DualityApp.DataDirectory, "Scene");
string path = PathHelper.GetFreePath(basePath, Resource.GetFileExtByType<Scene>());
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();
}
}
Expand All @@ -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<Resource> res)
{
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions Source/Editor/DualityEditor/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -810,26 +810,26 @@ 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
{
ContentRef<Scene> existingScene = ContentProvider.GetAvailableContent<Scene>().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();
}
}
Expand Down
Loading

0 comments on commit 0387b8e

Please sign in to comment.