Skip to content

Commit

Permalink
Re-enable unit map and recall list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Aug 10, 2016
1 parent 89246cd commit 1a5ce49
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/actions/unit_creator.cpp
Expand Up @@ -166,7 +166,7 @@ void unit_creator::add_unit(const config &cfg, const vconfig* vcfg)

if ( !recall_list_element ) {
//make the new unit
unit_ptr new_unit(new unit(temp_cfg, true, vcfg, &board_->unit_id_manager()));
unit_ptr new_unit(new unit(temp_cfg, true, vcfg));
map_location loc = find_location(temp_cfg, new_unit.get());
if ( loc.valid() ) {
//add the new unit to map
Expand Down
1 change: 0 additions & 1 deletion src/tests/test_recall_list.cpp
Expand Up @@ -24,7 +24,6 @@
BOOST_AUTO_TEST_SUITE( recall_list_suite )

BOOST_AUTO_TEST_CASE( test_1 ) {
return;
config game_config(test_utils::get_test_config());

config orc_config = config_of
Expand Down
11 changes: 0 additions & 11 deletions src/tests/test_unit_map.cpp
Expand Up @@ -34,8 +34,6 @@
BOOST_AUTO_TEST_SUITE( unit_map_suite )

BOOST_AUTO_TEST_CASE( test_1 ) {
// FIXME: this test currently fails becasue unit id manager was moved to game_board.
return;
config game_config(test_utils::get_test_config());

config orc_config;
Expand Down Expand Up @@ -122,8 +120,6 @@ BOOST_AUTO_TEST_CASE( test_1 ) {
}

BOOST_AUTO_TEST_CASE( track_real_unit_by_underlying_id ) {
// FIXME: this test currently fails becasue unit id manager was moved to game_board.
return;
config game_config(test_utils::get_test_config());

config orc_config;
Expand Down Expand Up @@ -170,8 +166,6 @@ BOOST_AUTO_TEST_CASE( track_real_unit_by_underlying_id ) {
}

BOOST_AUTO_TEST_CASE( track_fake_unit_by_underlying_id ) {
// FIXME: this test currently fails becasue unit id manager was moved to game_board.
return;
config game_config(test_utils::get_test_config());

config orc_config;
Expand Down Expand Up @@ -218,9 +212,6 @@ BOOST_AUTO_TEST_CASE( track_fake_unit_by_underlying_id ) {
}

BOOST_AUTO_TEST_CASE( track_real_unit_by_iterator ) {
// FIXME: this test currently fails becasue unit id manager was moved to game_board.
return;

config game_config(test_utils::get_test_config());

config orc_config;
Expand Down Expand Up @@ -258,8 +249,6 @@ BOOST_AUTO_TEST_CASE( track_real_unit_by_iterator ) {
}

BOOST_AUTO_TEST_CASE( track_fake_unit_by_iterator ) {
// FIXME: this test currently fails becasue unit id manager was moved to game_board.
return;
config game_config(test_utils::get_test_config());

config orc_config;
Expand Down
5 changes: 1 addition & 4 deletions src/units/id.cpp
Expand Up @@ -22,10 +22,7 @@ static lg::log_domain log_unit("unit");

namespace n_unit
{
id_manager id_manager::manager_;

id_manager::id_manager() : next_id_(0), fake_id_(0)
{}
id_manager id_manager::manager_(0);

unit_id id_manager::next_id()
{
Expand Down
4 changes: 2 additions & 2 deletions src/units/id.hpp
Expand Up @@ -33,7 +33,7 @@ namespace n_unit {
bool is_empty() const { return !value; }

static unit_id create_real(size_t val) { return unit_id(val); }
static unit_id create_fake(size_t val) { return unit_id(val + highest_bit); }
static unit_id create_fake(size_t val) { return unit_id(val | highest_bit); }

friend bool operator <(unit_id a, unit_id b) { return a.value < b.value; }
friend bool operator <=(unit_id a, unit_id b) { return a.value <= b.value; }
Expand All @@ -48,7 +48,6 @@ namespace n_unit {
size_t next_id_;
size_t fake_id_;
static id_manager manager_;
id_manager();
public:
id_manager(size_t next_id) : next_id_(next_id) , fake_id_(0) {}
/** returns id for unit that is created */
Expand All @@ -62,6 +61,7 @@ namespace n_unit {
/** Clears id counter after game */
void clear();
void reset_fake();
static id_manager& global_instance() {return manager_;}
};

}
Expand Down
16 changes: 8 additions & 8 deletions src/units/unit.cpp
Expand Up @@ -329,7 +329,7 @@ struct ptr_vector_pushback
boost::ptr_vector<config>* vec_;
};

unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg, n_unit::id_manager* id_manager)
unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg)
: ref_count_(0)
, loc_(cfg["x"] - 1, cfg["y"] - 1)
, advances_to_()
Expand Down Expand Up @@ -409,7 +409,7 @@ unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg, n_unit::id_m

validate_side(side_);
underlying_id_ = n_unit::unit_id(cfg["underlying_id"].to_size_t());
set_underlying_id(id_manager ? *id_manager : resources::gameboard->unit_id_manager());
set_underlying_id(resources::gameboard ? resources::gameboard->unit_id_manager() : n_unit::id_manager::global_instance());

overlays_ = utils::parenthetical_split(cfg["overlays"], ',');
if(overlays_.size() == 1 && overlays_.front() == "") {
Expand Down Expand Up @@ -624,7 +624,6 @@ unit::unit(const unit_type &u_type, int side, bool real_unit, unit_race::GENDER
, race_(&unit_race::null_race)
, id_()
, name_()
, underlying_id_(real_unit? n_unit::unit_id(0) : resources::gameboard->unit_id_manager().next_fake_id())
, undead_variation_()
, variation_(type_->default_variation())
, hit_points_(0)
Expand Down Expand Up @@ -695,7 +694,7 @@ unit::unit(const unit_type &u_type, int side, bool real_unit, unit_race::GENDER
if(real_unit) {
generate_name();
}
set_underlying_id(resources::gameboard->unit_id_manager());
set_underlying_id(resources::gameboard ? resources::gameboard->unit_id_manager() : n_unit::id_manager::global_instance());

// Set these after traits and modifications have set the maximums.
movement_ = max_movement_;
Expand Down Expand Up @@ -2361,22 +2360,23 @@ void unit::set_underlying_id(n_unit::id_manager& id_manager)

unit& unit::clone(bool is_temporary)
{
n_unit::id_manager& ids = resources::gameboard ? resources::gameboard->unit_id_manager() : n_unit::id_manager::global_instance();
if(is_temporary) {
underlying_id_ = resources::gameboard->unit_id_manager().next_fake_id();
underlying_id_ = ids.next_fake_id();
} else {
if(synced_context::is_synced() || !resources::gamedata || resources::gamedata->phase() == game_data::INITIAL) {
underlying_id_ = resources::gameboard->unit_id_manager().next_id();
underlying_id_ = ids.next_id();
}
else {
underlying_id_ = resources::gameboard->unit_id_manager().next_fake_id();
underlying_id_ = ids.next_fake_id();
}
std::string::size_type pos = id_.find_last_of('-');
if(pos != std::string::npos && pos+1 < id_.size()
&& id_.find_first_not_of("0123456789", pos+1) == std::string::npos) {
// this appears to be a duplicate of a generic unit, so give it a new id
WRN_UT << "assigning new id to clone of generic unit " << id_ << std::endl;
id_.clear();
set_underlying_id(resources::gameboard->unit_id_manager());
set_underlying_id(ids);
}
}
return *this;
Expand Down
6 changes: 1 addition & 5 deletions src/units/unit.hpp
Expand Up @@ -98,11 +98,7 @@ class unit
unit(const unit& u);

/** Initializes a unit from a config */
explicit unit(
const config& cfg
, bool use_traits = false
, const vconfig* vcfg = nullptr
, n_unit::id_manager* id_manager = nullptr);
explicit unit(const config& cfg, bool use_traits = false, const vconfig* vcfg = nullptr);

/**
* Initializes a unit from a unit type
Expand Down

2 comments on commit 1a5ce49

@GregoryLundberg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An observation ...

The issue is a visual artifact on HttT S20a ('Home of the North Elves') where, during the introductory sequence a unit uses move_unit_fake to approach the player's party. This movement begins under fog and leaves a static image of the moving unit at the starting point. This artifact clears once the movement completes.

This commit corrects that error.

@CelticMinstrel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's surprising, since it wasn't the intent of the commit at all... but I think the most likely reason is that + being changed to |. I just happened across it and thought "hey, this is clearly wrong", so I changed it.

Please sign in to comment.