clean and add a parameter to the sunset command for tuning the delay

...(in frames) between 2 darkenings

(as suggested by Mordante). You can still use just "sunset" to toogle,
the default is every 5 frames.
This commit is contained in:
Ali El Gariani 2007-06-02 17:54:00 +00:00
parent eb393126b2
commit a28991f607
3 changed files with 18 additions and 12 deletions

View file

@ -59,7 +59,8 @@ namespace {
const int MinZoom = 4;
const int MaxZoom = 200;
bool sunset = false;
size_t sunset_delay = 0;
size_t sunset_timer = 0;
}
display::display(unit_map& units, CVideo& video, const gamemap& map,
@ -789,8 +790,12 @@ void display::redraw_everything()
draw(true,true);
}
void display::toggle_sunset() {
sunset = !sunset;
void display::sunset(size_t delay) {
if (sunset_delay == 0) {
sunset_delay = (delay == 0 ? 5 : delay);
} else {
sunset_delay = delay;
}
}
void display::flip()
@ -801,10 +806,9 @@ void display::flip()
const surface frameBuffer = get_video_surface();
// this is just the debug function "sunset" to progressively darken the game area
// change the frequency for keeping a good framerate (specially if you use use --max-fps)
// FIXME: remove the use of random, and use some real timer
if (sunset && rand()%100 <= 10) {
// this is just the debug function "sunset" to progressively darken the map area
if (sunset_delay && ++sunset_timer > sunset_delay) {
sunset_timer = 0;
SDL_Rect r = map_area(); //use frameBuffer to also test the UI
const Uint32 color = SDL_MapRGBA(video().getSurface()->format,0,0,0,255);
// adjust the alpha if you want to balance cpu-cost / smooth sunset

View file

@ -115,6 +115,11 @@ public:
//invalidates entire screen, including all tiles and sidebar.
void redraw_everything();
//debug function to toggle the "sunset" mode
//the map area become progressively darker except where hexes are refreshed
//delay it's the number of frames between each darkening (0 to toggle)
void sunset(const size_t delay = 0);
void flip();
//draws invalidated items. If update is true, will also copy the
@ -213,10 +218,6 @@ public:
//function to remove a footstep from a specific location
void remove_footstep(const gamemap::location& loc);
//debug function to toggle the "sunset "mode
//the map area become progressively darker except where hexes are refreshed
void toggle_sunset();
//function to float a label above a tile
void float_label(const gamemap::location& loc, const std::string& text,
int red, int green, int blue);

View file

@ -1830,7 +1830,8 @@ namespace events{
} else if(cmd == "clear") {
gui_->clear_chat_messages();
} else if(cmd == "sunset") {
gui_->toggle_sunset();
int delay = lexical_cast_default<int>(data);
gui_->sunset(delay);
} else if(cmd == "w") {
save_game(data,gui::NULL_DIALOG);
} else if(cmd == "wq") {