Revert "Made the unit_drawer own its bar rect map instead of keeping it in the display singleton"

This reverts commit 1ff1b7fdd8. I've been informed this is inferior, performance-wise.
This commit is contained in:
Charles Dang 2017-03-08 19:18:14 +11:00
parent 1ff1b7fdd8
commit d10c4e7a0b
5 changed files with 20 additions and 20 deletions

View file

@ -156,6 +156,7 @@ 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),
@ -2560,7 +2561,7 @@ void display::draw_invalidated() {
return;
}
unit_drawer drawer = unit_drawer(*this);
unit_drawer drawer = unit_drawer(*this, energy_bar_rects_);
for (const map_location& loc : invalidated_) {
unit_map::const_iterator u_it = dc_->units().find(loc);

View file

@ -729,6 +729,7 @@ 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);
unit_drawer drawer = unit_drawer(*this, energy_bar_rects_);
for (const unit* temp_unit : *fake_unit_man_) {
const map_location& loc = temp_unit->get_location();

View file

@ -29,13 +29,13 @@
#include "units/animation_component.hpp"
#include "units/frame.hpp"
unit_drawer::unit_drawer(display & thedisp) :
unit_drawer::unit_drawer(display & thedisp, std::map<surface,SDL_Rect> & bar_rects) :
disp(thedisp),
dc(disp.get_disp_context()),
map(dc.map()),
teams(dc.teams()),
halo_man(thedisp.get_halo_manager()),
energy_bar_rects_(),
energy_bar_rects_(bar_rects),
viewing_team(disp.viewing_team()),
playing_team(disp.playing_team()),
viewing_team_ref(teams[viewing_team]),
@ -49,7 +49,7 @@ unit_drawer::unit_drawer(display & thedisp) :
hex_size_by_2(disp.hex_size()/2)
{}
void unit_drawer::redraw_unit (const unit & u)
void unit_drawer::redraw_unit (const unit & u) const
{
unit_animation_component & ac = u.anim_comp();
map_location loc = u.get_location();
@ -336,7 +336,7 @@ void unit_drawer::redraw_unit (const unit & u)
void unit_drawer::draw_bar(const std::string& image, int xpos, int ypos,
const map_location& loc, size_t height, double filled,
const color_t& col, fixed_t alpha)
const color_t& col, fixed_t alpha) const
{
filled = std::min<double>(std::max<double>(filled,0.0),1.0);
@ -408,7 +408,7 @@ struct is_energy_color {
(color&0x000000FF) < 0x00000010; }
};
const SDL_Rect& unit_drawer::calculate_energy_bar(surface surf)
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()) {
@ -439,13 +439,11 @@ const SDL_Rect& unit_drawer::calculate_energy_bar(surface surf)
}
}
SDL_Rect res {
first_col,
first_row,
last_col - first_col,
last_row + 1 - first_row
};
energy_bar_rects_.insert({surf, res});
const SDL_Rect res = sdl::create_rect(first_col
, first_row
, last_col-first_col
, last_row+1-first_row);
energy_bar_rects_.insert(std::pair<surface,SDL_Rect>(surf,res));
return calculate_energy_bar(surf);
}

View file

@ -45,7 +45,7 @@ typedef Sint32 fixed_t;
class unit_drawer
{
public:
unit_drawer(display & thedisp);
unit_drawer(display & thedisp, std::map<surface,SDL_Rect> & bar_rects);
private:
display & disp;
@ -53,7 +53,7 @@ private:
const gamemap & map;
const std::vector<team> & teams;
halo::manager & halo_man;
std::map<surface,SDL_Rect> energy_bar_rects_;
std::map<surface,SDL_Rect> & energy_bar_rects_;
size_t viewing_team;
size_t playing_team;
const team & viewing_team_ref;
@ -69,19 +69,19 @@ private:
public:
/** draw a unit. */
void redraw_unit(const unit & u);
void redraw_unit(const unit & u) const;
private:
/** draw a health/xp bar of a unit */
void draw_bar(const std::string& image, int xpos, int ypos,
const map_location& loc, size_t height, double filled,
const color_t& col, fixed_t alpha);
const color_t& col, fixed_t alpha) const;
/**
* Finds the start and end rows on the energy bar image.
*
* White pixels are substituted for the color of the energy.
*/
const SDL_Rect& calculate_energy_bar(surface surf);
const SDL_Rect& calculate_energy_bar(surface surf) const;
};
#endif