diff --git a/src/DirectX12GameEngine.Core/AsyncDictionary.cs b/src/DirectX12GameEngine.Core/AsyncDictionary.cs deleted file mode 100644 index 4a872a70..00000000 --- a/src/DirectX12GameEngine.Core/AsyncDictionary.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace DirectX12GameEngine.Core -{ - public class AsyncDictionary - { - private readonly Dictionary dictionary = new Dictionary(); - - public event EventHandler> ItemAdded; - - public void Add(TKey key, TValue value) - { - dictionary.Add(key, value); - ItemAdded?.Invoke(this, new DictionaryChangedEventArgs(key, value)); - } - - public bool ContainsKey(TKey key) => dictionary.ContainsKey(key); - - public bool ContainsValue(TValue value) => dictionary.ContainsValue(value); - - public async Task GetValueAsync(TKey key) - { - if (!dictionary.TryGetValue(key, out TValue value)) - { - TaskCompletionSource tcs = new TaskCompletionSource(); - - void OnItemAdded(object s, DictionaryChangedEventArgs e) - { - if (e.Item.Key.Equals(key)) - { - tcs.TrySetResult(e.Item.Value); - } - } - - ItemAdded += OnItemAdded; - value = await tcs.Task; - ItemAdded -= OnItemAdded; - } - - return value; - } - - public Task this[TKey key] => GetValueAsync(key); - } - - public class DictionaryChangedEventArgs : EventArgs - { - public DictionaryChangedEventArgs(TKey key, TValue value) - : this(new KeyValuePair(key, value)) - { - } - - public DictionaryChangedEventArgs(KeyValuePair item) - { - Item = item; - } - - public KeyValuePair Item { get; } - } -} diff --git a/src/DirectX12GameEngine.Core/DisposableExtensions.cs b/src/DirectX12GameEngine.Core/DisposableExtensions.cs deleted file mode 100644 index 2f1f8e49..00000000 --- a/src/DirectX12GameEngine.Core/DisposableExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace DirectX12GameEngine.Core -{ - public static class DisposableExtensions - { - public static T DisposeBy(this T item, ICollector collector) where T : IDisposable - { - collector.Disposables.Add(item); - return item; - } - } -} diff --git a/src/DirectX12GameEngine.Core/ICollector.cs b/src/DirectX12GameEngine.Core/ICollector.cs deleted file mode 100644 index 5c5bebc3..00000000 --- a/src/DirectX12GameEngine.Core/ICollector.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace DirectX12GameEngine.Core -{ - public interface ICollector - { - ICollection Disposables { get; } - } -} diff --git a/src/DirectX12GameEngine.Core/IIdentifiable.cs b/src/DirectX12GameEngine.Core/IIdentifiable.cs deleted file mode 100644 index 3e327b71..00000000 --- a/src/DirectX12GameEngine.Core/IIdentifiable.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace DirectX12GameEngine.Core -{ - public interface IIdentifiable - { - Guid Id { get; set; } - } -} diff --git a/src/DirectX12GameEngine.Core/QuaternionExtensions.cs b/src/DirectX12GameEngine.Core/QuaternionExtensions.cs deleted file mode 100644 index e20430f6..00000000 --- a/src/DirectX12GameEngine.Core/QuaternionExtensions.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Numerics; - -namespace DirectX12GameEngine.Core -{ - public static class QuaternionExtensions - { - public static Vector3 ToEuler(in Quaternion rotation) - { - Vector3 rotationEuler; - - float xx = rotation.X * rotation.X; - float yy = rotation.Y * rotation.Y; - float zz = rotation.Z * rotation.Z; - float xy = rotation.X * rotation.Y; - float zw = rotation.Z * rotation.W; - float zx = rotation.Z * rotation.X; - float yw = rotation.Y * rotation.W; - float yz = rotation.Y * rotation.Z; - float xw = rotation.X * rotation.W; - - rotationEuler.Y = (float)Math.Asin(2.0f * (yw - zx)); - double test = Math.Cos(rotationEuler.Y); - - if (test > 1e-6f) - { - rotationEuler.Z = (float)Math.Atan2(2.0f * (xy + zw), 1.0f - (2.0f * (yy + zz))); - rotationEuler.X = (float)Math.Atan2(2.0f * (yz + xw), 1.0f - (2.0f * (yy + xx))); - } - else - { - rotationEuler.Z = (float)Math.Atan2(2.0f * (zw - xy), 2.0f * (zx + yw)); - rotationEuler.X = 0.0f; - } - - return rotationEuler; - } - - public static Quaternion ToQuaternion(in Vector3 value) - { - Quaternion rotation; - - var halfAngles = value * 0.5f; - - var fSinX = (float)Math.Sin(halfAngles.X); - var fCosX = (float)Math.Cos(halfAngles.X); - var fSinY = (float)Math.Sin(halfAngles.Y); - var fCosY = (float)Math.Cos(halfAngles.Y); - var fSinZ = (float)Math.Sin(halfAngles.Z); - var fCosZ = (float)Math.Cos(halfAngles.Z); - - var fCosXY = fCosX * fCosY; - var fSinXY = fSinX * fSinY; - - rotation.X = fSinX * fCosY * fCosZ - fSinZ * fSinY * fCosX; - rotation.Y = fSinY * fCosX * fCosZ + fSinZ * fSinX * fCosY; - rotation.Z = fSinZ * fCosXY - fSinXY * fCosZ; - rotation.W = fCosZ * fCosXY + fSinXY * fSinZ; - - return rotation; - } - } -} diff --git a/src/DirectX12GameEngine.Graphics/GraphicsDevice.cs b/src/DirectX12GameEngine.Graphics/GraphicsDevice.cs index 1a30ff15..31752402 100644 --- a/src/DirectX12GameEngine.Graphics/GraphicsDevice.cs +++ b/src/DirectX12GameEngine.Graphics/GraphicsDevice.cs @@ -2,13 +2,12 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using DirectX12GameEngine.Core; using SharpDX.Direct3D; using SharpDX.Direct3D12; namespace DirectX12GameEngine.Graphics { - public sealed class GraphicsDevice : IDisposable, ICollector + public sealed class GraphicsDevice : IDisposable { private readonly AutoResetEvent fenceEvent = new AutoResetEvent(false); private SharpDX.Direct3D11.Device? nativeDirect3D11Device; @@ -53,8 +52,6 @@ namespace DirectX12GameEngine.Graphics public CommandList CopyCommandList { get; } - public ICollection Disposables { get; } = new List(); - public FeatureLevel FeatureLevel { get; } public GraphicsPresenter? Presenter { get; set; } @@ -163,11 +160,6 @@ namespace DirectX12GameEngine.Graphics NativeDirectFence.Dispose(); NativeDirectFence.Dispose(); - foreach (IDisposable disposable in Disposables) - { - disposable.Dispose(); - } - nativeDirect3D11Device?.Dispose(); NativeDevice.Dispose();