Ported DirectX12GameEngine.Core project

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-10 19:52:22 +02:00
1 親 06a0912f09
コミット 36ef5b38b7
8ファイル変更
+270 -1

検索条件に一致するファイルはありません

+62
ファイルの表示
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DirectX12GameEngine.Core
{
public class AsyncDictionary<TKey, TValue>
{
private readonly Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>();
public event EventHandler<DictionaryChangedEventArgs<TKey, TValue>> ItemAdded;
public void Add(TKey key, TValue value)
{
dictionary.Add(key, value);
ItemAdded?.Invoke(this, new DictionaryChangedEventArgs<TKey, TValue>(key, value));
}
public bool ContainsKey(TKey key) => dictionary.ContainsKey(key);
public bool ContainsValue(TValue value) => dictionary.ContainsValue(value);
public async Task<TValue> GetValueAsync(TKey key)
{
if (!dictionary.TryGetValue(key, out TValue value))
{
TaskCompletionSource<TValue> tcs = new TaskCompletionSource<TValue>();
void OnItemAdded(object s, DictionaryChangedEventArgs<TKey, TValue> e)
{
if (e.Item.Key.Equals(key))
{
tcs.TrySetResult(e.Item.Value);
}
}
ItemAdded += OnItemAdded;
value = await tcs.Task;
ItemAdded -= OnItemAdded;
}
return value;
}
public Task<TValue> this[TKey key] => GetValueAsync(key);
}
public class DictionaryChangedEventArgs<TKey, TValue> : EventArgs
{
public DictionaryChangedEventArgs(TKey key, TValue value)
: this(new KeyValuePair<TKey, TValue>(key, value))
{
}
public DictionaryChangedEventArgs(KeyValuePair<TKey, TValue> item)
{
Item = item;
}
public KeyValuePair<TKey, TValue> Item { get; }
}
}
+16 -1
ファイルの表示
@@ -1,7 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.18362.2002-preview" />
<PackageReference Include="System.Memory" Version="4.5.3" />
<PackageReference Include="System.Numerics.Vectors" Version="4.6.0-preview5.19224.8" />
<PackageReference Include="System.Runtime.InteropServices.WindowsRuntime" Version="4.3.0" />
</ItemGroup>
</Project>
+13
ファイルの表示
@@ -0,0 +1,13 @@
using System;
namespace DirectX12GameEngine.Core
{
public static class DisposableExtensions
{
public static T DisposeBy<T>(this T item, ICollector collector) where T : IDisposable
{
collector.Disposables.Add(item);
return item;
}
}
}
+10
ファイルの表示
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
namespace DirectX12GameEngine.Core
{
public interface ICollector
{
ICollection<IDisposable> Disposables { get; }
}
}
+9
ファイルの表示
@@ -0,0 +1,9 @@
using System;
namespace DirectX12GameEngine.Core
{
public interface IIdentifiable
{
Guid Id { get; set; }
}
}
+33
ファイルの表示
@@ -0,0 +1,33 @@
using System;
using System.Runtime.CompilerServices;
namespace DirectX12GameEngine.Core
{
public static class MemoryHelper
{
public static unsafe void Copy(IntPtr source, IntPtr destination, int sizeInBytesToCopy)
{
Copy(new Span<byte>(source.ToPointer(), sizeInBytesToCopy), destination);
}
public static unsafe void Copy<T>(Span<T> source, IntPtr destination) where T : unmanaged
{
source.CopyTo(new Span<T>(destination.ToPointer(), source.Length));
}
public static unsafe void Copy<T>(IntPtr source, Span<T> destination) where T : unmanaged
{
new Span<T>(source.ToPointer(), destination.Length).CopyTo(destination);
}
public static unsafe void Copy<T>(in T source, IntPtr destination) where T : unmanaged
{
Unsafe.Copy(destination.ToPointer(), ref Unsafe.AsRef(source));
}
public static unsafe void Copy<T>(IntPtr source, ref T destination) where T : unmanaged
{
Unsafe.Copy(ref destination, source.ToPointer());
}
}
}
+63
ファイルの表示
@@ -0,0 +1,63 @@
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;
}
}
}
+64
ファイルの表示
@@ -0,0 +1,64 @@
using System.Numerics;
using Windows.Foundation;
namespace DirectX12GameEngine.Core
{
public static class PointExtensions
{
public static Vector2 ToVector2(this in Point value)
{
return new Vector2((float)value.X, (float)value.Y);
}
public static Point ToPoint(this in Vector2 value)
{
return new Point(value.X, value.Y);
}
public static System.Drawing.PointF ToPointF(this in Point value)
{
return new System.Drawing.PointF((float)value.X, (float)value.Y);
}
public static Point ToPoint(this in System.Drawing.PointF value)
{
return new Point(value.X, value.Y);
}
}
public static class RectangleExtensions
{
public static System.Drawing.RectangleF ToRectangleF(this in Rect value)
{
return new System.Drawing.RectangleF((float)value.X, (float)value.Y, (float)value.Width, (float)value.Height);
}
public static Rect ToRect(this in System.Drawing.RectangleF value)
{
return new Rect(value.X, value.Y, value.Width, value.Height);
}
}
public static class SizeExtensions
{
public static Vector2 ToVector2(this in Size value)
{
return new Vector2((float)value.Width, (float)value.Height);
}
public static Size ToSize(this in Vector2 value)
{
return new Size(value.X, value.Y);
}
public static System.Drawing.SizeF ToSizeF(this in Size value)
{
return new System.Drawing.SizeF((float)value.Width, (float)value.Height);
}
public static Size ToSize(this in System.Drawing.SizeF value)
{
return new Size(value.Width, value.Height);
}
}
}