mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-04 07:55:39 +00:00
Update doxygen comment style.
This commit is contained in:
parent
c170ee4b14
commit
878d14ae5c
@ -12,29 +12,30 @@
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file random.cpp
|
||||
//! Generate random numbers.
|
||||
//!
|
||||
//! There are various ways to get a random number.
|
||||
//! rand() This can be used for things that never are send over the
|
||||
//! network e.g. generate a random map (the final result the
|
||||
//! map is send, but the other players don't need to generate
|
||||
//! the map.
|
||||
//!
|
||||
//! get_random() A random generator which is syncronized over the network
|
||||
//! this only seems to work when it's used by 1 player at the
|
||||
//! same time. It's syncronized after an event so if an event
|
||||
//! runs at two clients at the same time it gets out of sync
|
||||
//! and sets the entire game out of sync.
|
||||
//!
|
||||
//! game_state::get_random()
|
||||
//! A random generator which is seeded by the host of an MP
|
||||
//! game. This generator is (not yet) synchronized over the
|
||||
//! network. It's only used by [set_variable]rand=. The map
|
||||
//! designer has to make sure it stays in sync. This
|
||||
//! generator can be used at the same time at multiple client
|
||||
//! since the generators are always in sync.
|
||||
/**
|
||||
* @file random.cpp
|
||||
* Generate random numbers.
|
||||
*
|
||||
* There are various ways to get a random number.
|
||||
* rand() This can be used for things that never are send over the
|
||||
* network e.g. generate a random map (the final result the
|
||||
* map is send, but the other players don't need to generate
|
||||
* the map.
|
||||
*
|
||||
* get_random() A random generator which is syncronized over the network
|
||||
* this only seems to work when it's used by 1 player at the
|
||||
* same time. It's syncronized after an event so if an event
|
||||
* runs at two clients at the same time it gets out of sync
|
||||
* and sets the entire game out of sync.
|
||||
*
|
||||
* game_state::get_random()
|
||||
* A random generator which is seeded by the host of an MP
|
||||
* game. This generator is (not yet) synchronized over the
|
||||
* network. It's only used by [set_variable]rand=. The map
|
||||
* designer has to make sure it stays in sync. This
|
||||
* generator can be used at the same time at multiple client
|
||||
* since the generators are always in sync.
|
||||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
@ -135,14 +136,15 @@ simple_rng::simple_rng() :
|
||||
{}
|
||||
|
||||
simple_rng::simple_rng(const config& cfg) :
|
||||
//! @todo older savegames don't have random_seed stored, evaluate later
|
||||
//! whether default can be removed again. Look after branching 1.5.
|
||||
/**
|
||||
* @todo older savegames don't have random_seed stored, evaluate later
|
||||
* whether default can be removed again. Look after branching 1.5.
|
||||
*/
|
||||
random_seed_(lexical_cast_default<int>(cfg["random_seed"], 42)),
|
||||
random_pool_(random_seed_),
|
||||
random_calls_(0)
|
||||
{}
|
||||
|
||||
//! Get a new random number.
|
||||
int simple_rng::get_random()
|
||||
{
|
||||
random_next();
|
||||
@ -153,22 +155,11 @@ int simple_rng::get_random()
|
||||
return (static_cast<unsigned>(random_pool_ / 65536) % 32768);
|
||||
}
|
||||
|
||||
//! 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 simple_rng::seed_random(const unsigned call_count)
|
||||
{
|
||||
seed_random(random_seed_, call_count);
|
||||
}
|
||||
|
||||
//! 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 simple_rng::seed_random(const int seed, const unsigned call_count)
|
||||
{
|
||||
random_pool_ = seed;
|
||||
@ -181,7 +172,6 @@ void simple_rng::seed_random(const int seed, const unsigned call_count)
|
||||
// << random_pool_ << '\n';
|
||||
}
|
||||
|
||||
//! Sets the next random number in the pool.
|
||||
void simple_rng::random_next()
|
||||
{
|
||||
// Use the simple random generator as shown in man rand(3).
|
||||
|
@ -13,8 +13,7 @@
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file random.hpp
|
||||
//!
|
||||
/** @file random.hpp */
|
||||
|
||||
#ifndef RANDOM_H_INCLUDED
|
||||
#define RANDOM_H_INCLUDED
|
||||
@ -59,17 +58,35 @@ public:
|
||||
simple_rng();
|
||||
simple_rng(const config& cfg);
|
||||
|
||||
//! Get a new random number.
|
||||
/** Get a new random number. */
|
||||
int get_random();
|
||||
|
||||
//! Seeds the random pool.
|
||||
/**
|
||||
* 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.
|
||||
|
||||
/**
|
||||
* 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.
|
||||
/**
|
||||
* 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; }
|
||||
|
||||
@ -78,16 +95,16 @@ public:
|
||||
int get_random_calls() const { return random_calls_; }
|
||||
|
||||
private:
|
||||
//! Initial seed for the pool.
|
||||
/** Initial seed for the pool. */
|
||||
int random_seed_;
|
||||
|
||||
//! State for the random pool.
|
||||
/** State for the random pool. */
|
||||
int random_pool_;
|
||||
|
||||
//! Number of time a random number is generated.
|
||||
/** Number of time a random number is generated. */
|
||||
unsigned random_calls_;
|
||||
|
||||
//! Sets the next random number in the pool.
|
||||
/** Sets the next random number in the pool. */
|
||||
void random_next();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user