mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-22 19:06:15 +08:00
fix(input): map POSIX stick endpoints exactly (#244)
This commit is contained in:
@@ -253,9 +253,9 @@ public static class HostWindowInput
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte ToStickByte(float value)
|
internal static byte ToStickByte(float value)
|
||||||
{
|
{
|
||||||
return (byte)Math.Clamp((int)(128.0f + value * 127.0f), 0, 255);
|
return (byte)Math.Clamp((int)MathF.Round((value + 1.0f) * 127.5f), 0, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HostGamepadButtons MapButton(ButtonName name) => name switch
|
private static HostGamepadButtons MapButton(ButtonName name) => name switch
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2026 SharpEmu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
using SharpEmu.Libs.Pad;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace SharpEmu.Libs.Tests.Pad;
|
||||||
|
|
||||||
|
public sealed class HostWindowInputTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData(-1.0f, 0)]
|
||||||
|
[InlineData(0.0f, 128)]
|
||||||
|
[InlineData(1.0f, 255)]
|
||||||
|
public void ToStickByteMapsFullSilkRange(float value, int expected)
|
||||||
|
{
|
||||||
|
Assert.Equal((byte)expected, HostWindowInput.ToStickByte(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user