mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-23 16:22:59 +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:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user