diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.cpp | 1 | ||||
-rw-r--r-- | core/extension/gdnative_interface.cpp | 8 | ||||
-rw-r--r-- | core/extension/gdnative_interface.h | 1 | ||||
-rw-r--r-- | core/input/input.cpp | 2 | ||||
-rw-r--r-- | core/io/image.cpp | 119 | ||||
-rw-r--r-- | core/io/image.h | 2 | ||||
-rw-r--r-- | core/math/color.h | 4 | ||||
-rw-r--r-- | core/os/time.cpp | 121 | ||||
-rw-r--r-- | core/variant/variant.h | 1 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 4 | ||||
-rw-r--r-- | core/variant/variant_setget.cpp | 104 |
11 files changed, 243 insertions, 124 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 53c58084ac..892b74c26a 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -1072,7 +1072,6 @@ Error File::open_compressed(const String &p_path, ModeFlags p_mode_flags, Compre } Error File::open(const String &p_path, ModeFlags p_mode_flags) { - close(); Error err; f = FileAccess::open(p_path, p_mode_flags, &err); if (f.is_valid()) { diff --git a/core/extension/gdnative_interface.cpp b/core/extension/gdnative_interface.cpp index b5b340731d..a312ce4ebd 100644 --- a/core/extension/gdnative_interface.cpp +++ b/core/extension/gdnative_interface.cpp @@ -241,6 +241,13 @@ static GDNativeBool gdnative_variant_booleanize(const GDNativeVariantPtr p_self) return self->booleanize(); } +static void gdnative_variant_sub(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, GDNativeVariantPtr r_dst) { + const Variant *a = (const Variant *)p_a; + const Variant *b = (const Variant *)p_b; + memnew_placement(r_dst, Variant); + Variant::sub(*a, *b, *(Variant *)r_dst); +} + static void gdnative_variant_blend(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, float p_c, GDNativeVariantPtr r_dst) { const Variant *a = (const Variant *)p_a; const Variant *b = (const Variant *)p_b; @@ -939,6 +946,7 @@ void gdnative_setup_interface(GDNativeInterface *p_interface) { gdni.variant_iter_get = gdnative_variant_iter_get; gdni.variant_hash_compare = gdnative_variant_hash_compare; gdni.variant_booleanize = gdnative_variant_booleanize; + gdni.variant_sub = gdnative_variant_sub; gdni.variant_blend = gdnative_variant_blend; gdni.variant_interpolate = gdnative_variant_interpolate; gdni.variant_duplicate = gdnative_variant_duplicate; diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h index 732a1b5af0..2bac52dc4a 100644 --- a/core/extension/gdnative_interface.h +++ b/core/extension/gdnative_interface.h @@ -416,6 +416,7 @@ typedef struct { void (*variant_iter_get)(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeVariantPtr r_ret, GDNativeBool *r_valid); GDNativeBool (*variant_hash_compare)(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_other); GDNativeBool (*variant_booleanize)(const GDNativeVariantPtr p_self); + void (*variant_sub)(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, GDNativeVariantPtr r_dst); void (*variant_blend)(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, float p_c, GDNativeVariantPtr r_dst); void (*variant_interpolate)(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, float p_c, GDNativeVariantPtr r_dst); void (*variant_duplicate)(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_ret, GDNativeBool p_deep); diff --git a/core/input/input.cpp b/core/input/input.cpp index 343076b4e1..0db20a7c82 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -855,6 +855,8 @@ void Input::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, co return; } + ERR_FAIL_INDEX(p_shape, CursorShape::CURSOR_MAX); + set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot); } diff --git a/core/io/image.cpp b/core/io/image.cpp index fad9942017..661a9f7177 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -2442,6 +2442,39 @@ Ref<Image> Image::get_rect(const Rect2 &p_area) const { return img; } +void Image::_get_clipped_src_and_dest_rects(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest, Rect2i &r_clipped_src_rect, Rect2i &r_clipped_dest_rect) const { + r_clipped_dest_rect.position = p_dest; + r_clipped_src_rect = p_src_rect; + + if (r_clipped_src_rect.position.x < 0) { + r_clipped_dest_rect.position.x -= r_clipped_src_rect.position.x; + r_clipped_src_rect.size.x += r_clipped_src_rect.position.x; + r_clipped_src_rect.position.x = 0; + } + if (r_clipped_src_rect.position.y < 0) { + r_clipped_dest_rect.position.y -= r_clipped_src_rect.position.y; + r_clipped_src_rect.size.y += r_clipped_src_rect.position.y; + r_clipped_src_rect.position.y = 0; + } + + if (r_clipped_dest_rect.position.x < 0) { + r_clipped_src_rect.position.x -= r_clipped_dest_rect.position.x; + r_clipped_src_rect.size.x += r_clipped_dest_rect.position.x; + r_clipped_dest_rect.position.x = 0; + } + if (r_clipped_dest_rect.position.y < 0) { + r_clipped_src_rect.position.y -= r_clipped_dest_rect.position.y; + r_clipped_src_rect.size.y += r_clipped_dest_rect.position.y; + r_clipped_dest_rect.position.y = 0; + } + + r_clipped_src_rect.size.x = MAX(0, MIN(r_clipped_src_rect.size.x, MIN(p_src->width - r_clipped_src_rect.position.x, width - r_clipped_dest_rect.position.x))); + r_clipped_src_rect.size.y = MAX(0, MIN(r_clipped_src_rect.size.y, MIN(p_src->height - r_clipped_src_rect.position.y, height - r_clipped_dest_rect.position.y))); + + r_clipped_dest_rect.size.x = r_clipped_src_rect.size.x; + r_clipped_dest_rect.size.y = r_clipped_src_rect.size.y; +} + void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest) { ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); @@ -2451,22 +2484,13 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po ERR_FAIL_COND(format != p_src->format); ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot blit_rect in compressed or custom image formats."); - Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).intersection(p_src_rect); - - if (p_dest.x < 0) { - clipped_src_rect.position.x = ABS(p_dest.x); - } - if (p_dest.y < 0) { - clipped_src_rect.position.y = ABS(p_dest.y); - } - - if (clipped_src_rect.has_no_area()) { + Rect2i src_rect; + Rect2i dest_rect; + _get_clipped_src_and_dest_rects(p_src, p_src_rect, p_dest, src_rect, dest_rect); + if (src_rect.has_no_area() || dest_rect.has_no_area()) { return; } - Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y)); - Rect2i dest_rect = Rect2i(0, 0, width, height).intersection(Rect2i(p_dest - src_underscan, clipped_src_rect.size)); - uint8_t *wp = data.ptrw(); uint8_t *dst_data_ptr = wp; @@ -2477,8 +2501,8 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po for (int i = 0; i < dest_rect.size.y; i++) { for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; - int src_y = clipped_src_rect.position.y + i; + int src_x = src_rect.position.x + j; + int src_y = src_rect.position.y + i; int dst_x = dest_rect.position.x + j; int dst_y = dest_rect.position.y + i; @@ -2506,22 +2530,13 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co ERR_FAIL_COND_MSG(p_src->height != p_mask->height, "Source image height is different from mask height."); ERR_FAIL_COND(format != p_src->format); - Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).intersection(p_src_rect); - - if (p_dest.x < 0) { - clipped_src_rect.position.x = ABS(p_dest.x); - } - if (p_dest.y < 0) { - clipped_src_rect.position.y = ABS(p_dest.y); - } - - if (clipped_src_rect.has_no_area()) { + Rect2i src_rect; + Rect2i dest_rect; + _get_clipped_src_and_dest_rects(p_src, p_src_rect, p_dest, src_rect, dest_rect); + if (src_rect.has_no_area() || dest_rect.has_no_area()) { return; } - Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y)); - Rect2i dest_rect = Rect2i(0, 0, width, height).intersection(Rect2i(p_dest - src_underscan, clipped_src_rect.size)); - uint8_t *wp = data.ptrw(); uint8_t *dst_data_ptr = wp; @@ -2534,8 +2549,8 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co for (int i = 0; i < dest_rect.size.y; i++) { for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; - int src_y = clipped_src_rect.position.y + i; + int src_x = src_rect.position.x + j; + int src_y = src_rect.position.y + i; if (msk->get_pixel(src_x, src_y).a != 0) { int dst_x = dest_rect.position.x + j; @@ -2560,28 +2575,19 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P ERR_FAIL_COND(srcdsize == 0); ERR_FAIL_COND(format != p_src->format); - Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).intersection(p_src_rect); - - if (p_dest.x < 0) { - clipped_src_rect.position.x = ABS(p_dest.x); - } - if (p_dest.y < 0) { - clipped_src_rect.position.y = ABS(p_dest.y); - } - - if (clipped_src_rect.has_no_area()) { + Rect2i src_rect; + Rect2i dest_rect; + _get_clipped_src_and_dest_rects(p_src, p_src_rect, p_dest, src_rect, dest_rect); + if (src_rect.has_no_area() || dest_rect.has_no_area()) { return; } - Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y)); - Rect2i dest_rect = Rect2i(0, 0, width, height).intersection(Rect2i(p_dest - src_underscan, clipped_src_rect.size)); - Ref<Image> img = p_src; for (int i = 0; i < dest_rect.size.y; i++) { for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; - int src_y = clipped_src_rect.position.y + i; + int src_x = src_rect.position.x + j; + int src_y = src_rect.position.y + i; int dst_x = dest_rect.position.x + j; int dst_y = dest_rect.position.y + i; @@ -2609,29 +2615,20 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c ERR_FAIL_COND_MSG(p_src->height != p_mask->height, "Source image height is different from mask height."); ERR_FAIL_COND(format != p_src->format); - Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).intersection(p_src_rect); - - if (p_dest.x < 0) { - clipped_src_rect.position.x = ABS(p_dest.x); - } - if (p_dest.y < 0) { - clipped_src_rect.position.y = ABS(p_dest.y); - } - - if (clipped_src_rect.has_no_area()) { + Rect2i src_rect; + Rect2i dest_rect; + _get_clipped_src_and_dest_rects(p_src, p_src_rect, p_dest, src_rect, dest_rect); + if (src_rect.has_no_area() || dest_rect.has_no_area()) { return; } - Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y)); - Rect2i dest_rect = Rect2i(0, 0, width, height).intersection(Rect2i(p_dest - src_underscan, clipped_src_rect.size)); - Ref<Image> img = p_src; Ref<Image> msk = p_mask; for (int i = 0; i < dest_rect.size.y; i++) { for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; - int src_y = clipped_src_rect.position.y + i; + int src_x = src_rect.position.x + j; + int src_y = src_rect.position.y + i; // If the mask's pixel is transparent then we skip it //Color c = msk->get_pixel(src_x, src_y); @@ -3276,7 +3273,7 @@ Ref<Image> Image::rgbe_to_srgb() { for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { - new_image->set_pixel(col, row, get_pixel(col, row).to_srgb()); + new_image->set_pixel(col, row, get_pixel(col, row).linear_to_srgb()); } } diff --git a/core/io/image.h b/core/io/image.h index 7e1e853244..1025554d51 100644 --- a/core/io/image.h +++ b/core/io/image.h @@ -175,6 +175,8 @@ private: static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1, int *r_mm_width = nullptr, int *r_mm_height = nullptr); bool _can_modify(Format p_format) const; + _FORCE_INLINE_ void _get_clipped_src_and_dest_rects(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest, Rect2i &r_clipped_src_rect, Rect2i &r_clipped_dest_rect) const; + _FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixel_size, uint8_t *p_data, const uint8_t *p_pixel); _FORCE_INLINE_ void _get_pixelb(int p_x, int p_y, uint32_t p_pixel_size, const uint8_t *p_data, uint8_t *p_pixel); diff --git a/core/math/color.h b/core/math/color.h index b90a0f33a2..91e0bf5532 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -169,14 +169,14 @@ struct _NO_DISCARD_ Color { return res; } - _FORCE_INLINE_ Color to_linear() const { + _FORCE_INLINE_ Color srgb_to_linear() const { return Color( r < 0.04045f ? r * (1.0 / 12.92) : Math::pow((r + 0.055f) * (float)(1.0 / (1 + 0.055)), 2.4f), g < 0.04045f ? g * (1.0 / 12.92) : Math::pow((g + 0.055f) * (float)(1.0 / (1 + 0.055)), 2.4f), b < 0.04045f ? b * (1.0 / 12.92) : Math::pow((b + 0.055f) * (float)(1.0 / (1 + 0.055)), 2.4f), a); } - _FORCE_INLINE_ Color to_srgb() const { + _FORCE_INLINE_ Color linear_to_srgb() const { return Color( r < 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * Math::pow(r, 1.0f / 2.4f) - 0.055f, g < 0.0031308f ? 12.92f * g : (1.0f + 0.055f) * Math::pow(g, 1.0f / 2.4f) - 0.055f, diff --git a/core/os/time.cpp b/core/os/time.cpp index e339805475..2c6b142140 100644 --- a/core/os/time.cpp +++ b/core/os/time.cpp @@ -95,16 +95,16 @@ VARIANT_ENUM_CAST(Time::Weekday); day = day_number_copy + 1; \ } -#define VALIDATE_YMDHMS \ - ERR_FAIL_COND_V_MSG(month == 0, 0, "Invalid month value of: " + itos(month) + ", months are 1-indexed and cannot be 0. See the Time.Month enum for valid values."); \ - ERR_FAIL_COND_V_MSG(month > 12, 0, "Invalid month value of: " + itos(month) + ". See the Time.Month enum for valid values."); \ - ERR_FAIL_COND_V_MSG(hour > 23, 0, "Invalid hour value of: " + itos(hour) + "."); \ - ERR_FAIL_COND_V_MSG(minute > 59, 0, "Invalid minute value of: " + itos(minute) + "."); \ - ERR_FAIL_COND_V_MSG(second > 59, 0, "Invalid second value of: " + itos(second) + " (leap seconds are not supported)."); \ - /* Do this check after month is tested as valid. */ \ - ERR_FAIL_COND_V_MSG(day == 0, 0, "Invalid day value of: " + itos(month) + ", days are 1-indexed and cannot be 0."); \ - uint8_t days_in_this_month = MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month - 1]; \ - ERR_FAIL_COND_V_MSG(day > days_in_this_month, 0, "Invalid day value of: " + itos(day) + " which is larger than the maximum for this month, " + itos(days_in_this_month) + "."); +#define VALIDATE_YMDHMS(ret) \ + ERR_FAIL_COND_V_MSG(month == 0, ret, "Invalid month value of: " + itos(month) + ", months are 1-indexed and cannot be 0. See the Time.Month enum for valid values."); \ + ERR_FAIL_COND_V_MSG(month > 12, ret, "Invalid month value of: " + itos(month) + ". See the Time.Month enum for valid values."); \ + ERR_FAIL_COND_V_MSG(hour > 23, ret, "Invalid hour value of: " + itos(hour) + "."); \ + ERR_FAIL_COND_V_MSG(minute > 59, ret, "Invalid minute value of: " + itos(minute) + "."); \ + ERR_FAIL_COND_V_MSG(second > 59, ret, "Invalid second value of: " + itos(second) + " (leap seconds are not supported)."); \ + /* Do this check after month is tested as valid. */ \ + ERR_FAIL_COND_V_MSG(day == 0, ret, "Invalid day value of: " + itos(month) + ", days are 1-indexed and cannot be 0."); \ + uint8_t days_in_this_month = MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month - 1]; \ + ERR_FAIL_COND_V_MSG(day > days_in_this_month, ret, "Invalid day value of: " + itos(day) + " which is larger than the maximum for this month, " + itos(days_in_this_month) + "."); #define YMD_TO_DAY_NUMBER \ /* The day number since Unix epoch (0-index). Days before 1970 are negative. */ \ @@ -124,50 +124,54 @@ VARIANT_ENUM_CAST(Time::Weekday); } \ } -#define PARSE_ISO8601_STRING \ - int64_t year = UNIX_EPOCH_YEAR_AD; \ - Month month = MONTH_JANUARY; \ - uint8_t day = 1; \ - uint8_t hour = 0; \ - uint8_t minute = 0; \ - uint8_t second = 0; \ - { \ - bool has_date = false, has_time = false; \ - String date, time; \ - if (p_datetime.find_char('T') > 0) { \ - has_date = has_time = true; \ - PackedStringArray array = p_datetime.split("T"); \ - date = array[0]; \ - time = array[1]; \ - } else if (p_datetime.find_char(' ') > 0) { \ - has_date = has_time = true; \ - PackedStringArray array = p_datetime.split(" "); \ - date = array[0]; \ - time = array[1]; \ - } else if (p_datetime.find_char('-', 1) > 0) { \ - has_date = true; \ - date = p_datetime; \ - } else if (p_datetime.find_char(':') > 0) { \ - has_time = true; \ - time = p_datetime; \ - } \ - /* Set the variables from the contents of the string. */ \ - if (has_date) { \ - PackedInt32Array array = date.split_ints("-", false); \ - year = array[0]; \ - month = (Month)array[1]; \ - day = array[2]; \ - /* Handle negative years. */ \ - if (p_datetime.find_char('-') == 0) { \ - year *= -1; \ - } \ - } \ - if (has_time) { \ - PackedInt32Array array = time.split_ints(":", false); \ - hour = array[0]; \ - minute = array[1]; \ - second = array[2]; \ - } \ +#define PARSE_ISO8601_STRING(ret) \ + int64_t year = UNIX_EPOCH_YEAR_AD; \ + Month month = MONTH_JANUARY; \ + uint8_t day = 1; \ + uint8_t hour = 0; \ + uint8_t minute = 0; \ + uint8_t second = 0; \ + { \ + bool has_date = false, has_time = false; \ + String date, time; \ + if (p_datetime.find_char('T') > 0) { \ + has_date = has_time = true; \ + PackedStringArray array = p_datetime.split("T"); \ + ERR_FAIL_COND_V_MSG(array.size() < 2, ret, "Invalid ISO 8601 date/time string."); \ + date = array[0]; \ + time = array[1]; \ + } else if (p_datetime.find_char(' ') > 0) { \ + has_date = has_time = true; \ + PackedStringArray array = p_datetime.split(" "); \ + ERR_FAIL_COND_V_MSG(array.size() < 2, ret, "Invalid ISO 8601 date/time string."); \ + date = array[0]; \ + time = array[1]; \ + } else if (p_datetime.find_char('-', 1) > 0) { \ + has_date = true; \ + date = p_datetime; \ + } else if (p_datetime.find_char(':') > 0) { \ + has_time = true; \ + time = p_datetime; \ + } \ + /* Set the variables from the contents of the string. */ \ + if (has_date) { \ + PackedInt32Array array = date.split_ints("-", false); \ + ERR_FAIL_COND_V_MSG(array.size() < 3, ret, "Invalid ISO 8601 date string."); \ + year = array[0]; \ + month = (Month)array[1]; \ + day = array[2]; \ + /* Handle negative years. */ \ + if (p_datetime.find_char('-') == 0) { \ + year *= -1; \ + } \ + } \ + if (has_time) { \ + PackedInt32Array array = time.split_ints(":", false); \ + ERR_FAIL_COND_V_MSG(array.size() < 3, ret, "Invalid ISO 8601 time string."); \ + hour = array[0]; \ + minute = array[1]; \ + second = array[2]; \ + } \ } #define EXTRACT_FROM_DICTIONARY \ @@ -253,7 +257,7 @@ String Time::get_time_string_from_unix_time(int64_t p_unix_time_val) const { } Dictionary Time::get_datetime_dict_from_string(String p_datetime, bool p_weekday) const { - PARSE_ISO8601_STRING + PARSE_ISO8601_STRING(Dictionary()) Dictionary dict; dict[YEAR_KEY] = year; dict[MONTH_KEY] = (uint8_t)month; @@ -273,6 +277,7 @@ Dictionary Time::get_datetime_dict_from_string(String p_datetime, bool p_weekday String Time::get_datetime_string_from_dict(const Dictionary p_datetime, bool p_use_space) const { ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), "", "Invalid datetime Dictionary: Dictionary is empty."); EXTRACT_FROM_DICTIONARY + VALIDATE_YMDHMS("") // vformat only supports up to 6 arguments, so we need to split this up into 2 parts. String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day); if (p_use_space) { @@ -286,14 +291,14 @@ String Time::get_datetime_string_from_dict(const Dictionary p_datetime, bool p_u int64_t Time::get_unix_time_from_datetime_dict(const Dictionary p_datetime) const { ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), 0, "Invalid datetime Dictionary: Dictionary is empty"); EXTRACT_FROM_DICTIONARY - VALIDATE_YMDHMS + VALIDATE_YMDHMS(0) YMD_TO_DAY_NUMBER return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second; } int64_t Time::get_unix_time_from_datetime_string(String p_datetime) const { - PARSE_ISO8601_STRING - VALIDATE_YMDHMS + PARSE_ISO8601_STRING(-1) + VALIDATE_YMDHMS(0) YMD_TO_DAY_NUMBER return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second; } diff --git a/core/variant/variant.h b/core/variant/variant.h index ca18249f36..475bf7158d 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -511,6 +511,7 @@ public: Variant recursive_duplicate(bool p_deep, int recursion_count) const; static void blend(const Variant &a, const Variant &b, float c, Variant &r_dst); static void interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst); + static void sub(const Variant &a, const Variant &b, Variant &r_dst); /* Built-In Methods */ diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index c11925fa8c..f1daf1de13 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1656,8 +1656,8 @@ static void _register_variant_builtin_methods() { bind_method(Color, darkened, sarray("amount"), varray()); bind_method(Color, blend, sarray("over"), varray()); bind_method(Color, get_luminance, sarray(), varray()); - bind_method(Color, to_linear, sarray(), varray()); - bind_method(Color, to_srgb, sarray(), varray()); + bind_method(Color, srgb_to_linear, sarray(), varray()); + bind_method(Color, linear_to_srgb, sarray(), varray()); bind_method(Color, is_equal_approx, sarray("to"), varray()); diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index e604ff9567..705aa27be6 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -1868,6 +1868,110 @@ Variant Variant::recursive_duplicate(bool p_deep, int recursion_count) const { } } +void Variant::sub(const Variant &a, const Variant &b, Variant &r_dst) { + if (a.type != b.type) { + return; + } + + switch (a.type) { + case NIL: { + r_dst = Variant(); + } + return; + case INT: { + int64_t va = a._data._int; + int64_t vb = b._data._int; + r_dst = int(va - vb); + } + return; + case FLOAT: { + double ra = a._data._float; + double rb = b._data._float; + r_dst = ra - rb; + } + return; + case VECTOR2: { + r_dst = *reinterpret_cast<const Vector2 *>(a._data._mem) - *reinterpret_cast<const Vector2 *>(b._data._mem); + } + return; + case VECTOR2I: { + int32_t vax = reinterpret_cast<const Vector2i *>(a._data._mem)->x; + int32_t vbx = reinterpret_cast<const Vector2i *>(b._data._mem)->x; + int32_t vay = reinterpret_cast<const Vector2i *>(a._data._mem)->y; + int32_t vby = reinterpret_cast<const Vector2i *>(b._data._mem)->y; + r_dst = Vector2i(int32_t(vax - vbx), int32_t(vay - vby)); + } + return; + case RECT2: { + const Rect2 *ra = reinterpret_cast<const Rect2 *>(a._data._mem); + const Rect2 *rb = reinterpret_cast<const Rect2 *>(b._data._mem); + r_dst = Rect2(ra->position - rb->position, ra->size - rb->size); + } + return; + case RECT2I: { + const Rect2i *ra = reinterpret_cast<const Rect2i *>(a._data._mem); + const Rect2i *rb = reinterpret_cast<const Rect2i *>(b._data._mem); + + int32_t vax = ra->position.x; + int32_t vay = ra->position.y; + int32_t vbx = ra->size.x; + int32_t vby = ra->size.y; + int32_t vcx = rb->position.x; + int32_t vcy = rb->position.y; + int32_t vdx = rb->size.x; + int32_t vdy = rb->size.y; + + r_dst = Rect2i(int32_t(vax - vbx), int32_t(vay - vby), int32_t(vcx - vdx), int32_t(vcy - vdy)); + } + return; + case VECTOR3: { + r_dst = *reinterpret_cast<const Vector3 *>(a._data._mem) - *reinterpret_cast<const Vector3 *>(b._data._mem); + } + return; + case VECTOR3I: { + int32_t vax = reinterpret_cast<const Vector3i *>(a._data._mem)->x; + int32_t vbx = reinterpret_cast<const Vector3i *>(b._data._mem)->x; + int32_t vay = reinterpret_cast<const Vector3i *>(a._data._mem)->y; + int32_t vby = reinterpret_cast<const Vector3i *>(b._data._mem)->y; + int32_t vaz = reinterpret_cast<const Vector3i *>(a._data._mem)->z; + int32_t vbz = reinterpret_cast<const Vector3i *>(b._data._mem)->z; + r_dst = Vector3i(int32_t(vax - vbx), int32_t(vay - vby), int32_t(vaz - vbz)); + } + return; + case AABB: { + const ::AABB *ra = reinterpret_cast<const ::AABB *>(a._data._mem); + const ::AABB *rb = reinterpret_cast<const ::AABB *>(b._data._mem); + r_dst = ::AABB(ra->position - rb->position, ra->size - rb->size); + } + return; + case QUATERNION: { + Quaternion empty_rot; + const Quaternion *qa = reinterpret_cast<const Quaternion *>(a._data._mem); + const Quaternion *qb = reinterpret_cast<const Quaternion *>(b._data._mem); + r_dst = (*qb).inverse() * *qa; + } + return; + case COLOR: { + const Color *ca = reinterpret_cast<const Color *>(a._data._mem); + const Color *cb = reinterpret_cast<const Color *>(b._data._mem); + float new_r = ca->r - cb->r; + float new_g = ca->g - cb->g; + float new_b = ca->b - cb->b; + float new_a = ca->a - cb->a; + new_r = new_r > 1.0 ? 1.0 : new_r; + new_g = new_g > 1.0 ? 1.0 : new_g; + new_b = new_b > 1.0 ? 1.0 : new_b; + new_a = new_a > 1.0 ? 1.0 : new_a; + r_dst = Color(new_r, new_g, new_b, new_a); + } + return; + default: { + r_dst = a; + } + return; + } +} + void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) { if (a.type != b.type) { if (a.is_num() && b.is_num()) { |