mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-25 19:02:19 -05:00
Adds a function for grabbing physical device from virtual slot.
This commit is contained in:
parent
b3c3882b12
commit
c1659d3dcf
@ -7,14 +7,15 @@
|
||||
#include "SDLController.h"
|
||||
#include <Utils/StringHelper.h>
|
||||
|
||||
namespace Ship {
|
||||
uint8_t* controllerBits;
|
||||
|
||||
void Ship::ControlDeck::Init(uint8_t* bits) {
|
||||
void ControlDeck::Init(uint8_t* bits) {
|
||||
ScanPhysicalDevices();
|
||||
controllerBits = bits;
|
||||
}
|
||||
|
||||
void Ship::ControlDeck::ScanPhysicalDevices() {
|
||||
void ControlDeck::ScanPhysicalDevices() {
|
||||
|
||||
virtualDevices.clear();
|
||||
physicalDevices.clear();
|
||||
@ -44,13 +45,13 @@ void Ship::ControlDeck::ScanPhysicalDevices() {
|
||||
LoadControllerSettings();
|
||||
}
|
||||
|
||||
void Ship::ControlDeck::SetPhysicalDevice(int slot, int deviceSlot) {
|
||||
void ControlDeck::SetPhysicalDevice(int slot, int deviceSlot) {
|
||||
const std::shared_ptr<Controller> backend = physicalDevices[deviceSlot];
|
||||
virtualDevices[slot] = deviceSlot;
|
||||
*controllerBits |= (backend->Connected()) << slot;
|
||||
}
|
||||
|
||||
void Ship::ControlDeck::WriteToPad(OSContPad* pad) const {
|
||||
void ControlDeck::WriteToPad(OSContPad* pad) const {
|
||||
for (size_t i = 0; i < virtualDevices.size(); i++) {
|
||||
const std::shared_ptr<Controller> backend = physicalDevices[virtualDevices[i]];
|
||||
if (backend->GetGuid() == "Auto") {
|
||||
@ -65,7 +66,7 @@ void Ship::ControlDeck::WriteToPad(OSContPad* pad) const {
|
||||
|
||||
#define NESTED(key, ...) StringHelper::Sprintf("Controllers.%s.Slot_%d." key, device->GetGuid().c_str(), slot, __VA_ARGS__)
|
||||
|
||||
void Ship::ControlDeck::LoadControllerSettings() {
|
||||
void ControlDeck::LoadControllerSettings() {
|
||||
std::shared_ptr<Mercury> Config = GlobalCtx2::GetInstance()->GetConfig();
|
||||
|
||||
for (auto const& val : Config->rjson["Controllers"]["Deck"].items()) {
|
||||
@ -112,7 +113,7 @@ void Ship::ControlDeck::LoadControllerSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
void Ship::ControlDeck::SaveControllerSettings() {
|
||||
void ControlDeck::SaveControllerSettings() {
|
||||
std::shared_ptr<Mercury> Config = GlobalCtx2::GetInstance()->GetConfig();
|
||||
|
||||
for (size_t i = 0; i < virtualDevices.size(); i++) {
|
||||
@ -153,18 +154,23 @@ void Ship::ControlDeck::SaveControllerSettings() {
|
||||
Config->save();
|
||||
}
|
||||
|
||||
std::shared_ptr<Ship::Controller> Ship::ControlDeck::GetPhysicalDevice(int deviceSlot) {
|
||||
std::shared_ptr<Controller> ControlDeck::GetPhysicalDevice(int deviceSlot) {
|
||||
return physicalDevices[deviceSlot];
|
||||
}
|
||||
|
||||
size_t Ship::ControlDeck::GetNumPhysicalDevices() {
|
||||
size_t ControlDeck::GetNumPhysicalDevices() {
|
||||
return physicalDevices.size();
|
||||
}
|
||||
|
||||
int Ship::ControlDeck::GetVirtualDevice(int slot) {
|
||||
int ControlDeck::GetVirtualDevice(int slot) {
|
||||
return virtualDevices[slot];
|
||||
}
|
||||
|
||||
size_t Ship::ControlDeck::GetNumVirtualDevices() {
|
||||
size_t ControlDeck::GetNumVirtualDevices() {
|
||||
return virtualDevices.size();
|
||||
}
|
||||
|
||||
std::shared_ptr<Controller> ControlDeck::GetPhysicalDeviceFromVirtualSlot(int slot) {
|
||||
return GetPhysicalDevice(GetVirtualDevice(slot));
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ namespace Ship {
|
||||
void SaveControllerSettings();
|
||||
void SetPhysicalDevice(int slot, int deviceSlot);
|
||||
std::shared_ptr<Ship::Controller> GetPhysicalDevice(int deviceSlot);
|
||||
std::shared_ptr<Ship::Controller> GetPhysicalDeviceFromVirtualSlot(int slot);
|
||||
size_t GetNumPhysicalDevices();
|
||||
int GetVirtualDevice(int slot);
|
||||
size_t GetNumVirtualDevices();
|
||||
|
@ -17,7 +17,7 @@ namespace Ship {
|
||||
|
||||
std::shared_ptr<Controller> GetControllerPerSlot(int slot) {
|
||||
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
return controlDeck->GetPhysicalDevice(controlDeck->GetVirtualDevice(slot));
|
||||
return controlDeck->GetPhysicalDeviceFromVirtualSlot(slot);
|
||||
}
|
||||
|
||||
void InputEditor::DrawButton(const char* label, int n64Btn) {
|
||||
@ -83,7 +83,7 @@ namespace Ship {
|
||||
|
||||
void InputEditor::DrawControllerSchema() {
|
||||
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
auto Backend = controlDeck->GetPhysicalDevice(controlDeck->GetVirtualDevice(CurrentPort));
|
||||
auto Backend = controlDeck->GetPhysicalDeviceFromVirtualSlot(CurrentPort);
|
||||
DeviceProfile& profile = Backend->profiles[CurrentPort];
|
||||
float sensitivity = profile.Thresholds[SENSITIVITY];
|
||||
bool IsKeyboard = Backend->GetGuid() == "Keyboard" || Backend->GetGuid() == "Auto" || !Backend->Connected();
|
||||
|
@ -1309,7 +1309,7 @@ extern "C" void OTRControllerCallback(ControllerCallback* controller) {
|
||||
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
|
||||
for (int i = 0; i < controlDeck->GetNumVirtualDevices(); ++i) {
|
||||
auto physicalDevice = controlDeck->GetPhysicalDevice(controlDeck->GetVirtualDevice(i));
|
||||
auto physicalDevice = controlDeck->GetPhysicalDeviceFromVirtualSlot(i);
|
||||
physicalDevice->WriteToSource(i, controller);
|
||||
}
|
||||
}
|
||||
@ -1367,7 +1367,7 @@ extern "C" int Controller_ShouldRumble(size_t i) {
|
||||
auto controlDeck = Ship::GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck();
|
||||
|
||||
for (int i = 0; i < controlDeck->GetNumVirtualDevices(); ++i) {
|
||||
auto physicalDevice = controlDeck->GetPhysicalDevice(controlDeck->GetVirtualDevice(i));
|
||||
auto physicalDevice = controlDeck->GetPhysicalDeviceFromVirtualSlot(i);
|
||||
if (physicalDevice->CanRumble()) {
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user