summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.hpp9
-rw-r--r--src/game/interface.cpp24
-rw-r--r--src/render.cpp10
-rw-r--r--src/text.cpp2
4 files changed, 43 insertions, 2 deletions
diff --git a/src/common.hpp b/src/common.hpp
index b88434e..7b784bf 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -10,6 +10,8 @@
#include <SFML/Graphics.hpp>
#include "math.hpp"
+#define count(A) (sizeof(A) / sizeof((A)[0]))
+
extern bool debug_draw_cmodels;
extern bool debug_draw_paths;
extern bool debug_draw_tile_coords;
@@ -252,6 +254,9 @@ namespace interface {
std::list<log_entry_t> log;
+ double perf_hist[10] = {0};
+ size_t perf_hist_index = 0;
+
public:
state_t(sf::RenderWindow *window_, game::state_t *game);
void tick(double dt);
@@ -313,6 +318,10 @@ namespace render {
public:
double now, dt;
+ struct {
+ size_t sectors, tiles, entities;
+ } stats;
+
state_t(sf::RenderWindow *window_);
void begin_frame(double time_, double dt_);
void end_frame(void);
diff --git a/src/game/interface.cpp b/src/game/interface.cpp
index 2a52220..148f790 100644
--- a/src/game/interface.cpp
+++ b/src/game/interface.cpp
@@ -1,4 +1,5 @@
#include "game.hpp"
+#include <iomanip>
namespace interface {
@@ -141,6 +142,8 @@ void state_t::render_to(render::state_t *render)
{
size_t w = window->getSize().x, h = window->getSize().y;
v2f_t x;
+ std::stringstream ss;
+ double fps;
if (select.selecting)
render->render_hlrect(select.rect, sf::Color(200, 100, 50));
@@ -160,6 +163,27 @@ void state_t::render_to(render::state_t *render)
render->render_text(x, em, entry.text, render::ALIGN_LEFT_TOP, sf::Color::White);
x[1] += em;
}
+
+ x = v2f_t(0.0f, h - em * 1.5);
+ ss << "S/T/E: ";
+ ss << render->stats.sectors << "/";
+ ss << render->stats.tiles << "/";
+ ss << render->stats.entities;
+ render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White);
+
+ perf_hist_index = (perf_hist_index + 1) % count(perf_hist);
+ perf_hist[perf_hist_index] = 1.0 / render->dt;
+
+ fps = 0.0;
+ for (size_t i = 0; i < count(perf_hist); i++)
+ fps += perf_hist[i];
+ fps /= count(perf_hist);
+
+ x[1] -= em;
+ ss.str(std::string());
+ ss << std::fixed << std::setprecision(1);
+ ss << "FPS: " << fps;
+ render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White);
}
} // namespace interface
diff --git a/src/render.cpp b/src/render.cpp
index 792d70d..f773f92 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -27,6 +27,10 @@ void state_t::begin_frame(double now_, double dt_)
now = now_;
dt = dt_;
window->clear();
+
+ stats.sectors = 0;
+ stats.tiles = 0;
+ stats.entities = 0;
}
void state_t::end_frame(void)
@@ -101,7 +105,11 @@ void state_t::render_sector(world::sector_t *sector)
text.setScale(0.005, 0.005);
window->draw(text);
}
+
+ stats.tiles++;
}
+
+ stats.sectors++;
}
void state_t::render(game::state_t *game)
@@ -141,6 +149,8 @@ void state_t::render(game::state_t *game)
if (debug_draw_cmodels)
drender_entity(ent);
+
+ stats.entities++;
}
}
diff --git a/src/text.cpp b/src/text.cpp
index 898466f..0959277 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -8,8 +8,6 @@ static const char *human_names[] = {
"Kowalski", "Jackson", "Carter", "O'Neill", "Hammond", "Mitchell"
};
-#define count(A) (sizeof(A) / sizeof((A)[0]))
-
static std::string get_english(index_t index)
{
switch (index) {