mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-21 09:21:25 +02:00
Update to v094r21 release.
byuu says: This updates ruby to return shared_pointer<HID::Device> objects instead of HID::Device* objects. It also fixes an ID bug where joypads were starting at ID# 2+, but mice were also set to ID# 2. I also revised nall/hid a lot, with getters and setters instead of stabbing at internal state. I didn't yet patch nall::string to safely consume nullptr const char* values, though.
This commit is contained in:
@@ -130,21 +130,21 @@ using namespace nall;
|
||||
|
||||
#define DeclareInput(Name) \
|
||||
struct Input##Name : Input { \
|
||||
bool cap(const string& name) { return p.cap(name); } \
|
||||
any get(const string& name) { return p.get(name); } \
|
||||
bool set(const string& name, const any& value) { return p.set(name, value); } \
|
||||
\
|
||||
bool acquire() { return p.acquire(); } \
|
||||
bool unacquire() { return p.unacquire(); } \
|
||||
bool acquired() { return p.acquired(); } \
|
||||
\
|
||||
vector<HID::Device*> poll() { return p.poll(); } \
|
||||
bool rumble(uint64_t id, bool enable) { return p.rumble(id, enable); } \
|
||||
bool init() { return p.init(); } \
|
||||
void term() { p.term(); } \
|
||||
\
|
||||
Input##Name() : p(*new pInput##Name) {} \
|
||||
~Input##Name() { delete &p; } \
|
||||
\
|
||||
auto cap(const string& name) -> bool { return p.cap(name); } \
|
||||
auto get(const string& name) -> any { return p.get(name); } \
|
||||
auto set(const string& name, const any& value) -> bool { return p.set(name, value); } \
|
||||
\
|
||||
auto acquire() -> bool { return p.acquire(); } \
|
||||
auto unacquire() -> bool { return p.unacquire(); } \
|
||||
auto acquired() -> bool { return p.acquired(); } \
|
||||
\
|
||||
auto poll() -> vector<shared_pointer<HID::Device>> { return p.poll(); } \
|
||||
auto rumble(uint64_t id, bool enable) -> bool { return p.rumble(id, enable); } \
|
||||
auto init() -> bool { return p.init(); } \
|
||||
auto term() -> void { p.term(); } \
|
||||
\
|
||||
private: \
|
||||
pInput##Name& p; \
|
||||
|
@@ -1,23 +1,23 @@
|
||||
struct Input {
|
||||
static const char* Handle;
|
||||
static const char* KeyboardSupport;
|
||||
static const char* MouseSupport;
|
||||
static const char* JoypadSupport;
|
||||
static const char* JoypadRumbleSupport;
|
||||
static const nall::string Handle;
|
||||
static const nall::string KeyboardSupport;
|
||||
static const nall::string MouseSupport;
|
||||
static const nall::string JoypadSupport;
|
||||
static const nall::string JoypadRumbleSupport;
|
||||
|
||||
virtual bool cap(const nall::string& name) { return false; }
|
||||
virtual nall::any get(const nall::string& name) { return false; }
|
||||
virtual bool set(const nall::string& name, const nall::any& value) { return false; }
|
||||
Input() = default;
|
||||
virtual ~Input() = default;
|
||||
|
||||
virtual bool acquire() { return false; }
|
||||
virtual bool unacquire() { return false; }
|
||||
virtual bool acquired() { return false; }
|
||||
virtual auto cap(const nall::string& name) -> bool { return false; }
|
||||
virtual auto get(const nall::string& name) -> nall::any { return false; }
|
||||
virtual auto set(const nall::string& name, const nall::any& value) -> bool { return false; }
|
||||
|
||||
virtual nall::vector<nall::HID::Device*> poll() { return {}; }
|
||||
virtual bool rumble(uint64_t id, bool enable) { return false; }
|
||||
virtual bool init() { return true; }
|
||||
virtual void term() {}
|
||||
virtual auto acquire() -> bool { return false; }
|
||||
virtual auto unacquire() -> bool { return false; }
|
||||
virtual auto acquired() -> bool { return false; }
|
||||
|
||||
Input() {}
|
||||
virtual ~Input() {}
|
||||
virtual auto poll() -> nall::vector<nall::shared_pointer<nall::HID::Device>> { return {}; }
|
||||
virtual auto rumble(uint64_t id, bool enable) -> bool { return false; }
|
||||
virtual auto init() -> bool { return true; }
|
||||
virtual auto term() -> void {}
|
||||
};
|
||||
|
@@ -5,48 +5,47 @@ namespace ruby {
|
||||
|
||||
struct InputJoypadSDL {
|
||||
struct Joypad {
|
||||
HID::Joypad hid;
|
||||
shared_pointer<HID::Joypad> hid{new HID::Joypad};
|
||||
|
||||
unsigned id = 0;
|
||||
SDL_Joystick* handle = nullptr;
|
||||
};
|
||||
vector<Joypad> joypads;
|
||||
|
||||
void assign(HID::Joypad& hid, unsigned groupID, unsigned inputID, int16_t value) {
|
||||
auto& group = hid.group[groupID];
|
||||
if(group.input[inputID].value == value) return;
|
||||
if(input.onChange) input.onChange(hid, groupID, inputID, group.input[inputID].value, value);
|
||||
group.input[inputID].value = value;
|
||||
auto assign(shared_pointer<HID::Joypad> hid, unsigned groupID, unsigned inputID, int16_t value) -> void {
|
||||
auto& group = hid->group(groupID);
|
||||
if(group.input(inputID).value() == value) return;
|
||||
if(input.onChange) input.onChange(hid, groupID, inputID, group.input(inputID).value(), value);
|
||||
group.input(inputID).setValue(value);
|
||||
}
|
||||
|
||||
void poll(vector<HID::Device*>& devices) {
|
||||
auto poll(vector<shared_pointer<HID::Device>>& devices) -> void {
|
||||
SDL_JoystickUpdate();
|
||||
|
||||
for(auto& jp : joypads) {
|
||||
for(unsigned n = 0; n < jp.hid.axis().input.size(); n++) {
|
||||
for(auto n : range(jp.hid->axes())) {
|
||||
assign(jp.hid, HID::Joypad::GroupID::Axis, n, (int16_t)SDL_JoystickGetAxis(jp.handle, n));
|
||||
}
|
||||
|
||||
for(signed n = 0; n < (signed)jp.hid.hat().input.size() - 1; n += 2) {
|
||||
for(signed n = 0; n < (signed)jp.hid->hats().size() - 1; n += 2) {
|
||||
uint8_t state = SDL_JoystickGetHat(jp.handle, n >> 1);
|
||||
assign(jp.hid, HID::Joypad::GroupID::Hat, n + 0, state & SDL_HAT_LEFT ? -32768 : state & SDL_HAT_RIGHT ? +32767 : 0);
|
||||
assign(jp.hid, HID::Joypad::GroupID::Hat, n + 1, state & SDL_HAT_UP ? -32768 : state & SDL_HAT_DOWN ? +32767 : 0);
|
||||
}
|
||||
|
||||
for(unsigned n = 0; n < jp.hid.button().input.size(); n++) {
|
||||
for(auto n : range(jp.hid->buttons())) {
|
||||
assign(jp.hid, HID::Joypad::GroupID::Button, n, (bool)SDL_JoystickGetButton(jp.handle, n));
|
||||
}
|
||||
|
||||
devices.append(&jp.hid);
|
||||
devices.append(jp.hid);
|
||||
}
|
||||
}
|
||||
|
||||
bool init() {
|
||||
auto init() -> bool {
|
||||
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
|
||||
SDL_JoystickEventState(SDL_IGNORE);
|
||||
|
||||
unsigned joypadCount = SDL_NumJoysticks();
|
||||
for(unsigned id = 0; id < joypadCount; id++) {
|
||||
for(auto id : range(SDL_NumJoysticks())) {
|
||||
Joypad jp;
|
||||
jp.id = id;
|
||||
jp.handle = SDL_JoystickOpen(id);
|
||||
@@ -55,11 +54,11 @@ struct InputJoypadSDL {
|
||||
unsigned hats = SDL_JoystickNumHats(jp.handle) * 2;
|
||||
unsigned buttons = 32; //there is no SDL_JoystickNumButtons()
|
||||
|
||||
jp.hid.id = 2 + jp.id;
|
||||
for(unsigned n = 0; n < axes; n++) jp.hid.axis().append({n});
|
||||
for(unsigned n = 0; n < hats; n++) jp.hid.hat().append({n});
|
||||
for(unsigned n = 0; n < buttons; n++) jp.hid.button().append({n});
|
||||
jp.hid.rumble = false;
|
||||
jp.hid->setID(3 + jp.id);
|
||||
for(auto n : range(axes)) jp.hid->axes().append(n);
|
||||
for(auto n : range(hats)) jp.hid->hats().append(n);
|
||||
for(auto n : range(buttons)) jp.hid->buttons().append(n);
|
||||
jp.hid->setRumble(false);
|
||||
|
||||
joypads.append(jp);
|
||||
}
|
||||
@@ -67,7 +66,7 @@ struct InputJoypadSDL {
|
||||
return true;
|
||||
}
|
||||
|
||||
void term() {
|
||||
auto term() -> void {
|
||||
for(auto& jp : joypads) {
|
||||
SDL_JoystickClose(jp.handle);
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@
|
||||
namespace ruby {
|
||||
|
||||
struct InputKeyboardXlib {
|
||||
HID::Keyboard hid;
|
||||
shared_pointer<HID::Keyboard> hid{new HID::Keyboard};
|
||||
|
||||
Display* display = nullptr;
|
||||
|
||||
@@ -15,14 +15,14 @@ struct InputKeyboardXlib {
|
||||
};
|
||||
vector<Key> keys;
|
||||
|
||||
void assign(unsigned inputID, bool value) {
|
||||
auto& group = hid.group[HID::Keyboard::GroupID::Button];
|
||||
if(group.input[inputID].value == value) return;
|
||||
if(input.onChange) input.onChange(hid, HID::Keyboard::GroupID::Button, inputID, group.input[inputID].value, value);
|
||||
group.input[inputID].value = value;
|
||||
auto assign(unsigned inputID, bool value) -> void {
|
||||
auto& group = hid->buttons();
|
||||
if(group.input(inputID).value() == value) return;
|
||||
if(input.onChange) input.onChange(hid, HID::Keyboard::GroupID::Button, inputID, group.input(inputID).value(), value);
|
||||
group.input(inputID).setValue(value);
|
||||
}
|
||||
|
||||
void poll(vector<HID::Device*>& devices) {
|
||||
auto poll(vector<shared_pointer<HID::Device>>& devices) -> void {
|
||||
char state[32];
|
||||
XQueryKeymap(display, state);
|
||||
|
||||
@@ -31,10 +31,10 @@ struct InputKeyboardXlib {
|
||||
assign(n, value);
|
||||
}
|
||||
|
||||
devices.append(&hid);
|
||||
devices.append(hid);
|
||||
}
|
||||
|
||||
bool init() {
|
||||
auto init() -> bool {
|
||||
display = XOpenDisplay(0);
|
||||
|
||||
keys.append({"Escape", XK_Escape});
|
||||
@@ -151,17 +151,17 @@ struct InputKeyboardXlib {
|
||||
keys.append({"RightSuper", XK_Super_R});
|
||||
keys.append({"Menu", XK_Menu});
|
||||
|
||||
hid.id = 1;
|
||||
hid->setID(1);
|
||||
|
||||
for(unsigned n = 0; n < keys.size(); n++) {
|
||||
hid.button().append(keys[n].name);
|
||||
hid->buttons().append(keys[n].name);
|
||||
keys[n].keycode = XKeysymToKeycode(display, keys[n].keysym);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void term() {
|
||||
auto term() -> void {
|
||||
if(display) {
|
||||
XCloseDisplay(display);
|
||||
display = nullptr;
|
||||
|
@@ -4,7 +4,7 @@
|
||||
namespace ruby {
|
||||
|
||||
struct InputMouseXlib {
|
||||
HID::Mouse hid;
|
||||
shared_pointer<HID::Mouse> hid{new HID::Mouse};
|
||||
|
||||
uintptr_t handle = 0;
|
||||
|
||||
@@ -23,7 +23,7 @@ struct InputMouseXlib {
|
||||
unsigned relativeY = 0;
|
||||
} ms;
|
||||
|
||||
bool acquire() {
|
||||
auto acquire() -> bool {
|
||||
if(acquired()) return true;
|
||||
|
||||
if(XGrabPointer(display, handle, True, 0, GrabModeAsync, GrabModeAsync, rootWindow, invisibleCursor, CurrentTime) == GrabSuccess) {
|
||||
@@ -42,7 +42,7 @@ struct InputMouseXlib {
|
||||
}
|
||||
}
|
||||
|
||||
bool unacquire() {
|
||||
auto unacquire() -> bool {
|
||||
if(acquired()) {
|
||||
//restore cursor acceleration and release cursor
|
||||
XChangePointerControl(display, True, True, ms.numerator, ms.denominator, ms.threshold);
|
||||
@@ -52,18 +52,18 @@ struct InputMouseXlib {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool acquired() {
|
||||
auto acquired() -> bool {
|
||||
return ms.acquired;
|
||||
}
|
||||
|
||||
void assign(unsigned groupID, unsigned inputID, int16_t value) {
|
||||
auto& group = hid.group[groupID];
|
||||
if(group.input[inputID].value == value) return;
|
||||
if(input.onChange) input.onChange(hid, groupID, inputID, group.input[inputID].value, value);
|
||||
group.input[inputID].value = value;
|
||||
auto assign(unsigned groupID, unsigned inputID, int16_t value) -> void {
|
||||
auto& group = hid->group(groupID);
|
||||
if(group.input(inputID).value() == value) return;
|
||||
if(input.onChange) input.onChange(hid, groupID, inputID, group.input(inputID).value(), value);
|
||||
group.input(inputID).setValue(value);
|
||||
}
|
||||
|
||||
void poll(vector<HID::Device*>& devices) {
|
||||
auto poll(vector<shared_pointer<HID::Device>>& devices) -> void {
|
||||
Window rootReturn;
|
||||
Window childReturn;
|
||||
signed rootXReturn = 0;
|
||||
@@ -81,7 +81,7 @@ struct InputMouseXlib {
|
||||
assign(HID::Mouse::GroupID::Axis, 0, (int16_t)(rootXReturn - screenWidth / 2));
|
||||
assign(HID::Mouse::GroupID::Axis, 1, (int16_t)(rootYReturn - screenHeight / 2));
|
||||
|
||||
if(hid.axis().input[0].value != 0 || hid.axis().input[1].value != 0) {
|
||||
if(hid->axes().input(0).value() != 0 || hid->axes().input(1).value() != 0) {
|
||||
//if mouse moved, re-center mouse for next poll
|
||||
XWarpPointer(display, None, rootWindow, 0, 0, 0, 0, screenWidth / 2, screenHeight / 2);
|
||||
}
|
||||
@@ -99,10 +99,10 @@ struct InputMouseXlib {
|
||||
assign(HID::Mouse::GroupID::Button, 3, (bool)(maskReturn & Button4Mask));
|
||||
assign(HID::Mouse::GroupID::Button, 4, (bool)(maskReturn & Button5Mask));
|
||||
|
||||
devices.append(&hid);
|
||||
devices.append(hid);
|
||||
}
|
||||
|
||||
bool init(uintptr_t handle) {
|
||||
auto init(uintptr_t handle) -> bool {
|
||||
this->handle = handle;
|
||||
display = XOpenDisplay(0);
|
||||
rootWindow = DefaultRootWindow(display);
|
||||
@@ -128,21 +128,21 @@ struct InputMouseXlib {
|
||||
ms.relativeX = 0;
|
||||
ms.relativeY = 0;
|
||||
|
||||
hid.id = 2;
|
||||
hid->setID(2);
|
||||
|
||||
hid.axis().append({"X"});
|
||||
hid.axis().append({"Y"});
|
||||
hid->axes().append("X");
|
||||
hid->axes().append("Y");
|
||||
|
||||
hid.button().append({"Left"});
|
||||
hid.button().append({"Middle"});
|
||||
hid.button().append({"Right"});
|
||||
hid.button().append({"Up"});
|
||||
hid.button().append({"Down"});
|
||||
hid->buttons().append("Left");
|
||||
hid->buttons().append("Middle");
|
||||
hid->buttons().append("Right");
|
||||
hid->buttons().append("Up");
|
||||
hid->buttons().append("Down");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void term() {
|
||||
auto term() -> void {
|
||||
unacquire();
|
||||
XFreeCursor(display, invisibleCursor);
|
||||
XCloseDisplay(display);
|
||||
|
@@ -17,7 +17,7 @@ struct pInputSDL {
|
||||
uintptr_t handle = 0;
|
||||
} settings;
|
||||
|
||||
bool cap(const string& name) {
|
||||
auto cap(const string& name) -> bool {
|
||||
if(name == Input::Handle) return true;
|
||||
if(name == Input::KeyboardSupport) return true;
|
||||
if(name == Input::MouseSupport) return true;
|
||||
@@ -25,12 +25,12 @@ struct pInputSDL {
|
||||
return false;
|
||||
}
|
||||
|
||||
any get(const string& name) {
|
||||
auto get(const string& name) -> any {
|
||||
if(name == Input::Handle) return (uintptr_t)settings.handle;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set(const string& name, const any &value) {
|
||||
auto set(const string& name, const any& value) -> bool {
|
||||
if(name == Input::Handle) {
|
||||
settings.handle = any_cast<uintptr_t>(value);
|
||||
return true;
|
||||
@@ -39,38 +39,38 @@ struct pInputSDL {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool acquire() {
|
||||
auto acquire() -> bool {
|
||||
return xlibMouse.acquire();
|
||||
}
|
||||
|
||||
bool unacquire() {
|
||||
auto unacquire() -> bool {
|
||||
return xlibMouse.unacquire();
|
||||
}
|
||||
|
||||
bool acquired() {
|
||||
auto acquired() -> bool {
|
||||
return xlibMouse.acquired();
|
||||
}
|
||||
|
||||
vector<HID::Device*> poll() {
|
||||
vector<HID::Device*> devices;
|
||||
auto poll() -> vector<shared_pointer<HID::Device>> {
|
||||
vector<shared_pointer<HID::Device>> devices;
|
||||
xlibKeyboard.poll(devices);
|
||||
xlibMouse.poll(devices);
|
||||
sdl.poll(devices);
|
||||
return devices;
|
||||
}
|
||||
|
||||
bool rumble(uint64_t id, bool enable) {
|
||||
auto rumble(uint64_t id, bool enable) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool init() {
|
||||
if(xlibKeyboard.init() == false) return false;
|
||||
if(xlibMouse.init(settings.handle) == false) return false;
|
||||
if(sdl.init() == false) return false;
|
||||
auto init() -> bool {
|
||||
if(!xlibKeyboard.init()) return false;
|
||||
if(!xlibMouse.init(settings.handle)) return false;
|
||||
if(!sdl.init()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void term() {
|
||||
auto term() -> void {
|
||||
xlibKeyboard.term();
|
||||
xlibMouse.term();
|
||||
sdl.term();
|
||||
|
@@ -17,18 +17,18 @@ struct pInputXlib {
|
||||
uintptr_t handle = 0;
|
||||
} settings;
|
||||
|
||||
bool cap(const string& name) {
|
||||
auto cap(const string& name) -> bool {
|
||||
if(name == Input::KeyboardSupport) return true;
|
||||
if(name == Input::MouseSupport) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
any get(const string& name) {
|
||||
auto get(const string& name) -> any {
|
||||
if(name == Input::Handle) return (uintptr_t)settings.handle;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set(const string& name, const any &value) {
|
||||
auto set(const string& name, const any& value) -> bool {
|
||||
if(name == Input::Handle) {
|
||||
settings.handle = any_cast<uintptr_t>(value);
|
||||
return true;
|
||||
@@ -37,36 +37,36 @@ struct pInputXlib {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool acquire() {
|
||||
auto acquire() -> bool {
|
||||
return xlibMouse.acquire();
|
||||
}
|
||||
|
||||
bool unacquire() {
|
||||
auto unacquire() -> bool {
|
||||
return xlibMouse.unacquire();
|
||||
}
|
||||
|
||||
bool acquired() {
|
||||
auto acquired() -> bool {
|
||||
return xlibMouse.acquired();
|
||||
}
|
||||
|
||||
vector<HID::Device*> poll() {
|
||||
vector<HID::Device*> devices;
|
||||
auto poll() -> vector<shared_pointer<HID::Device>> {
|
||||
vector<shared_pointer<HID::Device>> devices;
|
||||
xlibKeyboard.poll(devices);
|
||||
xlibMouse.poll(devices);
|
||||
return devices;
|
||||
}
|
||||
|
||||
bool rumble(uint64_t id, bool enable) {
|
||||
auto rumble(uint64_t id, bool enable) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool init() {
|
||||
if(xlibKeyboard.init() == false) return false;
|
||||
if(xlibMouse.init(settings.handle) == false) return false;
|
||||
auto init() -> bool {
|
||||
if(!xlibKeyboard.init()) return false;
|
||||
if(!xlibMouse.init(settings.handle)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void term() {
|
||||
auto term() -> void {
|
||||
xlibKeyboard.term();
|
||||
xlibMouse.term();
|
||||
}
|
||||
|
@@ -363,43 +363,43 @@ AudioInterface::~AudioInterface() { term(); }
|
||||
|
||||
/* InputInterface */
|
||||
|
||||
const char* Input::Handle = "Handle";
|
||||
const char* Input::KeyboardSupport = "KeyboardSupport";
|
||||
const char* Input::MouseSupport = "MouseSupport";
|
||||
const char* Input::JoypadSupport = "JoypadSupport";
|
||||
const char* Input::JoypadRumbleSupport = "JoypadRumbleSupport";
|
||||
const string Input::Handle = "Handle";
|
||||
const string Input::KeyboardSupport = "KeyboardSupport";
|
||||
const string Input::MouseSupport = "MouseSupport";
|
||||
const string Input::JoypadSupport = "JoypadSupport";
|
||||
const string Input::JoypadRumbleSupport = "JoypadRumbleSupport";
|
||||
|
||||
void InputInterface::driver(const char* driver) {
|
||||
auto InputInterface::driver(string driver) -> void {
|
||||
if(p) term();
|
||||
|
||||
if(!driver || !*driver) driver = optimalDriver();
|
||||
if(!driver) driver = optimalDriver();
|
||||
|
||||
if(0);
|
||||
|
||||
#ifdef INPUT_WINDOWS
|
||||
else if(!strcmp(driver, "Windows")) p = new InputWindows();
|
||||
else if(driver == "Windows") p = new InputWindows();
|
||||
#endif
|
||||
|
||||
#ifdef INPUT_CARBON
|
||||
else if(!strcmp(driver, "Carbon")) p = new InputCarbon();
|
||||
else if(driver == "Carbon") p = new InputCarbon();
|
||||
#endif
|
||||
|
||||
#ifdef INPUT_UDEV
|
||||
else if(!strcmp(driver, "udev")) p = new InputUdev();
|
||||
else if(driver == "udev") p = new InputUdev();
|
||||
#endif
|
||||
|
||||
#ifdef INPUT_SDL
|
||||
else if(!strcmp(driver, "SDL")) p = new InputSDL();
|
||||
else if(driver == "SDL") p = new InputSDL();
|
||||
#endif
|
||||
|
||||
#ifdef INPUT_XLIB
|
||||
else if(!strcmp(driver, "Xlib")) p = new InputXlib();
|
||||
else if(driver == "Xlib") p = new InputXlib();
|
||||
#endif
|
||||
|
||||
else p = new Input();
|
||||
}
|
||||
|
||||
const char* InputInterface::optimalDriver() {
|
||||
auto InputInterface::optimalDriver() -> string {
|
||||
#if defined(INPUT_WINDOWS)
|
||||
return "Windows";
|
||||
|
||||
@@ -418,7 +418,7 @@ const char* InputInterface::optimalDriver() {
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* InputInterface::safestDriver() {
|
||||
auto InputInterface::safestDriver() -> string {
|
||||
#if defined(INPUT_WINDOWS)
|
||||
return "Windows";
|
||||
|
||||
@@ -437,7 +437,7 @@ const char* InputInterface::safestDriver() {
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* InputInterface::availableDrivers() {
|
||||
auto InputInterface::availableDrivers() -> string {
|
||||
return
|
||||
|
||||
//Windows
|
||||
@@ -469,12 +469,12 @@ const char* InputInterface::availableDrivers() {
|
||||
"None";
|
||||
}
|
||||
|
||||
bool InputInterface::init() {
|
||||
auto InputInterface::init() -> bool {
|
||||
if(!p) driver();
|
||||
return p->init();
|
||||
}
|
||||
|
||||
void InputInterface::term() {
|
||||
auto InputInterface::term() -> void {
|
||||
if(p) {
|
||||
p->term();
|
||||
delete p;
|
||||
@@ -482,15 +482,14 @@ void InputInterface::term() {
|
||||
}
|
||||
}
|
||||
|
||||
bool InputInterface::cap(const string& name) { return p ? p->cap(name) : false; }
|
||||
any InputInterface::get(const string& name) { return p ? p->get(name) : false; }
|
||||
bool InputInterface::set(const string& name, const any& value) { return p ? p->set(name, value) : false; }
|
||||
bool InputInterface::acquire() { return p ? p->acquire() : false; }
|
||||
bool InputInterface::unacquire() { return p ? p->unacquire() : false; }
|
||||
bool InputInterface::acquired() { return p ? p->acquired() : false; }
|
||||
vector<HID::Device*> InputInterface::poll() { return p ? p->poll() : vector<HID::Device*>(); }
|
||||
bool InputInterface::rumble(uint64_t id, bool enable) { return p ? p->rumble(id, enable) : false; }
|
||||
InputInterface::InputInterface() : p(nullptr) {}
|
||||
InputInterface::~InputInterface() { term(); }
|
||||
auto InputInterface::cap(const string& name) -> bool { return p ? p->cap(name) : false; }
|
||||
auto InputInterface::get(const string& name) -> any { return p ? p->get(name) : false; }
|
||||
auto InputInterface::set(const string& name, const any& value) -> bool { return p ? p->set(name, value) : false; }
|
||||
auto InputInterface::acquire() -> bool { return p ? p->acquire() : false; }
|
||||
auto InputInterface::unacquire() -> bool { return p ? p->unacquire() : false; }
|
||||
auto InputInterface::acquired() -> bool { return p ? p->acquired() : false; }
|
||||
auto InputInterface::poll() -> vector<shared_pointer<HID::Device>> { return p ? p->poll() : vector<shared_pointer<HID::Device>>(); }
|
||||
auto InputInterface::rumble(uint64_t id, bool enable) -> bool { return p ? p->rumble(id, enable) : false; }
|
||||
|
||||
};
|
||||
|
@@ -1,14 +1,14 @@
|
||||
/* ruby
|
||||
* author: byuu
|
||||
* license: ISC
|
||||
* version: 0.11 (2013-12-19)
|
||||
* version: 0.12 (2015-05-24)
|
||||
*
|
||||
* ruby is a cross-platform hardware abstraction layer
|
||||
* it provides a common interface to video, audio and input devices
|
||||
*/
|
||||
|
||||
#ifndef RUBY_H
|
||||
#define RUBY_H
|
||||
#ifndef RUBY_HPP
|
||||
#define RUBY_HPP
|
||||
|
||||
#include <nall/nall.hpp>
|
||||
|
||||
@@ -65,29 +65,28 @@ private:
|
||||
};
|
||||
|
||||
struct InputInterface {
|
||||
nall::function<void (nall::HID::Device& device, unsigned group, unsigned input, int16_t oldValue, int16_t newValue)> onChange;
|
||||
nall::function<void (nall::shared_pointer<nall::HID::Device> device, unsigned group, unsigned input, int16_t oldValue, int16_t newValue)> onChange;
|
||||
|
||||
void driver(const char* driver = "");
|
||||
const char* optimalDriver();
|
||||
const char* safestDriver();
|
||||
const char* availableDrivers();
|
||||
bool init();
|
||||
void term();
|
||||
|
||||
bool cap(const nall::string& name);
|
||||
nall::any get(const nall::string& name);
|
||||
bool set(const nall::string& name, const nall::any& value);
|
||||
|
||||
bool acquire();
|
||||
bool unacquire();
|
||||
bool acquired();
|
||||
|
||||
nall::vector<nall::HID::Device*> poll();
|
||||
bool rumble(uint64_t id, bool enable);
|
||||
|
||||
InputInterface();
|
||||
~InputInterface();
|
||||
|
||||
auto driver(nall::string driver = "") -> void;
|
||||
auto optimalDriver() -> nall::string;
|
||||
auto safestDriver() -> nall::string;
|
||||
auto availableDrivers() -> nall::string;
|
||||
auto init() -> bool;
|
||||
auto term() -> void;
|
||||
|
||||
auto cap(const nall::string& name) -> bool;
|
||||
auto get(const nall::string& name) -> nall::any;
|
||||
auto set(const nall::string& name, const nall::any& value) -> bool;
|
||||
|
||||
auto acquire() -> bool;
|
||||
auto unacquire() -> bool;
|
||||
auto acquired() -> bool;
|
||||
|
||||
auto poll() -> nall::vector<nall::shared_pointer<nall::HID::Device>>;
|
||||
auto rumble(uint64_t id, bool enable) -> bool;
|
||||
|
||||
private:
|
||||
Input* p = nullptr;
|
||||
};
|
||||
|
Reference in New Issue
Block a user