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

@ -8,8 +8,8 @@ class Timer
{ {
private: private:
bool m_stopped; bool m_stopped;
std::chrono::steady_clock::time_point m_start; steady_clock::time_point m_start;
std::chrono::steady_clock::time_point m_end; steady_clock::time_point m_end;
public: public:
Timer() : m_stopped(false) Timer() : m_stopped(false)
@ -19,13 +19,13 @@ public:
void Start() void Start()
{ {
m_stopped = false; m_stopped = false;
m_start = std::chrono::steady_clock::now(); m_start = steady_clock::now();
} }
void Stop() void Stop()
{ {
m_stopped = true; m_stopped = true;
m_end = std::chrono::steady_clock::now(); m_end = steady_clock::now();
} }
double GetElapsedTimeInSec() const double GetElapsedTimeInSec() const
@ -40,21 +40,21 @@ public:
u64 GetElapsedTimeInMicroSec() const u64 GetElapsedTimeInMicroSec() const
{ {
std::chrono::steady_clock::time_point now = m_stopped ? m_end : std::chrono::steady_clock::now(); steady_clock::time_point now = m_stopped ? m_end : steady_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(now - m_start).count(); return std::chrono::duration_cast<std::chrono::microseconds>(now - m_start).count();
} }
u64 GetElapsedTimeInNanoSec() const u64 GetElapsedTimeInNanoSec() const
{ {
std::chrono::steady_clock::time_point now = m_stopped ? m_end : std::chrono::steady_clock::now(); steady_clock::time_point now = m_stopped ? m_end : steady_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(now - m_start).count(); return std::chrono::duration_cast<std::chrono::nanoseconds>(now - m_start).count();
} }
u64 GetMsSince(std::chrono::steady_clock::time_point timestamp) u64 GetMsSince(steady_clock::time_point timestamp)
{ {
std::chrono::steady_clock::time_point now = m_stopped ? m_end : std::chrono::steady_clock::now(); steady_clock::time_point now = m_stopped ? m_end : steady_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(now - timestamp).count(); return std::chrono::duration_cast<std::chrono::milliseconds>(now - timestamp).count();
} }

View file

@ -17,6 +17,10 @@
#include <limits> #include <limits>
#include <array> #include <array>
using std::chrono::steady_clock;
using namespace std::literals;
#ifdef _MSC_VER #ifdef _MSC_VER
#if !defined(__cpp_lib_bitops) && _MSC_VER < 1928 #if !defined(__cpp_lib_bitops) && _MSC_VER < 1928
#define __cpp_lib_bitops #define __cpp_lib_bitops
@ -43,9 +47,6 @@
#define CHECK_MAX_SIZE(type, size) static_assert(sizeof(type) <= size, #type " type size is too big") #define CHECK_MAX_SIZE(type, size) static_assert(sizeof(type) <= size, #type " type size is too big")
#define CHECK_SIZE_ALIGN(type, size, align) CHECK_SIZE(type, size); CHECK_ALIGN(type, align) #define CHECK_SIZE_ALIGN(type, size, align) CHECK_SIZE(type, size); CHECK_ALIGN(type, align)
// Variant pattern matching helper
#define MATCH(arg, ...) constexpr(std::is_same_v<std::decay_t<decltype(arg)>, __VA_ARGS__>)
#define DECLARE(...) decltype(__VA_ARGS__) __VA_ARGS__ #define DECLARE(...) decltype(__VA_ARGS__) __VA_ARGS__
#define STR_CASE(...) case __VA_ARGS__: return #__VA_ARGS__ #define STR_CASE(...) case __VA_ARGS__: return #__VA_ARGS__
@ -149,10 +150,6 @@ namespace std
} }
#endif #endif
using steady_clock = std::conditional<
std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock, std::chrono::steady_clock>::type;
// Get integral type from type size // Get integral type from type size
template <std::size_t N> template <std::size_t N>
struct get_int_impl struct get_int_impl

View file

