mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-02 18:05:39 +00:00
Optimization: Only generate reports if they will be shown somewhere.
This commit is contained in:
parent
20470f4a7b
commit
713372699d
@ -31,6 +31,7 @@
|
||||
#include "map.hpp"
|
||||
#include "map_label.hpp"
|
||||
#include "minimap.hpp"
|
||||
#include "reports.hpp"
|
||||
#include "text.hpp"
|
||||
#include "time_of_day.hpp"
|
||||
#include "tooltips.hpp"
|
||||
@ -2475,7 +2476,12 @@ void display::draw_image_for_report(surface& img, SDL_Rect& rect)
|
||||
}
|
||||
}
|
||||
|
||||
void display::refresh_report(std::string const &report_name, const config &_report)
|
||||
/**
|
||||
* Redraws the specified report (if anything has changed).
|
||||
* If a config is not supplied, it will be generated via
|
||||
* reports::generate_report().
|
||||
*/
|
||||
void display::refresh_report(std::string const &report_name, const config * new_cfg)
|
||||
{
|
||||
const theme::status_item *item = theme_.get_status_item(report_name);
|
||||
if (!item) {
|
||||
@ -2483,6 +2489,11 @@ void display::refresh_report(std::string const &report_name, const config &_repo
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we will need the config. Generate one if needed.
|
||||
const config generated_cfg = new_cfg ? config() : reports::generate_report(report_name);
|
||||
if ( new_cfg == NULL )
|
||||
new_cfg = &generated_cfg;
|
||||
|
||||
SDL_Rect &rect = reportRects_[report_name];
|
||||
const SDL_Rect &new_rect = item->location(screen_area());
|
||||
surface &surf = reportSurfaces_[report_name];
|
||||
@ -2490,11 +2501,11 @@ void display::refresh_report(std::string const &report_name, const config &_repo
|
||||
config &report = reports_[report_name];
|
||||
|
||||
// Report and its location is unchanged since last time. Do nothing.
|
||||
if (surf && rect == new_rect && report == _report) {
|
||||
if (surf && rect == new_rect && report == *new_cfg) {
|
||||
return;
|
||||
}
|
||||
|
||||
report = _report;
|
||||
report = *new_cfg;
|
||||
|
||||
if (surf) {
|
||||
sdl_blit(surf, NULL, screen_.getSurface(), &rect);
|
||||
|
@ -354,7 +354,7 @@ public:
|
||||
void create_buttons();
|
||||
void invalidate_theme() { panelsDrawn_ = false; }
|
||||
|
||||
void refresh_report(std::string const &report_name, const config &);
|
||||
void refresh_report(std::string const &report_name, const config * new_cfg=NULL);
|
||||
|
||||
void draw_minimap_units();
|
||||
|
||||
|
@ -105,16 +105,16 @@ void editor_display::draw_sidebar()
|
||||
// Fill in the terrain report
|
||||
if (get_map().on_board_with_border(mouseoverHex_)) {
|
||||
text = get_map().get_terrain_editor_string(mouseoverHex_);
|
||||
refresh_report("terrain", element);
|
||||
refresh_report("terrain", &element);
|
||||
text = str_cast(mouseoverHex_);
|
||||
refresh_report("position", element);
|
||||
refresh_report("position", &element);
|
||||
}
|
||||
text = int(get_map().villages().size());
|
||||
refresh_report("villages", element);
|
||||
refresh_report("villages", &element);
|
||||
text = toolbar_hint_;
|
||||
refresh_report("editor_tool_hint", element);
|
||||
refresh_report("editor_tool_hint", &element);
|
||||
|
||||
refresh_report("terrain_image", palette_report_);
|
||||
refresh_report("terrain_image", &palette_report_);
|
||||
}
|
||||
|
||||
} //end namespace editor
|
||||
|
@ -363,23 +363,13 @@ bool game_display::has_time_area() const
|
||||
return tod_manager_.has_time_area();
|
||||
}
|
||||
|
||||
void game_display::draw_report(const std::string &report_name)
|
||||
{
|
||||
if(!team_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
refresh_report(report_name, reports::generate_report(report_name));
|
||||
}
|
||||
|
||||
void game_display::draw_sidebar()
|
||||
{
|
||||
draw_report("report_clock");
|
||||
draw_report("report_countdown");
|
||||
|
||||
if(teams_->empty()) {
|
||||
if ( !team_valid() )
|
||||
return;
|
||||
}
|
||||
|
||||
refresh_report("report_clock");
|
||||
refresh_report("report_countdown");
|
||||
|
||||
if (invalidateGameStatus_)
|
||||
{
|
||||
@ -388,7 +378,7 @@ void game_display::draw_sidebar()
|
||||
// We display the unit the mouse is over if it is over a unit,
|
||||
// otherwise we display the unit that is selected.
|
||||
BOOST_FOREACH(const std::string &name, reports::report_list()) {
|
||||
draw_report(name);
|
||||
refresh_report(name);
|
||||
}
|
||||
invalidateGameStatus_ = false;
|
||||
}
|
||||
|
@ -125,8 +125,6 @@ public:
|
||||
/** Draws the movement info (turns available) for a given location. */
|
||||
void draw_movement_info(const map_location& loc);
|
||||
|
||||
void draw_report(const std::string &report_name);
|
||||
|
||||
/** Function to invalidate that unit status displayed on the sidebar. */
|
||||
void invalidate_unit() { invalidateGameStatus_ = true; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user