added the --fps option...

...to display the number of fps the game is running at in-game
This commit is contained in:
Dave White 2005-01-27 03:45:00 +00:00
parent a51cc5478f
commit 89122101f2
5 changed files with 52 additions and 4 deletions

View file

@ -78,7 +78,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
theme_(theme_cfg,screen_area()), builder_(cfg, level, map),
first_turn_(true), in_game_(false), map_labels_(*this,map),
tod_hex_mask1(NULL), tod_hex_mask2(NULL), diagnostic_label_(0),
help_string_(0)
help_string_(0), fps_handle_(0)
{
if(non_interactive())
updatesLocked_++;
@ -671,11 +671,14 @@ void display::draw(bool update,bool force)
SDL_Delay(maximum<int>(10,wait_time));
if(update) {
lastDraw_ = SDL_GetTicks();
const int thisDraw = SDL_GetTicks();
const int latency = thisDraw - lastDraw_;
lastDraw_ = thisDraw;
if(wait_time >= 0 || drawSkips_ >= max_skips || force) {
if(changed)
if(changed) {
update_display();
}
} else {
drawSkips_++;
}
@ -687,6 +690,31 @@ void display::update_display()
if(updatesLocked_ > 0)
return;
if(preferences::show_fps()) {
static int last_sample = SDL_GetTicks();
static int frames = 0;
++frames;
if(frames == 10) {
const int this_sample = SDL_GetTicks();
const int fps = (frames*1000)/(this_sample - last_sample);
last_sample = this_sample;
frames = 0;
if(fps_handle_ != 0) {
font::remove_floating_label(fps_handle_);
fps_handle_ = 0;
}
std::ostringstream stream;
stream << fps << "fps";
fps_handle_ = font::add_floating_label(stream.str(),12,font::NORMAL_COLOUR,10,100,0,0,-1,screen_area(),font::LEFT_ALIGN);
}
} else if(fps_handle_ != 0) {
font::remove_floating_label(fps_handle_);
fps_handle_ = 0;
}
screen_.flip();
}

View file

@ -508,6 +508,9 @@ private:
//animated flags for each team
std::vector<animated<image::locator> > flags_;
//the handle for the label which displays fps
int fps_handle_;
};
//an object which will lock the display for the duration of its lifetime.

View file

@ -384,7 +384,9 @@ game_controller::game_controller(int argc, char** argv, bool use_sound)
continue;
}
if(val == "--nocache") {
if(val == "--fps") {
preferences::set_show_fps(true);
} else if(val == "--nocache") {
use_caching_ = false;
} else if(val == "--resolution" || val == "-r") {
if(arg_+1 != argc_) {

View file

@ -52,6 +52,8 @@ bool haloes = true;
bool unit_genders = true;
bool fps = false;
std::set<std::string> encountered_units_set;
std::set<std::string> encountered_terrains_set;
@ -704,6 +706,16 @@ void set_show_haloes(bool value)
prefs["show_haloes"] = value ? "yes" : "no";
}
bool show_fps()
{
return fps;
}
void set_show_fps(bool value)
{
fps = value;
}
std::set<std::string> &encountered_units() {
return encountered_units_set;
}

View file

@ -146,6 +146,9 @@ namespace preferences {
bool show_haloes();
void set_show_haloes(bool value);
bool show_fps();
void set_show_fps(bool value);
std::set<std::string> &encountered_units();
std::set<std::string> &encountered_terrains();