Statistics (fix #202)
This commit is contained in:
parent
d81225089a
commit
817ce53c23
@ -42,6 +42,7 @@
|
||||
E81A7C7D1865A2E900BF3FCE /* MiniHeap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E81A7C7B1865A2E900BF3FCE /* MiniHeap.cpp */; };
|
||||
E81CE4A6183F7A3000F22685 /* IFont.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E81CE4A4183F7A3000F22685 /* IFont.cpp */; };
|
||||
E81CE4A9183F7F2000F22685 /* MainScreen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E81CE4A7183F7F2000F22685 /* MainScreen.cpp */; };
|
||||
E82E66B318E9A35C004DBA18 /* Client_FPSCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E82E66B218E9A35C004DBA18 /* Client_FPSCounter.cpp */; };
|
||||
E834F55017942C43004EBE88 /* Grenade.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E834F54E17942C43004EBE88 /* Grenade.cpp */; };
|
||||
E834F55317944779004EBE88 /* NetClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E834F55117944778004EBE88 /* NetClient.cpp */; };
|
||||
E834F5561794BBD4004EBE88 /* Debug.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E834F5541794BBD4004EBE88 /* Debug.cpp */; };
|
||||
@ -366,6 +367,7 @@
|
||||
E81CE4A4183F7A3000F22685 /* IFont.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IFont.cpp; sourceTree = "<group>"; };
|
||||
E81CE4A7183F7F2000F22685 /* MainScreen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MainScreen.cpp; sourceTree = "<group>"; };
|
||||
E81CE4A8183F7F2000F22685 /* MainScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainScreen.h; sourceTree = "<group>"; };
|
||||
E82E66B218E9A35C004DBA18 /* Client_FPSCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Client_FPSCounter.cpp; sourceTree = "<group>"; };
|
||||
E834F54E17942C43004EBE88 /* Grenade.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Grenade.cpp; sourceTree = "<group>"; };
|
||||
E834F54F17942C43004EBE88 /* Grenade.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Grenade.h; sourceTree = "<group>"; };
|
||||
E834F55117944778004EBE88 /* NetClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetClient.cpp; sourceTree = "<group>"; };
|
||||
@ -1512,6 +1514,7 @@
|
||||
E8FE749118CC6E4900291338 /* Client_LocalEnts.cpp */,
|
||||
E8FE749318CC6EB500291338 /* Client_Draw.cpp */,
|
||||
E8FE749518CC6F2900291338 /* Client_Scene.cpp */,
|
||||
E82E66B218E9A35C004DBA18 /* Client_FPSCounter.cpp */,
|
||||
E8CF03C2178EE6D8000683D4 /* Client.h */,
|
||||
E834F56D1797D92F004EBE88 /* ChatWindow.cpp */,
|
||||
E834F56E1797D932004EBE88 /* ChatWindow.h */,
|
||||
@ -1928,6 +1931,7 @@
|
||||
E8567E7F1793E1B3009D83E0 /* GLVoxelModel.cpp in Sources */,
|
||||
E834F55017942C43004EBE88 /* Grenade.cpp in Sources */,
|
||||
E88EB02F185D9DC500565D07 /* YsrDevice.cpp in Sources */,
|
||||
E82E66B318E9A35C004DBA18 /* Client_FPSCounter.cpp in Sources */,
|
||||
E834F55317944779004EBE88 /* NetClient.cpp in Sources */,
|
||||
E834F5561794BBD4004EBE88 /* Debug.cpp in Sources */,
|
||||
E834F5591794DCFD004EBE88 /* IGameMode.cpp in Sources */,
|
||||
|
@ -682,6 +682,7 @@ namespace spades {
|
||||
ConfigNumberFormatter(0, " deg"));
|
||||
layouter.AddSliderField(_Tr("Preferences", "Minimap size"), "cg_minimapSize", 128, 256, 8,
|
||||
ConfigNumberFormatter(0, " px"));
|
||||
layouter.AddToggleField(_Tr("Preferences", "Show Statistics"), "cg_stats");
|
||||
layouter.AddToggleField(_Tr("Preferences", "Debug Hit Detection"), "cg_debugHitTest");
|
||||
layouter.AddToggleField(_Tr("Preferences", "Weapon Spread Guide"), "cg_debugAim");
|
||||
layouter.FinishLayout();
|
||||
|
@ -387,6 +387,8 @@ namespace spades {
|
||||
void Client::RunFrame(float dt) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
fpsCounter.MarkFrame();
|
||||
|
||||
if(frameToRendererInit > 0){
|
||||
// waiting for renderer initialization
|
||||
|
||||
|
@ -31,9 +31,11 @@
|
||||
#include <list>
|
||||
#include <Gui/View.h>
|
||||
#include <memory>
|
||||
#include <Core/Stopwatch.h>
|
||||
|
||||
namespace spades {
|
||||
class IStream;
|
||||
class Stopwatch;
|
||||
namespace client {
|
||||
class IRenderer;
|
||||
struct SceneDefinition;
|
||||
@ -81,6 +83,18 @@ namespace spades {
|
||||
}
|
||||
};
|
||||
|
||||
class FPSCounter {
|
||||
Stopwatch sw;
|
||||
int numFrames;
|
||||
double lastFps;
|
||||
public:
|
||||
FPSCounter();
|
||||
void MarkFrame();
|
||||
double GetFps() { return lastFps; }
|
||||
};
|
||||
|
||||
FPSCounter fpsCounter;
|
||||
|
||||
std::unique_ptr<NetClient> net;
|
||||
std::string playerName;
|
||||
std::unique_ptr<IStream> logStream;
|
||||
@ -249,6 +263,7 @@ namespace spades {
|
||||
void DrawHealth();
|
||||
void DrawAlert();
|
||||
void DrawDebugAim();
|
||||
void DrawStats();
|
||||
|
||||
void DrawScene();
|
||||
void AddGrenadeToScene(Grenade *);
|
||||
|
@ -60,6 +60,7 @@ SPADES_SETTING(cg_hitIndicator, "1");
|
||||
SPADES_SETTING(cg_debugAim, "0");
|
||||
SPADES_SETTING(cg_keyReloadWeapon, "");
|
||||
SPADES_SETTING(cg_screenshotFormat, "jpeg");
|
||||
SPADES_SETTING(cg_stats, "0");
|
||||
|
||||
namespace spades {
|
||||
namespace client {
|
||||
@ -817,6 +818,52 @@ namespace spades {
|
||||
DrawAlert();
|
||||
}
|
||||
|
||||
void Client::DrawStats() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
if(!cg_stats) return;
|
||||
|
||||
char buf[256];
|
||||
std::string str;
|
||||
|
||||
{
|
||||
auto fps = fpsCounter.GetFps();
|
||||
if(fps == 0.0)
|
||||
str += "--.-- fps";
|
||||
else {
|
||||
sprintf(buf, "%.02f fps", fps);
|
||||
str += buf;
|
||||
}
|
||||
}
|
||||
|
||||
if(net) {
|
||||
auto ping = net->GetPing();
|
||||
auto upbps = net->GetUplinkBps();
|
||||
auto downbps = net->GetDownlinkBps();
|
||||
sprintf(buf, ", ping: %dms, up/down: %.02f/%.02fkbps",
|
||||
ping, upbps / 1000.0, downbps / 1000.0);
|
||||
str += buf;
|
||||
}
|
||||
|
||||
float scrWidth = renderer->ScreenWidth();
|
||||
float scrHeight = renderer->ScreenHeight();
|
||||
IFont *font = textFont;
|
||||
float margin = 5.f;
|
||||
|
||||
IRenderer *r = renderer;
|
||||
auto size = font->Measure(str);
|
||||
size += Vector2(margin * 2.f, margin * 2.f);
|
||||
|
||||
auto pos =
|
||||
(Vector2(scrWidth, scrHeight) - size) * Vector2(0.5f, 1.f);
|
||||
|
||||
r->SetColorAlphaPremultiplied(Vector4(0.f, 0.f, 0.f, 0.5f));
|
||||
r->DrawImage(nullptr, AABB2(pos.x, pos.y, size.x, size.y));
|
||||
font->DrawShadow(str, pos + Vector2(margin, margin), 1.f,
|
||||
Vector4(1.f, 1.f, 1.f, 1.f),
|
||||
Vector4(0.f, 0.f, 0.f, 0.5f));
|
||||
}
|
||||
|
||||
void Client::Draw2D(){
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
@ -827,6 +874,8 @@ namespace spades {
|
||||
}
|
||||
|
||||
centerMessageView->Draw();
|
||||
|
||||
DrawStats();
|
||||
}
|
||||
|
||||
}
|
||||
|
43
Sources/Client/Client_FPSCounter.cpp
Normal file
43
Sources/Client/Client_FPSCounter.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
based on code of pysnip (c) Mathias Kaerlev 2011-2012.
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "Client.h"
|
||||
#include <Core/Stopwatch.h>
|
||||
|
||||
namespace spades { namespace client {
|
||||
|
||||
Client::FPSCounter::FPSCounter():
|
||||
numFrames(0),
|
||||
lastFps(0.0){
|
||||
sw.Reset();
|
||||
}
|
||||
|
||||
void Client::FPSCounter::MarkFrame() {
|
||||
numFrames++;
|
||||
if(sw.GetTime() > 0.5) {
|
||||
auto diff = sw.GetTime();
|
||||
lastFps = static_cast<double>(numFrames) / diff;
|
||||
numFrames = 0;
|
||||
sw.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
} }
|
@ -313,11 +313,12 @@ namespace spades {
|
||||
}
|
||||
};
|
||||
|
||||
NetClient::NetClient(Client *c){
|
||||
NetClient::NetClient(Client *c):
|
||||
client(c),
|
||||
host(nullptr),
|
||||
peer(nullptr){
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
client = c;
|
||||
|
||||
enet_initialize();
|
||||
SPLog("ENet initialized");
|
||||
|
||||
@ -347,12 +348,16 @@ namespace spades {
|
||||
|
||||
std::fill(savedPlayerTeam.begin(),
|
||||
savedPlayerTeam.end(), -1);
|
||||
|
||||
bandwidthMonitor.reset(new BandwidthMonitor(host));
|
||||
}
|
||||
NetClient::~NetClient(){
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
Disconnect();
|
||||
enet_host_destroy(host);
|
||||
if(host)
|
||||
enet_host_destroy(host);
|
||||
bandwidthMonitor.reset();
|
||||
SPLog("ENet host destroyed");
|
||||
}
|
||||
|
||||
@ -447,6 +452,9 @@ namespace spades {
|
||||
if(status == NetClientStatusNotConnected)
|
||||
return;
|
||||
|
||||
if(bandwidthMonitor)
|
||||
bandwidthMonitor->Update();
|
||||
|
||||
ENetEvent event;
|
||||
while(enet_host_service(host, &event, timeout) > 0){
|
||||
if(event.type == ENET_EVENT_TYPE_DISCONNECT) {
|
||||
@ -1830,5 +1838,23 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
NetClient::BandwidthMonitor::BandwidthMonitor(ENetHost *host):
|
||||
host(host),
|
||||
lastDown(0.0),
|
||||
lastUp(0.0){
|
||||
sw.Reset();
|
||||
}
|
||||
|
||||
void NetClient::BandwidthMonitor::Update() {
|
||||
if(sw.GetTime() > 0.5) {
|
||||
lastUp = host->totalSentData / sw.GetTime();
|
||||
lastDown = host->totalReceivedData / sw.GetTime();
|
||||
host->totalSentData = 0;
|
||||
host->totalReceivedData = 0;
|
||||
sw.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <Core/VersionInfo.h>
|
||||
#include "PhysicsConstants.h"
|
||||
#include "Player.h"
|
||||
#include <Core/Stopwatch.h>
|
||||
|
||||
struct _ENetHost;
|
||||
struct _ENetPeer;
|
||||
@ -61,6 +62,20 @@ namespace spades {
|
||||
unsigned int mapSize;
|
||||
std::vector<char> mapData;
|
||||
|
||||
class BandwidthMonitor {
|
||||
ENetHost *host;
|
||||
Stopwatch sw;
|
||||
double lastDown;
|
||||
double lastUp;
|
||||
public:
|
||||
BandwidthMonitor(ENetHost *);
|
||||
double GetDownlinkBps() { return lastDown * 8.; }
|
||||
double GetUplinkBps() { return lastUp * 8.; }
|
||||
void Update();
|
||||
};
|
||||
|
||||
std::unique_ptr<BandwidthMonitor> bandwidthMonitor;
|
||||
|
||||
std::vector<Vector3> savedPlayerPos;
|
||||
std::vector<Vector3> savedPlayerFront;
|
||||
std::vector<int> savedPlayerTeam;
|
||||
@ -134,6 +149,9 @@ namespace spades {
|
||||
void SendTeamChange(int team);
|
||||
void SendHandShakeValid(int challenge);
|
||||
void SendVersion();
|
||||
|
||||
double GetDownlinkBps() { return bandwidthMonitor->GetDownlinkBps(); }
|
||||
double GetUplinkBps() { return bandwidthMonitor->GetUplinkBps(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -165,17 +165,6 @@ 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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user