diff options
85 files changed, 1589 insertions, 932 deletions
diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp index a7c0a0353e..8f56ca37de 100644 --- a/core/object/worker_thread_pool.cpp +++ b/core/object/worker_thread_pool.cpp @@ -33,7 +33,6 @@ #include "core/object/script_language.h" #include "core/os/os.h" #include "core/os/thread_safe.h" -#include "core/templates/command_queue_mt.h" WorkerThreadPool::Task *const WorkerThreadPool::ThreadData::YIELDING = (Task *)1; @@ -46,7 +45,9 @@ void WorkerThreadPool::Task::free_template_userdata() { WorkerThreadPool *WorkerThreadPool::singleton = nullptr; -thread_local CommandQueueMT *WorkerThreadPool::flushing_cmd_queue = nullptr; +#ifdef THREADS_ENABLED +thread_local uintptr_t WorkerThreadPool::unlockable_mutexes[MAX_UNLOCKABLE_MUTEXES] = {}; +#endif void WorkerThreadPool::_process_task(Task *p_task) { #ifdef THREADS_ENABLED @@ -419,6 +420,34 @@ Error WorkerThreadPool::wait_for_task_completion(TaskID p_task_id) { return OK; } +void WorkerThreadPool::_lock_unlockable_mutexes() { +#ifdef THREADS_ENABLED + for (uint32_t i = 0; i < MAX_UNLOCKABLE_MUTEXES; i++) { + if (unlockable_mutexes[i]) { + if ((((uintptr_t)unlockable_mutexes[i]) & 1) == 0) { + ((Mutex *)unlockable_mutexes[i])->lock(); + } else { + ((BinaryMutex *)unlockable_mutexes[i])->lock(); + } + } + } +#endif +} + +void WorkerThreadPool::_unlock_unlockable_mutexes() { +#ifdef THREADS_ENABLED + for (uint32_t i = 0; i < MAX_UNLOCKABLE_MUTEXES; i++) { + if (unlockable_mutexes[i]) { + if ((((uintptr_t)unlockable_mutexes[i]) & 1) == 0) { + ((Mutex *)unlockable_mutexes[i])->unlock(); + } else { + ((BinaryMutex *)unlockable_mutexes[i])->unlock(); + } + } + } +#endif +} + void WorkerThreadPool::_wait_collaboratively(ThreadData *p_caller_pool_thread, Task *p_task) { // Keep processing tasks until the condition to stop waiting is met. @@ -426,6 +455,7 @@ void WorkerThreadPool::_wait_collaboratively(ThreadData *p_caller_pool_thread, T while (true) { Task *task_to_process = nullptr; + bool relock_unlockables = false; { MutexLock lock(task_mutex); bool was_signaled = p_caller_pool_thread->signaled; @@ -463,13 +493,9 @@ void WorkerThreadPool::_wait_collaboratively(ThreadData *p_caller_pool_thread, T if (!task_to_process) { p_caller_pool_thread->awaited_task = p_task; - if (flushing_cmd_queue) { - flushing_cmd_queue->unlock(); - } + _unlock_unlockable_mutexes(); + relock_unlockables = true; p_caller_pool_thread->cond_var.wait(lock); - if (flushing_cmd_queue) { - flushing_cmd_queue->lock(); - } DEV_ASSERT(exit_threads || p_caller_pool_thread->signaled || IS_WAIT_OVER); p_caller_pool_thread->awaited_task = nullptr; @@ -477,6 +503,10 @@ void WorkerThreadPool::_wait_collaboratively(ThreadData *p_caller_pool_thread, T } } + if (relock_unlockables) { + _lock_unlockable_mutexes(); + } + if (task_to_process) { _process_task(task_to_process); } @@ -603,13 +633,9 @@ void WorkerThreadPool::wait_for_group_task_completion(GroupID p_group) { { Group *group = *groupp; - if (flushing_cmd_queue) { - flushing_cmd_queue->unlock(); - } + _unlock_unlockable_mutexes(); group->done_semaphore.wait(); - if (flushing_cmd_queue) { - flushing_cmd_queue->lock(); - } + _lock_unlockable_mutexes(); uint32_t max_users = group->tasks_used + 1; // Add 1 because the thread waiting for it is also user. Read before to avoid another thread freeing task after increment. uint32_t finished_users = group->finished.increment(); // fetch happens before inc, so increment later. @@ -633,16 +659,41 @@ int WorkerThreadPool::get_thread_index() { return singleton->thread_ids.has(tid) ? singleton->thread_ids[tid] : -1; } -void WorkerThreadPool::thread_enter_command_queue_mt_flush(CommandQueueMT *p_queue) { - ERR_FAIL_COND(flushing_cmd_queue != nullptr); - flushing_cmd_queue = p_queue; +#ifdef THREADS_ENABLED +uint32_t WorkerThreadPool::thread_enter_unlock_allowance_zone(Mutex *p_mutex) { + return _thread_enter_unlock_allowance_zone(p_mutex, false); +} + +uint32_t WorkerThreadPool::thread_enter_unlock_allowance_zone(BinaryMutex *p_mutex) { + return _thread_enter_unlock_allowance_zone(p_mutex, true); } -void WorkerThreadPool::thread_exit_command_queue_mt_flush() { - ERR_FAIL_NULL(flushing_cmd_queue); - flushing_cmd_queue = nullptr; +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)) { + // Already registered in the current thread. + return UINT32_MAX; + } + if (!unlockable_mutexes[i]) { + unlockable_mutexes[i] = (uintptr_t)p_mutex; + if (p_is_binary) { + unlockable_mutexes[i] |= 1; + } + return i; + } + } + ERR_FAIL_V_MSG(UINT32_MAX, "No more unlockable mutex slots available. Engine bug."); } +void WorkerThreadPool::thread_exit_unlock_allowance_zone(uint32_t p_zone_id) { + if (p_zone_id == UINT32_MAX) { + return; + } + DEV_ASSERT(unlockable_mutexes[p_zone_id]); + unlockable_mutexes[p_zone_id] = 0; +} +#endif + void WorkerThreadPool::init(int p_thread_count, float p_low_priority_task_ratio) { ERR_FAIL_COND(threads.size() > 0); if (p_thread_count < 0) { diff --git a/core/object/worker_thread_pool.h b/core/object/worker_thread_pool.h index a9cf260a0f..8774143abf 100644 --- a/core/object/worker_thread_pool.h +++ b/core/object/worker_thread_pool.h @@ -41,8 +41,6 @@ #include "core/templates/rid.h" #include "core/templates/safe_refcount.h" -class CommandQueueMT; - class WorkerThreadPool : public Object { GDCLASS(WorkerThreadPool, Object) public: @@ -163,7 +161,10 @@ private: static WorkerThreadPool *singleton; - static thread_local CommandQueueMT *flushing_cmd_queue; +#ifdef THREADS_ENABLED + static const uint32_t MAX_UNLOCKABLE_MUTEXES = 2; + static thread_local uintptr_t unlockable_mutexes[MAX_UNLOCKABLE_MUTEXES]; +#endif TaskID _add_task(const Callable &p_callable, void (*p_func)(void *), void *p_userdata, BaseTemplateUserdata *p_template_userdata, bool p_high_priority, const String &p_description); GroupID _add_group_task(const Callable &p_callable, void (*p_func)(void *, uint32_t), void *p_userdata, BaseTemplateUserdata *p_template_userdata, int p_elements, int p_tasks, bool p_high_priority, const String &p_description); @@ -190,6 +191,13 @@ private: void _wait_collaboratively(ThreadData *p_caller_pool_thread, Task *p_task); +#ifdef THREADS_ENABLED + static uint32_t _thread_enter_unlock_allowance_zone(void *p_mutex, bool p_is_binary); +#endif + + void _lock_unlockable_mutexes(); + void _unlock_unlockable_mutexes(); + protected: static void _bind_methods(); @@ -232,8 +240,14 @@ public: static WorkerThreadPool *get_singleton() { return singleton; } static int get_thread_index(); - static void thread_enter_command_queue_mt_flush(CommandQueueMT *p_queue); - static void thread_exit_command_queue_mt_flush(); +#ifdef THREADS_ENABLED + static uint32_t thread_enter_unlock_allowance_zone(Mutex *p_mutex); + static uint32_t thread_enter_unlock_allowance_zone(BinaryMutex *p_mutex); + static void thread_exit_unlock_allowance_zone(uint32_t p_zone_id); +#else + static uint32_t thread_enter_unlock_allowance_zone(void *p_mutex) { return UINT32_MAX; } + static void thread_exit_unlock_allowance_zone(uint32_t p_zone_id) {} +#endif void init(int p_thread_count = -1, float p_low_priority_task_ratio = 0.3); void finish(); diff --git a/core/templates/command_queue_mt.h b/core/templates/command_queue_mt.h index 349404d75b..0748e9cb83 100644 --- a/core/templates/command_queue_mt.h +++ b/core/templates/command_queue_mt.h @@ -364,7 +364,7 @@ class CommandQueueMT { lock(); - WorkerThreadPool::thread_enter_command_queue_mt_flush(this); + uint32_t allowance_id = WorkerThreadPool::thread_enter_unlock_allowance_zone(&mutex); while (flush_read_ptr < command_mem.size()) { uint64_t size = *(uint64_t *)&command_mem[flush_read_ptr]; flush_read_ptr += 8; @@ -383,7 +383,7 @@ class CommandQueueMT { flush_read_ptr += size; } - WorkerThreadPool::thread_exit_command_queue_mt_flush(); + WorkerThreadPool::thread_exit_unlock_allowance_zone(allowance_id); command_mem.clear(); flush_read_ptr = 0; diff --git a/doc/classes/AudioEffectSpectrumAnalyzer.xml b/doc/classes/AudioEffectSpectrumAnalyzer.xml index fbc0c2275f..b90f87ef5b 100644 --- a/doc/classes/AudioEffectSpectrumAnalyzer.xml +++ b/doc/classes/AudioEffectSpectrumAnalyzer.xml @@ -5,6 +5,7 @@ </brief_description> <description> This audio effect does not affect sound output, but can be used for real-time audio visualizations. + This resource configures an [AudioEffectSpectrumAnalyzerInstance], which performs the actual analysis at runtime. An instance can be acquired with [method AudioServer.get_bus_effect_instance]. See also [AudioStreamGenerator] for procedurally generating sounds. </description> <tutorials> diff --git a/doc/classes/AudioEffectSpectrumAnalyzerInstance.xml b/doc/classes/AudioEffectSpectrumAnalyzerInstance.xml index e8c6394073..184f80db2e 100644 --- a/doc/classes/AudioEffectSpectrumAnalyzerInstance.xml +++ b/doc/classes/AudioEffectSpectrumAnalyzerInstance.xml @@ -1,10 +1,14 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AudioEffectSpectrumAnalyzerInstance" inherits="AudioEffectInstance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> <brief_description> + Queryable instance of an [AudioEffectSpectrumAnalyzer]. </brief_description> <description> + The runtime part of an [AudioEffectSpectrumAnalyzer], which can be used to query the magnitude of a frequency range on its host bus. + An instance of this class can be acquired with [method AudioServer.get_bus_effect_instance]. </description> <tutorials> + <link title="Audio Spectrum Visualizer Demo">https://godotengine.org/asset-library/asset/2762</link> </tutorials> <methods> <method name="get_magnitude_for_frequency_range" qualifiers="const"> @@ -13,15 +17,17 @@ <param index="1" name="to_hz" type="float" /> <param index="2" name="mode" type="int" enum="AudioEffectSpectrumAnalyzerInstance.MagnitudeMode" default="1" /> <description> + Returns the magnitude of the frequencies from [param from_hz] to [param to_hz] in linear energy as a Vector2. The [code]x[/code] component of the return value represents the left stereo channel, and [code]y[/code] represents the right channel. + [param mode] determines how the frequency range will be processed. See [enum MagnitudeMode]. </description> </method> </methods> <constants> <constant name="MAGNITUDE_AVERAGE" value="0" enum="MagnitudeMode"> - Use the average value as magnitude. + Use the average value across the frequency range as magnitude. </constant> <constant name="MAGNITUDE_MAX" value="1" enum="MagnitudeMode"> - Use the maximum value as magnitude. + Use the maximum value of the frequency range as magnitude. </constant> </constants> </class> diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index c5737b235f..b4c1647dde 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -1069,7 +1069,7 @@ If [code]false[/code], using [kbd]Ctrl + Left[/kbd] or [kbd]Ctrl + Right[/kbd] ([kbd]Cmd + Left[/kbd] or [kbd]Cmd + Right[/kbd] on macOS) bindings will use the behavior of [member text_editor/behavior/navigation/use_default_word_separators]. If [code]true[/code], it will also stop the caret if a character within [member text_editor/behavior/navigation/custom_word_separators] is detected. Useful for subword moving. This behavior also will be applied to the behavior of text selection. </member> <member name="text_editor/behavior/navigation/use_default_word_separators" type="bool" setter="" getter=""> - If [code]false[/code], using [kbd]Ctrl + Left[/kbd] or [kbd]Ctrl + Right[/kbd] ([kbd]Cmd + Left[/kbd] or [kbd]Cmd + Right[/kbd] on macOS) bindings will stop moving caret only if a space or punctuation is detected. If [code]true[/code], it will also stop the caret if a character is [code]´`~$^=+|<>[/code], a General Punctuation, or CJK Punctuation. Useful for subword moving. This behavior also will be applied to the behavior of text selection. + If [code]false[/code], using [kbd]Ctrl + Left[/kbd] or [kbd]Ctrl + Right[/kbd] ([kbd]Cmd + Left[/kbd] or [kbd]Cmd + Right[/kbd] on macOS) bindings will stop moving caret only if a space or punctuation is detected. If [code]true[/code], it will also stop the caret if a character is part of [code]`!"#$%&'()*+,-./:;<=>?@[\]^`{|}~[/code], the Unicode General Punctuation table, or the Unicode CJK Punctuation table. Useful for subword moving. This behavior also will be applied to the behavior of text selection. </member> <member name="text_editor/behavior/navigation/v_scroll_speed" type="int" setter="" getter=""> The number of pixels to scroll with every mouse wheel increment. Higher values make the script scroll by faster when using the mouse wheel. diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 8085b20730..a446f3c928 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -477,6 +477,9 @@ <member name="debug/gdscript/warnings/assert_always_true" type="int" setter="" getter="" default="1"> When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when an [code]assert[/code] call always evaluates to true. </member> + <member name="debug/gdscript/warnings/confusable_capture_reassignment" type="int" setter="" getter="" default="1"> + When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when a local variable captured by a lambda is reassigned, since this does not modify the outer local variable. + </member> <member name="debug/gdscript/warnings/confusable_identifier" type="int" setter="" getter="" default="1"> When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when an identifier contains characters that can be confused with something else, like when mixing different alphabets. </member> diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index f82671b533..f71601f9ae 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -1370,7 +1370,7 @@ If [code]false[/code], using [kbd]Ctrl + Left[/kbd] or [kbd]Ctrl + Right[/kbd] ([kbd]Cmd + Left[/kbd] or [kbd]Cmd + Right[/kbd] on macOS) bindings will use the behavior of [member use_default_word_separators]. If [code]true[/code], it will also stop the caret if a character within [member custom_word_separators] is detected. Useful for subword moving. This behavior also will be applied to the behavior of text selection. </member> <member name="use_default_word_separators" type="bool" setter="set_use_default_word_separators" getter="is_default_word_separators_enabled" default="true"> - If [code]false[/code], using [kbd]Ctrl + Left[/kbd] or [kbd]Ctrl + Right[/kbd] ([kbd]Cmd + Left[/kbd] or [kbd]Cmd + Right[/kbd] on macOS) bindings will stop moving caret only if a space or punctuation is detected. If [code]true[/code], it will also stop the caret if a character is [code]´`~$^=+|<>[/code], a General Punctuation, or CJK Punctuation. Useful for subword moving. This behavior also will be applied to the behavior of text selection. + If [code]false[/code], using [kbd]Ctrl + Left[/kbd] or [kbd]Ctrl + Right[/kbd] ([kbd]Cmd + Left[/kbd] or [kbd]Cmd + Right[/kbd] on macOS) bindings will stop moving caret only if a space or punctuation is detected. If [code]true[/code], it will also stop the caret if a character is part of [code]!"#$%&'()*+,-./:;<=>?@[\]^`{|}~[/code], the Unicode General Punctuation table, or the Unicode CJK Punctuation table. Useful for subword moving. This behavior also will be applied to the behavior of text selection. </member> <member name="virtual_keyboard_enabled" type="bool" setter="set_virtual_keyboard_enabled" getter="is_virtual_keyboard_enabled" default="true"> If [code]true[/code], the native virtual keyboard is shown when focused on platforms that support it. diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index bacf607c66..21790d29b5 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -1111,15 +1111,15 @@ MaterialStorage::MaterialStorage() { global_shader_uniforms.buffer_size = MAX(16, (int)GLOBAL_GET("rendering/limits/global_shader_variables/buffer_size")); if (global_shader_uniforms.buffer_size * sizeof(GlobalShaderUniforms::Value) > uint32_t(Config::get_singleton()->max_uniform_buffer_size)) { + // Limit to maximum support UBO size. global_shader_uniforms.buffer_size = uint32_t(Config::get_singleton()->max_uniform_buffer_size) / sizeof(GlobalShaderUniforms::Value); - WARN_PRINT("Project setting \"rendering/limits/global_shader_variables/buffer_size\" exceeds maximum uniform buffer size of: " + itos(Config::get_singleton()->max_uniform_buffer_size / sizeof(GlobalShaderUniforms::Value)) + ". Falling back on maximum buffer size."); } global_shader_uniforms.buffer_values = memnew_arr(GlobalShaderUniforms::Value, global_shader_uniforms.buffer_size); memset(global_shader_uniforms.buffer_values, 0, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size); global_shader_uniforms.buffer_usage = memnew_arr(GlobalShaderUniforms::ValueUsage, global_shader_uniforms.buffer_size); - global_shader_uniforms.buffer_dirty_regions = memnew_arr(bool, global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE); - memset(global_shader_uniforms.buffer_dirty_regions, 0, sizeof(bool) * global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE); + global_shader_uniforms.buffer_dirty_regions = memnew_arr(bool, 1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE)); + memset(global_shader_uniforms.buffer_dirty_regions, 0, sizeof(bool) * (1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE))); glGenBuffers(1, &global_shader_uniforms.buffer); glBindBuffer(GL_UNIFORM_BUFFER, global_shader_uniforms.buffer); glBufferData(GL_UNIFORM_BUFFER, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size, nullptr, GL_DYNAMIC_DRAW); @@ -1788,7 +1788,7 @@ void MaterialStorage::global_shader_parameter_add(const StringName &p_name, RS:: //is vector, allocate in buffer and update index gv.buffer_index = _global_shader_uniform_allocate(gv.buffer_elements); - ERR_FAIL_COND_MSG(gv.buffer_index < 0, vformat("Failed allocating global variable '%s' out of buffer memory. Consider increasing it in the Project Settings.", String(p_name))); + ERR_FAIL_COND_MSG(gv.buffer_index < 0, vformat("Failed allocating global variable '%s' out of buffer memory. Consider increasing rendering/limits/global_shader_variables/buffer_size in the Project Settings. Maximum items supported by this hardware is: %d.", String(p_name), Config::get_singleton()->max_uniform_buffer_size / sizeof(GlobalShaderUniforms::Value))); global_shader_uniforms.buffer_usage[gv.buffer_index].elements = gv.buffer_elements; _global_shader_uniform_store_in_buffer(gv.buffer_index, gv.type, gv.value); _global_shader_uniform_mark_buffer_dirty(gv.buffer_index, gv.buffer_elements); @@ -1999,7 +1999,7 @@ int32_t MaterialStorage::global_shader_parameters_instance_allocate(RID p_instan ERR_FAIL_COND_V(global_shader_uniforms.instance_buffer_pos.has(p_instance), -1); int32_t pos = _global_shader_uniform_allocate(ShaderLanguage::MAX_INSTANCE_UNIFORM_INDICES); global_shader_uniforms.instance_buffer_pos[p_instance] = pos; //save anyway - ERR_FAIL_COND_V_MSG(pos < 0, -1, "Too many instances using shader instance variables. Increase buffer size in Project Settings."); + ERR_FAIL_COND_V_MSG(pos < 0, -1, vformat("Too many instances using shader instance variables. Consider increasing rendering/limits/global_shader_variables/buffer_size in the Project Settings. Maximum items supported by this hardware is: %d.", Config::get_singleton()->max_uniform_buffer_size / sizeof(GlobalShaderUniforms::Value))); global_shader_uniforms.buffer_usage[pos].elements = ShaderLanguage::MAX_INSTANCE_UNIFORM_INDICES; return pos; } @@ -2079,7 +2079,7 @@ void MaterialStorage::global_shader_parameters_instance_update(RID p_instance, i void MaterialStorage::_update_global_shader_uniforms() { MaterialStorage *material_storage = MaterialStorage::get_singleton(); if (global_shader_uniforms.buffer_dirty_region_count > 0) { - uint32_t total_regions = global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE; + uint32_t total_regions = 1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE); if (total_regions / global_shader_uniforms.buffer_dirty_region_count <= 4) { // 25% of regions dirty, just update all buffer glBindBuffer(GL_UNIFORM_BUFFER, global_shader_uniforms.buffer); diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index ffd609d925..d192ce0356 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -682,6 +682,7 @@ void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) { editor = p_editor; connect("clear_selection", callable_mp(editor, &AnimationTrackEditor::_clear_selection).bind(false)); connect("select_key", callable_mp(editor, &AnimationTrackEditor::_key_selected), CONNECT_DEFERRED); + connect("deselect_key", callable_mp(editor, &AnimationTrackEditor::_key_deselected), CONNECT_DEFERRED); } void AnimationBezierTrackEdit::_play_position_draw() { @@ -877,7 +878,7 @@ void AnimationBezierTrackEdit::_clear_selection_for_anim(const Ref<Animation> &p _clear_selection(); } -void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos) { +void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos, bool p_single) { if (!(animation == p_anim)) { return; } @@ -886,7 +887,7 @@ void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int ERR_FAIL_COND(idx < 0); selection.insert(IntPair(p_track, idx)); - emit_signal(SNAME("select_key"), idx, true, p_track); + emit_signal(SNAME("select_key"), idx, p_single, p_track); queue_redraw(); } @@ -1002,7 +1003,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { return; } else if (ED_IS_SHORTCUT("animation_bezier_editor/select_all_keys", p_event)) { for (int i = 0; i < edit_points.size(); ++i) { - selection.insert(IntPair(edit_points[i].track, edit_points[i].key)); + _select_at_anim(animation, edit_points[i].track, animation->track_get_key_time(edit_points[i].track, edit_points[i].key), i == 0); } queue_redraw(); @@ -1010,6 +1011,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { return; } else if (ED_IS_SHORTCUT("animation_bezier_editor/deselect_all_keys", p_event)) { selection.clear(); + emit_signal(SNAME("clear_selection")); queue_redraw(); accept_event(); @@ -1235,7 +1237,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { int index = animation->track_find_key(selected_track, time, Animation::FIND_MODE_APPROX); ERR_FAIL_COND(index == -1); _clear_selection(); - selection.insert(IntPair(selected_track, index)); + _select_at_anim(animation, selected_track, animation->track_get_key_time(selected_track, index), true); moving_selection_attempt = true; moving_selection = false; @@ -1277,13 +1279,15 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { Rect2 selection_rect(bs_from, bs_to - bs_from); bool track_set = false; + int j = 0; for (int i = 0; i < edit_points.size(); i++) { if (edit_points[i].point_rect.intersects(selection_rect)) { - selection.insert(IntPair(edit_points[i].track, edit_points[i].key)); + _select_at_anim(animation, edit_points[i].track, animation->track_get_key_time(edit_points[i].track, edit_points[i].key), j == 0 && !box_selecting_add); if (!track_set) { track_set = true; set_animation_and_track(animation, edit_points[i].track, read_only); } + j++; } } } else { @@ -1418,21 +1422,22 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation); // 7-reselect - + int i = 0; for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { real_t oldpos = animation->track_get_key_time(E->get().first, E->get().second); real_t newpos = oldpos + moving_selection_offset.x; - undo_redo->add_do_method(this, "_select_at_anim", animation, E->get().first, newpos); - undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, oldpos); + undo_redo->add_do_method(this, "_select_at_anim", animation, E->get().first, newpos, i == 0); + undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, oldpos, i == 0); + i++; } undo_redo->commit_action(); } else if (select_single_attempt != IntPair(-1, -1)) { selection.clear(); - selection.insert(select_single_attempt); set_animation_and_track(animation, select_single_attempt.first, read_only); + _select_at_anim(animation, select_single_attempt.first, animation->track_get_key_time(select_single_attempt.first, select_single_attempt.second), true); } moving_selection = false; @@ -1567,9 +1572,10 @@ bool AnimationBezierTrackEdit::_try_select_at_ui_pos(const Point2 &p_pos, bool p if (selection.has(pair)) { if (p_deselectable) { selection.erase(pair); + emit_signal(SNAME("deselect_key"), edit_points[i].key, edit_points[i].track); } } else { - selection.insert(pair); + _select_at_anim(animation, edit_points[i].track, animation->track_get_key_time(edit_points[i].track, edit_points[i].key), false); } queue_redraw(); select_single_attempt = IntPair(-1, -1); @@ -1595,7 +1601,7 @@ bool AnimationBezierTrackEdit::_try_select_at_ui_pos(const Point2 &p_pos, bool p set_animation_and_track(animation, pair.first, read_only); if (!selection.has(pair)) { selection.clear(); - selection.insert(pair); + _select_at_anim(animation, edit_points[i].track, animation->track_get_key_time(edit_points[i].track, edit_points[i].key), true); } } return true; @@ -1763,12 +1769,16 @@ void AnimationBezierTrackEdit::duplicate_selected_keys(real_t p_ofs, bool p_ofs_ undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation); // Reselect duplicated. + int i = 0; for (const Pair<int, real_t> &E : new_selection_values) { - undo_redo->add_do_method(this, "_select_at_anim", animation, E.first, E.second); + undo_redo->add_do_method(this, "_select_at_anim", animation, E.first, E.second, i == 0); + i++; } + i = 0; for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { real_t time = animation->track_get_key_time(E->get().first, E->get().second); - undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, time); + undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, time, i == 0); + i++; } undo_redo->add_do_method(this, "queue_redraw"); @@ -1805,16 +1815,20 @@ void AnimationBezierTrackEdit::copy_selected_keys(bool p_cut) { undo_redo->create_action(TTR("Animation Cut Keys"), UndoRedo::MERGE_DISABLE, animation.ptr()); undo_redo->add_do_method(this, "_clear_selection_for_anim", animation); undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation); + int i = 0; for (RBMap<AnimationTrackEditor::SelectedKey, AnimationTrackEditor::KeyInfo>::Element *E = keys.back(); E; E = E->prev()) { int track_idx = E->key().track; int key_idx = E->key().key; float time = E->value().pos; undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_time", track_idx, time); undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track_idx, time, animation->track_get_key_value(track_idx, key_idx), animation->track_get_key_transition(track_idx, key_idx)); - undo_redo->add_undo_method(this, "_select_at_anim", animation, track_idx, time); + undo_redo->add_undo_method(this, "_select_at_anim", animation, track_idx, time, i == 0); + i++; } + i = 0; for (RBMap<AnimationTrackEditor::SelectedKey, AnimationTrackEditor::KeyInfo>::Element *E = keys.back(); E; E = E->prev()) { - undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, E->value().pos); + undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, E->value().pos, i == 0); + i++; } undo_redo->commit_action(); } @@ -1883,11 +1897,15 @@ void AnimationBezierTrackEdit::paste_keys(real_t p_ofs, bool p_ofs_valid) { undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation); // Reselect pasted. + int i = 0; for (const Pair<int, float> &E : new_selection_values) { - undo_redo->add_do_method(this, "_select_at_anim", animation, E.first, E.second); + undo_redo->add_do_method(this, "_select_at_anim", animation, E.first, E.second, i == 0); + i++; } + i = 0; for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { - undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, animation->track_get_key_time(E->get().first, E->get().second)); + undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, animation->track_get_key_time(E->get().first, E->get().second), i == 0); + i++; } undo_redo->commit_action(); @@ -1928,6 +1946,7 @@ void AnimationBezierTrackEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("_bezier_track_insert_key"), &AnimationBezierTrackEdit::_bezier_track_insert_key); ADD_SIGNAL(MethodInfo("select_key", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "single"), PropertyInfo(Variant::INT, "track"))); + ADD_SIGNAL(MethodInfo("deselect_key", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::INT, "track"))); ADD_SIGNAL(MethodInfo("clear_selection")); } diff --git a/editor/animation_bezier_editor.h b/editor/animation_bezier_editor.h index ab667421f3..888dad5341 100644 --- a/editor/animation_bezier_editor.h +++ b/editor/animation_bezier_editor.h @@ -144,7 +144,7 @@ class AnimationBezierTrackEdit : public Control { void _clear_selection(); void _clear_selection_for_anim(const Ref<Animation> &p_anim); - void _select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos); + void _select_at_anim(const Ref<Animation> &p_anim, int p_track, real_t p_pos, bool p_single); bool _try_select_at_ui_pos(const Point2 &p_pos, bool p_aggregate, bool p_deselectable); void _change_selected_keys_handle_mode(Animation::HandleMode p_mode, bool p_auto = false); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index b80a8d77f4..8628fd9e11 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -874,15 +874,15 @@ bool AnimationMultiTrackKeyEdit::_set(const StringName &p_name, const Variant &p undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } Vector2 prev = animation->bezier_track_get_key_out_handle(track, key); - undo_redo->add_do_method(this, "_bezier_track_set_key_out_handle", track, key, value); - undo_redo->add_undo_method(this, "_bezier_track_set_key_out_handle", track, key, prev); + undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", track, key, value); + undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track, key, prev); update_obj = true; } else if (name == "handle_mode") { const Variant &value = p_value; if (!setting) { setting = true; - undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS, animation.ptr()); } int prev_mode = animation->bezier_track_get_key_handle_mode(track, key); Vector2 prev_in_handle = animation->bezier_track_get_key_in_handle(track, key); diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 7e07e626b1..a9d37a6a99 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -347,18 +347,18 @@ void FindReplaceBar::_replace_all() { needs_to_count_results = true; } -void FindReplaceBar::_get_search_from(int &r_line, int &r_col, bool p_is_searching_next) { +void FindReplaceBar::_get_search_from(int &r_line, int &r_col, SearchMode p_search_mode) { if (!text_editor->has_selection(0) || is_selection_only()) { r_line = text_editor->get_caret_line(0); r_col = text_editor->get_caret_column(0); - if (!p_is_searching_next && r_line == result_line && r_col >= result_col && r_col <= result_col + get_search_text().length()) { + if (p_search_mode == SEARCH_PREV && r_line == result_line && r_col >= result_col && r_col <= result_col + get_search_text().length()) { r_col = result_col; } return; } - if (p_is_searching_next) { + if (p_search_mode == SEARCH_NEXT) { r_line = text_editor->get_selection_to_line(); r_col = text_editor->get_selection_to_column(); } else { @@ -368,7 +368,11 @@ void FindReplaceBar::_get_search_from(int &r_line, int &r_col, bool p_is_searchi } void FindReplaceBar::_update_results_count() { - if (!needs_to_count_results && (result_line != -1) && results_count_to_current > 0) { + int caret_line, caret_column; + _get_search_from(caret_line, caret_column, SEARCH_CURRENT); + bool match_selected = caret_line == result_line && caret_column == result_col && !is_selection_only() && text_editor->has_selection(0); + + if (match_selected && !needs_to_count_results && result_line != -1 && results_count_to_current > 0) { results_count_to_current += (flags & TextEdit::SEARCH_BACKWARDS) ? -1 : 1; if (results_count_to_current > results_count) { @@ -385,9 +389,10 @@ void FindReplaceBar::_update_results_count() { return; } - needs_to_count_results = false; + needs_to_count_results = !match_selected; results_count = 0; + results_count_to_current = 0; for (int i = 0; i < text_editor->get_line_count(); i++) { String line_text = text_editor->get_line(i); @@ -417,18 +422,26 @@ void FindReplaceBar::_update_results_count() { results_count++; - if (i == result_line) { - if (col_pos == result_col) { - results_count_to_current = results_count; - } else if (col_pos < result_col && col_pos + searched.length() > result_col) { - col_pos = result_col; - results_count_to_current = results_count; - } + if (i <= result_line && col_pos <= result_col) { + results_count_to_current = results_count; + } + if (i == result_line && col_pos < result_col && col_pos + searched.length() > result_col) { + // Searching forwards and backwards with repeating text can lead to different matches. + col_pos = result_col; } - col_pos += searched.length(); } } + if (!match_selected) { + // Current result should refer to the match before the caret, if the caret is not on a match. + if (caret_line != result_line || caret_column != result_col) { + results_count_to_current -= 1; + } + if (results_count_to_current == 0 && (caret_line > result_line || (caret_line == result_line && caret_column > result_col))) { + // Caret is after all matches. + results_count_to_current = results_count; + } + } } void FindReplaceBar::_update_matches_display() { @@ -457,7 +470,7 @@ bool FindReplaceBar::search_current() { _update_flags(false); int line, col; - _get_search_from(line, col); + _get_search_from(line, col, SEARCH_CURRENT); return _search(flags, line, col); } @@ -473,10 +486,14 @@ bool FindReplaceBar::search_prev() { String text = get_search_text(); + if ((flags & TextEdit::SEARCH_BACKWARDS) == 0) { + needs_to_count_results = true; + } + _update_flags(true); int line, col; - _get_search_from(line, col); + _get_search_from(line, col, SEARCH_PREV); col -= text.length(); if (col < 0) { @@ -499,10 +516,14 @@ bool FindReplaceBar::search_next() { popup_search(true); } + if (flags & TextEdit::SEARCH_BACKWARDS) { + needs_to_count_results = true; + } + _update_flags(false); int line, col; - _get_search_from(line, col, true); + _get_search_from(line, col, SEARCH_NEXT); return _search(flags, line, col); } @@ -653,6 +674,7 @@ void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) { } if (base_text_editor) { + text_editor->set_search_text(String()); base_text_editor->remove_find_replace_bar(); base_text_editor = nullptr; text_editor->disconnect(SceneStringName(text_changed), callable_mp(this, &FindReplaceBar::_editor_text_changed)); @@ -670,8 +692,7 @@ void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) { text_editor = base_text_editor->get_text_editor(); text_editor->connect(SceneStringName(text_changed), callable_mp(this, &FindReplaceBar::_editor_text_changed)); - _update_results_count(); - _update_matches_display(); + _editor_text_changed(); } void FindReplaceBar::_bind_methods() { diff --git a/editor/code_editor.h b/editor/code_editor.h index af33a3fac8..28f6944b66 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -64,6 +64,12 @@ class CodeTextEditor; class FindReplaceBar : public HBoxContainer { GDCLASS(FindReplaceBar, HBoxContainer); + enum SearchMode { + SEARCH_CURRENT, + SEARCH_NEXT, + SEARCH_PREV, + }; + LineEdit *search_text = nullptr; Label *matches_label = nullptr; Button *find_prev = nullptr; @@ -94,7 +100,7 @@ class FindReplaceBar : public HBoxContainer { bool replace_all_mode = false; bool preserve_cursor = false; - void _get_search_from(int &r_line, int &r_col, bool p_is_searching_next = false); + void _get_search_from(int &r_line, int &r_col, SearchMode p_search_mode); void _update_results_count(); void _update_matches_display(); diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 545404ec8e..b62351256e 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -55,11 +55,6 @@ void EditorAutoloadSettings::_notification(int p_what) { file_dialog->add_filter("*." + E); } - for (const AutoloadInfo &info : autoload_cache) { - if (info.node && info.in_editor) { - callable_mp((Node *)get_tree()->get_root(), &Node::add_child).call_deferred(info.node, false, Node::INTERNAL_MODE_DISABLED); - } - } browse_button->set_icon(get_editor_theme_icon(SNAME("Folder"))); } break; @@ -419,6 +414,8 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) { Ref<Script> scr = res; if (scr.is_valid()) { + ERR_FAIL_COND_V_MSG(!scr->is_valid(), nullptr, vformat("Failed to create an autoload, script '%s' is not compiling.", p_path)); + StringName ibt = scr->get_instance_base_type(); bool valid_type = ClassDB::is_parent_class(ibt, "Node"); ERR_FAIL_COND_V_MSG(!valid_type, nullptr, vformat("Failed to create an autoload, script '%s' does not inherit from 'Node'.", p_path)); @@ -436,6 +433,35 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) { return n; } +void EditorAutoloadSettings::init_autoloads() { + for (AutoloadInfo &info : autoload_cache) { + info.node = _create_autoload(info.path); + + if (info.node) { + Ref<Script> scr = info.node->get_script(); + info.in_editor = scr.is_valid() && scr->is_tool(); + info.node->set_name(info.name); + } + + if (info.is_singleton) { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->add_named_global_constant(info.name, info.node); + } + } + + if (!info.is_singleton && !info.in_editor && info.node != nullptr) { + memdelete(info.node); + info.node = nullptr; + } + } + + for (const AutoloadInfo &info : autoload_cache) { + if (info.node && info.in_editor) { + callable_mp((Node *)get_tree()->get_root(), &Node::add_child).call_deferred(info.node, false, Node::INTERNAL_MODE_DISABLED); + } + } +} + void EditorAutoloadSettings::update_autoload() { if (updating_autoload) { return; @@ -857,27 +883,6 @@ EditorAutoloadSettings::EditorAutoloadSettings() { autoload_cache.push_back(info); } - for (AutoloadInfo &info : autoload_cache) { - info.node = _create_autoload(info.path); - - if (info.node) { - Ref<Script> scr = info.node->get_script(); - info.in_editor = scr.is_valid() && scr->is_tool(); - info.node->set_name(info.name); - } - - if (info.is_singleton) { - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->add_named_global_constant(info.name, info.node); - } - } - - if (!info.is_singleton && !info.in_editor && info.node != nullptr) { - memdelete(info.node); - info.node = nullptr; - } - } - HBoxContainer *hbc = memnew(HBoxContainer); add_child(hbc); diff --git a/editor/editor_autoload_settings.h b/editor/editor_autoload_settings.h index e4ac62e700..2ab969eb59 100644 --- a/editor/editor_autoload_settings.h +++ b/editor/editor_autoload_settings.h @@ -104,6 +104,7 @@ protected: static void _bind_methods(); public: + void init_autoloads(); void update_autoload(); bool autoload_add(const String &p_name, const String &p_path); void autoload_remove(const String &p_name); diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index d84ccb0c03..f0dc850af0 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -44,6 +44,7 @@ #include "editor/editor_paths.h" #include "editor/editor_resource_preview.h" #include "editor/editor_settings.h" +#include "editor/project_settings_editor.h" #include "scene/resources/packed_scene.h" EditorFileSystem *EditorFileSystem::singleton = nullptr; @@ -206,17 +207,68 @@ EditorFileSystemDirectory::EditorFileSystemDirectory() { } EditorFileSystemDirectory::~EditorFileSystemDirectory() { - for (int i = 0; i < files.size(); i++) { - memdelete(files[i]); + for (EditorFileSystemDirectory::FileInfo *fi : files) { + memdelete(fi); } - for (int i = 0; i < subdirs.size(); i++) { - memdelete(subdirs[i]); + for (EditorFileSystemDirectory *dir : subdirs) { + memdelete(dir); + } +} + +EditorFileSystem::ScannedDirectory::~ScannedDirectory() { + for (ScannedDirectory *dir : subdirs) { + memdelete(dir); + } +} + +void EditorFileSystem::_first_scan_filesystem() { + Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES); + first_scan_root_dir = memnew(ScannedDirectory); + first_scan_root_dir->full_path = "res://"; + HashSet<String> existing_class_names; + + nb_files_total = _scan_new_dir(first_scan_root_dir, d); + + // This loads the global class names from the scripts and ensures that even if the + // global_script_class_cache.cfg was missing or invalid, the global class names are valid in ScriptServer. + _first_scan_process_scripts(first_scan_root_dir, existing_class_names); + + // Removing invalid global class to prevent having invalid paths in ScriptServer. + _remove_invalid_global_class_names(existing_class_names); + + // Now that all the global class names should be loaded, create autoloads and plugins. + // This is done after loading the global class names because autoloads and plugins can use + // global class names. + ProjectSettingsEditor::get_singleton()->init_autoloads(); + EditorNode::get_singleton()->init_plugins(); +} + +void EditorFileSystem::_first_scan_process_scripts(const ScannedDirectory *p_scan_dir, HashSet<String> &p_existing_class_names) { + for (ScannedDirectory *scan_sub_dir : p_scan_dir->subdirs) { + _first_scan_process_scripts(scan_sub_dir, p_existing_class_names); + } + + for (const String &scan_file : p_scan_dir->files) { + String path = p_scan_dir->full_path.path_join(scan_file); + String type = ResourceLoader::get_resource_type(path); + + if (ClassDB::is_parent_class(type, SNAME("Script"))) { + String script_class_extends; + String script_class_icon_path; + String script_class_name = _get_global_script_class(type, path, &script_class_extends, &script_class_icon_path); + _register_global_class_script(path, path, type, script_class_name, script_class_extends, script_class_icon_path); + + if (!script_class_name.is_empty()) { + p_existing_class_names.insert(script_class_name); + } + } } } void EditorFileSystem::_scan_filesystem() { - ERR_FAIL_COND(!scanning || new_filesystem); + // On the first scan, the first_scan_root_dir is created in _first_scan_filesystem. + ERR_FAIL_COND(!scanning || new_filesystem || (first_scan && !first_scan_root_dir)); //read .fscache String cpath; @@ -318,23 +370,33 @@ void EditorFileSystem::_scan_filesystem() { } EditorProgressBG scan_progress("efs", "ScanFS", 1000); - ScanProgress sp; - sp.low = 0; - sp.hi = 1; + sp.hi = nb_files_total; sp.progress = &scan_progress; new_filesystem = memnew(EditorFileSystemDirectory); new_filesystem->parent = nullptr; - Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES); - d->change_dir("res://"); - _scan_new_dir(new_filesystem, d, sp); - dep_update_list.clear(); + ScannedDirectory *sd; + // On the first scan, the first_scan_root_dir is created in _first_scan_filesystem. + if (first_scan) { + sd = first_scan_root_dir; + } else { + Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES); + sd = memnew(ScannedDirectory); + sd->full_path = "res://"; + nb_files_total = _scan_new_dir(sd, d); + } + + _process_file_system(sd, new_filesystem, sp); + dep_update_list.clear(); file_cache.clear(); //clear caches, no longer needed - if (!first_scan) { + if (first_scan) { + memdelete(first_scan_root_dir); + first_scan_root_dir = nullptr; + } else { //on the first scan this is done from the main thread after re-importing _save_filesystem_cache(); } @@ -567,6 +629,10 @@ bool EditorFileSystem::_scan_import_support(const Vector<String> &reimports) { bool EditorFileSystem::_update_scan_actions() { sources_changed.clear(); + // We need to update the script global class names before the reimports to be sure that + // all the importer classes that depends on class names will work. + _update_script_classes(); + bool fs_changed = false; Vector<String> reimports; @@ -615,7 +681,7 @@ bool EditorFileSystem::_update_scan_actions() { fs_changed = true; if (ClassDB::is_parent_class(ia.new_file->type, SNAME("Script"))) { - _queue_update_script_class(ia.dir->get_file_path(idx)); + _queue_update_script_class(ia.dir->get_file_path(idx), ia.new_file->type, ia.new_file->script_class_name, ia.new_file->script_class_extends, ia.new_file->script_class_icon_path); } if (ia.new_file->type == SNAME("PackedScene")) { _queue_update_scene_groups(ia.dir->get_file_path(idx)); @@ -626,8 +692,9 @@ bool EditorFileSystem::_update_scan_actions() { int idx = ia.dir->find_file_index(ia.file); ERR_CONTINUE(idx == -1); + String script_class_name = ia.dir->files[idx]->script_class_name; if (ClassDB::is_parent_class(ia.dir->files[idx]->type, SNAME("Script"))) { - _queue_update_script_class(ia.dir->get_file_path(idx)); + _queue_update_script_class(ia.dir->get_file_path(idx), "", "", "", ""); } if (ia.dir->files[idx]->type == SNAME("PackedScene")) { _queue_update_scene_groups(ia.dir->get_file_path(idx)); @@ -637,6 +704,15 @@ bool EditorFileSystem::_update_scan_actions() { memdelete(ia.dir->files[idx]); ia.dir->files.remove_at(idx); + // Restore another script with the same global class name if it exists. + if (!script_class_name.is_empty()) { + EditorFileSystemDirectory::FileInfo *old_fi = nullptr; + String old_file = _get_file_by_class_name(filesystem, script_class_name, old_fi); + if (!old_file.is_empty() && old_fi) { + _queue_update_script_class(old_file, old_fi->type, old_fi->script_class_name, old_fi->script_class_extends, old_fi->script_class_icon_path); + } + } + fs_changed = true; } break; @@ -667,10 +743,11 @@ bool EditorFileSystem::_update_scan_actions() { ERR_CONTINUE(idx == -1); String full_path = ia.dir->get_file_path(idx); - if (ClassDB::is_parent_class(ia.dir->files[idx]->type, SNAME("Script"))) { - _queue_update_script_class(full_path); + const EditorFileSystemDirectory::FileInfo *fi = ia.dir->files[idx]; + if (ClassDB::is_parent_class(fi->type, SNAME("Script"))) { + _queue_update_script_class(full_path, fi->type, fi->script_class_name, fi->script_class_extends, fi->script_class_icon_path); } - if (ia.dir->files[idx]->type == SNAME("PackedScene")) { + if (fi->type == SNAME("PackedScene")) { _queue_update_scene_groups(full_path); } @@ -711,6 +788,10 @@ bool EditorFileSystem::_update_scan_actions() { _save_filesystem_cache(); } + // Moving the processing of pending updates before the resources_reload event to be sure all global class names + // are updated. Script.cpp listens on resources_reload and reloads updated scripts. + _process_update_pending(); + if (reloads.size()) { emit_signal(SNAME("resources_reload"), reloads); } @@ -728,6 +809,14 @@ void EditorFileSystem::scan() { return; } + // The first scan must be on the main thread because, after the first scan and update + // of global class names, we load the plugins and autoloads. These need to + // be added on the main thread because they are nodes, and we need to wait for them + // to be loaded to continue the scan and reimportations. + if (first_scan) { + _first_scan_filesystem(); + } + _update_extensions(); if (!use_threads) { @@ -741,14 +830,14 @@ void EditorFileSystem::scan() { filesystem = new_filesystem; new_filesystem = nullptr; _update_scan_actions(); - scanning = false; - _update_pending_script_classes(); - _update_pending_scene_groups(); // Update all icons so they are loaded for the FileSystemDock. _update_files_icon_path(); + scanning = false; + // Set first_scan to false before the signals so the function doing_first_scan can return false + // in editor_node to start the export if needed. + first_scan = false; emit_signal(SNAME("filesystem_changed")); emit_signal(SNAME("sources_changed"), sources_changed.size() > 0); - first_scan = false; } else { ERR_FAIL_COND(thread.is_started()); set_process(true); @@ -762,28 +851,19 @@ void EditorFileSystem::scan() { } } -void EditorFileSystem::ScanProgress::update(int p_current, int p_total) const { - float ratio = low + ((hi - low) / p_total) * p_current; - progress->step(ratio * 1000); +void EditorFileSystem::ScanProgress::increment() { + current++; + float ratio = current / MAX(hi, 1.0f); + progress->step(ratio * 1000.0f); EditorFileSystem::singleton->scan_total = ratio; } -EditorFileSystem::ScanProgress EditorFileSystem::ScanProgress::get_sub(int p_current, int p_total) const { - ScanProgress sp = *this; - float slice = (sp.hi - sp.low) / p_total; - sp.low += slice * p_current; - sp.hi = slice; - return sp; -} - -void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAccess> &da, const ScanProgress &p_progress) { +int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref<DirAccess> &da) { List<String> dirs; List<String> files; String cd = da->get_current_dir(); - p_dir->modified_time = FileAccess::get_modified_time(cd); - da->list_dir_begin(); while (true) { String f = da->get_next(); @@ -816,55 +896,59 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc dirs.sort_custom<FileNoCaseComparator>(); files.sort_custom<FileNoCaseComparator>(); - int total = dirs.size() + files.size(); - int idx = 0; + int nb_files_total_scan = 0; - for (List<String>::Element *E = dirs.front(); E; E = E->next(), idx++) { + for (List<String>::Element *E = dirs.front(); E; E = E->next()) { if (da->change_dir(E->get()) == OK) { String d = da->get_current_dir(); if (d == cd || !d.begins_with(cd)) { da->change_dir(cd); //avoid recursion } else { - EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory); + ScannedDirectory *sd = memnew(ScannedDirectory); + sd->name = E->get(); + sd->full_path = p_dir->full_path.path_join(sd->name); - efd->parent = p_dir; - efd->name = E->get(); + nb_files_total_scan += _scan_new_dir(sd, da); - _scan_new_dir(efd, da, p_progress.get_sub(idx, total)); - - int idx2 = 0; - for (int i = 0; i < p_dir->subdirs.size(); i++) { - if (efd->name.filenocasecmp_to(p_dir->subdirs[i]->name) < 0) { - break; - } - idx2++; - } - if (idx2 == p_dir->subdirs.size()) { - p_dir->subdirs.push_back(efd); - } else { - p_dir->subdirs.insert(idx2, efd); - } + p_dir->subdirs.push_back(sd); da->change_dir(".."); } } else { ERR_PRINT("Cannot go into subdir '" + E->get() + "'."); } + } - p_progress.update(idx, total); + p_dir->files = files; + nb_files_total_scan += files.size(); + + return nb_files_total_scan; +} + +void EditorFileSystem::_process_file_system(const ScannedDirectory *p_scan_dir, EditorFileSystemDirectory *p_dir, ScanProgress &p_progress) { + p_dir->modified_time = FileAccess::get_modified_time(p_scan_dir->full_path); + + for (ScannedDirectory *scan_sub_dir : p_scan_dir->subdirs) { + EditorFileSystemDirectory *sub_dir = memnew(EditorFileSystemDirectory); + sub_dir->parent = p_dir; + sub_dir->name = scan_sub_dir->name; + p_dir->subdirs.push_back(sub_dir); + _process_file_system(scan_sub_dir, sub_dir, p_progress); } - for (List<String>::Element *E = files.front(); E; E = E->next(), idx++) { - String ext = E->get().get_extension().to_lower(); + for (const String &scan_file : p_scan_dir->files) { + String ext = scan_file.get_extension().to_lower(); if (!valid_extensions.has(ext)) { + p_progress.increment(); continue; //invalid } - EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo); - fi->file = E->get(); + String path = p_scan_dir->full_path.path_join(scan_file); - String path = cd.path_join(fi->file); + EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo); + fi->file = scan_file; + p_dir->files.push_back(fi); FileCache *fc = file_cache.getptr(path); uint64_t mt = FileAccess::get_modified_time(path); @@ -894,7 +978,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc ItemAction ia; ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT; ia.dir = p_dir; - ia.file = E->get(); + ia.file = fi->file; scan_actions.push_back(ia); } @@ -923,7 +1007,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc ItemAction ia; ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT; ia.dir = p_dir; - ia.file = E->get(); + ia.file = fi->file; scan_actions.push_back(ia); } } else { @@ -939,6 +1023,21 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc fi->script_class_name = fc->script_class_name; fi->script_class_extends = fc->script_class_extends; fi->script_class_icon_path = fc->script_class_icon_path; + + if (first_scan && ClassDB::is_parent_class(fi->type, SNAME("Script"))) { + bool update_script = false; + String old_class_name = fi->script_class_name; + fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path); + if (old_class_name != fi->script_class_name) { + update_script = true; + } else if (!fi->script_class_name.is_empty() && (!ScriptServer::is_global_class(fi->script_class_name) || ScriptServer::get_global_class_path(fi->script_class_name) != path)) { + // This script has a class name but is not in the global class names or the path of the class has changed. + update_script = true; + } + if (update_script) { + _queue_update_script_class(path, fi->type, fi->script_class_name, fi->script_class_extends, fi->script_class_icon_path); + } + } } else { //new or modified time fi->type = ResourceLoader::get_resource_type(path); @@ -956,7 +1055,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc // Files in dep_update_list are forced for rescan to update dependencies. They don't need other updates. if (!dep_update_list.has(path)) { if (ClassDB::is_parent_class(fi->type, SNAME("Script"))) { - _queue_update_script_class(path); + _queue_update_script_class(path, fi->type, fi->script_class_name, fi->script_class_extends, fi->script_class_icon_path); } if (fi->type == SNAME("PackedScene")) { _queue_update_scene_groups(path); @@ -973,16 +1072,16 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc } } - p_dir->files.push_back(fi); - p_progress.update(idx, total); + p_progress.increment(); } } -void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress) { +void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, ScanProgress &p_progress) { uint64_t current_mtime = FileAccess::get_modified_time(p_dir->get_path()); bool updated_dir = false; String cd = p_dir->get_path(); + int diff_nb_files = 0; if (current_mtime != p_dir->modified_time || using_fat32_or_exfat) { updated_dir = true; @@ -999,6 +1098,8 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const p_dir->get_subdir(i)->verified = false; } + diff_nb_files -= p_dir->files.size(); + //then scan files and directories and check what's different Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES); @@ -1024,17 +1125,25 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const int idx = p_dir->find_dir_index(f); if (idx == -1) { - if (_should_skip_directory(cd.path_join(f))) { + String dir_path = cd.path_join(f); + if (_should_skip_directory(dir_path)) { continue; } - EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory); + ScannedDirectory sd; + sd.name = f; + sd.full_path = dir_path; + EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory); efd->parent = p_dir; efd->name = f; + Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES); - d->change_dir(cd.path_join(f)); - _scan_new_dir(efd, d, p_progress.get_sub(1, 1)); + d->change_dir(dir_path); + int nb_files_dir = _scan_new_dir(&sd, d); + p_progress.hi += nb_files_dir; + diff_nb_files += nb_files_dir; + _process_file_system(&sd, efd, p_progress); ItemAction ia; ia.action = ItemAction::ACTION_DIR_ADD; @@ -1088,7 +1197,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const ia.file = f; scan_actions.push_back(ia); } - + diff_nb_files++; } else { p_dir->files[idx]->verified = true; } @@ -1106,6 +1215,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const ia.dir = p_dir; ia.file = p_dir->files[i]->file; scan_actions.push_back(ia); + diff_nb_files--; continue; } @@ -1152,10 +1262,16 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const scan_actions.push_back(ia); } } + + p_progress.increment(); } for (int i = 0; i < p_dir->subdirs.size(); i++) { if ((updated_dir && !p_dir->subdirs[i]->verified) || _should_skip_directory(p_dir->subdirs[i]->get_path())) { + // Add all the files of the folder to be sure _update_scan_actions process the removed files + // for global class names. + diff_nb_files += _insert_actions_delete_files_directory(p_dir->subdirs[i]); + //this directory was removed or ignored, add action to remove it ItemAction ia; ia.action = ItemAction::ACTION_DIR_REMOVE; @@ -1165,6 +1281,8 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const } _scan_fs_changes(p_dir->get_subdir(i), p_progress); } + + nb_files_total = MAX(nb_files_total + diff_nb_files, 0); } void EditorFileSystem::_delete_internal_files(const String &p_file) { @@ -1179,19 +1297,64 @@ void EditorFileSystem::_delete_internal_files(const String &p_file) { } } +int EditorFileSystem::_insert_actions_delete_files_directory(EditorFileSystemDirectory *p_dir) { + int nb_files = 0; + for (EditorFileSystemDirectory::FileInfo *fi : p_dir->files) { + ItemAction ia; + ia.action = ItemAction::ACTION_FILE_REMOVE; + ia.dir = p_dir; + ia.file = fi->file; + scan_actions.push_back(ia); + nb_files++; + } + + for (EditorFileSystemDirectory *sub_dir : p_dir->subdirs) { + nb_files += _insert_actions_delete_files_directory(sub_dir); + } + + return nb_files; +} + void EditorFileSystem::_thread_func_sources(void *_userdata) { EditorFileSystem *efs = (EditorFileSystem *)_userdata; if (efs->filesystem) { EditorProgressBG pr("sources", TTR("ScanSources"), 1000); ScanProgress sp; sp.progress = ≺ - sp.hi = 1; - sp.low = 0; + sp.hi = efs->nb_files_total; efs->_scan_fs_changes(efs->filesystem, sp); } efs->scanning_changes_done.set(); } +void EditorFileSystem::_remove_invalid_global_class_names(const HashSet<String> &p_existing_class_names) { + List<StringName> global_classes; + ScriptServer::get_global_class_list(&global_classes); + for (const StringName &class_name : global_classes) { + if (!p_existing_class_names.has(class_name)) { + ScriptServer::remove_global_class(class_name); + } + } +} + +String EditorFileSystem::_get_file_by_class_name(EditorFileSystemDirectory *p_dir, const String &p_class_name, EditorFileSystemDirectory::FileInfo *&r_file_info) { + for (EditorFileSystemDirectory::FileInfo *fi : p_dir->files) { + if (fi->script_class_name == p_class_name) { + r_file_info = fi; + return p_dir->get_path().path_join(fi->file); + } + } + + for (EditorFileSystemDirectory *sub_dir : p_dir->subdirs) { + String file = _get_file_by_class_name(sub_dir, p_class_name, r_file_info); + if (!file.is_empty()) { + return file; + } + } + r_file_info = nullptr; + return ""; +} + void EditorFileSystem::scan_changes() { if (first_scan || // Prevent a premature changes scan from inhibiting the first full scan scanning || scanning_changes || thread.is_started()) { @@ -1210,14 +1373,10 @@ void EditorFileSystem::scan_changes() { EditorProgressBG pr("sources", TTR("ScanSources"), 1000); ScanProgress sp; sp.progress = ≺ - sp.hi = 1; - sp.low = 0; + sp.hi = nb_files_total; scan_total = 0; _scan_fs_changes(filesystem, sp); - bool changed = _update_scan_actions(); - _update_pending_script_classes(); - _update_pending_scene_groups(); - if (changed) { + if (_update_scan_actions()) { emit_signal(SNAME("filesystem_changed")); } } @@ -1282,13 +1441,13 @@ void EditorFileSystem::_notification(int p_what) { thread_sources.wait_to_finish(); } bool changed = _update_scan_actions(); - _update_pending_script_classes(); - _update_pending_scene_groups(); + // Set first_scan to false before the signals so the function doing_first_scan can return false + // in editor_node to start the export if needed. + first_scan = false; if (changed) { emit_signal(SNAME("filesystem_changed")); } emit_signal(SNAME("sources_changed"), sources_changed.size() > 0); - first_scan = false; scanning_changes = false; // Changed to false here to prevent recursive triggering of scan thread. done_importing = true; } @@ -1302,13 +1461,13 @@ void EditorFileSystem::_notification(int p_what) { new_filesystem = nullptr; thread.wait_to_finish(); _update_scan_actions(); - _update_pending_script_classes(); - _update_pending_scene_groups(); // Update all icons so they are loaded for the FileSystemDock. _update_files_icon_path(); + // Set first_scan to false before the signals so the function doing_first_scan can return false + // in editor_node to start the export if needed. + first_scan = false; emit_signal(SNAME("filesystem_changed")); emit_signal(SNAME("sources_changed"), sources_changed.size() > 0); - first_scan = false; } if (done_importing && scan_changes_pending) { @@ -1323,7 +1482,7 @@ void EditorFileSystem::_notification(int p_what) { } bool EditorFileSystem::is_scanning() const { - return scanning || scanning_changes; + return scanning || scanning_changes || first_scan; } float EditorFileSystem::get_scanning_progress() const { @@ -1624,14 +1783,41 @@ void EditorFileSystem::_update_files_icon_path(EditorFileSystemDirectory *edp) { } void EditorFileSystem::_update_script_classes() { + if (update_script_paths.is_empty()) { + return; + } + update_script_mutex.lock(); - for (const String &path : update_script_paths) { - EditorFileSystem::get_singleton()->register_global_class_script(path, path); + for (const KeyValue<String, ScriptInfo> &E : update_script_paths) { + _register_global_class_script(E.key, E.key, E.value.type, E.value.script_class_name, E.value.script_class_extends, E.value.script_class_icon_path); } - // Parse documentation second, as it requires the class names to be correct and registered - for (const String &path : update_script_paths) { + update_script_paths.clear(); + update_script_mutex.unlock(); + + ScriptServer::save_global_classes(); + EditorNode::get_editor_data().script_class_save_icon_paths(); + + emit_signal("script_classes_updated"); + + // Rescan custom loaders and savers. + // Doing the following here because the `filesystem_changed` signal fires multiple times and isn't always followed by script classes update. + // So I thought it's better to do this when script classes really get updated + ResourceLoader::remove_custom_loaders(); + ResourceLoader::add_custom_loaders(); + ResourceSaver::remove_custom_savers(); + ResourceSaver::add_custom_savers(); +} + +void EditorFileSystem::_update_script_documentation() { + if (update_script_paths_documentation.is_empty()) { + return; + } + + update_script_mutex.lock(); + + for (const String &path : update_script_paths_documentation) { int index = -1; EditorFileSystemDirectory *efd = find_file(path, &index); @@ -1655,40 +1841,38 @@ void EditorFileSystem::_update_script_classes() { } } - update_script_paths.clear(); + update_script_paths_documentation.clear(); update_script_mutex.unlock(); - - ScriptServer::save_global_classes(); - EditorNode::get_editor_data().script_class_save_icon_paths(); - emit_signal("script_classes_updated"); - - // Rescan custom loaders and savers. - // Doing the following here because the `filesystem_changed` signal fires multiple times and isn't always followed by script classes update. - // So I thought it's better to do this when script classes really get updated - ResourceLoader::remove_custom_loaders(); - ResourceLoader::add_custom_loaders(); - ResourceSaver::remove_custom_savers(); - ResourceSaver::add_custom_savers(); } -void EditorFileSystem::_update_pending_script_classes() { - if (!update_script_paths.is_empty()) { - _update_script_classes(); - } else { - // In case the class cache file was removed somehow, regenerate it. - if (!FileAccess::exists(ScriptServer::get_global_class_cache_file_path())) { - ScriptServer::save_global_classes(); - } - } +void EditorFileSystem::_process_update_pending() { + _update_script_classes(); + // Parse documentation second, as it requires the class names to be loaded + // because _update_script_documentation loads the scripts completely. + _update_script_documentation(); + _update_pending_scene_groups(); } -void EditorFileSystem::_queue_update_script_class(const String &p_path) { +void EditorFileSystem::_queue_update_script_class(const String &p_path, const String &p_type, const String &p_script_class_name, const String &p_script_class_extends, const String &p_script_class_icon_path) { update_script_mutex.lock(); - update_script_paths.insert(p_path); + + ScriptInfo si; + si.type = p_type; + si.script_class_name = p_script_class_name; + si.script_class_extends = p_script_class_extends; + si.script_class_icon_path = p_script_class_icon_path; + update_script_paths.insert(p_path, si); + + update_script_paths_documentation.insert(p_path); + update_script_mutex.unlock(); } void EditorFileSystem::_update_scene_groups() { + if (update_scene_paths.is_empty()) { + return; + } + EditorProgress *ep = nullptr; if (update_scene_paths.size() > 1) { ep = memnew(EditorProgress("update_scene_groups", TTR("Update Scene Groups"), update_scene_paths.size())); @@ -1787,7 +1971,7 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) { } } if (ClassDB::is_parent_class(fs->files[cpos]->type, SNAME("Script"))) { - _queue_update_script_class(file); + _queue_update_script_class(file, fs->files[cpos]->type, "", "", ""); if (!fs->files[cpos]->script_class_icon_path.is_empty()) { update_files_icon_cache = true; } @@ -1840,6 +2024,7 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) { } const String old_script_class_icon_path = fs->files[cpos]->script_class_icon_path; + const String old_class_name = fs->files[cpos]->script_class_name; fs->files[cpos]->type = type; fs->files[cpos]->resource_script_class = script_class; fs->files[cpos]->uid = uid; @@ -1862,23 +2047,32 @@ void EditorFileSystem::update_files(const Vector<String> &p_script_paths) { EditorResourcePreview::get_singleton()->check_for_invalidation(file); if (ClassDB::is_parent_class(fs->files[cpos]->type, SNAME("Script"))) { - _queue_update_script_class(file); + _queue_update_script_class(file, fs->files[cpos]->type, fs->files[cpos]->script_class_name, fs->files[cpos]->script_class_extends, fs->files[cpos]->script_class_icon_path); } if (fs->files[cpos]->type == SNAME("PackedScene")) { _queue_update_scene_groups(file); } + if (fs->files[cpos]->type == SNAME("Resource")) { files_to_update_icon_path.push_back(fs->files[cpos]); } else if (old_script_class_icon_path != fs->files[cpos]->script_class_icon_path) { update_files_icon_cache = true; } + + // Restore another script as the global class name if multiple scripts had the same old class name. + if (!old_class_name.is_empty() && fs->files[cpos]->script_class_name != old_class_name && ClassDB::is_parent_class(type, SNAME("Script"))) { + EditorFileSystemDirectory::FileInfo *old_fi = nullptr; + String old_file = _get_file_by_class_name(filesystem, old_class_name, old_fi); + if (!old_file.is_empty() && old_fi) { + _queue_update_script_class(old_file, old_fi->type, old_fi->script_class_name, old_fi->script_class_extends, old_fi->script_class_icon_path); + } + } updated = true; } } if (updated) { - _update_pending_script_classes(); - _update_pending_scene_groups(); + _process_update_pending(); if (update_files_icon_cache) { _update_files_icon_path(); } else { @@ -1894,31 +2088,37 @@ HashSet<String> EditorFileSystem::get_valid_extensions() const { return valid_extensions; } -void EditorFileSystem::register_global_class_script(const String &p_search_path, const String &p_target_path) { +void EditorFileSystem::_register_global_class_script(const String &p_search_path, const String &p_target_path, const String &p_type, const String &p_script_class_name, const String &p_script_class_extends, const String &p_script_class_icon_path) { ScriptServer::remove_global_class_by_path(p_search_path); // First remove, just in case it changed - int index = -1; - EditorFileSystemDirectory *efd = find_file(p_search_path, &index); - - if (!efd || index < 0) { - // The file was removed + if (p_script_class_name.is_empty()) { return; } - if (!efd->files[index]->script_class_name.is_empty()) { - String lang; - for (int j = 0; j < ScriptServer::get_language_count(); j++) { - if (ScriptServer::get_language(j)->handles_global_class_type(efd->files[index]->type)) { - lang = ScriptServer::get_language(j)->get_name(); - } - } - if (lang.is_empty()) { - return; // No lang found that can handle this global class + String lang; + for (int j = 0; j < ScriptServer::get_language_count(); j++) { + if (ScriptServer::get_language(j)->handles_global_class_type(p_type)) { + lang = ScriptServer::get_language(j)->get_name(); + break; } + } + if (lang.is_empty()) { + return; // No lang found that can handle this global class + } - ScriptServer::add_global_class(efd->files[index]->script_class_name, efd->files[index]->script_class_extends, lang, p_target_path); - EditorNode::get_editor_data().script_class_set_icon_path(efd->files[index]->script_class_name, efd->files[index]->script_class_icon_path); - EditorNode::get_editor_data().script_class_set_name(p_target_path, efd->files[index]->script_class_name); + ScriptServer::add_global_class(p_script_class_name, p_script_class_extends, lang, p_target_path); + EditorNode::get_editor_data().script_class_set_icon_path(p_script_class_name, p_script_class_icon_path); + EditorNode::get_editor_data().script_class_set_name(p_target_path, p_script_class_name); +} + +void EditorFileSystem::register_global_class_script(const String &p_search_path, const String &p_target_path) { + int index_file; + EditorFileSystemDirectory *efsd = find_file(p_search_path, &index_file); + if (efsd) { + const EditorFileSystemDirectory::FileInfo *fi = efsd->files[index_file]; + EditorFileSystem::get_singleton()->_register_global_class_script(p_search_path, p_target_path, fi->type, fi->script_class_name, fi->script_class_extends, fi->script_class_icon_path); + } else { + ScriptServer::remove_global_class_by_path(p_search_path); } } @@ -2542,8 +2742,7 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) { ResourceUID::get_singleton()->update_cache(); // After reimporting, update the cache. _save_filesystem_cache(); - _update_pending_script_classes(); - _update_pending_scene_groups(); + _process_update_pending(); importing = false; if (!is_scanning()) { emit_signal(SNAME("filesystem_changed")); diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index 88cd67296b..b0c6f0de51 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -159,11 +159,21 @@ class EditorFileSystem : public Node { EditorFileSystemDirectory::FileInfo *new_file = nullptr; }; + struct ScannedDirectory { + String name; + String full_path; + Vector<ScannedDirectory *> subdirs; + List<String> files; + + ~ScannedDirectory(); + }; + bool use_threads = false; Thread thread; static void _thread_func(void *_userdata); EditorFileSystemDirectory *new_filesystem = nullptr; + ScannedDirectory *first_scan_root_dir = nullptr; bool scanning = false; bool importing = false; @@ -172,8 +182,11 @@ class EditorFileSystem : public Node { float scan_total; String filesystem_settings_version_for_import; bool revalidate_import_files = false; + int nb_files_total = 0; void _scan_filesystem(); + void _first_scan_filesystem(); + void _first_scan_process_scripts(const ScannedDirectory *p_scan_dir, HashSet<String> &p_existing_class_names); HashSet<String> late_update_files; @@ -202,11 +215,10 @@ class EditorFileSystem : public Node { HashSet<String> dep_update_list; struct ScanProgress { - float low = 0; float hi = 0; - mutable EditorProgressBG *progress = nullptr; - void update(int p_current, int p_total) const; - ScanProgress get_sub(int p_current, int p_total) const; + int current = 0; + EditorProgressBG *progress = nullptr; + void increment(); }; void _save_filesystem_cache(); @@ -214,15 +226,17 @@ class EditorFileSystem : public Node { bool _find_file(const String &p_file, EditorFileSystemDirectory **r_d, int &r_file_pos) const; - void _scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress); + void _scan_fs_changes(EditorFileSystemDirectory *p_dir, ScanProgress &p_progress); void _delete_internal_files(const String &p_file); + int _insert_actions_delete_files_directory(EditorFileSystemDirectory *p_dir); HashSet<String> textfile_extensions; HashSet<String> valid_extensions; HashSet<String> import_extensions; - void _scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAccess> &da, const ScanProgress &p_progress); + int _scan_new_dir(ScannedDirectory *p_dir, Ref<DirAccess> &da); + void _process_file_system(const ScannedDirectory *p_scan_dir, EditorFileSystemDirectory *p_dir, ScanProgress &p_progress); Thread thread_sources; bool scanning_changes = false; @@ -256,11 +270,20 @@ class EditorFileSystem : public Node { } }; + struct ScriptInfo { + String type; + String script_class_name; + String script_class_extends; + String script_class_icon_path; + }; + Mutex update_script_mutex; - HashSet<String> update_script_paths; - void _queue_update_script_class(const String &p_path); + HashMap<String, ScriptInfo> update_script_paths; + HashSet<String> update_script_paths_documentation; + void _queue_update_script_class(const String &p_path, const String &p_type, const String &p_script_class_name, const String &p_script_class_extends, const String &p_script_class_icon_path); void _update_script_classes(); - void _update_pending_script_classes(); + void _update_script_documentation(); + void _process_update_pending(); Mutex update_scene_mutex; HashSet<String> update_scene_paths; @@ -300,6 +323,10 @@ class EditorFileSystem : public Node { void _update_file_icon_path(EditorFileSystemDirectory::FileInfo *file_info); void _update_files_icon_path(EditorFileSystemDirectory *edp = nullptr); + void _remove_invalid_global_class_names(const HashSet<String> &p_existing_class_names); + String _get_file_by_class_name(EditorFileSystemDirectory *p_dir, const String &p_class_name, EditorFileSystemDirectory::FileInfo *&r_file_info); + + void _register_global_class_script(const String &p_search_path, const String &p_target_path, const String &p_type, const String &p_script_class_name, const String &p_script_class_extends, const String &p_script_class_icon_path); protected: void _notification(int p_what); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index ae7066fea9..4323025770 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -706,23 +706,7 @@ void EditorNode::_notification(int p_what) { } break; case NOTIFICATION_READY: { - { - started_timestamp = Time::get_singleton()->get_unix_time_from_system(); - _initializing_plugins = true; - Vector<String> addons; - if (ProjectSettings::get_singleton()->has_setting("editor_plugins/enabled")) { - addons = GLOBAL_GET("editor_plugins/enabled"); - } - - for (int i = 0; i < addons.size(); i++) { - set_addon_plugin_enabled(addons[i], true); - } - _initializing_plugins = false; - - if (!pending_addons.is_empty()) { - EditorFileSystem::get_singleton()->connect("script_classes_updated", callable_mp(this, &EditorNode::_enable_pending_addons)); - } - } + started_timestamp = Time::get_singleton()->get_unix_time_from_system(); RenderingServer::get_singleton()->viewport_set_disable_2d(get_scene_root()->get_viewport_rid(), true); RenderingServer::get_singleton()->viewport_set_environment_mode(get_viewport()->get_viewport_rid(), RenderingServer::VIEWPORT_ENVIRONMENT_DISABLED); @@ -860,6 +844,23 @@ void EditorNode::_update_update_spinner() { OS::get_singleton()->set_low_processor_usage_mode(!update_continuously); } +void EditorNode::init_plugins() { + _initializing_plugins = true; + Vector<String> addons; + if (ProjectSettings::get_singleton()->has_setting("editor_plugins/enabled")) { + addons = GLOBAL_GET("editor_plugins/enabled"); + } + + for (const String &addon : addons) { + set_addon_plugin_enabled(addon, true); + } + _initializing_plugins = false; + + if (!pending_addons.is_empty()) { + EditorFileSystem::get_singleton()->connect("script_classes_updated", callable_mp(this, &EditorNode::_enable_pending_addons), CONNECT_ONE_SHOT); + } +} + void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_name) { Ref<Script> scr = Object::cast_to<Script>(p_script); if (scr.is_null()) { @@ -954,6 +955,7 @@ void EditorNode::_fs_changed() { // FIXME: Move this to a cleaner location, it's hacky to do this in _fs_changed. String export_error; Error err = OK; + // It's important to wait for the first scan to finish; otherwise, scripts or resources might not be imported. if (!export_defer.preset.is_empty() && !EditorFileSystem::get_singleton()->is_scanning()) { String preset_name = export_defer.preset; // Ensures export_project does not loop infinitely, because notifications may diff --git a/editor/editor_node.h b/editor/editor_node.h index 49674dd1c1..28bd692ddf 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -683,6 +683,7 @@ protected: public: // Public for use with callable_mp. + void init_plugins(); void _on_plugin_ready(Object *p_script, const String &p_activate_name); void editor_select(int p_which); diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index a895219e6f..4cd44e3020 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -1065,7 +1065,7 @@ EditorResourcePicker::EditorResourcePicker(bool p_hide_assign_button_controls) { } edit_button = memnew(Button); - edit_button->set_flat(true); + edit_button->set_flat(false); edit_button->set_toggle_mode(true); edit_button->connect(SceneStringName(pressed), callable_mp(this, &EditorResourcePicker::_update_menu)); add_child(edit_button); @@ -1268,8 +1268,6 @@ void EditorAudioStreamPicker::_preview_draw() { if (audio_stream->get_length() > 0 && size.width > 0) { rect.size.height *= 0.5; - stream_preview_rect->draw_rect(rect, Color(0, 0, 0, 1)); - Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(audio_stream); float preview_len = preview->get_length(); @@ -1325,8 +1323,8 @@ void EditorAudioStreamPicker::_preview_draw() { text = audio_stream->get_class().replace_first("AudioStream", ""); } - stream_preview_rect->draw_texture(icon, Point2i(EDSCALE * 2, rect.position.y + (rect.size.height - icon->get_height()) / 2), icon_modulate); - stream_preview_rect->draw_string(font, Point2i(EDSCALE * 2 + icon->get_width(), rect.position.y + font->get_ascent(font_size) + (rect.size.height - font->get_height(font_size)) / 2), text, HORIZONTAL_ALIGNMENT_CENTER, size.width - 4 * EDSCALE - icon->get_width()); + stream_preview_rect->draw_texture(icon, Point2i(EDSCALE * 4, rect.position.y + (rect.size.height - icon->get_height()) / 2), icon_modulate); + stream_preview_rect->draw_string(font, Point2i(EDSCALE * 4 + icon->get_width(), rect.position.y + font->get_ascent(font_size) + (rect.size.height - font->get_height(font_size)) / 2), text, HORIZONTAL_ALIGNMENT_CENTER, size.width - 4 * EDSCALE - icon->get_width(), font_size, get_theme_color(SNAME("font_color"), EditorStringName(Editor))); } EditorAudioStreamPicker::EditorAudioStreamPicker() : diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 29ca1279b2..d4bd97a393 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -546,7 +546,7 @@ void FileSystemDock::_notification(int p_what) { case NOTIFICATION_PROCESS: { if (EditorFileSystem::get_singleton()->is_scanning()) { - scanning_progress->set_value(EditorFileSystem::get_singleton()->get_scanning_progress() * 100); + scanning_progress->set_value(EditorFileSystem::get_singleton()->get_scanning_progress() * 100.0f); } } break; diff --git a/editor/icons/AudioStreamPlayer.svg b/editor/icons/AudioStreamPlayer.svg index 98a1650f6f..a3c4ad8e35 100644 --- a/editor/icons/AudioStreamPlayer.svg +++ b/editor/icons/AudioStreamPlayer.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16" version="1.0" viewBox="0 0 2.4 2.4"><path fill="#e0e0e0" stroke="#e0e0e0" stroke-linejoin="round" stroke-width=".176" d="M1.382.335.777.858H.204v.673h.564l.614.531Z"/><path fill="none" stroke="#e0e0e0" stroke-linecap="round" stroke-width=".176" d="M1.718.572c.275.374.275.882 0 1.256M1.947.343c.402.5.402 1.213 0 1.714"/></svg>
\ No newline at end of file +<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16" version="1.0" viewBox="0 0 2.4 2.4"><path fill="#e0e0e0" stroke="#e0e0e0" stroke-linejoin="round" stroke-width=".176" d="M1.382.335.777.858H.204v.673h.564l.614.531Z"/><path fill="none" stroke="#e0e0e0" stroke-linecap="round" stroke-width=".176" d="M1.718.572a1.06 1.06 0 0 1 0 1.256M1.947.343c.402.5.402 1.213 0 1.714"/></svg>
\ No newline at end of file diff --git a/editor/icons/AudioStreamPlayer2D.svg b/editor/icons/AudioStreamPlayer2D.svg index 3a5c5c29af..fa60e30238 100644 --- a/editor/icons/AudioStreamPlayer2D.svg +++ b/editor/icons/AudioStreamPlayer2D.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16" version="1.0" viewBox="0 0 2.4 2.4"><path fill="#8da5f3" stroke="#8da5f3" stroke-linejoin="round" stroke-width=".176" d="M1.382.335.777.858H.204v.673h.564l.614.531Z"/><path fill="none" stroke="#8da5f3" stroke-linecap="round" stroke-width=".176" d="M1.718.572c.275.374.275.882 0 1.256M1.947.343c.402.5.402 1.213 0 1.714"/></svg>
\ No newline at end of file +<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16" version="1.0" viewBox="0 0 2.4 2.4"><path fill="#8da5f3" stroke="#8da5f3" stroke-linejoin="round" stroke-width=".176" d="M1.382.335.777.858H.204v.673h.564l.614.531Z"/><path fill="none" stroke="#8da5f3" stroke-linecap="round" stroke-width=".176" d="M1.718.572a1.06 1.06 0 0 1 0 1.256M1.947.343c.402.5.402 1.213 0 1.714"/></svg>
\ No newline at end of file diff --git a/editor/icons/AudioStreamPlayer3D.svg b/editor/icons/AudioStreamPlayer3D.svg index c0480d0c7d..f6be929e61 100644 --- a/editor/icons/AudioStreamPlayer3D.svg +++ b/editor/icons/AudioStreamPlayer3D.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16" version="1.0" viewBox="0 0 2.4 2.4"><path fill="#fc7f7f" stroke="#fc7f7f" stroke-linejoin="round" stroke-width=".176" d="M1.382.335.777.858H.204v.673h.564l.614.531Z"/><path fill="none" stroke="#fc7f7f" stroke-linecap="round" stroke-width=".176" d="M1.718.572c.275.374.275.882 0 1.256M1.947.343c.402.5.402 1.213 0 1.714"/></svg>
\ No newline at end of file +<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16" version="1.0" viewBox="0 0 2.4 2.4"><path fill="#fc7f7f" stroke="#fc7f7f" stroke-linejoin="round" stroke-width=".176" d="M1.382.335.777.858H.204v.673h.564l.614.531Z"/><path fill="none" stroke="#fc7f7f" stroke-linecap="round" stroke-width=".176" d="M1.718.572a1.06 1.06 0 0 1 0 1.256M1.947.343c.402.5.402 1.213 0 1.714"/></svg>
\ No newline at end of file diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp index 55a7208169..2db3fb1f07 100644 --- a/editor/import/3d/resource_importer_scene.cpp +++ b/editor/import/3d/resource_importer_scene.cpp @@ -1959,7 +1959,7 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "generate/physics", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/navmesh", PROPERTY_HINT_ENUM, "Disabled,Mesh + NavMesh,NavMesh Only"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/body_type", PROPERTY_HINT_ENUM, "Static,Dynamic,Area"), 0)); - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/shape_type", PROPERTY_HINT_ENUM, "Decompose Convex,Simple Convex,Trimesh,Box,Sphere,Cylinder,Capsule", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 2)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/shape_type", PROPERTY_HINT_ENUM, "Decompose Convex,Simple Convex,Trimesh,Box,Sphere,Cylinder,Capsule,Automatic", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 7)); r_options->push_back(ImportOption(PropertyInfo(Variant::OBJECT, "physics/physics_material_override", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsMaterial"), Variant())); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), 1)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), 1)); diff --git a/editor/import/3d/resource_importer_scene.h b/editor/import/3d/resource_importer_scene.h index cd6a725231..f9124ad289 100644 --- a/editor/import/3d/resource_importer_scene.h +++ b/editor/import/3d/resource_importer_scene.h @@ -212,6 +212,7 @@ class ResourceImporterScene : public ResourceImporter { SHAPE_TYPE_SPHERE, SHAPE_TYPE_CYLINDER, SHAPE_TYPE_CAPSULE, + SHAPE_TYPE_AUTOMATIC, }; static Error _check_resource_save_paths(const Dictionary &p_data); @@ -324,11 +325,21 @@ public: template <typename M> Vector<Ref<Shape3D>> ResourceImporterScene::get_collision_shapes(const Ref<ImporterMesh> &p_mesh, const M &p_options, float p_applied_root_scale) { ERR_FAIL_COND_V(p_mesh.is_null(), Vector<Ref<Shape3D>>()); - ShapeType generate_shape_type = SHAPE_TYPE_TRIMESH; + + ShapeType generate_shape_type = SHAPE_TYPE_AUTOMATIC; if (p_options.has(SNAME("physics/shape_type"))) { generate_shape_type = (ShapeType)p_options[SNAME("physics/shape_type")].operator int(); } + if (generate_shape_type == SHAPE_TYPE_AUTOMATIC) { + BodyType body_type = BODY_TYPE_STATIC; + if (p_options.has(SNAME("physics/body_type"))) { + body_type = (BodyType)p_options[SNAME("physics/body_type")].operator int(); + } + + generate_shape_type = body_type == BODY_TYPE_DYNAMIC ? SHAPE_TYPE_DECOMPOSE_CONVEX : SHAPE_TYPE_TRIMESH; + } + if (generate_shape_type == SHAPE_TYPE_DECOMPOSE_CONVEX) { Ref<MeshConvexDecompositionSettings> decomposition_settings = Ref<MeshConvexDecompositionSettings>(); decomposition_settings.instantiate(); @@ -482,11 +493,20 @@ template <typename M> Transform3D ResourceImporterScene::get_collision_shapes_transform(const M &p_options) { Transform3D transform; - ShapeType generate_shape_type = SHAPE_TYPE_TRIMESH; + ShapeType generate_shape_type = SHAPE_TYPE_AUTOMATIC; if (p_options.has(SNAME("physics/shape_type"))) { generate_shape_type = (ShapeType)p_options[SNAME("physics/shape_type")].operator int(); } + if (generate_shape_type == SHAPE_TYPE_AUTOMATIC) { + BodyType body_type = BODY_TYPE_STATIC; + if (p_options.has(SNAME("physics/body_type"))) { + body_type = (BodyType)p_options[SNAME("physics/body_type")].operator int(); + } + + generate_shape_type = body_type == BODY_TYPE_DYNAMIC ? SHAPE_TYPE_DECOMPOSE_CONVEX : SHAPE_TYPE_TRIMESH; + } + if (generate_shape_type == SHAPE_TYPE_BOX || generate_shape_type == SHAPE_TYPE_SPHERE || generate_shape_type == SHAPE_TYPE_CYLINDER || diff --git a/editor/plugins/editor_plugin.cpp b/editor/plugins/editor_plugin.cpp index 005407e188..d9f60e155d 100644 --- a/editor/plugins/editor_plugin.cpp +++ b/editor/plugins/editor_plugin.cpp @@ -414,13 +414,19 @@ void EditorPlugin::remove_translation_parser_plugin(const Ref<EditorTranslationP void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin> &p_importer, bool p_first_priority) { ERR_FAIL_COND(!p_importer.is_valid()); ResourceFormatImporter::get_singleton()->add_importer(p_importer, p_first_priority); - callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan).call_deferred(); + // Plugins are now loaded during the first scan. It's important not to start another scan, + // even a deferred one, as it would cause a scan during a scan at the next main thread iteration. + if (!EditorFileSystem::get_singleton()->doing_first_scan()) { + callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan).call_deferred(); + } } void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin> &p_importer) { ERR_FAIL_COND(!p_importer.is_valid()); ResourceFormatImporter::get_singleton()->remove_importer(p_importer); - if (!EditorNode::get_singleton()->is_exiting()) { + // Plugins are now loaded during the first scan. It's important not to start another scan, + // even a deferred one, as it would cause a scan during a scan at the next main thread iteration. + if (!EditorNode::get_singleton()->is_exiting() && !EditorFileSystem::get_singleton()->doing_first_scan()) { callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan).call_deferred(); } } diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 9d5dbb4a4f..a670c7937b 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -4049,6 +4049,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { filename = memnew(Label); filename->set_clip_text(true); filename->set_h_size_flags(SIZE_EXPAND_FILL); + filename->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); filename->add_theme_style_override(CoreStringName(normal), EditorNode::get_singleton()->get_editor_theme()->get_stylebox(CoreStringName(normal), SNAME("LineEdit"))); buttons_hbox->add_child(filename); diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index 94e68ccc7c..0d26212cdb 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -651,7 +651,7 @@ void TileSetAtlasSourceEditor::_update_tile_data_editors() { tile_data_editors_tree->add_theme_constant_override("v_separation", 1); tile_data_editors_tree->add_theme_constant_override("h_separation", 3); - Color group_color = get_theme_color(SNAME("prop_category"), EditorStringName(Editor)); + Color group_color = get_theme_color(SNAME("separator_color"), EditorStringName(Editor)); // List of editors. // --- Rendering --- @@ -2451,6 +2451,8 @@ void TileSetAtlasSourceEditor::_notification(int p_what) { resize_handle = get_editor_theme_icon(SNAME("EditorHandle")); resize_handle_disabled = get_editor_theme_icon(SNAME("EditorHandleDisabled")); + + tile_data_editors_tree->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), "PopupPanel")); } break; case NOTIFICATION_INTERNAL_PROCESS: { diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index c2d89b28f5..943e345e97 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -91,6 +91,10 @@ void ProjectSettingsEditor::update_plugins() { plugin_settings->update_plugins(); } +void ProjectSettingsEditor::init_autoloads() { + autoload_settings->init_autoloads(); +} + void ProjectSettingsEditor::_setting_edited(const String &p_name) { queue_save(); } diff --git a/editor/project_settings_editor.h b/editor/project_settings_editor.h index fb294c6bbd..5890ed2c2d 100644 --- a/editor/project_settings_editor.h +++ b/editor/project_settings_editor.h @@ -123,6 +123,7 @@ public: void set_plugins_page(); void set_general_page(const String &p_category); void update_plugins(); + void init_autoloads(); EditorAutoloadSettings *get_autoload_settings() { return autoload_settings; } GroupSettingsEditor *get_group_settings() { return group_settings; } diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 7f60fbbdb9..94bd3e16d3 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -77,12 +77,12 @@ void SceneTreeDock::_quick_open() { void SceneTreeDock::_inspect_hovered_node() { select_node_hovered_at_end_of_drag = true; - if (tree_item_inspected != nullptr) { - tree_item_inspected->clear_custom_color(0); - } Tree *tree = scene_tree->get_scene_tree(); TreeItem *item = tree->get_item_with_metadata(node_hovered_now->get_path()); if (item) { + if (tree_item_inspected) { + tree_item_inspected->clear_custom_color(0); + } tree_item_inspected = item; tree_item_inspected->set_custom_color(0, get_theme_color(SNAME("accent_color"), EditorStringName(Editor))); } @@ -133,8 +133,9 @@ void SceneTreeDock::input(const Ref<InputEvent> &p_event) { } if (mb->is_released()) { - if (tree_item_inspected != nullptr) { + if (tree_item_inspected) { tree_item_inspected->clear_custom_color(0); + tree_item_inspected = nullptr; } _reset_hovering_timer(); } diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 20d424894a..73b1e44db3 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -115,7 +115,7 @@ Variant GDScriptNativeClass::callp(const StringName &p_method, const Variant **p } GDScriptFunction *GDScript::_super_constructor(GDScript *p_script) { - if (p_script->initializer) { + if (likely(p_script->valid) && p_script->initializer) { return p_script->initializer; } else { GDScript *base_src = p_script->_base; @@ -136,7 +136,11 @@ void GDScript::_super_implicit_constructor(GDScript *p_script, GDScriptInstance } } ERR_FAIL_NULL(p_script->implicit_initializer); - p_script->implicit_initializer->call(p_instance, nullptr, 0, r_error); + if (likely(valid)) { + p_script->implicit_initializer->call(p_instance, nullptr, 0, r_error); + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; + } } GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_is_ref_counted, Callable::CallError &r_error) { @@ -662,7 +666,7 @@ String GDScript::_get_debug_path() const { } Error GDScript::_static_init() { - if (static_initializer) { + if (likely(valid) && static_initializer) { Callable::CallError call_err; static_initializer->call(nullptr, nullptr, 0, call_err); if (call_err.error != Callable::CallError::CALL_OK) { @@ -679,8 +683,6 @@ Error GDScript::_static_init() { return err; } -#ifdef TOOLS_ENABLED - void GDScript::_static_default_init() { for (const KeyValue<StringName, MemberInfo> &E : static_variables_indices) { const GDScriptDataType &type = E.value.data_type; @@ -702,6 +704,8 @@ void GDScript::_static_default_init() { } } +#ifdef TOOLS_ENABLED + void GDScript::_save_old_static_data() { old_static_variables_indices = static_variables_indices; old_static_variables = static_variables; @@ -873,9 +877,6 @@ Error GDScript::reload(bool p_keep_state) { #ifdef TOOLS_ENABLED if (can_run && p_keep_state) { _restore_old_static_data(); - } else if (!can_run) { - // Initialize static variables with sane default values even if the constructor isn't called. - _static_default_init(); } #endif @@ -912,18 +913,15 @@ void GDScript::unload_static() const { } Variant GDScript::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (unlikely(!valid)) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; - return Variant(); - } - GDScript *top = this; while (top) { - HashMap<StringName, GDScriptFunction *>::Iterator E = top->member_functions.find(p_method); - if (E) { - ERR_FAIL_COND_V_MSG(!E->value->is_static(), Variant(), "Can't call non-static function '" + String(p_method) + "' in script."); + if (likely(top->valid)) { + HashMap<StringName, GDScriptFunction *>::Iterator E = top->member_functions.find(p_method); + if (E) { + ERR_FAIL_COND_V_MSG(!E->value->is_static(), Variant(), "Can't call non-static function '" + String(p_method) + "' in script."); - return E->value->call(nullptr, p_args, p_argcount, r_error); + return E->value->call(nullptr, p_args, p_argcount, r_error); + } } top = top->_base; } @@ -939,10 +937,6 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const { return true; } - if (unlikely(!valid)) { - return false; - } - const GDScript *top = this; while (top) { { @@ -956,7 +950,7 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const { { HashMap<StringName, MemberInfo>::ConstIterator E = top->static_variables_indices.find(p_name); if (E) { - if (E->value.getter) { + if (likely(top->valid) && E->value.getter) { Callable::CallError ce; r_ret = const_cast<GDScript *>(this)->callp(E->value.getter, nullptr, 0, ce); return true; @@ -966,7 +960,7 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const { } } - { + if (likely(top->valid)) { HashMap<StringName, GDScriptFunction *>::ConstIterator E = top->member_functions.find(p_name); if (E && E->value->is_static()) { if (top->rpc_config.has(p_name)) { @@ -999,10 +993,6 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) { return true; } - if (unlikely(!valid)) { - return false; - } - GDScript *top = this; while (top) { HashMap<StringName, MemberInfo>::ConstIterator E = top->static_variables_indices.find(p_name); @@ -1017,7 +1007,7 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) { return false; } } - if (member->setter) { + if (likely(top->valid) && member->setter) { const Variant *args = &value; Callable::CallError err; callp(member->setter, &args, 1, err); @@ -1037,10 +1027,6 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) { void GDScript::_get_property_list(List<PropertyInfo> *p_properties) const { p_properties->push_back(PropertyInfo(Variant::STRING, "script/source", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL)); - if (unlikely(!valid)) { - return; - } - List<const GDScript *> classes; const GDScript *top = this; while (top) { @@ -1657,10 +1643,6 @@ GDScript::~GDScript() { ////////////////////////////// bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { - if (unlikely(!script->valid)) { - return false; - } - { HashMap<StringName, GDScript::MemberInfo>::Iterator E = script->member_indices.find(p_name); if (E) { @@ -1674,7 +1656,7 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { return false; } } - if (member->setter) { + if (likely(script->valid) && member->setter) { const Variant *args = &value; Callable::CallError err; callp(member->setter, &args, 1, err); @@ -1701,7 +1683,7 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { return false; } } - if (member->setter) { + if (likely(sptr->valid) && member->setter) { const Variant *args = &value; Callable::CallError err; callp(member->setter, &args, 1, err); @@ -1713,7 +1695,7 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { } } - { + if (likely(sptr->valid)) { HashMap<StringName, GDScriptFunction *>::Iterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._set); if (E) { Variant name = p_name; @@ -1734,14 +1716,10 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { } bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { - if (unlikely(!script->valid)) { - return false; - } - { HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = script->member_indices.find(p_name); if (E) { - if (E->value.getter) { + if (likely(script->valid) && E->value.getter) { Callable::CallError err; r_ret = const_cast<GDScriptInstance *>(this)->callp(E->value.getter, nullptr, 0, err); if (err.error == Callable::CallError::CALL_OK) { @@ -1766,7 +1744,7 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { { HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = sptr->static_variables_indices.find(p_name); if (E) { - if (E->value.getter) { + if (likely(sptr->valid) && E->value.getter) { Callable::CallError ce; r_ret = const_cast<GDScript *>(sptr)->callp(E->value.getter, nullptr, 0, ce); return true; @@ -1784,7 +1762,7 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { } } - { + if (likely(sptr->valid)) { HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(p_name); if (E) { if (sptr->rpc_config.has(p_name)) { @@ -1804,7 +1782,7 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { } } - { + if (likely(sptr->valid)) { HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get); if (E) { Variant name = p_name; @@ -1844,13 +1822,15 @@ void GDScriptInstance::validate_property(PropertyInfo &p_property) const { const GDScript *sptr = script.ptr(); while (sptr) { - HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._validate_property); - if (E) { - Callable::CallError err; - Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err); - if (err.error == Callable::CallError::CALL_OK) { - p_property = PropertyInfo::from_dict(property); - return; + if (likely(sptr->valid)) { + HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._validate_property); + if (E) { + Callable::CallError err; + Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err); + if (err.error == Callable::CallError::CALL_OK) { + p_property = PropertyInfo::from_dict(property); + return; + } } } sptr = sptr->_base; @@ -1858,49 +1838,47 @@ void GDScriptInstance::validate_property(PropertyInfo &p_property) const { } void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { - if (unlikely(!script->valid)) { - return; - } - // exported members, not done yet! const GDScript *sptr = script.ptr(); List<PropertyInfo> props; while (sptr) { - HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list); - if (E) { - Callable::CallError err; - Variant ret = const_cast<GDScriptFunction *>(E->value)->call(const_cast<GDScriptInstance *>(this), nullptr, 0, err); - if (err.error == Callable::CallError::CALL_OK) { - ERR_FAIL_COND_MSG(ret.get_type() != Variant::ARRAY, "Wrong type for _get_property_list, must be an array of dictionaries."); - - Array arr = ret; - for (int i = 0; i < arr.size(); i++) { - Dictionary d = arr[i]; - ERR_CONTINUE(!d.has("name")); - ERR_CONTINUE(!d.has("type")); - - PropertyInfo pinfo; - pinfo.name = d["name"]; - pinfo.type = Variant::Type(d["type"].operator int()); - if (d.has("hint")) { - pinfo.hint = PropertyHint(d["hint"].operator int()); - } - if (d.has("hint_string")) { - pinfo.hint_string = d["hint_string"]; - } - if (d.has("usage")) { - pinfo.usage = d["usage"]; - } - if (d.has("class_name")) { - pinfo.class_name = d["class_name"]; - } + if (likely(sptr->valid)) { + HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list); + if (E) { + Callable::CallError err; + Variant ret = const_cast<GDScriptFunction *>(E->value)->call(const_cast<GDScriptInstance *>(this), nullptr, 0, err); + if (err.error == Callable::CallError::CALL_OK) { + ERR_FAIL_COND_MSG(ret.get_type() != Variant::ARRAY, "Wrong type for _get_property_list, must be an array of dictionaries."); + + Array arr = ret; + for (int i = 0; i < arr.size(); i++) { + Dictionary d = arr[i]; + ERR_CONTINUE(!d.has("name")); + ERR_CONTINUE(!d.has("type")); + + PropertyInfo pinfo; + pinfo.name = d["name"]; + pinfo.type = Variant::Type(d["type"].operator int()); + if (d.has("hint")) { + pinfo.hint = PropertyHint(d["hint"].operator int()); + } + if (d.has("hint_string")) { + pinfo.hint_string = d["hint_string"]; + } + if (d.has("usage")) { + pinfo.usage = d["usage"]; + } + if (d.has("class_name")) { + pinfo.class_name = d["class_name"]; + } - ERR_CONTINUE(pinfo.name.is_empty() && (pinfo.usage & PROPERTY_USAGE_STORAGE)); - ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX); + ERR_CONTINUE(pinfo.name.is_empty() && (pinfo.usage & PROPERTY_USAGE_STORAGE)); + ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX); - props.push_back(pinfo); + props.push_back(pinfo); + } } } } @@ -1940,21 +1918,19 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const } bool GDScriptInstance::property_can_revert(const StringName &p_name) const { - if (unlikely(!script->valid)) { - return false; - } - Variant name = p_name; const Variant *args[1] = { &name }; const GDScript *sptr = script.ptr(); while (sptr) { - HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_can_revert); - if (E) { - Callable::CallError err; - Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err); - if (err.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::BOOL && ret.operator bool()) { - return true; + if (likely(sptr->valid)) { + HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_can_revert); + if (E) { + Callable::CallError err; + Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err); + if (err.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::BOOL && ret.operator bool()) { + return true; + } } } sptr = sptr->_base; @@ -1964,22 +1940,20 @@ bool GDScriptInstance::property_can_revert(const StringName &p_name) const { } bool GDScriptInstance::property_get_revert(const StringName &p_name, Variant &r_ret) const { - if (unlikely(!script->valid)) { - return false; - } - Variant name = p_name; const Variant *args[1] = { &name }; const GDScript *sptr = script.ptr(); while (sptr) { - HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_get_revert); - if (E) { - Callable::CallError err; - Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err); - if (err.error == Callable::CallError::CALL_OK && ret.get_type() != Variant::NIL) { - r_ret = ret; - return true; + if (likely(sptr->valid)) { + HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._property_get_revert); + if (E) { + Callable::CallError err; + Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err); + if (err.error == Callable::CallError::CALL_OK && ret.get_type() != Variant::NIL) { + r_ret = ret; + return true; + } } } sptr = sptr->_base; @@ -2035,30 +2009,28 @@ void GDScriptInstance::_call_implicit_ready_recursively(GDScript *p_script) { if (p_script->_base) { _call_implicit_ready_recursively(p_script->_base); } - if (p_script->implicit_ready) { + if (likely(p_script->valid) && p_script->implicit_ready) { Callable::CallError err; p_script->implicit_ready->call(this, nullptr, 0, err); } } Variant GDScriptInstance::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (unlikely(!script->valid)) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; - return Variant(); - } - GDScript *sptr = script.ptr(); if (unlikely(p_method == SceneStringName(_ready))) { // Call implicit ready first, including for the super classes recursively. _call_implicit_ready_recursively(sptr); } while (sptr) { - HashMap<StringName, GDScriptFunction *>::Iterator E = sptr->member_functions.find(p_method); - if (E) { - return E->value->call(this, p_args, p_argcount, r_error); + if (likely(sptr->valid)) { + HashMap<StringName, GDScriptFunction *>::Iterator E = sptr->member_functions.find(p_method); + if (E) { + return E->value->call(this, p_args, p_argcount, r_error); + } } sptr = sptr->_base; } + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; return Variant(); } @@ -2083,12 +2055,14 @@ void GDScriptInstance::notification(int p_notification, bool p_reversed) { sptr = sptr->_base; } for (GDScript *sc : pl) { - HashMap<StringName, GDScriptFunction *>::Iterator E = sc->member_functions.find(GDScriptLanguage::get_singleton()->strings._notification); - if (E) { - Callable::CallError err; - E->value->call(this, args, 1, err); - if (err.error != Callable::CallError::CALL_OK) { - //print error about notification call + if (likely(sc->valid)) { + HashMap<StringName, GDScriptFunction *>::Iterator E = sc->member_functions.find(GDScriptLanguage::get_singleton()->strings._notification); + if (E) { + Callable::CallError err; + E->value->call(this, args, 1, err); + if (err.error != Callable::CallError::CALL_OK) { + //print error about notification call + } } } } @@ -2759,7 +2733,7 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b String source = f->get_as_utf8_string(); GDScriptParser parser; - err = parser.parse(source, p_path, false); + err = parser.parse(source, p_path, false, false); const GDScriptParser::ClassNode *c = parser.get_tree(); if (!c) { diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 728459de44..d097cb193b 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -169,9 +169,7 @@ private: GDScriptFunction *static_initializer = nullptr; Error _static_init(); -#ifdef TOOLS_ENABLED void _static_default_init(); // Initialize static variables with default values based on their types. -#endif int subclass_count = 0; RBSet<Object *> instances; diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 76e690a083..9147204a9b 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2663,6 +2663,21 @@ void GDScriptAnalyzer::reduce_assignment(GDScriptParser::AssignmentNode *p_assig reduce_expression(p_assignment->assignee); +#ifdef DEBUG_ENABLED + { + GDScriptParser::ExpressionNode *base = p_assignment->assignee; + while (base && base->type == GDScriptParser::Node::SUBSCRIPT) { + base = static_cast<GDScriptParser::SubscriptNode *>(base)->base; + } + if (base && base->type == GDScriptParser::Node::IDENTIFIER) { + GDScriptParser::IdentifierNode *id = static_cast<GDScriptParser::IdentifierNode *>(base); + if (current_lambda && current_lambda->captures_indices.has(id->name)) { + parser->push_warning(p_assignment, GDScriptWarning::CONFUSABLE_CAPTURE_REASSIGNMENT, id->name); + } + } + } +#endif + if (p_assignment->assigned_value == nullptr || p_assignment->assignee == nullptr) { return; } diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp index ac6f5f05c6..c56ae0fb14 100644 --- a/modules/gdscript/gdscript_cache.cpp +++ b/modules/gdscript/gdscript_cache.cpp @@ -91,12 +91,8 @@ Error GDScriptParserRef::raise_status(Status p_new_status) { result = get_analyzer()->resolve_interface(); } break; case INTERFACE_SOLVED: { - status = BODY_SOLVED; - result = get_analyzer()->resolve_body(); - } break; - case BODY_SOLVED: { status = FULLY_SOLVED; - result = get_analyzer()->resolve_dependencies(); + result = get_analyzer()->resolve_body(); } break; case FULLY_SOLVED: { return result; @@ -344,7 +340,11 @@ Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_erro } } + // Allowing lifting the lock might cause a script to be reloaded multiple times, + // which, as a last resort deadlock prevention strategy, is a good tradeoff. + uint32_t allowance_id = WorkerThreadPool::thread_enter_unlock_allowance_zone(&singleton->mutex); r_error = script->reload(true); + WorkerThreadPool::thread_exit_unlock_allowance_zone(allowance_id); if (r_error) { return script; } diff --git a/modules/gdscript/gdscript_cache.h b/modules/gdscript/gdscript_cache.h index c738233beb..16121cc082 100644 --- a/modules/gdscript/gdscript_cache.h +++ b/modules/gdscript/gdscript_cache.h @@ -48,7 +48,6 @@ public: PARSED, INHERITANCE_SOLVED, INTERFACE_SOLVED, - BODY_SOLVED, FULLY_SOLVED, }; diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index eeffc13a10..5469dad3f7 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -3006,6 +3006,8 @@ Error GDScriptCompiler::_compile_class(GDScript *p_script, const GDScriptParser: has_static_data = has_static_data || inner_class->has_static_data; } + p_script->_static_default_init(); + p_script->valid = true; return OK; } @@ -3228,11 +3230,7 @@ Error GDScriptCompiler::compile(const GDScriptParser *p_parser, GDScript *p_scri GDScriptCache::add_static_script(p_script); } - err = GDScriptCache::finish_compiling(main_script->path); - if (err) { - main_script->valid = false; - } - return err; + return GDScriptCache::finish_compiling(main_script->path); } String GDScriptCompiler::get_error() const { diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index aaa09134f0..a1ea94667d 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -309,13 +309,14 @@ void GDScriptParser::set_last_completion_call_arg(int p_argument) { completion_call_stack.back()->get().argument = p_argument; } -Error GDScriptParser::parse(const String &p_source_code, const String &p_script_path, bool p_for_completion) { +Error GDScriptParser::parse(const String &p_source_code, const String &p_script_path, bool p_for_completion, bool p_parse_body) { clear(); String source = p_source_code; int cursor_line = -1; int cursor_column = -1; for_completion = p_for_completion; + parse_body = p_parse_body; int tab_size = 4; #ifdef TOOLS_ENABLED @@ -689,6 +690,12 @@ void GDScriptParser::parse_program() { } } + // When the only thing needed is the class name and the icon, we don't need to parse the hole file. + // It really speed up the call to GDScriptLanguage::get_global_class_name especially for large script. + if (!parse_body) { + return; + } + #undef PUSH_PENDING_ANNOTATIONS_TO_HEAD parse_class_body(true); diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 96358165c0..21942222cf 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -1329,6 +1329,7 @@ private: bool _is_tool = false; String script_path; bool for_completion = false; + bool parse_body = true; bool panic_mode = false; bool can_break = false; bool can_continue = false; @@ -1560,7 +1561,7 @@ private: #endif // TOOLS_ENABLED public: - Error parse(const String &p_source_code, const String &p_script_path, bool p_for_completion); + Error parse(const String &p_source_code, const String &p_script_path, bool p_for_completion, bool p_parse_body = true); Error parse_binary(const Vector<uint8_t> &p_binary, const String &p_script_path); ClassNode *get_tree() const { return head; } bool is_tool() const { return _is_tool; } diff --git a/modules/gdscript/gdscript_warning.cpp b/modules/gdscript/gdscript_warning.cpp index 611a9ad2d9..e8fb1d94b3 100644 --- a/modules/gdscript/gdscript_warning.cpp +++ b/modules/gdscript/gdscript_warning.cpp @@ -145,6 +145,9 @@ String GDScriptWarning::get_message() const { case CONFUSABLE_LOCAL_USAGE: CHECK_SYMBOLS(1); return vformat(R"(The identifier "%s" will be shadowed below in the block.)", symbols[0]); + case CONFUSABLE_CAPTURE_REASSIGNMENT: + CHECK_SYMBOLS(1); + return vformat(R"(Reassigning lambda capture does not modify the outer local variable "%s".)", symbols[0]); case INFERENCE_ON_VARIANT: CHECK_SYMBOLS(1); return vformat("The %s type is being inferred from a Variant value, so it will be typed as Variant.", symbols[0]); @@ -231,6 +234,7 @@ String GDScriptWarning::get_name_from_code(Code p_code) { "CONFUSABLE_IDENTIFIER", "CONFUSABLE_LOCAL_DECLARATION", "CONFUSABLE_LOCAL_USAGE", + "CONFUSABLE_CAPTURE_REASSIGNMENT", "INFERENCE_ON_VARIANT", "NATIVE_METHOD_OVERRIDE", "GET_NODE_DEFAULT_WITHOUT_ONREADY", diff --git a/modules/gdscript/gdscript_warning.h b/modules/gdscript/gdscript_warning.h index 3ad9488138..1c806bb4e2 100644 --- a/modules/gdscript/gdscript_warning.h +++ b/modules/gdscript/gdscript_warning.h @@ -85,6 +85,7 @@ public: CONFUSABLE_IDENTIFIER, // The identifier contains misleading characters that can be confused. E.g. "usеr" (has Cyrillic "е" instead of Latin "e"). CONFUSABLE_LOCAL_DECLARATION, // The parent block declares an identifier with the same name below. CONFUSABLE_LOCAL_USAGE, // The identifier will be shadowed below in the block. + CONFUSABLE_CAPTURE_REASSIGNMENT, // Reassigning lambda capture does not modify the outer local variable. INFERENCE_ON_VARIANT, // The declaration uses type inference but the value is typed as Variant. NATIVE_METHOD_OVERRIDE, // The script method overrides a native one, this may not work as intended. GET_NODE_DEFAULT_WITHOUT_ONREADY, // A class variable uses `get_node()` (or the `$` notation) as its default value, but does not use the @onready annotation. @@ -137,6 +138,7 @@ public: WARN, // CONFUSABLE_IDENTIFIER WARN, // CONFUSABLE_LOCAL_DECLARATION WARN, // CONFUSABLE_LOCAL_USAGE + WARN, // CONFUSABLE_CAPTURE_REASSIGNMENT ERROR, // INFERENCE_ON_VARIANT // Most likely done by accident, usually inference is trying for a particular type. ERROR, // NATIVE_METHOD_OVERRIDE // May not work as expected. ERROR, // GET_NODE_DEFAULT_WITHOUT_ONREADY // May not work as expected. diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_capture_reassignment.gd b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_capture_reassignment.gd new file mode 100644 index 0000000000..b1accbe628 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_capture_reassignment.gd @@ -0,0 +1,27 @@ +var member := 1 + +func test(): + var number := 1 + var string := "1" + var vector := Vector2i(1, 0) + var array_assign := [1] + var array_append := [1] + var f := func (): + member = 2 + number = 2 + string += "2" + vector.x = 2 + array_assign = [2] + array_append.append(2) + var g := func (): + member = 3 + number = 3 + string += "3" + vector.x = 3 + array_assign = [3] + array_append.append(3) + prints("g", member, number, string, vector, array_assign, array_append) + g.call() + prints("f", member, number, string, vector, array_assign, array_append) + f.call() + prints("test", member, number, string, vector, array_assign, array_append) diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_capture_reassignment.out b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_capture_reassignment.out new file mode 100644 index 0000000000..b335a04a02 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_capture_reassignment.out @@ -0,0 +1,36 @@ +GDTEST_OK +>> WARNING +>> Line: 11 +>> CONFUSABLE_CAPTURE_REASSIGNMENT +>> Reassigning lambda capture does not modify the outer local variable "number". +>> WARNING +>> Line: 12 +>> CONFUSABLE_CAPTURE_REASSIGNMENT +>> Reassigning lambda capture does not modify the outer local variable "string". +>> WARNING +>> Line: 13 +>> CONFUSABLE_CAPTURE_REASSIGNMENT +>> Reassigning lambda capture does not modify the outer local variable "vector". +>> WARNING +>> Line: 14 +>> CONFUSABLE_CAPTURE_REASSIGNMENT +>> Reassigning lambda capture does not modify the outer local variable "array_assign". +>> WARNING +>> Line: 18 +>> CONFUSABLE_CAPTURE_REASSIGNMENT +>> Reassigning lambda capture does not modify the outer local variable "number". +>> WARNING +>> Line: 19 +>> CONFUSABLE_CAPTURE_REASSIGNMENT +>> Reassigning lambda capture does not modify the outer local variable "string". +>> WARNING +>> Line: 20 +>> CONFUSABLE_CAPTURE_REASSIGNMENT +>> Reassigning lambda capture does not modify the outer local variable "vector". +>> WARNING +>> Line: 21 +>> CONFUSABLE_CAPTURE_REASSIGNMENT +>> Reassigning lambda capture does not modify the outer local variable "array_assign". +g 3 3 123 (3, 0) [3] [1, 2, 3] +f 3 2 12 (2, 0) [2] [1, 2, 3] +test 3 1 1 (1, 0) [1] [1, 2, 3] diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.gd b/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.gd index 46b6856d22..c3a42288c7 100644 --- a/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.gd +++ b/modules/gdscript/tests/scripts/parser/features/lambda_ends_with_new_line.gd @@ -9,6 +9,7 @@ func four_parameters(_a, callable : Callable, b=func(): print(10)): func test(): var v + @warning_ignore("confusable_capture_reassignment") v=func():v=1 if true: v=1 print(v) diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp index 541e369925..04edde8300 100644 --- a/modules/openxr/openxr_api.cpp +++ b/modules/openxr/openxr_api.cpp @@ -902,6 +902,47 @@ bool OpenXRAPI::setup_play_space() { new_reference_space = XR_REFERENCE_SPACE_TYPE_LOCAL; will_emulate_local_floor = true; + + if (local_floor_emulation.local_space == XR_NULL_HANDLE) { + XrReferenceSpaceCreateInfo create_info = { + XR_TYPE_REFERENCE_SPACE_CREATE_INFO, // type + nullptr, // next + XR_REFERENCE_SPACE_TYPE_LOCAL, // referenceSpaceType + identityPose, // poseInReferenceSpace + }; + + XrResult result = xrCreateReferenceSpace(session, &create_info, &local_floor_emulation.local_space); + if (XR_FAILED(result)) { + print_line("OpenXR: Failed to create LOCAL space in order to emulate LOCAL_FLOOR [", get_error_string(result), "]"); + will_emulate_local_floor = false; + } + } + + if (local_floor_emulation.stage_space == XR_NULL_HANDLE) { + XrReferenceSpaceCreateInfo create_info = { + XR_TYPE_REFERENCE_SPACE_CREATE_INFO, // type + nullptr, // next + XR_REFERENCE_SPACE_TYPE_STAGE, // referenceSpaceType + identityPose, // poseInReferenceSpace + }; + + XrResult result = xrCreateReferenceSpace(session, &create_info, &local_floor_emulation.stage_space); + if (XR_FAILED(result)) { + print_line("OpenXR: Failed to create STAGE space in order to emulate LOCAL_FLOOR [", get_error_string(result), "]"); + will_emulate_local_floor = false; + } + } + + if (!will_emulate_local_floor) { + if (local_floor_emulation.local_space != XR_NULL_HANDLE) { + xrDestroySpace(local_floor_emulation.local_space); + local_floor_emulation.local_space = XR_NULL_HANDLE; + } + if (local_floor_emulation.stage_space != XR_NULL_HANDLE) { + xrDestroySpace(local_floor_emulation.stage_space); + local_floor_emulation.stage_space = XR_NULL_HANDLE; + } + } } else { // Fallback on LOCAL, which all OpenXR runtimes are required to support. print_verbose(String("OpenXR: ") + OpenXRUtil::get_reference_space_name(requested_reference_space) + String(" isn't supported, defaulting to LOCAL space.")); @@ -931,16 +972,11 @@ bool OpenXRAPI::setup_play_space() { play_space = new_play_space; reference_space = new_reference_space; - emulating_local_floor = will_emulate_local_floor; - if (emulating_local_floor) { - // We'll use the STAGE space to get the floor height, but we can't do that until - // after xrWaitFrame(), so just set this flag for now. - // Render state will be updated then. - should_reset_emulated_floor_height = true; - } else { - // Update render state so this play space is used rendering the upcoming frame. - set_render_play_space(play_space); - } + local_floor_emulation.enabled = will_emulate_local_floor; + local_floor_emulation.should_reset_floor_height = will_emulate_local_floor; + + // Update render state so this play space is used rendering the upcoming frame. + set_render_play_space(play_space); return true; } @@ -975,63 +1011,39 @@ bool OpenXRAPI::setup_view_space() { } bool OpenXRAPI::reset_emulated_floor_height() { - ERR_FAIL_COND_V(!emulating_local_floor, false); - - // This is based on the example code in the OpenXR spec which shows how to - // emulate LOCAL_FLOOR if it's not supported. - // See: https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#XR_EXT_local_floor + ERR_FAIL_COND_V(!local_floor_emulation.enabled, false); + ERR_FAIL_COND_V(local_floor_emulation.local_space == XR_NULL_HANDLE, false); + ERR_FAIL_COND_V(local_floor_emulation.stage_space == XR_NULL_HANDLE, false); XrResult result; - XrPosef identityPose = { - { 0.0, 0.0, 0.0, 1.0 }, - { 0.0, 0.0, 0.0 } - }; - - XrSpace local_space = XR_NULL_HANDLE; - XrSpace stage_space = XR_NULL_HANDLE; - - XrReferenceSpaceCreateInfo create_info = { - XR_TYPE_REFERENCE_SPACE_CREATE_INFO, // type - nullptr, // next - XR_REFERENCE_SPACE_TYPE_LOCAL, // referenceSpaceType - identityPose, // poseInReferenceSpace - }; - - result = xrCreateReferenceSpace(session, &create_info, &local_space); - if (XR_FAILED(result)) { - print_line("OpenXR: Failed to create LOCAL space in order to emulate LOCAL_FLOOR [", get_error_string(result), "]"); - return false; - } - - create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_STAGE; - result = xrCreateReferenceSpace(session, &create_info, &stage_space); - if (XR_FAILED(result)) { - print_line("OpenXR: Failed to create STAGE space in order to emulate LOCAL_FLOOR [", get_error_string(result), "]"); - xrDestroySpace(local_space); - return false; - } - XrSpaceLocation stage_location = { XR_TYPE_SPACE_LOCATION, // type nullptr, // next 0, // locationFlags - identityPose, // pose + { { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0 } }, // pose }; - result = xrLocateSpace(stage_space, local_space, get_predicted_display_time(), &stage_location); - - xrDestroySpace(local_space); - xrDestroySpace(stage_space); + result = xrLocateSpace(local_floor_emulation.stage_space, local_floor_emulation.local_space, get_predicted_display_time(), &stage_location); if (XR_FAILED(result)) { print_line("OpenXR: Failed to locate STAGE space in LOCAL space, in order to emulate LOCAL_FLOOR [", get_error_string(result), "]"); return false; } + XrPosef pose = { + { 0.0, 0.0, 0.0, 1.0 }, + { 0.0, stage_location.pose.position.y, 0.0 } + }; + + XrReferenceSpaceCreateInfo create_info = { + XR_TYPE_REFERENCE_SPACE_CREATE_INFO, // type + nullptr, // next + XR_REFERENCE_SPACE_TYPE_LOCAL, // referenceSpaceType + pose, // poseInReferenceSpace + }; + XrSpace new_play_space; - create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; - create_info.poseInReferenceSpace.position.y = stage_location.pose.position.y; result = xrCreateReferenceSpace(session, &create_info, &new_play_space); if (XR_FAILED(result)) { print_line("OpenXR: Failed to recreate emulated LOCAL_FLOOR play space with latest floor estimate [", get_error_string(result), "]"); @@ -1275,6 +1287,16 @@ void OpenXRAPI::destroy_session() { xrDestroySpace(view_space); view_space = XR_NULL_HANDLE; } + if (local_floor_emulation.local_space != XR_NULL_HANDLE) { + xrDestroySpace(local_floor_emulation.local_space); + local_floor_emulation.local_space = XR_NULL_HANDLE; + } + if (local_floor_emulation.stage_space != XR_NULL_HANDLE) { + xrDestroySpace(local_floor_emulation.stage_space); + local_floor_emulation.stage_space = XR_NULL_HANDLE; + } + local_floor_emulation.enabled = false; + local_floor_emulation.should_reset_floor_height = false; if (supported_reference_spaces != nullptr) { // free previous results @@ -1953,8 +1975,8 @@ bool OpenXRAPI::poll_events() { XrEventDataReferenceSpaceChangePending *event = (XrEventDataReferenceSpaceChangePending *)&runtimeEvent; print_verbose(String("OpenXR EVENT: reference space type ") + OpenXRUtil::get_reference_space_name(event->referenceSpaceType) + " change pending!"); - if (emulating_local_floor) { - should_reset_emulated_floor_height = true; + if (local_floor_emulation.enabled) { + local_floor_emulation.should_reset_floor_height = true; } if (event->poseValid && xr_interface) { xr_interface->on_pose_recentered(); @@ -2097,16 +2119,18 @@ bool OpenXRAPI::process() { set_render_display_info(frame_state.predictedDisplayTime, frame_state.shouldRender); + // This is before setup_play_space() to ensure that it happens on the frame after + // the play space has been created. + if (unlikely(local_floor_emulation.should_reset_floor_height && !play_space_is_dirty)) { + reset_emulated_floor_height(); + local_floor_emulation.should_reset_floor_height = false; + } + if (unlikely(play_space_is_dirty)) { setup_play_space(); play_space_is_dirty = false; } - if (unlikely(should_reset_emulated_floor_height)) { - reset_emulated_floor_height(); - should_reset_emulated_floor_height = false; - } - for (OpenXRExtensionWrapper *wrapper : registered_extension_wrappers) { wrapper->on_process(); } diff --git a/modules/openxr/openxr_api.h b/modules/openxr/openxr_api.h index f9d2e60148..748ef3af94 100644 --- a/modules/openxr/openxr_api.h +++ b/modules/openxr/openxr_api.h @@ -165,8 +165,16 @@ private: XrSpace view_space = XR_NULL_HANDLE; XRPose::TrackingConfidence head_pose_confidence = XRPose::XR_TRACKING_CONFIDENCE_NONE; - bool emulating_local_floor = false; - bool should_reset_emulated_floor_height = false; + // When LOCAL_FLOOR isn't supported, we use an approach based on the example code in the + // OpenXR spec in order to emulate it. + // See: https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#XR_EXT_local_floor + struct LocalFloorEmulation { + bool enabled = false; + XrSpace local_space = XR_NULL_HANDLE; + XrSpace stage_space = XR_NULL_HANDLE; + bool should_reset_floor_height = false; + } local_floor_emulation; + bool reset_emulated_floor_height(); bool load_layer_properties(); diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp index 3fad8c2987..c05ad93f42 100644 --- a/platform/linuxbsd/wayland/display_server_wayland.cpp +++ b/platform/linuxbsd/wayland/display_server_wayland.cpp @@ -1111,6 +1111,28 @@ Key DisplayServerWayland::keyboard_get_keycode_from_physical(Key p_keycode) cons return key; } +void DisplayServerWayland::try_suspend() { + // Due to various reasons, we manually handle display synchronization by + // waiting for a frame event (request to draw) or, if available, the actual + // window's suspend status. When a window is suspended, we can avoid drawing + // altogether, either because the compositor told us that we don't need to or + // because the pace of the frame events became unreliable. + if (emulate_vsync) { + bool frame = wayland_thread.wait_frame_suspend_ms(1000); + if (!frame) { + suspended = true; + } + } else { + if (wayland_thread.is_suspended()) { + suspended = true; + } + } + + if (suspended) { + DEBUG_LOG_WAYLAND("Window suspended."); + } +} + void DisplayServerWayland::process_events() { wayland_thread.mutex.lock(); @@ -1193,30 +1215,32 @@ void DisplayServerWayland::process_events() { wayland_thread.keyboard_echo_keys(); if (!suspended) { - if (emulate_vsync) { - // Due to various reasons, we manually handle display synchronization by - // waiting for a frame event (request to draw) or, if available, the actual - // window's suspend status. When a window is suspended, we can avoid drawing - // altogether, either because the compositor told us that we don't need to or - // because the pace of the frame events became unreliable. - bool frame = wayland_thread.wait_frame_suspend_ms(1000); - if (!frame) { - suspended = true; + // Due to the way legacy suspension works, we have to treat low processor + // usage mode very differently than the regular one. + if (OS::get_singleton()->is_in_low_processor_usage_mode()) { + // NOTE: We must avoid committing a surface if we expect a new frame, as we + // might otherwise commit some inconsistent data (e.g. buffer scale). Note + // that if a new frame is expected it's going to be committed by the renderer + // soon anyways. + if (!RenderingServer::get_singleton()->has_changed()) { + // We _can't_ commit in a different thread (such as in the frame callback + // itself) because we would risk to step on the renderer's feet, which would + // cause subtle but severe issues, such as crashes on setups with explicit + // sync. This isn't normally a problem, as the renderer commits at every + // frame (which is what we need for atomic surface updates anyways), but in + // low processor usage mode that expectation is broken. When it's on, our + // frame rate stops being constant. This also reflects in the frame + // information we use for legacy suspension. In order to avoid issues, let's + // manually commit all surfaces, so that we can get fresh frame data. + wayland_thread.commit_surfaces(); + try_suspend(); } } else { - if (wayland_thread.is_suspended()) { - suspended = true; - } - } - - if (suspended) { - DEBUG_LOG_WAYLAND("Window suspended."); - } - } else { - if (wayland_thread.get_reset_frame()) { - // At last, a sign of life! We're no longer suspended. - suspended = false; + try_suspend(); } + } else if (wayland_thread.get_reset_frame()) { + // At last, a sign of life! We're no longer suspended. + suspended = false; } #ifdef DBUS_ENABLED diff --git a/platform/linuxbsd/wayland/display_server_wayland.h b/platform/linuxbsd/wayland/display_server_wayland.h index f02640a12e..e611533664 100644 --- a/platform/linuxbsd/wayland/display_server_wayland.h +++ b/platform/linuxbsd/wayland/display_server_wayland.h @@ -154,6 +154,8 @@ class DisplayServerWayland : public DisplayServer { virtual void _show_window(); + void try_suspend(); + public: virtual bool has_feature(Feature p_feature) const override; diff --git a/platform/linuxbsd/wayland/wayland_thread.cpp b/platform/linuxbsd/wayland/wayland_thread.cpp index 63a8db07df..341cc517e3 100644 --- a/platform/linuxbsd/wayland/wayland_thread.cpp +++ b/platform/linuxbsd/wayland/wayland_thread.cpp @@ -968,7 +968,6 @@ void WaylandThread::_frame_wl_callback_on_done(void *data, struct wl_callback *w ws->frame_callback = wl_surface_frame(ws->wl_surface), wl_callback_add_listener(ws->frame_callback, &frame_wl_callback_listener, ws); - wl_surface_commit(ws->wl_surface); if (ws->wl_surface && ws->buffer_scale_changed) { // NOTE: We're only now setting the buffer scale as the idea is to get this @@ -980,11 +979,6 @@ void WaylandThread::_frame_wl_callback_on_done(void *data, struct wl_callback *w // rendering if needed. wl_surface_set_buffer_scale(ws->wl_surface, window_state_get_preferred_buffer_scale(ws)); } - - // NOTE: Remember to set here also other buffer-dependent states (e.g. opaque - // region) if used, to be as close as possible to an atomic surface update. - // Ideally we'd only have one surface commit, but it's not really doable given - // the current state of things. } void WaylandThread::_wl_surface_on_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output) { @@ -3241,10 +3235,6 @@ void WaylandThread::window_create(DisplayServer::WindowID p_window_id, int p_wid ws.frame_callback = wl_surface_frame(ws.wl_surface); wl_callback_add_listener(ws.frame_callback, &frame_wl_callback_listener, &ws); - // NOTE: This commit is only called once to start the whole frame callback - // "loop". - wl_surface_commit(ws.wl_surface); - if (registry.xdg_exporter) { ws.xdg_exported = zxdg_exporter_v1_export(registry.xdg_exporter, ws.wl_surface); zxdg_exported_v1_add_listener(ws.xdg_exported, &xdg_exported_listener, &ws); @@ -4120,6 +4110,10 @@ void WaylandThread::primary_set_text(const String &p_text) { wl_display_roundtrip(wl_display); } +void WaylandThread::commit_surfaces() { + wl_surface_commit(main_window.wl_surface); +} + void WaylandThread::set_frame() { frame = true; } diff --git a/platform/linuxbsd/wayland/wayland_thread.h b/platform/linuxbsd/wayland/wayland_thread.h index 75d03181e2..775ca71346 100644 --- a/platform/linuxbsd/wayland/wayland_thread.h +++ b/platform/linuxbsd/wayland/wayland_thread.h @@ -992,6 +992,8 @@ public: void primary_set_text(const String &p_text); + void commit_surfaces(); + void set_frame(); bool get_reset_frame(); bool wait_frame_suspend_ms(int p_timeout); diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index a605e664ce..ea84130828 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -3040,7 +3040,7 @@ void DisplayServerX11::window_set_ime_active(const bool p_active, WindowID p_win XWindowAttributes xwa; XSync(x11_display, False); XGetWindowAttributes(x11_display, wd.x11_xim_window, &xwa); - if (xwa.map_state == IsViewable && _window_focus_check()) { + if (xwa.map_state == IsViewable) { _set_input_focus(wd.x11_xim_window, RevertToParent); } XSetICFocus(wd.xic); diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 0ad84240e4..8e1abba3bb 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -142,8 +142,9 @@ def detect_build_env_arch(): if os.getenv("VCTOOLSINSTALLDIR"): host_path_index = os.getenv("PATH").upper().find(os.getenv("VCTOOLSINSTALLDIR").upper() + "BIN\\HOST") if host_path_index > -1: - first_path_arch = os.getenv("PATH").split(";")[0].rsplit("\\", 1)[-1].lower() - return msvc_target_aliases[first_path_arch] + first_path_arch = os.getenv("PATH")[host_path_index:].split(";")[0].rsplit("\\", 1)[-1].lower() + if first_path_arch in msvc_target_aliases.keys(): + return msvc_target_aliases[first_path_arch] msys_target_aliases = { "mingw32": "x86_32", diff --git a/scene/3d/bone_attachment_3d.cpp b/scene/3d/bone_attachment_3d.cpp index 6aade24e4e..4889512037 100644 --- a/scene/3d/bone_attachment_3d.cpp +++ b/scene/3d/bone_attachment_3d.cpp @@ -239,9 +239,20 @@ int BoneAttachment3D::get_bone_idx() const { } void BoneAttachment3D::set_override_pose(bool p_override) { + if (override_pose == p_override) { + return; + } + override_pose = p_override; set_notify_transform(override_pose); set_process_internal(override_pose); + if (!override_pose && bone_idx >= 0) { + Skeleton3D *sk = _get_skeleton3d(); + if (sk) { + sk->reset_bone_pose(bone_idx); + } + } + notify_property_list_changed(); } diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 0bdb487300..c3c4b1d3fb 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -2331,18 +2331,19 @@ void CodeEdit::move_lines_up() { unfold_line(line); swap_lines(line - 1, line); } - } - - // Fix selection if it ended at column 0, since it wasn't moved. - for (int i = 0; i < get_caret_count(); i++) { - if (has_selection(i) && get_selection_to_column(i) == 0 && get_selection_to_line(i) != 0) { - if (is_caret_after_selection_origin(i)) { - set_caret_line(get_caret_line(i) - 1, false, true, -1, i); - } else { - set_selection_origin_line(get_selection_origin_line(i) - 1, true, -1, i); + // Fix selection if the last one ends at column 0, since it wasn't moved. + for (int i = 0; i < get_caret_count(); i++) { + if (has_selection(i) && get_selection_to_column(i) == 0 && get_selection_to_line(i) == line_range.y + 1) { + if (is_caret_after_selection_origin(i)) { + set_caret_line(get_caret_line(i) - 1, false, true, -1, i); + } else { + set_selection_origin_line(get_selection_origin_line(i) - 1, true, -1, i); + } + break; } } } + adjust_viewport_to_caret(); end_multicaret_edit(); end_complex_operation(); @@ -2352,30 +2353,41 @@ void CodeEdit::move_lines_down() { begin_complex_operation(); begin_multicaret_edit(); - Vector<Point2i> line_ranges = get_line_ranges_from_carets(); - - // Fix selection if it ended at column 0, since it won't be moved. - for (int i = 0; i < get_caret_count(); i++) { - if (has_selection(i) && get_selection_to_column(i) == 0 && get_selection_to_line(i) != get_line_count() - 1) { - if (is_caret_after_selection_origin(i)) { - set_caret_line(get_caret_line(i) + 1, false, true, -1, i); - } else { - set_selection_origin_line(get_selection_origin_line(i) + 1, true, -1, i); - } - } - } - // Move lines down by swapping each line with the one below it. + Vector<Point2i> line_ranges = get_line_ranges_from_carets(); + // Reverse in case line ranges are adjacent, if the first ends at column 0. + line_ranges.reverse(); for (Point2i line_range : line_ranges) { if (line_range.y == get_line_count() - 1) { continue; } + // Fix selection if the last one ends at column 0, since it won't be moved. + bool selection_to_line_at_end = false; + for (int i = 0; i < get_caret_count(); i++) { + if (has_selection(i) && get_selection_to_column(i) == 0 && get_selection_to_line(i) == line_range.y + 1) { + selection_to_line_at_end = get_selection_to_line(i) == get_line_count() - 1; + if (selection_to_line_at_end) { + break; + } + if (is_caret_after_selection_origin(i)) { + set_caret_line(get_caret_line(i) + 1, false, true, -1, i); + } else { + set_selection_origin_line(get_selection_origin_line(i) + 1, true, -1, i); + } + break; + } + } + if (selection_to_line_at_end) { + continue; + } + unfold_line(line_range.y + 1); for (int line = line_range.y; line >= line_range.x; line--) { unfold_line(line); swap_lines(line + 1, line); } } + adjust_viewport_to_caret(); end_multicaret_edit(); end_complex_operation(); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 233c7200ff..7b682daa83 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -472,7 +472,7 @@ String TextEdit::Text::get_custom_word_separators() const { } String TextEdit::Text::get_default_word_separators() const { - String concat_separators = "´`~$^=+|<>"; + String concat_separators = "!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~"; for (char32_t ch = 0x2000; ch <= 0x206F; ++ch) { // General punctuation block. concat_separators += ch; } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index ae8e2a493d..5bbf8ebff4 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2907,9 +2907,8 @@ void Node::_duplicate_properties(const Node *p_root, const Node *p_original, Nod arr[i] = p_copy->get_node_or_null(p_original->get_path_to(property_node)); } } - value = arr; - p_copy->set(name, value); } + p_copy->set(name, arr); } else { p_copy->set(name, value); } diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index b2567e431b..7d121c9d87 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -324,6 +324,21 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const { is_uniform_type_compatible = E->get().type == cached.get_type(); } +#ifndef DISABLE_DEPRECATED + // PackedFloat32Array -> PackedVector4Array conversion. + if (!is_uniform_type_compatible && E->get().type == Variant::PACKED_VECTOR4_ARRAY && cached.get_type() == Variant::PACKED_FLOAT32_ARRAY) { + PackedVector4Array varray; + PackedFloat32Array array = (PackedFloat32Array)cached; + + for (int i = 0; i + 3 < array.size(); i += 4) { + varray.push_back(Vector4(array[i], array[i + 1], array[i + 2], array[i + 3])); + } + + param_cache.insert(E->get().name, varray); + is_uniform_type_compatible = true; + } +#endif + if (is_uniform_type_compatible && E->get().type == Variant::OBJECT && cached.get_type() == Variant::OBJECT) { // Check if the Object class (hint string) changed, for example Texture2D sampler to Texture3D. // Allow inheritance, Texture2D type sampler should also accept CompressedTexture2D. diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp index d1c8c71b7f..13b00be1c4 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp @@ -1165,8 +1165,8 @@ MaterialStorage::MaterialStorage() { global_shader_uniforms.buffer_values = memnew_arr(GlobalShaderUniforms::Value, global_shader_uniforms.buffer_size); memset(global_shader_uniforms.buffer_values, 0, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size); global_shader_uniforms.buffer_usage = memnew_arr(GlobalShaderUniforms::ValueUsage, global_shader_uniforms.buffer_size); - global_shader_uniforms.buffer_dirty_regions = memnew_arr(bool, global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE); - memset(global_shader_uniforms.buffer_dirty_regions, 0, sizeof(bool) * global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE); + global_shader_uniforms.buffer_dirty_regions = memnew_arr(bool, 1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE)); + memset(global_shader_uniforms.buffer_dirty_regions, 0, sizeof(bool) * (1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE))); global_shader_uniforms.buffer = RD::get_singleton()->storage_buffer_create(sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size); } @@ -1769,7 +1769,7 @@ void MaterialStorage::global_shader_parameters_instance_update(RID p_instance, i void MaterialStorage::_update_global_shader_uniforms() { MaterialStorage *material_storage = MaterialStorage::get_singleton(); if (global_shader_uniforms.buffer_dirty_region_count > 0) { - uint32_t total_regions = global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE; + uint32_t total_regions = 1 + (global_shader_uniforms.buffer_size / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE); if (total_regions / global_shader_uniforms.buffer_dirty_region_count <= 4) { // 25% of regions dirty, just update all buffer RD::get_singleton()->buffer_update(global_shader_uniforms.buffer, 0, sizeof(GlobalShaderUniforms::Value) * global_shader_uniforms.buffer_size, global_shader_uniforms.buffer_values); diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 1e9690a8ae..5b4931edec 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -3982,12 +3982,9 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C } value = Variant(array); } else { - PackedFloat32Array array; + PackedVector4Array array; for (int i = 0; i < array_size; i += 4) { - array.push_back(p_value[i].real); - array.push_back(p_value[i + 1].real); - array.push_back(p_value[i + 2].real); - array.push_back(p_value[i + 3].real); + array.push_back(Vector4(p_value[i].real, p_value[i + 1].real, p_value[i + 2].real, p_value[i + 3].real)); } value = Variant(array); } @@ -4219,7 +4216,7 @@ PropertyInfo ShaderLanguage::uniform_to_property_info(const ShaderNode::Uniform if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { pi.type = Variant::PACKED_COLOR_ARRAY; } else { - pi.type = Variant::PACKED_FLOAT32_ARRAY; + pi.type = Variant::PACKED_VECTOR4_ARRAY; } } else { if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SOURCE_COLOR) { diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h index 317dbe9ab9..a166002cdd 100644 --- a/tests/scene/test_code_edit.h +++ b/tests/scene/test_code_edit.h @@ -4889,6 +4889,17 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK(code_edit->get_caret_line() == 0); CHECK(code_edit->get_caret_column() == 1); + // Does nothing at the first line when selection ends at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(0, 0, 1, 0); + code_edit->move_lines_up(); + CHECK(code_edit->get_text() == "test\nlines\nto\n\nmove\naround"); + CHECK(code_edit->has_selection()); + CHECK(code_edit->get_selection_origin_line() == 0); + CHECK(code_edit->get_selection_origin_column() == 0); + CHECK(code_edit->get_caret_line() == 1); + CHECK(code_edit->get_caret_column() == 0); + // Works on empty line. code_edit->set_text("test\nlines\nto\n\nmove\naround"); code_edit->set_caret_line(3); @@ -4950,9 +4961,9 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK_FALSE(code_edit->has_selection(2)); CHECK(code_edit->get_caret_line(2) == 3); CHECK(code_edit->get_caret_column(2) == 4); + code_edit->remove_secondary_carets(); // Move multiple separate lines with multiple selections. - code_edit->remove_secondary_carets(); code_edit->set_text("test\nlines\nto\n\nmove\naround"); code_edit->select(2, 2, 1, 4); code_edit->add_caret(5, 0); @@ -4970,6 +4981,44 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK(code_edit->get_selection_origin_column(1) == 0); CHECK(code_edit->get_caret_line(1) == 4); CHECK(code_edit->get_caret_column(1) == 1); + code_edit->remove_secondary_carets(); + + // Move lines with adjacent selections that end at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(1, 2, 2, 0); + code_edit->add_caret(2, 2); + code_edit->select(2, 2, 3, 0, 1); + code_edit->move_lines_up(); + CHECK(code_edit->get_text() == "lines\nto\ntest\n\nmove\naround"); + CHECK(code_edit->get_caret_count() == 2); + CHECK(code_edit->has_selection(0)); + CHECK(code_edit->get_selection_origin_line(0) == 0); + CHECK(code_edit->get_selection_origin_column(0) == 2); + CHECK(code_edit->get_caret_line(0) == 1); + CHECK(code_edit->get_caret_column(0) == 0); + CHECK(code_edit->has_selection(1)); + CHECK(code_edit->get_selection_origin_line(1) == 1); + CHECK(code_edit->get_selection_origin_column(1) == 2); + CHECK(code_edit->get_caret_line(1) == 2); + CHECK(code_edit->get_caret_column(1) == 0); + code_edit->remove_secondary_carets(); + code_edit->deselect(); + + code_edit->set_line_folding_enabled(true); + + // Move line up into a folded region unfolds it. + code_edit->set_text("test\n\tline1 test\n\t\tline 2\ntest2"); + code_edit->set_caret_line(3); + code_edit->set_caret_column(0); + code_edit->fold_line(0); + CHECK(code_edit->is_line_folded(0)); + code_edit->move_lines_up(); + CHECK(code_edit->get_caret_count() == 1); + CHECK_FALSE(code_edit->has_selection(0)); + CHECK(code_edit->get_caret_line() == 2); + CHECK(code_edit->get_caret_column() == 0); + CHECK(code_edit->get_text() == "test\n\tline1 test\ntest2\n\t\tline 2"); + CHECK_FALSE(code_edit->is_line_folded(0)); } SUBCASE("[SceneTree][CodeEdit] move lines down") { @@ -5004,6 +5053,17 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK(code_edit->get_caret_line() == 5); CHECK(code_edit->get_caret_column() == 1); + // Does nothing at the last line when selection ends at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(4, 0, 5, 0); + code_edit->move_lines_down(); + CHECK(code_edit->get_text() == "test\nlines\nto\n\nmove\naround"); + CHECK(code_edit->has_selection()); + CHECK(code_edit->get_selection_origin_line() == 4); + CHECK(code_edit->get_selection_origin_column() == 0); + CHECK(code_edit->get_caret_line() == 5); + CHECK(code_edit->get_caret_column() == 0); + // Works on empty line. code_edit->set_text("test\nlines\nto\n\nmove\naround"); code_edit->set_caret_line(3); @@ -5085,6 +5145,64 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK(code_edit->get_selection_origin_column(1) == 0); CHECK(code_edit->get_caret_line(1) == 5); CHECK(code_edit->get_caret_column(1) == 2); + + // Move lines with adjacent selections that end at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(1, 2, 2, 0); + code_edit->add_caret(2, 2); + code_edit->select(2, 2, 3, 0, 1); + code_edit->move_lines_down(); + CHECK(code_edit->get_text() == "test\n\nlines\nto\nmove\naround"); + CHECK(code_edit->get_caret_count() == 2); + CHECK(code_edit->has_selection(0)); + CHECK(code_edit->get_selection_origin_line(0) == 2); + CHECK(code_edit->get_selection_origin_column(0) == 2); + CHECK(code_edit->get_caret_line(0) == 3); + CHECK(code_edit->get_caret_column(0) == 0); + CHECK(code_edit->has_selection(1)); + CHECK(code_edit->get_selection_origin_line(1) == 3); + CHECK(code_edit->get_selection_origin_column(1) == 2); + CHECK(code_edit->get_caret_line(1) == 4); + CHECK(code_edit->get_caret_column(1) == 0); + code_edit->remove_secondary_carets(); + + // Move lines with disconnected adjacent selections that end at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(0, 2, 1, 0); + code_edit->add_caret(2, 2); + code_edit->select(2, 0, 3, 0, 1); + code_edit->move_lines_down(); + CHECK(code_edit->get_text() == "lines\ntest\n\nto\nmove\naround"); + CHECK(code_edit->get_caret_count() == 2); + CHECK(code_edit->has_selection(0)); + CHECK(code_edit->get_selection_origin_line(0) == 1); + CHECK(code_edit->get_selection_origin_column(0) == 2); + CHECK(code_edit->get_caret_line(0) == 2); + CHECK(code_edit->get_caret_column(0) == 0); + CHECK(code_edit->has_selection(1)); + CHECK(code_edit->get_selection_origin_line(1) == 3); + CHECK(code_edit->get_selection_origin_column(1) == 0); + CHECK(code_edit->get_caret_line(1) == 4); + CHECK(code_edit->get_caret_column(1) == 0); + code_edit->remove_secondary_carets(); + code_edit->deselect(); + + code_edit->set_line_folding_enabled(true); + + // Move line down into a folded region unfolds it. + code_edit->set_text("test\ntest2\n\tline1 test\n\t\tline 2\ntest2"); + code_edit->set_caret_line(0); + code_edit->set_caret_column(0); + code_edit->fold_line(1); + CHECK(code_edit->is_line_folded(1)); + code_edit->move_lines_down(); + CHECK(code_edit->get_caret_count() == 1); + CHECK_FALSE(code_edit->has_selection(0)); + CHECK(code_edit->get_caret_line() == 1); + CHECK(code_edit->get_caret_column() == 0); + CHECK(code_edit->get_text() == "test2\ntest\n\tline1 test\n\t\tline 2\ntest2"); + CHECK_FALSE(code_edit->is_line_folded(0)); + CHECK_FALSE(code_edit->is_line_folded(1)); } SUBCASE("[SceneTree][CodeEdit] delete lines") { diff --git a/thirdparty/README.md b/thirdparty/README.md index 93469f69bb..4572687be2 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -882,7 +882,7 @@ instead of `miniz.h` as an external dependency. ## thorvg - Upstream: https://github.com/thorvg/thorvg -- Version: 0.13.7 (d2c0428a99f7305c086caffe0c730add601ebd6e, 2024) +- Version: 0.14.0 (ae4e9d003c93325f1eba64319fa9852a0d764b4c, 2024) - License: MIT Files extracted from upstream source: diff --git a/thirdparty/thorvg/AUTHORS b/thirdparty/thorvg/AUTHORS index da58481032..e00e91a696 100644 --- a/thirdparty/thorvg/AUTHORS +++ b/thirdparty/thorvg/AUTHORS @@ -1,10 +1,10 @@ -Hermet Park <hermet@lottiefiles.com>, <chuneon.park@samsung.com> +Hermet Park <hermet@lottiefiles.com> Prudhvi Raj Vasireddi <prudhvi.raj@samsung.com> Junsu Choi <jsuya.choi@samsung.com> Pranay Samanta <pranay.ks@samsung.com> Mateusz Palkowski <m.palkowski@samsung.com> Subhransu Mohanty <sub.mohanty@samsung.com> -Mira Grudzinska <veleveta@gmail.com>, <m.grudzinska@samsung.com> +Mira Grudzinska <mira@lottiefiles.com> Michal Szczecinski <m.szczecinsk@partner.samsung.com> Shinwoo Kim <cinoo.kim@samsung.com> Piotr Kalota <p.kalota@samsung.com> @@ -27,3 +27,7 @@ Jinny You <jinny@lottiefiles.com> Nattu Adnan <nattu@reallynattu.com> Gabor Kiss-Vamosi <kisvegabor@gmail.com> Lorcán Mc Donagh <lorcan@lmdsp.com> +Lucas Niu <hoiyu3twon9@gmail.com> +Francisco Ramírez <franchuti688@gmail.com> +Abdelrahman Ashraf <a.theashraf@gmail.com> +Neo Xu <neo.xu1990@gmail.com> diff --git a/thirdparty/thorvg/inc/config.h b/thirdparty/thorvg/inc/config.h index fc7f3ac36d..6218c18e68 100644 --- a/thirdparty/thorvg/inc/config.h +++ b/thirdparty/thorvg/inc/config.h @@ -15,5 +15,5 @@ // For internal debugging: //#define THORVG_LOG_ENABLED -#define THORVG_VERSION_STRING "0.13.8" +#define THORVG_VERSION_STRING "0.14.0" #endif diff --git a/thirdparty/thorvg/inc/thorvg.h b/thirdparty/thorvg/inc/thorvg.h index 8285aa1c4c..0b7e9771b9 100644 --- a/thirdparty/thorvg/inc/thorvg.h +++ b/thirdparty/thorvg/inc/thorvg.h @@ -72,6 +72,10 @@ class Animation; /** * @brief Enumeration specifying the result from the APIs. + * + * All ThorVG APIs could potentially return one of the values in the list. + * Please note that some APIs may additionally specify the reasons that trigger their return values. + * */ enum class Result { @@ -157,7 +161,7 @@ enum class CompositeMethod AlphaMask, ///< Alpha Masking using the compositing target's pixels as an alpha value. InvAlphaMask, ///< Alpha Masking using the complement to the compositing target's pixels as an alpha value. LumaMask, ///< Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the compositing target's pixels. @since 0.9 - InvLumaMask, ///< Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the complement to the compositing target's pixels. + InvLumaMask, ///< Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the complement to the compositing target's pixels. @since 0.11 AddMask, ///< Combines the target and source objects pixels using target alpha. (T * TA) + (S * (255 - TA)) (Experimental API) SubtractMask, ///< Subtracts the source color from the target color while considering their respective target alpha. (T * TA) - (S * (255 - TA)) (Experimental API) IntersectMask, ///< Computes the result by taking the minimum value between the target alpha and the source alpha and multiplies it with the target color. (T * min(TA, SA)) (Experimental API) @@ -277,8 +281,6 @@ public: * The rotational axis passes through the point on the object with zero coordinates. * * @param[in] degree The value of the angle in degrees. - * - * @retval Result::Success when succeed, Result::FailedAllocation otherwise. */ Result rotate(float degree) noexcept; @@ -286,8 +288,6 @@ public: * @brief Sets the scale value of the object. * * @param[in] factor The value of the scaling factor. The default value is 1. - * - * @retval Result::Success when succeed, Result::FailedAllocation otherwise. */ Result scale(float factor) noexcept; @@ -299,8 +299,6 @@ public: * * @param[in] x The value of the horizontal shift. * @param[in] y The value of the vertical shift. - * - * @retval Result::Success when succeed, Result::FailedAllocation otherwise. */ Result translate(float x, float y) noexcept; @@ -310,8 +308,6 @@ public: * The augmented matrix of the transformation is expected to be given. * * @param[in] m The 3x3 augmented matrix. - * - * @retval Result::Success when succeed, Result::FailedAllocation otherwise. */ Result transform(const Matrix& m) noexcept; @@ -332,8 +328,6 @@ public: * * @param[in] o The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. * - * @retval Result::Success when succeed. - * * @note Setting the opacity with this API may require multiple render pass for composition. It is recommended to avoid changing the opacity if possible. * @note ClipPath won't use the opacity value. (see: enum class CompositeMethod::ClipPath) */ @@ -344,8 +338,6 @@ public: * * @param[in] target The paint of the target object. * @param[in] method The method used to composite the source object with the target. - * - * @retval Result::Success when succeed, Result::InvalidArguments otherwise. */ Result composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept; @@ -358,24 +350,11 @@ public: * * @param[in] method The blending method to be set. * - * @retval Result::Success when the blending method is successfully set. - * * @note Experimental API */ Result blend(BlendMethod method) const noexcept; /** - * @brief Gets the bounding box of the paint object before any transformation. - * - * @param[out] x The x coordinate of the upper left corner of the object. - * @param[out] y The y coordinate of the upper left corner of the object. - * @param[out] w The width of the object. - * @param[out] h The height of the object. - * - * @return Result::Success when succeed, Result::InsufficientCondition otherwise. - * - * @note The bounding box doesn't indicate the final rendered region. It's the smallest rectangle that encloses the object. - * @see Paint::bounds(float* x, float* y, float* w, float* h, bool transformed); * @deprecated Use bounds(float* x, float* y, float* w, float* h, bool transformed) instead */ TVG_DEPRECATED Result bounds(float* x, float* y, float* w, float* h) const noexcept; @@ -391,8 +370,6 @@ public: * @param[out] h The height of the object. * @param[in] transformed If @c true, the paint's transformations are taken into account, otherwise they aren't. * - * @retval Result::Success when succeed, Result::InsufficientCondition otherwise. - * * @note The bounding box doesn't indicate the actual drawing region. It's the smallest rectangle that encloses the object. */ Result bounds(float* x, float* y, float* w, float* h, bool transformed) const noexcept; @@ -479,8 +456,6 @@ public: * * @param[in] colorStops An array of ColorStop data structure. * @param[in] cnt The count of the @p colorStops array equal to the colors number used in the gradient. - * - * @retval Result::Success when succeed. */ Result colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept; @@ -488,8 +463,6 @@ public: * @brief Sets the FillSpread value, which specifies how to fill the area outside the gradient bounds. * * @param[in] s The FillSpread value. - * - * @retval Result::Success when succeed. */ Result spread(FillSpread s) noexcept; @@ -499,8 +472,6 @@ public: * The augmented matrix of the transformation is expected to be given. * * @param[in] m The 3x3 augmented matrix. - * - * @retval Result::Success when succeed, Result::FailedAllocation otherwise. */ Result transform(const Matrix& m) noexcept; @@ -567,16 +538,6 @@ public: Canvas(RenderMethod*); virtual ~Canvas(); - /** - * @brief Sets the size of the container, where all the paints pushed into the Canvas are stored. - * - * If the number of objects pushed into the Canvas is known in advance, calling the function - * prevents multiple memory reallocation, thus improving the performance. - * - * @param[in] n The number of objects for which the memory is to be reserved. - * - * @return Result::Success when succeed. - */ TVG_DEPRECATED Result reserve(uint32_t n) noexcept; /** @@ -599,9 +560,7 @@ public: * * @param[in] paint A Paint object to be drawn. * - * @retval Result::Success When succeed. * @retval Result::MemoryCorruption In case a @c nullptr is passed as the argument. - * @retval Result::InsufficientCondition An internal error. * * @note The rendering order of the paints is the same as the order as they were pushed into the canvas. Consider sorting the paints before pushing them if you intend to use layering. * @see Canvas::paints() @@ -618,7 +577,6 @@ public: * * @param[in] free If @c true, the memory occupied by paints is deallocated, otherwise it is not. * - * @retval Result::Success when succeed, Result::InsufficientCondition otherwise. * * @see Canvas::push() * @see Canvas::paints() @@ -633,8 +591,6 @@ public: * * @param[in] paint A pointer to the Paint object or @c nullptr. * - * @retval Result::Success when succeed, Result::InsufficientCondition otherwise. - * * @note The Update behavior can be asynchronous if the assigned thread number is greater than zero. */ virtual Result update(Paint* paint = nullptr) noexcept; @@ -642,8 +598,6 @@ public: /** * @brief Requests the canvas to draw the Paint objects. * - * @retval Result::Success when succeed, Result::InsufficientCondition otherwise. - * * @note Drawing can be asynchronous if the assigned thread number is greater than zero. To guarantee the drawing is done, call sync() afterwards. * @see Canvas::sync() */ @@ -660,8 +614,6 @@ public: * @param[in] w The width of the rectangle. * @param[in] h The height of the rectangle. * - * @retval Result::Success when succeed, Result::InsufficientCondition otherwise. - * * @see SwCanvas::target() * @see GlCanvas::target() * @see WgCanvas::target() @@ -679,7 +631,6 @@ public: * The Canvas rendering can be performed asynchronously. To make sure that rendering is finished, * the sync() must be called after the draw() regardless of threading. * - * @retval Result::Success when succeed, Result::InsufficientCondition otherwise. * @see Canvas::draw() */ virtual Result sync() noexcept; @@ -713,8 +664,6 @@ public: * @param[in] x2 The horizontal coordinate of the second point used to determine the gradient bounds. * @param[in] y2 The vertical coordinate of the second point used to determine the gradient bounds. * - * @retval Result::Success when succeed. - * * @note In case the first and the second points are equal, an object filled with such a gradient fill is not rendered. */ Result linear(float x1, float y1, float x2, float y2) noexcept; @@ -730,8 +679,6 @@ public: * @param[out] y1 The vertical coordinate of the first point used to determine the gradient bounds. * @param[out] x2 The horizontal coordinate of the second point used to determine the gradient bounds. * @param[out] y2 The vertical coordinate of the second point used to determine the gradient bounds. - * - * @retval Result::Success when succeed. */ Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept; @@ -775,7 +722,7 @@ public: * @param[in] cy The vertical coordinate of the center of the bounding circle. * @param[in] radius The radius of the bounding circle. * - * @retval Result::Success when succeed, Result::InvalidArguments in case the @p radius value is zero or less. + * @retval Result::InvalidArguments in case the @p radius value is zero or less. */ Result radial(float cx, float cy, float radius) noexcept; @@ -788,7 +735,6 @@ public: * @param[out] cy The vertical coordinate of the center of the bounding circle. * @param[out] radius The radius of the bounding circle. * - * @retval Result::Success when succeed. */ Result radial(float* cx, float* cy, float* radius) const noexcept; @@ -834,8 +780,6 @@ public: * * The transformation matrix, the color, the fill and the stroke properties are retained. * - * @retval Result::Success when succeed. - * * @note The memory, where the path data is stored, is not deallocated at this stage for caching effect. */ Result reset() noexcept; @@ -847,8 +791,6 @@ public: * * @param[in] x The horizontal coordinate of the initial point of the sub-path. * @param[in] y The vertical coordinate of the initial point of the sub-path. - * - * @retval Result::Success when succeed. */ Result moveTo(float x, float y) noexcept; @@ -860,8 +802,6 @@ public: * @param[in] x The horizontal coordinate of the end-point of the line. * @param[in] y The vertical coordinate of the end-point of the line. * - * @retval Result::Success when succeed. - * * @note In case this is the first command in the path, it corresponds to the moveTo() call. */ Result lineTo(float x, float y) noexcept; @@ -879,8 +819,6 @@ public: * @param[in] x The horizontal coordinate of the end-point of the curve. * @param[in] y The vertical coordinate of the end-point of the curve. * - * @retval Result::Success when succeed. - * * @note In case this is the first command in the path, no data from the path are rendered. */ Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept; @@ -890,8 +828,6 @@ public: * * The value of the current point is set to the initial point of the closed sub-path. * - * @retval Result::Success when succeed. - * * @note In case the sub-path does not contain any points, this function has no effect. */ Result close() noexcept; @@ -916,8 +852,6 @@ public: * @param[in] rx The x-axis radius of the ellipse defining the rounded corners of the rectangle. * @param[in] ry The y-axis radius of the ellipse defining the rounded corners of the rectangle. * - * @retval Result::Success when succeed. - * * @note For @p rx and @p ry greater than or equal to the half of @p w and the half of @p h, respectively, the shape become an ellipse. */ Result appendRect(float x, float y, float w, float h, float rx = 0, float ry = 0) noexcept; @@ -936,7 +870,6 @@ public: * @param[in] rx The x-axis radius of the ellipse. * @param[in] ry The y-axis radius of the ellipse. * - * @retval Result::Success when succeed. */ Result appendCircle(float cx, float cy, float rx, float ry) noexcept; @@ -953,8 +886,6 @@ public: * @param[in] sweep The central angle of the arc given in degrees, measured counter-clockwise from @p startAngle. * @param[in] pie Specifies whether to draw radii from the arc's center to both of its end-point - drawn if @c true. * - * @retval Result::Success when succeed. - * * @note Setting @p sweep value greater than 360 degrees, is equivalent to calling appendCircle(cx, cy, radius, radius). */ Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept; @@ -971,8 +902,6 @@ public: * @param[in] pts The array of the two-dimensional points. * @param[in] ptsCnt The number of the points in the @p pts array. * - * @retval Result::Success when succeed, Result::InvalidArguments otherwise. - * * @note The interface is designed for optimal path setting if the caller has a completed path commands already. */ Result appendPath(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept; @@ -982,7 +911,6 @@ public: * * @param[in] width The width of the stroke. The default value is 0. * - * @retval Result::Success when succeed. */ Result stroke(float width) noexcept; @@ -994,7 +922,6 @@ public: * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0. * - * @retval Result::Success when succeed. */ Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept; @@ -1003,8 +930,7 @@ public: * * @param[in] f The gradient fill. * - * @retval Result::Success When succeed. - * @retval Result::MemoryCorruption In case a @c nullptr is passed as the argument or an error with accessing it. + * @retval Result::MemoryCorruption In case a @c nullptr is passed as the argument. */ Result stroke(std::unique_ptr<Fill> f) noexcept; @@ -1014,8 +940,6 @@ public: * @param[in] dashPattern The array of consecutive pair values of the dash length and the gap length. * @param[in] cnt The length of the @p dashPattern array. * - * @retval Result::Success When succeed. - * @retval Result::FailedAllocation An internal error with a memory allocation for an object to be dashed. * @retval Result::InvalidArguments In case @p dashPattern is @c nullptr and @p cnt > 0, @p cnt is zero, any of the dash pattern values is zero or less. * * @note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt. @@ -1028,7 +952,6 @@ public: * * @param[in] cap The cap style value. The default value is @c StrokeCap::Square. * - * @retval Result::Success when succeed. */ Result stroke(StrokeCap cap) noexcept; @@ -1039,7 +962,6 @@ public: * * @param[in] join The join style value. The default value is @c StrokeJoin::Bevel. * - * @retval Result::Success when succeed. */ Result stroke(StrokeJoin join) noexcept; @@ -1048,7 +970,7 @@ public: * * @param[in] miterlimit The miterlimit imposes a limit on the extent of the stroke join, when the @c StrokeJoin::Miter join style is set. The default value is 4. * - * @retval Result::Success when succeed or Result::InvalidArgument for @p miterlimit values less than zero. + * @retval Result::InvalidArgument for @p miterlimit values less than zero. * * @since 0.11 */ @@ -1064,8 +986,6 @@ public: * @param[in] simultaneous Determines how to trim multiple paths within a single shape. If set to @c true (default), trimming is applied simultaneously to all paths; * Otherwise, all paths are treated as a single entity with a combined length equal to the sum of their individual lengths and are trimmed as such. * - * @retval Result::Success when succeed. - * * @note Experimental API */ Result strokeTrim(float begin, float end, bool simultaneous = true) noexcept; @@ -1080,8 +1000,6 @@ public: * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0. * - * @retval Result::Success when succeed. - * * @note Either a solid color or a gradient fill is applied, depending on what was set as last. * @note ClipPath won't use the fill values. (see: enum class CompositeMethod::ClipPath) */ @@ -1094,8 +1012,6 @@ public: * * @param[in] f The unique pointer to the gradient fill. * - * @retval Result::Success when succeed, Result::MemoryCorruption otherwise. - * * @note Either a solid color or a gradient fill is applied, depending on what was set as last. */ Result fill(std::unique_ptr<Fill> f) noexcept; @@ -1104,8 +1020,6 @@ public: * @brief Sets the fill rule for the Shape object. * * @param[in] r The fill rule value. The default value is @c FillRule::Winding. - * - * @retval Result::Success when succeed. */ Result fill(FillRule r) noexcept; @@ -1114,8 +1028,6 @@ public: * * @param[in] strokeFirst If @c true the stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the default option). * - * @retval Result::Success when succeed. - * * @since 0.10 */ Result order(bool strokeFirst) noexcept; @@ -1179,7 +1091,6 @@ public: * @param[out] b The blue color channel value in the range [0 ~ 255]. * @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. * - * @retval Result::Success when succeed, Result::InsufficientCondition otherwise. */ Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const noexcept; @@ -1228,7 +1139,7 @@ public: * @param[out] begin The starting point of the segment to display along the path. * @param[out] end Specifies the end of the segment to display along the path. * - * @retval @c true if trimming is applied simultaneously to all paths of the shape, @c false otherwise. + * @return @c true if trimming is applied simultaneously to all paths of the shape, @c false otherwise. * * @note Experimental API */ @@ -1277,10 +1188,8 @@ public: * * @param[in] path A path to the picture file. * - * @retval Result::Success When succeed. * @retval Result::InvalidArguments In case the @p path is invalid. * @retval Result::NonSupport When trying to load a file with an unknown extension. - * @retval Result::Unknown If an error occurs at a later stage. * * @note The Load behavior can be asynchronous if the assigned thread number is greater than zero. * @see Initializer::init() @@ -1288,41 +1197,26 @@ public: Result load(const std::string& path) noexcept; /** - * @brief Loads a picture data from a memory block of a given size. - * - * ThorVG efficiently caches the loaded data using the specified @p data address as a key - * when the @p copy has @c false. This means that loading the same data again will not result in duplicate operations - * for the sharable @p data. Instead, ThorVG will reuse the previously loaded picture data. - * - * @param[in] data A pointer to a memory location where the content of the picture file is stored. - * @param[in] size The size in bytes of the memory occupied by the @p data. - * @param[in] copy Decides whether the data should be copied into the engine local buffer. - * - * @retval Result::Success When succeed. - * @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less. - * @retval Result::NonSupport When trying to load a file with an unknown extension. - * @retval Result::Unknown If an error occurs at a later stage. - * - * @warning: you have responsibility to release the @p data memory if the @p copy is true * @deprecated Use load(const char* data, uint32_t size, const std::string& mimeType, bool copy) instead. - * @see Result load(const char* data, uint32_t size, const std::string& mimeType, bool copy = false) noexcept */ TVG_DEPRECATED Result load(const char* data, uint32_t size, bool copy = false) noexcept; /** * @brief Loads a picture data from a memory block of a given size. * + * ThorVG efficiently caches the loaded data using the specified @p data address as a key + * when the @p copy has @c false. This means that loading the same data again will not result in duplicate operations + * for the sharable @p data. Instead, ThorVG will reuse the previously loaded picture data. + * * @param[in] data A pointer to a memory location where the content of the picture file is stored. * @param[in] size The size in bytes of the memory occupied by the @p data. * @param[in] mimeType Mimetype or extension of data such as "jpg", "jpeg", "lottie", "svg", "svg+xml", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one. * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not. * - * @retval Result::Success When succeed. * @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less. * @retval Result::NonSupport When trying to load a file with an unknown extension. - * @retval Result::Unknown If an error occurs at a later stage. * - * @warning: It's the user responsibility to release the @p data memory if the @p copy is @c true. + * @warning: It's the user responsibility to release the @p data memory. * * @note If you are unsure about the MIME type, you can provide an empty value like @c "", and thorvg will attempt to figure it out. * @since 0.5 @@ -1338,7 +1232,6 @@ public: * @param[in] w A new width of the image in pixels. * @param[in] h A new height of the image in pixels. * - * @retval Result::Success when succeed, Result::InsufficientCondition otherwise. */ Result size(float w, float h) noexcept; @@ -1348,7 +1241,6 @@ public: * @param[out] w The width of the image in pixels. * @param[out] h The height of the image in pixels. * - * @retval Result::Success when succeed. */ Result size(float* w, float* h) const noexcept; @@ -1359,16 +1251,12 @@ public: * when the @p copy has @c false. This means that loading the same data again will not result in duplicate operations * for the sharable @p data. Instead, ThorVG will reuse the previously loaded picture data. * - * @param[in] paint A Tvg_Paint pointer to the picture object. * @param[in] data A pointer to a memory location where the content of the picture raw data is stored. * @param[in] w The width of the image @p data in pixels. * @param[in] h The height of the image @p data in pixels. * @param[in] premultiplied If @c true, the given image data is alpha-premultiplied. * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not. * - * @retval Result::Success When succeed, Result::InsufficientCondition otherwise. - * @retval Result::FailedAllocation An internal error possibly with memory allocation. - * * @since 0.9 */ Result load(uint32_t* data, uint32_t w, uint32_t h, bool copy) noexcept; @@ -1387,9 +1275,6 @@ public: * @param[in] triangles An array of Polygons(triangles) that make up the mesh, or null to remove the mesh. * @param[in] triangleCnt The number of Polygons(triangles) provided, or 0 to remove the mesh. * - * @retval Result::Success When succeed. - * @retval Result::Unknown If fails - * * @note The Polygons are copied internally, so modifying them after calling Mesh::mesh has no affect. * @warning Please do not use it, this API is not official one. It could be modified in the next version. * @@ -1456,24 +1341,12 @@ public: * * @param[in] paint A Paint object to be drawn. * - * @retval Result::Success when succeed, Result::MemoryCorruption otherwise. - * * @note The rendering order of the paints is the same as the order as they were pushed. Consider sorting the paints before pushing them if you intend to use layering. * @see Scene::paints() * @see Scene::clear() */ Result push(std::unique_ptr<Paint> paint) noexcept; - /** - * @brief Sets the size of the container, where all the paints pushed into the Scene are stored. - * - * If the number of objects pushed into the scene is known in advance, calling the function - * prevents multiple memory reallocation, thus improving the performance. - * - * @param[in] size The number of objects for which the memory is to be reserved. - * - * @return Result::Success when succeed, Result::FailedAllocation otherwise. - */ TVG_DEPRECATED Result reserve(uint32_t size) noexcept; /** @@ -1496,8 +1369,6 @@ public: * * @param[in] free If @c true, the memory occupied by paints is deallocated, otherwise it is not. * - * @retval Result::Success when succeed - * * @warning If you don't free the paints they become dangled. They are supposed to be reused, otherwise you are responsible for their lives. Thus please use the @p free argument only when you know how it works, otherwise it's not recommended. * * @since 0.2 @@ -1547,7 +1418,6 @@ public: * @param[in] style The style of the font. It can be used to set the font to 'italic'. * If not specified, the default style is used. Only 'italic' style is supported currently. * - * @retval Result::Success when the font properties are set successfully. * @retval Result::InsufficientCondition when the specified @p name cannot be found. * * @note Experimental API @@ -1562,8 +1432,6 @@ public: * * @param[in] text The multi-byte text encoded with utf8 string to be rendered. * - * @retval Result::Success when succeed. - * * @note Experimental API */ Result text(const char* text) noexcept; @@ -1575,7 +1443,6 @@ public: * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. * - * @retval Result::Success when succeed. * @retval Result::InsufficientCondition when the font has not been set up prior to this operation. * * @see Text::font() @@ -1591,7 +1458,6 @@ public: * * @param[in] f The unique pointer to the gradient fill. * - * @retval Result::Success when succeed, Result::MemoryCorruption otherwise. * @retval Result::InsufficientCondition when the font has not been set up prior to this operation. * * @note Either a solid color or a gradient fill is applied, depending on what was set as last. @@ -1602,7 +1468,7 @@ public: Result fill(std::unique_ptr<Fill> f) noexcept; /** - * @brief Loads a scalable font data(ttf) from a file. + * @brief Loads a scalable font data (ttf) from a file. * * ThorVG efficiently caches the loaded data using the specified @p path as a key. * This means that loading the same file again will not result in duplicate operations; @@ -1610,10 +1476,8 @@ public: * * @param[in] path The path to the font file. * - * @retval Result::Success When succeed. * @retval Result::InvalidArguments In case the @p path is invalid. * @retval Result::NonSupport When trying to load a file with an unknown extension. - * @retval Result::Unknown If an error occurs at a later stage. * * @note Experimental API * @@ -1622,13 +1486,39 @@ public: static Result load(const std::string& path) noexcept; /** + * @brief Loads a scalable font data (ttf) from a memory block of a given size. + * + * ThorVG efficiently caches the loaded font data using the specified @p name as a key. + * This means that loading the same fonts again will not result in duplicate operations. + * Instead, ThorVG will reuse the previously loaded font data. + * + * @param[in] name The name under which the font will be stored and accessible (e.x. in a @p font() API). + * @param[in] data A pointer to a memory location where the content of the font data is stored. + * @param[in] size The size in bytes of the memory occupied by the @p data. + * @param[in] mimeType Mimetype or extension of font data. In case an empty string is provided the loader will be determined automatically. + * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not (default). + * + * @retval Result::InvalidArguments If no name is provided or if @p size is zero while @p data points to a valid memory location. + * @retval Result::NonSupport When trying to load a file with an unsupported extension. + * @retval Result::InsufficientCondition If attempting to unload the font data that has not been previously loaded. + * + * @warning: It's the user responsibility to release the @p data memory. + * + * @note To unload the font data loaded using this API, pass the proper @p name and @c nullptr as @p data. + * @note If you are unsure about the MIME type, you can provide an empty value like @c "", and thorvg will attempt to figure it out. + * @note Experimental API + * + * @see Text::font(const char* name, float size, const char* style) + */ + static Result load(const char* name, const char* data, uint32_t size, const std::string& mimeType = "ttf", bool copy = false) noexcept; + + /** * @brief Unloads the specified scalable font data (TTF) that was previously loaded. * * This function is used to release resources associated with a font file that has been loaded into memory. * * @param[in] path The file path of the loaded font. * - * @retval Result::Success Successfully unloads the font data. * @retval Result::InsufficientCondition Fails if the loader is not initialized. * * @note If the font data is currently in use, it will not be immediately unloaded. @@ -1703,14 +1593,14 @@ public: * @param[in] h The height of the raster image. * @param[in] cs The value specifying the way the 32-bits colors should be read/written. * - * @retval Result::Success When succeed. - * @retval Result::MemoryCorruption When casting in the internal function implementation failed. * @retval Result::InvalidArguments In case no valid pointer is provided or the width, or the height or the stride is zero. + * @retval Result::InsufficientCondition if the canvas is performing rendering. Please ensure the canvas is synced. * @retval Result::NonSupport In case the software engine is not supported. * * @warning Do not access @p buffer during Canvas::push() - Canvas::sync(). It should not be accessed while the engine is writing on it. * * @see Canvas::viewport() + * @see Canvas::sync() */ Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept; @@ -1726,7 +1616,6 @@ public: * * @param[in] policy The method specifying the Memory Pool behavior. The default value is @c MempoolPolicy::Default. * - * @retval Result::Success When succeed. * @retval Result::InsufficientCondition If the canvas contains some paints already. * @retval Result::NonSupport In case the software engine is not supported. * @@ -1756,7 +1645,7 @@ public: * * @warning Please do not use it. This class is not fully supported yet. * - * @note Experimental API + * @since 0.14 */ class TVG_API GlCanvas final : public Canvas { @@ -1773,10 +1662,11 @@ public: * @param[in] w The width (in pixels) of the raster image. * @param[in] h The height (in pixels) of the raster image. * - * @warning This API is experimental and not officially supported. It may be modified or removed in future versions. - * @warning Drawing on the main surface is currently not permitted. If the identifier (@p id) is set to @c 0, the operation will be aborted. + * @retval Result::InsufficientCondition if the canvas is performing rendering. Please ensure the canvas is synced. + * @retval Result::NonSupport In case the gl engine is not supported. * * @see Canvas::viewport() + * @see Canvas::sync() * * @note Currently, this only allows the GL_RGBA8 color space format. * @note Experimental API @@ -1788,7 +1678,7 @@ public: * * @return A new GlCanvas object. * - * @note Experimental API + * @since 0.14 */ static std::unique_ptr<GlCanvas> gen() noexcept; @@ -1811,14 +1701,22 @@ public: ~WgCanvas(); /** - * @brief Sets the target window for the rasterization. + * @brief Sets the drawing target for the rasterization. * - * @warning Please do not use it, this API is not official one. It could be modified in the next version. + * @param[in] instance WGPUInstance, context for all other wgpu objects. + * @param[in] surface WGPUSurface, handle to a presentable surface. + * @param[in] w The width of the surface. + * @param[in] h The height of the surface. + * + * @retval Result::InsufficientCondition if the canvas is performing rendering. Please ensure the canvas is synced. + * @retval Result::NonSupport In case the wg engine is not supported. * * @note Experimental API + * * @see Canvas::viewport() + * @see Canvas::sync() */ - Result target(void* window, uint32_t w, uint32_t h) noexcept; + Result target(void* instance, void* surface, uint32_t w, uint32_t h) noexcept; /** * @brief Creates a new WgCanvas object. @@ -1852,11 +1750,7 @@ public: * @param[in] engine The engine types to initialize. This is relative to the Canvas types, in which it will be used. For multiple backends bitwise operation is allowed. * @param[in] threads The number of additional threads. Zero indicates only the main thread is to be used. * - * @retval Result::Success When succeed. - * @retval Result::FailedAllocation An internal error possibly with memory allocation. - * @retval Result::InvalidArguments If unknown engine type chosen. * @retval Result::NonSupport In case the engine type is not supported on the system. - * @retval Result::Unknown Others. * * @note The Initializer keeps track of the number of times it was called. Threads count is fixed at the first init() call. * @see Initializer::term() @@ -1868,11 +1762,8 @@ public: * * @param[in] engine The engine types to terminate. This is relative to the Canvas types, in which it will be used. For multiple backends bitwise operation is allowed * - * @retval Result::Success When succeed. * @retval Result::InsufficientCondition In case there is nothing to be terminated. - * @retval Result::InvalidArguments If unknown engine type chosen. * @retval Result::NonSupport In case the engine type is not supported on the system. - * @retval Result::Unknown Others. * * @note Initializer does own reference counting for multiple calls. * @see Initializer::init() @@ -1903,7 +1794,6 @@ public: * * @param[in] no The index of the animation frame to be displayed. The index should be less than the totalFrame(). * - * @retval Result::Success Successfully set the frame. * @retval Result::InsufficientCondition if the given @p no is the same as the current frame value. * @retval Result::NonSupport The current Picture data does not support animations. * @@ -1975,9 +1865,7 @@ public: * @param[in] begin segment start. * @param[in] end segment end. * - * @retval Result::Success When succeed. * @retval Result::InsufficientCondition In case the animation is not loaded. - * @retval Result::InvalidArguments When the given parameter is invalid. * @retval Result::NonSupport When it's not animatable. * * @note Range from 0.0~1.0 @@ -1993,9 +1881,7 @@ public: * @param[out] begin segment start. * @param[out] end segment end. * - * @retval Result::Success When succeed. * @retval Result::InsufficientCondition In case the animation is not loaded. - * @retval Result::InvalidArguments When the given parameter is invalid. * @retval Result::NonSupport When it's not animatable. * * @note Experimental API @@ -2056,10 +1942,8 @@ public: * @param[in] path A path to the file, in which the paint data is to be saved. * @param[in] compress If @c true then compress data if possible. * - * @retval Result::Success When succeed. * @retval Result::InsufficientCondition If currently saving other resources. * @retval Result::NonSupport When trying to save a file with an unknown extension or in an unsupported format. - * @retval Result::MemoryCorruption An internal error. * @retval Result::Unknown In case an empty paint is to be saved. * * @note Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call sync() afterwards. @@ -2079,10 +1963,8 @@ public: * @param[in] quality The encoded quality level. @c 0 is the minimum, @c 100 is the maximum value(recommended). * @param[in] fps The desired frames per second (FPS). For example, to encode data at 60 FPS, pass 60. Pass 0 to keep the original frame data. * - * @retval Result::Success if the export succeeds. * @retval Result::InsufficientCondition if there are ongoing resource-saving operations. * @retval Result::NonSupport if an attempt is made to save the file with an unknown extension or in an unsupported format. - * @retval Result::MemoryCorruption in case of an internal error. * @retval Result::Unknown if attempting to save an empty paint. * * @note A higher frames per second (FPS) would result in a larger file size. It is recommended to use the default value. @@ -2101,9 +1983,6 @@ public: * Thus, if you wish to have a benefit of it, you must call sync() after the save() in the proper delayed time. * Otherwise, you can call sync() immediately. * - * @retval Result::Success when succeed. - * @retval Result::InsufficientCondition otherwise. - * * @note The asynchronous tasking is dependent on the Saver module implementation. * @see Saver::save() * diff --git a/thirdparty/thorvg/src/common/tvgMath.cpp b/thirdparty/thorvg/src/common/tvgMath.cpp index e6b5d47050..e99ec46681 100644 --- a/thirdparty/thorvg/src/common/tvgMath.cpp +++ b/thirdparty/thorvg/src/common/tvgMath.cpp @@ -111,3 +111,11 @@ void operator*=(Point& pt, const Matrix& m) pt.x = tx; pt.y = ty; } + + +Point operator*(const Point& pt, const Matrix& m) +{ + auto tx = pt.x * m.e11 + pt.y * m.e12 + m.e13; + auto ty = pt.x * m.e21 + pt.y * m.e22 + m.e23; + return {tx, ty}; +} diff --git a/thirdparty/thorvg/src/common/tvgMath.h b/thirdparty/thorvg/src/common/tvgMath.h index 0f877d919e..3555885c8e 100644 --- a/thirdparty/thorvg/src/common/tvgMath.h +++ b/thirdparty/thorvg/src/common/tvgMath.h @@ -152,9 +152,9 @@ static inline void operator*=(Matrix& lhs, const Matrix& rhs) } -static inline void mathLog(Matrix* m) +static inline void mathLog(const Matrix& m) { - TVGLOG("MATH", "Matrix: [%f %f %f] [%f %f %f] [%f %f %f]", m->e11, m->e12, m->e13, m->e21, m->e22, m->e23, m->e31, m->e32, m->e33); + TVGLOG("COMMON", "Matrix: [%f %f %f] [%f %f %f] [%f %f %f]", m.e11, m.e12, m.e13, m.e21, m.e22, m.e23, m.e31, m.e32, m.e33); } @@ -163,6 +163,7 @@ static inline void mathLog(Matrix* m) /************************************************************************/ void operator*=(Point& pt, const Matrix& m); +Point operator*(const Point& pt, const Matrix& m); static inline bool mathZero(const Point& p) @@ -231,6 +232,11 @@ static inline Point operator/(const Point& lhs, const float rhs) } +static inline void mathLog(const Point& pt) +{ + TVGLOG("COMMON", "Point: [%f %f]", pt.x, pt.y); +} + /************************************************************************/ /* Interpolation functions */ /************************************************************************/ diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp index f29bc09b77..ae784ccfd7 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp +++ b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp @@ -647,9 +647,9 @@ static bool _hslToRgb(float hue, float saturation, float brightness, uint8_t* re } } - *red = static_cast<uint8_t>(roundf(_red * 255.0f)); - *green = static_cast<uint8_t>(roundf(_green * 255.0f)); - *blue = static_cast<uint8_t>(roundf(_blue * 255.0f)); + *red = static_cast<uint8_t>(ceil(_red * 255.0f)); + *green = static_cast<uint8_t>(ceil(_green * 255.0f)); + *blue = static_cast<uint8_t>(ceil(_blue * 255.0f)); return true; } diff --git a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterAvx.h b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterAvx.h index cbaec28fa3..a072a88819 100644 --- a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterAvx.h +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterAvx.h @@ -101,47 +101,57 @@ static void avxRasterPixel32(uint32_t *dst, uint32_t val, uint32_t offset, int32 static bool avxRasterTranslucentRect(SwSurface* surface, const SwBBox& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { - if (surface->channelSize != sizeof(uint32_t)) { - TVGERR("SW_ENGINE", "Unsupported Channel Size = %d", surface->channelSize); - return false; - } - - auto color = surface->join(r, g, b, a); - auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x; auto h = static_cast<uint32_t>(region.max.y - region.min.y); auto w = static_cast<uint32_t>(region.max.x - region.min.x); - uint32_t ialpha = 255 - a; + //32bits channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(r, g, b, a); + auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x; - auto avxColor = _mm_set1_epi32(color); - auto avxIalpha = _mm_set1_epi8(ialpha); + uint32_t ialpha = 255 - a; - for (uint32_t y = 0; y < h; ++y) { - auto dst = &buffer[y * surface->stride]; + auto avxColor = _mm_set1_epi32(color); + auto avxIalpha = _mm_set1_epi8(ialpha); - //1. fill the not aligned memory (for 128-bit registers a 16-bytes alignment is required) - auto notAligned = ((uintptr_t)dst & 0xf) / 4; - if (notAligned) { - notAligned = (N_32BITS_IN_128REG - notAligned > w ? w : N_32BITS_IN_128REG - notAligned); - for (uint32_t x = 0; x < notAligned; ++x, ++dst) { - *dst = color + ALPHA_BLEND(*dst, ialpha); + for (uint32_t y = 0; y < h; ++y) { + auto dst = &buffer[y * surface->stride]; + + //1. fill the not aligned memory (for 128-bit registers a 16-bytes alignment is required) + auto notAligned = ((uintptr_t)dst & 0xf) / 4; + if (notAligned) { + notAligned = (N_32BITS_IN_128REG - notAligned > w ? w : N_32BITS_IN_128REG - notAligned); + for (uint32_t x = 0; x < notAligned; ++x, ++dst) { + *dst = color + ALPHA_BLEND(*dst, ialpha); + } } - } - //2. fill the aligned memory - N_32BITS_IN_128REG pixels processed at once - uint32_t iterations = (w - notAligned) / N_32BITS_IN_128REG; - uint32_t avxFilled = iterations * N_32BITS_IN_128REG; - auto avxDst = (__m128i*)dst; - for (uint32_t x = 0; x < iterations; ++x, ++avxDst) { - *avxDst = _mm_add_epi32(avxColor, ALPHA_BLEND(*avxDst, avxIalpha)); - } + //2. fill the aligned memory - N_32BITS_IN_128REG pixels processed at once + uint32_t iterations = (w - notAligned) / N_32BITS_IN_128REG; + uint32_t avxFilled = iterations * N_32BITS_IN_128REG; + auto avxDst = (__m128i*)dst; + for (uint32_t x = 0; x < iterations; ++x, ++avxDst) { + *avxDst = _mm_add_epi32(avxColor, ALPHA_BLEND(*avxDst, avxIalpha)); + } - //3. fill the remaining pixels - int32_t leftovers = w - notAligned - avxFilled; - dst += avxFilled; - while (leftovers--) { - *dst = color + ALPHA_BLEND(*dst, ialpha); - dst++; + //3. fill the remaining pixels + int32_t leftovers = w - notAligned - avxFilled; + dst += avxFilled; + while (leftovers--) { + *dst = color + ALPHA_BLEND(*dst, ialpha); + dst++; + } + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + TVGLOG("SW_ENGINE", "Require AVX Optimization, Channel Size = %d", surface->channelSize); + auto buffer = surface->buf8 + (region.min.y * surface->stride) + region.min.x; + auto ialpha = ~a; + for (uint32_t y = 0; y < h; ++y) { + auto dst = &buffer[y * surface->stride]; + for (uint32_t x = 0; x < w; ++x, ++dst) { + *dst = a + MULTIPLY(*dst, ialpha); + } } } return true; @@ -150,56 +160,68 @@ static bool avxRasterTranslucentRect(SwSurface* surface, const SwBBox& region, u static bool avxRasterTranslucentRle(SwSurface* surface, const SwRleData* rle, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { - if (surface->channelSize != sizeof(uint32_t)) { - TVGERR("SW_ENGINE", "Unsupported Channel Size = %d", surface->channelSize); - return false; - } - - auto color = surface->join(r, g, b, a); auto span = rle->spans; - uint32_t src; - for (uint32_t i = 0; i < rle->size; ++i) { - auto dst = &surface->buf32[span->y * surface->stride + span->x]; + //32bit channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(r, g, b, a); + uint32_t src; - if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); - else src = color; + for (uint32_t i = 0; i < rle->size; ++i) { + auto dst = &surface->buf32[span->y * surface->stride + span->x]; - auto ialpha = IA(src); + if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); + else src = color; - //1. fill the not aligned memory (for 128-bit registers a 16-bytes alignment is required) - auto notAligned = ((uintptr_t)dst & 0xf) / 4; - if (notAligned) { - notAligned = (N_32BITS_IN_128REG - notAligned > span->len ? span->len : N_32BITS_IN_128REG - notAligned); - for (uint32_t x = 0; x < notAligned; ++x, ++dst) { - *dst = src + ALPHA_BLEND(*dst, ialpha); + auto ialpha = IA(src); + + //1. fill the not aligned memory (for 128-bit registers a 16-bytes alignment is required) + auto notAligned = ((uintptr_t)dst & 0xf) / 4; + if (notAligned) { + notAligned = (N_32BITS_IN_128REG - notAligned > span->len ? span->len : N_32BITS_IN_128REG - notAligned); + for (uint32_t x = 0; x < notAligned; ++x, ++dst) { + *dst = src + ALPHA_BLEND(*dst, ialpha); + } } - } - //2. fill the aligned memory using avx - N_32BITS_IN_128REG pixels processed at once - //In order to avoid unneccessary avx variables declarations a check is made whether there are any iterations at all - uint32_t iterations = (span->len - notAligned) / N_32BITS_IN_128REG; - uint32_t avxFilled = 0; - if (iterations > 0) { - auto avxSrc = _mm_set1_epi32(src); - auto avxIalpha = _mm_set1_epi8(ialpha); + //2. fill the aligned memory using avx - N_32BITS_IN_128REG pixels processed at once + //In order to avoid unneccessary avx variables declarations a check is made whether there are any iterations at all + uint32_t iterations = (span->len - notAligned) / N_32BITS_IN_128REG; + uint32_t avxFilled = 0; + if (iterations > 0) { + auto avxSrc = _mm_set1_epi32(src); + auto avxIalpha = _mm_set1_epi8(ialpha); + + avxFilled = iterations * N_32BITS_IN_128REG; + auto avxDst = (__m128i*)dst; + for (uint32_t x = 0; x < iterations; ++x, ++avxDst) { + *avxDst = _mm_add_epi32(avxSrc, ALPHA_BLEND(*avxDst, avxIalpha)); + } + } - avxFilled = iterations * N_32BITS_IN_128REG; - auto avxDst = (__m128i*)dst; - for (uint32_t x = 0; x < iterations; ++x, ++avxDst) { - *avxDst = _mm_add_epi32(avxSrc, ALPHA_BLEND(*avxDst, avxIalpha)); + //3. fill the remaining pixels + int32_t leftovers = span->len - notAligned - avxFilled; + dst += avxFilled; + while (leftovers--) { + *dst = src + ALPHA_BLEND(*dst, ialpha); + dst++; } - } - //3. fill the remaining pixels - int32_t leftovers = span->len - notAligned - avxFilled; - dst += avxFilled; - while (leftovers--) { - *dst = src + ALPHA_BLEND(*dst, ialpha); - dst++; + ++span; + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + TVGLOG("SW_ENGINE", "Require AVX Optimization, Channel Size = %d", surface->channelSize); + uint8_t src; + for (uint32_t i = 0; i < rle->size; ++i, ++span) { + auto dst = &surface->buf8[span->y * surface->stride + span->x]; + if (span->coverage < 255) src = MULTIPLY(span->coverage, a); + else src = a; + auto ialpha = ~a; + for (uint32_t x = 0; x < span->len; ++x, ++dst) { + *dst = src + MULTIPLY(*dst, ialpha); + } } - - ++span; } return true; } diff --git a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterNeon.h b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterNeon.h index 1ea6cd96cf..91cf7743c1 100644 --- a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterNeon.h +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterNeon.h @@ -91,44 +91,56 @@ static void neonRasterPixel32(uint32_t *dst, uint32_t val, uint32_t offset, int3 static bool neonRasterTranslucentRle(SwSurface* surface, const SwRleData* rle, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { - if (surface->channelSize != sizeof(uint32_t)) { - TVGERR("SW_ENGINE", "Unsupported Channel Size = %d", surface->channelSize); - return false; - } - - auto color = surface->join(r, g, b, a); auto span = rle->spans; - uint32_t src; - uint8x8_t *vDst = nullptr; - uint16_t align; - - for (uint32_t i = 0; i < rle->size; ++i) { - if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); - else src = color; - - auto dst = &surface->buf32[span->y * surface->stride + span->x]; - auto ialpha = IA(src); - - if ((((uintptr_t) dst) & 0x7) != 0) { - //fill not aligned byte - *dst = src + ALPHA_BLEND(*dst, ialpha); - vDst = (uint8x8_t*)(dst + 1); - align = 1; - } else { - vDst = (uint8x8_t*) dst; - align = 0; - } - uint8x8_t vSrc = (uint8x8_t) vdup_n_u32(src); - uint8x8_t vIalpha = vdup_n_u8((uint8_t) ialpha); + //32bit channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(r, g, b, a); + uint32_t src; + uint8x8_t *vDst = nullptr; + uint16_t align; + + for (uint32_t i = 0; i < rle->size; ++i) { + if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); + else src = color; - for (uint32_t x = 0; x < (span->len - align) / 2; ++x) - vDst[x] = vadd_u8(vSrc, ALPHA_BLEND(vDst[x], vIalpha)); + auto dst = &surface->buf32[span->y * surface->stride + span->x]; + auto ialpha = IA(src); - auto leftovers = (span->len - align) % 2; - if (leftovers > 0) dst[span->len - 1] = src + ALPHA_BLEND(dst[span->len - 1], ialpha); + if ((((uintptr_t) dst) & 0x7) != 0) { + //fill not aligned byte + *dst = src + ALPHA_BLEND(*dst, ialpha); + vDst = (uint8x8_t*)(dst + 1); + align = 1; + } else { + vDst = (uint8x8_t*) dst; + align = 0; + } - ++span; + uint8x8_t vSrc = (uint8x8_t) vdup_n_u32(src); + uint8x8_t vIalpha = vdup_n_u8((uint8_t) ialpha); + + for (uint32_t x = 0; x < (span->len - align) / 2; ++x) + vDst[x] = vadd_u8(vSrc, ALPHA_BLEND(vDst[x], vIalpha)); + + auto leftovers = (span->len - align) % 2; + if (leftovers > 0) dst[span->len - 1] = src + ALPHA_BLEND(dst[span->len - 1], ialpha); + + ++span; + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + TVGLOG("SW_ENGINE", "Require Neon Optimization, Channel Size = %d", surface->channelSize); + uint8_t src; + for (uint32_t i = 0; i < rle->size; ++i, ++span) { + auto dst = &surface->buf8[span->y * surface->stride + span->x]; + if (span->coverage < 255) src = MULTIPLY(span->coverage, a); + else src = a; + auto ialpha = ~a; + for (uint32_t x = 0; x < span->len; ++x, ++dst) { + *dst = src + MULTIPLY(*dst, ialpha); + } + } } return true; } @@ -136,41 +148,51 @@ static bool neonRasterTranslucentRle(SwSurface* surface, const SwRleData* rle, u static bool neonRasterTranslucentRect(SwSurface* surface, const SwBBox& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { - if (surface->channelSize != sizeof(uint32_t)) { - TVGERR("SW_ENGINE", "Unsupported Channel Size = %d", surface->channelSize); - return false; - } - - auto color = surface->join(r, g, b, a); - auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x; auto h = static_cast<uint32_t>(region.max.y - region.min.y); auto w = static_cast<uint32_t>(region.max.x - region.min.x); - auto ialpha = 255 - a; - auto vColor = vdup_n_u32(color); - auto vIalpha = vdup_n_u8((uint8_t) ialpha); + //32bits channels + if (surface->channelSize == sizeof(uint32_t)) { + auto color = surface->join(r, g, b, a); + auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x; + auto ialpha = 255 - a; - uint8x8_t* vDst = nullptr; - uint32_t align; + auto vColor = vdup_n_u32(color); + auto vIalpha = vdup_n_u8((uint8_t) ialpha); - for (uint32_t y = 0; y < h; ++y) { - auto dst = &buffer[y * surface->stride]; + uint8x8_t* vDst = nullptr; + uint32_t align; - if ((((uintptr_t) dst) & 0x7) != 0) { - //fill not aligned byte - *dst = color + ALPHA_BLEND(*dst, ialpha); - vDst = (uint8x8_t*) (dst + 1); - align = 1; - } else { - vDst = (uint8x8_t*) dst; - align = 0; - } + for (uint32_t y = 0; y < h; ++y) { + auto dst = &buffer[y * surface->stride]; - for (uint32_t x = 0; x < (w - align) / 2; ++x) - vDst[x] = vadd_u8((uint8x8_t)vColor, ALPHA_BLEND(vDst[x], vIalpha)); + if ((((uintptr_t) dst) & 0x7) != 0) { + //fill not aligned byte + *dst = color + ALPHA_BLEND(*dst, ialpha); + vDst = (uint8x8_t*) (dst + 1); + align = 1; + } else { + vDst = (uint8x8_t*) dst; + align = 0; + } - auto leftovers = (w - align) % 2; - if (leftovers > 0) dst[w - 1] = color + ALPHA_BLEND(dst[w - 1], ialpha); + for (uint32_t x = 0; x < (w - align) / 2; ++x) + vDst[x] = vadd_u8((uint8x8_t)vColor, ALPHA_BLEND(vDst[x], vIalpha)); + + auto leftovers = (w - align) % 2; + if (leftovers > 0) dst[w - 1] = color + ALPHA_BLEND(dst[w - 1], ialpha); + } + //8bit grayscale + } else if (surface->channelSize == sizeof(uint8_t)) { + TVGLOG("SW_ENGINE", "Require Neon Optimization, Channel Size = %d", surface->channelSize); + auto buffer = surface->buf8 + (region.min.y * surface->stride) + region.min.x; + auto ialpha = ~a; + for (uint32_t y = 0; y < h; ++y) { + auto dst = &buffer[y * surface->stride]; + for (uint32_t x = 0; x < w; ++x, ++dst) { + *dst = a + MULTIPLY(*dst, ialpha); + } + } } return true; } diff --git a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterTexmap.h b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterTexmap.h index bab534bba2..cfce7785c7 100644 --- a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterTexmap.h +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRasterTexmap.h @@ -824,7 +824,7 @@ static AASpans* _AASpans(float ymin, float ymax, const SwImage* image, const SwB //Initialize X range auto height = yEnd - yStart; - aaSpans->lines = static_cast<AALine*>(calloc(height, sizeof(AALine))); + aaSpans->lines = static_cast<AALine*>(malloc(height * sizeof(AALine))); for (int32_t i = 0; i < height; i++) { aaSpans->lines[i].x[0] = INT32_MAX; @@ -878,7 +878,7 @@ static void _calcHorizCoverage(AALine *lines, int32_t eidx, int32_t y, int32_t x /* * This Anti-Aliasing mechanism is originated from Hermet Park's idea. * To understand this AA logic, you can refer this page: - * www.hermet.pe.kr/122 (hermetpark@gmail.com) + * https://uigraphics.tistory.com/1 */ static void _calcAAEdge(AASpans *aaSpans, int32_t eidx) { @@ -924,6 +924,9 @@ static void _calcAAEdge(AASpans *aaSpans, int32_t eidx) //Calculates AA Edges for (y++; y < yEnd; y++) { + + if (lines[y].x[0] == INT32_MAX) continue; + //Ready tx if (eidx == 0) { tx[0] = pEdge.x; diff --git a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp index 78108af095..0a3f5ef7e7 100644 --- a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwRenderer.cpp @@ -147,7 +147,7 @@ struct SwShapeTask : SwTask } } //Fill - if (flags & (RenderUpdateFlag::Gradient | RenderUpdateFlag::Transform | RenderUpdateFlag::Color)) { + if (flags & (RenderUpdateFlag::Path |RenderUpdateFlag::Gradient | RenderUpdateFlag::Transform | RenderUpdateFlag::Color)) { if (visibleFill || clipper) { if (!shapeGenRle(&shape, rshape, antialiasing(strokeWidth))) goto err; } @@ -160,7 +160,7 @@ struct SwShapeTask : SwTask } } //Stroke - if (flags & (RenderUpdateFlag::Stroke | RenderUpdateFlag::Transform)) { + if (flags & (RenderUpdateFlag::Path | RenderUpdateFlag::Stroke | RenderUpdateFlag::Transform)) { if (strokeWidth > 0.0f) { shapeResetStroke(&shape, rshape, transform); if (!shapeGenStrokeRle(&shape, rshape, transform, clipRegion, bbox, mpool, tid)) goto err; @@ -718,9 +718,6 @@ void* SwRenderer::prepareCommon(SwTask* task, const RenderTransform* transform, if (!surface) return task; if (flags == RenderUpdateFlag::None) return task; - //Finish previous task if it has duplicated request. - task->done(); - //TODO: Failed threading them. It would be better if it's possible. //See: https://github.com/thorvg/thorvg/issues/1409 //Guarantee composition targets get ready. @@ -769,8 +766,11 @@ RenderData SwRenderer::prepare(Surface* surface, const RenderMesh* mesh, RenderD //prepare task auto task = static_cast<SwImageTask*>(data); if (!task) task = new SwImageTask; + else task->done(); + task->source = surface; task->mesh = mesh; + return prepareCommon(task, transform, clips, opacity, flags); } @@ -780,6 +780,8 @@ RenderData SwRenderer::prepare(const Array<RenderData>& scene, RenderData data, //prepare task auto task = static_cast<SwSceneTask*>(data); if (!task) task = new SwSceneTask; + else task->done(); + task->scene = scene; //TODO: Failed threading them. It would be better if it's possible. @@ -788,6 +790,7 @@ RenderData SwRenderer::prepare(const Array<RenderData>& scene, RenderData data, for (auto task = scene.begin(); task < scene.end(); ++task) { static_cast<SwTask*>(*task)->done(); } + return prepareCommon(task, transform, clips, opacity, flags); } @@ -796,10 +799,10 @@ RenderData SwRenderer::prepare(const RenderShape& rshape, RenderData data, const { //prepare task auto task = static_cast<SwShapeTask*>(data); - if (!task) { - task = new SwShapeTask; - task->rshape = &rshape; - } + if (!task) task = new SwShapeTask; + else task->done(); + + task->rshape = &rshape; task->clipper = clipper; return prepareCommon(task, transform, clips, opacity, flags); diff --git a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwStroke.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwStroke.cpp index 9ec4bd78a5..18f5f3eca8 100644 --- a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwStroke.cpp +++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwStroke.cpp @@ -238,7 +238,7 @@ static void _outside(SwStroke& stroke, int32_t side, SwFixed lineLength) } else { //this is a mitered (pointed) or beveled (truncated) corner auto rotate = SIDE_TO_ROTATE(side); - auto bevel = (stroke.join == StrokeJoin::Bevel) ? true : false; + auto bevel = stroke.join == StrokeJoin::Bevel; SwFixed phi = 0; SwFixed thcos = 0; @@ -816,7 +816,7 @@ void strokeReset(SwStroke* stroke, const RenderShape* rshape, const Matrix* tran stroke->width = HALF_STROKE(rshape->strokeWidth()); stroke->cap = rshape->strokeCap(); - stroke->miterlimit = static_cast<SwFixed>(rshape->strokeMiterlimit()) << 16; + stroke->miterlimit = static_cast<SwFixed>(rshape->strokeMiterlimit() * 65536.0f); //Save line join: it can be temporarily changed when stroking curves... stroke->joinSaved = stroke->join = rshape->strokeJoin(); diff --git a/thirdparty/thorvg/src/renderer/tvgCanvas.h b/thirdparty/thorvg/src/renderer/tvgCanvas.h index a4b866eacb..9d216e2f30 100644 --- a/thirdparty/thorvg/src/renderer/tvgCanvas.h +++ b/thirdparty/thorvg/src/renderer/tvgCanvas.h @@ -26,17 +26,15 @@ #include "tvgPaint.h" +enum Status : uint8_t {Synced = 0, Updating, Drawing, Damanged}; + struct Canvas::Impl { - enum Status : uint8_t {Synced = 0, Updating, Drawing}; - list<Paint*> paints; RenderMethod* renderer; RenderRegion vport = {0, 0, INT32_MAX, INT32_MAX}; Status status = Status::Synced; - bool refresh = false; //if all paints should be updated by force. - Impl(RenderMethod* pRenderer) : renderer(pRenderer) { renderer->ref(); @@ -87,18 +85,13 @@ struct Canvas::Impl return Result::Success; } - void needRefresh() - { - refresh = true; - } - Result update(Paint* paint, bool force) { if (paints.empty() || status == Status::Drawing) return Result::InsufficientCondition; Array<RenderData> clips; auto flag = RenderUpdateFlag::None; - if (refresh || force) flag = RenderUpdateFlag::All; + if (status == Status::Damanged || force) flag = RenderUpdateFlag::All; if (paint) { paint->pImpl->update(renderer, nullptr, clips, 255, flag); @@ -106,7 +99,6 @@ struct Canvas::Impl for (auto paint : paints) { paint->pImpl->update(renderer, nullptr, clips, 255, flag); } - refresh = false; } status = Status::Updating; return Result::Success; @@ -114,6 +106,7 @@ struct Canvas::Impl Result draw() { + if (status == Status::Damanged) update(nullptr, false); if (status == Status::Drawing || paints.empty() || !renderer->preRender()) return Result::InsufficientCondition; bool rendered = false; @@ -129,7 +122,7 @@ struct Canvas::Impl Result sync() { - if (status == Status::Synced) return Result::InsufficientCondition; + if (status == Status::Synced || status == Status::Damanged) return Result::InsufficientCondition; if (renderer->sync()) { status = Status::Synced; @@ -141,7 +134,8 @@ struct Canvas::Impl Result viewport(int32_t x, int32_t y, int32_t w, int32_t h) { - if (status != Status::Synced) return Result::InsufficientCondition; + if (status != Status::Damanged && status != Status::Synced) return Result::InsufficientCondition; + RenderRegion val = {x, y, w, h}; //intersect if the target buffer is already set. auto surface = renderer->mainSurface(); @@ -151,7 +145,7 @@ struct Canvas::Impl if (vport == val) return Result::Success; renderer->viewport(val); vport = val; - needRefresh(); + status = Status::Damanged; return Result::Success; } }; diff --git a/thirdparty/thorvg/src/renderer/tvgGlCanvas.cpp b/thirdparty/thorvg/src/renderer/tvgGlCanvas.cpp index 211dbb589c..82666b7ae3 100644 --- a/thirdparty/thorvg/src/renderer/tvgGlCanvas.cpp +++ b/thirdparty/thorvg/src/renderer/tvgGlCanvas.cpp @@ -45,15 +45,14 @@ struct GlCanvas::Impl /************************************************************************/ #ifdef THORVG_GL_RASTER_SUPPORT -GlCanvas::GlCanvas() : Canvas(GlRenderer::gen()), pImpl(new Impl) +GlCanvas::GlCanvas() : Canvas(GlRenderer::gen()), pImpl(nullptr) #else -GlCanvas::GlCanvas() : Canvas(nullptr), pImpl(new Impl) +GlCanvas::GlCanvas() : Canvas(nullptr), pImpl(nullptr) #endif { } - GlCanvas::~GlCanvas() { delete(pImpl); @@ -63,6 +62,10 @@ GlCanvas::~GlCanvas() Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h) noexcept { #ifdef THORVG_GL_RASTER_SUPPORT + if (Canvas::pImpl->status != Status::Damanged && Canvas::pImpl->status != Status::Synced) { + return Result::InsufficientCondition; + } + //We know renderer type, avoid dynamic_cast for performance. auto renderer = static_cast<GlRenderer*>(Canvas::pImpl->renderer); if (!renderer) return Result::MemoryCorruption; @@ -72,7 +75,7 @@ Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h) noexcept renderer->viewport(Canvas::pImpl->vport); //Paints must be updated again with this new target. - Canvas::pImpl->needRefresh(); + Canvas::pImpl->status = Status::Damanged; return Result::Success; #endif diff --git a/thirdparty/thorvg/src/renderer/tvgLoader.cpp b/thirdparty/thorvg/src/renderer/tvgLoader.cpp index 4b8d3256a9..6a81ddcdbb 100644 --- a/thirdparty/thorvg/src/renderer/tvgLoader.cpp +++ b/thirdparty/thorvg/src/renderer/tvgLoader.cpp @@ -433,3 +433,27 @@ LoadModule* LoaderMgr::loader(const uint32_t *data, uint32_t w, uint32_t h, bool delete(loader); return nullptr; } + + +//loads fonts from memory - loader is cached (regardless of copy value) in order to access it while setting font +LoadModule* LoaderMgr::loader(const char* name, const char* data, uint32_t size, TVG_UNUSED const string& mimeType, bool copy) +{ +#ifdef THORVG_TTF_LOADER_SUPPORT + //TODO: add check for mimetype ? + if (auto loader = _findFromCache(name)) return loader; + + //function is dedicated for ttf loader (the only supported font loader) + auto loader = new TtfLoader; + if (loader->open(data, size, copy)) { + loader->hashpath = strdup(name); + loader->pathcache = true; + ScopedLock lock(key); + _activeLoaders.back(loader); + return loader; + } + + TVGLOG("LOADER", "The font data \"%s\" could not be loaded.", name); + delete(loader); +#endif + return nullptr; +} diff --git a/thirdparty/thorvg/src/renderer/tvgLoader.h b/thirdparty/thorvg/src/renderer/tvgLoader.h index b15032df27..74c4f43964 100644 --- a/thirdparty/thorvg/src/renderer/tvgLoader.h +++ b/thirdparty/thorvg/src/renderer/tvgLoader.h @@ -32,6 +32,7 @@ struct LoaderMgr static LoadModule* loader(const string& path, bool* invalid); static LoadModule* loader(const char* data, uint32_t size, const string& mimeType, bool copy); static LoadModule* loader(const uint32_t* data, uint32_t w, uint32_t h, bool copy); + static LoadModule* loader(const char* name, const char* data, uint32_t size, const string& mimeType, bool copy); static LoadModule* loader(const char* key); static bool retrieve(const string& path); static bool retrieve(LoadModule* loader); diff --git a/thirdparty/thorvg/src/renderer/tvgShape.cpp b/thirdparty/thorvg/src/renderer/tvgShape.cpp index c010aa7bbf..3b9293a00e 100644 --- a/thirdparty/thorvg/src/renderer/tvgShape.cpp +++ b/thirdparty/thorvg/src/renderer/tvgShape.cpp @@ -88,6 +88,8 @@ Result Shape::appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point* pImpl->grow(cmdCnt, ptsCnt); pImpl->append(cmds, cmdCnt, pts, ptsCnt); + pImpl->flag |= RenderUpdateFlag::Path; + return Result::Success; } @@ -104,6 +106,8 @@ Result Shape::lineTo(float x, float y) noexcept { pImpl->lineTo(x, y); + pImpl->flag |= RenderUpdateFlag::Path; + return Result::Success; } @@ -112,6 +116,8 @@ Result Shape::cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float { pImpl->cubicTo(cx1, cy1, cx2, cy2, x, y); + pImpl->flag |= RenderUpdateFlag::Path; + return Result::Success; } @@ -120,6 +126,8 @@ Result Shape::close() noexcept { pImpl->close(); + pImpl->flag |= RenderUpdateFlag::Path; + return Result::Success; } @@ -137,9 +145,12 @@ Result Shape::appendCircle(float cx, float cy, float rx, float ry) noexcept pImpl->cubicTo(cx + rxKappa, cy - ry, cx + rx, cy - ryKappa, cx + rx, cy); pImpl->close(); + pImpl->flag |= RenderUpdateFlag::Path; + return Result::Success; } + Result Shape::appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept { //just circle @@ -196,6 +207,8 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa if (pie) pImpl->close(); + pImpl->flag |= RenderUpdateFlag::Path; + return Result::Success; } @@ -234,6 +247,8 @@ Result Shape::appendRect(float x, float y, float w, float h, float rx, float ry) pImpl->close(); } + pImpl->flag |= RenderUpdateFlag::Path; + return Result::Success; } diff --git a/thirdparty/thorvg/src/renderer/tvgShape.h b/thirdparty/thorvg/src/renderer/tvgShape.h index 4e85db37d0..c45995a64d 100644 --- a/thirdparty/thorvg/src/renderer/tvgShape.h +++ b/thirdparty/thorvg/src/renderer/tvgShape.h @@ -167,24 +167,18 @@ struct Shape::Impl memcpy(rs.path.pts.end(), pts, sizeof(Point) * ptsCnt); rs.path.cmds.count += cmdCnt; rs.path.pts.count += ptsCnt; - - flag |= RenderUpdateFlag::Path; } void moveTo(float x, float y) { rs.path.cmds.push(PathCommand::MoveTo); rs.path.pts.push({x, y}); - - flag |= RenderUpdateFlag::Path; } void lineTo(float x, float y) { rs.path.cmds.push(PathCommand::LineTo); rs.path.pts.push({x, y}); - - flag |= RenderUpdateFlag::Path; } void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) @@ -193,8 +187,6 @@ struct Shape::Impl rs.path.pts.push({cx1, cy1}); rs.path.pts.push({cx2, cy2}); rs.path.pts.push({x, y}); - - flag |= RenderUpdateFlag::Path; } void close() @@ -203,8 +195,6 @@ struct Shape::Impl if (rs.path.cmds.count > 0 && rs.path.cmds.last() == PathCommand::Close) return; rs.path.cmds.push(PathCommand::Close); - - flag |= RenderUpdateFlag::Path; } void strokeWidth(float width) diff --git a/thirdparty/thorvg/src/renderer/tvgSwCanvas.cpp b/thirdparty/thorvg/src/renderer/tvgSwCanvas.cpp index 52d85d8320..d762492f22 100644 --- a/thirdparty/thorvg/src/renderer/tvgSwCanvas.cpp +++ b/thirdparty/thorvg/src/renderer/tvgSwCanvas.cpp @@ -46,9 +46,9 @@ struct SwCanvas::Impl /************************************************************************/ #ifdef THORVG_SW_RASTER_SUPPORT -SwCanvas::SwCanvas() : Canvas(SwRenderer::gen()), pImpl(new Impl) +SwCanvas::SwCanvas() : Canvas(SwRenderer::gen()), pImpl(nullptr) #else -SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(new Impl) +SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(nullptr) #endif { } @@ -82,6 +82,10 @@ Result SwCanvas::mempool(MempoolPolicy policy) noexcept Result SwCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept { #ifdef THORVG_SW_RASTER_SUPPORT + if (Canvas::pImpl->status != Status::Damanged && Canvas::pImpl->status != Status::Synced) { + return Result::InsufficientCondition; + } + //We know renderer type, avoid dynamic_cast for performance. auto renderer = static_cast<SwRenderer*>(Canvas::pImpl->renderer); if (!renderer) return Result::MemoryCorruption; @@ -90,12 +94,12 @@ Result SwCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t Canvas::pImpl->vport = {0, 0, (int32_t)w, (int32_t)h}; renderer->viewport(Canvas::pImpl->vport); - //Paints must be updated again with this new target. - Canvas::pImpl->needRefresh(); - //FIXME: The value must be associated with an individual canvas instance. ImageLoader::cs = static_cast<ColorSpace>(cs); + //Paints must be updated again with this new target. + Canvas::pImpl->status = Status::Damanged; + return Result::Success; #endif return Result::NonSupport; diff --git a/thirdparty/thorvg/src/renderer/tvgText.cpp b/thirdparty/thorvg/src/renderer/tvgText.cpp index 1fe244c11d..4b5eb35ce5 100644 --- a/thirdparty/thorvg/src/renderer/tvgText.cpp +++ b/thirdparty/thorvg/src/renderer/tvgText.cpp @@ -71,6 +71,21 @@ Result Text::load(const std::string& path) noexcept } +Result Text::load(const char* name, const char* data, uint32_t size, const string& mimeType, bool copy) noexcept +{ + if (!name || (size == 0 && data)) return Result::InvalidArguments; + + //unload font + if (!data) { + if (LoaderMgr::retrieve(name)) return Result::Success; + return Result::InsufficientCondition; + } + + if (!LoaderMgr::loader(name, data, size, mimeType, copy)) return Result::NonSupport; + return Result::Success; +} + + Result Text::unload(const std::string& path) noexcept { if (LoaderMgr::retrieve(path)) return Result::Success; diff --git a/thirdparty/thorvg/src/renderer/tvgText.h b/thirdparty/thorvg/src/renderer/tvgText.h index f4fb12259a..c56ce8b878 100644 --- a/thirdparty/thorvg/src/renderer/tvgText.h +++ b/thirdparty/thorvg/src/renderer/tvgText.h @@ -100,7 +100,7 @@ struct Text::Impl bool render(RenderMethod* renderer) { if (paint) return PP(paint)->render(renderer); - return false; + return true; } bool load() diff --git a/thirdparty/thorvg/src/renderer/tvgWgCanvas.cpp b/thirdparty/thorvg/src/renderer/tvgWgCanvas.cpp index 7db77f6d0c..067e35b1f0 100644 --- a/thirdparty/thorvg/src/renderer/tvgWgCanvas.cpp +++ b/thirdparty/thorvg/src/renderer/tvgWgCanvas.cpp @@ -47,33 +47,39 @@ WgCanvas::WgCanvas() : Canvas(nullptr), pImpl(nullptr) { } + WgCanvas::~WgCanvas() { delete pImpl; } -Result WgCanvas::target(void* window, uint32_t w, uint32_t h) noexcept + +Result WgCanvas::target(void* instance, void* surface, uint32_t w, uint32_t h) noexcept { #ifdef THORVG_WG_RASTER_SUPPORT - if (!window) return Result::InvalidArguments; - if ((w == 0) || (h == 0)) return Result::InvalidArguments; + if (Canvas::pImpl->status != Status::Damanged && Canvas::pImpl->status != Status::Synced) { + return Result::InsufficientCondition; + } + + if (!instance || !surface || (w == 0) || (h == 0)) return Result::InvalidArguments; //We know renderer type, avoid dynamic_cast for performance. auto renderer = static_cast<WgRenderer*>(Canvas::pImpl->renderer); if (!renderer) return Result::MemoryCorruption; - if (!renderer->target(window, w, h)) return Result::Unknown; + if (!renderer->target((WGPUInstance)instance, (WGPUSurface)surface, w, h)) return Result::Unknown; Canvas::pImpl->vport = {0, 0, (int32_t)w, (int32_t)h}; renderer->viewport(Canvas::pImpl->vport); //Paints must be updated again with this new target. - Canvas::pImpl->needRefresh(); + Canvas::pImpl->status = Status::Damanged; return Result::Success; #endif return Result::NonSupport; } + unique_ptr<WgCanvas> WgCanvas::gen() noexcept { #ifdef THORVG_WG_RASTER_SUPPORT diff --git a/thirdparty/thorvg/update-thorvg.sh b/thirdparty/thorvg/update-thorvg.sh index 663d685d01..d08158bfe7 100755 --- a/thirdparty/thorvg/update-thorvg.sh +++ b/thirdparty/thorvg/update-thorvg.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -VERSION=0.13.8 +VERSION=0.14.0 cd thirdparty/thorvg/ || true rm -rf AUTHORS LICENSE inc/ src/ *.zip *.tar.gz tmp/ |
