summaryrefslogtreecommitdiffhomepage
path: root/Stars45
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-03-18 01:24:57 +0100
committerAki <please@ignore.pl>2022-03-18 01:24:57 +0100
commitc4d8f11ded765f5f762b1b2bbf10fac952730bbe (patch)
tree57a18742ed865d10ce8835421b6c3264a20bf902 /Stars45
parent2d6958e78d7713e3e7f1ddd7c58f036e6e19a936 (diff)
downloadstarshatter-c4d8f11ded765f5f762b1b2bbf10fac952730bbe.zip
starshatter-c4d8f11ded765f5f762b1b2bbf10fac952730bbe.tar.gz
starshatter-c4d8f11ded765f5f762b1b2bbf10fac952730bbe.tar.bz2
Fixed FPS counter
Diffstat (limited to 'Stars45')
-rw-r--r--Stars45/Clock.cpp11
-rw-r--r--Stars45/Clock.h2
-rw-r--r--Stars45/Game.cpp22
-rw-r--r--Stars45/Game.h6
-rw-r--r--Stars45/Mfd.cpp2
-rw-r--r--Stars45/Starshatter.cpp4
6 files changed, 16 insertions, 31 deletions
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) {