The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
random_new_synced.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 #include "random_new_synced.hpp"
15 #include "log.hpp"
16 
17 static lg::log_domain log_random("random");
18 #define DBG_RND LOG_STREAM(debug, log_random)
19 #define LOG_RND LOG_STREAM(info, log_random)
20 #define WRN_RND LOG_STREAM(warn, log_random)
21 #define ERR_RND LOG_STREAM(err, log_random)
22 
23 namespace random_new
24 {
25  synced_rng::synced_rng(std::function<std::string()> seed_generator)
26  : has_valid_seed_(false), seed_generator_(seed_generator), gen_()
27  {
28  }
30  {
31  if(!has_valid_seed_)
32  {
33  initialize();
34  }
35  //getting here means random was called form inside a synced context.
36  uint32_t retv = gen_.get_next_random();
37 
38  LOG_RND << "random_new::rng::next_random_impl returned " << retv;
39  return retv;
40  }
41 
43  {
44  std::string new_seed = seed_generator_();
45  gen_.seed_random(new_seed, 0);
46  has_valid_seed_ = true;
47  }
48 
50  {
51 
52  }
53 }
static lg::log_domain log_random("random")
virtual uint32_t next_random_impl()
boost::uint32_t uint32_t
Definition: xbrz.hpp:45
uint32_t get_next_random()
Get a new random number.
Definition: mt_rng.cpp:63
void seed_random(const std::string &seed, const unsigned int call_count=0)
Same as uint32_t version, but uses a stringstream to convert given hex string.
Definition: mt_rng.cpp:88
synced_rng(std::function< std::string()> seed_generator)
#define LOG_RND
std::function< std::string()> seed_generator_
Standard logging facilities (interface).
GLsizei const GLcharARB ** string
Definition: glew.h:4503