Add Counter for world updates per Second (#707)

* Add Counter for world updates per Second

This work was just done for personal testing and is probably not up to the
required code standards. Nonetheless, I have decided to send a PR as it is very
useful information and a good starting point.

* add MarkWorldUpdate method
This commit is contained in:
NotAFile 2018-01-06 11:38:14 +01:00 committed by YVT
parent d45678b3c8
commit 4ea1e50ae0
4 changed files with 23 additions and 4 deletions

View File

@ -99,6 +99,7 @@ namespace spades {
};
FPSCounter fpsCounter;
FPSCounter upsCounter;
std::unique_ptr<NetClient> net;
std::string playerName;
@ -265,16 +266,16 @@ namespace spades {
/**
* Retrieves the target player ID of the current camera mode (as returned by
* `GetCameraMode`).
*
* Throws an exception if the current camera mode does not have a player in concern.
*
* Throws an exception if the current camera mode does not have a player in concern.
*/
int GetCameraTargetPlayerId();
/**
* Retrieves the target player of the current camera mode (as returned by
* `GetCameraMode`).
*
* Throws an exception if the current camera mode does not have a player in concern.
*
* Throws an exception if the current camera mode does not have a player in concern.
*/
Player &GetCameraTargetPlayer();
@ -413,6 +414,8 @@ namespace spades {
World *GetWorld() const { return world.get(); }
void AddLocalEntity(ILocalEntity *ent) { localEntities.emplace_back(ent); }
void MarkWorldUpdate();
IRenderer *GetRenderer() { return renderer; }
SceneDefinition GetLastSceneDef() { return lastSceneDef; }
IAudioDevice *GetAudioDevice() { return audioDevice; }

View File

@ -924,6 +924,16 @@ namespace spades {
str += buf;
}
}
{
// Display world updates per second
auto ups = upsCounter.GetFps();
if (ups == 0.0)
str += ", --.-- ups";
else {
sprintf(buf, ", %.02f ups", ups);
str += buf;
}
}
if (net) {
auto ping = net->GetPing();

View File

@ -336,5 +336,9 @@ namespace spades {
}
}
}
void Client::MarkWorldUpdate() {
upsCounter.MarkFrame();
}
}
}

View File

@ -818,6 +818,8 @@ namespace spades {
if (protocolVersion == 4)
bytesPerEntry++;
client->MarkWorldUpdate();
int entries = static_cast<int>(reader.GetData().size() / bytesPerEntry);
for (int i = 0; i < entries; i++) {
int idx = i;