From c4d8f11ded765f5f762b1b2bbf10fac952730bbe Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 18 Mar 2022 01:24:57 +0100 Subject: Fixed FPS counter --- Stars45/Clock.cpp | 11 ++++++++++- Stars45/Clock.h | 2 ++ Stars45/Game.cpp | 22 +--------------------- Stars45/Game.h | 6 ------ Stars45/Mfd.cpp | 2 +- Stars45/Starshatter.cpp | 4 ++-- 6 files changed, 16 insertions(+), 31 deletions(-) (limited to 'Stars45') diff --git a/Stars45/Clock.cpp b/Stars45/Clock.cpp index 5315b99..03c2771 100644 --- a/Stars45/Clock.cpp +++ b/Stars45/Clock.cpp @@ -18,7 +18,8 @@ Clock::Clock() : m_real_elapsed {inner_clock::duration::zero()}, m_compression {NO_COMPRESSION}, m_delta {STARTING_DELTA}, - m_gui_delta {STARTING_DELTA} + m_gui_delta {STARTING_DELTA}, + m_rate {0.0} { } @@ -43,6 +44,7 @@ Clock::Step() m_delta = seconds.count() * m_compression; m_gui_delta = seconds.count(); m_point = next; + m_rate = 1 / m_gui_delta; return m_delta; } @@ -77,6 +79,13 @@ Clock::GuiDelta() const double +Clock::Rate() const +{ + return m_rate; +} + + +double Clock::TimeCompression() const { return m_compression; diff --git a/Stars45/Clock.h b/Stars45/Clock.h index 5628e45..512ee0f 100644 --- a/Stars45/Clock.h +++ b/Stars45/Clock.h @@ -26,6 +26,7 @@ public: double Delta() const; double GuiDelta() const; + double Rate() const; double TimeCompression() const; count_type GameTime() const; count_type RealTime() const; @@ -39,6 +40,7 @@ protected: double m_compression; double m_delta; double m_gui_delta; + double m_rate; }; diff --git a/Stars45/Game.cpp b/Stars45/Game.cpp index 2b38db7..c5c9ab8 100644 --- a/Stars45/Game.cpp +++ b/Stars45/Game.cpp @@ -38,8 +38,7 @@ const double MAX_FRAME_TIME_NORMAL = 1.0 / 5.0; Game::Game() : world(0), video_factory(0), video(0), video_settings(0), soundcard(0), screen(0), totaltime(0), - hInst(0), hwnd(0), frame_rate(0), frame_count(0), frame_count0(0), - frame_time(0), frame_time0(0), + hInst(0), hwnd(0), status(Game::OK), exit_code(0), window_style(0) { if (!game) { @@ -112,17 +111,6 @@ bool Game::IsWindowed() // +--------------------------------------------------------------------+ -double -Game::FrameRate() -{ - if (game) - return game->frame_rate; - - return 0; -} - -// +--------------------------------------------------------------------+ - bool Game::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) { @@ -614,16 +602,8 @@ Game::GetScreenHeight() void Game::CollectStats() { - frame_count++; - if (!totaltime) totaltime = clock.RealTime(); - if (frame_time - frame_time0 > 200) { - frame_rate = (frame_count - frame_count0) * 1000.0 / (frame_time - frame_time0); - frame_time0 = frame_time; - frame_count0 = frame_count; - } - if (video) { stats.nframe = video->GetStats().nframe; stats.nverts = video->GetStats().nverts; diff --git a/Stars45/Game.h b/Stars45/Game.h index 65963b1..8d30f42 100644 --- a/Stars45/Game.h +++ b/Stars45/Game.h @@ -71,7 +71,6 @@ public: Clock* GetClock(); DWORD Frame(); - double FrameRate(); void SetMaxFrameLength(double seconds) { max_frame_length = seconds; } double GetMaxFrameLength() { return max_frame_length; } @@ -141,11 +140,6 @@ protected: RECT client_rect; // Saved client area size for mode switches Clock clock; - double frame_rate; - int frame_count; - int frame_count0; - int frame_time; - int frame_time0; int status; int exit_code; diff --git a/Stars45/Mfd.cpp b/Stars45/Mfd.cpp index 58a5a4d..cf50bd9 100644 --- a/Stars45/Mfd.cpp +++ b/Stars45/Mfd.cpp @@ -1087,7 +1087,7 @@ MFD::DrawGameMFD() int t = 0; if (!HUDView::IsArcade() && HUDView::ShowFPS()) { - sprintf_s(txt, "FPS: %6.2f", Game::GetInstance()->FrameRate()); + sprintf_s(txt, "FPS: %6.2f", Game::GetInstance()->GetClock()->Rate()); DrawMFDText(t++, txt, txt_rect, DT_LEFT); txt_rect.y += 10; diff --git a/Stars45/Starshatter.cpp b/Stars45/Starshatter.cpp index 28f1506..0e0f696 100644 --- a/Stars45/Starshatter.cpp +++ b/Stars45/Starshatter.cpp @@ -1484,7 +1484,7 @@ Starshatter::DoGameScreenFrame() } } - gamescreen->FrameRate(frame_rate); + gamescreen->FrameRate(Game::GetInstance()->GetClock()->Rate()); gamescreen->ExecFrame(); if (KeyDown(KEY_EXIT)) { @@ -1564,7 +1564,7 @@ Starshatter::DoGameScreenFrame() DoGameKeys(); } - gamescreen->FrameRate(frame_rate); + gamescreen->FrameRate(Game::GetInstance()->GetClock()->Rate()); gamescreen->ExecFrame(); if (Game::GetInstance()->GetClock()->GameTime() - time_mark > 60000) { -- cgit v1.1