game: print simple performance stats on F3 in debug mode

This commit is contained in:
Crypto City 2021-08-26 17:27:06 +00:00
parent b5e734efd1
commit 731555b99c

View File

@ -641,6 +641,11 @@ private:
uint32_t cached_potential_x0;
uint32_t cached_potential_y0;
uint32_t update_count;
uint32_t fps_base_update_count;
Urho3D::Timer fpsTimer;
float fps;
std::list<std::shared_ptr<QueuedCommand>> queued_commands;
struct AddBlockCommand: public QueuedCommand
@ -739,7 +744,11 @@ CryptoCityUrho3D::CryptoCityUrho3D(Context *ctx):
selectionTutorialTriggered_(false),
notification_sent_by_command_processing(false),
cached_potential_x0(0),
cached_potential_y0(0)
cached_potential_y0(0),
update_count(0),
fps_base_update_count(0),
fpsTimer(),
fps(0.0f)
{
}
@ -2419,8 +2428,6 @@ void CryptoCityUrho3D::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
using namespace Update;
static uint32_t update_count = 0;
if (update_count == 0)
startupTutorialTimer_.Reset();
else if (!startupTutorialTriggered_ && startupTutorialTimer_.GetMSec(false) >= 3000)
@ -2433,6 +2440,15 @@ void CryptoCityUrho3D::HandleUpdate(StringHash eventType, VariantMap& eventData)
if (++update_count == 2)
ui->RefreshNotifications();
const unsigned ms = fpsTimer.GetMSec(false);
if (ms > 2000)
{
fpsTimer.Reset();
fps = 1000.0f * (update_count - fps_base_update_count) / (float)ms;
fps_base_update_count = update_count;
}
if (newCity_ && gameState.cityState.ready)
{
MoveCameraToStartPosition(startPositionHugTerrain_);
@ -7118,6 +7134,11 @@ void CryptoCityUrho3D::HandleKeyDown(StringHash /*eventType*/, VariantMap& event
// Toggle debug HUD with F2
if (debug && key == KEY_F2)
GetSubsystem<DebugHud>()->ToggleAll();
else if (debug && key == KEY_F3)
{
Graphics* graphics = GetSubsystem<Graphics>();
printf("%.1f FPS, %u primitives, %u batches\n", fps, graphics->GetNumPrimitives(), graphics->GetNumBatches());
}
else if (debug && key == KEY_F6)
RebuildMap(true);