bsnes/higan/target-bsnes/input/input.hpp

95 lines
2.6 KiB
C++
Raw Normal View History

struct InputMapping {
auto bind() -> void;
auto bind(string mapping) -> void;
auto bind(shared_pointer<HID::Device> device, uint group, uint input, int16 oldValue, int16 newValue) -> bool;
auto unbind() -> void;
auto poll() -> int16;
auto rumble(bool enable) -> void;
auto displayName() -> string;
using Type = Emulator::Interface::Input::Type;
auto isDigital() const -> bool {
return type == Type::Hat || type == Type::Button || type == Type::Trigger || type == Type::Control;
}
auto isAnalog() const -> bool {
return type == Type::Axis;
}
auto isRumble() const -> bool {
return type == Type::Rumble;
}
uint portID = 0;
uint deviceID = 0;
uint inputID = 0;
maybe<uint> turboID;
string path; //configuration file key path
string name; //input name (human readable)
uint type = 0;
string assignment = "None";
enum class Logic : uint { AND, OR };
enum class Qualifier : uint { None, Lo, Hi, Rumble };
virtual auto logic() const -> Logic { return Logic::OR; }
struct Mapping {
shared_pointer<HID::Device> device;
uint group = 0;
uint input = 0;
Qualifier qualifier = Qualifier::None;
};
vector<Mapping> mappings;
uint3 turboCounter = 0;
};
struct InputHotkey : InputMapping {
InputHotkey(string name) { this->name = name; }
auto& onPress(function<void()> press) { return this->press = press, *this; }
auto& onRelease(function<void()> release) { return this->release = release, *this; }
//auto logic() const -> Logic override { return Logic::AND; }
function<auto() -> void> press;
function<auto() -> void> release;
int16 state = 0;
};
struct InputDevice {
uint id;
string name;
vector<InputMapping> mappings;
};
struct InputPort {
uint id;
string name;
vector<InputDevice> devices;
};
struct InputManager {
auto initialize() -> void;
auto bind() -> void;
auto poll() -> void;
auto frame() -> void;
auto onChange(shared_pointer<HID::Device> device, uint group, uint input, int16_t oldValue, int16_t newValue) -> void;
auto mapping(uint port, uint device, uint input) -> maybe<InputMapping&>;
auto findMouse() -> shared_pointer<HID::Device>;
//hotkeys.cpp
auto bindHotkeys() -> void;
auto pollHotkeys() -> void;
public:
vector<shared_pointer<HID::Device>> devices;
vector<InputPort> ports;
vector<InputHotkey> hotkeys;
uint64 lastPoll; //time in milliseconds since last call to poll()
uint64 frequency; //minimum time in milliseconds before poll() can be called again
uint turboCounter = 0;
uint turboFrequency = 0;
};
Update to 20180731 release. byuu says: I've completed moving all the class objects from `unique_pointer<T>` to just T. The one exception is the Emulator::Interface instance. I can absolutely make that a global object, but only in bsnes where there's just the one emulation core. I also moved all the SettingsWindow and ToolsWindow panels out to their own global objects, and fixed a very difficult bug with GTK TabFrame controls. The configuration settings panel is now the emulator settings panel. And I added some spacing between bold label sections on both the emulator and driver settings panels. I gave fixing ComboButtonItem my best shot, given I can't reproduce the crash. Probably won't work, though. Also made a very slight consistency improvement to ruby and renamed driverName() to driver(). ... An important change ... as a result of moving bsnes to global objects, this means that the constructors for all windows run before the presentation window is displayed. Before this change, only the presentation window was constructed first berore displaying it, followed by the construction of the rest of the GUI windows. The upside to this is that as soon as you see the main window, the GUI is ready to go without a period where it's unresponsive. The downside to this is it takes about 1.5 seconds to show the main window, compared to around 0.75 seconds before. I've no intention of changing that back. So if the startup time becomes a problem, then we'll just have to work on optimizing hiro, so that it can construct all the global Window objects quicker. The main way to do that would be to not do calls to the Layout::setGeometry functions for every widget added, and instead wait until the window is displayed. But I don't have an easy way to do that, because you want the widget geometry values to be sane even before the window is visible to help size certain things.
2018-07-31 10:56:45 +00:00
extern InputManager inputManager;