mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-20 22:05:12 +00:00
std::chrono cleanup: always use steady_clock
This commit is contained in:
parent
12a48fc6d1
commit
aa3aef4beb
19 changed files with 96 additions and 97 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue