Adds a function for grabbing physical device from virtual slot.

This commit is contained in:
Kenix3 2022-08-02 21:58:30 -04:00
parent b3c3882b12
commit c1659d3dcf
5 changed files with 132 additions and 125 deletions

View File

@ -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));
}
}

View File

@ -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();

View File

@ -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();

View File

@ -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;
}