split random.hpp into creating separate headers...
...for the rng and simple_rng class
This commit is contained in:
parent
6aea43e73d
commit
5ae38e8898
9 changed files with 143 additions and 78 deletions
|
@ -4724,6 +4724,10 @@
|
|||
RelativePath="..\..\src\reports.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\rng.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\save_blocker.hpp"
|
||||
>
|
||||
|
@ -4752,6 +4756,10 @@
|
|||
RelativePath="..\..\src\show_dialog.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\simple_rng.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\sound.hpp"
|
||||
>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "../gettext.hpp"
|
||||
#include "../map_create.hpp"
|
||||
#include "../mapgen.hpp"
|
||||
#include "../random.hpp"
|
||||
#include "../rng.hpp"
|
||||
#include "../sound.hpp"
|
||||
|
||||
#include "formula_string_utils.hpp"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define GAME_STATUS_HPP_INCLUDED
|
||||
|
||||
#include "random.hpp"
|
||||
#include "simple_rng.hpp"
|
||||
#include "team.hpp"
|
||||
#include "time_of_day.hpp"
|
||||
#include "variable.hpp"
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "race.hpp"
|
||||
#include "random.hpp"
|
||||
#include "simple_rng.hpp"
|
||||
|
||||
#include "log.hpp" // needed for deprecation warning
|
||||
|
||||
|
|
|
@ -41,7 +41,8 @@
|
|||
|
||||
#include "config.hpp"
|
||||
#include "random.hpp"
|
||||
|
||||
#include "rng.hpp"
|
||||
#include "simple_rng.hpp"
|
||||
|
||||
namespace {
|
||||
rand_rng::rng *random_generator = NULL ;
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#ifndef RANDOM_HPP_INCLUDED
|
||||
#define RANDOM_HPP_INCLUDED
|
||||
|
||||
#include "SDL_types.h"
|
||||
|
||||
class config;
|
||||
|
||||
int get_random();
|
||||
|
@ -29,88 +27,15 @@ void set_random_results(const config& cfg);
|
|||
namespace rand_rng
|
||||
{
|
||||
|
||||
class rng
|
||||
{
|
||||
public:
|
||||
rng();
|
||||
int get_random();
|
||||
|
||||
const config* get_random_results();
|
||||
void set_random_results(const config& cfg);
|
||||
|
||||
protected:
|
||||
config* random();
|
||||
void set_random(config*);
|
||||
|
||||
private:
|
||||
config* random_;
|
||||
size_t random_child_;
|
||||
};
|
||||
class rng;
|
||||
|
||||
struct set_random_generator {
|
||||
set_random_generator(rng* r);
|
||||
~set_random_generator();
|
||||
|
||||
private:
|
||||
rng* old_;
|
||||
};
|
||||
|
||||
class simple_rng
|
||||
{
|
||||
public:
|
||||
simple_rng();
|
||||
simple_rng(const config& cfg);
|
||||
|
||||
/** Get a new random number. */
|
||||
int get_random();
|
||||
|
||||
/**
|
||||
* Seeds the random pool.
|
||||
*
|
||||
* @param call_count Upon loading we need to restore the state at saving
|
||||
* so set the number of times a random number is
|
||||
* generated for replays the orginal value is
|
||||
* required.
|
||||
*/
|
||||
void seed_random(const unsigned call_count = 0);
|
||||
|
||||
/**
|
||||
* Seeds the random pool.
|
||||
*
|
||||
* @param seed The initial value for the random engine.
|
||||
* @param call_count Upon loading we need to restore the state at saving
|
||||
* so set the number of times a random number is
|
||||
* generated for replays the orginal value is
|
||||
* required.
|
||||
*/
|
||||
void seed_random(const int seed, const unsigned call_count = 0);
|
||||
|
||||
/**
|
||||
* Resets the random to the 0 calls and the seed to the random
|
||||
* this way we stay in the same sequence but don't have a lot
|
||||
* calls. Used when moving to the next scenario.
|
||||
*/
|
||||
void rotate_random()
|
||||
{ random_seed_ = random_pool_; random_calls_ = 0; }
|
||||
|
||||
|
||||
int get_random_seed() const { return random_seed_; }
|
||||
int get_random_calls() const { return random_calls_; }
|
||||
|
||||
private:
|
||||
/** Initial seed for the pool. */
|
||||
int random_seed_;
|
||||
|
||||
/** State for the random pool. */
|
||||
int random_pool_;
|
||||
|
||||
/** Number of time a random number is generated. */
|
||||
unsigned random_calls_;
|
||||
|
||||
/** Sets the next random number in the pool. */
|
||||
void random_next();
|
||||
};
|
||||
|
||||
} // ends rand_rng namespace
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "gamestatus.hpp"
|
||||
#include "map_location.hpp"
|
||||
#include "random.hpp"
|
||||
#include "rng.hpp"
|
||||
|
||||
class config_writer;
|
||||
class game_display;
|
||||
|
|
46
src/rng.hpp
Normal file
46
src/rng.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2003 by David White <dave@whitevine.net>
|
||||
Copyright (C) 2005 - 2009 by Yann Dirson <ydirson@altern.org>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/** @file random.hpp */
|
||||
|
||||
#ifndef RNG_HPP_INCLUDED
|
||||
#define RNG_HPP_INCLUDED
|
||||
|
||||
#include "random.hpp"
|
||||
|
||||
namespace rand_rng
|
||||
{
|
||||
|
||||
class rng
|
||||
{
|
||||
public:
|
||||
rng();
|
||||
int get_random();
|
||||
|
||||
const config* get_random_results();
|
||||
void set_random_results(const config& cfg);
|
||||
|
||||
protected:
|
||||
config* random();
|
||||
void set_random(config*);
|
||||
|
||||
private:
|
||||
config* random_;
|
||||
size_t random_child_;
|
||||
};
|
||||
|
||||
} // ends rand_rng namespace
|
||||
|
||||
#endif
|
82
src/simple_rng.hpp
Normal file
82
src/simple_rng.hpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2003 by David White <dave@whitevine.net>
|
||||
Copyright (C) 2005 - 2009 by Yann Dirson <ydirson@altern.org>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef SIMPLE_RNG_HPP_INCLUDED
|
||||
#define SIMPLE_RNG_HPP_INCLUDED
|
||||
|
||||
class config;
|
||||
|
||||
namespace rand_rng
|
||||
{
|
||||
|
||||
class simple_rng
|
||||
{
|
||||
public:
|
||||
simple_rng();
|
||||
simple_rng(const config& cfg);
|
||||
|
||||
/** Get a new random number. */
|
||||
int get_random();
|
||||
|
||||
/**
|
||||
* Seeds the random pool.
|
||||
*
|
||||
* @param call_count Upon loading we need to restore the state at saving
|
||||
* so set the number of times a random number is
|
||||
* generated for replays the orginal value is
|
||||
* required.
|
||||
*/
|
||||
void seed_random(const unsigned call_count = 0);
|
||||
|
||||
/**
|
||||
* Seeds the random pool.
|
||||
*
|
||||
* @param seed The initial value for the random engine.
|
||||
* @param call_count Upon loading we need to restore the state at saving
|
||||
* so set the number of times a random number is
|
||||
* generated for replays the orginal value is
|
||||
* required.
|
||||
*/
|
||||
void seed_random(const int seed, const unsigned call_count = 0);
|
||||
|
||||
/**
|
||||
* Resets the random to the 0 calls and the seed to the random
|
||||
* this way we stay in the same sequence but don't have a lot
|
||||
* calls. Used when moving to the next scenario.
|
||||
*/
|
||||
void rotate_random()
|
||||
{ random_seed_ = random_pool_; random_calls_ = 0; }
|
||||
|
||||
|
||||
int get_random_seed() const { return random_seed_; }
|
||||
int get_random_calls() const { return random_calls_; }
|
||||
|
||||
private:
|
||||
/** Initial seed for the pool. */
|
||||
int random_seed_;
|
||||
|
||||
/** State for the random pool. */
|
||||
int random_pool_;
|
||||
|
||||
/** Number of time a random number is generated. */
|
||||
unsigned random_calls_;
|
||||
|
||||
/** Sets the next random number in the pool. */
|
||||
void random_next();
|
||||
};
|
||||
|
||||
} // ends rand_rng namespace
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue