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

标签 c linux sdl joystick gamepad

我有一个便宜的 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/

相关文章:

c - 测试大尾数法或小尾数法的这段代码是如何工作的?

c - Windows 控制台下的 Stdin 和 EOF 行为

c - 动态左移或右移

linux - 在 Linux 上后台运行嵌入式 Jetty 服务器

C++ SDL 运动播放器 "duplication"?

android - 是否有使用C/C++和SDL对Android进行编程的入门指南?

c - 在 for 循环中使用 scanf

linux - 为什么这些 sudo 命令会失败?

c - fork之后,全局变量是共享的吗?

c++ - 如何使用 g++ 编译和链接库 (SDL) 以便我拥有独立程序?