Make controller button code thread-safe (#405)

* Refactor spinlock to meet Lockable requirements
* Input: Refactor button code and make it thread-safe
This commit is contained in:
Exzap 2022-10-23 15:47:42 +02:00 committed by GitHub
parent c40466f3a8
commit 028b3f7992
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 311 additions and 220 deletions

View file

@ -1,5 +1,6 @@
#include "input/api/Keyboard/KeyboardController.h"
#include <boost/container/small_vector.hpp>
#include "input/api/Keyboard/KeyboardController.h"
#include "gui/guiWrapper.h"
KeyboardController::KeyboardController()
@ -51,7 +52,9 @@ ControllerState KeyboardController::raw_state()
ControllerState result{};
if (g_window_info.app_active)
{
g_window_info.get_keystates(result.buttons);
boost::container::small_vector<uint32, 16> pressedKeys;
g_window_info.iter_keystates([&pressedKeys](const std::pair<const uint32, bool>& keyState) { if (keyState.second) pressedKeys.emplace_back(keyState.first); });
result.buttons.SetPressedButtons(pressedKeys);
}
return result;
}