Compare commits
13 Commits
5ccebc018f
...
b9f2d50730
Author | SHA1 | Date |
---|---|---|
|
b9f2d50730 | |
|
debb76f62a | |
|
ca61e94b13 | |
|
36e6c6f332 | |
|
916962da6c | |
|
cfd52b00bd | |
|
b0e1ad3cf8 | |
|
2c4e1b972a | |
|
751b8310ce | |
|
474b8fe37d | |
|
bc41d2c079 | |
|
d5ddd44bd3 | |
|
de9d13757a |
|
@ -1,7 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||||
<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!");
|
||||||
Handle = IntPtr.Zero;
|
|
||||||
FAudio.FAudio_Release(Handle);
|
FAudio.FAudio_Release(Handle);
|
||||||
|
Handle = IntPtr.Zero;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +118,13 @@ namespace MoonWorks.Audio
|
||||||
|
|
||||||
IntPtr chainPtr;
|
IntPtr chainPtr;
|
||||||
chainPtr = Marshal.AllocHGlobal(
|
chainPtr = Marshal.AllocHGlobal(
|
||||||
sizeof(FAudio.FAudioEffectChain)
|
Marshal.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(
|
||||||
sizeof(FAudio.FAudioEffectDescriptor)
|
Marshal.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(
|
||||||
sizeof(FAudio.FAudioFXReverbParameters)
|
Marshal.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) sizeof(FAudio.FAudioFXReverbParameters),
|
(uint) Marshal.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 * sizeof(FAudio.FAudioSendDescriptor)
|
2 * Marshal.SizeOf<FAudio.FAudioSendDescriptor>()
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;
|
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;
|
||||||
|
|
|
@ -12,6 +12,7 @@ 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,6 +12,7 @@ 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,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using RefreshCS;
|
using RefreshCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
|
@ -823,6 +824,11 @@ 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(
|
||||||
|
@ -1421,7 +1427,7 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(IntPtr) uniformsPtr,
|
(IntPtr) uniformsPtr,
|
||||||
(uint) sizeof(T)
|
(uint) Marshal.SizeOf<T>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1448,7 +1454,7 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(IntPtr) uniformsPtr,
|
(IntPtr) uniformsPtr,
|
||||||
(uint) sizeof(T)
|
(uint) Marshal.SizeOf<T>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1476,7 +1482,7 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(IntPtr) uniformsPtr,
|
(IntPtr) uniformsPtr,
|
||||||
(uint) sizeof(T)
|
(uint) Marshal.SizeOf<T>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1632,17 +1638,18 @@ 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,
|
||||||
|
@ -1656,13 +1663,13 @@ namespace MoonWorks.Graphics
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Texture(
|
// Override the texture properties to avoid allocating a new texture instance!
|
||||||
Device,
|
window.SwapchainTexture.Handle = texturePtr;
|
||||||
texturePtr,
|
window.SwapchainTexture.Width = width;
|
||||||
window.SwapchainFormat,
|
window.SwapchainTexture.Height = height;
|
||||||
width,
|
window.SwapchainTexture.Format = window.SwapchainFormat;
|
||||||
height
|
|
||||||
);
|
return window.SwapchainTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1741,7 +1748,7 @@ namespace MoonWorks.Graphics
|
||||||
AssertRenderPassInactive("Cannot copy during render pass!");
|
AssertRenderPassInactive("Cannot copy during render pass!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var elementSize = sizeof(T);
|
var elementSize = Marshal.SizeOf<T>();
|
||||||
|
|
||||||
fixed (T* ptr = &data[startElement])
|
fixed (T* ptr = &data[startElement])
|
||||||
{
|
{
|
||||||
|
@ -1770,9 +1777,9 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
buffer.Handle,
|
buffer.Handle,
|
||||||
(uint) sizeof(T) * bufferOffsetInElements,
|
(uint) Marshal.SizeOf<T>() * bufferOffsetInElements,
|
||||||
dataPtr,
|
dataPtr,
|
||||||
(uint) sizeof(T) * numElements
|
(uint) Marshal.SizeOf<T>() * numElements
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1972,10 +1979,13 @@ namespace MoonWorks.Graphics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pipelineDepthFormat = graphicsPipeline.AttachmentInfo.DepthStencilFormat;
|
if (graphicsPipeline.AttachmentInfo.HasDepthStencilAttachment)
|
||||||
if (pipelineDepthFormat != depthStencilFormat)
|
|
||||||
{
|
{
|
||||||
throw new System.InvalidOperationException($"Depth texture format mismatch! Pipeline expects {pipelineDepthFormat}, render pass attachment is {depthStencilFormat}");
|
var pipelineDepthFormat = graphicsPipeline.AttachmentInfo.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 * sizeof(Wellspring.FontRange);
|
var nativeSize = fontRanges.Length * Marshal.SizeOf<Wellspring.FontRange>();
|
||||||
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) sizeof(Wellspring.FontRange));
|
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) Marshal.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,6 +73,10 @@ 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;
|
||||||
|
@ -101,6 +105,73 @@ 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; protected set; }
|
public IntPtr Handle { get; internal 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) sizeof(T)
|
Stride = (uint) Marshal.SizeOf<T>()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using RefreshCS;
|
using RefreshCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
|
@ -32,7 +33,7 @@ namespace MoonWorks.Graphics
|
||||||
return new Buffer(
|
return new Buffer(
|
||||||
device,
|
device,
|
||||||
usageFlags,
|
usageFlags,
|
||||||
(uint) sizeof(T) * elementCount
|
(uint) Marshal.SizeOf<T>() * elementCount
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,15 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Texture : GraphicsResource
|
public class Texture : GraphicsResource
|
||||||
{
|
{
|
||||||
public uint Width { get; }
|
public uint Width { get; internal set; }
|
||||||
public uint Height { get; }
|
public uint Height { get; internal set; }
|
||||||
public uint Depth { get; }
|
public uint Depth { get; }
|
||||||
public TextureFormat Format { get; }
|
public TextureFormat Format { get; internal set; }
|
||||||
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) sizeof(T),
|
UniformBufferSize = (uint) Marshal.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) sizeof(T),
|
UniformBufferSize = (uint) Marshal.SizeOf<T>(),
|
||||||
SamplerBindingCount = samplerBindingCount
|
SamplerBindingCount = samplerBindingCount
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -18,26 +20,34 @@
|
||||||
{
|
{
|
||||||
if (isPressed)
|
if (isPressed)
|
||||||
{
|
{
|
||||||
if (ButtonStatus == ButtonStatus.Pressed)
|
if (IsUp)
|
||||||
{
|
|
||||||
return new ButtonState(ButtonStatus.Held);
|
|
||||||
}
|
|
||||||
else if (ButtonStatus == ButtonStatus.Released)
|
|
||||||
{
|
{
|
||||||
return new ButtonState(ButtonStatus.Pressed);
|
return new ButtonState(ButtonStatus.Pressed);
|
||||||
}
|
}
|
||||||
else if (ButtonStatus == ButtonStatus.Held)
|
else
|
||||||
{
|
{
|
||||||
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.Released)
|
if (a.ButtonStatus == ButtonStatus.Idle || a.ButtonStatus == ButtonStatus.Released)
|
||||||
{
|
{
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,19 @@
|
||||||
public enum ButtonStatus
|
public enum ButtonStatus
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates that the input is not pressed.
|
/// Indicates that the button was not pressed last frame and is still not pressed.
|
||||||
|
/// </summary>
|
||||||
|
Idle,
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates that the button was released this frame.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Released,
|
Released,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates that the input was pressed this frame.
|
/// Indicates that the button was pressed this frame.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Pressed,
|
Pressed,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates that the input has been held for multiple frames.
|
/// Indicates that the button has been held for multiple frames.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Held
|
Held
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
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
|
||||||
|
@ -12,6 +11,7 @@ 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,8 +41,10 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -54,18 +56,18 @@ namespace MoonWorks.Input
|
||||||
|
|
||||||
State = SDL.SDL_GetKeyboardState(out _);
|
State = SDL.SDL_GetKeyboardState(out _);
|
||||||
|
|
||||||
foreach (int keycode in Enum.GetValues(typeof(KeyCode)))
|
foreach (KeyCode keycode in KeyCodes)
|
||||||
{
|
{
|
||||||
var button = Keys[keycode];
|
var button = Keys[(int) keycode];
|
||||||
button.Update();
|
button.Update();
|
||||||
|
|
||||||
if (button.IsPressed)
|
if (button.IsPressed)
|
||||||
{
|
{
|
||||||
if (TextInputBindings.TryGetValue((KeyCode) keycode, out var textIndex))
|
if (TextInputBindings.TryGetValue(keycode, out var textIndex))
|
||||||
{
|
{
|
||||||
Inputs.OnTextInput(TextInputCharacters[(textIndex)]);
|
Inputs.OnTextInput(TextInputCharacters[(textIndex)]);
|
||||||
}
|
}
|
||||||
else if (IsDown(KeyCode.LeftControl) && (KeyCode) keycode == KeyCode.V)
|
else if (IsDown(KeyCode.LeftControl) && keycode == KeyCode.V)
|
||||||
{
|
{
|
||||||
Inputs.OnTextInput(TextInputCharacters[6]);
|
Inputs.OnTextInput(TextInputCharacters[6]);
|
||||||
}
|
}
|
||||||
|
@ -76,11 +78,6 @@ 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;
|
||||||
|
@ -91,11 +88,26 @@ 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,8 +43,6 @@ 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);
|
||||||
|
@ -78,7 +76,7 @@ namespace MoonWorks.Input
|
||||||
Wheel = WheelRaw - previousWheelRaw;
|
Wheel = WheelRaw - previousWheelRaw;
|
||||||
previousWheelRaw = WheelRaw;
|
previousWheelRaw = WheelRaw;
|
||||||
|
|
||||||
foreach (var button in Buttons)
|
foreach (var button in CodeToButton.Values)
|
||||||
{
|
{
|
||||||
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 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 has been continuously held for more than one frame.
|
/// True if the button has been continuously held for more than one frame.
|
||||||
|
@ -15,15 +15,25 @@ namespace MoonWorks.Input
|
||||||
public bool IsHeld => State.IsHeld;
|
public bool IsHeld => State.IsHeld;
|
||||||
|
|
||||||
/// <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 is not pressed.
|
/// True if the button was released this frame.
|
||||||
/// </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,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using MoonWorks.Graphics;
|
||||||
using SDL2;
|
using SDL2;
|
||||||
|
|
||||||
namespace MoonWorks
|
namespace MoonWorks
|
||||||
|
@ -10,6 +11,7 @@ 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