summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/input/input_event.cpp2
-rw-r--r--core/io/resource.cpp1
-rw-r--r--core/math/aabb.h2
-rw-r--r--core/math/delaunay_3d.h12
-rw-r--r--core/math/dynamic_bvh.h9
-rw-r--r--core/math/geometry_2d.h6
-rw-r--r--core/math/random_pcg.cpp2
-rw-r--r--core/math/rect2.h14
-rw-r--r--core/math/rect2i.h14
-rw-r--r--core/math/transform_interpolator.cpp76
-rw-r--r--core/math/transform_interpolator.h46
-rw-r--r--core/object/object.cpp77
-rw-r--r--core/object/script_language.cpp19
-rw-r--r--core/object/script_language.h2
-rw-r--r--core/os/main_loop.h1
-rw-r--r--core/os/os.h3
-rw-r--r--core/string/ustring.cpp127
-rw-r--r--core/string/ustring.h9
-rw-r--r--core/templates/local_vector.h16
-rw-r--r--core/variant/variant_call.cpp2
20 files changed, 319 insertions, 121 deletions
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index bd1fde5a85..bf1de8d3b2 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -132,6 +132,8 @@ void InputEvent::_bind_methods() {
ClassDB::bind_method(D_METHOD("xformed_by", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2()));
ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device");
+
+ BIND_CONSTANT(DEVICE_ID_EMULATION);
}
///////////////////////////////////
diff --git a/core/io/resource.cpp b/core/io/resource.cpp
index 5edb045760..dc974a545a 100644
--- a/core/io/resource.cpp
+++ b/core/io/resource.cpp
@@ -214,6 +214,7 @@ Error Resource::copy_from(const Ref<Resource> &p_resource) {
}
return OK;
}
+
void Resource::reload_from_file() {
String path = get_path();
if (!path.is_resource_file()) {
diff --git a/core/math/aabb.h b/core/math/aabb.h
index 7927c431eb..48a883e64c 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -101,7 +101,7 @@ struct _NO_DISCARD_ AABB {
_FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */
_FORCE_INLINE_ AABB abs() const {
- return AABB(Vector3(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0), position.z + MIN(size.z, (real_t)0)), size.abs());
+ return AABB(position + size.min(Vector3()), size.abs());
}
Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const;
diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h
index 7df8c37e3c..846acdecc3 100644
--- a/core/math/delaunay_3d.h
+++ b/core/math/delaunay_3d.h
@@ -281,9 +281,7 @@ public:
}
Vector3i grid_pos = Vector3i(points[i] * ACCEL_GRID_SIZE);
- grid_pos.x = CLAMP(grid_pos.x, 0, ACCEL_GRID_SIZE - 1);
- grid_pos.y = CLAMP(grid_pos.y, 0, ACCEL_GRID_SIZE - 1);
- grid_pos.z = CLAMP(grid_pos.z, 0, ACCEL_GRID_SIZE - 1);
+ grid_pos = grid_pos.clamp(Vector3i(), Vector3i(ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1));
for (List<Simplex *>::Element *E = acceleration_grid[grid_pos.x][grid_pos.y][grid_pos.z].front(); E;) {
List<Simplex *>::Element *N = E->next(); //may be deleted
@@ -339,12 +337,8 @@ public:
Vector3 extents = Vector3(radius2, radius2, radius2);
Vector3i from = Vector3i((center - extents) * ACCEL_GRID_SIZE);
Vector3i to = Vector3i((center + extents) * ACCEL_GRID_SIZE);
- from.x = CLAMP(from.x, 0, ACCEL_GRID_SIZE - 1);
- from.y = CLAMP(from.y, 0, ACCEL_GRID_SIZE - 1);
- from.z = CLAMP(from.z, 0, ACCEL_GRID_SIZE - 1);
- to.x = CLAMP(to.x, 0, ACCEL_GRID_SIZE - 1);
- to.y = CLAMP(to.y, 0, ACCEL_GRID_SIZE - 1);
- to.z = CLAMP(to.z, 0, ACCEL_GRID_SIZE - 1);
+ from = from.clamp(Vector3i(), Vector3i(ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1));
+ to = to.clamp(Vector3i(), Vector3i(ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1, ACCEL_GRID_SIZE - 1));
for (int32_t x = from.x; x <= to.x; x++) {
for (int32_t y = from.y; y <= to.y; y++) {
diff --git a/core/math/dynamic_bvh.h b/core/math/dynamic_bvh.h
index f586b845c3..26fc517f7f 100644
--- a/core/math/dynamic_bvh.h
+++ b/core/math/dynamic_bvh.h
@@ -376,13 +376,8 @@ void DynamicBVH::convex_query(const Plane *p_planes, int p_plane_count, const Ve
volume.min = p_points[0];
volume.max = p_points[0];
} else {
- volume.min.x = MIN(volume.min.x, p_points[i].x);
- volume.min.y = MIN(volume.min.y, p_points[i].y);
- volume.min.z = MIN(volume.min.z, p_points[i].z);
-
- volume.max.x = MAX(volume.max.x, p_points[i].x);
- volume.max.y = MAX(volume.max.y, p_points[i].y);
- volume.max.z = MAX(volume.max.z, p_points[i].z);
+ volume.min = volume.min.min(p_points[i]);
+ volume.max = volume.max.max(p_points[i]);
}
}
diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h
index fbcaa018a8..1502b2807c 100644
--- a/core/math/geometry_2d.h
+++ b/core/math/geometry_2d.h
@@ -377,10 +377,8 @@ public:
Vector2 further_away_opposite(1e20, 1e20);
for (int i = 0; i < c; i++) {
- further_away.x = MAX(p[i].x, further_away.x);
- further_away.y = MAX(p[i].y, further_away.y);
- further_away_opposite.x = MIN(p[i].x, further_away_opposite.x);
- further_away_opposite.y = MIN(p[i].y, further_away_opposite.y);
+ further_away = further_away.max(p[i]);
+ further_away_opposite = further_away_opposite.min(p[i]);
}
// Make point outside that won't intersect with points in segment from p_point.
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp
index e083820494..55787a0b57 100644
--- a/core/math/random_pcg.cpp
+++ b/core/math/random_pcg.cpp
@@ -52,7 +52,7 @@ int64_t RandomPCG::rand_weighted(const Vector<float> &p_weights) {
weights_sum += weights[i];
}
- float remaining_distance = Math::randf() * weights_sum;
+ float remaining_distance = randf() * weights_sum;
for (int64_t i = 0; i < weights_size; ++i) {
remaining_distance -= weights[i];
if (remaining_distance < 0) {
diff --git a/core/math/rect2.h b/core/math/rect2.h
index 0f874d4857..497ed8cf04 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -152,14 +152,12 @@ struct _NO_DISCARD_ Rect2 {
return Rect2();
}
- new_rect.position.x = MAX(p_rect.position.x, position.x);
- new_rect.position.y = MAX(p_rect.position.y, position.y);
+ new_rect.position = p_rect.position.max(position);
Point2 p_rect_end = p_rect.position + p_rect.size;
Point2 end = position + size;
- new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.position.x;
- new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.position.y;
+ new_rect.size = p_rect_end.min(end) - new_rect.position;
return new_rect;
}
@@ -172,11 +170,9 @@ struct _NO_DISCARD_ Rect2 {
#endif
Rect2 new_rect;
- new_rect.position.x = MIN(p_rect.position.x, position.x);
- new_rect.position.y = MIN(p_rect.position.y, position.y);
+ new_rect.position = p_rect.position.min(position);
- new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x);
- new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y);
+ new_rect.size = (p_rect.position + p_rect.size).max(position + size);
new_rect.size = new_rect.size - new_rect.position; // Make relative again.
@@ -282,7 +278,7 @@ struct _NO_DISCARD_ Rect2 {
}
_FORCE_INLINE_ Rect2 abs() const {
- return Rect2(Point2(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0)), size.abs());
+ return Rect2(position + size.min(Point2()), size.abs());
}
_FORCE_INLINE_ Rect2 round() const {
diff --git a/core/math/rect2i.h b/core/math/rect2i.h
index 205b2c7198..64806414c7 100644
--- a/core/math/rect2i.h
+++ b/core/math/rect2i.h
@@ -95,14 +95,12 @@ struct _NO_DISCARD_ Rect2i {
return Rect2i();
}
- new_rect.position.x = MAX(p_rect.position.x, position.x);
- new_rect.position.y = MAX(p_rect.position.y, position.y);
+ new_rect.position = p_rect.position.max(position);
Point2i p_rect_end = p_rect.position + p_rect.size;
Point2i end = position + size;
- new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.position.x;
- new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.position.y;
+ new_rect.size = p_rect_end.min(end) - new_rect.position;
return new_rect;
}
@@ -115,11 +113,9 @@ struct _NO_DISCARD_ Rect2i {
#endif
Rect2i new_rect;
- new_rect.position.x = MIN(p_rect.position.x, position.x);
- new_rect.position.y = MIN(p_rect.position.y, position.y);
+ new_rect.position = p_rect.position.min(position);
- new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x);
- new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y);
+ new_rect.size = (p_rect.position + p_rect.size).max(position + size);
new_rect.size = new_rect.size - new_rect.position; // Make relative again.
@@ -217,7 +213,7 @@ struct _NO_DISCARD_ Rect2i {
}
_FORCE_INLINE_ Rect2i abs() const {
- return Rect2i(Point2i(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs());
+ return Rect2i(position + size.min(Point2i()), size.abs());
}
_FORCE_INLINE_ void set_end(const Vector2i &p_end) {
diff --git a/core/math/transform_interpolator.cpp b/core/math/transform_interpolator.cpp
new file mode 100644
index 0000000000..7cfe880b5a
--- /dev/null
+++ b/core/math/transform_interpolator.cpp
@@ -0,0 +1,76 @@
+/**************************************************************************/
+/* transform_interpolator.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#include "transform_interpolator.h"
+
+#include "core/math/transform_2d.h"
+
+void TransformInterpolator::interpolate_transform_2d(const Transform2D &p_prev, const Transform2D &p_curr, Transform2D &r_result, real_t p_fraction) {
+ // Extract parameters.
+ Vector2 p1 = p_prev.get_origin();
+ Vector2 p2 = p_curr.get_origin();
+
+ // Special case for physics interpolation, if flipping, don't interpolate basis.
+ // If the determinant polarity changes, the handedness of the coordinate system changes.
+ if (_sign(p_prev.determinant()) != _sign(p_curr.determinant())) {
+ r_result.columns[0] = p_curr.columns[0];
+ r_result.columns[1] = p_curr.columns[1];
+ r_result.set_origin(p1.lerp(p2, p_fraction));
+ return;
+ }
+
+ real_t r1 = p_prev.get_rotation();
+ real_t r2 = p_curr.get_rotation();
+
+ Size2 s1 = p_prev.get_scale();
+ Size2 s2 = p_curr.get_scale();
+
+ // Slerp rotation.
+ Vector2 v1(Math::cos(r1), Math::sin(r1));
+ Vector2 v2(Math::cos(r2), Math::sin(r2));
+
+ real_t dot = v1.dot(v2);
+
+ dot = CLAMP(dot, -1, 1);
+
+ Vector2 v;
+
+ if (dot > 0.9995f) {
+ v = v1.lerp(v2, p_fraction).normalized(); // Linearly interpolate to avoid numerical precision issues.
+ } else {
+ real_t angle = p_fraction * Math::acos(dot);
+ Vector2 v3 = (v2 - v1 * dot).normalized();
+ v = v1 * Math::cos(angle) + v3 * Math::sin(angle);
+ }
+
+ // Construct matrix.
+ r_result = Transform2D(Math::atan2(v.y, v.x), p1.lerp(p2, p_fraction));
+ r_result.scale_basis(s1.lerp(s2, p_fraction));
+}
diff --git a/core/math/transform_interpolator.h b/core/math/transform_interpolator.h
new file mode 100644
index 0000000000..a9bce2bd7f
--- /dev/null
+++ b/core/math/transform_interpolator.h
@@ -0,0 +1,46 @@
+/**************************************************************************/
+/* transform_interpolator.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#ifndef TRANSFORM_INTERPOLATOR_H
+#define TRANSFORM_INTERPOLATOR_H
+
+#include "core/math/math_defs.h"
+
+struct Transform2D;
+
+class TransformInterpolator {
+private:
+ static bool _sign(real_t p_val) { return p_val >= 0; }
+
+public:
+ static void interpolate_transform_2d(const Transform2D &p_prev, const Transform2D &p_curr, Transform2D &r_result, real_t p_fraction);
+};
+
+#endif // TRANSFORM_INTERPOLATOR_H
diff --git a/core/object/object.cpp b/core/object/object.cpp
index e0a1ddcce0..8b6fd587e0 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -1100,11 +1100,6 @@ bool Object::_has_user_signal(const StringName &p_name) const {
return signal_map[p_name].user.name.length() > 0;
}
-struct _ObjectSignalDisconnectData {
- StringName signal;
- Callable callable;
-};
-
Error Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
if (unlikely(p_argcount < 1)) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
@@ -1153,26 +1148,43 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
// which is needed in certain edge cases; e.g., https://github.com/godotengine/godot/issues/73889.
Ref<RefCounted> rc = Ref<RefCounted>(Object::cast_to<RefCounted>(this));
- List<_ObjectSignalDisconnectData> disconnect_data;
-
// Ensure that disconnecting the signal or even deleting the object
// will not affect the signal calling.
- LocalVector<Connection> slot_conns;
- slot_conns.resize(s->slot_map.size());
- {
- uint32_t idx = 0;
- for (const KeyValue<Callable, SignalData::Slot> &slot_kv : s->slot_map) {
- slot_conns[idx++] = slot_kv.value.conn;
+ Callable *slot_callables = (Callable *)alloca(sizeof(Callable) * s->slot_map.size());
+ uint32_t *slot_flags = (uint32_t *)alloca(sizeof(uint32_t) * s->slot_map.size());
+ uint32_t slot_count = 0;
+
+ for (const KeyValue<Callable, SignalData::Slot> &slot_kv : s->slot_map) {
+ memnew_placement(&slot_callables[slot_count], Callable(slot_kv.value.conn.callable));
+ slot_flags[slot_count] = slot_kv.value.conn.flags;
+ ++slot_count;
+ }
+
+ DEV_ASSERT(slot_count == s->slot_map.size());
+
+ // Disconnect all one-shot connections before emitting to prevent recursion.
+ for (uint32_t i = 0; i < slot_count; ++i) {
+ bool disconnect = slot_flags[i] & CONNECT_ONE_SHOT;
+#ifdef TOOLS_ENABLED
+ if (disconnect && (slot_flags[i] & CONNECT_PERSIST) && Engine::get_singleton()->is_editor_hint()) {
+ // This signal was connected from the editor, and is being edited. Just don't disconnect for now.
+ disconnect = false;
+ }
+#endif
+ if (disconnect) {
+ _disconnect(p_name, slot_callables[i]);
}
- DEV_ASSERT(idx == s->slot_map.size());
}
OBJ_DEBUG_LOCK
Error err = OK;
- for (const Connection &c : slot_conns) {
- if (!c.callable.is_valid()) {
+ for (uint32_t i = 0; i < slot_count; ++i) {
+ const Callable &callable = slot_callables[i];
+ const uint32_t &flags = slot_flags[i];
+
+ if (!callable.is_valid()) {
// Target might have been deleted during signal callback, this is expected and OK.
continue;
}
@@ -1180,51 +1192,34 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
const Variant **args = p_args;
int argc = p_argcount;
- if (c.flags & CONNECT_DEFERRED) {
- MessageQueue::get_singleton()->push_callablep(c.callable, args, argc, true);
+ if (flags & CONNECT_DEFERRED) {
+ MessageQueue::get_singleton()->push_callablep(callable, args, argc, true);
} else {
Callable::CallError ce;
_emitting = true;
Variant ret;
- c.callable.callp(args, argc, ret, ce);
+ callable.callp(args, argc, ret, ce);
_emitting = false;
if (ce.error != Callable::CallError::CALL_OK) {
#ifdef DEBUG_ENABLED
- if (c.flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref<Script>(script)->is_tool())) {
+ if (flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref<Script>(script)->is_tool())) {
continue;
}
#endif
- Object *target = c.callable.get_object();
+ Object *target = callable.get_object();
if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD && target && !ClassDB::class_exists(target->get_class_name())) {
//most likely object is not initialized yet, do not throw error.
} else {
- ERR_PRINT("Error calling from signal '" + String(p_name) + "' to callable: " + Variant::get_callable_error_text(c.callable, args, argc, ce) + ".");
+ ERR_PRINT("Error calling from signal '" + String(p_name) + "' to callable: " + Variant::get_callable_error_text(callable, args, argc, ce) + ".");
err = ERR_METHOD_NOT_FOUND;
}
}
}
-
- bool disconnect = c.flags & CONNECT_ONE_SHOT;
-#ifdef TOOLS_ENABLED
- if (disconnect && (c.flags & CONNECT_PERSIST) && Engine::get_singleton()->is_editor_hint()) {
- //this signal was connected from the editor, and is being edited. just don't disconnect for now
- disconnect = false;
- }
-#endif
- if (disconnect) {
- _ObjectSignalDisconnectData dd;
- dd.signal = p_name;
- dd.callable = c.callable;
- disconnect_data.push_back(dd);
- }
}
- while (!disconnect_data.is_empty()) {
- const _ObjectSignalDisconnectData &dd = disconnect_data.front()->get();
-
- _disconnect(dd.signal, dd.callable);
- disconnect_data.pop_front();
+ for (uint32_t i = 0; i < slot_count; ++i) {
+ slot_callables[i].~Callable();
}
return err;
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index 1196c2f787..73da0ba2af 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -34,6 +34,7 @@
#include "core/core_string_names.h"
#include "core/debugger/engine_debugger.h"
#include "core/debugger/script_debugger.h"
+#include "core/io/resource_loader.h"
#include <stdint.h>
@@ -170,6 +171,24 @@ void Script::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "source_code", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_source_code", "get_source_code");
}
+void Script::reload_from_file() {
+#ifdef TOOLS_ENABLED
+ // Replicates how the ScriptEditor reloads script resources, which generally handles it.
+ // However, when scripts are to be reloaded but aren't open in the internal editor, we go through here instead.
+ const Ref<Script> rel = ResourceLoader::load(ResourceLoader::path_remap(get_path()), get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE);
+ if (rel.is_null()) {
+ return;
+ }
+
+ set_source_code(rel->get_source_code());
+ set_last_modified_time(rel->get_last_modified_time());
+
+ reload();
+#else
+ Resource::reload_from_file();
+#endif
+}
+
void ScriptServer::set_scripting_enabled(bool p_enabled) {
scripting_enabled = p_enabled;
}
diff --git a/core/object/script_language.h b/core/object/script_language.h
index be50e58d79..c6c6f3de9f 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -125,6 +125,8 @@ protected:
Dictionary _get_script_constant_map();
public:
+ virtual void reload_from_file() override;
+
virtual bool can_instantiate() const = 0;
virtual Ref<Script> get_base_script() const = 0; //for script inheritance
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index b45eb38aeb..e48541d074 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -62,6 +62,7 @@ public:
};
virtual void initialize();
+ virtual void iteration_prepare() {}
virtual bool physics_process(double p_time);
virtual bool process(double p_time);
virtual void finalize();
diff --git a/core/os/os.h b/core/os/os.h
index e0dda0b155..4f0df1543f 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -56,7 +56,8 @@ class OS {
bool _verbose_stdout = false;
bool _debug_stdout = false;
String _local_clipboard;
- int _exit_code = EXIT_FAILURE; // unexpected exit is marked as failure
+ // Assume success by default, all failure cases need to set EXIT_FAILURE explicitly.
+ int _exit_code = EXIT_SUCCESS;
bool _allow_hidpi = false;
bool _allow_layered = false;
bool _stdout_enabled = true;
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index a7e12138f2..dbc283946e 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -927,52 +927,49 @@ static _FORCE_INLINE_ signed char natural_cmp_common(const char32_t *&r_this_str
return 0;
}
-signed char String::naturalcasecmp_to(const String &p_str) const {
- const char32_t *this_str = get_data();
- const char32_t *that_str = p_str.get_data();
-
- if (this_str && that_str) {
- while (*this_str == '.' || *that_str == '.') {
- if (*this_str++ != '.') {
+static _FORCE_INLINE_ signed char naturalcasecmp_to_base(const char32_t *p_this_str, const char32_t *p_that_str) {
+ if (p_this_str && p_that_str) {
+ while (*p_this_str == '.' || *p_that_str == '.') {
+ if (*p_this_str++ != '.') {
return 1;
}
- if (*that_str++ != '.') {
+ if (*p_that_str++ != '.') {
return -1;
}
- if (!*that_str) {
+ if (!*p_that_str) {
return 1;
}
- if (!*this_str) {
+ if (!*p_this_str) {
return -1;
}
}
- while (*this_str) {
- if (!*that_str) {
+ while (*p_this_str) {
+ if (!*p_that_str) {
return 1;
- } else if (is_digit(*this_str)) {
- if (!is_digit(*that_str)) {
+ } else if (is_digit(*p_this_str)) {
+ if (!is_digit(*p_that_str)) {
return -1;
}
- signed char ret = natural_cmp_common(this_str, that_str);
+ signed char ret = natural_cmp_common(p_this_str, p_that_str);
if (ret) {
return ret;
}
- } else if (is_digit(*that_str)) {
+ } else if (is_digit(*p_that_str)) {
return 1;
} else {
- if (*this_str < *that_str) { // If current character in this is less, we are less.
+ if (*p_this_str < *p_that_str) { // If current character in this is less, we are less.
return -1;
- } else if (*this_str > *that_str) { // If current character in this is greater, we are greater.
+ } else if (*p_this_str > *p_that_str) { // If current character in this is greater, we are greater.
return 1;
}
- this_str++;
- that_str++;
+ p_this_str++;
+ p_that_str++;
}
}
- if (*that_str) {
+ if (*p_that_str) {
return -1;
}
}
@@ -980,52 +977,56 @@ signed char String::naturalcasecmp_to(const String &p_str) const {
return 0;
}
-signed char String::naturalnocasecmp_to(const String &p_str) const {
+signed char String::naturalcasecmp_to(const String &p_str) const {
const char32_t *this_str = get_data();
const char32_t *that_str = p_str.get_data();
- if (this_str && that_str) {
- while (*this_str == '.' || *that_str == '.') {
- if (*this_str++ != '.') {
+ return naturalcasecmp_to_base(this_str, that_str);
+}
+
+static _FORCE_INLINE_ signed char naturalnocasecmp_to_base(const char32_t *p_this_str, const char32_t *p_that_str) {
+ if (p_this_str && p_that_str) {
+ while (*p_this_str == '.' || *p_that_str == '.') {
+ if (*p_this_str++ != '.') {
return 1;
}
- if (*that_str++ != '.') {
+ if (*p_that_str++ != '.') {
return -1;
}
- if (!*that_str) {
+ if (!*p_that_str) {
return 1;
}
- if (!*this_str) {
+ if (!*p_this_str) {
return -1;
}
}
- while (*this_str) {
- if (!*that_str) {
+ while (*p_this_str) {
+ if (!*p_that_str) {
return 1;
- } else if (is_digit(*this_str)) {
- if (!is_digit(*that_str)) {
+ } else if (is_digit(*p_this_str)) {
+ if (!is_digit(*p_that_str)) {
return -1;
}
- signed char ret = natural_cmp_common(this_str, that_str);
+ signed char ret = natural_cmp_common(p_this_str, p_that_str);
if (ret) {
return ret;
}
- } else if (is_digit(*that_str)) {
+ } else if (is_digit(*p_that_str)) {
return 1;
} else {
- if (_find_upper(*this_str) < _find_upper(*that_str)) { // If current character in this is less, we are less.
+ if (_find_upper(*p_this_str) < _find_upper(*p_that_str)) { // If current character in this is less, we are less.
return -1;
- } else if (_find_upper(*this_str) > _find_upper(*that_str)) { // If current character in this is greater, we are greater.
+ } else if (_find_upper(*p_this_str) > _find_upper(*p_that_str)) { // If current character in this is greater, we are greater.
return 1;
}
- this_str++;
- that_str++;
+ p_this_str++;
+ p_that_str++;
}
}
- if (*that_str) {
+ if (*p_that_str) {
return -1;
}
}
@@ -1033,6 +1034,54 @@ signed char String::naturalnocasecmp_to(const String &p_str) const {
return 0;
}
+signed char String::naturalnocasecmp_to(const String &p_str) const {
+ const char32_t *this_str = get_data();
+ const char32_t *that_str = p_str.get_data();
+
+ return naturalnocasecmp_to_base(this_str, that_str);
+}
+
+static _FORCE_INLINE_ signed char file_cmp_common(const char32_t *&r_this_str, const char32_t *&r_that_str) {
+ // Compare leading `_` sequences.
+ while (*r_this_str && *r_that_str) {
+ // Sort `_` lower than everything except `.`
+ if (*r_this_str != '_' && *r_that_str == '_') {
+ return *r_this_str == '.' ? -1 : 1;
+ }
+ if (*r_this_str == '_' && *r_that_str != '_') {
+ return *r_that_str == '.' ? 1 : -1;
+ }
+ r_this_str++;
+ r_that_str++;
+ }
+
+ return 0;
+}
+
+signed char String::filecasecmp_to(const String &p_str) const {
+ const char32_t *this_str = get_data();
+ const char32_t *that_str = p_str.get_data();
+
+ signed char ret = file_cmp_common(this_str, that_str);
+ if (ret) {
+ return ret;
+ }
+
+ return naturalcasecmp_to_base(this_str, that_str);
+}
+
+signed char String::filenocasecmp_to(const String &p_str) const {
+ const char32_t *this_str = get_data();
+ const char32_t *that_str = p_str.get_data();
+
+ signed char ret = file_cmp_common(this_str, that_str);
+ if (ret) {
+ return ret;
+ }
+
+ return naturalnocasecmp_to_base(this_str, that_str);
+}
+
const char32_t *String::get_data() const {
static const char32_t zero = 0;
return size() ? &operator[](0) : &zero;
diff --git a/core/string/ustring.h b/core/string/ustring.h
index 0fb72fccd2..fa904c8200 100644
--- a/core/string/ustring.h
+++ b/core/string/ustring.h
@@ -265,6 +265,9 @@ public:
signed char nocasecmp_to(const String &p_str) const;
signed char naturalcasecmp_to(const String &p_str) const;
signed char naturalnocasecmp_to(const String &p_str) const;
+ // Special sorting for file names. Names starting with `_` are put before all others except those starting with `.`, otherwise natural comparison is used.
+ signed char filecasecmp_to(const String &p_str) const;
+ signed char filenocasecmp_to(const String &p_str) const;
const char32_t *get_data() const;
/* standard size stuff */
@@ -499,6 +502,12 @@ struct NaturalNoCaseComparator {
}
};
+struct FileNoCaseComparator {
+ bool operator()(const String &p_a, const String &p_b) const {
+ return p_a.filenocasecmp_to(p_b) < 0;
+ }
+};
+
template <typename L, typename R>
_FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
while (true) {
diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h
index 6478297fd1..e0047e0782 100644
--- a/core/templates/local_vector.h
+++ b/core/templates/local_vector.h
@@ -104,6 +104,22 @@ public:
return false;
}
+ U erase_multiple_unordered(const T &p_val) {
+ U from = 0;
+ U occurrences = 0;
+ while (true) {
+ int64_t idx = find(p_val, from);
+
+ if (idx == -1) {
+ break;
+ }
+ remove_at_unordered(idx);
+ from = idx;
+ occurrences++;
+ }
+ return occurrences;
+ }
+
void invert() {
for (U i = 0; i < count / 2; i++) {
SWAP(data[i], data[count - i - 1]);
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 5f04c42536..ba7c44e405 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -1644,6 +1644,8 @@ static void _register_variant_builtin_methods() {
bind_string_method(nocasecmp_to, sarray("to"), varray());
bind_string_method(naturalcasecmp_to, sarray("to"), varray());
bind_string_method(naturalnocasecmp_to, sarray("to"), varray());
+ bind_string_method(filecasecmp_to, sarray("to"), varray());
+ bind_string_method(filenocasecmp_to, sarray("to"), varray());
bind_string_method(length, sarray(), varray());
bind_string_method(substr, sarray("from", "len"), varray(-1));
bind_string_method(get_slice, sarray("delimiter", "slice"), varray());