Renamed namespace 'random' to 'randomness'

This is because GCC 4.x has a problem with symbol name collisions with 'random'
This commit is contained in:
Charles Dang 2017-04-21 03:05:52 +11:00
parent 46acff818b
commit e90d11d02a
23 changed files with 52 additions and 52 deletions

View file

@ -207,8 +207,8 @@ namespace
{
//we are in the situation, that the unit is owned by a human, but he's not allowed to do this decision.
//because it's a mp game and it's not his turn.
//note that it doesn't matter whether we call random::generator->next_random() or rand().
res = random::generator->get_random_int(0, nb_options_-1);
//note that it doesn't matter whether we call randomness::generator->next_random() or rand().
res = randomness::generator->get_random_int(0, nb_options_-1);
}
LOG_NG << "unit at position " << loc_ << "choose advancement number " << res << "\n";
config retv;

View file

@ -907,7 +907,7 @@ namespace {
int &abs_n = *(attacker_turn ? &abs_n_attack_ : &abs_n_defend_);
bool &update_fog = *(attacker_turn ? &update_def_fog_ : &update_att_fog_);
int ran_num = random::generator->get_random_int(0,99);
int ran_num = randomness::generator->get_random_int(0,99);
bool hits = (ran_num < attacker.cth_);
int damage = 0;

View file

@ -528,7 +528,7 @@ data* recruitment::get_best_leader_from_ratio_scores(std::vector<data>& leader_d
assert(ratio_score_sum > 0.0);
// Shuffle leader_data to break ties randomly.
std::shuffle(leader_data.begin(), leader_data.end(), random::rng::default_instance());
std::shuffle(leader_data.begin(), leader_data.end(), randomness::rng::default_instance());
// Find which leader should recruit according to ratio_scores.
data* best_leader_data = nullptr;

View file

@ -1292,12 +1292,12 @@ void monte_carlo_combat_matrix::simulate()
{
bool a_hit = false;
bool b_hit = false;
bool a_slowed = random::generator->get_random_bool(a_initially_slowed_chance_);
bool b_slowed = random::generator->get_random_bool(b_initially_slowed_chance_);
bool a_slowed = randomness::generator->get_random_bool(a_initially_slowed_chance_);
bool b_slowed = randomness::generator->get_random_bool(b_initially_slowed_chance_);
const std::vector<double>& a_initial = a_slowed ? a_initial_slowed_ : a_initial_;
const std::vector<double>& b_initial = b_slowed ? b_initial_slowed_ : b_initial_;
unsigned int a_hp = random::generator->get_random_element(a_initial.begin(), a_initial.end());
unsigned int b_hp = random::generator->get_random_element(b_initial.begin(), b_initial.end());
unsigned int a_hp = randomness::generator->get_random_element(a_initial.begin(), a_initial.end());
unsigned int b_hp = randomness::generator->get_random_element(b_initial.begin(), b_initial.end());
unsigned int a_strikes = calc_blows_a(a_hp);
unsigned int b_strikes = calc_blows_b(b_hp);
@ -1307,7 +1307,7 @@ void monte_carlo_combat_matrix::simulate()
{
if (k < a_strikes)
{
if (random::generator->get_random_bool(a_hit_chance_))
if (randomness::generator->get_random_bool(a_hit_chance_))
{
// A hits B
unsigned int damage = a_slowed ? a_slow_damage_ : a_damage_;
@ -1330,7 +1330,7 @@ void monte_carlo_combat_matrix::simulate()
if (k < b_strikes)
{
if (random::generator->get_random_bool(b_hit_chance_))
if (randomness::generator->get_random_bool(b_hit_chance_))
{
// B hits A
unsigned int damage = b_slowed ? b_slow_damage_ : b_damage_;

View file

@ -298,7 +298,7 @@ void editor_action_shuffle_area::perform_without_undo(map_context& mc) const
{
std::vector<map_location> shuffle;
std::copy(area_.begin(), area_.end(), std::inserter(shuffle, shuffle.begin()));
std::shuffle(shuffle.begin(), shuffle.end(), random::rng::default_instance());
std::shuffle(shuffle.begin(), shuffle.end(), randomness::rng::default_instance());
std::vector<map_location>::const_iterator shuffle_it = shuffle.begin();
std::set<map_location>::const_iterator orig_it = area_.begin();
while (orig_it != area_.end()) {

View file

@ -777,8 +777,8 @@ private:
{
int res = 0;
while(faces > 0 && num_rolls-- > 0) {
if(random::generator) {
res += (random::generator->next_random() % faces) + 1;
if(randomness::generator) {
res += (randomness::generator->next_random() % faces) + 1;
} else {
res += (rand() % faces) + 1;
}

View file

@ -203,9 +203,9 @@ void game_state::init(const config& level, play_controller & pc)
{
//sync traits of start units and the random start time.
random::set_random_determinstic deterministic(gamedata_.rng());
randomness::set_random_determinstic deterministic(gamedata_.rng());
tod_manager_.resolve_random(*random::generator);
tod_manager_.resolve_random(*randomness::generator);
for(team_builder_ptr tb_ptr : team_builders)
{

View file

@ -68,7 +68,7 @@ std::vector<game_tip> shuffle(const std::vector<game_tip>& tips)
}
}
std::shuffle(result.begin(), result.end(), random::rng::default_instance());
std::shuffle(result.begin(), result.end(), randomness::rng::default_instance());
return result;
}

View file

@ -29,7 +29,7 @@ static lg::log_domain log_random("random");
namespace {
class rng_default : public random::rng
class rng_default : public randomness::rng
{
public:
rng_default()
@ -51,7 +51,7 @@ namespace {
};
}
namespace random
namespace randomness
{
rng* generator = &rng::default_instance();

View file

@ -19,7 +19,7 @@
#include <iterator> //needed for std::distance
#include <limits>
namespace random
namespace randomness
{
/**
this class does not give synced random results derived classes might do.

View file

@ -14,7 +14,7 @@
#include "random_deterministic.hpp"
namespace random
namespace randomness
{
rng_deterministic::rng_deterministic(rand_rng::mt_rng& gen)

View file

@ -16,7 +16,7 @@
#include "random.hpp"
#include "mt_rng.hpp"
namespace random
namespace randomness
{
/**
This rng is used when the normal synced rng is not available
@ -24,7 +24,7 @@ namespace random
or during the "Deterministic SP mode"
*/
class rng_deterministic : public random::rng
class rng_deterministic : public randomness::rng
{
public:
rng_deterministic(rand_rng::mt_rng& gen);

View file

@ -20,7 +20,7 @@ static lg::log_domain log_random("random");
#define WRN_RND LOG_STREAM(warn, log_random)
#define ERR_RND LOG_STREAM(err, log_random)
namespace random
namespace randomness
{
synced_rng::synced_rng(std::function<std::string()> seed_generator)
: has_valid_seed_(false), seed_generator_(seed_generator), gen_()
@ -35,7 +35,7 @@ namespace random
//getting here means random was called form inside a synced context.
uint32_t retv = gen_.get_next_random();
LOG_RND << "random::rng::next_random_impl returned " << retv;
LOG_RND << "randomness::rng::next_random_impl returned " << retv;
return retv;
}

View file

@ -23,9 +23,9 @@
/*
todo: use a boost::random based solution.
*/
namespace random
namespace randomness
{
class synced_rng : public random::rng
class synced_rng : public randomness::rng
{
public:
synced_rng(std::function<std::string()> seed_generator);

View file

@ -219,7 +219,7 @@ static int intf_name_generator(lua_State *L)
static int intf_random(lua_State *L)
{
if (lua_isnoneornil(L, 1)) {
double r = double(random::generator->next_random());
double r = double(randomness::generator->next_random());
double r_max = double(std::numeric_limits<uint32_t>::max());
lua_push(L, r / (r_max + 1));
return 1;
@ -238,7 +238,7 @@ static int intf_random(lua_State *L)
if (min > max) {
return luaL_argerror(L, 1, "min > max");
}
lua_push(L, random::generator->get_random_int(min, max));
lua_push(L, randomness::generator->get_random_int(min, max));
return 1;
}
}

View file

@ -227,7 +227,7 @@ bool synced_context::can_undo()
//this method should only works in a synced context.
assert(is_synced());
//if we called the rng or if we sended data of this action over the network already, undoing is impossible.
return (!is_simultaneously_) && (random::generator->get_random_calls() == 0);
return (!is_simultaneously_) && (randomness::generator->get_random_calls() == 0);
}
void synced_context::set_last_unit_id(int id)
@ -253,16 +253,16 @@ void synced_context::send_user_choice()
syncmp_registry::send_user_choice();
}
std::shared_ptr<random::rng> synced_context::get_rng_for_action()
std::shared_ptr<randomness::rng> synced_context::get_rng_for_action()
{
const std::string& mode = resources::classification->random_mode;
if(mode == "deterministic")
{
return std::shared_ptr<random::rng>(new random::rng_deterministic(resources::gamedata->rng()));
return std::shared_ptr<randomness::rng>(new randomness::rng_deterministic(resources::gamedata->rng()));
}
else
{
return std::shared_ptr<random::rng>(new random::synced_rng(generate_random_seed));
return std::shared_ptr<randomness::rng>(new randomness::synced_rng(generate_random_seed));
}
}
@ -377,7 +377,7 @@ void synced_context::reset_undo_commands()
set_scontext_synced_base::set_scontext_synced_base()
: new_rng_(synced_context::get_rng_for_action())
, old_rng_(random::generator)
, old_rng_(randomness::generator)
{
LOG_REPLAY << "set_scontext_synced_base::set_scontext_synced_base\n";
assert(!resources::whiteboard->has_planned_unit_map());
@ -386,14 +386,14 @@ set_scontext_synced_base::set_scontext_synced_base()
synced_context::reset_is_simultaneously();
synced_context::set_last_unit_id(resources::gameboard->unit_id_manager().get_save_id());
synced_context::reset_undo_commands();
old_rng_ = random::generator;
random::generator = new_rng_.get();
old_rng_ = randomness::generator;
randomness::generator = new_rng_.get();
}
set_scontext_synced_base::~set_scontext_synced_base()
{
LOG_REPLAY << "set_scontext_synced_base:: destructor\n";
assert(synced_context::get_synced_state() == synced_context::SYNCED);
random::generator = old_rng_;
randomness::generator = old_rng_;
synced_context::set_synced_state(synced_context::UNSYNCED);
}
@ -492,21 +492,21 @@ int set_scontext_synced::get_random_calls()
leave_synced_context::leave_synced_context()
: old_rng_(random::generator)
: old_rng_(randomness::generator)
{
assert(synced_context::get_synced_state() == synced_context::SYNCED);
synced_context::set_synced_state(synced_context::LOCAL_CHOICE);
//calling the synced rng form inside a local_choice would cause oos.
//TODO: should we also reset the synced checkup?
random::generator = &random::rng::default_instance();
randomness::generator = &randomness::rng::default_instance();
}
leave_synced_context::~leave_synced_context()
{
assert(synced_context::get_synced_state() == synced_context::LOCAL_CHOICE);
synced_context::set_synced_state(synced_context::SYNCED);
random::generator = old_rng_;
randomness::generator = old_rng_;
}
set_scontext_unsynced::set_scontext_unsynced()

View file

@ -109,7 +109,7 @@ public:
/**
@return a rng_deterministic if in determinsic mode otherwise a rng_synced.
*/
static std::shared_ptr<random::rng> get_rng_for_action();
static std::shared_ptr<randomness::rng> get_rng_for_action();
/**
@return whether we already sended data about the current action to other clients. which means we cannot undo it.
returns is_simultaneously_
@ -181,8 +181,8 @@ public:
set_scontext_synced_base();
~set_scontext_synced_base();
protected:
std::shared_ptr<random::rng> new_rng_;
random::rng* old_rng_;
std::shared_ptr<randomness::rng> new_rng_;
randomness::rng* old_rng_;
};
/*
a RAII object to enter the synced context, cannot be called if we are already in a synced context.
@ -218,7 +218,7 @@ public:
leave_synced_context();
~leave_synced_context();
private:
random::rng* old_rng_;
randomness::rng* old_rng_;
};
/**

View file

@ -309,7 +309,7 @@ BOOST_AUTO_TEST_CASE( validate_get_random_int )
rand_rng::mt_rng mt_(cfg);
std::shared_ptr<random::rng> gen_ (new random::rng_deterministic(mt_));
std::shared_ptr<randomness::rng> gen_ (new randomness::rng_deterministic(mt_));
int val = gen_->get_random_int(0, validation_get_random_int_max);
BOOST_CHECK_EQUAL ( val , validation_get_random_int_correct_answer );
@ -317,7 +317,7 @@ BOOST_AUTO_TEST_CASE( validate_get_random_int )
BOOST_AUTO_TEST_CASE( validate_get_random_int2 )
{
std::shared_ptr<random::rng> gen_ (new random::synced_rng(validate_get_random_int_seed_generator));
std::shared_ptr<randomness::rng> gen_ (new randomness::synced_rng(validate_get_random_int_seed_generator));
for (int i = 0; i < validation_get_random_int_num_draws; i++) {
gen_->next_random();

View file

@ -77,7 +77,7 @@ tod_manager& tod_manager::operator=(const tod_manager& manager)
return *this;
}
void tod_manager::resolve_random(random::rng& r)
void tod_manager::resolve_random(randomness::rng& r)
{
//process the random_start_time string, which can be boolean yes/no true/false or a
//comma-separated string of integers >= 1 referring to the times_ array indices

View file

@ -22,7 +22,7 @@ class gamemap;
class unit_map;
class game_data;
namespace random
namespace randomness
{
class rng;
}
@ -39,7 +39,7 @@ class tod_manager
/**
handles random_start_time, should be called before the game starts.
*/
void resolve_random(random::rng& r);
void resolve_random(randomness::rng& r);
int get_current_time(const map_location& loc = map_location::null_location()) const;
void set_current_time(int time);

View file

@ -215,7 +215,7 @@ static unit_race::GENDER generate_gender(const unit_type& type, bool random_gend
if(random_gender == false || genders.size() == 1) {
return genders.front();
} else {
return genders[random::generator->get_random_int(0,genders.size()-1)];
return genders[randomness::generator->get_random_int(0,genders.size()-1)];
// Note: genders is guaranteed to be non-empty, so this is not a
// potential division by zero.
// Note: Whoever wrote this code, you should have used an assertion, to save others hours of work...
@ -858,7 +858,7 @@ void unit::generate_traits(bool must_have_only)
int max_traits = u_type.num_traits();
for(; nb_traits < max_traits && !candidate_traits.empty(); ++nb_traits)
{
int num = random::generator->get_random_int(0,candidate_traits.size()-1);
int num = randomness::generator->get_random_int(0,candidate_traits.size()-1);
modifications_.add_child("trait", *candidate_traits[num]);
candidate_traits.erase(candidate_traits.begin() + num);
}

View file

@ -171,6 +171,6 @@ std::string context_free_grammar_generator::generate() const {
void context_free_grammar_generator::init_seed(uint32_t seed[]) const {
for (unsigned short int i = 0; i < seed_size; i++) {
seed[i] = random::generator->next_random();
seed[i] = randomness::generator->next_random();
}
}

View file

@ -65,7 +65,7 @@ static ucs4::string markov_generate_name(const markov_prefix_map& prefixes,
std::vector<int> random(max_len);
size_t j = 0;
for(; j < max_len; ++j) {
random[j] = random::generator->next_random();
random[j] = randomness::generator->next_random();
}
j = 0;