2013-08-08 7 views
0

FFI 모듈을 사용하여 NodeJS에서 SDL2 라이브러리의 조이스틱 클래스를 사용하기 위해 객체를 작성하려고했지만 문제가 계속 발생했습니다. 대략 50 % 정도는 예상대로 작동하지만 다른 시간에는 프로그램이 연결된 조이스틱을 찾을 수 없다고 주장합니다 (SDL_GetError() 사용).노드 FFI를 사용하여 SDL2 조이스틱 바인딩을 생성 할 때의 문제점

"Joystick hasn't been opened yet" 

어떤 아이디어 :

// Constructor... 
function Joystick(deviceId){  
    this.joystickPointer = ref.refType('pointer'); 

    this.SDL = ffi.Library("SDL2.dll", {  
    "SDL_Init": ["Uint32", ["string"]], 
    "SDL_Quit": ["void", []], 
    "SDL_JoystickOpen": ["pointer", ["int"]], 
    "SDL_NumJoysticks": ["int", []], 
    "SDL_JoystickName": ["string", [this.joystickPointer]], 
    "SDL_JoystickNumButtons": ["int", [this.joystickPointer]], 
    "SDL_JoystickGetButton": ["Uint8", [this.joystickPointer, "int"]], 
    "SDL_JoystickNumAxes": ["int", [this.joystickPointer]], 
    "SDL_JoystickGetAxis": ["int16", [this.joystickPointer, "int"]], 
    "SDL_JoystickGetAttached": ["bool", [this.joystickPointer]], 
    "SDL_JoystickClose": ["void", [this.joystickPointer]], 
    "SDL_JoystickUpdate": ["void", []], 
    "SDL_GetError": ["string", []] 
    }); 

     // Setup 
    this.deviceId = deviceId || 0; 
    this.SDL.SDL_Init("SDL_INIT_JOYSTICK"); 
    this.joystickObject = this.SDL.SDL_JoystickOpen(this.deviceId); 

     // Poll Joystick 
     this.deviceCount = this.SDL.SDL_NumJoysticks(); 
    this.buttons = this.SDL.SDL_JoystickNumButtons(this.joystickObject); 
    this.name = this.SDL.SDL_JoystickName(this.joystickObject); 

     // Cleanup 
     this.SDL.SDL_JoystickClose(this.joystickObject); 
     this.SDL.SDL_Quit();  

    return false; 
} 

var testJoystick = new Joystick(0); 
console.log(testJoystick.name); 

이 나에게 다음과 같은 오류 메시지를 제공, SDL_GetError을() 실패

다음은 코드의 샘플입니까?

답변

0

예상 한대로 작동하도록 위의 코드에 너무 많은 문제가 있다고 의심됩니다. 결국 다른 솔루션을 생각해 냈습니다.

정적 인 낮은 수준의 입력 라이브러리 인 http://forums.tigsource.com/index.php?topic=10675.0을 발견했습니다. 그 위에 뼈대 라이브러리를 작성하고 연결 한 다음 적용했습니다 ...

그것은 잘 작동하고 SDL보다 훨씬 가볍고, 더 많이 ...

내가 시간이 있다면 앞으로 몇 일 이내에 GIT 또는의 Bitbucket에 넣어해야합니다.