New debug tool to analyze invalidation performance:

When fps and debug are activated, also show the mean number of drawn
hexes by frame

If some hexes are invalidated but not drawn (off-screen anims) also
show this number between parenthesis

Also changed "30fps" to "fps: 30" for better readability of these
debug info when around 10
This commit is contained in:
Ali El Gariani 2009-05-12 18:56:07 +00:00
parent 66c62d5dd1
commit 74b4880b97
2 changed files with 20 additions and 3 deletions

View File

@ -121,6 +121,8 @@ display::display(CVideo& video, const gamemap* map, const config& theme_cfg, con
#endif #endif
map_screenshot_(false), map_screenshot_(false),
fps_handle_(0), fps_handle_(0),
invalidated_hexes_(0),
drawn_hexes_(0),
idle_anim_(preferences::idle_anim()), idle_anim_(preferences::idle_anim()),
idle_anim_rate_(1.0), idle_anim_rate_(1.0),
map_screenshot_surf_(NULL), map_screenshot_surf_(NULL),
@ -883,8 +885,8 @@ void display::update_display()
static int last_sample = SDL_GetTicks(); static int last_sample = SDL_GetTicks();
static int frames = 0; static int frames = 0;
++frames; ++frames;
const int sample_freq = 10;
if(frames == 10) { if(frames == sample_freq) {
const int this_sample = SDL_GetTicks(); const int this_sample = SDL_GetTicks();
const int fps = (frames*1000)/(this_sample - last_sample); const int fps = (frames*1000)/(this_sample - last_sample);
@ -896,7 +898,15 @@ void display::update_display()
fps_handle_ = 0; fps_handle_ = 0;
} }
std::ostringstream stream; std::ostringstream stream;
stream << fps << "fps"; stream << "fps: " << fps;
if (game_config::debug) {
stream << "\nhex: " << drawn_hexes_*1.0/sample_freq;
if (drawn_hexes_ != invalidated_hexes_)
stream << " (" << (invalidated_hexes_-drawn_hexes_)*1.0/sample_freq << ")";
}
drawn_hexes_ = 0;
invalidated_hexes_ = 0;
fps_handle_ = font::add_floating_label(stream.str(),12, fps_handle_ = font::add_floating_label(stream.str(),12,
benchmark ? font::BAD_COLOUR : font::NORMAL_COLOUR, benchmark ? font::BAD_COLOUR : font::NORMAL_COLOUR,
10,100,0,0,-1,screen_area(),font::LEFT_ALIGN); 10,100,0,0,-1,screen_area(),font::LEFT_ALIGN);
@ -904,6 +914,8 @@ void display::update_display()
} else if(fps_handle_ != 0) { } else if(fps_handle_ != 0) {
font::remove_floating_label(fps_handle_); font::remove_floating_label(fps_handle_);
fps_handle_ = 0; fps_handle_ = 0;
drawn_hexes_ = 0;
invalidated_hexes_ = 0;
} }
flip(); flip();
@ -1984,11 +1996,13 @@ void display::draw_invalidated() {
continue; continue;
} }
draw_hex(loc); draw_hex(loc);
drawn_hexes_+=1;
// If the tile is at the border, we start to blend it // If the tile is at the border, we start to blend it
if(!on_map && !off_map_tile) { if(!on_map && !off_map_tile) {
draw_border(loc, xpos, ypos); draw_border(loc, xpos, ypos);
} }
} }
invalidated_hexes_ += invalidated_.size();
} }
void display::draw_hex(const map_location& loc) { void display::draw_hex(const map_location& loc) {

View File

@ -818,6 +818,9 @@ protected:
private: private:
/** Handle for the label which displays frames per second. */ /** Handle for the label which displays frames per second. */
int fps_handle_; int fps_handle_;
/** Count work done for the debug info displayed under fps */
int invalidated_hexes_;
int drawn_hexes_;
bool idle_anim_; bool idle_anim_;
double idle_anim_rate_; double idle_anim_rate_;