diff --git a/managers/cheat_manager.c b/managers/cheat_manager.c index a828479f65..a00649e306 100644 --- a/managers/cheat_manager.c +++ b/managers/cheat_manager.c @@ -1227,7 +1227,8 @@ int cheat_manager_add_matches(const char *path, void cheat_manager_apply_rumble(struct item_cheat *cheat, unsigned int curr_value) { - bool rumble = false; + bool rumble = false; + retro_time_t current_time = cpu_features_get_time_usec(); switch (cheat->rumble_type) { @@ -1273,8 +1274,8 @@ void cheat_manager_apply_rumble(struct item_cheat *cheat, unsigned int curr_valu { if (rumble) { - cheat->rumble_primary_end_time = cpu_features_get_time_usec() + (cheat->rumble_primary_duration * 1000); - cheat->rumble_secondary_end_time = cpu_features_get_time_usec() + (cheat->rumble_secondary_duration * 1000); + cheat->rumble_primary_end_time = current_time + (cheat->rumble_primary_duration * 1000); + cheat->rumble_secondary_end_time = current_time + (cheat->rumble_secondary_duration * 1000); input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_STRONG, cheat->rumble_primary_strength); input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_WEAK, cheat->rumble_secondary_strength); } @@ -1285,18 +1286,20 @@ void cheat_manager_apply_rumble(struct item_cheat *cheat, unsigned int curr_valu return; } - if (cheat->rumble_primary_end_time <= cpu_features_get_time_usec()) + if (cheat->rumble_primary_end_time <= current_time) { if (cheat->rumble_primary_end_time != 0) - input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_STRONG, 0); + input_driver_set_rumble_state(cheat->rumble_port, + RETRO_RUMBLE_STRONG, 0); cheat->rumble_primary_end_time = 0; } else { - input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_STRONG, cheat->rumble_primary_strength); + input_driver_set_rumble_state(cheat->rumble_port, + RETRO_RUMBLE_STRONG, cheat->rumble_primary_strength); } - if (cheat->rumble_secondary_end_time <= cpu_features_get_time_usec()) + if (cheat->rumble_secondary_end_time <= current_time) { if (cheat->rumble_secondary_end_time != 0) input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_WEAK, 0); diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index 01e76a4102..0fb5f393f5 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -286,9 +286,8 @@ static bool netplay_poll(netplay_t *netplay) { size_t i; uint32_t client; - bool blocking = false; - - netplay->can_poll = false; + bool blocking = false; + retro_time_t current_time = cpu_features_get_time_usec(); if (!netplay_get_self_input_state(netplay)) goto catastrophe; @@ -439,7 +438,7 @@ static bool netplay_poll(netplay_t *netplay) <= netplay->self_frame_count) { netplay->stall = NETPLAY_STALL_RUNNING_FAST; - netplay->stall_time = cpu_features_get_time_usec(); + netplay->stall_time = current_time; /* Figure out who to blame */ if (netplay->is_server) @@ -469,22 +468,25 @@ static bool netplay_poll(netplay_t *netplay) netplay->self_mode == NETPLAY_CONNECTION_SLAVE) && netplay->unread_frame_count <= netplay->self_frame_count) { - netplay->stall = NETPLAY_STALL_SPECTATOR_WAIT; - netplay->stall_time = cpu_features_get_time_usec(); + netplay->stall = NETPLAY_STALL_SPECTATOR_WAIT; + netplay->stall_time = current_time; } } /* If we're stalling, consider disconnection */ if (netplay->stall && netplay->stall_time) { - retro_time_t now = cpu_features_get_time_usec(); + retro_time_t now = current_time; /* Don't stall out while they're paused */ if (netplay->remote_paused) netplay->stall_time = now; - else if (now - netplay->stall_time >= - (netplay->is_server ? MAX_SERVER_STALL_TIME_USEC : - MAX_CLIENT_STALL_TIME_USEC)) + else if ( + now - netplay->stall_time >= + (netplay->is_server + ? MAX_SERVER_STALL_TIME_USEC + : MAX_CLIENT_STALL_TIME_USEC) + ) { /* Stalled out! */ if (netplay->is_server) @@ -531,7 +533,10 @@ catastrophe: void input_poll_net(netplay_t *netplay) { if (!netplay_should_skip(netplay) && netplay_can_poll(netplay)) + { + netplay->can_poll = false; netplay_poll(netplay); + } } /* Netplay polling callbacks */ diff --git a/network/netplay/netplay_sync.c b/network/netplay/netplay_sync.c index 9e31630f44..227ca1da7e 100644 --- a/network/netplay/netplay_sync.c +++ b/network/netplay/netplay_sync.c @@ -752,6 +752,7 @@ process: void netplay_sync_post_frame(netplay_t *netplay, bool stalled) { uint32_t lo_frame_count, hi_frame_count; + retro_time_t current_time = cpu_features_get_time_usec(); /* Unless we're stalling, we've just finished running a frame */ if (!stalled) @@ -878,15 +879,14 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled) while (netplay->replay_frame_count < netplay->run_frame_count) { - retro_time_t start, tm; + retro_time_t tm; struct delta_frame *ptr = &netplay->buffer[netplay->replay_ptr]; + retro_time_t start = current_time; serial_info.data = ptr->state; serial_info.size = netplay->state_size; serial_info.data_const = NULL; - start = cpu_features_get_time_usec(); - /* Remember the current state */ memset(serial_info.data, 0, serial_info.size); core_serialize(&serial_info); @@ -923,7 +923,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled) #endif /* Get our time window */ - tm = cpu_features_get_time_usec() - start; + tm = current_time - start; netplay->frame_run_time_sum -= netplay->frame_run_time[netplay->frame_run_time_ptr]; netplay->frame_run_time[netplay->frame_run_time_ptr] = tm; netplay->frame_run_time_sum += tm; @@ -983,7 +983,6 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled) { if (netplay->self_frame_count + 3 < lo_frame_count) { - retro_time_t cur_time = cpu_features_get_time_usec(); uint32_t cur_behind = lo_frame_count - netplay->self_frame_count; /* We're behind, but we'll only try to catch up if we're actually @@ -991,11 +990,12 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled) if (netplay->catch_up_time == 0) { /* Record our current time to check for catch-up later */ - netplay->catch_up_time = cur_time; + netplay->catch_up_time = current_time; netplay->catch_up_behind = cur_behind; } - else if (cur_time - netplay->catch_up_time > CATCH_UP_CHECK_TIME_USEC) + else if (current_time - netplay->catch_up_time + > CATCH_UP_CHECK_TIME_USEC) { /* Time to check how far behind we are */ if (netplay->catch_up_behind <= cur_behind) @@ -1009,7 +1009,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled) else { /* Check again in another period */ - netplay->catch_up_time = cur_time; + netplay->catch_up_time = current_time; netplay->catch_up_behind = cur_behind; } }