Drop the _new suffix from random_new

The 'old' random code has long been removed.
This commit is contained in:
Charles Dang 2017-04-20 08:48:47 +11:00
parent b53ff3187b
commit d8ed11c2b1
27 changed files with 96 additions and 96 deletions

View file

@ -920,12 +920,12 @@
<Unit filename="../../src/preferences_display.hpp" />
<Unit filename="../../src/quit_confirmation.cpp" />
<Unit filename="../../src/quit_confirmation.hpp" />
<Unit filename="../../src/random_new.cpp" />
<Unit filename="../../src/random_new.hpp" />
<Unit filename="../../src/random_new_deterministic.cpp" />
<Unit filename="../../src/random_new_deterministic.hpp" />
<Unit filename="../../src/random_new_synced.cpp" />
<Unit filename="../../src/random_new_synced.hpp" />
<Unit filename="../../src/random.cpp" />
<Unit filename="../../src/random.hpp" />
<Unit filename="../../src/random_deterministic.cpp" />
<Unit filename="../../src/random_deterministic.hpp" />
<Unit filename="../../src/random_synced.cpp" />
<Unit filename="../../src/random_synced.hpp" />
<Unit filename="../../src/recall_list_manager.cpp" />
<Unit filename="../../src/recall_list_manager.hpp" />
<Unit filename="../../src/replay.cpp" />

View file

@ -322,9 +322,9 @@ playsingle_controller.cpp
playturn.cpp
playturn_network_adapter.cpp
preferences_display.cpp
random_new.cpp
random_new_deterministic.cpp
random_new_synced.cpp
random.cpp
random_deterministic.cpp
random_synced.cpp
recall_list_manager.cpp
replay.cpp
replay_controller.cpp

View file

@ -29,7 +29,7 @@
#include "gui/widgets/window.hpp" //gui2::window::OK
#include "log.hpp"
#include "play_controller.hpp" //resources::controller
#include "random_new.hpp"
#include "random.hpp"
#include "resources.hpp"
#include "statistics.hpp"
#include "synced_user_choice.hpp"
@ -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_new::generator->next_random() or rand().
res = random_new::generator->get_random_int(0, nb_options_-1);
//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);
}
LOG_NG << "unit at position " << loc_ << "choose advancement number " << res << "\n";
config retv;

View file

@ -35,7 +35,7 @@
#include "map/map.hpp"
#include "mouse_handler_base.hpp"
#include "play_controller.hpp"
#include "random_new.hpp"
#include "random.hpp"
#include "replay.hpp"
#include "resources.hpp"
#include "statistics.hpp"
@ -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_new::generator->get_random_int(0,99);
int ran_num = random::generator->get_random_int(0,99);
bool hits = (ran_num < attacker.cth_);
int damage = 0;

View file

@ -33,7 +33,7 @@
#include "map/label.hpp"
#include "pathfind/pathfind.hpp"
#include "pathutils.hpp"
#include "random_new.hpp"
#include "random.hpp"
#include "resources.hpp"
#include "team.hpp"
#include "tod_manager.hpp"
@ -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_new::rng::default_instance());
std::shuffle(leader_data.begin(), leader_data.end(), random::rng::default_instance());
// Find which leader should recruit according to ratio_scores.
data* best_leader_data = nullptr;

View file

