From 770ec9fe6d71e8a3bf3f01ad1400e654f72e168d Mon Sep 17 00:00:00 2001 From: Tornado Tech <54727692+Tornado-Technology@users.noreply.github.com> Date: Fri, 16 Aug 2024 03:31:52 +1000 Subject: [PATCH] Update utilities --- .../Utilities/Helpers/AudioTypeHelper.cs | 2 +- .../DependenciesContainer.cs | 2 +- .../Realisation/EventBus/EntitiesEventBus.cs | 2 +- .../EventBus/EntitiesEventRefHandler.cs | 2 +- Hypercube.Shared/EventBus/EventBus.cs | 4 +-- .../EventBus/EventSubscription.cs | 2 +- Hypercube.Shared/Utilities/Ref/RefHandler.cs | 5 ---- .../Utilities/SimpleCallbackContainer.cs | 29 ------------------- Hypercube.Shared/Utilities/Units/UnitBox.cs | 15 ---------- .../Extensions/StringExtension.cs | 5 +++- .../Extensions/TypeExtension.cs | 4 ++- .../Helpers}/UnitHelper.cs | 6 ++-- Hypercube.Utilities/Ref/RefHandler.cs | 5 ++++ .../RuntimeInformation.cs | 14 +++++---- .../Units/Unit.cs | 7 +++-- Hypercube.Utilities/Units/UnitBox.cs | 21 ++++++++++++++ 16 files changed, 57 insertions(+), 68 deletions(-) delete mode 100644 Hypercube.Shared/Utilities/Ref/RefHandler.cs delete mode 100644 Hypercube.Shared/Utilities/SimpleCallbackContainer.cs delete mode 100644 Hypercube.Shared/Utilities/Units/UnitBox.cs rename {Hypercube.Shared/Utilities => Hypercube.Utilities/Helpers}/UnitHelper.cs (70%) create mode 100644 Hypercube.Utilities/Ref/RefHandler.cs rename {Hypercube.Shared/Utilities => Hypercube.Utilities}/RuntimeInformation.cs (80%) rename {Hypercube.Shared/Utilities => Hypercube.Utilities}/Units/Unit.cs (51%) create mode 100644 Hypercube.Utilities/Units/UnitBox.cs diff --git a/Hypercube.Client/Utilities/Helpers/AudioTypeHelper.cs b/Hypercube.Client/Utilities/Helpers/AudioTypeHelper.cs index a772010..31e36b1 100644 --- a/Hypercube.Client/Utilities/Helpers/AudioTypeHelper.cs +++ b/Hypercube.Client/Utilities/Helpers/AudioTypeHelper.cs @@ -1,6 +1,6 @@ using System.Collections.Frozen; using Hypercube.Client.Audio; -using Hypercube.Shared.Utilities.Extensions; +using Hypercube.Utilities.Extensions; namespace Hypercube.Client.Utilities.Helpers; diff --git a/Hypercube.Dependencies/DependenciesContainer.cs b/Hypercube.Dependencies/DependenciesContainer.cs index afde00d..bf9f03e 100644 --- a/Hypercube.Dependencies/DependenciesContainer.cs +++ b/Hypercube.Dependencies/DependenciesContainer.cs @@ -1,6 +1,6 @@ using System.Reflection; using Hypercube.Shared.Logging; -using Hypercube.Shared.Utilities.Extensions; +using Hypercube.Utilities.Extensions; using JetBrains.Annotations; namespace Hypercube.Dependencies; diff --git a/Hypercube.Shared/Entities/Realisation/EventBus/EntitiesEventBus.cs b/Hypercube.Shared/Entities/Realisation/EventBus/EntitiesEventBus.cs index 38f8ad6..8e22dde 100644 --- a/Hypercube.Shared/Entities/Realisation/EventBus/EntitiesEventBus.cs +++ b/Hypercube.Shared/Entities/Realisation/EventBus/EntitiesEventBus.cs @@ -2,7 +2,7 @@ using Hypercube.Shared.Entities.Realisation.Components; using Hypercube.Shared.Entities.Realisation.EventBus.EventArgs; using Hypercube.Shared.Entities.Realisation.Systems; -using Hypercube.Shared.Utilities.Units; +using Hypercube.Utilities.Units; namespace Hypercube.Shared.Entities.Realisation.EventBus; diff --git a/Hypercube.Shared/Entities/Realisation/EventBus/EntitiesEventRefHandler.cs b/Hypercube.Shared/Entities/Realisation/EventBus/EntitiesEventRefHandler.cs index 29484ba..a5d1ac6 100644 --- a/Hypercube.Shared/Entities/Realisation/EventBus/EntitiesEventRefHandler.cs +++ b/Hypercube.Shared/Entities/Realisation/EventBus/EntitiesEventRefHandler.cs @@ -1,6 +1,6 @@ using Hypercube.Shared.Entities.Realisation.Components; using Hypercube.Shared.Entities.Realisation.EventBus.EventArgs; -using Hypercube.Shared.Utilities.Units; +using Hypercube.Utilities.Units; namespace Hypercube.Shared.Entities.Realisation.EventBus; diff --git a/Hypercube.Shared/EventBus/EventBus.cs b/Hypercube.Shared/EventBus/EventBus.cs index e4ebd02..f35fc14 100644 --- a/Hypercube.Shared/EventBus/EventBus.cs +++ b/Hypercube.Shared/EventBus/EventBus.cs @@ -1,7 +1,7 @@ using System.Runtime.CompilerServices; using Hypercube.Shared.EventBus.Events; -using Hypercube.Shared.Utilities.Ref; -using Hypercube.Shared.Utilities.Units; +using Hypercube.Utilities.Ref; +using Hypercube.Utilities.Units; namespace Hypercube.Shared.EventBus; diff --git a/Hypercube.Shared/EventBus/EventSubscription.cs b/Hypercube.Shared/EventBus/EventSubscription.cs index c794bcf..bb7ac14 100644 --- a/Hypercube.Shared/EventBus/EventSubscription.cs +++ b/Hypercube.Shared/EventBus/EventSubscription.cs @@ -1,4 +1,4 @@ -using Hypercube.Shared.Utilities.Ref; +using Hypercube.Utilities.Ref; namespace Hypercube.Shared.EventBus; diff --git a/Hypercube.Shared/Utilities/Ref/RefHandler.cs b/Hypercube.Shared/Utilities/Ref/RefHandler.cs deleted file mode 100644 index 95e9532..0000000 --- a/Hypercube.Shared/Utilities/Ref/RefHandler.cs +++ /dev/null @@ -1,5 +0,0 @@ -using Hypercube.Shared.Utilities.Units; - -namespace Hypercube.Shared.Utilities.Ref; - -public delegate void RefHandler(ref Unit ev); \ No newline at end of file diff --git a/Hypercube.Shared/Utilities/SimpleCallbackContainer.cs b/Hypercube.Shared/Utilities/SimpleCallbackContainer.cs deleted file mode 100644 index 8f09265..0000000 --- a/Hypercube.Shared/Utilities/SimpleCallbackContainer.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace Hypercube.Shared.Utilities; - -public sealed class SimpleCallbackContainer where TBaseArgs : notnull -{ - private readonly Dictionary> _callbacks = new(); - - public void Register(Action callback) - { - if (_callbacks.ContainsKey(typeof(TArgs))) - throw new Exception(); - - _callbacks.Add(typeof(TArgs), args => - { - var obj = Convert.ChangeType(args, typeof(TArgs)); - if (obj is not TArgs casted) - return; - - callback.Invoke(casted); - }); - } - - public void Invoke(TBaseArgs args) - { - if (!_callbacks.TryGetValue(args.GetType(), out var callback)) - return; - - callback.Invoke(args); - } -} \ No newline at end of file diff --git a/Hypercube.Shared/Utilities/Units/UnitBox.cs b/Hypercube.Shared/Utilities/Units/UnitBox.cs deleted file mode 100644 index 11f47c6..0000000 --- a/Hypercube.Shared/Utilities/Units/UnitBox.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Hypercube.Shared.Utilities.Units; - -/// -/// Whenever you see this it is some other object, it should be resolved using Unsafe.As() -/// -/// -/// Should be used whenever we want to pass value by ref -/// -[StructLayout(LayoutKind.Sequential)] -public sealed class UnitBox -{ - public Unit Value; -} \ No newline at end of file diff --git a/Hypercube.Utilities/Extensions/StringExtension.cs b/Hypercube.Utilities/Extensions/StringExtension.cs index 159edb5..aa45615 100644 --- a/Hypercube.Utilities/Extensions/StringExtension.cs +++ b/Hypercube.Utilities/Extensions/StringExtension.cs @@ -1,5 +1,8 @@ -namespace Hypercube.Shared.Utilities.Extensions; +using JetBrains.Annotations; +namespace Hypercube.Utilities.Extensions; + +[PublicAPI] public static class StringExtension { public static string RemoveChar(this string str, char @char) { diff --git a/Hypercube.Utilities/Extensions/TypeExtension.cs b/Hypercube.Utilities/Extensions/TypeExtension.cs index dd45cc4..4776039 100644 --- a/Hypercube.Utilities/Extensions/TypeExtension.cs +++ b/Hypercube.Utilities/Extensions/TypeExtension.cs @@ -1,7 +1,9 @@ using System.Reflection; +using JetBrains.Annotations; -namespace Hypercube.Shared.Utilities.Extensions; +namespace Hypercube.Utilities.Extensions; +[PublicAPI] public static class TypeExtension { /// diff --git a/Hypercube.Shared/Utilities/UnitHelper.cs b/Hypercube.Utilities/Helpers/UnitHelper.cs similarity index 70% rename from Hypercube.Shared/Utilities/UnitHelper.cs rename to Hypercube.Utilities/Helpers/UnitHelper.cs index 44926be..cc598ee 100644 --- a/Hypercube.Shared/Utilities/UnitHelper.cs +++ b/Hypercube.Utilities/Helpers/UnitHelper.cs @@ -1,8 +1,10 @@ using System.Runtime.CompilerServices; -using Hypercube.Shared.Utilities.Units; +using Hypercube.Utilities.Units; +using JetBrains.Annotations; -namespace Hypercube.Shared.Utilities; +namespace Hypercube.Utilities.Helpers; +[PublicAPI] public static class UnitHelper { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Hypercube.Utilities/Ref/RefHandler.cs b/Hypercube.Utilities/Ref/RefHandler.cs new file mode 100644 index 0000000..9a10f14 --- /dev/null +++ b/Hypercube.Utilities/Ref/RefHandler.cs @@ -0,0 +1,5 @@ +using Hypercube.Utilities.Units; + +namespace Hypercube.Utilities.Ref; + +public delegate void RefHandler(ref Unit ev); \ No newline at end of file diff --git a/Hypercube.Shared/Utilities/RuntimeInformation.cs b/Hypercube.Utilities/RuntimeInformation.cs similarity index 80% rename from Hypercube.Shared/Utilities/RuntimeInformation.cs rename to Hypercube.Utilities/RuntimeInformation.cs index ed409d3..8c684e5 100644 --- a/Hypercube.Shared/Utilities/RuntimeInformation.cs +++ b/Hypercube.Utilities/RuntimeInformation.cs @@ -1,21 +1,23 @@ using System.Runtime; +using JetBrains.Annotations; using SysRuntimeInformation = System.Runtime.InteropServices.RuntimeInformation; -namespace Hypercube.Shared.Utilities; +namespace Hypercube.Utilities; +[PublicAPI] public static class RuntimeInformation { public static string[] GetInformationDump() { var version = typeof(RuntimeInformation).Assembly.GetName().Version; - - return new[] - { + + return + [ $"OS: {SysRuntimeInformation.OSDescription} {SysRuntimeInformation.OSArchitecture}", $".NET Runtime: {SysRuntimeInformation.FrameworkDescription} {SysRuntimeInformation.RuntimeIdentifier}", $"Server GC: {GCSettings.IsServerGC}", $"Architecture: {SysRuntimeInformation.ProcessArchitecture}", - $"Hypercube Version: {version}", - }; + $"Version: {version}" + ]; } } \ No newline at end of file diff --git a/Hypercube.Shared/Utilities/Units/Unit.cs b/Hypercube.Utilities/Units/Unit.cs similarity index 51% rename from Hypercube.Shared/Utilities/Units/Unit.cs rename to Hypercube.Utilities/Units/Unit.cs index 6a3adab..6fd4613 100644 --- a/Hypercube.Shared/Utilities/Units/Unit.cs +++ b/Hypercube.Utilities/Units/Unit.cs @@ -1,6 +1,9 @@ -namespace Hypercube.Shared.Utilities.Units; +using JetBrains.Annotations; + +namespace Hypercube.Utilities.Units; /// -/// Whenever you see this struct it some other object, it should be resolved using Unsafe.As() +/// Whenever you see this struct it some other object, it should be resolved using Unsafe.As(). /// +[PublicAPI] public readonly struct Unit; \ No newline at end of file diff --git a/Hypercube.Utilities/Units/UnitBox.cs b/Hypercube.Utilities/Units/UnitBox.cs new file mode 100644 index 0000000..7e6a8cd --- /dev/null +++ b/Hypercube.Utilities/Units/UnitBox.cs @@ -0,0 +1,21 @@ +using System.Runtime.InteropServices; +using JetBrains.Annotations; + +namespace Hypercube.Utilities.Units; + +/// +/// Whenever you see this it is some other object, it should be resolved using Unsafe.As(). +/// +/// +/// Should be used whenever we want to pass value by ref. +/// +[PublicAPI, StructLayout(LayoutKind.Sequential)] +public sealed class UnitBox +{ + public Unit Value; + + public static implicit operator Unit(UnitBox unitBox) + { + return unitBox.Value; + } +} \ No newline at end of file