diff options
47 files changed, 710 insertions, 261 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 96e1da9dde..9de901754a 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -1105,8 +1105,8 @@ void Semaphore::wait() { semaphore.wait(); } -Error Semaphore::try_wait() { - return semaphore.try_wait() ? OK : ERR_BUSY; +bool Semaphore::try_wait() { + return semaphore.try_wait(); } void Semaphore::post() { @@ -1125,7 +1125,7 @@ void Mutex::lock() { mutex.lock(); } -Error Mutex::try_lock() { +bool Mutex::try_lock() { return mutex.try_lock(); } diff --git a/core/core_bind.h b/core/core_bind.h index c0c87fd009..8852463234 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -361,7 +361,7 @@ class Mutex : public RefCounted { public: void lock(); - Error try_lock(); + bool try_lock(); void unlock(); }; @@ -373,7 +373,7 @@ class Semaphore : public RefCounted { public: void wait(); - Error try_wait(); + bool try_wait(); void post(); }; diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp index 7be14b741d..e26ead6d8c 100644 --- a/core/extension/extension_api_dump.cpp +++ b/core/extension/extension_api_dump.cpp @@ -82,6 +82,11 @@ static String get_property_info_type_name(const PropertyInfo &p_info) { return get_builtin_or_variant_type_name(p_info.type); } +static String get_type_meta_name(const GodotTypeInfo::Metadata metadata) { + static const char *argmeta[11] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double" }; + return argmeta[metadata]; +} + Dictionary GDExtensionAPIDump::generate_extension_api() { Dictionary api_dump; @@ -840,6 +845,10 @@ Dictionary GDExtensionAPIDump::generate_extension_api() { d3["type"] = get_property_info_type_name(pinfo); + if (mi.get_argument_meta(i) > 0) { + d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)mi.get_argument_meta(i)); + } + if (i == -1) { d2["return_value"] = d3; } else { @@ -884,8 +893,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api() { d3["type"] = get_property_info_type_name(pinfo); if (method->get_argument_meta(i) > 0) { - static const char *argmeta[11] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double" }; - d3["meta"] = argmeta[method->get_argument_meta(i)]; + d3["meta"] = get_type_meta_name(method->get_argument_meta(i)); } if (i >= 0 && i >= (method->get_argument_count() - default_args.size())) { @@ -929,6 +937,9 @@ Dictionary GDExtensionAPIDump::generate_extension_api() { Dictionary d3; d3["name"] = F.arguments[i].name; d3["type"] = get_property_info_type_name(F.arguments[i]); + if (F.get_argument_meta(i) > 0) { + d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)F.get_argument_meta(i)); + } arguments.push_back(d3); } if (arguments.size()) { diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 646bdea758..f0f160940d 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -327,7 +327,7 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) { bool found_route = false; - Vector<Point *> open_list; + LocalVector<Point *> open_list; SortArray<Point *, SortPoints> sorter; begin_point->g_score = 0; @@ -335,19 +335,19 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) { open_list.push_back(begin_point); while (!open_list.is_empty()) { - Point *p = open_list[0]; // The currently processed point + Point *p = open_list[0]; // The currently processed point. if (p == end_point) { found_route = true; break; } - sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list + sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list. open_list.remove_at(open_list.size() - 1); - p->closed_pass = pass; // Mark the point as closed + p->closed_pass = pass; // Mark the point as closed. for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) { - Point *e = *(it.value); // The neighbor point + Point *e = *(it.value); // The neighbor point. if (!e->enabled || e->closed_pass == pass) { continue; @@ -370,9 +370,9 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) { e->f_score = e->g_score + _estimate_cost(e->id, end_point->id); if (new_point) { // The position of the new points is already known. - sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr()); } else { - sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr()); } } } diff --git a/core/math/a_star_grid_2d.cpp b/core/math/a_star_grid_2d.cpp index 677e609763..139dc3afb1 100644 --- a/core/math/a_star_grid_2d.cpp +++ b/core/math/a_star_grid_2d.cpp @@ -265,7 +265,7 @@ AStarGrid2D::Point *AStarGrid2D::_jump(Point *p_from, Point *p_to) { return nullptr; } -void AStarGrid2D::_get_nbors(Point *p_point, List<Point *> &r_nbors) { +void AStarGrid2D::_get_nbors(Point *p_point, LocalVector<Point *> &r_nbors) { bool ts0 = false, td0 = false, ts1 = false, td1 = false, ts2 = false, td2 = false, @@ -378,7 +378,7 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) { bool found_route = false; - Vector<Point *> open_list; + LocalVector<Point *> open_list; SortArray<Point *, SortPoints> sorter; p_begin_point->g_score = 0; @@ -394,14 +394,14 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) { break; } - sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list. + sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list. open_list.remove_at(open_list.size() - 1); p->closed_pass = pass; // Mark the point as closed. - List<Point *> nbors; + LocalVector<Point *> nbors; _get_nbors(p, nbors); - for (List<Point *>::Element *E = nbors.front(); E; E = E->next()) { - Point *e = E->get(); // The neighbor point. + + for (Point *e : nbors) { real_t weight_scale = 1.0; if (jumping_enabled) { @@ -433,9 +433,9 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) { e->f_score = e->g_score + _estimate_cost(e->id, p_end_point->id); if (new_point) { // The position of the new points is already known. - sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr()); } else { - sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr()); } } } diff --git a/core/math/a_star_grid_2d.h b/core/math/a_star_grid_2d.h index 6b9012a5e3..e4e62ec360 100644 --- a/core/math/a_star_grid_2d.h +++ b/core/math/a_star_grid_2d.h @@ -124,7 +124,7 @@ private: // Internal routines. return &points[p_y][p_x]; } - void _get_nbors(Point *p_point, List<Point *> &r_nbors); + void _get_nbors(Point *p_point, LocalVector<Point *> &r_nbors); Point *_jump(Point *p_from, Point *p_to); bool _solve(Point *p_begin_point, Point *p_end_point); diff --git a/core/math/bvh.h b/core/math/bvh.h index 357d483375..ea8289607e 100644 --- a/core/math/bvh.h +++ b/core/math/bvh.h @@ -780,7 +780,7 @@ private: if (p_thread_safe) { _mutex = p_mutex; - if (_mutex->try_lock() != OK) { + if (!_mutex->try_lock()) { WARN_PRINT("Info : multithread BVH access detected (benign)"); _mutex->lock(); } diff --git a/core/object/make_virtuals.py b/core/object/make_virtuals.py index 0ee95835a6..18f27ae4a4 100644 --- a/core/object/make_virtuals.py +++ b/core/object/make_virtuals.py @@ -72,6 +72,7 @@ def generate_version(argcount, const=False, returns=False): s = s.replace("$RVOID", "(void)r_ret;") # If required, may lead to uninitialized errors s = s.replace("$CALLPTRRETDEF", "PtrToArg<m_ret>::EncodeT ret;") method_info += "\tmethod_info.return_val = GetTypeInfo<m_ret>::get_class_info();\\\n" + method_info += "\tmethod_info.return_val_metadata = GetTypeInfo<m_ret>::METADATA;\\\n" else: s = s.replace("$RET", "") s = s.replace("$RVOID", "") @@ -113,6 +114,9 @@ def generate_version(argcount, const=False, returns=False): ) callptrargsptr += "&argval" + str(i + 1) method_info += "\tmethod_info.arguments.push_back(GetTypeInfo<m_type" + str(i + 1) + ">::get_class_info());\\\n" + method_info += ( + "\tmethod_info.arguments_metadata.push_back(GetTypeInfo<m_type" + str(i + 1) + ">::METADATA);\\\n" + ) if argcount: callsiargs += "};\\\n" diff --git a/core/object/object.cpp b/core/object/object.cpp index a8b9e00c96..57aa1339ec 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1549,7 +1549,9 @@ void Object::_bind_methods() { #define BIND_OBJ_CORE_METHOD(m_method) \ ::ClassDB::add_virtual_method(get_class_static(), m_method, true, Vector<String>(), true); - BIND_OBJ_CORE_METHOD(MethodInfo("_notification", PropertyInfo(Variant::INT, "what"))); + MethodInfo notification_mi("_notification", PropertyInfo(Variant::INT, "what")); + notification_mi.arguments_metadata.push_back(GodotTypeInfo::Metadata::METADATA_INT_IS_INT32); + BIND_OBJ_CORE_METHOD(notification_mi); BIND_OBJ_CORE_METHOD(MethodInfo(Variant::BOOL, "_set", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value"))); #ifdef TOOLS_ENABLED MethodInfo miget("_get", PropertyInfo(Variant::STRING_NAME, "property")); diff --git a/core/object/object.h b/core/object/object.h index ec77da4ee1..5ec69a371b 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -223,6 +223,16 @@ struct MethodInfo { int id = 0; List<PropertyInfo> arguments; Vector<Variant> default_arguments; + int return_val_metadata = 0; + Vector<int> arguments_metadata; + + int get_argument_meta(int p_arg) const { + ERR_FAIL_COND_V(p_arg < -1 || p_arg > arguments.size(), 0); + if (p_arg == -1) { + return return_val_metadata; + } + return arguments_metadata.size() > p_arg ? arguments_metadata[p_arg] : 0; + } inline bool operator==(const MethodInfo &p_method) const { return id == p_method.id; } inline bool operator<(const MethodInfo &p_method) const { return id == p_method.id ? (name < p_method.name) : (id < p_method.id); } diff --git a/core/os/mutex.h b/core/os/mutex.h index c91917a9a1..ceedcb235a 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -31,7 +31,6 @@ #ifndef MUTEX_H #define MUTEX_H -#include "core/error/error_list.h" #include "core/typedefs.h" #include <mutex> @@ -49,8 +48,8 @@ public: mutex.unlock(); } - _ALWAYS_INLINE_ Error try_lock() const { - return mutex.try_lock() ? OK : ERR_BUSY; + _ALWAYS_INLINE_ bool try_lock() const { + return mutex.try_lock(); } }; diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h index e290b7c00b..a232fcb1ce 100644 --- a/core/os/rw_lock.h +++ b/core/os/rw_lock.h @@ -31,7 +31,7 @@ #ifndef RW_LOCK_H #define RW_LOCK_H -#include "core/error/error_list.h" +#include "core/typedefs.h" #include <shared_mutex> @@ -39,34 +39,34 @@ class RWLock { mutable std::shared_timed_mutex mutex; public: - // Lock the rwlock, block if locked by someone else - void read_lock() const { + // Lock the RWLock, block if locked by someone else. + _ALWAYS_INLINE_ void read_lock() const { mutex.lock_shared(); } - // Unlock the rwlock, let other threads continue - void read_unlock() const { + // Unlock the RWLock, let other threads continue. + _ALWAYS_INLINE_ void read_unlock() const { mutex.unlock_shared(); } - // Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock. - Error read_try_lock() const { - return mutex.try_lock_shared() ? OK : ERR_BUSY; + // Attempt to lock the RWLock for reading. True on success, false means it can't lock. + _ALWAYS_INLINE_ bool read_try_lock() const { + return mutex.try_lock_shared(); } - // Lock the rwlock, block if locked by someone else - void write_lock() { + // Lock the RWLock, block if locked by someone else. + _ALWAYS_INLINE_ void write_lock() { mutex.lock(); } - // Unlock the rwlock, let other thwrites continue - void write_unlock() { + // Unlock the RWLock, let other threads continue. + _ALWAYS_INLINE_ void write_unlock() { mutex.unlock(); } - // Attempt to lock the rwlock, OK on success, ERR_BUSY means it can't lock. - Error write_try_lock() { - return mutex.try_lock() ? OK : ERR_BUSY; + // Attempt to lock the RWLock for writing. True on success, false means it can't lock. + _ALWAYS_INLINE_ bool write_try_lock() { + return mutex.try_lock(); } }; @@ -74,11 +74,11 @@ class RWLockRead { const RWLock &lock; public: - RWLockRead(const RWLock &p_lock) : + _ALWAYS_INLINE_ RWLockRead(const RWLock &p_lock) : lock(p_lock) { lock.read_lock(); } - ~RWLockRead() { + _ALWAYS_INLINE_ ~RWLockRead() { lock.read_unlock(); } }; @@ -87,11 +87,11 @@ class RWLockWrite { RWLock &lock; public: - RWLockWrite(RWLock &p_lock) : + _ALWAYS_INLINE_ RWLockWrite(RWLock &p_lock) : lock(p_lock) { lock.write_lock(); } - ~RWLockWrite() { + _ALWAYS_INLINE_ ~RWLockWrite() { lock.write_unlock(); } }; diff --git a/core/os/semaphore.h b/core/os/semaphore.h index 6a290f21c6..a992a4587d 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -39,32 +39,33 @@ class Semaphore { private: - mutable std::mutex mutex_; - mutable std::condition_variable condition_; - mutable unsigned long count_ = 0; // Initialized as locked. + mutable std::mutex mutex; + mutable std::condition_variable condition; + mutable uint32_t count = 0; // Initialized as locked. public: _ALWAYS_INLINE_ void post() const { - std::lock_guard<decltype(mutex_)> lock(mutex_); - ++count_; - condition_.notify_one(); + std::lock_guard lock(mutex); + count++; + condition.notify_one(); } _ALWAYS_INLINE_ void wait() const { - std::unique_lock<decltype(mutex_)> lock(mutex_); - while (!count_) { // Handle spurious wake-ups. - condition_.wait(lock); + std::unique_lock lock(mutex); + while (!count) { // Handle spurious wake-ups. + condition.wait(lock); } - --count_; + count--; } _ALWAYS_INLINE_ bool try_wait() const { - std::lock_guard<decltype(mutex_)> lock(mutex_); - if (count_) { - --count_; + std::lock_guard lock(mutex); + if (count) { + count--; return true; + } else { + return false; } - return false; } }; diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml index b0657cab90..6f4a7fc13d 100644 --- a/doc/classes/DisplayServer.xml +++ b/doc/classes/DisplayServer.xml @@ -190,6 +190,7 @@ <description> Adds a new checkable item with text [param label] to the global menu with ID [param menu_root]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. + [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS. [b]Supported system menu IDs:[/b] [codeblock] @@ -211,6 +212,7 @@ <description> Adds a new checkable item with text [param label] and icon [param icon] to the global menu with ID [param menu_root]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. + [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS. [b]Supported system menu IDs:[/b] [codeblock] @@ -232,6 +234,7 @@ <description> Adds a new item with text [param label] and icon [param icon] to the global menu with ID [param menu_root]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. + [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS. [b]Supported system menu IDs:[/b] [codeblock] @@ -254,6 +257,7 @@ Adds a new radio-checkable item with text [param label] and icon [param icon] to the global menu with ID [param menu_root]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. [b]Note:[/b] Radio-checkable items just display a checkmark, but don't have any built-in checking behavior and must be checked/unchecked manually. See [method global_menu_set_item_checked] for more info on how to control it. + [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS. [b]Supported system menu IDs:[/b] [codeblock] @@ -274,6 +278,7 @@ <description> Adds a new item with text [param label] to the global menu with ID [param menu_root]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. + [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS. [b]Supported system menu IDs:[/b] [codeblock] @@ -285,7 +290,7 @@ <method name="global_menu_add_multistate_item"> <return type="int" /> <param index="0" name="menu_root" type="String" /> - <param index="1" name="labe" type="String" /> + <param index="1" name="label" type="String" /> <param index="2" name="max_states" type="int" /> <param index="3" name="default_state" type="int" /> <param index="4" name="callback" type="Callable" /> @@ -294,10 +299,11 @@ <param index="7" name="accelerator" type="int" enum="Key" default="0" /> <param index="8" name="index" type="int" default="-1" /> <description> - Adds a new item with text [param labe] to the global menu with ID [param menu_root]. + Adds a new item with text [param label] to the global menu with ID [param menu_root]. Contrarily to normal binary items, multistate items can have more than two states, as defined by [param max_states]. Each press or activate of the item will increase the state by one. The default value is defined by [param default_state]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. [b]Note:[/b] By default, there's no indication of the current item state, it should be changed manually. + [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS. [b]Supported system menu IDs:[/b] [codeblock] @@ -319,6 +325,7 @@ Adds a new radio-checkable item with text [param label] to the global menu with ID [param menu_root]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. [b]Note:[/b] Radio-checkable items just display a checkmark, but don't have any built-in checking behavior and must be checked/unchecked manually. See [method global_menu_set_item_checked] for more info on how to control it. + [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS. [b]Supported system menu IDs:[/b] [codeblock] @@ -562,6 +569,7 @@ <param index="2" name="callback" type="Callable" /> <description> Sets the callback of the item at index [param idx]. Callback is emitted when an item is pressed. + [b]Note:[/b] The [param callback] Callable needs to accept exactly one Variant parameter, the parameter passed to the Callable will be the value passed to the tag parameter when the menu item was created. [b]Note:[/b] This method is implemented on macOS. </description> </method> @@ -623,6 +631,7 @@ <param index="2" name="key_callback" type="Callable" /> <description> Sets the callback of the item at index [param idx]. Callback is emitted when its accelerator is activated. + [b]Note:[/b] The [param key_callback] Callable needs to accept exactly one Variant parameter, the parameter passed to the Callable will be the value passed to the tag parameter when the menu item was created. [b]Note:[/b] This method is implemented on macOS. </description> </method> diff --git a/doc/classes/Mutex.xml b/doc/classes/Mutex.xml index 74f29bdc48..78694ce813 100644 --- a/doc/classes/Mutex.xml +++ b/doc/classes/Mutex.xml @@ -18,9 +18,9 @@ </description> </method> <method name="try_lock"> - <return type="int" enum="Error" /> + <return type="bool" /> <description> - Tries locking this [Mutex], but does not block. Returns [constant OK] on success, [constant ERR_BUSY] otherwise. + Tries locking this [Mutex], but does not block. Returns [code]true[/code] on success, [code]false[/code] otherwise. [b]Note:[/b] This function returns [constant OK] if the thread already has ownership of the mutex. </description> </method> diff --git a/doc/classes/Semaphore.xml b/doc/classes/Semaphore.xml index 6b2007363e..d1d126c5cb 100644 --- a/doc/classes/Semaphore.xml +++ b/doc/classes/Semaphore.xml @@ -17,9 +17,9 @@ </description> </method> <method name="try_wait"> - <return type="int" enum="Error" /> + <return type="bool" /> <description> - Like [method wait], but won't block, so if the value is zero, fails immediately and returns [constant ERR_BUSY]. If non-zero, it returns [constant OK] to report success. + Like [method wait], but won't block, so if the value is zero, fails immediately and returns [code]false[/code]. If non-zero, it returns [code]true[/code] to report success. </description> </method> <method name="wait"> diff --git a/doc/classes/TileData.xml b/doc/classes/TileData.xml index f815b8d0c3..bedc52abd1 100644 --- a/doc/classes/TileData.xml +++ b/doc/classes/TileData.xml @@ -218,7 +218,7 @@ <member name="terrain_set" type="int" setter="set_terrain_set" getter="get_terrain_set" default="-1"> ID of the terrain set that the tile uses. </member> - <member name="texture_offset" type="Vector2i" setter="set_texture_offset" getter="get_texture_offset" default="Vector2i(0, 0)"> + <member name="texture_origin" type="Vector2i" setter="set_texture_origin" getter="get_texture_origin" default="Vector2i(0, 0)"> Offsets the position of where the tile is drawn. </member> <member name="transpose" type="bool" setter="set_transpose" getter="get_transpose" default="false"> diff --git a/doc/classes/TileMap.xml b/doc/classes/TileMap.xml index 2fd42666b4..c387bd435b 100644 --- a/doc/classes/TileMap.xml +++ b/doc/classes/TileMap.xml @@ -251,7 +251,7 @@ <param index="0" name="map_position" type="Vector2i" /> <description> Returns the centered position of a cell in the TileMap's local coordinate space. To convert the returned value into global coordinates, use [method Node2D.to_global]. See also [method local_to_map]. - [b]Note:[/b] This may not correspond to the visual position of the tile, i.e. it ignores the [member TileData.texture_offset] property of individual tiles. + [b]Note:[/b] This may not correspond to the visual position of the tile, i.e. it ignores the [member TileData.texture_origin] property of individual tiles. </description> </method> <method name="move_layer"> diff --git a/doc/classes/TileSet.xml b/doc/classes/TileSet.xml index a812b52307..a39a43be4c 100644 --- a/doc/classes/TileSet.xml +++ b/doc/classes/TileSet.xml @@ -143,6 +143,14 @@ Returns the custom data layers count. </description> </method> + <method name="get_navigation_layer_layer_value" qualifiers="const"> + <return type="bool" /> + <param index="0" name="layer_index" type="int" /> + <param index="1" name="layer_number" type="int" /> + <description> + Returns whether or not the specified navigation layer of the TileSet navigation data layer identified by the given [param layer_index] is enabled, given a navigation_layers [param layer_number] between 1 and 32. + </description> + </method> <method name="get_navigation_layer_layers" qualifiers="const"> <return type="int" /> <param index="0" name="layer_index" type="int" /> @@ -500,6 +508,15 @@ Sets the type of the custom data layer identified by the given index. </description> </method> + <method name="set_navigation_layer_layer_value"> + <return type="void" /> + <param index="0" name="layer_index" type="int" /> + <param index="1" name="layer_number" type="int" /> + <param index="2" name="value" type="bool" /> + <description> + Based on [param value], enables or disables the specified navigation layer of the TileSet navigation data layer identified by the given [param layer_index], given a navigation_layers [param layer_number] between 1 and 32. + </description> + </method> <method name="set_navigation_layer_layers"> <return type="void" /> <param index="0" name="layer_index" type="int" /> diff --git a/drivers/coreaudio/audio_driver_coreaudio.cpp b/drivers/coreaudio/audio_driver_coreaudio.cpp index 219529d2f6..e9eb11e2e3 100644 --- a/drivers/coreaudio/audio_driver_coreaudio.cpp +++ b/drivers/coreaudio/audio_driver_coreaudio.cpp @@ -283,7 +283,7 @@ void AudioDriverCoreAudio::unlock() { } bool AudioDriverCoreAudio::try_lock() { - return mutex.try_lock() == OK; + return mutex.try_lock(); } void AudioDriverCoreAudio::finish() { diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 0814d5b5ca..aee907854c 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -122,7 +122,7 @@ bool CreateDialog::_should_hide_type(const String &p_type) const { return true; } - if (base_type == "Node" && p_type.begins_with("Editor")) { + if (is_base_type_node && p_type.begins_with("Editor")) { return true; // Do not show editor nodes. } @@ -508,6 +508,11 @@ String CreateDialog::get_selected_type() { return selected->get_text(0); } +void CreateDialog::set_base_type(const String &p_base) { + base_type = p_base; + is_base_type_node = ClassDB::is_parent_class(p_base, "Node"); +} + Variant CreateDialog::instantiate_selected() { TreeItem *selected = search_options->get_selected(); diff --git a/editor/create_dialog.h b/editor/create_dialog.h index ad63346a02..37579812cf 100644 --- a/editor/create_dialog.h +++ b/editor/create_dialog.h @@ -51,6 +51,7 @@ class CreateDialog : public ConfirmationDialog { Tree *search_options = nullptr; String base_type; + bool is_base_type_node = false; String icon_fallback; String preferred_search_result_type; @@ -113,7 +114,7 @@ public: Variant instantiate_selected(); String get_selected_type(); - void set_base_type(const String &p_base) { base_type = p_base; } + void set_base_type(const String &p_base); String get_base_type() const { return base_type; } void select_base(); diff --git a/editor/input_event_configuration_dialog.cpp b/editor/input_event_configuration_dialog.cpp index 48e3759e57..37c2fd5f1e 100644 --- a/editor/input_event_configuration_dialog.cpp +++ b/editor/input_event_configuration_dialog.cpp @@ -685,9 +685,9 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() { // Key Mode Selection key_mode = memnew(OptionButton); - key_mode->add_item("Keycode (Latin equvialent)", KEYMODE_KEYCODE); - key_mode->add_item("Physical Keycode (poistion of US QWERTY keyboard)", KEYMODE_PHY_KEYCODE); - key_mode->add_item("Unicode (case-insencetive)", KEYMODE_UNICODE); + key_mode->add_item(TTR("Keycode (Latin Equivalent)"), KEYMODE_KEYCODE); + key_mode->add_item(TTR("Physical Keycode (Position on US QWERTY Keyboard)"), KEYMODE_PHY_KEYCODE); + key_mode->add_item(TTR("Key Label (Unicode, Case-Insensitive)"), KEYMODE_UNICODE); key_mode->connect("item_selected", callable_mp(this, &InputEventConfigurationDialog::_key_mode_selected)); key_mode->hide(); additional_options_container->add_child(key_mode); diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp index e430848875..fd651dd507 100644 --- a/editor/plugins/tiles/tile_atlas_view.cpp +++ b/editor/plugins/tiles/tile_atlas_view.cpp @@ -247,7 +247,7 @@ void TileAtlasView::_draw_base_tiles() { for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(atlas_coords); frame++) { // Update the y to max value. Rect2i base_frame_rect = tile_set_atlas_source->get_tile_texture_region(atlas_coords, frame); - Vector2i offset_pos = base_frame_rect.get_center() + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, 0); + Vector2i offset_pos = base_frame_rect.get_center() + tile_set_atlas_source->get_tile_data(atlas_coords, 0)->get_texture_origin(); // Draw the tile. TileMap::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0, frame); @@ -322,18 +322,19 @@ void TileAtlasView::_draw_base_tiles_shape_grid() { Vector2i tile_shape_size = tile_set->get_tile_size(); for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) { Vector2i tile_id = tile_set_atlas_source->get_tile_id(i); - Vector2 in_tile_base_offset = tile_set_atlas_source->get_tile_effective_texture_offset(tile_id, 0); - - for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(tile_id); frame++) { - Color color = grid_color; - if (frame > 0) { - color.a *= 0.3; + Vector2 in_tile_base_offset = tile_set_atlas_source->get_tile_data(tile_id, 0)->get_texture_origin(); + if (tile_set_atlas_source->is_position_in_tile_texture_region(tile_id, 0, -tile_shape_size / 2) && tile_set_atlas_source->is_position_in_tile_texture_region(tile_id, 0, tile_shape_size / 2 - Vector2(1, 1))) { + for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(tile_id); frame++) { + Color color = grid_color; + if (frame > 0) { + color.a *= 0.3; + } + Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(tile_id, frame); + Transform2D tile_xform; + tile_xform.set_origin(texture_region.get_center() + in_tile_base_offset); + tile_xform.set_scale(tile_shape_size); + tile_set->draw_tile_shape(base_tiles_shape_grid, tile_xform, color); } - Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(tile_id); - Transform2D tile_xform; - tile_xform.set_origin(texture_region.get_center() + in_tile_base_offset); - tile_xform.set_scale(tile_shape_size); - tile_set->draw_tile_shape(base_tiles_shape_grid, tile_xform, color); } } } @@ -372,10 +373,10 @@ void TileAtlasView::_draw_alternatives() { // Update the y to max value. Vector2i offset_pos; if (transposed) { - offset_pos = (current_pos + Vector2(texture_region_size.y, texture_region_size.x) / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, alternative_id)); + offset_pos = (current_pos + Vector2(texture_region_size.y, texture_region_size.x) / 2 + tile_data->get_texture_origin()); y_increment = MAX(y_increment, texture_region_size.x); } else { - offset_pos = (current_pos + texture_region_size / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, alternative_id)); + offset_pos = (current_pos + texture_region_size / 2 + tile_data->get_texture_origin()); y_increment = MAX(y_increment, texture_region_size.y); } diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index 1a4223e9e6..3dd0c84ee7 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -1122,14 +1122,15 @@ void TileDataDefaultEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2 return; } + Vector2 texture_origin = tile_data->get_texture_origin(); if (value.get_type() == Variant::BOOL) { Ref<Texture2D> texture = (bool)value ? tile_bool_checked : tile_bool_unchecked; int size = MIN(tile_set->get_tile_size().x, tile_set->get_tile_size().y) / 3; - Rect2 rect = p_transform.xform(Rect2(Vector2(-size / 2, -size / 2), Vector2(size, size))); + Rect2 rect = p_transform.xform(Rect2(Vector2(-size / 2, -size / 2) - texture_origin, Vector2(size, size))); p_canvas_item->draw_texture_rect(texture, rect); } else if (value.get_type() == Variant::COLOR) { int size = MIN(tile_set->get_tile_size().x, tile_set->get_tile_size().y) / 3; - Rect2 rect = p_transform.xform(Rect2(Vector2(-size / 2, -size / 2), Vector2(size, size))); + Rect2 rect = p_transform.xform(Rect2(Vector2(-size / 2, -size / 2) - texture_origin, Vector2(size, size))); p_canvas_item->draw_rect(rect, value); } else { Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font(SNAME("bold"), SNAME("EditorFonts")); @@ -1166,8 +1167,8 @@ void TileDataDefaultEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2 } Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); - p_canvas_item->draw_string_outline(font, p_transform.get_origin() + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); - p_canvas_item->draw_string(font, p_transform.get_origin() + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color); + p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); + p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color); } } @@ -1241,20 +1242,38 @@ TileDataDefaultEditor::~TileDataDefaultEditor() { memdelete(dummy_object); } -void TileDataTextureOffsetEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { +void TileDataTextureOriginEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { TileData *tile_data = _get_tile_data(p_cell); ERR_FAIL_COND(!tile_data); Vector2i tile_set_tile_size = tile_set->get_tile_size(); - Color color = Color(1.0, 0.0, 0.0); + Color color = Color(1.0, 1.0, 1.0); if (p_selected) { Color grid_color = EDITOR_GET("editors/tiles_editor/grid_color"); Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); color = selection_color; } - Transform2D tile_xform; - tile_xform.set_scale(tile_set_tile_size); - tile_set->draw_tile_shape(p_canvas_item, p_transform * tile_xform, color); + + TileSetSource *source = *(tile_set->get_source(p_cell.source_id)); + TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source); + if (atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, -tile_set_tile_size / 2) && atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, tile_set_tile_size / 2 - Vector2(1, 1))) { + Transform2D tile_xform; + tile_xform.set_scale(tile_set_tile_size); + tile_set->draw_tile_shape(p_canvas_item, p_transform * tile_xform, color); + } + + if (atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, Vector2())) { + Ref<Texture2D> position_icon = TileSetEditor::get_singleton()->get_theme_icon(SNAME("EditorPosition"), SNAME("EditorIcons")); + p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2()) - (position_icon->get_size() / 2), color); + } else { + Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font(SNAME("bold"), SNAME("EditorFonts")); + int font_size = TileSetEditor::get_singleton()->get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts")); + Vector2 texture_origin = tile_data->get_texture_origin(); + String text = vformat("%s", texture_origin); + Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); + p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); + p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color); + } } void TileDataPositionEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { @@ -1288,8 +1307,21 @@ void TileDataYSortEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); color = selection_color; } - Ref<Texture2D> position_icon = TileSetEditor::get_singleton()->get_theme_icon(SNAME("EditorPosition"), SNAME("EditorIcons")); - p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(0, tile_data->get_y_sort_origin())) - position_icon->get_size() / 2, color); + Vector2 texture_origin = tile_data->get_texture_origin(); + TileSetSource *source = *(tile_set->get_source(p_cell.source_id)); + TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source); + if (atlas_source->is_position_in_tile_texture_region(p_cell.get_atlas_coords(), p_cell.alternative_tile, Vector2(0, tile_data->get_y_sort_origin()))) { + Ref<Texture2D> position_icon = TileSetEditor::get_singleton()->get_theme_icon(SNAME("EditorPosition"), SNAME("EditorIcons")); + p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(0, tile_data->get_y_sort_origin())) - position_icon->get_size() / 2, color); + } else { + Ref<Font> font = TileSetEditor::get_singleton()->get_theme_font(SNAME("bold"), SNAME("EditorFonts")); + int font_size = TileSetEditor::get_singleton()->get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts")); + String text = vformat("%s", tile_data->get_y_sort_origin()); + + Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); + p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); + p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color); + } } void TileDataOcclusionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected) { @@ -1333,7 +1365,7 @@ void TileDataOcclusionShapeEditor::_set_painted_value(TileSetAtlasSource *p_tile if (occluder_polygon.is_valid()) { polygon_editor->add_polygon(occluder_polygon->get_polygon()); } - polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), tile_data->get_texture_origin(), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); } void TileDataOcclusionShapeEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) { @@ -1342,7 +1374,7 @@ void TileDataOcclusionShapeEditor::_set_value(TileSetAtlasSource *p_tile_set_atl Ref<OccluderPolygon2D> occluder_polygon = p_value; tile_data->set_occluder(occlusion_layer, occluder_polygon); - polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), tile_data->get_texture_origin(), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); } Variant TileDataOcclusionShapeEditor::_get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { @@ -1489,7 +1521,7 @@ void TileDataCollisionEditor::_set_painted_value(TileSetAtlasSource *p_tile_set_ E.value->update_property(); } - polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), tile_data->get_texture_origin(), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); } void TileDataCollisionEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) { @@ -1508,7 +1540,7 @@ void TileDataCollisionEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_so tile_data->set_collision_polygon_one_way_margin(physics_layer, i, polygon_dict["one_way_margin"]); } - polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), tile_data->get_texture_origin(), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); } Variant TileDataCollisionEditor::_get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { @@ -1741,7 +1773,7 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas TileData *tile_data = p_tile_set_atlas_source->get_tile_data(hovered_coords, 0); int terrain_set = tile_data->get_terrain_set(); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(hovered_coords); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(hovered_coords, 0); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); if (terrain_set >= 0 && terrain_set == int(dummy_object->get("terrain_set"))) { // Draw hovered bit. @@ -1792,7 +1824,7 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas // Text p_canvas_item->draw_set_transform_matrix(Transform2D()); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); Color color = Color(1, 1, 1); String text; @@ -1885,7 +1917,7 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas Vector2i coords = E.get_atlas_coords(); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_data(coords, 0)->get_texture_origin(); Vector<Vector2> polygon = tile_set->get_terrain_polygon(terrain_set); for (int j = 0; j < polygon.size(); j++) { @@ -1930,7 +1962,7 @@ void TileDataTerrainsEditor::forward_draw_over_alternatives(TileAtlasView *p_til TileData *tile_data = p_tile_set_atlas_source->get_tile_data(hovered_coords, hovered_alternative); int terrain_set = tile_data->get_terrain_set(); Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(hovered_coords, hovered_alternative); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(hovered_coords, hovered_alternative); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); if (terrain_set == int(dummy_object->get("terrain_set"))) { // Draw hovered bit. @@ -1984,7 +2016,7 @@ void TileDataTerrainsEditor::forward_draw_over_alternatives(TileAtlasView *p_til // Text p_canvas_item->draw_set_transform_matrix(Transform2D()); Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); Color color = Color(1, 1, 1); String text; @@ -2069,7 +2101,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t // Set the terrains bits. Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); Vector<Vector2> polygon = tile_set->get_terrain_polygon(tile_data->get_terrain_set()); if (Geometry2D::is_segment_intersecting_polygon(mm->get_position() - position, drag_last_pos - position, polygon)) { @@ -2103,7 +2135,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t TileData *tile_data = p_tile_set_atlas_source->get_tile_data(coords, 0); int terrain_set = tile_data->get_terrain_set(); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); dummy_object->set("terrain_set", terrain_set); dummy_object->set("terrain", -1); @@ -2218,7 +2250,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t // Set the terrain bit. Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); Vector<Vector2> polygon = tile_set->get_terrain_polygon(terrain_set); if (Geometry2D::is_point_in_polygon(mb->get_position() - position, polygon)) { @@ -2365,7 +2397,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t TileData *tile_data = p_tile_set_atlas_source->get_tile_data(coords, 0); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); Vector<Vector2> polygon = tile_set->get_terrain_polygon(terrain_set); for (int j = 0; j < polygon.size(); j++) { @@ -2465,7 +2497,7 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(TileAtlasVi // Set the terrains bits. Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); Vector<Vector2> polygon = tile_set->get_terrain_polygon(tile_data->get_terrain_set()); if (Geometry2D::is_segment_intersecting_polygon(mm->get_position() - position, drag_last_pos - position, polygon)) { @@ -2501,7 +2533,7 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(TileAtlasVi TileData *tile_data = p_tile_set_atlas_source->get_tile_data(coords, alternative_tile); int terrain_set = tile_data->get_terrain_set(); Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); dummy_object->set("terrain_set", terrain_set); dummy_object->set("terrain", -1); @@ -2591,7 +2623,7 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(TileAtlasVi // Set the terrain bit. Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); - Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); + Vector2i position = texture_region.get_center() + tile_data->get_texture_origin(); Vector<Vector2> polygon = tile_set->get_terrain_polygon(terrain_set); if (Geometry2D::is_point_in_polygon(mb->get_position() - position, polygon)) { @@ -2741,7 +2773,7 @@ void TileDataNavigationEditor::_set_painted_value(TileSetAtlasSource *p_tile_set polygon_editor->add_polygon(nav_polygon->get_outline(i)); } } - polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), tile_data->get_texture_origin(), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); } void TileDataNavigationEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile, Variant p_value) { @@ -2750,7 +2782,7 @@ void TileDataNavigationEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_s Ref<NavigationPolygon> nav_polygon = p_value; tile_data->set_navigation_polygon(navigation_layer, nav_polygon); - polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); + polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), tile_data->get_texture_origin(), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); } Variant TileDataNavigationEditor::_get_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) { diff --git a/editor/plugins/tiles/tile_data_editors.h b/editor/plugins/tiles/tile_data_editors.h index 02d4584428..1ebf30aecd 100644 --- a/editor/plugins/tiles/tile_data_editors.h +++ b/editor/plugins/tiles/tile_data_editors.h @@ -242,8 +242,8 @@ public: ~TileDataDefaultEditor(); }; -class TileDataTextureOffsetEditor : public TileDataDefaultEditor { - GDCLASS(TileDataTextureOffsetEditor, TileDataDefaultEditor); +class TileDataTextureOriginEditor : public TileDataDefaultEditor { + GDCLASS(TileDataTextureOriginEditor, TileDataDefaultEditor); public: virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index d79bd8ced3..f0a02a3768 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -897,7 +897,7 @@ void TileMapEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p_over // Compute the offset Rect2i source_rect = atlas_source->get_tile_texture_region(E.value.get_atlas_coords()); - Vector2i tile_offset = atlas_source->get_tile_effective_texture_offset(E.value.get_atlas_coords(), E.value.alternative_tile); + Vector2i tile_offset = tile_data->get_texture_origin(); // Compute the destination rectangle in the CanvasItem. Rect2 dest_rect; diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index a12a647e99..840a3911af 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -640,14 +640,14 @@ void TileSetAtlasSourceEditor::_update_tile_data_editors() { // --- Rendering --- ADD_TILE_DATA_EDITOR_GROUP("Rendering"); - ADD_TILE_DATA_EDITOR(group, "Texture Offset", "texture_offset"); - if (!tile_data_editors.has("texture_offset")) { - TileDataTextureOffsetEditor *tile_data_texture_offset_editor = memnew(TileDataTextureOffsetEditor); - tile_data_texture_offset_editor->hide(); - tile_data_texture_offset_editor->setup_property_editor(Variant::VECTOR2, "texture_offset"); - tile_data_texture_offset_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::queue_redraw)); - tile_data_texture_offset_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::queue_redraw)); - tile_data_editors["texture_offset"] = tile_data_texture_offset_editor; + ADD_TILE_DATA_EDITOR(group, "Texture Origin", "texture_origin"); + if (!tile_data_editors.has("texture_origin")) { + TileDataTextureOriginEditor *tile_data_texture_origin_editor = memnew(TileDataTextureOriginEditor); + tile_data_texture_origin_editor->hide(); + tile_data_texture_origin_editor->setup_property_editor(Variant::VECTOR2, "texture_origin"); + tile_data_texture_origin_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::queue_redraw)); + tile_data_texture_origin_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::queue_redraw)); + tile_data_editors["texture_origin"] = tile_data_texture_origin_editor; } ADD_TILE_DATA_EDITOR(group, "Modulate", "modulate"); @@ -1864,7 +1864,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_unscaled_draw() { for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) { Vector2i coords = tile_set_atlas_source->get_tile_id(i); Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(coords); - Vector2i position = texture_region.get_center() + tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); + Vector2i position = texture_region.get_center() + tile_set_atlas_source->get_tile_data(coords, 0)->get_texture_origin(); Transform2D xform = tile_atlas_control->get_parent_control()->get_transform(); xform.translate_local(position); @@ -1887,7 +1887,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_unscaled_draw() { continue; } Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(E.tile); - Vector2i position = texture_region.get_center() + tile_set_atlas_source->get_tile_effective_texture_offset(E.tile, 0); + Vector2i position = texture_region.get_center() + tile_set_atlas_source->get_tile_data(E.tile, 0)->get_texture_origin(); Transform2D xform = tile_atlas_control->get_parent_control()->get_transform(); xform.translate_local(position); @@ -2039,7 +2039,7 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw() { continue; } Rect2i rect = tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); - Vector2 position = rect.get_center() + tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); + Vector2 position = rect.get_center() + tile_set_atlas_source->get_tile_data(coords, alternative_tile)->get_texture_origin(); Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform(); xform.translate_local(position); @@ -2063,7 +2063,7 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw() { continue; } Rect2i rect = tile_atlas_view->get_alternative_tile_rect(E.tile, E.alternative); - Vector2 position = rect.get_center() + tile_set_atlas_source->get_tile_effective_texture_offset(E.tile, E.alternative); + Vector2 position = rect.get_center() + tile_set_atlas_source->get_tile_data(E.tile, E.alternative)->get_texture_origin(); Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform(); xform.translate_local(position); @@ -2704,7 +2704,7 @@ void EditorPropertyTilePolygon::update_property() { Vector2i coords = atlas_tile_proxy_object->get_edited_tiles().front()->get().tile; int alternative = atlas_tile_proxy_object->get_edited_tiles().front()->get().alternative; TileData *tile_data = tile_set_atlas_source->get_tile_data(coords, alternative); - generic_tile_polygon_editor->set_background(tile_set_atlas_source->get_texture(), tile_set_atlas_source->get_tile_texture_region(coords), tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); + generic_tile_polygon_editor->set_background(tile_set_atlas_source->get_texture(), tile_set_atlas_source->get_tile_texture_region(coords), tile_data->get_texture_origin(), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate()); // Reset the polygons. generic_tile_polygon_editor->clear_polygons(); diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp index 77dd0f7793..fad36660d9 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.cpp +++ b/editor/plugins/tiles/tiles_editor_plugin.cpp @@ -106,7 +106,7 @@ void TilesEditorPlugin::_thread() { Vector2i coords = tile_map->get_cell_atlas_coords(0, cell); int alternative = tile_map->get_cell_alternative_tile(0, cell); - Vector2 center = world_pos - atlas_source->get_tile_effective_texture_offset(coords, alternative); + Vector2 center = world_pos - atlas_source->get_tile_data(coords, alternative)->get_texture_origin(); encompassing_rect.expand_to(center - atlas_source->get_tile_texture_region(coords).size / 2); encompassing_rect.expand_to(center + atlas_source->get_tile_texture_region(coords).size / 2); } diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/MSBuildPanel.cs b/modules/mono/editor/GodotTools/GodotTools/Build/MSBuildPanel.cs index 8cb64b4f56..262de024ca 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Build/MSBuildPanel.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Build/MSBuildPanel.cs @@ -175,7 +175,7 @@ namespace GodotTools.Build AddChild(BuildOutputView); } - public override void _Notification(long what) + public override void _Notification(int what) { base._Notification(what); diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs index db96003baf..019504ad66 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs @@ -71,7 +71,7 @@ namespace GodotTools.Export } } - public override void _ExportBegin(string[] features, bool isDebug, string path, long flags) + public override void _ExportBegin(string[] features, bool isDebug, string path, uint flags) { base._ExportBegin(features, isDebug, path, flags); diff --git a/modules/mono/editor/GodotTools/GodotTools/HotReloadAssemblyWatcher.cs b/modules/mono/editor/GodotTools/GodotTools/HotReloadAssemblyWatcher.cs index e401910301..eb42f01b3a 100644 --- a/modules/mono/editor/GodotTools/GodotTools/HotReloadAssemblyWatcher.cs +++ b/modules/mono/editor/GodotTools/GodotTools/HotReloadAssemblyWatcher.cs @@ -9,7 +9,7 @@ namespace GodotTools { private Timer _watchTimer; - public override void _Notification(long what) + public override void _Notification(int what) { if (what == Node.NotificationWMWindowFocusIn) { diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 390d1e5d3d..ad6306bb41 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -3000,7 +3000,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() { } else if (return_info.type == Variant::NIL) { imethod.return_type.cname = name_cache.type_void; } else { - imethod.return_type.cname = _get_type_name_from_meta(return_info.type, m ? m->get_argument_meta(-1) : GodotTypeInfo::METADATA_NONE); + imethod.return_type.cname = _get_type_name_from_meta(return_info.type, m ? m->get_argument_meta(-1) : (GodotTypeInfo::Metadata)method_info.return_val_metadata); } for (int i = 0; i < argc; i++) { @@ -3024,7 +3024,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() { } else if (arginfo.type == Variant::NIL) { iarg.type.cname = name_cache.type_Variant; } else { - iarg.type.cname = _get_type_name_from_meta(arginfo.type, m ? m->get_argument_meta(i) : GodotTypeInfo::METADATA_NONE); + iarg.type.cname = _get_type_name_from_meta(arginfo.type, m ? m->get_argument_meta(i) : (GodotTypeInfo::Metadata)method_info.get_argument_meta(i)); } iarg.name = escape_csharp_keyword(snake_to_camel_case(iarg.name)); @@ -3124,7 +3124,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() { } else if (arginfo.type == Variant::NIL) { iarg.type.cname = name_cache.type_Variant; } else { - iarg.type.cname = _get_type_name_from_meta(arginfo.type, GodotTypeInfo::METADATA_NONE); + iarg.type.cname = _get_type_name_from_meta(arginfo.type, (GodotTypeInfo::Metadata)method_info.get_argument_meta(i)); } iarg.name = escape_csharp_keyword(snake_to_camel_case(iarg.name)); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs index f4646d1d3c..a61c5403b9 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs @@ -189,10 +189,15 @@ namespace Godot.Collections /// <summary> /// Resizes this <see cref="Array"/> to the given size. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="newSize">The new size of the array.</param> /// <returns><see cref="Error.Ok"/> if successful, or an error code.</returns> public Error Resize(int newSize) { + ThrowIfReadOnly(); + var self = (godot_array)NativeValue; return NativeFuncs.godotsharp_array_resize(ref self, newSize); } @@ -200,8 +205,13 @@ namespace Godot.Collections /// <summary> /// Shuffles the contents of this <see cref="Array"/> into a random order. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> public void Shuffle() { + ThrowIfReadOnly(); + var self = (godot_array)NativeValue; NativeFuncs.godotsharp_array_shuffle(ref self); } @@ -240,6 +250,9 @@ namespace Godot.Collections /// <summary> /// Returns the item at the given <paramref name="index"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The property is assigned and the array is read-only. + /// </exception> /// <value>The <see cref="Variant"/> item at the given <paramref name="index"/>.</value> public unsafe Variant this[int index] { @@ -250,8 +263,11 @@ namespace Godot.Collections } set { + ThrowIfReadOnly(); + if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index)); + var self = (godot_array)NativeValue; godot_variant* ptrw = NativeFuncs.godotsharp_array_ptrw(ref self); godot_variant* itemPtr = &ptrw[index]; @@ -264,9 +280,14 @@ namespace Godot.Collections /// Adds an item to the end of this <see cref="Array"/>. /// This is the same as <c>append</c> or <c>push_back</c> in GDScript. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="item">The <see cref="Variant"/> item to add.</param> public void Add(Variant item) { + ThrowIfReadOnly(); + godot_variant variantValue = (godot_variant)item.NativeVar; var self = (godot_array)NativeValue; _ = NativeFuncs.godotsharp_array_add(ref self, variantValue); @@ -282,6 +303,9 @@ namespace Godot.Collections /// <summary> /// Erases all items from this <see cref="Array"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> public void Clear() => Resize(0); /// <summary> @@ -303,10 +327,15 @@ namespace Godot.Collections /// or the position at the end of the array. /// Existing items will be moved to the right. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="index">The index to insert at.</param> /// <param name="item">The <see cref="Variant"/> item to insert.</param> public void Insert(int index, Variant item) { + ThrowIfReadOnly(); + if (index < 0 || index > Count) throw new ArgumentOutOfRangeException(nameof(index)); @@ -319,9 +348,14 @@ namespace Godot.Collections /// Removes the first occurrence of the specified <paramref name="item"/> /// from this <see cref="Array"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="item">The value to remove.</param> public bool Remove(Variant item) { + ThrowIfReadOnly(); + int index = IndexOf(item); if (index >= 0) { @@ -335,9 +369,14 @@ namespace Godot.Collections /// <summary> /// Removes an element from this <see cref="Array"/> by index. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="index">The index of the element to remove.</param> public void RemoveAt(int index) { + ThrowIfReadOnly(); + if (index < 0 || index > Count) throw new ArgumentOutOfRangeException(nameof(index)); @@ -358,7 +397,28 @@ namespace Godot.Collections object ICollection.SyncRoot => false; - bool ICollection<Variant>.IsReadOnly => false; + /// <summary> + /// Returns <see langword="true"/> if the array is read-only. + /// See <see cref="MakeReadOnly"/>. + /// </summary> + public bool IsReadOnly => NativeValue.DangerousSelfRef.IsReadOnly; + + /// <summary> + /// Makes the <see cref="Array"/> read-only, i.e. disabled modying of the + /// array's elements. Does not apply to nested content, e.g. content of + /// nested arrays. + /// </summary> + public void MakeReadOnly() + { + if (IsReadOnly) + { + // Avoid interop call when the array is already read-only. + return; + } + + var self = (godot_array)NativeValue; + NativeFuncs.godotsharp_array_make_read_only(ref self); + } /// <summary> /// Copies the elements of this <see cref="Array"/> to the given @@ -472,6 +532,14 @@ namespace Godot.Collections { elem = NativeValue.DangerousSelfRef.Elements[index]; } + + private void ThrowIfReadOnly() + { + if (IsReadOnly) + { + throw new InvalidOperationException("Array instance is read-only."); + } + } } internal interface IGenericGodotArray @@ -592,6 +660,9 @@ namespace Godot.Collections /// <summary> /// Resizes this <see cref="Array{T}"/> to the given size. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="newSize">The new size of the array.</param> /// <returns><see cref="Error.Ok"/> if successful, or an error code.</returns> public Error Resize(int newSize) @@ -602,6 +673,9 @@ namespace Godot.Collections /// <summary> /// Shuffles the contents of this <see cref="Array{T}"/> into a random order. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> public void Shuffle() { _underlyingArray.Shuffle(); @@ -634,6 +708,9 @@ namespace Godot.Collections /// <summary> /// Returns the value at the given <paramref name="index"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The property is assigned and the array is read-only. + /// </exception> /// <value>The value at the given <paramref name="index"/>.</value> public unsafe T this[int index] { @@ -644,8 +721,11 @@ namespace Godot.Collections } set { + ThrowIfReadOnly(); + if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index)); + var self = (godot_array)_underlyingArray.NativeValue; godot_variant* ptrw = NativeFuncs.godotsharp_array_ptrw(ref self); godot_variant* itemPtr = &ptrw[index]; @@ -673,10 +753,15 @@ namespace Godot.Collections /// or the position at the end of the array. /// Existing items will be moved to the right. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="index">The index to insert at.</param> /// <param name="item">The item to insert.</param> public void Insert(int index, T item) { + ThrowIfReadOnly(); + if (index < 0 || index > Count) throw new ArgumentOutOfRangeException(nameof(index)); @@ -688,6 +773,9 @@ namespace Godot.Collections /// <summary> /// Removes an element from this <see cref="Array{T}"/> by index. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="index">The index of the element to remove.</param> public void RemoveAt(int index) { @@ -703,16 +791,35 @@ namespace Godot.Collections /// <returns>The number of elements.</returns> public int Count => _underlyingArray.Count; - bool ICollection<T>.IsReadOnly => false; + /// <summary> + /// Returns <see langword="true"/> if the array is read-only. + /// See <see cref="MakeReadOnly"/>. + /// </summary> + public bool IsReadOnly => _underlyingArray.IsReadOnly; + + /// <summary> + /// Makes the <see cref="Array{T}"/> read-only, i.e. disabled modying of the + /// array's elements. Does not apply to nested content, e.g. content of + /// nested arrays. + /// </summary> + public void MakeReadOnly() + { + _underlyingArray.MakeReadOnly(); + } /// <summary> /// Adds an item to the end of this <see cref="Array{T}"/>. /// This is the same as <c>append</c> or <c>push_back</c> in GDScript. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="item">The item to add.</param> /// <returns>The new size after adding the item.</returns> public void Add(T item) { + ThrowIfReadOnly(); + using var variantValue = VariantUtils.CreateFrom(item); var self = (godot_array)_underlyingArray.NativeValue; _ = NativeFuncs.godotsharp_array_add(ref self, variantValue); @@ -721,6 +828,9 @@ namespace Godot.Collections /// <summary> /// Erases all items from this <see cref="Array{T}"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> public void Clear() { _underlyingArray.Clear(); @@ -769,10 +879,15 @@ namespace Godot.Collections /// Removes the first occurrence of the specified value /// from this <see cref="Array{T}"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The array is read-only. + /// </exception> /// <param name="item">The value to remove.</param> /// <returns>A <see langword="bool"/> indicating success or failure.</returns> public bool Remove(T item) { + ThrowIfReadOnly(); + int index = IndexOf(item); if (index >= 0) { @@ -812,5 +927,13 @@ namespace Godot.Collections [MethodImpl(MethodImplOptions.AggressiveInlining)] public static explicit operator Array<T>(Variant from) => from.AsGodotArray<T>(); + + private void ThrowIfReadOnly() + { + if (IsReadOnly) + { + throw new InvalidOperationException("Array instance is read-only."); + } + } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs index fa304c1b94..923b2adafd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs @@ -93,10 +93,15 @@ namespace Godot.Collections /// By default, duplicate keys are not copied over, unless <paramref name="overwrite"/> /// is <see langword="true"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The dictionary is read-only. + /// </exception> /// <param name="dictionary">Dictionary to copy entries from.</param> /// <param name="overwrite">If duplicate keys should be copied over as well.</param> public void Merge(Dictionary dictionary, bool overwrite = false) { + ThrowIfReadOnly(); + var self = (godot_dictionary)NativeValue; var other = (godot_dictionary)dictionary.NativeValue; NativeFuncs.godotsharp_dictionary_merge(ref self, in other, overwrite.ToGodotBool()); @@ -175,8 +180,12 @@ namespace Godot.Collections /// <summary> /// Returns the value at the given <paramref name="key"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The property is assigned and the dictionary is read-only. + /// </exception> /// <exception cref="KeyNotFoundException"> - /// An entry for <paramref name="key"/> does not exist in the dictionary. + /// The property is retrieved and an entry for <paramref name="key"/> + /// does not exist in the dictionary. /// </exception> /// <value>The value at the given <paramref name="key"/>.</value> public Variant this[Variant key] @@ -197,6 +206,8 @@ namespace Godot.Collections } set { + ThrowIfReadOnly(); + var self = (godot_dictionary)NativeValue; NativeFuncs.godotsharp_dictionary_set_value(ref self, (godot_variant)key.NativeVar, (godot_variant)value.NativeVar); @@ -207,6 +218,9 @@ namespace Godot.Collections /// Adds an value <paramref name="value"/> at key <paramref name="key"/> /// to this <see cref="Dictionary"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The dictionary is read-only. + /// </exception> /// <exception cref="ArgumentException"> /// An entry for <paramref name="key"/> already exists in the dictionary. /// </exception> @@ -214,6 +228,8 @@ namespace Godot.Collections /// <param name="value">The value to add.</param> public void Add(Variant key, Variant value) { + ThrowIfReadOnly(); + var variantKey = (godot_variant)key.NativeVar; var self = (godot_dictionary)NativeValue; @@ -230,8 +246,13 @@ namespace Godot.Collections /// <summary> /// Clears the dictionary, removing all entries from it. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The dictionary is read-only. + /// </exception> public void Clear() { + ThrowIfReadOnly(); + var self = (godot_dictionary)NativeValue; NativeFuncs.godotsharp_dictionary_clear(ref self); } @@ -267,15 +288,22 @@ namespace Godot.Collections /// <summary> /// Removes an element from this <see cref="Dictionary"/> by key. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The dictionary is read-only. + /// </exception> /// <param name="key">The key of the element to remove.</param> public bool Remove(Variant key) { + ThrowIfReadOnly(); + var self = (godot_dictionary)NativeValue; return NativeFuncs.godotsharp_dictionary_remove_key(ref self, (godot_variant)key.NativeVar).ToBool(); } bool ICollection<KeyValuePair<Variant, Variant>>.Remove(KeyValuePair<Variant, Variant> item) { + ThrowIfReadOnly(); + godot_variant variantKey = (godot_variant)item.Key.NativeVar; var self = (godot_dictionary)NativeValue; bool found = NativeFuncs.godotsharp_dictionary_try_get_value(ref self, @@ -311,7 +339,28 @@ namespace Godot.Collections } } - bool ICollection<KeyValuePair<Variant, Variant>>.IsReadOnly => false; + /// <summary> + /// Returns <see langword="true"/> if the dictionary is read-only. + /// See <see cref="MakeReadOnly"/>. + /// </summary> + public bool IsReadOnly => NativeValue.DangerousSelfRef.IsReadOnly; + + /// <summary> + /// Makes the <see cref="Dictionary"/> read-only, i.e. disabled modying of the + /// dictionary's elements. Does not apply to nested content, e.g. content of + /// nested dictionaries. + /// </summary> + public void MakeReadOnly() + { + if (IsReadOnly) + { + // Avoid interop call when the dictionary is already read-only. + return; + } + + var self = (godot_dictionary)NativeValue; + NativeFuncs.godotsharp_dictionary_make_read_only(ref self); + } /// <summary> /// Gets the value for the given <paramref name="key"/> in the dictionary. @@ -397,6 +446,14 @@ namespace Godot.Collections using (str) return Marshaling.ConvertStringToManaged(str); } + + private void ThrowIfReadOnly() + { + if (IsReadOnly) + { + throw new InvalidOperationException("Dictionary instance is read-only."); + } + } } internal interface IGenericGodotDictionary @@ -508,6 +565,9 @@ namespace Godot.Collections /// By default, duplicate keys are not copied over, unless <paramref name="overwrite"/> /// is <see langword="true"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The dictionary is read-only. + /// </exception> /// <param name="dictionary">Dictionary to copy entries from.</param> /// <param name="overwrite">If duplicate keys should be copied over as well.</param> public void Merge(Dictionary<TKey, TValue> dictionary, bool overwrite = false) @@ -536,6 +596,13 @@ namespace Godot.Collections /// <summary> /// Returns the value at the given <paramref name="key"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The property is assigned and the dictionary is read-only. + /// </exception> + /// <exception cref="KeyNotFoundException"> + /// The property is retrieved and an entry for <paramref name="key"/> + /// does not exist in the dictionary. + /// </exception> /// <value>The value at the given <paramref name="key"/>.</value> public TValue this[TKey key] { @@ -557,6 +624,8 @@ namespace Godot.Collections } set { + ThrowIfReadOnly(); + using var variantKey = VariantUtils.CreateFrom(key); using var variantValue = VariantUtils.CreateFrom(value); var self = (godot_dictionary)_underlyingDict.NativeValue; @@ -616,10 +685,15 @@ namespace Godot.Collections /// Adds an object <paramref name="value"/> at key <paramref name="key"/> /// to this <see cref="Dictionary{TKey, TValue}"/>. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The dictionary is read-only. + /// </exception> /// <param name="key">The key at which to add the object.</param> /// <param name="value">The object to add.</param> public void Add(TKey key, TValue value) { + ThrowIfReadOnly(); + using var variantKey = VariantUtils.CreateFrom(key); var self = (godot_dictionary)_underlyingDict.NativeValue; @@ -645,9 +719,14 @@ namespace Godot.Collections /// <summary> /// Removes an element from this <see cref="Dictionary{TKey, TValue}"/> by key. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The dictionary is read-only. + /// </exception> /// <param name="key">The key of the element to remove.</param> public bool Remove(TKey key) { + ThrowIfReadOnly(); + using var variantKey = VariantUtils.CreateFrom(key); var self = (godot_dictionary)_underlyingDict.NativeValue; return NativeFuncs.godotsharp_dictionary_remove_key(ref self, variantKey).ToBool(); @@ -683,7 +762,21 @@ namespace Godot.Collections /// <returns>The number of elements.</returns> public int Count => _underlyingDict.Count; - bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => false; + /// <summary> + /// Returns <see langword="true"/> if the dictionary is read-only. + /// See <see cref="MakeReadOnly"/>. + /// </summary> + public bool IsReadOnly => _underlyingDict.IsReadOnly; + + /// <summary> + /// Makes the <see cref="Dictionary{TKey, TValue}"/> read-only, i.e. disabled + /// modying of the dictionary's elements. Does not apply to nested content, + /// e.g. content of nested dictionaries. + /// </summary> + public void MakeReadOnly() + { + _underlyingDict.MakeReadOnly(); + } void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item) => Add(item.Key, item.Value); @@ -691,6 +784,9 @@ namespace Godot.Collections /// <summary> /// Clears the dictionary, removing all entries from it. /// </summary> + /// <exception cref="InvalidOperationException"> + /// The dictionary is read-only. + /// </exception> public void Clear() => _underlyingDict.Clear(); bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item) @@ -740,6 +836,8 @@ namespace Godot.Collections bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item) { + ThrowIfReadOnly(); + using var variantKey = VariantUtils.CreateFrom(item.Key); var self = (godot_dictionary)_underlyingDict.NativeValue; bool found = NativeFuncs.godotsharp_dictionary_try_get_value(ref self, @@ -789,5 +887,13 @@ namespace Godot.Collections [MethodImpl(MethodImplOptions.AggressiveInlining)] public static explicit operator Dictionary<TKey, TValue>(Variant from) => from.AsGodotDictionary<TKey, TValue>(); + + private void ThrowIfReadOnly() + { + if (IsReadOnly) + { + throw new InvalidOperationException("Dictionary instance is read-only."); + } + } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs index c295e500de..43e7c7eb9a 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs @@ -697,6 +697,9 @@ namespace Godot.NativeInterop private uint _safeRefCount; public VariantVector _arrayVector; + + private unsafe godot_variant* _readOnly; + // There are more fields here, but we don't care as we never store this in C# public readonly int Size @@ -704,6 +707,12 @@ namespace Godot.NativeInterop [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _arrayVector.Size; } + + public readonly unsafe bool IsReadOnly + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _readOnly != null; + } } [StructLayout(LayoutKind.Sequential)] @@ -737,6 +746,12 @@ namespace Godot.NativeInterop get => _p != null ? _p->Size : 0; } + public readonly unsafe bool IsReadOnly + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _p != null && _p->IsReadOnly; + } + public unsafe void Dispose() { if (_p == null) @@ -766,35 +781,59 @@ namespace Godot.NativeInterop // A correctly constructed value needs to call the native default constructor to allocate `_p`. // Don't pass a C# default constructed `godot_dictionary` to native code, unless it's going to // be re-assigned a new value (the copy constructor checks if `_p` is null so that's fine). - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Explicit)] // ReSharper disable once InconsistentNaming public ref struct godot_dictionary { [MethodImpl(MethodImplOptions.AggressiveInlining)] internal readonly unsafe godot_dictionary* GetUnsafeAddress() - => (godot_dictionary*)Unsafe.AsPointer(ref Unsafe.AsRef(in _p)); + => (godot_dictionary*)Unsafe.AsPointer(ref Unsafe.AsRef(in _getUnsafeAddressHelper)); - private IntPtr _p; + [FieldOffset(0)] private byte _getUnsafeAddressHelper; - public readonly bool IsAllocated + [FieldOffset(0)] private unsafe DictionaryPrivate* _p; + + [StructLayout(LayoutKind.Sequential)] + private struct DictionaryPrivate + { + private uint _safeRefCount; + + private unsafe godot_variant* _readOnly; + + // There are more fields here, but we don't care as we never store this in C# + + public readonly unsafe bool IsReadOnly + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _readOnly != null; + } + } + + public readonly unsafe bool IsAllocated { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _p != IntPtr.Zero; + get => _p != null; } - public void Dispose() + public readonly unsafe bool IsReadOnly { - if (_p == IntPtr.Zero) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _p != null && _p->IsReadOnly; + } + + public unsafe void Dispose() + { + if (_p == null) return; NativeFuncs.godotsharp_dictionary_destroy(ref this); - _p = IntPtr.Zero; + _p = null; } [StructLayout(LayoutKind.Sequential)] // ReSharper disable once InconsistentNaming internal struct movable { - private IntPtr _p; + private unsafe DictionaryPrivate* _p; public static unsafe explicit operator movable(in godot_dictionary value) => *(movable*)CustomUnsafe.AsPointer(ref CustomUnsafe.AsRef(value)); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs index d116284e1c..1e23689c95 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs @@ -376,6 +376,8 @@ namespace Godot.NativeInterop public static partial Error godotsharp_array_resize(ref godot_array p_self, int p_new_size); + public static partial void godotsharp_array_make_read_only(ref godot_array p_self); + public static partial void godotsharp_array_shuffle(ref godot_array p_self); public static partial void godotsharp_array_to_string(ref godot_array p_self, out godot_string r_str); @@ -416,6 +418,8 @@ namespace Godot.NativeInterop public static partial godot_bool godotsharp_dictionary_remove_key(ref godot_dictionary p_self, in godot_variant p_key); + public static partial void godotsharp_dictionary_make_read_only(ref godot_dictionary p_self); + public static partial void godotsharp_dictionary_to_string(ref godot_dictionary p_self, out godot_string r_str); // StringExtensions diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs index cb9525b49c..df67e075ac 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs @@ -69,19 +69,6 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if the strings begins - /// with the given string <paramref name="text"/>. - /// </summary> - /// <param name="instance">The string to check.</param> - /// <param name="text">The beginning string.</param> - /// <returns>If the string begins with the given string.</returns> - [Obsolete("Use string.StartsWith instead.")] - public static bool BeginsWith(this string instance, string text) - { - return instance.StartsWith(text); - } - - /// <summary> /// Returns the bigrams (pairs of consecutive letters) of this string. /// </summary> /// <param name="instance">The string that will be used.</param> @@ -618,7 +605,7 @@ namespace Godot } else { - if (instance.BeginsWith("/")) + if (instance.StartsWith('/')) { rs = instance.Substring(1); directory = "/"; @@ -1199,23 +1186,6 @@ namespace Godot } /// <summary> - /// Returns a copy of the string with characters removed from the left. - /// The <paramref name="chars"/> argument is a string specifying the set of characters - /// to be removed. - /// Note: The <paramref name="chars"/> is not a prefix. See <see cref="TrimPrefix"/> - /// method that will remove a single prefix string rather than a set of characters. - /// </summary> - /// <seealso cref="RStrip(string, string)"/> - /// <param name="instance">The string to remove characters from.</param> - /// <param name="chars">The characters to be removed.</param> - /// <returns>A copy of the string with characters removed from the left.</returns> - [Obsolete("Use string.TrimStart instead.")] - public static string LStrip(this string instance, string chars) - { - return instance.TrimStart(chars.ToCharArray()); - } - - /// <summary> /// Do a simple expression match, where '*' matches zero or more /// arbitrary characters and '?' matches any single character except '.'. /// </summary> @@ -1504,23 +1474,6 @@ namespace Godot } /// <summary> - /// Returns a copy of the string with characters removed from the right. - /// The <paramref name="chars"/> argument is a string specifying the set of characters - /// to be removed. - /// Note: The <paramref name="chars"/> is not a suffix. See <see cref="TrimSuffix"/> - /// method that will remove a single suffix string rather than a set of characters. - /// </summary> - /// <seealso cref="LStrip(string, string)"/> - /// <param name="instance">The string to remove characters from.</param> - /// <param name="chars">The characters to be removed.</param> - /// <returns>A copy of the string with characters removed from the right.</returns> - [Obsolete("Use string.TrimEnd instead.")] - public static string RStrip(this string instance, string chars) - { - return instance.TrimEnd(chars.ToCharArray()); - } - - /// <summary> /// Returns the SHA-1 hash of the string as an array of bytes. /// </summary> /// <seealso cref="Sha1Text(string)"/> diff --git a/modules/mono/glue/runtime_interop.cpp b/modules/mono/glue/runtime_interop.cpp index e7f50d2caa..d17fe3e75f 100644 --- a/modules/mono/glue/runtime_interop.cpp +++ b/modules/mono/glue/runtime_interop.cpp @@ -1012,6 +1012,10 @@ int32_t godotsharp_array_resize(Array *p_self, int32_t p_new_size) { return (int32_t)p_self->resize(p_new_size); } +void godotsharp_array_make_read_only(Array *p_self) { + p_self->make_read_only(); +} + void godotsharp_array_shuffle(Array *p_self) { p_self->shuffle(); } @@ -1081,6 +1085,10 @@ bool godotsharp_dictionary_remove_key(Dictionary *p_self, const Variant *p_key) return p_self->erase(*p_key); } +void godotsharp_dictionary_make_read_only(Dictionary *p_self) { + p_self->make_read_only(); +} + void godotsharp_dictionary_to_string(const Dictionary *p_self, String *r_str) { *r_str = Variant(*p_self).operator String(); } @@ -1439,6 +1447,7 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_array_insert, (void *)godotsharp_array_remove_at, (void *)godotsharp_array_resize, + (void *)godotsharp_array_make_read_only, (void *)godotsharp_array_shuffle, (void *)godotsharp_array_to_string, (void *)godotsharp_dictionary_try_get_value, @@ -1454,6 +1463,7 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_dictionary_merge, (void *)godotsharp_dictionary_recursive_equal, (void *)godotsharp_dictionary_remove_key, + (void *)godotsharp_dictionary_make_read_only, (void *)godotsharp_dictionary_to_string, (void *)godotsharp_string_simplify_path, (void *)godotsharp_string_to_camel_case, diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index 27cb84fb9d..9dad0c9357 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -44,7 +44,7 @@ void AudioDriverOpenSL::_buffer_callback( if (pause) { mix = false; } else { - mix = mutex.try_lock() == OK; + mix = mutex.try_lock(); } if (mix) { diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 8c5aab4c80..a1304ab991 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -1379,7 +1379,7 @@ void TileMap::draw_tile(RID p_canvas_item, const Vector2i &p_position, const Ref Color modulate = tile_data->get_modulate() * p_modulation; // Compute the offset. - Vector2i tile_offset = atlas_source->get_tile_effective_texture_offset(p_atlas_coords, p_alternative_tile); + Vector2i tile_offset = tile_data->get_texture_origin(); // Get destination rect. Rect2 dest_rect; diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 3ceb27b3e6..869d12b4df 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -663,18 +663,18 @@ void Window::set_visible(bool p_visible) { return; } - visible = p_visible; - if (!is_inside_tree()) { + visible = p_visible; return; } - if (updating_child_controls) { - _update_child_controls(); - } - ERR_FAIL_COND_MSG(get_parent() == nullptr, "Can't change visibility of main window."); + visible = p_visible; + + // Stop any queued resizing, as the window will be resized right now. + updating_child_controls = false; + Viewport *embedder_vp = _get_embedder(); if (!embedder_vp) { @@ -833,7 +833,7 @@ bool Window::is_visible() const { } void Window::_update_window_size() { - // Force window to respect size limitations of rendering server + // Force window to respect size limitations of rendering server. RenderingServer *rendering_server = RenderingServer::get_singleton(); if (rendering_server) { Size2i max_window_size = rendering_server->get_maximum_viewport_size(); @@ -1130,6 +1130,7 @@ void Window::_notification(int p_what) { case NOTIFICATION_READY: { if (wrap_controls) { + // Finish any resizing immediately so it doesn't interfere on stuff overriding _ready(). _update_child_controls(); } } break; @@ -1138,9 +1139,7 @@ void Window::_notification(int p_what) { _invalidate_theme_cache(); _update_theme_item_cache(); - if (embedder) { - embedder->_sub_window_update(this); - } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { + if (!embedder && window_id != DisplayServer::INVALID_WINDOW_ID) { String tr_title = atr(title); #ifdef DEBUG_ENABLED if (window_id == DisplayServer::MAIN_WINDOW_ID) { @@ -1152,8 +1151,6 @@ void Window::_notification(int p_what) { #endif DisplayServer::get_singleton()->window_set_title(tr_title, window_id); } - - child_controls_changed(); } break; case NOTIFICATION_EXIT_TREE: { @@ -1254,8 +1251,13 @@ Vector<Vector2> Window::get_mouse_passthrough_polygon() const { void Window::set_wrap_controls(bool p_enable) { wrap_controls = p_enable; - if (wrap_controls) { - child_controls_changed(); + + if (!is_inside_tree()) { + return; + } + + if (updating_child_controls) { + _update_child_controls(); } else { _update_window_size(); } @@ -1282,23 +1284,23 @@ Size2 Window::_get_contents_minimum_size() const { return max; } -void Window::_update_child_controls() { - if (!updating_child_controls) { +void Window::child_controls_changed() { + if (!is_inside_tree() || !visible || updating_child_controls) { return; } - _update_window_size(); - - updating_child_controls = false; + updating_child_controls = true; + call_deferred(SNAME("_update_child_controls")); } -void Window::child_controls_changed() { - if (!is_inside_tree() || !visible || updating_child_controls) { +void Window::_update_child_controls() { + if (!updating_child_controls) { return; } - updating_child_controls = true; - call_deferred(SNAME("_update_child_controls")); + _update_window_size(); + + updating_child_controls = false; } bool Window::_can_consume_input_events() const { @@ -1647,7 +1649,24 @@ void Window::_invalidate_theme_cache() { void Window::_update_theme_item_cache() { // Request an update on the next frame to reflect theme changes. // Updating without a delay can cause a lot of lag. - child_controls_changed(); + if (!wrap_controls) { + updating_embedded_window = true; + call_deferred(SNAME("_update_embedded_window")); + } else { + child_controls_changed(); + } +} + +void Window::_update_embedded_window() { + if (!updating_embedded_window) { + return; + } + + if (embedder) { + embedder->_sub_window_update(this); + }; + + updating_embedded_window = false; } void Window::set_theme_type_variation(const StringName &p_theme_type) { @@ -2201,6 +2220,7 @@ void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("child_controls_changed"), &Window::child_controls_changed); ClassDB::bind_method(D_METHOD("_update_child_controls"), &Window::_update_child_controls); + ClassDB::bind_method(D_METHOD("_update_embedded_window"), &Window::_update_embedded_window); ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Window::set_theme); ClassDB::bind_method(D_METHOD("get_theme"), &Window::get_theme); diff --git a/scene/main/window.h b/scene/main/window.h index 18841a4f1a..182caf5f0c 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -116,6 +116,7 @@ private: bool exclusive = false; bool wrap_controls = false; bool updating_child_controls = false; + bool updating_embedded_window = false; bool clamp_to_embedder = false; LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED; @@ -123,6 +124,7 @@ private: bool auto_translate = true; void _update_child_controls(); + void _update_embedded_window(); Size2i content_scale_size; ContentScaleMode content_scale_mode = CONTENT_SCALE_MODE_DISABLED; diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 50f3015814..cb3c865f05 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -4691,6 +4691,7 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol data_tracks.resize(tracks_to_compress.size()); time_tracks.resize(tracks_to_compress.size()); + uint32_t needed_min_page_size = base_page_size; for (uint32_t i = 0; i < data_tracks.size(); i++) { data_tracks[i].split_tolerance = p_split_tolerance; if (track_get_type(tracks_to_compress[i]) == TYPE_BLEND_SHAPE) { @@ -4698,7 +4699,12 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol } else { data_tracks[i].components = 3; } + needed_min_page_size += data_tracks[i].data.size() + data_tracks[i].get_temp_packet_size(); } + for (uint32_t i = 0; i < time_tracks.size(); i++) { + needed_min_page_size += time_tracks[i].packets.size() * 4; // time packet is 32 bits + } + ERR_FAIL_COND_MSG(p_page_size < needed_min_page_size, "Cannot compress with the given page size"); while (true) { // Begin by finding the keyframe in all tracks with the time closest to the current time diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index b5a68ef14b..58a638804d 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -991,6 +991,28 @@ uint32_t TileSet::get_navigation_layer_layers(int p_layer_index) const { return navigation_layers[p_layer_index].layers; } +void TileSet::set_navigation_layer_layer_value(int p_layer_index, int p_layer_number, bool p_value) { + ERR_FAIL_COND_MSG(p_layer_number < 1, "Navigation layer number must be between 1 and 32 inclusive."); + ERR_FAIL_COND_MSG(p_layer_number > 32, "Navigation layer number must be between 1 and 32 inclusive."); + + uint32_t _navigation_layers = get_navigation_layer_layers(p_layer_index); + + if (p_value) { + _navigation_layers |= 1 << (p_layer_number - 1); + } else { + _navigation_layers &= ~(1 << (p_layer_number - 1)); + } + + set_navigation_layer_layers(p_layer_index, _navigation_layers); +} + +bool TileSet::get_navigation_layer_layer_value(int p_layer_index, int p_layer_number) const { + ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Navigation layer number must be between 1 and 32 inclusive."); + ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Navigation layer number must be between 1 and 32 inclusive."); + + return get_navigation_layer_layers(p_layer_index) & (1 << (p_layer_number - 1)); +} + // Custom data. int TileSet::get_custom_data_layers_count() const { return custom_data_layers.size(); @@ -2533,6 +2555,11 @@ void TileSet::_compatibility_conversion() { bool flip_v = flags & 2; bool transpose = flags & 4; + Transform2D xform; + xform = flip_h ? xform.scaled(Size2(-1, 1)) : xform; + xform = flip_v ? xform.scaled(Size2(1, -1)) : xform; + xform = transpose ? xform.rotated(Math_PI).scaled(Size2(-1, -1)) : xform; + int alternative_tile = 0; if (!atlas_source->has_tile(coords)) { atlas_source->create_tile(coords); @@ -2569,14 +2596,26 @@ void TileSet::_compatibility_conversion() { if (ctd->occluder.is_valid()) { if (get_occlusion_layers_count() < 1) { add_occlusion_layer(); + }; + Ref<OccluderPolygon2D> occluder = ctd->occluder->duplicate(); + Vector<Vector2> polygon = ctd->occluder->get_polygon(); + for (int index = 0; index < polygon.size(); index++) { + polygon.write[index] = xform.xform(polygon[index] - ctd->region.get_size() / 2.0); } - tile_data->set_occluder(0, ctd->occluder); + occluder->set_polygon(polygon); + tile_data->set_occluder(0, occluder); } if (ctd->navigation.is_valid()) { if (get_navigation_layers_count() < 1) { add_navigation_layer(); } - tile_data->set_navigation_polygon(0, ctd->autotile_navpoly_map[coords]); + Ref<NavigationPolygon> navigation = ctd->navigation->duplicate(); + Vector<Vector2> vertices = navigation->get_vertices(); + for (int index = 0; index < vertices.size(); index++) { + vertices.write[index] = xform.xform(vertices[index] - ctd->region.get_size() / 2.0); + } + navigation->set_vertices(vertices); + tile_data->set_navigation_polygon(0, navigation); } tile_data->set_z_index(ctd->z_index); @@ -2594,7 +2633,7 @@ void TileSet::_compatibility_conversion() { if (convex_shape.is_valid()) { Vector<Vector2> polygon = convex_shape->get_points(); for (int point_index = 0; point_index < polygon.size(); point_index++) { - polygon.write[point_index] = csd.transform.xform(polygon[point_index]); + polygon.write[point_index] = xform.xform(csd.transform.xform(polygon[point_index]) - ctd->region.get_size() / 2.0); } tile_data->set_collision_polygons_count(0, tile_data->get_collision_polygons_count(0) + 1); int index = tile_data->get_collision_polygons_count(0) - 1; @@ -2605,9 +2644,15 @@ void TileSet::_compatibility_conversion() { } } } + // Update the size count. + if (!compatibility_size_count.has(ctd->region.get_size())) { + compatibility_size_count[ctd->region.get_size()] = 0; + } + compatibility_size_count[ctd->region.get_size()]++; } break; case COMPATIBILITY_TILE_MODE_AUTO_TILE: { // Not supported. It would need manual conversion. + WARN_PRINT_ONCE("Could not convert 3.x autotiles to 4.x. This operation cannot be done automatically, autotiles must be re-created using the terrain system."); } break; case COMPATIBILITY_TILE_MODE_ATLAS_TILE: { atlas_source->set_margins(ctd->region.get_position()); @@ -2624,6 +2669,11 @@ void TileSet::_compatibility_conversion() { bool flip_v = flags & 2; bool transpose = flags & 4; + Transform2D xform; + xform = flip_h ? xform.scaled(Size2(-1, 1)) : xform; + xform = flip_v ? xform.scaled(Size2(1, -1)) : xform; + xform = transpose ? xform.rotated(Math_PI).scaled(Size2(-1, -1)) : xform; + int alternative_tile = 0; if (!atlas_source->has_tile(coords)) { atlas_source->create_tile(coords); @@ -2661,13 +2711,25 @@ void TileSet::_compatibility_conversion() { if (get_occlusion_layers_count() < 1) { add_occlusion_layer(); } - tile_data->set_occluder(0, ctd->autotile_occluder_map[coords]); + Ref<OccluderPolygon2D> occluder = ctd->autotile_occluder_map[coords]->duplicate(); + Vector<Vector2> polygon = ctd->occluder->get_polygon(); + for (int index = 0; index < polygon.size(); index++) { + polygon.write[index] = xform.xform(polygon[index] - ctd->region.get_size() / 2.0); + } + occluder->set_polygon(polygon); + tile_data->set_occluder(0, occluder); } if (ctd->autotile_navpoly_map.has(coords)) { if (get_navigation_layers_count() < 1) { add_navigation_layer(); } - tile_data->set_navigation_polygon(0, ctd->autotile_navpoly_map[coords]); + Ref<NavigationPolygon> navigation = ctd->autotile_navpoly_map[coords]->duplicate(); + Vector<Vector2> vertices = navigation->get_vertices(); + for (int index = 0; index < vertices.size(); index++) { + vertices.write[index] = xform.xform(vertices[index] - ctd->region.get_size() / 2.0); + } + navigation->set_vertices(vertices); + tile_data->set_navigation_polygon(0, navigation); } if (ctd->autotile_priority_map.has(coords)) { tile_data->set_probability(ctd->autotile_priority_map[coords]); @@ -2689,7 +2751,7 @@ void TileSet::_compatibility_conversion() { if (convex_shape.is_valid()) { Vector<Vector2> polygon = convex_shape->get_points(); for (int point_index = 0; point_index < polygon.size(); point_index++) { - polygon.write[point_index] = csd.transform.xform(polygon[point_index]); + polygon.write[point_index] = xform.xform(csd.transform.xform(polygon[point_index]) - ctd->autotile_tile_size / 2.0); } tile_data->set_collision_polygons_count(0, tile_data->get_collision_polygons_count(0) + 1); int index = tile_data->get_collision_polygons_count(0) - 1; @@ -2712,6 +2774,12 @@ void TileSet::_compatibility_conversion() { } } } + + // Update the size count. + if (!compatibility_size_count.has(ctd->region.get_size())) { + compatibility_size_count[ctd->autotile_tile_size] = 0; + } + compatibility_size_count[ctd->autotile_tile_size] += atlas_size.x * atlas_size.y; } break; } @@ -2728,7 +2796,18 @@ void TileSet::_compatibility_conversion() { } } - // Reset compatibility data + // Update the TileSet tile_size according to the most common size found. + Vector2i max_size = get_tile_size(); + int max_count = 0; + for (KeyValue<Vector2i, int> kv : compatibility_size_count) { + if (kv.value > max_count) { + max_size = kv.key; + max_count = kv.value; + } + } + set_tile_size(max_size); + + // Reset compatibility data (besides the histogram counts) for (const KeyValue<int, CompatibilityTileData *> &E : compatibility_data) { memdelete(E.value); } @@ -2909,6 +2988,10 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { } ctd->shapes.push_back(csd); } + } else if (what == "occluder") { + ctd->occluder = p_value; + } else if (what == "navigation") { + ctd->navigation = p_value; /* // IGNORED FOR NOW, they seem duplicated data compared to the shapes array @@ -3387,6 +3470,8 @@ void TileSet::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_navigation_layer", "layer_index"), &TileSet::remove_navigation_layer); ClassDB::bind_method(D_METHOD("set_navigation_layer_layers", "layer_index", "layers"), &TileSet::set_navigation_layer_layers); ClassDB::bind_method(D_METHOD("get_navigation_layer_layers", "layer_index"), &TileSet::get_navigation_layer_layers); + ClassDB::bind_method(D_METHOD("set_navigation_layer_layer_value", "layer_index", "layer_number", "value"), &TileSet::set_navigation_layer_layer_value); + ClassDB::bind_method(D_METHOD("get_navigation_layer_layer_value", "layer_index", "layer_number"), &TileSet::get_navigation_layer_layer_value); // Custom data ClassDB::bind_method(D_METHOD("get_custom_data_layers_count"), &TileSet::get_custom_data_layers_count); @@ -4282,19 +4367,11 @@ Rect2i TileSetAtlasSource::get_tile_texture_region(Vector2i p_atlas_coords, int return Rect2(origin, region_size); } -Vector2i TileSetAtlasSource::get_tile_effective_texture_offset(Vector2i p_atlas_coords, int p_alternative_tile) const { - ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), Vector2i(), vformat("TileSetAtlasSource has no tile at %s.", Vector2i(p_atlas_coords))); - ERR_FAIL_COND_V_MSG(!has_alternative_tile(p_atlas_coords, p_alternative_tile), Vector2i(), vformat("TileSetAtlasSource has no alternative tile with id %d at %s.", p_alternative_tile, String(p_atlas_coords))); - ERR_FAIL_COND_V(!tile_set, Vector2i()); +bool TileSetAtlasSource::is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const { + Size2 size = get_tile_texture_region(p_atlas_coords).size; + Rect2 rect = Rect2(-size / 2 - get_tile_data(p_atlas_coords, p_alternative_tile)->get_texture_origin(), size); - Vector2 margin = (get_tile_texture_region(p_atlas_coords).size - tile_set->get_tile_size()) / 2; - margin = Vector2i(MAX(0, margin.x), MAX(0, margin.y)); - Vector2i effective_texture_offset = get_tile_data(p_atlas_coords, p_alternative_tile)->get_texture_offset(); - if (ABS(effective_texture_offset.x) > margin.x || ABS(effective_texture_offset.y) > margin.y) { - effective_texture_offset = effective_texture_offset.clamp(-margin, margin); - } - - return effective_texture_offset; + return rect.has_point(p_position); } // Getters for texture and tile region (padded or not) @@ -5046,7 +5123,7 @@ TileData *TileData::duplicate() { output->flip_h = flip_h; output->flip_v = flip_v; output->transpose = transpose; - output->tex_offset = tex_offset; + output->texture_origin = texture_origin; output->material = material; output->modulate = modulate; output->z_index = z_index; @@ -5096,13 +5173,13 @@ bool TileData::get_transpose() const { return transpose; } -void TileData::set_texture_offset(Vector2i p_texture_offset) { - tex_offset = p_texture_offset; +void TileData::set_texture_origin(Vector2i p_texture_origin) { + texture_origin = p_texture_origin; emit_signal(SNAME("changed")); } -Vector2i TileData::get_texture_offset() const { - return tex_offset; +Vector2i TileData::get_texture_origin() const { + return texture_origin; } void TileData::set_material(Ref<Material> p_material) { @@ -5390,6 +5467,13 @@ Variant TileData::get_custom_data_by_layer_id(int p_layer_id) const { } bool TileData::_set(const StringName &p_name, const Variant &p_value) { +#ifndef DISABLE_DEPRECATED + if (p_name == "texture_offset") { + texture_origin = p_value; + return true; + } +#endif + Vector<String> components = String(p_name).split("/", true, 2); if (components.size() == 2 && components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_int()) { @@ -5511,6 +5595,13 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) { } bool TileData::_get(const StringName &p_name, Variant &r_ret) const { +#ifndef DISABLE_DEPRECATED + if (p_name == "texture_offset") { + r_ret = texture_origin; + return true; + } +#endif + Vector<String> components = String(p_name).split("/", true, 2); if (tile_set) { @@ -5692,8 +5783,8 @@ void TileData::_bind_methods() { ClassDB::bind_method(D_METHOD("get_transpose"), &TileData::get_transpose); ClassDB::bind_method(D_METHOD("set_material", "material"), &TileData::set_material); ClassDB::bind_method(D_METHOD("get_material"), &TileData::get_material); - ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &TileData::set_texture_offset); - ClassDB::bind_method(D_METHOD("get_texture_offset"), &TileData::get_texture_offset); + ClassDB::bind_method(D_METHOD("set_texture_origin", "texture_origin"), &TileData::set_texture_origin); + ClassDB::bind_method(D_METHOD("get_texture_origin"), &TileData::get_texture_origin); ClassDB::bind_method(D_METHOD("set_modulate", "modulate"), &TileData::set_modulate); ClassDB::bind_method(D_METHOD("get_modulate"), &TileData::get_modulate); ClassDB::bind_method(D_METHOD("set_z_index", "z_index"), &TileData::set_z_index); @@ -5746,7 +5837,7 @@ void TileData::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "get_flip_h"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_v"), "set_flip_v", "get_flip_v"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transpose"), "set_transpose", "get_transpose"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "texture_offset", PROPERTY_HINT_NONE, "suffix:px"), "set_texture_offset", "get_texture_offset"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "texture_origin", PROPERTY_HINT_NONE, "suffix:px"), "set_texture_origin", "get_texture_origin"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial,ShaderMaterial"), "set_material", "get_material"); ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index"), "set_z_index", "get_z_index"); diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index c2ed798f2b..ad25629a1c 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -198,6 +198,7 @@ private: HashMap<int, CompatibilityTileData *> compatibility_data; HashMap<int, int> compatibility_tilemap_mapping_tile_modes; HashMap<int, RBMap<Array, Array>> compatibility_tilemap_mapping; + HashMap<Vector2i, int> compatibility_size_count; void _compatibility_conversion(); @@ -475,6 +476,8 @@ public: void remove_navigation_layer(int p_index); void set_navigation_layer_layers(int p_layer_index, uint32_t p_layers); uint32_t get_navigation_layer_layers(int p_layer_index) const; + void set_navigation_layer_layer_value(int p_layer_index, int p_layer_number, bool p_value); + bool get_navigation_layer_layer_value(int p_layer_index, int p_layer_number) const; // Custom data int get_custom_data_layers_count() const; @@ -719,7 +722,7 @@ public: // Helpers. Vector2i get_atlas_grid_size() const; Rect2i get_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const; - Vector2i get_tile_effective_texture_offset(Vector2i p_atlas_coords, int p_alternative_tile) const; + bool is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const; // Getters for texture and tile region (padded or not) Ref<Texture2D> get_runtime_texture() const; @@ -785,7 +788,7 @@ private: bool flip_h = false; bool flip_v = false; bool transpose = false; - Vector2i tex_offset; + Vector2i texture_origin; Ref<Material> material = Ref<Material>(); Color modulate = Color(1.0, 1.0, 1.0, 1.0); int z_index = 0; @@ -864,8 +867,8 @@ public: void set_transpose(bool p_transpose); bool get_transpose() const; - void set_texture_offset(Vector2i p_texture_offset); - Vector2i get_texture_offset() const; + void set_texture_origin(Vector2i p_texture_origin); + Vector2i get_texture_origin() const; void set_material(Ref<Material> p_material); Ref<Material> get_material() const; void set_modulate(Color p_modulate); diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 11bbd9dae2..2d65cea432 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -571,7 +571,7 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("global_menu_add_icon_check_item", "menu_root", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_icon_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("global_menu_add_radio_check_item", "menu_root", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_radio_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("global_menu_add_icon_radio_check_item", "menu_root", "icon", "label", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_icon_radio_check_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("global_menu_add_multistate_item", "menu_root", "labe", "max_states", "default_state", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_multistate_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("global_menu_add_multistate_item", "menu_root", "label", "max_states", "default_state", "callback", "key_callback", "tag", "accelerator", "index"), &DisplayServer::global_menu_add_multistate_item, DEFVAL(Callable()), DEFVAL(Callable()), DEFVAL(Variant()), DEFVAL(Key::NONE), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("global_menu_add_separator", "menu_root", "index"), &DisplayServer::global_menu_add_separator, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("global_menu_get_item_index_from_text", "menu_root", "text"), &DisplayServer::global_menu_get_item_index_from_text); |