garbage collection optimizations

moar-validation
cosmonaut 2022-12-13 00:34:16 -08:00
parent cfd52b00bd
commit 916962da6c
2 changed files with 75 additions and 5 deletions

View File

@ -101,6 +101,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];

View File

@ -11,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;
@ -40,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);
} }
@ -53,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]);
} }