From 4f11a0a9873ec9bd2a95ed0d10094606c172693b Mon Sep 17 00:00:00 2001 From: kleonc <9283098+kleonc@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:26:21 +0200 Subject: [PATCH 01/37] Support importing 1/2/4-bpp BMP images of size non-divisible by 8/4/2 --- modules/bmp/image_loader_bmp.cpp | 67 +++++--------------------------- 1 file changed, 10 insertions(+), 57 deletions(-) diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp index 72b540496d09..1804d73a696b 100644 --- a/modules/bmp/image_loader_bmp.cpp +++ b/modules/bmp/image_loader_bmp.cpp @@ -59,30 +59,6 @@ Error ImageLoaderBMP::convert_to_image(Ref p_image, size_t height = (size_t)p_header.bmp_info_header.bmp_height; size_t bits_per_pixel = (size_t)p_header.bmp_info_header.bmp_bit_count; - // Check whether we can load it - - if (bits_per_pixel == 1) { - // Requires bit unpacking... - ERR_FAIL_COND_V_MSG(width % 8 != 0, ERR_UNAVAILABLE, - vformat("1-bpp BMP images must have a width that is a multiple of 8, but the imported BMP is %d pixels wide.", int(width))); - ERR_FAIL_COND_V_MSG(height % 8 != 0, ERR_UNAVAILABLE, - vformat("1-bpp BMP images must have a height that is a multiple of 8, but the imported BMP is %d pixels tall.", int(height))); - - } else if (bits_per_pixel == 2) { - // Requires bit unpacking... - ERR_FAIL_COND_V_MSG(width % 4 != 0, ERR_UNAVAILABLE, - vformat("2-bpp BMP images must have a width that is a multiple of 4, but the imported BMP is %d pixels wide.", int(width))); - ERR_FAIL_COND_V_MSG(height % 4 != 0, ERR_UNAVAILABLE, - vformat("2-bpp BMP images must have a height that is a multiple of 4, but the imported BMP is %d pixels tall.", int(height))); - - } else if (bits_per_pixel == 4) { - // Requires bit unpacking... - ERR_FAIL_COND_V_MSG(width % 2 != 0, ERR_UNAVAILABLE, - vformat("4-bpp BMP images must have a width that is a multiple of 2, but the imported BMP is %d pixels wide.", int(width))); - ERR_FAIL_COND_V_MSG(height % 2 != 0, ERR_UNAVAILABLE, - vformat("4-bpp BMP images must have a height that is a multiple of 2, but the imported BMP is %d pixels tall.", int(height))); - } - // Image data (might be indexed) Vector data; int data_len = 0; @@ -98,55 +74,32 @@ Error ImageLoaderBMP::convert_to_image(Ref p_image, uint8_t *data_w = data.ptrw(); uint8_t *write_buffer = data_w; - const uint32_t width_bytes = width * bits_per_pixel / 8; - const uint32_t line_width = (width_bytes + 3) & ~3; + const uint32_t width_bytes = (width * bits_per_pixel + 7) / 8; + const uint32_t line_width = (width_bytes + 3) & ~3; // Padded to 4 bytes. - // The actual data traversal is determined by - // the data width in case of 8/4/2/1 bit images - const uint32_t w = bits_per_pixel >= 16 ? width : width_bytes; const uint8_t *line = p_buffer + (line_width * (height - 1)); const uint8_t *end_buffer = p_buffer + p_header.bmp_file_header.bmp_file_size - p_header.bmp_file_header.bmp_file_offset; + ERR_FAIL_COND_V(line + line_width > end_buffer, ERR_FILE_CORRUPT); for (uint64_t i = 0; i < height; i++) { const uint8_t *line_ptr = line; - for (unsigned int j = 0; j < w; j++) { - ERR_FAIL_COND_V(line_ptr >= end_buffer, ERR_FILE_CORRUPT); + for (unsigned int j = 0; j < width; j++) { switch (bits_per_pixel) { case 1: { - uint8_t color_index = *line_ptr; + write_buffer[index] = (line[(j * bits_per_pixel) / 8] >> (8 - bits_per_pixel * (1 + j % 8))) & 0x01; - write_buffer[index + 0] = (color_index >> 7) & 1; - write_buffer[index + 1] = (color_index >> 6) & 1; - write_buffer[index + 2] = (color_index >> 5) & 1; - write_buffer[index + 3] = (color_index >> 4) & 1; - write_buffer[index + 4] = (color_index >> 3) & 1; - write_buffer[index + 5] = (color_index >> 2) & 1; - write_buffer[index + 6] = (color_index >> 1) & 1; - write_buffer[index + 7] = (color_index >> 0) & 1; - - index += 8; - line_ptr += 1; + index++; } break; case 2: { - uint8_t color_index = *line_ptr; + write_buffer[index] = (line[(j * bits_per_pixel) / 8] >> (8 - bits_per_pixel * (1 + j % 4))) & 0x03; - write_buffer[index + 0] = (color_index >> 6) & 3; - write_buffer[index + 1] = (color_index >> 4) & 3; - write_buffer[index + 2] = (color_index >> 2) & 3; - write_buffer[index + 3] = color_index & 3; - - index += 4; - line_ptr += 1; + index++; } break; case 4: { - uint8_t color_index = *line_ptr; - - write_buffer[index + 0] = (color_index >> 4) & 0x0f; - write_buffer[index + 1] = color_index & 0x0f; + write_buffer[index] = (line[(j * bits_per_pixel) / 8] >> (8 - bits_per_pixel * (1 + j % 2))) & 0x0f; - index += 2; - line_ptr += 1; + index++; } break; case 8: { uint8_t color_index = *line_ptr; From b36bebc6da1a603c4092a6f48373168a4b895c5d Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 11 Sep 2024 20:50:51 +0200 Subject: [PATCH 02/37] Add SCROLL_MODE_RESERVE to ScrollContainer --- doc/classes/ScrollContainer.xml | 3 +++ scene/gui/scroll_container.cpp | 32 +++++++++++++++++++++----------- scene/gui/scroll_container.h | 4 ++++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/doc/classes/ScrollContainer.xml b/doc/classes/ScrollContainer.xml index 2181194fd46c..405bba356434 100644 --- a/doc/classes/ScrollContainer.xml +++ b/doc/classes/ScrollContainer.xml @@ -102,6 +102,9 @@ Scrolling enabled, scrollbar will be hidden. + + Combines [constant SCROLL_MODE_AUTO] and [constant SCROLL_MODE_SHOW_ALWAYS]. The scrollbar is only visible if necessary, but the content size is adjusted as if it was always visible. It's useful for ensuring that content size stays the same regardless if the scrollbar is visible. + diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index f1902bade440..2211bd76fc94 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -58,7 +58,7 @@ Size2 ScrollContainer::get_minimum_size() const { if (horizontal_scroll_mode == SCROLL_MODE_DISABLED) { min_size.x = largest_child_min_size.x; - bool v_scroll_show = vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (vertical_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.y > size.y); + bool v_scroll_show = vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || vertical_scroll_mode == SCROLL_MODE_RESERVE || (vertical_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.y > size.y); if (v_scroll_show && v_scroll->get_parent() == this) { min_size.x += v_scroll->get_minimum_size().x; } @@ -66,7 +66,7 @@ Size2 ScrollContainer::get_minimum_size() const { if (vertical_scroll_mode == SCROLL_MODE_DISABLED) { min_size.y = largest_child_min_size.y; - bool h_scroll_show = horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (horizontal_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.x > size.x); + bool h_scroll_show = horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || horizontal_scroll_mode == SCROLL_MODE_RESERVE || (horizontal_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.x > size.x); if (h_scroll_show && h_scroll->get_parent() == this) { min_size.y += h_scroll->get_minimum_size().y; } @@ -92,6 +92,15 @@ void ScrollContainer::_cancel_drag() { } } +bool ScrollContainer::_is_h_scroll_visible() const { + // Scrolls may have been moved out for reasons. + return h_scroll->is_visible() && h_scroll->get_parent() == this; +} + +bool ScrollContainer::_is_v_scroll_visible() const { + return v_scroll->is_visible() && v_scroll->get_parent() == this; +} + void ScrollContainer::gui_input(const Ref &p_gui_input) { ERR_FAIL_COND(p_gui_input.is_null()); @@ -298,11 +307,11 @@ void ScrollContainer::_reposition_children() { ofs += theme_cache.panel_style->get_offset(); bool rtl = is_layout_rtl(); - if (h_scroll->is_visible_in_tree() && h_scroll->get_parent() == this) { //scrolls may have been moved out for reasons + if (_is_h_scroll_visible() || horizontal_scroll_mode == SCROLL_MODE_RESERVE) { size.y -= h_scroll->get_minimum_size().y; } - if (v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) { //scrolls may have been moved out for reasons + if (_is_v_scroll_visible() || vertical_scroll_mode == SCROLL_MODE_RESERVE) { size.x -= v_scroll->get_minimum_size().x; } @@ -324,7 +333,7 @@ void ScrollContainer::_reposition_children() { r.size.height = MAX(size.height, minsize.height); } r.position += ofs; - if (rtl && v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) { + if (rtl && _is_v_scroll_visible()) { r.position.x += v_scroll->get_minimum_size().x; } r.position = r.position.floor(); @@ -436,14 +445,14 @@ void ScrollContainer::update_scrollbars() { Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); - h_scroll->set_visible(horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (horizontal_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.width > size.width)); - v_scroll->set_visible(vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (vertical_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.height > size.height)); + h_scroll->set_visible(horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || ((horizontal_scroll_mode == SCROLL_MODE_AUTO || horizontal_scroll_mode == SCROLL_MODE_RESERVE) && largest_child_min_size.width > size.width)); + v_scroll->set_visible(vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || ((vertical_scroll_mode == SCROLL_MODE_AUTO || vertical_scroll_mode == SCROLL_MODE_RESERVE) && largest_child_min_size.height > size.height)); h_scroll->set_max(largest_child_min_size.width); - h_scroll->set_page((v_scroll->is_visible() && v_scroll->get_parent() == this) ? size.width - vmin.width : size.width); + h_scroll->set_page(_is_v_scroll_visible() ? size.width - vmin.width : size.width); v_scroll->set_max(largest_child_min_size.height); - v_scroll->set_page((h_scroll->is_visible() && h_scroll->get_parent() == this) ? size.height - hmin.height : size.height); + v_scroll->set_page(_is_h_scroll_visible() ? size.height - hmin.height : size.height); // Avoid scrollbar overlapping. _updating_scrollbars = true; @@ -603,14 +612,15 @@ void ScrollContainer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_vertical", PROPERTY_HINT_NONE, "suffix:px"), "set_v_scroll", "get_v_scroll"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_horizontal_custom_step", PROPERTY_HINT_RANGE, "-1,4096,suffix:px"), "set_horizontal_custom_step", "get_horizontal_custom_step"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_vertical_custom_step", PROPERTY_HINT_RANGE, "-1,4096,suffix:px"), "set_vertical_custom_step", "get_vertical_custom_step"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "horizontal_scroll_mode", PROPERTY_HINT_ENUM, "Disabled,Auto,Always Show,Never Show"), "set_horizontal_scroll_mode", "get_horizontal_scroll_mode"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "vertical_scroll_mode", PROPERTY_HINT_ENUM, "Disabled,Auto,Always Show,Never Show"), "set_vertical_scroll_mode", "get_vertical_scroll_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "horizontal_scroll_mode", PROPERTY_HINT_ENUM, "Disabled,Auto,Always Show,Never Show,Reserve"), "set_horizontal_scroll_mode", "get_horizontal_scroll_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "vertical_scroll_mode", PROPERTY_HINT_ENUM, "Disabled,Auto,Always Show,Never Show,Reserve"), "set_vertical_scroll_mode", "get_vertical_scroll_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_deadzone"), "set_deadzone", "get_deadzone"); BIND_ENUM_CONSTANT(SCROLL_MODE_DISABLED); BIND_ENUM_CONSTANT(SCROLL_MODE_AUTO); BIND_ENUM_CONSTANT(SCROLL_MODE_SHOW_ALWAYS); BIND_ENUM_CONSTANT(SCROLL_MODE_SHOW_NEVER); + BIND_ENUM_CONSTANT(SCROLL_MODE_RESERVE); BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, ScrollContainer, panel_style, "panel"); diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h index 02146618cddd..afd3c8bd57a7 100644 --- a/scene/gui/scroll_container.h +++ b/scene/gui/scroll_container.h @@ -44,6 +44,7 @@ class ScrollContainer : public Container { SCROLL_MODE_AUTO, SCROLL_MODE_SHOW_ALWAYS, SCROLL_MODE_SHOW_NEVER, + SCROLL_MODE_RESERVE, }; private: @@ -75,6 +76,9 @@ class ScrollContainer : public Container { void _cancel_drag(); + bool _is_h_scroll_visible() const; + bool _is_v_scroll_visible() const; + protected: Size2 get_minimum_size() const override; From 89491f4403041ec81e8506a45f00f54033e45202 Mon Sep 17 00:00:00 2001 From: Slashscreen Date: Sun, 11 Aug 2024 23:28:32 -0700 Subject: [PATCH 03/37] Add callable support for `find` and `rfind` `Array` methods --- core/variant/array.cpp | 65 ++++++++++++++++++++++++++++++++- core/variant/array.h | 2 + core/variant/variant_call.cpp | 2 + doc/classes/Array.xml | 39 ++++++++++++++++++++ tests/core/variant/test_array.h | 18 +++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 54cd1eda2fc4..5d3292d0b937 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -369,6 +369,34 @@ int Array::find(const Variant &p_value, int p_from) const { return ret; } +int Array::find_custom(const Callable &p_callable, int p_from) const { + int ret = -1; + + if (p_from < 0 || size() == 0) { + return ret; + } + + const Variant *argptrs[1]; + + for (int i = p_from; i < size(); i++) { + const Variant &val = _p->array[i]; + argptrs[0] = &val; + Variant res; + Callable::CallError ce; + p_callable.callp(argptrs, 1, res, ce); + if (unlikely(ce.error != Callable::CallError::CALL_OK)) { + ERR_FAIL_V_MSG(ret, "Error calling method from 'find_custom': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + } + + ERR_FAIL_COND_V_MSG(res.get_type() != Variant::Type::BOOL, ret, "Error on method from 'find_custom': Return type of callable must be boolean."); + if (res.operator bool()) { + return i; + } + } + + return ret; +} + int Array::rfind(const Variant &p_value, int p_from) const { if (_p->array.size() == 0) { return -1; @@ -394,6 +422,41 @@ int Array::rfind(const Variant &p_value, int p_from) const { return -1; } +int Array::rfind_custom(const Callable &p_callable, int p_from) const { + if (_p->array.size() == 0) { + return -1; + } + + if (p_from < 0) { + // Relative offset from the end. + p_from = _p->array.size() + p_from; + } + if (p_from < 0 || p_from >= _p->array.size()) { + // Limit to array boundaries. + p_from = _p->array.size() - 1; + } + + const Variant *argptrs[1]; + + for (int i = p_from; i >= 0; i--) { + const Variant &val = _p->array[i]; + argptrs[0] = &val; + Variant res; + Callable::CallError ce; + p_callable.callp(argptrs, 1, res, ce); + if (unlikely(ce.error != Callable::CallError::CALL_OK)) { + ERR_FAIL_V_MSG(-1, "Error calling method from 'rfind_custom': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + } + + ERR_FAIL_COND_V_MSG(res.get_type() != Variant::Type::BOOL, -1, "Error on method from 'rfind_custom': Return type of callable must be boolean."); + if (res.operator bool()) { + return i; + } + } + + return -1; +} + int Array::count(const Variant &p_value) const { Variant value = p_value; ERR_FAIL_COND_V(!_p->typed.validate(value, "count"), 0); @@ -761,7 +824,7 @@ Variant Array::max() const { return Variant(); //not a valid comparison } if (bool(ret)) { - //is less + //is greater maxval = test; } } diff --git a/core/variant/array.h b/core/variant/array.h index 3aa957b31268..ec6c078fb8cb 100644 --- a/core/variant/array.h +++ b/core/variant/array.h @@ -152,7 +152,9 @@ class Array { void reverse(); int find(const Variant &p_value, int p_from = 0) const; + int find_custom(const Callable &p_callable, int p_from = 0) const; int rfind(const Variant &p_value, int p_from = -1) const; + int rfind_custom(const Callable &p_callable, int p_from = -1) const; int count(const Variant &p_value) const; bool has(const Variant &p_value) const; diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 5e402937cf98..65eea9115bdc 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -2289,7 +2289,9 @@ static void _register_variant_builtin_methods_array() { bind_method(Array, back, sarray(), varray()); bind_method(Array, pick_random, sarray(), varray()); bind_method(Array, find, sarray("what", "from"), varray(0)); + bind_method(Array, find_custom, sarray("method", "from"), varray(0)); bind_method(Array, rfind, sarray("what", "from"), varray(-1)); + bind_method(Array, rfind_custom, sarray("method", "from"), varray(-1)); bind_method(Array, count, sarray("value"), varray()); bind_method(Array, has, sarray("value"), varray()); bind_method(Array, pop_back, sarray(), varray()); diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index bd0e05f8e02b..0230c5bd7279 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -325,6 +325,7 @@ Returns the number of times an element is in the array. + To count how many elements in an array satisfy a condition, see [method reduce]. @@ -396,6 +397,25 @@ [b]Note:[/b] For performance reasons, the search is affected by [param what]'s [enum Variant.Type]. For example, [code]7[/code] ([int]) and [code]7.0[/code] ([float]) are not considered equal for this method. + + + + + + Returns the index of the [b]first[/b] element in the array that causes [param method] to return [code]true[/code], or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the end of the array. + [param method] is a callable that takes an element of the array, and returns a [bool]. + [b]Note:[/b] If you just want to know whether the array contains [i]anything[/i] that satisfies [param method], use [method any]. + [codeblocks] + [gdscript] + func is_even(number): + return number % 2 == 0 + + func _ready(): + print([1, 3, 4, 7].find_custom(is_even.bind())) # prints 2 + [/gdscript] + [/codeblocks] + + @@ -619,6 +639,17 @@ func is_length_greater(a, b): return a.length() > b.length() [/codeblock] + This method can also be used to count how many elements in an array satisfy a certain condition, similar to [method count]: + [codeblock] + func is_even(number): + return number % 2 == 0 + + func _ready(): + var arr = [1, 2, 3, 4, 5] + # Increment count if it's even, else leaves count the same. + var even_count = arr.reduce(func(count, next): return count + 1 if is_even(next) else count, 0) + print(even_count) # Prints 2 + [/codeblock] See also [method map], [method filter], [method any] and [method all]. @@ -655,6 +686,14 @@ Returns the index of the [b]last[/b] occurrence of [param what] in this array, or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the beginning of the array. This method is the reverse of [method find]. + + + + + + Returns the index of the [b]last[/b] element of the array that causes [param method] to return [code]true[/code], or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the beginning of the array. This method is the reverse of [method find_custom]. + + diff --git a/tests/core/variant/test_array.h b/tests/core/variant/test_array.h index 787b8f39d9fe..15e2cebe0990 100644 --- a/tests/core/variant/test_array.h +++ b/tests/core/variant/test_array.h @@ -634,6 +634,24 @@ TEST_CASE("[Array] Typed copying") { a6.clear(); } +static bool _find_custom_callable(const Variant &p_val) { + return (int)p_val % 2 == 0; +} + +TEST_CASE("[Array] Test find_custom") { + Array a1 = build_array(1, 3, 4, 5, 8, 9); + // Find first even number. + int index = a1.find_custom(callable_mp_static(_find_custom_callable)); + CHECK_EQ(index, 2); +} + +TEST_CASE("[Array] Test rfind_custom") { + Array a1 = build_array(1, 3, 4, 5, 8, 9); + // Find last even number. + int index = a1.rfind_custom(callable_mp_static(_find_custom_callable)); + CHECK_EQ(index, 4); +} + } // namespace TestArray #endif // TEST_ARRAY_H From 68d494e24e2d6704ae95b1d00fa91b440311e8c3 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Thu, 15 Aug 2024 09:14:41 +0800 Subject: [PATCH 04/37] Add translation domain --- core/register_core_types.cpp | 1 + core/string/translation_domain.cpp | 165 +++++++++++++++++++++++++++++ core/string/translation_domain.h | 65 ++++++++++++ core/string/translation_server.cpp | 153 +++++++++----------------- core/string/translation_server.h | 12 ++- doc/classes/TranslationDomain.xml | 59 +++++++++++ doc/classes/TranslationServer.xml | 40 +++++-- 7 files changed, 379 insertions(+), 116 deletions(-) create mode 100644 core/string/translation_domain.cpp create mode 100644 core/string/translation_domain.h create mode 100644 doc/classes/TranslationDomain.xml diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index c866ff041525..3a578d01a6ba 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -233,6 +233,7 @@ void register_core_types() { GDREGISTER_CLASS(MainLoop); GDREGISTER_CLASS(Translation); + GDREGISTER_CLASS(TranslationDomain); GDREGISTER_CLASS(OptimizedTranslation); GDREGISTER_CLASS(UndoRedo); GDREGISTER_CLASS(TriangleMesh); diff --git a/core/string/translation_domain.cpp b/core/string/translation_domain.cpp new file mode 100644 index 000000000000..b44eb40366a9 --- /dev/null +++ b/core/string/translation_domain.cpp @@ -0,0 +1,165 @@ +/**************************************************************************/ +/* translation_domain.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "translation_domain.h" + +#include "core/string/translation.h" +#include "core/string/translation_server.h" + +StringName TranslationDomain::get_message_from_translations(const String &p_locale, const StringName &p_message, const StringName &p_context) const { + StringName res; + int best_score = 0; + + for (const Ref &E : translations) { + ERR_CONTINUE(E.is_null()); + int score = TranslationServer::get_singleton()->compare_locales(p_locale, E->get_locale()); + if (score > 0 && score >= best_score) { + const StringName r = E->get_message(p_message, p_context); + if (!r) { + continue; + } + res = r; + best_score = score; + if (score == 10) { + break; // Exact match, skip the rest. + } + } + } + + return res; +} + +StringName TranslationDomain::get_message_from_translations(const String &p_locale, const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const { + StringName res; + int best_score = 0; + + for (const Ref &E : translations) { + ERR_CONTINUE(E.is_null()); + int score = TranslationServer::get_singleton()->compare_locales(p_locale, E->get_locale()); + if (score > 0 && score >= best_score) { + const StringName r = E->get_plural_message(p_message, p_message_plural, p_n, p_context); + if (!r) { + continue; + } + res = r; + best_score = score; + if (score == 10) { + break; // Exact match, skip the rest. + } + } + } + + return res; +} + +PackedStringArray TranslationDomain::get_loaded_locales() const { + PackedStringArray locales; + for (const Ref &E : translations) { + ERR_CONTINUE(E.is_null()); + locales.push_back(E->get_locale()); + } + return locales; +} + +Ref TranslationDomain::get_translation_object(const String &p_locale) const { + Ref res; + int best_score = 0; + + for (const Ref &E : translations) { + ERR_CONTINUE(E.is_null()); + + int score = TranslationServer::get_singleton()->compare_locales(p_locale, E->get_locale()); + if (score > 0 && score >= best_score) { + res = E; + best_score = score; + if (score == 10) { + break; // Exact match, skip the rest. + } + } + } + return res; +} + +void TranslationDomain::add_translation(const Ref &p_translation) { + translations.insert(p_translation); +} + +void TranslationDomain::remove_translation(const Ref &p_translation) { + translations.erase(p_translation); +} + +void TranslationDomain::clear() { + translations.clear(); +} + +StringName TranslationDomain::translate(const StringName &p_message, const StringName &p_context) const { + const String &locale = TranslationServer::get_singleton()->get_locale(); + StringName res = get_message_from_translations(locale, p_message, p_context); + + const String &fallback = TranslationServer::get_singleton()->get_fallback_locale(); + if (!res && fallback.length() >= 2) { + res = get_message_from_translations(fallback, p_message, p_context); + } + + if (!res) { + return p_message; + } + return res; +} + +StringName TranslationDomain::translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const { + const String &locale = TranslationServer::get_singleton()->get_locale(); + StringName res = get_message_from_translations(locale, p_message, p_message_plural, p_n, p_context); + + const String &fallback = TranslationServer::get_singleton()->get_fallback_locale(); + if (!res && fallback.length() >= 2) { + res = get_message_from_translations(fallback, p_message, p_message_plural, p_n, p_context); + } + + if (!res) { + if (p_n == 1) { + return p_message; + } + return p_message_plural; + } + return res; +} + +void TranslationDomain::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_translation_object", "locale"), &TranslationDomain::get_translation_object); + ClassDB::bind_method(D_METHOD("add_translation", "translation"), &TranslationDomain::add_translation); + ClassDB::bind_method(D_METHOD("remove_translation", "translation"), &TranslationDomain::remove_translation); + ClassDB::bind_method(D_METHOD("clear"), &TranslationDomain::clear); + ClassDB::bind_method(D_METHOD("translate", "message", "context"), &TranslationDomain::translate, DEFVAL(StringName())); + ClassDB::bind_method(D_METHOD("translate_plural", "message", "message_plural", "n", "context"), &TranslationDomain::translate_plural, DEFVAL(StringName())); +} + +TranslationDomain::TranslationDomain() { +} diff --git a/core/string/translation_domain.h b/core/string/translation_domain.h new file mode 100644 index 000000000000..61399672174b --- /dev/null +++ b/core/string/translation_domain.h @@ -0,0 +1,65 @@ +/**************************************************************************/ +/* translation_domain.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef TRANSLATION_DOMAIN_H +#define TRANSLATION_DOMAIN_H + +#include "core/object/ref_counted.h" + +class Translation; + +class TranslationDomain : public RefCounted { + GDCLASS(TranslationDomain, RefCounted); + + HashSet> translations; + +protected: + static void _bind_methods(); + +public: + // Methods in this section are not intended for scripting. + StringName get_message_from_translations(const String &p_locale, const StringName &p_message, const StringName &p_context) const; + StringName get_message_from_translations(const String &p_locale, const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const; + PackedStringArray get_loaded_locales() const; + +public: + Ref get_translation_object(const String &p_locale) const; + + void add_translation(const Ref &p_translation); + void remove_translation(const Ref &p_translation); + void clear(); + + StringName translate(const StringName &p_message, const StringName &p_context) const; + StringName translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const; + + TranslationDomain(); +}; + +#endif // TRANSLATION_DOMAIN_H diff --git a/core/string/translation_server.cpp b/core/string/translation_server.cpp index d4aa1523409d..ae822b43fb46 100644 --- a/core/string/translation_server.cpp +++ b/core/string/translation_server.cpp @@ -404,69 +404,36 @@ String TranslationServer::get_locale() const { return locale; } -PackedStringArray TranslationServer::get_loaded_locales() const { - PackedStringArray locales; - for (const Ref &E : translations) { - const Ref &t = E; - ERR_FAIL_COND_V(t.is_null(), PackedStringArray()); - String l = t->get_locale(); - - locales.push_back(l); - } +String TranslationServer::get_fallback_locale() const { + return fallback; +} - return locales; +PackedStringArray TranslationServer::get_loaded_locales() const { + return main_domain->get_loaded_locales(); } void TranslationServer::add_translation(const Ref &p_translation) { - translations.insert(p_translation); + main_domain->add_translation(p_translation); } void TranslationServer::remove_translation(const Ref &p_translation) { - translations.erase(p_translation); + main_domain->remove_translation(p_translation); } Ref TranslationServer::get_translation_object(const String &p_locale) { - Ref res; - int best_score = 0; - - for (const Ref &E : translations) { - const Ref &t = E; - ERR_FAIL_COND_V(t.is_null(), nullptr); - String l = t->get_locale(); - - int score = compare_locales(p_locale, l); - if (score > 0 && score >= best_score) { - res = t; - best_score = score; - if (score == 10) { - break; // Exact match, skip the rest. - } - } - } - return res; + return main_domain->get_translation_object(p_locale); } void TranslationServer::clear() { - translations.clear(); + main_domain->clear(); } StringName TranslationServer::translate(const StringName &p_message, const StringName &p_context) const { - // Match given message against the translation catalog for the project locale. - if (!enabled) { return p_message; } - StringName res = _get_message_from_translations(p_message, p_context, locale, false); - - if (!res && fallback.length() >= 2) { - res = _get_message_from_translations(p_message, p_context, fallback, false); - } - - if (!res) { - return pseudolocalization_enabled ? pseudolocalize(p_message) : p_message; - } - + const StringName res = main_domain->translate(p_message, p_context); return pseudolocalization_enabled ? pseudolocalize(res) : res; } @@ -478,51 +445,7 @@ StringName TranslationServer::translate_plural(const StringName &p_message, cons return p_message_plural; } - StringName res = _get_message_from_translations(p_message, p_context, locale, true, p_message_plural, p_n); - - if (!res && fallback.length() >= 2) { - res = _get_message_from_translations(p_message, p_context, fallback, true, p_message_plural, p_n); - } - - if (!res) { - if (p_n == 1) { - return p_message; - } - return p_message_plural; - } - - return res; -} - -StringName TranslationServer::_get_message_from_translations(const StringName &p_message, const StringName &p_context, const String &p_locale, bool plural, const String &p_message_plural, int p_n) const { - StringName res; - int best_score = 0; - - for (const Ref &E : translations) { - const Ref &t = E; - ERR_FAIL_COND_V(t.is_null(), p_message); - String l = t->get_locale(); - - int score = compare_locales(p_locale, l); - if (score > 0 && score >= best_score) { - StringName r; - if (!plural) { - r = t->get_message(p_message, p_context); - } else { - r = t->get_plural_message(p_message, p_message_plural, p_n, p_context); - } - if (!r) { - continue; - } - res = r; - best_score = score; - if (score == 10) { - break; // Exact match, skip the rest. - } - } - } - - return res; + return main_domain->translate_plural(p_message, p_message_plural, p_n, p_context); } TranslationServer *TranslationServer::singleton = nullptr; @@ -549,6 +472,34 @@ bool TranslationServer::_load_translations(const String &p_from) { return false; } +bool TranslationServer::has_domain(const StringName &p_domain) const { + if (p_domain == StringName()) { + return true; + } + return custom_domains.has(p_domain); +} + +Ref TranslationServer::get_or_add_domain(const StringName &p_domain) { + if (p_domain == StringName()) { + return main_domain; + } + const Ref *domain = custom_domains.getptr(p_domain); + if (domain) { + if (domain->is_valid()) { + return *domain; + } + ERR_PRINT("Bug (please report): Found invalid translation domain."); + } + Ref new_domain = memnew(TranslationDomain); + custom_domains[p_domain] = new_domain; + return new_domain; +} + +void TranslationServer::remove_domain(const StringName &p_domain) { + ERR_FAIL_COND_MSG(p_domain == StringName(), "Cannot remove main translation domain."); + custom_domains.erase(p_domain); +} + void TranslationServer::setup() { String test = GLOBAL_DEF("internationalization/locale/test", ""); test = test.strip_edges(); @@ -595,24 +546,11 @@ String TranslationServer::get_tool_locale() { { #endif // Look for best matching loaded translation. - String best_locale = "en"; - int best_score = 0; - - for (const Ref &E : translations) { - const Ref &t = E; - ERR_FAIL_COND_V(t.is_null(), best_locale); - String l = t->get_locale(); - - int score = compare_locales(locale, l); - if (score > 0 && score >= best_score) { - best_locale = l; - best_score = score; - if (score == 10) { - break; // Exact match, skip the rest. - } - } + Ref t = main_domain->get_translation_object(locale); + if (t.is_null()) { + return "en"; } - return best_locale; + return t->get_locale(); } } @@ -925,6 +863,10 @@ void TranslationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_translation", "translation"), &TranslationServer::remove_translation); ClassDB::bind_method(D_METHOD("get_translation_object", "locale"), &TranslationServer::get_translation_object); + ClassDB::bind_method(D_METHOD("has_domain", "domain"), &TranslationServer::has_domain); + ClassDB::bind_method(D_METHOD("get_or_add_domain", "domain"), &TranslationServer::get_or_add_domain); + ClassDB::bind_method(D_METHOD("remove_domain", "domain"), &TranslationServer::remove_domain); + ClassDB::bind_method(D_METHOD("clear"), &TranslationServer::clear); ClassDB::bind_method(D_METHOD("get_loaded_locales"), &TranslationServer::get_loaded_locales); @@ -947,5 +889,6 @@ void TranslationServer::load_translations() { TranslationServer::TranslationServer() { singleton = this; + main_domain.instantiate(); init_locale_info(); } diff --git a/core/string/translation_server.h b/core/string/translation_server.h index bb285ab19cac..1271abec99d3 100644 --- a/core/string/translation_server.h +++ b/core/string/translation_server.h @@ -32,6 +32,7 @@ #define TRANSLATION_SERVER_H #include "core/string/translation.h" +#include "core/string/translation_domain.h" class TranslationServer : public Object { GDCLASS(TranslationServer, Object); @@ -39,7 +40,9 @@ class TranslationServer : public Object { String locale = "en"; String fallback; - HashSet> translations; + Ref main_domain; + HashMap> custom_domains; + Ref tool_translation; Ref property_translation; Ref doc_translation; @@ -70,8 +73,6 @@ class TranslationServer : public Object { bool _load_translations(const String &p_from); String _standardize_locale(const String &p_locale, bool p_add_defaults) const; - StringName _get_message_from_translations(const StringName &p_message, const StringName &p_context, const String &p_locale, bool plural, const String &p_message_plural = "", int p_n = 0) const; - static void _bind_methods(); struct LocaleScriptInfo { @@ -99,6 +100,7 @@ class TranslationServer : public Object { void set_locale(const String &p_locale); String get_locale() const; + String get_fallback_locale() const; Ref get_translation_object(const String &p_locale); Vector get_all_languages() const; @@ -144,6 +146,10 @@ class TranslationServer : public Object { StringName extractable_translate(const StringName &p_message, const StringName &p_context = "") const; StringName extractable_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const; + bool has_domain(const StringName &p_domain) const; + Ref get_or_add_domain(const StringName &p_domain); + void remove_domain(const StringName &p_domain); + void setup(); void clear(); diff --git a/doc/classes/TranslationDomain.xml b/doc/classes/TranslationDomain.xml new file mode 100644 index 000000000000..8079685885da --- /dev/null +++ b/doc/classes/TranslationDomain.xml @@ -0,0 +1,59 @@ + + + + A self-contained collection of [Translation] resources. + + + [TranslationDomain] is a self-contained collection of [Translation] resources. Translations can be added to or removed from it. + + + + + + + + + Adds a translation. + + + + + + Removes all translations. + + + + + + + Returns the [Translation] instance that best matches [param locale]. Returns [code]null[/code] if there are no matches. + + + + + + + Removes the given translation. + + + + + + + + Returns the current locale's translation for the given message and context. + + + + + + + + + + Returns the current locale's translation for the given message, plural message and context. + The number [param n] is the number or quantity of the plural object. It will be used to guide the translation system to fetch the correct plural form for the selected language. + + + + diff --git a/doc/classes/TranslationServer.xml b/doc/classes/TranslationServer.xml index db1a65278c91..39afa2c0d2cd 100644 --- a/doc/classes/TranslationServer.xml +++ b/doc/classes/TranslationServer.xml @@ -4,7 +4,8 @@ The server responsible for language translations. - The server that manages all language translations. Translations can be added to or removed from it. + The translation server is the API backend that manages all language translations. + Translations are stored in [TranslationDomain]s, which can be accessed by name. The most commonly used translation domain is the main translation domain, which always exists and can be accessed using an empty [StringName]. The translation server provides wrapper methods for accessing the master translation domain directly, without having to fetch the main translation domain first. $DOCS_URL/tutorials/i18n/internationalizing_games.html @@ -15,13 +16,13 @@ - Adds a [Translation] resource. + Adds a translation to the main translation domain. - Clears the server from all translations. + Removes all translations from the main translation domain. @@ -84,6 +85,13 @@ Returns a locale's language and its variant (e.g. [code]"en_US"[/code] would return [code]"English (United States)"[/code]). + + + + + Returns the translation domain with the specified name. An empty translation domain will be created and added if it does not exist. + + @@ -102,8 +110,14 @@ - Returns the [Translation] instance based on the [param locale] passed in. - It will return [code]null[/code] if there is no [Translation] instance that matches the [param locale]. + Returns the [Translation] instance that best matches [param locale] in the main translation domain. Returns [code]null[/code] if there are no matches. + + + + + + + Returns [code]true[/code] if a translation domain with the specified name exists. @@ -119,11 +133,19 @@ Reparses the pseudolocalization options and reloads the translation. + + + + + Removes the translation domain with the specified name. + [b]Note:[/b] Trying to remove the main translation domain is an error. + + - Removes the given translation from the server. + Removes the given translation from the main translation domain. @@ -146,7 +168,8 @@ - Returns the current locale's translation for the given message (key) and context. + Returns the current locale's translation for the given message and context. + [b]Note:[/b] This method always uses the main translation domain. @@ -156,8 +179,9 @@ - Returns the current locale's translation for the given message (key), plural message and context. + Returns the current locale's translation for the given message, plural message and context. The number [param n] is the number or quantity of the plural object. It will be used to guide the translation system to fetch the correct plural form for the selected language. + [b]Note:[/b] This method always uses the main translation domain. From c5d147b9b573fe1a534a7bba78ab5615ffadad96 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 16 Aug 2024 17:25:24 +0800 Subject: [PATCH 05/37] Allow configuring which translation domain Object.tr uses --- core/object/object.cpp | 16 ++++++++++++-- core/object/object.h | 5 +++++ doc/classes/Node.xml | 7 +++++++ doc/classes/Object.xml | 13 ++++++++++++ scene/main/node.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++ scene/main/node.h | 8 +++++++ 6 files changed, 94 insertions(+), 2 deletions(-) diff --git a/core/object/object.cpp b/core/object/object.cpp index da3ca6bc61f2..faf109a13c44 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1527,6 +1527,14 @@ void Object::initialize_class() { initialized = true; } +StringName Object::get_translation_domain() const { + return _translation_domain; +} + +void Object::set_translation_domain(const StringName &p_domain) { + _translation_domain = p_domain; +} + String Object::tr(const StringName &p_message, const StringName &p_context) const { if (!_can_translate || !TranslationServer::get_singleton()) { return p_message; @@ -1541,7 +1549,8 @@ String Object::tr(const StringName &p_message, const StringName &p_context) cons return TranslationServer::get_singleton()->tool_translate(p_message, p_context); } - return TranslationServer::get_singleton()->translate(p_message, p_context); + const Ref domain = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain()); + return domain->translate(p_message, p_context); } String Object::tr_n(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const { @@ -1562,7 +1571,8 @@ String Object::tr_n(const StringName &p_message, const StringName &p_message_plu return TranslationServer::get_singleton()->tool_translate_plural(p_message, p_message_plural, p_n, p_context); } - return TranslationServer::get_singleton()->translate_plural(p_message, p_message_plural, p_n, p_context); + const Ref domain = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain()); + return domain->translate_plural(p_message, p_message_plural, p_n, p_context); } void Object::_clear_internal_resource_paths(const Variant &p_var) { @@ -1714,6 +1724,8 @@ void Object::_bind_methods() { ClassDB::bind_method(D_METHOD("can_translate_messages"), &Object::can_translate_messages); ClassDB::bind_method(D_METHOD("tr", "message", "context"), &Object::tr, DEFVAL(StringName())); ClassDB::bind_method(D_METHOD("tr_n", "message", "plural_message", "n", "context"), &Object::tr_n, DEFVAL(StringName())); + ClassDB::bind_method(D_METHOD("get_translation_domain"), &Object::get_translation_domain); + ClassDB::bind_method(D_METHOD("set_translation_domain", "domain"), &Object::set_translation_domain); ClassDB::bind_method(D_METHOD("is_queued_for_deletion"), &Object::is_queued_for_deletion); ClassDB::bind_method(D_METHOD("cancel_free"), &Object::cancel_free); diff --git a/core/object/object.h b/core/object/object.h index 6d22f320afc6..1274247d716b 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -665,6 +665,8 @@ class Object { Object(bool p_reference); protected: + StringName _translation_domain; + _FORCE_INLINE_ bool _instance_binding_reference(bool p_reference) { bool can_die = true; if (_instance_bindings) { @@ -954,6 +956,9 @@ class Object { _FORCE_INLINE_ void set_message_translation(bool p_enable) { _can_translate = p_enable; } _FORCE_INLINE_ bool can_translate_messages() const { return _can_translate; } + virtual StringName get_translation_domain() const; + virtual void set_translation_domain(const StringName &p_domain); + #ifdef TOOLS_ENABLED virtual void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const; void editor_set_section_unfold(const String &p_section, bool p_unfolded); diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 0042ce67d52b..42753f70715f 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -973,6 +973,13 @@ Similar to [method call_thread_safe], but for setting properties. + + + + Makes this node inherit the translation domain from its parent node. If this node has no parent, the main translation domain will be used. + This is the default behavior for all nodes. Calling [method Object.set_translation_domain] disables this behavior. + + diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml index a331c05e47cb..98811ba29038 100644 --- a/doc/classes/Object.xml +++ b/doc/classes/Object.xml @@ -818,6 +818,12 @@ [b]Note:[/b] Due of the implementation, each [Dictionary] is formatted very similarly to the returned values of [method get_method_list]. + + + + Returns the name of the translation domain used by [method tr] and [method tr_n]. See also [TranslationServer]. + + @@ -1070,6 +1076,13 @@ If a script already exists, its instance is detached, and its property values and state are lost. Built-in property values are still kept. + + + + + Sets the name of the translation domain used by [method tr] and [method tr_n]. See also [TranslationServer]. + + diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 858fc2246b82..eb3448e1a2ae 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -111,6 +111,7 @@ void Node::_notification(int p_notification) { data.auto_translate_mode = AUTO_TRANSLATE_MODE_ALWAYS; } data.is_auto_translate_dirty = true; + data.is_translation_domain_dirty = true; #ifdef TOOLS_ENABLED // Don't translate UI elements when they're being edited. @@ -1320,6 +1321,51 @@ bool Node::can_auto_translate() const { return data.is_auto_translating; } +StringName Node::get_translation_domain() const { + ERR_READ_THREAD_GUARD_V(StringName()); + + if (data.is_translation_domain_inherited && data.is_translation_domain_dirty) { + const_cast(this)->_translation_domain = data.parent ? data.parent->get_translation_domain() : StringName(); + data.is_translation_domain_dirty = false; + } + return _translation_domain; +} + +void Node::set_translation_domain(const StringName &p_domain) { + ERR_THREAD_GUARD + + if (!data.is_translation_domain_inherited && _translation_domain == p_domain) { + return; + } + + _translation_domain = p_domain; + data.is_translation_domain_inherited = false; + data.is_translation_domain_dirty = false; + _propagate_translation_domain_dirty(); +} + +void Node::set_translation_domain_inherited() { + ERR_THREAD_GUARD + + if (data.is_translation_domain_inherited) { + return; + } + data.is_translation_domain_inherited = true; + data.is_translation_domain_dirty = true; + _propagate_translation_domain_dirty(); +} + +void Node::_propagate_translation_domain_dirty() { + for (KeyValue &K : data.children) { + Node *child = K.value; + if (child->data.is_translation_domain_inherited) { + child->data.is_translation_domain_dirty = true; + child->_propagate_translation_domain_dirty(); + } + } + notification(NOTIFICATION_TRANSLATION_CHANGED); +} + StringName Node::get_name() const { return data.name; } @@ -3610,6 +3656,7 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("set_auto_translate_mode", "mode"), &Node::set_auto_translate_mode); ClassDB::bind_method(D_METHOD("get_auto_translate_mode"), &Node::get_auto_translate_mode); + ClassDB::bind_method(D_METHOD("set_translation_domain_inherited"), &Node::set_translation_domain_inherited); ClassDB::bind_method(D_METHOD("get_window"), &Node::get_window); ClassDB::bind_method(D_METHOD("get_last_exclusive_window"), &Node::get_last_exclusive_window); diff --git a/scene/main/node.h b/scene/main/node.h index dc65513fcaeb..4560ed085c1a 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -255,6 +255,9 @@ class Node : public Object { mutable bool is_auto_translating = true; mutable bool is_auto_translate_dirty = true; + mutable bool is_translation_domain_inherited = true; + mutable bool is_translation_domain_dirty = true; + mutable NodePath *path_cache = nullptr; } data; @@ -281,6 +284,7 @@ class Node : public Object { void _propagate_physics_interpolation_reset_requested(bool p_requested); void _propagate_process_owner(Node *p_owner, int p_pause_notification, int p_enabled_notification); void _propagate_groups_dirty(); + void _propagate_translation_domain_dirty(); Array _get_node_and_resource(const NodePath &p_path); void _duplicate_properties(const Node *p_root, const Node *p_original, Node *p_copy, int p_flags) const; @@ -735,6 +739,10 @@ class Node : public Object { AutoTranslateMode get_auto_translate_mode() const; bool can_auto_translate() const; + virtual StringName get_translation_domain() const override; + virtual void set_translation_domain(const StringName &p_domain) override; + void set_translation_domain_inherited(); + _FORCE_INLINE_ String atr(const String p_message, const StringName p_context = "") const { return can_auto_translate() ? tr(p_message, p_context) : p_message; } _FORCE_INLINE_ String atr_n(const String p_message, const StringName &p_message_plural, int p_n, const StringName p_context = "") const { return can_auto_translate() ? tr_n(p_message, p_message_plural, p_n, p_context) : p_message; } From 818acb42900267f6c5dc2637e1bd8b7002413a98 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 16 Aug 2024 22:19:14 +0800 Subject: [PATCH 06/37] Make editor use translation domains How editor plugins use this feature: 1. Pick a unique translation domain name. 2. `_enter_tree()`: load translations into that translation domain. 3. Call `set_translation_domain()` for its root UI node. 4. `_exit_tree()`: remove that translation domain. Plugins can also set the translation domain to `godot.editor` for nested nodes that should use editor translations. `EditorFileDialog` automatically does this. --- core/object/object.cpp | 18 ----- core/string/translation_server.cpp | 101 ++++------------------------- core/string/translation_server.h | 15 +---- doc/classes/TranslationDomain.xml | 1 + doc/classes/TranslationServer.xml | 2 +- editor/editor_node.cpp | 2 + editor/editor_settings.cpp | 2 + editor/editor_translation.cpp | 16 +++-- editor/gui/editor_file_dialog.cpp | 4 ++ editor/project_manager.cpp | 2 + 10 files changed, 38 insertions(+), 125 deletions(-) diff --git a/core/object/object.cpp b/core/object/object.cpp index faf109a13c44..2d9d468d3883 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1540,15 +1540,6 @@ String Object::tr(const StringName &p_message, const StringName &p_context) cons return p_message; } - if (Engine::get_singleton()->is_editor_hint() || Engine::get_singleton()->is_project_manager_hint()) { - String tr_msg = TranslationServer::get_singleton()->extractable_translate(p_message, p_context); - if (!tr_msg.is_empty() && tr_msg != p_message) { - return tr_msg; - } - - return TranslationServer::get_singleton()->tool_translate(p_message, p_context); - } - const Ref domain = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain()); return domain->translate(p_message, p_context); } @@ -1562,15 +1553,6 @@ String Object::tr_n(const StringName &p_message, const StringName &p_message_plu return p_message_plural; } - if (Engine::get_singleton()->is_editor_hint() || Engine::get_singleton()->is_project_manager_hint()) { - String tr_msg = TranslationServer::get_singleton()->extractable_translate_plural(p_message, p_message_plural, p_n, p_context); - if (!tr_msg.is_empty() && tr_msg != p_message && tr_msg != p_message_plural) { - return tr_msg; - } - - return TranslationServer::get_singleton()->tool_translate_plural(p_message, p_message_plural, p_n, p_context); - } - const Ref domain = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain()); return domain->translate_plural(p_message, p_message_plural, p_n, p_context); } diff --git a/core/string/translation_server.cpp b/core/string/translation_server.cpp index ae822b43fb46..c6b818a49b3b 100644 --- a/core/string/translation_server.cpp +++ b/core/string/translation_server.cpp @@ -525,22 +525,14 @@ void TranslationServer::setup() { #endif } -void TranslationServer::set_tool_translation(const Ref &p_translation) { - tool_translation = p_translation; -} - -Ref TranslationServer::get_tool_translation() const { - return tool_translation; -} - String TranslationServer::get_tool_locale() { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint() || Engine::get_singleton()->is_project_manager_hint()) { - if (TranslationServer::get_singleton()->get_tool_translation().is_valid()) { - return tool_translation->get_locale(); - } else { + const PackedStringArray &locales = editor_domain->get_loaded_locales(); + if (locales.is_empty()) { return "en"; } + return locales[0]; } else { #else { @@ -555,97 +547,23 @@ String TranslationServer::get_tool_locale() { } StringName TranslationServer::tool_translate(const StringName &p_message, const StringName &p_context) const { - if (tool_translation.is_valid()) { - StringName r = tool_translation->get_message(p_message, p_context); - if (r) { - return r; - } - } - return p_message; + return editor_domain->translate(p_message, p_context); } StringName TranslationServer::tool_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const { - if (tool_translation.is_valid()) { - StringName r = tool_translation->get_plural_message(p_message, p_message_plural, p_n, p_context); - if (r) { - return r; - } - } - - if (p_n == 1) { - return p_message; - } - return p_message_plural; -} - -void TranslationServer::set_property_translation(const Ref &p_translation) { - property_translation = p_translation; + return editor_domain->translate_plural(p_message, p_message_plural, p_n, p_context); } StringName TranslationServer::property_translate(const StringName &p_message, const StringName &p_context) const { - if (property_translation.is_valid()) { - StringName r = property_translation->get_message(p_message, p_context); - if (r) { - return r; - } - } - return p_message; -} - -void TranslationServer::set_doc_translation(const Ref &p_translation) { - doc_translation = p_translation; + return property_domain->translate(p_message, p_context); } StringName TranslationServer::doc_translate(const StringName &p_message, const StringName &p_context) const { - if (doc_translation.is_valid()) { - StringName r = doc_translation->get_message(p_message, p_context); - if (r) { - return r; - } - } - return p_message; + return doc_domain->translate(p_message, p_context); } StringName TranslationServer::doc_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const { - if (doc_translation.is_valid()) { - StringName r = doc_translation->get_plural_message(p_message, p_message_plural, p_n, p_context); - if (r) { - return r; - } - } - - if (p_n == 1) { - return p_message; - } - return p_message_plural; -} - -void TranslationServer::set_extractable_translation(const Ref &p_translation) { - extractable_translation = p_translation; -} - -StringName TranslationServer::extractable_translate(const StringName &p_message, const StringName &p_context) const { - if (extractable_translation.is_valid()) { - StringName r = extractable_translation->get_message(p_message, p_context); - if (r) { - return r; - } - } - return p_message; -} - -StringName TranslationServer::extractable_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const { - if (extractable_translation.is_valid()) { - StringName r = extractable_translation->get_plural_message(p_message, p_message_plural, p_n, p_context); - if (r) { - return r; - } - } - - if (p_n == 1) { - return p_message; - } - return p_message_plural; + return doc_domain->translate_plural(p_message, p_message_plural, p_n, p_context); } bool TranslationServer::is_pseudolocalization_enabled() const { @@ -890,5 +808,8 @@ void TranslationServer::load_translations() { TranslationServer::TranslationServer() { singleton = this; main_domain.instantiate(); + editor_domain = get_or_add_domain("godot.editor"); + property_domain = get_or_add_domain("godot.properties"); + doc_domain = get_or_add_domain("godot.documentation"); init_locale_info(); } diff --git a/core/string/translation_server.h b/core/string/translation_server.h index 1271abec99d3..272fa1f11cc5 100644 --- a/core/string/translation_server.h +++ b/core/string/translation_server.h @@ -41,13 +41,11 @@ class TranslationServer : public Object { String fallback; Ref main_domain; + Ref editor_domain; + Ref property_domain; + Ref doc_domain; HashMap> custom_domains; - Ref tool_translation; - Ref property_translation; - Ref doc_translation; - Ref extractable_translation; - bool enabled = true; bool pseudolocalization_enabled = false; @@ -133,18 +131,11 @@ class TranslationServer : public Object { int compare_locales(const String &p_locale_a, const String &p_locale_b) const; String get_tool_locale(); - void set_tool_translation(const Ref &p_translation); - Ref get_tool_translation() const; StringName tool_translate(const StringName &p_message, const StringName &p_context = "") const; StringName tool_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const; - void set_property_translation(const Ref &p_translation); StringName property_translate(const StringName &p_message, const StringName &p_context = "") const; - void set_doc_translation(const Ref &p_translation); StringName doc_translate(const StringName &p_message, const StringName &p_context = "") const; StringName doc_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const; - void set_extractable_translation(const Ref &p_translation); - StringName extractable_translate(const StringName &p_message, const StringName &p_context = "") const; - StringName extractable_translate_plural(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const; bool has_domain(const StringName &p_domain) const; Ref get_or_add_domain(const StringName &p_domain); diff --git a/doc/classes/TranslationDomain.xml b/doc/classes/TranslationDomain.xml index 8079685885da..da6f2704bf36 100644 --- a/doc/classes/TranslationDomain.xml +++ b/doc/classes/TranslationDomain.xml @@ -5,6 +5,7 @@ [TranslationDomain] is a self-contained collection of [Translation] resources. Translations can be added to or removed from it. + If you're working with the main translation domain, it is more convenient to use the wrap methods on [TranslationServer]. diff --git a/doc/classes/TranslationServer.xml b/doc/classes/TranslationServer.xml index 39afa2c0d2cd..0a4965c36c1c 100644 --- a/doc/classes/TranslationServer.xml +++ b/doc/classes/TranslationServer.xml @@ -5,7 +5,7 @@ The translation server is the API backend that manages all language translations. - Translations are stored in [TranslationDomain]s, which can be accessed by name. The most commonly used translation domain is the main translation domain, which always exists and can be accessed using an empty [StringName]. The translation server provides wrapper methods for accessing the master translation domain directly, without having to fetch the main translation domain first. + Translations are stored in [TranslationDomain]s, which can be accessed by name. The most commonly used translation domain is the main translation domain. It always exists and can be accessed using an empty [StringName]. The translation server provides wrapper methods for accessing the main translation domain directly, without having to fetch the translation domain first. Custom translation domains are mainly for advanced usages like editor plugins. Names starting with [code]godot.[/code] are reserved for engine internals. $DOCS_URL/tutorials/i18n/internationalizing_games.html diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 66fd2cf904ec..770bf5726dce 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6557,6 +6557,8 @@ EditorNode::EditorNode() { DEV_ASSERT(!singleton); singleton = this; + set_translation_domain("godot.editor"); + Resource::_get_local_scene_func = _resource_get_edited_scene; { diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 96a7700c34a5..2bc14b3410eb 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -1210,6 +1210,8 @@ void EditorSettings::create() { void EditorSettings::setup_language() { String lang = get("interface/editor/editor_language"); + TranslationServer::get_singleton()->set_locale(lang); + if (lang == "en") { return; // Default, nothing to do. } diff --git a/editor/editor_translation.cpp b/editor/editor_translation.cpp index 4654d41082c2..6ccde3b6967f 100644 --- a/editor/editor_translation.cpp +++ b/editor/editor_translation.cpp @@ -54,6 +54,8 @@ Vector get_editor_locales() { } void load_editor_translations(const String &p_locale) { + const Ref domain = TranslationServer::get_singleton()->get_or_add_domain("godot.editor"); + EditorTranslationList *etl = _editor_translations; while (etl->data) { if (etl->lang == p_locale) { @@ -70,7 +72,7 @@ void load_editor_translations(const String &p_locale) { if (tr.is_valid()) { tr->set_locale(etl->lang); - TranslationServer::get_singleton()->set_tool_translation(tr); + domain->add_translation(tr); break; } } @@ -80,6 +82,8 @@ void load_editor_translations(const String &p_locale) { } void load_property_translations(const String &p_locale) { + const Ref domain = TranslationServer::get_singleton()->get_or_add_domain("godot.properties"); + PropertyTranslationList *etl = _property_translations; while (etl->data) { if (etl->lang == p_locale) { @@ -96,7 +100,7 @@ void load_property_translations(const String &p_locale) { if (tr.is_valid()) { tr->set_locale(etl->lang); - TranslationServer::get_singleton()->set_property_translation(tr); + domain->add_translation(tr); break; } } @@ -106,6 +110,8 @@ void load_property_translations(const String &p_locale) { } void load_doc_translations(const String &p_locale) { + const Ref domain = TranslationServer::get_singleton()->get_or_add_domain("godot.documentation"); + DocTranslationList *dtl = _doc_translations; while (dtl->data) { if (dtl->lang == p_locale) { @@ -122,7 +128,7 @@ void load_doc_translations(const String &p_locale) { if (tr.is_valid()) { tr->set_locale(dtl->lang); - TranslationServer::get_singleton()->set_doc_translation(tr); + domain->add_translation(tr); break; } } @@ -132,6 +138,8 @@ void load_doc_translations(const String &p_locale) { } void load_extractable_translations(const String &p_locale) { + const Ref domain = TranslationServer::get_singleton()->get_or_add_domain("godot.editor"); + ExtractableTranslationList *etl = _extractable_translations; while (etl->data) { if (etl->lang == p_locale) { @@ -148,7 +156,7 @@ void load_extractable_translations(const String &p_locale) { if (tr.is_valid()) { tr->set_locale(etl->lang); - TranslationServer::get_singleton()->set_extractable_translation(tr); + domain->add_translation(tr); break; } } diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp index b6aa3c22152e..18f1f6da0c5e 100644 --- a/editor/gui/editor_file_dialog.cpp +++ b/editor/gui/editor_file_dialog.cpp @@ -207,6 +207,10 @@ void EditorFileDialog::_update_theme_item_cache() { void EditorFileDialog::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_POSTINITIALIZE: { + set_translation_domain(SNAME("godot.editor")); + } break; + case NOTIFICATION_THEME_CHANGED: case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_TRANSLATION_CHANGED: { diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 279590563acc..8411c0edea12 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -1081,6 +1081,8 @@ void ProjectManager::_titlebar_resized() { ProjectManager::ProjectManager() { singleton = this; + set_translation_domain("godot.editor"); + // Turn off some servers we aren't going to be using in the Project Manager. NavigationServer3D::get_singleton()->set_active(false); PhysicsServer3D::get_singleton()->set_active(false); From f7a7ecc10ae6f8f0590651d836e1169c6034087f Mon Sep 17 00:00:00 2001 From: MewPurPur Date: Thu, 19 Sep 2024 01:15:12 +0300 Subject: [PATCH 07/37] Expose has_undo() and has_redo() of LineEdit --- doc/classes/LineEdit.xml | 12 ++++++++++++ scene/gui/line_edit.cpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml index d218f720a380..9c460e6d62b4 100644 --- a/doc/classes/LineEdit.xml +++ b/doc/classes/LineEdit.xml @@ -151,12 +151,24 @@ Returns [code]true[/code] if the user has text in the [url=https://en.wikipedia.org/wiki/Input_method]Input Method Editor[/url] (IME). + + + + Returns [code]true[/code] if a "redo" action is available. + + Returns [code]true[/code] if the user has selected text. + + + + Returns [code]true[/code] if an "undo" action is available. + + diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index a08fb96e71d0..756cb77c60d2 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -2763,6 +2763,8 @@ void LineEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("select", "from", "to"), &LineEdit::select, DEFVAL(0), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("select_all"), &LineEdit::select_all); ClassDB::bind_method(D_METHOD("deselect"), &LineEdit::deselect); + ClassDB::bind_method(D_METHOD("has_undo"), &LineEdit::has_undo); + ClassDB::bind_method(D_METHOD("has_redo"), &LineEdit::has_redo); ClassDB::bind_method(D_METHOD("has_selection"), &LineEdit::has_selection); ClassDB::bind_method(D_METHOD("get_selected_text"), &LineEdit::get_selected_text); ClassDB::bind_method(D_METHOD("get_selection_from_column"), &LineEdit::get_selection_from_column); From ec189b1574d24fda24f13210be0fb79a309b22da Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Thu, 19 Sep 2024 19:21:48 +0200 Subject: [PATCH 08/37] C#: Use dotnet CLI to launch OpenVisualStudio.dll Use the DLL instead of the EXE, so we can rely on the dotnet CLI handling the architecture. --- .../GodotTools.OpenVisualStudio.csproj | 1 - modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/GodotTools.OpenVisualStudio.csproj b/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/GodotTools.OpenVisualStudio.csproj index f23f2b9a8cfc..208e6d8f4119 100644 --- a/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/GodotTools.OpenVisualStudio.csproj +++ b/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/GodotTools.OpenVisualStudio.csproj @@ -5,7 +5,6 @@ net6.0-windows 10 enable - win-x86 False LatestMajor diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs index d3899c809a2b..e84b4e92c72f 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs @@ -259,11 +259,12 @@ public Error OpenInExternalEditor(Script script, int line, int col) var args = new List { + Path.Combine(GodotSharpDirs.DataEditorToolsDir, "GodotTools.OpenVisualStudio.dll"), GodotSharpDirs.ProjectSlnPath, line >= 0 ? $"{scriptPath};{line + 1};{col + 1}" : scriptPath }; - string command = Path.Combine(GodotSharpDirs.DataEditorToolsDir, "GodotTools.OpenVisualStudio.exe"); + string command = DotNetFinder.FindDotNetExe() ?? "dotnet"; try { From d6c0a53ecf3e02aba625b5a70de4454645216b2f Mon Sep 17 00:00:00 2001 From: Matt Enad Date: Thu, 19 Sep 2024 13:31:05 -0400 Subject: [PATCH 09/37] Add error messages to binding generator --- modules/mono/editor/bindings_generator.cpp | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 3222c58c4ed7..d0adf39fb2be 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -1452,7 +1452,7 @@ Error BindingsGenerator::_populate_method_icalls_table(const TypeInterface &p_it } const TypeInterface *return_type = _get_type_or_null(imethod.return_type); - ERR_FAIL_NULL_V(return_type, ERR_BUG); // Return type not found + ERR_FAIL_NULL_V_MSG(return_type, ERR_BUG, "Return type '" + imethod.return_type.cname + "' was not found."); String im_unique_sig = get_ret_unique_sig(return_type) + ",CallMethodBind"; @@ -1463,7 +1463,7 @@ Error BindingsGenerator::_populate_method_icalls_table(const TypeInterface &p_it // Get arguments information for (const ArgumentInterface &iarg : imethod.arguments) { const TypeInterface *arg_type = _get_type_or_null(iarg.type); - ERR_FAIL_NULL_V(arg_type, ERR_BUG); // Argument type not found + ERR_FAIL_NULL_V_MSG(arg_type, ERR_BUG, "Argument type '" + iarg.type.cname + "' was not found."); im_unique_sig += ","; im_unique_sig += get_arg_unique_sig(*arg_type); @@ -2313,7 +2313,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str const ArgumentInterface &iarg = *itr; const TypeInterface *arg_type = _get_type_or_null(iarg.type); - ERR_FAIL_NULL_V(arg_type, ERR_BUG); // Argument type not found + ERR_FAIL_NULL_V_MSG(arg_type, ERR_BUG, "Argument type '" + iarg.type.cname + "' was not found."); if (i != 0) { output << ", "; @@ -2333,7 +2333,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str if (imethod.return_type.cname != name_cache.type_void) { const TypeInterface *return_type = _get_type_or_null(imethod.return_type); - ERR_FAIL_NULL_V(return_type, ERR_BUG); // Return type not found + ERR_FAIL_NULL_V_MSG(return_type, ERR_BUG, "Return type '" + imethod.return_type.cname + "' was not found."); output << INDENT3 "ret = " << sformat(return_type->cs_managed_to_variant, "callRet", return_type->cs_type, return_type->name) @@ -2552,7 +2552,7 @@ Error BindingsGenerator::_generate_cs_property(const BindingsGenerator::TypeInte const TypeReference &proptype_name = getter ? getter->return_type : setter->arguments.back()->get().type; const TypeInterface *prop_itype = _get_type_or_singleton_or_null(proptype_name); - ERR_FAIL_NULL_V(prop_itype, ERR_BUG); // Property type not found + ERR_FAIL_NULL_V_MSG(prop_itype, ERR_BUG, "Property type '" + proptype_name.cname + "' was not found."); ERR_FAIL_COND_V_MSG(prop_itype->is_singleton, ERR_BUG, "Property type is a singleton: '" + p_itype.name + "." + String(p_iprop.cname) + "'."); @@ -2651,7 +2651,7 @@ Error BindingsGenerator::_generate_cs_property(const BindingsGenerator::TypeInte Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterface &p_itype, const BindingsGenerator::MethodInterface &p_imethod, int &p_method_bind_count, StringBuilder &p_output) { const TypeInterface *return_type = _get_type_or_singleton_or_null(p_imethod.return_type); - ERR_FAIL_NULL_V(return_type, ERR_BUG); // Return type not found + ERR_FAIL_NULL_V_MSG(return_type, ERR_BUG, "Return type '" + p_imethod.return_type.cname + "' was not found."); ERR_FAIL_COND_V_MSG(return_type->is_singleton, ERR_BUG, "Method return type is a singleton: '" + p_itype.name + "." + p_imethod.name + "'."); @@ -2690,7 +2690,7 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf const ArgumentInterface &first = p_imethod.arguments.front()->get(); for (const ArgumentInterface &iarg : p_imethod.arguments) { const TypeInterface *arg_type = _get_type_or_singleton_or_null(iarg.type); - ERR_FAIL_NULL_V(arg_type, ERR_BUG); // Argument type not found + ERR_FAIL_NULL_V_MSG(arg_type, ERR_BUG, "Argument type '" + iarg.type.cname + "' was not found."); ERR_FAIL_COND_V_MSG(arg_type->is_singleton, ERR_BUG, "Argument type is a singleton: '" + iarg.name + "' of method '" + p_itype.name + "." + p_imethod.name + "'."); @@ -2944,7 +2944,7 @@ Error BindingsGenerator::_generate_cs_signal(const BindingsGenerator::TypeInterf const ArgumentInterface &first = p_isignal.arguments.front()->get(); for (const ArgumentInterface &iarg : p_isignal.arguments) { const TypeInterface *arg_type = _get_type_or_singleton_or_null(iarg.type); - ERR_FAIL_NULL_V(arg_type, ERR_BUG); // Argument type not found + ERR_FAIL_NULL_V_MSG(arg_type, ERR_BUG, "Argument type '" + iarg.type.cname + "' was not found."); ERR_FAIL_COND_V_MSG(arg_type->is_singleton, ERR_BUG, "Argument type is a singleton: '" + iarg.name + "' of signal '" + p_itype.name + "." + p_isignal.name + "'."); @@ -3013,7 +3013,7 @@ Error BindingsGenerator::_generate_cs_signal(const BindingsGenerator::TypeInterf int idx = 0; for (const ArgumentInterface &iarg : p_isignal.arguments) { const TypeInterface *arg_type = _get_type_or_null(iarg.type); - ERR_FAIL_NULL_V(arg_type, ERR_BUG); // Argument type not found + ERR_FAIL_NULL_V_MSG(arg_type, ERR_BUG, "Argument type '" + iarg.type.cname + "' was not found."); if (idx != 0) { p_output << ", "; @@ -3113,7 +3113,7 @@ Error BindingsGenerator::_generate_cs_native_calls(const InternalCall &p_icall, bool ret_void = p_icall.return_type.cname == name_cache.type_void; const TypeInterface *return_type = _get_type_or_null(p_icall.return_type); - ERR_FAIL_NULL_V(return_type, ERR_BUG); // Return type not found + ERR_FAIL_NULL_V_MSG(return_type, ERR_BUG, "Return type '" + p_icall.return_type.cname + "' was not found."); StringBuilder c_func_sig; StringBuilder c_in_statements; @@ -3129,7 +3129,7 @@ Error BindingsGenerator::_generate_cs_native_calls(const InternalCall &p_icall, int i = 0; for (const TypeReference &arg_type_ref : p_icall.argument_types) { const TypeInterface *arg_type = _get_type_or_null(arg_type_ref); - ERR_FAIL_NULL_V(arg_type, ERR_BUG); // Return type not found + ERR_FAIL_NULL_V_MSG(arg_type, ERR_BUG, "Argument type '" + arg_type_ref.cname + "' was not found."); String c_param_name = "arg" + itos(i + 1); @@ -3389,7 +3389,7 @@ const String BindingsGenerator::_get_generic_type_parameters(const TypeInterface String params = "<"; for (const TypeReference ¶m_type : p_generic_type_parameters) { const TypeInterface *param_itype = _get_type_or_singleton_or_null(param_type); - ERR_FAIL_NULL_V(param_itype, ""); // Parameter type not found + ERR_FAIL_NULL_V_MSG(param_itype, "", "Parameter type '" + param_type.cname + "' was not found."); ERR_FAIL_COND_V_MSG(param_itype->is_singleton, "", "Generic type parameter is a singleton: '" + param_itype->name + "'."); From e2b25cfc0de38ac1a09de7f570cc67eced9ca887 Mon Sep 17 00:00:00 2001 From: ev13bird <177461312+ev13bird@users.noreply.github.com> Date: Fri, 20 Sep 2024 06:17:15 +1000 Subject: [PATCH 10/37] Fix minor typo in EditorPlugin remove_inspector_plugin --- doc/classes/EditorPlugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml index de49764f0d8c..8189f253fb49 100644 --- a/doc/classes/EditorPlugin.xml +++ b/doc/classes/EditorPlugin.xml @@ -701,7 +701,7 @@ - Removes an inspector plugin registered by [method add_import_plugin] + Removes an inspector plugin registered by [method add_inspector_plugin]. From c4bea28e1734e2d13fa9a7e01d48059c65e22113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C5=A0vejda?= Date: Thu, 19 Sep 2024 22:26:23 +0200 Subject: [PATCH 11/37] Fix typo in CompositorEffect documentation --- doc/classes/CompositorEffect.xml | 2 +- doc/classes/RenderingServer.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/classes/CompositorEffect.xml b/doc/classes/CompositorEffect.xml index 9ac54edb11b7..8961e10f91bb 100644 --- a/doc/classes/CompositorEffect.xml +++ b/doc/classes/CompositorEffect.xml @@ -87,7 +87,7 @@ The callback is called before our transparent rendering pass, but after our sky is rendered and we've created our back buffers. - The callback is called after our transparent rendering pass, but before any build in post effects and output to our render target. + The callback is called after our transparent rendering pass, but before any built-in post-processing effects and output to our render target. Represents the size of the [enum EffectCallbackType] enum. diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 3658dafea6b1..c62770cf1ff8 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -5148,7 +5148,7 @@ The callback is called before our transparent rendering pass, but after our sky is rendered and we've created our back buffers. - The callback is called after our transparent rendering pass, but before any build in post effects and output to our render target. + The callback is called after our transparent rendering pass, but before any built-in post-processing effects and output to our render target. From 72c183ce8ba6f5c78213d49dd3a135690ef0bfd3 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Tue, 18 Jun 2024 10:36:58 -0500 Subject: [PATCH 12/37] CI: Update pre-commit `clang-format` to 18.1.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Modernized `.clang-format` file against latest LLVM config settings --- .clang-format | 231 ++++++++++++++++++++++++---------------- .pre-commit-config.yaml | 2 +- 2 files changed, 141 insertions(+), 92 deletions(-) diff --git a/.clang-format b/.clang-format index 1df6c35bfb5b..eda00dd8ddce 100644 --- a/.clang-format +++ b/.clang-format @@ -1,29 +1,59 @@ # Commented out parameters are those with the same value as base LLVM style. # We can uncomment them if we want to change their value, or enforce the -# chosen value in case the base style changes (last sync: Clang 14.0). ---- -### General config, applies to all languages ### -BasedOnStyle: LLVM +# chosen value in case the base style changes (last sync: Clang 18.1.8). +BasedOnStyle: LLVM AccessModifierOffset: -4 AlignAfterOpenBracket: DontAlign # AlignArrayOfStructures: None -# AlignConsecutiveMacros: None -# AlignConsecutiveAssignments: None -# AlignConsecutiveBitFields: None -# AlignConsecutiveDeclarations: None +# AlignConsecutiveAssignments: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCompound: false +# AlignFunctionPointers: false +# PadOperators: true +# AlignConsecutiveBitFields: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCompound: false +# AlignFunctionPointers: false +# PadOperators: false +# AlignConsecutiveDeclarations: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCompound: false +# AlignFunctionPointers: false +# PadOperators: false +# AlignConsecutiveMacros: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCompound: false +# AlignFunctionPointers: false +# PadOperators: false +# AlignConsecutiveShortCaseStatements: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCaseColons: false # AlignEscapedNewlines: Right -AlignOperands: DontAlign -AlignTrailingComments: false +AlignOperands: DontAlign +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 # AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: false -# AllowShortEnumsOnASingleLine: true +# AllowBreakBeforeNoexceptSpecifier: Never # AllowShortBlocksOnASingleLine: Never # AllowShortCaseLabelsOnASingleLine: false +# AllowShortCompoundRequirementOnASingleLine: true +# AllowShortEnumsOnASingleLine: true # AllowShortFunctionsOnASingleLine: All -# AllowShortLambdasOnASingleLine: All # AllowShortIfStatementsOnASingleLine: Never +# AllowShortLambdasOnASingleLine: All # AllowShortLoopsOnASingleLine: false -# AlwaysBreakAfterDefinitionReturnType: None # AlwaysBreakAfterReturnType: None # AlwaysBreakBeforeMultilineStrings: false # AlwaysBreakTemplateDeclarations: MultiLine @@ -31,50 +61,49 @@ AllowAllParametersOfDeclarationOnNextLine: false # - __capability # BinPackArguments: true # BinPackParameters: true +# BitFieldColonSpacing: Both # BraceWrapping: -# AfterCaseLabel: false -# AfterClass: false +# AfterCaseLabel: false +# AfterClass: false # AfterControlStatement: Never -# AfterEnum: false -# AfterFunction: false -# AfterNamespace: false +# AfterEnum: false +# AfterFunction: false +# AfterNamespace: false # AfterObjCDeclaration: false -# AfterStruct: false -# AfterUnion: false +# AfterStruct: false +# AfterUnion: false # AfterExternBlock: false -# BeforeCatch: false -# BeforeElse: false +# BeforeCatch: false +# BeforeElse: false # BeforeLambdaBody: false -# BeforeWhile: false -# IndentBraces: false +# BeforeWhile: false +# IndentBraces: false # SplitEmptyFunction: true # SplitEmptyRecord: true # SplitEmptyNamespace: true +# BreakAdjacentStringLiterals: true +# BreakAfterAttributes: Leave +# BreakAfterJavaFieldAnnotations: false +# BreakArrays: true # BreakBeforeBinaryOperators: None -# BreakBeforeConceptDeclarations: true # BreakBeforeBraces: Attach -# BreakBeforeInheritanceComma: false -# BreakInheritanceList: BeforeColon +# BreakBeforeConceptDeclarations: Always +# BreakBeforeInlineASMColon: OnlyMultiline # BreakBeforeTernaryOperators: true -# BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: AfterColon +# BreakInheritanceList: BeforeColon # BreakStringLiterals: true -ColumnLimit: 0 -# CommentPragmas: '^ IWYU pragma:' -# QualifierAlignment: Leave +ColumnLimit: 0 +# CommentPragmas: '^ IWYU pragma:' # CompactNamespaces: false ConstructorInitializerIndentWidth: 8 ContinuationIndentWidth: 8 Cpp11BracedListStyle: false -# DeriveLineEnding: true # DerivePointerAlignment: false -# DisableFormat: false +# DisableFormat: false # EmptyLineAfterAccessModifier: Never # EmptyLineBeforeAccessModifier: LogicalBlock # ExperimentalAutoDetectBinPacking: false -# PackConstructorInitializers: BinPack -ConstructorInitializerAllOnOneLineOrOnePerLine: true -# AllowAllConstructorInitializersOnNextLine: true # FixNamespaceComments: true # ForEachMacros: # - foreach @@ -82,118 +111,138 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true # - BOOST_FOREACH # IfMacros: # - KJ_IF_MAYBE -# IncludeBlocks: Preserve +# IncludeBlocks: Preserve IncludeCategories: - - Regex: '".*"' - Priority: 1 - - Regex: '^<.*\.h>' - Priority: 2 - - Regex: '^<.*' - Priority: 3 -# IncludeIsMainRegex: '(Test)?$' + - Regex: ^".*"$ + Priority: 1 + - Regex: ^<.*\.h>$ + Priority: 2 + - Regex: ^<.*>$ + Priority: 3 +# IncludeIsMainRegex: (Test)?$ # IncludeIsMainSourceRegex: '' # IndentAccessModifiers: false -IndentCaseLabels: true # IndentCaseBlocks: false +IndentCaseLabels: true +# IndentExternBlock: AfterExternBlock # IndentGotoLabels: true # IndentPPDirectives: None -# IndentExternBlock: AfterExternBlock -# IndentRequires: false -IndentWidth: 4 +# IndentRequiresClause: true +IndentWidth: 4 # IndentWrappedFunctionNames: false +# InsertBraces: false +# InsertNewlineAtEOF: false # InsertTrailingCommas: None +# IntegerLiteralSeparator: +# Binary: 0 +# BinaryMinDigits: 0 +# Decimal: 0 +# DecimalMinDigits: 0 +# Hex: 0 +# HexMinDigits: 0 +JavaImportGroups: + - org.godotengine + - android + - androidx + - com.android + - com.google + - java + - javax # JavaScriptQuotes: Leave # JavaScriptWrapImports: true +# KeepEmptyLinesAtEOF: false KeepEmptyLinesAtTheStartOfBlocks: false # LambdaBodyIndentation: Signature +# Language: Cpp +# LineEnding: DeriveLF # MacroBlockBegin: '' -# MacroBlockEnd: '' +# MacroBlockEnd: '' # MaxEmptyLinesToKeep: 1 # NamespaceIndentation: None +# ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +# ObjCBreakBeforeNestedBlockParam: true +# ObjCSpaceAfterProperty: false +# ObjCSpaceBeforeProtocolList: true +# PPIndentWidth: -1 +PackConstructorInitializers: NextLine # PenaltyBreakAssignment: 2 # PenaltyBreakBeforeFirstCallParameter: 19 # PenaltyBreakComment: 300 # PenaltyBreakFirstLessLess: 120 # PenaltyBreakOpenParenthesis: 0 +# PenaltyBreakScopeResolution: 500 # PenaltyBreakString: 1000 # PenaltyBreakTemplateDeclaration: 10 # PenaltyExcessCharacter: 1000000 -# PenaltyReturnTypeOnItsOwnLine: 60 # PenaltyIndentedWhitespace: 0 +# PenaltyReturnTypeOnItsOwnLine: 60 # PointerAlignment: Right -# PPIndentWidth: -1 +# QualifierAlignment: Leave # ReferenceAlignment: Pointer -# ReflowComments: true +# ReflowComments: true # RemoveBracesLLVM: false +# RemoveParentheses: Leave +# RemoveSemicolon: false +# RequiresClausePosition: OwnLine +# RequiresExpressionIndentation: OuterScope # SeparateDefinitionBlocks: Leave # ShortNamespaceLines: 1 -# SortIncludes: CaseSensitive +# SkipMacroDefinitionBody: false +# SortIncludes: CaseSensitive # SortJavaStaticImport: Before -# SortUsingDeclarations: true +# SortUsingDeclarations: LexicographicNumeric # SpaceAfterCStyleCast: false # SpaceAfterLogicalNot: false # SpaceAfterTemplateKeyword: true +# SpaceAroundPointerQualifiers: Default # SpaceBeforeAssignmentOperators: true # SpaceBeforeCaseColon: false # SpaceBeforeCpp11BracedList: false # SpaceBeforeCtorInitializerColon: true # SpaceBeforeInheritanceColon: true -# SpaceBeforeParens: ControlStatements +# SpaceBeforeJsonColon: false # SpaceBeforeParensOptions: # AfterControlStatements: true # AfterForeachMacros: true -# AfterFunctionDefinitionName: false # AfterFunctionDeclarationName: false -# AfterIfMacros: true +# AfterFunctionDefinitionName: false +# AfterIfMacros: true # AfterOverloadedOperator: false +# AfterPlacementOperator: true +# AfterRequiresInClause: false +# AfterRequiresInExpression: false # BeforeNonEmptyParentheses: false -# SpaceAroundPointerQualifiers: Default # SpaceBeforeRangeBasedForLoopColon: true +# SpaceBeforeSquareBrackets: false # SpaceInEmptyBlock: false -# SpaceInEmptyParentheses: false # SpacesBeforeTrailingComments: 1 -# SpacesInAngles: Never -# SpacesInConditionalStatement: false +# SpacesInAngles: Never # SpacesInContainerLiterals: true -# SpacesInCStyleCastParentheses: false ## Godot TODO: We'll want to use a min of 1, but we need to see how to fix ## our comment capitalization at the same time. SpacesInLineCommentPrefix: - Minimum: 0 - Maximum: -1 -# SpacesInParentheses: false + Minimum: 0 + Maximum: -1 +# SpacesInParens: Never +# SpacesInParensOptions: +# InConditionalStatements: false +# InCStyleCasts: false +# InEmptyParentheses: false +# Other: false # SpacesInSquareBrackets: false -# SpaceBeforeSquareBrackets: false -# BitFieldColonSpacing: Both +Standard: c++17 # StatementAttributeLikeMacros: # - Q_EMIT # StatementMacros: # - Q_UNUSED # - QT_REQUIRE_VERSION -TabWidth: 4 -# UseCRLF: false -UseTab: Always +TabWidth: 4 +UseTab: Always +# VerilogBreakBetweenInstancePorts: true # WhitespaceSensitiveMacros: -# - STRINGIZE -# - PP_STRINGIZE # - BOOST_PP_STRINGIZE -# - NS_SWIFT_NAME # - CF_SWIFT_NAME ---- -### C++ specific config ### -Language: Cpp -Standard: c++17 ---- -### ObjC specific config ### -Language: ObjC -# ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 4 -# ObjCBreakBeforeNestedBlockParam: true -# ObjCSpaceAfterProperty: false -# ObjCSpaceBeforeProtocolList: true ---- -### Java specific config ### -Language: Java -# BreakAfterJavaFieldAnnotations: false -JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax'] -... +# - NS_SWIFT_NAME +# - PP_STRINGIZE +# - STRINGIZE diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a3bf09bb5655..cb25337fadfa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ exclude: | repos: - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v17.0.6 + rev: v18.1.8 hooks: - id: clang-format files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|inc|java|glsl)$ From bdcee836adf52f38d5d89f3304556bd707a79705 Mon Sep 17 00:00:00 2001 From: Lisandro Lorea Date: Wed, 18 Sep 2024 16:07:47 -0300 Subject: [PATCH 13/37] Expose Viewport::get_audio_listener_2d and Viewport::get_audio_listener_3d to scripting Document exposed methods Apply suggestions from code review Co-authored-by: Micky <66727710+Mickeon@users.noreply.github.com> Document default behavior when no audio listeners are active --- doc/classes/Viewport.xml | 12 ++++++++++++ scene/main/viewport.cpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 85663e10b285..95a1d0f77e0a 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -33,6 +33,18 @@ Returns the first valid [World3D] for this viewport, searching the [member world_3d] property of itself and any Viewport ancestor. + + + + Returns the currently active 2D audio listener. Returns [code]null[/code] if there are no active 2D audio listeners, in which case the active 2D camera will be treated as listener. + + + + + + Returns the currently active 3D audio listener. Returns [code]null[/code] if there are no active 3D audio listeners, in which case the active 3D camera will be treated as listener. + + diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index acf4f6767313..ba69f8cc45df 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -4671,6 +4671,7 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d); ClassDB::bind_method(D_METHOD("is_audio_listener_2d"), &Viewport::is_audio_listener_2d); + ClassDB::bind_method(D_METHOD("get_audio_listener_2d"), &Viewport::get_audio_listener_2d); ClassDB::bind_method(D_METHOD("get_camera_2d"), &Viewport::get_camera_2d); #ifndef _3D_DISABLED @@ -4681,6 +4682,7 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_use_own_world_3d", "enable"), &Viewport::set_use_own_world_3d); ClassDB::bind_method(D_METHOD("is_using_own_world_3d"), &Viewport::is_using_own_world_3d); + ClassDB::bind_method(D_METHOD("get_audio_listener_3d"), &Viewport::get_audio_listener_3d); ClassDB::bind_method(D_METHOD("get_camera_3d"), &Viewport::get_camera_3d); ClassDB::bind_method(D_METHOD("set_as_audio_listener_3d", "enable"), &Viewport::set_as_audio_listener_3d); ClassDB::bind_method(D_METHOD("is_audio_listener_3d"), &Viewport::is_audio_listener_3d); From 3b839347df1714cab08d373a551da2602e1a7cdf Mon Sep 17 00:00:00 2001 From: SheepYhangCN Date: Wed, 18 Sep 2024 19:10:59 +0800 Subject: [PATCH 14/37] Added fallback_to_opengl3 --- doc/classes/ProjectSettings.xml | 4 +++ main/main.cpp | 1 + platform/android/display_server_android.cpp | 14 +++++++-- platform/ios/display_server_ios.mm | 14 +++++++-- platform/linuxbsd/x11/display_server_x11.cpp | 32 ++++++++++++-------- platform/macos/display_server_macos.mm | 12 ++++++-- platform/windows/display_server_windows.cpp | 11 +++++++ 7 files changed, 68 insertions(+), 20 deletions(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index d35d30efd8b2..758e98ad8577 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2795,6 +2795,10 @@ If [code]true[/code], the forward renderer will fall back to Direct3D 12 if Vulkan is not supported. [b]Note:[/b] This setting is implemented only on Windows. + + If [code]true[/code], the forward renderer will fall back to OpenGL 3 if both Direct3D 12, Metal and Vulkan are not supported. + [b]Note:[/b] This setting is implemented only on Windows, Android, macOS, iOS, and Linux/X11. + If [code]true[/code], the forward renderer will fall back to Vulkan if Direct3D 12 is not supported. [b]Note:[/b] This setting is implemented only on Windows. diff --git a/main/main.cpp b/main/main.cpp index f1ee4bf2a6bb..fa50a3039f43 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1977,6 +1977,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_vulkan", true); GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_d3d12", true); + GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_opengl3", true); } { diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index b88d887af52c..c1053215c694 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -607,11 +607,19 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis if (rendering_context) { if (rendering_context->initialize() != OK) { - ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver)); memdelete(rendering_context); rendering_context = nullptr; - r_error = ERR_UNAVAILABLE; - return; + bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); + if (fallback_to_opengl3 && rendering_driver != "opengl3") { + WARN_PRINT("Your device seem not to support Vulkan, switching to OpenGL 3."); + rendering_driver = "opengl3"; + OS::get_singleton()->set_current_rendering_method("gl_compatibility"); + OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); + } else { + ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver)); + r_error = ERR_UNAVAILABLE; + return; + } } union { diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm index 5a027e019649..e51d43bd8999 100644 --- a/platform/ios/display_server_ios.mm +++ b/platform/ios/display_server_ios.mm @@ -107,11 +107,19 @@ #endif if (rendering_context) { if (rendering_context->initialize() != OK) { - ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver)); memdelete(rendering_context); rendering_context = nullptr; - r_error = ERR_UNAVAILABLE; - return; + bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); + if (fallback_to_opengl3 && rendering_driver != "opengl3") { + WARN_PRINT("Your device seem not to support MoltenVK or Metal, switching to OpenGL 3."); + rendering_driver = "opengl3"; + OS::get_singleton()->set_current_rendering_method("gl_compatibility"); + OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); + } else { + ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver)); + r_error = ERR_UNAVAILABLE; + return; + } } if (rendering_context->window_create(MAIN_WINDOW_ID, &wpd) != OK) { diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index a12c93527366..7949f80f2486 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -6160,20 +6160,28 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode if (rendering_context->initialize() != OK) { memdelete(rendering_context); rendering_context = nullptr; - r_error = ERR_CANT_CREATE; + bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); + if (fallback_to_opengl3 && rendering_driver != "opengl3") { + WARN_PRINT("Your video card drivers seem not to support the required Vulkan version, switching to OpenGL 3."); + rendering_driver = "opengl3"; + OS::get_singleton()->set_current_rendering_method("gl_compatibility"); + OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); + } else { + r_error = ERR_CANT_CREATE; + + if (p_rendering_driver == "vulkan") { + OS::get_singleton()->alert( + vformat("Your video card drivers seem not to support the required Vulkan version.\n\n" + "If possible, consider updating your video card drivers or using the OpenGL 3 driver.\n\n" + "You can enable the OpenGL 3 driver by starting the engine from the\n" + "command line with the command:\n\n \"%s\" --rendering-driver opengl3\n\n" + "If you recently updated your video card drivers, try rebooting.", + executable_name), + "Unable to initialize Vulkan video driver"); + } - if (p_rendering_driver == "vulkan") { - OS::get_singleton()->alert( - vformat("Your video card drivers seem not to support the required Vulkan version.\n\n" - "If possible, consider updating your video card drivers or using the OpenGL 3 driver.\n\n" - "You can enable the OpenGL 3 driver by starting the engine from the\n" - "command line with the command:\n\n \"%s\" --rendering-driver opengl3\n\n" - "If you recently updated your video card drivers, try rebooting.", - executable_name), - "Unable to initialize Vulkan video driver"); + ERR_FAIL_MSG(vformat("Could not initialize %s", rendering_driver)); } - - ERR_FAIL_MSG(vformat("Could not initialize %s", rendering_driver)); } driver_found = true; } diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 52dc51bc960d..f6c1d11028db 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -3649,8 +3649,16 @@ if (rendering_context->initialize() != OK) { memdelete(rendering_context); rendering_context = nullptr; - r_error = ERR_CANT_CREATE; - ERR_FAIL_MSG("Could not initialize " + rendering_driver); + bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); + if (fallback_to_opengl3 && rendering_driver != "opengl3") { + WARN_PRINT("Your device seem not to support MoltenVK or Metal, switching to OpenGL 3."); + rendering_driver = "opengl3"; + OS::get_singleton()->set_current_rendering_method("gl_compatibility"); + OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); + } else { + r_error = ERR_CANT_CREATE; + ERR_FAIL_MSG("Could not initialize " + rendering_driver); + } } } #endif diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 50ebe7077fdb..42cd85b69edd 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -6177,6 +6177,17 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win } } #endif + bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); + if (failed && fallback_to_opengl3 && rendering_driver != "opengl3") { + memdelete(rendering_context); + rendering_context = nullptr; + tested_drivers.set_flag(DRIVER_ID_COMPAT_OPENGL3); + WARN_PRINT("Your video card drivers seem not to support Direct3D 12 or Vulkan, switching to OpenGL 3."); + rendering_driver = "opengl3"; + OS::get_singleton()->set_current_rendering_method("gl_compatibility"); + OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); + failed = false; + } if (failed) { memdelete(rendering_context); rendering_context = nullptr; From 3bfadeff25c5d86a65a17ee172465e626c9741ba Mon Sep 17 00:00:00 2001 From: kleonc <9283098+kleonc@users.noreply.github.com> Date: Fri, 20 Sep 2024 00:18:54 +0200 Subject: [PATCH 15/37] Fix C# operator *(Transform3D, AABB) --- core/math/basis.h | 8 ++++---- .../mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/math/basis.h b/core/math/basis.h index 5c1a5fbdda71..236d6661033e 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -41,11 +41,11 @@ struct [[nodiscard]] Basis { Vector3(0, 0, 1) }; - _FORCE_INLINE_ const Vector3 &operator[](int p_axis) const { - return rows[p_axis]; + _FORCE_INLINE_ const Vector3 &operator[](int p_row) const { + return rows[p_row]; } - _FORCE_INLINE_ Vector3 &operator[](int p_axis) { - return rows[p_axis]; + _FORCE_INLINE_ Vector3 &operator[](int p_row) { + return rows[p_row]; } void invert(); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs index 0f534d477f29..0dc143edea0d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs @@ -468,8 +468,8 @@ public Transform3D(Projection projection) { for (int j = 0; j < 3; j++) { - real_t e = transform.Basis[i][j] * min[j]; - real_t f = transform.Basis[i][j] * max[j]; + real_t e = transform.Basis[j][i] * min[j]; + real_t f = transform.Basis[j][i] * max[j]; if (e < f) { tmin[i] += e; From 3d6814e5d2c9e7dc88d7f2ff3611236a1298fd8f Mon Sep 17 00:00:00 2001 From: kit Date: Thu, 19 Sep 2024 19:19:34 -0400 Subject: [PATCH 16/37] Fix TabContainer tab offset moving when not needed --- scene/gui/tab_container.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 6e533aa5abc8..eb9616c93935 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -267,10 +267,14 @@ void TabContainer::_repaint() { Vector controls = _get_tab_controls(); int current = get_current_tab(); + // Move the TabBar to the top or bottom. + // Don't change the left and right offsets since the TabBar will resize and may change tab offset. if (tabs_position == POSITION_BOTTOM) { - tab_bar->set_anchors_and_offsets_preset(PRESET_BOTTOM_WIDE); + tab_bar->set_anchor_and_offset(SIDE_BOTTOM, 1.0, 0.0); + tab_bar->set_anchor_and_offset(SIDE_TOP, 1.0, -_get_tab_height()); } else { - tab_bar->set_anchors_and_offsets_preset(PRESET_TOP_WIDE); + tab_bar->set_anchor_and_offset(SIDE_BOTTOM, 0.0, _get_tab_height()); + tab_bar->set_anchor_and_offset(SIDE_TOP, 0.0, 0.0); } updating_visibility = true; @@ -299,7 +303,6 @@ void TabContainer::_repaint() { } updating_visibility = false; - _update_margins(); update_minimum_size(); } From e826ab9ba90595007b698df36622b725697ec26c Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Fri, 20 Sep 2024 15:11:08 +1000 Subject: [PATCH 17/37] [2D,Metal]: Fix subpixel blending; fix inconsistent blend state in Metal --- drivers/metal/metal_objects.h | 7 +++++++ drivers/metal/metal_objects.mm | 4 ++++ .../rendering/renderer_rd/renderer_canvas_render_rd.cpp | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/drivers/metal/metal_objects.h b/drivers/metal/metal_objects.h index 97f33bb1e84f..030b353ee82a 100644 --- a/drivers/metal/metal_objects.h +++ b/drivers/metal/metal_objects.h @@ -318,6 +318,13 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDCommandBuffer { dirty.set_flag(DirtyFlag::DIRTY_UNIFORMS); } + _FORCE_INLINE_ void mark_blend_dirty() { + if (!blend_constants.has_value()) { + return; + } + dirty.set_flag(DirtyFlag::DIRTY_BLEND); + } + MTLScissorRect clip_to_render_area(MTLScissorRect p_rect) const { uint32_t raLeft = render_area.position.x; uint32_t raRight = raLeft + render_area.size.width; diff --git a/drivers/metal/metal_objects.mm b/drivers/metal/metal_objects.mm index d3c3d2b23271..1d08a10781d2 100644 --- a/drivers/metal/metal_objects.mm +++ b/drivers/metal/metal_objects.mm @@ -143,6 +143,9 @@ if (render.pipeline != nullptr && render.pipeline->depth_stencil != rp->depth_stencil) { render.dirty.set_flag(RenderState::DIRTY_DEPTH); } + if (rp->raster_state.blend.enabled) { + render.dirty.set_flag(RenderState::DIRTY_BLEND); + } render.pipeline = rp; } } else if (p->type == MDPipelineType::Compute) { @@ -301,6 +304,7 @@ render.mark_viewport_dirty(); render.mark_scissors_dirty(); render.mark_vertex_dirty(); + render.mark_blend_dirty(); } void MDCommandBuffer::_render_set_dirty_state() { diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index 738bcd48329e..57497eb20701 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -2479,6 +2479,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar r_current_batch = _new_batch(r_batch_broken); r_current_batch->command_type = Item::Command::TYPE_NINEPATCH; r_current_batch->command = c; + r_current_batch->has_blend = false; r_current_batch->pipeline_variant = PipelineVariant::PIPELINE_VARIANT_NINEPATCH; } @@ -2548,6 +2549,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar r_current_batch = _new_batch(r_batch_broken); r_current_batch->command_type = Item::Command::TYPE_POLYGON; + r_current_batch->has_blend = false; r_current_batch->command = c; TextureState tex_state(polygon->texture, texture_filter, texture_repeat, false, use_linear_colors); @@ -2585,6 +2587,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar if (primitive->point_count != r_current_batch->primitive_points || r_current_batch->command_type != Item::Command::TYPE_PRIMITIVE) { r_current_batch = _new_batch(r_batch_broken); r_current_batch->command_type = Item::Command::TYPE_PRIMITIVE; + r_current_batch->has_blend = false; r_current_batch->command = c; r_current_batch->primitive_points = primitive->point_count; @@ -2646,6 +2649,7 @@ void RendererCanvasRenderRD::_record_item_commands(const Item *p_item, RenderTar r_current_batch = _new_batch(r_batch_broken); r_current_batch->command = c; r_current_batch->command_type = c->type; + r_current_batch->has_blend = false; InstanceData *instance_data = nullptr; @@ -2799,6 +2803,7 @@ void RendererCanvasRenderRD::_render_batch(RD::DrawListID p_draw_list, PipelineV RID pipeline = p_pipeline_variants->variants[p_batch->light_mode][p_batch->pipeline_variant].get_render_pipeline(RD::INVALID_ID, p_framebuffer_format); RD::get_singleton()->draw_list_bind_render_pipeline(p_draw_list, pipeline); if (p_batch->has_blend) { + DEV_ASSERT(p_batch->pipeline_variant == PIPELINE_VARIANT_QUAD_LCD_BLEND); RD::get_singleton()->draw_list_set_blend_constants(p_draw_list, p_batch->modulate); } From a3158d89bb7cba513fc2aa47cdc23fe39d2a1ad3 Mon Sep 17 00:00:00 2001 From: Wierdox <104049283+Wierdox@users.noreply.github.com> Date: Sat, 7 Sep 2024 02:13:54 -0700 Subject: [PATCH 18/37] Fix AudioStreamPlayer3D still processing when out of range --- scene/3d/audio_stream_player_3d.cpp | 11 ++++++++++- scene/3d/audio_stream_player_3d.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 591528b91561..98bee2115c2c 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -401,10 +401,19 @@ Vector AudioStreamPlayer3D::_update_panning() { if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) { total_max = MAX(total_max, listener_area_pos.length()); } - if (total_max > max_distance) { + if (dist > total_max || total_max > max_distance) { + if (!was_further_than_max_distance_last_frame) { + HashMap> bus_volumes; + for (Ref &playback : internal->stream_playbacks) { + // So the player gets muted and mostly stops mixing when out of range. + AudioServer::get_singleton()->set_playback_bus_volumes_linear(playback, bus_volumes); + } + was_further_than_max_distance_last_frame = true; // Cache so we don't set the volume over and over. + } continue; //can't hear this sound in this listener } } + was_further_than_max_distance_last_frame = false; float multiplier = Math::db_to_linear(_get_attenuation_db(dist)); if (max_distance > 0) { diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index 72356faad7fc..91104a06c744 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -105,6 +105,7 @@ class AudioStreamPlayer3D : public Node3D { float linear_attenuation = 0; float max_distance = 0.0; + bool was_further_than_max_distance_last_frame = false; Ref velocity_tracker; From b1000d1830e2a0486a68e787d032ef5c2bc6a576 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 20 Sep 2024 15:21:50 +0800 Subject: [PATCH 19/37] Don't list CSV as a valid extension for Translation resource --- editor/localization_editor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp index 6bc3a27a9584..3c07e8575845 100644 --- a/editor/localization_editor.cpp +++ b/editor/localization_editor.cpp @@ -37,7 +37,6 @@ #include "editor/filesystem_dock.h" #include "editor/gui/editor_file_dialog.h" #include "editor/pot_generator.h" -#include "editor/themes/editor_scale.h" #include "scene/gui/control.h" void LocalizationEditor::_notification(int p_what) { @@ -49,6 +48,7 @@ void LocalizationEditor::_notification(int p_what) { List tfn; ResourceLoader::get_recognized_extensions_for_type("Translation", &tfn); + tfn.erase("csv"); // CSV is recognized by the resource importer to generate translation files, but it's not a translation file itself. for (const String &E : tfn) { translation_file_open->add_filter("*." + E); } From f169616cc6b394b5ba95e2d1d99f217552dab60f Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 20 Sep 2024 16:21:03 +0800 Subject: [PATCH 20/37] Update AnimationTree parameter list when updating AnimationNodeTransition input names --- scene/animation/animation_blend_tree.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index cdc85d2b2d2b..a96417738f8e 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -1139,7 +1139,11 @@ void AnimationNodeTransition::remove_input(int p_index) { bool AnimationNodeTransition::set_input_name(int p_input, const String &p_name) { pending_update = true; - return AnimationNode::set_input_name(p_input, p_name); + if (!AnimationNode::set_input_name(p_input, p_name)) { + return false; + } + emit_signal(SNAME("tree_changed")); // For updating enum options. + return true; } void AnimationNodeTransition::set_input_as_auto_advance(int p_input, bool p_enable) { From 9e1121a18c4011d039037378bedf8138b2f79649 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 20 Sep 2024 19:33:32 +0800 Subject: [PATCH 21/37] Add missing period for sentences in classref --- doc/classes/EditorSettings.xml | 2 +- doc/classes/EngineDebugger.xml | 2 +- doc/classes/FontFile.xml | 2 +- doc/classes/RDPipelineDepthStencilState.xml | 2 +- doc/classes/RenderingDevice.xml | 2 +- doc/classes/RenderingServer.xml | 2 +- doc/classes/SurfaceTool.xml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index a151d8a41eac..940fec4688d1 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -904,7 +904,7 @@ If [code]true[/code], add a margin around Array, Dictionary, and Resource Editors that are not already colored. - [b]Note:[/b] If [member interface/inspector/nested_color_mode] is set to [b]Containers & Resources[/b] this parameter will have no effect since those editors will already be colored + [b]Note:[/b] If [member interface/inspector/nested_color_mode] is set to [b]Containers & Resources[/b] this parameter will have no effect since those editors will already be colored. If [code]true[/code], forces all property groups to be expanded in the Inspector dock and prevents collapsing them. diff --git a/doc/classes/EngineDebugger.xml b/doc/classes/EngineDebugger.xml index 7583520da0d0..bcc1ac5299ce 100644 --- a/doc/classes/EngineDebugger.xml +++ b/doc/classes/EngineDebugger.xml @@ -87,7 +87,7 @@ - Forces a processing loop of debugger events. The purpose of this method is just processing events every now and then when the script might get too busy, so that bugs like infinite loops can be caught + Forces a processing loop of debugger events. The purpose of this method is just processing events every now and then when the script might get too busy, so that bugs like infinite loops can be caught. diff --git a/doc/classes/FontFile.xml b/doc/classes/FontFile.xml index 1b8fa0077285..c230bf5ad281 100644 --- a/doc/classes/FontFile.xml +++ b/doc/classes/FontFile.xml @@ -58,7 +58,7 @@ - Removes all font sizes from the cache entry + Removes all font sizes from the cache entry. diff --git a/doc/classes/RDPipelineDepthStencilState.xml b/doc/classes/RDPipelineDepthStencilState.xml index b8245f97af23..dc1e70eb5586 100644 --- a/doc/classes/RDPipelineDepthStencilState.xml +++ b/doc/classes/RDPipelineDepthStencilState.xml @@ -19,7 +19,7 @@ The operation to perform on the stencil buffer for back pixels that pass the stencil test but fail the depth test. - The operation to perform on the stencil buffer for back pixels that fail the stencil test + The operation to perform on the stencil buffer for back pixels that fail the stencil test. The operation to perform on the stencil buffer for back pixels that pass the stencil test. diff --git a/doc/classes/RenderingDevice.xml b/doc/classes/RenderingDevice.xml index ddd52c6835b8..2ff7e934e9cd 100644 --- a/doc/classes/RenderingDevice.xml +++ b/doc/classes/RenderingDevice.xml @@ -905,7 +905,7 @@ - Creates a shared texture using the specified [param view] and the texture information from [param with_texture]'s [param layer] and [param mipmap]. The number of included mipmaps from the original texture can be controlled using the [param mipmaps] parameter. Only relevant for textures with multiple layers, such as 3D textures, texture arrays and cubemaps. For single-layer textures, use [method texture_create_shared] + Creates a shared texture using the specified [param view] and the texture information from [param with_texture]'s [param layer] and [param mipmap]. The number of included mipmaps from the original texture can be controlled using the [param mipmaps] parameter. Only relevant for textures with multiple layers, such as 3D textures, texture arrays and cubemaps. For single-layer textures, use [method texture_create_shared]. For 2D textures (which only have one layer), [param layer] must be [code]0[/code]. [b]Note:[/b] Layer slicing is only supported for 2D texture arrays, not 3D textures or cubemaps. diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 3658dafea6b1..531bd8d80ff9 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -3532,7 +3532,7 @@ - Creates a placeholder for a 2-dimensional layered texture and adds it to the RenderingServer. It can be accessed with the RID that is returned. This RID will be used in all [code]texture_2d_layered_*[/code] RenderingServer functions, although it does nothing when used. See also [method texture_2d_layered_placeholder_create] + Creates a placeholder for a 2-dimensional layered texture and adds it to the RenderingServer. It can be accessed with the RID that is returned. This RID will be used in all [code]texture_2d_layered_*[/code] RenderingServer functions, although it does nothing when used. See also [method texture_2d_layered_placeholder_create]. Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] method. [b]Note:[/b] The equivalent resource is [PlaceholderTexture2D]. diff --git a/doc/classes/SurfaceTool.xml b/doc/classes/SurfaceTool.xml index a8bd068b1ce0..9c1525d8f896 100644 --- a/doc/classes/SurfaceTool.xml +++ b/doc/classes/SurfaceTool.xml @@ -241,7 +241,7 @@ Set to [constant SKIN_8_WEIGHTS] to indicate that up to 8 bone influences per vertex may be used. - By default, only 4 bone influences are used ([constant SKIN_4_WEIGHTS]) + By default, only 4 bone influences are used ([constant SKIN_4_WEIGHTS]). [b]Note:[/b] This function takes an enum, not the exact number of weights. From b37fc1014abf7adda70dc30b0822d775b3a4433f Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Wed, 26 Jun 2024 11:13:05 -0500 Subject: [PATCH 22/37] Style: Apply new `clang-format` changes --- drivers/gles3/shaders/sky.glsl | 2 - .../storage/render_scene_buffers_gles3.h | 6 +-- drivers/gles3/storage/texture_storage.h | 2 +- editor/editor_resource_preview.h | 2 +- editor/export/editor_export_platform.h | 2 +- editor/gui/editor_title_bar.h | 2 +- .../plugins/animation_state_machine_editor.h | 2 +- editor/plugins/font_config_plugin.h | 12 ++--- .../plugins/gpu_particles_3d_editor_plugin.h | 2 +- editor/plugins/text_editor.h | 4 +- editor/plugins/tiles/tile_data_editors.cpp | 2 +- editor/plugins/tiles/tile_data_editors.h | 12 ++--- editor/plugins/tiles/tile_map_layer_editor.h | 6 +-- .../language_server/gdscript_extend_parser.h | 4 +- modules/navigation/nav_base.h | 2 +- modules/text_server_adv/text_server_adv.h | 2 +- modules/text_server_fb/text_server_fb.h | 2 +- .../godotengine/godot/plugin/SignalInfo.java | 2 +- platform/linuxbsd/export/export_plugin.h | 2 +- platform/linuxbsd/joypad_linux.cpp | 2 +- platform/linuxbsd/wayland/key_mapping_xkb.h | 2 +- platform/linuxbsd/x11/gl_manager_x11_egl.h | 4 +- platform/macos/export/export_plugin.h | 2 +- platform/windows/display_server_windows.cpp | 2 +- platform/windows/export/export_plugin.h | 2 +- platform/windows/gl_manager_windows_angle.h | 4 +- scene/2d/tile_map_layer.h | 2 +- scene/gui/color_mode.h | 14 +++--- scene/resources/2d/tile_set.h | 38 +++++++-------- scene/resources/3d/primitive_meshes.h | 6 +-- scene/resources/camera_attributes.h | 2 +- .../dummy/storage/material_storage.h | 2 +- .../rendering/dummy/storage/texture_storage.h | 48 +++++++++---------- .../rendering/renderer_rd/environment/fog.h | 4 +- .../rendering/renderer_rd/environment/gi.h | 4 +- .../forward_mobile/render_forward_mobile.h | 10 ++-- .../renderer_rd/renderer_scene_render_rd.h | 6 +-- servers/rendering/renderer_rd/shader_rd.h | 2 +- .../rendering/renderer_rd/shaders/canvas.glsl | 12 ++--- .../renderer_rd/shaders/environment/sky.glsl | 6 +-- .../shaders/environment/volumetric_fog.glsl | 4 +- .../scene_forward_clustered.glsl | 10 ++-- .../forward_mobile/scene_forward_mobile.glsl | 12 ++--- .../renderer_rd/shaders/particles.glsl | 6 +-- .../rendering/renderer_scene_occlusion_cull.h | 2 +- servers/rendering/rendering_device_commons.h | 2 +- servers/rendering/storage/material_storage.h | 2 +- .../rendering/storage/render_scene_buffers.h | 8 ++-- servers/rendering/storage/texture_storage.h | 2 +- servers/xr/xr_controller_tracker.cpp | 2 +- servers/xr/xr_interface.h | 4 +- 51 files changed, 150 insertions(+), 148 deletions(-) diff --git a/drivers/gles3/shaders/sky.glsl b/drivers/gles3/shaders/sky.glsl index f734e4b35544..186b630bc85b 100644 --- a/drivers/gles3/shaders/sky.glsl +++ b/drivers/gles3/shaders/sky.glsl @@ -212,9 +212,7 @@ void main() { #endif { - #CODE : SKY - } color *= sky_energy_multiplier; diff --git a/drivers/gles3/storage/render_scene_buffers_gles3.h b/drivers/gles3/storage/render_scene_buffers_gles3.h index a7a676ad33e0..9a2912f97806 100644 --- a/drivers/gles3/storage/render_scene_buffers_gles3.h +++ b/drivers/gles3/storage/render_scene_buffers_gles3.h @@ -103,9 +103,9 @@ class RenderSceneBuffersGLES3 : public RenderSceneBuffers { virtual void configure(const RenderSceneBuffersConfiguration *p_config) override; void configure_for_probe(Size2i p_size); - virtual void set_fsr_sharpness(float p_fsr_sharpness) override{}; - virtual void set_texture_mipmap_bias(float p_texture_mipmap_bias) override{}; - virtual void set_use_debanding(bool p_use_debanding) override{}; + virtual void set_fsr_sharpness(float p_fsr_sharpness) override {} + virtual void set_texture_mipmap_bias(float p_texture_mipmap_bias) override {} + virtual void set_use_debanding(bool p_use_debanding) override {} void set_apply_color_adjustments_in_post(bool p_apply_in_post); void free_render_buffer_data(); diff --git a/drivers/gles3/storage/texture_storage.h b/drivers/gles3/storage/texture_storage.h index 26864c2f3b70..b1d46309788d 100644 --- a/drivers/gles3/storage/texture_storage.h +++ b/drivers/gles3/storage/texture_storage.h @@ -582,7 +582,7 @@ class TextureStorage : public RendererTextureStorage { virtual RID decal_allocate() override; virtual void decal_initialize(RID p_rid) override; - virtual void decal_free(RID p_rid) override{}; + virtual void decal_free(RID p_rid) override {} virtual void decal_set_size(RID p_decal, const Vector3 &p_size) override; virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override; diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h index 2870f9a2019b..57b6e4cedb44 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -65,7 +65,7 @@ class EditorResourcePreviewGenerator : public RefCounted { virtual bool handles(const String &p_type) const; virtual Ref generate(const Ref &p_from, const Size2 &p_size, Dictionary &p_metadata) const; virtual Ref generate_from_path(const String &p_path, const Size2 &p_size, Dictionary &p_metadata) const; - virtual void abort(){}; + virtual void abort() {} virtual bool generate_small_preview_automatically() const; virtual bool can_generate_small_preview() const; diff --git a/editor/export/editor_export_platform.h b/editor/export/editor_export_platform.h index a800bb95e6d5..95f21ceafb33 100644 --- a/editor/export/editor_export_platform.h +++ b/editor/export/editor_export_platform.h @@ -308,7 +308,7 @@ class EditorExportPlatform : public RefCounted { virtual Error export_pack(const Ref &p_preset, bool p_debug, const String &p_path, BitField p_flags = 0); virtual Error export_zip(const Ref &p_preset, bool p_debug, const String &p_path, BitField p_flags = 0); virtual void get_platform_features(List *r_features) const = 0; - virtual void resolve_platform_feature_priorities(const Ref &p_preset, HashSet &p_features){}; + virtual void resolve_platform_feature_priorities(const Ref &p_preset, HashSet &p_features) {} virtual String get_debug_protocol() const { return "tcp://"; } EditorExportPlatform(); diff --git a/editor/gui/editor_title_bar.h b/editor/gui/editor_title_bar.h index 4055476b820b..13fd5d6cdbef 100644 --- a/editor/gui/editor_title_bar.h +++ b/editor/gui/editor_title_bar.h @@ -43,7 +43,7 @@ class EditorTitleBar : public HBoxContainer { protected: virtual void gui_input(const Ref &p_event) override; - static void _bind_methods(){}; + static void _bind_methods() {} public: void set_can_move_window(bool p_enabled); diff --git a/editor/plugins/animation_state_machine_editor.h b/editor/plugins/animation_state_machine_editor.h index 860d0ed35d12..eb623a147d62 100644 --- a/editor/plugins/animation_state_machine_editor.h +++ b/editor/plugins/animation_state_machine_editor.h @@ -322,7 +322,7 @@ class EditorAnimationMultiTransitionEdit : public RefCounted { public: void add_transition(const StringName &p_from, const StringName &p_to, Ref p_transition); - EditorAnimationMultiTransitionEdit(){}; + EditorAnimationMultiTransitionEdit() {} }; #endif // ANIMATION_STATE_MACHINE_EDITOR_H diff --git a/editor/plugins/font_config_plugin.h b/editor/plugins/font_config_plugin.h index e83f29a77b8b..87fd3861dc93 100644 --- a/editor/plugins/font_config_plugin.h +++ b/editor/plugins/font_config_plugin.h @@ -51,7 +51,7 @@ class EditorPropertyFontMetaObject : public RefCounted { void set_dict(const Dictionary &p_dict); Dictionary get_dict(); - EditorPropertyFontMetaObject(){}; + EditorPropertyFontMetaObject() {} }; /*************************************************************************/ @@ -75,7 +75,7 @@ class EditorPropertyFontOTObject : public RefCounted { void set_defaults(const Dictionary &p_dict); Dictionary get_defaults(); - EditorPropertyFontOTObject(){}; + EditorPropertyFontOTObject() {} }; /*************************************************************************/ @@ -103,7 +103,7 @@ class EditorPropertyFontMetaOverride : public EditorProperty { protected: void _notification(int p_what); - static void _bind_methods(){}; + static void _bind_methods() {} void _edit_pressed(); void _page_changed(int p_page); @@ -138,7 +138,7 @@ class EditorPropertyOTVariation : public EditorProperty { EditorPaginator *paginator = nullptr; protected: - static void _bind_methods(){}; + static void _bind_methods() {} void _edit_pressed(); void _page_changed(int p_page); @@ -187,7 +187,7 @@ class EditorPropertyOTFeatures : public EditorProperty { protected: void _notification(int p_what); - static void _bind_methods(){}; + static void _bind_methods() {} void _edit_pressed(); void _page_changed(int p_page); @@ -256,7 +256,7 @@ class EditorPropertyFontNamesArray : public EditorPropertyArray { virtual void _add_element() override; void _add_font(int p_option); - static void _bind_methods(){}; + static void _bind_methods() {} public: EditorPropertyFontNamesArray(); diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.h b/editor/plugins/gpu_particles_3d_editor_plugin.h index 5f59f6dca78a..1295836b5f42 100644 --- a/editor/plugins/gpu_particles_3d_editor_plugin.h +++ b/editor/plugins/gpu_particles_3d_editor_plugin.h @@ -59,7 +59,7 @@ class GPUParticles3DEditorBase : public Control { Vector geometry; bool _generate(Vector &points, Vector &normals); - virtual void _generate_emission_points(){}; + virtual void _generate_emission_points() {} void _node_selected(const NodePath &p_path); public: diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index 1acec4e95976..b6c203f2a284 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -127,8 +127,8 @@ class TextEditor : public ScriptEditorBase { virtual Variant get_navigation_state() override; virtual Vector get_functions() override; virtual PackedInt32Array get_breakpoints() override; - virtual void set_breakpoint(int p_line, bool p_enabled) override{}; - virtual void clear_breakpoints() override{}; + virtual void set_breakpoint(int p_line, bool p_enabled) override {} + virtual void clear_breakpoints() override {} virtual void goto_line(int p_line, int p_column = 0) override; void goto_line_selection(int p_line, int p_begin, int p_end); virtual void set_executing_line(int p_line) override; diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index 79915012a887..12b9761fd2f1 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -1097,7 +1097,7 @@ void TileDataDefaultEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas_ } }; -void TileDataDefaultEditor::forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform){ +void TileDataDefaultEditor::forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_set_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) { }; diff --git a/editor/plugins/tiles/tile_data_editors.h b/editor/plugins/tiles/tile_data_editors.h index 9b1eadf3317d..1426bb4c2f4b 100644 --- a/editor/plugins/tiles/tile_data_editors.h +++ b/editor/plugins/tiles/tile_data_editors.h @@ -54,7 +54,7 @@ class TileDataEditor : public VBoxContainer { protected: Ref tile_set; TileData *_get_tile_data(TileMapCell p_cell); - virtual void _tile_set_changed(){}; + virtual void _tile_set_changed() {} static void _bind_methods(); @@ -63,13 +63,13 @@ class TileDataEditor : public VBoxContainer { // Input to handle painting. virtual Control *get_toolbar() { return nullptr; }; - virtual void forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform){}; - virtual void forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform){}; - virtual void forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref &p_event){}; - virtual void forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref &p_event){}; + virtual void forward_draw_over_atlas(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) {} + virtual void forward_draw_over_alternatives(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, CanvasItem *p_canvas_item, Transform2D p_transform) {} + virtual void forward_painting_atlas_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref &p_event) {} + virtual void forward_painting_alternatives_gui_input(TileAtlasView *p_tile_atlas_view, TileSetAtlasSource *p_tile_atlas_source, const Ref &p_event) {} // Used to draw the tile data property value over a tile. - virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false){}; + virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) {} }; class DummyObject : public Object { diff --git a/editor/plugins/tiles/tile_map_layer_editor.h b/editor/plugins/tiles/tile_map_layer_editor.h index 7d749be1bacd..805af7b58ed1 100644 --- a/editor/plugins/tiles/tile_map_layer_editor.h +++ b/editor/plugins/tiles/tile_map_layer_editor.h @@ -66,9 +66,9 @@ class TileMapLayerSubEditorPlugin : public Object { }; virtual bool forward_canvas_gui_input(const Ref &p_event) { return false; }; - virtual void forward_canvas_draw_over_viewport(Control *p_overlay){}; - virtual void tile_set_changed(){}; - virtual void edit(ObjectID p_tile_map_layer_id){}; + virtual void forward_canvas_draw_over_viewport(Control *p_overlay) {} + virtual void tile_set_changed() {} + virtual void edit(ObjectID p_tile_map_layer_id) {} }; class TileMapLayerEditorTilesPlugin : public TileMapLayerSubEditorPlugin { diff --git a/modules/gdscript/language_server/gdscript_extend_parser.h b/modules/gdscript/language_server/gdscript_extend_parser.h index a808f19e5b53..239f7d9f43f4 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.h +++ b/modules/gdscript/language_server/gdscript_extend_parser.h @@ -37,10 +37,10 @@ #include "core/variant/variant.h" #ifndef LINE_NUMBER_TO_INDEX -#define LINE_NUMBER_TO_INDEX(p_line) ((p_line)-1) +#define LINE_NUMBER_TO_INDEX(p_line) ((p_line) - 1) #endif #ifndef COLUMN_NUMBER_TO_INDEX -#define COLUMN_NUMBER_TO_INDEX(p_column) ((p_column)-1) +#define COLUMN_NUMBER_TO_INDEX(p_column) ((p_column) - 1) #endif #ifndef SYMBOL_SEPERATOR diff --git a/modules/navigation/nav_base.h b/modules/navigation/nav_base.h index c28392acf732..d2308abfaf7d 100644 --- a/modules/navigation/nav_base.h +++ b/modules/navigation/nav_base.h @@ -64,7 +64,7 @@ class NavBase : public NavRid { void set_owner_id(ObjectID p_owner_id) { owner_id = p_owner_id; } ObjectID get_owner_id() const { return owner_id; } - virtual ~NavBase(){}; + virtual ~NavBase() {} }; #endif // NAV_BASE_H diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index 448be9ebe4c7..c63389b1c635 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -705,7 +705,7 @@ class TextServerAdvanced : public TextServerExtension { }; protected: - static void _bind_methods(){}; + static void _bind_methods() {} void full_copy(ShapedTextDataAdvanced *p_shaped); void invalidate(ShapedTextDataAdvanced *p_shaped, bool p_text = false); diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h index ee1f72401f94..7f12ad593b6f 100644 --- a/modules/text_server_fb/text_server_fb.h +++ b/modules/text_server_fb/text_server_fb.h @@ -574,7 +574,7 @@ class TextServerFallback : public TextServerExtension { Mutex ft_mutex; protected: - static void _bind_methods(){}; + static void _bind_methods() {} void full_copy(ShapedTextDataFallback *p_shaped); void invalidate(ShapedTextDataFallback *p_shaped); diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/SignalInfo.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/SignalInfo.java index 4a166112abed..be5a7a2962e9 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/plugin/SignalInfo.java +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/SignalInfo.java @@ -50,7 +50,7 @@ public SignalInfo(@NonNull String signalName, Class... paramTypes) { } this.name = signalName; - this.paramTypes = paramTypes == null ? new Class[ 0 ] : paramTypes; + this.paramTypes = paramTypes == null ? new Class[0] : paramTypes; this.paramTypesNames = new String[this.paramTypes.length]; for (int i = 0; i < this.paramTypes.length; i++) { this.paramTypesNames[i] = this.paramTypes[i].getName(); diff --git a/platform/linuxbsd/export/export_plugin.h b/platform/linuxbsd/export/export_plugin.h index 1d9ef01d1a88..9e016bd4c3b5 100644 --- a/platform/linuxbsd/export/export_plugin.h +++ b/platform/linuxbsd/export/export_plugin.h @@ -48,7 +48,7 @@ class EditorExportPlatformLinuxBSD : public EditorExportPlatformPC { String cmd_args; bool wait = false; - SSHCleanupCommand(){}; + SSHCleanupCommand() {} SSHCleanupCommand(const String &p_host, const String &p_port, const Vector &p_ssh_arg, const String &p_cmd_args, bool p_wait = false) { host = p_host; port = p_port; diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp index a67428b9a48d..49f2690e6115 100644 --- a/platform/linuxbsd/joypad_linux.cpp +++ b/platform/linuxbsd/joypad_linux.cpp @@ -50,7 +50,7 @@ #define LONG_BITS (sizeof(long) * 8) #define test_bit(nr, addr) (((1UL << ((nr) % LONG_BITS)) & ((addr)[(nr) / LONG_BITS])) != 0) -#define NBITS(x) ((((x)-1) / LONG_BITS) + 1) +#define NBITS(x) ((((x) - 1) / LONG_BITS) + 1) #ifdef UDEV_ENABLED static const char *ignore_str = "/dev/input/js"; diff --git a/platform/linuxbsd/wayland/key_mapping_xkb.h b/platform/linuxbsd/wayland/key_mapping_xkb.h index 306a8f25b57c..9b8c90a445e0 100644 --- a/platform/linuxbsd/wayland/key_mapping_xkb.h +++ b/platform/linuxbsd/wayland/key_mapping_xkb.h @@ -51,7 +51,7 @@ class KeyMappingXKB { static inline HashMap scancode_map_inv; static inline HashMap location_map; - KeyMappingXKB(){}; + KeyMappingXKB() {} public: static void initialize(); diff --git a/platform/linuxbsd/x11/gl_manager_x11_egl.h b/platform/linuxbsd/x11/gl_manager_x11_egl.h index b9c96619c42d..405dda3d8367 100644 --- a/platform/linuxbsd/x11/gl_manager_x11_egl.h +++ b/platform/linuxbsd/x11/gl_manager_x11_egl.h @@ -52,8 +52,8 @@ class GLManagerEGL_X11 : public EGLManager { public: void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height) {} - GLManagerEGL_X11(){}; - ~GLManagerEGL_X11(){}; + GLManagerEGL_X11() {} + ~GLManagerEGL_X11() {} }; #endif // X11_ENABLED && GLES3_ENABLED diff --git a/platform/macos/export/export_plugin.h b/platform/macos/export/export_plugin.h index 5457c687d399..d88d347359a4 100644 --- a/platform/macos/export/export_plugin.h +++ b/platform/macos/export/export_plugin.h @@ -68,7 +68,7 @@ class EditorExportPlatformMacOS : public EditorExportPlatform { String cmd_args; bool wait = false; - SSHCleanupCommand(){}; + SSHCleanupCommand() {} SSHCleanupCommand(const String &p_host, const String &p_port, const Vector &p_ssh_arg, const String &p_cmd_args, bool p_wait = false) { host = p_host; port = p_port; diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 50ebe7077fdb..a89dc38cd467 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -381,7 +381,7 @@ class FileDialogEventHandler : public IFileDialogEvents, public IFileDialogContr ctls[cid] = p_name; } - virtual ~FileDialogEventHandler(){}; + virtual ~FileDialogEventHandler() {} }; #if defined(__GNUC__) && !defined(__clang__) diff --git a/platform/windows/export/export_plugin.h b/platform/windows/export/export_plugin.h index e86aac83d447..1972b36845f3 100644 --- a/platform/windows/export/export_plugin.h +++ b/platform/windows/export/export_plugin.h @@ -52,7 +52,7 @@ class EditorExportPlatformWindows : public EditorExportPlatformPC { String cmd_args; bool wait = false; - SSHCleanupCommand(){}; + SSHCleanupCommand() {} SSHCleanupCommand(const String &p_host, const String &p_port, const Vector &p_ssh_arg, const String &p_cmd_args, bool p_wait = false) { host = p_host; port = p_port; diff --git a/platform/windows/gl_manager_windows_angle.h b/platform/windows/gl_manager_windows_angle.h index f43a6fbe022a..9c02912b86df 100644 --- a/platform/windows/gl_manager_windows_angle.h +++ b/platform/windows/gl_manager_windows_angle.h @@ -52,8 +52,8 @@ class GLManagerANGLE_Windows : public EGLManager { public: void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height); - GLManagerANGLE_Windows(){}; - ~GLManagerANGLE_Windows(){}; + GLManagerANGLE_Windows() {} + ~GLManagerANGLE_Windows() {} }; #endif // WINDOWS_ENABLED && GLES3_ENABLED diff --git a/scene/2d/tile_map_layer.h b/scene/2d/tile_map_layer.h index cc0a5b49fb9c..6cb481849c54 100644 --- a/scene/2d/tile_map_layer.h +++ b/scene/2d/tile_map_layer.h @@ -90,7 +90,7 @@ class TerrainConstraint { TerrainConstraint(Ref p_tile_set, const Vector2i &p_position, int p_terrain); // For the center terrain bit TerrainConstraint(Ref p_tile_set, const Vector2i &p_position, const TileSet::CellNeighbor &p_bit, int p_terrain); // For peering bits - TerrainConstraint(){}; + TerrainConstraint() {} }; #ifdef DEBUG_ENABLED diff --git a/scene/gui/color_mode.h b/scene/gui/color_mode.h index 84e9d4542df7..94193ccf747d 100644 --- a/scene/gui/color_mode.h +++ b/scene/gui/color_mode.h @@ -50,14 +50,14 @@ class ColorMode { virtual Color get_color() const = 0; - virtual void _value_changed(){}; + virtual void _value_changed() {} virtual void slider_draw(int p_which) = 0; virtual bool apply_theme() const { return false; } virtual ColorPicker::PickerShapeType get_shape_override() const { return ColorPicker::SHAPE_MAX; } ColorMode(ColorPicker *p_color_picker); - virtual ~ColorMode(){}; + virtual ~ColorMode() {} }; class ColorModeHSV : public ColorMode { @@ -81,7 +81,7 @@ class ColorModeHSV : public ColorMode { virtual void slider_draw(int p_which) override; ColorModeHSV(ColorPicker *p_color_picker) : - ColorMode(p_color_picker){}; + ColorMode(p_color_picker) {} }; class ColorModeRGB : public ColorMode { @@ -100,7 +100,7 @@ class ColorModeRGB : public ColorMode { virtual void slider_draw(int p_which) override; ColorModeRGB(ColorPicker *p_color_picker) : - ColorMode(p_color_picker){}; + ColorMode(p_color_picker) {} }; class ColorModeRAW : public ColorMode { @@ -122,7 +122,7 @@ class ColorModeRAW : public ColorMode { virtual bool apply_theme() const override; ColorModeRAW(ColorPicker *p_color_picker) : - ColorMode(p_color_picker){}; + ColorMode(p_color_picker) {} }; class ColorModeOKHSL : public ColorMode { @@ -147,9 +147,9 @@ class ColorModeOKHSL : public ColorMode { virtual ColorPicker::PickerShapeType get_shape_override() const override { return ColorPicker::SHAPE_OKHSL_CIRCLE; } ColorModeOKHSL(ColorPicker *p_color_picker) : - ColorMode(p_color_picker){}; + ColorMode(p_color_picker) {} - ~ColorModeOKHSL(){}; + ~ColorModeOKHSL() {} }; #endif // COLOR_MODE_H diff --git a/scene/resources/2d/tile_set.h b/scene/resources/2d/tile_set.h index 931495d02082..15e1a16359e8 100644 --- a/scene/resources/2d/tile_set.h +++ b/scene/resources/2d/tile_set.h @@ -571,25 +571,25 @@ class TileSetSource : public Resource { // Not exposed. virtual void set_tile_set(const TileSet *p_tile_set); TileSet *get_tile_set() const; - virtual void notify_tile_data_properties_should_change(){}; - virtual void add_occlusion_layer(int p_index){}; - virtual void move_occlusion_layer(int p_from_index, int p_to_pos){}; - virtual void remove_occlusion_layer(int p_index){}; - virtual void add_physics_layer(int p_index){}; - virtual void move_physics_layer(int p_from_index, int p_to_pos){}; - virtual void remove_physics_layer(int p_index){}; - virtual void add_terrain_set(int p_index){}; - virtual void move_terrain_set(int p_from_index, int p_to_pos){}; - virtual void remove_terrain_set(int p_index){}; - virtual void add_terrain(int p_terrain_set, int p_index){}; - virtual void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos){}; - virtual void remove_terrain(int p_terrain_set, int p_index){}; - virtual void add_navigation_layer(int p_index){}; - virtual void move_navigation_layer(int p_from_index, int p_to_pos){}; - virtual void remove_navigation_layer(int p_index){}; - virtual void add_custom_data_layer(int p_index){}; - virtual void move_custom_data_layer(int p_from_index, int p_to_pos){}; - virtual void remove_custom_data_layer(int p_index){}; + virtual void notify_tile_data_properties_should_change() {} + virtual void add_occlusion_layer(int p_index) {} + virtual void move_occlusion_layer(int p_from_index, int p_to_pos) {} + virtual void remove_occlusion_layer(int p_index) {} + virtual void add_physics_layer(int p_index) {} + virtual void move_physics_layer(int p_from_index, int p_to_pos) {} + virtual void remove_physics_layer(int p_index) {} + virtual void add_terrain_set(int p_index) {} + virtual void move_terrain_set(int p_from_index, int p_to_pos) {} + virtual void remove_terrain_set(int p_index) {} + virtual void add_terrain(int p_terrain_set, int p_index) {} + virtual void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos) {} + virtual void remove_terrain(int p_terrain_set, int p_index) {} + virtual void add_navigation_layer(int p_index) {} + virtual void move_navigation_layer(int p_from_index, int p_to_pos) {} + virtual void remove_navigation_layer(int p_index) {} + virtual void add_custom_data_layer(int p_index) {} + virtual void move_custom_data_layer(int p_from_index, int p_to_pos) {} + virtual void remove_custom_data_layer(int p_index) {} virtual void reset_state() override; // Tiles. diff --git a/scene/resources/3d/primitive_meshes.h b/scene/resources/3d/primitive_meshes.h index fc2489923abe..85f46a482a37 100644 --- a/scene/resources/3d/primitive_meshes.h +++ b/scene/resources/3d/primitive_meshes.h @@ -77,7 +77,7 @@ class PrimitiveMesh : public Mesh { Vector2 get_uv2_scale(Vector2 p_margin_scale = Vector2(1.0, 1.0)) const; float get_lightmap_texel_size() const; - virtual void _update_lightmap_size(){}; + virtual void _update_lightmap_size() {} void _on_settings_changed(); @@ -541,7 +541,7 @@ class TextMesh : public PrimitiveMesh { Vector2 point; bool sharp = false; - ContourPoint(){}; + ContourPoint() {} ContourPoint(const Vector2 &p_pt, bool p_sharp) { point = p_pt; sharp = p_sharp; @@ -551,7 +551,7 @@ class TextMesh : public PrimitiveMesh { struct ContourInfo { real_t length = 0.0; bool ccw = true; - ContourInfo(){}; + ContourInfo() {} ContourInfo(real_t p_len, bool p_ccw) { length = p_len; ccw = p_ccw; diff --git a/scene/resources/camera_attributes.h b/scene/resources/camera_attributes.h index 0f819134e224..de57b0ce8fb6 100644 --- a/scene/resources/camera_attributes.h +++ b/scene/resources/camera_attributes.h @@ -53,7 +53,7 @@ class CameraAttributes : public Resource { float auto_exposure_max = 64.0; float auto_exposure_speed = 0.5; float auto_exposure_scale = 0.4; - virtual void _update_auto_exposure(){}; + virtual void _update_auto_exposure() {} public: virtual RID get_rid() const override; diff --git a/servers/rendering/dummy/storage/material_storage.h b/servers/rendering/dummy/storage/material_storage.h index 4a956cd25d08..e4c58474e25c 100644 --- a/servers/rendering/dummy/storage/material_storage.h +++ b/servers/rendering/dummy/storage/material_storage.h @@ -97,7 +97,7 @@ class MaterialStorage : public RendererMaterialStorage { /* MATERIAL API */ virtual RID material_allocate() override { return RID(); } virtual void material_initialize(RID p_rid) override {} - virtual void material_free(RID p_rid) override{}; + virtual void material_free(RID p_rid) override {} virtual void material_set_render_priority(RID p_material, int priority) override {} virtual void material_set_shader(RID p_shader_material, RID p_shader) override {} diff --git a/servers/rendering/dummy/storage/texture_storage.h b/servers/rendering/dummy/storage/texture_storage.h index 609f19589fdb..1a566b518d90 100644 --- a/servers/rendering/dummy/storage/texture_storage.h +++ b/servers/rendering/dummy/storage/texture_storage.h @@ -56,14 +56,14 @@ class TextureStorage : public RendererTextureStorage { /* Canvas Texture API */ virtual RID canvas_texture_allocate() override { return RID(); }; - virtual void canvas_texture_initialize(RID p_rid) override{}; - virtual void canvas_texture_free(RID p_rid) override{}; + virtual void canvas_texture_initialize(RID p_rid) override {} + virtual void canvas_texture_free(RID p_rid) override {} - virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override{}; - virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override{}; + virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override {} + virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override {} - virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override{}; - virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override{}; + virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override {} + virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override {} /* Texture API */ @@ -88,20 +88,20 @@ class TextureStorage : public RendererTextureStorage { ERR_FAIL_NULL(t); t->image = p_image->duplicate(); }; - virtual void texture_2d_layered_initialize(RID p_texture, const Vector> &p_layers, RS::TextureLayeredType p_layered_type) override{}; - virtual void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector> &p_data) override{}; - virtual void texture_proxy_initialize(RID p_texture, RID p_base) override{}; //all slices, then all the mipmaps, must be coherent + virtual void texture_2d_layered_initialize(RID p_texture, const Vector> &p_layers, RS::TextureLayeredType p_layered_type) override {} + virtual void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector> &p_data) override {} + virtual void texture_proxy_initialize(RID p_texture, RID p_base) override {} //all slices, then all the mipmaps, must be coherent virtual RID texture_create_from_native_handle(RS::TextureType p_type, Image::Format p_format, uint64_t p_native_handle, int p_width, int p_height, int p_depth, int p_layers = 1, RS::TextureLayeredType p_layered_type = RS::TEXTURE_LAYERED_2D_ARRAY) override { return RID(); } - virtual void texture_2d_update(RID p_texture, const Ref &p_image, int p_layer = 0) override{}; - virtual void texture_3d_update(RID p_texture, const Vector> &p_data) override{}; - virtual void texture_proxy_update(RID p_proxy, RID p_base) override{}; + virtual void texture_2d_update(RID p_texture, const Ref &p_image, int p_layer = 0) override {} + virtual void texture_3d_update(RID p_texture, const Vector> &p_data) override {} + virtual void texture_proxy_update(RID p_proxy, RID p_base) override {} //these two APIs can be used together or in combination with the others. - virtual void texture_2d_placeholder_initialize(RID p_texture) override{}; - virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override{}; - virtual void texture_3d_placeholder_initialize(RID p_texture) override{}; + virtual void texture_2d_placeholder_initialize(RID p_texture) override {} + virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override {} + virtual void texture_3d_placeholder_initialize(RID p_texture) override {} virtual Ref texture_2d_get(RID p_texture) const override { DummyTexture *t = texture_owner.get_or_null(p_texture); @@ -112,31 +112,31 @@ class TextureStorage : public RendererTextureStorage { virtual Vector> texture_3d_get(RID p_texture) const override { return Vector>(); }; virtual void texture_replace(RID p_texture, RID p_by_texture) override { texture_free(p_by_texture); }; - virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) override{}; + virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) override {} - virtual void texture_set_path(RID p_texture, const String &p_path) override{}; + virtual void texture_set_path(RID p_texture, const String &p_path) override {} virtual String texture_get_path(RID p_texture) const override { return String(); }; virtual Image::Format texture_get_format(RID p_texture) const override { return Image::FORMAT_MAX; } - virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override{}; - virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override{}; - virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override{}; + virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override {} + virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override {} + virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override {} - virtual void texture_debug_usage(List *r_info) override{}; + virtual void texture_debug_usage(List *r_info) override {} - virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override{}; + virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override {} virtual Size2 texture_size_with_proxy(RID p_proxy) override { return Size2(); }; - virtual void texture_rd_initialize(RID p_texture, const RID &p_rd_texture, const RS::TextureLayeredType p_layer_type = RS::TEXTURE_LAYERED_2D_ARRAY) override{}; + virtual void texture_rd_initialize(RID p_texture, const RID &p_rd_texture, const RS::TextureLayeredType p_layer_type = RS::TEXTURE_LAYERED_2D_ARRAY) override {} virtual RID texture_get_rd_texture(RID p_texture, bool p_srgb = false) const override { return RID(); }; virtual uint64_t texture_get_native_handle(RID p_texture, bool p_srgb = false) const override { return 0; }; /* DECAL API */ virtual RID decal_allocate() override { return RID(); } virtual void decal_initialize(RID p_rid) override {} - virtual void decal_free(RID p_rid) override{}; + virtual void decal_free(RID p_rid) override {} virtual void decal_set_size(RID p_decal, const Vector3 &p_size) override {} virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override {} diff --git a/servers/rendering/renderer_rd/environment/fog.h b/servers/rendering/renderer_rd/environment/fog.h index 25fb190f444c..75b9c563f732 100644 --- a/servers/rendering/renderer_rd/environment/fog.h +++ b/servers/rendering/renderer_rd/environment/fog.h @@ -316,8 +316,8 @@ class Fog : public RendererFog { int last_shadow_filter = -1; - virtual void configure(RenderSceneBuffersRD *p_render_buffers) override{}; - virtual void free_data() override{}; + virtual void configure(RenderSceneBuffersRD *p_render_buffers) override {} + virtual void free_data() override {} bool sync_gi_dependent_sets_validity(bool p_ensure_freed = false); diff --git a/servers/rendering/renderer_rd/environment/gi.h b/servers/rendering/renderer_rd/environment/gi.h index 6169d386b53e..f6f9ab4f7545 100644 --- a/servers/rendering/renderer_rd/environment/gi.h +++ b/servers/rendering/renderer_rd/environment/gi.h @@ -461,7 +461,7 @@ class GI : public RendererGI { RID get_voxel_gi_buffer(); - virtual void configure(RenderSceneBuffersRD *p_render_buffers) override{}; + virtual void configure(RenderSceneBuffersRD *p_render_buffers) override {} virtual void free_data() override; }; @@ -675,7 +675,7 @@ class GI : public RendererGI { int32_t cascade_dynamic_light_count[SDFGI::MAX_CASCADES]; //used dynamically RID integrate_sky_uniform_set; - virtual void configure(RenderSceneBuffersRD *p_render_buffers) override{}; + virtual void configure(RenderSceneBuffersRD *p_render_buffers) override {} virtual void free_data() override; ~SDFGI(); diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h index fc60c770e8c8..9e429d598adb 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h @@ -366,12 +366,12 @@ class RenderForwardMobile : public RendererSceneRenderRD { virtual RID _render_buffers_get_normal_texture(Ref p_render_buffers) override; virtual RID _render_buffers_get_velocity_texture(Ref p_render_buffers) override; - virtual void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override{}; - virtual void environment_set_ssil_quality(RS::EnvironmentSSILQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override{}; - virtual void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) override{}; + virtual void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override {} + virtual void environment_set_ssil_quality(RS::EnvironmentSSILQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override {} + virtual void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) override {} - virtual void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) override{}; - virtual void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) override{}; + virtual void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) override {} + virtual void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) override {} /* Geometry instance */ diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.h b/servers/rendering/renderer_rd/renderer_scene_render_rd.h index 022a4560f8d2..b82d50378eb8 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.h @@ -165,9 +165,9 @@ class RendererSceneRenderRD : public RendererSceneRender { /* LIGHTING */ - virtual void setup_added_reflection_probe(const Transform3D &p_transform, const Vector3 &p_half_size){}; - virtual void setup_added_light(const RS::LightType p_type, const Transform3D &p_transform, float p_radius, float p_spot_aperture){}; - virtual void setup_added_decal(const Transform3D &p_transform, const Vector3 &p_half_size){}; + virtual void setup_added_reflection_probe(const Transform3D &p_transform, const Vector3 &p_half_size) {} + virtual void setup_added_light(const RS::LightType p_type, const Transform3D &p_transform, float p_radius, float p_spot_aperture) {} + virtual void setup_added_decal(const Transform3D &p_transform, const Vector3 &p_half_size) {} /* GI */ diff --git a/servers/rendering/renderer_rd/shader_rd.h b/servers/rendering/renderer_rd/shader_rd.h index 22a21086af9d..688092d604fb 100644 --- a/servers/rendering/renderer_rd/shader_rd.h +++ b/servers/rendering/renderer_rd/shader_rd.h @@ -46,7 +46,7 @@ class ShaderRD { int group = 0; CharString text; bool default_enabled = true; - VariantDefine(){}; + VariantDefine() {} VariantDefine(int p_group, const String &p_text, bool p_default_enabled) { group = p_group; default_enabled = p_default_enabled; diff --git a/servers/rendering/renderer_rd/shaders/canvas.glsl b/servers/rendering/renderer_rd/shaders/canvas.glsl index 2154d56faf04..5e19c24246cb 100644 --- a/servers/rendering/renderer_rd/shaders/canvas.glsl +++ b/servers/rendering/renderer_rd/shaders/canvas.glsl @@ -41,11 +41,11 @@ layout(location = 3) out vec2 pixel_size_interp; #endif #ifdef MATERIAL_UNIFORMS_USED -layout(set = 1, binding = 0, std140) uniform MaterialUniforms{ - +/* clang-format off */ +layout(set = 1, binding = 0, std140) uniform MaterialUniforms { #MATERIAL_UNIFORMS - } material; +/* clang-format on */ #endif #GLOBALS @@ -258,11 +258,11 @@ layout(location = 3) in vec2 pixel_size_interp; layout(location = 0) out vec4 frag_color; #ifdef MATERIAL_UNIFORMS_USED -layout(set = 1, binding = 0, std140) uniform MaterialUniforms{ - +/* clang-format off */ +layout(set = 1, binding = 0, std140) uniform MaterialUniforms { #MATERIAL_UNIFORMS - } material; +/* clang-format on */ #endif vec2 screen_uv_to_sdf(vec2 p_uv) { diff --git a/servers/rendering/renderer_rd/shaders/environment/sky.glsl b/servers/rendering/renderer_rd/shaders/environment/sky.glsl index 5aa37354948f..cc1c40cad1f4 100644 --- a/servers/rendering/renderer_rd/shaders/environment/sky.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/sky.glsl @@ -106,9 +106,11 @@ layout(set = 0, binding = 3, std140) uniform DirectionalLights { directional_lights; #ifdef MATERIAL_UNIFORMS_USED -layout(set = 1, binding = 0, std140) uniform MaterialUniforms{ +/* clang-format off */ +layout(set = 1, binding = 0, std140) uniform MaterialUniforms { #MATERIAL_UNIFORMS } material; +/* clang-format on */ #endif layout(set = 2, binding = 0) uniform textureCube radiance; @@ -247,9 +249,7 @@ void main() { #endif //USE_CUBEMAP_PASS { - #CODE : SKY - } frag_color.rgb = color; diff --git a/servers/rendering/renderer_rd/shaders/environment/volumetric_fog.glsl b/servers/rendering/renderer_rd/shaders/environment/volumetric_fog.glsl index 2360375c2379..929f1e34df0e 100644 --- a/servers/rendering/renderer_rd/shaders/environment/volumetric_fog.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/volumetric_fog.glsl @@ -77,9 +77,11 @@ layout(r32ui, set = 1, binding = 4) uniform volatile uimage3D light_only_map; #endif #ifdef MATERIAL_UNIFORMS_USED -layout(set = 2, binding = 0, std140) uniform MaterialUniforms{ +/* clang-format off */ +layout(set = 2, binding = 0, std140) uniform MaterialUniforms { #MATERIAL_UNIFORMS } material; +/* clang-format on */ #endif #GLOBALS diff --git a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl index cfde97af95f1..a441b1667d25 100644 --- a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl +++ b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl @@ -116,9 +116,11 @@ layout(location = 8) out vec4 prev_screen_position; #endif #ifdef MATERIAL_UNIFORMS_USED -layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms{ +/* clang-format off */ +layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms { #MATERIAL_UNIFORMS } material; +/* clang-format on */ #endif float global_time; @@ -808,11 +810,11 @@ ivec2 multiview_uv(ivec2 uv) { #endif #ifdef MATERIAL_UNIFORMS_USED -layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms{ - +/* clang-format off */ +layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms { #MATERIAL_UNIFORMS - } material; +/* clang-format on */ #endif #GLOBALS diff --git a/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl b/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl index b21769f20747..92a8e2be3265 100644 --- a/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl +++ b/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl @@ -107,11 +107,11 @@ layout(location = 6) mediump out vec3 binormal_interp; #endif #ifdef MATERIAL_UNIFORMS_USED -layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms{ - +/* clang-format off */ +layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms { #MATERIAL_UNIFORMS - } material; +/* clang-format on */ #endif #ifdef MODE_DUAL_PARABOLOID @@ -671,11 +671,11 @@ ivec2 multiview_uv(ivec2 uv) { #endif #ifdef MATERIAL_UNIFORMS_USED -layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms{ - +/* clang-format off */ +layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms { #MATERIAL_UNIFORMS - } material; +/* clang-format on */ #endif #GLOBALS diff --git a/servers/rendering/renderer_rd/shaders/particles.glsl b/servers/rendering/renderer_rd/shaders/particles.glsl index 7c5291038fed..a8f27ba726ee 100644 --- a/servers/rendering/renderer_rd/shaders/particles.glsl +++ b/servers/rendering/renderer_rd/shaders/particles.glsl @@ -168,11 +168,11 @@ layout(set = 2, binding = 1) uniform texture2D height_field_texture; /* SET 3: MATERIAL */ #ifdef MATERIAL_UNIFORMS_USED -layout(set = 3, binding = 0, std140) uniform MaterialUniforms{ - +/* clang-format off */ +layout(set = 3, binding = 0, std140) uniform MaterialUniforms { #MATERIAL_UNIFORMS - } material; +/* clang-format on */ #endif layout(push_constant, std430) uniform Params { diff --git a/servers/rendering/renderer_scene_occlusion_cull.h b/servers/rendering/renderer_scene_occlusion_cull.h index a848c86bd2a5..df403c548411 100644 --- a/servers/rendering/renderer_scene_occlusion_cull.h +++ b/servers/rendering/renderer_scene_occlusion_cull.h @@ -192,7 +192,7 @@ class RendererSceneOcclusionCull { RID get_debug_texture(); const Size2i &get_occlusion_buffer_size() const { return occlusion_buffer_size; } - virtual ~HZBuffer(){}; + virtual ~HZBuffer() {} }; static RendererSceneOcclusionCull *get_singleton() { return singleton; } diff --git a/servers/rendering/rendering_device_commons.h b/servers/rendering/rendering_device_commons.h index 8c3996bd8043..d72265958cb5 100644 --- a/servers/rendering/rendering_device_commons.h +++ b/servers/rendering/rendering_device_commons.h @@ -34,7 +34,7 @@ #include "core/object/object.h" #include "core/variant/type_info.h" -#define STEPIFY(m_number, m_alignment) ((((m_number) + ((m_alignment)-1)) / (m_alignment)) * (m_alignment)) +#define STEPIFY(m_number, m_alignment) ((((m_number) + ((m_alignment) - 1)) / (m_alignment)) * (m_alignment)) class RenderingDeviceCommons : public Object { //////////////////////////////////////////// diff --git a/servers/rendering/storage/material_storage.h b/servers/rendering/storage/material_storage.h index 03feda8abb08..a5935cc90f72 100644 --- a/servers/rendering/storage/material_storage.h +++ b/servers/rendering/storage/material_storage.h @@ -36,7 +36,7 @@ class RendererMaterialStorage { public: - virtual ~RendererMaterialStorage(){}; + virtual ~RendererMaterialStorage() {} /* GLOBAL SHADER UNIFORM API */ virtual void global_shader_parameter_add(const StringName &p_name, RS::GlobalShaderParameterType p_type, const Variant &p_value) = 0; diff --git a/servers/rendering/storage/render_scene_buffers.h b/servers/rendering/storage/render_scene_buffers.h index 6c82d477997f..b860af764001 100644 --- a/servers/rendering/storage/render_scene_buffers.h +++ b/servers/rendering/storage/render_scene_buffers.h @@ -91,7 +91,7 @@ class RenderSceneBuffersConfiguration : public RefCounted { void set_use_debanding(bool p_use_debanding) { use_debanding = p_use_debanding; } RenderSceneBuffersConfiguration() {} - virtual ~RenderSceneBuffersConfiguration(){}; + virtual ~RenderSceneBuffersConfiguration() {} }; class RenderSceneBuffers : public RefCounted { @@ -101,8 +101,8 @@ class RenderSceneBuffers : public RefCounted { static void _bind_methods(); public: - RenderSceneBuffers(){}; - virtual ~RenderSceneBuffers(){}; + RenderSceneBuffers() {} + virtual ~RenderSceneBuffers() {} virtual void configure(const RenderSceneBuffersConfiguration *p_config) = 0; @@ -124,7 +124,7 @@ class RenderSceneBuffersExtension : public RenderSceneBuffers { GDVIRTUAL1(_set_use_debanding, bool) public: - virtual ~RenderSceneBuffersExtension(){}; + virtual ~RenderSceneBuffersExtension() {} virtual void configure(const RenderSceneBuffersConfiguration *p_config) override; diff --git a/servers/rendering/storage/texture_storage.h b/servers/rendering/storage/texture_storage.h index 7388307ac0f1..6e1cb9eb7f43 100644 --- a/servers/rendering/storage/texture_storage.h +++ b/servers/rendering/storage/texture_storage.h @@ -61,7 +61,7 @@ class RendererTextureStorage { /* Texture API */ virtual bool can_create_resources_async() const = 0; - virtual ~RendererTextureStorage(){}; + virtual ~RendererTextureStorage() {} virtual RID texture_allocate() = 0; virtual void texture_free(RID p_rid) = 0; diff --git a/servers/xr/xr_controller_tracker.cpp b/servers/xr/xr_controller_tracker.cpp index df85e86b7e95..2d6cf44ce87e 100644 --- a/servers/xr/xr_controller_tracker.cpp +++ b/servers/xr/xr_controller_tracker.cpp @@ -32,7 +32,7 @@ #include "core/input/input.h" -void XRControllerTracker::_bind_methods(){}; +void XRControllerTracker::_bind_methods() {} XRControllerTracker::XRControllerTracker() { type = XRServer::TRACKER_CONTROLLER; diff --git a/servers/xr/xr_interface.h b/servers/xr/xr_interface.h index 6b6a67a04c09..55495731c558 100644 --- a/servers/xr/xr_interface.h +++ b/servers/xr/xr_interface.h @@ -137,10 +137,10 @@ class XRInterface : public RefCounted { virtual RID get_color_texture(); /* obtain color output texture (if applicable) */ virtual RID get_depth_texture(); /* obtain depth output texture (if applicable, used for reprojection) */ virtual RID get_velocity_texture(); /* obtain velocity output texture (if applicable, used for spacewarp) */ - virtual void pre_render(){}; + virtual void pre_render() {} virtual bool pre_draw_viewport(RID p_render_target) { return true; }; /* inform XR interface we are about to start our viewport draw process */ virtual Vector post_draw_viewport(RID p_render_target, const Rect2 &p_screen_rect) = 0; /* inform XR interface we finished our viewport draw process */ - virtual void end_frame(){}; + virtual void end_frame() {} /** passthrough **/ From e90c5a46042feb4b1781062dc4d4e8f075009638 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Wed, 26 Jun 2024 11:13:31 -0500 Subject: [PATCH 23/37] Ignore `clang-format` changes commit --- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index ebfd3b515af3..1c78dde7a4e9 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -54,3 +54,6 @@ df61dc4b2bd54a5a40c515493c76f5a458e5b541 # Enforce template syntax `typename` over `class` 9903e6779b70fc03aae70a37b9cf053f4f355b91 + +# Style: Apply new `clang-format` fixes +b37fc1014abf7adda70dc30b0822d775b3a4433f From 84e278cbfd2b645a2b5acb0ec1ad869e6d50c971 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sun, 21 Jul 2024 05:32:35 +0200 Subject: [PATCH 24/37] Tweak script editor zoom presets to be more useful The presets are now 50%, 75%, 90%, 100%, 110%, 125%, 150%. This also mentions Ctrl + mouse wheel in the tooltip. --- editor/code_editor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index d24b1edd709d..514b07ea17fd 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -798,7 +798,7 @@ FindReplaceBar::FindReplaceBar() { /*** CODE EDITOR ****/ -static constexpr float ZOOM_FACTOR_PRESETS[7] = { 0.25f, 0.5f, 0.75f, 1.0f, 1.5f, 2.0f, 3.0f }; +static constexpr float ZOOM_FACTOR_PRESETS[8] = { 0.5f, 0.75f, 0.9f, 1.0f, 1.1f, 1.25f, 1.5f, 2.0f }; // This function should be used to handle shortcuts that could otherwise // be handled too late if they weren't handled here. @@ -1690,8 +1690,7 @@ void CodeTextEditor::_zoom_to(float p_zoom_factor) { } void CodeTextEditor::set_zoom_factor(float p_zoom_factor) { - int preset_count = sizeof(ZOOM_FACTOR_PRESETS) / sizeof(float); - zoom_factor = CLAMP(p_zoom_factor, ZOOM_FACTOR_PRESETS[0], ZOOM_FACTOR_PRESETS[preset_count - 1]); + zoom_factor = CLAMP(p_zoom_factor, 0.25f, 3.0f); int neutral_font_size = int(EDITOR_GET("interface/editor/code_font_size")) * EDSCALE; int new_font_size = Math::round(zoom_factor * neutral_font_size); @@ -1815,7 +1814,8 @@ CodeTextEditor::CodeTextEditor() { status_bar->add_child(zoom_button); zoom_button->set_flat(true); zoom_button->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); - zoom_button->set_tooltip_text(TTR("Zoom factor")); + zoom_button->set_tooltip_text( + TTR("Zoom factor") + "\n" + vformat(TTR("%sMouse wheel, %s/%s: Finetune\n%s: Reset"), keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL), ED_GET_SHORTCUT("script_editor/zoom_in")->get_as_text(), ED_GET_SHORTCUT("script_editor/zoom_out")->get_as_text(), ED_GET_SHORTCUT("script_editor/reset_zoom")->get_as_text())); zoom_button->set_text("100 %"); PopupMenu *zoom_menu = zoom_button->get_popup(); From d33f4820cd14e38571f0998b59fc72c0d67dfb1e Mon Sep 17 00:00:00 2001 From: Dungeon Master <70334983+ItzCog@users.noreply.github.com> Date: Sat, 14 Sep 2024 05:09:22 +0800 Subject: [PATCH 25/37] Change "deconstructor" to "destructor" in `NOTIFICATION_PREDELETE` docs --- doc/classes/Object.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml index a331c05e47cb..3e015f9e7aa3 100644 --- a/doc/classes/Object.xml +++ b/doc/classes/Object.xml @@ -1121,7 +1121,7 @@ Notification received when the object is initialized, before its script is attached. Used internally. - Notification received when the object is about to be deleted. Can act as the deconstructor of some programming languages. + Notification received when the object is about to be deleted. Can be used like destructors in object-oriented programming languages. Notification received when the object finishes hot reloading. This notification is only sent for extensions classes and derived. From fdc6ffd264d015d4f6ba22488a4e7ab78d365b24 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Fri, 20 Sep 2024 09:34:11 -0500 Subject: [PATCH 26/37] Style: Update `ruff` & `mypy` to latest versions --- .pre-commit-config.yaml | 4 ++-- modules/raycast/godot_update_embree.py | 14 +++++++------- pyproject.toml | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cb25337fadfa..8cfb00fd8eea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,14 +39,14 @@ repos: stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy` - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.4 + rev: v0.6.6 hooks: - id: ruff args: [--fix] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.971 + rev: v1.11.2 hooks: - id: mypy files: \.py$ diff --git a/modules/raycast/godot_update_embree.py b/modules/raycast/godot_update_embree.py index c1790603650b..c4fff330c93e 100644 --- a/modules/raycast/godot_update_embree.py +++ b/modules/raycast/godot_update_embree.py @@ -4,8 +4,8 @@ import shutil import stat import subprocess -from types import TracebackType -from typing import Any, Callable, Tuple, Type +import sys +from typing import Any, Callable git_tag = "v4.3.1" @@ -100,9 +100,7 @@ commit_hash = str(subprocess.check_output(["git", "rev-parse", "HEAD"], universal_newlines=True)).strip() -def on_rm_error( - function: Callable[..., Any], path: str, excinfo: Tuple[Type[Exception], Exception, TracebackType] -) -> None: +def on_rm_error(function: Callable[..., Any], path: str, excinfo: Exception) -> None: """ Error handler for `shutil.rmtree()`. @@ -113,10 +111,12 @@ def on_rm_error( os.unlink(path) -# 3.12 Python and beyond should replace `onerror` with `onexc`. # We remove the .git directory because it contains # a lot of read-only files that are problematic on Windows. -shutil.rmtree(".git", onerror=on_rm_error) +if sys.version_info >= (3, 12): + shutil.rmtree(".git", onexc=on_rm_error) +else: + shutil.rmtree(".git", onerror=on_rm_error) # type: ignore all_files = set(cpp_files) diff --git a/pyproject.toml b/pyproject.toml index 59b6d09a0322..1cf789b46069 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ warn_unreachable = true namespace_packages = true explicit_package_bases = true exclude = ["thirdparty/"] +python_version = "3.8" [tool.ruff] extend-exclude = ["thirdparty"] From 203d3be200c9b607e5eaba82d9a267813a6700cd Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Thu, 18 Jan 2024 17:20:56 +0100 Subject: [PATCH 27/37] [Core] Add way to check if a signal has any connections Added to `Object` and `Signal` --- core/object/object.cpp | 19 +++++++++++++++++++ core/object/object.h | 1 + core/variant/callable.cpp | 7 +++++++ core/variant/callable.h | 1 + core/variant/variant_call.cpp | 1 + doc/classes/Object.xml | 8 ++++++++ doc/classes/Signal.xml | 6 ++++++ scene/main/node.cpp | 5 +++++ scene/main/node.h | 1 + 9 files changed, 49 insertions(+) diff --git a/core/object/object.cpp b/core/object/object.cpp index 2d9d468d3883..b3a4ec6e2ed6 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1457,6 +1457,24 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable return s->slot_map.has(*p_callable.get_base_comparator()); } +bool Object::has_connections(const StringName &p_signal) const { + const SignalData *s = signal_map.getptr(p_signal); + if (!s) { + bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal); + if (signal_is_valid) { + return false; + } + + if (!script.is_null() && Ref