Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Convert Math class to namespace #94441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/io/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "core/io/file_access.h"
#include "core/io/resource_loader.h"
#include "core/math/math_funcs.h"
#include "core/math/random_pcg.h"
#include "core/object/script_language.h"
#include "core/os/os.h"
#include "scene/main/node.h" //only so casting works
Expand Down Expand Up @@ -99,7 +100,7 @@ void Resource::set_path_cache(const String &p_path) {
GDVIRTUAL_CALL(_set_path_cache, p_path);
}

static thread_local RandomPCG unique_id_gen(0, RandomPCG::DEFAULT_INC);
static thread_local RandomPCG unique_id_gen = RandomPCG(0);

void Resource::seed_scene_unique_id(uint32_t p_seed) {
unique_id_gen.seed(p_seed);
Expand Down
29 changes: 15 additions & 14 deletions core/math/math_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
#include "math_funcs.h"

#include "core/error/error_macros.h"
#include "core/math/random_pcg.h"

RandomPCG Math::default_rand(RandomPCG::DEFAULT_SEED, RandomPCG::DEFAULT_INC);
static RandomPCG default_rand;

uint32_t Math::rand_from_seed(uint64_t *seed) {
RandomPCG rng = RandomPCG(*seed, RandomPCG::DEFAULT_INC);
uint32_t Math::rand_from_seed(uint64_t *p_seed) {
RandomPCG rng = RandomPCG(*p_seed);
uint32_t r = rng.rand();
*seed = rng.get_seed();
*p_seed = rng.get_seed();
return r;
}

void Math::seed(uint64_t x) {
default_rand.seed(x);
void Math::seed(uint64_t p_value) {
default_rand.seed(p_value);
}

void Math::randomize() {
Expand All @@ -53,8 +54,8 @@ uint32_t Math::rand() {
return default_rand.rand();
}

double Math::randfn(double mean, double deviation) {
return default_rand.randfn(mean, deviation);
double Math::randfn(double p_mean, double p_deviation) {
return default_rand.randfn(p_mean, p_deviation);
}

int Math::step_decimals(double p_step) {
Expand Down Expand Up @@ -168,14 +169,14 @@ uint32_t Math::larger_prime(uint32_t p_val) {
}
}

double Math::random(double from, double to) {
return default_rand.random(from, to);
double Math::random(double p_from, double p_to) {
return default_rand.random(p_from, p_to);
}

float Math::random(float from, float to) {
return default_rand.random(from, to);
float Math::random(float p_from, float p_to) {
return default_rand.random(p_from, p_to);
}

int Math::random(int from, int to) {
return default_rand.random(from, to);
int Math::random(int p_from, int p_to) {
return default_rand.random(p_from, p_to);
}
Loading