diff options
-rw-r--r-- | core/image.cpp | 21 | ||||
-rw-r--r-- | core/safe_refcount.h | 16 | ||||
-rw-r--r-- | doc/classes/Node.xml | 6 | ||||
-rw-r--r-- | editor/code_editor.cpp | 23 | ||||
-rw-r--r-- | editor/editor_fonts.cpp | 26 | ||||
-rw-r--r-- | editor/editor_settings.cpp | 4 |
6 files changed, 62 insertions, 34 deletions
diff --git a/core/image.cpp b/core/image.cpp index 5ce744f709..6211c06ebe 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -754,15 +754,14 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict for (int32_t buffer_x = 0; buffer_x < dst_width; buffer_x++) { - float src_real_x = buffer_x * x_scale; - int32_t src_x = src_real_x; - - int32_t start_x = MAX(0, src_x - half_kernel + 1); - int32_t end_x = MIN(src_width - 1, src_x + half_kernel); + // The corresponding point on the source image + float src_x = (buffer_x + 0.5f) * x_scale; // Offset by 0.5 so it uses the pixel's center + int32_t start_x = MAX(0, int32_t(src_x) - half_kernel + 1); + int32_t end_x = MIN(src_width - 1, int32_t(src_x) + half_kernel); // Create the kernel used by all the pixels of the column for (int32_t target_x = start_x; target_x <= end_x; target_x++) - kernel[target_x - start_x] = _lanczos((src_real_x - target_x) / scale_factor); + kernel[target_x - start_x] = _lanczos((target_x + 0.5f - src_x) / scale_factor); for (int32_t buffer_y = 0; buffer_y < src_height; buffer_y++) { @@ -805,14 +804,12 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict for (int32_t dst_y = 0; dst_y < dst_height; dst_y++) { - float buffer_real_y = dst_y * y_scale; - int32_t buffer_y = buffer_real_y; - - int32_t start_y = MAX(0, buffer_y - half_kernel + 1); - int32_t end_y = MIN(src_height - 1, buffer_y + half_kernel); + float buffer_y = (dst_y + 0.5f) * y_scale; + int32_t start_y = MAX(0, int32_t(buffer_y) - half_kernel + 1); + int32_t end_y = MIN(src_height - 1, int32_t(buffer_y) + half_kernel); for (int32_t target_y = start_y; target_y <= end_y; target_y++) - kernel[target_y - start_y] = _lanczos((buffer_real_y - target_y) / scale_factor); + kernel[target_y - start_y] = _lanczos((target_y + 0.5f - buffer_y) / scale_factor); for (int32_t dst_x = 0; dst_x < dst_width; dst_x++) { diff --git a/core/safe_refcount.h b/core/safe_refcount.h index 54f540b0c7..0b65ffb9ca 100644 --- a/core/safe_refcount.h +++ b/core/safe_refcount.h @@ -97,8 +97,8 @@ static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V v /* Implementation for GCC & Clang */ -// GCC guarantees atomic intrinsics for sizes of 1, 2, 4 and 8 bytes. -// Clang states it supports GCC atomic builtins. +#include <stdbool.h> +#include <atomic> template <class T> static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) { @@ -107,7 +107,7 @@ static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) { T tmp = static_cast<T const volatile &>(*pw); if (tmp == 0) return 0; // if zero, can't add to it anymore - if (__sync_val_compare_and_swap(pw, tmp, tmp + 1) == tmp) + if (__atomic_compare_exchange_n(pw, &tmp, tmp + 1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) == true) return tmp + 1; } } @@ -115,25 +115,25 @@ static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) { template <class T> static _ALWAYS_INLINE_ T atomic_decrement(volatile T *pw) { - return __sync_sub_and_fetch(pw, 1); + return __atomic_sub_fetch(pw, 1, __ATOMIC_SEQ_CST); } template <class T> static _ALWAYS_INLINE_ T atomic_increment(volatile T *pw) { - return __sync_add_and_fetch(pw, 1); + return __atomic_add_fetch(pw, 1, __ATOMIC_SEQ_CST); } template <class T, class V> static _ALWAYS_INLINE_ T atomic_sub(volatile T *pw, volatile V val) { - return __sync_sub_and_fetch(pw, val); + return __atomic_sub_fetch(pw, val, __ATOMIC_SEQ_CST); } template <class T, class V> static _ALWAYS_INLINE_ T atomic_add(volatile T *pw, volatile V val) { - return __sync_add_and_fetch(pw, val); + return __atomic_add_fetch(pw, val, __ATOMIC_SEQ_CST); } template <class T, class V> @@ -143,7 +143,7 @@ static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V v T tmp = static_cast<T const volatile &>(*pw); if (tmp >= val) return tmp; // already greater, or equal - if (__sync_val_compare_and_swap(pw, tmp, val) == tmp) + if (__atomic_compare_exchange_n(pw, &tmp, val, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) == true) return val; } } diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 889ce4d3eb..097fa1f6e5 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -122,6 +122,12 @@ <description> Adds a child node. Nodes can have any number of children, but every child must have a unique name. Child nodes are automatically deleted when the parent node is deleted, so an entire scene can be removed by deleting its topmost node. If [code]legible_unique_name[/code] is [code]true[/code], the child node will have an human-readable name based on the name of the node being instanced instead of its type. + [b]Note:[/b] If the child node already has a parent, the function will fail. Use [method remove_child] first to remove the node from its current parent. For example: + [codeblock] + if child_node.get_parent(): + child_node.get_parent().remove_child(child_node) + add_child(child_node) + [/codeblock] </description> </method> <method name="add_child_below_node"> diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 5b1a460a54..33af5927b3 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -164,6 +164,7 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) _update_results_count(); } else { + results_count = 0; result_line = -1; result_col = -1; text_edit->set_search_text(""); @@ -196,7 +197,7 @@ void FindReplaceBar::_replace() { void FindReplaceBar::_replace_all() { text_edit->disconnect("text_changed", this, "_editor_text_changed"); - // line as x so it gets priority in comparison, column as y + // Line as x so it gets priority in comparison, column as y. Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column()); Point2i prev_match = Point2(-1, -1); @@ -228,7 +229,7 @@ void FindReplaceBar::_replace_all() { Point2i match_to(result_line, result_col + search_text_len); if (match_from < prev_match) { - break; // done + break; // Done. } prev_match = Point2i(result_line, result_col + replace_text.length()); @@ -241,14 +242,14 @@ void FindReplaceBar::_replace_all() { continue; } - // replace but adjust selection bounds + // Replace but adjust selection bounds. text_edit->insert_text_at_cursor(replace_text); if (match_to.x == selection_end.x) { selection_end.y += replace_text.length() - search_text_len; } } else { - // just replace + // Just replace. text_edit->insert_text_at_cursor(replace_text); } @@ -260,12 +261,12 @@ void FindReplaceBar::_replace_all() { replace_all_mode = false; - // restore editor state (selection, cursor, scroll) + // Restore editor state (selection, cursor, scroll). text_edit->cursor_set_line(orig_cursor.x); text_edit->cursor_set_column(orig_cursor.y); if (selection_enabled && is_selection_only()) { - // reselect + // Reselect. text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); } else { text_edit->deselect(); @@ -363,7 +364,7 @@ bool FindReplaceBar::search_prev() { int line, col; _get_search_from(line, col); if (text_edit->is_selection_active()) - col--; //Skip currently selected word. + col--; // Skip currently selected word. if (line == result_line && col == result_col) { col -= text.length(); @@ -751,7 +752,7 @@ void CodeTextEditor::_zoom_changed() { } void CodeTextEditor::_reset_zoom() { - Ref<DynamicFont> font = text_editor->get_font("font"); // reset source font size to default + Ref<DynamicFont> font = text_editor->get_font("font"); // Reset source font size to default. if (font.is_valid()) { EditorSettings::get_singleton()->set("interface/editor/code_font_size", 14); @@ -1261,7 +1262,7 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { int col_to = text_editor->get_selection_to_column(); int cursor_pos = text_editor->cursor_get_column(); - // Check if all lines in the selected block are commented + // Check if all lines in the selected block are commented. bool is_commented = true; for (int i = begin; i <= end; i++) { if (!text_editor->get_line(i).begins_with(delimiter)) { @@ -1456,14 +1457,14 @@ void CodeTextEditor::_on_settings_change() { font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size"); - // AUTO BRACE COMPLETION + // Auto brace completion. text_editor->set_auto_brace_completion( EDITOR_GET("text_editor/completion/auto_brace_complete")); code_complete_timer->set_wait_time( EDITOR_GET("text_editor/completion/code_complete_delay")); - // call hint settings + // Call hint settings. text_editor->set_callhint_settings( EDITOR_GET("text_editor/completion/put_callhint_tooltip_below_current_line"), EDITOR_GET("text_editor/completion/callhint_tooltip_offset")); diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 73438ffc0c..55cae35a4a 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -94,7 +94,31 @@ void editor_register_fonts(Ref<Theme> p_theme) { /* Custom font */ bool font_antialiased = (bool)EditorSettings::get_singleton()->get("interface/editor/font_antialiased"); - DynamicFontData::Hinting font_hinting = (DynamicFontData::Hinting)(int)EditorSettings::get_singleton()->get("interface/editor/font_hinting"); + int font_hinting_setting = (int)EditorSettings::get_singleton()->get("interface/editor/font_hinting"); + + DynamicFontData::Hinting font_hinting; + switch (font_hinting_setting) { + case 0: + // The "Auto" setting uses the setting that best matches the OS' font rendering: + // - macOS doesn't use font hinting. + // - Windows uses ClearType, which is in between "Light" and "Normal" hinting. + // - Linux has configurable font hinting, but most distributions including Ubuntu default to "Light". +#ifdef OSX_ENABLED + font_hinting = DynamicFontData::HINTING_NONE; +#else + font_hinting = DynamicFontData::HINTING_LIGHT; +#endif + break; + case 1: + font_hinting = DynamicFontData::HINTING_NONE; + break; + case 2: + font_hinting = DynamicFontData::HINTING_LIGHT; + break; + default: + font_hinting = DynamicFontData::HINTING_NORMAL; + break; + } String custom_font_path = EditorSettings::get_singleton()->get("interface/editor/main_font"); Ref<DynamicFontData> CustomFont; diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index e3f2a888d6..2d2e53370d 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -324,8 +324,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("interface/editor/code_font_size", 14); hints["interface/editor/code_font_size"] = PropertyInfo(Variant::INT, "interface/editor/code_font_size", PROPERTY_HINT_RANGE, "8,48,1", PROPERTY_USAGE_DEFAULT); _initial_set("interface/editor/font_antialiased", true); - _initial_set("interface/editor/font_hinting", 2); - hints["interface/editor/font_hinting"] = PropertyInfo(Variant::INT, "interface/editor/font_hinting", PROPERTY_HINT_ENUM, "None,Light,Normal", PROPERTY_USAGE_DEFAULT); + _initial_set("interface/editor/font_hinting", 0); + hints["interface/editor/font_hinting"] = PropertyInfo(Variant::INT, "interface/editor/font_hinting", PROPERTY_HINT_ENUM, "Auto,None,Light,Normal", PROPERTY_USAGE_DEFAULT); _initial_set("interface/editor/main_font", ""); hints["interface/editor/main_font"] = PropertyInfo(Variant::STRING, "interface/editor/main_font", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT); _initial_set("interface/editor/main_font_bold", ""); |