Made the unit_drawer own its bar rect map instead of keeping it in the display singleton
This commit is contained in:
parent
0cc0b9fc74
commit
1ff1b7fdd8
5 changed files with 20 additions and 20 deletions
|
@ -156,7 +156,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),
|
||||
|
@ -2561,7 +2560,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);
|
||||
|
|
|
@ -729,7 +729,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_;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -29,13 +29,13 @@
|
|||
#include "units/animation_component.hpp"
|
||||
#include "units/frame.hpp"
|
||||
|
||||
unit_drawer::unit_drawer(display & thedisp, std::map<surface,SDL_Rect> & 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),
|
||||
energy_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, std::map<surface,SDL_Rect> & bar_rec
|
|||
hex_size_by_2(disp.hex_size()/2)
|
||||
{}
|
||||
|
||||
void unit_drawer::redraw_unit (const unit & u) const
|
||||
void unit_drawer::redraw_unit (const unit & u)
|
||||
{
|
||||
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) const
|
|||
|
||||
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
|
||||
const color_t& col, fixed_t alpha)
|
||||
{
|
||||
|
||||
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
|
||||
const SDL_Rect& unit_drawer::calculate_energy_bar(surface surf)
|
||||
{
|
||||
const std::map<surface,SDL_Rect>::const_iterator i = energy_bar_rects_.find(surf);
|
||||
if(i != energy_bar_rects_.end()) {
|
||||
|
@ -439,11 +439,13 @@ const SDL_Rect& unit_drawer::calculate_energy_bar(surface surf) const
|
|||
}
|
||||
}
|
||||
|
||||
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));
|
||||
SDL_Rect res {
|
||||
first_col,
|
||||
first_row,
|
||||
last_col - first_col,
|
||||
last_row + 1 - first_row
|
||||
};
|
||||
|
||||
energy_bar_rects_.insert({surf, res});
|
||||
return calculate_energy_bar(surf);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef Sint32 fixed_t;
|
|||
class unit_drawer
|
||||
{
|
||||
public:
|
||||
unit_drawer(display & thedisp, std::map<surface,SDL_Rect> & bar_rects);
|
||||
unit_drawer(display & thedisp);
|
||||
|
||||
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) const;
|
||||
void redraw_unit(const unit & u);
|
||||
|
||||
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;
|
||||
const color_t& col, fixed_t alpha);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
const SDL_Rect& calculate_energy_bar(surface surf);
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue