Skip to content

Commit 8241837

Browse files
author
Aytackydln
committed
use source-gen calculated max key for DeviceKey stores
1 parent cf8ed8a commit 8241837

12 files changed

Lines changed: 25 additions & 17 deletions

File tree

Project-Aurora/AuroraCommon/AuroraCommon.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<ItemGroup>
1717
<PackageReference Include="IronPython" Version="3.4.1" />
1818
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="9.0.0" />
19+
<PackageReference Include="Raiqub.Generators.EnumUtilities" Version="1.13.4" />
1920
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.111" />
2021
<PackageReference Include="Serilog" Version="4.3.0" />
2122
<PackageReference Include="SmartThreadPool.dll" Version="2.3.0" />

Project-Aurora/AuroraCommon/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class Constants
77
public const string DeviceManagerPipe = "Aurora\\DeviceManager";
88
public const string AuroraInterfacePipe = "aurora\\interface";
99

10-
public static readonly int MaxKeyId = Enum.GetValues(typeof(DeviceKeys)).Cast<int>().Max() + 1;
10+
public static readonly int MaxKeyId = DeviceKeysMetadata.MaximumValue;
1111

1212
public const string DeviceLedMap = "DeviceLedMap";
1313
public const string DeviceInformations = "DeviceInformations";

Project-Aurora/AuroraCommon/Devices/DeviceKeys.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System.ComponentModel;
2+
using Raiqub.Generators.EnumUtilities;
23

34
namespace Common.Devices;
45

