Added gamepad control support, cleaned up GetBufferDataGame for clarity
parent
091fe5e9f6
commit
c0213bafc8
|
@ -17,7 +17,7 @@ namespace MoonWorks.Test
|
|||
|
||||
public BasicTriangleGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||
{
|
||||
Logger.LogInfo("Press A to toggle wireframe mode\nPress S to toggle small viewport\nPress D to toggle scissor rect");
|
||||
Logger.LogInfo("Press Left to toggle wireframe mode\nPress Down to toggle small viewport\nPress Right to toggle scissor rect");
|
||||
|
||||
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangleVertices.spv"));
|
||||
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.spv"));
|
||||
|
@ -35,19 +35,19 @@ namespace MoonWorks.Test
|
|||
|
||||
protected override void Update(System.TimeSpan delta)
|
||||
{
|
||||
if (Inputs.Keyboard.IsPressed(Input.KeyCode.A))
|
||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
|
||||
{
|
||||
useWireframeMode = !useWireframeMode;
|
||||
Logger.LogInfo("Using wireframe mode: " + useWireframeMode);
|
||||
}
|
||||
|
||||
if (Inputs.Keyboard.IsPressed(Input.KeyCode.S))
|
||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
|
||||
{
|
||||
useSmallViewport = !useSmallViewport;
|
||||
Logger.LogInfo("Using small viewport: " + useSmallViewport);
|
||||
}
|
||||
|
||||
if (Inputs.Keyboard.IsPressed(Input.KeyCode.D))
|
||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
|
||||
{
|
||||
useScissorRect = !useScissorRect;
|
||||
Logger.LogInfo("Using scissor rect: " + useScissorRect);
|
||||
|
|
|
@ -341,7 +341,7 @@ namespace MoonWorks.Test
|
|||
|
||||
finishedLoading = true;
|
||||
Logger.LogInfo("Finished loading!");
|
||||
Logger.LogInfo("Press A to toggle Depth-Only Mode");
|
||||
Logger.LogInfo("Press Down to toggle Depth-Only Mode");
|
||||
}
|
||||
|
||||
protected override void Update(System.TimeSpan delta)
|
||||
|
@ -356,7 +356,7 @@ namespace MoonWorks.Test
|
|||
cubeTimer * 2f
|
||||
);
|
||||
|
||||
if (Inputs.Keyboard.IsPressed(Input.KeyCode.A))
|
||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
|
||||
{
|
||||
depthOnlyEnabled = !depthOnlyEnabled;
|
||||
Logger.LogInfo("Depth-Only Mode enabled: " + depthOnlyEnabled);
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace MoonWorks.Test
|
|||
|
||||
public CullFaceGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||
{
|
||||
Logger.LogInfo("Press A to toggle the winding order of the triangles (default is counter-clockwise)");
|
||||
Logger.LogInfo("Press Down to toggle the winding order of the triangles (default is counter-clockwise)");
|
||||
|
||||
// Load the shaders
|
||||
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColorVert.spv"));
|
||||
|
@ -84,7 +84,7 @@ namespace MoonWorks.Test
|
|||
|
||||
protected override void Update(System.TimeSpan delta)
|
||||
{
|
||||
if (Inputs.Keyboard.IsPressed(Input.KeyCode.A))
|
||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom))
|
||||
{
|
||||
useClockwiseWinding = !useClockwiseWinding;
|
||||
Logger.LogInfo("Using clockwise winding: " + useClockwiseWinding);
|
||||
|
|
|
@ -9,28 +9,28 @@ namespace MoonWorks.Test
|
|||
{
|
||||
public GetBufferDataGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||
{
|
||||
PositionColorVertex[] vertices = new PositionColorVertex[]
|
||||
PositionVertex[] vertices = new PositionVertex[]
|
||||
{
|
||||
new PositionColorVertex(new Vector3(0, 0, 0), Color.Red),
|
||||
new PositionColorVertex(new Vector3(0, 0, 1), Color.Green),
|
||||
new PositionColorVertex(new Vector3(0, 1, 0), Color.Blue),
|
||||
new PositionColorVertex(new Vector3(0, 1, 1), Color.Yellow),
|
||||
new PositionColorVertex(new Vector3(1, 0, 0), Color.Orange),
|
||||
new PositionColorVertex(new Vector3(1, 0, 1), Color.Brown),
|
||||
new PositionColorVertex(new Vector3(1, 1, 0), Color.Black),
|
||||
new PositionColorVertex(new Vector3(1, 1, 1), Color.White),
|
||||
new PositionVertex(new Vector3(0, 0, 0)),
|
||||
new PositionVertex(new Vector3(0, 0, 1)),
|
||||
new PositionVertex(new Vector3(0, 1, 0)),
|
||||
new PositionVertex(new Vector3(0, 1, 1)),
|
||||
new PositionVertex(new Vector3(1, 0, 0)),
|
||||
new PositionVertex(new Vector3(1, 0, 1)),
|
||||
new PositionVertex(new Vector3(1, 1, 0)),
|
||||
new PositionVertex(new Vector3(1, 1, 1)),
|
||||
};
|
||||
|
||||
PositionColorVertex[] otherVerts = new PositionColorVertex[]
|
||||
PositionVertex[] otherVerts = new PositionVertex[]
|
||||
{
|
||||
new PositionColorVertex(new Vector3(0.5f, 0.5f, 0.5f), Color.Fuchsia),
|
||||
new PositionColorVertex(new Vector3(0.1f, 0.1f, 0.1f), Color.LightCoral),
|
||||
new PositionColorVertex(new Vector3(0.2f, 0.2f, 0.2f), Color.Lime)
|
||||
new PositionVertex(new Vector3(1, 2, 3)),
|
||||
new PositionVertex(new Vector3(4, 5, 6)),
|
||||
new PositionVertex(new Vector3(7, 8, 9))
|
||||
};
|
||||
|
||||
int vertexSize = Marshal.SizeOf<PositionColorVertex>();
|
||||
int vertexSize = Marshal.SizeOf<PositionVertex>();
|
||||
|
||||
Buffer vertexBuffer = Buffer.Create<PositionColorVertex>(
|
||||
Buffer vertexBuffer = Buffer.Create<PositionVertex>(
|
||||
GraphicsDevice,
|
||||
BufferUsageFlags.Vertex,
|
||||
(uint) vertices.Length
|
||||
|
@ -44,7 +44,7 @@ namespace MoonWorks.Test
|
|||
GraphicsDevice.Wait();
|
||||
|
||||
// Read back and print out the vertex values
|
||||
PositionColorVertex[] readbackVertices = new PositionColorVertex[vertices.Length];
|
||||
PositionVertex[] readbackVertices = new PositionVertex[vertices.Length];
|
||||
vertexBuffer.GetData(
|
||||
readbackVertices,
|
||||
(uint) (vertexSize * readbackVertices.Length) // FIXME: Seems like this should get auto-calculated somehow
|
||||
|
@ -65,7 +65,7 @@ namespace MoonWorks.Test
|
|||
readbackVertices,
|
||||
(uint) (vertexSize * readbackVertices.Length)
|
||||
);
|
||||
Logger.LogInfo("===");
|
||||
Logger.LogInfo("=== Change first three vertices ===");
|
||||
for (int i = 0; i < readbackVertices.Length; i += 1)
|
||||
{
|
||||
Logger.LogInfo(readbackVertices[i].ToString());
|
||||
|
@ -88,7 +88,7 @@ namespace MoonWorks.Test
|
|||
readbackVertices,
|
||||
(uint) (vertexSize * readbackVertices.Length)
|
||||
);
|
||||
Logger.LogInfo("===");
|
||||
Logger.LogInfo("=== Change last two vertices ===");
|
||||
for (int i = 0; i < readbackVertices.Length; i += 1)
|
||||
{
|
||||
Logger.LogInfo(readbackVertices[i].ToString());
|
||||
|
@ -98,7 +98,17 @@ namespace MoonWorks.Test
|
|||
|
||||
protected override void Update(System.TimeSpan delta) { }
|
||||
|
||||
protected override void Draw(double alpha) { }
|
||||
protected override void Draw(double alpha)
|
||||
{
|
||||
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||
Texture? swapchainTexture = cmdbuf.AcquireSwapchainTexture(MainWindow);
|
||||
if (swapchainTexture != null)
|
||||
{
|
||||
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, Color.Black));
|
||||
cmdbuf.EndRenderPass();
|
||||
}
|
||||
GraphicsDevice.Submit(cmdbuf);
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace MoonWorks.Test
|
|||
|
||||
public MSAAGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||
{
|
||||
Logger.LogInfo("Press A and D to cycle between sample counts");
|
||||
Logger.LogInfo("Press Left and Right to cycle between sample counts");
|
||||
Logger.LogInfo("Setting sample count to: " + currentSampleCount);
|
||||
|
||||
// Create the MSAA pipelines
|
||||
|
@ -94,7 +94,7 @@ namespace MoonWorks.Test
|
|||
{
|
||||
SampleCount prevSampleCount = currentSampleCount;
|
||||
|
||||
if (Inputs.Keyboard.IsPressed(Input.KeyCode.A))
|
||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
|
||||
{
|
||||
currentSampleCount -= 1;
|
||||
if (currentSampleCount < 0)
|
||||
|
@ -102,7 +102,7 @@ namespace MoonWorks.Test
|
|||
currentSampleCount = SampleCount.Eight;
|
||||
}
|
||||
}
|
||||
if (Inputs.Keyboard.IsPressed(Input.KeyCode.D))
|
||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
|
||||
{
|
||||
currentSampleCount += 1;
|
||||
if (currentSampleCount > SampleCount.Eight)
|
||||
|
|
|
@ -55,5 +55,44 @@ namespace MoonWorks.Test
|
|||
{
|
||||
return SDL2.SDL.SDL_GetBasePath() + "Content/Textures/" + textureName;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
public static bool CheckButtonPressed(Input.Inputs inputs, ButtonType buttonType)
|
||||
{
|
||||
bool pressed = false;
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
return pressed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace MoonWorks.Test
|
|||
|
||||
public TexturedQuadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||
{
|
||||
Logger.LogInfo("Press A and D to cycle between sampler states");
|
||||
Logger.LogInfo("Press Left and Right to cycle between sampler states");
|
||||
Logger.LogInfo("Setting sampler state to: " + samplerNames[0]);
|
||||
|
||||
// Load the shaders
|
||||
|
@ -86,7 +86,7 @@ namespace MoonWorks.Test
|
|||
{
|
||||
int prevSamplerIndex = currentSamplerIndex;
|
||||
|
||||
if (Inputs.Keyboard.IsPressed(Input.KeyCode.A))
|
||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
|
||||
{
|
||||
currentSamplerIndex -= 1;
|
||||
if (currentSamplerIndex < 0)
|
||||
|
@ -95,7 +95,7 @@ namespace MoonWorks.Test
|
|||
}
|
||||
}
|
||||
|
||||
if (Inputs.Keyboard.IsPressed(Input.KeyCode.D))
|
||||
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
|
||||
{
|
||||
currentSamplerIndex += 1;
|
||||
if (currentSamplerIndex >= samplers.Length)
|
||||
|
|
Loading…
Reference in New Issue