mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Merge pull request #94441 from Repiteo/core/math-namespace
Core: Convert `Math` class to namespace
This commit is contained in:
commit
2eec0fc526
10 changed files with 797 additions and 665 deletions
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include "core/io/resource_loader.h"
|
#include "core/io/resource_loader.h"
|
||||||
#include "core/math/math_funcs.h"
|
#include "core/math/math_funcs.h"
|
||||||
|
#include "core/math/random_pcg.h"
|
||||||
#include "core/os/os.h"
|
#include "core/os/os.h"
|
||||||
#include "scene/main/node.h" //only so casting works
|
#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);
|
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) {
|
void Resource::seed_scene_unique_id(uint32_t p_seed) {
|
||||||
unique_id_gen.seed(p_seed);
|
unique_id_gen.seed(p_seed);
|
||||||
|
|
|
||||||
|
|
@ -31,18 +31,19 @@
|
||||||
#include "math_funcs.h"
|
#include "math_funcs.h"
|
||||||
|
|
||||||
#include "core/error/error_macros.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) {
|
uint32_t Math::rand_from_seed(uint64_t *p_seed) {
|
||||||
RandomPCG rng = RandomPCG(*seed, RandomPCG::DEFAULT_INC);
|
RandomPCG rng = RandomPCG(*p_seed);
|
||||||
uint32_t r = rng.rand();
|
uint32_t r = rng.rand();
|
||||||
*seed = rng.get_seed();
|
*p_seed = rng.get_seed();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Math::seed(uint64_t x) {
|
void Math::seed(uint64_t p_value) {
|
||||||
default_rand.seed(x);
|
default_rand.seed(p_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Math::randomize() {
|
void Math::randomize() {
|
||||||
|
|
@ -53,8 +54,8 @@ uint32_t Math::rand() {
|
||||||
return default_rand.rand();
|
return default_rand.rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
double Math::randfn(double mean, double deviation) {
|
double Math::randfn(double p_mean, double p_deviation) {
|
||||||
return default_rand.randfn(mean, deviation);
|
return default_rand.randfn(p_mean, p_deviation);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Math::step_decimals(double p_step) {
|
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) {
|
double Math::random(double p_from, double p_to) {
|
||||||
return default_rand.random(from, to);
|
return default_rand.random(p_from, p_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Math::random(float from, float to) {
|
float Math::random(float p_from, float p_to) {
|
||||||
return default_rand.random(from, to);
|
return default_rand.random(p_from, p_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Math::random(int from, int to) {
|
int Math::random(int p_from, int p_to) {
|
||||||
return default_rand.random(from, to);
|
return default_rand.random(p_from, p_to);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -38,6 +38,7 @@
|
||||||
#include "core/io/image_loader.h"
|
#include "core/io/image_loader.h"
|
||||||
#include "core/io/resource_uid.h"
|
#include "core/io/resource_uid.h"
|
||||||
#include "core/io/zip_io.h"
|
#include "core/io/zip_io.h"
|
||||||
|
#include "core/math/random_pcg.h"
|
||||||
#include "core/version.h"
|
#include "core/version.h"
|
||||||
#include "editor/editor_file_system.h"
|
#include "editor/editor_file_system.h"
|
||||||
#include "editor/editor_node.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];
|
seed = ((seed << 5) + seed) ^ ptr[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
RandomPCG rng = RandomPCG(seed, RandomPCG::DEFAULT_INC);
|
RandomPCG rng = RandomPCG(seed);
|
||||||
iv.resize(16);
|
iv.resize(16);
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
iv.write[i] = rng.rand() % 256;
|
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;
|
seed = ((seed << 5) + seed) ^ pd.file_ofs[i].size;
|
||||||
}
|
}
|
||||||
|
|
||||||
RandomPCG rng = RandomPCG(seed, RandomPCG::DEFAULT_INC);
|
RandomPCG rng = RandomPCG(seed);
|
||||||
iv.resize(16);
|
iv.resize(16);
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
iv.write[i] = rng.rand() % 256;
|
iv.write[i] = rng.rand() % 256;
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "navigation_region_3d_gizmo_plugin.h"
|
#include "navigation_region_3d_gizmo_plugin.h"
|
||||||
|
|
||||||
|
#include "core/math/random_pcg.h"
|
||||||
#include "scene/3d/navigation_region_3d.h"
|
#include "scene/3d/navigation_region_3d.h"
|
||||||
#include "servers/navigation_server_3d.h"
|
#include "servers/navigation_server_3d.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
#include "tile_set_editor.h"
|
#include "tile_set_editor.h"
|
||||||
|
|
||||||
#include "core/math/geometry_2d.h"
|
#include "core/math/geometry_2d.h"
|
||||||
|
#include "core/math/random_pcg.h"
|
||||||
#include "core/os/keyboard.h"
|
#include "core/os/keyboard.h"
|
||||||
|
|
||||||
#include "editor/editor_node.h"
|
#include "editor/editor_node.h"
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
|
|
||||||
#include "core/input/input.h"
|
#include "core/input/input.h"
|
||||||
#include "core/math/geometry_2d.h"
|
#include "core/math/geometry_2d.h"
|
||||||
|
#include "core/math/random_pcg.h"
|
||||||
#include "core/os/keyboard.h"
|
#include "core/os/keyboard.h"
|
||||||
|
|
||||||
TileMapLayer *TileMapLayerSubEditorPlugin::_get_edited_layer() const {
|
TileMapLayer *TileMapLayerSubEditorPlugin::_get_edited_layer() const {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "navigation_region_2d.h"
|
#include "navigation_region_2d.h"
|
||||||
|
|
||||||
|
#include "core/math/random_pcg.h"
|
||||||
#include "scene/resources/world_2d.h"
|
#include "scene/resources/world_2d.h"
|
||||||
#include "servers/navigation_server_2d.h"
|
#include "servers/navigation_server_2d.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include "core/io/marshalls.h"
|
#include "core/io/marshalls.h"
|
||||||
#include "core/math/geometry_2d.h"
|
#include "core/math/geometry_2d.h"
|
||||||
|
#include "core/math/random_pcg.h"
|
||||||
#include "scene/2d/tile_map.h"
|
#include "scene/2d/tile_map.h"
|
||||||
#include "scene/gui/control.h"
|
#include "scene/gui/control.h"
|
||||||
#include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h"
|
#include "scene/resources/2d/navigation_mesh_source_geometry_data_2d.h"
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "navigation_region_3d.h"
|
#include "navigation_region_3d.h"
|
||||||
|
|
||||||
|
#include "core/math/random_pcg.h"
|
||||||
#include "scene/resources/3d/navigation_mesh_source_geometry_data_3d.h"
|
#include "scene/resources/3d/navigation_mesh_source_geometry_data_3d.h"
|
||||||
#include "servers/navigation_server_3d.h"
|
#include "servers/navigation_server_3d.h"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue