2015-03-02 20:13:28 +11:00
|
|
|
#include "../tomoko.hpp"
|
2015-04-13 21:16:33 +10:00
|
|
|
#include "hotkeys.cpp"
|
2015-03-02 20:13:28 +11:00
|
|
|
InputManager* inputManager = nullptr;
|
|
|
|
|
|
|
|
auto InputMapping::bind() -> void {
|
|
|
|
auto token = assignment.split("/");
|
2015-05-23 15:29:18 +10:00
|
|
|
if(token.size() < 3) return unbind();
|
Update to v094r20 release.
byuu says:
Main reason for this WIP was because of all the added lines to hiro for
selective component disabling. May as well get all the diff-noise apart
from code changes.
It also merges something I've been talking to Cydrak about ... making
nall::string::(integer,decimal) do built-in binary,octal,hex decoding
instead of just failing on those. This will have fun little side effects
all over the place, like being able to view a topic on my forum via
"forum.byuu.org/topic/0b10010110", heh.
There are two small changes to higan itself, though. First up, I fixed
the resampler ratio when loading non-SNES games. Tested and I can play
Game Boy games fine now. Second, I hooked up menu option hiding for
reset and controller selection. Right now, this works like higan v094,
but I'm thinking I might want to show the "Device -> Controller" even if
that's all that's there. It kind of jives nicer with the input settings
window to see the labels there, I think. And if we ever do add more
stuff, it'll be nice that people already always expect that menu there.
Remaining issues:
* add slotted cart loader (SGB, BSX, ST)
* add DIP switch selection window (NSS)
* add timing configuration (video/audio sync)
2015-05-23 15:37:08 +10:00
|
|
|
uint64_t id = hex(token[0]);
|
2015-03-02 20:13:28 +11:00
|
|
|
unsigned group = token[1].decimal();
|
|
|
|
unsigned input = token[2].decimal();
|
2015-05-23 15:29:18 +10:00
|
|
|
string qualifier = token(3, "None");
|
2015-03-02 20:13:28 +11:00
|
|
|
|
|
|
|
for(auto& device : inputManager->devices) {
|
|
|
|
if(id != device->id) continue;
|
|
|
|
|
|
|
|
this->device = device;
|
|
|
|
this->group = group;
|
|
|
|
this->input = input;
|
2015-05-23 15:29:18 +10:00
|
|
|
this->qualifier = Qualifier::None;
|
|
|
|
if(qualifier == "Lo") this->qualifier = Qualifier::Lo;
|
|
|
|
if(qualifier == "Hi") this->qualifier = Qualifier::Hi;
|
|
|
|
if(qualifier == "Rumble") this->qualifier = Qualifier::Rumble;
|
2015-03-02 20:13:28 +11:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputMapping::bind(HID::Device& device, unsigned group, unsigned input, int16 oldValue, int16 newValue) -> bool {
|
2015-05-23 15:29:18 +10:00
|
|
|
if(device.isNull() || (device.isKeyboard() && device.group[group].input[input].name == "Escape")) {
|
|
|
|
return unbind(), true;
|
|
|
|
}
|
|
|
|
|
|
|
|
string encoding = {hex(device.id), "/", group, "/", input};
|
|
|
|
|
|
|
|
if(isDigital()) {
|
|
|
|
if((device.isKeyboard() && group == HID::Keyboard::GroupID::Button)
|
|
|
|
|| (device.isMouse() && group == HID::Mouse::GroupID::Button)
|
|
|
|
|| (device.isJoypad() && group == HID::Joypad::GroupID::Button)) {
|
|
|
|
if(newValue) {
|
|
|
|
this->assignment = encoding;
|
|
|
|
return bind(), true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if((device.isJoypad() && group == HID::Joypad::GroupID::Axis)
|
|
|
|
|| (device.isJoypad() && group == HID::Joypad::GroupID::Hat)) {
|
|
|
|
if(newValue < -16384) {
|
|
|
|
this->assignment = {encoding, "/Lo"};
|
|
|
|
return bind(), true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newValue > +16384) {
|
|
|
|
this->assignment = {encoding, "/Hi"};
|
|
|
|
return bind(), true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isAnalog()) {
|
|
|
|
if((device.isMouse() && group == HID::Mouse::GroupID::Axis)
|
|
|
|
|| (device.isJoypad() && group == HID::Joypad::GroupID::Axis)
|
|
|
|
|| (device.isJoypad() && group == HID::Joypad::GroupID::Hat)) {
|
|
|
|
if(newValue < -16384 || newValue > +16384) {
|
|
|
|
this->assignment = encoding;
|
|
|
|
return bind(), true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Update to v094r13 release.
byuu says:
This version polishes up the input dialogue (reset, erase, disable
button when item not focused, split device ID from mapping name), adds
color emulation toggle, and add dummy menu items for remaining features
(to be filled in later.)
Also, it now compiles cleanly on Windows with GTK.
I didn't test with TDM-GCC-32, because for god knows what reason, the
32-bit version ships with headers from Windows 95 OSR2 only. So I built
with TDM-GCC-64 with arch=x86.
And uh, apparently, moving or resizing a window causes a Visual C++
runtime exception in the GTK+ DLLs. This doesn't happen with trance or
renshuu built with TDM-GCC-32. So, yeah, like I said, don't use -m32.
2015-03-07 21:21:47 +11:00
|
|
|
|
2015-05-23 15:29:18 +10:00
|
|
|
if(isRumble()) {
|
|
|
|
if(device.isJoypad() && group == HID::Joypad::GroupID::Button) {
|
|
|
|
if(newValue) {
|
|
|
|
encoding = {this->assignment, "/Rumble"};
|
|
|
|
return bind(), true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-03-02 20:13:28 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
auto InputMapping::poll() -> int16 {
|
2015-05-23 15:29:18 +10:00
|
|
|
if(!device) return 0;
|
|
|
|
auto value = device->group[group].input[input].value;
|
|
|
|
|
|
|
|
if(isDigital()) {
|
|
|
|
if(device->isKeyboard() && group == HID::Keyboard::GroupID::Button) return value != 0;
|
|
|
|
if(device->isMouse() && group == HID::Mouse::GroupID::Button) return value != 0;
|
|
|
|
if(device->isJoypad() && group == HID::Joypad::GroupID::Button) return value != 0;
|
|
|
|
if((device->isJoypad() && group == HID::Joypad::GroupID::Axis)
|
|
|
|
|| (device->isJoypad() && group == HID::Joypad::GroupID::Hat)) {
|
|
|
|
if(qualifier == Qualifier::Lo) return value < -16384;
|
|
|
|
if(qualifier == Qualifier::Hi) return value > +16384;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isAnalog()) {
|
|
|
|
if(device->isMouse() && group == HID::Mouse::GroupID::Axis) return value;
|
|
|
|
if(device->isJoypad() && group == HID::Joypad::GroupID::Axis) return value >> 8;
|
|
|
|
if(device->isJoypad() && group == HID::Joypad::GroupID::Hat) return value < 0 ? -1 : value > 0 ? +1 : 0;
|
|
|
|
}
|
|
|
|
|
2015-03-02 20:13:28 +11:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Update to v094r13 release.
byuu says:
This version polishes up the input dialogue (reset, erase, disable
button when item not focused, split device ID from mapping name), adds
color emulation toggle, and add dummy menu items for remaining features
(to be filled in later.)
Also, it now compiles cleanly on Windows with GTK.
I didn't test with TDM-GCC-32, because for god knows what reason, the
32-bit version ships with headers from Windows 95 OSR2 only. So I built
with TDM-GCC-64 with arch=x86.
And uh, apparently, moving or resizing a window causes a Visual C++
runtime exception in the GTK+ DLLs. This doesn't happen with trance or
renshuu built with TDM-GCC-32. So, yeah, like I said, don't use -m32.
2015-03-07 21:21:47 +11:00
|
|
|
auto InputMapping::unbind() -> void {
|
|
|
|
this->assignment = "None";
|
|
|
|
this->device = nullptr;
|
|
|
|
this->group = 0;
|
|
|
|
this->input = 0;
|
2015-05-23 15:29:18 +10:00
|
|
|
this->qualifier = Qualifier::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputMapping::assignmentName() const -> string {
|
|
|
|
if(!device) return "None";
|
|
|
|
string path;
|
|
|
|
path.append(device->name);
|
|
|
|
path.append(".", device->group[group].name);
|
|
|
|
path.append(".", device->group[group].input[input].name);
|
|
|
|
if(qualifier == Qualifier::Lo) path.append(".Lo");
|
|
|
|
if(qualifier == Qualifier::Hi) path.append(".Hi");
|
|
|
|
if(qualifier == Qualifier::Rumble) path.append(".Rumble");
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputMapping::deviceName() const -> string {
|
|
|
|
if(!device) return "";
|
|
|
|
return device->id;
|
Update to v094r13 release.
byuu says:
This version polishes up the input dialogue (reset, erase, disable
button when item not focused, split device ID from mapping name), adds
color emulation toggle, and add dummy menu items for remaining features
(to be filled in later.)
Also, it now compiles cleanly on Windows with GTK.
I didn't test with TDM-GCC-32, because for god knows what reason, the
32-bit version ships with headers from Windows 95 OSR2 only. So I built
with TDM-GCC-64 with arch=x86.
And uh, apparently, moving or resizing a window causes a Visual C++
runtime exception in the GTK+ DLLs. This doesn't happen with trance or
renshuu built with TDM-GCC-32. So, yeah, like I said, don't use -m32.
2015-03-07 21:21:47 +11:00
|
|
|
}
|
|
|
|
|
2015-03-02 20:13:28 +11:00
|
|
|
//
|
|
|
|
|
|
|
|
InputManager::InputManager() {
|
|
|
|
inputManager = this;
|
|
|
|
input.onChange = {&InputManager::onChange, this};
|
|
|
|
|
|
|
|
for(auto& emulator : program->emulators) {
|
|
|
|
Configuration::Node nodeEmulator;
|
|
|
|
|
|
|
|
emulators.append(InputEmulator());
|
|
|
|
auto& inputEmulator = emulators.last();
|
|
|
|
inputEmulator.name = emulator->information.name;
|
|
|
|
|
|
|
|
for(auto& port : emulator->port) {
|
|
|
|
Configuration::Node nodePort;
|
|
|
|
|
|
|
|
inputEmulator.ports.append(InputPort());
|
|
|
|
auto& inputPort = inputEmulator.ports.last();
|
|
|
|
inputPort.name = port.name;
|
|
|
|
for(auto& device : port.device) {
|
|
|
|
Configuration::Node nodeDevice;
|
|
|
|
|
|
|
|
inputPort.devices.append(InputDevice());
|
|
|
|
auto& inputDevice = inputPort.devices.last();
|
|
|
|
inputDevice.name = device.name;
|
|
|
|
for(auto number : device.order) {
|
|
|
|
auto& input = device.input[number];
|
|
|
|
inputDevice.mappings.append(new InputMapping());
|
|
|
|
auto& inputMapping = inputDevice.mappings.last();
|
|
|
|
inputMapping->name = input.name;
|
|
|
|
inputMapping->link = &input;
|
|
|
|
input.guid = (uintptr_t)inputMapping;
|
|
|
|
|
|
|
|
nodeDevice.append(inputMapping->assignment, inputMapping->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodePort.append(nodeDevice, string{inputDevice.name}.replace(" ", ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeEmulator.append(nodePort, string{inputPort.name}.replace(" ", ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
config.append(nodeEmulator, string{inputEmulator.name}.replace(" ", ""));
|
|
|
|
}
|
|
|
|
|
2015-04-13 21:16:33 +10:00
|
|
|
appendHotkeys();
|
2015-03-03 21:14:49 +11:00
|
|
|
config.load({configpath(), "tomoko/input.bml"});
|
|
|
|
config.save({configpath(), "tomoko/input.bml"});
|
2015-03-02 20:13:28 +11:00
|
|
|
poll(); //will call bind();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputManager::bind() -> void {
|
|
|
|
for(auto& emulator : emulators) {
|
|
|
|
for(auto& port : emulator.ports) {
|
|
|
|
for(auto& device : port.devices) {
|
|
|
|
for(auto& mapping : device.mappings) {
|
|
|
|
mapping->bind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-13 21:16:33 +10:00
|
|
|
|
|
|
|
for(auto& hotkey : hotkeys) {
|
|
|
|
hotkey->bind();
|
|
|
|
}
|
2015-03-02 20:13:28 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
auto InputManager::poll() -> void {
|
|
|
|
auto devices = input.poll();
|
|
|
|
bool changed = devices.size() != this->devices.size();
|
|
|
|
if(changed == false) {
|
|
|
|
for(auto n : range(devices)) {
|
|
|
|
changed = devices[n] != this->devices[n];
|
|
|
|
if(changed) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(changed == true) {
|
|
|
|
this->devices = devices;
|
|
|
|
bind();
|
|
|
|
}
|
2015-04-13 21:16:33 +10:00
|
|
|
|
|
|
|
if(presentation && presentation->focused()) pollHotkeys();
|
2015-03-02 20:13:28 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
auto InputManager::onChange(HID::Device& device, unsigned group, unsigned input, int16 oldValue, int16 newValue) -> void {
|
|
|
|
if(settingsManager->focused()) {
|
|
|
|
settingsManager->input.inputEvent(device, group, input, oldValue, newValue);
|
2015-04-13 21:16:33 +10:00
|
|
|
settingsManager->hotkeys.inputEvent(device, group, input, oldValue, newValue);
|
2015-03-02 20:13:28 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InputManager::quit() -> void {
|
2015-03-03 21:14:49 +11:00
|
|
|
config.save({configpath(), "tomoko/input.bml"});
|
2015-04-13 21:16:33 +10:00
|
|
|
emulators.reset();
|
|
|
|
hotkeys.reset();
|
2015-03-02 20:13:28 +11:00
|
|
|
}
|
2015-05-23 15:29:18 +10:00
|
|
|
|
|
|
|
auto InputManager::findMouse() -> HID::Device* {
|
|
|
|
for(auto device : devices) {
|
|
|
|
if(device->isMouse()) return device;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|