Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions sources/engine/Stride.Input/GamePadLayouts/GamePadLayout8BitDo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace Stride.Input;

public class GamePadLayout8BitDo : GamePadLayout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not meant to be derived, better seal the class.

{
private static readonly ushort _vendorId = 0x2DC8;

public GamePadLayout8BitDo()
{
AddButtonToButton(7, GamePadButton.Start);
AddButtonToButton(6, GamePadButton.Back);
AddButtonToButton(8, GamePadButton.LeftThumb);
AddButtonToButton(9, GamePadButton.RightThumb);
AddButtonToButton(4, GamePadButton.LeftShoulder);
AddButtonToButton(5, GamePadButton.RightShoulder);
AddButtonToButton(0, GamePadButton.A);
AddButtonToButton(1, GamePadButton.B);
AddButtonToButton(2, GamePadButton.X);
AddButtonToButton(3, GamePadButton.Y);
AddAxisToAxis(0, GamePadAxis.LeftThumbX);
AddAxisToAxis(1, GamePadAxis.LeftThumbY, true);
AddAxisToAxis(3, GamePadAxis.RightThumbX);
AddAxisToAxis(4, GamePadAxis.RightThumbY, true);
AddAxisToAxis(2, GamePadAxis.LeftTrigger, remap: true);
AddAxisToAxis(5, GamePadAxis.RightTrigger, remap: true);
}

public override bool MatchDevice(IInputSource source, IGameControllerDevice device)
{
byte[] guidBytes = device.ProductId.ToByteArray();

ushort vendorId = BitConverter.ToUInt16(guidBytes, 4);

return vendorId == _vendorId;
Comment on lines +31 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to do a non-alloc comparison? Maybe with a Span<byte> or a similar API.

}
}
5 changes: 4 additions & 1 deletion sources/engine/Stride.Input/GamePadLayouts/GamePadLayouts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ static GamePadLayouts()

// Support for DualShock4 controllers
AddLayout(new GamePadLayoutDS4());

// Support for 8BitDo controllers
AddLayout(new GamePadLayout8BitDo());
}

/// <summary>
Expand Down Expand Up @@ -55,4 +58,4 @@ public static GamePadLayout FindLayout(IInputSource source, IGameControllerDevic
}
}
}
}
}