Merge pull request #94441 from Repiteo/core/math-namespace

Core: Convert `Math` class to namespace
This commit is contained in:
Thaddeus Crews 2025-03-23 19:03:55 -05:00
commit 2eec0fc526
No known key found for this signature in database
GPG key ID: 62181B86FE9E5D84
10 changed files with 797 additions and 665 deletions

View file

@ -32,6 +32,7 @@
#include "core/io/resource_loader.h"
#include "core/math/math_funcs.h"
#include "core/math/random_pcg.h"
#include "core/os/os.h"
#include "scene/main/node.h" //only so casting works
@ -113,7 +114,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);

View file

@ -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() {
@ -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) {
@ -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);
}

File diff suppressed because it is too large Load diff

View file

@ -38,6 +38,7 @@
#include "core/io/image_loader.h"
#include "core/io/resource_uid.h"
#include "core/io/zip_io.h"
#include "core/math/random_pcg.h"
#include "core/version.h"
#include "editor/editor_file_system.h"
#include "editor/editor_node.h"
@ -290,7 +291,7 @@ Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_pa
seed = ((seed << 5) + seed) ^ ptr[i];
}
RandomPCG rng = RandomPCG(seed, RandomPCG::DEFAULT_INC);
RandomPCG rng = RandomPCG(seed);
iv.resize(16);
for (int i = 0; i < 16; i++) {
iv.write[i] = rng.rand() % 256;
@ -2022,7 +2023,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
seed = ((seed << 5) + seed) ^ pd.file_ofs[i].size;
}
RandomPCG rng = RandomPCG(seed, RandomPCG::DEFAULT_INC);
RandomPCG rng = RandomPCG(seed);
iv.resize(16);
for (int i = 0; i < 16; i++) {
iv.write[i] = rng.rand() % 256;

View file

@ -30,6 +30,7 @@
#include "navigation_region_3d_gizmo_plugin.h"
#include "core/math/random_pcg.h"
#include "scene/3d/navigation_region_3d.h"
#include "servers/navigation_server_3d.h"

View file

@ -33,6 +33,7 @@
#include "tile_set_editor.h"
#include "core/math/geometry_2d.h"
#include "core/math/random_pcg.h"
#include "core/os/keyboard.h"
#include "editor/editor_node.h"

View file

@ -44,6 +44,7 @@
#include "core/input/input.h"
#include "core/math/geometry_2d.h"
#include "core/math/random_pcg.h"
#include "core/os/keyboard.h"
TileMapLayer *TileMapLayerSubEditorPlugin::_get_edited_layer() const {

View file

@ -30,6 +30,7 @@
#include "navigation_region_2d.h"
#include "core/math/random_pcg.h"
#include "scene/resources/world_2d.h"
#include "servers/navigation_server_2d.h"

View file

@ -32,6 +32,7 @@
#include "core/io/marshalls.h"
#include "core/math/geometry_2d.h"
#include "core/math/random_pcg.h"
#include "scene/2d/tile_map.h"
#include "scene/gui/control.h"
#include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h"

View file

@ -30,6 +30,7 @@
#include "navigation_region_3d.h"
#include "core/math/random_pcg.h"
#include "scene/resources/3d/navigation_mesh_source_geometry_data_3d.h"
#include "servers/navigation_server_3d.h"