56
/// <summary>
67
/// Enum definition, representing everysingle supported device key
78
/// </summary>
9+
[EnumGenerator]
810
public enum DeviceKeys
911
{
1012
/// <summary>

Project-Aurora/Project-Aurora/ConfigUi.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ public Layer? SelectedLayer {
591591
private Control? _selectedControl;
592592
private readonly Control_ProfilesStack _profilesStack;
593593
private HwndSource? _windowHwndSource;
594-
private readonly Dictionary<DeviceKeys, MediaColor> _uiKeyColors = new(Effects.MaxDeviceId, EnumHashGetter.Instance as IEqualityComparer<DeviceKeys>);
594+
private readonly Dictionary<DeviceKeys, MediaColor> _uiKeyColors = new(Constants.MaxKeyId, EnumHashGetter.Instance as IEqualityComparer<DeviceKeys>);
595595

596596
#endregion
597597

Project-Aurora/Project-Aurora/Devices/DeviceManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Runtime.CompilerServices;
88
using System.Threading;
99
using System.Threading.Tasks;
10-
using AuroraRgb.EffectsEngine;
1110
using AuroraRgb.Modules;
1211
using AuroraRgb.Utils;
1312
using Common;
@@ -48,7 +47,7 @@ public sealed class DeviceManager : IDisposable
4847
public DeviceManager(AuroraControlInterface auroraControlInterface)
4948
{
5049
_auroraControlInterface = auroraControlInterface;
51-
_sharedDeviceColor = new MemorySharedArrayWrite<SimpleColor>(Constants.DeviceLedMap, Effects.MaxDeviceId);
50+
_sharedDeviceColor = new MemorySharedArrayWrite<SimpleColor>(Constants.DeviceLedMap, Constants.MaxKeyId);
5251

5352
_deviceManagerInfo = new MemorySharedStruct<DeviceManagerInfo>(Constants.DeviceInformations);
5453
_deviceManagerInfo.Updated += OnDeviceManagerInfoOnUpdated;

Project-Aurora/Project-Aurora/EffectsEngine/EffectCanvas.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using AuroraRgb.Settings;
6+
using Common;
67
using Common.Devices;
78

89
namespace AuroraRgb.EffectsEngine;
@@ -39,7 +40,7 @@ public sealed class EffectCanvas : IEqualityComparer<EffectCanvas>, IEquatable<E
3940
public float HeightCenter { get; init; }
4041

4142
private readonly BitmapRectangle _emptyRectangle = BitmapRectangle.EmptyRectangle;
42-
private readonly BitmapRectangle[] _keyRectangles = Enumerable.Range(0, Effects.MaxDeviceId + 1)
43+
private readonly BitmapRectangle[] _keyRectangles = Enumerable.Range(0, Constants.MaxKeyId + 1)
4344
.Select(_ => BitmapRectangle.EmptyRectangle)
4445
.ToArray();
4546

Project-Aurora/Project-Aurora/EffectsEngine/Effects.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public int GetHashCode(Enum obj)
3434

3535
public class Effects(Task<DeviceManager> deviceManager)
3636
{
37-
//Optimization: used to mitigate dictionary resizing
38-
//TODO https://github.com/skarllot/EnumUtilities/issues/469
39-
public const int MaxDeviceId = 2000;
40-
4137
private static readonly DeviceKeys[] PossiblePeripheralKeys =
4238
[
4339
DeviceKeys.Peripheral,

Project-Aurora/Project-Aurora/EffectsEngine/NoRenderLayer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Runtime.CompilerServices;
55
using System.Runtime.InteropServices;
66
using AuroraRgb.Settings;
7+
using Common;
78
using Common.Devices;
89
using Common.Utils;
910

@@ -13,9 +14,9 @@ public sealed class NoRenderLayer : EffectLayer
1314
{
1415
private static readonly Color Transparent = Color.Transparent;
1516
private static DeviceKeys[] AllKeys => Effects.Canvas.Keys;
16-
private readonly Color[] _emptyKeyColors = new Color[Effects.MaxDeviceId + 1];
17+
private readonly Color[] _emptyKeyColors = new Color[Constants.MaxKeyId + 1];
1718

18-
private readonly Color[] _keyColors = new Color[Effects.MaxDeviceId + 1];
19+
private readonly Color[] _keyColors = new Color[Constants.MaxKeyId + 1];
1920
private double _opacity = 1;
2021
private bool _isOpaque = true;
2122

Project-Aurora/Project-Aurora/Modules/Layouts/KeyboardLayoutManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using AuroraRgb.Settings;
1414
using AuroraRgb.Settings.Controls.Keycaps;
1515
using AuroraRgb.Settings.Layouts;
16+
using Common;
1617
using Common.Devices;
1718
using Application = System.Windows.Application;
1819
using MediaColor = System.Windows.Media.Color;
@@ -280,7 +281,7 @@ private void CalculateBitmap(VirtualGroup virtualKeyboardGroup, float keyboardWi
280281
double widthMax = 1;
281282
double heightMax = 1;
282283
var bitmapMap =
283-
new Dictionary<DeviceKeys, BitmapRectangle>(Effects.MaxDeviceId, EnumHashGetter.Instance as IEqualityComparer<DeviceKeys>);
284+
new Dictionary<DeviceKeys, BitmapRectangle>(Constants.MaxKeyId, EnumHashGetter.Instance as IEqualityComparer<DeviceKeys>);
284285

285286
foreach (var key in virtualKeyboardGroup.GroupedKeys)
286287
{

Project-Aurora/Project-Aurora/Settings/Layers/InteractiveLayerHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using AuroraRgb.Settings.Layers.Controls;
1414
using AuroraRgb.Settings.Overrides;
1515
using AuroraRgb.Utils;
16+
using Common;
1617
using Common.Devices;
1718
using Common.Utils;
1819
using Newtonsoft.Json;
@@ -140,7 +141,7 @@ public override void Default()
140141
public sealed class InteractiveLayerHandler : LayerHandler<InteractiveLayerHandlerProperties, BitmapEffectLayer>
141142
{
142143
private readonly Func<KeyValuePair<DeviceKeys, long>, bool> _keysToRemove;
143-
private readonly ConcurrentDictionary<DeviceKeys, InputItem> _inputDictionary = new(new Dictionary<DeviceKeys, InputItem>(Effects.MaxDeviceId));
144+
private readonly ConcurrentDictionary<DeviceKeys, InputItem> _inputDictionary = new(new Dictionary<DeviceKeys, InputItem>(Constants.MaxKeyId));
144145

145146
private long _previousTime;
146147
private long _currentTime;

0 commit comments

Comments
 (0)