2022-11-09 19:54:42 +00:00
|
|
|
|
using MoonWorks.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace MoonWorks.Test
|
|
|
|
|
{
|
|
|
|
|
public static class TestUtils
|
|
|
|
|
{
|
2024-03-07 18:35:12 +00:00
|
|
|
|
// change this to test different backends
|
2024-03-11 17:20:54 +00:00
|
|
|
|
public static Backend[] PreferredBackends = [Backend.D3D11];
|
2024-03-06 08:15:44 +00:00
|
|
|
|
|
2022-11-09 19:54:42 +00:00
|
|
|
|
public static WindowCreateInfo GetStandardWindowCreateInfo()
|
|
|
|
|
{
|
|
|
|
|
return new WindowCreateInfo(
|
|
|
|
|
"Main Window",
|
|
|
|
|
640,
|
|
|
|
|
480,
|
|
|
|
|
ScreenMode.Windowed,
|
|
|
|
|
PresentMode.FIFO
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FrameLimiterSettings GetStandardFrameLimiterSettings()
|
|
|
|
|
{
|
|
|
|
|
return new FrameLimiterSettings(
|
|
|
|
|
FrameLimiterMode.Capped,
|
|
|
|
|
60
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GraphicsPipelineCreateInfo GetStandardGraphicsPipelineCreateInfo(
|
2022-11-17 20:33:58 +00:00
|
|
|
|
TextureFormat swapchainFormat,
|
2022-11-09 19:54:42 +00:00
|
|
|
|
ShaderModule vertShaderModule,
|
|
|
|
|
ShaderModule fragShaderModule
|
|
|
|
|
) {
|
|
|
|
|
return new GraphicsPipelineCreateInfo
|
|
|
|
|
{
|
|
|
|
|
AttachmentInfo = new GraphicsPipelineAttachmentInfo(
|
|
|
|
|
new ColorAttachmentDescription(
|
2022-11-17 20:33:58 +00:00
|
|
|
|
swapchainFormat,
|
2022-11-09 19:54:42 +00:00
|
|
|
|
ColorAttachmentBlendState.Opaque
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
DepthStencilState = DepthStencilState.Disable,
|
|
|
|
|
MultisampleState = MultisampleState.None,
|
|
|
|
|
PrimitiveType = PrimitiveType.TriangleList,
|
2023-01-27 03:22:38 +00:00
|
|
|
|
RasterizerState = RasterizerState.CCW_CullNone,
|
2022-11-09 19:54:42 +00:00
|
|
|
|
VertexInputState = VertexInputState.Empty,
|
|
|
|
|
VertexShaderInfo = GraphicsShaderInfo.Create(vertShaderModule, "main", 0),
|
|
|
|
|
FragmentShaderInfo = GraphicsShaderInfo.Create(fragShaderModule, "main", 0)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetShaderPath(string shaderName)
|
|
|
|
|
{
|
2023-01-21 00:57:25 +00:00
|
|
|
|
return SDL2.SDL.SDL_GetBasePath() + "Content/Shaders/Compiled/" + shaderName + ".refresh";
|
2022-11-09 19:54:42 +00:00
|
|
|
|
}
|
2022-11-12 17:51:22 +00:00
|
|
|
|
|
|
|
|
|
public static string GetTexturePath(string textureName)
|
|
|
|
|
{
|
|
|
|
|
return SDL2.SDL.SDL_GetBasePath() + "Content/Textures/" + textureName;
|
|
|
|
|
}
|
2022-12-23 04:48:07 +00:00
|
|
|
|
|
2024-02-07 15:27:55 +00:00
|
|
|
|
public static string GetVideoPath(string videoName)
|
|
|
|
|
{
|
|
|
|
|
return SDL2.SDL.SDL_GetBasePath() + "Content/Videos/" + videoName;
|
|
|
|
|
}
|
2023-01-22 01:59:48 +00:00
|
|
|
|
|
2024-02-07 15:27:55 +00:00
|
|
|
|
public enum ButtonType
|
|
|
|
|
{
|
|
|
|
|
Left, // A/left arrow on keyboard, left face button on gamepad
|
|
|
|
|
Bottom, // S/down arrow on keyboard, bottom face button on gamepad
|
|
|
|
|
Right // D/right arrow on keyboard, right face button on gamepad
|
|
|
|
|
}
|
2022-12-23 04:48:07 +00:00
|
|
|
|
|
2024-02-07 15:27:55 +00:00
|
|
|
|
public static bool CheckButtonPressed(Input.Inputs inputs, ButtonType buttonType)
|
|
|
|
|
{
|
|
|
|
|
bool pressed = false;
|
2022-12-23 04:48:07 +00:00
|
|
|
|
|
2024-02-07 15:27:55 +00:00
|
|
|
|
if (buttonType == ButtonType.Left)
|
|
|
|
|
{
|
|
|
|
|
pressed = (
|
|
|
|
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsPressed) ||
|
|
|
|
|
inputs.Keyboard.IsPressed(Input.KeyCode.A) ||
|
|
|
|
|
inputs.Keyboard.IsPressed(Input.KeyCode.Left)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else if (buttonType == ButtonType.Bottom)
|
|
|
|
|
{
|
|
|
|
|
pressed = (
|
|
|
|
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsPressed) ||
|
|
|
|
|
inputs.Keyboard.IsPressed(Input.KeyCode.S) ||
|
|
|
|
|
inputs.Keyboard.IsPressed(Input.KeyCode.Down)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else if (buttonType == ButtonType.Right)
|
|
|
|
|
{
|
|
|
|
|
pressed = (
|
|
|
|
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsPressed) ||
|
|
|
|
|
inputs.Keyboard.IsPressed(Input.KeyCode.D) ||
|
|
|
|
|
inputs.Keyboard.IsPressed(Input.KeyCode.Right)
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-12-23 04:48:07 +00:00
|
|
|
|
|
2024-02-07 15:27:55 +00:00
|
|
|
|
return pressed;
|
|
|
|
|
}
|
2023-01-07 15:47:08 +00:00
|
|
|
|
|
2024-02-07 15:27:55 +00:00
|
|
|
|
public static bool CheckButtonDown(Input.Inputs inputs, ButtonType buttonType)
|
|
|
|
|
{
|
|
|
|
|
bool down = false;
|
2023-01-07 15:47:08 +00:00
|
|
|
|
|
2024-02-07 15:27:55 +00:00
|
|
|
|
if (buttonType == ButtonType.Left)
|
|
|
|
|
{
|
|
|
|
|
down = (
|
|
|
|
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsDown) ||
|
|
|
|
|
inputs.Keyboard.IsDown(Input.KeyCode.A) ||
|
|
|
|
|
inputs.Keyboard.IsDown(Input.KeyCode.Left)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else if (buttonType == ButtonType.Bottom)
|
|
|
|
|
{
|
|
|
|
|
down = (
|
|
|
|
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsDown) ||
|
|
|
|
|
inputs.Keyboard.IsDown(Input.KeyCode.S) ||
|
|
|
|
|
inputs.Keyboard.IsDown(Input.KeyCode.Down)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else if (buttonType == ButtonType.Right)
|
|
|
|
|
{
|
|
|
|
|
down = (
|
|
|
|
|
(inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsDown) ||
|
|
|
|
|
inputs.Keyboard.IsDown(Input.KeyCode.D) ||
|
|
|
|
|
inputs.Keyboard.IsDown(Input.KeyCode.Right)
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-01-07 15:47:08 +00:00
|
|
|
|
|
2024-02-07 15:27:55 +00:00
|
|
|
|
return down;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-09 19:54:42 +00:00
|
|
|
|
}
|