Show ping (fixing #146)

This commit is contained in:
yvt 2014-03-16 01:23:30 +09:00
parent cd980b478f
commit 2af2826918
3 changed files with 26 additions and 1 deletions

View File

@ -430,6 +430,17 @@ namespace spades {
peer = NULL;
}
int NetClient::GetPing() {
SPADES_MARK_FUNCTION();
if(status == NetClientStatusNotConnected)
return -1;
auto rtt = peer->roundTripTime;
if(rtt == 0) return -1;
return static_cast<int>(rtt);
}
void NetClient::DoEvents(int timeout) {
SPADES_MARK_FUNCTION();

View File

@ -111,6 +111,8 @@ namespace spades {
void Connect(const ServerAddress& hostname);
void Disconnect();
int GetPing();
void DoEvents(int timeout = 0);
void SendJoin(int team, WeaponType,

View File

@ -32,6 +32,7 @@
#include <stdio.h>
#include <string.h>
#include "TCGameMode.h"
#include "NetClient.h"
namespace spades {
namespace client {
@ -153,8 +154,8 @@ namespace spades {
MakeVector4(0, 0, 0, 0.3f));
font->Draw(buf, pos, 1.f, whiteColor);
font = client->textFont;
if(ctf) {
font = client->textFont;
// draw caplimit
sprintf(buf, "LIMIT %d", ctf->GetCaptureLimit());
size = font->Measure(buf);
@ -164,6 +165,17 @@ namespace spades {
font->Draw(buf, pos, 1.f, whiteColor);
}
// draw ping
auto ping = client->net ? client->net->GetPing() : -1;
if(ping != -1) {
sprintf(buf, "PING %dms", ping);
size = font->Measure(buf);
pos.x = 16.f;
font->Draw(buf, pos + MakeVector2(0, 1), 1.f,
MakeVector4(0, 0, 0, 0.3f));
font->Draw(buf, pos, 1.f, whiteColor);
}
// draw team bar
image = whiteImage;
renderer->SetColorAlphaPremultiplied(AdjustColor(GetTeamColor(0), 0.8f, 0.3f));