mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-20 09:31:36 +02:00
Update to 20180730 release.
byuu says: These WIPs-within-WIPs are getting more and more broken ... this isn't going the way I wanted. But ... this time around, I've revamped the entire ruby API again, to solve a bunch of tough problems that have always made using ruby really clunky. But there are *so many* ruby drivers that it's going to take a long time to work through them all. This WIP is only going to run bsnes, and only on FreeBSD, and only with some drivers. hiro's Application::initialize() now calls hiro::initialize(), which you define inside of your hiro apps. This lets you call Application::setName(...) before anything else in hiro runs. This is essential on Xorg to set program icons, for instance. With the ruby rewrite and the change to hiro, I can get away from the need to make everything in bsnes/higan pointers to objects, and can now just declare them as regular objects.
This commit is contained in:
167
ruby/input/input.cpp
Normal file
167
ruby/input/input.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
#if defined(INPUT_CARBON)
|
||||
#include <ruby/input/carbon.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_QUARTZ)
|
||||
#include <ruby/input/quartz.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_SDL)
|
||||
#include <ruby/input/sdl.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_UDEV)
|
||||
#include <ruby/input/udev.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_WINDOWS)
|
||||
#include <ruby/input/windows.cpp>
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_XLIB)
|
||||
#include <ruby/input/xlib.cpp>
|
||||
#endif
|
||||
|
||||
namespace ruby {
|
||||
|
||||
auto Input::setContext(uintptr context) -> bool {
|
||||
if(driver->context == context) return true;
|
||||
if(!driver->hasContext()) return false;
|
||||
if(!driver->setContext(driver->context = context)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
auto Input::acquired() -> bool {
|
||||
return driver->acquired();
|
||||
}
|
||||
|
||||
auto Input::acquire() -> bool {
|
||||
return driver->acquire();
|
||||
}
|
||||
|
||||
auto Input::release() -> bool {
|
||||
return driver->release();
|
||||
}
|
||||
|
||||
auto Input::poll() -> vector<shared_pointer<nall::HID::Device>> {
|
||||
return driver->poll();
|
||||
}
|
||||
|
||||
auto Input::rumble(uint64_t id, bool enable) -> bool {
|
||||
return driver->rumble(id, enable);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
auto Input::onChange(const function<void (shared_pointer<HID::Device>, uint, uint, int16_t, int16_t)>& onChange) -> void {
|
||||
change = onChange;
|
||||
}
|
||||
|
||||
auto Input::doChange(shared_pointer<HID::Device> device, uint group, uint input, int16_t oldValue, int16_t newValue) -> void {
|
||||
if(change) change(device, group, input, oldValue, newValue);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
auto Input::create(string driver) -> bool {
|
||||
reset();
|
||||
if(!driver) driver = optimalDriver();
|
||||
|
||||
#if defined(INPUT_WINDOWS)
|
||||
if(driver == "Windows") self.driver = new InputWindows(*this);
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_QUARTZ)
|
||||
if(driver == "Quartz") self.driver = new InputQuartz(*this);
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_CARBON)
|
||||
if(driver == "Carbon") self.driver = new InputCarbon(*this);
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_UDEV)
|
||||
if(driver == "udev") self.driver = new InputUdev(*this);
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_SDL)
|
||||
if(driver == "SDL") self.driver = new InputSDL(*this);
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_XLIB)
|
||||
if(driver == "Xlib") self.driver = new InputXlib(*this);
|
||||
#endif
|
||||
|
||||
if(!self.driver) self.driver = new InputDriver(*this);
|
||||
|
||||
return self.driver->create();
|
||||
}
|
||||
|
||||
auto Input::hasDrivers() -> vector<string> {
|
||||
return {
|
||||
|
||||
#if defined(INPUT_WINDOWS)
|
||||
"Windows",
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_QUARTZ)
|
||||
"Quartz",
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_CARBON)
|
||||
"Carbon",
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_UDEV)
|
||||
"udev",
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_SDL)
|
||||
"SDL",
|
||||
#endif
|
||||
|
||||
#if defined(INPUT_XLIB)
|
||||
"Xlib",
|
||||
#endif
|
||||
|
||||
"None"};
|
||||
}
|
||||
|
||||
auto Input::optimalDriver() -> string {
|
||||
#if defined(INPUT_WINDOWS)
|
||||
return "Windows";
|
||||
#elif defined(INPUT_QUARTZ)
|
||||
return "Quartz";
|
||||
#elif defined(INPUT_CARBON)
|
||||
return "Carbon";
|
||||
#elif defined(INPUT_UDEV)
|
||||
return "udev";
|
||||
#elif defined(INPUT_SDL)
|
||||
return "SDL";
|
||||
#elif defined(INPUT_XLIB)
|
||||
return "Xlib";
|
||||
#else
|
||||
return "None";
|
||||
#endif
|
||||
}
|
||||
|
||||
auto Input::safestDriver() -> string {
|
||||
#if defined(INPUT_WINDOWS)
|
||||
return "Windows";
|
||||
#elif defined(INPUT_QUARTZ)
|
||||
return "Quartz";
|
||||
#elif defined(INPUT_CARBON)
|
||||
return "Carbon";
|
||||
#elif defined(INPUT_UDEV)
|
||||
return "udev";
|
||||
#elif defined(INPUT_SDL)
|
||||
return "SDL";
|
||||
#elif defined(INPUT_XLIB)
|
||||
return "Xlib";
|
||||
#else
|
||||
return "none";
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
60
ruby/input/input.hpp
Normal file
60
ruby/input/input.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
struct Input;
|
||||
|
||||
struct InputDriver {
|
||||
InputDriver(Input& super) : super(super) {}
|
||||
virtual ~InputDriver() = default;
|
||||
|
||||
virtual auto create() -> bool { return true; }
|
||||
virtual auto driverName() -> string { return "None"; }
|
||||
virtual auto ready() -> bool { return true; }
|
||||
|
||||
virtual auto hasContext() -> bool { return false; }
|
||||
|
||||
virtual auto setContext(uintptr context) -> bool { return true; }
|
||||
|
||||
virtual auto acquired() -> bool { return false; }
|
||||
virtual auto acquire() -> bool { return false; }
|
||||
virtual auto release() -> bool { return false; }
|
||||
virtual auto poll() -> vector<shared_pointer<nall::HID::Device>> { return {}; }
|
||||
virtual auto rumble(uint64_t id, bool enable) -> bool { return false; }
|
||||
|
||||
protected:
|
||||
Input& super;
|
||||
friend class Input;
|
||||
|
||||
uintptr context = 0;
|
||||
};
|
||||
|
||||
struct Input {
|
||||
static auto hasDrivers() -> vector<string>;
|
||||
static auto hasDriver(string driver) -> bool { return (bool)hasDrivers().find(driver); }
|
||||
static auto optimalDriver() -> string;
|
||||
static auto safestDriver() -> string;
|
||||
|
||||
Input() : self(*this) {}
|
||||
explicit operator bool() const { return (bool)driver; }
|
||||
auto reset() -> void { driver.reset(); }
|
||||
auto create(string driver = "") -> bool;
|
||||
auto driverName() -> string { return driver->driverName(); }
|
||||
auto ready() -> bool { return driver->ready(); }
|
||||
|
||||
auto hasContext() -> bool { return driver->hasContext(); }
|
||||
|
||||
auto context() -> uintptr { return driver->context; }
|
||||
|
||||
auto setContext(uintptr context) -> bool;
|
||||
|
||||
auto acquired() -> bool;
|
||||
auto acquire() -> bool;
|
||||
auto release() -> bool;
|
||||
auto poll() -> vector<shared_pointer<nall::HID::Device>>;
|
||||
auto rumble(uint64_t id, bool enable) -> bool;
|
||||
|
||||
auto onChange(const function<void (shared_pointer<nall::HID::Device>, uint, uint, int16_t, int16_t)>&) -> void;
|
||||
auto doChange(shared_pointer<nall::HID::Device> device, uint group, uint input, int16_t oldValue, int16_t newValue) -> void;
|
||||
|
||||
protected:
|
||||
Input& self;
|
||||
unique_pointer<InputDriver> driver;
|
||||
function<void (shared_pointer<nall::HID::Device> device, uint group, uint input, int16_t oldValue, int16_t newValue)> change;
|
||||
};
|
@@ -6,38 +6,32 @@
|
||||
#include "mouse/xlib.cpp"
|
||||
#include "joypad/sdl.cpp"
|
||||
|
||||
struct InputSDL : Input {
|
||||
InputSDL() : _keyboard(*this), _mouse(*this), _joypad(*this) { initialize(); }
|
||||
struct InputSDL : InputDriver {
|
||||
InputSDL& self;
|
||||
|
||||
InputSDL(Input& super) : InputDriver(super), self(*this), keyboard(super), mouse(super), joypad(super) {}
|
||||
~InputSDL() { terminate(); }
|
||||
|
||||
auto driver() -> string override { return "SDL"; }
|
||||
auto ready() -> bool override { return _ready; }
|
||||
|
||||
auto hasContext() -> bool override { return true; }
|
||||
|
||||
auto setContext(uintptr context) -> bool override {
|
||||
if(context == Input::context()) return true;
|
||||
if(!Input::setContext(context)) return false;
|
||||
auto create() -> bool {
|
||||
return initialize();
|
||||
}
|
||||
|
||||
auto acquired() -> bool override {
|
||||
return _mouse.acquired();
|
||||
}
|
||||
auto driverName() -> string override { return "SDL"; }
|
||||
auto ready() -> bool override { return isReady; }
|
||||
|
||||
auto acquire() -> bool override {
|
||||
return _mouse.acquire();
|
||||
}
|
||||
auto hasContext() -> bool override { return true; }
|
||||
|
||||
auto release() -> bool override {
|
||||
return _mouse.release();
|
||||
}
|
||||
auto setContext(uintptr context) -> bool override { return initialize(); }
|
||||
|
||||
auto acquired() -> bool override { return mouse.acquired(); }
|
||||
auto acquire() -> bool override { return mouse.acquire(); }
|
||||
auto release() -> bool override { return mouse.release(); }
|
||||
|
||||
auto poll() -> vector<shared_pointer<HID::Device>> override {
|
||||
vector<shared_pointer<HID::Device>> devices;
|
||||
_keyboard.poll(devices);
|
||||
_mouse.poll(devices);
|
||||
_joypad.poll(devices);
|
||||
keyboard.poll(devices);
|
||||
mouse.poll(devices);
|
||||
joypad.poll(devices);
|
||||
return devices;
|
||||
}
|
||||
|
||||
@@ -48,23 +42,23 @@ struct InputSDL : Input {
|
||||
private:
|
||||
auto initialize() -> bool {
|
||||
terminate();
|
||||
if(!_context) return false;
|
||||
if(!_keyboard.initialize()) return false;
|
||||
if(!_mouse.initialize(_context)) return false;
|
||||
if(!_joypad.initialize()) return false;
|
||||
return _ready = true;
|
||||
if(!self.context) return false;
|
||||
if(!keyboard.initialize()) return false;
|
||||
if(!mouse.initialize(self.context)) return false;
|
||||
if(!joypad.initialize()) return false;
|
||||
return isReady = true;
|
||||
}
|
||||
|
||||
auto terminate() -> void {
|
||||
_ready = false;
|
||||
_keyboard.terminate();
|
||||
_mouse.terminate();
|
||||
_joypad.terminate();
|
||||
isReady = false;
|
||||
keyboard.terminate();
|
||||
mouse.terminate();
|
||||
joypad.terminate();
|
||||
}
|
||||
|
||||
bool _ready = false;
|
||||
bool isReady = false;
|
||||
|
||||
InputKeyboardXlib _keyboard;
|
||||
InputMouseXlib _mouse;
|
||||
InputJoypadSDL _joypad;
|
||||
InputKeyboardXlib keyboard;
|
||||
InputMouseXlib mouse;
|
||||
InputJoypadSDL joypad;
|
||||
};
|
||||
|
Reference in New Issue
Block a user