fix bug #9398 (Attacking units always above defending units).

Now correctly z-ordered.

- insert the temporary unit in the common set of invalidated units

- add a STL-sorting in this set using a z-order to draw hexes in the
good sequence (maybe also use this idea elsewhere ?)
This commit is contained in:
Ali El Gariani 2007-06-29 13:46:19 +00:00
parent d7c2140e83
commit dbe422c928
2 changed files with 21 additions and 8 deletions

View file

@ -385,6 +385,14 @@ protected:
void invalidate_locations_in_rect(SDL_Rect r);
// Strict weak ordering to sort a STL-set of hexes for drawing
// using the z-order. (1000 are just to weight the y compare to x)
struct ordered_draw : public std::binary_function<gamemap::location, gamemap::location, bool> {
bool operator()(gamemap::location a, gamemap::location b) {
return (a.y*2 + a.x%2) * 1000 + a.x < (b.y*2 + b.x%2) * 1000 + b.x;
}
};
//function to invalidate controls and panels when changed after
//they have been drawn initially. Useful for dynamic theme modification.
bool draw_init();

View file

@ -231,7 +231,7 @@ void game_display::draw(bool update,bool force)
// Units can overlap multiple hexes, so we need to (1)
// redraw them last, and (2) redraw them if they are
// adjacent existing hexes.
std::set<gamemap::location> unit_invals;
std::set<gamemap::location, ordered_draw> unit_invals;
SDL_Rect clip_rect = map_area();
surface const dst(screen_.getSurface());
@ -239,9 +239,10 @@ void game_display::draw(bool update,bool force)
std::set<gamemap::location>::const_iterator it;
for(it = invalidated_.begin(); it != invalidated_.end(); ++it) {
if (units_.find(*it) != units_.end()) {
if ((temp_unit_ && temp_unit_loc_==*it) || units_.find(*it) != units_.end()) {
unit_invals.insert(*it);
}
const time_of_day& tod = status_.get_time_of_day();
const time_of_day& tod_at = timeofday_at(status_,units_,*it,map_);
image::TYPE image_type = image::SCALED_TO_HEX;
@ -388,12 +389,16 @@ void game_display::draw(bool update,bool force)
}
for(it = unit_invals.begin(); it != unit_invals.end(); ++it) {
unit &u = units_.find(*it)->second;
u.redraw_unit(*this, *it);
//simulate_delay += 1;
}
if (temp_unit_ && invalidated_.find(temp_unit_loc_) != invalidated_.end()) {
temp_unit_->redraw_unit(*this, temp_unit_loc_);
unit_map::iterator u_it = units_.find(*it);
if (u_it != units_.end()) {
u_it->second.redraw_unit(*this, *it);
//simulate_delay += 1;
}
if (temp_unit_ && temp_unit_loc_ == *it) {
temp_unit_->redraw_unit(*this, temp_unit_loc_);
//simulate_delay += 1;
}
}
halo::render();