mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
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
This commit is contained in:
@ -153,7 +153,8 @@ const int num_hotkeys = (sizeof(hotkey_labels) / sizeof(hotkey_labels[0]));
|
|||||||
namespace HotkeyManagerEmu
|
namespace HotkeyManagerEmu
|
||||||
{
|
{
|
||||||
|
|
||||||
static u32 hotkeyDown[6];
|
static u32 hotkeyDown[3];
|
||||||
|
static HotkeyStatus hotkey;
|
||||||
|
|
||||||
static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys");
|
static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys");
|
||||||
InputConfig* GetConfig()
|
InputConfig* GetConfig()
|
||||||
@ -161,31 +162,22 @@ InputConfig* GetConfig()
|
|||||||
return &s_config;
|
return &s_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetStatus(u8 _port, HotkeyStatus* _pHotkeyStatus)
|
void GetStatus()
|
||||||
{
|
{
|
||||||
memset(_pHotkeyStatus, 0, sizeof(*_pHotkeyStatus));
|
hotkey.err = PAD_ERR_NONE;
|
||||||
_pHotkeyStatus->err = PAD_ERR_NONE;
|
|
||||||
|
|
||||||
std::unique_lock<std::recursive_mutex> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get input
|
// get input
|
||||||
((HotkeyManager*)s_config.controllers[_port])->GetInput(_pHotkeyStatus);
|
((HotkeyManager*)s_config.controllers[0])->GetInput(&hotkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsReady()
|
||||||
|
{
|
||||||
|
std::unique_lock<std::recursive_mutex> lk(s_config.controls_lock, std::try_to_lock);
|
||||||
|
return lk.owns_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsPressed(int Id, bool held)
|
bool IsPressed(int Id, bool held)
|
||||||
{
|
{
|
||||||
HotkeyStatus hotkey;
|
|
||||||
memset(&hotkey, 0, sizeof(hotkey));
|
|
||||||
GetStatus(0, &hotkey);
|
|
||||||
unsigned int set = Id / 32;
|
unsigned int set = Id / 32;
|
||||||
unsigned int setKey = Id % 32;
|
unsigned int setKey = Id % 32;
|
||||||
if (hotkey.button[set] & (1 << setKey))
|
if (hotkey.button[set] & (1 << setKey))
|
||||||
@ -215,7 +207,7 @@ void Initialize(void* const hwnd)
|
|||||||
// load the saved controller config
|
// load the saved controller config
|
||||||
s_config.LoadConfig(true);
|
s_config.LoadConfig(true);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 6; ++i)
|
for (unsigned int i = 0; i < 3; ++i)
|
||||||
hotkeyDown[i] = 0;
|
hotkeyDown[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +227,7 @@ void Shutdown()
|
|||||||
|
|
||||||
HotkeyManager::HotkeyManager()
|
HotkeyManager::HotkeyManager()
|
||||||
{
|
{
|
||||||
for (int set = 0; set < 6; set++)
|
for (int set = 0; set < 3; set++)
|
||||||
{
|
{
|
||||||
// buttons
|
// buttons
|
||||||
if ((set * 32) < num_hotkeys)
|
if ((set * 32) < num_hotkeys)
|
||||||
@ -266,9 +258,14 @@ std::string HotkeyManager::GetName() const
|
|||||||
|
|
||||||
void HotkeyManager::GetInput(HotkeyStatus* const kb)
|
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)
|
if ((set * 32) < num_hotkeys)
|
||||||
|
{
|
||||||
|
kb->button[set] = 0;
|
||||||
m_keys[set]->GetState(&kb->button[set], hotkey_bitmasks);
|
m_keys[set]->GetState(&kb->button[set], hotkey_bitmasks);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HotkeyManager::LoadDefaults(const ControllerInterface& ciface)
|
void HotkeyManager::LoadDefaults(const ControllerInterface& ciface)
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
void LoadDefaults(const ControllerInterface& ciface);
|
void LoadDefaults(const ControllerInterface& ciface);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Buttons* m_keys[6];
|
Buttons* m_keys[3];
|
||||||
ControlGroup* m_options;
|
ControlGroup* m_options;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ namespace HotkeyManagerEmu
|
|||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
InputConfig* GetConfig();
|
InputConfig* GetConfig();
|
||||||
void GetStatus(u8 _port, HotkeyStatus* _pKeyboardStatus);
|
void GetStatus();
|
||||||
|
bool IsReady();
|
||||||
bool IsPressed(int Id, bool held);
|
bool IsPressed(int Id, bool held);
|
||||||
}
|
}
|
||||||
|
@ -1263,11 +1263,15 @@ const CGameListCtrl *CFrame::GetGameListCtrl() const
|
|||||||
|
|
||||||
void CFrame::PollHotkeys(wxTimerEvent& event)
|
void CFrame::PollHotkeys(wxTimerEvent& event)
|
||||||
{
|
{
|
||||||
|
if (!HotkeyManagerEmu::IsReady())
|
||||||
|
return;
|
||||||
|
|
||||||
if (Core::GetState() == Core::CORE_UNINITIALIZED || Core::GetState() == Core::CORE_PAUSE)
|
if (Core::GetState() == Core::CORE_UNINITIALIZED || Core::GetState() == Core::CORE_PAUSE)
|
||||||
g_controller_interface.UpdateInput();
|
g_controller_interface.UpdateInput();
|
||||||
|
|
||||||
if (Core::GetState() != Core::CORE_STOPPING)
|
if (Core::GetState() != Core::CORE_STOPPING)
|
||||||
{
|
{
|
||||||
|
HotkeyManagerEmu::GetStatus();
|
||||||
wxKeyEvent keyevent = 0;
|
wxKeyEvent keyevent = 0;
|
||||||
|
|
||||||
if (IsHotkey(keyevent, HK_TOGGLE_THROTTLE))
|
if (IsHotkey(keyevent, HK_TOGGLE_THROTTLE))
|
||||||
|
Reference in New Issue
Block a user