Skip to content

Commit

Permalink
Merge branch 'units_draw_const'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 10, 2014
2 parents 534e351 + 4459277 commit 5dad318
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 94 deletions.
3 changes: 2 additions & 1 deletion src/actions/attack.cpp
Expand Up @@ -994,7 +994,8 @@ namespace {
}
}

unit_display::unit_attack(attacker.loc_, defender.loc_, damage,
unit_display::unit_attack(game_display::get_singleton(), *resources::gameboard,
attacker.loc_, defender.loc_, damage,
*attacker_stats->weapon, defender_stats->weapon,
abs_n, float_text.str(), drains_damage, "");
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/move.cpp
Expand Up @@ -494,7 +494,7 @@ namespace { // Private helpers for move_unit()
moves_left_.pop_front();

// Invalidate before moving so we invalidate neighbor hexes if needed.
move_it_->invalidate(*move_loc_);
move_it_->invalidate(disp);

// Attempt actually moving.
// (Fails if *step_to is occupied).
Expand Down
16 changes: 8 additions & 8 deletions src/display.cpp
Expand Up @@ -569,7 +569,7 @@ void display::change_map(const gamemap* m)
builder_->change_map(m);
}

void display::change_units(unit_map* umap)
void display::change_units(const unit_map* umap)
{
units_ = umap;
}
Expand Down Expand Up @@ -2554,7 +2554,7 @@ void display::draw_invalidated() {
invalidated_hexes_ += invalidated_.size();

BOOST_FOREACH(const map_location& loc, invalidated_) {
unit_map::iterator u_it = units_->find(loc);
unit_map::const_iterator u_it = units_->find(loc);
exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc);
if (u_it != units_->end()
&& (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id()))
Expand Down Expand Up @@ -3034,9 +3034,9 @@ void display::invalidate_animations_location(const map_location& loc) {
}


std::vector<unit*> display::get_unit_list_for_invalidation() {
std::vector<unit*> unit_list;
BOOST_FOREACH(unit &u, *units_) {
std::vector<const unit*> display::get_unit_list_for_invalidation() {
std::vector<const unit*> unit_list;
BOOST_FOREACH(const unit &u, *units_) {
unit_list.push_back(&u);
}
return unit_list;
Expand All @@ -3056,8 +3056,8 @@ void display::invalidate_animations()
}
}
}
std::vector<unit*> unit_list=get_unit_list_for_invalidation();
BOOST_FOREACH(unit* u, unit_list) {
std::vector<const unit*> unit_list=get_unit_list_for_invalidation();
BOOST_FOREACH(const unit* u, unit_list) {
u->refresh();
}
bool new_inval;
Expand All @@ -3067,7 +3067,7 @@ void display::invalidate_animations()
#pragma omp parallel for reduction(|:new_inval) shared(unit_list) schedule(guided)
#endif //_OPENMP
for(int i=0; i < static_cast<int>(unit_list.size()); i++) {
new_inval |= unit_list[i]->invalidate(unit_list[i]->get_location());
new_inval |= unit_list[i]->invalidate(*this);
}
}while(new_inval);
}
Expand Down
9 changes: 4 additions & 5 deletions src/display.hpp
Expand Up @@ -96,8 +96,7 @@ class display
* Cancels all the exclusive draw requests.
*/
void clear_exclusive_draws() { exclusive_unit_draw_requests_.clear(); }
unit_map& get_units() {return *units_;}
const unit_map& get_const_units() const {return *units_;}
const unit_map& get_units() const {return *units_;}

/**
* Allows a unit to request to be the only one drawn in its hex. Useful for situations where
Expand Down Expand Up @@ -155,7 +154,7 @@ class display

void change_map(const gamemap* m);
void change_teams(const std::vector<team>* teams);
void change_units(unit_map* units);
void change_units(const unit_map* units);

static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
{ return 0xFF000000 | (red << 16) | (green << 8) | blue; }
Expand Down Expand Up @@ -411,7 +410,7 @@ class display
* helper function for invalidate_animations
* returns a list of units to check for invalidation
*/
virtual std::vector<unit*> get_unit_list_for_invalidation();
virtual std::vector<const unit*> get_unit_list_for_invalidation();

/**
* Per-location invalidation called by invalidate_animations()
Expand Down Expand Up @@ -628,7 +627,7 @@ class display

protected:
//TODO sort
unit_map* units_;
const unit_map* units_;

typedef std::map<map_location, std::string> exclusive_unit_draw_requests_t;
/// map of hexes where only one unit should be drawn, the one identified by the associated id string
Expand Down
4 changes: 4 additions & 0 deletions src/game_board.hpp
Expand Up @@ -124,6 +124,10 @@ class game_board {
bool has_visible_unit (const map_location & loc, size_t team, bool see_all = false) { return has_visible_unit(loc, teams_[team], see_all); }

unit* get_visible_unit(const map_location &loc, const team &current_team, bool see_all = false); //TODO: can this not return a pointer?

// Wrapped functions from unit_map. These should ultimately provide notification to observers, pathfinding.

unit_map::iterator find_unit(const map_location & loc) { return units_.find(loc); }
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/game_display.cpp
Expand Up @@ -620,9 +620,9 @@ void game_display::float_label(const map_location& loc, const std::string& text,
font::add_floating_label(flabel);
}

std::vector<unit*> game_display::get_unit_list_for_invalidation() {
std::vector<unit*> unit_list = display::get_unit_list_for_invalidation();;
BOOST_FOREACH(unit *u, fake_units_) {
std::vector<const unit*> game_display::get_unit_list_for_invalidation() {
std::vector<const unit*> unit_list = display::get_unit_list_for_invalidation();;
BOOST_FOREACH(const unit *u, fake_units_) {
unit_list.push_back(u);
}
return unit_list;;
Expand Down
2 changes: 1 addition & 1 deletion src/game_display.hpp
Expand Up @@ -154,7 +154,7 @@ class game_display : public display
/**
* the list of units we need to look at, game_display adds fake units
*/
virtual std::vector<unit*> get_unit_list_for_invalidation();
virtual std::vector<const unit*> get_unit_list_for_invalidation();


public:
Expand Down
2 changes: 1 addition & 1 deletion src/game_events/action_wml.cpp
Expand Up @@ -945,7 +945,7 @@ WML_HANDLER_FUNCTION(kill, event_info, cfg)
resources::screen->invalidate(loc);
unit_map::iterator iun = resources::units->find(loc);
if ( iun != resources::units->end() && iun.valid() )
iun->invalidate(loc);
iun->invalidate(*resources::screen);
}
resources::screen->redraw_minimap();

