Estella
0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
RandomSource.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3
#pragma once
4
19
20
#include <chrono>
21
#include <random>
22
#include <string_view>
23
24
#include "
Types.hpp
"
25
#include "
Hash.hpp
"
26
27
namespace
esengine
{
28
29
class
RandomSource
{
30
public
:
31
RandomSource
()
32
: root_(static_cast<
u32
>(
std
::chrono::steady_clock::now().time_since_epoch().count())) {}
33
34
explicit
RandomSource
(
u32
root
) : root_(
root
) {}
35
37
void
reseed
(
u32
root
) { root_ =
root
; }
38
39
u32
root
()
const
{
return
root_; }
40
42
std::mt19937
stream
(std::string_view name)
const
{
43
return
std::mt19937(
hash::fnv1a32
(name) ^ root_);
44
}
45
46
private
:
47
u32
root_;
48
};
49
55
void
setPendingRandomSeed
(
u32
seed);
57
bool
takePendingRandomSeed
(
u32
& out);
58
59
}
// namespace esengine
Hash.hpp
Types.hpp
Core type definitions and utilities for ESEngine.
esengine::RandomSource::reseed
void reseed(u32 root)
Definition
RandomSource.hpp:37
esengine::RandomSource::RandomSource
RandomSource(u32 root)
Definition
RandomSource.hpp:34
esengine::RandomSource::root
u32 root() const
Definition
RandomSource.hpp:39
esengine::RandomSource::RandomSource
RandomSource()
Definition
RandomSource.hpp:31
esengine::RandomSource::stream
std::mt19937 stream(std::string_view name) const
Definition
RandomSource.hpp:42
esengine::hash::fnv1a32
constexpr u32 fnv1a32(std::string_view text)
Definition
Hash.hpp:27
esengine
Definition
EasingFunctions.hpp:10
esengine::takePendingRandomSeed
bool takePendingRandomSeed(u32 &out)
Definition
RandomSource.cpp:16
esengine::u32
std::uint32_t u32
Unsigned 32-bit integer.
Definition
Types.hpp:45
esengine::setPendingRandomSeed
void setPendingRandomSeed(u32 seed)
Definition
RandomSource.cpp:11
std
Definition
Common.hpp:208
src
esengine
core
RandomSource.hpp
Generated by
1.15.0