@ -339,10 +339,10 @@ error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
{ {
// report back new data every ~10 ms even if the input doesn't change // report back new data every ~10 ms even if the input doesn't change
// this is observed behaviour when using a Dualshock 3 controller // this is observed behaviour when using a Dualshock 3 controller
static std::array<std::chrono::time_point<steady_clock>, CELL_PAD_MAX_PORT_NUM> last_update = { }; static std::array<steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> last_update = { };
const std::chrono::time_point<steady_clock> now = steady_clock::now(); const auto now = steady_clock::now();
if (btnChanged || pad->m_buffer_cleared || (std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update[port_no]).count() >= 10)) if (btnChanged || pad->m_buffer_cleared || now - last_update[port_no] >= 10ms)
{ {
data->len = CELL_PAD_LEN_CHANGE_SENSOR_ON; data->len = CELL_PAD_LEN_CHANGE_SENSOR_ON;
last_update[port_no] = now; last_update[port_no] = now;

View file

@ -11,6 +11,7 @@
#include "sceNp.h" #include "sceNp.h"
#include "cellSysutil.h" #include "cellSysutil.h"
#include "Emu/Cell/lv2/sys_time.h"
#include "Emu/NP/np_handler.h" #include "Emu/NP/np_handler.h"
#include "Emu/NP/np_contexts.h" #include "Emu/NP/np_contexts.h"
@ -2519,9 +2520,18 @@ error_code sceNpManagerGetNetworkTime(vm::ptr<CellRtcTick> pTick)
return SCE_NP_ERROR_INVALID_STATE; return SCE_NP_ERROR_INVALID_STATE;
} }
auto now = std::chrono::system_clock::now(); vm::var<s64> sec;
// That's assuming epoch is unix epoch which is not actually standardized, god I hate you C++ std vm::var<s64> nsec;
pTick->tick = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() + (62135596800 * 1000 * 1000);
error_code ret = sys_time_get_current_time(sec, nsec);
if (ret != CELL_OK)
{
return ret;
}
// Taken from cellRtc
pTick->tick = *nsec / 1000 + *sec * cellRtcGetTickResolution() + 62135596800000000ULL;
return CELL_OK; return CELL_OK;
} }

View file

