OGLplus  (0.59.0) a C++ wrapper for rendering APIs

state.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_APPLICATION_STATE_HPP
10 #define EAGINE_APPLICATION_STATE_HPP
11 
12 #include "../main_ctx_object.hpp"
13 #include "../valid_if/positive.hpp"
14 #include "state_view.hpp"
15 #include <random>
16 
17 namespace eagine::application {
18 //------------------------------------------------------------------------------
23  : public main_ctx_object
24  , public context_state_view {
25 
26 public:
28 
30  auto advance_time() noexcept -> auto& {
31  if(EAGINE_UNLIKELY(_fixed_fps)) {
32  _frame_time.advance(1.F / extract(_fixed_fps));
33  } else {
34  _frame_time.assign(
35  std::chrono::duration<float>(run_time()).count());
36  }
37  return *this;
38  }
39 
41  auto update_activity() noexcept -> context_state&;
42 
44  auto notice_user_active() noexcept -> auto& {
45  _new_user_idle = false;
46  return *this;
47  }
48 
50  void random_uniform(span<byte> dest) {
51  generate(dest, [this] { return _dist_uniform_byte(_rand_eng); });
52  }
53 
55  void random_uniform_01(span<float> dest) {
56  generate(dest, [this] { return _dist_uniform_float_01(_rand_eng); });
57  }
58 
60  void random_normal(span<float> dest) {
61  generate(dest, [this] { return _dist_normal_float(_rand_eng); });
62  }
63 
64 private:
65  valid_if_positive<float> _fixed_fps;
66 
67  std::chrono::duration<float> _sim_activity_for;
68 
70  std::default_random_engine::result_type _rand_init;
71 
72  std::default_random_engine _rand_eng;
73  std::uniform_int_distribution<byte> _dist_uniform_byte{0x00, 0xFF};
74  std::uniform_real_distribution<float> _dist_uniform_float_01{0.F, 1.F};
75  std::normal_distribution<float> _dist_normal_float{0.F, 1.F};
76 };
77 //------------------------------------------------------------------------------
78 } // namespace eagine::application
79 
80 #include <eagine/application/state.inl>
81 
82 #endif
Application harness / wrapper code is placed in this namespace.
Definition: eagine.hpp:72
Helper class used to initialize main context objects.
Definition: main_ctx_object.hpp:45
Read-only view of application context state values.
Definition: state_view.hpp:34
Base class for main context objects.
Definition: main_ctx_object.hpp:71
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
void random_uniform(span< byte > dest)
Generates random uniformly-distributed bytes.
Definition: state.hpp:50
Primary template for conditionally valid values.
Definition: decl.hpp:49
auto update_activity() noexcept -> context_state &
Updates the user activity tracking.
Class managing application context variables.
Definition: state.hpp:22
static auto generate(basic_span< T, P, S > spn, Generator gen) -> basic_span< T, P, S >
Fills a span with elements generated by a generator callable.
Definition: span_algo.hpp:584
void random_normal(span< float > dest)
Generates random normally-distributed floats.
Definition: state.hpp:60
auto run_time() const noexcept -> clock_type::duration
Returns the application run time duration.
Definition: state_view.hpp:40
void random_uniform_01(span< float > dest)
Generates random uniformly-distributed floats in range <0, 1>.
Definition: state.hpp:55
auto advance_time() noexcept -> auto &
Advances the simulation time.
Definition: state.hpp:30
auto notice_user_active() noexcept -> auto &
Notice that the user generated some input.
Definition: state.hpp:44

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).