gpt4 book ai didi

c - Linux 上的 SDL 是否支持多个游戏 handle /操纵杆?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:16:20 28 4
gpt4 key购买 nike

我有一个便宜的 PS3 Controller 和一个 NEO-GEO X Controller 。它们都在例如上检测到。 Fedora 20 和 Lubuntu 14.04。它们出现在 lsusb 中

Bus 001 Device 012: ID 0e8f:0003 GreenAsia Inc. MaxFire Blaze2
Bus 001 Device 016: ID 1292:4e47 Innomedia

设备显示在 /dev/input 下。在它们上运行 udevadm 显示 GreenAsia 设备使用 pantherlord 驱动程序,而另一个设备使用 hid-generic

如果我运行以下测试代码,SDL 只会报告 GreenAsia 设备。如果我拔下它然后检测到其他设备。这是 SDL 的已知限制还是其他问题?

// from http://www.libsdl.org/release/SDL-1.2.15/docs/html/guideinput.html
#include "SDL/SDL.h"

int main () {
if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0)
{
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
printf("%i joysticks were found.\n\n", SDL_NumJoysticks() );
printf("The names of the joysticks are:\n");

for( int i=0; i < SDL_NumJoysticks(); i++ )
{
printf(" %s\n", SDL_JoystickName(i));
}
return 0;
}

最佳答案

如果只有一个操纵杆映射到设备 /dev/input/event13 或类似设备,我的问题的答案似乎是“否”,这就是我的 PS3 Controller 在我的案例。

SDL_SYS_JoystickInit中有如下代码

#if SDL_INPUT_LINUXEV
/* This is a special case...
If the event devices are valid then the joystick devices
will be duplicates but without extra information about their
hats or balls. Unfortunately, the event devices can't
currently be calibrated, so it's a win-lose situation.
So : /dev/input/eventX = /dev/input/jsY = /dev/jsY
*/
if ( (i == 0) && (numjoysticks > 0) )
break;
#endif

i 为 0 时,它正在寻找“事件”设备。我的 PS3 Controller 获得设备 /dev/input/event13/dev/input/js1,但我的 NEO-GEO X Controller 只有设备 /dev/input/js0,所以跳出循环会导致它被忽略。

这种情况下的解决方法是将没有相应“事件”设备的设备添加到 SDL_JOYSTICK_DEVICE

感谢 Brian McFarland 帮助查明此事。

关于c - Linux 上的 SDL 是否支持多个游戏 handle /操纵杆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29589982/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com