Skip to content

Commit

Permalink
Correctly calculate gamereport networking stats
Browse files Browse the repository at this point in the history
  • Loading branch information
altf4 committed Mar 27, 2021
1 parent 33875d2 commit ceeb5c9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Source/Core/Core/Slippi/SlippiNetplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ unsigned int SlippiNetplayClient::OnData(sf::Packet &packet)

u64 curTime = Common::Timer::GetTimeUs();

// 120 frames to let the game settle before measuring network quality
if (frame > 120)
{
std::lock_guard<std::recursive_mutex> lkq(packetTimestampsMutex);
packetTimestamps.push_back(curTime);
Expand Down Expand Up @@ -744,9 +746,12 @@ void SlippiNetplayClient::GetNetworkingStats(SlippiGameReporter::GameReport *rep
std::vector<u64> differences;
{
std::lock_guard<std::recursive_mutex> lkq(packetTimestampsMutex);
differences.resize(packetTimestamps.size()-1);
std::adjacent_difference(packetTimestamps.begin(), packetTimestamps.end(), differences.begin());
// For absolutely no reason that I can gather, adjacent_difference puts an exta element at the front of the result vector. Remove it
differences.erase(differences.begin());
}
report->jitterMean = std::accumulate(differences.begin(), differences.end(), 0LL) / differences.size();
report->jitterMean = std::accumulate(differences.begin(), differences.end(), 0) / differences.size();
report->jitterMax = (float)*std::max_element(differences.begin(), differences.end());
report->jitterVariance = ComputeSampleVariance(report->jitterMean, differences);
}

0 comments on commit ceeb5c9

Please sign in to comment.