Skip to content

Commit

Permalink
redraw_unit takes display & as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 17, 2014
1 parent f0fc9ff commit 4ff77b8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/display.cpp
Expand Up @@ -32,6 +32,7 @@
#include "minimap.hpp"
#include "play_controller.hpp" //note: this can probably be refactored out
#include "reports.hpp"
#include "team.hpp"
#include "terrain_builder.hpp"
#include "text.hpp"
#include "time_of_day.hpp"
Expand Down Expand Up @@ -2554,7 +2555,7 @@ void display::draw_invalidated() {
exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc);
if (u_it != dc_->units().end()
&& (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id()))
(static_cast<const drawable_unit*> (&*u_it))->redraw_unit();
(static_cast<const drawable_unit*> (&*u_it))->redraw_unit(*this);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/display.hpp
Expand Up @@ -165,7 +165,7 @@ class display

void change_display_context(const display_context * dc);

const display_context & get_disp_context() { return *dc_; }
const display_context & get_disp_context() const { return *dc_; }

static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
{ return 0xFF000000 | (red << 16) | (green << 8) | blue; }
Expand Down
15 changes: 9 additions & 6 deletions src/drawable_unit.cpp
Expand Up @@ -25,12 +25,15 @@

#include <boost/foreach.hpp>

void drawable_unit::redraw_unit () const
void drawable_unit::redraw_unit (display & disp) const
{
display &disp = *display::get_singleton();
const gamemap &map = disp.get_map();
const display_context & dc = disp.get_disp_context();
const gamemap &map = dc.map();
const std::vector<team> &teams = dc.teams();

if ( hidden_ || disp.is_blindfolded() || !is_visible_to_team(disp.get_teams()[disp.viewing_team()],map, disp.show_everything()) )
const team & viewing_team = teams[disp.viewing_team()];

if ( hidden_ || disp.is_blindfolded() || !is_visible_to_team(viewing_team,map, disp.show_everything()) )
{
clear_haloes();
if(anim_) {
Expand Down Expand Up @@ -197,7 +200,7 @@ void drawable_unit::redraw_unit () const

if(size_t(side()) != disp.viewing_team()+1) {
if(disp.team_valid() &&
disp.get_teams()[disp.viewing_team()].is_enemy(side())) {
viewing_team.is_enemy(side())) {
if (preferences::show_enemy_orb() && !get_state(STATE_PETRIFIED))
orb_img = &enemy_orb;
else
Expand All @@ -217,7 +220,7 @@ void drawable_unit::redraw_unit () const
if (preferences::show_unmoved_orb())
orb_img = &unmoved_orb;
else orb_img = NULL;
} else if ( disp.get_disp_context().unit_can_move(*this) ) {
} else if ( dc.unit_can_move(*this) ) {
if (preferences::show_partial_orb())
orb_img = &partmoved_orb;
else orb_img = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/drawable_unit.hpp
Expand Up @@ -33,7 +33,7 @@ class drawable_unit : protected unit //TODO: Get rid of inheritance and use comp
{ //IMO, it would be better for drawable unit to hold a unit reference, and be marked as a friend class.
//But I don't want to rewrite the redraw() function right now.
/** draw a unit. */
void redraw_unit() const;
void redraw_unit(display & disp) const;

friend class display;
friend class game_display;
Expand Down
2 changes: 1 addition & 1 deletion src/game_display.cpp
Expand Up @@ -252,7 +252,7 @@ void game_display::draw_invalidated()
exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc);
if (invalidated_.find(loc) != invalidated_.end()
&& (request == exclusive_unit_draw_requests_.end() || request->second == temp_unit->id()))
(static_cast<const drawable_unit*> (temp_unit))->redraw_unit();
(static_cast<const drawable_unit*> (temp_unit))->redraw_unit(*this);
}
}

Expand Down

0 comments on commit 4ff77b8

Please sign in to comment.