Expand Down
4 changes: 2 additions & 2 deletions src/leader_scroll_dialog.cpp
Expand Up @@ -59,7 +59,7 @@ void status_table(display& gui, int selected)
items.push_back(heading.str());

const gamemap& map = gui.get_map();
const unit_map& units = gui.get_const_units();
const unit_map& units = gui.get_units();
assert(&gui.get_teams() == resources::teams);
const std::vector<team>& teams = gui.get_teams();

Expand Down Expand Up @@ -201,7 +201,7 @@ void scenario_settings_table(display& gui, int selected)
items.push_back(heading.str());

//const gamemap& map = gui.get_map();
const unit_map& units = gui.get_const_units();
const unit_map& units = gui.get_units();
const std::vector<team>& teams = gui.get_teams();

const team& viewing_team = teams[gui.viewing_team()];
Expand Down
33 changes: 16 additions & 17 deletions src/unit.cpp
Expand Up @@ -1803,7 +1803,7 @@ const surface unit::still_image(bool scaled) const
return unit_image;
}

void unit::set_standing(bool with_bars)
void unit::set_standing(bool with_bars) const
{
display *disp = display::get_singleton();
if (preferences::show_standing_animations()&& !incapacitated()) {
Expand All @@ -1815,28 +1815,28 @@ void unit::set_standing(bool with_bars)
}
}

