summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/config/project_settings.cpp2
-rw-r--r--core/debugger/remote_debugger.cpp3
-rw-r--r--core/extension/gdextension.cpp2
-rw-r--r--core/extension/gdextension_interface.h6
-rw-r--r--core/input/input.cpp16
-rw-r--r--core/input/input.h6
-rw-r--r--core/io/image.cpp98
-rw-r--r--core/io/image.h22
-rw-r--r--core/io/marshalls.cpp18
-rw-r--r--core/io/resource.cpp17
-rw-r--r--core/io/resource_loader.cpp98
-rw-r--r--core/io/resource_loader.h1
-rw-r--r--core/object/object.cpp2
-rw-r--r--core/object/script_language.cpp4
-rw-r--r--core/object/script_language.h1
-rw-r--r--core/object/worker_thread_pool.cpp18
-rw-r--r--core/os/os.h2
-rw-r--r--core/templates/command_queue_mt.h8
-rw-r--r--core/variant/variant_construct.h8
19 files changed, 184 insertions, 148 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index e59f79fcc8..37a2608c10 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -1491,7 +1491,7 @@ ProjectSettings::ProjectSettings() {
PackedStringArray extensions;
extensions.push_back("gd");
- if (Engine::get_singleton()->has_singleton("GodotSharp")) {
+ if (ClassDB::class_exists("CSharpScript")) {
extensions.push_back("cs");
}
extensions.push_back("gdshader");
diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp
index bd30da3047..e2ed7245a2 100644
--- a/core/debugger/remote_debugger.cpp
+++ b/core/debugger/remote_debugger.cpp
@@ -39,6 +39,7 @@
#include "core/io/resource_loader.h"
#include "core/object/script_language.h"
#include "core/os/os.h"
+#include "servers/display_server.h"
class RemoteDebugger::PerformanceProfiler : public EngineProfiler {
Object *performance = nullptr;
@@ -539,7 +540,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
OS::get_singleton()->delay_usec(10000);
if (Thread::get_caller_id() == Thread::get_main_id()) {
// If this is a busy loop on the main thread, events still need to be processed.
- OS::get_singleton()->process_and_drop_events();
+ DisplayServer::get_singleton()->force_process_and_drop_events();
}
}
}
diff --git a/core/extension/gdextension.cpp b/core/extension/gdextension.cpp
index 47628e4ea0..8e2366fc95 100644
--- a/core/extension/gdextension.cpp
+++ b/core/extension/gdextension.cpp
@@ -795,7 +795,7 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb
// because that's what we want to check to see if it's changed.
library_path = actual_lib_path.get_base_dir().path_join(p_path.get_file());
} else {
- library_path = p_path;
+ library_path = actual_lib_path;
}
ERR_FAIL_COND_V_MSG(err == ERR_FILE_NOT_FOUND, err, "GDExtension dynamic library not found: " + abs_path);
diff --git a/core/extension/gdextension_interface.h b/core/extension/gdextension_interface.h
index d6c1df9c00..fce377f967 100644
--- a/core/extension/gdextension_interface.h
+++ b/core/extension/gdextension_interface.h
@@ -2800,12 +2800,16 @@ typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassVirtualMethod)(G
*
* Registers an integer constant on an extension class in the ClassDB.
*
+ * Note about registering bitfield values (if p_is_bitfield is true): even though p_constant_value is signed, language bindings are
+ * advised to treat bitfields as uint64_t, since this is generally clearer and can prevent mistakes like using -1 for setting all bits.
+ * Language APIs should thus provide an abstraction that registers bitfields (uint64_t) separately from regular constants (int64_t).
+ *
* @param p_library A pointer the library received by the GDExtension's entry point function.
* @param p_class_name A pointer to a StringName with the class name.
* @param p_enum_name A pointer to a StringName with the enum name.
* @param p_constant_name A pointer to a StringName with the constant name.
* @param p_constant_value The constant value.
- * @param p_is_bitfield Whether or not this is a bit field.
+ * @param p_is_bitfield Whether or not this constant is part of a bitfield.
*/
typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassIntegerConstant)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_enum_name, GDExtensionConstStringNamePtr p_constant_name, GDExtensionInt p_constant_value, GDExtensionBool p_is_bitfield);
diff --git a/core/input/input.cpp b/core/input/input.cpp
index ec0303df06..91378591b0 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -890,8 +890,9 @@ void Input::action_press(const StringName &p_action, float p_strength) {
// Create or retrieve existing action.
ActionState &action_state = action_states[p_action];
+ // As input may come in part way through a physics tick, the earliest we can react to it is the next physics tick.
if (!action_state.cache.pressed) {
- action_state.pressed_physics_frame = Engine::get_singleton()->get_physics_frames();
+ action_state.pressed_physics_frame = Engine::get_singleton()->get_physics_frames() + 1;
action_state.pressed_process_frame = Engine::get_singleton()->get_process_frames();
}
action_state.exact = true;
@@ -908,7 +909,8 @@ void Input::action_release(const StringName &p_action) {
action_state.cache.pressed = 0;
action_state.cache.strength = 0.0;
action_state.cache.raw_strength = 0.0;
- action_state.released_physics_frame = Engine::get_singleton()->get_physics_frames();
+ // As input may come in part way through a physics tick, the earliest we can react to it is the next physics tick.
+ action_state.released_physics_frame = Engine::get_singleton()->get_physics_frames() + 1;
action_state.released_process_frame = Engine::get_singleton()->get_process_frames();
action_state.device_states.clear();
action_state.exact = true;
@@ -1023,7 +1025,7 @@ void Input::parse_input_event(const Ref<InputEvent> &p_event) {
if (buffered_events.is_empty() || !buffered_events.back()->get()->accumulate(p_event)) {
buffered_events.push_back(p_event);
}
- } else if (use_input_buffering) {
+ } else if (agile_input_event_flushing) {
buffered_events.push_back(p_event);
} else {
_parse_input_event_impl(p_event, false);
@@ -1054,12 +1056,12 @@ void Input::flush_buffered_events() {
}
}
-bool Input::is_using_input_buffering() {
- return use_input_buffering;
+bool Input::is_agile_input_event_flushing() {
+ return agile_input_event_flushing;
}
-void Input::set_use_input_buffering(bool p_enable) {
- use_input_buffering = p_enable;
+void Input::set_agile_input_event_flushing(bool p_enable) {
+ agile_input_event_flushing = p_enable;
}
void Input::set_use_accumulated_input(bool p_enable) {
diff --git a/core/input/input.h b/core/input/input.h
index 4daea0c9e8..89e48f53d7 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -128,7 +128,7 @@ private:
bool emulate_touch_from_mouse = false;
bool emulate_mouse_from_touch = false;
- bool use_input_buffering = false;
+ bool agile_input_event_flushing = false;
bool use_accumulated_input = true;
int mouse_from_touch_index = -1;
@@ -367,8 +367,8 @@ public:
void flush_frame_parsed_events();
#endif
void flush_buffered_events();
- bool is_using_input_buffering();
- void set_use_input_buffering(bool p_enable);
+ bool is_agile_input_event_flushing();
+ void set_agile_input_event_flushing(bool p_enable);
void set_use_accumulated_input(bool p_enable);
bool is_using_accumulated_input();
diff --git a/core/io/image.cpp b/core/io/image.cpp
index 4b1188ad47..d0598e4dc6 100644
--- a/core/io/image.cpp
+++ b/core/io/image.cpp
@@ -300,10 +300,10 @@ int Image::get_format_block_size(Format p_format) {
return 1;
}
-void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_width, int &r_height) const {
+void Image::_get_mipmap_offset_and_size(int p_mipmap, int64_t &r_offset, int &r_width, int &r_height) const {
int w = width;
int h = height;
- int ofs = 0;
+ int64_t ofs = 0;
int pixel_size = get_format_pixel_size(format);
int pixel_rshift = get_format_pixel_rshift(format);
@@ -315,7 +315,7 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_widt
int bw = w % block != 0 ? w + (block - w % block) : w;
int bh = h % block != 0 ? h + (block - h % block) : h;
- int s = bw * bh;
+ int64_t s = bw * bh;
s *= pixel_size;
s >>= pixel_rshift;
@@ -329,37 +329,30 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_widt
r_height = h;
}
-int Image::get_mipmap_offset(int p_mipmap) const {
+int64_t Image::get_mipmap_offset(int p_mipmap) const {
ERR_FAIL_INDEX_V(p_mipmap, get_mipmap_count() + 1, -1);
- int ofs, w, h;
+ int64_t ofs;
+ int w, h;
_get_mipmap_offset_and_size(p_mipmap, ofs, w, h);
return ofs;
}
-int Image::get_mipmap_byte_size(int p_mipmap) const {
- ERR_FAIL_INDEX_V(p_mipmap, get_mipmap_count() + 1, -1);
-
- int ofs, w, h;
- _get_mipmap_offset_and_size(p_mipmap, ofs, w, h);
- int ofs2;
- _get_mipmap_offset_and_size(p_mipmap + 1, ofs2, w, h);
- return ofs2 - ofs;
-}
-
-void Image::get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) const {
- int ofs, w, h;
+void Image::get_mipmap_offset_and_size(int p_mipmap, int64_t &r_ofs, int64_t &r_size) const {
+ int64_t ofs;
+ int w, h;
_get_mipmap_offset_and_size(p_mipmap, ofs, w, h);
- int ofs2;
+ int64_t ofs2;
_get_mipmap_offset_and_size(p_mipmap + 1, ofs2, w, h);
r_ofs = ofs;
r_size = ofs2 - ofs;
}
-void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int &r_size, int &w, int &h) const {
- int ofs;
+void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int64_t &r_ofs, int64_t &r_size, int &w, int &h) const {
+ int64_t ofs;
_get_mipmap_offset_and_size(p_mipmap, ofs, w, h);
- int ofs2, w2, h2;
+ int64_t ofs2;
+ int w2, h2;
_get_mipmap_offset_and_size(p_mipmap + 1, ofs2, w2, h2);
r_ofs = ofs;
r_size = ofs2 - ofs;
@@ -538,8 +531,8 @@ void Image::convert(Format p_new_format) {
}
}
- int mip_offset = 0;
- int mip_size = 0;
+ int64_t mip_offset = 0;
+ int64_t mip_size = 0;
new_img.get_mipmap_offset_and_size(mip, mip_offset, mip_size);
memcpy(new_img.data.ptrw() + mip_offset, new_mip->data.ptr(), mip_size);
@@ -555,8 +548,8 @@ void Image::convert(Format p_new_format) {
int conversion_type = format | p_new_format << 8;
for (int mip = 0; mip < mipmap_count; mip++) {
- int mip_offset = 0;
- int mip_size = 0;
+ int64_t mip_offset = 0;
+ int64_t mip_size = 0;
int mip_width = 0;
int mip_height = 0;
get_mipmap_offset_size_and_dimensions(mip, mip_offset, mip_size, mip_width, mip_height);
@@ -1151,7 +1144,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
if (i == 0) {
// Read from the first mipmap that will be interpolated
// (if both levels are the same, we will not interpolate, but at least we'll sample from the right level)
- int offs;
+ int64_t offs;
_get_mipmap_offset_and_size(mip1, offs, src_width, src_height);
src_ptr = r_ptr + offs;
} else if (!interpolate_mipmaps) {
@@ -1159,7 +1152,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
break;
} else {
// Switch to read from the second mipmap that will be interpolated
- int offs;
+ int64_t offs;
_get_mipmap_offset_and_size(mip2, offs, src_width, src_height);
src_ptr = r_ptr + offs;
// Switch to write to the second destination image
@@ -1599,9 +1592,9 @@ void Image::flip_x() {
}
/// Get mipmap size and offset.
-int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps, int *r_mm_width, int *r_mm_height) {
+int64_t Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps, int *r_mm_width, int *r_mm_height) {
// Data offset in mipmaps (including the original texture).
- int size = 0;
+ int64_t size = 0;
int w = p_width;
int h = p_height;
@@ -1623,7 +1616,7 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &
int bw = w % block != 0 ? w + (block - w % block) : w;
int bh = h % block != 0 ? h + (block - h % block) : h;
- int s = bw * bh;
+ int64_t s = bw * bh;
s *= pixsize;
s >>= pixshift;
@@ -1837,7 +1830,8 @@ Error Image::generate_mipmaps(bool p_renormalize) {
int prev_w = width;
for (int i = 1; i <= mmcount; i++) {
- int ofs, w, h;
+ int64_t ofs;
+ int w, h;
_get_mipmap_offset_and_size(i, ofs, w, h);
switch (format) {
@@ -1993,7 +1987,8 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
uint8_t *base_ptr = data.ptrw();
for (int i = 1; i <= mmcount; i++) {
- int ofs, w, h;
+ int64_t ofs;
+ int w, h;
_get_mipmap_offset_and_size(i, ofs, w, h);
uint8_t *ptr = &base_ptr[ofs];
@@ -2102,21 +2097,6 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
_set_color_at_ofs(ptr, pixel_ofs, c);
}
}
-#if 0
- {
- int size = get_mipmap_byte_size(i);
- print_line("size for mimpap " + itos(i) + ": " + itos(size));
- Vector<uint8_t> imgdata;
- imgdata.resize(size);
-
-
- uint8_t* wr = imgdata.ptrw();
- memcpy(wr.ptr(), ptr, size);
- wr = uint8_t*();
- Ref<Image> im = Image::create_from_data(w, h, false, format, imgdata);
- im->save_png("res://mipmap_" + itos(i) + ".png");
- }
-#endif
}
return OK;
@@ -2131,7 +2111,8 @@ void Image::clear_mipmaps() {
return;
}
- int ofs, w, h;
+ int64_t ofs;
+ int w, h;
_get_mipmap_offset_and_size(1, ofs, w, h);
data.resize(ofs);
@@ -2176,7 +2157,7 @@ void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps, Forma
ERR_FAIL_INDEX_MSG(p_format, FORMAT_MAX, "The Image format specified (" + itos(p_format) + ") is out of range. See Image's Format enum.");
int mm = 0;
- int size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0);
+ int64_t size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0);
data.resize(size);
{
@@ -2202,7 +2183,7 @@ void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps, Forma
ERR_FAIL_INDEX_MSG(p_format, FORMAT_MAX, "The Image format specified (" + itos(p_format) + ") is out of range. See Image's Format enum.");
int mm;
- int size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0);
+ int64_t size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0);
if (unlikely(p_data.size() != size)) {
String description_mipmaps = get_format_name(p_format) + " ";
@@ -2405,7 +2386,7 @@ bool Image::is_invisible() const {
return false;
}
- int len = data.size();
+ int64_t len = data.size();
if (len == 0) {
return true;
@@ -2445,7 +2426,7 @@ bool Image::is_invisible() const {
}
Image::AlphaMode Image::detect_alpha() const {
- int len = data.size();
+ int64_t len = data.size();
if (len == 0) {
return ALPHA_NONE;
@@ -2579,7 +2560,7 @@ Vector<uint8_t> Image::save_webp_to_buffer(const bool p_lossy, const float p_qua
return save_webp_buffer_func(Ref<Image>((Image *)this), p_lossy, p_quality);
}
-int Image::get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps) {
+int64_t Image::get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps) {
int mm;
return _get_dst_image_size(p_width, p_height, p_format, mm, p_mipmaps ? -1 : 0);
}
@@ -2597,7 +2578,7 @@ Size2i Image::get_image_mipmap_size(int p_width, int p_height, Format p_format,
return ret;
}
-int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap) {
+int64_t Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap) {
if (p_mipmap <= 0) {
return 0;
}
@@ -2605,7 +2586,7 @@ int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, i
return _get_dst_image_size(p_width, p_height, p_format, mm, p_mipmap - 1);
}
-int Image::get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h) {
+int64_t Image::get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h) {
if (p_mipmap <= 0) {
r_w = p_width;
r_h = p_height;
@@ -3642,9 +3623,10 @@ Ref<Image> Image::rgbe_to_srgb() {
return new_image;
}
-Ref<Image> Image::get_image_from_mipmap(int p_mipamp) const {
- int ofs, size, w, h;
- get_mipmap_offset_size_and_dimensions(p_mipamp, ofs, size, w, h);
+Ref<Image> Image::get_image_from_mipmap(int p_mipmap) const {
+ int64_t ofs, size;
+ int w, h;
+ get_mipmap_offset_size_and_dimensions(p_mipmap, ofs, size, w, h);
Vector<uint8_t> new_data;
new_data.resize(size);
diff --git a/core/io/image.h b/core/io/image.h
index d3ae99954f..d55cc39dbb 100644
--- a/core/io/image.h
+++ b/core/io/image.h
@@ -195,9 +195,9 @@ private:
data = p_image.data;
}
- _FORCE_INLINE_ void _get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_width, int &r_height) const; //get where the mipmap begins in data
+ _FORCE_INLINE_ void _get_mipmap_offset_and_size(int p_mipmap, int64_t &r_offset, int &r_width, int &r_height) const; //get where the mipmap begins in data
- static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1, int *r_mm_width = nullptr, int *r_mm_height = nullptr);
+ static int64_t _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1, int *r_mm_width = nullptr, int *r_mm_height = nullptr);
bool _can_modify(Format p_format) const;
_FORCE_INLINE_ void _get_clipped_src_and_dest_rects(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest, Rect2i &r_clipped_src_rect, Rect2i &r_clipped_dest_rect) const;
@@ -238,10 +238,12 @@ public:
*/
Format get_format() const;
- int get_mipmap_byte_size(int p_mipmap) const; //get where the mipmap begins in data
- int get_mipmap_offset(int p_mipmap) const; //get where the mipmap begins in data
- void get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) const; //get where the mipmap begins in data
- void get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int &r_size, int &w, int &h) const; //get where the mipmap begins in data
+ /**
+ * Get where the mipmap begins in data.
+ */
+ int64_t get_mipmap_offset(int p_mipmap) const;
+ void get_mipmap_offset_and_size(int p_mipmap, int64_t &r_ofs, int64_t &r_size) const;
+ void get_mipmap_offset_size_and_dimensions(int p_mipmap, int64_t &r_ofs, int64_t &r_size, int &w, int &h) const;
enum Image3DValidateError {
VALIDATE_3D_OK,
@@ -351,11 +353,11 @@ public:
static int get_format_block_size(Format p_format);
static void get_format_min_pixel_size(Format p_format, int &r_w, int &r_h);
- static int get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps = false);
+ static int64_t get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps = false);
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
static Size2i get_image_mipmap_size(int p_width, int p_height, Format p_format, int p_mipmap);
- static int get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap);
- static int get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h);
+ static int64_t get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap);
+ static int64_t get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h);
enum CompressMode {
COMPRESS_S3TC,
@@ -383,7 +385,7 @@ public:
void srgb_to_linear();
void normal_map_to_xy();
Ref<Image> rgbe_to_srgb();
- Ref<Image> get_image_from_mipmap(int p_mipamp) const;
+ Ref<Image> get_image_from_mipmap(int p_mipmap) const;
void bump_map_to_normal_map(float bump_scale = 1.0);
void blit_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest);
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index c0d18d0120..67469de5cc 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -1315,10 +1315,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
if (array.is_typed()) {
Ref<Script> script = array.get_typed_script();
if (script.is_valid()) {
- header |= HEADER_DATA_FIELD_TYPED_ARRAY_SCRIPT;
+ header |= p_full_objects ? HEADER_DATA_FIELD_TYPED_ARRAY_SCRIPT : HEADER_DATA_FIELD_TYPED_ARRAY_CLASS_NAME;
} else if (array.get_typed_class_name() != StringName()) {
header |= HEADER_DATA_FIELD_TYPED_ARRAY_CLASS_NAME;
} else {
+ // No need to check `p_full_objects` since for `Variant::OBJECT`
+ // `array.get_typed_class_name()` should be non-empty.
header |= HEADER_DATA_FIELD_TYPED_ARRAY_BUILTIN;
}
}
@@ -1783,12 +1785,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
Variant variant = array.get_typed_script();
Ref<Script> script = variant;
if (script.is_valid()) {
- String path = script->get_path();
- ERR_FAIL_COND_V_MSG(path.is_empty() || !path.begins_with("res://"), ERR_UNAVAILABLE, "Failed to encode a path to a custom script for an array type.");
- _encode_string(path, buf, r_len);
+ if (p_full_objects) {
+ String path = script->get_path();
+ ERR_FAIL_COND_V_MSG(path.is_empty() || !path.begins_with("res://"), ERR_UNAVAILABLE, "Failed to encode a path to a custom script for an array type.");
+ _encode_string(path, buf, r_len);
+ } else {
+ _encode_string(EncodedObjectAsID::get_class_static(), buf, r_len);
+ }
} else if (array.get_typed_class_name() != StringName()) {
- _encode_string(array.get_typed_class_name(), buf, r_len);
+ _encode_string(p_full_objects ? array.get_typed_class_name().operator String() : EncodedObjectAsID::get_class_static(), buf, r_len);
} else {
+ // No need to check `p_full_objects` since for `Variant::OBJECT`
+ // `array.get_typed_class_name()` should be non-empty.
if (buf) {
encode_uint32(array.get_typed_builtin(), buf);
buf += 4;
diff --git a/core/io/resource.cpp b/core/io/resource.cpp
index c045c0fc74..432adb88da 100644
--- a/core/io/resource.cpp
+++ b/core/io/resource.cpp
@@ -40,7 +40,12 @@
#include <stdio.h>
void Resource::emit_changed() {
- emit_signal(CoreStringName(changed));
+ if (ResourceLoader::is_within_load() && MessageQueue::get_main_singleton() != MessageQueue::get_singleton() && !MessageQueue::get_singleton()->is_flushing()) {
+ // Let the connection happen on the call queue, later, since signals are not thread-safe.
+ call_deferred("emit_signal", CoreStringName(changed));
+ } else {
+ emit_signal(CoreStringName(changed));
+ }
}
void Resource::_resource_path_changed() {
@@ -161,12 +166,22 @@ bool Resource::editor_can_reload_from_file() {
}
void Resource::connect_changed(const Callable &p_callable, uint32_t p_flags) {
+ if (ResourceLoader::is_within_load() && MessageQueue::get_main_singleton() != MessageQueue::get_singleton() && !MessageQueue::get_singleton()->is_flushing()) {
+ // Let the check and connection happen on the call queue, later, since signals are not thread-safe.
+ callable_mp(this, &Resource::connect_changed).call_deferred(p_callable, p_flags);
+ return;
+ }
if (!is_connected(CoreStringName(changed), p_callable) || p_flags & CONNECT_REFERENCE_COUNTED) {
connect(CoreStringName(changed), p_callable, p_flags);
}
}
void Resource::disconnect_changed(const Callable &p_callable) {
+ if (ResourceLoader::is_within_load() && MessageQueue::get_main_singleton() != MessageQueue::get_singleton() && !MessageQueue::get_singleton()->is_flushing()) {
+ // Let the check and disconnection happen on the call queue, later, since signals are not thread-safe.
+ callable_mp(this, &Resource::disconnect_changed).call_deferred(p_callable);
+ return;
+ }
if (is_connected(CoreStringName(changed), p_callable)) {
disconnect(CoreStringName(changed), p_callable);
}
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 20dd192da1..2b5e83264e 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -304,31 +304,24 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
thread_load_mutex.unlock();
// Thread-safe either if it's the current thread or a brand new one.
- thread_local bool mq_override_present = false;
CallQueue *own_mq_override = nullptr;
if (load_nesting == 0) {
- mq_override_present = false;
load_paths_stack = memnew(Vector<String>);
- if (!load_task.dependent_path.is_empty()) {
- load_paths_stack->push_back(load_task.dependent_path);
- }
if (!Thread::is_main_thread()) {
// Let the caller thread use its own, for added flexibility. Provide one otherwise.
if (MessageQueue::get_singleton() == MessageQueue::get_main_singleton()) {
own_mq_override = memnew(CallQueue);
MessageQueue::set_thread_singleton_override(own_mq_override);
}
- mq_override_present = true;
set_current_thread_safe_for_nodes(true);
}
- } else {
- DEV_ASSERT(load_task.dependent_path.is_empty());
}
// --
- Ref<Resource> res = _load(load_task.remapped_path, load_task.remapped_path != load_task.local_path ? load_task.local_path : String(), load_task.type_hint, load_task.cache_mode, &load_task.error, load_task.use_sub_threads, &load_task.progress);
- if (mq_override_present) {
+ Error load_err = OK;
+ Ref<Resource> res = _load(load_task.remapped_path, load_task.remapped_path != load_task.local_path ? load_task.local_path : String(), load_task.type_hint, load_task.cache_mode, &load_err, load_task.use_sub_threads, &load_task.progress);
+ if (MessageQueue::get_singleton() != MessageQueue::get_main_singleton()) {
MessageQueue::get_singleton()->flush();
}
@@ -336,7 +329,8 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
load_task.resource = res;
- load_task.progress = 1.0; //it was fully loaded at this point, so force progress to 1.0
+ load_task.progress = 1.0; // It was fully loaded at this point, so force progress to 1.0.
+ load_task.error = load_err;
if (load_task.error != OK) {
load_task.status = THREAD_LOAD_FAILED;
} else {
@@ -351,7 +345,14 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
bool ignoring = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP;
bool replacing = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP;
+ bool unlock_pending = true;
if (load_task.resource.is_valid()) {
+ // From now on, no critical section needed as no one will write to the task anymore.
+ // Moreover, the mutex being unlocked is a requirement if some of the calls below
+ // that set the resource up invoke code that in turn requests resource loading.
+ thread_load_mutex.unlock();
+ unlock_pending = false;
+
if (!ignoring) {
if (replacing) {
Ref<Resource> old_res = ResourceCache::get_ref(load_task.local_path);
@@ -389,13 +390,18 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
load_task.status = THREAD_LOAD_LOADED;
load_task.progress = 1.0;
+ thread_load_mutex.unlock();
+ unlock_pending = false;
+
if (_loaded_callback) {
_loaded_callback(load_task.resource, load_task.local_path);
}
}
}
- thread_load_mutex.unlock();
+ if (unlock_pending) {
+ thread_load_mutex.unlock();
+ }
if (load_nesting == 0) {
if (own_mq_override) {
@@ -473,12 +479,13 @@ Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path,
if (!ignoring_cache && thread_load_tasks.has(local_path)) {
load_token = Ref<LoadToken>(thread_load_tasks[local_path].load_token);
- if (!load_token.is_valid()) {
+ if (load_token.is_valid()) {
+ return load_token;
+ } else {
// The token is dying (reached 0 on another thread).
// Ensure it's killed now so the path can be safely reused right away.
thread_load_tasks[local_path].load_token->clear();
}
- return load_token;
}
load_token.instantiate();
@@ -560,39 +567,46 @@ float ResourceLoader::_dependency_get_progress(const String &p_path) {
}
ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, float *r_progress) {
- MutexLock thread_load_lock(thread_load_mutex);
+ bool ensure_progress = false;
+ ThreadLoadStatus status = THREAD_LOAD_IN_PROGRESS;
+ {
+ MutexLock thread_load_lock(thread_load_mutex);
- if (!user_load_tokens.has(p_path)) {
- print_verbose("load_threaded_get_status(): No threaded load for resource path '" + p_path + "' has been initiated or its result has already been collected.");
- return THREAD_LOAD_INVALID_RESOURCE;
- }
+ if (!user_load_tokens.has(p_path)) {
+ print_verbose("load_threaded_get_status(): No threaded load for resource path '" + p_path + "' has been initiated or its result has already been collected.");
+ return THREAD_LOAD_INVALID_RESOURCE;
+ }
- String local_path = _validate_local_path(p_path);
- if (!thread_load_tasks.has(local_path)) {
+ String local_path = _validate_local_path(p_path);
+ if (!thread_load_tasks.has(local_path)) {
#ifdef DEV_ENABLED
- CRASH_NOW();
+ CRASH_NOW();
#endif
- // On non-dev, be defensive and at least avoid crashing (at this point at least).
- return THREAD_LOAD_INVALID_RESOURCE;
- }
+ // On non-dev, be defensive and at least avoid crashing (at this point at least).
+ return THREAD_LOAD_INVALID_RESOURCE;
+ }
- ThreadLoadTask &load_task = thread_load_tasks[local_path];
- ThreadLoadStatus status;
- status = load_task.status;
- if (r_progress) {
- *r_progress = _dependency_get_progress(local_path);
- }
+ ThreadLoadTask &load_task = thread_load_tasks[local_path];
+ status = load_task.status;
+ if (r_progress) {
+ *r_progress = _dependency_get_progress(local_path);
+ }
- // Support userland polling in a loop on the main thread.
- if (Thread::is_main_thread() && status == THREAD_LOAD_IN_PROGRESS) {
- uint64_t frame = Engine::get_singleton()->get_process_frames();
- if (frame == load_task.last_progress_check_main_thread_frame) {
- _ensure_load_progress();
- } else {
- load_task.last_progress_check_main_thread_frame = frame;
+ // Support userland polling in a loop on the main thread.
+ if (Thread::is_main_thread() && status == THREAD_LOAD_IN_PROGRESS) {
+ uint64_t frame = Engine::get_singleton()->get_process_frames();
+ if (frame == load_task.last_progress_check_main_thread_frame) {
+ ensure_progress = true;
+ } else {
+ load_task.last_progress_check_main_thread_frame = frame;
+ }
}
}
+ if (ensure_progress) {
+ _ensure_load_progress();
+ }
+
return status;
}
@@ -626,13 +640,13 @@ Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path, Error *r_e
if (Thread::is_main_thread() && !load_token->local_path.is_empty()) {
const ThreadLoadTask &load_task = thread_load_tasks[load_token->local_path];
while (load_task.status == THREAD_LOAD_IN_PROGRESS) {
- if (!_ensure_load_progress()) {
- // This local poll loop is not needed.
- break;
- }
thread_load_lock.~MutexLock();
+ bool exit = !_ensure_load_progress();
OS::get_singleton()->delay_usec(1000);
new (&thread_load_lock) MutexLock(thread_load_mutex);
+ if (exit) {
+ break;
+ }
}
}
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 46df79ea22..5f1831f0d9 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -170,7 +170,6 @@ private:
LoadToken *load_token = nullptr;
String local_path;
String remapped_path;
- String dependent_path;
String type_hint;
float progress = 0.0f;
float max_reported_progress = 0.0f;
diff --git a/core/object/object.cpp b/core/object/object.cpp
index 97a3a405b9..e4d1a8fc9a 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -763,7 +763,7 @@ Variant Object::callp(const StringName &p_method, const Variant **p_args, int p_
}
if (is_ref_counted()) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
- ERR_FAIL_V_MSG(Variant(), "Can't 'free' a reference.");
+ ERR_FAIL_V_MSG(Variant(), "Can't free a RefCounted object.");
}
if (_lock_index.get() > 1) {
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index 0b528e908a..cdc56e5ec5 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -491,10 +491,6 @@ void ScriptServer::save_global_classes() {
ProjectSettings::get_singleton()->store_global_class_list(gcarr);
}
-String ScriptServer::get_global_class_cache_file_path() {
- return ProjectSettings::get_singleton()->get_global_class_list_path();
-}
-
////////////////////
ScriptCodeCompletionCache *ScriptCodeCompletionCache::singleton = nullptr;
diff --git a/core/object/script_language.h b/core/object/script_language.h
index 223f114150..59a43a7b29 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -97,7 +97,6 @@ public:
static void get_global_class_list(List<StringName> *r_global_classes);
static void get_inheriters_list(const StringName &p_base_type, List<StringName> *r_classes);
static void save_global_classes();
- static String get_global_class_cache_file_path();
static void init_languages();
static void finish_languages();
diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp
index caf4ed3835..56b9fa8475 100644
--- a/core/object/worker_thread_pool.cpp
+++ b/core/object/worker_thread_pool.cpp
@@ -59,8 +59,9 @@ void WorkerThreadPool::_process_task(Task *p_task) {
CallQueue *call_queue_backup = MessageQueue::get_singleton() != MessageQueue::get_main_singleton() ? MessageQueue::get_singleton() : nullptr;
{
- // Tasks must start with this unset. They are free to set-and-forget otherwise.
+ // Tasks must start with these at default values. They are free to set-and-forget otherwise.
set_current_thread_safe_for_nodes(false);
+ MessageQueue::set_thread_singleton_override(nullptr);
// Since the WorkerThreadPool is started before the script server,
// its pre-created threads can't have ScriptServer::thread_enter() called on them early.
// Therefore, we do it late at the first opportunity, so in case the task
@@ -82,6 +83,10 @@ void WorkerThreadPool::_process_task(Task *p_task) {
}
#endif
+#ifdef THREADS_ENABLED
+ bool low_priority = p_task->low_priority;
+#endif
+
if (p_task->group) {
// Handling a group
bool do_post = false;
@@ -158,7 +163,7 @@ void WorkerThreadPool::_process_task(Task *p_task) {
#ifdef THREADS_ENABLED
{
curr_thread.current_task = prev_task;
- if (p_task->low_priority) {
+ if (low_priority) {
low_priority_threads_used--;
if (_try_promote_low_priority_task()) {
@@ -397,16 +402,17 @@ Error WorkerThreadPool::wait_for_task_completion(TaskID p_task_id) {
task->waiting_user++;
}
- task_mutex.unlock();
-
if (caller_pool_thread) {
+ task_mutex.unlock();
_wait_collaboratively(caller_pool_thread, task);
+ task_mutex.lock();
task->waiting_pool--;
if (task->waiting_pool == 0 && task->waiting_user == 0) {
tasks.erase(p_task_id);
task_allocator.free(task);
}
} else {
+ task_mutex.unlock();
task->done_semaphore.wait();
task_mutex.lock();
task->waiting_user--;
@@ -414,9 +420,9 @@ Error WorkerThreadPool::wait_for_task_completion(TaskID p_task_id) {
tasks.erase(p_task_id);
task_allocator.free(task);
}
- task_mutex.unlock();
}
+ task_mutex.unlock();
return OK;
}
@@ -670,7 +676,7 @@ uint32_t WorkerThreadPool::thread_enter_unlock_allowance_zone(BinaryMutex *p_mut
uint32_t WorkerThreadPool::_thread_enter_unlock_allowance_zone(void *p_mutex, bool p_is_binary) {
for (uint32_t i = 0; i < MAX_UNLOCKABLE_MUTEXES; i++) {
- if (unlikely(unlockable_mutexes[i] == (uintptr_t)p_mutex)) {
+ if (unlikely((unlockable_mutexes[i] & ~1) == (uintptr_t)p_mutex)) {
// Already registered in the current thread.
return UINT32_MAX;
}
diff --git a/core/os/os.h b/core/os/os.h
index 63cc6ed50e..91e0ce9379 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -328,8 +328,6 @@ public:
virtual void benchmark_end_measure(const String &p_context, const String &p_what);
virtual void benchmark_dump();
- virtual void process_and_drop_events() {}
-
virtual Error setup_remote_filesystem(const String &p_server_host, int p_port, const String &p_password, String &r_project_path);
enum PreferredTextureFormat {
diff --git a/core/templates/command_queue_mt.h b/core/templates/command_queue_mt.h
index 0748e9cb83..1e6c6e42a9 100644
--- a/core/templates/command_queue_mt.h
+++ b/core/templates/command_queue_mt.h
@@ -370,15 +370,19 @@ class CommandQueueMT {
flush_read_ptr += 8;
CommandBase *cmd = reinterpret_cast<CommandBase *>(&command_mem[flush_read_ptr]);
cmd->call();
+
+ // Handle potential realloc due to the command and unlock allowance.
+ cmd = reinterpret_cast<CommandBase *>(&command_mem[flush_read_ptr]);
+
if (unlikely(cmd->sync)) {
sync_head++;
unlock(); // Give an opportunity to awaiters right away.
sync_cond_var.notify_all();
lock();
+ // Handle potential realloc happened during unlock.
+ cmd = reinterpret_cast<CommandBase *>(&command_mem[flush_read_ptr]);
}
- // If the command involved reallocating the buffer, the address may have changed.
- cmd = reinterpret_cast<CommandBase *>(&command_mem[flush_read_ptr]);
cmd->~CommandBase();
flush_read_ptr += size;
diff --git a/core/variant/variant_construct.h b/core/variant/variant_construct.h
index b824044b82..5afdb884f6 100644
--- a/core/variant/variant_construct.h
+++ b/core/variant/variant_construct.h
@@ -153,11 +153,14 @@ public:
class VariantConstructorObject {
public:
static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) {
- VariantInternal::clear(&r_ret);
if (p_args[0]->get_type() == Variant::NIL) {
+ VariantInternal::clear(&r_ret);
+ VariantTypeChanger<Object *>::change(&r_ret);
VariantInternal::object_assign_null(&r_ret);
r_error.error = Callable::CallError::CALL_OK;
} else if (p_args[0]->get_type() == Variant::OBJECT) {
+ VariantInternal::clear(&r_ret);
+ VariantTypeChanger<Object *>::change(&r_ret);
VariantInternal::object_assign(&r_ret, p_args[0]);
r_error.error = Callable::CallError::CALL_OK;
} else {
@@ -169,6 +172,7 @@ public:
static inline void validated_construct(Variant *r_ret, const Variant **p_args) {
VariantInternal::clear(r_ret);
+ VariantTypeChanger<Object *>::change(r_ret);
VariantInternal::object_assign(r_ret, p_args[0]);
}
static void ptr_construct(void *base, const void **p_args) {
@@ -198,11 +202,13 @@ public:
}
VariantInternal::clear(&r_ret);
+ VariantTypeChanger<Object *>::change(&r_ret);
VariantInternal::object_assign_null(&r_ret);
}
static inline void validated_construct(Variant *r_ret, const Variant **p_args) {
VariantInternal::clear(r_ret);
+ VariantTypeChanger<Object *>::change(r_ret);
VariantInternal::object_assign_null(r_ret);
}
static void ptr_construct(void *base, const void **p_args) {