From 62a9c19ae19a9129021aeb9ec596fbae5950e5dd Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 20 Dec 2019 13:43:19 +0100 Subject: [PATCH] =?UTF-8?q?Removed=20my=20'optimisations'=20from=20LED=20s?= =?UTF-8?q?amples=20and=20made=20it=20a=20lot=20faster=20=F0=9F=98=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expanded settings --- src/Artemis.Core/RGB.NET/BitmapBrush.cs | 34 ++---- src/Artemis.UI/Artemis.UI.csproj | 3 +- .../Screens/Settings/SettingsView.xaml | 109 ++++++++++-------- .../Screens/Settings/SettingsViewModel.cs | 39 +++++-- .../Tabs/Plugins/PluginSettingsViewModel.cs | 23 ++++ 5 files changed, 129 insertions(+), 79 deletions(-) create mode 100644 src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs diff --git a/src/Artemis.Core/RGB.NET/BitmapBrush.cs b/src/Artemis.Core/RGB.NET/BitmapBrush.cs index 46a11e38f..57bdee0b2 100644 --- a/src/Artemis.Core/RGB.NET/BitmapBrush.cs +++ b/src/Artemis.Core/RGB.NET/BitmapBrush.cs @@ -46,6 +46,7 @@ namespace Artemis.Core.RGB.NET public Dictionary RenderedTargets { get; } = new Dictionary(); public Scale Scale { get; set; } + public Scale RenderedScale { get; private set; } public SKBitmap Bitmap { get; private set; } #endregion @@ -85,7 +86,6 @@ namespace Artemis.Core.RGB.NET { var sampleSize = _sampleSizeSetting.Value; var sampleDepth = Math.Sqrt(sampleSize).RoundToInt(); - var pixelSpan = Bitmap.GetPixelSpan(); foreach (var renderTarget in renderTargets) { @@ -94,7 +94,8 @@ namespace Artemis.Core.RGB.NET (float) ((renderTarget.Rectangle.Location.X + 4) * Scale.Horizontal), (float) ((renderTarget.Rectangle.Location.Y + 4) * Scale.Vertical), (float) ((renderTarget.Rectangle.Size.Width - 8) * Scale.Horizontal), - (float) ((renderTarget.Rectangle.Size.Height - 8) * Scale.Vertical)); + (float) ((renderTarget.Rectangle.Size.Height - 8) * Scale.Vertical) + ); var verticalSteps = rect.Height / (sampleDepth - 1); var horizontalSteps = rect.Width / (sampleDepth - 1); @@ -103,6 +104,8 @@ namespace Artemis.Core.RGB.NET var r = 0; var g = 0; var b = 0; + + // TODO: Compare this with LINQ, might be quicker and cleaner for (var horizontalStep = 0; horizontalStep < sampleDepth; horizontalStep++) { for (var verticalStep = 0; verticalStep < sampleDepth; verticalStep++) @@ -112,11 +115,11 @@ namespace Artemis.Core.RGB.NET if (x < 0 || x > Bitmap.Width || y < 0 || y > Bitmap.Height) continue; - var (pixelA, pixelR, pixelG, pixelB) = GetRgbColor(pixelSpan, x, y); - a += pixelA; - r += pixelR; - g += pixelG; - b += pixelB; + var color = Bitmap.GetPixel(x, y); + a += color.Alpha; + r += color.Red; + g += color.Green; + b += color.Blue; // Uncomment to view the sample pixels in the debugger, need a checkbox in the actual debugger but this was a quickie // Bitmap.SetPixel(x, y, new SKColor(0, 255, 0)); @@ -127,8 +130,6 @@ namespace Artemis.Core.RGB.NET } } - public Scale RenderedScale { get; private set; } - private void CreateBitmap(Rectangle rectangle) { var width = Math.Min((rectangle.Location.X + rectangle.Size.Width) * Scale.Horizontal, 4096); @@ -136,21 +137,6 @@ namespace Artemis.Core.RGB.NET Bitmap = new SKBitmap(new SKImageInfo(width.RoundToInt(), height.RoundToInt())); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private Tuple GetRgbColor(in ReadOnlySpan pixelSpan, float x, float y) - { - var index = ((int) y * Bitmap.Width + (int) x) * 4; - if (index + 3 > pixelSpan.Length) - return new Tuple(0, 0, 0, 0); - - var b = pixelSpan[index]; - var g = pixelSpan[index + 1]; - var r = pixelSpan[index + 2]; - var a = pixelSpan[index + 3]; - - return new Tuple(a, r, g, b); - } - /// public virtual void PerformFinalize() { diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index a57331b6e..a5f7cb957 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -201,6 +201,7 @@ + SidebarView.xaml @@ -533,5 +534,5 @@ - + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/SettingsView.xaml b/src/Artemis.UI/Screens/Settings/SettingsView.xaml index c0897814b..51d99aa03 100644 --- a/src/Artemis.UI/Screens/Settings/SettingsView.xaml +++ b/src/Artemis.UI/Screens/Settings/SettingsView.xaml @@ -78,11 +78,58 @@ - + + + + + + + + + + + + + Logs + + Opens the directory where logs are stored. + + + + + + + + + + + + + + + + + + + + Application files + + Opens the directory where application files like plugins and settings are stored. + + + + + + @@ -106,7 +153,7 @@ - + @@ -127,7 +174,7 @@ - + @@ -144,12 +191,11 @@ LED sample size - Sets the amount of samples that is taken to determine each LEDs color. - Best you leave it on 1 but included for completeness, a higher value increases CPU-usage quite rapidly. + Sets the amount of samples that is taken to determine each LEDs color. This means a LED can be semi off if it is not completely covered by a color. - + @@ -159,64 +205,37 @@ - Below you view and manage your plugins. To find and install new plugins use the workshop (TODO). + The list below shows all loaded plugins. You can't really edit it right now. If you're missing something, view your logs folder. - + + + + - - - - - - - - - - - - - - + - - - - - - - + + diff --git a/src/Artemis.UI/Screens/Settings/SettingsViewModel.cs b/src/Artemis.UI/Screens/Settings/SettingsViewModel.cs index 9a8235b68..263cdc7de 100644 --- a/src/Artemis.UI/Screens/Settings/SettingsViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/SettingsViewModel.cs @@ -1,11 +1,17 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; +using Artemis.Core; +using Artemis.Core.Plugins.Abstract; using Artemis.Core.Services; +using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Storage.Interfaces; using Artemis.UI.Ninject.Factories; using Artemis.UI.Screens.Settings.Debug; using Artemis.UI.Screens.Settings.Tabs.Devices; +using Artemis.UI.Screens.Settings.Tabs.Plugins; using MaterialDesignThemes.Wpf; using Ninject; using Stylet; @@ -18,10 +24,12 @@ namespace Artemis.UI.Screens.Settings private readonly IKernel _kernel; private readonly ISettingsService _settingsService; private readonly ISurfaceService _surfaceService; + private readonly IPluginService _pluginService; private readonly IWindowManager _windowManager; public SettingsViewModel(IKernel kernel, ISurfaceService surfaceService, + IPluginService pluginService, IWindowManager windowManager, ISettingsService settingsService, IDeviceSettingsViewModelFactory deviceSettingsViewModelFactory) @@ -32,12 +40,13 @@ namespace Artemis.UI.Screens.Settings _kernel = kernel; _surfaceService = surfaceService; + _pluginService = pluginService; _windowManager = windowManager; _settingsService = settingsService; _deviceSettingsViewModelFactory = deviceSettingsViewModelFactory; DeviceSettingsViewModels = new BindableCollection(); - + Plugins = new BindableCollection(); RenderScales = new List> {new Tuple("10%", 0.1)}; for (var i = 25; i <= 100; i += 25) RenderScales.Add(new Tuple(i + "%", i / 100.0)); @@ -50,11 +59,11 @@ namespace Artemis.UI.Screens.Settings SampleSizes = new List {1, 9}; } - public List SampleSizes { get; set; } - - public BindableCollection DeviceSettingsViewModels { get; set; } - + public List> TargetFrameRates { get; set; } public List> RenderScales { get; set; } + public List SampleSizes { get; set; } + public BindableCollection DeviceSettingsViewModels { get; set; } + public BindableCollection Plugins { get; set; } public Tuple SelectedRenderScale { @@ -66,7 +75,7 @@ namespace Artemis.UI.Screens.Settings { get => TargetFrameRates.FirstOrDefault(t => Math.Abs(t.Item2 - TargetFrameRate) < 0.01); set => TargetFrameRate = value.Item2; - } + } public double RenderScale { @@ -78,7 +87,6 @@ namespace Artemis.UI.Screens.Settings } } - public List> TargetFrameRates { get; set; } public int TargetFrameRate { @@ -100,14 +108,17 @@ namespace Artemis.UI.Screens.Settings } } - public string Title => "Settings"; - protected override void OnActivate() { DeviceSettingsViewModels.Clear(); foreach (var device in _surfaceService.ActiveSurface.Devices) DeviceSettingsViewModels.Add(_deviceSettingsViewModelFactory.Create(device)); + // TODO: GetPluginsOfType isn't ideal here as it doesn't include disabled plugins + Plugins.Clear(); + foreach (var plugin in _pluginService.GetPluginsOfType()) + Plugins.Add(new PluginSettingsViewModel(plugin)); + base.OnActivate(); } @@ -115,5 +126,15 @@ namespace Artemis.UI.Screens.Settings { _windowManager.ShowWindow(_kernel.Get()); } + + public void ShowLogsFolder() + { + Process.Start(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs")); + } + + public void ShowDataFolder() + { + Process.Start(Constants.DataFolder); + } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs new file mode 100644 index 000000000..d10405a31 --- /dev/null +++ b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsViewModel.cs @@ -0,0 +1,23 @@ +using System; +using Artemis.Core.Plugins.Abstract; +using Stylet; + +namespace Artemis.UI.Screens.Settings.Tabs.Plugins +{ + public class PluginSettingsViewModel : PropertyChangedBase + { + private readonly Plugin _plugin; + + public PluginSettingsViewModel(Plugin plugin) + { + _plugin = plugin; + IsEnabled = true; + } + + public string Type => _plugin.GetType().BaseType?.Name ?? _plugin.GetType().Name; + public string Name => _plugin.PluginInfo.Name; + public string Description => "N.Y.I."; + public Version Version => _plugin.PluginInfo.Version; + public bool IsEnabled { get; set; } + } +} \ No newline at end of file