add PPSMonitor

This commit is contained in:
Lion Kortlepel authored and Anonymous275 committed 2021-03-18 23:44:14 +02:00
1 parent 72607583bf
commit f19a012509
15 files changed
+185 -66

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
#include "TPPSMonitor.h"
#include "Client.h"
TPPSMonitor::TPPSMonitor(TServer& Server)
: mServer(Server) {
Application::SetPPS("-");
Application::RegisterShutdownHandler([&] { mShutdown = true; });
}
void TPPSMonitor::operator()() {
while (!mShutdown) {
int C = 0, V = 0;
if (mServer.ClientCount() == 0) {
Application::SetPPS("-");
return;
}
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
if (!ClientPtr.expired()) {
auto c = ClientPtr.lock();
if (c->GetCarCount() > 0) {
C++;
V += c->GetCarCount();
}
}
return true;
});
if (C == 0 || mInternalPPS == 0) {
Application::SetPPS("-");
} else {
int R = (mInternalPPS / C) / V;
Application::SetPPS(std::to_string(R));
}
mInternalPPS = 0;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}