diff options
61 files changed, 1255 insertions, 499 deletions
diff --git a/core/templates/paged_array.h b/core/templates/paged_array.h new file mode 100644 index 0000000000..71183c4ad8 --- /dev/null +++ b/core/templates/paged_array.h @@ -0,0 +1,349 @@ +/*************************************************************************/ +/* paged_array.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* 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 PAGED_ARRAY_H +#define PAGED_ARRAY_H + +#include "core/os/memory.h" +#include "core/os/spin_lock.h" +#include "core/typedefs.h" + +// PagedArray is used mainly for filling a very large array from multiple threads efficiently and without causing major fragmentation + +// PageArrayPool manages central page allocation in a thread safe matter + +template <class T> +class PagedArrayPool { + T **page_pool = nullptr; + uint32_t pages_allocated = 0; + + uint32_t *available_page_pool = nullptr; + uint32_t pages_available = 0; + + uint32_t page_size = 0; + SpinLock spin_lock; + +public: + uint32_t alloc_page() { + spin_lock.lock(); + if (unlikely(pages_available == 0)) { + uint32_t pages_used = pages_allocated; + + pages_allocated++; + page_pool = (T **)memrealloc(page_pool, sizeof(T *) * pages_allocated); + available_page_pool = (uint32_t *)memrealloc(available_page_pool, sizeof(uint32_t) * pages_allocated); + + page_pool[pages_used] = (T *)memalloc(sizeof(T) * page_size); + available_page_pool[0] = pages_used; + + pages_available++; + } + + pages_available--; + uint32_t page = available_page_pool[pages_available]; + spin_lock.unlock(); + + return page; + } + T *get_page(uint32_t p_page_id) { + return page_pool[p_page_id]; + } + + void free_page(uint32_t p_page_id) { + spin_lock.lock(); + available_page_pool[pages_available] = p_page_id; + pages_available++; + spin_lock.unlock(); + } + + uint32_t get_page_size_shift() const { + return get_shift_from_power_of_2(page_size); + } + + uint32_t get_page_size_mask() const { + return page_size - 1; + } + + void reset() { + ERR_FAIL_COND(pages_available < pages_allocated); + if (pages_allocated) { + for (uint32_t i = 0; i < pages_allocated; i++) { + memfree(page_pool[i]); + } + memfree(page_pool); + memfree(available_page_pool); + page_pool = nullptr; + available_page_pool = nullptr; + pages_allocated = 0; + pages_available = 0; + } + } + bool is_configured() const { + return page_size > 0; + } + + void configure(uint32_t p_page_size) { + ERR_FAIL_COND(page_pool != nullptr); //sanity check + ERR_FAIL_COND(p_page_size == 0); + page_size = nearest_power_of_2_templated(p_page_size); + } + + PagedArrayPool(uint32_t p_page_size = 4096) { // power of 2 recommended because of alignment with OS page sizes. Even if element is bigger, its still a multiple and get rounded amount of pages + configure(p_page_size); + } + + ~PagedArrayPool() { + ERR_FAIL_COND_MSG(pages_available < pages_allocated, "Pages in use exist at exit in PagedArrayPool"); + reset(); + } +}; + +// PageArray is a local array that is optimized to grow in place, then be cleared often. +// It does so by allocating pages from a PagedArrayPool. +// It is safe to use multiple PagedArrays from different threads, sharing a single PagedArrayPool + +template <class T> +class PagedArray { + PagedArrayPool<T> *page_pool = nullptr; + + T **page_data = nullptr; + uint32_t *page_ids = nullptr; + uint32_t max_pages_used = 0; + uint32_t page_size_shift = 0; + uint32_t page_size_mask = 0; + uint64_t count = 0; + + _FORCE_INLINE_ uint32_t _get_pages_in_use() const { + if (count == 0) { + return 0; + } else { + return ((count - 1) >> page_size_shift) + 1; + } + } + + void _grow_page_array() { + //no more room in the page array to put the new page, make room + if (max_pages_used == 0) { + max_pages_used = 1; + } else { + max_pages_used *= 2; // increase in powers of 2 to keep allocations to minimum + } + page_data = (T **)memrealloc(page_data, sizeof(T *) * max_pages_used); + page_ids = (uint32_t *)memrealloc(page_ids, sizeof(uint32_t) * max_pages_used); + } + +public: + _FORCE_INLINE_ const T &operator[](uint64_t p_index) const { + CRASH_BAD_UNSIGNED_INDEX(p_index, count); + uint32_t page = p_index >> page_size_shift; + uint32_t offset = p_index & page_size_mask; + + return page_data[page][offset]; + } + _FORCE_INLINE_ T &operator[](uint64_t p_index) { + CRASH_BAD_UNSIGNED_INDEX(p_index, count); + uint32_t page = p_index >> page_size_shift; + uint32_t offset = p_index & page_size_mask; + + return page_data[page][offset]; + } + + _FORCE_INLINE_ void push_back(const T &p_value) { + uint32_t remainder = count & page_size_mask; + if (unlikely(remainder == 0)) { + // at 0, so time to request a new page + uint32_t page_count = _get_pages_in_use(); + uint32_t new_page_count = page_count + 1; + + if (unlikely(new_page_count > max_pages_used)) { + ERR_FAIL_COND(page_pool == nullptr); //sanity check + + _grow_page_array(); //keep out of inline + } + + uint32_t page_id = page_pool->alloc_page(); + page_data[page_count] = page_pool->get_page(page_id); + page_ids[page_count] = page_id; + } + + // place the new value + uint32_t page = count >> page_size_shift; + uint32_t offset = count & page_size_mask; + + if (!__has_trivial_constructor(T)) { + memnew_placement(&page_data[page][offset], T(p_value)); + } else { + page_data[page][offset] = p_value; + } + + count++; + } + + void clear() { + //destruct if needed + if (!__has_trivial_destructor(T)) { + for (uint64_t i = 0; i < count; i++) { + uint32_t page = i >> page_size_shift; + uint32_t offset = i & page_size_mask; + page_data[page][offset].~T(); + } + } + + //return the pages to the pagepool, so they can be used by another array eventually + uint32_t pages_used = _get_pages_in_use(); + for (uint32_t i = 0; i < pages_used; i++) { + page_pool->free_page(page_ids[i]); + } + + count = 0; + + //note we leave page_data and page_indices intact for next use. If you really want to clear them call reset() + } + + void reset() { + clear(); + if (page_data) { + memfree(page_data); + memfree(page_ids); + page_data = nullptr; + page_ids = nullptr; + max_pages_used = 0; + } + } + + // This takes the pages from a source array and merges them to this one + // resulting order is undefined, but content is merged very efficiently, + // making it ideal to fill content on several threads to later join it. + + void merge_unordered(PagedArray<T> &p_array) { + ERR_FAIL_COND(page_pool != p_array.page_pool); + + uint32_t remainder = count & page_size_mask; + + T *remainder_page = nullptr; + uint32_t remainder_page_id; + + if (remainder > 0) { + uint32_t last_page = _get_pages_in_use() - 1; + remainder_page = page_data[last_page]; + remainder_page_id = page_ids[last_page]; + } + + count -= remainder; + + uint32_t src_pages = p_array._get_pages_in_use(); + uint32_t page_size = page_size_mask + 1; + + for (uint32_t i = 0; i < src_pages; i++) { + uint32_t page_count = _get_pages_in_use(); + uint32_t new_page_count = page_count + 1; + + if (unlikely(new_page_count > max_pages_used)) { + _grow_page_array(); //keep out of inline + } + + page_data[page_count] = p_array.page_data[i]; + page_ids[page_count] = p_array.page_ids[i]; + if (i == src_pages - 1) { + //last page, only increment with remainder + count += p_array.count & page_size_mask; + } else { + count += page_size; + } + } + p_array.count = 0; //take away the other array pages + + //handle the remainder page if exists + if (remainder_page) { + uint32_t new_remainder = count & page_size_mask; + + if (new_remainder > 0) { + //must merge old remainder with new remainder + + T *dst_page = page_data[_get_pages_in_use() - 1]; + uint32_t to_copy = MIN(page_size - new_remainder, remainder); + + for (uint32_t i = 0; i < to_copy; i++) { + if (!__has_trivial_constructor(T)) { + memnew_placement(&dst_page[i + new_remainder], T(remainder_page[i + remainder - to_copy])); + } else { + dst_page[i + new_remainder] = remainder_page[i + remainder - to_copy]; + } + + if (!__has_trivial_destructor(T)) { + remainder_page[i + remainder - to_copy].~T(); + } + } + + remainder -= to_copy; //subtract what was copied from remainder + count += to_copy; //add what was copied to the count + + if (remainder == 0) { + //entire remainder copied, let go of remainder page + page_pool->free_page(remainder_page_id); + remainder_page = nullptr; + } + } + + if (remainder > 0) { + //there is still remainder, append it + uint32_t page_count = _get_pages_in_use(); + uint32_t new_page_count = page_count + 1; + + if (unlikely(new_page_count > max_pages_used)) { + _grow_page_array(); //keep out of inline + } + + page_data[page_count] = remainder_page; + page_ids[page_count] = remainder_page_id; + + count += remainder; + } + } + } + + uint64_t size() const { + return count; + } + + void set_page_pool(PagedArrayPool<T> *p_page_pool) { + ERR_FAIL_COND(max_pages_used > 0); //sanity check + + page_pool = p_page_pool; + page_size_mask = page_pool->get_page_size_mask(); + page_size_shift = page_pool->get_page_size_shift(); + } + + ~PagedArray() { + reset(); + } +}; + +#endif // PAGED_ARRAY_H diff --git a/core/templates/vector.h b/core/templates/vector.h index 9d45f7c30a..7420384bf7 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -112,6 +112,10 @@ public: sort_custom<_DefaultComparator<T>>(); } + Vector<T> duplicate() { + return *this; + } + void ordered_insert(const T &p_val) { int i; for (i = 0; i < _cowdata.size(); i++) { diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 55a34af723..afe4f2702e 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1316,6 +1316,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedByteArray, invert, sarray(), varray()); bind_method(PackedByteArray, subarray, sarray("from", "to"), varray()); bind_method(PackedByteArray, sort, sarray(), varray()); + bind_method(PackedByteArray, duplicate, sarray(), varray()); bind_function(PackedByteArray, get_string_from_ascii, _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray()); bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray()); @@ -1342,6 +1343,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt32Array, subarray, sarray("from", "to"), varray()); bind_method(PackedInt32Array, to_byte_array, sarray(), varray()); bind_method(PackedInt32Array, sort, sarray(), varray()); + bind_method(PackedInt32Array, duplicate, sarray(), varray()); /* Int64 Array */ @@ -1359,6 +1361,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt64Array, subarray, sarray("from", "to"), varray()); bind_method(PackedInt64Array, to_byte_array, sarray(), varray()); bind_method(PackedInt64Array, sort, sarray(), varray()); + bind_method(PackedInt64Array, duplicate, sarray(), varray()); /* Float32 Array */ @@ -1376,6 +1379,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat32Array, subarray, sarray("from", "to"), varray()); bind_method(PackedFloat32Array, to_byte_array, sarray(), varray()); bind_method(PackedFloat32Array, sort, sarray(), varray()); + bind_method(PackedFloat32Array, duplicate, sarray(), varray()); /* Float64 Array */ @@ -1393,6 +1397,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat64Array, subarray, sarray("from", "to"), varray()); bind_method(PackedFloat64Array, to_byte_array, sarray(), varray()); bind_method(PackedFloat64Array, sort, sarray(), varray()); + bind_method(PackedFloat64Array, duplicate, sarray(), varray()); /* String Array */ @@ -1410,6 +1415,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedStringArray, subarray, sarray("from", "to"), varray()); bind_method(PackedStringArray, to_byte_array, sarray(), varray()); bind_method(PackedStringArray, sort, sarray(), varray()); + bind_method(PackedStringArray, duplicate, sarray(), varray()); /* Vector2 Array */ @@ -1427,6 +1433,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector2Array, subarray, sarray("from", "to"), varray()); bind_method(PackedVector2Array, to_byte_array, sarray(), varray()); bind_method(PackedVector2Array, sort, sarray(), varray()); + bind_method(PackedVector2Array, duplicate, sarray(), varray()); /* Vector3 Array */ @@ -1444,6 +1451,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector3Array, subarray, sarray("from", "to"), varray()); bind_method(PackedVector3Array, to_byte_array, sarray(), varray()); bind_method(PackedVector3Array, sort, sarray(), varray()); + bind_method(PackedVector3Array, duplicate, sarray(), varray()); /* Color Array */ @@ -1461,6 +1469,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedColorArray, subarray, sarray("from", "to"), varray()); bind_method(PackedColorArray, to_byte_array, sarray(), varray()); bind_method(PackedColorArray, sort, sarray(), varray()); + bind_method(PackedColorArray, duplicate, sarray(), varray()); /* Register constants */ diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index cee7465205..28cf8ef967 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -2023,6 +2023,24 @@ Variant Variant::duplicate(bool deep) const { return operator Dictionary().duplicate(deep); case ARRAY: return operator Array().duplicate(deep); + case PACKED_BYTE_ARRAY: + return operator Vector<uint8_t>().duplicate(); + case PACKED_INT32_ARRAY: + return operator Vector<int32_t>().duplicate(); + case PACKED_INT64_ARRAY: + return operator Vector<int64_t>().duplicate(); + case PACKED_FLOAT32_ARRAY: + return operator Vector<float>().duplicate(); + case PACKED_FLOAT64_ARRAY: + return operator Vector<double>().duplicate(); + case PACKED_STRING_ARRAY: + return operator Vector<String>().duplicate(); + case PACKED_VECTOR2_ARRAY: + return operator Vector<Vector2>().duplicate(); + case PACKED_VECTOR3_ARRAY: + return operator Vector<Vector3>().duplicate(); + case PACKED_COLOR_ARRAY: + return operator Vector<Color>().duplicate(); default: return *this; } diff --git a/doc/classes/BoxMesh.xml b/doc/classes/BoxMesh.xml index 88d22ac899..8a1b9e939e 100644 --- a/doc/classes/BoxMesh.xml +++ b/doc/classes/BoxMesh.xml @@ -6,6 +6,7 @@ <description> Generate an axis-aligned box [PrimitiveMesh]. The box's UV layout is arranged in a 3×2 layout that allows texturing each face individually. To apply the same texture on all faces, change the material's UV property to [code]Vector3(3, 2, 1)[/code]. + [b]Note:[/b] When using a large textured [BoxMesh] (e.g. as a floor), you may stumble upon UV jittering issues depending on the camera angle. To solve this, increase [member subdivide_depth], [member subdivide_height] and [member subdivide_width] until you no longer notice UV jittering. </description> <tutorials> </tutorials> diff --git a/doc/classes/PackedByteArray.xml b/doc/classes/PackedByteArray.xml index 91d066260b..0cef26df79 100644 --- a/doc/classes/PackedByteArray.xml +++ b/doc/classes/PackedByteArray.xml @@ -5,7 +5,6 @@ </brief_description> <description> An [Array] specifically designed to hold bytes. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. </description> <tutorials> </tutorials> @@ -86,6 +85,13 @@ GZIP has a maximal compression ratio of 1032:1, meaning it's very possible for a small compressed payload to decompress to a potentially very large output. To guard against this, you may provide a maximum size this function is allowed to allocate in bytes via [code]max_output_size[/code]. Passing -1 will allow for unbounded output. If any positive value is passed, and the decompression exceeds that amount in bytes, then an error will be returned. </description> </method> + <method name="duplicate"> + <return type="PackedByteArray"> + </return> + <description> + Creates a copy of the array, and returns it. + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/doc/classes/PackedColorArray.xml b/doc/classes/PackedColorArray.xml index 3065d16945..b45e2cbe2e 100644 --- a/doc/classes/PackedColorArray.xml +++ b/doc/classes/PackedColorArray.xml @@ -5,7 +5,6 @@ </brief_description> <description> An [Array] specifically designed to hold [Color]. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. </description> <tutorials> </tutorials> @@ -53,6 +52,13 @@ Appends a [PackedColorArray] at the end of this array. </description> </method> + <method name="duplicate"> + <return type="PackedColorArray"> + </return> + <description> + Creates a copy of the array, and returns it. + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/doc/classes/PackedFloat32Array.xml b/doc/classes/PackedFloat32Array.xml index ab9594d2e3..d6825dbcd7 100644 --- a/doc/classes/PackedFloat32Array.xml +++ b/doc/classes/PackedFloat32Array.xml @@ -5,7 +5,6 @@ </brief_description> <description> An [Array] specifically designed to hold 32-bit floating-point values. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. If you need to pack 64-bit floats tightly, see [PackedFloat64Array]. </description> <tutorials> @@ -54,6 +53,13 @@ Appends a [PackedFloat32Array] at the end of this array. </description> </method> + <method name="duplicate"> + <return type="PackedFloat32Array"> + </return> + <description> + Creates a copy of the array, and returns it. + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/doc/classes/PackedFloat64Array.xml b/doc/classes/PackedFloat64Array.xml index 3088aee483..9b6df93cf5 100644 --- a/doc/classes/PackedFloat64Array.xml +++ b/doc/classes/PackedFloat64Array.xml @@ -5,7 +5,6 @@ </brief_description> <description> An [Array] specifically designed to hold 64-bit floating-point values. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. If you only need to pack 32-bit floats tightly, see [PackedFloat32Array] for a more memory-friendly alternative. </description> <tutorials> @@ -54,6 +53,13 @@ Appends a [PackedFloat64Array] at the end of this array. </description> </method> + <method name="duplicate"> + <return type="PackedFloat64Array"> + </return> + <description> + Creates a copy of the array, and returns it. + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/doc/classes/PackedInt32Array.xml b/doc/classes/PackedInt32Array.xml index eded545de8..7923b268a4 100644 --- a/doc/classes/PackedInt32Array.xml +++ b/doc/classes/PackedInt32Array.xml @@ -5,7 +5,6 @@ </brief_description> <description> An [Array] specifically designed to hold 32-bit integer values. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. [b]Note:[/b] This type stores signed 32-bit integers, which means it can take values in the interval [code][-2^31, 2^31 - 1][/code], i.e. [code][-2147483648, 2147483647][/code]. Exceeding those bounds will wrap around. In comparison, [int] uses signed 64-bit integers which can hold much larger values. If you need to pack 64-bit integers tightly, see [PackedInt64Array]. </description> <tutorials> @@ -54,6 +53,13 @@ Appends a [PackedInt32Array] at the end of this array. </description> </method> + <method name="duplicate"> + <return type="PackedInt32Array"> + </return> + <description> + Creates a copy of the array, and returns it. + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/doc/classes/PackedInt64Array.xml b/doc/classes/PackedInt64Array.xml index 83731b1023..f7e9128410 100644 --- a/doc/classes/PackedInt64Array.xml +++ b/doc/classes/PackedInt64Array.xml @@ -5,7 +5,6 @@ </brief_description> <description> An [Array] specifically designed to hold 64-bit integer values. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. [b]Note:[/b] This type stores signed 64-bit integers, which means it can take values in the interval [code][-2^63, 2^63 - 1][/code], i.e. [code][-9223372036854775808, 9223372036854775807][/code]. Exceeding those bounds will wrap around. If you only need to pack 32-bit integers tightly, see [PackedInt32Array] for a more memory-friendly alternative. </description> <tutorials> @@ -54,6 +53,13 @@ Appends a [PackedInt64Array] at the end of this array. </description> </method> + <method name="duplicate"> + <return type="PackedInt64Array"> + </return> + <description> + Creates a copy of the array, and returns it. + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/doc/classes/PackedStringArray.xml b/doc/classes/PackedStringArray.xml index c71f5ffa7e..1ae0d55177 100644 --- a/doc/classes/PackedStringArray.xml +++ b/doc/classes/PackedStringArray.xml @@ -5,7 +5,6 @@ </brief_description> <description> An [Array] specifically designed to hold [String]s. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. </description> <tutorials> <link title="OS Test Demo">https://godotengine.org/asset-library/asset/677</link> @@ -54,6 +53,13 @@ Appends a [PackedStringArray] at the end of this array. </description> </method> + <method name="duplicate"> + <return type="PackedStringArray"> + </return> + <description> + Creates a copy of the array, and returns it. + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/doc/classes/PackedVector2Array.xml b/doc/classes/PackedVector2Array.xml index 5f68d9256d..9ab3a03edb 100644 --- a/doc/classes/PackedVector2Array.xml +++ b/doc/classes/PackedVector2Array.xml @@ -5,7 +5,6 @@ </brief_description> <description> An [Array] specifically designed to hold [Vector2]. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. </description> <tutorials> <link title="2D Navigation Astar Demo">https://godotengine.org/asset-library/asset/519</link> @@ -54,6 +53,13 @@ Appends a [PackedVector2Array] at the end of this array. </description> </method> + <method name="duplicate"> + <return type="PackedVector2Array"> + </return> + <description> + Creates a copy of the array, and returns it. + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/doc/classes/PackedVector3Array.xml b/doc/classes/PackedVector3Array.xml index e681e1deb7..80787547ac 100644 --- a/doc/classes/PackedVector3Array.xml +++ b/doc/classes/PackedVector3Array.xml @@ -5,7 +5,6 @@ </brief_description> <description> An [Array] specifically designed to hold [Vector3]. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. </description> <tutorials> </tutorials> @@ -53,6 +52,13 @@ Appends a [PackedVector3Array] at the end of this array. </description> </method> + <method name="duplicate"> + <return type="PackedVector3Array"> + </return> + <description> + Creates a copy of the array, and returns it. + </description> + </method> <method name="empty"> <return type="bool"> </return> diff --git a/doc/classes/PlaneMesh.xml b/doc/classes/PlaneMesh.xml index 2081442e04..333d687e91 100644 --- a/doc/classes/PlaneMesh.xml +++ b/doc/classes/PlaneMesh.xml @@ -5,6 +5,7 @@ </brief_description> <description> Class representing a planar [PrimitiveMesh]. This flat mesh does not have a thickness. By default, this mesh is aligned on the X and Z axes; this default rotation isn't suited for use with billboarded materials. For billboarded materials, use [QuadMesh] instead. + [b]Note:[/b] When using a large textured [PlaneMesh] (e.g. as a floor), you may stumble upon UV jittering issues depending on the camera angle. To solve this, increase [member subdivide_depth] and [member subdivide_width] until you no longer notice UV jittering. </description> <tutorials> </tutorials> diff --git a/doc/classes/XRController3D.xml b/doc/classes/XRController3D.xml index 78684d10ee..345e5efdee 100644 --- a/doc/classes/XRController3D.xml +++ b/doc/classes/XRController3D.xml @@ -19,7 +19,7 @@ If active, returns the name of the associated controller if provided by the AR/VR SDK used. </description> </method> - <method name="get_hand" qualifiers="const"> + <method name="get_tracker_hand" qualifiers="const"> <return type="int" enum="XRPositionalTracker.TrackerHand"> </return> <description> diff --git a/doc/classes/XRPositionalTracker.xml b/doc/classes/XRPositionalTracker.xml index 5ed7a26b19..36ff312e4d 100644 --- a/doc/classes/XRPositionalTracker.xml +++ b/doc/classes/XRPositionalTracker.xml @@ -12,7 +12,7 @@ <link title="VR tutorial index">https://docs.godotengine.org/en/latest/tutorials/vr/index.html</link> </tutorials> <methods> - <method name="get_hand" qualifiers="const"> + <method name="get_tracker_hand" qualifiers="const"> <return type="int" enum="XRPositionalTracker.TrackerHand"> </return> <description> @@ -68,18 +68,18 @@ Returns the tracker's type, which will be one of the values from the [enum XRServer.TrackerType] enum. </description> </method> - <method name="get_tracks_orientation" qualifiers="const"> + <method name="is_tracking_orientation" qualifiers="const"> <return type="bool"> </return> <description> - Returns [code]true[/code] if this device tracks orientation. + Returns [code]true[/code] if this device is tracking orientation. </description> </method> - <method name="get_tracks_position" qualifiers="const"> + <method name="is_tracking_position" qualifiers="const"> <return type="bool"> </return> <description> - Returns [code]true[/code] if this device tracks position. + Returns [code]true[/code] if this device is tracking position. </description> </method> <method name="get_transform" qualifiers="const"> @@ -101,10 +101,10 @@ <constant name="TRACKER_HAND_UNKNOWN" value="0" enum="TrackerHand"> The hand this tracker is held in is unknown or not applicable. </constant> - <constant name="TRACKER_LEFT_HAND" value="1" enum="TrackerHand"> + <constant name="TRACKER_HAND_LEFT" value="1" enum="TrackerHand"> This tracker is the left hand controller. </constant> - <constant name="TRACKER_RIGHT_HAND" value="2" enum="TrackerHand"> + <constant name="TRACKER_HAND_RIGHT" value="2" enum="TrackerHand"> This tracker is the right hand controller. </constant> </constants> diff --git a/editor/icons/GuiToggleOn.svg b/editor/icons/GuiToggleOn.svg index 8ab0998f71..37b47e8de4 100644 --- a/editor/icons/GuiToggleOn.svg +++ b/editor/icons/GuiToggleOn.svg @@ -1 +1 @@ -<svg height="16" viewBox="0 0 38 15.999999" width="38" xmlns="http://www.w3.org/2000/svg"><path d="m8 1c-3.878 0-7 3.122-7 7s3.122 7 7 7h22c3.878 0 7-3.122 7-7s-3.122-7-7-7zm22 2a5 5 0 0 1 5 5 5 5 0 0 1 -5 5 5 5 0 0 1 -5-5 5 5 0 0 1 5-5z" fill="#e0e0e0" stroke-width="55.8958"/></svg> +<svg height="16" viewBox="0 0 38 15.999999" width="38" xmlns="http://www.w3.org/2000/svg"><path d="m8 1c-4 0-7 3.0000002-7 7.0000002 0 3.9999998 3 6.9999998 7 6.9999998h22c4 0 7-3 7-6.9999998 0-4-3-7.0000002-7-7.0000002-7.333334 0-14.55609 0-22 0z" fill="#699ce8"/><circle cx="30" cy="8" fill="#fefefe" r="5"/></svg> diff --git a/editor/icons/GuiToggleOnMirrored.svg b/editor/icons/GuiToggleOnMirrored.svg index 7339b6efd2..fa7f602ee7 100644 --- a/editor/icons/GuiToggleOnMirrored.svg +++ b/editor/icons/GuiToggleOnMirrored.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="42" height="26"><path fill="#e0e0e0" d="M31 5c4.986 0 9 3.568 9 8s-4.014 8-9 8H11c-4.986 0-9-3.568-9-8s4.014-8 9-8zM10 8a-5 5 0 0 0-5 5-5 5 0 0 0 5 5-5 5 0 0 0 5-5-5 5 0 0 0-5-5z"/></svg> +<svg height="26" width="42" xmlns="http://www.w3.org/2000/svg"><path d="m31 5c4.986 0 9 3.568 9 8s-4.014 8-9 8h-20c-4.986 0-9-3.568-9-8s4.014-8 9-8z" fill="#699ce8"/><circle cx="10" cy="13" fill="#fefefe" r="5"/></svg> diff --git a/modules/arkit/arkit_interface.mm b/modules/arkit/arkit_interface.mm index 6d69f4a2f4..1c42e6e008 100644 --- a/modules/arkit/arkit_interface.mm +++ b/modules/arkit/arkit_interface.mm @@ -398,14 +398,14 @@ XRPositionalTracker *ARKitInterface::get_anchor_for_uuid(const unsigned char *p_ } XRPositionalTracker *new_tracker = memnew(XRPositionalTracker); - new_tracker->set_type(XRServer::TRACKER_ANCHOR); + new_tracker->set_tracker_type(XRServer::TRACKER_ANCHOR); char tracker_name[256]; sprintf(tracker_name, "Anchor %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", p_uuid[0], p_uuid[1], p_uuid[2], p_uuid[3], p_uuid[4], p_uuid[5], p_uuid[6], p_uuid[7], p_uuid[8], p_uuid[9], p_uuid[10], p_uuid[11], p_uuid[12], p_uuid[13], p_uuid[14], p_uuid[15]); String name = tracker_name; print_line("Adding tracker " + name); - new_tracker->set_name(name); + new_tracker->set_tracker_name(name); // add our tracker XRServer::get_singleton()->add_tracker(new_tracker); diff --git a/modules/gdnative/xr/xr_interface_gdnative.cpp b/modules/gdnative/xr/xr_interface_gdnative.cpp index d03fc33935..d1d575db62 100644 --- a/modules/gdnative/xr/xr_interface_gdnative.cpp +++ b/modules/gdnative/xr/xr_interface_gdnative.cpp @@ -302,12 +302,12 @@ godot_int GDAPI godot_xr_add_controller(char *p_device_name, godot_int p_hand, g ERR_FAIL_NULL_V(input, 0); XRPositionalTracker *new_tracker = memnew(XRPositionalTracker); - new_tracker->set_name(p_device_name); - new_tracker->set_type(XRServer::TRACKER_CONTROLLER); + new_tracker->set_tracker_name(p_device_name); + new_tracker->set_tracker_type(XRServer::TRACKER_CONTROLLER); if (p_hand == 1) { - new_tracker->set_hand(XRPositionalTracker::TRACKER_LEFT_HAND); + new_tracker->set_tracker_hand(XRPositionalTracker::TRACKER_HAND_LEFT); } else if (p_hand == 2) { - new_tracker->set_hand(XRPositionalTracker::TRACKER_RIGHT_HAND); + new_tracker->set_tracker_hand(XRPositionalTracker::TRACKER_HAND_RIGHT); } // also register as joystick... diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 42c2585487..a2f687cd96 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -475,12 +475,3 @@ void Node2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_index", "get_z_index"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "z_as_relative"), "set_z_as_relative", "is_z_relative"); } - -Node2D::Node2D() { - angle = 0; - _scale = Vector2(1, 1); - skew = 0; - _xform_dirty = false; - z_index = 0; - z_relative = true; -} diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index e20f746447..a66e7f625d 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -37,15 +37,15 @@ class Node2D : public CanvasItem { GDCLASS(Node2D, CanvasItem); Point2 pos; - float angle; - Size2 _scale; - float skew; - int z_index; - bool z_relative; + float angle = 0; + Size2 _scale = Vector2(1, 1); + float skew = 0; + int z_index = 0; + bool z_relative = true; Transform2D _mat; - bool _xform_dirty; + bool _xform_dirty = false; void _update_transform(); @@ -121,7 +121,7 @@ public: Transform2D get_transform() const override; - Node2D(); + Node2D() {} }; #endif // NODE2D_H diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index f40a993423..6571474c9b 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -387,14 +387,3 @@ void PathFollow2D::set_loop(bool p_loop) { bool PathFollow2D::has_loop() const { return loop; } - -PathFollow2D::PathFollow2D() { - offset = 0; - h_offset = 0; - v_offset = 0; - path = nullptr; - rotates = true; - cubic = true; - loop = true; - lookahead = 4; -} diff --git a/scene/2d/path_2d.h b/scene/2d/path_2d.h index fcb8b40125..40042a04ef 100644 --- a/scene/2d/path_2d.h +++ b/scene/2d/path_2d.h @@ -63,14 +63,14 @@ class PathFollow2D : public Node2D { public: private: - Path2D *path; - real_t offset; - real_t h_offset; - real_t v_offset; - real_t lookahead; - bool cubic; - bool loop; - bool rotates; + Path2D *path = nullptr; + real_t offset = 0; + real_t h_offset = 0; + real_t v_offset = 0; + real_t lookahead = 4; + bool cubic = true; + bool loop = true; + bool rotates = true; void _update_transform(); @@ -107,7 +107,7 @@ public: String get_configuration_warning() const override; - PathFollow2D(); + PathFollow2D() {} }; #endif // PATH_2D_H diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index e8005f38ed..deb04f0978 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -784,28 +784,4 @@ void Node3D::_bind_methods() { } Node3D::Node3D() : - xform_change(this) { - data.dirty = DIRTY_NONE; - data.children_lock = 0; - - data.ignore_notification = false; - data.top_level = false; - data.top_level_active = false; - data.scale = Vector3(1, 1, 1); - data.viewport = nullptr; - data.inside_world = false; - data.visible = true; - data.disable_scale = false; - -#ifdef TOOLS_ENABLED - data.gizmo_disabled = false; - data.gizmo_dirty = false; -#endif - data.notify_local_transform = false; - data.notify_transform = false; - data.parent = nullptr; - data.C = nullptr; -} - -Node3D::~Node3D() { -} + xform_change(this) {} diff --git a/scene/3d/node_3d.h b/scene/3d/node_3d.h index 5fb421c930..180c441a2a 100644 --- a/scene/3d/node_3d.h +++ b/scene/3d/node_3d.h @@ -65,32 +65,32 @@ class Node3D : public Node { mutable Transform global_transform; mutable Transform local_transform; mutable Vector3 rotation; - mutable Vector3 scale; + mutable Vector3 scale = Vector3(1, 1, 1); - mutable int dirty; + mutable int dirty = DIRTY_NONE; - Viewport *viewport; + Viewport *viewport = nullptr; - bool top_level_active; - bool top_level; - bool inside_world; + bool top_level_active = false; + bool top_level = false; + bool inside_world = false; - int children_lock; - Node3D *parent; + int children_lock = 0; + Node3D *parent = nullptr; List<Node3D *> children; - List<Node3D *>::Element *C; + List<Node3D *>::Element *C = nullptr; - bool ignore_notification; - bool notify_local_transform; - bool notify_transform; + bool ignore_notification = false; + bool notify_local_transform = false; + bool notify_transform = false; - bool visible; - bool disable_scale; + bool visible = true; + bool disable_scale = false; #ifdef TOOLS_ENABLED Ref<Node3DGizmo> gizmo; - bool gizmo_disabled; - bool gizmo_dirty; + bool gizmo_disabled = false; + bool gizmo_dirty = false; #endif } data; @@ -197,7 +197,6 @@ public: void force_update_transform(); Node3D(); - ~Node3D(); }; #endif // NODE_3D_H diff --git a/scene/3d/path_3d.cpp b/scene/3d/path_3d.cpp index ae6bbad8bf..54e6330722 100644 --- a/scene/3d/path_3d.cpp +++ b/scene/3d/path_3d.cpp @@ -385,14 +385,3 @@ void PathFollow3D::set_loop(bool p_loop) { bool PathFollow3D::has_loop() const { return loop; } - -PathFollow3D::PathFollow3D() { - offset = 0; - delta_offset = 0; - h_offset = 0; - v_offset = 0; - path = nullptr; - rotation_mode = ROTATION_XYZ; - cubic = true; - loop = true; -} diff --git a/scene/3d/path_3d.h b/scene/3d/path_3d.h index 1b0f5fa4e0..39f04f1556 100644 --- a/scene/3d/path_3d.h +++ b/scene/3d/path_3d.h @@ -65,14 +65,14 @@ public: }; private: - Path3D *path; - real_t delta_offset; // change in offset since last _update_transform - real_t offset; - real_t h_offset; - real_t v_offset; - bool cubic; - bool loop; - RotationMode rotation_mode; + Path3D *path = nullptr; + real_t delta_offset = 0; // Change in offset since last _update_transform. + real_t offset = 0; + real_t h_offset = 0; + real_t v_offset = 0; + bool cubic = true; + bool loop = true; + RotationMode rotation_mode = ROTATION_XYZ; void _update_transform(bool p_update_xyz_rot = true); @@ -106,7 +106,7 @@ public: String get_configuration_warning() const override; - PathFollow3D(); + PathFollow3D() {} }; VARIANT_ENUM_CAST(PathFollow3D::RotationMode); diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp index 763461880f..5d48795dc1 100644 --- a/scene/3d/xr_nodes.cpp +++ b/scene/3d/xr_nodes.cpp @@ -247,7 +247,7 @@ void XRController3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_joystick_axis", "axis"), &XRController3D::get_joystick_axis); ClassDB::bind_method(D_METHOD("get_is_active"), &XRController3D::get_is_active); - ClassDB::bind_method(D_METHOD("get_hand"), &XRController3D::get_hand); + ClassDB::bind_method(D_METHOD("get_tracker_hand"), &XRController3D::get_tracker_hand); ClassDB::bind_method(D_METHOD("get_rumble"), &XRController3D::get_rumble); ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &XRController3D::set_rumble); @@ -349,7 +349,7 @@ bool XRController3D::get_is_active() const { return is_active; }; -XRPositionalTracker::TrackerHand XRController3D::get_hand() const { +XRPositionalTracker::TrackerHand XRController3D::get_tracker_hand() const { // get our XRServer XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL_V(xr_server, XRPositionalTracker::TRACKER_HAND_UNKNOWN); @@ -359,7 +359,7 @@ XRPositionalTracker::TrackerHand XRController3D::get_hand() const { return XRPositionalTracker::TRACKER_HAND_UNKNOWN; }; - return tracker->get_hand(); + return tracker->get_tracker_hand(); }; String XRController3D::get_configuration_warning() const { diff --git a/scene/3d/xr_nodes.h b/scene/3d/xr_nodes.h index 751b2b68cb..6aa7709485 100644 --- a/scene/3d/xr_nodes.h +++ b/scene/3d/xr_nodes.h @@ -93,7 +93,7 @@ public: void set_rumble(real_t p_rumble); bool get_is_active() const; - XRPositionalTracker::TrackerHand get_hand() const; + XRPositionalTracker::TrackerHand get_tracker_hand() const; Ref<Mesh> get_mesh() const; diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index bdbb0d4684..bc37045386 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -3043,38 +3043,3 @@ void Control::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point"))); } - -Control::Control() { - data.parent = nullptr; - - data.mouse_filter = MOUSE_FILTER_STOP; - - data.RI = nullptr; - data.theme_owner = nullptr; - data.theme_owner_window = nullptr; - data.default_cursor = CURSOR_ARROW; - data.layout_dir = LAYOUT_DIRECTION_INHERITED; - data.h_size_flags = SIZE_FILL; - data.v_size_flags = SIZE_FILL; - data.expand = 1; - data.rotation = 0; - data.parent_canvas_item = nullptr; - data.scale = Vector2(1, 1); - - data.block_minimum_size_adjust = false; - data.disable_visibility_clip = false; - data.h_grow = GROW_DIRECTION_END; - data.v_grow = GROW_DIRECTION_END; - data.minimum_size_valid = false; - data.updating_last_minimum_size = false; - - data.clip_contents = false; - for (int i = 0; i < 4; i++) { - data.anchor[i] = ANCHOR_BEGIN; - data.margin[i] = 0; - } - data.focus_mode = FOCUS_NONE; -} - -Control::~Control() { -} diff --git a/scene/gui/control.h b/scene/gui/control.h index d314c7357b..2241c242bb 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -166,46 +166,46 @@ private: Point2 pos_cache; Size2 size_cache; Size2 minimum_size_cache; - bool minimum_size_valid; + bool minimum_size_valid = false; Size2 last_minimum_size; - bool updating_last_minimum_size; + bool updating_last_minimum_size = false; - float margin[4]; - float anchor[4]; - FocusMode focus_mode; - GrowDirection h_grow; - GrowDirection v_grow; + float margin[4] = { 0.0, 0.0, 0.0, 0.0 }; + float anchor[4] = { ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN }; + FocusMode focus_mode = FOCUS_NONE; + GrowDirection h_grow = GROW_DIRECTION_END; + GrowDirection v_grow = GROW_DIRECTION_END; - LayoutDirection layout_dir; + LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED; - float rotation; - Vector2 scale; + float rotation = 0; + Vector2 scale = Vector2(1, 1); Vector2 pivot_offset; - int h_size_flags; - int v_size_flags; - float expand; + int h_size_flags = SIZE_FILL; + int v_size_flags = SIZE_FILL; + float expand = 1; Point2 custom_minimum_size; - MouseFilter mouse_filter; + MouseFilter mouse_filter = MOUSE_FILTER_STOP; - bool clip_contents; + bool clip_contents = false; - bool block_minimum_size_adjust; - bool disable_visibility_clip; + bool block_minimum_size_adjust = false; + bool disable_visibility_clip = false; - Control *parent; + Control *parent = nullptr; ObjectID drag_owner; Ref<Theme> theme; - Control *theme_owner; - Window *theme_owner_window; + Control *theme_owner = nullptr; + Window *theme_owner_window = nullptr; String tooltip; - CursorShape default_cursor; + CursorShape default_cursor = CURSOR_ARROW; - List<Control *>::Element *RI; + List<Control *>::Element *RI = nullptr; - CanvasItem *parent_canvas_item; + CanvasItem *parent_canvas_item = nullptr; NodePath focus_neighbor[4]; NodePath focus_next; @@ -518,8 +518,7 @@ public: virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override; virtual String get_configuration_warning() const override; - Control(); - ~Control(); + Control() {} }; VARIANT_ENUM_CAST(Control::FocusMode); diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index acbb6d7ab5..28cc056d6e 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -63,6 +63,3 @@ Panel::Panel() { // Has visible stylebox, so stop by default. set_mouse_filter(MOUSE_FILTER_STOP); } - -Panel::~Panel() { -} diff --git a/scene/gui/panel.h b/scene/gui/panel.h index a68c3d3f0c..e2c1ddc91d 100644 --- a/scene/gui/panel.h +++ b/scene/gui/panel.h @@ -54,7 +54,6 @@ public: Mode get_mode() const; Panel(); - ~Panel(); }; VARIANT_ENUM_CAST(Panel::Mode) diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 01c1a15b79..809b4ffd64 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -568,16 +568,12 @@ void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, in text_buf[p_index]->draw(canvas, text_pos, p_font_color); } -void TabContainer::_on_theme_changed() { - if (!_theme_changing) { - return; - } - +void TabContainer::_refresh_texts() { text_buf.clear(); + Vector<Control *> tabs = _get_tabs(); bool rtl = is_layout_rtl(); Ref<Font> font = get_theme_font("font"); int font_size = get_theme_font_size("font_size"); - Vector<Control *> tabs = _get_tabs(); for (int i = 0; i < tabs.size(); i++) { Control *control = Object::cast_to<Control>(tabs[i]); String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); @@ -587,6 +583,14 @@ void TabContainer::_on_theme_changed() { name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); text_buf.push_back(name); } +} + +void TabContainer::_on_theme_changed() { + if (!_theme_changing) { + return; + } + + _refresh_texts(); minimum_size_changed(); if (get_tab_count() > 0) { @@ -679,21 +683,7 @@ Vector<Control *> TabContainer::_get_tabs() const { } void TabContainer::_child_renamed_callback() { - text_buf.clear(); - Vector<Control *> tabs = _get_tabs(); - bool rtl = is_layout_rtl(); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); - for (int i = 0; i < tabs.size(); i++) { - Control *control = Object::cast_to<Control>(tabs[i]); - String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); - Ref<TextLine> name; - name.instance(); - name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); - name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); - text_buf.push_back(name); - } - + _refresh_texts(); update(); } @@ -708,20 +698,8 @@ void TabContainer::add_child_notify(Node *p_child) { return; } - text_buf.clear(); Vector<Control *> tabs = _get_tabs(); - bool rtl = is_layout_rtl(); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); - for (int i = 0; i < tabs.size(); i++) { - Control *control = Object::cast_to<Control>(tabs[i]); - String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); - Ref<TextLine> name; - name.instance(); - name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); - name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); - text_buf.push_back(name); - } + _refresh_texts(); bool first = false; @@ -743,7 +721,6 @@ void TabContainer::add_child_notify(Node *p_child) { c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT))); c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT))); c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM))); - update(); p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback)); if (first && is_inside_tree()) { @@ -751,6 +728,13 @@ void TabContainer::add_child_notify(Node *p_child) { } } +void TabContainer::move_child_notify(Node *p_child) { + Container::move_child_notify(p_child); + call_deferred("_update_current_tab"); + _refresh_texts(); + update(); +} + int TabContainer::get_tab_count() const { return _get_tabs().size(); } @@ -813,20 +797,8 @@ void TabContainer::remove_child_notify(Node *p_child) { } void TabContainer::_update_current_tab() { - text_buf.clear(); Vector<Control *> tabs = _get_tabs(); - bool rtl = is_layout_rtl(); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); - for (int i = 0; i < tabs.size(); i++) { - Control *control = Object::cast_to<Control>(tabs[i]); - String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); - Ref<TextLine> name; - name.instance(); - name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); - name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); - text_buf.push_back(name); - } + _refresh_texts(); int tc = tabs.size(); if (current >= tc) { diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index 91153e5fc3..9ff56afe6e 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -73,12 +73,14 @@ private: void _on_mouse_exited(); void _update_current_tab(); void _draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x); + void _refresh_texts(); protected: void _child_renamed_callback(); void _gui_input(const Ref<InputEvent> &p_event); void _notification(int p_what); virtual void add_child_notify(Node *p_child) override; + virtual void move_child_notify(Node *p_child) override; virtual void remove_child_notify(Node *p_child) override; Variant get_drag_data(const Point2 &p_point) override; diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 43350fae37..8babb1460f 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -292,15 +292,10 @@ void CanvasItemMaterial::_bind_methods() { CanvasItemMaterial::CanvasItemMaterial() : element(this) { - blend_mode = BLEND_MODE_MIX; - light_mode = LIGHT_MODE_NORMAL; - particles_animation = false; - set_particles_anim_h_frames(1); set_particles_anim_v_frames(1); set_particles_anim_loop(false); - current_key.key = 0; current_key.invalid_key = 1; _queue_shader_change(); } @@ -1411,30 +1406,7 @@ CanvasItem::TextureRepeat CanvasItem::get_texture_repeat() const { CanvasItem::CanvasItem() : xform_change(this) { - window = nullptr; canvas_item = RenderingServer::get_singleton()->canvas_item_create(); - visible = true; - pending_update = false; - modulate = Color(1, 1, 1, 1); - self_modulate = Color(1, 1, 1, 1); - top_level = false; - first_draw = false; - drawing = false; - behind = false; - clip_children = false; - block_transform_notify = false; - canvas_layer = nullptr; - use_parent_material = false; - global_invalid = true; - notify_local_transform = false; - notify_transform = false; - light_mask = 1; - texture_repeat = TEXTURE_REPEAT_PARENT_NODE; - texture_filter = TEXTURE_FILTER_PARENT_NODE; - texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; - texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; - - C = nullptr; } CanvasItem::~CanvasItem() { diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h index 3cde6b69c1..34268c1a78 100644 --- a/scene/main/canvas_item.h +++ b/scene/main/canvas_item.h @@ -73,7 +73,7 @@ private: uint32_t invalid_key : 1; }; - uint32_t key; + uint32_t key = 0; bool operator<(const MaterialKey &p_key) const { return key < p_key.key; @@ -114,10 +114,11 @@ private: _FORCE_INLINE_ void _queue_shader_change(); _FORCE_INLINE_ bool _is_shader_dirty() const; - BlendMode blend_mode; - LightMode light_mode; - bool particles_animation; + BlendMode blend_mode = BLEND_MODE_MIX; + LightMode light_mode = LIGHT_MODE_NORMAL; + bool particles_animation = false; + // Initialized in the constructor. int particles_anim_h_frames; int particles_anim_v_frames; bool particles_anim_loop; @@ -188,39 +189,38 @@ private: RID canvas_item; String group; - CanvasLayer *canvas_layer; + CanvasLayer *canvas_layer = nullptr; - Color modulate; - Color self_modulate; + Color modulate = Color(1, 1, 1, 1); + Color self_modulate = Color(1, 1, 1, 1); List<CanvasItem *> children_items; - List<CanvasItem *>::Element *C; - - int light_mask; - - Window *window; - bool first_draw; - bool visible; - bool clip_children; - bool pending_update; - bool top_level; - bool drawing; - bool block_transform_notify; - bool behind; - bool use_parent_material; - bool notify_local_transform; - bool notify_transform; - - RS::CanvasItemTextureFilter texture_filter_cache; - RS::CanvasItemTextureRepeat texture_repeat_cache; - - TextureFilter texture_filter; - TextureRepeat texture_repeat; + List<CanvasItem *>::Element *C = nullptr; + + int light_mask = 1; + + Window *window = nullptr; + bool first_draw = false; + bool visible = true; + bool clip_children = false; + bool pending_update = false; + bool top_level = false; + bool drawing = false; + bool block_transform_notify = false; + bool behind = false; + bool use_parent_material = false; + bool notify_local_transform = false; + bool notify_transform = false; + + RS::CanvasItemTextureFilter texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; + RS::CanvasItemTextureRepeat texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; + TextureFilter texture_filter = TEXTURE_FILTER_PARENT_NODE; + TextureRepeat texture_repeat = TEXTURE_REPEAT_PARENT_NODE; Ref<Material> material; mutable Transform2D global_transform; - mutable bool global_invalid; + mutable bool global_invalid = true; void _top_level_raise_self(); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 47440f8c60..e2df2860ea 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2925,35 +2925,6 @@ String Node::_get_name_num_separator() { } Node::Node() { - data.pos = -1; - data.depth = -1; - data.blocked = 0; - data.parent = nullptr; - data.tree = nullptr; - data.physics_process = false; - data.idle_process = false; - data.process_priority = 0; - data.physics_process_internal = false; - data.idle_process_internal = false; - data.inside_tree = false; - data.ready_notified = false; - - data.owner = nullptr; - data.OW = nullptr; - data.input = false; - data.unhandled_input = false; - data.unhandled_key_input = false; - data.pause_mode = PAUSE_MODE_INHERIT; - data.pause_owner = nullptr; - data.network_master = 1; //server by default - data.path_cache = nullptr; - data.parent_owned = false; - data.in_constructor = true; - data.viewport = nullptr; - data.use_placeholder = false; - data.display_folded = false; - data.ready_first = true; - orphan_node_count++; } diff --git a/scene/main/node.h b/scene/main/node.h index 024d036fd3..5c178d401c 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -90,54 +90,54 @@ private: HashMap<NodePath, int> editable_instances; - Node *parent; - Node *owner; - Vector<Node *> children; // list of children - int pos; - int depth; - int blocked; // safeguard that throws an error when attempting to modify the tree in a harmful way while being traversed. + Node *parent = nullptr; + Node *owner = nullptr; + Vector<Node *> children; + int pos = -1; + int depth = -1; + int blocked = 0; // Safeguard that throws an error when attempting to modify the tree in a harmful way while being traversed. StringName name; - SceneTree *tree; - bool inside_tree; - bool ready_notified; //this is a small hack, so if a node is added during _ready() to the tree, it correctly gets the _ready() notification - bool ready_first; + SceneTree *tree = nullptr; + bool inside_tree = false; + bool ready_notified = false; // This is a small hack, so if a node is added during _ready() to the tree, it correctly gets the _ready() notification. + bool ready_first = true; #ifdef TOOLS_ENABLED - NodePath import_path; //path used when imported, used by scene editors to keep tracking + NodePath import_path; // Path used when imported, used by scene editors to keep tracking. #endif - Viewport *viewport; + Viewport *viewport = nullptr; Map<StringName, GroupData> grouped; - List<Node *>::Element *OW; // owned element + List<Node *>::Element *OW = nullptr; // Owned element. List<Node *> owned; - PauseMode pause_mode; - Node *pause_owner; + PauseMode pause_mode = PAUSE_MODE_INHERIT; + Node *pause_owner = nullptr; - int network_master; + int network_master = 1; // Server by default. Vector<NetData> rpc_methods; Vector<NetData> rpc_properties; - // variables used to properly sort the node when processing, ignored otherwise - //should move all the stuff below to bits - bool physics_process; - bool idle_process; - int process_priority; + // Variables used to properly sort the node when processing, ignored otherwise. + // TODO: Should move all the stuff below to bits. + bool physics_process = false; + bool idle_process = false; + int process_priority = 0; - bool physics_process_internal; - bool idle_process_internal; + bool physics_process_internal = false; + bool idle_process_internal = false; - bool input; - bool unhandled_input; - bool unhandled_key_input; + bool input = false; + bool unhandled_input = false; + bool unhandled_key_input = false; - bool parent_owned; - bool in_constructor; - bool use_placeholder; + bool parent_owned = false; + bool in_constructor = true; + bool use_placeholder = false; - bool display_folded; + bool display_folded = false; - mutable NodePath *path_cache; + mutable NodePath *path_cache = nullptr; } data; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 1df61daa2c..5cf3cbd382 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1332,14 +1332,6 @@ SceneTree::SceneTree() { if (singleton == nullptr) { singleton = this; } - _quit = false; - accept_quit = true; - quit_on_go_back = true; - initialized = false; -#ifdef DEBUG_ENABLED - debug_collisions_hint = false; - debug_navigation_hint = false; -#endif debug_collisions_color = GLOBAL_DEF("debug/shapes/collision/shape_color", Color(0.0, 0.6, 0.7, 0.5)); debug_collision_contact_color = GLOBAL_DEF("debug/shapes/collision/contact_color", Color(1.0, 0.2, 0.1, 0.8)); debug_navigation_color = GLOBAL_DEF("debug/shapes/navigation/geometry_color", Color(0.1, 1.0, 0.7, 0.4)); @@ -1347,23 +1339,7 @@ SceneTree::SceneTree() { collision_debug_contacts = GLOBAL_DEF("debug/shapes/collision/max_contacts_displayed", 10000); ProjectSettings::get_singleton()->set_custom_property_info("debug/shapes/collision/max_contacts_displayed", PropertyInfo(Variant::INT, "debug/shapes/collision/max_contacts_displayed", PROPERTY_HINT_RANGE, "0,20000,1")); // No negative - tree_version = 1; - physics_process_time = 1; - idle_process_time = 1; - - root = nullptr; - pause = false; - current_frame = 0; - tree_changed_name = "tree_changed"; - node_added_name = "node_added"; - node_removed_name = "node_removed"; - node_renamed_name = "node_renamed"; - ugc_locked = false; - call_lock = 0; - root_lock = 0; - node_count = 0; - - //create with mainloop + // Create with mainloop. root = memnew(Window); root->set_name("root"); @@ -1371,8 +1347,7 @@ SceneTree::SceneTree() { root->set_world_3d(Ref<World3D>(memnew(World3D))); } - // Initialize network state - multiplayer_poll = true; + // Initialize network state. set_multiplayer(Ref<MultiplayerAPI>(memnew(MultiplayerAPI))); //root->set_world_2d( Ref<World2D>( memnew( World2D ))); @@ -1409,8 +1384,8 @@ SceneTree::SceneTree() { ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/2d_sdf/oversize", PropertyInfo(Variant::INT, "rendering/quality/2d_sdf/oversize", PROPERTY_HINT_ENUM, "100%,120%,150%,200%")); ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/2d_sdf/scale", PropertyInfo(Variant::INT, "rendering/quality/2d_sdf/scale", PROPERTY_HINT_ENUM, "100%,50%,25%")); - { //load default fallback environment - //get possible extensions + { // Load default fallback environment. + // Get possible extensions. List<String> exts; ResourceLoader::get_recognized_extensions_for_type("Environment", &exts); String ext_hint; @@ -1420,9 +1395,9 @@ SceneTree::SceneTree() { } ext_hint += "*." + E->get(); } - //get path + // Get path. String env_path = GLOBAL_DEF("rendering/environment/default_environment", ""); - //setup property + // Setup property. ProjectSettings::get_singleton()->set_custom_property_info("rendering/environment/default_environment", PropertyInfo(Variant::STRING, "rendering/viewport/default_environment", PROPERTY_HINT_FILE, ext_hint)); env_path = env_path.strip_edges(); if (env_path != String()) { @@ -1431,10 +1406,10 @@ SceneTree::SceneTree() { root->get_world_3d()->set_fallback_environment(env); } else { if (Engine::get_singleton()->is_editor_hint()) { - //file was erased, clear the field. + // File was erased, clear the field. ProjectSettings::get_singleton()->set("rendering/environment/default_environment", ""); } else { - //file was erased, notify user. + // File was erased, notify user. ERR_PRINT(RTR("Default Environment as specified in Project Settings (Rendering -> Environment -> Default Environment) could not be loaded.")); } } diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 3e5802ce2e..9cf129d959 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -80,37 +80,36 @@ public: private: struct Group { Vector<Node *> nodes; - //uint64_t last_tree_version; bool changed; Group() { changed = false; }; }; - Window *root; + Window *root = nullptr; - uint64_t tree_version; - float physics_process_time; - float idle_process_time; - bool accept_quit; - bool quit_on_go_back; + uint64_t tree_version = 1; + float physics_process_time = 1.0; + float idle_process_time = 1.0; + bool accept_quit = true; + bool quit_on_go_back = true; #ifdef DEBUG_ENABLED - bool debug_collisions_hint; - bool debug_navigation_hint; + bool debug_collisions_hint = false; + bool debug_navigation_hint = false; #endif - bool pause; - int root_lock; + bool pause = false; + int root_lock = 0; Map<StringName, Group> group_map; - bool _quit; - bool initialized; + bool _quit = false; + bool initialized = false; - StringName tree_changed_name; - StringName node_added_name; - StringName node_removed_name; - StringName node_renamed_name; + StringName tree_changed_name = "tree_changed"; + StringName node_added_name = "node_added"; + StringName node_removed_name = "node_removed"; + StringName node_renamed_name = "node_renamed"; - int64_t current_frame; - int node_count; + int64_t current_frame = 0; + int node_count = 0; #ifdef TOOLS_ENABLED Node *edited_scene_root; @@ -122,14 +121,14 @@ private: bool operator<(const UGCall &p_with) const { return group == p_with.group ? call < p_with.call : group < p_with.group; } }; - //safety for when a node is deleted while a group is being called - int call_lock; - Set<Node *> call_skip; //skip erased nodes + // Safety for when a node is deleted while a group is being called. + int call_lock = 0; + Set<Node *> call_skip; // Skip erased nodes. List<ObjectID> delete_queue; Map<UGCall, Vector<Variant>> unique_group_calls; - bool ugc_locked; + bool ugc_locked = false; void _flush_ugc(); _FORCE_INLINE_ void _update_group_order(Group &g, bool p_use_priority = false); @@ -157,7 +156,7 @@ private: ///network/// Ref<MultiplayerAPI> multiplayer; - bool multiplayer_poll; + bool multiplayer_poll = true; void _network_peer_connected(int p_id); void _network_peer_disconnected(int p_id); @@ -183,7 +182,7 @@ private: Variant _call_group(const Variant **p_args, int p_argcount, Callable::CallError &r_error); void _flush_delete_queue(); - //optimization + // Optimization. friend class CanvasItem; friend class Node3D; friend class Viewport; diff --git a/servers/rendering/renderer_rd/renderer_scene_render_forward.h b/servers/rendering/renderer_rd/renderer_scene_render_forward.h index 94284e509c..da4cb579c1 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_forward.h +++ b/servers/rendering/renderer_rd/renderer_scene_render_forward.h @@ -582,7 +582,7 @@ class RendererSceneRenderForward : public RendererSceneRenderRD { protected: virtual void _render_scene(RID p_render_buffer, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, int p_directional_light_count, RID *p_gi_probe_cull_result, int p_gi_probe_cull_count, InstanceBase **p_lightmap_cull_result, int p_lightmap_cull_count, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, const Color &p_default_bg_color, float p_lod_threshold); - virtual void _render_shadow(RID p_framebuffer, InstanceBase **p_cull_result, int p_cull_count, const CameraMatrix &p_projection, const Transform &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0, float p_screen_lod_threshold = 0.0); + virtual void _render_shadow(RID p_framebuffer, InstanceBase **p_cull_result, int p_cull_count, const CameraMatrix &p_projection, const Transform &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0.0, float p_screen_lod_threshold = 0.0); virtual void _render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region); virtual void _render_uv2(InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region); virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, InstanceBase **p_cull_result, int p_cull_count, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture); diff --git a/servers/xr/xr_positional_tracker.cpp b/servers/xr/xr_positional_tracker.cpp index a59565fe0d..91469b1aec 100644 --- a/servers/xr/xr_positional_tracker.cpp +++ b/servers/xr/xr_positional_tracker.cpp @@ -34,25 +34,25 @@ void XRPositionalTracker::_bind_methods() { BIND_ENUM_CONSTANT(TRACKER_HAND_UNKNOWN); - BIND_ENUM_CONSTANT(TRACKER_LEFT_HAND); - BIND_ENUM_CONSTANT(TRACKER_RIGHT_HAND); + BIND_ENUM_CONSTANT(TRACKER_HAND_LEFT); + BIND_ENUM_CONSTANT(TRACKER_HAND_RIGHT); // this class is read only from GDScript, so we only have access to getters.. ClassDB::bind_method(D_METHOD("get_tracker_type"), &XRPositionalTracker::get_tracker_type); ClassDB::bind_method(D_METHOD("get_tracker_id"), &XRPositionalTracker::get_tracker_id); ClassDB::bind_method(D_METHOD("get_tracker_name"), &XRPositionalTracker::get_tracker_name); ClassDB::bind_method(D_METHOD("get_joy_id"), &XRPositionalTracker::get_joy_id); - ClassDB::bind_method(D_METHOD("get_tracks_orientation"), &XRPositionalTracker::get_tracks_orientation); + ClassDB::bind_method(D_METHOD("is_tracking_orientation"), &XRPositionalTracker::is_tracking_orientation); ClassDB::bind_method(D_METHOD("get_orientation"), &XRPositionalTracker::get_orientation); - ClassDB::bind_method(D_METHOD("get_tracks_position"), &XRPositionalTracker::get_tracks_position); + ClassDB::bind_method(D_METHOD("is_tracking_position"), &XRPositionalTracker::is_tracking_position); ClassDB::bind_method(D_METHOD("get_position"), &XRPositionalTracker::get_position); - ClassDB::bind_method(D_METHOD("get_hand"), &XRPositionalTracker::get_hand); + ClassDB::bind_method(D_METHOD("get_tracker_hand"), &XRPositionalTracker::get_tracker_hand); ClassDB::bind_method(D_METHOD("get_transform", "adjust_by_reference_frame"), &XRPositionalTracker::get_transform); ClassDB::bind_method(D_METHOD("get_mesh"), &XRPositionalTracker::get_mesh); // these functions we don't want to expose to normal users but do need to be callable from GDNative - ClassDB::bind_method(D_METHOD("_set_type", "type"), &XRPositionalTracker::set_type); - ClassDB::bind_method(D_METHOD("_set_name", "name"), &XRPositionalTracker::set_name); + ClassDB::bind_method(D_METHOD("_set_tracker_type", "type"), &XRPositionalTracker::set_tracker_type); + ClassDB::bind_method(D_METHOD("_set_tracker_name", "name"), &XRPositionalTracker::set_tracker_name); ClassDB::bind_method(D_METHOD("_set_joy_id", "joy_id"), &XRPositionalTracker::set_joy_id); ClassDB::bind_method(D_METHOD("_set_orientation", "orientation"), &XRPositionalTracker::set_orientation); ClassDB::bind_method(D_METHOD("_set_rw_position", "rw_position"), &XRPositionalTracker::set_rw_position); @@ -63,7 +63,7 @@ void XRPositionalTracker::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rumble"), "set_rumble", "get_rumble"); }; -void XRPositionalTracker::set_type(XRServer::TrackerType p_type) { +void XRPositionalTracker::set_tracker_type(XRServer::TrackerType p_type) { if (type != p_type) { type = p_type; hand = XRPositionalTracker::TRACKER_HAND_UNKNOWN; @@ -81,7 +81,7 @@ XRServer::TrackerType XRPositionalTracker::get_tracker_type() const { return type; }; -void XRPositionalTracker::set_name(const String &p_name) { +void XRPositionalTracker::set_tracker_name(const String &p_name) { name = p_name; }; @@ -101,14 +101,14 @@ int XRPositionalTracker::get_joy_id() const { return joy_id; }; -bool XRPositionalTracker::get_tracks_orientation() const { - return tracks_orientation; +bool XRPositionalTracker::is_tracking_orientation() const { + return tracking_orientation; }; void XRPositionalTracker::set_orientation(const Basis &p_orientation) { _THREAD_SAFE_METHOD_ - tracks_orientation = true; // obviously we have this + tracking_orientation = true; // obviously we have this orientation = p_orientation; }; @@ -118,8 +118,8 @@ Basis XRPositionalTracker::get_orientation() const { return orientation; }; -bool XRPositionalTracker::get_tracks_position() const { - return tracks_position; +bool XRPositionalTracker::is_tracking_position() const { + return tracking_position; }; void XRPositionalTracker::set_position(const Vector3 &p_position) { @@ -130,7 +130,7 @@ void XRPositionalTracker::set_position(const Vector3 &p_position) { real_t world_scale = xr_server->get_world_scale(); ERR_FAIL_COND(world_scale == 0); - tracks_position = true; // obviously we have this + tracking_position = true; // obviously we have this rw_position = p_position / world_scale; }; @@ -147,7 +147,7 @@ Vector3 XRPositionalTracker::get_position() const { void XRPositionalTracker::set_rw_position(const Vector3 &p_rw_position) { _THREAD_SAFE_METHOD_ - tracks_position = true; // obviously we have this + tracking_position = true; // obviously we have this rw_position = p_rw_position; }; @@ -169,11 +169,11 @@ Ref<Mesh> XRPositionalTracker::get_mesh() const { return mesh; }; -XRPositionalTracker::TrackerHand XRPositionalTracker::get_hand() const { +XRPositionalTracker::TrackerHand XRPositionalTracker::get_tracker_hand() const { return hand; }; -void XRPositionalTracker::set_hand(const XRPositionalTracker::TrackerHand p_hand) { +void XRPositionalTracker::set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand) { XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL(xr_server); @@ -182,11 +182,11 @@ void XRPositionalTracker::set_hand(const XRPositionalTracker::TrackerHand p_hand ERR_FAIL_COND((type != XRServer::TRACKER_CONTROLLER) && (p_hand != XRPositionalTracker::TRACKER_HAND_UNKNOWN)); hand = p_hand; - if (hand == XRPositionalTracker::TRACKER_LEFT_HAND) { + if (hand == XRPositionalTracker::TRACKER_HAND_LEFT) { if (!xr_server->is_tracker_id_in_use_for_type(type, 1)) { tracker_id = 1; }; - } else if (hand == XRPositionalTracker::TRACKER_RIGHT_HAND) { + } else if (hand == XRPositionalTracker::TRACKER_HAND_RIGHT) { if (!xr_server->is_tracker_id_in_use_for_type(type, 2)) { tracker_id = 2; }; @@ -227,8 +227,8 @@ XRPositionalTracker::XRPositionalTracker() { name = "Unknown"; joy_id = -1; tracker_id = 0; - tracks_orientation = false; - tracks_position = false; + tracking_orientation = false; + tracking_position = false; hand = TRACKER_HAND_UNKNOWN; rumble = 0.0; }; diff --git a/servers/xr/xr_positional_tracker.h b/servers/xr/xr_positional_tracker.h index 8834b64464..c0976d3c13 100644 --- a/servers/xr/xr_positional_tracker.h +++ b/servers/xr/xr_positional_tracker.h @@ -50,8 +50,8 @@ class XRPositionalTracker : public Object { public: enum TrackerHand { TRACKER_HAND_UNKNOWN, /* unknown or not applicable */ - TRACKER_LEFT_HAND, /* controller is the left hand controller */ - TRACKER_RIGHT_HAND /* controller is the right hand controller */ + TRACKER_HAND_LEFT, /* controller is the left hand controller */ + TRACKER_HAND_RIGHT /* controller is the right hand controller */ }; private: @@ -59,9 +59,9 @@ private: StringName name; // (unique) name of the tracker int tracker_id; // tracker index id that is unique per type int joy_id; // if we also have a related joystick entity, the id of the joystick - bool tracks_orientation; // do we track orientation? + bool tracking_orientation; // do we track orientation? Basis orientation; // our orientation - bool tracks_position; // do we track position? + bool tracking_position; // do we track position? Vector3 rw_position; // our position "in the real world, so without world_scale applied" Ref<Mesh> mesh; // when available, a mesh that can be used to render this tracker TrackerHand hand; // if known, the hand this tracker is held in @@ -71,23 +71,23 @@ protected: static void _bind_methods(); public: - void set_type(XRServer::TrackerType p_type); + void set_tracker_type(XRServer::TrackerType p_type); XRServer::TrackerType get_tracker_type() const; - void set_name(const String &p_name); + void set_tracker_name(const String &p_name); StringName get_tracker_name() const; int get_tracker_id() const; void set_joy_id(int p_joy_id); int get_joy_id() const; - bool get_tracks_orientation() const; + bool is_tracking_orientation() const; void set_orientation(const Basis &p_orientation); Basis get_orientation() const; - bool get_tracks_position() const; + bool is_tracking_position() const; void set_position(const Vector3 &p_position); // set position with world_scale applied Vector3 get_position() const; // get position with world_scale applied void set_rw_position(const Vector3 &p_rw_position); Vector3 get_rw_position() const; - XRPositionalTracker::TrackerHand get_hand() const; - void set_hand(const XRPositionalTracker::TrackerHand p_hand); + XRPositionalTracker::TrackerHand get_tracker_hand() const; + void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand); real_t get_rumble() const; void set_rumble(real_t p_rumble); void set_mesh(const Ref<Mesh> &p_mesh); diff --git a/tests/test_macros.h b/tests/test_macros.h index 05fae128b3..ae6af93825 100644 --- a/tests/test_macros.h +++ b/tests/test_macros.h @@ -41,6 +41,9 @@ // The test is skipped with this, run pending tests with `--test --no-skip`. #define TEST_CASE_PENDING(name) TEST_CASE(name *doctest::skip()) +// The test case is marked as failed, but does not fail the entire test run. +#define TEST_CASE_MAY_FAIL(name) TEST_CASE(name *doctest::may_fail()) + // Temporarily disable error prints to test failure paths. // This allows to avoid polluting the test summary with error messages. // The `_print_error_enabled` boolean is defined in `core/print_string.cpp` and diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 9f2c2d6911..5d961854cb 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -54,6 +54,7 @@ #include "test_oa_hash_map.h" #include "test_object.h" #include "test_ordered_hash_map.h" +#include "test_paged_array.h" #include "test_pck_packer.h" #include "test_physics_2d.h" #include "test_physics_3d.h" diff --git a/tests/test_paged_array.h b/tests/test_paged_array.h new file mode 100644 index 0000000000..6b61160229 --- /dev/null +++ b/tests/test_paged_array.h @@ -0,0 +1,153 @@ +/*************************************************************************/ +/* test_paged_array.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* 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 TEST_PAGED_ARRAY_H +#define TEST_PAGED_ARRAY_H + +#include "core/templates/paged_array.h" + +#include "thirdparty/doctest/doctest.h" + +namespace TestPagedArray { + +// PagedArray + +TEST_CASE("[PagedArray] Simple fill and refill") { + PagedArrayPool<uint32_t> pool; + PagedArray<uint32_t> array; + array.set_page_pool(&pool); + + for (uint32_t i = 0; i < 123456; i++) { + array.push_back(i); + } + CHECK_MESSAGE( + array.size() == 123456, + "PagedArray should have 123456 elements."); + + bool all_match = true; + for (uint32_t i = 0; i < 123456; i++) { + if (array[i] != i) { + all_match = false; + break; + } + } + + CHECK_MESSAGE( + all_match, + "PagedArray elements should match from 0 to 123455."); + + array.clear(); + + CHECK_MESSAGE( + array.size() == 0, + "PagedArray elements should be 0 after clear."); + + for (uint32_t i = 0; i < 999; i++) { + array.push_back(i); + } + CHECK_MESSAGE( + array.size() == 999, + "PagedArray should have 999 elements."); + + all_match = true; + for (uint32_t i = 0; i < 999; i++) { + if (array[i] != i) { + all_match = false; + } + } + + CHECK_MESSAGE( + all_match, + "PagedArray elements should match from 0 to 998."); + + array.reset(); //reset so pagepool can be reset + pool.reset(); +} + +TEST_CASE("[PagedArray] Shared pool fill, including merging") { + PagedArrayPool<uint32_t> pool; + PagedArray<uint32_t> array1; + PagedArray<uint32_t> array2; + array1.set_page_pool(&pool); + array2.set_page_pool(&pool); + + for (uint32_t i = 0; i < 123456; i++) { + array1.push_back(i); + } + CHECK_MESSAGE( + array1.size() == 123456, + "PagedArray #1 should have 123456 elements."); + + bool all_match = true; + for (uint32_t i = 0; i < 123456; i++) { + if (array1[i] != i) { + all_match = false; + } + } + + CHECK_MESSAGE( + all_match, + "PagedArray #1 elements should match from 0 to 123455."); + + for (uint32_t i = 0; i < 999; i++) { + array2.push_back(i); + } + CHECK_MESSAGE( + array2.size() == 999, + "PagedArray #2 should have 999 elements."); + + all_match = true; + for (uint32_t i = 0; i < 999; i++) { + if (array2[i] != i) { + all_match = false; + } + } + + CHECK_MESSAGE( + all_match, + "PagedArray #2 elements should match from 0 to 998."); + + array1.merge_unordered(array2); + + CHECK_MESSAGE( + array1.size() == 123456 + 999, + "PagedArray #1 should now be 123456 + 999 elements."); + + CHECK_MESSAGE( + array2.size() == 0, + "PagedArray #2 should now be 0 elements."); + + array1.reset(); //reset so pagepool can be reset + array2.reset(); //reset so pagepool can be reset + pool.reset(); +} +} // namespace TestPagedArray + +#endif // TEST_PAGED_ARRAY_H diff --git a/tests/test_random_number_generator.h b/tests/test_random_number_generator.h index 50ad5ee362..900bb55ffd 100644 --- a/tests/test_random_number_generator.h +++ b/tests/test_random_number_generator.h @@ -36,6 +36,150 @@ namespace TestRandomNumberGenerator { +TEST_CASE("[RandomNumberGenerator] Float") { + Ref<RandomNumberGenerator> rng = memnew(RandomNumberGenerator); + rng->set_seed(0); + + INFO("Should give float between 0.0 and 1.0."); + for (int i = 0; i < 1000; i++) { + real_t n = rng->randf(); + CHECK(n >= 0.0); + CHECK(n <= 1.0); + } +} + +TEST_CASE("[RandomNumberGenerator] Integer range via modulo") { + Ref<RandomNumberGenerator> rng = memnew(RandomNumberGenerator); + rng->set_seed(0); + + INFO("Should give integer between 0 and 100."); + for (int i = 0; i < 1000; i++) { + uint32_t n = rng->randi() % 100; + CHECK(n >= 0); + CHECK(n <= 100); + } +} + +TEST_CASE_MAY_FAIL("[RandomNumberGenerator] Integer 32 bit") { + Ref<RandomNumberGenerator> rng = memnew(RandomNumberGenerator); + rng->set_seed(0); // Change the seed if this fails. + + bool higher = false; + int i; + for (i = 0; i < 1000; i++) { + uint32_t n = rng->randi(); + if (n > 0x0fff'ffff) { + higher = true; + break; + } + } + INFO("Current seed: " << rng->get_seed()); + INFO("Current iteration: " << i); + CHECK_MESSAGE(higher, "Given current seed, this should give an integer higher than 0x0fff'ffff at least once."); +} + +TEST_CASE("[RandomNumberGenerator] Float and integer range") { + Ref<RandomNumberGenerator> rng = memnew(RandomNumberGenerator); + rng->set_seed(0); + uint64_t initial_state = rng->get_state(); + uint32_t initial_seed = rng->get_seed(); + + INFO("Should give float between -100.0 and 100.0, base test."); + for (int i = 0; i < 1000; i++) { + real_t n0 = rng->randf_range(-100.0, 100.0); + CHECK(n0 >= -100); + CHECK(n0 <= 100); + } + + rng->randomize(); + INFO("Should give float between -75.0 and 75.0."); + INFO("Shouldn't be affected by randomize."); + for (int i = 0; i < 1000; i++) { + real_t n1 = rng->randf_range(-75.0, 75.0); + CHECK(n1 >= -75); + CHECK(n1 <= 75); + } + + rng->set_state(initial_state); + INFO("Should give integer between -50 and 50."); + INFO("Shouldn't be affected by set_state."); + for (int i = 0; i < 1000; i++) { + real_t n2 = rng->randi_range(-50, 50); + CHECK(n2 >= -50); + CHECK(n2 <= 50); + } + + rng->set_seed(initial_seed); + INFO("Should give integer between -25 and 25."); + INFO("Shouldn't be affected by set_seed."); + for (int i = 0; i < 1000; i++) { + int32_t n3 = rng->randi_range(-25, 25); + CHECK(n3 >= -25); + CHECK(n3 <= 25); + } + + rng->randf(); + rng->randf(); + + INFO("Should give float between -10.0 and 10.0."); + INFO("Shouldn't be affected after generating new numbers."); + for (int i = 0; i < 1000; i++) { + real_t n4 = rng->randf_range(-10.0, 10.0); + CHECK(n4 >= -10); + CHECK(n4 <= 10); + } + + rng->randi(); + rng->randi(); + + INFO("Should give integer between -5 and 5."); + INFO("Shouldn't be affected after generating new numbers."); + for (int i = 0; i < 1000; i++) { + real_t n5 = rng->randf_range(-5, 5); + CHECK(n5 >= -5); + CHECK(n5 <= 5); + } +} + +TEST_CASE_MAY_FAIL("[RandomNumberGenerator] Normal distribution") { + Ref<RandomNumberGenerator> rng = memnew(RandomNumberGenerator); + rng->set_seed(1); // Change the seed if this fails. + INFO("Should give a number between -5 to 5 (5 std deviations away; above 99.7% chance it will be in this range)."); + INFO("Standard randfn function call."); + for (int i = 0; i < 100; i++) { + real_t n = rng->randfn(); + CHECK(n >= -5); + CHECK(n <= 5); + } + + INFO("Should give number between -5 to 5 after multiple randi/randf calls."); + INFO("5 std deviations away; above 99.7% chance it will be in this range."); + rng->randf(); + rng->randi(); + for (int i = 0; i < 100; i++) { + real_t n = rng->randfn(); + CHECK(n >= -5); + CHECK(n <= 5); + } + + INFO("Checks if user defined mean and deviation work properly."); + INFO("5 std deviations away; above 99.7% chance it will be in this range."); + for (int i = 0; i < 100; i++) { + real_t n = rng->randfn(5, 10); + CHECK(n >= -45); + CHECK(n <= 55); + } + + INFO("Checks if randfn works with changed seeds."); + INFO("5 std deviations away; above 99.7% chance it will be in this range."); + rng->randomize(); + for (int i = 0; i < 100; i++) { + real_t n = rng->randfn(3, 3); + CHECK(n >= -12); + CHECK(n <= 18); + } +} + TEST_CASE("[RandomNumberGenerator] Zero for first number immediately after seeding") { Ref<RandomNumberGenerator> rng = memnew(RandomNumberGenerator); rng->set_seed(0); diff --git a/thirdparty/README.md b/thirdparty/README.md index 73a62458c3..8cb6424a1c 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -206,7 +206,7 @@ Files extracted from upstream source: ## International Components for Unicode - Upstream: https://github.com/unicode-org/icu -- Version: 68.1 +- Version: 68.2 - License: Unicode Files extracted from upstream source: diff --git a/thirdparty/icu4c/APIChangeReport.md b/thirdparty/icu4c/APIChangeReport.md index 0cf9ed5bfc..5385904fd1 100644 --- a/thirdparty/icu4c/APIChangeReport.md +++ b/thirdparty/icu4c/APIChangeReport.md @@ -23,8 +23,10 @@ Removed from ICU 67 | File | API | ICU 67 | ICU 68 | |---|---|---|---| +| fmtable.h | const UFormattable* icu::Formattable::toUFormattable() | StableICU 52 | (missing) | measunit.h | LocalArray<MeasureUnit> icu::MeasureUnit::splitToSingleUnits(int32_t&, UErrorCode&) const | InternalICU 67 | (missing) | measunit.h | int32_t icu::MeasureUnit::getIndex() const | Internal | (missing) +| measunit.h | <tt>static</tt> MeasureUnit icu::MeasureUnit::resolveUnitPerUnit(const MeasureUnit&, const MeasureUnit&, bool*) | Internal | (missing) | measunit.h | <tt>static</tt> int32_t icu::MeasureUnit::getIndexCount() | Internal | (missing) | measunit.h | <tt>static</tt> int32_t icu::MeasureUnit::internalGetIndexForTypeAndSubtype(const char*, const char*) | Internal | (missing) | nounit.h | UClassID icu::NoUnit::getDynamicClassID() const | DraftICU 60 | (missing) @@ -35,6 +37,7 @@ Removed from ICU 67 | nounit.h | <tt>static</tt> NoUnit icu::NoUnit::permille() | DraftICU 60 | (missing) | nounit.h | <tt>static</tt> UClassID icu::NoUnit::getStaticClassID() | DraftICU 60 | (missing) | nounit.h | void* icu::NoUnit::clone() const | DraftICU 60 | (missing) +| uniset.h | const USet* icu::UnicodeSet::toUSet() | StableICU 4.2 | (missing) ## Deprecated @@ -57,6 +60,7 @@ Changed in ICU 68 (old, new) |---|---|---|---| | bytestrie.h | BytesTrie& icu::BytesTrie::resetToState64(uint64_t) | Draft→StableICU 65 | bytestrie.h | uint64_t icu::BytesTrie::getState64() const | Draft→StableICU 65 +| listformatter.h | <tt>static</tt> ListFormatter* icu::ListFormatter::createInstance(const Locale&, UListFormatterType, UListFormatterWidth, UErrorCode&) | Draft→StableICU 67 | localebuilder.h | UBool icu::LocaleBuilder::copyErrorTo(UErrorCode&) const | Draft→StableICU 65 | localematcher.h | Builder& icu::LocaleMatcher::Builder::addSupportedLocale(const Locale&) | Draft→StableICU 65 | localematcher.h | Builder& icu::LocaleMatcher::Builder::operator=(Builder&&) | Draft→StableICU 65 @@ -132,6 +136,13 @@ Changed in ICU 68 (old, new) | ucal.h | int32_t ucal_getHostTimeZone(UChar*, int32_t, UErrorCode*) | Draft→StableICU 65 | ucharstrie.h | UCharsTrie& icu::UCharsTrie::resetToState64(uint64_t) | Draft→StableICU 65 | ucharstrie.h | uint64_t icu::UCharsTrie::getState64() const | Draft→StableICU 65 +| ulistformatter.h | UListFormatter* ulistfmt_openForType(const char*, UListFormatterType, UListFormatterWidth, UErrorCode*) | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterType::ULISTFMT_TYPE_AND | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterType::ULISTFMT_TYPE_OR | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterType::ULISTFMT_TYPE_UNITS | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterWidth::ULISTFMT_WIDTH_NARROW | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterWidth::ULISTFMT_WIDTH_SHORT | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterWidth::ULISTFMT_WIDTH_WIDE | Draft→StableICU 67 | uloc.h | UEnumeration* uloc_openAvailableByType(ULocAvailableType, UErrorCode*) | Draft→StableICU 65 | uloc.h | <tt>enum</tt> ULocAvailableType::ULOC_AVAILABLE_DEFAULT | Draft→StableICU 65 | uloc.h | <tt>enum</tt> ULocAvailableType::ULOC_AVAILABLE_ONLY_LEGACY_ALIASES | Draft→StableICU 65 @@ -151,6 +162,8 @@ Promoted to stable in ICU 68 |---|---|---|---| | bytestrie.h | BytesTrie& icu::BytesTrie::resetToState64(uint64_t) | Draft→StableICU 65 | bytestrie.h | uint64_t icu::BytesTrie::getState64() const | Draft→StableICU 65 +| fmtable.h | UFormattable* icu::Formattable::toUFormattable() | (missing) | StableICU 52 +| listformatter.h | <tt>static</tt> ListFormatter* icu::ListFormatter::createInstance(const Locale&, UListFormatterType, UListFormatterWidth, UErrorCode&) | Draft→StableICU 67 | localebuilder.h | UBool icu::LocaleBuilder::copyErrorTo(UErrorCode&) const | Draft→StableICU 65 | localematcher.h | Builder& icu::LocaleMatcher::Builder::addSupportedLocale(const Locale&) | Draft→StableICU 65 | localematcher.h | Builder& icu::LocaleMatcher::Builder::operator=(Builder&&) | Draft→StableICU 65 @@ -224,10 +237,18 @@ Promoted to stable in ICU 68 | ucal.h | int32_t ucal_getHostTimeZone(UChar*, int32_t, UErrorCode*) | Draft→StableICU 65 | ucharstrie.h | UCharsTrie& icu::UCharsTrie::resetToState64(uint64_t) | Draft→StableICU 65 | ucharstrie.h | uint64_t icu::UCharsTrie::getState64() const | Draft→StableICU 65 +| ulistformatter.h | UListFormatter* ulistfmt_openForType(const char*, UListFormatterType, UListFormatterWidth, UErrorCode*) | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterType::ULISTFMT_TYPE_AND | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterType::ULISTFMT_TYPE_OR | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterType::ULISTFMT_TYPE_UNITS | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterWidth::ULISTFMT_WIDTH_NARROW | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterWidth::ULISTFMT_WIDTH_SHORT | Draft→StableICU 67 +| ulistformatter.h | <tt>enum</tt> UListFormatterWidth::ULISTFMT_WIDTH_WIDE | Draft→StableICU 67 | uloc.h | UEnumeration* uloc_openAvailableByType(ULocAvailableType, UErrorCode*) | Draft→StableICU 65 | uloc.h | <tt>enum</tt> ULocAvailableType::ULOC_AVAILABLE_DEFAULT | Draft→StableICU 65 | uloc.h | <tt>enum</tt> ULocAvailableType::ULOC_AVAILABLE_ONLY_LEGACY_ALIASES | Draft→StableICU 65 | uloc.h | <tt>enum</tt> ULocAvailableType::ULOC_AVAILABLE_WITH_LEGACY_ALIASES | Draft→StableICU 65 +| uniset.h | USet* icu::UnicodeSet::toUSet() | (missing) | StableICU 4.2 | utrace.h | <tt>enum</tt> UTraceFunctionNumber::UTRACE_UDATA_BUNDLE | Draft→StableICU 65 | utrace.h | <tt>enum</tt> UTraceFunctionNumber::UTRACE_UDATA_DATA_FILE | Draft→StableICU 65 | utrace.h | <tt>enum</tt> UTraceFunctionNumber::UTRACE_UDATA_RES_FILE | Draft→StableICU 65 @@ -242,6 +263,7 @@ Added in ICU 68 | dtitvfmt.h | UDisplayContext icu::DateIntervalFormat::getContext(UDisplayContextType, UErrorCode&) const | (missing) | DraftICU 68 | dtitvfmt.h | void icu::DateIntervalFormat::setContext(UDisplayContext, UErrorCode&) | (missing) | DraftICU 68 | dtptngen.h | <tt>static</tt> DateTimePatternGenerator* icu::DateTimePatternGenerator::createInstanceNoStdPat(const Locale&, UErrorCode&) | (missing) | Internal +| fmtable.h | UFormattable* icu::Formattable::toUFormattable() | (missing) | StableICU 52 | localematcher.h | Builder& icu::LocaleMatcher::Builder::setMaxDistance(const Locale&, const Locale&) | (missing) | DraftICU 68 | localematcher.h | Builder& icu::LocaleMatcher::Builder::setNoDefaultLocale() | (missing) | DraftICU 68 | localematcher.h | UBool icu::LocaleMatcher::isMatch(const Locale&, const Locale&, UErrorCode&) const | (missing) | DraftICU 68 @@ -285,12 +307,14 @@ Added in ICU 68 | numberrangeformatter.h | std::pair< StringClass, StringClass > icu::number::FormattedNumberRange::getDecimalNumbers(UErrorCode&) const | (missing) | DraftICU 68 | plurrule.h | UnicodeString icu::PluralRules::select(const number::FormattedNumberRange&, UErrorCode&) const | (missing) | DraftICU 68 | plurrule.h | UnicodeString icu::PluralRules::select(const number::impl::UFormattedNumberRangeData*, UErrorCode&) const | (missing) | Internal +| plurrule.h | int32_t icu::PluralRules::getSamples(const UnicodeString&, FixedDecimal*, int32_t, UErrorCode&) | (missing) | Internal | timezone.h | <tt>static</tt> TimeZone* icu::TimeZone::forLocaleOrDefault(const Locale&) | (missing) | Internal | ucurr.h | <tt>enum</tt> UCurrNameStyle::UCURR_FORMAL_SYMBOL_NAME | (missing) | DraftICU 68 | ucurr.h | <tt>enum</tt> UCurrNameStyle::UCURR_VARIANT_SYMBOL_NAME | (missing) | DraftICU 68 | udateintervalformat.h | UDisplayContext udtitvfmt_getContext(const UDateIntervalFormat*, UDisplayContextType, UErrorCode*) | (missing) | DraftICU 68 | udateintervalformat.h | void udtitvfmt_setContext(UDateIntervalFormat*, UDisplayContext, UErrorCode*) | (missing) | DraftICU 68 | umachine.h | <tt>#define</tt> U_DEFINE_FALSE_AND_TRUE | (missing) | InternalICU 68 +| uniset.h | USet* icu::UnicodeSet::toUSet() | (missing) | StableICU 4.2 | unum.h | <tt>enum</tt> UNumberFormatMinimumGroupingDigits::UNUM_MINIMUM_GROUPING_DIGITS_AUTO | (missing) | DraftICU 68 | unum.h | <tt>enum</tt> UNumberFormatMinimumGroupingDigits::UNUM_MINIMUM_GROUPING_DIGITS_MIN2 | (missing) | DraftICU 68 | unumberformatter.h | <tt>enum</tt> UNumberUnitWidth::UNUM_UNIT_WIDTH_FORMAL | (missing) | DraftICU 68 @@ -317,7 +341,6 @@ Other existing drafts in ICU 68 | bytestream.h | void icu::ByteSink::AppendU8(const char*, int32_t) | DraftICU 67 | | bytestream.h | void icu::ByteSink::AppendU8(const char8_t*, int32_t) | DraftICU 67 | | dtptngen.h | UDateFormatHourCycle icu::DateTimePatternGenerator::getDefaultHourCycle(UErrorCode&) const | DraftICU 67 | -| listformatter.h | <tt>static</tt> ListFormatter* icu::ListFormatter::createInstance(const Locale&, UListFormatterType, UListFormatterWidth, UErrorCode&) | DraftICU 67 | | localematcher.h | Builder& icu::LocaleMatcher::Builder::setDirection(ULocMatchDirection) | DraftICU 67 | | localematcher.h | <tt>enum</tt> ULocMatchDirection::ULOCMATCH_DIRECTION_ONLY_TWO_WAY | DraftICU 67 | | localematcher.h | <tt>enum</tt> ULocMatchDirection::ULOCMATCH_DIRECTION_WITH_ONE_WAY | DraftICU 67 | @@ -349,13 +372,6 @@ Other existing drafts in ICU 68 | udateintervalformat.h | void udtitvfmt_formatCalendarToResult(const UDateIntervalFormat*, UCalendar*, UCalendar*, UFormattedDateInterval*, UErrorCode*) | DraftICU 67 | | udateintervalformat.h | void udtitvfmt_formatToResult(const UDateIntervalFormat*, UDate, UDate, UFormattedDateInterval*, UErrorCode*) | DraftICU 67 | | udatpg.h | UDateFormatHourCycle udatpg_getDefaultHourCycle(const UDateTimePatternGenerator*, UErrorCode*) | DraftICU 67 | -| ulistformatter.h | UListFormatter* ulistfmt_openForType(const char*, UListFormatterType, UListFormatterWidth, UErrorCode*) | DraftICU 67 | -| ulistformatter.h | <tt>enum</tt> UListFormatterType::ULISTFMT_TYPE_AND | DraftICU 67 | -| ulistformatter.h | <tt>enum</tt> UListFormatterType::ULISTFMT_TYPE_OR | DraftICU 67 | -| ulistformatter.h | <tt>enum</tt> UListFormatterType::ULISTFMT_TYPE_UNITS | DraftICU 67 | -| ulistformatter.h | <tt>enum</tt> UListFormatterWidth::ULISTFMT_WIDTH_NARROW | DraftICU 67 | -| ulistformatter.h | <tt>enum</tt> UListFormatterWidth::ULISTFMT_WIDTH_SHORT | DraftICU 67 | -| ulistformatter.h | <tt>enum</tt> UListFormatterWidth::ULISTFMT_WIDTH_WIDE | DraftICU 67 | | uregex.h | <tt>enum</tt> URegexpFlag::UREGEX_CANON_EQ | DraftICU 2.4 | | utrace.h | <tt>enum</tt> UTraceFunctionNumber::UTRACE_UBRK_CREATE_BREAK_ENGINE | DraftICU 67 | | utrace.h | <tt>enum</tt> UTraceFunctionNumber::UTRACE_UBRK_CREATE_CHARACTER | DraftICU 67 | @@ -373,7 +389,7 @@ This section shows cases where the signature was "simplified" for the sake of co ## Colophon -Contents generated by StableAPI tool on Wed Sep 30 17:44:26 PDT 2020 +Contents generated by StableAPI tool on Fri Oct 23 11:32:42 PDT 2020 Copyright © 2019 and later: Unicode, Inc. and others. License & terms of use: http://www.unicode.org/copyright.html diff --git a/thirdparty/icu4c/common/cmemory.h b/thirdparty/icu4c/common/cmemory.h index 210bc7645e..a9d9424b4e 100644 --- a/thirdparty/icu4c/common/cmemory.h +++ b/thirdparty/icu4c/common/cmemory.h @@ -725,9 +725,14 @@ public: } MemoryPool& operator=(MemoryPool&& other) U_NOEXCEPT { - fCount = other.fCount; - fPool = std::move(other.fPool); - other.fCount = 0; + // Since `this` may contain instances that need to be deleted, we can't + // just throw them away and replace them with `other`. The normal way of + // dealing with this in C++ is to swap `this` and `other`, rather than + // simply overwrite: the destruction of `other` can then take care of + // running MemoryPool::~MemoryPool() over the still-to-be-deallocated + // instances. + std::swap(fCount, other.fCount); + std::swap(fPool, other.fPool); return *this; } @@ -796,9 +801,6 @@ protected: template<typename T, int32_t stackCapacity = 8> class MaybeStackVector : protected MemoryPool<T, stackCapacity> { public: - using MemoryPool<T, stackCapacity>::MemoryPool; - using MemoryPool<T, stackCapacity>::operator=; - template<typename... Args> T* emplaceBack(Args&&... args) { return this->create(args...); diff --git a/thirdparty/icu4c/common/locid.cpp b/thirdparty/icu4c/common/locid.cpp index 2804e36bf6..874e4a7055 100644 --- a/thirdparty/icu4c/common/locid.cpp +++ b/thirdparty/icu4c/common/locid.cpp @@ -35,6 +35,7 @@ #include "unicode/bytestream.h" #include "unicode/locid.h" +#include "unicode/localebuilder.h" #include "unicode/strenum.h" #include "unicode/stringpiece.h" #include "unicode/uloc.h" @@ -1028,7 +1029,7 @@ public: // place the the replaced locale ID in out and return true. // Otherwise return false for no replacement or error. bool replace( - const Locale& locale, CharString& out, UErrorCode status); + const Locale& locale, CharString& out, UErrorCode& status); private: const char* language; @@ -1336,10 +1337,13 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status) // Cannot use nullptr for language because that will construct // the default locale, in that case, use "und" to get the correct // locale. - Locale l(language == nullptr ? "und" : language, nullptr, script); + Locale l = LocaleBuilder() + .setLanguage(language == nullptr ? "und" : language) + .setScript(script) + .build(status); l.addLikelySubtags(status); const char* likelyRegion = l.getCountry(); - CharString* item = nullptr; + LocalPointer<CharString> item; if (likelyRegion != nullptr && uprv_strlen(likelyRegion) > 0) { size_t len = uprv_strlen(likelyRegion); const char* foundInReplacement = uprv_strstr(replacement, @@ -1351,20 +1355,22 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status) *(foundInReplacement-1) == ' '); U_ASSERT(foundInReplacement[len] == ' ' || foundInReplacement[len] == '\0'); - item = new CharString(foundInReplacement, (int32_t)len, status); + item.adoptInsteadAndCheckErrorCode( + new CharString(foundInReplacement, (int32_t)len, status), status); } } - if (item == nullptr) { - item = new CharString(replacement, - (int32_t)(firstSpace - replacement), status); + if (item.isNull() && U_SUCCESS(status)) { + item.adoptInsteadAndCheckErrorCode( + new CharString(replacement, + (int32_t)(firstSpace - replacement), status), status); } if (U_FAILURE(status)) { return false; } - if (item == nullptr) { + if (item.isNull()) { status = U_MEMORY_ALLOCATION_ERROR; return false; } replacedRegion = item->data(); - toBeFreed.addElement(item, status); + toBeFreed.addElement(item.orphan(), status); } U_ASSERT(!same(region, replacedRegion)); region = replacedRegion; @@ -1453,7 +1459,7 @@ AliasReplacer::outputToString( int32_t variantsStart = out.length(); for (int32_t i = 0; i < variants.size(); i++) { out.append(SEP_CHAR, status) - .append((const char*)((UVector*)variants.elementAt(i)), + .append((const char*)(variants.elementAt(i)), status); } T_CString_toUpperCase(out.data() + variantsStart); @@ -1470,7 +1476,7 @@ AliasReplacer::outputToString( } bool -AliasReplacer::replace(const Locale& locale, CharString& out, UErrorCode status) +AliasReplacer::replace(const Locale& locale, CharString& out, UErrorCode& status) { data = AliasData::singleton(status); if (U_FAILURE(status)) { @@ -2453,9 +2459,13 @@ Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErro if (U_FAILURE(status)) { return; } + if (status == U_STRING_NOT_TERMINATED_WARNING) { + status = U_ZERO_ERROR; + } int32_t bufferLength = uprv_max((int32_t)(uprv_strlen(fullName) + 1), ULOC_FULLNAME_CAPACITY); int32_t newLength = uloc_setKeywordValue(keywordName, keywordValue, fullName, bufferLength, &status) + 1; + U_ASSERT(status != U_STRING_NOT_TERMINATED_WARNING); /* Handle the case the current buffer is not enough to hold the new id */ if (status == U_BUFFER_OVERFLOW_ERROR) { U_ASSERT(newLength > bufferLength); @@ -2472,6 +2482,7 @@ Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErro fullName = newFullName; status = U_ZERO_ERROR; uloc_setKeywordValue(keywordName, keywordValue, fullName, newLength, &status); + U_ASSERT(status != U_STRING_NOT_TERMINATED_WARNING); } else { U_ASSERT(newLength <= bufferLength); } diff --git a/thirdparty/icu4c/common/rbbitblb.cpp b/thirdparty/icu4c/common/rbbitblb.cpp index bcbdab9227..70e260fc08 100644 --- a/thirdparty/icu4c/common/rbbitblb.cpp +++ b/thirdparty/icu4c/common/rbbitblb.cpp @@ -1402,12 +1402,13 @@ void RBBITableBuilder::exportTable(void *where) { U_ASSERT (sd->fAccepting <= 255); U_ASSERT (sd->fLookAhead <= 255); U_ASSERT (0 <= sd->fTagsIdx && sd->fTagsIdx <= 255); - row->r8.fAccepting = sd->fAccepting; - row->r8.fLookAhead = sd->fLookAhead; - row->r8.fTagsIdx = sd->fTagsIdx; + RBBIStateTableRow8 *r8 = (RBBIStateTableRow8*)row; + r8->fAccepting = sd->fAccepting; + r8->fLookAhead = sd->fLookAhead; + r8->fTagsIdx = sd->fTagsIdx; for (col=0; col<catCount; col++) { U_ASSERT (sd->fDtran->elementAti(col) <= kMaxStateFor8BitsTable); - row->r8.fNextState[col] = sd->fDtran->elementAti(col); + r8->fNextState[col] = sd->fDtran->elementAti(col); } } else { U_ASSERT (sd->fAccepting <= 0xffff); @@ -1603,12 +1604,13 @@ void RBBITableBuilder::exportSafeTable(void *where) { UnicodeString *rowString = (UnicodeString *)fSafeTable->elementAt(state); RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen); if (use8BitsForSafeTable()) { - row->r8.fAccepting = 0; - row->r8.fLookAhead = 0; - row->r8.fTagsIdx = 0; + RBBIStateTableRow8 *r8 = (RBBIStateTableRow8*)row; + r8->fAccepting = 0; + r8->fLookAhead = 0; + r8->fTagsIdx = 0; for (col=0; col<catCount; col++) { U_ASSERT(rowString->charAt(col) <= kMaxStateFor8BitsTable); - row->r8.fNextState[col] = static_cast<uint8_t>(rowString->charAt(col)); + r8->fNextState[col] = static_cast<uint8_t>(rowString->charAt(col)); } } else { row->r16.fAccepting = 0; diff --git a/thirdparty/icu4c/common/uloc.cpp b/thirdparty/icu4c/common/uloc.cpp index 522f33dbe2..ebfbb50650 100644 --- a/thirdparty/icu4c/common/uloc.cpp +++ b/thirdparty/icu4c/common/uloc.cpp @@ -877,6 +877,9 @@ uloc_setKeywordValue(const char* keywordName, if(U_FAILURE(*status)) { return -1; } + if (*status == U_STRING_NOT_TERMINATED_WARNING) { + *status = U_ZERO_ERROR; + } if (keywordName == NULL || keywordName[0] == 0 || bufferCapacity <= 1) { *status = U_ILLEGAL_ARGUMENT_ERROR; return 0; @@ -914,6 +917,7 @@ uloc_setKeywordValue(const char* keywordName, startSearchHere = (char*)locale_getKeywordsStart(buffer); if(startSearchHere == NULL || (startSearchHere[1]==0)) { if(keywordValueLen == 0) { /* no keywords = nothing to remove */ + U_ASSERT(*status != U_STRING_NOT_TERMINATED_WARNING); return bufLen; } @@ -933,6 +937,7 @@ uloc_setKeywordValue(const char* keywordName, startSearchHere += keywordNameLen; *startSearchHere++ = '='; uprv_strcpy(startSearchHere, keywordValueBuffer); + U_ASSERT(*status != U_STRING_NOT_TERMINATED_WARNING); return needLen; } /* end shortcut - no @ */ @@ -1047,13 +1052,27 @@ uloc_setKeywordValue(const char* keywordName, if (!handledInputKeyAndValue || U_FAILURE(*status)) { /* if input key/value specified removal of a keyword not present in locale, or * there was an error in CharString.append, leave original locale alone. */ + U_ASSERT(*status != U_STRING_NOT_TERMINATED_WARNING); return bufLen; } // needLen = length of the part before '@' needLen = (int32_t)(startSearchHere - buffer); - return needLen + updatedKeysAndValues.extract( + // Check to see can we fit the startSearchHere, if not, return + // U_BUFFER_OVERFLOW_ERROR without copy updatedKeysAndValues into it. + // We do this because this API function does not behave like most others: + // It promises never to set a U_STRING_NOT_TERMINATED_WARNING. + // When the contents fits but without the terminating NUL, in this case we need to not change + // the buffer contents and return with a buffer overflow error. + int32_t appendLength = updatedKeysAndValues.length(); + if (appendLength >= bufferCapacity - needLen) { + *status = U_BUFFER_OVERFLOW_ERROR; + return needLen + appendLength; + } + needLen += updatedKeysAndValues.extract( startSearchHere, bufferCapacity - needLen, *status); + U_ASSERT(*status != U_STRING_NOT_TERMINATED_WARNING); + return needLen; } /* ### ID parsing implementation **************************************************/ diff --git a/thirdparty/icu4c/common/unicode/docmain.h b/thirdparty/icu4c/common/unicode/docmain.h index b7984ada03..edcb5d4e83 100644 --- a/thirdparty/icu4c/common/unicode/docmain.h +++ b/thirdparty/icu4c/common/unicode/docmain.h @@ -143,6 +143,11 @@ * <td>icu::MessageFormat</td> * </tr> * <tr> + * <td>List Formatting</td> + * <td>ulistformatter.h</td> + * <td>icu::ListFormatter</td> + * </tr> + * <tr> * <td>Number Formatting<br/>(includes currency and unit formatting)</td> * <td>unumberformatter.h, unum.h</td> * <td>icu::number::NumberFormatter (ICU 60+) or icu::NumberFormat (older versions)</td> diff --git a/thirdparty/icu4c/common/unicode/urename.h b/thirdparty/icu4c/common/unicode/urename.h index 20232cd209..fe59fdd893 100644 --- a/thirdparty/icu4c/common/unicode/urename.h +++ b/thirdparty/icu4c/common/unicode/urename.h @@ -1137,6 +1137,7 @@ #define ulocimp_toLanguageTag U_ICU_ENTRY_POINT_RENAME(ulocimp_toLanguageTag) #define ulocimp_toLegacyKey U_ICU_ENTRY_POINT_RENAME(ulocimp_toLegacyKey) #define ulocimp_toLegacyType U_ICU_ENTRY_POINT_RENAME(ulocimp_toLegacyType) +#define ultag_getTKeyStart U_ICU_ENTRY_POINT_RENAME(ultag_getTKeyStart) #define ultag_isExtensionSubtags U_ICU_ENTRY_POINT_RENAME(ultag_isExtensionSubtags) #define ultag_isLanguageSubtag U_ICU_ENTRY_POINT_RENAME(ultag_isLanguageSubtag) #define ultag_isPrivateuseValueSubtags U_ICU_ENTRY_POINT_RENAME(ultag_isPrivateuseValueSubtags) diff --git a/thirdparty/icu4c/common/unicode/uvernum.h b/thirdparty/icu4c/common/unicode/uvernum.h index a4cbb9e0fe..a46481a3fe 100644 --- a/thirdparty/icu4c/common/unicode/uvernum.h +++ b/thirdparty/icu4c/common/unicode/uvernum.h @@ -66,7 +66,7 @@ * This value will change in the subsequent releases of ICU * @stable ICU 2.6 */ -#define U_ICU_VERSION_MINOR_NUM 1 +#define U_ICU_VERSION_MINOR_NUM 2 /** The current ICU patchlevel version as an integer. * This value will change in the subsequent releases of ICU @@ -139,7 +139,7 @@ * This value will change in the subsequent releases of ICU * @stable ICU 2.4 */ -#define U_ICU_VERSION "68.1" +#define U_ICU_VERSION "68.2" /** * The current ICU library major version number as a string, for library name suffixes. @@ -158,7 +158,7 @@ /** Data version in ICU4C. * @internal ICU 4.4 Internal Use Only **/ -#define U_ICU_DATA_VERSION "68.1" +#define U_ICU_DATA_VERSION "68.2" #endif /* U_HIDE_INTERNAL_API */ /*=========================================================================== diff --git a/thirdparty/icu4c/common/wintz.cpp b/thirdparty/icu4c/common/wintz.cpp index 3730232286..580cedadb6 100644 --- a/thirdparty/icu4c/common/wintz.cpp +++ b/thirdparty/icu4c/common/wintz.cpp @@ -36,17 +36,58 @@ U_NAMESPACE_BEGIN +// Note these constants and the struct are only used when dealing with the fallback path for RDP sesssions. + +// This is the location of the time zones in the registry on Vista+ systems. +// See: https://docs.microsoft.com/windows/win32/api/timezoneapi/ns-timezoneapi-dynamic_time_zone_information +#define WINDOWS_TIMEZONES_REG_KEY_PATH L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones" + +// Max length for a registry key is 255. +1 for null. +// See: https://docs.microsoft.com/windows/win32/sysinfo/registry-element-size-limits +#define WINDOWS_MAX_REG_KEY_LENGTH 256 + +#if U_PLATFORM_HAS_WINUWP_API == 0 + +// This is the layout of the TZI binary value in the registry. +// See: https://docs.microsoft.com/windows/win32/api/timezoneapi/ns-timezoneapi-time_zone_information +typedef struct _REG_TZI_FORMAT { + LONG Bias; + LONG StandardBias; + LONG DaylightBias; + SYSTEMTIME StandardDate; + SYSTEMTIME DaylightDate; +} REG_TZI_FORMAT; + +#endif // U_PLATFORM_HAS_WINUWP_API + /** -* Main Windows time zone detection function. -* Returns the Windows time zone converted to an ICU time zone as a heap-allocated buffer, or nullptr upon failure. +* This is main Windows time zone detection function. +* +* It returns the Windows time zone converted to an ICU time zone as a heap-allocated buffer, or nullptr upon failure. * -* Note: We use the Win32 API GetDynamicTimeZoneInformation (available since Vista+) to get the current time zone info. -* This API returns a non-localized time zone name, which is mapped to an ICU time zone ID (~ Olsen ID). +* We use the Win32 API GetDynamicTimeZoneInformation (which is available since Vista) to get the current time zone info, +* as this API returns a non-localized time zone name which can be then mapped to an ICU time zone. +* +* However, in some RDP/terminal services situations, this struct isn't always fully complete, and the TimeZoneKeyName +* field of the struct might be NULL. This can happen with some 3rd party RDP clients, and also when using older versions +* of the RDP protocol, which don't send the newer TimeZoneKeyNamei information and only send the StandardName and DaylightName. +* +* Since these 3rd party clients and older RDP clients only send the pre-Vista time zone information to the server, this means that we +* need to fallback on using the pre-Vista methods to determine the time zone. This unfortunately requires examining the registry directly +* in order to try and determine the current time zone. +* +* Note that this can however still fail in some cases though if the client and server are using different languages, as the StandardName +* that is sent by client is localized in the client's language. However, we must compare this to the names that are on the server, which +* are localized in registry using the server's language. Despite that, this is the best we can do. +* +* Note: This fallback method won't work for the UWP version though, as we can't use the registry APIs in UWP. +* +* Once we have the current Windows time zone, then we can then map it to an ICU time zone ID (~ Olsen ID). */ U_CAPI const char* U_EXPORT2 uprv_detectWindowsTimeZone() { - // Obtain the DYNAMIC_TIME_ZONE_INFORMATION info to get the non-localized time zone name. + // We first try to obtain the time zone directly by using the TimeZoneKeyName field of the DYNAMIC_TIME_ZONE_INFORMATION struct. DYNAMIC_TIME_ZONE_INFORMATION dynamicTZI; uprv_memset(&dynamicTZI, 0, sizeof(dynamicTZI)); SYSTEMTIME systemTimeAllZero; @@ -86,22 +127,138 @@ uprv_detectWindowsTimeZone() // Note '-' before 'utcOffsetMin'. The timezone ID's sign convention // is that a timezone ahead of UTC is Etc/GMT-<offset> and a timezone // behind UTC is Etc/GMT+<offset>. - int ret = snprintf(gmtOffsetTz, UPRV_LENGTHOF(gmtOffsetTz), "Etc/GMT%+d", -utcOffsetMins / 60); + int ret = snprintf(gmtOffsetTz, UPRV_LENGTHOF(gmtOffsetTz), "Etc/GMT%+ld", -utcOffsetMins / 60); if (ret > 0 && ret < UPRV_LENGTHOF(gmtOffsetTz)) { return uprv_strdup(gmtOffsetTz); } } } - // If DST is NOT disabled, but we have an empty TimeZoneKeyName, then it is unclear - // what we should do as this should not happen. + // If DST is NOT disabled, but the TimeZoneKeyName field of the struct is NULL, then we may be dealing with a + // RDP/terminal services session where the 'Time Zone Redirection' feature is enabled. However, either the RDP + // client sent the server incomplete info (some 3rd party RDP clients only send the StandardName and DaylightName, + // but do not send the important TimeZoneKeyName), or if the RDP server has not appropriately populated the struct correctly. + // + // In this case we unfortunately have no choice but to fallback to using the pre-Vista method of determining the + // time zone, which requires examining the registry directly. + // + // Note that this can however still fail though if the client and server are using different languages, as the StandardName + // that is sent by client is *localized* in the client's language. However, we must compare this to the names that are + // on the server, which are *localized* in registry using the server's language. + // + // One other note is that this fallback method doesn't work for the UWP version, as we can't use the registry APIs. + + // windowsTimeZoneName will point at timezoneSubKeyName if we had to fallback to using the registry, and we found a match. + WCHAR timezoneSubKeyName[WINDOWS_MAX_REG_KEY_LENGTH]; + WCHAR *windowsTimeZoneName = dynamicTZI.TimeZoneKeyName; + if (dynamicTZI.TimeZoneKeyName[0] == 0) { + +// We can't use the registry APIs in the UWP version. +#if U_PLATFORM_HAS_WINUWP_API == 1 + (void)timezoneSubKeyName; // suppress unused variable warnings. return nullptr; +#else + // Open the path to the time zones in the Windows registry. + LONG ret; + HKEY hKeyAllTimeZones = nullptr; + ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, WINDOWS_TIMEZONES_REG_KEY_PATH, 0, KEY_READ, + reinterpret_cast<PHKEY>(&hKeyAllTimeZones)); + + if (ret != ERROR_SUCCESS) { + // If we can't open the key, then we can't do much, so fail. + return nullptr; + } + + // Read the number of subkeys under the time zone registry path. + DWORD numTimeZoneSubKeys; + ret = RegQueryInfoKeyW(hKeyAllTimeZones, nullptr, nullptr, nullptr, &numTimeZoneSubKeys, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); + + if (ret != ERROR_SUCCESS) { + RegCloseKey(hKeyAllTimeZones); + return nullptr; + } + + // Examine each of the subkeys to try and find a match for the localized standard name ("Std"). + // + // Note: The name of the time zone subkey itself is not localized, but the "Std" name is localized. This means + // that we could fail to find a match if the RDP client and RDP server are using different languages, but unfortunately + // there isn't much we can do about it. + HKEY hKeyTimeZoneSubKey = nullptr; + ULONG registryValueType; + WCHAR registryStandardName[WINDOWS_MAX_REG_KEY_LENGTH]; + + for (DWORD i = 0; i < numTimeZoneSubKeys; i++) { + // Note: RegEnumKeyExW wants the size of the buffer in characters. + DWORD size = UPRV_LENGTHOF(timezoneSubKeyName); + ret = RegEnumKeyExW(hKeyAllTimeZones, i, timezoneSubKeyName, &size, nullptr, nullptr, nullptr, nullptr); + + if (ret != ERROR_SUCCESS) { + RegCloseKey(hKeyAllTimeZones); + return nullptr; + } + + ret = RegOpenKeyExW(hKeyAllTimeZones, timezoneSubKeyName, 0, KEY_READ, + reinterpret_cast<PHKEY>(&hKeyTimeZoneSubKey)); + + if (ret != ERROR_SUCCESS) { + RegCloseKey(hKeyAllTimeZones); + return nullptr; + } + + // Note: RegQueryValueExW wants the size of the buffer in bytes. + size = sizeof(registryStandardName); + ret = RegQueryValueExW(hKeyTimeZoneSubKey, L"Std", nullptr, ®istryValueType, + reinterpret_cast<LPBYTE>(registryStandardName), &size); + + if (ret != ERROR_SUCCESS || registryValueType != REG_SZ) { + RegCloseKey(hKeyTimeZoneSubKey); + RegCloseKey(hKeyAllTimeZones); + return nullptr; + } + + // Note: wcscmp does an ordinal (byte) comparison. + if (wcscmp(reinterpret_cast<WCHAR *>(registryStandardName), dynamicTZI.StandardName) == 0) { + // Since we are comparing the *localized* time zone name, it's possible that some languages might use + // the same string for more than one time zone. Thus we need to examine the TZI data in the registry to + // compare the GMT offset (the bias), and the DST transition dates, to ensure it's the same time zone + // as the currently reported one. + REG_TZI_FORMAT registryTziValue; + uprv_memset(®istryTziValue, 0, sizeof(registryTziValue)); + + // Note: RegQueryValueExW wants the size of the buffer in bytes. + DWORD timezoneTziValueSize = sizeof(registryTziValue); + ret = RegQueryValueExW(hKeyTimeZoneSubKey, L"TZI", nullptr, ®istryValueType, + reinterpret_cast<LPBYTE>(®istryTziValue), &timezoneTziValueSize); + + if (ret == ERROR_SUCCESS) { + if ((dynamicTZI.Bias == registryTziValue.Bias) && + (memcmp((const void *)&dynamicTZI.StandardDate, (const void *)®istryTziValue.StandardDate, sizeof(SYSTEMTIME)) == 0) && + (memcmp((const void *)&dynamicTZI.DaylightDate, (const void *)®istryTziValue.DaylightDate, sizeof(SYSTEMTIME)) == 0)) + { + // We found a matching time zone. + windowsTimeZoneName = timezoneSubKeyName; + break; + } + } + } + RegCloseKey(hKeyTimeZoneSubKey); + hKeyTimeZoneSubKey = nullptr; + } + + if (hKeyTimeZoneSubKey != nullptr) { + RegCloseKey(hKeyTimeZoneSubKey); + } + if (hKeyAllTimeZones != nullptr) { + RegCloseKey(hKeyAllTimeZones); + } +#endif // U_PLATFORM_HAS_WINUWP_API } CharString winTZ; UErrorCode status = U_ZERO_ERROR; - winTZ.appendInvariantChars(UnicodeString(TRUE, dynamicTZI.TimeZoneKeyName, -1), status); + winTZ.appendInvariantChars(UnicodeString(TRUE, windowsTimeZoneName, -1), status); // Map Windows Timezone name (non-localized) to ICU timezone ID (~ Olson timezone id). StackUResourceBundle winTZBundle; @@ -123,18 +280,29 @@ uprv_detectWindowsTimeZone() int regionCodeLen = GetGeoInfoW(geoId, GEO_ISO2, regionCodeW, UPRV_LENGTHOF(regionCodeW), 0); const UChar *icuTZ16 = nullptr; - int32_t tzLen; + int32_t tzListLen = 0; if (regionCodeLen != 0) { for (int i = 0; i < UPRV_LENGTHOF(regionCodeW); i++) { regionCode[i] = static_cast<char>(regionCodeW[i]); } - icuTZ16 = ures_getStringByKey(winTZBundle.getAlias(), regionCode, &tzLen, &status); + icuTZ16 = ures_getStringByKey(winTZBundle.getAlias(), regionCode, &tzListLen, &status); } if (regionCodeLen == 0 || U_FAILURE(status)) { // fallback to default "001" (world) status = U_ZERO_ERROR; - icuTZ16 = ures_getStringByKey(winTZBundle.getAlias(), "001", &tzLen, &status); + icuTZ16 = ures_getStringByKey(winTZBundle.getAlias(), "001", &tzListLen, &status); + } + + // Note: We want the first entry in the string returned by ures_getStringByKey. + // However this string can be a space delimited list of timezones: + // Ex: "America/New_York America/Detroit America/Indiana/Petersburg ..." + // We need to stop at the first space, so we pass tzLen (instead of tzListLen) to appendInvariantChars below. + int32_t tzLen = 0; + if (tzListLen > 0) { + while (!(icuTZ16[tzLen] == u'\0' || icuTZ16[tzLen] == u' ')) { + tzLen++; + } } // Note: cloneData returns nullptr if the status is a failure, so this diff --git a/thirdparty/icu4c/icudt68l.dat b/thirdparty/icu4c/icudt68l.dat Binary files differindex 548c1a5a72..9ecea5d548 100644 --- a/thirdparty/icu4c/icudt68l.dat +++ b/thirdparty/icu4c/icudt68l.dat |