mirror of https://github.com/PCSX2/pcsx2.git
Misc: Replace _BitScanForward() with std::countr_zero()
This commit is contained in:
parent
088630a999
commit
7dd1f7321a
|
@ -20,7 +20,6 @@
|
|||
#include "QtHost.h"
|
||||
#include "QtUtils.h"
|
||||
|
||||
#include "pcsx2/GS/GSIntrin.h" // _BitScanForward
|
||||
#include "pcsx2/ImGui/ImGuiManager.h"
|
||||
|
||||
#include "common/Assertions.h"
|
||||
|
@ -32,6 +31,8 @@
|
|||
#include <QtGui/QScreen>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtGui/QWindowStateChangeEvent>
|
||||
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -301,11 +302,12 @@ bool DisplayWidget::event(QEvent* event)
|
|||
case QEvent::MouseButtonDblClick:
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
unsigned long button_index;
|
||||
if (_BitScanForward(&button_index, static_cast<u32>(static_cast<const QMouseEvent*>(event)->button())))
|
||||
if (const u32 button_mask = static_cast<u32>(static_cast<const QMouseEvent*>(event)->button()))
|
||||
{
|
||||
Host::RunOnCPUThread([button_index, pressed = (event->type() != QEvent::MouseButtonRelease)]() {
|
||||
InputManager::InvokeEvents(InputManager::MakePointerButtonKey(0, button_index), static_cast<float>(pressed));
|
||||
Host::RunOnCPUThread([button_index = std::countr_zero(button_mask),
|
||||
pressed = (event->type() != QEvent::MouseButtonRelease)]() {
|
||||
InputManager::InvokeEvents(
|
||||
InputManager::MakePointerButtonKey(0, button_index), static_cast<float>(pressed));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -97,9 +97,8 @@ bool InputBindingDialog::eventFilter(QObject* watched, QEvent* event)
|
|||
else if (event_type == QEvent::MouseButtonPress || event_type == QEvent::MouseButtonDblClick)
|
||||
{
|
||||
// double clicks get triggered if we click bind, then click again quickly.
|
||||
unsigned long button_index;
|
||||
if (_BitScanForward(&button_index, static_cast<u32>(static_cast<const QMouseEvent*>(event)->button())))
|
||||
m_new_bindings.push_back(InputManager::MakePointerButtonKey(0, button_index));
|
||||
if (const u32 button_mask = static_cast<u32>(static_cast<const QMouseEvent*>(event)->button()))
|
||||
m_new_bindings.push_back(InputManager::MakePointerButtonKey(0, std::countr_zero(button_mask)));
|
||||
return true;
|
||||
}
|
||||
else if (event_type == QEvent::Wheel)
|
||||
|
|
|
@ -21,13 +21,12 @@
|
|||
#include <QtGui/QWheelEvent>
|
||||
#include <QtWidgets/QInputDialog>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
#include "pcsx2/Host.h"
|
||||
|
||||
#include "pcsx2/GS/GSIntrin.h" // _BitScanForward
|
||||
|
||||
#include "QtHost.h"
|
||||
#include "QtUtils.h"
|
||||
#include "Settings/ControllerSettingsDialog.h"
|
||||
|
@ -134,9 +133,8 @@ bool InputBindingWidget::eventFilter(QObject* watched, QEvent* event)
|
|||
else if (event_type == QEvent::MouseButtonPress || event_type == QEvent::MouseButtonDblClick)
|
||||
{
|
||||
// double clicks get triggered if we click bind, then click again quickly.
|
||||
unsigned long button_index;
|
||||
if (_BitScanForward(&button_index, static_cast<u32>(static_cast<const QMouseEvent*>(event)->button())))
|
||||
m_new_bindings.push_back(InputManager::MakePointerButtonKey(0, button_index));
|
||||
if (const u32 button_mask = static_cast<u32>(static_cast<const QMouseEvent*>(event)->button()))
|
||||
m_new_bindings.push_back(InputManager::MakePointerButtonKey(0, std::countr_zero(button_mask)));
|
||||
return true;
|
||||
}
|
||||
else if (event_type == QEvent::Wheel)
|
||||
|
|
|
@ -26,10 +26,9 @@
|
|||
#include "common/Path.h"
|
||||
#include "common/StringUtil.h"
|
||||
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
|
||||
#include "GS/GSIntrin.h" // _BitScanForward
|
||||
|
||||
static constexpr const char* CONTROLLER_DB_FILENAME = "game_controller_db.txt";
|
||||
|
||||
static constexpr const char* s_sdl_axis_names[] = {
|
||||
|
@ -776,16 +775,14 @@ bool SDLInputSource::HandleJoystickHatEvent(const SDL_JoyHatEvent* ev)
|
|||
if (it == m_controllers.end() || ev->hat >= it->last_hat_state.size())
|
||||
return false;
|
||||
|
||||
const unsigned long last_direction = it->last_hat_state[ev->hat];
|
||||
const u8 last_direction = it->last_hat_state[ev->hat];
|
||||
it->last_hat_state[ev->hat] = ev->value;
|
||||
|
||||
unsigned long changed_direction = last_direction ^ ev->value;
|
||||
u8 changed_direction = last_direction ^ ev->value;
|
||||
while (changed_direction != 0)
|
||||
{
|
||||
unsigned long pos;
|
||||
_BitScanForward(&pos, changed_direction);
|
||||
|
||||
const unsigned long mask = (1u << pos);
|
||||
const u8 pos = std::countr_zero(changed_direction);
|
||||
const u8 mask = (1u << pos);
|
||||
changed_direction &= ~mask;
|
||||
|
||||
const InputBindingKey key(
|
||||
|
|
Loading…
Reference in New Issue