mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-28 10:15:28 +03:00
Slightly refactor controller code in HID
Now uses ranges where possible and a function to get the number of connected controllers has been added.
This commit is contained in:
parent
2873f11baa
commit
9a8e39cba1
@ -69,14 +69,7 @@ namespace skyline::input {
|
||||
|
||||
// We do this to prevent triggering the event unless there's a real change in a device's style, which would be caused if we disconnected all controllers then reconnected them
|
||||
for (auto &device : npads) {
|
||||
bool connected{};
|
||||
for (const auto &controller : controllers) {
|
||||
if (controller.device == &device) {
|
||||
connected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!connected)
|
||||
if (!ranges::any_of(controllers, [&](auto &controller) { return controller.device == &device; }))
|
||||
device.Disconnect();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <range/v3/algorithm.hpp>
|
||||
#include "npad_device.h"
|
||||
|
||||
namespace skyline::input {
|
||||
@ -69,6 +70,16 @@ namespace skyline::input {
|
||||
return npads.operator[](Translate(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Counts the number of currently connected controllers
|
||||
*/
|
||||
size_t GetConnectedControllerCount() {
|
||||
std::scoped_lock lock{mutex};
|
||||
return static_cast<size_t>(ranges::count_if(controllers, [](const auto &controller) {
|
||||
return controller.device != nullptr && controller.device->connectionState.connected;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deduces all the mappings from guest controllers -> players based on the configuration supplied by HID services and available controllers
|
||||
* @note If any class members were edited, the mutex shouldn't be released till this is called
|
||||
|
Loading…
Reference in New Issue
Block a user