void unit::set_ghosted(bool with_bars)
void unit::set_ghosted(bool with_bars) const
{
display *disp = display::get_singleton();
start_animation(INT_MAX, choose_animation(*disp, loc_, "ghosted"),
with_bars);
}

void unit::set_disabled_ghosted(bool with_bars)
void unit::set_disabled_ghosted(bool with_bars) const
{
display *disp = display::get_singleton();
start_animation(INT_MAX, choose_animation(*disp, loc_, "disabled_ghosted"),
with_bars);
}

void unit::set_idling()
void unit::set_idling() const
{
display *disp = display::get_singleton();
start_animation(INT_MAX, choose_animation(*disp, loc_, "idling"),
true, "", 0, STATE_FORGET);
}

void unit::set_selecting()
void unit::set_selecting() const
{
const display *disp = display::get_singleton();
if (preferences::show_standing_animations() && !get_state(STATE_PETRIFIED)) {
Expand All @@ -1848,8 +1848,8 @@ void unit::set_selecting()
}
}

void unit::start_animation(int start_time, const unit_animation *animation,
bool with_bars, const std::string &text, Uint32 text_color, STATE state)
void unit::start_animation (int start_time, const unit_animation *animation,
bool with_bars, const std::string &text, Uint32 text_color, STATE state) const
{
const display * disp = display::get_singleton();
if (!animation) {
Expand Down Expand Up @@ -1877,14 +1877,14 @@ void unit::start_animation(int start_time, const unit_animation *animation,
}


void unit::set_facing(map_location::DIRECTION dir) {
void unit::set_facing(map_location::DIRECTION dir) const {
if(dir != map_location::NDIRECTIONS) {
facing_ = dir;
}
// Else look at yourself (not available so continue to face the same direction)
}

void unit::redraw_unit()
void unit::redraw_unit () const
{
display &disp = *display::get_singleton();
const gamemap &map = disp.get_map();
Expand Down Expand Up @@ -2151,27 +2151,26 @@ void unit::redraw_unit()
refreshing_ = false;
}

void unit::clear_haloes()
void unit::clear_haloes () const
{
if(unit_halo_ != halo::NO_HALO) {
halo::remove(unit_halo_);
unit_halo_ = halo::NO_HALO;
}
if(anim_ ) anim_->clear_haloes();
}
bool unit::invalidate(const map_location &loc)
bool unit::invalidate (const display & disp) const
{
bool result = false;

// Very early calls, anim not initialized yet
if(get_animation()) {
frame_parameters params;
const display * disp = display::get_singleton();
const gamemap & map = disp->get_map();
const t_translation::t_terrain terrain = map.get_terrain(loc);
const gamemap & map = disp.get_map();
const t_translation::t_terrain terrain = map.get_terrain(get_location());
const terrain_type& terrain_info = map.get_terrain_info(terrain);

int height_adjust = static_cast<int>(terrain_info.unit_height_adjust() * disp->get_zoom_factor());
int height_adjust = static_cast<int>(terrain_info.unit_height_adjust() * disp.get_zoom_factor());
if (is_flying() && height_adjust < 0) {
height_adjust = 0;
}
Expand Down Expand Up @@ -3027,7 +3026,7 @@ int side_upkeep(int side)
return res;
}

void unit::refresh()
void unit::refresh() const
{
if (state_ == STATE_FORGET && anim_ && anim_->animation_finished_potential())
{
Expand Down Expand Up @@ -3119,7 +3118,7 @@ void unit::remove_movement_ai()
}


void unit::set_hidden(bool state) {
void unit::set_hidden(bool state) const {
hidden_ = state;
if(!state) return;
// We need to get rid of haloes immediately to avoid display glitches
Expand Down
50 changes: 25 additions & 25 deletions src/unit.hpp
Expand Up @@ -204,7 +204,7 @@ class unit
void end_turn();
void new_scenario();
/** Called on every draw */
void refresh();
void refresh() const;

bool take_hit(int damage) { hit_points_ -= damage; return hit_points_ <= 0; }
void heal(int amount);
Expand Down Expand Up @@ -249,23 +249,22 @@ class unit
const surface still_image(bool scaled = false) const;

/** draw a unit. */
void redraw_unit();
void redraw_unit() const;
/** Clear unit_halo_ */
void clear_haloes();
void clear_haloes() const;

void set_standing(bool with_bars = true);
void set_standing(bool with_bars = true) const;

void set_ghosted(bool with_bars = true);
void set_disabled_ghosted(bool with_bars = true);
void set_ghosted(bool with_bars = true) const;
void set_disabled_ghosted(bool with_bars = true) const;

void set_idling();
void set_selecting();
unit_animation* get_animation() { return anim_.get();}
const unit_animation* get_animation() const { return anim_.get();}
void set_facing(map_location::DIRECTION dir);
void set_idling() const;
void set_selecting() const;
unit_animation* get_animation() const { return anim_.get();}
void set_facing(map_location::DIRECTION dir) const;
map_location::DIRECTION facing() const { return facing_; }

bool invalidate(const map_location &loc);
bool invalidate(const display & disp) const;
const std::vector<t_string>& trait_names() const { return trait_names_; }
const std::vector<t_string>& trait_descriptions() const { return trait_descriptions_; }
std::vector<std::string> get_traits_list() const;
Expand All @@ -282,7 +281,7 @@ class unit
int upkeep() const;
bool loyal() const;

void set_hidden(bool state);
void set_hidden(bool state) const;
bool get_hidden() const { return hidden_; }
bool is_flying() const { return movement_type_.is_flying(); }
bool is_fearless() const { return is_fearless_; }
Expand Down Expand Up @@ -327,9 +326,9 @@ class unit
STATE_STANDING, /** anim must fit in a hex */
STATE_FORGET, /** animation will be automatically replaced by a standing anim when finished */
STATE_ANIM}; /** normal anims */
void start_animation(int start_time, const unit_animation *animation,
void start_animation (int start_time, const unit_animation *animation,
bool with_bars, const std::string &text = "",
Uint32 text_color = 0, STATE state = STATE_ANIM);
Uint32 text_color = 0, STATE state = STATE_ANIM) const;

/** The name of the file to game_display (used in menus). */
std::string absolute_image() const;
Expand Down Expand Up @@ -488,14 +487,15 @@ class unit
config events_;
config filter_recall_;
bool emit_zoc_;
STATE state_;

mutable STATE state_; //animation state

std::vector<std::string> overlays_;

std::string role_;
std::vector<attack_type> attacks_;
map_location::DIRECTION facing_;

mutable map_location::DIRECTION facing_; //TODO: I think we actually consider this to be part of the gamestate, so it might be better if it's not mutable
//But it's not easy to separate this guy from the animation code right now.
std::vector<t_string> trait_names_;
std::vector<t_string> trait_descriptions_;

Expand All @@ -508,16 +508,16 @@ class unit
// Animations:
std::vector<unit_animation> animations_;

boost::scoped_ptr<unit_animation> anim_;
int next_idling_;
int frame_begin_time_;
mutable boost::scoped_ptr<unit_animation> anim_;
mutable int next_idling_; // used for animation
mutable int frame_begin_time_; // used for animation


int unit_halo_;
mutable int unit_halo_; // flag used for drawing / animation
bool getsHit_;
bool refreshing_; // avoid infinite recursion
bool hidden_;
bool draw_bars_;
mutable bool refreshing_; // avoid infinite recursion. flag used for drawing / animation
mutable bool hidden_;
mutable bool draw_bars_; // flag used for drawing / animation
double hp_bar_scaling_, xp_bar_scaling_;

config modifications_;
Expand Down

0 comments on commit 5dad318

Please sign in to comment.