forked from RigsOfRods/rigs-of-rods
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added net performance graphs to MPClientList UI.
This is a spinoff from RigsOfRods#3055 Requires updated rorserver. New features: - Added send timestamp to `RoRnet::Header` - all packets now track their time shift between remote client and local client. Note that the existing truck time shift tracking made by Ulteq is unchanged for now. - Added queue timestamp to `RoRnet::Header` - all packets now track the delay between creating the packet and transmitting it to server. - Added recv queue timestamp to `NetRecvPacket` - all packets now track local delay between receiving packet and processing it. - Added 3 new graphs to the MPClientList UI: 1. timeshift (should be stable), 2. local recv lag, 3. remote send lag. Motivation: - to smoothen out character movement the same way truck movement is smoothed. That requires tracking the timeshift, and Ulteq's truck smoothing code is very much tied to `Actor` and `ActorManager`. - To clean up network timers - there are 3 separate timers (`Character`, `Actor`, `ActorManager` - the pattern is not clear). - To better understand and tweak network traffic. - I like diagnostic views. Time spent: 6.5hours, not counting rorserver.
- Loading branch information
Showing
9 changed files
with
293 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
This source file is part of Rigs of Rods | ||
Copyright 2005-2012 Pierre-Michel Ricordel | ||
Copyright 2007-2012 Thomas Fischer | ||
Copyright 2013-2023 Petr Ohlidal | ||
For more information, see http://www.rigsofrods.org/ | ||
Rigs of Rods is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License version 3, as | ||
published by the Free Software Foundation. | ||
Rigs of Rods is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifdef USE_SOCKETW | ||
|
||
#include "Network.h" | ||
|
||
#include "Application.h" | ||
#include "ChatSystem.h" | ||
#include "Console.h" | ||
#include "ErrorUtils.h" | ||
#include "GameContext.h" | ||
#include "GUIManager.h" | ||
#include "GUI_TopMenubar.h" | ||
#include "Language.h" | ||
#include "RoRVersion.h" | ||
#include "ScriptEngine.h" | ||
#include "Utils.h" | ||
|
||
#include <Ogre.h> | ||
#include <SocketW.h> | ||
|
||
#include <algorithm> | ||
#include <chrono> | ||
#include <cstring> | ||
|
||
using namespace RoR; | ||
|
||
NetGraphData::NetGraphData(size_t size) | ||
{ | ||
plotline.resize(size, RoRnet::NetTime32_t(0)); | ||
} | ||
|
||
void NetGraphData::AddSample(RoRnet::NetTime32_t sample) | ||
{ | ||
plotline.erase(plotline.begin()); | ||
plotline.push_back(sample); | ||
const auto minmax = std::minmax_element(plotline.begin(), plotline.end()); | ||
plotline_min = *minmax.first; | ||
plotline_max = *minmax.second; | ||
|
||
// smooth scale | ||
const float SMOOTH_UP = 0.4f; | ||
const float SMOOTH_DOWN = 0.05f; | ||
|
||
const float fmin = static_cast<float>(*minmax.first); | ||
if (fmin < plotline_smoothmin) | ||
plotline_smoothmin = fmin * SMOOTH_UP + plotline_smoothmin * (1.f - SMOOTH_UP); | ||
else | ||
plotline_smoothmin = fmin * SMOOTH_DOWN + plotline_smoothmin * (1.f - SMOOTH_DOWN); | ||
|
||
const float fmax = static_cast<float>(*minmax.second); | ||
if (fmax > plotline_smoothmax) | ||
plotline_smoothmax = fmax * SMOOTH_UP + plotline_smoothmax * (1.f - SMOOTH_UP); | ||
else | ||
plotline_smoothmax = fmax * SMOOTH_DOWN + plotline_smoothmax * (1.f - SMOOTH_DOWN); | ||
} | ||
|
||
// static | ||
float NetGraphData::ImPlotGetSample(void* data, int idx) | ||
{ | ||
NetGraphPlotline* plotline = static_cast<NetGraphPlotline*>(data); | ||
return static_cast<float>(plotline->at(idx)); | ||
} | ||
|
||
void NetGraphData::ImPlotLines(const char* label, const char* overlay_text, ImVec2 size) | ||
{ | ||
ImGui::PlotLines( | ||
label, | ||
NetGraphData::ImPlotGetSample, | ||
static_cast<void*>(&plotline), | ||
static_cast<int>(plotline.size()), | ||
/*values_offset:*/0, | ||
overlay_text, | ||
plotline_smoothmin, | ||
plotline_smoothmax, | ||
size); | ||
} | ||
|
||
#endif // USE_SOCKETW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
This source file is part of Rigs of Rods | ||
Copyright 2005-2012 Pierre-Michel Ricordel | ||
Copyright 2007-2012 Thomas Fischer | ||
Copyright 2013-2023 Petr Ohlidal | ||
For more information, see http://www.rigsofrods.org/ | ||
Rigs of Rods is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License version 3, as | ||
published by the Free Software Foundation. | ||
Rigs of Rods is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef USE_SOCKETW | ||
|
||
#include "Application.h" | ||
#include "OgreImGui.h" | ||
#include "RoRnet.h" | ||
|
||
namespace RoR { | ||
|
||
/// @addtogroup Network | ||
/// @{ | ||
|
||
typedef std::vector<RoRnet::NetTime32_t> NetGraphPlotline; | ||
|
||
struct NetGraphData | ||
{ | ||
NetGraphPlotline plotline; | ||
RoRnet::NetTime32_t plotline_max = 0; | ||
RoRnet::NetTime32_t plotline_min = 0; | ||
float plotline_smoothmax = 0.f; | ||
float plotline_smoothmin = 0.f; | ||
|
||
NetGraphData(size_t size); | ||
|
||
void AddSample(RoRnet::NetTime32_t sample); | ||
static float ImPlotGetSample(void* data, int idx); | ||
void ImPlotLines(const char* label, const char* overlay_text, ImVec2 size); | ||
}; | ||
|
||
struct NetClientStats | ||
{ | ||
NetGraphData remote_queue_delay = NetGraphData(20); //!< How long it takes remote client to transmit outgoing packet. | ||
NetGraphData local_queue_delay = NetGraphData(20); //!< How long it takes us to process received packet. | ||
NetGraphData client_time_offset = NetGraphData(40); //!< Difference between client timers; we monitor it's stability. | ||
}; | ||
|
||
/// @} //addtogroup Network | ||
|
||
} // namespace RoR | ||
|
||
#endif // USE_SOCKETW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.