@ -41,7 +41,7 @@
#include "actions/attack.hpp"
#include "game_config.hpp"
#include "preferences.hpp"
#include "random_new.hpp"
#include "random.hpp"
#include "utils/general.hpp"
#include <array>
#include <cmath>
@ -1292,12 +1292,12 @@ void monte_carlo_combat_matrix::simulate()
{
bool a_hit = false;
bool b_hit = false;
bool a_slowed = random_new::generator->get_random_bool(a_initially_slowed_chance_);
bool b_slowed = random_new::generator->get_random_bool(b_initially_slowed_chance_);
bool a_slowed = random::generator->get_random_bool(a_initially_slowed_chance_);
bool b_slowed = random::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_new::generator->get_random_element(a_initial.begin(), a_initial.end());
unsigned int b_hp = random_new::generator->get_random_element(b_initial.begin(), b_initial.end());
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_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_new::generator->get_random_bool(a_hit_chance_))
if (random::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_new::generator->get_random_bool(b_hit_chance_))
if (random::generator->get_random_bool(b_hit_chance_))
{
// B hits A
unsigned int damage = b_slowed ? b_slow_damage_ : b_damage_;

View file

@ -21,7 +21,7 @@
#include "editor/action/action.hpp"
#include "editor/map/map_context.hpp"
#include "gettext.hpp"
#include "random_new.hpp"
#include "random.hpp"
#include <memory>
@ -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_new::rng::default_instance());
std::shuffle(shuffle.begin(), shuffle.end(), random::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

@ -16,7 +16,7 @@
#include "formula/callable.hpp"
#include "formula/function.hpp"
#include "random_new.hpp"
#include "random.hpp"
#include "serialization/string_utils.hpp"
#include <cassert>
@ -777,8 +777,8 @@ private:
{
int res = 0;
while(faces > 0 && num_rolls-- > 0) {
if(random_new::generator) {
res += (random_new::generator->next_random() % faces) + 1;
if(random::generator) {
res += (random::generator->next_random() % faces) + 1;
} else {
res += (rand() % faces) + 1;
}

View file

@ -47,7 +47,7 @@
#include "play_controller.hpp"
#include "recall_list_manager.hpp"
#include "replay.hpp"
#include "random_new.hpp"
#include "random.hpp"
#include "resources.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "side_filter.hpp"

View file

@ -24,7 +24,7 @@
#include "pathfind/teleport.hpp"
#include "play_controller.hpp"
#include "game_preferences.hpp"
#include "random_new_deterministic.hpp"
#include "random_deterministic.hpp"
#include "reports.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "teambuilder.hpp"
@ -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_new::set_random_determinstic deterministic(gamedata_.rng());
random::set_random_determinstic deterministic(gamedata_.rng());
tod_manager_.resolve_random(*random_new::generator);
tod_manager_.resolve_random(*random::generator);
for(team_builder_ptr tb_ptr : team_builders)
{

View file

@ -18,7 +18,7 @@
#include "config.hpp"
#include "game_preferences.hpp"
#include "random_new.hpp"
#include "random.hpp"
#include "serialization/string_utils.hpp"
namespace gui2
@ -68,7 +68,7 @@ std::vector<game_tip> shuffle(const std::vector<game_tip>& tips)
}
}
std::shuffle(result.begin(), result.end(), random_new::rng::default_instance());
std::shuffle(result.begin(), result.end(), random::rng::default_instance());
return result;
}

View file

@ -37,7 +37,7 @@
#include "map/label.hpp"
#include "map/map.hpp"
#include "playturn.hpp"
#include "random_new_deterministic.hpp"
#include "random_deterministic.hpp"
#include "replay_helper.hpp"
#include "resources.hpp"
#include "savegame.hpp"

View file

@ -12,7 +12,7 @@
See the COPYING file for more details.
*/
#include "random_new.hpp"
#include "random.hpp"
#include "log.hpp"
@ -29,7 +29,7 @@ static lg::log_domain log_random("random");
namespace {
class rng_default : public random_new::rng
class rng_default : public random::rng
{
public:
rng_default()
@ -51,7 +51,7 @@ namespace {
};
}
namespace random_new
namespace random
{
rng* generator = &rng::default_instance();

View file

@ -11,15 +11,15 @@
See the COPYING file for more details.
*/
#ifndef RANDOM_NEW_H_INCLUDED
#define RANDOM_NEW_H_INCLUDED
#ifndef RANDOM_H_INCLUDED
#define RANDOM_H_INCLUDED
#include <cstdlib> //needed for RAND_MAX
#include <cstdint>
#include <iterator> //needed for std::distance
#include <limits>
namespace random_new
namespace random
{
/**
this class does not give synced random results derived classes might do.

View file

@ -11,10 +11,10 @@
See the COPYING file for more details.
*/
#include "random_new_deterministic.hpp"
#include "random_deterministic.hpp"
namespace random_new
namespace random
{
rng_deterministic::rng_deterministic(rand_rng::mt_rng& gen)

View file

@ -11,12 +11,12 @@
See the COPYING file for more details.
*/
#ifndef RANDOM_NEW_DETERMINISTIC_H_INCLUDED
#define RANDOM_NEW_DETERMINISTIC_H_INCLUDED
#include "random_new.hpp"
#ifndef RANDOM_DETERMINISTIC_H_INCLUDED
#define RANDOM_DETERMINISTIC_H_INCLUDED
#include "random.hpp"
#include "mt_rng.hpp"
namespace random_new
namespace random
{
/**
This rng is used when the normal synced rng is not available
@ -24,7 +24,7 @@ namespace random_new
or during the "Deterministic SP mode"
*/
class rng_deterministic : public random_new::rng
class rng_deterministic : public random::rng
{
public:
rng_deterministic(rand_rng::mt_rng& gen);

View file

@ -11,7 +11,7 @@
See the COPYING file for more details.
*/
#include "random_new_synced.hpp"
#include "random_synced.hpp"
#include "log.hpp"
static lg::log_domain log_random("random");
@ -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_new
namespace random
{
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_new
//getting here means random was called form inside a synced context.
uint32_t retv = gen_.get_next_random();
LOG_RND << "random_new::rng::next_random_impl returned " << retv;
LOG_RND << "random::rng::next_random_impl returned " << retv;
return retv;
}

View file

@ -12,10 +12,10 @@
See the COPYING file for more details.
*/
#ifndef RANDOM_NEW_SYNCED_H_INCLUDED
#define RANDOM_NEW_SYNCED_H_INCLUDED
#ifndef RANDOM_SYNCED_H_INCLUDED
#define RANDOM_SYNCED_H_INCLUDED
#include "random_new.hpp"
#include "random.hpp"
#include "mt_rng.hpp"
#include "utils/functional.hpp"
@ -23,9 +23,9 @@
/*
todo: use a boost::random based solution.
*/
namespace random_new
namespace random
{
class synced_rng : public random_new::rng
class synced_rng : public random::rng
{
public:
synced_rng(std::function<std::string()> seed_generator);

View file

@ -20,7 +20,7 @@
#include "gui/widgets/settings.hpp"
#include "log.hpp"
#include "lua_jailbreak_exception.hpp" // for lua_jailbreak_exception
#include "random_new.hpp"
#include "random.hpp"
#include "seed_rng.hpp"
#ifdef DEBUG_LUA
@ -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_new::generator->next_random());
double r = double(random::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_new::generator->get_random_int(min, max));
lua_push(L, random::generator->get_random_int(min, max));
return 1;
}
}

View file

@ -20,9 +20,9 @@
#include "config_assign.hpp"
#include "game_classification.hpp"
#include "replay.hpp"
#include "random_new.hpp"
#include "random_new_synced.hpp"
#include "random_new_deterministic.hpp"
#include "random.hpp"
#include "random_synced.hpp"
#include "random_deterministic.hpp"
#include "resources.hpp"
#include "synced_checkup.hpp"
#include "game_data.hpp"
@ -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_new::generator->get_random_calls() == 0);
return (!is_simultaneously_) && (random::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_new::rng> synced_context::get_rng_for_action()
std::shared_ptr<random::rng> synced_context::get_rng_for_action()
{
const std::string& mode = resources::classification->random_mode;
if(mode == "deterministic")
{
return std::shared_ptr<random_new::rng>(new random_new::rng_deterministic(resources::gamedata->rng()));
return std::shared_ptr<random::rng>(new random::rng_deterministic(resources::gamedata->rng()));
}
else
{
return std::shared_ptr<random_new::rng>(new random_new::synced_rng(generate_random_seed));
return std::shared_ptr<random::rng>(new random::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_new::generator)
, old_rng_(random::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_new::generator;
random_new::generator = new_rng_.get();
old_rng_ = random::generator;
random::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_new::generator = old_rng_;
random::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_new::generator)
: old_rng_(random::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_new::generator = &random_new::rng::default_instance();
random::generator = &random::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_new::generator = old_rng_;
random::generator = old_rng_;
}
set_scontext_unsynced::set_scontext_unsynced()

View file

@ -18,8 +18,8 @@
#include "synced_commands.hpp"
#include "synced_checkup.hpp"
#include "replay.hpp"
#include "random_new.hpp"
#include "random_new_synced.hpp"
#include "random.hpp"
#include "random_synced.hpp"
#include "game_events/pump.hpp" // for queued_event
#include "generic_event.hpp"
#include "mouse_handler_base.hpp"
@ -109,7 +109,7 @@ public:
/**
@return a rng_deterministic if in determinsic mode otherwise a rng_synced.
*/
static std::shared_ptr<random_new::rng> get_rng_for_action();
static std::shared_ptr<random::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_new::rng> new_rng_;
random_new::rng* old_rng_;
std::shared_ptr<random::rng> new_rng_;
random::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_new::rng* old_rng_;
random::rng* old_rng_;
};
/**

View file

@ -15,8 +15,8 @@
#define GETTEXT_DOMAIN "wesnoth-test"
#include <boost/test/unit_test.hpp>
#include "random_new_synced.hpp"
#include "random_new_deterministic.hpp"
#include "random_synced.hpp"
#include "random_deterministic.hpp"
#include "config.hpp"
#include <sstream>
#include <iomanip>
@ -295,8 +295,8 @@ std::string validate_get_random_int_seed_generator()
/**
* This test and the next validate that we are getting the correct values
* from the get_random_int function, in the class random_new.
* We test both subclasses of random_new.
* from the get_random_int function, in the class random.
* We test both subclasses of random.
* If these tests fail but the seed manipulation tests all pass,
* and validate_mt19937 passes, then it suggests that the implementation
* of get_random_int may not be working properly on your platform.
@ -309,7 +309,7 @@ BOOST_AUTO_TEST_CASE( validate_get_random_int )
rand_rng::mt_rng mt_(cfg);
std::shared_ptr<random_new::rng> gen_ (new random_new::rng_deterministic(mt_));
std::shared_ptr<random::rng> gen_ (new random::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_new::rng> gen_ (new random_new::synced_rng(validate_get_random_int_seed_generator));
std::shared_ptr<random::rng> gen_ (new random::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

@ -21,7 +21,7 @@
#include "log.hpp"
#include "map/map.hpp"
#include "play_controller.hpp"
#include "random_new.hpp"
#include "random.hpp"
#include "units/unit.hpp"
#include "units/abilities.hpp"
#include "wml_exception.hpp"
@ -77,7 +77,7 @@ tod_manager& tod_manager::operator=(const tod_manager& manager)
return *this;
}
void tod_manager::resolve_random(random_new::rng& r)
void tod_manager::resolve_random(random::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_new
namespace random
{
class rng;
}
@ -39,7 +39,7 @@ class tod_manager
/**
handles random_start_time, should be called before the game starts.
*/
void resolve_random(random_new::rng& r);
void resolve_random(random::rng& r);
int get_current_time(const map_location& loc = map_location::null_location()) const;
void set_current_time(int time);

View file

@ -33,7 +33,7 @@
#include "lexical_cast.hpp"
#include "log.hpp" // for LOG_STREAM, logger, etc
#include "map/map.hpp" // for gamemap
#include "random_new.hpp" // for generator, rng
#include "random.hpp" // for generator, rng
#include "resources.hpp" // for units, gameboard, teams, etc
#include "scripting/game_lua_kernel.hpp" // for game_lua_kernel
#include "side_filter.hpp" // for side_filter
@ -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_new::generator->get_random_int(0,genders.size()-1)];
return genders[random::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_new::generator->get_random_int(0,candidate_traits.size()-1);
int num = random::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

@ -21,7 +21,7 @@
#include "utils/context_free_grammar_generator.hpp"
#include "log.hpp"
#include "random_new.hpp"
#include "random.hpp"
#include "serialization/string_utils.hpp"
#include <algorithm>
@ -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_new::generator->next_random();
seed[i] = random::generator->next_random();
}
}

View file

@ -20,7 +20,7 @@
#include "utils/markov_generator.hpp"
#include "serialization/unicode_cast.hpp"
#include "random_new.hpp"
#include "random.hpp"
static void add_prefixes(const ucs4::string& str, size_t length, markov_prefix_map& res)
{
@ -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_new::generator->next_random();
random[j] = random::generator->next_random();
}
j = 0;