2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-14 07:26:09 +00:00

Input: Add onControllerAdded/Removed callbacks and also display the controller name in the input viewer

This commit is contained in:
2022-02-09 00:54:53 -08:00
parent 52fd54bc3e
commit a6b2d66e1e
12 changed files with 175 additions and 59 deletions

View File

@@ -271,6 +271,9 @@ private:
using delta_clock = std::chrono::high_resolution_clock;
std::chrono::time_point<delta_clock> m_prevFrameTime;
std::vector<u32> m_defferredControllers; // used to capture controllers added before CInputGenerator
// is built, i.e during initialization
public:
Application(hecl::Runtime::FileStoreManager& fileMgr, hecl::CVarManager& cvarMgr, hecl::CVarCommons& cvarCmns)
: m_fileMgr(fileMgr), m_cvarManager(cvarMgr), m_cvarCommons(cvarCmns), m_imGuiConsole(cvarMgr, cvarCmns) {}
@@ -314,6 +317,15 @@ public:
}
bool onAppIdle(float realDt) noexcept override {
if (auto* input = g_InputGenerator) {
if (!m_defferredControllers.empty()) {
for (const auto which : m_defferredControllers) {
input->controllerAdded(which);
}
m_defferredControllers.clear();
}
}
if (!m_projectInitialized && !m_deferredProject.empty()) {
if (CDvdFile::Initialize(m_deferredProject)) {
m_projectInitialized = true;
@@ -429,6 +441,20 @@ public:
}
}
void onControllerAdded(uint32_t which) noexcept override {
if (auto* input = g_InputGenerator) {
input->controllerAdded(which);
} else {
m_defferredControllers.emplace_back(which);
}
}
void onControllerRemoved(uint32_t which) noexcept override {
if (auto* input = g_InputGenerator) {
input->controllerRemoved(which);
}
}
void onAppExiting() noexcept override {
m_imGuiConsole.Shutdown();
if (g_mainMP1) {