The Battle for Wesnoth  1.19.5+dev
random_deterministic.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "random.hpp"
19 #include "mt_rng.hpp"
20 
21 
22 #include <functional>
23 namespace randomness
24 {
25  /**
26  This rng is used when the normal synced rng is not available
27  this is currently only he case at the very start of the scenario (random generation of starting units traits).
28 
29  or during the "Deterministic SP mode"
30  */
32  {
33  public:
35  virtual ~rng_deterministic();
36 
37  protected:
38  virtual uint32_t next_random_impl();
39  private:
41  };
42 
43  class rng_proxy : public randomness::rng
44  {
45  public:
46  using t_impl = std::function<uint32_t()>;
47  rng_proxy(t_impl&& impl)
48  : impl_(std::move(impl))
49  {
50  }
51  virtual ~rng_proxy() = default;
52 
53  protected:
54  virtual uint32_t next_random_impl()
55  {
56  return impl_();
57  };
58 
59  private:
61  };
62 
63  /**
64  RAII class to use rng_deterministic in the current scope.
65  */
67  {
68  public:
71  private :
74  };
75 }
This rng is used when the normal synced rng is not available this is currently only he case at the ve...
virtual ~rng_proxy()=default
std::function< uint32_t()> t_impl
virtual uint32_t next_random_impl()
this class does not give synced random results derived classes might do.
Definition: random.hpp:28
RAII class to use rng_deterministic in the current scope.