diff --git a/core/math/bvh_cull.inc b/core/math/bvh_cull.inc index cba8ea6cb31..d7edc8a8843 100644 --- a/core/math/bvh_cull.inc +++ b/core/math/bvh_cull.inc @@ -14,7 +14,7 @@ struct CullParams { uint32_t pairable_type; // optional components for different tests - Vector3 point; + Point point; BVHABB_CLASS abb; typename BVHABB_CLASS::ConvexHull hull; typename BVHABB_CLASS::Segment segment; diff --git a/core/math/bvh_debug.inc b/core/math/bvh_debug.inc index a97304334cd..55db794ee35 100644 --- a/core/math/bvh_debug.inc +++ b/core/math/bvh_debug.inc @@ -6,24 +6,21 @@ void _debug_recursive_print_tree(int p_tree_id) const { } String _debug_aabb_to_string(const BVHABB_CLASS &aabb) const { - String sz = "("; - sz += itos(aabb.min.x); - sz += " ~ "; - sz += itos(-aabb.neg_max.x); - sz += ") ("; + Point size = aabb.calculate_size(); - sz += itos(aabb.min.y); - sz += " ~ "; - sz += itos(-aabb.neg_max.y); - sz += ") ("; + String sz; + float vol = 0.0; - sz += itos(aabb.min.z); - sz += " ~ "; - sz += itos(-aabb.neg_max.z); - sz += ") "; + for (int i = 0; i < Point::AXES_COUNT; ++i) { + sz += "("; + sz += itos(aabb.min[i]); + sz += " ~ "; + sz += itos(-aabb.neg_max[i]); + sz += ") "; + + vol += size[i]; + } - Vector3 size = aabb.calculate_size(); - float vol = size.x * size.y * size.z; sz += "vol " + itos(vol); return sz; diff --git a/core/math/bvh_split.inc b/core/math/bvh_split.inc index 3fcc4c7b101..72c37abe0ec 100644 --- a/core/math/bvh_split.inc +++ b/core/math/bvh_split.inc @@ -28,11 +28,15 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u Point centre = full_bound.calculate_centre(); Point size = full_bound.calculate_size(); - int order[3]; + int order[Point::AXIS_COUNT]; order[0] = size.min_axis(); - order[2] = size.max_axis(); - order[1] = 3 - (order[0] + order[2]); + order[Point::AXIS_COUNT - 1] = size.max_axis(); + + static_assert(Point::AXIS_COUNT <= 3, "BVH Point::AXIS_COUNT has unexpected size"); + if (Point::AXIS_COUNT == 3) { + order[1] = 3 - (order[0] + order[2]); + } // simplest case, split on the longest axis int split_axis = order[0]; @@ -54,7 +58,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u // detect when split on longest axis failed int min_threshold = MAX_ITEMS / 4; - int min_group_size[3]; + int min_group_size[Point::AXIS_COUNT]; min_group_size[0] = MIN(num_a, num_b); if (min_group_size[0] < min_threshold) { // slow but sure .. first move everything back into a @@ -64,7 +68,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u num_b = 0; // now calculate the best split - for (int axis = 1; axis < 3; axis++) { + for (int axis = 1; axis < Point::AXIS_COUNT; axis++) { split_axis = order[axis]; int count = 0; @@ -82,7 +86,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u // best axis int best_axis = 0; int best_min = min_group_size[0]; - for (int axis = 1; axis < 3; axis++) { + for (int axis = 1; axis < Point::AXIS_COUNT; axis++) { if (min_group_size[axis] > best_min) { best_min = min_group_size[axis]; best_axis = axis; diff --git a/core/object.cpp b/core/object.cpp index 2802b6c537d..424e7c3a258 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1540,7 +1540,7 @@ void Object::_disconnect(const StringName &p_signal, Object *p_to_object, const if (!p_force) { slot->reference_count--; // by default is zero, if it was not referenced it will go below it - if (slot->reference_count >= 0) { + if (slot->reference_count > 0) { return; } } diff --git a/core/os/thread.cpp b/core/os/thread.cpp index 97d53c1b0d2..621fd7f4478 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -28,9 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -// Define PLATFORM_CUSTOM_THREAD_H in platform_config.h -// Overriding the platform implementation is required in some proprietary platforms -#ifndef PLATFORM_CUSTOM_THREAD_H +#ifndef PLATFORM_THREAD_OVERRIDE // See details in thread.h #include "thread.h" @@ -138,4 +136,4 @@ Thread::ID Thread::get_caller_id() { } } #endif -#endif // PLATFORM_CUSTOM_THREAD_H +#endif // PLATFORM_THREAD_OVERRIDE diff --git a/core/os/thread.h b/core/os/thread.h index 2f2c3e557d2..732de607189 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -28,10 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -// Define PLATFORM_CUSTOM_THREAD_H in platform_config.h +// Define PLATFORM_THREAD_OVERRIDE in your platform's `platform_config.h` +// to use a custom Thread implementation defined in `platform/[your_platform]/platform_thread.h` // Overriding the platform implementation is required in some proprietary platforms -#ifdef PLATFORM_CUSTOM_THREAD_H -#include PLATFORM_CUSTOM_THREAD_H +#ifdef PLATFORM_THREAD_OVERRIDE +#include "platform_thread.h" #else #ifndef THREAD_H #define THREAD_H @@ -119,4 +120,4 @@ public: }; #endif // THREAD_H -#endif // PLATFORM_CUSTOM_THREAD_H +#endif // PLATFORM_THREAD_OVERRIDE diff --git a/doc/classes/Dictionary.xml b/doc/classes/Dictionary.xml index 8c48699c70a..691c0ea9455 100644 --- a/doc/classes/Dictionary.xml +++ b/doc/classes/Dictionary.xml @@ -29,7 +29,7 @@ some_key = 42, } [/codeblock] - You can access a dictionary's values by referencing the appropriate key. In the above example, [code]points_dir["White"][/code] will return [code]50[/code]. You can also write [code]points_dir.White[/code], which is equivalent. However, you'll have to use the bracket syntax if the key you're accessing the dictionary with isn't a fixed string (such as a number or variable). + You can access a dictionary's values by referencing the appropriate key. In the above example, [code]points_dict["White"][/code] will return [code]50[/code]. You can also write [code]points_dict.White[/code], which is equivalent. However, you'll have to use the bracket syntax if the key you're accessing the dictionary with isn't a fixed string (such as a number or variable). [codeblock] export(string, "White", "Yellow", "Orange") var my_color var points_dict = {"White": 50, "Yellow": 75, "Orange": 100} @@ -50,7 +50,7 @@ Finally, dictionaries can contain different types of keys and values in the same dictionary: [codeblock] # This is a valid dictionary. - # To access the string "Nested value" below, use `my_dir.sub_dir.sub_key` or `my_dir["sub_dir"]["sub_key"]`. + # To access the string "Nested value" below, use `my_dict.sub_dict.sub_key` or `my_dict["sub_dict"]["sub_key"]`. # Indexing styles can be mixed and matched depending on your needs. var my_dict = { "String Key": 5, diff --git a/doc/classes/SurfaceTool.xml b/doc/classes/SurfaceTool.xml index e50a1683f6f..f04dd3a3741 100644 --- a/doc/classes/SurfaceTool.xml +++ b/doc/classes/SurfaceTool.xml @@ -170,14 +170,14 @@ - Generates normals from vertices so you do not have to do it manually. If [code]flip[/code] is [code]true[/code], the resulting normals will be inverted. [method generate_normals] should be called [i]after[/i] generating geometry and [i]before[/i] committing the mesh using [method commit] or [method commit_to_arrays]. + Generates normals from vertices so you do not have to do it manually. If [code]flip[/code] is [code]true[/code], the resulting normals will be inverted. [method generate_normals] should be called [i]after[/i] generating geometry and [i]before[/i] committing the mesh using [method commit] or [method commit_to_arrays]. For correct display of normal-mapped surfaces, you will also have to generate tangents using [method generate_tangents]. [b]Note:[/b] [method generate_normals] only works if the primitive type to be set to [constant Mesh.PRIMITIVE_TRIANGLES]. - Generates a tangent vector for each vertex. Requires that each vertex have UVs and normals set already. + Generates a tangent vector for each vertex. Requires that each vertex have UVs and normals set already (see [method generate_normals]). diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index 2b65e99bd01..9d68bf8bd4a 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -257,6 +257,11 @@ Error DirAccessWindows::rename(String p_path, String p_new_path) { // If we're only changing file name case we need to do a little juggling if (p_path.to_lower() == p_new_path.to_lower()) { + if (dir_exists(p_path)) { + // The path is a dir; just rename + return ::_wrename(p_path.c_str(), p_new_path.c_str()) == 0 ? OK : FAILED; + } + // The path is a file; juggle WCHAR tmpfile[MAX_PATH]; if (!GetTempFileNameW(fix_path(get_current_dir()).c_str(), NULL, 0, tmpfile)) { diff --git a/misc/dist/osx_tools.app/Contents/Resources/Godot.icns b/misc/dist/osx_tools.app/Contents/Resources/Godot.icns index be9254630c7..61697976c64 100644 Binary files a/misc/dist/osx_tools.app/Contents/Resources/Godot.icns and b/misc/dist/osx_tools.app/Contents/Resources/Godot.icns differ diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp index 16dc7d26910..48df8180fa1 100644 --- a/modules/bmp/image_loader_bmp.cpp +++ b/modules/bmp/image_loader_bmp.cpp @@ -91,11 +91,13 @@ Error ImageLoaderBMP::convert_to_image(Ref p_image, // the data width in case of 8/4/1 bit images const uint32_t w = bits_per_pixel >= 24 ? width : width_bytes; const uint8_t *line = p_buffer + (line_width * (height - 1)); + const uint8_t *end_buffer = p_buffer + p_header.bmp_file_header.bmp_file_size - p_header.bmp_file_header.bmp_file_offset; for (uint64_t i = 0; i < height; i++) { const uint8_t *line_ptr = line; for (unsigned int j = 0; j < w; j++) { + ERR_FAIL_COND_V(line_ptr >= end_buffer, ERR_FILE_CORRUPT); switch (bits_per_pixel) { case 1: { uint8_t color_index = *line_ptr; diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index de1c54f2a8d..50934012e2e 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -833,7 +833,8 @@ - Returns an array with the given range. Range can be 1 argument N (0 to N-1), two arguments (initial, final-1) or three arguments (initial, final-1, increment). + Returns an array with the given range. Range can be 1 argument [code]N[/code] (0 to [code]N[/code] - 1), two arguments ([code]initial[/code], [code]final - 1[/code]) or three arguments ([code]initial[/code], [code]final - 1[/code], [code]increment[/code]). Returns an empty array if the range isn't valid (e.g. [code]range(2, 5, -1)[/code] or [code]range(5, 5, 1)[/code]). + Returns an array with the given range. [code]range()[/code] can have 1 argument N ([code]0[/code] to [code]N - 1[/code]), two arguments ([code]initial[/code], [code]final - 1[/code]) or three arguments ([code]initial[/code], [code]final - 1[/code], [code]increment[/code]). [code]increment[/code] can be negative. If [code]increment[/code] is negative, [code]final - 1[/code] will become [code]final + 1[/code]. Also, the initial value must be greater than the final value for the loop to run. [codeblock] print(range(4)) print(range(2, 5)) @@ -845,6 +846,20 @@ [2, 3, 4] [0, 2, 4] [/codeblock] + To iterate over an [Array] backwards, use: + [codeblock] + var array = [3, 6, 9] + var i := array.size() - 1 + while i >= 0: + print(array[i]) + i -= 1 + [/codeblock] + Output: + [codeblock] + 9 + 6 + 3 + [/codeblock] diff --git a/modules/upnp/doc_classes/UPNP.xml b/modules/upnp/doc_classes/UPNP.xml index 04c1641891e..d8ecec6ac6b 100644 --- a/modules/upnp/doc_classes/UPNP.xml +++ b/modules/upnp/doc_classes/UPNP.xml @@ -16,6 +16,38 @@ [codeblock] upnp.delete_port_mapping(port) [/codeblock] + [b]Note:[/b] UPnP discovery blocks the current thread. To perform discovery without blocking the main thread, use [Thread]s like this: + [codeblock] + # Emitted when UPnP port mapping setup is completed (regardless of success or failure). + signal upnp_completed(error) + + # Replace this with your own server port number between 1025 and 65535. + const SERVER_PORT = 3928 + var thread = null + + func _upnp_setup(server_port): + # UPNP queries take some time. + var upnp = UPNP.new() + var err = upnp.discover() + + if err != OK: + push_error(str(err)) + emit_signal("upnp_completed", err) + return + + if upnp.get_gateway() and upnp.get_gateway().is_valid_gateway(): + upnp.add_port_mapping(server_port, server_port, ProjectSettings.get_setting("application/config/name"), "UDP") + upnp.add_port_mapping(server_port, server_port, ProjectSettings.get_setting("application/config/name"), "TCP") + emit_signal("upnp_completed", OK) + + func _ready(): + thread = Thread.new() + thread.start(self, "_upnp_setup", SERVER_PORT) + + func _exit_tree(): + # Wait for thread finish here to handle game exit while the thread is running. + thread.wait_to_finish() + [/codeblock] diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index c54b06dac31..f66dcee5379 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -327,11 +327,17 @@ float AnimationNodeStateMachinePlayback::process(AnimationNodeStateMachine *p_st } } else { // teleport to start - path.clear(); - current = start_request; - playing = true; - play_start = true; - start_request = StringName(); //clear start request + if (p_state_machine->states.has(start_request)) { + path.clear(); + current = start_request; + playing = true; + play_start = true; + start_request = StringName(); //clear start request + } else { + StringName node = start_request; + start_request = StringName(); //clear start request + ERR_FAIL_V_MSG(0, "No such node: '" + node + "'"); + } } }