Bug 218289 - devel/sdl20: gamecontrollerdb.txt cannot be shared among FreeBSD systems
Summary: devel/sdl20: gamecontrollerdb.txt cannot be shared among FreeBSD systems
Status: Closed DUPLICATE of bug 252371
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Dmitry Marakasov
URL:
Keywords: needs-patch
Depends on:
Blocks:
 
Reported: 2017-04-01 11:37 UTC by Jan Beich
Modified: 2021-01-23 14:10 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2017-04-01 11:37:19 UTC
devel/sdl20 provides GameController API[1]. Some games and game system
emulators[2] can take advantage of a shared database[3] that maps buttons on
various joysticks/gamepads to Xbox 360 layout in order to provide sane
default bindings. The API relies on OS exposing a way to uniquely identify
devices. On FreeBSD SDL implements GUIDs as a stub[4] based on cdev index
and HID usage name. What this means is that users cannot share controller
mappings. For example, games/openmw adds the following:

  30783030303520283029000000000000,X360 Controller,platform:FreeBSD,x:b13,a:b11,b:b12,y:b14,back:b5,guide:b4,guide:b10,start:b4,dpleft:b2,dpdown:b1,dpright:b3,dpup:b0,leftshoulder:b8,lefttrigger:b9,lefttrigger:a2,rightshoulder:b9,righttrigger:a5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,

but I have a different joystick with the same GUID

  30783030303520283029000000000000,Thrustmaster Dual Analog 3.2,platform:FreeBSD,a:b0,b:b2,x:b1,y:b3,back:b8,start:b9,leftshoulder:b4,rightshoulder:b6,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b5,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,

Not to mention the first SDL_JoystickOpen() call mutates GUID, so it's very
confusing when mapping buttons via x11/antimicro or x11/controllermap.

  $ testgamecontroller
  SDL_SYS_JoystickGetDeviceGUID: using "0x0005 (0)" as GUID
  INFO: Controller 0: Thrustmaster dual analog 3.2 (guid 30783030303520283029000000000000)
  INFO: There are 1 game controller(s) attached (1 joystick(s))

  $ testjoystick
  INFO: There are 1 joysticks attached
  INFO: Joystick 0: 0x0005 (0)
  SDL_SYS_JoystickGetGUID: using "Game_Pad (0)" as GUID
  INFO:        axes: 4
  INFO:       balls: 0
  INFO:        hats: 1
  INFO:     buttons: 12
  INFO: instance id: 0
  INFO:        guid: 47616d655f5061642028302900000000

Ideally, the fix is to match Linux behavior in order to reuse the existing
controller database. As neither evdev(4) in kernel nor webcamd currently
support HID devices we have to adjust usbhid(3) backend to query
USB_GET_DEVICE_DESC directly (or via libusb) then copy BUS_USB, IdVendor,
idProduct, bcdDevice or iProduct string into GUID[5]. Both
SDL_JoystickGetDeviceGUID and SDL_JoystickGetGUID have to return the same
values for the same joysticks.

  $ usbconfig -d ugen0.2 dump_device_desc
  ugen0.2: <Mega World Thrustmaster dual analog 3.2> at usbus0, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON(350mA)

    bLength = 0x0012
    bDescriptorType = 0x0001
    bcdUSB = 0x0110
    bDeviceClass = 0x0000  <Probed by interface class>
    bDeviceSubClass = 0x0000
    bDeviceProtocol = 0x0000
    bMaxPacketSize0 = 0x0008
    idVendor = 0x044f
    idProduct = 0xb315
    bcdDevice = 0x0101
    iManufacturer = 0x0001  <Mega World>
    iProduct = 0x0002  <Thrustmaster dual analog 3.2>
    iSerialNumber = 0x0000  <no string>
    bNumConfigurations = 0x0001

[1] http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-December/086663.html
[2] devel/love, devel/renpy, emulators/ppsspp, emulators/yape (not until 0.70.1),
    games/ioquake3-devel, games/openmw, games/supertux2, games/retroarch,
    libgosu, MonoGame, Unreal Engine 4, BlockAttack, CaveExpress, RBDOOM-3-bfg,
    refkeen, SDLPoP, etc. Commercial games are mostly for linuxulator + evdev:
    https://www.reddit.com/r/linux_gaming/comments/4mk48m/list_of_games_with_controller_support/
[3] https://github.com/gabomdq/SDL_GameControllerDB
[4] https://hg.libsdl.org/SDL/file/release-2.0.5/src/joystick/bsd/SDL_sysjoystick.c#l623
[5] https://hg.libsdl.org/SDL/file/release-2.0.5/src/joystick/linux/SDL_sysjoystick.c#l118
    http://lxr.free-electrons.com/source/include/linux/usb/input.h#L17
Comment 1 commit-hook freebsd_committer freebsd_triage 2017-07-26 23:04:43 UTC
A commit references this bug:

Author: tobik
Date: Wed Jul 26 23:03:58 UTC 2017
New revision: 446702
URL: https://svnweb.freebsd.org/changeset/ports/446702

Log:
  games/openmw: Update to 0.42.0

  - Drop the gamecontrollerdb.txt patch since controller mappings cannot
    be shared reliably between FreeBSD systems [1]
  - Drop patch for inverting the joystick Y-axis based on the invert
    mouse setting

  Changes:	https://github.com/OpenMW/openmw/releases/tag/openmw-0.42.0
  PR:		218289 [1]

Changes:
  head/games/openmw/Makefile
  head/games/openmw/distinfo
  head/games/openmw/files/patch-apps_openmw_mwinput_inputmanagerimp.cpp
  head/games/openmw/files/patch-files_gamecontrollerdb.txt
Comment 2 Walter Schwarzenfeld freebsd_triage 2018-02-16 13:45:07 UTC
Is this fixed? Could it be closed?
Comment 3 Jan Beich freebsd_committer freebsd_triage 2018-03-05 14:00:09 UTC
No joy even with SDL 2.0.8.

emulators/ppsspp has a workaround since ports r452123 but not all buttons work[1] unlike when using SDL_GAMECONTROLLERCONFIG environment variable or OLDJOY port option.

games/sdlpop only supports joystick if SDL_GAMECONTROLLERCONFIG is set.

[1] on my gamepad Left Trigger and Right Shoulder are both recognized as b5, Right Trigger and Right Thumbstick are both recognized as ThumbL
Comment 4 Jan Beich freebsd_committer freebsd_triage 2018-03-05 14:40:00 UTC
Nevermind games/sdlpop. SDL_Joystick is restored on master branch, SDL_GameControllerAddMappingsFromFile isn't used and there's no default registry of mappings to replace gamecontrollerdb.txt.
Comment 5 Jan Beich freebsd_committer freebsd_triage 2021-01-23 14:10:46 UTC
GUIDs from hgame(4) on FreeBSD >= 13.0 or from sysutils/iichid are same as on Linux. Individual ports that install gamecontrollerdb.txt need to patch s/Linux/FreeBSD/ but otherwise default configs come from src/joystick/SDL_gamecontrollerdb.h.

Obsolete after devel/sdl20 enables evdev-based joystick support.

*** This bug has been marked as a duplicate of bug 252371 ***