diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.cpp | 5 | ||||
-rw-r--r-- | core/core_bind.h | 1 | ||||
-rw-r--r-- | core/extension/gdnative_interface.cpp | 4 | ||||
-rw-r--r-- | core/input/input.cpp | 6 | ||||
-rw-r--r-- | core/io/pck_packer.cpp | 3 | ||||
-rw-r--r-- | core/io/pck_packer.h | 2 | ||||
-rw-r--r-- | core/math/basis.cpp | 4 | ||||
-rw-r--r-- | core/math/geometry_2d.h | 3 | ||||
-rw-r--r-- | core/math/math_funcs.cpp | 4 | ||||
-rw-r--r-- | core/math/math_funcs.h | 5 | ||||
-rw-r--r-- | core/math/transform_2d.cpp | 6 | ||||
-rw-r--r-- | core/math/vector2.cpp | 4 | ||||
-rw-r--r-- | core/math/vector2.h | 2 | ||||
-rw-r--r-- | core/math/vector3.h | 2 | ||||
-rw-r--r-- | core/math/vector3i.h | 2 | ||||
-rw-r--r-- | core/object/object.cpp | 2 | ||||
-rw-r--r-- | core/os/os.h | 3 | ||||
-rw-r--r-- | core/string/ustring.cpp | 16 | ||||
-rw-r--r-- | core/templates/thread_work_pool.cpp | 2 | ||||
-rw-r--r-- | core/typedefs.h | 4 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 13 |
21 files changed, 58 insertions, 35 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index d42d39a159..0bf6efc96d 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -315,6 +315,10 @@ Error OS::set_thread_name(const String &p_name) { return ::Thread::get_caller_id(); }; +::Thread::ID OS::get_main_thread_id() const { + return ::Thread::get_main_id(); +}; + bool OS::has_feature(const String &p_feature) const { return ::OS::get_singleton()->has_feature(p_feature); } @@ -601,6 +605,7 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &OS::set_thread_name); ClassDB::bind_method(D_METHOD("get_thread_caller_id"), &OS::get_thread_caller_id); + ClassDB::bind_method(D_METHOD("get_main_thread_id"), &OS::get_main_thread_id); ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &OS::has_feature); diff --git a/core/core_bind.h b/core/core_bind.h index 641e3a33ae..4bacfa720c 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -237,6 +237,7 @@ public: Error set_thread_name(const String &p_name); Thread::ID get_thread_caller_id() const; + Thread::ID get_main_thread_id() const; bool has_feature(const String &p_feature) const; diff --git a/core/extension/gdnative_interface.cpp b/core/extension/gdnative_interface.cpp index 4770c9c65f..a65408fdda 100644 --- a/core/extension/gdnative_interface.cpp +++ b/core/extension/gdnative_interface.cpp @@ -774,13 +774,13 @@ static GDNativeTypePtr gdnative_packed_vector3_array_operator_index_const(const static GDNativeVariantPtr gdnative_array_operator_index(GDNativeTypePtr p_self, GDNativeInt p_index) { Array *self = (Array *)p_self; ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); - return (GDNativeTypePtr)&self[p_index]; + return (GDNativeVariantPtr)&self->operator[](p_index); } static GDNativeVariantPtr gdnative_array_operator_index_const(const GDNativeTypePtr p_self, GDNativeInt p_index) { const Array *self = (const Array *)p_self; ERR_FAIL_INDEX_V(p_index, self->size(), nullptr); - return (GDNativeTypePtr)&self[p_index]; + return (GDNativeVariantPtr)&self->operator[](p_index); } /* OBJECT API */ diff --git a/core/input/input.cpp b/core/input/input.cpp index 4b5a84f401..6fd8aca01b 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -714,11 +714,11 @@ Point2i Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, con // detect the warp: if the relative distance is greater than the half of the size of the relevant rect // (checked per each axis), it will be considered as the consequence of a former pointer warp. - const Point2i rel_sgn(p_motion->get_relative().x >= 0.0f ? 1 : -1, p_motion->get_relative().y >= 0.0 ? 1 : -1); + const Point2i rel_sign(p_motion->get_relative().x >= 0.0f ? 1 : -1, p_motion->get_relative().y >= 0.0 ? 1 : -1); const Size2i warp_margin = p_rect.size * 0.5f; const Point2i rel_warped( - Math::fmod(p_motion->get_relative().x + rel_sgn.x * warp_margin.x, p_rect.size.x) - rel_sgn.x * warp_margin.x, - Math::fmod(p_motion->get_relative().y + rel_sgn.y * warp_margin.y, p_rect.size.y) - rel_sgn.y * warp_margin.y); + Math::fmod(p_motion->get_relative().x + rel_sign.x * warp_margin.x, p_rect.size.x) - rel_sign.x * warp_margin.x, + Math::fmod(p_motion->get_relative().y + rel_sign.y * warp_margin.y, p_rect.size.y) - rel_sign.y * warp_margin.y); const Point2i pos_local = p_motion->get_global_position() - p_rect.position; const Point2i pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y)); diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 806a95398f..8d75581342 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -47,13 +47,14 @@ static int _get_pad(int p_alignment, int p_n) { } void PCKPacker::_bind_methods() { - ClassDB::bind_method(D_METHOD("pck_start", "pck_name", "alignment", "key", "encrypt_directory"), &PCKPacker::pck_start, DEFVAL(0), DEFVAL(String()), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("pck_start", "pck_name", "alignment", "key", "encrypt_directory"), &PCKPacker::pck_start, DEFVAL(32), DEFVAL("0000000000000000000000000000000000000000000000000000000000000000"), DEFVAL(false)); ClassDB::bind_method(D_METHOD("add_file", "pck_path", "source_path", "encrypt"), &PCKPacker::add_file, DEFVAL(false)); ClassDB::bind_method(D_METHOD("flush", "verbose"), &PCKPacker::flush, DEFVAL(false)); } Error PCKPacker::pck_start(const String &p_file, int p_alignment, const String &p_key, bool p_encrypt_directory) { ERR_FAIL_COND_V_MSG((p_key.is_empty() || !p_key.is_valid_hex_number(false) || p_key.length() != 64), ERR_CANT_CREATE, "Invalid Encryption Key (must be 64 characters long)."); + ERR_FAIL_COND_V_MSG(p_alignment <= 0, ERR_CANT_CREATE, "Invalid alignment, must be greater then 0."); String _key = p_key.to_lower(); key.resize(32); diff --git a/core/io/pck_packer.h b/core/io/pck_packer.h index 3d2ce8f240..bd8902a01d 100644 --- a/core/io/pck_packer.h +++ b/core/io/pck_packer.h @@ -58,7 +58,7 @@ class PCKPacker : public RefCounted { Vector<File> files; public: - Error pck_start(const String &p_file, int p_alignment = 0, const String &p_key = String(), bool p_encrypt_directory = false); + Error pck_start(const String &p_file, int p_alignment = 32, const String &p_key = "0000000000000000000000000000000000000000000000000000000000000000", bool p_encrypt_directory = false); Error add_file(const String &p_file, const String &p_src, bool p_encrypt = false); Error flush(bool p_verbose = false); diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 3d893afb4d..566300c716 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -261,7 +261,7 @@ Vector3 Basis::get_scale_abs() const { } Vector3 Basis::get_scale_local() const { - real_t det_sign = SGN(determinant()); + real_t det_sign = SIGN(determinant()); return det_sign * Vector3(elements[0].length(), elements[1].length(), elements[2].length()); } @@ -287,7 +287,7 @@ Vector3 Basis::get_scale() const { // matrix elements. // // The rotation part of this decomposition is returned by get_rotation* functions. - real_t det_sign = SGN(determinant()); + real_t det_sign = SIGN(determinant()); return det_sign * get_scale_abs(); } diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index 6010159597..028ac0f4eb 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -181,8 +181,7 @@ public: D = Vector2(D.x * Bn.x + D.y * Bn.y, D.y * Bn.x - D.x * Bn.y); // Fail if C x B and D x B have the same sign (segments don't intersect). - // (equivalent to condition (C.y < 0 && D.y < CMP_EPSILON) || (C.y > 0 && D.y > CMP_EPSILON)) - if (C.y * D.y > CMP_EPSILON) { + if ((C.y < -CMP_EPSILON && D.y < -CMP_EPSILON) || (C.y > CMP_EPSILON && D.y > CMP_EPSILON)) { return false; } diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index bbed257f60..2b6d92fe0e 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -53,6 +53,10 @@ uint32_t Math::rand() { return default_rand.rand(); } +double Math::randfn(double mean, double deviation) { + return default_rand.randfn(mean, deviation); +} + int Math::step_decimals(double p_step) { static const int maxn = 10; static const double sd[maxn] = { diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index b3eabd3e7a..8df45255c9 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -266,8 +266,8 @@ public: float s = CLAMP((p_s - p_from) / (p_to - p_from), 0.0f, 1.0f); return s * s * (3.0f - 2.0f * s); } - static _ALWAYS_INLINE_ double move_toward(double p_from, double p_to, double p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SGN(p_to - p_from) * p_delta; } - static _ALWAYS_INLINE_ float move_toward(float p_from, float p_to, float p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SGN(p_to - p_from) * p_delta; } + static _ALWAYS_INLINE_ double move_toward(double p_from, double p_to, double p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SIGN(p_to - p_from) * p_delta; } + static _ALWAYS_INLINE_ float move_toward(float p_from, float p_to, float p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SIGN(p_to - p_from) * p_delta; } static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; } static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; } @@ -318,6 +318,7 @@ public: static uint32_t rand(); static _ALWAYS_INLINE_ double randd() { return (double)rand() / (double)Math::RANDOM_32BIT_MAX; } static _ALWAYS_INLINE_ float randf() { return (float)rand() / (float)Math::RANDOM_32BIT_MAX; } + static double randfn(double mean, double deviation); static double random(double from, double to); static float random(float from, float to); diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index df43c605f9..4bdeaa2a58 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -69,12 +69,12 @@ void Transform2D::rotate(const real_t p_phi) { real_t Transform2D::get_skew() const { real_t det = basis_determinant(); - return Math::acos(elements[0].normalized().dot(SGN(det) * elements[1].normalized())) - Math_PI * 0.5; + return Math::acos(elements[0].normalized().dot(SIGN(det) * elements[1].normalized())) - Math_PI * 0.5; } void Transform2D::set_skew(const real_t p_angle) { real_t det = basis_determinant(); - elements[1] = SGN(det) * elements[0].rotated((Math_PI * 0.5 + p_angle)).normalized() * elements[1].length(); + elements[1] = SIGN(det) * elements[0].rotated((Math_PI * 0.5 + p_angle)).normalized() * elements[1].length(); } real_t Transform2D::get_rotation() const { @@ -111,7 +111,7 @@ Transform2D::Transform2D(const real_t p_rot, const Size2 &p_scale, const real_t } Size2 Transform2D::get_scale() const { - real_t det_sign = SGN(basis_determinant()); + real_t det_sign = SIGN(basis_determinant()); return Size2(elements[0].length(), det_sign * elements[1].length()); } diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 6259bdead0..718e94eee4 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -79,7 +79,7 @@ real_t Vector2::angle_to(const Vector2 &p_vector2) const { } real_t Vector2::angle_to_point(const Vector2 &p_vector2) const { - return (*this - p_vector2).angle(); + return (p_vector2 - *this).angle(); } real_t Vector2::dot(const Vector2 &p_other) const { @@ -91,7 +91,7 @@ real_t Vector2::cross(const Vector2 &p_other) const { } Vector2 Vector2::sign() const { - return Vector2(SGN(x), SGN(y)); + return Vector2(SIGN(x), SIGN(y)); } Vector2 Vector2::floor() const { diff --git a/core/math/vector2.h b/core/math/vector2.h index 332c0475fa..0a7b9d3faf 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -345,7 +345,7 @@ struct Vector2i { bool operator!=(const Vector2i &p_vec2) const; real_t aspect() const { return width / (real_t)height; } - Vector2i sign() const { return Vector2i(SGN(x), SGN(y)); } + Vector2i sign() const { return Vector2i(SIGN(x), SIGN(y)); } Vector2i abs() const { return Vector2i(ABS(x), ABS(y)); } Vector2i clamp(const Vector2i &p_min, const Vector2i &p_max) const; diff --git a/core/math/vector3.h b/core/math/vector3.h index dc9aa60458..02a56f684e 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -217,7 +217,7 @@ Vector3 Vector3::abs() const { } Vector3 Vector3::sign() const { - return Vector3(SGN(x), SGN(y), SGN(z)); + return Vector3(SIGN(x), SIGN(y), SIGN(z)); } Vector3 Vector3::floor() const { diff --git a/core/math/vector3i.h b/core/math/vector3i.h index 9308d09045..10c28a5bb9 100644 --- a/core/math/vector3i.h +++ b/core/math/vector3i.h @@ -115,7 +115,7 @@ Vector3i Vector3i::abs() const { } Vector3i Vector3i::sign() const { - return Vector3i(SGN(x), SGN(y), SGN(z)); + return Vector3i(SIGN(x), SIGN(y), SIGN(z)); } /* Operators */ diff --git a/core/object/object.cpp b/core/object/object.cpp index 8e96695f0d..90bd697d37 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1410,7 +1410,7 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, ERR_FAIL_COND_MSG(!s->slot_map.has(*p_callable.get_base_comparator()), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + "."); - SignalData::Slot *slot = &s->slot_map[p_callable]; + SignalData::Slot *slot = &s->slot_map[*p_callable.get_base_comparator()]; if (!p_force) { slot->reference_count--; // by default is zero, if it was not referenced it will go below it diff --git a/core/os/os.h b/core/os/os.h index 52bf731501..3042696cce 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -243,7 +243,7 @@ public: void set_stdout_enabled(bool p_enabled); void set_stderr_enabled(bool p_enabled); - bool is_single_window() const; + virtual bool is_single_window() const; virtual void disable_crash_handler() {} virtual bool is_disable_crash_handler() const { return false; } @@ -298,6 +298,7 @@ public: virtual void set_exit_code(int p_code); virtual int get_processor_count() const; + virtual int get_default_thread_pool_size() const { return get_processor_count(); } virtual String get_unique_id() const; diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 4798cab641..70236231a2 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -38,6 +38,7 @@ #include "core/string/translation.h" #include "core/string/ucaps.h" #include "core/variant/variant.h" +#include "core/version_generated.gen.h" #include <stdio.h> #include <stdlib.h> @@ -4868,15 +4869,20 @@ String TTRN(const String &p_text, const String &p_text_plural, int p_n, const St return p_text_plural; } +/* DTR and DTRN are used for the documentation, handling descriptions extracted + * from the XML. + * They also replace `$DOCS_URL` with the actual URL to the documentation's branch, + * to allow dehardcoding it in the XML and doing proper substitutions everywhere. + */ String DTR(const String &p_text, const String &p_context) { // Comes straight from the XML, so remove indentation and any trailing whitespace. const String text = p_text.dedent().strip_edges(); if (TranslationServer::get_singleton()) { - return TranslationServer::get_singleton()->doc_translate(text, p_context); + return String(TranslationServer::get_singleton()->doc_translate(text, p_context)).replace("$DOCS_URL", VERSION_DOCS_URL); } - return text; + return text.replace("$DOCS_URL", VERSION_DOCS_URL); } String DTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context) { @@ -4884,14 +4890,14 @@ String DTRN(const String &p_text, const String &p_text_plural, int p_n, const St const String text_plural = p_text_plural.dedent().strip_edges(); if (TranslationServer::get_singleton()) { - return TranslationServer::get_singleton()->doc_translate_plural(text, text_plural, p_n, p_context); + return String(TranslationServer::get_singleton()->doc_translate_plural(text, text_plural, p_n, p_context)).replace("$DOCS_URL", VERSION_DOCS_URL); } // Return message based on English plural rule if translation is not possible. if (p_n == 1) { - return text; + return text.replace("$DOCS_URL", VERSION_DOCS_URL); } - return text_plural; + return text_plural.replace("$DOCS_URL", VERSION_DOCS_URL); } #endif diff --git a/core/templates/thread_work_pool.cpp b/core/templates/thread_work_pool.cpp index 17969a2c90..710f043a4a 100644 --- a/core/templates/thread_work_pool.cpp +++ b/core/templates/thread_work_pool.cpp @@ -47,7 +47,7 @@ void ThreadWorkPool::_thread_function(void *p_user) { void ThreadWorkPool::init(int p_thread_count) { ERR_FAIL_COND(threads != nullptr); if (p_thread_count < 0) { - p_thread_count = OS::get_singleton()->get_processor_count(); + p_thread_count = OS::get_singleton()->get_default_thread_pool_size(); } thread_count = p_thread_count; diff --git a/core/typedefs.h b/core/typedefs.h index 9ab874b2f0..95bd423817 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -91,8 +91,8 @@ #define ABS(m_v) (((m_v) < 0) ? (-(m_v)) : (m_v)) #endif -#ifndef SGN -#define SGN(m_v) (((m_v) == 0) ? (0.0) : (((m_v) < 0) ? (-1.0) : (+1.0))) +#ifndef SIGN +#define SIGN(m_v) (((m_v) == 0) ? (0.0) : (((m_v) < 0) ? (-1.0) : (+1.0))) #endif #ifndef MIN diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index e89bdd4faa..554b2f1c25 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -151,10 +151,10 @@ struct VariantUtilityFunctions { r_error.error = Callable::CallError::CALL_OK; switch (x.get_type()) { case Variant::INT: { - return SGN(VariantInternalAccessor<int64_t>::get(&x)); + return SIGN(VariantInternalAccessor<int64_t>::get(&x)); } break; case Variant::FLOAT: { - return SGN(VariantInternalAccessor<double>::get(&x)); + return SIGN(VariantInternalAccessor<double>::get(&x)); } break; case Variant::VECTOR2: { return VariantInternalAccessor<Vector2>::get(&x).sign(); @@ -176,11 +176,11 @@ struct VariantUtilityFunctions { } static inline double signf(double x) { - return SGN(x); + return SIGN(x); } static inline int64_t signi(int64_t x) { - return SGN(x); + return SIGN(x); } static inline double pow(double x, double y) { @@ -403,6 +403,10 @@ struct VariantUtilityFunctions { return Math::randf(); } + static inline double randfn(double mean, double deviation) { + return Math::randfn(mean, deviation); + } + static inline int64_t randi_range(int64_t from, int64_t to) { return Math::random((int32_t)from, (int32_t)to); } @@ -1239,6 +1243,7 @@ void Variant::_register_variant_utility_functions() { FUNCBINDR(randf, sarray(), Variant::UTILITY_FUNC_TYPE_RANDOM); FUNCBINDR(randi_range, sarray("from", "to"), Variant::UTILITY_FUNC_TYPE_RANDOM); FUNCBINDR(randf_range, sarray("from", "to"), Variant::UTILITY_FUNC_TYPE_RANDOM); + FUNCBINDR(randfn, sarray("mean", "deviation"), Variant::UTILITY_FUNC_TYPE_RANDOM); FUNCBIND(seed, sarray("base"), Variant::UTILITY_FUNC_TYPE_RANDOM); FUNCBINDR(rand_from_seed, sarray("seed"), Variant::UTILITY_FUNC_TYPE_RANDOM); |