mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-05 13:20:11 +00:00
feat(agc): read the pad snapshot only while the panel is wanted
PadStatusDisplay::Poll asks the provider for a snapshot only when the panel can be shown: in the events mode always, otherwise only while a request keeps it visible. With ANYPS5_PAD_STATUS unset or 0 and no request the provider is not called, so the host builds no snapshot and reads no controller state for it. An unchanged snapshot is not observed again, and a display that stopped being polled observes the next snapshot afresh when a request makes it wanted again. The entry point for the host's pad code is AgcDriverPadStatusPoll_nid_postfix.
This commit is contained in:
1 parent
2835df4219
commit
45edae3108
2 files changed
+25
No files matched your search
@@ -41,6 +41,8 @@ public:
|
||||
bool Observe(Clock::time_point now, const PadStatusSnapshot& snapshot);
|
||||
void Request(Clock::time_point now);
|
||||
bool Visible(Clock::time_point now) const;
|
||||
bool Wants(Clock::time_point now) const;
|
||||
bool Poll(Clock::time_point now, const PadStatusProvider& provider);
|
||||
std::vector<std::string> Lines() const;
|
||||
|
||||
private:
|
||||
@@ -48,11 +50,13 @@ private:
|
||||
std::optional<PadStatusSnapshot> previous;
|
||||
std::array<bool, PadStatusSlots> seen{};
|
||||
std::optional<Clock::time_point> shownUntil;
|
||||
std::optional<PadStatusSnapshot> polled;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
extern "C" void AgcDriverPadStatusObserve_nid_postfix(const AgcDriver::PadStatusSnapshot* snapshot);
|
||||
extern "C" void AgcDriverPadStatusPoll_nid_postfix(const AgcDriver::PadStatusProvider* provider);
|
||||
extern "C" void AgcDriverPadStatusShow_nid_postfix();
|
||||
|
||||
#endif
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
namespace AgcDriver {
|
||||
namespace {
|
||||
@@ -132,6 +133,21 @@ bool PadStatusDisplay::Visible(Clock::time_point now) const {
|
||||
return shownUntil.has_value() && now < *shownUntil;
|
||||
}
|
||||
|
||||
bool PadStatusDisplay::Wants(Clock::time_point now) const {
|
||||
return mode == PadStatusMode::Events || Visible(now);
|
||||
}
|
||||
|
||||
bool PadStatusDisplay::Poll(Clock::time_point now, const PadStatusProvider& provider) {
|
||||
if (!Wants(now)) {
|
||||
polled.reset();
|
||||
return false;
|
||||
}
|
||||
auto snapshot = provider.read();
|
||||
if (!polled.has_value() || *polled != snapshot) Observe(now, snapshot);
|
||||
polled = std::move(snapshot);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::string> PadStatusDisplay::Lines() const {
|
||||
std::vector<std::string> lines;
|
||||
for (std::size_t slot = 0; slot < PadStatusSlots; ++slot) {
|
||||
@@ -166,6 +182,11 @@ extern "C" void AgcDriverPadStatusObserve_nid_postfix(const AgcDriver::PadStatus
|
||||
AgcDriver::display().Observe(AgcDriver::PadStatusDisplay::Clock::now(), *snapshot);
|
||||
}
|
||||
|
||||
extern "C" void AgcDriverPadStatusPoll_nid_postfix(const AgcDriver::PadStatusProvider* provider) {
|
||||
std::lock_guard lock(AgcDriver::displayMutex);
|
||||
AgcDriver::display().Poll(AgcDriver::PadStatusDisplay::Clock::now(), *provider);
|
||||
}
|
||||
|
||||
extern "C" void AgcDriverPadStatusShow_nid_postfix() {
|
||||
std::lock_guard lock(AgcDriver::displayMutex);
|
||||
AgcDriver::display().Request(AgcDriver::PadStatusDisplay::Clock::now());
|
||||
|
||||
Reference in new issue
Block a user