mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
std::chrono cleanup: always use steady_clock
This commit is contained in:
parent
12a48fc6d1
commit
aa3aef4beb
@ -8,8 +8,8 @@ class Timer
|
||||
{
|
||||
private:
|
||||
bool m_stopped;
|
||||
std::chrono::steady_clock::time_point m_start;
|
||||
std::chrono::steady_clock::time_point m_end;
|
||||
steady_clock::time_point m_start;
|
||||
steady_clock::time_point m_end;
|
||||
|
||||
public:
|
||||
Timer() : m_stopped(false)
|
||||
@ -19,13 +19,13 @@ public:
|
||||
void Start()
|
||||
{
|
||||
m_stopped = false;
|
||||
m_start = std::chrono::steady_clock::now();
|
||||
m_start = steady_clock::now();
|
||||
}
|
||||
|
||||
void Stop()
|
||||
{
|
||||
m_stopped = true;
|
||||
m_end = std::chrono::steady_clock::now();
|
||||
m_end = steady_clock::now();
|
||||
}
|
||||
|
||||
double GetElapsedTimeInSec() const
|
||||
@ -40,21 +40,21 @@ public:
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -17,6 +17,10 @@
|
||||
#include <limits>
|
||||
#include <array>
|
||||
|
||||
using std::chrono::steady_clock;
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if !defined(__cpp_lib_bitops) && _MSC_VER < 1928
|
||||
#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_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 STR_CASE(...) case __VA_ARGS__: return #__VA_ARGS__
|
||||
@ -149,10 +150,6 @@ namespace std
|
||||
}
|
||||
#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
|
||||
template <std::size_t N>
|
||||
struct get_int_impl
|
||||
|
@ -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
|
||||
// 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 = { };
|
||||
const std::chrono::time_point<steady_clock> now = steady_clock::now();
|
||||
static std::array<steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> last_update = { };
|
||||
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;
|
||||
last_update[port_no] = now;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "sceNp.h"
|
||||
#include "cellSysutil.h"
|
||||
|
||||
#include "Emu/Cell/lv2/sys_time.h"
|
||||
#include "Emu/NP/np_handler.h"
|
||||
#include "Emu/NP/np_contexts.h"
|
||||
|
||||
@ -2519,9 +2520,18 @@ error_code sceNpManagerGetNetworkTime(vm::ptr<CellRtcTick> pTick)
|
||||
return SCE_NP_ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
auto now = std::chrono::system_clock::now();
|
||||
// That's assuming epoch is unix epoch which is not actually standardized, god I hate you C++ std
|
||||
pTick->tick = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() + (62135596800 * 1000 * 1000);
|
||||
vm::var<s64> sec;
|
||||
vm::var<s64> nsec;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ public:
|
||||
{
|
||||
std::lock_guard lock(data_mutex);
|
||||
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto now = steady_clock::now();
|
||||
|
||||
message msg;
|
||||
msg.dst_addr = *dst;
|
||||
@ -328,7 +328,7 @@ public:
|
||||
std::lock_guard lock(data_mutex);
|
||||
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();)
|
||||
{
|
||||
@ -366,7 +366,7 @@ public:
|
||||
if (thread_ctrl::state() == thread_state::aborting)
|
||||
return;
|
||||
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto now = steady_clock::now();
|
||||
// Check for messages that haven't been acked
|
||||
std::set<s32> rtt_increased;
|
||||
for (auto it = msgs.begin(); it != msgs.end();)
|
||||
@ -442,9 +442,9 @@ public:
|
||||
::sockaddr_in dst_addr;
|
||||
std::vector<u8> data;
|
||||
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
|
||||
struct rtt_info
|
||||
{
|
||||
|
@ -135,12 +135,12 @@ class MouseHandlerBase
|
||||
protected:
|
||||
MouseInfo m_info;
|
||||
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
|
||||
{
|
||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
double elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now - last_update).count() / 1000.0;
|
||||
steady_clock::time_point now = steady_clock::now();
|
||||
double elapsed = (now - last_update).count() / 1000'000.;
|
||||
|
||||
if (elapsed > elapsed_time)
|
||||
{
|
||||
|
@ -305,7 +305,7 @@ bool rpcn_client::connect(const std::string& host)
|
||||
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;
|
||||
|
||||
return true;
|
||||
@ -349,9 +349,9 @@ bool rpcn_client::login(const std::string& npid, const std::string& password, co
|
||||
// Make sure signaling works
|
||||
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);
|
||||
}
|
||||
@ -409,7 +409,7 @@ bool rpcn_client::manage_connection()
|
||||
if (authentified && !in_config)
|
||||
{
|
||||
// Ping the UDP Signaling Server
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto now = steady_clock::now();
|
||||
|
||||
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
|
||||
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);
|
||||
ping[0] = 1;
|
||||
|
@ -236,7 +236,7 @@ protected:
|
||||
u32 received_version = 0;
|
||||
|
||||
// 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_udp{};
|
||||
|
@ -111,7 +111,7 @@ void signaling_handler::signal_sig2_callback(u64 room_id, u16 member_id, SceNpMa
|
||||
//// 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++)
|
||||
{
|
||||
@ -229,7 +229,7 @@ void signaling_handler::process_incoming_messages()
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto now = steady_clock::now();
|
||||
if (si)
|
||||
si->time_last_msg_recvd = now;
|
||||
|
||||
@ -257,7 +257,7 @@ void signaling_handler::process_incoming_messages()
|
||||
case signal_pong:
|
||||
reply = false;
|
||||
schedule_repeat = false;
|
||||
reschedule_packet(si, signal_ping, now + std::chrono::seconds(15));
|
||||
reschedule_packet(si, signal_ping, now + 15s);
|
||||
break;
|
||||
case signal_connect:
|
||||
reply = true;
|
||||
@ -324,14 +324,14 @@ void signaling_handler::operator()()
|
||||
|
||||
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();)
|
||||
{
|
||||
if (it->first > now)
|
||||
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
|
||||
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;
|
||||
qp.sig_info = si;
|
||||
@ -517,7 +517,7 @@ void signaling_handler::start_sig_nl(u32 conn_id, u32 addr, u16 port)
|
||||
si->port = 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)
|
||||
@ -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);
|
||||
|
||||
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)
|
||||
@ -550,7 +550,7 @@ void signaling_handler::disconnect_sig2_users(u64 room_id)
|
||||
if (si->connStatus != SCE_NP_SIGNALING_CONN_STATUS_INACTIVE && !si->self)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,16 @@ struct signaling_info
|
||||
u16 port = 0;
|
||||
|
||||
// For handler
|
||||
std::chrono::time_point<std::chrono::system_clock> time_last_msg_recvd = std::chrono::system_clock::now();
|
||||
bool self = false;
|
||||
u32 version = 0;
|
||||
steady_clock::time_point time_last_msg_recvd = steady_clock::now();
|
||||
|
||||
bool self = false;
|
||||
u32 version = 0;
|
||||
// Signaling
|
||||
u32 conn_id = 0;
|
||||
ext_signaling_status ext_status = ext_sign_none;
|
||||
u32 conn_id = 0;
|
||||
ext_signaling_status ext_status = ext_sign_none;
|
||||
// Matching2
|
||||
u64 room_id = 0;
|
||||
u16 member_id = 0;
|
||||
u64 room_id = 0;
|
||||
u16 member_id = 0;
|
||||
};
|
||||
|
||||
enum SignalingCommand : u32
|
||||
@ -128,7 +129,7 @@ private:
|
||||
|
||||
private:
|
||||
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_all_packets(std::shared_ptr<signaling_info>& si);
|
||||
|
||||
@ -139,7 +140,7 @@ private:
|
||||
signaling_packet sig1_packet{.version = 1u};
|
||||
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;
|
||||
std::unordered_map<std::string, u32> npid_to_conn_id; // (npid, conn_id)
|
||||
@ -150,5 +151,5 @@ private:
|
||||
void process_incoming_messages();
|
||||
std::shared_ptr<signaling_info> get_signaling_ptr(const signaling_packet* sp);
|
||||
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);
|
||||
};
|
||||
|
@ -44,12 +44,12 @@ namespace rsx
|
||||
s32 user_interface::run_input_loop()
|
||||
{
|
||||
const u64 ms_interval = 200;
|
||||
std::array<std::chrono::steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> timestamp;
|
||||
timestamp.fill(std::chrono::steady_clock::now());
|
||||
std::array<steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> timestamp;
|
||||
timestamp.fill(steady_clock::now());
|
||||
|
||||
const u64 ms_threshold = 500;
|
||||
std::array<std::chrono::steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> initial_timestamp;
|
||||
initial_timestamp.fill(std::chrono::steady_clock::now());
|
||||
std::array<steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> initial_timestamp;
|
||||
initial_timestamp.fill(steady_clock::now());
|
||||
|
||||
std::array<std::array<bool, pad_button::pad_button_max_enum>, CELL_PAD_MAX_PORT_NUM> button_state;
|
||||
for (auto& state : button_state)
|
||||
@ -155,14 +155,14 @@ namespace rsx
|
||||
if (!button_state[pad_index][button_id])
|
||||
{
|
||||
// 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];
|
||||
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)
|
||||
{
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ namespace rsx
|
||||
|
||||
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
|
||||
u8 inc = 10;
|
||||
@ -508,7 +508,7 @@ namespace rsx
|
||||
worker(stop_at);
|
||||
|
||||
// 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;
|
||||
if ((std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update) > 100ms) || (stop_at == entry_count))
|
||||
{
|
||||
|
@ -1195,7 +1195,7 @@ namespace rsx
|
||||
struct profiling_timer
|
||||
{
|
||||
bool enabled = false;
|
||||
std::chrono::time_point<steady_clock> last;
|
||||
steady_clock::time_point last;
|
||||
|
||||
profiling_timer() = default;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 };
|
||||
|
@ -13,13 +13,6 @@
|
||||
#include "define_new_memleakdetect.h"
|
||||
#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/BEType.h"
|
||||
#include "util/atomic.hpp"
|
||||
@ -39,5 +32,3 @@ namespace std { inline namespace literals { inline namespace chrono_literals {}}
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
using namespace std::literals;
|
||||
|
@ -137,7 +137,7 @@ namespace logs
|
||||
QueryPerformanceCounter(&start);
|
||||
}
|
||||
#else
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
steady_clock::time_point start = steady_clock::now();
|
||||
#endif
|
||||
|
||||
u64 get() const
|
||||
@ -148,7 +148,7 @@ namespace logs
|
||||
const LONGLONG diff = now.QuadPart - start.QuadPart;
|
||||
return diff / freq.QuadPart * 1'000'000 + diff % freq.QuadPart * 1'000'000 / freq.QuadPart;
|
||||
#else
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count();
|
||||
return (steady_clock::now() - start).count() / 1000;
|
||||
#endif
|
||||
}
|
||||
} timebase{};
|
||||
|
Loading…
Reference in New Issue
Block a user