From a83d27b9c2bcc1c5c617474edf84b6a24c722085 Mon Sep 17 00:00:00 2001 From: skidau Date: Sun, 1 Mar 2015 07:43:34 +1100 Subject: [PATCH] Increased the performance of the hotkey code by: * Halving the number of hotkeys checked for (there were extra for future use) * Gets the controller status once before parsing hotkeys * Checks for the GUI lock once before parsing hotkeys * Removed some redundant memsets --- Source/Core/Core/HotkeyManager.cpp | 41 ++++++++++++++---------------- Source/Core/Core/HotkeyManager.h | 5 ++-- Source/Core/DolphinWX/Frame.cpp | 4 +++ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index 8233b32d5e..9fc7208ddb 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -153,7 +153,8 @@ const int num_hotkeys = (sizeof(hotkey_labels) / sizeof(hotkey_labels[0])); namespace HotkeyManagerEmu { -static u32 hotkeyDown[6]; +static u32 hotkeyDown[3]; +static HotkeyStatus hotkey; static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys"); InputConfig* GetConfig() @@ -161,31 +162,22 @@ InputConfig* GetConfig() return &s_config; } -void GetStatus(u8 _port, HotkeyStatus* _pHotkeyStatus) +void GetStatus() { - memset(_pHotkeyStatus, 0, sizeof(*_pHotkeyStatus)); - _pHotkeyStatus->err = PAD_ERR_NONE; - - std::unique_lock lk(s_config.controls_lock, std::try_to_lock); - - if (!lk.owns_lock()) - { - // if gui has lock (messing with controls), skip this input cycle - for (int i = 0; i < 6; i++) - _pHotkeyStatus->button[i] = 0; - - return; - } + hotkey.err = PAD_ERR_NONE; // get input - ((HotkeyManager*)s_config.controllers[_port])->GetInput(_pHotkeyStatus); + ((HotkeyManager*)s_config.controllers[0])->GetInput(&hotkey); +} + +bool IsReady() +{ + std::unique_lock lk(s_config.controls_lock, std::try_to_lock); + return lk.owns_lock(); } bool IsPressed(int Id, bool held) { - HotkeyStatus hotkey; - memset(&hotkey, 0, sizeof(hotkey)); - GetStatus(0, &hotkey); unsigned int set = Id / 32; unsigned int setKey = Id % 32; if (hotkey.button[set] & (1 << setKey)) @@ -215,7 +207,7 @@ void Initialize(void* const hwnd) // load the saved controller config s_config.LoadConfig(true); - for (unsigned int i = 0; i < 6; ++i) + for (unsigned int i = 0; i < 3; ++i) hotkeyDown[i] = 0; } @@ -235,7 +227,7 @@ void Shutdown() HotkeyManager::HotkeyManager() { - for (int set = 0; set < 6; set++) + for (int set = 0; set < 3; set++) { // buttons if ((set * 32) < num_hotkeys) @@ -266,9 +258,14 @@ std::string HotkeyManager::GetName() const void HotkeyManager::GetInput(HotkeyStatus* const kb) { - for (int set = 0; set < 6; set++) + for (int set = 0; set < 3; set++) + { if ((set * 32) < num_hotkeys) + { + kb->button[set] = 0; m_keys[set]->GetState(&kb->button[set], hotkey_bitmasks); + } + } } void HotkeyManager::LoadDefaults(const ControllerInterface& ciface) diff --git a/Source/Core/Core/HotkeyManager.h b/Source/Core/Core/HotkeyManager.h index 1e03163def..6095db4906 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -24,7 +24,7 @@ public: void LoadDefaults(const ControllerInterface& ciface); private: - Buttons* m_keys[6]; + Buttons* m_keys[3]; ControlGroup* m_options; }; @@ -34,6 +34,7 @@ namespace HotkeyManagerEmu void Shutdown(); InputConfig* GetConfig(); - void GetStatus(u8 _port, HotkeyStatus* _pKeyboardStatus); + void GetStatus(); + bool IsReady(); bool IsPressed(int Id, bool held); } diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index be2f0c68dc..8906dba1f6 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -1263,11 +1263,15 @@ const CGameListCtrl *CFrame::GetGameListCtrl() const void CFrame::PollHotkeys(wxTimerEvent& event) { + if (!HotkeyManagerEmu::IsReady()) + return; + if (Core::GetState() == Core::CORE_UNINITIALIZED || Core::GetState() == Core::CORE_PAUSE) g_controller_interface.UpdateInput(); if (Core::GetState() != Core::CORE_STOPPING) { + HotkeyManagerEmu::GetStatus(); wxKeyEvent keyevent = 0; if (IsHotkey(keyevent, HK_TOGGLE_THROTTLE))