Skip to content

Commit

Permalink
fake unit manager returns a range rather than & to container
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 18, 2014
1 parent fd9379e commit 44a0752
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/display.cpp
Expand Up @@ -3056,7 +3056,7 @@ void display::invalidate_animations()
}
}
}
const std::deque<unit*> & unit_list = fake_unit_man_->get_fake_unit_list_for_invalidation();
fake_unit_manager::range unit_list = fake_unit_man_->get_unit_range();

BOOST_FOREACH(const unit & u, dc_->units()) {
u.anim_comp().refresh();
Expand Down
13 changes: 9 additions & 4 deletions src/fake_unit_manager.hpp
Expand Up @@ -17,6 +17,8 @@

#include <deque>

#include <boost/range/iterator_range.hpp>

class display;
class unit;
class fake_unit;
Expand All @@ -28,23 +30,26 @@ class fake_unit_manager {
//Anticipate making place_temporary_unit and remove_temporary_unit private to force exception safety
friend class fake_unit;

const std::deque<unit*> & get_fake_unit_list_for_invalidation() {return fake_units_; }
typedef unit* internal_ptr_type;
typedef boost::iterator_range<std::deque<unit*>::const_iterator> range;

range get_unit_range() const { return boost::make_iterator_range(fake_units_.begin(), fake_units_.end()); }

private:
/** Temporarily place a unit on map (moving: can overlap others).
* The temp unit is added at the end of the temporary unit dequeue,
* and therefore gets drawn last, over other units and temp units.
* Adding the same unit twice isn't allowed.
*/
void place_temporary_unit(unit *u);
void place_temporary_unit(internal_ptr_type);

/** Removes any instances of this temporary unit from the temporary unit vector.
* Returns the number of temp units deleted (0 or 1, any other number indicates an error).
*/
int remove_temporary_unit(unit *u);
int remove_temporary_unit(internal_ptr_type);

/// collection of units destined to be drawn but not put into the unit map
std::deque<unit*> fake_units_;
std::deque<internal_ptr_type> fake_units_;
display & my_display_;
};

Expand Down
2 changes: 1 addition & 1 deletion src/game_display.cpp
Expand Up @@ -246,7 +246,7 @@ void game_display::draw_invalidated()
halo::unrender(invalidated_);
display::draw_invalidated();

BOOST_FOREACH(const unit* temp_unit, fake_unit_man_->get_fake_unit_list_for_invalidation()) {
BOOST_FOREACH(const unit* temp_unit, fake_unit_man_->get_unit_range()) {
const map_location& loc = temp_unit->get_location();
exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc);
if (invalidated_.find(loc) != invalidated_.end()
Expand Down

0 comments on commit 44a0752

Please sign in to comment.