diff options
86 files changed, 465 insertions, 284 deletions
diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index d3b0039e72..fe9e468774 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -527,7 +527,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } } else if (command == "set_skip_breakpoints") { - ERR_FAIL_COND(data.size() < 1); + ERR_FAIL_COND(data.is_empty()); script_debugger->set_skip_breakpoints(data[0]); } else { bool captured = false; @@ -631,7 +631,7 @@ Error RemoteDebugger::_core_capture(const String &p_cmd, const Array &p_data, bo } } else if (p_cmd == "set_skip_breakpoints") { - ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_data.is_empty(), ERR_INVALID_DATA); script_debugger->set_skip_breakpoints(p_data[0]); } else if (p_cmd == "break") { script_debugger->debug(script_debugger->get_break_language()); @@ -643,7 +643,7 @@ Error RemoteDebugger::_core_capture(const String &p_cmd, const Array &p_data, bo Error RemoteDebugger::_profiler_capture(const String &p_cmd, const Array &p_data, bool &r_captured) { r_captured = false; - ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_data.is_empty(), ERR_INVALID_DATA); ERR_FAIL_COND_V(p_data[0].get_type() != Variant::BOOL, ERR_INVALID_DATA); ERR_FAIL_COND_V(!has_profiler(p_cmd), ERR_UNAVAILABLE); Array opts; diff --git a/core/input/input.cpp b/core/input/input.cpp index 4e33d3087d..d87a8824f7 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -130,6 +130,7 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("set_magnetometer", "value"), &Input::set_magnetometer); ClassDB::bind_method(D_METHOD("set_gyroscope", "value"), &Input::set_gyroscope); ClassDB::bind_method(D_METHOD("get_last_mouse_velocity"), &Input::get_last_mouse_velocity); + ClassDB::bind_method(D_METHOD("get_last_mouse_screen_velocity"), &Input::get_last_mouse_screen_velocity); ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask); ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &Input::set_mouse_mode); ClassDB::bind_method(D_METHOD("get_mouse_mode"), &Input::get_mouse_mode); @@ -201,7 +202,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S Object::get_argument_options(p_function, p_idx, r_options); } -void Input::VelocityTrack::update(const Vector2 &p_delta_p) { +void Input::VelocityTrack::update(const Vector2 &p_delta_p, const Vector2 &p_screen_delta_p) { uint64_t tick = OS::get_singleton()->get_ticks_usec(); uint32_t tdiff = tick - last_tick; float delta_t = tdiff / 1000000.0; @@ -210,12 +211,15 @@ void Input::VelocityTrack::update(const Vector2 &p_delta_p) { if (delta_t > max_ref_frame) { // First movement in a long time, reset and start again. velocity = Vector2(); + screen_velocity = Vector2(); accum = p_delta_p; + screen_accum = p_screen_delta_p; accum_t = 0; return; } accum += p_delta_p; + screen_accum += p_screen_delta_p; accum_t += delta_t; if (accum_t < min_ref_frame) { @@ -224,6 +228,7 @@ void Input::VelocityTrack::update(const Vector2 &p_delta_p) { } velocity = accum / accum_t; + screen_velocity = screen_accum / accum_t; accum = Vector2(); accum_t = 0; } @@ -594,7 +599,8 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em set_mouse_position(position); } Vector2 relative = mm->get_relative(); - mouse_velocity_track.update(relative); + Vector2 screen_relative = mm->get_relative_screen_position(); + mouse_velocity_track.update(relative, screen_relative); if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) { Ref<InputEventScreenDrag> drag_event; @@ -602,10 +608,12 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em drag_event->set_position(position); drag_event->set_relative(relative); + drag_event->set_relative_screen_position(screen_relative); drag_event->set_tilt(mm->get_tilt()); drag_event->set_pen_inverted(mm->get_pen_inverted()); drag_event->set_pressure(mm->get_pressure()); drag_event->set_velocity(get_last_mouse_velocity()); + drag_event->set_screen_velocity(get_last_mouse_screen_velocity()); drag_event->set_device(InputEvent::DEVICE_ID_EMULATION); _THREAD_SAFE_UNLOCK_ @@ -669,8 +677,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (sd.is_valid()) { VelocityTrack &track = touch_velocity_track[sd->get_index()]; - track.update(sd->get_relative()); + track.update(sd->get_relative(), sd->get_relative_screen_position()); sd->set_velocity(track.velocity); + sd->set_screen_velocity(track.screen_velocity); if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) { Ref<InputEventMouseMotion> motion_event; @@ -683,7 +692,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em motion_event->set_position(sd->get_position()); motion_event->set_global_position(sd->get_position()); motion_event->set_relative(sd->get_relative()); + motion_event->set_relative_screen_position(sd->get_relative_screen_position()); motion_event->set_velocity(sd->get_velocity()); + motion_event->set_screen_velocity(sd->get_screen_velocity()); motion_event->set_button_mask(mouse_button_mask); _parse_input_event_impl(motion_event, true); @@ -827,10 +838,15 @@ Point2 Input::get_mouse_position() const { } Point2 Input::get_last_mouse_velocity() { - mouse_velocity_track.update(Vector2()); + mouse_velocity_track.update(Vector2(), Vector2()); return mouse_velocity_track.velocity; } +Point2 Input::get_last_mouse_screen_velocity() { + mouse_velocity_track.update(Vector2(), Vector2()); + return mouse_velocity_track.screen_velocity; +} + BitField<MouseButtonMask> Input::get_mouse_button_mask() const { return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state(); } diff --git a/core/input/input.h b/core/input/input.h index b98406e884..a7ae3349b2 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -145,12 +145,14 @@ private: struct VelocityTrack { uint64_t last_tick = 0; Vector2 velocity; + Vector2 screen_velocity; Vector2 accum; + Vector2 screen_accum; float accum_t = 0.0f; float min_ref_frame; float max_ref_frame; - void update(const Vector2 &p_delta_p); + void update(const Vector2 &p_delta_p, const Vector2 &p_screen_delta_p); void reset(); VelocityTrack(); }; @@ -302,6 +304,7 @@ public: Point2 get_mouse_position() const; Vector2 get_last_mouse_velocity(); + Vector2 get_last_mouse_screen_velocity(); BitField<MouseButtonMask> get_mouse_button_mask() const; void warp_mouse(const Vector2 &p_position); diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 89ffcecf50..bd1fde5a85 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -927,6 +927,14 @@ Vector2 InputEventMouseMotion::get_relative() const { return relative; } +void InputEventMouseMotion::set_relative_screen_position(const Vector2 &p_relative) { + screen_relative = p_relative; +} + +Vector2 InputEventMouseMotion::get_relative_screen_position() const { + return screen_relative; +} + void InputEventMouseMotion::set_velocity(const Vector2 &p_velocity) { velocity = p_velocity; } @@ -935,6 +943,14 @@ Vector2 InputEventMouseMotion::get_velocity() const { return velocity; } +void InputEventMouseMotion::set_screen_velocity(const Vector2 &p_velocity) { + screen_velocity = p_velocity; +} + +Vector2 InputEventMouseMotion::get_screen_velocity() const { + return screen_velocity; +} + Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Ref<InputEventMouseMotion> mm; mm.instantiate(); @@ -952,7 +968,9 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co mm->set_button_mask(get_button_mask()); mm->set_relative(p_xform.basis_xform(get_relative())); + mm->set_relative_screen_position(get_relative_screen_position()); mm->set_velocity(p_xform.basis_xform(get_velocity())); + mm->set_screen_velocity(get_screen_velocity()); return mm; } @@ -1027,7 +1045,9 @@ bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) { set_position(motion->get_position()); set_global_position(motion->get_global_position()); set_velocity(motion->get_velocity()); + set_screen_velocity(motion->get_screen_velocity()); relative += motion->get_relative(); + screen_relative += motion->get_relative_screen_position(); return true; } @@ -1045,14 +1065,22 @@ void InputEventMouseMotion::_bind_methods() { ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative); ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative); + ClassDB::bind_method(D_METHOD("set_screen_relative", "relative"), &InputEventMouseMotion::set_relative_screen_position); + ClassDB::bind_method(D_METHOD("get_screen_relative"), &InputEventMouseMotion::get_relative_screen_position); + ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &InputEventMouseMotion::set_velocity); ClassDB::bind_method(D_METHOD("get_velocity"), &InputEventMouseMotion::get_velocity); + ClassDB::bind_method(D_METHOD("set_screen_velocity", "velocity"), &InputEventMouseMotion::set_screen_velocity); + ClassDB::bind_method(D_METHOD("get_screen_velocity"), &InputEventMouseMotion::get_screen_velocity); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pressure"), "set_pressure", "get_pressure"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pen_inverted"), "set_pen_inverted", "get_pen_inverted"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative", PROPERTY_HINT_NONE, "suffix:px"), "set_relative", "get_relative"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "screen_relative", PROPERTY_HINT_NONE, "suffix:px"), "set_screen_relative", "get_screen_relative"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "velocity", PROPERTY_HINT_NONE, "suffix:px/s"), "set_velocity", "get_velocity"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "screen_velocity", PROPERTY_HINT_NONE, "suffix:px/s"), "set_screen_velocity", "get_screen_velocity"); } /////////////////////////////////// @@ -1422,6 +1450,14 @@ Vector2 InputEventScreenDrag::get_relative() const { return relative; } +void InputEventScreenDrag::set_relative_screen_position(const Vector2 &p_relative) { + screen_relative = p_relative; +} + +Vector2 InputEventScreenDrag::get_relative_screen_position() const { + return screen_relative; +} + void InputEventScreenDrag::set_velocity(const Vector2 &p_velocity) { velocity = p_velocity; } @@ -1430,6 +1466,14 @@ Vector2 InputEventScreenDrag::get_velocity() const { return velocity; } +void InputEventScreenDrag::set_screen_velocity(const Vector2 &p_velocity) { + screen_velocity = p_velocity; +} + +Vector2 InputEventScreenDrag::get_screen_velocity() const { + return screen_velocity; +} + Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Ref<InputEventScreenDrag> sd; @@ -1444,7 +1488,9 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con sd->set_tilt(get_tilt()); sd->set_position(p_xform.xform(pos + p_local_ofs)); sd->set_relative(p_xform.basis_xform(relative)); + sd->set_relative_screen_position(get_relative_screen_position()); sd->set_velocity(p_xform.basis_xform(velocity)); + sd->set_screen_velocity(get_screen_velocity()); return sd; } @@ -1469,7 +1515,9 @@ bool InputEventScreenDrag::accumulate(const Ref<InputEvent> &p_event) { set_position(drag->get_position()); set_velocity(drag->get_velocity()); + set_screen_velocity(drag->get_screen_velocity()); relative += drag->get_relative(); + screen_relative += drag->get_relative_screen_position(); return true; } @@ -1493,16 +1541,24 @@ void InputEventScreenDrag::_bind_methods() { ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative); ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative); + ClassDB::bind_method(D_METHOD("set_screen_relative", "relative"), &InputEventScreenDrag::set_relative_screen_position); + ClassDB::bind_method(D_METHOD("get_screen_relative"), &InputEventScreenDrag::get_relative_screen_position); + ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &InputEventScreenDrag::set_velocity); ClassDB::bind_method(D_METHOD("get_velocity"), &InputEventScreenDrag::get_velocity); + ClassDB::bind_method(D_METHOD("set_screen_velocity", "velocity"), &InputEventScreenDrag::set_screen_velocity); + ClassDB::bind_method(D_METHOD("get_screen_velocity"), &InputEventScreenDrag::get_screen_velocity); + ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pressure"), "set_pressure", "get_pressure"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pen_inverted"), "set_pen_inverted", "get_pen_inverted"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "suffix:px"), "set_position", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative", PROPERTY_HINT_NONE, "suffix:px"), "set_relative", "get_relative"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "screen_relative", PROPERTY_HINT_NONE, "suffix:px"), "set_screen_relative", "get_screen_relative"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "velocity", PROPERTY_HINT_NONE, "suffix:px/s"), "set_velocity", "get_velocity"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "screen_velocity", PROPERTY_HINT_NONE, "suffix:px/s"), "set_screen_velocity", "get_screen_velocity"); } /////////////////////////////////// diff --git a/core/input/input_event.h b/core/input/input_event.h index 61a53116e9..21b61f3bc2 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -271,7 +271,9 @@ class InputEventMouseMotion : public InputEventMouse { Vector2 tilt; float pressure = 0; Vector2 relative; + Vector2 screen_relative; Vector2 velocity; + Vector2 screen_velocity; bool pen_inverted = false; protected: @@ -290,9 +292,15 @@ public: void set_relative(const Vector2 &p_relative); Vector2 get_relative() const; + void set_relative_screen_position(const Vector2 &p_relative); + Vector2 get_relative_screen_position() const; + void set_velocity(const Vector2 &p_velocity); Vector2 get_velocity() const; + void set_screen_velocity(const Vector2 &p_velocity); + Vector2 get_screen_velocity() const; + virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override; virtual String as_text() const override; virtual String to_string() override; @@ -393,7 +401,9 @@ class InputEventScreenDrag : public InputEventFromWindow { int index = 0; Vector2 pos; Vector2 relative; + Vector2 screen_relative; Vector2 velocity; + Vector2 screen_velocity; Vector2 tilt; float pressure = 0; bool pen_inverted = false; @@ -420,9 +430,15 @@ public: void set_relative(const Vector2 &p_relative); Vector2 get_relative() const; + void set_relative_screen_position(const Vector2 &p_relative); + Vector2 get_relative_screen_position() const; + void set_velocity(const Vector2 &p_velocity); Vector2 get_velocity() const; + void set_screen_velocity(const Vector2 &p_velocity); + Vector2 get_screen_velocity() const; + virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override; virtual String as_text() const override; virtual String to_string() override; diff --git a/core/io/image.cpp b/core/io/image.cpp index 9aa7c9794a..24caccca5f 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -1029,7 +1029,7 @@ void Image::resize_to_po2(bool p_square, Interpolation p_interpolation) { } void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { - ERR_FAIL_COND_MSG(data.size() == 0, "Cannot resize image before creating it, use set_data() first."); + ERR_FAIL_COND_MSG(data.is_empty(), "Cannot resize image before creating it, use set_data() first."); ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats."); bool mipmap_aware = p_interpolation == INTERPOLATE_TRILINEAR /* || p_interpolation == INTERPOLATE_TRICUBIC */; @@ -1700,7 +1700,7 @@ static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint3 } void Image::shrink_x2() { - ERR_FAIL_COND(data.size() == 0); + ERR_FAIL_COND(data.is_empty()); if (mipmaps) { //just use the lower mipmap as base and copy all @@ -1710,7 +1710,7 @@ void Image::shrink_x2() { int new_size = data.size() - ofs; new_img.resize(new_size); - ERR_FAIL_COND(new_img.size() == 0); + ERR_FAIL_COND(new_img.is_empty()); { uint8_t *w = new_img.ptrw(); @@ -1729,8 +1729,8 @@ void Image::shrink_x2() { ERR_FAIL_COND(!_can_modify(format)); int ps = get_format_pixel_size(format); new_img.resize((width / 2) * (height / 2) * ps); - ERR_FAIL_COND(new_img.size() == 0); - ERR_FAIL_COND(data.size() == 0); + ERR_FAIL_COND(new_img.is_empty()); + ERR_FAIL_COND(data.is_empty()); { uint8_t *w = new_img.ptrw(); @@ -2781,7 +2781,7 @@ void Image::_get_clipped_src_and_dest_rects(const Ref<Image> &p_src, const Rect2 } void Image::blit_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); + ERR_FAIL_COND_MSG(p_src.is_null(), "Cannot blit_rect an image: invalid source Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); ERR_FAIL_COND(dsize == 0); @@ -2823,8 +2823,8 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const P } void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2i &p_src_rect, const Point2i &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); - ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object."); + ERR_FAIL_COND_MSG(p_src.is_null(), "Cannot blit_rect_mask an image: invalid source Image object."); + ERR_FAIL_COND_MSG(p_mask.is_null(), "Cannot blit_rect_mask an image: invalid mask Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); int maskdsize = p_mask->data.size(); @@ -2873,7 +2873,7 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co } void Image::blend_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); + ERR_FAIL_COND_MSG(p_src.is_null(), "Cannot blend_rect an image: invalid source Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); ERR_FAIL_COND(dsize == 0); @@ -2908,8 +2908,8 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const } void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2i &p_src_rect, const Point2i &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); - ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object."); + ERR_FAIL_COND_MSG(p_src.is_null(), "Cannot blend_rect_mask an image: invalid source Image object."); + ERR_FAIL_COND_MSG(p_mask.is_null(), "Cannot blend_rect_mask an image: invalid mask Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); int maskdsize = p_mask->data.size(); @@ -3323,7 +3323,7 @@ void Image::adjust_bcs(float p_brightness, float p_contrast, float p_saturation) } Image::UsedChannels Image::detect_used_channels(CompressSource p_source) const { - ERR_FAIL_COND_V(data.size() == 0, USED_CHANNELS_RGBA); + ERR_FAIL_COND_V(data.is_empty(), USED_CHANNELS_RGBA); ERR_FAIL_COND_V(is_compressed(), USED_CHANNELS_RGBA); bool r = false, g = false, b = false, a = false, c = false; @@ -3878,7 +3878,7 @@ Error Image::load_ktx_from_buffer(const Vector<uint8_t> &p_array) { void Image::convert_rg_to_ra_rgba8() { ERR_FAIL_COND(format != FORMAT_RGBA8); - ERR_FAIL_COND(!data.size()); + ERR_FAIL_COND(data.is_empty()); int s = data.size(); uint8_t *w = data.ptrw(); @@ -3891,7 +3891,7 @@ void Image::convert_rg_to_ra_rgba8() { void Image::convert_ra_rgba8_to_rg() { ERR_FAIL_COND(format != FORMAT_RGBA8); - ERR_FAIL_COND(!data.size()); + ERR_FAIL_COND(data.is_empty()); int s = data.size(); uint8_t *w = data.ptrw(); @@ -3904,7 +3904,7 @@ void Image::convert_ra_rgba8_to_rg() { void Image::convert_rgba8_to_bgra8() { ERR_FAIL_COND(format != FORMAT_RGBA8); - ERR_FAIL_COND(!data.size()); + ERR_FAIL_COND(data.is_empty()); int s = data.size(); uint8_t *w = data.ptrw(); diff --git a/core/io/image.h b/core/io/image.h index be308b0ac1..e35b359a79 100644 --- a/core/io/image.h +++ b/core/io/image.h @@ -431,7 +431,7 @@ public: void set_as_black(); void copy_internals_from(const Ref<Image> &p_image) { - ERR_FAIL_COND_MSG(p_image.is_null(), "It's not a reference to a valid Image object."); + ERR_FAIL_COND_MSG(p_image.is_null(), "Cannot copy image internals: invalid Image object."); format = p_image->format; width = p_image->width; height = p_image->height; diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index c6452f1033..bef515f259 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -81,7 +81,7 @@ void ImageFormatLoaderExtension::_bind_methods() { } Error ImageLoader::load_image(String p_file, Ref<Image> p_image, Ref<FileAccess> p_custom, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) { - ERR_FAIL_COND_V_MSG(p_image.is_null(), ERR_INVALID_PARAMETER, "It's not a reference to a valid Image object."); + ERR_FAIL_COND_V_MSG(p_image.is_null(), ERR_INVALID_PARAMETER, "Can't load an image: invalid Image object."); Ref<FileAccess> f = p_custom; if (f.is_null()) { diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index faf7d75172..06888c7cda 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -454,7 +454,7 @@ bool XMLParser::is_empty() const { } Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) { - ERR_FAIL_COND_V(p_buffer.size() == 0, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_buffer.is_empty(), ERR_INVALID_DATA); if (data_copy) { memdelete_arr(data_copy); diff --git a/core/math/geometry_2d.cpp b/core/math/geometry_2d.cpp index 74cb92539a..1e5f12bebf 100644 --- a/core/math/geometry_2d.cpp +++ b/core/math/geometry_2d.cpp @@ -93,7 +93,7 @@ void Geometry2D::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_re // For example, it will prioritize a 1024x1024 atlas (works everywhere) instead of a // 256x8192 atlas (won't work anywhere). - ERR_FAIL_COND(p_rects.size() == 0); + ERR_FAIL_COND(p_rects.is_empty()); for (int i = 0; i < p_rects.size(); i++) { ERR_FAIL_COND(p_rects[i].width <= 0); ERR_FAIL_COND(p_rects[i].height <= 0); diff --git a/core/variant/array.cpp b/core/variant/array.cpp index ab0315ae34..5d6fbb8bed 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -316,17 +316,17 @@ void Array::erase(const Variant &p_value) { } Variant Array::front() const { - ERR_FAIL_COND_V_MSG(_p->array.size() == 0, Variant(), "Can't take value from empty array."); + ERR_FAIL_COND_V_MSG(_p->array.is_empty(), Variant(), "Can't take value from empty array."); return operator[](0); } Variant Array::back() const { - ERR_FAIL_COND_V_MSG(_p->array.size() == 0, Variant(), "Can't take value from empty array."); + ERR_FAIL_COND_V_MSG(_p->array.is_empty(), Variant(), "Can't take value from empty array."); return operator[](_p->array.size() - 1); } Variant Array::pick_random() const { - ERR_FAIL_COND_V_MSG(_p->array.size() == 0, Variant(), "Can't take value from empty array."); + ERR_FAIL_COND_V_MSG(_p->array.is_empty(), Variant(), "Can't take value from empty array."); return operator[](Math::rand() % _p->array.size()); } diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 90f7e7b44a..b551a7059e 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -885,7 +885,7 @@ struct _VariantCall { ERR_FAIL_COND_V_MSG(size % sizeof(int32_t), dest, "PackedByteArray size must be a multiple of 4 (size of 32-bit integer) to convert to PackedInt32Array."); const uint8_t *r = p_instance->ptr(); dest.resize(size / sizeof(int32_t)); - ERR_FAIL_COND_V(dest.size() == 0, dest); // Avoid UB in case resize failed. + ERR_FAIL_COND_V(dest.is_empty(), dest); // Avoid UB in case resize failed. memcpy(dest.ptrw(), r, dest.size() * sizeof(int32_t)); return dest; } @@ -899,7 +899,7 @@ struct _VariantCall { ERR_FAIL_COND_V_MSG(size % sizeof(int64_t), dest, "PackedByteArray size must be a multiple of 8 (size of 64-bit integer) to convert to PackedInt64Array."); const uint8_t *r = p_instance->ptr(); dest.resize(size / sizeof(int64_t)); - ERR_FAIL_COND_V(dest.size() == 0, dest); // Avoid UB in case resize failed. + ERR_FAIL_COND_V(dest.is_empty(), dest); // Avoid UB in case resize failed. memcpy(dest.ptrw(), r, dest.size() * sizeof(int64_t)); return dest; } @@ -913,7 +913,7 @@ struct _VariantCall { ERR_FAIL_COND_V_MSG(size % sizeof(float), dest, "PackedByteArray size must be a multiple of 4 (size of 32-bit float) to convert to PackedFloat32Array."); const uint8_t *r = p_instance->ptr(); dest.resize(size / sizeof(float)); - ERR_FAIL_COND_V(dest.size() == 0, dest); // Avoid UB in case resize failed. + ERR_FAIL_COND_V(dest.is_empty(), dest); // Avoid UB in case resize failed. memcpy(dest.ptrw(), r, dest.size() * sizeof(float)); return dest; } @@ -927,7 +927,7 @@ struct _VariantCall { ERR_FAIL_COND_V_MSG(size % sizeof(double), dest, "PackedByteArray size must be a multiple of 8 (size of 64-bit double) to convert to PackedFloat64Array."); const uint8_t *r = p_instance->ptr(); dest.resize(size / sizeof(double)); - ERR_FAIL_COND_V(dest.size() == 0, dest); // Avoid UB in case resize failed. + ERR_FAIL_COND_V(dest.is_empty(), dest); // Avoid UB in case resize failed. memcpy(dest.ptrw(), r, dest.size() * sizeof(double)); return dest; } diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml index fc162b0761..bb84813835 100644 --- a/doc/classes/Input.xml +++ b/doc/classes/Input.xml @@ -156,6 +156,12 @@ Returns the strength of the joypad vibration: x is the strength of the weak motor, and y is the strength of the strong motor. </description> </method> + <method name="get_last_mouse_screen_velocity"> + <return type="Vector2" /> + <description> + Returns the last mouse velocity in screen coordinates. To provide a precise and jitter-free velocity, mouse velocity is only calculated every 0.1s. Therefore, mouse velocity will lag mouse movements. + </description> + </method> <method name="get_last_mouse_velocity"> <return type="Vector2" /> <description> diff --git a/doc/classes/InputEventMouseMotion.xml b/doc/classes/InputEventMouseMotion.xml index 33a50d9daf..e6ec674975 100644 --- a/doc/classes/InputEventMouseMotion.xml +++ b/doc/classes/InputEventMouseMotion.xml @@ -23,12 +23,21 @@ <member name="relative" type="Vector2" setter="set_relative" getter="get_relative" default="Vector2(0, 0)"> The mouse position relative to the previous position (position at the last frame). [b]Note:[/b] Since [InputEventMouseMotion] is only emitted when the mouse moves, the last event won't have a relative position of [code]Vector2(0, 0)[/code] when the user stops moving the mouse. + [b]Note:[/b] [member relative] is automatically scaled according to the content scale factor, which is defined by the project's stretch mode settings. This means mouse sensitivity will appear different depending on resolution when using [member relative] in a script that handles mouse aiming with the [constant Input.MOUSE_MODE_CAPTURED] mouse mode. To avoid this, use [member screen_relative] instead. + </member> + <member name="screen_relative" type="Vector2" setter="set_screen_relative" getter="get_screen_relative" default="Vector2(0, 0)"> + The unscaled mouse position relative to the previous position in the coordinate system of the screen (position at the last frame). + [b]Note:[/b] Since [InputEventMouseMotion] is only emitted when the mouse moves, the last event won't have a relative position of [code]Vector2(0, 0)[/code] when the user stops moving the mouse. This coordinate is [i]not[/i] scaled according to the content scale factor or calls to [method InputEvent.xformed_by]. This should be preferred over [member relative] for mouse aiming when using the [constant Input.MOUSE_MODE_CAPTURED] mouse mode, regardless of the project's stretch mode. + </member> + <member name="screen_velocity" type="Vector2" setter="set_screen_velocity" getter="get_screen_velocity" default="Vector2(0, 0)"> + The unscaled mouse velocity in pixels per second in screen coordinates. This velocity is [i]not[/i] scaled according to the content scale factor or calls to [method InputEvent.xformed_by]. This should be preferred over [member velocity] for mouse aiming when using the [constant Input.MOUSE_MODE_CAPTURED] mouse mode, regardless of the project's stretch mode. </member> <member name="tilt" type="Vector2" setter="set_tilt" getter="get_tilt" default="Vector2(0, 0)"> Represents the angles of tilt of the pen. Positive X-coordinate value indicates a tilt to the right. Positive Y-coordinate value indicates a tilt toward the user. Ranges from [code]-1.0[/code] to [code]1.0[/code] for both axes. </member> <member name="velocity" type="Vector2" setter="set_velocity" getter="get_velocity" default="Vector2(0, 0)"> The mouse velocity in pixels per second. + [b]Note:[/b] [member velocity] is automatically scaled according to the content scale factor, which is defined by the project's stretch mode settings. This means mouse sensitivity will appear different depending on resolution when using [member velocity] in a script that handles mouse aiming with the [constant Input.MOUSE_MODE_CAPTURED] mouse mode. To avoid this, use [member screen_velocity] instead. </member> </members> </class> diff --git a/doc/classes/InputEventScreenDrag.xml b/doc/classes/InputEventScreenDrag.xml index 07c0a87180..bd6c26f561 100644 --- a/doc/classes/InputEventScreenDrag.xml +++ b/doc/classes/InputEventScreenDrag.xml @@ -24,12 +24,20 @@ </member> <member name="relative" type="Vector2" setter="set_relative" getter="get_relative" default="Vector2(0, 0)"> The drag position relative to the previous position (position at the last frame). + [b]Note:[/b] [member relative] is automatically scaled according to the content scale factor, which is defined by the project's stretch mode settings. This means touch sensitivity will appear different depending on resolution when using [member relative] in a script that handles touch aiming. To avoid this, use [member screen_relative] instead. + </member> + <member name="screen_relative" type="Vector2" setter="set_screen_relative" getter="get_screen_relative" default="Vector2(0, 0)"> + The unscaled drag position relative to the previous position in screen coordinates (position at the last frame). This position is [i]not[/i] scaled according to the content scale factor or calls to [method InputEvent.xformed_by]. This should be preferred over [member relative] for touch aiming regardless of the project's stretch mode. + </member> + <member name="screen_velocity" type="Vector2" setter="set_screen_velocity" getter="get_screen_velocity" default="Vector2(0, 0)"> + The unscaled drag velocity in pixels per second in screen coordinates. This velocity is [i]not[/i] scaled according to the content scale factor or calls to [method InputEvent.xformed_by]. This should be preferred over [member velocity] for touch aiming regardless of the project's stretch mode. </member> <member name="tilt" type="Vector2" setter="set_tilt" getter="get_tilt" default="Vector2(0, 0)"> Represents the angles of tilt of the pen. Positive X-coordinate value indicates a tilt to the right. Positive Y-coordinate value indicates a tilt toward the user. Ranges from [code]-1.0[/code] to [code]1.0[/code] for both axes. </member> <member name="velocity" type="Vector2" setter="set_velocity" getter="get_velocity" default="Vector2(0, 0)"> The drag velocity. + [b]Note:[/b] [member velocity] is automatically scaled according to the content scale factor, which is defined by the project's stretch mode settings. This means touch sensitivity will appear different depending on resolution when using [member velocity] in a script that handles touch aiming. To avoid this, use [member screen_velocity] instead. </member> </members> </class> diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 12d7f90bd2..6f65572f34 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2086,8 +2086,11 @@ If in doubt, leave this setting empty. </member> <member name="physics/2d/default_angular_damp" type="float" setter="" getter="" default="1.0"> - The default angular damp in 2D. - [b]Note:[/b] Good values are in the range [code]0[/code] to [code]1[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Values greater than [code]1[/code] will aim to reduce the velocity to [code]0[/code] in less than a second e.g. a value of [code]2[/code] will aim to reduce the velocity to [code]0[/code] in half a second. A value equal to or greater than the physics frame rate ([member ProjectSettings.physics/common/physics_ticks_per_second], [code]60[/code] by default) will bring the object to a stop in one iteration. + The default rotational motion damping in 2D. Damping is used to gradually slow down physical objects over time. RigidBodies will fall back to this value when combining their own damping values and no area damping value is present. + Suggested values are in the range [code]0[/code] to [code]30[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Greater values will stop the object faster. A value equal to or greater than the physics tick rate ([member physics/common/physics_ticks_per_second]) will bring the object to a stop in one iteration. + [b]Note:[/b] Godot damping calculations are velocity-dependent, meaning bodies moving faster will take a longer time to come to rest. They do not simulate inertia, friction, or air resistance. Therefore heavier or larger bodies will lose speed at the same proportional rate as lighter or smaller bodies. + During each physics tick, Godot will multiply the linear velocity of RigidBodies by [code]1.0 - combined_damp / physics_ticks_per_second[/code]. By default, bodies combine damp factors: [code]combined_damp[/code] is the sum of the damp value of the body and this value or the area's value the body is in. See [enum RigidBody2D.DampMode]. + [b]Warning:[/b] Godot's damping calculations are simulation tick rate dependent. Changing [member physics/common/physics_ticks_per_second] may significantly change the outcomes and feel of your simulation. This is true for the entire range of damping values greater than 0. To get back to a similar feel, you also need to change your damp values. This needed change is not proportional and differs from case to case. </member> <member name="physics/2d/default_gravity" type="float" setter="" getter="" default="980.0"> The default gravity strength in 2D (in pixels per second squared). @@ -2118,8 +2121,11 @@ [/codeblocks] </member> <member name="physics/2d/default_linear_damp" type="float" setter="" getter="" default="0.1"> - The default linear damp in 2D. - [b]Note:[/b] Good values are in the range [code]0[/code] to [code]1[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Values greater than [code]1[/code] will aim to reduce the velocity to [code]0[/code] in less than a second e.g. a value of [code]2[/code] will aim to reduce the velocity to [code]0[/code] in half a second. A value equal to or greater than the physics frame rate ([member ProjectSettings.physics/common/physics_ticks_per_second], [code]60[/code] by default) will bring the object to a stop in one iteration. + The default linear motion damping in 2D. Damping is used to gradually slow down physical objects over time. RigidBodies will fall back to this value when combining their own damping values and no area damping value is present. + Suggested values are in the range [code]0[/code] to [code]30[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Greater values will stop the object faster. A value equal to or greater than the physics tick rate ([member physics/common/physics_ticks_per_second]) will bring the object to a stop in one iteration. + [b]Note:[/b] Godot damping calculations are velocity-dependent, meaning bodies moving faster will take a longer time to come to rest. They do not simulate inertia, friction, or air resistance. Therefore heavier or larger bodies will lose speed at the same proportional rate as lighter or smaller bodies. + During each physics tick, Godot will multiply the linear velocity of RigidBodies by [code]1.0 - combined_damp / physics_ticks_per_second[/code], where [code]combined_damp[/code] is the sum of the linear damp of the body and this value, or the area's value the body is in, assuming the body defaults to combine damp values. See [enum RigidBody2D.DampMode]. + [b]Warning:[/b] Godot's damping calculations are simulation tick rate dependent. Changing [member physics/common/physics_ticks_per_second] may significantly change the outcomes and feel of your simulation. This is true for the entire range of damping values greater than 0. To get back to a similar feel, you also need to change your damp values. This needed change is not proportional and differs from case to case. </member> <member name="physics/2d/physics_engine" type="String" setter="" getter="" default=""DEFAULT""> Sets which physics engine to use for 2D physics. @@ -2158,8 +2164,11 @@ Time (in seconds) of inactivity before which a 2D physics body will put to sleep. See [constant PhysicsServer2D.SPACE_PARAM_BODY_TIME_TO_SLEEP]. </member> <member name="physics/3d/default_angular_damp" type="float" setter="" getter="" default="0.1"> - The default angular damp in 3D. - [b]Note:[/b] Good values are in the range [code]0[/code] to [code]1[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Values greater than [code]1[/code] will aim to reduce the velocity to [code]0[/code] in less than a second e.g. a value of [code]2[/code] will aim to reduce the velocity to [code]0[/code] in half a second. A value equal to or greater than the physics frame rate ([member ProjectSettings.physics/common/physics_ticks_per_second], [code]60[/code] by default) will bring the object to a stop in one iteration. + The default rotational motion damping in 3D. Damping is used to gradually slow down physical objects over time. RigidBodies will fall back to this value when combining their own damping values and no area damping value is present. + Suggested values are in the range [code]0[/code] to [code]30[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Greater values will stop the object faster. A value equal to or greater than the physics tick rate ([member physics/common/physics_ticks_per_second]) will bring the object to a stop in one iteration. + [b]Note:[/b] Godot damping calculations are velocity-dependent, meaning bodies moving faster will take a longer time to come to rest. They do not simulate inertia, friction, or air resistance. Therefore heavier or larger bodies will lose speed at the same proportional rate as lighter or smaller bodies. + During each physics tick, Godot will multiply the angular velocity of RigidBodies by [code]1.0 - combined_damp / physics_ticks_per_second[/code]. By default, bodies combine damp factors: [code]combined_damp[/code] is the sum of the damp value of the body and this value or the area's value the body is in. See [enum RigidBody3D.DampMode]. + [b]Warning:[/b] Godot's damping calculations are simulation tick rate dependent. Changing [member physics/common/physics_ticks_per_second] may significantly change the outcomes and feel of your simulation. This is true for the entire range of damping values greater than 0. To get back to a similar feel, you also need to change your damp values. This needed change is not proportional and differs from case to case. </member> <member name="physics/3d/default_gravity" type="float" setter="" getter="" default="9.8"> The default gravity strength in 3D (in meters per second squared). @@ -2190,8 +2199,11 @@ [/codeblocks] </member> <member name="physics/3d/default_linear_damp" type="float" setter="" getter="" default="0.1"> - The default linear damp in 3D. - [b]Note:[/b] Good values are in the range [code]0[/code] to [code]1[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Values greater than [code]1[/code] will aim to reduce the velocity to [code]0[/code] in less than a second e.g. a value of [code]2[/code] will aim to reduce the velocity to [code]0[/code] in half a second. A value equal to or greater than the physics frame rate ([member ProjectSettings.physics/common/physics_ticks_per_second], [code]60[/code] by default) will bring the object to a stop in one iteration. + The default linear motion damping in 3D. Damping is used to gradually slow down physical objects over time. RigidBodies will fall back to this value when combining their own damping values and no area damping value is present. + Suggested values are in the range [code]0[/code] to [code]30[/code]. At value [code]0[/code] objects will keep moving with the same velocity. Greater values will stop the object faster. A value equal to or greater than the physics tick rate ([member physics/common/physics_ticks_per_second]) will bring the object to a stop in one iteration. + [b]Note:[/b] Godot damping calculations are velocity-dependent, meaning bodies moving faster will take a longer time to come to rest. They do not simulate inertia, friction, or air resistance. Therefore heavier or larger bodies will lose speed at the same proportional rate as lighter or smaller bodies. + During each physics tick, Godot will multiply the linear velocity of RigidBodies by [code]1.0 - combined_damp / physics_ticks_per_second[/code]. By default, bodies combine damp factors: [code]combined_damp[/code] is the sum of the damp value of the body and this value or the area's value the body is in. See [enum RigidBody3D.DampMode]. + [b]Warning:[/b] Godot's damping calculations are simulation tick rate dependent. Changing [member physics/common/physics_ticks_per_second] may significantly change the outcomes and feel of your simulation. This is true for the entire range of damping values greater than 0. To get back to a similar feel, you also need to change your damp values. This needed change is not proportional and differs from case to case. </member> <member name="physics/3d/physics_engine" type="String" setter="" getter="" default=""DEFAULT""> Sets which physics engine to use for 3D physics. diff --git a/drivers/d3d12/d3d12_context.cpp b/drivers/d3d12/d3d12_context.cpp index da112d8376..d2d1cae5c8 100644 --- a/drivers/d3d12/d3d12_context.cpp +++ b/drivers/d3d12/d3d12_context.cpp @@ -329,7 +329,7 @@ Error D3D12Context::_select_adapter(int &r_index) { adapters.push_back(curr_adapter); } - ERR_FAIL_COND_V_MSG(adapters.size() == 0, ERR_CANT_CREATE, "Adapters enumeration reported zero accessible devices."); + ERR_FAIL_COND_V_MSG(adapters.is_empty(), ERR_CANT_CREATE, "Adapters enumeration reported zero accessible devices."); // The device should really be a preference, but for now choosing a discrete GPU over the // integrated one is better than the default. diff --git a/drivers/gles3/storage/mesh_storage.cpp b/drivers/gles3/storage/mesh_storage.cpp index 475f3c33b8..928e4e23ce 100644 --- a/drivers/gles3/storage/mesh_storage.cpp +++ b/drivers/gles3/storage/mesh_storage.cpp @@ -471,7 +471,7 @@ void MeshStorage::mesh_surface_update_vertex_region(RID p_mesh, int p_surface, i Mesh *mesh = mesh_owner.get_or_null(p_mesh); ERR_FAIL_NULL(mesh); ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count); - ERR_FAIL_COND(p_data.size() == 0); + ERR_FAIL_COND(p_data.is_empty()); uint64_t data_size = p_data.size(); ERR_FAIL_COND(p_offset + data_size > mesh->surfaces[p_surface]->vertex_buffer_size); @@ -486,7 +486,7 @@ void MeshStorage::mesh_surface_update_attribute_region(RID p_mesh, int p_surface Mesh *mesh = mesh_owner.get_or_null(p_mesh); ERR_FAIL_NULL(mesh); ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count); - ERR_FAIL_COND(p_data.size() == 0); + ERR_FAIL_COND(p_data.is_empty()); uint64_t data_size = p_data.size(); ERR_FAIL_COND(p_offset + data_size > mesh->surfaces[p_surface]->attribute_buffer_size); @@ -501,7 +501,7 @@ void MeshStorage::mesh_surface_update_skin_region(RID p_mesh, int p_surface, int Mesh *mesh = mesh_owner.get_or_null(p_mesh); ERR_FAIL_NULL(mesh); ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count); - ERR_FAIL_COND(p_data.size() == 0); + ERR_FAIL_COND(p_data.is_empty()); uint64_t data_size = p_data.size(); ERR_FAIL_COND(p_offset + data_size > mesh->surfaces[p_surface]->skin_buffer_size); diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 3c863bdc19..93dcc341c1 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -387,7 +387,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread } } else if (p_msg == "set_pid") { - ERR_FAIL_COND(p_data.size() < 1); + ERR_FAIL_COND(p_data.is_empty()); remote_pid = p_data[0]; } else if (p_msg == "scene:click_ctrl") { ERR_FAIL_COND(p_data.size() < 2); @@ -806,7 +806,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread } performance_profiler->update_monitors(monitors); } else if (p_msg == "filesystem:update_file") { - ERR_FAIL_COND(p_data.size() < 1); + ERR_FAIL_COND(p_data.is_empty()); if (EditorFileSystem::get_singleton()) { EditorFileSystem::get_singleton()->update_file(p_data[0]); } diff --git a/editor/editor_command_palette.cpp b/editor/editor_command_palette.cpp index 567b686b85..d740641f57 100644 --- a/editor/editor_command_palette.cpp +++ b/editor/editor_command_palette.cpp @@ -63,7 +63,7 @@ float EditorCommandPalette::_score_path(const String &p_search, const String &p_ } void EditorCommandPalette::_update_command_search(const String &search_text) { - ERR_FAIL_COND(commands.size() == 0); + ERR_FAIL_COND(commands.is_empty()); HashMap<String, TreeItem *> sections; TreeItem *first_section = nullptr; diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 9fbe7ba655..5021b814ea 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1183,7 +1183,7 @@ void EditorFileSystem::_thread_func_sources(void *_userdata) { sp.low = 0; efs->_scan_fs_changes(efs->filesystem, sp); } - efs->scanning_changes_done = true; + efs->scanning_changes_done.set(); } void EditorFileSystem::scan_changes() { @@ -1197,7 +1197,7 @@ void EditorFileSystem::scan_changes() { _update_extensions(); sources_changed.clear(); scanning_changes = true; - scanning_changes_done = false; + scanning_changes_done.clear(); if (!use_threads) { if (filesystem) { @@ -1216,7 +1216,7 @@ void EditorFileSystem::scan_changes() { } } scanning_changes = false; - scanning_changes_done = true; + scanning_changes_done.set(); emit_signal(SNAME("sources_changed"), sources_changed.size() > 0); } else { ERR_FAIL_COND(thread_sources.is_started()); @@ -1269,7 +1269,7 @@ void EditorFileSystem::_notification(int p_what) { bool done_importing = false; if (scanning_changes) { - if (scanning_changes_done) { + if (scanning_changes_done.is_set()) { set_process(false); if (thread_sources.is_started()) { diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index 2f5cd88a55..d099a6fedc 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -231,7 +231,7 @@ class EditorFileSystem : public Node { Thread thread_sources; bool scanning_changes = false; - bool scanning_changes_done = false; + SafeFlag scanning_changes_done; static void _thread_func_sources(void *_userdata); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 4501c52bc8..6633121737 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -3892,7 +3892,7 @@ void EditorInspector::_property_changed(const String &p_path, const Variant &p_v } void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array p_values, bool p_changing) { - ERR_FAIL_COND(p_paths.size() == 0 || p_values.size() == 0); + ERR_FAIL_COND(p_paths.is_empty() || p_values.is_empty()); ERR_FAIL_COND(p_paths.size() != p_values.size()); String names; for (int i = 0; i < p_paths.size(); i++) { diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index 8401f08391..dd1440fe0b 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -37,7 +37,7 @@ #include "editor/themes/editor_scale.h" String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { - if (grabber->is_visible()) { + if (!read_only && grabber->is_visible()) { Key key = (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) ? Key::META : Key::CTRL; return TS->format_number(rtos(get_value())) + "\n\n" + vformat(TTR("Hold %s to round to integers.\nHold Shift for more precise changes."), find_keycode_name(key)); } @@ -390,13 +390,9 @@ void EditorSpinSlider::_draw_spin_slider() { grabbing_spinner_mouse_pos = get_global_position() + grabber_rect.get_center(); - bool display_grabber = (grabbing_grabber || mouse_over_spin || mouse_over_grabber) && !grabbing_spinner && !(value_input_popup && value_input_popup->is_visible()); + bool display_grabber = !read_only && (grabbing_grabber || mouse_over_spin || mouse_over_grabber) && !grabbing_spinner && !(value_input_popup && value_input_popup->is_visible()); if (grabber->is_visible() != display_grabber) { - if (display_grabber) { - grabber->show(); - } else { - grabber->hide(); - } + grabber->set_visible(display_grabber); } if (display_grabber) { diff --git a/editor/import/3d/collada.cpp b/editor/import/3d/collada.cpp index ae8041d6fe..d484476b35 100644 --- a/editor/import/3d/collada.cpp +++ b/editor/import/3d/collada.cpp @@ -178,7 +178,7 @@ Transform3D Collada::Node::get_global_transform() const { } Vector<float> Collada::AnimationTrack::get_value_at_time(float p_time) const { - ERR_FAIL_COND_V(keys.size() == 0, Vector<float>()); + ERR_FAIL_COND_V(keys.is_empty(), Vector<float>()); int i = 0; for (i = 0; i < keys.size(); i++) { diff --git a/editor/import/3d/resource_importer_obj.cpp b/editor/import/3d/resource_importer_obj.cpp index a5e51636af..4b340ea997 100644 --- a/editor/import/3d/resource_importer_obj.cpp +++ b/editor/import/3d/resource_importer_obj.cpp @@ -306,7 +306,7 @@ static Error _parse_obj(const String &p_path, List<Ref<ImporterMesh>> &r_meshes, Vector<String> face[3]; face[0] = v[1].split("/"); face[1] = v[2].split("/"); - ERR_FAIL_COND_V(face[0].size() == 0, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V(face[0].is_empty(), ERR_FILE_CORRUPT); ERR_FAIL_COND_V(face[0].size() != face[1].size(), ERR_FILE_CORRUPT); for (int i = 2; i < v.size() - 1; i++) { diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index d437f23740..9edf468ec6 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -192,7 +192,7 @@ static void _plot_triangle(Vector2i *p_vertices, const Vector2i &p_offset, bool } Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file, const HashMap<String, HashMap<StringName, Variant>> &p_source_file_options, const HashMap<String, String> &p_base_paths) { - ERR_FAIL_COND_V(p_source_file_options.size() == 0, ERR_BUG); //should never happen + ERR_FAIL_COND_V(p_source_file_options.is_empty(), ERR_BUG); //should never happen Vector<EditorAtlasPacker::Chart> charts; Vector<PackData> pack_data_files; diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 8edd569a87..daaf271d71 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -758,86 +758,97 @@ void EditorAssetLibrary::_select_asset(int p_id) { _api_request("asset/" + itos(p_id), REQUESTING_ASSET); } -void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PackedByteArray &p_data, int p_queue_id) { +void EditorAssetLibrary::_image_update(bool p_use_cache, bool p_final, const PackedByteArray &p_data, int p_queue_id) { Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target); + if (!obj) { + return; + } - if (obj) { - bool image_set = false; - PackedByteArray image_data = p_data; + bool image_set = false; + PackedByteArray image_data = p_data; - if (use_cache) { - String cache_filename_base = EditorPaths::get_singleton()->get_cache_dir().path_join("assetimage_" + image_queue[p_queue_id].image_url.md5_text()); + if (p_use_cache) { + String cache_filename_base = EditorPaths::get_singleton()->get_cache_dir().path_join("assetimage_" + image_queue[p_queue_id].image_url.md5_text()); - Ref<FileAccess> file = FileAccess::open(cache_filename_base + ".data", FileAccess::READ); - if (file.is_valid()) { - PackedByteArray cached_data; - int len = file->get_32(); - cached_data.resize(len); + Ref<FileAccess> file = FileAccess::open(cache_filename_base + ".data", FileAccess::READ); + if (file.is_valid()) { + PackedByteArray cached_data; + int len = file->get_32(); + cached_data.resize(len); - uint8_t *w = cached_data.ptrw(); - file->get_buffer(w, len); + uint8_t *w = cached_data.ptrw(); + file->get_buffer(w, len); - image_data = cached_data; - } + image_data = cached_data; + } + } + + int len = image_data.size(); + const uint8_t *r = image_data.ptr(); + Ref<Image> image = memnew(Image); + + uint8_t png_signature[8] = { 137, 80, 78, 71, 13, 10, 26, 10 }; + uint8_t jpg_signature[3] = { 255, 216, 255 }; + uint8_t webp_signature[4] = { 82, 73, 70, 70 }; + uint8_t bmp_signature[2] = { 66, 77 }; + + if (r) { + Ref<Image> parsed_image; + + if ((memcmp(&r[0], &png_signature[0], 8) == 0) && Image::_png_mem_loader_func) { + parsed_image = Image::_png_mem_loader_func(r, len); + } else if ((memcmp(&r[0], &jpg_signature[0], 3) == 0) && Image::_jpg_mem_loader_func) { + parsed_image = Image::_jpg_mem_loader_func(r, len); + } else if ((memcmp(&r[0], &webp_signature[0], 4) == 0) && Image::_webp_mem_loader_func) { + parsed_image = Image::_webp_mem_loader_func(r, len); + } else if ((memcmp(&r[0], &bmp_signature[0], 2) == 0) && Image::_bmp_mem_loader_func) { + parsed_image = Image::_bmp_mem_loader_func(r, len); + } else if (Image::_svg_scalable_mem_loader_func) { + parsed_image = Image::_svg_scalable_mem_loader_func(r, len, 1.0); } - int len = image_data.size(); - const uint8_t *r = image_data.ptr(); - Ref<Image> image = Ref<Image>(memnew(Image)); - - uint8_t png_signature[8] = { 137, 80, 78, 71, 13, 10, 26, 10 }; - uint8_t jpg_signature[3] = { 255, 216, 255 }; - uint8_t webp_signature[4] = { 82, 73, 70, 70 }; - uint8_t bmp_signature[2] = { 66, 77 }; - - if (r) { - if ((memcmp(&r[0], &png_signature[0], 8) == 0) && Image::_png_mem_loader_func) { - image->copy_internals_from(Image::_png_mem_loader_func(r, len)); - } else if ((memcmp(&r[0], &jpg_signature[0], 3) == 0) && Image::_jpg_mem_loader_func) { - image->copy_internals_from(Image::_jpg_mem_loader_func(r, len)); - } else if ((memcmp(&r[0], &webp_signature[0], 4) == 0) && Image::_webp_mem_loader_func) { - image->copy_internals_from(Image::_webp_mem_loader_func(r, len)); - } else if ((memcmp(&r[0], &bmp_signature[0], 2) == 0) && Image::_bmp_mem_loader_func) { - image->copy_internals_from(Image::_bmp_mem_loader_func(r, len)); - } else if (Image::_svg_scalable_mem_loader_func) { - image->copy_internals_from(Image::_svg_scalable_mem_loader_func(r, len, 1.0)); + if (parsed_image.is_null()) { + if (is_print_verbose_enabled()) { + ERR_PRINT(vformat("Asset Library: Invalid image downloaded from '%s' for asset # %d", image_queue[p_queue_id].image_url, image_queue[p_queue_id].asset_id)); } + } else { + image->copy_internals_from(parsed_image); } + } - if (!image->is_empty()) { - switch (image_queue[p_queue_id].image_type) { - case IMAGE_QUEUE_ICON: + if (!image->is_empty()) { + switch (image_queue[p_queue_id].image_type) { + case IMAGE_QUEUE_ICON: + image->resize(64 * EDSCALE, 64 * EDSCALE, Image::INTERPOLATE_LANCZOS); + break; - image->resize(64 * EDSCALE, 64 * EDSCALE, Image::INTERPOLATE_LANCZOS); + case IMAGE_QUEUE_THUMBNAIL: { + float max_height = 85 * EDSCALE; - break; - case IMAGE_QUEUE_THUMBNAIL: { - float max_height = 85 * EDSCALE; + float scale_ratio = max_height / (image->get_height() * EDSCALE); + if (scale_ratio < 1) { + image->resize(image->get_width() * EDSCALE * scale_ratio, image->get_height() * EDSCALE * scale_ratio, Image::INTERPOLATE_LANCZOS); + } + } break; - float scale_ratio = max_height / (image->get_height() * EDSCALE); - if (scale_ratio < 1) { - image->resize(image->get_width() * EDSCALE * scale_ratio, image->get_height() * EDSCALE * scale_ratio, Image::INTERPOLATE_LANCZOS); - } - } break; - case IMAGE_QUEUE_SCREENSHOT: { - float max_height = 397 * EDSCALE; + case IMAGE_QUEUE_SCREENSHOT: { + float max_height = 397 * EDSCALE; - float scale_ratio = max_height / (image->get_height() * EDSCALE); - if (scale_ratio < 1) { - image->resize(image->get_width() * EDSCALE * scale_ratio, image->get_height() * EDSCALE * scale_ratio, Image::INTERPOLATE_LANCZOS); - } - } break; - } + float scale_ratio = max_height / (image->get_height() * EDSCALE); + if (scale_ratio < 1) { + image->resize(image->get_width() * EDSCALE * scale_ratio, image->get_height() * EDSCALE * scale_ratio, Image::INTERPOLATE_LANCZOS); + } + } break; + } - Ref<ImageTexture> tex = ImageTexture::create_from_image(image); + Ref<ImageTexture> tex = ImageTexture::create_from_image(image); - obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, tex); - image_set = true; - } + obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, tex); + image_set = true; + } - if (!image_set && final) { - obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_editor_theme_icon(SNAME("FileBrokenBigThumb"))); - } + if (!image_set && p_final) { + obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_editor_theme_icon(SNAME("FileBrokenBigThumb"))); } } @@ -870,7 +881,10 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons _image_update(p_code == HTTPClient::RESPONSE_NOT_MODIFIED, true, p_data, p_queue_id); } else { - WARN_PRINT("Error getting image file from URL: " + image_queue[p_queue_id].image_url); + if (is_print_verbose_enabled()) { + WARN_PRINT(vformat("Asset Library: Error getting image from '%s' for asset # %d.", image_queue[p_queue_id].image_url, image_queue[p_queue_id].asset_id)); + } + Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target); if (obj) { obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_editor_theme_icon(SNAME("FileBrokenBigThumb"))); @@ -919,22 +933,48 @@ void EditorAssetLibrary::_update_image_queue() { } } -void EditorAssetLibrary::_request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index) { +void EditorAssetLibrary::_request_image(ObjectID p_for, int p_asset_id, String p_image_url, ImageType p_type, int p_image_index) { + // Remove extra spaces around the URL. This isn't strictly valid, but recoverable. + String trimmed_url = p_image_url.strip_edges(); + if (trimmed_url != p_image_url && is_print_verbose_enabled()) { + WARN_PRINT(vformat("Asset Library: Badly formatted image URL '%s' for asset # %d.", p_image_url, p_asset_id)); + } + + // Validate the image URL first. + { + String url_scheme; + String url_host; + int url_port; + String url_path; + Error err = trimmed_url.parse_url(url_scheme, url_host, url_port, url_path); + if (err != OK) { + if (is_print_verbose_enabled()) { + ERR_PRINT(vformat("Asset Library: Invalid image URL '%s' for asset # %d.", trimmed_url, p_asset_id)); + } + + Object *obj = ObjectDB::get_instance(p_for); + if (obj) { + obj->call("set_image", p_type, p_image_index, get_editor_theme_icon(SNAME("FileBrokenBigThumb"))); + } + return; + } + } + ImageQueue iq; - iq.image_url = p_image_url; + iq.image_url = trimmed_url; iq.image_index = p_image_index; iq.image_type = p_type; iq.request = memnew(HTTPRequest); setup_http_request(iq.request); iq.target = p_for; + iq.asset_id = p_asset_id; iq.queue_id = ++last_queue_id; iq.active = false; iq.request->connect("request_completed", callable_mp(this, &EditorAssetLibrary::_image_request_completed).bind(iq.queue_id)); image_queue[iq.queue_id] = iq; - add_child(iq.request); _image_update(true, false, PackedByteArray(), iq.queue_id); @@ -1311,7 +1351,7 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const item->connect("category_selected", callable_mp(this, &EditorAssetLibrary::_select_category)); if (r.has("icon_url") && !r["icon_url"].operator String().is_empty()) { - _request_image(item->get_instance_id(), r["icon_url"], IMAGE_QUEUE_ICON, 0); + _request_image(item->get_instance_id(), r["asset_id"], r["icon_url"], IMAGE_QUEUE_ICON, 0); } } @@ -1362,7 +1402,7 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const } if (r.has("icon_url") && !r["icon_url"].operator String().is_empty()) { - _request_image(description->get_instance_id(), r["icon_url"], IMAGE_QUEUE_ICON, 0); + _request_image(description->get_instance_id(), r["asset_id"], r["icon_url"], IMAGE_QUEUE_ICON, 0); } if (d.has("previews")) { @@ -1383,11 +1423,11 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const description->add_preview(i, is_video, video_url); if (p.has("thumbnail")) { - _request_image(description->get_instance_id(), p["thumbnail"], IMAGE_QUEUE_THUMBNAIL, i); + _request_image(description->get_instance_id(), r["asset_id"], p["thumbnail"], IMAGE_QUEUE_THUMBNAIL, i); } if (!is_video) { - _request_image(description->get_instance_id(), p["link"], IMAGE_QUEUE_SCREENSHOT, i); + _request_image(description->get_instance_id(), r["asset_id"], p["link"], IMAGE_QUEUE_SCREENSHOT, i); } } } diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h index bbce14a9dd..3e95a19160 100644 --- a/editor/plugins/asset_library_editor_plugin.h +++ b/editor/plugins/asset_library_editor_plugin.h @@ -262,14 +262,15 @@ class EditorAssetLibrary : public PanelContainer { String image_url; HTTPRequest *request = nullptr; ObjectID target; + int asset_id = -1; }; int last_queue_id; HashMap<int, ImageQueue> image_queue; - void _image_update(bool use_cache, bool final, const PackedByteArray &p_data, int p_queue_id); + void _image_update(bool p_use_cache, bool p_final, const PackedByteArray &p_data, int p_queue_id); void _image_request_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data, int p_queue_id); - void _request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index); + void _request_image(ObjectID p_for, int p_asset_id, String p_image_url, ImageType p_type, int p_image_index); void _update_image_queue(); HBoxContainer *_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items); diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index f0fd40a77e..eed09f289d 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -201,7 +201,7 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { valid_normals.resize(vpc); } - ERR_FAIL_COND_MSG(valid_positions.size() == 0, "No pixels with transparency > 128 in image..."); + ERR_FAIL_COND_MSG(valid_positions.is_empty(), "No pixels with transparency > 128 in image..."); if (capture_colors) { PackedColorArray pca; diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp index af04d45ba8..f9a2ffdd3b 100644 --- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp @@ -280,7 +280,7 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() { valid_normals.resize(vpc); } - ERR_FAIL_COND_MSG(valid_positions.size() == 0, "No pixels with transparency > 128 in image..."); + ERR_FAIL_COND_MSG(valid_positions.is_empty(), "No pixels with transparency > 128 in image..."); Vector<uint8_t> texdata; diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp index 370c423b40..086abc0859 100644 --- a/editor/plugins/multimesh_editor_plugin.cpp +++ b/editor/plugins/multimesh_editor_plugin.cpp @@ -154,7 +154,7 @@ void MultiMeshEditor::_populate() { area_accum += area; } - ERR_FAIL_COND_MSG(triangle_area_map.size() == 0, "Couldn't map area."); + ERR_FAIL_COND_MSG(triangle_area_map.is_empty(), "Couldn't map area."); ERR_FAIL_COND_MSG(area_accum == 0, "Couldn't map area."); Ref<MultiMesh> multimesh = memnew(MultiMesh); diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index a427d0359d..77ed48a662 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -969,7 +969,7 @@ void EditorNode3DGizmoPlugin::add_material(const String &p_name, Ref<StandardMat Ref<StandardMaterial3D> EditorNode3DGizmoPlugin::get_material(const String &p_name, const Ref<EditorNode3DGizmo> &p_gizmo) { ERR_FAIL_COND_V(!materials.has(p_name), Ref<StandardMaterial3D>()); - ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<StandardMaterial3D>()); + ERR_FAIL_COND_V(materials[p_name].is_empty(), Ref<StandardMaterial3D>()); if (p_gizmo.is_null() || materials[p_name].size() == 1) { return materials[p_name][0]; diff --git a/editor/plugins/text_shader_editor.cpp b/editor/plugins/text_shader_editor.cpp index 98d83b6e95..fe8fb79c56 100644 --- a/editor/plugins/text_shader_editor.cpp +++ b/editor/plugins/text_shader_editor.cpp @@ -473,7 +473,7 @@ void ShaderTextEditor::_validate_script() { if (last_compile_result != OK) { //preprocessor error - ERR_FAIL_COND(err_positions.size() == 0); + ERR_FAIL_COND(err_positions.is_empty()); String err_text = error_pp; int err_line = err_positions.front()->get().line; diff --git a/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp b/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp index 4895e1d291..1762efeab6 100644 --- a/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp @@ -269,7 +269,7 @@ void TileSetScenesCollectionSourceEditor::_scene_file_selected(const String &p_p void TileSetScenesCollectionSourceEditor::_source_delete_pressed() { Vector<int> selected_indices = scene_tiles_list->get_selected_items(); - ERR_FAIL_COND(selected_indices.size() <= 0); + ERR_FAIL_COND(selected_indices.is_empty()); int scene_id = scene_tiles_list->get_item_metadata(selected_indices[0]); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index ffb482d103..6f7d571792 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -996,7 +996,7 @@ void ProjectManager::_files_dropped(PackedStringArray p_files) { const String &file = p_files[i]; folders_set.insert(da->dir_exists(file) ? file : file.get_base_dir()); } - ERR_FAIL_COND(folders_set.size() == 0); // This can't really happen, we consume every dropped file path above. + ERR_FAIL_COND(folders_set.is_empty()); // This can't really happen, we consume every dropped file path above. PackedStringArray folders; for (const String &E : folders_set) { diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp index 07cb96b9bc..367dd324c2 100644 --- a/editor/rename_dialog.cpp +++ b/editor/rename_dialog.cpp @@ -368,7 +368,7 @@ void RenameDialog::_post_popup() { preview_node = nullptr; Array selected_node_list = editor_selection->get_selected_nodes(); - ERR_FAIL_COND(selected_node_list.size() == 0); + ERR_FAIL_COND(selected_node_list.is_empty()); preview_node = Object::cast_to<Node>(selected_node_list[0]); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 5b789c9445..d7738e0ba5 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -2660,7 +2660,7 @@ void SceneTreeDock::_create() { } else if (current_option == TOOL_REPLACE) { List<Node *> selection = editor_selection->get_selected_node_list(); - ERR_FAIL_COND(selection.size() <= 0); + ERR_FAIL_COND(selection.is_empty()); EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Change type of node(s)"), UndoRedo::MERGE_DISABLE, selection.front()->get()); @@ -2679,7 +2679,7 @@ void SceneTreeDock::_create() { ur->commit_action(false); } else if (current_option == TOOL_REPARENT_TO_NEW_NODE) { List<Node *> selection = editor_selection->get_selected_node_list(); - ERR_FAIL_COND(selection.size() <= 0); + ERR_FAIL_COND(selection.is_empty()); // Find top level node in selection bool only_one_top_node = true; diff --git a/main/main.cpp b/main/main.cpp index bc2a6107b5..f8fc3804ae 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -3546,7 +3546,7 @@ bool Main::start() { Error err; Vector<String> paths = get_files_with_extension(gdscript_docs_path, "gd"); - ERR_FAIL_COND_V_MSG(paths.size() == 0, false, "Couldn't find any GDScript files under the given directory: " + gdscript_docs_path); + ERR_FAIL_COND_V_MSG(paths.is_empty(), false, "Couldn't find any GDScript files under the given directory: " + gdscript_docs_path); for (const String &path : paths) { Ref<GDScript> gdscript = ResourceLoader::load(path); diff --git a/misc/hooks/pre-commit-clang-format b/misc/hooks/pre-commit-clang-format index e5cf0c4aa2..eddbc59364 100755 --- a/misc/hooks/pre-commit-clang-format +++ b/misc/hooks/pre-commit-clang-format @@ -140,6 +140,9 @@ do if grep -q "\-so_wrap." <<< $file; then continue; fi + if grep -q "tests/python_build" <<< $file; then + continue; + fi # ignore file if we do check for file extensions and the file # does not match any of the extensions specified in $FILE_EXTS diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index 1de76c60b5..604ad5e1e4 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -800,7 +800,7 @@ CSGBrush *CSGMesh3D::_build_brush() { if (arrays.size() == 0) { _make_dirty(); - ERR_FAIL_COND_V(arrays.size() == 0, memnew(CSGBrush)); + ERR_FAIL_COND_V(arrays.is_empty(), memnew(CSGBrush)); } Vector<Vector3> avertices = arrays[Mesh::ARRAY_VERTEX]; diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp index 63f12ea1c1..910c4ed242 100644 --- a/modules/enet/enet_multiplayer_peer.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -40,20 +40,20 @@ void ENetMultiplayerPeer::set_target_peer(int p_peer) { int ENetMultiplayerPeer::get_packet_peer() const { ERR_FAIL_COND_V_MSG(!_is_active(), 1, "The multiplayer instance isn't currently active."); - ERR_FAIL_COND_V(incoming_packets.size() == 0, 1); + ERR_FAIL_COND_V(incoming_packets.is_empty(), 1); return incoming_packets.front()->get().from; } MultiplayerPeer::TransferMode ENetMultiplayerPeer::get_packet_mode() const { ERR_FAIL_COND_V_MSG(!_is_active(), TRANSFER_MODE_RELIABLE, "The multiplayer instance isn't currently active."); - ERR_FAIL_COND_V(incoming_packets.size() == 0, TRANSFER_MODE_RELIABLE); + ERR_FAIL_COND_V(incoming_packets.is_empty(), TRANSFER_MODE_RELIABLE); return incoming_packets.front()->get().transfer_mode; } int ENetMultiplayerPeer::get_packet_channel() const { ERR_FAIL_COND_V_MSG(!_is_active(), 1, "The multiplayer instance isn't currently active."); - ERR_FAIL_COND_V(incoming_packets.size() == 0, 1); + ERR_FAIL_COND_V(incoming_packets.is_empty(), 1); int ch = incoming_packets.front()->get().channel; if (ch >= SYSCH_MAX) { // First 2 channels are reserved. return ch - SYSCH_MAX + 1; @@ -321,7 +321,7 @@ int ENetMultiplayerPeer::get_available_packet_count() const { } Error ENetMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V_MSG(incoming_packets.size() == 0, ERR_UNAVAILABLE, "No incoming packets available."); + ERR_FAIL_COND_V_MSG(incoming_packets.is_empty(), ERR_UNAVAILABLE, "No incoming packets available."); _pop_current_packet(); diff --git a/modules/enet/enet_packet_peer.cpp b/modules/enet/enet_packet_peer.cpp index f2bf5337ee..edb33fc96b 100644 --- a/modules/enet/enet_packet_peer.cpp +++ b/modules/enet/enet_packet_peer.cpp @@ -90,7 +90,7 @@ int ENetPacketPeer::get_available_packet_count() const { Error ENetPacketPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { ERR_FAIL_NULL_V(peer, ERR_UNCONFIGURED); - ERR_FAIL_COND_V(!packet_queue.size(), ERR_UNAVAILABLE); + ERR_FAIL_COND_V(packet_queue.is_empty(), ERR_UNAVAILABLE); if (last_packet) { enet_packet_destroy(last_packet); last_packet = nullptr; diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 3ba6e4d160..649bd735c6 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -510,7 +510,7 @@ void GDScriptParser::push_multiline(bool p_state) { } void GDScriptParser::pop_multiline() { - ERR_FAIL_COND_MSG(multiline_stack.size() == 0, "Parser bug: trying to pop from multiline stack without available value."); + ERR_FAIL_COND_MSG(multiline_stack.is_empty(), "Parser bug: trying to pop from multiline stack without available value."); multiline_stack.pop_back(); tokenizer->set_multiline_mode(multiline_stack.size() > 0 ? multiline_stack.back()->get() : false); } diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 7344dc054f..ff2f290e4f 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -250,7 +250,7 @@ Error GLTFDocument::_serialize_gltf_extensions(Ref<GLTFState> p_state) const { } Error GLTFDocument::_serialize_scenes(Ref<GLTFState> p_state) { - ERR_FAIL_COND_V_MSG(p_state->root_nodes.size() == 0, ERR_INVALID_DATA, "GLTF export: The scene must have at least one root node."); + ERR_FAIL_COND_V_MSG(p_state->root_nodes.is_empty(), ERR_INVALID_DATA, "GLTF export: The scene must have at least one root node."); // Godot only supports one scene per glTF file. Array scenes; Dictionary scene_dict; @@ -430,20 +430,22 @@ Error GLTFDocument::_serialize_nodes(Ref<GLTFState> p_state) { } if (gltf_node->skeleton != -1 && gltf_node->skin < 0) { } - if (gltf_node->xform != Transform3D()) { - node["matrix"] = _xform_to_array(gltf_node->xform); - } - - if (!gltf_node->rotation.is_equal_approx(Quaternion())) { - node["rotation"] = _quaternion_to_array(gltf_node->rotation); - } - - if (!gltf_node->scale.is_equal_approx(Vector3(1.0f, 1.0f, 1.0f))) { - node["scale"] = _vec3_to_arr(gltf_node->scale); - } - - if (!gltf_node->position.is_zero_approx()) { - node["translation"] = _vec3_to_arr(gltf_node->position); + if (gltf_node->transform.basis.is_orthogonal()) { + // An orthogonal transform is decomposable into TRS, so prefer that. + const Vector3 position = gltf_node->get_position(); + if (!position.is_zero_approx()) { + node["translation"] = _vec3_to_arr(position); + } + const Quaternion rotation = gltf_node->get_rotation(); + if (!rotation.is_equal_approx(Quaternion())) { + node["rotation"] = _quaternion_to_array(rotation); + } + const Vector3 scale = gltf_node->get_scale(); + if (!scale.is_equal_approx(Vector3(1.0f, 1.0f, 1.0f))) { + node["scale"] = _vec3_to_arr(scale); + } + } else { + node["matrix"] = _xform_to_array(gltf_node->transform); } if (gltf_node->children.size()) { Array children; @@ -609,20 +611,17 @@ Error GLTFDocument::_parse_nodes(Ref<GLTFState> p_state) { node->skin = n["skin"]; } if (n.has("matrix")) { - node->xform = _arr_to_xform(n["matrix"]); + node->transform = _arr_to_xform(n["matrix"]); } else { if (n.has("translation")) { - node->position = _arr_to_vec3(n["translation"]); + node->set_position(_arr_to_vec3(n["translation"])); } if (n.has("rotation")) { - node->rotation = _arr_to_quaternion(n["rotation"]); + node->set_rotation(_arr_to_quaternion(n["rotation"])); } if (n.has("scale")) { - node->scale = _arr_to_vec3(n["scale"]); + node->set_scale(_arr_to_vec3(n["scale"])); } - - node->xform.basis.set_quaternion_scale(node->rotation, node->scale); - node->xform.origin = node->position; } if (n.has("extensions")) { @@ -807,7 +806,7 @@ Error GLTFDocument::_parse_buffers(Ref<GLTFState> p_state, const String &p_base_ uri = uri.uri_decode(); uri = p_base_path.path_join(uri).replace("\\", "/"); // Fix for Windows. buffer_data = FileAccess::get_file_as_bytes(uri); - ERR_FAIL_COND_V_MSG(buffer.size() == 0, ERR_PARSE_ERROR, "glTF: Couldn't load binary file as an array: " + uri); + ERR_FAIL_COND_V_MSG(buffer.is_empty(), ERR_PARSE_ERROR, "glTF: Couldn't load binary file as an array: " + uri); } ERR_FAIL_COND_V(!buffer.has("byteLength"), ERR_PARSE_ERROR); @@ -1545,7 +1544,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> p_state, } } - ERR_FAIL_COND_V(attribs.size() == 0, -1); + ERR_FAIL_COND_V(attribs.is_empty(), -1); Ref<GLTFAccessor> accessor; accessor.instantiate(); @@ -1904,7 +1903,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> p_stat _calc_accessor_min_max(i, element_count, type_max, attribs, type_min); } - ERR_FAIL_COND_V(!attribs.size(), -1); + ERR_FAIL_COND_V(attribs.is_empty(), -1); Ref<GLTFAccessor> accessor; accessor.instantiate(); @@ -2222,7 +2221,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> p_state) { Dictionary attributes; { Vector<Vector3> a = array[Mesh::ARRAY_VERTEX]; - ERR_FAIL_COND_V(!a.size(), ERR_INVALID_DATA); + ERR_FAIL_COND_V(a.is_empty(), ERR_INVALID_DATA); attributes["POSITION"] = _encode_accessor_as_vec3(p_state, a, true); vertex_num = a.size(); } @@ -2789,7 +2788,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) { } else if (primitive == Mesh::PRIMITIVE_TRIANGLES) { //generate indices because they need to be swapped for CW/CCW const Vector<Vector3> &vertices = array[Mesh::ARRAY_VERTEX]; - ERR_FAIL_COND_V(vertices.size() == 0, ERR_PARSE_ERROR); + ERR_FAIL_COND_V(vertices.is_empty(), ERR_PARSE_ERROR); Vector<int> indices; const int vs = vertices.size(); indices.resize(vs); @@ -2920,7 +2919,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) { if (t.has("TANGENT")) { const Vector<Vector3> tangents_v3 = _decode_accessor_as_vec3(p_state, t["TANGENT"], true); const Vector<float> src_tangents = array[Mesh::ARRAY_TANGENT]; - ERR_FAIL_COND_V(src_tangents.size() == 0, ERR_PARSE_ERROR); + ERR_FAIL_COND_V(src_tangents.is_empty(), ERR_PARSE_ERROR); Vector<float> tangents_v4; @@ -4415,7 +4414,7 @@ Error GLTFDocument::_verify_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin) { out_roots.sort(); - ERR_FAIL_COND_V(out_roots.size() == 0, FAILED); + ERR_FAIL_COND_V(out_roots.is_empty(), FAILED); // Make sure the roots are the exact same (they better be) ERR_FAIL_COND_V(out_roots.size() != p_skin->roots.size(), FAILED); @@ -4801,10 +4800,10 @@ Error GLTFDocument::_create_skeletons(Ref<GLTFState> p_state) { node->set_name(_gen_unique_bone_name(p_state, skel_i, node->get_name())); skeleton->add_bone(node->get_name()); - skeleton->set_bone_rest(bone_index, node->xform); - skeleton->set_bone_pose_position(bone_index, node->position); - skeleton->set_bone_pose_rotation(bone_index, node->rotation.normalized()); - skeleton->set_bone_pose_scale(bone_index, node->scale); + skeleton->set_bone_rest(bone_index, node->transform); + skeleton->set_bone_pose_position(bone_index, node->get_position()); + skeleton->set_bone_pose_rotation(bone_index, node->get_rotation()); + skeleton->set_bone_pose_scale(bone_index, node->get_scale()); if (node->parent >= 0 && p_state->nodes[node->parent]->skeleton == skel_i) { const int bone_parent = skeleton->find_bone(p_state->nodes[node->parent]->get_name()); @@ -5509,10 +5508,7 @@ GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> p_state, Light3D *p_l } void GLTFDocument::_convert_spatial(Ref<GLTFState> p_state, Node3D *p_spatial, Ref<GLTFNode> p_node) { - Transform3D xform = p_spatial->get_transform(); - p_node->scale = xform.basis.get_scale(); - p_node->rotation = xform.basis.get_rotation_quaternion(); - p_node->position = xform.origin; + p_node->transform = p_spatial->get_transform(); } Node3D *GLTFDocument::_generate_spatial(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index) { @@ -5632,7 +5628,7 @@ void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeInd GLTFMeshIndex mesh_i = p_state->meshes.size(); p_state->meshes.push_back(gltf_mesh); p_gltf_node->mesh = mesh_i; - p_gltf_node->xform = csg->get_meshes()[0]; + p_gltf_node->transform = csg->get_meshes()[0]; p_gltf_node->set_name(_gen_unique_name(p_state, csg->get_name())); } #endif // MODULE_CSG_ENABLED @@ -5708,7 +5704,7 @@ void GLTFDocument::_convert_grid_map_to_gltf(GridMap *p_grid_map, GLTFNodeIndex gltf_mesh->set_mesh(_mesh_to_importer_mesh(p_grid_map->get_mesh_library()->get_item_mesh(cell))); new_gltf_node->mesh = p_state->meshes.size(); p_state->meshes.push_back(gltf_mesh); - new_gltf_node->xform = cell_xform * p_grid_map->get_transform(); + new_gltf_node->transform = cell_xform * p_grid_map->get_transform(); new_gltf_node->set_name(_gen_unique_name(p_state, p_grid_map->get_mesh_library()->get_item_name(cell))); } } @@ -5776,7 +5772,7 @@ void GLTFDocument::_convert_multi_mesh_instance_to_gltf( Ref<GLTFNode> new_gltf_node; new_gltf_node.instantiate(); new_gltf_node->mesh = mesh_index; - new_gltf_node->xform = transform; + new_gltf_node->transform = transform; new_gltf_node->set_name(_gen_unique_name(p_state, p_multi_mesh_instance->get_name())); p_gltf_node->children.push_back(p_state->nodes.size()); p_state->nodes.push_back(new_gltf_node); @@ -5801,10 +5797,7 @@ void GLTFDocument::_convert_skeleton_to_gltf(Skeleton3D *p_skeleton3d, Ref<GLTFS // Note that we cannot use _gen_unique_bone_name here, because glTF spec requires all node // names to be unique regardless of whether or not they are used as joints. joint_node->set_name(_gen_unique_name(p_state, skeleton->get_bone_name(bone_i))); - Transform3D xform = skeleton->get_bone_pose(bone_i); - joint_node->scale = xform.basis.get_scale(); - joint_node->rotation = xform.basis.get_rotation_quaternion(); - joint_node->position = xform.origin; + joint_node->transform = skeleton->get_bone_pose(bone_i); joint_node->joint = true; GLTFNodeIndex current_node_i = p_state->nodes.size(); p_state->scene_nodes.insert(current_node_i, skeleton); @@ -5953,7 +5946,7 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> p_state, const GLTFNodeIn Array args; args.append(p_scene_root); current_node->propagate_call(StringName("set_owner"), args); - current_node->set_transform(gltf_node->xform); + current_node->set_transform(gltf_node->transform); } p_state->scene_nodes.insert(p_node_index, current_node); @@ -6111,7 +6104,7 @@ struct SceneFormatImporterGLTFInterpolate<Quaternion> { template <class T> T GLTFDocument::_interpolate_track(const Vector<real_t> &p_times, const Vector<T> &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp) { - ERR_FAIL_COND_V(!p_values.size(), T()); + ERR_FAIL_COND_V(p_values.is_empty(), T()); if (p_times.size() != (p_values.size() / (p_interp == GLTFAnimation::INTERP_CUBIC_SPLINE ? 3 : 1))) { ERR_PRINT_ONCE("The interpolated values are not corresponding to its times."); return p_values[0]; @@ -6285,7 +6278,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_ if (track.position_track.values.size()) { bool is_default = true; //discard the track if all it contains is default values if (p_remove_immutable_tracks) { - Vector3 base_pos = p_state->nodes[track_i.key]->position; + Vector3 base_pos = gltf_node->get_position(); for (int i = 0; i < track.position_track.times.size(); i++) { int value_index = track.position_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i; ERR_FAIL_COND_MSG(value_index >= track.position_track.values.size(), "Animation sampler output accessor with 'CUBICSPLINE' interpolation doesn't have enough elements."); @@ -6310,7 +6303,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_ if (track.rotation_track.values.size()) { bool is_default = true; //discard the track if all it contains is default values if (p_remove_immutable_tracks) { - Quaternion base_rot = p_state->nodes[track_i.key]->rotation.normalized(); + Quaternion base_rot = gltf_node->get_rotation(); for (int i = 0; i < track.rotation_track.times.size(); i++) { int value_index = track.rotation_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i; ERR_FAIL_COND_MSG(value_index >= track.rotation_track.values.size(), "Animation sampler output accessor with 'CUBICSPLINE' interpolation doesn't have enough elements."); @@ -6335,7 +6328,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_ if (track.scale_track.values.size()) { bool is_default = true; //discard the track if all it contains is default values if (p_remove_immutable_tracks) { - Vector3 base_scale = p_state->nodes[track_i.key]->scale; + Vector3 base_scale = gltf_node->get_scale(); for (int i = 0; i < track.scale_track.times.size(); i++) { int value_index = track.scale_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i; ERR_FAIL_COND_MSG(value_index >= track.scale_track.values.size(), "Animation sampler output accessor with 'CUBICSPLINE' interpolation doesn't have enough elements."); @@ -6366,15 +6359,15 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_ Vector3 base_scale = Vector3(1, 1, 1); if (rotation_idx == -1) { - base_rot = p_state->nodes[track_i.key]->rotation.normalized(); + base_rot = gltf_node->get_rotation(); } if (position_idx == -1) { - base_pos = p_state->nodes[track_i.key]->position; + base_pos = gltf_node->get_position(); } if (scale_idx == -1) { - base_scale = p_state->nodes[track_i.key]->scale; + base_scale = gltf_node->get_scale(); } bool last = false; @@ -6481,10 +6474,7 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> p_state) { if (!mi) { continue; } - Transform3D mi_xform = mi->get_transform(); - node->scale = mi_xform.basis.get_scale(); - node->rotation = mi_xform.basis.get_rotation_quaternion(); - node->position = mi_xform.origin; + node->transform = mi->get_transform(); Node *skel_node = mi->get_node_or_null(mi->get_skeleton_path()); Skeleton3D *godot_skeleton = Object::cast_to<Skeleton3D>(skel_node); diff --git a/modules/gltf/structures/gltf_node.cpp b/modules/gltf/structures/gltf_node.cpp index 30895034a9..03f71525fd 100644 --- a/modules/gltf/structures/gltf_node.cpp +++ b/modules/gltf/structures/gltf_node.cpp @@ -89,11 +89,11 @@ void GLTFNode::set_height(int p_height) { } Transform3D GLTFNode::get_xform() { - return xform; + return transform; } void GLTFNode::set_xform(Transform3D p_xform) { - xform = p_xform; + transform = p_xform; } GLTFMeshIndex GLTFNode::get_mesh() { @@ -129,27 +129,27 @@ void GLTFNode::set_skeleton(GLTFSkeletonIndex p_skeleton) { } Vector3 GLTFNode::get_position() { - return position; + return transform.origin; } void GLTFNode::set_position(Vector3 p_position) { - position = p_position; + transform.origin = p_position; } Quaternion GLTFNode::get_rotation() { - return rotation; + return transform.basis.get_rotation_quaternion(); } void GLTFNode::set_rotation(Quaternion p_rotation) { - rotation = p_rotation; + transform.basis.set_quaternion_scale(p_rotation, transform.basis.get_scale()); } Vector3 GLTFNode::get_scale() { - return scale; + return transform.basis.get_scale(); } void GLTFNode::set_scale(Vector3 p_scale) { - scale = p_scale; + transform.basis = transform.basis.orthonormalized() * Basis::from_scale(p_scale); } Vector<int> GLTFNode::get_children() { diff --git a/modules/gltf/structures/gltf_node.h b/modules/gltf/structures/gltf_node.h index c2d2f64495..aba7374127 100644 --- a/modules/gltf/structures/gltf_node.h +++ b/modules/gltf/structures/gltf_node.h @@ -40,18 +40,14 @@ class GLTFNode : public Resource { friend class GLTFDocument; private: - // matrices need to be transformed to this GLTFNodeIndex parent = -1; int height = -1; - Transform3D xform; + Transform3D transform; GLTFMeshIndex mesh = -1; GLTFCameraIndex camera = -1; GLTFSkinIndex skin = -1; GLTFSkeletonIndex skeleton = -1; bool joint = false; - Vector3 position; - Quaternion rotation; - Vector3 scale = Vector3(1, 1, 1); Vector<int> children; GLTFLightIndex light = -1; Dictionary additional_data; diff --git a/modules/lightmapper_rd/lightmapper_rd.cpp b/modules/lightmapper_rd/lightmapper_rd.cpp index 02b5aefc9f..9ee281ad99 100644 --- a/modules/lightmapper_rd/lightmapper_rd.cpp +++ b/modules/lightmapper_rd/lightmapper_rd.cpp @@ -49,7 +49,7 @@ void LightmapperRD::add_mesh(const MeshData &p_mesh) { ERR_FAIL_COND(p_mesh.emission_on_uv2.is_null() || p_mesh.emission_on_uv2->is_empty()); ERR_FAIL_COND(p_mesh.albedo_on_uv2->get_width() != p_mesh.emission_on_uv2->get_width()); ERR_FAIL_COND(p_mesh.albedo_on_uv2->get_height() != p_mesh.emission_on_uv2->get_height()); - ERR_FAIL_COND(p_mesh.points.size() == 0); + ERR_FAIL_COND(p_mesh.points.is_empty()); MeshInstance mi; mi.data = p_mesh; mesh_instances.push_back(mi); @@ -1986,7 +1986,7 @@ Variant LightmapperRD::get_bake_mesh_userdata(int p_index) const { } Rect2 LightmapperRD::get_bake_mesh_uv_scale(int p_index) const { - ERR_FAIL_COND_V(bake_textures.size() == 0, Rect2()); + ERR_FAIL_COND_V(bake_textures.is_empty(), Rect2()); Rect2 uv_ofs; Vector2 atlas_size = Vector2(bake_textures[0]->get_width(), bake_textures[0]->get_height()); uv_ofs.position = Vector2(mesh_instances[p_index].offset) / atlas_size; diff --git a/modules/minimp3/resource_importer_mp3.cpp b/modules/minimp3/resource_importer_mp3.cpp index 33c926689a..e4b54ef050 100644 --- a/modules/minimp3/resource_importer_mp3.cpp +++ b/modules/minimp3/resource_importer_mp3.cpp @@ -110,7 +110,7 @@ Ref<AudioStreamMP3> ResourceImporterMP3::import_mp3(const String &p_path) { mp3_stream.instantiate(); mp3_stream->set_data(data); - ERR_FAIL_COND_V(!mp3_stream->get_data().size(), Ref<AudioStreamMP3>()); + ERR_FAIL_COND_V(mp3_stream->get_data().is_empty(), Ref<AudioStreamMP3>()); return mp3_stream; } diff --git a/modules/multiplayer/multiplayer_debugger.cpp b/modules/multiplayer/multiplayer_debugger.cpp index a4d2aed2d6..c816bd3b6b 100644 --- a/modules/multiplayer/multiplayer_debugger.cpp +++ b/modules/multiplayer/multiplayer_debugger.cpp @@ -89,7 +89,7 @@ Error MultiplayerDebugger::_capture(void *p_user, const String &p_msg, const Arr // BandwidthProfiler int MultiplayerDebugger::BandwidthProfiler::bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer) { - ERR_FAIL_COND_V(p_buffer.size() == 0, 0); + ERR_FAIL_COND_V(p_buffer.is_empty(), 0); int total_bandwidth = 0; uint64_t timestamp = OS::get_singleton()->get_ticks_msec(); @@ -174,7 +174,7 @@ Array MultiplayerDebugger::RPCFrame::serialize() { } bool MultiplayerDebugger::RPCFrame::deserialize(const Array &p_arr) { - ERR_FAIL_COND_V(p_arr.size() < 1, false); + ERR_FAIL_COND_V(p_arr.is_empty(), false); uint32_t size = p_arr[0]; ERR_FAIL_COND_V(size % 6, false); ERR_FAIL_COND_V((uint32_t)p_arr.size() != size + 1, false); @@ -279,7 +279,7 @@ Array MultiplayerDebugger::ReplicationFrame::serialize() { } bool MultiplayerDebugger::ReplicationFrame::deserialize(const Array &p_arr) { - ERR_FAIL_COND_V(p_arr.size() < 1, false); + ERR_FAIL_COND_V(p_arr.is_empty(), false); uint32_t size = p_arr[0]; ERR_FAIL_COND_V(size % 7, false); ERR_FAIL_COND_V((uint32_t)p_arr.size() != size + 1, false); diff --git a/modules/multiplayer/scene_multiplayer.cpp b/modules/multiplayer/scene_multiplayer.cpp index 665b246bc5..5655467df7 100644 --- a/modules/multiplayer/scene_multiplayer.cpp +++ b/modules/multiplayer/scene_multiplayer.cpp @@ -440,7 +440,7 @@ void SceneMultiplayer::disconnect_peer(int p_id) { } Error SceneMultiplayer::send_bytes(Vector<uint8_t> p_data, int p_to, MultiplayerPeer::TransferMode p_mode, int p_channel) { - ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet."); + ERR_FAIL_COND_V_MSG(p_data.is_empty(), ERR_INVALID_DATA, "Trying to send an empty raw packet."); ERR_FAIL_COND_V_MSG(!multiplayer_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no multiplayer peer is active."); ERR_FAIL_COND_V_MSG(multiplayer_peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a multiplayer peer which is not connected."); @@ -460,7 +460,7 @@ Error SceneMultiplayer::send_bytes(Vector<uint8_t> p_data, int p_to, Multiplayer Error SceneMultiplayer::send_auth(int p_to, Vector<uint8_t> p_data) { ERR_FAIL_COND_V(multiplayer_peer.is_null() || multiplayer_peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED); ERR_FAIL_COND_V(!pending_peers.has(p_to), ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_data.is_empty(), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V_MSG(pending_peers[p_to].local, ERR_FILE_CANT_WRITE, "The authentication session was previously marked as completed, no more authentication data can be sent."); ERR_FAIL_COND_V_MSG(pending_peers[p_to].remote, ERR_FILE_CANT_WRITE, "The remote peer notified that the authentication session was completed, no more authentication data can be sent."); diff --git a/modules/multiplayer/scene_replication_interface.cpp b/modules/multiplayer/scene_replication_interface.cpp index 35ff62dd06..b61cf0bf1d 100644 --- a/modules/multiplayer/scene_replication_interface.cpp +++ b/modules/multiplayer/scene_replication_interface.cpp @@ -783,7 +783,7 @@ Error SceneReplicationInterface::on_delta_receive(int p_from, const uint8_t *p_b ERR_CONTINUE_MSG(true, "Ignoring delta for non-authority or invalid synchronizer."); } List<NodePath> props = sync->get_delta_properties(indexes); - ERR_FAIL_COND_V(props.size() == 0, ERR_INVALID_DATA); + ERR_FAIL_COND_V(props.is_empty(), ERR_INVALID_DATA); Vector<Variant> vars; vars.resize(props.size()); int consumed = 0; diff --git a/modules/navigation/nav_mesh_generator_3d.cpp b/modules/navigation/nav_mesh_generator_3d.cpp index b93d1dbd52..95854f29e7 100644 --- a/modules/navigation/nav_mesh_generator_3d.cpp +++ b/modules/navigation/nav_mesh_generator_3d.cpp @@ -713,7 +713,7 @@ void NavMeshGenerator3D::generator_bake_from_source_geometry_data(Ref<Navigation Vector<unsigned char> tri_areas; tri_areas.resize(ntris); - ERR_FAIL_COND(tri_areas.size() == 0); + ERR_FAIL_COND(tri_areas.is_empty()); memset(tri_areas.ptrw(), 0, ntris * sizeof(unsigned char)); rcMarkWalkableTriangles(&ctx, cfg.walkableSlopeAngle, verts, nverts, tris, ntris, tri_areas.ptrw()); diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp index 80ddfe703f..36c3faaf75 100644 --- a/modules/openxr/openxr_api.cpp +++ b/modules/openxr/openxr_api.cpp @@ -2857,7 +2857,7 @@ bool OpenXRAPI::sync_action_sets(const Vector<RID> p_active_sets) { } } - ERR_FAIL_COND_V(active_sets.size() == 0, false); + ERR_FAIL_COND_V(active_sets.is_empty(), false); XrActionsSyncInfo sync_info = { XR_TYPE_ACTIONS_SYNC_INFO, // type diff --git a/modules/svg/image_loader_svg.cpp b/modules/svg/image_loader_svg.cpp index a542bbc234..affe163aeb 100644 --- a/modules/svg/image_loader_svg.cpp +++ b/modules/svg/image_loader_svg.cpp @@ -72,7 +72,7 @@ Ref<Image> ImageLoaderSVG::load_mem_svg(const uint8_t *p_svg, int p_size, float img.instantiate(); Error err = create_image_from_utf8_buffer(img, p_svg, p_size, p_scale, false); - ERR_FAIL_COND_V(err, Ref<Image>()); + ERR_FAIL_COND_V_MSG(err != OK, Ref<Image>(), vformat("ImageLoaderSVG: Failed to create SVG from buffer, error code %d.", err)); return img; } diff --git a/modules/upnp/upnp.cpp b/modules/upnp/upnp.cpp index aef4f394b2..2812f37eb2 100644 --- a/modules/upnp/upnp.cpp +++ b/modules/upnp/upnp.cpp @@ -265,7 +265,7 @@ void UPNP::clear_devices() { } Ref<UPNPDevice> UPNP::get_gateway() const { - ERR_FAIL_COND_V_MSG(devices.size() < 1, nullptr, "Couldn't find any UPNPDevices."); + ERR_FAIL_COND_V_MSG(devices.is_empty(), nullptr, "Couldn't find any UPNPDevices."); for (int i = 0; i < devices.size(); i++) { Ref<UPNPDevice> dev = get_device(i); diff --git a/modules/websocket/remote_debugger_peer_websocket.cpp b/modules/websocket/remote_debugger_peer_websocket.cpp index 791b6d9ec9..dc6833e8c3 100644 --- a/modules/websocket/remote_debugger_peer_websocket.cpp +++ b/modules/websocket/remote_debugger_peer_websocket.cpp @@ -91,7 +91,7 @@ bool RemoteDebuggerPeerWebSocket::has_message() { } Array RemoteDebuggerPeerWebSocket::get_message() { - ERR_FAIL_COND_V(in_queue.size() < 1, Array()); + ERR_FAIL_COND_V(in_queue.is_empty(), Array()); Array msg = in_queue[0]; in_queue.pop_front(); return msg; diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index 9e706dbeef..332cf93d36 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -124,7 +124,7 @@ Error WebSocketMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buff current_packet.data = nullptr; } - ERR_FAIL_COND_V(incoming_packets.size() == 0, ERR_UNAVAILABLE); + ERR_FAIL_COND_V(incoming_packets.is_empty(), ERR_UNAVAILABLE); current_packet = incoming_packets.front()->get(); incoming_packets.pop_front(); @@ -164,7 +164,7 @@ void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) { } int WebSocketMultiplayerPeer::get_packet_peer() const { - ERR_FAIL_COND_V(incoming_packets.size() == 0, 1); + ERR_FAIL_COND_V(incoming_packets.is_empty(), 1); return incoming_packets.front()->get().source; } diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 828476edfb..5415423fb8 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -675,6 +675,7 @@ void WebXRInterfaceJS::_update_input_source(int p_input_source_id) { event->set_index(touch_index); event->set_position(position); event->set_relative(delta); + event->set_relative_screen_position(delta); Input::get_singleton()->parse_input_event(event); } } diff --git a/platform/android/android_input_handler.cpp b/platform/android/android_input_handler.cpp index 8e7f355114..373dd399e4 100644 --- a/platform/android/android_input_handler.cpp +++ b/platform/android/android_input_handler.cpp @@ -207,6 +207,7 @@ void AndroidInputHandler::process_touch_event(int p_event, int p_pointer, const ev->set_index(touch[i].id); ev->set_position(p_points[idx].pos); ev->set_relative(p_points[idx].pos - touch[i].pos); + ev->set_relative_screen_position(ev->get_relative()); Input::get_singleton()->parse_input_event(ev); touch.write[i].pos = p_points[idx].pos; } @@ -306,6 +307,7 @@ void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_an ev->set_position(p_event_pos); ev->set_global_position(p_event_pos); ev->set_relative(p_event_pos - hover_prev_pos); + ev->set_relative_screen_position(ev->get_relative()); Input::get_singleton()->parse_input_event(ev); hover_prev_pos = p_event_pos; } break; @@ -342,10 +344,12 @@ void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_an ev->set_position(hover_prev_pos); ev->set_global_position(hover_prev_pos); ev->set_relative(p_event_pos); + ev->set_relative_screen_position(p_event_pos); } else { ev->set_position(p_event_pos); ev->set_global_position(p_event_pos); ev->set_relative(p_event_pos - hover_prev_pos); + ev->set_relative_screen_position(ev->get_relative()); mouse_event_info.pos = p_event_pos; hover_prev_pos = p_event_pos; } diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm index 2f2878bfc0..9c671f2ea9 100644 --- a/platform/ios/display_server_ios.mm +++ b/platform/ios/display_server_ios.mm @@ -236,6 +236,7 @@ void DisplayServerIOS::touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x ev->set_tilt(p_tilt); ev->set_position(Vector2(p_x, p_y)); ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y)); + ev->set_relative_screen_position(ev->get_relative()); perform_event(ev); } diff --git a/platform/linuxbsd/wayland/wayland_thread.cpp b/platform/linuxbsd/wayland/wayland_thread.cpp index 0e9c3fb776..ae1d96a3b1 100644 --- a/platform/linuxbsd/wayland/wayland_thread.cpp +++ b/platform/linuxbsd/wayland/wayland_thread.cpp @@ -1514,6 +1514,8 @@ void WaylandThread::_wl_pointer_on_frame(void *data, struct wl_pointer *wl_point mm->set_relative(pd.position - old_pd.position); mm->set_velocity((Vector2)pos_delta / time_delta); } + mm->set_relative_screen_position(mm->get_relative()); + mm->set_screen_velocity(mm->get_velocity()); Ref<InputEventMessage> msg; msg.instantiate(); @@ -2411,11 +2413,13 @@ void WaylandThread::_wp_tablet_tool_on_frame(void *data, struct zwp_tablet_tool_ mm->set_pen_inverted(td.is_eraser); mm->set_relative(td.position - old_td.position); + mm->set_relative_screen_position(mm->get_relative()); // FIXME: Stop doing this to calculate speed. // FIXME2: It has been done, port this from the pointer logic once this works again. Input::get_singleton()->set_mouse_position(td.position); mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity()); + mm->set_screen_velocity(mm->get_velocity()); Ref<InputEventMessage> inputev_msg; inputev_msg.instantiate(); diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 93d528bab6..c0937b6d4f 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -4524,6 +4524,7 @@ void DisplayServerX11::process_events() { sd->set_index(index); sd->set_position(pos); sd->set_relative(pos - curr_pos_elem->value); + sd->set_relative_screen_position(sd->get_relative()); Input::get_singleton()->parse_input_event(sd); curr_pos_elem->value = pos; @@ -4945,8 +4946,10 @@ void DisplayServerX11::process_events() { mm->set_position(pos); mm->set_global_position(pos); mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity()); + mm->set_screen_velocity(mm->get_velocity()); mm->set_relative(rel); + mm->set_relative_screen_position(rel); last_mouse_pos = pos; diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm index 4505becbc2..f6f054c1e6 100644 --- a/platform/macos/godot_content_view.mm +++ b/platform/macos/godot_content_view.mm @@ -448,8 +448,10 @@ } mm->set_global_position(wd.mouse_pos); mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity()); + mm->set_screen_velocity(mm->get_velocity()); const Vector2i relativeMotion = Vector2i(delta.x, delta.y) * ds->screen_get_max_scale(); mm->set_relative(relativeMotion); + mm->set_relative_screen_position(relativeMotion); ds->get_key_modifier_state([event modifierFlags], mm); Input::get_singleton()->parse_input_event(mm); diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index aacbe4879f..bc4c0d22f0 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -328,7 +328,9 @@ void DisplayServerWeb::_mouse_move_callback(double p_x, double p_y, double p_rel ev->set_global_position(pos); ev->set_relative(Vector2(p_rel_x, p_rel_y)); + ev->set_relative_screen_position(ev->get_relative()); ev->set_velocity(Input::get_singleton()->get_last_mouse_velocity()); + ev->set_screen_velocity(ev->get_velocity()); Input::get_singleton()->parse_input_event(ev); } @@ -707,6 +709,7 @@ void DisplayServerWeb::_touch_callback(int p_type, int p_count) { Point2 &prev = ds->touches[i]; ev->set_relative(ev->get_position() - prev); + ev->set_relative_screen_position(ev->get_relative()); prev = ev->get_position(); Input::get_singleton()->parse_input_event(ev); diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index c5bcb70d9f..f0eec78b0d 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -2913,6 +2913,7 @@ void DisplayServerWindows::_drag_event(WindowID p_window, float p_x, float p_y, event->set_index(idx); event->set_position(Vector2(p_x, p_y)); event->set_relative(Vector2(p_x, p_y) - curr->get()); + event->set_relative_screen_position(event->get_relative()); Input::get_singleton()->parse_input_event(event); @@ -3425,6 +3426,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA mm->set_position(c); mm->set_global_position(c); mm->set_velocity(Vector2(0, 0)); + mm->set_screen_velocity(Vector2(0, 0)); if (raw->data.mouse.usFlags == MOUSE_MOVE_RELATIVE) { mm->set_relative(Vector2(raw->data.mouse.lLastX, raw->data.mouse.lLastY)); @@ -3449,6 +3451,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA old_x = coords.x; old_y = coords.y; } + mm->set_relative_screen_position(mm->get_relative()); if ((windows[window_id].window_has_focus || windows[window_id].is_popup) && mm->get_relative() != Vector2()) { Input::get_singleton()->parse_input_event(mm); @@ -3536,6 +3539,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity()); + mm->set_screen_velocity(mm->get_velocity()); if (old_invalid) { old_x = mm->get_position().x; @@ -3544,6 +3548,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } mm->set_relative(Vector2(mm->get_position() - Vector2(old_x, old_y))); + mm->set_relative_screen_position(mm->get_relative()); old_x = mm->get_position().x; old_y = mm->get_position().y; if (windows[window_id].window_has_focus || window_get_active_popup() == window_id) { @@ -3683,6 +3688,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity()); + mm->set_screen_velocity(mm->get_velocity()); if (old_invalid) { old_x = mm->get_position().x; @@ -3691,6 +3697,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } mm->set_relative(Vector2(mm->get_position() - Vector2(old_x, old_y))); + mm->set_relative_screen_position(mm->get_relative()); old_x = mm->get_position().x; old_y = mm->get_position().y; if (windows[window_id].window_has_focus || window_get_active_popup() == window_id) { @@ -3802,6 +3809,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity()); + mm->set_screen_velocity(mm->get_velocity()); if (old_invalid) { old_x = mm->get_position().x; @@ -3810,6 +3818,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } mm->set_relative(Vector2(mm->get_position() - Vector2(old_x, old_y))); + mm->set_relative_screen_position(mm->get_relative()); old_x = mm->get_position().x; old_y = mm->get_position().y; diff --git a/scene/3d/voxel_gi.cpp b/scene/3d/voxel_gi.cpp index 7c617e8bd2..011aecc724 100644 --- a/scene/3d/voxel_gi.cpp +++ b/scene/3d/voxel_gi.cpp @@ -79,7 +79,7 @@ Dictionary VoxelGIData::_get_data() const { if (otsize != Vector3i()) { Ref<Image> img = Image::create_from_data(otsize.x * otsize.y, otsize.z, false, Image::FORMAT_L8, get_distance_field()); Vector<uint8_t> df_png = img->save_png_to_buffer(); - ERR_FAIL_COND_V(df_png.size() == 0, Dictionary()); + ERR_FAIL_COND_V(df_png.is_empty(), Dictionary()); d["octree_df_png"] = df_png; } else { d["octree_df"] = Vector<uint8_t>(); diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 5603b2dbe4..fb7d01f115 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -100,22 +100,22 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra EngineDebugger::get_singleton()->send_message("filesystem:update_file", { arr }); } else if (p_msg == "inspect_object") { // Object Inspect - ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); ObjectID id = p_args[0]; _send_object_id(id); } else if (p_msg == "override_camera_2D:set") { // Camera - ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); bool enforce = p_args[0]; scene_tree->get_root()->enable_canvas_transform_override(enforce); } else if (p_msg == "override_camera_2D:transform") { - ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); Transform2D transform = p_args[0]; scene_tree->get_root()->set_canvas_transform_override(transform); #ifndef _3D_DISABLED } else if (p_msg == "override_camera_3D:set") { - ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); bool enable = p_args[0]; scene_tree->get_root()->enable_camera_3d_override(enable); @@ -200,7 +200,7 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra live_editor->_instance_node_func(p_args[0], p_args[1], p_args[2]); } else if (p_msg == "live_remove_node") { - ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); live_editor->_remove_node_func(p_args[0]); } else if (p_msg == "live_remove_and_keep_node") { diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 7bbc0a5ec5..b9b68127db 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -82,7 +82,7 @@ Dictionary Control::_edit_get_state() const { } void Control::_edit_set_state(const Dictionary &p_state) { - ERR_FAIL_COND((p_state.size() <= 0) || + ERR_FAIL_COND(p_state.is_empty() || !p_state.has("rotation") || !p_state.has("scale") || !p_state.has("pivot") || !p_state.has("anchors") || !p_state.has("offsets") || !p_state.has("layout_mode") || !p_state.has("anchors_layout_preset")); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index e2925920a2..95dc50f203 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -3927,7 +3927,7 @@ void TextEdit::end_complex_operation() { if (complex_operation_count > 0) { return; } - ERR_FAIL_COND(undo_stack.size() == 0); + ERR_FAIL_COND(undo_stack.is_empty()); undo_stack.back()->get().end_carets = carets; if (undo_stack.back()->get().chain_forward) { diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index fa14ad5b3c..0f89784369 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -50,12 +50,14 @@ Error HTTPRequest::_parse_url(const String &p_url) { String scheme; Error err = p_url.parse_url(scheme, url, port, request_string); - ERR_FAIL_COND_V_MSG(err != OK, err, "Error parsing URL: " + p_url + "."); + ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Error parsing URL: '%s'.", p_url)); + if (scheme == "https://") { use_tls = true; } else if (scheme != "http://") { - ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, "Invalid URL scheme: " + scheme + "."); + ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, vformat("Invalid URL scheme: '%s'.", scheme)); } + if (port == 0) { port = use_tls ? 443 : 80; } diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 6532a15114..0245584f17 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -4866,7 +4866,7 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol p.offset = data_tracks[i].data.size(); time_tracks[i].packets.push_back(p); } else { - ERR_FAIL_COND(time_tracks[i].packets.size() == 0); + ERR_FAIL_COND(time_tracks[i].packets.is_empty()); time_tracks[i].packets[time_tracks[i].packets.size() - 1].count++; } } @@ -4953,7 +4953,7 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol p.offset = data_tracks[comp_track].data.size(); time_tracks[comp_track].packets.push_back(p); } else { - ERR_CONTINUE(time_tracks[comp_track].packets.size() == 0); + ERR_CONTINUE(time_tracks[comp_track].packets.is_empty()); time_tracks[comp_track].packets[time_tracks[comp_track].packets.size() - 1].count++; } } diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp index dde556c264..a51e28c9fe 100644 --- a/scene/resources/immediate_mesh.cpp +++ b/scene/resources/immediate_mesh.cpp @@ -147,7 +147,7 @@ void ImmediateMesh::surface_add_vertex_2d(const Vector2 &p_vertex) { void ImmediateMesh::surface_end() { ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); - ERR_FAIL_COND_MSG(!vertices.size(), "No vertices were added, surface can't be created."); + ERR_FAIL_COND_MSG(vertices.is_empty(), "No vertices were added, surface can't be created."); uint64_t format = ARRAY_FORMAT_VERTEX | ARRAY_FLAG_FORMAT_CURRENT_VERSION; diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp index 2ffb8da46c..952e99608d 100644 --- a/scene/resources/importer_mesh.cpp +++ b/scene/resources/importer_mesh.cpp @@ -186,7 +186,7 @@ void ImporterMesh::add_surface(Mesh::PrimitiveType p_primitive, const Array &p_a Surface::LOD lod; lod.distance = E; lod.indices = p_lods[E]; - ERR_CONTINUE(lod.indices.size() == 0); + ERR_CONTINUE(lod.indices.is_empty()); s.lods.push_back(lod); } @@ -684,7 +684,7 @@ bool ImporterMesh::has_mesh() const { } Ref<ArrayMesh> ImporterMesh::get_mesh(const Ref<ArrayMesh> &p_base) { - ERR_FAIL_COND_V(surfaces.size() == 0, Ref<ArrayMesh>()); + ERR_FAIL_COND_V(surfaces.is_empty(), Ref<ArrayMesh>()); if (mesh.is_null()) { if (p_base.is_valid()) { diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index de81b9d785..e90f163546 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -1192,7 +1192,7 @@ void SceneState::update_instance_resource(String p_path, Ref<PackedScene> p_pack } int SceneState::find_node_by_path(const NodePath &p_node) const { - ERR_FAIL_COND_V_MSG(node_path_cache.size() == 0, -1, "This operation requires the node cache to have been built."); + ERR_FAIL_COND_V_MSG(node_path_cache.is_empty(), -1, "This operation requires the node cache to have been built."); if (!node_path_cache.has(p_node)) { if (get_base_scene_state().is_valid()) { diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index eb28c9e601..b8b4854109 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -52,7 +52,7 @@ void PrimitiveMesh::_update() const { Vector<Vector3> points = arr[RS::ARRAY_VERTEX]; - ERR_FAIL_COND_MSG(points.size() == 0, "_create_mesh_array must return at least a vertex array."); + ERR_FAIL_COND_MSG(points.is_empty(), "_create_mesh_array must return at least a vertex array."); aabb = AABB(); diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 73baba6c93..653f234d3d 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -690,7 +690,7 @@ Array SurfaceTool::commit_to_arrays() { } break; case Mesh::ARRAY_INDEX: { - ERR_CONTINUE(index_array.size() == 0); + ERR_CONTINUE(index_array.is_empty()); Vector<int> array; array.resize(index_array.size()); @@ -1280,7 +1280,7 @@ SurfaceTool::CustomFormat SurfaceTool::get_custom_format(int p_channel_index) co } void SurfaceTool::optimize_indices_for_cache() { ERR_FAIL_NULL(optimize_vertex_cache_func); - ERR_FAIL_COND(index_array.size() == 0); + ERR_FAIL_COND(index_array.is_empty()); ERR_FAIL_COND(primitive != Mesh::PRIMITIVE_TRIANGLES); ERR_FAIL_COND(index_array.size() % 3 != 0); @@ -1290,7 +1290,7 @@ void SurfaceTool::optimize_indices_for_cache() { } AABB SurfaceTool::get_aabb() const { - ERR_FAIL_COND_V(vertex_array.size() == 0, AABB()); + ERR_FAIL_COND_V(vertex_array.is_empty(), AABB()); AABB aabb; for (uint32_t i = 0; i < vertex_array.size(); i++) { @@ -1310,8 +1310,8 @@ Vector<int> SurfaceTool::generate_lod(float p_threshold, int p_target_index_coun ERR_FAIL_NULL_V(simplify_func, lod); ERR_FAIL_COND_V(p_target_index_count < 0, lod); - ERR_FAIL_COND_V(vertex_array.size() == 0, lod); - ERR_FAIL_COND_V(index_array.size() == 0, lod); + ERR_FAIL_COND_V(vertex_array.is_empty(), lod); + ERR_FAIL_COND_V(index_array.is_empty(), lod); ERR_FAIL_COND_V(index_array.size() % 3 != 0, lod); ERR_FAIL_COND_V(index_array.size() < (unsigned int)p_target_index_count, lod); diff --git a/scene/theme/theme_owner.cpp b/scene/theme/theme_owner.cpp index b559c8c58d..8cdffe8c73 100644 --- a/scene/theme/theme_owner.cpp +++ b/scene/theme/theme_owner.cpp @@ -250,7 +250,7 @@ void ThemeOwner::get_theme_type_dependencies(const Node *p_for_node, const Strin } Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const StringName &p_name, const List<StringName> &p_theme_types) { - ERR_FAIL_COND_V_MSG(p_theme_types.size() == 0, Variant(), "At least one theme type must be specified."); + ERR_FAIL_COND_V_MSG(p_theme_types.is_empty(), Variant(), "At least one theme type must be specified."); // First, look through each control or window node in the branch, until no valid parent can be found. // Only nodes with a theme resource attached are considered. @@ -286,7 +286,7 @@ Variant ThemeOwner::get_theme_item_in_types(Theme::DataType p_data_type, const S } bool ThemeOwner::has_theme_item_in_types(Theme::DataType p_data_type, const StringName &p_name, const List<StringName> &p_theme_types) { - ERR_FAIL_COND_V_MSG(p_theme_types.size() == 0, false, "At least one theme type must be specified."); + ERR_FAIL_COND_V_MSG(p_theme_types.is_empty(), false, "At least one theme type must be specified."); // First, look through each control or window node in the branch, until no valid parent can be found. // Only nodes with a theme resource attached are considered. diff --git a/servers/audio/effects/audio_effect_record.cpp b/servers/audio/effects/audio_effect_record.cpp index 6e49bb122b..e1e9270074 100644 --- a/servers/audio/effects/audio_effect_record.cpp +++ b/servers/audio/effects/audio_effect_record.cpp @@ -204,7 +204,7 @@ Ref<AudioStreamWAV> AudioEffectRecord::get_recording() const { Vector<uint8_t> dst_data; ERR_FAIL_COND_V(current_instance.is_null(), nullptr); - ERR_FAIL_COND_V(current_instance->recording_data.size() == 0, nullptr); + ERR_FAIL_COND_V(current_instance->recording_data.is_empty(), nullptr); if (dst_format == AudioStreamWAV::FORMAT_8_BITS) { int data_size = current_instance->recording_data.size(); diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index f340f7bbf8..4a901897de 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -1589,7 +1589,7 @@ void AudioServer::remove_listener_changed_callback(AudioCallback p_callback, voi } void AudioServer::set_bus_layout(const Ref<AudioBusLayout> &p_bus_layout) { - ERR_FAIL_COND(p_bus_layout.is_null() || p_bus_layout->buses.size() == 0); + ERR_FAIL_COND(p_bus_layout.is_null() || p_bus_layout->buses.is_empty()); lock(); for (int i = 0; i < buses.size(); i++) { diff --git a/servers/physics_2d/godot_shape_2d.cpp b/servers/physics_2d/godot_shape_2d.cpp index 2b3f496fc0..db5e6b2353 100644 --- a/servers/physics_2d/godot_shape_2d.cpp +++ b/servers/physics_2d/godot_shape_2d.cpp @@ -584,7 +584,7 @@ void GodotConvexPolygonShape2D::set_data(const Variant &p_data) { if (p_data.get_type() == Variant::PACKED_VECTOR2_ARRAY) { Vector<Vector2> arr = p_data; - ERR_FAIL_COND(arr.size() == 0); + ERR_FAIL_COND(arr.is_empty()); point_count = arr.size(); points = memnew_arr(Point, point_count); const Vector2 *r = arr.ptr(); diff --git a/servers/rendering/renderer_rd/shader_rd.cpp b/servers/rendering/renderer_rd/shader_rd.cpp index 1c54ce5657..6230b93ebc 100644 --- a/servers/rendering/renderer_rd/shader_rd.cpp +++ b/servers/rendering/renderer_rd/shader_rd.cpp @@ -138,7 +138,7 @@ void ShaderRD::setup(const char *p_vertex_code, const char *p_fragment_code, con RID ShaderRD::version_create() { //initialize() was never called - ERR_FAIL_COND_V(group_to_variant_map.size() == 0, RID()); + ERR_FAIL_COND_V(group_to_variant_map.is_empty(), RID()); Version version; version.dirty = true; @@ -301,7 +301,7 @@ void ShaderRD::_compile_variant(uint32_t p_variant, const CompileData *p_data) { Vector<uint8_t> shader_data = RD::get_singleton()->shader_compile_binary_from_spirv(stages, name + ":" + itos(variant)); - ERR_FAIL_COND(shader_data.size() == 0); + ERR_FAIL_COND(shader_data.is_empty()); { MutexLock lock(variant_set_mutex); @@ -714,7 +714,7 @@ ShaderRD::ShaderRD() { void ShaderRD::initialize(const Vector<String> &p_variant_defines, const String &p_general_defines) { ERR_FAIL_COND(variant_defines.size()); - ERR_FAIL_COND(p_variant_defines.size() == 0); + ERR_FAIL_COND(p_variant_defines.is_empty()); general_defines = p_general_defines.utf8(); @@ -776,7 +776,7 @@ void ShaderRD::_initialize_cache() { // Same as above, but allows specifying shader compilation groups. void ShaderRD::initialize(const Vector<VariantDefine> &p_variant_defines, const String &p_general_defines) { ERR_FAIL_COND(variant_defines.size()); - ERR_FAIL_COND(p_variant_defines.size() == 0); + ERR_FAIL_COND(p_variant_defines.is_empty()); general_defines = p_general_defines.utf8(); diff --git a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp index 245dac94ac..05929a862a 100644 --- a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp @@ -529,7 +529,7 @@ void MeshStorage::mesh_surface_update_vertex_region(RID p_mesh, int p_surface, i Mesh *mesh = mesh_owner.get_or_null(p_mesh); ERR_FAIL_NULL(mesh); ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count); - ERR_FAIL_COND(p_data.size() == 0); + ERR_FAIL_COND(p_data.is_empty()); ERR_FAIL_COND(mesh->surfaces[p_surface]->vertex_buffer.is_null()); uint64_t data_size = p_data.size(); const uint8_t *r = p_data.ptr(); @@ -541,7 +541,7 @@ void MeshStorage::mesh_surface_update_attribute_region(RID p_mesh, int p_surface Mesh *mesh = mesh_owner.get_or_null(p_mesh); ERR_FAIL_NULL(mesh); ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count); - ERR_FAIL_COND(p_data.size() == 0); + ERR_FAIL_COND(p_data.is_empty()); ERR_FAIL_COND(mesh->surfaces[p_surface]->attribute_buffer.is_null()); uint64_t data_size = p_data.size(); const uint8_t *r = p_data.ptr(); @@ -553,7 +553,7 @@ void MeshStorage::mesh_surface_update_skin_region(RID p_mesh, int p_surface, int Mesh *mesh = mesh_owner.get_or_null(p_mesh); ERR_FAIL_NULL(mesh); ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_surface, mesh->surface_count); - ERR_FAIL_COND(p_data.size() == 0); + ERR_FAIL_COND(p_data.is_empty()); ERR_FAIL_COND(mesh->surfaces[p_surface]->skin_buffer.is_null()); uint64_t data_size = p_data.size(); const uint8_t *r = p_data.ptr(); diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index 7784ad5d49..dd94982f1a 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -859,7 +859,7 @@ void TextureStorage::texture_2d_initialize(RID p_texture, const Ref<Image> &p_im } void TextureStorage::texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) { - ERR_FAIL_COND(p_layers.size() == 0); + ERR_FAIL_COND(p_layers.is_empty()); ERR_FAIL_COND(p_layered_type == RS::TEXTURE_LAYERED_CUBEMAP && p_layers.size() != 6); ERR_FAIL_COND(p_layered_type == RS::TEXTURE_LAYERED_CUBEMAP_ARRAY && (p_layers.size() < 6 || (p_layers.size() % 6) != 0)); @@ -971,7 +971,7 @@ void TextureStorage::texture_2d_layered_initialize(RID p_texture, const Vector<R } void TextureStorage::texture_3d_initialize(RID p_texture, Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) { - ERR_FAIL_COND(p_data.size() == 0); + ERR_FAIL_COND(p_data.is_empty()); Image::Image3DValidateError verr = Image::validate_3d_image(p_format, p_width, p_height, p_depth, p_mipmaps, p_data); if (verr != Image::VALIDATE_3D_OK) { @@ -1269,7 +1269,7 @@ Ref<Image> TextureStorage::texture_2d_get(RID p_texture) const { } #endif Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, 0); - ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); + ERR_FAIL_COND_V(data.is_empty(), Ref<Image>()); Ref<Image> image; // Expand RGB10_A2 into RGBAH. This is needed for capturing viewport data @@ -1318,7 +1318,7 @@ Ref<Image> TextureStorage::texture_2d_layer_get(RID p_texture, int p_layer) cons ERR_FAIL_NULL_V(tex, Ref<Image>()); Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, p_layer); - ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); + ERR_FAIL_COND_V(data.is_empty(), Ref<Image>()); Ref<Image> image = Image::create_from_data(tex->width, tex->height, tex->mipmaps > 1, tex->validated_format, data); ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); if (tex->format != tex->validated_format) { diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp index 0c95301402..5d65118159 100644 --- a/servers/rendering/rendering_device.cpp +++ b/servers/rendering/rendering_device.cpp @@ -146,7 +146,7 @@ String RenderingDevice::shader_get_spirv_cache_key() const { RID RenderingDevice::shader_create_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name) { Vector<uint8_t> bytecode = shader_compile_binary_from_spirv(p_spirv, p_shader_name); - ERR_FAIL_COND_V(bytecode.size() == 0, RID()); + ERR_FAIL_COND_V(bytecode.is_empty(), RID()); return shader_create_from_bytecode(bytecode); } @@ -2464,12 +2464,12 @@ RID RenderingDevice::uniform_buffer_create(uint32_t p_size_bytes, const Vector<u RID RenderingDevice::uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set) { _THREAD_SAFE_METHOD_ - ERR_FAIL_COND_V(p_uniforms.size() == 0, RID()); + ERR_FAIL_COND_V(p_uniforms.is_empty(), RID()); Shader *shader = shader_owner.get_or_null(p_shader); ERR_FAIL_NULL_V(shader, RID()); - ERR_FAIL_COND_V_MSG(p_shader_set >= (uint32_t)shader->uniform_sets.size() || shader->uniform_sets[p_shader_set].size() == 0, RID(), + ERR_FAIL_COND_V_MSG(p_shader_set >= (uint32_t)shader->uniform_sets.size() || shader->uniform_sets[p_shader_set].is_empty(), RID(), "Desired set (" + itos(p_shader_set) + ") not used by shader."); // See that all sets in shader are satisfied. diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 99b1c5631a..99b0b1886c 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -901,7 +901,7 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint64_t p_format, uint ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_INT32_ARRAY, ERR_INVALID_PARAMETER); Vector<int> indices = p_arrays[ai]; - ERR_FAIL_COND_V(indices.size() == 0, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(indices.is_empty(), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(indices.size() != p_index_array_len, ERR_INVALID_PARAMETER); /* determine whether using 16 or 32 bits indices */ @@ -1326,7 +1326,7 @@ Error RenderingServer::mesh_create_surface_data_from_arrays(SurfaceData *r_surfa float distance = E; ERR_CONTINUE(distance <= 0.0); Vector<int> indices = p_lods[E]; - ERR_CONTINUE(indices.size() == 0); + ERR_CONTINUE(indices.is_empty()); uint32_t index_count = indices.size(); ERR_CONTINUE(index_count >= (uint32_t)index_array_len); // Should be smaller.. @@ -1781,7 +1781,7 @@ Array RenderingServer::mesh_create_arrays_from_surface_data(const SurfaceData &p Vector<uint8_t> attrib_data = p_data.attribute_data; Vector<uint8_t> skin_data = p_data.skin_data; - ERR_FAIL_COND_V(vertex_data.size() == 0 && (p_data.format & RS::ARRAY_FORMAT_VERTEX), Array()); + ERR_FAIL_COND_V(vertex_data.is_empty() && (p_data.format & RS::ARRAY_FORMAT_VERTEX), Array()); int vertex_len = p_data.vertex_count; Vector<uint8_t> index_data = p_data.index_data; |