Fix gamepad removal not working properly
This commit is contained in:
@ -69,10 +69,21 @@ public class GamePad
|
||||
|
||||
private var _btns = [UInt8](repeating: 0, count: Int(SDL_CONTROLLER_BUTTON_MAX.rawValue))
|
||||
private var _axes = [Int16](repeating: 0, count: Int(SDL_CONTROLLER_AXIS_MAX.rawValue))
|
||||
private var _sdlPad: OpaquePointer
|
||||
private var _joyID: SDL_JoystickID, _sdlPad: OpaquePointer
|
||||
|
||||
internal init(pad: OpaquePointer)
|
||||
internal var instanceID: SDL_JoystickID { _joyID }
|
||||
public var name: String { String(cString: SDL_GameControllerName(_sdlPad)) }
|
||||
|
||||
internal static func open(device: Int32) -> GamePad?
|
||||
{
|
||||
guard let sdlPad = SDL_GameControllerOpen(device) else { return nil }
|
||||
let joyID = SDL_JoystickGetDeviceInstanceID(device)
|
||||
return GamePad(instance: joyID, pad: sdlPad)
|
||||
}
|
||||
|
||||
private init(instance: SDL_JoystickID, pad: OpaquePointer)
|
||||
{
|
||||
self._joyID = instance
|
||||
self._sdlPad = pad
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user