diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/image.cpp | 4 | ||||
-rw-r--r-- | core/image.h | 1 | ||||
-rw-r--r-- | core/math/random_pcg.cpp | 14 | ||||
-rw-r--r-- | core/math/random_pcg.h | 21 | ||||
-rw-r--r-- | core/script_language.cpp | 22 | ||||
-rw-r--r-- | core/script_language.h | 1 |
6 files changed, 48 insertions, 15 deletions
diff --git a/core/image.cpp b/core/image.cpp index 5a287ca50e..f547d7e973 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -735,6 +735,10 @@ static void _overlay(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, } } +bool Image::is_size_po2() const { + return uint32_t(width) == next_power_of_2(width) && uint32_t(height) == next_power_of_2(height); +} + void Image::resize_to_po2(bool p_square) { if (!_can_modify(format)) { diff --git a/core/image.h b/core/image.h index 872b84d565..69a42f169a 100644 --- a/core/image.h +++ b/core/image.h @@ -223,6 +223,7 @@ public: void resize(int p_width, int p_height, Interpolation p_interpolation = INTERPOLATE_BILINEAR); void shrink_x2(); void expand_x2_hq2x(); + bool is_size_po2() const; /** * Crop the image to a specific size, if larger, then the image is filled by black */ diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp index 8bbcca88fe..8c324414e6 100644 --- a/core/math/random_pcg.cpp +++ b/core/math/random_pcg.cpp @@ -32,24 +32,24 @@ #include "core/os/os.h" -RandomPCG::RandomPCG(uint64_t seed, uint64_t inc) : +RandomPCG::RandomPCG(uint64_t p_seed, uint64_t p_inc) : pcg() { - pcg.state = seed; - pcg.inc = inc; + pcg.inc = p_inc; + seed(p_seed); } void RandomPCG::randomize() { seed(OS::get_singleton()->get_ticks_usec() * pcg.state + PCG_DEFAULT_INC_64); } -double RandomPCG::random(double from, double to) { +double RandomPCG::random(double p_from, double p_to) { unsigned int r = rand(); double ret = (double)r / (double)RANDOM_MAX; - return (ret) * (to - from) + from; + return (ret) * (p_to - p_from) + p_from; } -float RandomPCG::random(float from, float to) { +float RandomPCG::random(float p_from, float p_to) { unsigned int r = rand(); float ret = (float)r / (float)RANDOM_MAX; - return (ret) * (to - from) + from; + return (ret) * (p_to - p_from) + p_from; } diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index 2a69d43904..f6cc3db595 100644 --- a/core/math/random_pcg.h +++ b/core/math/random_pcg.h @@ -37,28 +37,33 @@ class RandomPCG { pcg32_random_t pcg; + uint64_t current_seed = DEFAULT_SEED; // seed with this to get the same state public: static const uint64_t DEFAULT_SEED = 12047754176567800795U; static const uint64_t DEFAULT_INC = PCG_DEFAULT_INC_64; static const uint64_t RANDOM_MAX = 0xFFFFFFFF; - RandomPCG(uint64_t seed = DEFAULT_SEED, uint64_t inc = PCG_DEFAULT_INC_64); + RandomPCG(uint64_t p_seed = DEFAULT_SEED, uint64_t p_inc = PCG_DEFAULT_INC_64); - _FORCE_INLINE_ void seed(uint64_t seed) { - pcg.state = seed; + _FORCE_INLINE_ void seed(uint64_t p_seed) { + current_seed = p_seed; + pcg.state = p_seed; pcg32_random_r(&pcg); // Force changing internal state to avoid initial 0 } - _FORCE_INLINE_ uint64_t get_seed() { return pcg.state; } + _FORCE_INLINE_ uint64_t get_seed() { return current_seed; } void randomize(); - _FORCE_INLINE_ uint32_t rand() { return pcg32_random_r(&pcg); } + _FORCE_INLINE_ uint32_t rand() { + current_seed = pcg.state; + return pcg32_random_r(&pcg); + } _FORCE_INLINE_ double randd() { return (double)rand() / (double)RANDOM_MAX; } _FORCE_INLINE_ float randf() { return (float)rand() / (float)RANDOM_MAX; } - double random(double from, double to); - float random(float from, float to); - real_t random(int from, int to) { return (real_t)random((real_t)from, (real_t)to); } + double random(double p_from, double p_to); + float random(float p_from, float p_to); + real_t random(int p_from, int p_to) { return (real_t)random((real_t)p_from, (real_t)p_to); } }; #endif // RANDOM_PCG_H diff --git a/core/script_language.cpp b/core/script_language.cpp index f0310ffc31..1c244661b0 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -409,6 +409,11 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co return true; } + if (constants.has(p_name)) { + r_ret = constants[p_name]; + return true; + } + if (!script->is_placeholder_fallback_enabled()) { Variant defval; if (script->get_property_default_value(p_name, defval)) { @@ -444,6 +449,13 @@ Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_n *r_is_valid = true; return values[p_name].get_type(); } + + if (constants.has(p_name)) { + if (r_is_valid) + *r_is_valid = true; + return constants[p_name].get_type(); + } + if (r_is_valid) *r_is_valid = false; @@ -513,6 +525,9 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c owner->_change_notify(); } //change notify + + constants.clear(); + script->get_constants(&constants); } void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) { @@ -552,6 +567,13 @@ Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_nam *r_valid = true; return E->value(); } + + E = constants.find(p_name); + if (E) { + if (r_valid) + *r_valid = true; + return E->value(); + } } if (r_valid) diff --git a/core/script_language.h b/core/script_language.h index 2d35097692..65fb0f0268 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -336,6 +336,7 @@ class PlaceHolderScriptInstance : public ScriptInstance { Object *owner; List<PropertyInfo> properties; Map<StringName, Variant> values; + Map<StringName, Variant> constants; ScriptLanguage *language; Ref<Script> script; |