Skip to content

Commit

Permalink
Fix FromSteerValue
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBang1112 committed Jun 30, 2024
1 parent 95068db commit c144d20
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Src/GBX.NET/Inputs/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ internal static class Input
_ => 0
};

// using knowledge from https://github.com/stefan-baumann/ManiaPlanetSharp/issues/15#issuecomment-761836833

private static int ToSteerValue(this uint data)
{
var dir = (data >> 16) & 0xFF;
Expand All @@ -55,24 +57,24 @@ private static int ToSteerValue(this uint data)
return dir switch
{
0xFF => ushort.MaxValue + 1 - val,
1 => -ushort.MaxValue - 1,
_ => val * -1 * (int)(dir + 1)
1 => -ushort.MaxValue - 1, // the steer is full left (steer is 0 in this case)
_ => -val * (int)(dir + 1)
};
}

private static uint FromSteerValue(this int value)
private static uint FromSteerValue(this int steerValue)
{
if (value > 0)
if (steerValue == -ushort.MaxValue - 1)
{
return (uint)(0xFF0000 | (ushort.MaxValue + 1 - value));
return 0x010000;
}

if (value < 0)
if (steerValue > 0)
{
return (uint)(0x010000 | (value & 0xFFFF));
return (uint)((0xFF << 16) | (ushort.MaxValue + 1 - steerValue));
}

return 0;
return (uint)Math.Abs(steerValue);
}

private static uint FromGasValue(this int value)
Expand Down

0 comments on commit c144d20

Please sign in to comment.