summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/config/project_settings.cpp1
-rw-r--r--core/io/ip.cpp8
-rw-r--r--core/io/resource_loader.cpp12
-rw-r--r--core/math/random_pcg.h12
-rw-r--r--core/os/thread.cpp6
-rw-r--r--core/os/thread.h2
-rw-r--r--core/string/translation.cpp20
-rw-r--r--core/typedefs.h4
-rw-r--r--core/variant/array.cpp2
-rw-r--r--core/variant/variant.cpp4
-rw-r--r--core/variant/variant_utility.cpp12
11 files changed, 63 insertions, 20 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index 933b9891cc..f3c0bc2153 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -1331,6 +1331,7 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/occlusion_culling/bvh_build_quality", PROPERTY_HINT_ENUM, "Low,Medium,High"), 2);
GLOBAL_DEF(PropertyInfo(Variant::INT, "memory/limits/multithreaded_server/rid_pool_prealloc", PROPERTY_HINT_RANGE, "0,500,1"), 60); // No negative and limit to 500 due to crashes.
GLOBAL_DEF_RST("internationalization/rendering/force_right_to_left_layout_direction", false);
+ GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "internationalization/rendering/root_node_layout_direction", PROPERTY_HINT_RANGE, "Based on Locale,Left-to-Right,Right-to-Left"), 0);
GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/timers/incremental_search_max_interval_msec", PROPERTY_HINT_RANGE, "0,10000,1,or_greater"), 2000);
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index 28b7037120..65728f34f6 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -75,7 +75,7 @@ struct _IP_ResolverPrivate {
Semaphore sem;
Thread thread;
- bool thread_abort = false;
+ SafeFlag thread_abort;
void resolve_queues() {
for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) {
@@ -111,7 +111,7 @@ struct _IP_ResolverPrivate {
static void _thread_function(void *self) {
_IP_ResolverPrivate *ipr = static_cast<_IP_ResolverPrivate *>(self);
- while (!ipr->thread_abort) {
+ while (!ipr->thread_abort.is_set()) {
ipr->sem.wait();
ipr->resolve_queues();
}
@@ -343,12 +343,12 @@ IP::IP() {
singleton = this;
resolver = memnew(_IP_ResolverPrivate);
- resolver->thread_abort = false;
+ resolver->thread_abort.clear();
resolver->thread.start(_IP_ResolverPrivate::_thread_function, resolver);
}
IP::~IP() {
- resolver->thread_abort = true;
+ resolver->thread_abort.set();
resolver->sem.post();
resolver->thread.wait_to_finish();
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index c47f297a72..d0448e86fc 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -492,13 +492,21 @@ Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path, Error *r_e
print_lt("GET: load count: " + itos(thread_loading_count) + " / wait count: " + itos(thread_waiting_count) + " / suspended count: " + itos(thread_suspended_count) + " / active: " + itos(thread_loading_count - thread_suspended_count));
}
+ bool still_valid = true;
+ bool was_thread = load_task.thread;
do {
load_task.cond_var->wait(thread_load_lock);
+ if (!thread_load_tasks.has(local_path)) { //may have been erased during unlock and this was always an invalid call
+ still_valid = false;
+ break;
+ }
} while (load_task.cond_var); // In case of spurious wakeup.
- thread_suspended_count--;
+ if (was_thread) {
+ thread_suspended_count--;
+ }
- if (!thread_load_tasks.has(local_path)) { //may have been erased during unlock and this was always an invalid call
+ if (!still_valid) {
if (r_error) {
*r_error = ERR_INVALID_PARAMETER;
}
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h
index fe40e7f76a..cc22b23b70 100644
--- a/core/math/random_pcg.h
+++ b/core/math/random_pcg.h
@@ -126,10 +126,18 @@ public:
}
_FORCE_INLINE_ double randfn(double p_mean, double p_deviation) {
- return p_mean + p_deviation * (cos(Math_TAU * randd()) * sqrt(-2.0 * log(randd()))); // Box-Muller transform
+ double temp = randd();
+ if (temp < CMP_EPSILON) {
+ temp += CMP_EPSILON; // To prevent generating of INF value in log function, resulting to return NaN value from this function.
+ }
+ return p_mean + p_deviation * (cos(Math_TAU * randd()) * sqrt(-2.0 * log(temp))); // Box-Muller transform.
}
_FORCE_INLINE_ float randfn(float p_mean, float p_deviation) {
- return p_mean + p_deviation * (cos((float)Math_TAU * randf()) * sqrt(-2.0 * log(randf()))); // Box-Muller transform
+ float temp = randf();
+ if (temp < CMP_EPSILON) {
+ temp += CMP_EPSILON; // To prevent generating of INF value in log function, resulting to return NaN value from this function.
+ }
+ return p_mean + p_deviation * (cos((float)Math_TAU * randf()) * sqrt(-2.0 * log(temp))); // Box-Muller transform.
}
double random(double p_from, double p_to);
diff --git a/core/os/thread.cpp b/core/os/thread.cpp
index 9d16392b2a..92865576f3 100644
--- a/core/os/thread.cpp
+++ b/core/os/thread.cpp
@@ -50,8 +50,8 @@ void Thread::_set_platform_functions(const PlatformFunctions &p_functions) {
platform_functions = p_functions;
}
-void Thread::callback(Thread *p_self, const Settings &p_settings, Callback p_callback, void *p_userdata) {
- Thread::caller_id = _thread_id_hash(p_self->thread.get_id());
+void Thread::callback(ID p_caller_id, const Settings &p_settings, Callback p_callback, void *p_userdata) {
+ Thread::caller_id = p_caller_id;
if (platform_functions.set_priority) {
platform_functions.set_priority(p_settings.priority);
}
@@ -79,7 +79,7 @@ void Thread::start(Thread::Callback p_callback, void *p_user, const Settings &p_
std::thread empty_thread;
thread.swap(empty_thread);
}
- std::thread new_thread(&Thread::callback, this, p_settings, p_callback, p_user);
+ std::thread new_thread(&Thread::callback, _thread_id_hash(thread.get_id()), p_settings, p_callback, p_user);
thread.swap(new_thread);
id = _thread_id_hash(thread.get_id());
}
diff --git a/core/os/thread.h b/core/os/thread.h
index 3d4c48a760..6eb21fba65 100644
--- a/core/os/thread.h
+++ b/core/os/thread.h
@@ -82,7 +82,7 @@ private:
static thread_local ID caller_id;
std::thread thread;
- static void callback(Thread *p_self, const Settings &p_settings, Thread::Callback p_callback, void *p_userdata);
+ static void callback(ID p_caller_id, const Settings &p_settings, Thread::Callback p_callback, void *p_userdata);
static PlatformFunctions platform_functions;
diff --git a/core/string/translation.cpp b/core/string/translation.cpp
index b9d5d3b538..160bad14ab 100644
--- a/core/string/translation.cpp
+++ b/core/string/translation.cpp
@@ -712,7 +712,25 @@ String TranslationServer::get_tool_locale() {
#else
{
#endif
- return get_locale();
+ // Look for best matching loaded translation.
+ String best_locale = "en";
+ int best_score = 0;
+
+ for (const Ref<Translation> &E : translations) {
+ const Ref<Translation> &t = E;
+ ERR_FAIL_COND_V(t.is_null(), best_locale);
+ String l = t->get_locale();
+
+ int score = compare_locales(locale, l);
+ if (score > 0 && score >= best_score) {
+ best_locale = l;
+ best_score = score;
+ if (score == 10) {
+ break; // Exact match, skip the rest.
+ }
+ }
+ }
+ return best_locale;
}
}
diff --git a/core/typedefs.h b/core/typedefs.h
index cd1367611a..1dcba58188 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -305,9 +305,9 @@ struct BuildIndexSequence<0, Is...> : IndexSequence<Is...> {};
#endif
// Macro GD_IS_DEFINED() allows to check if a macro is defined. It needs to be defined to anything (say 1) to work.
-#define __GDARG_PLACEHOLDER_1 0,
+#define __GDARG_PLACEHOLDER_1 false,
#define __gd_take_second_arg(__ignored, val, ...) val
-#define ____gd_is_defined(arg1_or_junk) __gd_take_second_arg(arg1_or_junk 1, 0)
+#define ____gd_is_defined(arg1_or_junk) __gd_take_second_arg(arg1_or_junk true, false)
#define ___gd_is_defined(val) ____gd_is_defined(__GDARG_PLACEHOLDER_##val)
#define GD_IS_DEFINED(x) ___gd_is_defined(x)
diff --git a/core/variant/array.cpp b/core/variant/array.cpp
index d156c35343..5215142dd3 100644
--- a/core/variant/array.cpp
+++ b/core/variant/array.cpp
@@ -466,7 +466,7 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const {
ERR_FAIL_COND_V_MSG(p_step > 0 && begin > end, result, "Slice is positive, but bounds is decreasing.");
ERR_FAIL_COND_V_MSG(p_step < 0 && begin < end, result, "Slice is negative, but bounds is increasing.");
- int result_size = (end - begin) / p_step;
+ int result_size = (end - begin) / p_step + (((end - begin) % p_step != 0) ? 1 : 0);
result.resize(result_size);
for (int src_idx = begin, dest_idx = 0; dest_idx < result_size; ++dest_idx) {
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp
index 2da9559873..fa3bb78913 100644
--- a/core/variant/variant.cpp
+++ b/core/variant/variant.cpp
@@ -2941,7 +2941,7 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
return hash_one_uint64((uint64_t)_data._int);
} break;
case FLOAT: {
- return hash_murmur3_one_float(_data._float);
+ return hash_murmur3_one_double(_data._float);
} break;
case STRING: {
return reinterpret_cast<const String *>(_data._mem)->hash();
@@ -3158,7 +3158,7 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
}
return hash_fmix32(h);
} else {
- return hash_murmur3_one_float(0.0);
+ return hash_murmur3_one_double(0.0);
}
} break;
diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp
index 8f3ae65b9c..a6363039ba 100644
--- a/core/variant/variant_utility.cpp
+++ b/core/variant/variant_utility.cpp
@@ -542,7 +542,8 @@ struct VariantUtilityFunctions {
}
Variant base = *p_args[0];
Variant ret;
- for (int i = 1; i < p_argcount; i++) {
+
+ for (int i = 0; i < p_argcount; i++) {
Variant::Type arg_type = p_args[i]->get_type();
if (arg_type != Variant::INT && arg_type != Variant::FLOAT) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
@@ -550,6 +551,9 @@ struct VariantUtilityFunctions {
r_error.argument = i;
return Variant();
}
+ if (i == 0) {
+ continue;
+ }
bool valid;
Variant::evaluate(Variant::OP_LESS, base, *p_args[i], ret, valid);
if (!valid) {
@@ -582,7 +586,8 @@ struct VariantUtilityFunctions {
}
Variant base = *p_args[0];
Variant ret;
- for (int i = 1; i < p_argcount; i++) {
+
+ for (int i = 0; i < p_argcount; i++) {
Variant::Type arg_type = p_args[i]->get_type();
if (arg_type != Variant::INT && arg_type != Variant::FLOAT) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
@@ -590,6 +595,9 @@ struct VariantUtilityFunctions {
r_error.argument = i;
return Variant();
}
+ if (i == 0) {
+ continue;
+ }
bool valid;
Variant::evaluate(Variant::OP_GREATER, base, *p_args[i], ret, valid);
if (!valid) {