std::chrono cleanup: always use steady_clock

This commit is contained in:
Nekotekina 2020-12-11 16:31:32 +03:00
parent 12a48fc6d1
commit aa3aef4beb
19 changed files with 96 additions and 97 deletions

View file

@ -13,7 +13,7 @@ constexpr auto qstr = QString::fromStdString;
bool keyboard_pad_handler::Init()
{
const std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
const steady_clock::time_point now = steady_clock::now();
m_last_mouse_move_left = now;
m_last_mouse_move_right = now;
m_last_mouse_move_up = now;
@ -372,13 +372,13 @@ void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event)
{
Key(mouse::move_right, false);
Key(mouse::move_left, true, std::min(m_deadzone_x + std::abs(movement_x), 255));
m_last_mouse_move_left = std::chrono::steady_clock::now();
m_last_mouse_move_left = steady_clock::now();
}
else if (movement_x > 0)
{
Key(mouse::move_left, false);
Key(mouse::move_right, true, std::min(m_deadzone_x + movement_x, 255));
m_last_mouse_move_right = std::chrono::steady_clock::now();
m_last_mouse_move_right = steady_clock::now();
}
// in Qt mouse up is equivalent to movement_y < 0
@ -386,13 +386,13 @@ void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event)
{
Key(mouse::move_down, false);
Key(mouse::move_up, true, std::min(m_deadzone_y + std::abs(movement_y), 255));
m_last_mouse_move_up = std::chrono::steady_clock::now();
m_last_mouse_move_up = steady_clock::now();
}
else if (movement_y > 0)
{
Key(mouse::move_up, false);
Key(mouse::move_down, true, std::min(m_deadzone_y + movement_y, 255));
m_last_mouse_move_down = std::chrono::steady_clock::now();
m_last_mouse_move_down = steady_clock::now();
}
event->ignore();
@ -415,12 +415,12 @@ void keyboard_pad_handler::mouseWheelEvent(QWheelEvent* event)
if (to_left)
{
Key(mouse::wheel_left, true);
m_last_wheel_move_left = std::chrono::steady_clock::now();
m_last_wheel_move_left = steady_clock::now();
}
else
{
Key(mouse::wheel_right, true);
m_last_wheel_move_right = std::chrono::steady_clock::now();
m_last_wheel_move_right = steady_clock::now();
}
}
if (const int y = direction.y())
@ -430,12 +430,12 @@ void keyboard_pad_handler::mouseWheelEvent(QWheelEvent* event)
if (to_up)
{
Key(mouse::wheel_up, true);
m_last_wheel_move_up = std::chrono::steady_clock::now();
m_last_wheel_move_up = steady_clock::now();
}
else
{
Key(mouse::wheel_down, true);
m_last_wheel_move_down = std::chrono::steady_clock::now();
m_last_wheel_move_down = steady_clock::now();
}
}
}
@ -727,7 +727,7 @@ void keyboard_pad_handler::ThreadProc()
static const double stick_interval = 10.0;
static const double button_interval = 10.0;
const auto now = std::chrono::steady_clock::now();
const auto now = steady_clock::now();
const double elapsed_left = std::chrono::duration_cast<std::chrono::microseconds>(now - m_last_mouse_move_left).count() / 1000.0;
const double elapsed_right = std::chrono::duration_cast<std::chrono::microseconds>(now - m_last_mouse_move_right).count() / 1000.0;

View file

@ -107,12 +107,12 @@ private:
std::vector<std::shared_ptr<Pad>> bindings;
// Button Movements
std::chrono::steady_clock::time_point m_button_time;
steady_clock::time_point m_button_time;
f32 m_analog_lerp_factor = 1.0f;
f32 m_trigger_lerp_factor = 1.0f;
// Stick Movements
std::chrono::steady_clock::time_point m_stick_time;
steady_clock::time_point m_stick_time;
f32 m_l_stick_lerp_factor = 1.0f;
f32 m_r_stick_lerp_factor = 1.0f;
u8 m_stick_min[4] = { 0, 0, 0, 0 };
@ -120,18 +120,18 @@ private:
u8 m_stick_val[4] = { 128, 128, 128, 128 };
// Mouse Movements
std::chrono::steady_clock::time_point m_last_mouse_move_left;
std::chrono::steady_clock::time_point m_last_mouse_move_right;
std::chrono::steady_clock::time_point m_last_mouse_move_up;
std::chrono::steady_clock::time_point m_last_mouse_move_down;
steady_clock::time_point m_last_mouse_move_left;
steady_clock::time_point m_last_mouse_move_right;
steady_clock::time_point m_last_mouse_move_up;
steady_clock::time_point m_last_mouse_move_down;
int m_deadzone_x = 60;
int m_deadzone_y = 60;
double m_multi_x = 2;
double m_multi_y = 2.5;
// Mousewheel
std::chrono::steady_clock::time_point m_last_wheel_move_up;
std::chrono::steady_clock::time_point m_last_wheel_move_down;
std::chrono::steady_clock::time_point m_last_wheel_move_left;
std::chrono::steady_clock::time_point m_last_wheel_move_right;
steady_clock::time_point m_last_wheel_move_up;
steady_clock::time_point m_last_wheel_move_down;
steady_clock::time_point m_last_wheel_move_left;
steady_clock::time_point m_last_wheel_move_right;
};

View file

@ -492,7 +492,7 @@ void xinput_pad_handler::apply_pad_data(const std::shared_ptr<PadDevice>& device
dev->smallVibrate = speed_small;
// XBox One Controller can't handle faster vibration updates than ~10ms. Elite is even worse. So I'll use 20ms to be on the safe side. No lag was noticable.
if (dev->newVibrateData && (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - dev->last_vibration) > 20ms))
if (dev->newVibrateData && steady_clock::now() - dev->last_vibration > 20ms)
{
XINPUT_VIBRATION vibrate;
vibrate.wLeftMotorSpeed = speed_large * 257;
@ -501,7 +501,7 @@ void xinput_pad_handler::apply_pad_data(const std::shared_ptr<PadDevice>& device
if ((*xinputSetState)(padnum, &vibrate) == ERROR_SUCCESS)
{
dev->newVibrateData = false;
dev->last_vibration = std::chrono::high_resolution_clock::now();
dev->last_vibration = steady_clock::now();
}
}
}

View file

@ -92,7 +92,7 @@ class xinput_pad_handler final : public PadHandlerBase
bool newVibrateData{ true };
u16 largeVibrate{ 0 };
u16 smallVibrate{ 0 };
std::chrono::high_resolution_clock::time_point last_vibration;
steady_clock::time_point last_vibration;
bool is_scp_device{ false };
DWORD state{ ERROR_NOT_CONNECTED }; // holds internal controller state change
SCP_EXTN state_scp{ 0 };