Compare commits
1 Commits
b9f2d50730
...
5ccebc018f
Author | SHA1 | Date |
---|---|---|
|
5ccebc018f |
|
@ -1,7 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Platforms>x64</Platforms>
|
<Platforms>x64</Platforms>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
@ -46,8 +46,8 @@ namespace MoonWorks.Audio
|
||||||
if (devices == 0)
|
if (devices == 0)
|
||||||
{
|
{
|
||||||
Logger.LogError("No audio devices found!");
|
Logger.LogError("No audio devices found!");
|
||||||
FAudio.FAudio_Release(Handle);
|
|
||||||
Handle = IntPtr.Zero;
|
Handle = IntPtr.Zero;
|
||||||
|
FAudio.FAudio_Release(Handle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +118,13 @@ namespace MoonWorks.Audio
|
||||||
|
|
||||||
IntPtr chainPtr;
|
IntPtr chainPtr;
|
||||||
chainPtr = Marshal.AllocHGlobal(
|
chainPtr = Marshal.AllocHGlobal(
|
||||||
Marshal.SizeOf<FAudio.FAudioEffectChain>()
|
sizeof(FAudio.FAudioEffectChain)
|
||||||
);
|
);
|
||||||
|
|
||||||
FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr;
|
FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr;
|
||||||
reverbChain->EffectCount = 1;
|
reverbChain->EffectCount = 1;
|
||||||
reverbChain->pEffectDescriptors = Marshal.AllocHGlobal(
|
reverbChain->pEffectDescriptors = Marshal.AllocHGlobal(
|
||||||
Marshal.SizeOf<FAudio.FAudioEffectDescriptor>()
|
sizeof(FAudio.FAudioEffectDescriptor)
|
||||||
);
|
);
|
||||||
|
|
||||||
FAudio.FAudioEffectDescriptor* reverbDescriptor =
|
FAudio.FAudioEffectDescriptor* reverbDescriptor =
|
||||||
|
@ -157,7 +157,7 @@ namespace MoonWorks.Audio
|
||||||
// Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC
|
// Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC
|
||||||
|
|
||||||
IntPtr reverbParamsPtr = Marshal.AllocHGlobal(
|
IntPtr reverbParamsPtr = Marshal.AllocHGlobal(
|
||||||
Marshal.SizeOf<FAudio.FAudioFXReverbParameters>()
|
sizeof(FAudio.FAudioFXReverbParameters)
|
||||||
);
|
);
|
||||||
|
|
||||||
FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr;
|
FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr;
|
||||||
|
@ -187,7 +187,7 @@ namespace MoonWorks.Audio
|
||||||
ReverbVoice,
|
ReverbVoice,
|
||||||
0,
|
0,
|
||||||
reverbParamsPtr,
|
reverbParamsPtr,
|
||||||
(uint) Marshal.SizeOf<FAudio.FAudioFXReverbParameters>(),
|
(uint) sizeof(FAudio.FAudioFXReverbParameters),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
Marshal.FreeHGlobal(reverbParamsPtr);
|
Marshal.FreeHGlobal(reverbParamsPtr);
|
||||||
|
@ -198,7 +198,7 @@ namespace MoonWorks.Audio
|
||||||
{
|
{
|
||||||
SendCount = 2,
|
SendCount = 2,
|
||||||
pSends = Marshal.AllocHGlobal(
|
pSends = Marshal.AllocHGlobal(
|
||||||
2 * Marshal.SizeOf<FAudio.FAudioSendDescriptor>()
|
2 * sizeof(FAudio.FAudioSendDescriptor)
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;
|
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;
|
||||||
|
|
|
@ -12,7 +12,6 @@ namespace MoonWorks.Collision.Fixed
|
||||||
private readonly Fix64 cellSize;
|
private readonly Fix64 cellSize;
|
||||||
|
|
||||||
private readonly Dictionary<long, HashSet<T>> hashDictionary = new Dictionary<long, HashSet<T>>();
|
private readonly Dictionary<long, HashSet<T>> hashDictionary = new Dictionary<long, HashSet<T>>();
|
||||||
// FIXME: this ICollidable causes boxing which triggers garbage collection
|
|
||||||
private readonly Dictionary<T, (ICollidable, Transform2D, uint)> IDLookup = new Dictionary<T, (ICollidable, Transform2D, uint)>();
|
private readonly Dictionary<T, (ICollidable, Transform2D, uint)> IDLookup = new Dictionary<T, (ICollidable, Transform2D, uint)>();
|
||||||
|
|
||||||
public int MinX { get; private set; } = 0;
|
public int MinX { get; private set; } = 0;
|
||||||
|
|
|
@ -12,7 +12,6 @@ namespace MoonWorks.Collision.Float
|
||||||
private readonly int cellSize;
|
private readonly int cellSize;
|
||||||
|
|
||||||
private readonly Dictionary<long, HashSet<T>> hashDictionary = new Dictionary<long, HashSet<T>>();
|
private readonly Dictionary<long, HashSet<T>> hashDictionary = new Dictionary<long, HashSet<T>>();
|
||||||
// FIXME: this ICollidable causes boxing which triggers garbage collection
|
|
||||||
private readonly Dictionary<T, (ICollidable, Transform2D, uint)> IDLookup = new Dictionary<T, (ICollidable, Transform2D, uint)>();
|
private readonly Dictionary<T, (ICollidable, Transform2D, uint)> IDLookup = new Dictionary<T, (ICollidable, Transform2D, uint)>();
|
||||||
|
|
||||||
public int MinX { get; private set; } = 0;
|
public int MinX { get; private set; } = 0;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using RefreshCS;
|
using RefreshCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
|
@ -824,11 +823,6 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertRenderPassActive();
|
AssertRenderPassActive();
|
||||||
|
|
||||||
if (scissor.X < 0 || scissor.Y < 0 || scissor.W <= 0 || scissor.H <= 0)
|
|
||||||
{
|
|
||||||
throw new System.ArgumentOutOfRangeException("Scissor position cannot be negative and dimensions must be positive!");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Refresh.Refresh_SetScissor(
|
Refresh.Refresh_SetScissor(
|
||||||
|
@ -1427,7 +1421,7 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(IntPtr) uniformsPtr,
|
(IntPtr) uniformsPtr,
|
||||||
(uint) Marshal.SizeOf<T>()
|
(uint) sizeof(T)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1454,7 +1448,7 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(IntPtr) uniformsPtr,
|
(IntPtr) uniformsPtr,
|
||||||
(uint) Marshal.SizeOf<T>()
|
(uint) sizeof(T)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1482,7 +1476,7 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(IntPtr) uniformsPtr,
|
(IntPtr) uniformsPtr,
|
||||||
(uint) Marshal.SizeOf<T>()
|
(uint) sizeof(T)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1638,18 +1632,17 @@ namespace MoonWorks.Graphics
|
||||||
/// Can return null if the swapchain is unavailable. The user should ALWAYS handle the case where this occurs.
|
/// Can return null if the swapchain is unavailable. The user should ALWAYS handle the case where this occurs.
|
||||||
/// If null is returned, presentation will not occur.
|
/// If null is returned, presentation will not occur.
|
||||||
/// It is an error to acquire two swapchain textures from the same window in one command buffer.
|
/// It is an error to acquire two swapchain textures from the same window in one command buffer.
|
||||||
/// It is an error to dispose the swapchain texture. If you do this your game WILL crash. DO NOT DO THIS.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Texture AcquireSwapchainTexture(
|
public Texture AcquireSwapchainTexture(
|
||||||
Window window
|
Window window
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (!window.Claimed)
|
if (!window.Claimed)
|
||||||
{
|
{
|
||||||
throw new System.InvalidOperationException("Cannot acquire swapchain texture, window has not been claimed!");
|
throw new System.InvalidOperationException("Cannot acquire swapchain texture, window has not been claimed!");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var texturePtr = Refresh.Refresh_AcquireSwapchainTexture(
|
var texturePtr = Refresh.Refresh_AcquireSwapchainTexture(
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
|
@ -1663,13 +1656,13 @@ namespace MoonWorks.Graphics
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override the texture properties to avoid allocating a new texture instance!
|
return new Texture(
|
||||||
window.SwapchainTexture.Handle = texturePtr;
|
Device,
|
||||||
window.SwapchainTexture.Width = width;
|
texturePtr,
|
||||||
window.SwapchainTexture.Height = height;
|
window.SwapchainFormat,
|
||||||
window.SwapchainTexture.Format = window.SwapchainFormat;
|
width,
|
||||||
|
height
|
||||||
return window.SwapchainTexture;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1748,7 +1741,7 @@ namespace MoonWorks.Graphics
|
||||||
AssertRenderPassInactive("Cannot copy during render pass!");
|
AssertRenderPassInactive("Cannot copy during render pass!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var elementSize = Marshal.SizeOf<T>();
|
var elementSize = sizeof(T);
|
||||||
|
|
||||||
fixed (T* ptr = &data[startElement])
|
fixed (T* ptr = &data[startElement])
|
||||||
{
|
{
|
||||||
|
@ -1777,9 +1770,9 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
buffer.Handle,
|
buffer.Handle,
|
||||||
(uint) Marshal.SizeOf<T>() * bufferOffsetInElements,
|
(uint) sizeof(T) * bufferOffsetInElements,
|
||||||
dataPtr,
|
dataPtr,
|
||||||
(uint) Marshal.SizeOf<T>() * numElements
|
(uint) sizeof(T) * numElements
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1979,13 +1972,10 @@ namespace MoonWorks.Graphics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (graphicsPipeline.AttachmentInfo.HasDepthStencilAttachment)
|
var pipelineDepthFormat = graphicsPipeline.AttachmentInfo.DepthStencilFormat;
|
||||||
|
if (pipelineDepthFormat != depthStencilFormat)
|
||||||
{
|
{
|
||||||
var pipelineDepthFormat = graphicsPipeline.AttachmentInfo.DepthStencilFormat;
|
throw new System.InvalidOperationException($"Depth texture format mismatch! Pipeline expects {pipelineDepthFormat}, render pass attachment is {depthStencilFormat}");
|
||||||
if (pipelineDepthFormat != depthStencilFormat)
|
|
||||||
{
|
|
||||||
throw new System.InvalidOperationException($"Depth texture format mismatch! Pipeline expects {pipelineDepthFormat}, render pass attachment is {depthStencilFormat}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ namespace MoonWorks.Graphics.Font
|
||||||
{
|
{
|
||||||
fixed (FontRange *pFontRanges = &fontRanges[0])
|
fixed (FontRange *pFontRanges = &fontRanges[0])
|
||||||
{
|
{
|
||||||
var nativeSize = fontRanges.Length * Marshal.SizeOf<Wellspring.FontRange>();
|
var nativeSize = fontRanges.Length * sizeof(Wellspring.FontRange);
|
||||||
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) Marshal.SizeOf<Wellspring.FontRange>());
|
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) sizeof(Wellspring.FontRange));
|
||||||
System.Buffer.MemoryCopy(pFontRanges, fontRangeMemory, nativeSize, nativeSize);
|
System.Buffer.MemoryCopy(pFontRanges, fontRangeMemory, nativeSize, nativeSize);
|
||||||
|
|
||||||
var result = Wellspring.Wellspring_PackFontRanges(Handle, (IntPtr) fontRangeMemory, (uint) fontRanges.Length);
|
var result = Wellspring.Wellspring_PackFontRanges(Handle, (IntPtr) fontRangeMemory, (uint) fontRanges.Length);
|
||||||
|
|
|
@ -73,10 +73,6 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
window.Claimed = true;
|
window.Claimed = true;
|
||||||
window.SwapchainFormat = GetSwapchainFormat(window);
|
window.SwapchainFormat = GetSwapchainFormat(window);
|
||||||
if (window.SwapchainTexture == null)
|
|
||||||
{
|
|
||||||
window.SwapchainTexture = new Texture(this, IntPtr.Zero, window.SwapchainFormat, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@ -105,73 +101,6 @@ namespace MoonWorks.Graphics
|
||||||
return new CommandBuffer(this, Refresh.Refresh_AcquireCommandBuffer(Handle, 0));
|
return new CommandBuffer(this, Refresh.Refresh_AcquireCommandBuffer(Handle, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe void Submit(CommandBuffer commandBuffer)
|
|
||||||
{
|
|
||||||
var commandBufferPtrs = stackalloc IntPtr[1];
|
|
||||||
|
|
||||||
commandBufferPtrs[0] = commandBuffer.Handle;
|
|
||||||
|
|
||||||
Refresh.Refresh_Submit(
|
|
||||||
Handle,
|
|
||||||
1,
|
|
||||||
(IntPtr) commandBufferPtrs
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe void Submit(
|
|
||||||
CommandBuffer commandBufferOne,
|
|
||||||
CommandBuffer commandBufferTwo
|
|
||||||
) {
|
|
||||||
var commandBufferPtrs = stackalloc IntPtr[2];
|
|
||||||
|
|
||||||
commandBufferPtrs[0] = commandBufferOne.Handle;
|
|
||||||
commandBufferPtrs[1] = commandBufferTwo.Handle;
|
|
||||||
|
|
||||||
Refresh.Refresh_Submit(
|
|
||||||
Handle,
|
|
||||||
2,
|
|
||||||
(IntPtr) commandBufferPtrs
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe void Submit(
|
|
||||||
CommandBuffer commandBufferOne,
|
|
||||||
CommandBuffer commandBufferTwo,
|
|
||||||
CommandBuffer commandBufferThree
|
|
||||||
) {
|
|
||||||
var commandBufferPtrs = stackalloc IntPtr[3];
|
|
||||||
|
|
||||||
commandBufferPtrs[0] = commandBufferOne.Handle;
|
|
||||||
commandBufferPtrs[1] = commandBufferTwo.Handle;
|
|
||||||
commandBufferPtrs[2] = commandBufferThree.Handle;
|
|
||||||
|
|
||||||
Refresh.Refresh_Submit(
|
|
||||||
Handle,
|
|
||||||
3,
|
|
||||||
(IntPtr) commandBufferPtrs
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe void Submit(
|
|
||||||
CommandBuffer commandBufferOne,
|
|
||||||
CommandBuffer commandBufferTwo,
|
|
||||||
CommandBuffer commandBufferThree,
|
|
||||||
CommandBuffer commandBufferFour
|
|
||||||
) {
|
|
||||||
var commandBufferPtrs = stackalloc IntPtr[4];
|
|
||||||
|
|
||||||
commandBufferPtrs[0] = commandBufferOne.Handle;
|
|
||||||
commandBufferPtrs[1] = commandBufferTwo.Handle;
|
|
||||||
commandBufferPtrs[2] = commandBufferThree.Handle;
|
|
||||||
commandBufferPtrs[3] = commandBufferFour.Handle;
|
|
||||||
|
|
||||||
Refresh.Refresh_Submit(
|
|
||||||
Handle,
|
|
||||||
4,
|
|
||||||
(IntPtr) commandBufferPtrs
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe void Submit(params CommandBuffer[] commandBuffers)
|
public unsafe void Submit(params CommandBuffer[] commandBuffers)
|
||||||
{
|
{
|
||||||
var commandBufferPtrs = stackalloc IntPtr[commandBuffers.Length];
|
var commandBufferPtrs = stackalloc IntPtr[commandBuffers.Length];
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace MoonWorks.Graphics
|
||||||
public abstract class GraphicsResource : IDisposable
|
public abstract class GraphicsResource : IDisposable
|
||||||
{
|
{
|
||||||
public GraphicsDevice Device { get; }
|
public GraphicsDevice Device { get; }
|
||||||
public IntPtr Handle { get; internal set; }
|
public IntPtr Handle { get; protected set; }
|
||||||
|
|
||||||
public bool IsDisposed { get; private set; }
|
public bool IsDisposed { get; private set; }
|
||||||
protected abstract Action<IntPtr, IntPtr> QueueDestroyFunction { get; }
|
protected abstract Action<IntPtr, IntPtr> QueueDestroyFunction { get; }
|
||||||
|
|
|
@ -134,7 +134,7 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
Binding = 0,
|
Binding = 0,
|
||||||
InputRate = VertexInputRate.Vertex,
|
InputRate = VertexInputRate.Vertex,
|
||||||
Stride = (uint) Marshal.SizeOf<T>()
|
Stride = (uint) sizeof(T)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using RefreshCS;
|
using RefreshCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
|
@ -33,7 +32,7 @@ namespace MoonWorks.Graphics
|
||||||
return new Buffer(
|
return new Buffer(
|
||||||
device,
|
device,
|
||||||
usageFlags,
|
usageFlags,
|
||||||
(uint) Marshal.SizeOf<T>() * elementCount
|
(uint) sizeof(T) * elementCount
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,14 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Texture : GraphicsResource
|
public class Texture : GraphicsResource
|
||||||
{
|
{
|
||||||
public uint Width { get; internal set; }
|
public uint Width { get; }
|
||||||
public uint Height { get; internal set; }
|
public uint Height { get; }
|
||||||
public uint Depth { get; }
|
public uint Depth { get; }
|
||||||
public TextureFormat Format { get; internal set; }
|
public TextureFormat Format { get; }
|
||||||
public bool IsCube { get; }
|
public bool IsCube { get; }
|
||||||
public uint LevelCount { get; }
|
public uint LevelCount { get; }
|
||||||
public TextureUsageFlags UsageFlags { get; }
|
public TextureUsageFlags UsageFlags { get; }
|
||||||
|
|
||||||
// FIXME: this allocates a delegate instance
|
|
||||||
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
|
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
ShaderModule = shaderModule,
|
ShaderModule = shaderModule,
|
||||||
EntryPointName = entryPointName,
|
EntryPointName = entryPointName,
|
||||||
UniformBufferSize = (uint) Marshal.SizeOf<T>(),
|
UniformBufferSize = (uint) sizeof(T),
|
||||||
BufferBindingCount = bufferBindingCount,
|
BufferBindingCount = bufferBindingCount,
|
||||||
ImageBindingCount = imageBindingCount
|
ImageBindingCount = imageBindingCount
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
ShaderModule = shaderModule,
|
ShaderModule = shaderModule,
|
||||||
EntryPointName = entryPointName,
|
EntryPointName = entryPointName,
|
||||||
UniformBufferSize = (uint) Marshal.SizeOf<T>(),
|
UniformBufferSize = (uint) sizeof(T),
|
||||||
SamplerBindingCount = samplerBindingCount
|
SamplerBindingCount = samplerBindingCount
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
public bool IsHeld => ButtonStatus == ButtonStatus.Held;
|
public bool IsHeld => ButtonStatus == ButtonStatus.Held;
|
||||||
public bool IsDown => ButtonStatus == ButtonStatus.Pressed || ButtonStatus == ButtonStatus.Held;
|
public bool IsDown => ButtonStatus == ButtonStatus.Pressed || ButtonStatus == ButtonStatus.Held;
|
||||||
public bool IsReleased => ButtonStatus == ButtonStatus.Released;
|
public bool IsReleased => ButtonStatus == ButtonStatus.Released;
|
||||||
public bool IsIdle => ButtonStatus == ButtonStatus.Idle;
|
|
||||||
public bool IsUp => ButtonStatus == ButtonStatus.Idle || ButtonStatus == ButtonStatus.Released;
|
|
||||||
|
|
||||||
public ButtonState(ButtonStatus buttonStatus)
|
public ButtonState(ButtonStatus buttonStatus)
|
||||||
{
|
{
|
||||||
|
@ -20,34 +18,26 @@
|
||||||
{
|
{
|
||||||
if (isPressed)
|
if (isPressed)
|
||||||
{
|
{
|
||||||
if (IsUp)
|
if (ButtonStatus == ButtonStatus.Pressed)
|
||||||
|
{
|
||||||
|
return new ButtonState(ButtonStatus.Held);
|
||||||
|
}
|
||||||
|
else if (ButtonStatus == ButtonStatus.Released)
|
||||||
{
|
{
|
||||||
return new ButtonState(ButtonStatus.Pressed);
|
return new ButtonState(ButtonStatus.Pressed);
|
||||||
}
|
}
|
||||||
else
|
else if (ButtonStatus == ButtonStatus.Held)
|
||||||
{
|
{
|
||||||
return new ButtonState(ButtonStatus.Held);
|
return new ButtonState(ButtonStatus.Held);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return new ButtonState(ButtonStatus.Released);
|
||||||
if (IsDown)
|
|
||||||
{
|
|
||||||
return new ButtonState(ButtonStatus.Released);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return new ButtonState(ButtonStatus.Idle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Combines two button states. Useful for alt controls or input buffering.
|
|
||||||
/// </summary>
|
|
||||||
public static ButtonState operator |(ButtonState a, ButtonState b)
|
public static ButtonState operator |(ButtonState a, ButtonState b)
|
||||||
{
|
{
|
||||||
if (a.ButtonStatus == ButtonStatus.Idle || a.ButtonStatus == ButtonStatus.Released)
|
if (a.ButtonStatus == ButtonStatus.Released)
|
||||||
{
|
{
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,15 @@
|
||||||
public enum ButtonStatus
|
public enum ButtonStatus
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates that the button was not pressed last frame and is still not pressed.
|
/// Indicates that the input is not pressed.
|
||||||
/// </summary>
|
|
||||||
Idle,
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates that the button was released this frame.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Released,
|
Released,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates that the button was pressed this frame.
|
/// Indicates that the input was pressed this frame.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Pressed,
|
Pressed,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates that the button has been held for multiple frames.
|
/// Indicates that the input has been held for multiple frames.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Held
|
Held
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using SDL2;
|
using SDL2;
|
||||||
|
|
||||||
namespace MoonWorks.Input
|
namespace MoonWorks.Input
|
||||||
|
@ -11,7 +12,6 @@ namespace MoonWorks.Input
|
||||||
|
|
||||||
public IntPtr State { get; private set; }
|
public IntPtr State { get; private set; }
|
||||||
|
|
||||||
private KeyCode[] KeyCodes;
|
|
||||||
private KeyboardButton[] Keys { get; }
|
private KeyboardButton[] Keys { get; }
|
||||||
private int numKeys;
|
private int numKeys;
|
||||||
|
|
||||||
|
@ -41,10 +41,8 @@ namespace MoonWorks.Input
|
||||||
{
|
{
|
||||||
SDL.SDL_GetKeyboardState(out numKeys);
|
SDL.SDL_GetKeyboardState(out numKeys);
|
||||||
|
|
||||||
KeyCodes = Enum.GetValues<KeyCode>();
|
|
||||||
Keys = new KeyboardButton[numKeys];
|
Keys = new KeyboardButton[numKeys];
|
||||||
|
foreach (KeyCode keycode in Enum.GetValues(typeof(KeyCode)))
|
||||||
foreach (KeyCode keycode in KeyCodes)
|
|
||||||
{
|
{
|
||||||
Keys[(int) keycode] = new KeyboardButton(this, keycode);
|
Keys[(int) keycode] = new KeyboardButton(this, keycode);
|
||||||
}
|
}
|
||||||
|
@ -56,18 +54,18 @@ namespace MoonWorks.Input
|
||||||
|
|
||||||
State = SDL.SDL_GetKeyboardState(out _);
|
State = SDL.SDL_GetKeyboardState(out _);
|
||||||
|
|
||||||
foreach (KeyCode keycode in KeyCodes)
|
foreach (int keycode in Enum.GetValues(typeof(KeyCode)))
|
||||||
{
|
{
|
||||||
var button = Keys[(int) keycode];
|
var button = Keys[keycode];
|
||||||
button.Update();
|
button.Update();
|
||||||
|
|
||||||
if (button.IsPressed)
|
if (button.IsPressed)
|
||||||
{
|
{
|
||||||
if (TextInputBindings.TryGetValue(keycode, out var textIndex))
|
if (TextInputBindings.TryGetValue((KeyCode) keycode, out var textIndex))
|
||||||
{
|
{
|
||||||
Inputs.OnTextInput(TextInputCharacters[(textIndex)]);
|
Inputs.OnTextInput(TextInputCharacters[(textIndex)]);
|
||||||
}
|
}
|
||||||
else if (IsDown(KeyCode.LeftControl) && keycode == KeyCode.V)
|
else if (IsDown(KeyCode.LeftControl) && (KeyCode) keycode == KeyCode.V)
|
||||||
{
|
{
|
||||||
Inputs.OnTextInput(TextInputCharacters[6]);
|
Inputs.OnTextInput(TextInputCharacters[6]);
|
||||||
}
|
}
|
||||||
|
@ -78,6 +76,11 @@ namespace MoonWorks.Input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsDown(KeyCode keycode)
|
||||||
|
{
|
||||||
|
return Keys[(int) keycode].IsDown;
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsPressed(KeyCode keycode)
|
public bool IsPressed(KeyCode keycode)
|
||||||
{
|
{
|
||||||
return Keys[(int) keycode].IsPressed;
|
return Keys[(int) keycode].IsPressed;
|
||||||
|
@ -88,26 +91,11 @@ namespace MoonWorks.Input
|
||||||
return Keys[(int) keycode].IsHeld;
|
return Keys[(int) keycode].IsHeld;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsDown(KeyCode keycode)
|
|
||||||
{
|
|
||||||
return Keys[(int) keycode].IsDown;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsReleased(KeyCode keycode)
|
public bool IsReleased(KeyCode keycode)
|
||||||
{
|
{
|
||||||
return Keys[(int) keycode].IsReleased;
|
return Keys[(int) keycode].IsReleased;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsIdle(KeyCode keycode)
|
|
||||||
{
|
|
||||||
return Keys[(int) keycode].IsIdle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsUp(KeyCode keycode)
|
|
||||||
{
|
|
||||||
return Keys[(int) keycode].IsUp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public KeyboardButton Button(KeyCode keycode)
|
public KeyboardButton Button(KeyCode keycode)
|
||||||
{
|
{
|
||||||
return Keys[(int) keycode];
|
return Keys[(int) keycode];
|
||||||
|
|
|
@ -43,6 +43,8 @@ namespace MoonWorks.Input
|
||||||
|
|
||||||
private readonly Dictionary<MouseButtonCode, MouseButton> CodeToButton;
|
private readonly Dictionary<MouseButtonCode, MouseButton> CodeToButton;
|
||||||
|
|
||||||
|
private IEnumerable<MouseButton> Buttons => CodeToButton.Values;
|
||||||
|
|
||||||
public Mouse()
|
public Mouse()
|
||||||
{
|
{
|
||||||
LeftButton = new MouseButton(this, MouseButtonCode.Left, SDL.SDL_BUTTON_LMASK);
|
LeftButton = new MouseButton(this, MouseButtonCode.Left, SDL.SDL_BUTTON_LMASK);
|
||||||
|
@ -76,7 +78,7 @@ namespace MoonWorks.Input
|
||||||
Wheel = WheelRaw - previousWheelRaw;
|
Wheel = WheelRaw - previousWheelRaw;
|
||||||
previousWheelRaw = WheelRaw;
|
previousWheelRaw = WheelRaw;
|
||||||
|
|
||||||
foreach (var button in CodeToButton.Values)
|
foreach (var button in Buttons)
|
||||||
{
|
{
|
||||||
button.Update();
|
button.Update();
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,9 @@ namespace MoonWorks.Input
|
||||||
public ButtonState State { get; protected set; }
|
public ButtonState State { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True if the button was pressed this exact frame.
|
/// True if the button is pressed or held.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsPressed => State.IsPressed;
|
public bool IsDown => State.IsDown;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True if the button has been continuously held for more than one frame.
|
/// True if the button has been continuously held for more than one frame.
|
||||||
|
@ -15,25 +15,15 @@ namespace MoonWorks.Input
|
||||||
public bool IsHeld => State.IsHeld;
|
public bool IsHeld => State.IsHeld;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True if the button is pressed or held.
|
/// True if the button was pressed this exact frame.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDown => State.IsDown;
|
public bool IsPressed => State.IsPressed;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True if the button was released this frame.
|
/// True if the button is not pressed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsReleased => State.IsReleased;
|
public bool IsReleased => State.IsReleased;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// True if the button was not pressed the previous or current frame.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsIdle => State.IsIdle;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// True if the button is idle or released.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsUp => State.IsUp;
|
|
||||||
|
|
||||||
internal virtual void Update()
|
internal virtual void Update()
|
||||||
{
|
{
|
||||||
State = State.Update(CheckPressed());
|
State = State.Update(CheckPressed());
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using MoonWorks.Graphics;
|
|
||||||
using SDL2;
|
using SDL2;
|
||||||
|
|
||||||
namespace MoonWorks
|
namespace MoonWorks
|
||||||
|
@ -11,7 +10,6 @@ namespace MoonWorks
|
||||||
public ScreenMode ScreenMode { get; private set; }
|
public ScreenMode ScreenMode { get; private set; }
|
||||||
public uint Width { get; private set; }
|
public uint Width { get; private set; }
|
||||||
public uint Height { get; private set; }
|
public uint Height { get; private set; }
|
||||||
internal Texture SwapchainTexture { get; set; } = null;
|
|
||||||
|
|
||||||
public bool Claimed { get; internal set; }
|
public bool Claimed { get; internal set; }
|
||||||
public MoonWorks.Graphics.TextureFormat SwapchainFormat { get; internal set; }
|
public MoonWorks.Graphics.TextureFormat SwapchainFormat { get; internal set; }
|
||||||
|
|
Loading…
Reference in New Issue