Made energy_bar_rects static in unit_drawer file (superior version of 1ff1b7fdd)

I reverted the aforementioned commit after being informed it would be inferior, performance-wise.
However, this should solve that as the map is no longer constantly recreated.

This also addresses some issues I had with the original commit where I had to make some member
functions non-const.
This commit is contained in:
Charles Dang 2017-05-17 22:40:02 +11:00
parent 4479682469
commit 5e6e8eab6f
5 changed files with 10 additions and 11 deletions

View file

@ -155,7 +155,6 @@ display::display(const display_context * dc, CVideo& video, std::weak_ptr<wb::ma
screen_(video),
currentTeam_(0),
dont_show_all_(false),
energy_bar_rects_(),
xpos_(0),
ypos_(0),
view_locked_(false),
@ -2503,7 +2502,7 @@ void display::draw_invalidated() {
return;
}
unit_drawer drawer = unit_drawer(*this, energy_bar_rects_);
unit_drawer drawer = unit_drawer(*this);
for (const map_location& loc : invalidated_) {
unit_map::const_iterator u_it = dc_->units().find(loc);

View file

@ -711,7 +711,6 @@ protected:
CVideo& screen_;
size_t currentTeam_;
bool dont_show_all_; //const team *viewpoint_;
std::map<surface,SDL_Rect> energy_bar_rects_;
int xpos_, ypos_;
bool view_locked_;
theme theme_;

View file

@ -252,7 +252,7 @@ void game_display::draw_invalidated()
if (fake_unit_man_->empty()) {
return;
}
unit_drawer drawer = unit_drawer(*this, energy_bar_rects_);
unit_drawer drawer = unit_drawer(*this);
for (const unit* temp_unit : *fake_unit_man_) {
const map_location& loc = temp_unit->get_location();

View file

@ -29,13 +29,15 @@
#include "units/animation_component.hpp"
#include "units/frame.hpp"
unit_drawer::unit_drawer(display & thedisp, std::map<surface,SDL_Rect> & bar_rects) :
// Map of different energy bar surfaces and their dimensions.
static std::map<surface, SDL_Rect> energy_bar_rects;
unit_drawer::unit_drawer(display & thedisp) :
disp(thedisp),
dc(disp.get_disp_context()),
map(dc.map()),
teams(dc.teams()),
halo_man(thedisp.get_halo_manager()),
energy_bar_rects_(bar_rects),
viewing_team(disp.viewing_team()),
playing_team(disp.playing_team()),
viewing_team_ref(teams[viewing_team]),
@ -411,8 +413,8 @@ struct is_energy_color {
const SDL_Rect& unit_drawer::calculate_energy_bar(surface surf) const
{
const std::map<surface,SDL_Rect>::const_iterator i = energy_bar_rects_.find(surf);
if(i != energy_bar_rects_.end()) {
const std::map<surface,SDL_Rect>::const_iterator i = energy_bar_rects.find(surf);
if(i != energy_bar_rects.end()) {
return i->second;
}
@ -446,7 +448,7 @@ const SDL_Rect& unit_drawer::calculate_energy_bar(surface surf) const
, last_col-first_col
, last_row+1-first_row
};
energy_bar_rects_.emplace(surf, res);
energy_bar_rects.emplace(surf, res);
return calculate_energy_bar(surf);
}

View file

@ -43,7 +43,7 @@ class surface;
class unit_drawer
{
public:
unit_drawer(display & thedisp, std::map<surface,SDL_Rect> & bar_rects);
explicit unit_drawer(display & thedisp);
private:
display & disp;
@ -51,7 +51,6 @@ private:
const gamemap & map;
const std::vector<team> & teams;
halo::manager & halo_man;
std::map<surface,SDL_Rect> & energy_bar_rects_;
size_t viewing_team;
size_t playing_team;
const team & viewing_team_ref;