@ -305,7 +305,7 @@ public:
{ {
std::lock_guard lock(data_mutex); std::lock_guard lock(data_mutex);
const auto now = std::chrono::system_clock::now(); const auto now = steady_clock::now();
message msg; message msg;
msg.dst_addr = *dst; msg.dst_addr = *dst;
@ -328,7 +328,7 @@ public:
std::lock_guard lock(data_mutex); std::lock_guard lock(data_mutex);
rtts[sock_id].num_retries = 0; rtts[sock_id].num_retries = 0;
const auto now = std::chrono::system_clock::now(); const auto now = steady_clock::now();
for (auto it = msgs.begin(); it != msgs.end();) for (auto it = msgs.begin(); it != msgs.end();)
{ {
@ -366,7 +366,7 @@ public:
if (thread_ctrl::state() == thread_state::aborting) if (thread_ctrl::state() == thread_state::aborting)
return; return;
const auto now = std::chrono::system_clock::now(); const auto now = steady_clock::now();
// Check for messages that haven't been acked // Check for messages that haven't been acked
std::set<s32> rtt_increased; std::set<s32> rtt_increased;
for (auto it = msgs.begin(); it != msgs.end();) for (auto it = msgs.begin(); it != msgs.end();)
@ -442,9 +442,9 @@ public:
::sockaddr_in dst_addr; ::sockaddr_in dst_addr;
std::vector<u8> data; std::vector<u8> data;
u64 seq; u64 seq;
std::chrono::time_point<std::chrono::system_clock> initial_sendtime; steady_clock::time_point initial_sendtime;
}; };
std::map<std::chrono::time_point<std::chrono::system_clock>, message> msgs; // (wakeup time, msg) std::map<steady_clock::time_point, message> msgs; // (wakeup time, msg)
// List of rtts // List of rtts
struct rtt_info struct rtt_info
{ {

View file

@ -135,12 +135,12 @@ class MouseHandlerBase
protected: protected:
MouseInfo m_info; MouseInfo m_info;
std::vector<Mouse> m_mice; std::vector<Mouse> m_mice;
std::chrono::steady_clock::time_point last_update; steady_clock::time_point last_update;
bool is_time_for_update(double elapsed_time = 10.0) // 4-10 ms, let's use 10 for now bool is_time_for_update(double elapsed_time = 10.0) // 4-10 ms, let's use 10 for now
{ {
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); steady_clock::time_point now = steady_clock::now();
double elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now - last_update).count() / 1000.0; double elapsed = (now - last_update).count() / 1000'000.;
if (elapsed > elapsed_time) if (elapsed > elapsed_time)
{ {

View file

@ -305,7 +305,7 @@ bool rpcn_client::connect(const std::string& host)
return false; return false;
} }
last_ping_time = std::chrono::system_clock::now() - std::chrono::seconds(5); last_ping_time = steady_clock::now() - 5s;
last_pong_time = last_ping_time; last_pong_time = last_ping_time;
return true; return true;
@ -349,9 +349,9 @@ bool rpcn_client::login(const std::string& npid, const std::string& password, co
// Make sure signaling works // Make sure signaling works
if (!in_config) if (!in_config)
{ {
auto start = std::chrono::system_clock::now(); auto start = steady_clock::now();
while (!get_addr_sig() && (std::chrono::system_clock::now() - start) < std::chrono::seconds(5)) while (!get_addr_sig() && steady_clock::now() - start < 5s)
{ {
std::this_thread::sleep_for(5ms); std::this_thread::sleep_for(5ms);
} }
@ -409,7 +409,7 @@ bool rpcn_client::manage_connection()
if (authentified && !in_config) if (authentified && !in_config)
{ {
// Ping the UDP Signaling Server // Ping the UDP Signaling Server
auto now = std::chrono::system_clock::now(); auto now = steady_clock::now();
auto rpcn_msgs = get_rpcn_msgs(); auto rpcn_msgs = get_rpcn_msgs();
@ -432,7 +432,7 @@ bool rpcn_client::manage_connection()
} }
// Send a packet every 5 seconds and then every 500 ms until reply is received // Send a packet every 5 seconds and then every 500 ms until reply is received
if ((now - last_pong_time) > std::chrono::seconds(5) && (now - last_ping_time) > std::chrono::milliseconds(500)) if (now - last_pong_time > 5s && now - last_ping_time > 500ms)
{ {
std::vector<u8> ping(9); std::vector<u8> ping(9);
ping[0] = 1; ping[0] = 1;

View file

@ -236,7 +236,7 @@ protected:
u32 received_version = 0; u32 received_version = 0;
// UDP Signaling related // UDP Signaling related
std::chrono::time_point<std::chrono::system_clock> last_ping_time{}, last_pong_time{}; steady_clock::time_point last_ping_time{}, last_pong_time{};
sockaddr_in addr_rpcn{}; sockaddr_in addr_rpcn{};
sockaddr_in addr_rpcn_udp{}; sockaddr_in addr_rpcn_udp{};

View file

@ -111,7 +111,7 @@ void signaling_handler::signal_sig2_callback(u64 room_id, u16 member_id, SceNpMa
//// SIGNALING MSGS PROCESSING //// //// SIGNALING MSGS PROCESSING ////
/////////////////////////////////// ///////////////////////////////////
void signaling_handler::reschedule_packet(std::shared_ptr<signaling_info>& si, SignalingCommand cmd, std::chrono::time_point<std::chrono::system_clock> new_timepoint) void signaling_handler::reschedule_packet(std::shared_ptr<signaling_info>& si, SignalingCommand cmd, steady_clock::time_point new_timepoint)
{ {
for (auto it = qpackets.begin(); it != qpackets.end(); it++) for (auto it = qpackets.begin(); it != qpackets.end(); it++)
{ {
@ -229,7 +229,7 @@ void signaling_handler::process_incoming_messages()
continue; continue;
} }
const auto now = std::chrono::system_clock::now(); const auto now = steady_clock::now();
if (si) if (si)
si->time_last_msg_recvd = now; si->time_last_msg_recvd = now;
@ -257,7 +257,7 @@ void signaling_handler::process_incoming_messages()
case signal_pong: case signal_pong:
reply = false; reply = false;
schedule_repeat = false; schedule_repeat = false;
reschedule_packet(si, signal_ping, now + std::chrono::seconds(15)); reschedule_packet(si, signal_ping, now + 15s);
break; break;
case signal_connect: case signal_connect:
reply = true; reply = true;
@ -324,14 +324,14 @@ void signaling_handler::operator()()
process_incoming_messages(); process_incoming_messages();
const auto now = std::chrono::system_clock::now(); const auto now = steady_clock::now();
for (auto it = qpackets.begin(); it != qpackets.end();) for (auto it = qpackets.begin(); it != qpackets.end();)
{ {
if (it->first > now) if (it->first > now)
break; break;
if (it->second.sig_info->time_last_msg_recvd < now - std::chrono::seconds(60)) if (it->second.sig_info->time_last_msg_recvd < now - 60s)
{ {
// We had no connection to opponent for 60 seconds, consider the connection dead // We had no connection to opponent for 60 seconds, consider the connection dead
sign_log.trace("Timeout disconnection"); sign_log.trace("Timeout disconnection");
@ -461,7 +461,7 @@ void signaling_handler::send_signaling_packet(signaling_packet& sp, u32 addr, u1
} }
} }
void signaling_handler::queue_signaling_packet(signaling_packet& sp, std::shared_ptr<signaling_info> si, std::chrono::time_point<std::chrono::system_clock> wakeup_time) void signaling_handler::queue_signaling_packet(signaling_packet& sp, std::shared_ptr<signaling_info> si, steady_clock::time_point wakeup_time)
{ {
queued_packet qp; queued_packet qp;
qp.sig_info = si; qp.sig_info = si;
@ -517,7 +517,7 @@ void signaling_handler::start_sig_nl(u32 conn_id, u32 addr, u16 port)
si->port = port; si->port = port;
send_signaling_packet(sent_packet, si->addr, si->port); send_signaling_packet(sent_packet, si->addr, si->port);
queue_signaling_packet(sent_packet, si, std::chrono::system_clock::now() + REPEAT_CONNECT_DELAY); queue_signaling_packet(sent_packet, si, steady_clock::now() + REPEAT_CONNECT_DELAY);
} }
void signaling_handler::start_sig2(u64 room_id, u16 member_id) void signaling_handler::start_sig2(u64 room_id, u16 member_id)
@ -530,7 +530,7 @@ void signaling_handler::start_sig2(u64 room_id, u16 member_id)
auto si = sig2_peers.at(room_id).at(member_id); auto si = sig2_peers.at(room_id).at(member_id);
send_signaling_packet(sent_packet, si->addr, si->port); send_signaling_packet(sent_packet, si->addr, si->port);
queue_signaling_packet(sent_packet, si, std::chrono::system_clock::now() + REPEAT_CONNECT_DELAY); queue_signaling_packet(sent_packet, si, steady_clock::now() + REPEAT_CONNECT_DELAY);
} }
void signaling_handler::disconnect_sig2_users(u64 room_id) void signaling_handler::disconnect_sig2_users(u64 room_id)
@ -550,7 +550,7 @@ void signaling_handler::disconnect_sig2_users(u64 room_id)
if (si->connStatus != SCE_NP_SIGNALING_CONN_STATUS_INACTIVE && !si->self) if (si->connStatus != SCE_NP_SIGNALING_CONN_STATUS_INACTIVE && !si->self)
{ {
send_signaling_packet(sent_packet, si->addr, si->port); send_signaling_packet(sent_packet, si->addr, si->port);
queue_signaling_packet(sent_packet, si, std::chrono::system_clock::now() + REPEAT_FINISHED_DELAY); queue_signaling_packet(sent_packet, si, steady_clock::now() + REPEAT_FINISHED_DELAY);
} }
} }
} }

View file

@ -23,15 +23,16 @@ struct signaling_info
u16 port = 0; u16 port = 0;
// For handler // For handler
std::chrono::time_point<std::chrono::system_clock> time_last_msg_recvd = std::chrono::system_clock::now(); steady_clock::time_point time_last_msg_recvd = steady_clock::now();
bool self = false;
u32 version = 0; bool self = false;
u32 version = 0;
// Signaling // Signaling
u32 conn_id = 0; u32 conn_id = 0;
ext_signaling_status ext_status = ext_sign_none; ext_signaling_status ext_status = ext_sign_none;
// Matching2 // Matching2
u64 room_id = 0; u64 room_id = 0;
u16 member_id = 0; u16 member_id = 0;
}; };
enum SignalingCommand : u32 enum SignalingCommand : u32
@ -128,7 +129,7 @@ private:
private: private:
bool validate_signaling_packet(const signaling_packet* sp); bool validate_signaling_packet(const signaling_packet* sp);
void reschedule_packet(std::shared_ptr<signaling_info>& si, SignalingCommand cmd, std::chrono::time_point<std::chrono::system_clock> new_timepoint); void reschedule_packet(std::shared_ptr<signaling_info>& si, SignalingCommand cmd, steady_clock::time_point new_timepoint);
void retire_packet(std::shared_ptr<signaling_info>& si, SignalingCommand cmd); void retire_packet(std::shared_ptr<signaling_info>& si, SignalingCommand cmd);
void retire_all_packets(std::shared_ptr<signaling_info>& si); void retire_all_packets(std::shared_ptr<signaling_info>& si);
@ -139,7 +140,7 @@ private:
signaling_packet sig1_packet{.version = 1u}; signaling_packet sig1_packet{.version = 1u};
signaling_packet sig2_packet{.version = 2u}; signaling_packet sig2_packet{.version = 2u};
std::map<std::chrono::time_point<std::chrono::system_clock>, queued_packet> qpackets; // (wakeup time, packet) std::map<steady_clock::time_point, queued_packet> qpackets; // (wakeup time, packet)
u32 cur_conn_id = 1; u32 cur_conn_id = 1;
std::unordered_map<std::string, u32> npid_to_conn_id; // (npid, conn_id) std::unordered_map<std::string, u32> npid_to_conn_id; // (npid, conn_id)
@ -150,5 +151,5 @@ private:
void process_incoming_messages(); void process_incoming_messages();
std::shared_ptr<signaling_info> get_signaling_ptr(const signaling_packet* sp); std::shared_ptr<signaling_info> get_signaling_ptr(const signaling_packet* sp);
void send_signaling_packet(signaling_packet& sp, u32 addr, u16 port); void send_signaling_packet(signaling_packet& sp, u32 addr, u16 port);
void queue_signaling_packet(signaling_packet& sp, std::shared_ptr<signaling_info> si, std::chrono::time_point<std::chrono::system_clock> wakeup_time); void queue_signaling_packet(signaling_packet& sp, std::shared_ptr<signaling_info> si, steady_clock::time_point wakeup_time);
}; };

View file

@ -44,12 +44,12 @@ namespace rsx
s32 user_interface::run_input_loop() s32 user_interface::run_input_loop()
{ {
const u64 ms_interval = 200; const u64 ms_interval = 200;
std::array<std::chrono::steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> timestamp; std::array<steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> timestamp;
timestamp.fill(std::chrono::steady_clock::now()); timestamp.fill(steady_clock::now());
const u64 ms_threshold = 500; const u64 ms_threshold = 500;
std::array<std::chrono::steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> initial_timestamp; std::array<steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> initial_timestamp;
initial_timestamp.fill(std::chrono::steady_clock::now()); initial_timestamp.fill(steady_clock::now());
std::array<std::array<bool, pad_button::pad_button_max_enum>, CELL_PAD_MAX_PORT_NUM> button_state; std::array<std::array<bool, pad_button::pad_button_max_enum>, CELL_PAD_MAX_PORT_NUM> button_state;
for (auto& state : button_state) for (auto& state : button_state)
@ -155,14 +155,14 @@ namespace rsx
if (!button_state[pad_index][button_id]) if (!button_state[pad_index][button_id])
{ {
// the d-pad button was not pressed before, so this is a new button press // the d-pad button was not pressed before, so this is a new button press
timestamp[pad_index] = std::chrono::steady_clock::now(); timestamp[pad_index] = steady_clock::now();
initial_timestamp[pad_index] = timestamp[pad_index]; initial_timestamp[pad_index] = timestamp[pad_index];
on_button_pressed(static_cast<pad_button>(button_id)); on_button_pressed(static_cast<pad_button>(button_id));
} }
else if (input_timer.GetMsSince(initial_timestamp[pad_index]) > ms_threshold && input_timer.GetMsSince(timestamp[pad_index]) > ms_interval) else if (input_timer.GetMsSince(initial_timestamp[pad_index]) > ms_threshold && input_timer.GetMsSince(timestamp[pad_index]) > ms_interval)
{ {
// the d-pad button was pressed for at least the given threshold in ms and will trigger at an interval // the d-pad button was pressed for at least the given threshold in ms and will trigger at an interval
timestamp[pad_index] = std::chrono::steady_clock::now(); timestamp[pad_index] = steady_clock::now();
on_button_pressed(static_cast<pad_button>(button_id)); on_button_pressed(static_cast<pad_button>(button_id));
} }
} }

View file

@ -496,7 +496,7 @@ namespace rsx
if (nb_workers == 1) if (nb_workers == 1)
{ {
std::chrono::time_point<steady_clock> last_update; steady_clock::time_point last_update;
// Call the worker function directly, stoping it prematurely to be able update the screen // Call the worker function directly, stoping it prematurely to be able update the screen
u8 inc = 10; u8 inc = 10;
@ -508,7 +508,7 @@ namespace rsx
worker(stop_at); worker(stop_at);
// Only update the screen at about 10fps since updating it everytime slows down the process // Only update the screen at about 10fps since updating it everytime slows down the process
std::chrono::time_point<steady_clock> now = std::chrono::steady_clock::now(); steady_clock::time_point now = steady_clock::now();
processed_since_last_update += inc; processed_since_last_update += inc;
if ((std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update) > 100ms) || (stop_at == entry_count)) if ((std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update) > 100ms) || (stop_at == entry_count))
{ {

View file

@ -1195,7 +1195,7 @@ namespace rsx
struct profiling_timer struct profiling_timer
{ {
bool enabled = false; bool enabled = false;
std::chrono::time_point<steady_clock> last; steady_clock::time_point last;
profiling_timer() = default; profiling_timer() = default;

View file

@ -13,7 +13,7 @@ constexpr auto qstr = QString::fromStdString;
bool keyboard_pad_handler::Init() 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_left = now;
m_last_mouse_move_right = now; m_last_mouse_move_right = now;
m_last_mouse_move_up = 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_right, false);
Key(mouse::move_left, true, std::min(m_deadzone_x + std::abs(movement_x), 255)); 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) else if (movement_x > 0)
{ {
Key(mouse::move_left, false); Key(mouse::move_left, false);
Key(mouse::move_right, true, std::min(m_deadzone_x + movement_x, 255)); 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 // 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_down, false);
Key(mouse::move_up, true, std::min(m_deadzone_y + std::abs(movement_y), 255)); 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) else if (movement_y > 0)
{ {
Key(mouse::move_up, false); Key(mouse::move_up, false);
Key(mouse::move_down, true, std::min(m_deadzone_y + movement_y, 255)); 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(); event->ignore();
@ -415,12 +415,12 @@ void keyboard_pad_handler::mouseWheelEvent(QWheelEvent* event)
if (to_left) if (to_left)
{ {
Key(mouse::wheel_left, true); Key(mouse::wheel_left, true);
m_last_wheel_move_left = std::chrono::steady_clock::now(); m_last_wheel_move_left = steady_clock::now();
} }
else else
{ {
Key(mouse::wheel_right, true); 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()) if (const int y = direction.y())
@ -430,12 +430,12 @@ void keyboard_pad_handler::mouseWheelEvent(QWheelEvent* event)
if (to_up) if (to_up)
{ {
Key(mouse::wheel_up, true); Key(mouse::wheel_up, true);
m_last_wheel_move_up = std::chrono::steady_clock::now(); m_last_wheel_move_up = steady_clock::now();
} }
else else
{ {
Key(mouse::wheel_down, true); 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 stick_interval = 10.0;
static const double button_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_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; 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; std::vector<std::shared_ptr<Pad>> bindings;
// Button Movements // 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_analog_lerp_factor = 1.0f;
f32 m_trigger_lerp_factor = 1.0f; f32 m_trigger_lerp_factor = 1.0f;
// Stick Movements // 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_l_stick_lerp_factor = 1.0f;
f32 m_r_stick_lerp_factor = 1.0f; f32 m_r_stick_lerp_factor = 1.0f;
u8 m_stick_min[4] = { 0, 0, 0, 0 }; u8 m_stick_min[4] = { 0, 0, 0, 0 };
@ -120,18 +120,18 @@ private:
u8 m_stick_val[4] = { 128, 128, 128, 128 }; u8 m_stick_val[4] = { 128, 128, 128, 128 };
// Mouse Movements // Mouse Movements
std::chrono::steady_clock::time_point m_last_mouse_move_left; steady_clock::time_point m_last_mouse_move_left;
std::chrono::steady_clock::time_point m_last_mouse_move_right; steady_clock::time_point m_last_mouse_move_right;
std::chrono::steady_clock::time_point m_last_mouse_move_up; 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_down;
int m_deadzone_x = 60; int m_deadzone_x = 60;
int m_deadzone_y = 60; int m_deadzone_y = 60;
double m_multi_x = 2; double m_multi_x = 2;
double m_multi_y = 2.5; double m_multi_y = 2.5;
// Mousewheel // Mousewheel
std::chrono::steady_clock::time_point m_last_wheel_move_up; steady_clock::time_point m_last_wheel_move_up;
std::chrono::steady_clock::time_point m_last_wheel_move_down; steady_clock::time_point m_last_wheel_move_down;
std::chrono::steady_clock::time_point m_last_wheel_move_left; 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_right;
}; };

View file

@ -492,7 +492,7 @@ void xinput_pad_handler::apply_pad_data(const std::shared_ptr<PadDevice>& device
dev->smallVibrate = speed_small; 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. // 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; XINPUT_VIBRATION vibrate;
vibrate.wLeftMotorSpeed = speed_large * 257; 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) if ((*xinputSetState)(padnum, &vibrate) == ERROR_SUCCESS)
{ {
dev->newVibrateData = false; 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 }; bool newVibrateData{ true };
u16 largeVibrate{ 0 }; u16 largeVibrate{ 0 };
u16 smallVibrate{ 0 }; u16 smallVibrate{ 0 };
std::chrono::high_resolution_clock::time_point last_vibration; steady_clock::time_point last_vibration;
bool is_scp_device{ false }; bool is_scp_device{ false };
DWORD state{ ERROR_NOT_CONNECTED }; // holds internal controller state change DWORD state{ ERROR_NOT_CONNECTED }; // holds internal controller state change
SCP_EXTN state_scp{ 0 }; SCP_EXTN state_scp{ 0 };

View file

@ -13,13 +13,6 @@
#include "define_new_memleakdetect.h" #include "define_new_memleakdetect.h"
#endif #endif
#pragma warning( disable : 4351 )
// MSVC bug workaround
#ifdef _MSC_VER
namespace std { inline namespace literals { inline namespace chrono_literals {}}}
#endif
#include "Utilities/types.h" #include "Utilities/types.h"
#include "Utilities/BEType.h" #include "Utilities/BEType.h"
#include "util/atomic.hpp" #include "util/atomic.hpp"
@ -39,5 +32,3 @@ namespace std { inline namespace literals { inline namespace chrono_literals {}}
#include <unordered_map> #include <unordered_map>
#include <algorithm> #include <algorithm>
#include <string_view> #include <string_view>
using namespace std::literals;

View file

@ -137,7 +137,7 @@ namespace logs
QueryPerformanceCounter(&start); QueryPerformanceCounter(&start);
} }
#else #else
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); steady_clock::time_point start = steady_clock::now();
#endif #endif
u64 get() const u64 get() const
@ -148,7 +148,7 @@ namespace logs
const LONGLONG diff = now.QuadPart - start.QuadPart; const LONGLONG diff = now.QuadPart - start.QuadPart;
return diff / freq.QuadPart * 1'000'000 + diff % freq.QuadPart * 1'000'000 / freq.QuadPart; return diff / freq.QuadPart * 1'000'000 + diff % freq.QuadPart * 1'000'000 / freq.QuadPart;
#else #else
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count(); return (steady_clock::now() - start).count() / 1000;
#endif #endif
} }
} timebase{}; } timebase{};