diff options
264 files changed, 18280 insertions, 3982 deletions
diff --git a/.appveyor.yml b/.appveyor.yml index 7691f65d6a..567da9cd5d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,7 +4,7 @@ environment: HOME: "%HOMEDRIVE%%HOMEPATH%" PYTHON: C:\Python27 SCONS_CACHE_ROOT: "%HOME%\\scons_cache" - SCONS_CACHE_LIMIT: 512 + SCONS_CACHE_LIMIT: 1024 matrix: - VS: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat GD_PLATFORM: windows @@ -29,4 +29,4 @@ before_build: - SET "SCONS_CACHE=%SCONS_CACHE_ROOT%\master" build_script: -- scons platform=%GD_PLATFORM% target=%TARGET% tools=%TOOLS% verbose=yes progress=no gdnative_wrapper=yes +- scons platform=%GD_PLATFORM% target=%TARGET% tools=%TOOLS% debug_symbols=no verbose=yes progress=no gdnative_wrapper=yes diff --git a/.travis.yml b/.travis.yml index e89774a2a2..404bdc9d90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ env: global: - SCONS_CACHE=$HOME/.scons_cache - SCONS_CACHE_LIMIT=1024 - - OPTIONS="verbose=yes progress=no gdnative_wrapper=yes" + - OPTIONS="debug_symbols=no verbose=yes progress=no gdnative_wrapper=yes" - secure: "QLFRizqry/Y5pnEZvDlQz5S3YydQ+600u4rHEzFgUTd0heYeQaETXAQeMzp0ymuG1BkdRAl5YJoLVJgAzjwI9hrvugvoUlh2//SfpqZCHN/Q1fYbtGgNTn01R3VFEpcfYQL93I2EjrxVm0WTM4PwCvMO+hU0aWTRDvCt1Lty0kMR+RMDQOO/woqunoXh5wvFNxTJJkAmuLe0v962DJYOIwJAnqMLR0aFYjmeQJ20bc/2X5oLt+WuJDuf/lGj6WSlD6z/o/kL3YxHoUyw4A/HAZ2IX0IfNHKuay60ESWzl/NlobnePiPwHAE2pdDVu//q16fanb9VeYnBYRFse49TpFRb86Lo+Qz8nKDJqpQEIY0YKNCFqekrubqTM++Lj6QvGpykQZNxUhybmELcEsRG4PS0UMvCpebdnJD46nNB+DtO2Lgb4xXDLQwpq19z1wizq/XDQ5hz61TIIx8+i8TsgdSQKCTeWovd4HcD4CVjAD5XTLGgyRmI/zC2d+lTnKo6W9diLq/bX/Goq2QPeaTPABqv817IaJka2JyugQ7Qal/+gNTjYRRsimRCL9B2tVh+Uh8rWhTFhQL4QbP5P65HF+p8qojUzqtAhPMbZ8mxUtNukUI3liVgPgiMss96sG0nTVglFgkkAkEjIMFnqMSKnTfG812K4jIhp2jCO2Q3NeI=" cache: diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index becaa9ade9..4ba80941e0 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -135,6 +135,12 @@ Comment: CA certificates Copyright: Mozilla Contributors License: MPL-2.0 +Files: ./thirdparty/cvtt/ +Comment: Convection Texture Tools Stand-Alone Kernels +Copyright: 2018, Eric Lasota + 2018, Microsoft Corp. +License: MIT + Files: ./thirdparty/enet/ Comment: ENet Copyright: 2002-2016, Lee Salzman diff --git a/core/class_db.h b/core/class_db.h index f1d1879236..66a67f6c9f 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -39,6 +39,10 @@ @author Juan Linietsky <reduzio@gmail.com> */ +/** To bind more then 6 parameters include this: + * #include "method_bind_ext.gen.inc" + */ + #define DEFVAL(m_defval) (m_defval) //#define SIMPLE_METHODDEF diff --git a/core/color.cpp b/core/color.cpp index fcfcf20355..17c9e2daeb 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -253,6 +253,21 @@ Color Color::hex64(uint64_t p_hex) { return Color(r, g, b, a); } +Color Color::from_rgbe9995(uint32_t p_rgbe) { + + float r = p_rgbe & 0x1ff; + float g = (p_rgbe >> 9) & 0x1ff; + float b = (p_rgbe >> 18) & 0x1ff; + float e = (p_rgbe >> 27); + float m = Math::pow(2, e - 15.0 - 9.0); + + float rd = r * m; + float gd = g * m; + float bd = b * m; + + return Color(rd, gd, bd, 1.0f); +} + static float _parse_col(const String &p_str, int p_ofs) { int ig = 0; @@ -506,8 +521,11 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) { return Color(m + r, m + g, m + b, p_a); } +// FIXME: Remove once Godot 3.1 has been released float Color::gray() const { + ERR_EXPLAIN("Color.gray() is deprecated and will be removed in a future version. Use Color.get_v() for a better grayscale approximation."); + WARN_DEPRECATED return (r + g + b) / 3.0; } diff --git a/core/color.h b/core/color.h index c0516e55fe..00f4c9e9e8 100644 --- a/core/color.h +++ b/core/color.h @@ -195,6 +195,7 @@ struct Color { static Color named(const String &p_name); String to_html(bool p_alpha = true) const; Color from_hsv(float p_h, float p_s, float p_v, float p_a); + static Color from_rgbe9995(uint32_t p_color); _FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys operator String() const; diff --git a/core/global_constants.cpp b/core/global_constants.cpp index 187813f9d0..962881e720 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -532,6 +532,7 @@ void register_global_constants() { BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_GLOBAL_DIR); BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_RESOURCE_TYPE); BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_MULTILINE_TEXT); + BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_PLACEHOLDER_TEXT); BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_COLOR_NO_ALPHA); BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_IMAGE_COMPRESS_LOSSY); BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS); diff --git a/core/image.cpp b/core/image.cpp index c94f2c3534..b1f0125b43 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -37,6 +37,7 @@ #include "print_string.h" #include "io/resource_loader.h" +#include "math_funcs.h" #include "thirdparty/misc/hq2x.h" #include <stdio.h> @@ -525,7 +526,7 @@ static double _bicubic_interp_kernel(double x) { return bc; } -template <int CC> +template <int CC, class T = uint8_t> static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { // get source image size @@ -556,7 +557,7 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_ // initial pixel value - uint8_t *__restrict dst = p_dst + (y * p_dst_width + x) * CC; + T *__restrict dst = ((T *)p_dst) + (y * p_dst_width + x) * CC; double color[CC]; for (int i = 0; i < CC; i++) { @@ -584,23 +585,32 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_ ox2 = xmax; // get pixel of original image - const uint8_t *__restrict p = p_src + (oy2 * p_src_width + ox2) * CC; + const T *__restrict p = ((T *)p_src) + (oy2 * p_src_width + ox2) * CC; for (int i = 0; i < CC; i++) { - - color[i] += p[i] * k2; + if (sizeof(T) == 2) { //half float + color[i] = Math::half_to_float(p[i]); + } else { + color[i] += p[i] * k2; + } } } } for (int i = 0; i < CC; i++) { - dst[i] = CLAMP(Math::fast_ftoi(color[i]), 0, 255); + if (sizeof(T) == 1) { //byte + dst[i] = CLAMP(Math::fast_ftoi(color[i]), 0, 255); + } else if (sizeof(T) == 2) { //half float + dst[i] = Math::make_half_float(color[i]); + } else { + dst[i] = color[i]; + } } } } } -template <int CC> +template <int CC, class T = uint8_t> static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { enum { @@ -640,22 +650,58 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict for (uint32_t l = 0; l < CC; l++) { - uint32_t p00 = p_src[y_ofs_up + src_xofs_left + l] << FRAC_BITS; - uint32_t p10 = p_src[y_ofs_up + src_xofs_right + l] << FRAC_BITS; - uint32_t p01 = p_src[y_ofs_down + src_xofs_left + l] << FRAC_BITS; - uint32_t p11 = p_src[y_ofs_down + src_xofs_right + l] << FRAC_BITS; - - uint32_t interp_up = p00 + (((p10 - p00) * src_xofs_frac) >> FRAC_BITS); - uint32_t interp_down = p01 + (((p11 - p01) * src_xofs_frac) >> FRAC_BITS); - uint32_t interp = interp_up + (((interp_down - interp_up) * src_yofs_frac) >> FRAC_BITS); - interp >>= FRAC_BITS; - p_dst[i * p_dst_width * CC + j * CC + l] = interp; + if (sizeof(T) == 1) { //uint8 + uint32_t p00 = p_src[y_ofs_up + src_xofs_left + l] << FRAC_BITS; + uint32_t p10 = p_src[y_ofs_up + src_xofs_right + l] << FRAC_BITS; + uint32_t p01 = p_src[y_ofs_down + src_xofs_left + l] << FRAC_BITS; + uint32_t p11 = p_src[y_ofs_down + src_xofs_right + l] << FRAC_BITS; + + uint32_t interp_up = p00 + (((p10 - p00) * src_xofs_frac) >> FRAC_BITS); + uint32_t interp_down = p01 + (((p11 - p01) * src_xofs_frac) >> FRAC_BITS); + uint32_t interp = interp_up + (((interp_down - interp_up) * src_yofs_frac) >> FRAC_BITS); + interp >>= FRAC_BITS; + p_dst[i * p_dst_width * CC + j * CC + l] = interp; + } else if (sizeof(T) == 2) { //half float + + float xofs_frac = float(src_xofs_frac) / (1 << FRAC_BITS); + float yofs_frac = float(src_yofs_frac) / (1 << FRAC_BITS); + const T *src = ((const T *)p_src); + T *dst = ((T *)p_dst); + + float p00 = Math::half_to_float(src[y_ofs_up + src_xofs_left + l]); + float p10 = Math::half_to_float(src[y_ofs_up + src_xofs_right + l]); + float p01 = Math::half_to_float(src[y_ofs_down + src_xofs_left + l]); + float p11 = Math::half_to_float(src[y_ofs_down + src_xofs_right + l]); + + float interp_up = p00 + (p10 - p00) * xofs_frac; + float interp_down = p01 + (p11 - p01) * xofs_frac; + float interp = interp_up + ((interp_down - interp_up) * yofs_frac); + + dst[i * p_dst_width * CC + j * CC + l] = Math::make_half_float(interp); + } else if (sizeof(T) == 4) { //float + + float xofs_frac = float(src_xofs_frac) / (1 << FRAC_BITS); + float yofs_frac = float(src_yofs_frac) / (1 << FRAC_BITS); + const T *src = ((const T *)p_src); + T *dst = ((T *)p_dst); + + float p00 = src[y_ofs_up + src_xofs_left + l]; + float p10 = src[y_ofs_up + src_xofs_right + l]; + float p01 = src[y_ofs_down + src_xofs_left + l]; + float p11 = src[y_ofs_down + src_xofs_right + l]; + + float interp_up = p00 + (p10 - p00) * xofs_frac; + float interp_down = p01 + (p11 - p01) * xofs_frac; + float interp = interp_up + ((interp_down - interp_up) * yofs_frac); + + dst[i * p_dst_width * CC + j * CC + l] = interp; + } } } } } -template <int CC> +template <int CC, class T = uint8_t> static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { for (uint32_t i = 0; i < p_dst_height; i++) { @@ -670,8 +716,11 @@ static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict for (uint32_t l = 0; l < CC; l++) { - uint32_t p = p_src[y_ofs + src_xofs + l]; - p_dst[i * p_dst_width * CC + j * CC + l] = p; + const T *src = ((const T *)p_src); + T *dst = ((T *)p_dst); + + T p = src[y_ofs + src_xofs + l]; + dst[i * p_dst_width * CC + j * CC + l] = p; } } } @@ -766,12 +815,30 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { case INTERPOLATE_NEAREST: { - switch (get_format_pixel_size(format)) { - case 1: _scale_nearest<1>(r_ptr, w_ptr, width, height, p_width, p_height); break; - case 2: _scale_nearest<2>(r_ptr, w_ptr, width, height, p_width, p_height); break; - case 3: _scale_nearest<3>(r_ptr, w_ptr, width, height, p_width, p_height); break; - case 4: _scale_nearest<4>(r_ptr, w_ptr, width, height, p_width, p_height); break; + if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) { + switch (get_format_pixel_size(format)) { + case 1: _scale_nearest<1>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 2: _scale_nearest<2>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 3: _scale_nearest<3>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 4: _scale_nearest<4>(r_ptr, w_ptr, width, height, p_width, p_height); break; + } + } else if (format >= FORMAT_RF && format <= FORMAT_RGBAF) { + switch (get_format_pixel_size(format)) { + case 4: _scale_nearest<1, float>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 8: _scale_nearest<2, float>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 12: _scale_nearest<3, float>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 16: _scale_nearest<4, float>(r_ptr, w_ptr, width, height, p_width, p_height); break; + } + + } else if (format >= FORMAT_RH && format <= FORMAT_RGBAH) { + switch (get_format_pixel_size(format)) { + case 2: _scale_nearest<1, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 4: _scale_nearest<2, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 6: _scale_nearest<3, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 8: _scale_nearest<4, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break; + } } + } break; case INTERPOLATE_BILINEAR: case INTERPOLATE_TRILINEAR: { @@ -812,11 +879,27 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } } - switch (get_format_pixel_size(format)) { - case 1: _scale_bilinear<1>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; - case 2: _scale_bilinear<2>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; - case 3: _scale_bilinear<3>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; - case 4: _scale_bilinear<4>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) { + switch (get_format_pixel_size(format)) { + case 1: _scale_bilinear<1>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + case 2: _scale_bilinear<2>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + case 3: _scale_bilinear<3>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + case 4: _scale_bilinear<4>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + } + } else if (format >= FORMAT_RF && format <= FORMAT_RGBAF) { + switch (get_format_pixel_size(format)) { + case 4: _scale_bilinear<1, float>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + case 8: _scale_bilinear<2, float>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + case 12: _scale_bilinear<3, float>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + case 16: _scale_bilinear<4, float>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + } + } else if (format >= FORMAT_RH && format <= FORMAT_RGBAH) { + switch (get_format_pixel_size(format)) { + case 2: _scale_bilinear<1, uint16_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + case 4: _scale_bilinear<2, uint16_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + case 6: _scale_bilinear<3, uint16_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + case 8: _scale_bilinear<4, uint16_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break; + } } } @@ -829,13 +912,28 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } break; case INTERPOLATE_CUBIC: { - switch (get_format_pixel_size(format)) { - case 1: _scale_cubic<1>(r_ptr, w_ptr, width, height, p_width, p_height); break; - case 2: _scale_cubic<2>(r_ptr, w_ptr, width, height, p_width, p_height); break; - case 3: _scale_cubic<3>(r_ptr, w_ptr, width, height, p_width, p_height); break; - case 4: _scale_cubic<4>(r_ptr, w_ptr, width, height, p_width, p_height); break; + if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) { + switch (get_format_pixel_size(format)) { + case 1: _scale_cubic<1>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 2: _scale_cubic<2>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 3: _scale_cubic<3>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 4: _scale_cubic<4>(r_ptr, w_ptr, width, height, p_width, p_height); break; + } + } else if (format >= FORMAT_RF && format <= FORMAT_RGBAF) { + switch (get_format_pixel_size(format)) { + case 4: _scale_cubic<1, float>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 8: _scale_cubic<2, float>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 12: _scale_cubic<3, float>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 16: _scale_cubic<4, float>(r_ptr, w_ptr, width, height, p_width, p_height); break; + } + } else if (format >= FORMAT_RH && format <= FORMAT_RGBAH) { + switch (get_format_pixel_size(format)) { + case 2: _scale_cubic<1, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 4: _scale_cubic<2, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 6: _scale_cubic<3, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break; + case 8: _scale_cubic<4, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break; + } } - } break; } @@ -1029,8 +1127,10 @@ bool Image::_can_modify(Format p_format) const { return p_format <= FORMAT_RGBE9995; } -template <int CC, bool renormalize> -static void _generate_po2_mipmap(const uint8_t *p_src, uint8_t *p_dst, uint32_t p_width, uint32_t p_height) { +template <class Component, int CC, bool renormalize, + void (*average_func)(Component &, const Component &, const Component &, const Component &, const Component &), + void (*renormalize_func)(Component *)> +static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint32_t p_width, uint32_t p_height) { //fast power of 2 mipmap generation uint32_t dst_w = p_width >> 1; @@ -1038,34 +1138,19 @@ static void _generate_po2_mipmap(const uint8_t *p_src, uint8_t *p_dst, uint32_t for (uint32_t i = 0; i < dst_h; i++) { - const uint8_t *rup_ptr = &p_src[i * 2 * p_width * CC]; - const uint8_t *rdown_ptr = rup_ptr + p_width * CC; - uint8_t *dst_ptr = &p_dst[i * dst_w * CC]; + const Component *rup_ptr = &p_src[i * 2 * p_width * CC]; + const Component *rdown_ptr = rup_ptr + p_width * CC; + Component *dst_ptr = &p_dst[i * dst_w * CC]; uint32_t count = dst_w; while (count--) { for (int j = 0; j < CC; j++) { - - uint16_t val = 0; - val += rup_ptr[j]; - val += rup_ptr[j + CC]; - val += rdown_ptr[j]; - val += rdown_ptr[j + CC]; - dst_ptr[j] = val >> 2; + average_func(dst_ptr[j], rup_ptr[j], rup_ptr[j + CC], rdown_ptr[j], rdown_ptr[j + CC]); } if (renormalize) { - Vector3 n(dst_ptr[0] / 255.0, dst_ptr[1] / 255.0, dst_ptr[2] / 255.0); - n *= 2.0; - n -= Vector3(1, 1, 1); - n.normalize(); - n += Vector3(1, 1, 1); - n *= 0.5; - n *= 255; - dst_ptr[0] = CLAMP(int(n.x), 0, 255); - dst_ptr[1] = CLAMP(int(n.y), 0, 255); - dst_ptr[2] = CLAMP(int(n.z), 0, 255); + renormalize_func(dst_ptr); } dst_ptr += CC; @@ -1150,11 +1235,23 @@ void Image::shrink_x2() { switch (format) { case FORMAT_L8: - case FORMAT_R8: _generate_po2_mipmap<1, false>(r.ptr(), w.ptr(), width, height); break; - case FORMAT_LA8: _generate_po2_mipmap<2, false>(r.ptr(), w.ptr(), width, height); break; - case FORMAT_RG8: _generate_po2_mipmap<2, false>(r.ptr(), w.ptr(), width, height); break; - case FORMAT_RGB8: _generate_po2_mipmap<3, false>(r.ptr(), w.ptr(), width, height); break; - case FORMAT_RGBA8: _generate_po2_mipmap<4, false>(r.ptr(), w.ptr(), width, height); break; + case FORMAT_R8: _generate_po2_mipmap<uint8_t, 1, false, Image::average_4_uint8, Image::renormalize_uint8>(r.ptr(), w.ptr(), width, height); break; + case FORMAT_LA8: _generate_po2_mipmap<uint8_t, 2, false, Image::average_4_uint8, Image::renormalize_uint8>(r.ptr(), w.ptr(), width, height); break; + case FORMAT_RG8: _generate_po2_mipmap<uint8_t, 2, false, Image::average_4_uint8, Image::renormalize_uint8>(r.ptr(), w.ptr(), width, height); break; + case FORMAT_RGB8: _generate_po2_mipmap<uint8_t, 3, false, Image::average_4_uint8, Image::renormalize_uint8>(r.ptr(), w.ptr(), width, height); break; + case FORMAT_RGBA8: _generate_po2_mipmap<uint8_t, 4, false, Image::average_4_uint8, Image::renormalize_uint8>(r.ptr(), w.ptr(), width, height); break; + + case FORMAT_RF: _generate_po2_mipmap<float, 1, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(r.ptr()), reinterpret_cast<float *>(w.ptr()), width, height); break; + case FORMAT_RGF: _generate_po2_mipmap<float, 2, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(r.ptr()), reinterpret_cast<float *>(w.ptr()), width, height); break; + case FORMAT_RGBF: _generate_po2_mipmap<float, 3, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(r.ptr()), reinterpret_cast<float *>(w.ptr()), width, height); break; + case FORMAT_RGBAF: _generate_po2_mipmap<float, 4, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(r.ptr()), reinterpret_cast<float *>(w.ptr()), width, height); break; + + case FORMAT_RH: _generate_po2_mipmap<uint16_t, 1, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(r.ptr()), reinterpret_cast<uint16_t *>(w.ptr()), width, height); break; + case FORMAT_RGH: _generate_po2_mipmap<uint16_t, 2, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(r.ptr()), reinterpret_cast<uint16_t *>(w.ptr()), width, height); break; + case FORMAT_RGBH: _generate_po2_mipmap<uint16_t, 3, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(r.ptr()), reinterpret_cast<uint16_t *>(w.ptr()), width, height); break; + case FORMAT_RGBAH: _generate_po2_mipmap<uint16_t, 4, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(r.ptr()), reinterpret_cast<uint16_t *>(w.ptr()), width, height); break; + + case FORMAT_RGBE9995: _generate_po2_mipmap<uint32_t, 1, false, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(r.ptr()), reinterpret_cast<uint32_t *>(w.ptr()), width, height); break; default: {} } } @@ -1224,21 +1321,68 @@ Error Image::generate_mipmaps(bool p_renormalize) { switch (format) { case FORMAT_L8: - case FORMAT_R8: _generate_po2_mipmap<1, false>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break; + case FORMAT_R8: _generate_po2_mipmap<uint8_t, 1, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break; case FORMAT_LA8: - case FORMAT_RG8: _generate_po2_mipmap<2, false>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break; + case FORMAT_RG8: _generate_po2_mipmap<uint8_t, 2, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break; case FORMAT_RGB8: if (p_renormalize) - _generate_po2_mipmap<3, true>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + _generate_po2_mipmap<uint8_t, 3, true, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); else - _generate_po2_mipmap<3, false>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + _generate_po2_mipmap<uint8_t, 3, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break; case FORMAT_RGBA8: if (p_renormalize) - _generate_po2_mipmap<4, true>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + _generate_po2_mipmap<uint8_t, 4, true, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + else + _generate_po2_mipmap<uint8_t, 4, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + break; + case FORMAT_RF: + _generate_po2_mipmap<float, 1, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); + break; + case FORMAT_RGF: + _generate_po2_mipmap<float, 2, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); + break; + case FORMAT_RGBF: + if (p_renormalize) + _generate_po2_mipmap<float, 3, true, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); + else + _generate_po2_mipmap<float, 3, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); + + break; + case FORMAT_RGBAF: + if (p_renormalize) + _generate_po2_mipmap<float, 4, true, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); + else + _generate_po2_mipmap<float, 4, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h); + + break; + case FORMAT_RH: + _generate_po2_mipmap<uint16_t, 1, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); + break; + case FORMAT_RGH: + _generate_po2_mipmap<uint16_t, 2, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); + break; + case FORMAT_RGBH: + if (p_renormalize) + _generate_po2_mipmap<uint16_t, 3, true, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); else - _generate_po2_mipmap<4, false>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + _generate_po2_mipmap<uint16_t, 3, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); + + break; + case FORMAT_RGBAH: + if (p_renormalize) + _generate_po2_mipmap<uint16_t, 4, true, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); + else + _generate_po2_mipmap<uint16_t, 4, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h); + + break; + case FORMAT_RGBE9995: + if (p_renormalize) + _generate_po2_mipmap<uint32_t, 1, true, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(&wp[prev_ofs]), reinterpret_cast<uint32_t *>(&wp[ofs]), prev_w, prev_h); + else + _generate_po2_mipmap<uint32_t, 1, false, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(&wp[prev_ofs]), reinterpret_cast<uint32_t *>(&wp[ofs]), prev_w, prev_h); + break; default: {} } @@ -1617,8 +1761,10 @@ bool Image::is_compressed() const { Error Image::decompress() { - if (format >= FORMAT_DXT1 && format <= FORMAT_BPTC_RGBFU && _image_decompress_bc) + if (format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG && _image_decompress_bc) _image_decompress_bc(this); + else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc) + _image_decompress_bptc(this); else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc) _image_decompress_pvrtc(this); else if (format == FORMAT_ETC && _image_decompress_etc1) @@ -1659,6 +1805,11 @@ Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_loss ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE); _image_compress_etc2_func(this, p_lossy_quality, p_source); } break; + case COMPRESS_BPTC: { + + ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE); + _image_compress_bptc_func(this, p_lossy_quality, p_source); + } break; } return OK; @@ -1996,12 +2147,14 @@ ImageMemLoadFunc Image::_jpg_mem_loader_func = NULL; ImageMemLoadFunc Image::_webp_mem_loader_func = NULL; void (*Image::_image_compress_bc_func)(Image *, Image::CompressSource) = NULL; +void (*Image::_image_compress_bptc_func)(Image *, float, Image::CompressSource) = NULL; void (*Image::_image_compress_pvrtc2_func)(Image *) = NULL; void (*Image::_image_compress_pvrtc4_func)(Image *) = NULL; void (*Image::_image_compress_etc1_func)(Image *, float) = NULL; void (*Image::_image_compress_etc2_func)(Image *, float, Image::CompressSource) = NULL; void (*Image::_image_decompress_pvrtc)(Image *) = NULL; void (*Image::_image_decompress_bc)(Image *) = NULL; +void (*Image::_image_decompress_bptc)(Image *) = NULL; void (*Image::_image_decompress_etc1)(Image *) = NULL; void (*Image::_image_decompress_etc2)(Image *) = NULL; @@ -2185,18 +2338,7 @@ Color Image::get_pixel(int p_x, int p_y) const { return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), Math::half_to_float(a)); } break; case FORMAT_RGBE9995: { - uint32_t rgbe = ((uint32_t *)ptr)[ofs]; - float r = rgbe & 0x1ff; - float g = (rgbe >> 9) & 0x1ff; - float b = (rgbe >> 18) & 0x1ff; - float e = (rgbe >> 27); - float m = Math::pow(2, e - 15.0 - 9.0); - ; - float rd = r * m; - float gd = g * m; - float bd = b * m; - - return Color(rd, gd, bd, 1.0); + return Color::from_rgbe9995(((uint32_t *)ptr)[ofs]); } break; default: { @@ -2230,10 +2372,10 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { switch (format) { case FORMAT_L8: { - ptr[ofs] = uint8_t(CLAMP(p_color.gray() * 255.0, 0, 255)); + ptr[ofs] = uint8_t(CLAMP(p_color.get_v() * 255.0, 0, 255)); } break; case FORMAT_LA8: { - ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.gray() * 255.0, 0, 255)); + ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.get_v() * 255.0, 0, 255)); ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.a * 255.0, 0, 255)); } break; case FORMAT_R8: { @@ -2530,6 +2672,11 @@ void Image::set_compress_bc_func(void (*p_compress_func)(Image *, CompressSource _image_compress_bc_func = p_compress_func; } +void Image::set_compress_bptc_func(void (*p_compress_func)(Image *, float, CompressSource)) { + + _image_compress_bptc_func = p_compress_func; +} + void Image::normalmap_to_xy() { convert(Image::FORMAT_RGBA8); @@ -2783,6 +2930,55 @@ Error Image::_load_from_buffer(const PoolVector<uint8_t> &p_array, ImageMemLoadF return OK; } +void Image::average_4_uint8(uint8_t &p_out, const uint8_t &p_a, const uint8_t &p_b, const uint8_t &p_c, const uint8_t &p_d) { + p_out = static_cast<uint8_t>((p_a + p_b + p_c + p_d + 2) >> 2); +} + +void Image::average_4_float(float &p_out, const float &p_a, const float &p_b, const float &p_c, const float &p_d) { + p_out = (p_a + p_b + p_c + p_d) * 0.25f; +} + +void Image::average_4_half(uint16_t &p_out, const uint16_t &p_a, const uint16_t &p_b, const uint16_t &p_c, const uint16_t &p_d) { + p_out = Math::make_half_float((Math::half_to_float(p_a) + Math::half_to_float(p_b) + Math::half_to_float(p_c) + Math::half_to_float(p_d)) * 0.25f); +} + +void Image::average_4_rgbe9995(uint32_t &p_out, const uint32_t &p_a, const uint32_t &p_b, const uint32_t &p_c, const uint32_t &p_d) { + p_out = ((Color::from_rgbe9995(p_a) + Color::from_rgbe9995(p_b) + Color::from_rgbe9995(p_c) + Color::from_rgbe9995(p_d)) * 0.25f).to_rgbe9995(); +} + +void Image::renormalize_uint8(uint8_t *p_rgb) { + Vector3 n(p_rgb[0] / 255.0, p_rgb[1] / 255.0, p_rgb[2] / 255.0); + n *= 2.0; + n -= Vector3(1, 1, 1); + n.normalize(); + n += Vector3(1, 1, 1); + n *= 0.5; + n *= 255; + p_rgb[0] = CLAMP(int(n.x), 0, 255); + p_rgb[1] = CLAMP(int(n.y), 0, 255); + p_rgb[2] = CLAMP(int(n.z), 0, 255); +} + +void Image::renormalize_float(float *p_rgb) { + Vector3 n(p_rgb[0], p_rgb[1], p_rgb[2]); + n.normalize(); + p_rgb[0] = n.x; + p_rgb[1] = n.y; + p_rgb[2] = n.z; +} + +void Image::renormalize_half(uint16_t *p_rgb) { + Vector3 n(Math::half_to_float(p_rgb[0]), Math::half_to_float(p_rgb[1]), Math::half_to_float(p_rgb[2])); + n.normalize(); + p_rgb[0] = Math::make_half_float(n.x); + p_rgb[1] = Math::make_half_float(n.y); + p_rgb[2] = Math::make_half_float(n.z); +} + +void Image::renormalize_rgbe9995(uint32_t *p_rgb) { + // Never used +} + Image::Image(const uint8_t *p_mem_png_jpg, int p_len) { width = 0; diff --git a/core/image.h b/core/image.h index c450e88290..854096b773 100644 --- a/core/image.h +++ b/core/image.h @@ -127,6 +127,7 @@ public: static ImageMemLoadFunc _webp_mem_loader_func; static void (*_image_compress_bc_func)(Image *, CompressSource p_source); + static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, CompressSource p_source); static void (*_image_compress_pvrtc2_func)(Image *); static void (*_image_compress_pvrtc4_func)(Image *); static void (*_image_compress_etc1_func)(Image *, float); @@ -134,6 +135,7 @@ public: static void (*_image_decompress_pvrtc)(Image *); static void (*_image_decompress_bc)(Image *); + static void (*_image_decompress_bptc)(Image *); static void (*_image_decompress_etc1)(Image *); static void (*_image_decompress_etc2)(Image *); @@ -182,6 +184,15 @@ private: Error _load_from_buffer(const PoolVector<uint8_t> &p_array, ImageMemLoadFunc p_loader); + static void average_4_uint8(uint8_t &p_out, const uint8_t &p_a, const uint8_t &p_b, const uint8_t &p_c, const uint8_t &p_d); + static void average_4_float(float &p_out, const float &p_a, const float &p_b, const float &p_c, const float &p_d); + static void average_4_half(uint16_t &p_out, const uint16_t &p_a, const uint16_t &p_b, const uint16_t &p_c, const uint16_t &p_d); + static void average_4_rgbe9995(uint32_t &p_out, const uint32_t &p_a, const uint32_t &p_b, const uint32_t &p_c, const uint32_t &p_d); + static void renormalize_uint8(uint8_t *p_rgb); + static void renormalize_float(float *p_rgb); + static void renormalize_half(uint16_t *p_rgb); + static void renormalize_rgbe9995(uint32_t *p_rgb); + public: int get_width() const; ///< Get image width int get_height() const; ///< Get image height @@ -282,6 +293,7 @@ public: COMPRESS_PVRTC4, COMPRESS_ETC, COMPRESS_ETC2, + COMPRESS_BPTC }; Error compress(CompressMode p_mode = COMPRESS_S3TC, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7); @@ -305,6 +317,7 @@ public: Ref<Image> get_rect(const Rect2 &p_area) const; static void set_compress_bc_func(void (*p_compress_func)(Image *, CompressSource)); + static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, CompressSource)); static String get_format_name(Format p_format); Error load_png_from_buffer(const PoolVector<uint8_t> &p_array); diff --git a/core/input_map.cpp b/core/input_map.cpp index d33f40cbcf..ffc8a39da5 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -44,7 +44,7 @@ void InputMap::_bind_methods() { ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.5f)); ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action); - ClassDB::bind_method(D_METHOD("action_set_deadzone", "deadzone"), &InputMap::action_set_deadzone); + ClassDB::bind_method(D_METHOD("action_set_deadzone", "action", "deadzone"), &InputMap::action_set_deadzone); ClassDB::bind_method(D_METHOD("action_add_event", "action", "event"), &InputMap::action_add_event); ClassDB::bind_method(D_METHOD("action_has_event", "action", "event"), &InputMap::action_has_event); ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event"), &InputMap::action_erase_event); diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp index cfe6655504..83e8a40da9 100644 --- a/core/io/resource_import.cpp +++ b/core/io/resource_import.cpp @@ -78,7 +78,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy if (assign != String()) { if (!path_found && assign.begins_with("path.") && r_path_and_type.path == String()) { String feature = assign.get_slicec('.', 1); - if (OS::get_singleton()->has_feature(feature)) { + if (feature == "fallback" || OS::get_singleton()->has_feature(feature)) { r_path_and_type.path = value; path_found = true; //first match must have priority } diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index cb923d264e..45c106102e 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -397,7 +397,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Map<Edge, RetFaceConnect>::Element *F = ret_edges.find(e); ERR_CONTINUE(!F); - List<Geometry::MeshData::Face>::Element *O = F->get().left == E ? F->get().right : F->get().left; ERR_CONTINUE(O == E); ERR_CONTINUE(O == NULL); @@ -426,7 +425,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me Edge e2(idx, idxn); Map<Edge, RetFaceConnect>::Element *F2 = ret_edges.find(e2); - ERR_CONTINUE(!F2); //change faceconnect, point to this face instead if (F2->get().left == O) @@ -439,6 +437,15 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me } } + // remove all edge connections to this face + for (Map<Edge, RetFaceConnect>::Element *E = ret_edges.front(); E; E = E->next()) { + if (E->get().left == O) + E->get().left = NULL; + + if (E->get().right == O) + E->get().right = NULL; + } + ret_edges.erase(F); //remove the edge ret_faces.erase(O); //remove the face } diff --git a/core/object.cpp b/core/object.cpp index ba8b710a84..76226d113a 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1476,8 +1476,13 @@ Error Object::connect(const StringName &p_signal, Object *p_to_object, const Str Signal::Target target(p_to_object->get_instance_id(), p_to_method); if (s->slot_map.has(target)) { - ERR_EXPLAIN("Signal '" + p_signal + "' is already connected to given method '" + p_to_method + "' in that object."); - ERR_FAIL_COND_V(s->slot_map.has(target), ERR_INVALID_PARAMETER); + if (p_flags & CONNECT_REFERENCE_COUNTED) { + s->slot_map[target].reference_count++; + return OK; + } else { + ERR_EXPLAIN("Signal '" + p_signal + "' is already connected to given method '" + p_to_method + "' in that object."); + ERR_FAIL_COND_V(s->slot_map.has(target), ERR_INVALID_PARAMETER); + } } Signal::Slot slot; @@ -1491,6 +1496,10 @@ Error Object::connect(const StringName &p_signal, Object *p_to_object, const Str conn.binds = p_binds; slot.conn = conn; slot.cE = p_to_object->connections.push_back(conn); + if (p_flags & CONNECT_REFERENCE_COUNTED) { + slot.reference_count = 1; + } + s->slot_map[target] = slot; return OK; @@ -1521,6 +1530,10 @@ bool Object::is_connected(const StringName &p_signal, Object *p_to_object, const void Object::disconnect(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) { + _disconnect(p_signal, p_to_object, p_to_method); +} +void Object::_disconnect(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method, bool p_force) { + ERR_FAIL_NULL(p_to_object); Signal *s = signal_map.getptr(p_signal); if (!s) { @@ -1539,7 +1552,16 @@ void Object::disconnect(const StringName &p_signal, Object *p_to_object, const S ERR_FAIL(); } - p_to_object->connections.erase(s->slot_map[target].cE); + Signal::Slot *slot = &s->slot_map[target]; + + if (!p_force) { + slot->reference_count--; // by default is zero, if it was not referenced it will go below it + if (slot->reference_count >= 0) { + return; + } + } + + p_to_object->connections.erase(slot->cE); s->slot_map.erase(target); if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(), p_signal)) { @@ -1761,6 +1783,7 @@ void Object::_bind_methods() { BIND_ENUM_CONSTANT(CONNECT_DEFERRED); BIND_ENUM_CONSTANT(CONNECT_PERSIST); BIND_ENUM_CONSTANT(CONNECT_ONESHOT); + BIND_ENUM_CONSTANT(CONNECT_REFERENCE_COUNTED); } void Object::call_deferred(const StringName &p_method, VARIANT_ARG_DECLARE) { @@ -1948,13 +1971,13 @@ Object::~Object() { Connection &c = E->get(); ERR_CONTINUE(c.source != this); //bug? - this->disconnect(c.signal, c.target, c.method); + this->_disconnect(c.signal, c.target, c.method, true); } while (connections.size()) { Connection c = connections.front()->get(); - c.source->disconnect(c.signal, c.target, c.method); + c.source->_disconnect(c.signal, c.target, c.method, true); } ObjectDB::remove_instance(this); diff --git a/core/object.h b/core/object.h index 8dc3426d1d..d741371306 100644 --- a/core/object.h +++ b/core/object.h @@ -71,6 +71,7 @@ enum PropertyHint { PROPERTY_HINT_GLOBAL_DIR, ///< a directory path must be passed PROPERTY_HINT_RESOURCE_TYPE, ///< a resource object type PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines + PROPERTY_HINT_PLACEHOLDER_TEXT, ///< used to set a placeholder text for string properties PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color PROPERTY_HINT_IMAGE_COMPRESS_LOSSY, PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS, @@ -391,7 +392,8 @@ public: CONNECT_DEFERRED = 1, CONNECT_PERSIST = 2, // hint for scene to save this connection - CONNECT_ONESHOT = 4 + CONNECT_ONESHOT = 4, + CONNECT_REFERENCE_COUNTED = 8, }; struct Connection { @@ -442,8 +444,10 @@ private: struct Slot { + int reference_count; Connection conn; List<Connection>::Element *cE; + Slot() { reference_count = 0; } }; MethodInfo user; @@ -547,6 +551,8 @@ protected: friend class ClassDB; virtual void _validate_property(PropertyInfo &property) const; + void _disconnect(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method, bool p_force = false); + public: //should be protected, but bug in clang++ static void initialize_class(); _FORCE_INLINE_ static void register_custom_data_to_otdb(){}; diff --git a/core/os/os.h b/core/os/os.h index dd783408e8..12c0222ad4 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -254,7 +254,7 @@ public: virtual String get_executable_path() const; virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false) = 0; - virtual Error kill(const ProcessID &p_pid) = 0; + virtual Error kill(const ProcessID &p_pid, const int p_max_wait_msec = -1) = 0; virtual int get_process_id() const; virtual Error shell_open(String p_uri); diff --git a/core/reference.h b/core/reference.h index 0d6b1ced6e..25e02180fa 100644 --- a/core/reference.h +++ b/core/reference.h @@ -87,6 +87,13 @@ class Ref { //virtual Reference * get_reference() const { return reference; } public: + _FORCE_INLINE_ bool operator==(const T *p_ptr) const { + return reference == p_ptr; + } + _FORCE_INLINE_ bool operator!=(const T *p_ptr) const { + return reference != p_ptr; + } + _FORCE_INLINE_ bool operator<(const Ref<T> &p_r) const { return reference < p_r.reference; diff --git a/core/resource.cpp b/core/resource.cpp index 87ff4d3c2a..3078eb135a 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -151,7 +151,7 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res List<PropertyInfo> plist; get_property_list(&plist); - Resource *r = (Resource *)ClassDB::instance(get_class()); + Resource *r = Object::cast_to<Resource>(ClassDB::instance(get_class())); ERR_FAIL_COND_V(!r, Ref<Resource>()); r->local_scene = p_for_scene; @@ -182,7 +182,9 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res r->set(E->get().name, p); } - return Ref<Resource>(r); + RES res = Ref<Resource>(r); + + return res; } void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) { diff --git a/core/variant_call.cpp b/core/variant_call.cpp index ea51419233..1c50df75f5 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1920,23 +1920,11 @@ void register_variant_methods() { transform_x.set(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0); _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_Z", transform_z); - _VariantCall::add_variant_constant(Variant::PLANE, "X", Plane(Vector3(1, 0, 0), 0)); - _VariantCall::add_variant_constant(Variant::PLANE, "Y", Plane(Vector3(0, 1, 0), 0)); - _VariantCall::add_variant_constant(Variant::PLANE, "Z", Plane(Vector3(0, 0, 1), 0)); + _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_YZ", Plane(Vector3(1, 0, 0), 0)); + _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XZ", Plane(Vector3(0, 1, 0), 0)); + _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XY", Plane(Vector3(0, 0, 1), 0)); _VariantCall::add_variant_constant(Variant::QUAT, "IDENTITY", Quat(0, 0, 0, 1)); - - CharType black_circle[2] = { 0x25CF, 0 }; - _VariantCall::add_variant_constant(Variant::STRING, "BLACK_CIRCLE", String(black_circle)); - CharType white_circle[2] = { 0x25CB, 0 }; - _VariantCall::add_variant_constant(Variant::STRING, "WHITE_CIRCLE", String(white_circle)); - CharType black_diamond[2] = { 0x25C6, 0 }; - _VariantCall::add_variant_constant(Variant::STRING, "BLACK_DIAMOND", String(black_diamond)); - CharType white_diamond[2] = { 0x25C7, 0 }; - _VariantCall::add_variant_constant(Variant::STRING, "WHITE_DIAMOND", String(white_diamond)); - - _VariantCall::add_variant_constant(Variant::NODE_PATH, "CURRENT", String(".")); - _VariantCall::add_variant_constant(Variant::NODE_PATH, "PARENT", String("..")); } void unregister_variant_methods() { diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 47553659c9..d2c6a853ad 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1262,12 +1262,14 @@ </constant> <constant name="PROPERTY_HINT_MULTILINE_TEXT" value="18" enum="PropertyHint"> </constant> - <constant name="PROPERTY_HINT_COLOR_NO_ALPHA" value="19" enum="PropertyHint"> + <constant name="PROPERTY_HINT_PLACEHOLDER_TEXT" value="19" enum="PropertyHint"> </constant> - <constant name="PROPERTY_HINT_IMAGE_COMPRESS_LOSSY" value="20" enum="PropertyHint"> + <constant name="PROPERTY_HINT_COLOR_NO_ALPHA" value="20" enum="PropertyHint"> + </constant> + <constant name="PROPERTY_HINT_IMAGE_COMPRESS_LOSSY" value="21" enum="PropertyHint"> Hints that the image is compressed using lossy compression. </constant> - <constant name="PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS" value="21" enum="PropertyHint"> + <constant name="PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS" value="22" enum="PropertyHint"> Hints that the image is compressed using lossless compression. </constant> <constant name="PROPERTY_USAGE_STORAGE" value="1" enum="PropertyUsageFlags"> diff --git a/doc/classes/AnimationNode.xml b/doc/classes/AnimationNode.xml index 2f991699d6..d9bad150df 100644 --- a/doc/classes/AnimationNode.xml +++ b/doc/classes/AnimationNode.xml @@ -9,14 +9,6 @@ <demos> </demos> <methods> - <method name="_parent_set" qualifiers="virtual"> - <return type="void"> - </return> - <argument index="0" name="parent" type="Object"> - </argument> - <description> - </description> - </method> <method name="add_input"> <return type="void"> </return> @@ -62,40 +54,26 @@ <method name="blend_node"> <return type="float"> </return> - <argument index="0" name="node" type="AnimationNode"> + <argument index="0" name="name" type="String"> </argument> - <argument index="1" name="time" type="float"> + <argument index="1" name="node" type="AnimationNode"> </argument> - <argument index="2" name="seek" type="bool"> + <argument index="2" name="time" type="float"> </argument> - <argument index="3" name="blend" type="float"> + <argument index="3" name="seek" type="bool"> </argument> - <argument index="4" name="filter" type="int" enum="AnimationNode.FilterAction" default="0"> + <argument index="4" name="blend" type="float"> </argument> - <argument index="5" name="optimize" type="bool" default="true"> + <argument index="5" name="filter" type="int" enum="AnimationNode.FilterAction" default="0"> </argument> - <description> - </description> - </method> - <method name="get_caption" qualifiers="virtual"> - <return type="String"> - </return> - <description> - </description> - </method> - <method name="get_input_activity" qualifiers="const"> - <return type="float"> - </return> - <argument index="0" name="input" type="int"> + <argument index="6" name="optimize" type="bool" default="true"> </argument> <description> </description> </method> - <method name="get_input_connection"> + <method name="get_caption" qualifiers="virtual"> <return type="String"> </return> - <argument index="0" name="input" type="int"> - </argument> <description> </description> </method> @@ -113,21 +91,11 @@ <description> </description> </method> - <method name="get_parent" qualifiers="const"> - <return type="AnimationNode"> - </return> - <description> - </description> - </method> - <method name="get_position" qualifiers="const"> - <return type="Vector2"> - </return> - <description> - </description> - </method> - <method name="get_tree" qualifiers="const"> - <return type="AnimationTree"> + <method name="get_parameter" qualifiers="const"> + <return type="Variant"> </return> + <argument index="0" name="name" type="String"> + </argument> <description> </description> </method> @@ -173,18 +141,12 @@ <description> </description> </method> - <method name="set_parent"> + <method name="set_parameter"> <return type="void"> </return> - <argument index="0" name="parent" type="Object"> + <argument index="0" name="name" type="String"> </argument> - <description> - </description> - </method> - <method name="set_position"> - <return type="void"> - </return> - <argument index="0" name="position" type="Vector2"> + <argument index="1" name="value" type="Variant"> </argument> <description> </description> @@ -199,6 +161,10 @@ <description> </description> </signal> + <signal name="tree_changed"> + <description> + </description> + </signal> </signals> <constants> <constant name="FILTER_IGNORE" value="0" enum="FilterAction"> diff --git a/doc/classes/AnimationNodeAdd2.xml b/doc/classes/AnimationNodeAdd2.xml index 267eec6406..9297faa1b7 100644 --- a/doc/classes/AnimationNodeAdd2.xml +++ b/doc/classes/AnimationNodeAdd2.xml @@ -11,8 +11,6 @@ <methods> </methods> <members> - <member name="amount" type="float" setter="set_amount" getter="get_amount"> - </member> <member name="sync" type="bool" setter="set_use_sync" getter="is_using_sync"> </member> </members> diff --git a/doc/classes/AnimationNodeAdd3.xml b/doc/classes/AnimationNodeAdd3.xml index 6596b76f85..deb8d74a38 100644 --- a/doc/classes/AnimationNodeAdd3.xml +++ b/doc/classes/AnimationNodeAdd3.xml @@ -11,8 +11,6 @@ <methods> </methods> <members> - <member name="amount" type="float" setter="set_amount" getter="get_amount"> - </member> <member name="sync" type="bool" setter="set_use_sync" getter="is_using_sync"> </member> </members> diff --git a/doc/classes/AnimationNodeBlend2.xml b/doc/classes/AnimationNodeBlend2.xml index 8ef114f69b..42bb12d9d0 100644 --- a/doc/classes/AnimationNodeBlend2.xml +++ b/doc/classes/AnimationNodeBlend2.xml @@ -11,8 +11,6 @@ <methods> </methods> <members> - <member name="amount" type="float" setter="set_amount" getter="get_amount"> - </member> <member name="sync" type="bool" setter="set_use_sync" getter="is_using_sync"> </member> </members> diff --git a/doc/classes/AnimationNodeBlend3.xml b/doc/classes/AnimationNodeBlend3.xml index 094810d008..cd3d9f9bc8 100644 --- a/doc/classes/AnimationNodeBlend3.xml +++ b/doc/classes/AnimationNodeBlend3.xml @@ -11,8 +11,6 @@ <methods> </methods> <members> - <member name="amount" type="float" setter="set_amount" getter="get_amount"> - </member> <member name="sync" type="bool" setter="set_use_sync" getter="is_using_sync"> </member> </members> diff --git a/doc/classes/AnimationNodeBlendSpace1D.xml b/doc/classes/AnimationNodeBlendSpace1D.xml index 96c94a8972..2113948b2e 100644 --- a/doc/classes/AnimationNodeBlendSpace1D.xml +++ b/doc/classes/AnimationNodeBlendSpace1D.xml @@ -73,8 +73,6 @@ </method> </methods> <members> - <member name="blend_pos" type="float" setter="set_blend_pos" getter="get_blend_pos"> - </member> <member name="max_space" type="float" setter="set_max_space" getter="get_max_space"> </member> <member name="min_space" type="float" setter="set_min_space" getter="get_min_space"> diff --git a/doc/classes/AnimationNodeBlendSpace2D.xml b/doc/classes/AnimationNodeBlendSpace2D.xml index 31dc7eebac..39d780b6ef 100644 --- a/doc/classes/AnimationNodeBlendSpace2D.xml +++ b/doc/classes/AnimationNodeBlendSpace2D.xml @@ -113,8 +113,6 @@ <members> <member name="auto_triangles" type="bool" setter="set_auto_triangles" getter="get_auto_triangles"> </member> - <member name="blend_position" type="Vector2" setter="set_blend_position" getter="get_blend_position"> - </member> <member name="max_space" type="Vector2" setter="set_max_space" getter="get_max_space"> </member> <member name="min_space" type="Vector2" setter="set_min_space" getter="get_min_space"> diff --git a/doc/classes/AnimationNodeBlendTree.xml b/doc/classes/AnimationNodeBlendTree.xml index 88257883a3..cd28232908 100644 --- a/doc/classes/AnimationNodeBlendTree.xml +++ b/doc/classes/AnimationNodeBlendTree.xml @@ -16,6 +16,8 @@ </argument> <argument index="1" name="node" type="AnimationNode"> </argument> + <argument index="2" name="position" type="Vector2" default="Vector2( 0, 0 )"> + </argument> <description> </description> </method> @@ -49,6 +51,14 @@ <description> </description> </method> + <method name="get_node_position" qualifiers="const"> + <return type="Vector2"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> <method name="has_node" qualifiers="const"> <return type="bool"> </return> @@ -75,6 +85,16 @@ <description> </description> </method> + <method name="set_node_position"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="position" type="Vector2"> + </argument> + <description> + </description> + </method> </methods> <members> <member name="graph_offset" type="Vector2" setter="set_graph_offset" getter="get_graph_offset"> diff --git a/doc/classes/AnimationNodeOneShot.xml b/doc/classes/AnimationNodeOneShot.xml index b59b6e2b83..12cb9775a2 100644 --- a/doc/classes/AnimationNodeOneShot.xml +++ b/doc/classes/AnimationNodeOneShot.xml @@ -15,12 +15,6 @@ <description> </description> </method> - <method name="is_active" qualifiers="const"> - <return type="bool"> - </return> - <description> - </description> - </method> <method name="set_mix_mode"> <return type="void"> </return> @@ -29,18 +23,6 @@ <description> </description> </method> - <method name="start"> - <return type="void"> - </return> - <description> - </description> - </method> - <method name="stop"> - <return type="void"> - </return> - <description> - </description> - </method> </methods> <members> <member name="autorestart" type="bool" setter="set_autorestart" getter="has_autorestart"> diff --git a/doc/classes/AnimationNodeStateMachine.xml b/doc/classes/AnimationNodeStateMachine.xml index ad40f20db1..ed4098d938 100644 --- a/doc/classes/AnimationNodeStateMachine.xml +++ b/doc/classes/AnimationNodeStateMachine.xml @@ -16,6 +16,8 @@ </argument> <argument index="1" name="node" type="AnimationNode"> </argument> + <argument index="2" name="position" type="Vector2" default="Vector2( 0, 0 )"> + </argument> <description> </description> </method> @@ -31,12 +33,6 @@ <description> </description> </method> - <method name="get_current_node" qualifiers="const"> - <return type="String"> - </return> - <description> - </description> - </method> <method name="get_end_node" qualifiers="const"> <return type="String"> </return> @@ -65,6 +61,14 @@ <description> </description> </method> + <method name="get_node_position" qualifiers="const"> + <return type="Vector2"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> <method name="get_start_node" qualifiers="const"> <return type="String"> </return> @@ -101,12 +105,6 @@ <description> </description> </method> - <method name="get_travel_path" qualifiers="const"> - <return type="PoolStringArray"> - </return> - <description> - </description> - </method> <method name="has_node" qualifiers="const"> <return type="bool"> </return> @@ -115,21 +113,13 @@ <description> </description> </method> - <method name="has_transition"> - <return type="void"> + <method name="has_transition" qualifiers="const"> + <return type="bool"> </return> <argument index="0" name="from" type="String"> </argument> <argument index="1" name="to" type="String"> </argument> - <argument index="2" name="arg2" type="AnimationNodeStateMachineTransition"> - </argument> - <description> - </description> - </method> - <method name="is_playing" qualifiers="const"> - <return type="bool"> - </return> <description> </description> </method> @@ -185,32 +175,20 @@ <description> </description> </method> - <method name="set_start_node"> + <method name="set_node_position"> <return type="void"> </return> <argument index="0" name="name" type="String"> </argument> - <description> - </description> - </method> - <method name="start"> - <return type="void"> - </return> - <argument index="0" name="node" type="String"> + <argument index="1" name="position" type="Vector2"> </argument> <description> </description> </method> - <method name="stop"> + <method name="set_start_node"> <return type="void"> </return> - <description> - </description> - </method> - <method name="travel"> - <return type="bool"> - </return> - <argument index="0" name="to_node" type="String"> + <argument index="0" name="name" type="String"> </argument> <description> </description> diff --git a/doc/classes/AnimationNodeStateMachinePlayback.xml b/doc/classes/AnimationNodeStateMachinePlayback.xml new file mode 100644 index 0000000000..6bf9504efb --- /dev/null +++ b/doc/classes/AnimationNodeStateMachinePlayback.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="AnimationNodeStateMachinePlayback" inherits="Resource" category="Core" version="3.1"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_current_node" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_travel_path" qualifiers="const"> + <return type="PoolStringArray"> + </return> + <description> + </description> + </method> + <method name="is_playing" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="start"> + <return type="void"> + </return> + <argument index="0" name="node" type="String"> + </argument> + <description> + </description> + </method> + <method name="stop"> + <return type="void"> + </return> + <description> + </description> + </method> + <method name="travel"> + <return type="void"> + </return> + <argument index="0" name="to_node" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/AnimationNodeStateMachineTransition.xml b/doc/classes/AnimationNodeStateMachineTransition.xml index 280a1413b8..e07a9fc980 100644 --- a/doc/classes/AnimationNodeStateMachineTransition.xml +++ b/doc/classes/AnimationNodeStateMachineTransition.xml @@ -11,6 +11,8 @@ <methods> </methods> <members> + <member name="advance_condition" type="String" setter="set_advance_condition" getter="get_advance_condition"> + </member> <member name="auto_advance" type="bool" setter="set_auto_advance" getter="has_auto_advance"> </member> <member name="disabled" type="bool" setter="set_disabled" getter="is_disabled"> @@ -22,6 +24,12 @@ <member name="xfade_time" type="float" setter="set_xfade_time" getter="get_xfade_time"> </member> </members> + <signals> + <signal name="advance_condition_changed"> + <description> + </description> + </signal> + </signals> <constants> <constant name="SWITCH_MODE_IMMEDIATE" value="0" enum="SwitchMode"> </constant> diff --git a/doc/classes/AnimationNodeTimeScale.xml b/doc/classes/AnimationNodeTimeScale.xml index b3e90d190b..226c855b83 100644 --- a/doc/classes/AnimationNodeTimeScale.xml +++ b/doc/classes/AnimationNodeTimeScale.xml @@ -10,10 +10,6 @@ </demos> <methods> </methods> - <members> - <member name="scale" type="float" setter="set_scale" getter="get_scale"> - </member> - </members> <constants> </constants> </class> diff --git a/doc/classes/AnimationNodeTimeSeek.xml b/doc/classes/AnimationNodeTimeSeek.xml index a479208128..707b09a4a5 100644 --- a/doc/classes/AnimationNodeTimeSeek.xml +++ b/doc/classes/AnimationNodeTimeSeek.xml @@ -10,10 +10,6 @@ </demos> <methods> </methods> - <members> - <member name="seek_pos" type="float" setter="set_seek_pos" getter="get_seek_pos"> - </member> - </members> <constants> </constants> </class> diff --git a/doc/classes/AnimationNodeTransition.xml b/doc/classes/AnimationNodeTransition.xml index 3731fc05ed..317bc5ed69 100644 --- a/doc/classes/AnimationNodeTransition.xml +++ b/doc/classes/AnimationNodeTransition.xml @@ -11,8 +11,6 @@ <methods> </methods> <members> - <member name="current" type="int" setter="set_current" getter="get_current"> - </member> <member name="input_0/auto_advance" type="bool" setter="set_input_as_auto_advance" getter="is_input_set_as_auto_advance"> </member> <member name="input_0/name" type="String" setter="set_input_caption" getter="get_input_caption"> diff --git a/doc/classes/AnimationTree.xml b/doc/classes/AnimationTree.xml index 9b3679ae93..9a6a75079c 100644 --- a/doc/classes/AnimationTree.xml +++ b/doc/classes/AnimationTree.xml @@ -23,6 +23,16 @@ <description> </description> </method> + <method name="rename_parameter"> + <return type="void"> + </return> + <argument index="0" name="old_name" type="String"> + </argument> + <argument index="1" name="new_name" type="String"> + </argument> + <description> + </description> + </method> </methods> <members> <member name="active" type="bool" setter="set_active" getter="is_active"> diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml index 5ccf0b55aa..1e2478dd14 100644 --- a/doc/classes/ArrayMesh.xml +++ b/doc/classes/ArrayMesh.xml @@ -76,9 +76,9 @@ <method name="lightmap_unwrap"> <return type="int" enum="Error"> </return> - <argument index="0" name="arg0" type="Transform"> + <argument index="0" name="transform" type="Transform"> </argument> - <argument index="1" name="arg1" type="float"> + <argument index="1" name="texel_size" type="float"> </argument> <description> Will perform a UV unwrap on the [code]ArrayMesh[/code] to prepare the mesh for lightmapping. diff --git a/doc/classes/AudioEffectRecord.xml b/doc/classes/AudioEffectRecord.xml new file mode 100644 index 0000000000..b7771fc9c5 --- /dev/null +++ b/doc/classes/AudioEffectRecord.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="AudioEffectRecord" inherits="AudioEffect" category="Core" version="3.1"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_recording" qualifiers="const"> + <return type="AudioStreamSample"> + </return> + <description> + </description> + </method> + <method name="is_recording_active" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="set_recording_active"> + <return type="void"> + </return> + <argument index="0" name="record" type="bool"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="format" type="int" setter="set_format" getter="get_format" enum="AudioStreamSample.Format"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/doc/classes/AudioServer.xml b/doc/classes/AudioServer.xml index 51df1e99dd..37756bcfd8 100644 --- a/doc/classes/AudioServer.xml +++ b/doc/classes/AudioServer.xml @@ -34,6 +34,26 @@ Adds an [AudioEffect] effect to the bus [code]bus_idx[/code] at [code]at_position[/code]. </description> </method> + <method name="capture_get_device"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="capture_get_device_list"> + <return type="Array"> + </return> + <description> + </description> + </method> + <method name="capture_set_device"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> <method name="generate_bus_layout" qualifiers="const"> <return type="AudioBusLayout"> </return> @@ -328,7 +348,7 @@ <method name="set_device"> <return type="void"> </return> - <argument index="0" name="arg0" type="String"> + <argument index="0" name="device" type="String"> </argument> <description> </description> diff --git a/doc/classes/AudioStreamMicrophone.xml b/doc/classes/AudioStreamMicrophone.xml new file mode 100644 index 0000000000..079555d17e --- /dev/null +++ b/doc/classes/AudioStreamMicrophone.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="AudioStreamMicrophone" inherits="AudioStream" category="Core" version="3.1"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/AudioStreamSample.xml b/doc/classes/AudioStreamSample.xml index b6abda1a6f..9e56cc6016 100644 --- a/doc/classes/AudioStreamSample.xml +++ b/doc/classes/AudioStreamSample.xml @@ -11,6 +11,14 @@ <demos> </demos> <methods> + <method name="save_to_wav"> + <return type="void"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> </methods> <members> <member name="data" type="PoolByteArray" setter="set_data" getter="get_data"> diff --git a/doc/classes/BakedLightmap.xml b/doc/classes/BakedLightmap.xml index 77895249e5..966b6dd7c4 100644 --- a/doc/classes/BakedLightmap.xml +++ b/doc/classes/BakedLightmap.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="BakedLightmap" inherits="VisualInstance" category="Core" version="3.1"> <brief_description> + Prerendered indirect light map for a scene. </brief_description> <description> + Baked lightmaps are an alternative workflow for adding indirect (or baked) lighting to a scene. Unlike the [GIProbe] approach, baked lightmaps work fine on low-end PCs and mobile devices as they consume almost no resources in run-time. </description> <tutorials> <link>http://docs.godotengine.org/en/3.0/tutorials/3d/baked_lightmaps.html</link> @@ -29,36 +31,49 @@ </methods> <members> <member name="bake_cell_size" type="float" setter="set_bake_cell_size" getter="get_bake_cell_size"> + Grid subdivision size for lightmapper calculation. Default value of [code]0.25[/code] will work for most cases. Increase for better lighting on small details or if your scene is very large. </member> <member name="bake_energy" type="float" setter="set_energy" getter="get_energy"> </member> <member name="bake_extents" type="Vector3" setter="set_extents" getter="get_extents"> + Size of affected area. </member> <member name="bake_hdr" type="bool" setter="set_hdr" getter="is_hdr"> + If [code]true[/code] lightmap can capture light values greater than [code]1.0[/code]. Turning this off will result in a smaller lightmap. Default value:[code]false[/code]. </member> <member name="bake_mode" type="int" setter="set_bake_mode" getter="get_bake_mode" enum="BakedLightmap.BakeMode"> + Lightmapping mode. See [enum BakeMode]. </member> <member name="bake_propagation" type="float" setter="set_propagation" getter="get_propagation"> </member> <member name="bake_quality" type="int" setter="set_bake_quality" getter="get_bake_quality" enum="BakedLightmap.BakeQuality"> + Three quality modes are available. Higher quality requires more rendering time. See [enum BakeQuality]. </member> <member name="capture_cell_size" type="float" setter="set_capture_cell_size" getter="get_capture_cell_size"> + Grid size used for real-time capture information on dynamic objects. Cannot be larger than [member bake_cell_size]. </member> <member name="image_path" type="String" setter="set_image_path" getter="get_image_path"> + Location where lightmaps will be saved. </member> <member name="light_data" type="BakedLightmapData" setter="set_light_data" getter="get_light_data"> + The calculated light data. </member> </members> <constants> <constant name="BAKE_QUALITY_LOW" value="0" enum="BakeQuality"> + Lowest bake quality mode. Fastest to calculate. </constant> <constant name="BAKE_QUALITY_MEDIUM" value="1" enum="BakeQuality"> + Default bake quality mode. </constant> <constant name="BAKE_QUALITY_HIGH" value="2" enum="BakeQuality"> + Highest bake quality mode. Takes longer to calculate. </constant> <constant name="BAKE_MODE_CONE_TRACE" value="0" enum="BakeMode"> + Less precise but faster bake mode. </constant> <constant name="BAKE_MODE_RAY_TRACE" value="1" enum="BakeMode"> + More precise bake mode but can take considerably longer to bake. </constant> <constant name="BAKE_ERROR_OK" value="0" enum="BakeError"> </constant> diff --git a/doc/classes/BitMap.xml b/doc/classes/BitMap.xml index 98f554ebaa..7fe6a2acef 100644 --- a/doc/classes/BitMap.xml +++ b/doc/classes/BitMap.xml @@ -54,6 +54,26 @@ Returns the amount of bitmap elements that are set to true. </description> </method> + <method name="grow_mask"> + <return type="void"> + </return> + <argument index="0" name="pixels" type="int"> + </argument> + <argument index="1" name="rect" type="Rect2"> + </argument> + <description> + </description> + </method> + <method name="opaque_to_polygons" qualifiers="const"> + <return type="Array"> + </return> + <argument index="0" name="rect" type="Rect2"> + </argument> + <argument index="1" name="epsilon" type="float" default="2.0"> + </argument> + <description> + </description> + </method> <method name="set_bit"> <return type="void"> </return> diff --git a/doc/classes/Camera.xml b/doc/classes/Camera.xml index 7f7f152ae9..c7eb365891 100644 --- a/doc/classes/Camera.xml +++ b/doc/classes/Camera.xml @@ -27,6 +27,14 @@ Gets the camera transform. Subclassed cameras (such as CharacterCamera) may provide different transforms than the [Node] transform. </description> </method> + <method name="get_cull_mask_bit" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="layer" type="int"> + </argument> + <description> + </description> + </method> <method name="is_position_behind" qualifiers="const"> <return type="bool"> </return> @@ -79,6 +87,16 @@ Returns a 3D position in worldspace, that is the result of projecting a point on the [Viewport] rectangle by the camera projection. This is useful for casting rays in the form of (origin, normal) for object intersection or picking. </description> </method> + <method name="set_cull_mask_bit"> + <return type="void"> + </return> + <argument index="0" name="layer" type="int"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <description> + </description> + </method> <method name="set_orthogonal"> <return type="void"> </return> diff --git a/doc/classes/Color.xml b/doc/classes/Color.xml index c675bbe994..b66239181a 100644 --- a/doc/classes/Color.xml +++ b/doc/classes/Color.xml @@ -305,5 +305,295 @@ </member> </members> <constants> + <constant name="gray" value="Color( 0.75, 0.75, 0.75, 1 )"> + </constant> + <constant name="aliceblue" value="Color( 0.94, 0.97, 1, 1 )"> + </constant> + <constant name="antiquewhite" value="Color( 0.98, 0.92, 0.84, 1 )"> + </constant> + <constant name="aqua" value="Color( 0, 1, 1, 1 )"> + </constant> + <constant name="aquamarine" value="Color( 0.5, 1, 0.83, 1 )"> + </constant> + <constant name="azure" value="Color( 0.94, 1, 1, 1 )"> + </constant> + <constant name="beige" value="Color( 0.96, 0.96, 0.86, 1 )"> + </constant> + <constant name="bisque" value="Color( 1, 0.89, 0.77, 1 )"> + </constant> + <constant name="black" value="Color( 0, 0, 0, 1 )"> + </constant> + <constant name="blanchedalmond" value="Color( 1, 0.92, 0.8, 1 )"> + </constant> + <constant name="blue" value="Color( 0, 0, 1, 1 )"> + </constant> + <constant name="blueviolet" value="Color( 0.54, 0.17, 0.89, 1 )"> + </constant> + <constant name="brown" value="Color( 0.65, 0.16, 0.16, 1 )"> + </constant> + <constant name="burlywood" value="Color( 0.87, 0.72, 0.53, 1 )"> + </constant> + <constant name="cadetblue" value="Color( 0.37, 0.62, 0.63, 1 )"> + </constant> + <constant name="chartreuse" value="Color( 0.5, 1, 0, 1 )"> + </constant> + <constant name="chocolate" value="Color( 0.82, 0.41, 0.12, 1 )"> + </constant> + <constant name="coral" value="Color( 1, 0.5, 0.31, 1 )"> + </constant> + <constant name="cornflower" value="Color( 0.39, 0.58, 0.93, 1 )"> + </constant> + <constant name="cornsilk" value="Color( 1, 0.97, 0.86, 1 )"> + </constant> + <constant name="crimson" value="Color( 0.86, 0.08, 0.24, 1 )"> + </constant> + <constant name="cyan" value="Color( 0, 1, 1, 1 )"> + </constant> + <constant name="darkblue" value="Color( 0, 0, 0.55, 1 )"> + </constant> + <constant name="darkcyan" value="Color( 0, 0.55, 0.55, 1 )"> + </constant> + <constant name="darkgoldenrod" value="Color( 0.72, 0.53, 0.04, 1 )"> + </constant> + <constant name="darkgray" value="Color( 0.66, 0.66, 0.66, 1 )"> + </constant> + <constant name="darkgreen" value="Color( 0, 0.39, 0, 1 )"> + </constant> + <constant name="darkkhaki" value="Color( 0.74, 0.72, 0.42, 1 )"> + </constant> + <constant name="darkmagenta" value="Color( 0.55, 0, 0.55, 1 )"> + </constant> + <constant name="darkolivegreen" value="Color( 0.33, 0.42, 0.18, 1 )"> + </constant> + <constant name="darkorange" value="Color( 1, 0.55, 0, 1 )"> + </constant> + <constant name="darkorchid" value="Color( 0.6, 0.2, 0.8, 1 )"> + </constant> + <constant name="darkred" value="Color( 0.55, 0, 0, 1 )"> + </constant> + <constant name="darksalmon" value="Color( 0.91, 0.59, 0.48, 1 )"> + </constant> + <constant name="darkseagreen" value="Color( 0.56, 0.74, 0.56, 1 )"> + </constant> + <constant name="darkslateblue" value="Color( 0.28, 0.24, 0.55, 1 )"> + </constant> + <constant name="darkslategray" value="Color( 0.18, 0.31, 0.31, 1 )"> + </constant> + <constant name="darkturquoise" value="Color( 0, 0.81, 0.82, 1 )"> + </constant> + <constant name="darkviolet" value="Color( 0.58, 0, 0.83, 1 )"> + </constant> + <constant name="deeppink" value="Color( 1, 0.08, 0.58, 1 )"> + </constant> + <constant name="deepskyblue" value="Color( 0, 0.75, 1, 1 )"> + </constant> + <constant name="dimgray" value="Color( 0.41, 0.41, 0.41, 1 )"> + </constant> + <constant name="dodgerblue" value="Color( 0.12, 0.56, 1, 1 )"> + </constant> + <constant name="firebrick" value="Color( 0.7, 0.13, 0.13, 1 )"> + </constant> + <constant name="floralwhite" value="Color( 1, 0.98, 0.94, 1 )"> + </constant> + <constant name="forestgreen" value="Color( 0.13, 0.55, 0.13, 1 )"> + </constant> + <constant name="fuchsia" value="Color( 1, 0, 1, 1 )"> + </constant> + <constant name="gainsboro" value="Color( 0.86, 0.86, 0.86, 1 )"> + </constant> + <constant name="ghostwhite" value="Color( 0.97, 0.97, 1, 1 )"> + </constant> + <constant name="gold" value="Color( 1, 0.84, 0, 1 )"> + </constant> + <constant name="goldenrod" value="Color( 0.85, 0.65, 0.13, 1 )"> + </constant> + <constant name="green" value="Color( 0, 1, 0, 1 )"> + </constant> + <constant name="greenyellow" value="Color( 0.68, 1, 0.18, 1 )"> + </constant> + <constant name="honeydew" value="Color( 0.94, 1, 0.94, 1 )"> + </constant> + <constant name="hotpink" value="Color( 1, 0.41, 0.71, 1 )"> + </constant> + <constant name="indianred" value="Color( 0.8, 0.36, 0.36, 1 )"> + </constant> + <constant name="indigo" value="Color( 0.29, 0, 0.51, 1 )"> + </constant> + <constant name="ivory" value="Color( 1, 1, 0.94, 1 )"> + </constant> + <constant name="khaki" value="Color( 0.94, 0.9, 0.55, 1 )"> + </constant> + <constant name="lavender" value="Color( 0.9, 0.9, 0.98, 1 )"> + </constant> + <constant name="lavenderblush" value="Color( 1, 0.94, 0.96, 1 )"> + </constant> + <constant name="lawngreen" value="Color( 0.49, 0.99, 0, 1 )"> + </constant> + <constant name="lemonchiffon" value="Color( 1, 0.98, 0.8, 1 )"> + </constant> + <constant name="lightblue" value="Color( 0.68, 0.85, 0.9, 1 )"> + </constant> + <constant name="lightcoral" value="Color( 0.94, 0.5, 0.5, 1 )"> + </constant> + <constant name="lightcyan" value="Color( 0.88, 1, 1, 1 )"> + </constant> + <constant name="lightgoldenrod" value="Color( 0.98, 0.98, 0.82, 1 )"> + </constant> + <constant name="lightgray" value="Color( 0.83, 0.83, 0.83, 1 )"> + </constant> + <constant name="lightgreen" value="Color( 0.56, 0.93, 0.56, 1 )"> + </constant> + <constant name="lightpink" value="Color( 1, 0.71, 0.76, 1 )"> + </constant> + <constant name="lightsalmon" value="Color( 1, 0.63, 0.48, 1 )"> + </constant> + <constant name="lightseagreen" value="Color( 0.13, 0.7, 0.67, 1 )"> + </constant> + <constant name="lightskyblue" value="Color( 0.53, 0.81, 0.98, 1 )"> + </constant> + <constant name="lightslategray" value="Color( 0.47, 0.53, 0.6, 1 )"> + </constant> + <constant name="lightsteelblue" value="Color( 0.69, 0.77, 0.87, 1 )"> + </constant> + <constant name="lightyellow" value="Color( 1, 1, 0.88, 1 )"> + </constant> + <constant name="lime" value="Color( 0, 1, 0, 1 )"> + </constant> + <constant name="limegreen" value="Color( 0.2, 0.8, 0.2, 1 )"> + </constant> + <constant name="linen" value="Color( 0.98, 0.94, 0.9, 1 )"> + </constant> + <constant name="magenta" value="Color( 1, 0, 1, 1 )"> + </constant> + <constant name="maroon" value="Color( 0.69, 0.19, 0.38, 1 )"> + </constant> + <constant name="mediumaquamarine" value="Color( 0.4, 0.8, 0.67, 1 )"> + </constant> + <constant name="mediumblue" value="Color( 0, 0, 0.8, 1 )"> + </constant> + <constant name="mediumorchid" value="Color( 0.73, 0.33, 0.83, 1 )"> + </constant> + <constant name="mediumpurple" value="Color( 0.58, 0.44, 0.86, 1 )"> + </constant> + <constant name="mediumseagreen" value="Color( 0.24, 0.7, 0.44, 1 )"> + </constant> + <constant name="mediumslateblue" value="Color( 0.48, 0.41, 0.93, 1 )"> + </constant> + <constant name="mediumspringgreen" value="Color( 0, 0.98, 0.6, 1 )"> + </constant> + <constant name="mediumturquoise" value="Color( 0.28, 0.82, 0.8, 1 )"> + </constant> + <constant name="mediumvioletred" value="Color( 0.78, 0.08, 0.52, 1 )"> + </constant> + <constant name="midnightblue" value="Color( 0.1, 0.1, 0.44, 1 )"> + </constant> + <constant name="mintcream" value="Color( 0.96, 1, 0.98, 1 )"> + </constant> + <constant name="mistyrose" value="Color( 1, 0.89, 0.88, 1 )"> + </constant> + <constant name="moccasin" value="Color( 1, 0.89, 0.71, 1 )"> + </constant> + <constant name="navajowhite" value="Color( 1, 0.87, 0.68, 1 )"> + </constant> + <constant name="navyblue" value="Color( 0, 0, 0.5, 1 )"> + </constant> + <constant name="oldlace" value="Color( 0.99, 0.96, 0.9, 1 )"> + </constant> + <constant name="olive" value="Color( 0.5, 0.5, 0, 1 )"> + </constant> + <constant name="olivedrab" value="Color( 0.42, 0.56, 0.14, 1 )"> + </constant> + <constant name="orange" value="Color( 1, 0.65, 0, 1 )"> + </constant> + <constant name="orangered" value="Color( 1, 0.27, 0, 1 )"> + </constant> + <constant name="orchid" value="Color( 0.85, 0.44, 0.84, 1 )"> + </constant> + <constant name="palegoldenrod" value="Color( 0.93, 0.91, 0.67, 1 )"> + </constant> + <constant name="palegreen" value="Color( 0.6, 0.98, 0.6, 1 )"> + </constant> + <constant name="paleturquoise" value="Color( 0.69, 0.93, 0.93, 1 )"> + </constant> + <constant name="palevioletred" value="Color( 0.86, 0.44, 0.58, 1 )"> + </constant> + <constant name="papayawhip" value="Color( 1, 0.94, 0.84, 1 )"> + </constant> + <constant name="peachpuff" value="Color( 1, 0.85, 0.73, 1 )"> + </constant> + <constant name="peru" value="Color( 0.8, 0.52, 0.25, 1 )"> + </constant> + <constant name="pink" value="Color( 1, 0.75, 0.8, 1 )"> + </constant> + <constant name="plum" value="Color( 0.87, 0.63, 0.87, 1 )"> + </constant> + <constant name="powderblue" value="Color( 0.69, 0.88, 0.9, 1 )"> + </constant> + <constant name="purple" value="Color( 0.63, 0.13, 0.94, 1 )"> + </constant> + <constant name="rebeccapurple" value="Color( 0.4, 0.2, 0.6, 1 )"> + </constant> + <constant name="red" value="Color( 1, 0, 0, 1 )"> + </constant> + <constant name="rosybrown" value="Color( 0.74, 0.56, 0.56, 1 )"> + </constant> + <constant name="royalblue" value="Color( 0.25, 0.41, 0.88, 1 )"> + </constant> + <constant name="saddlebrown" value="Color( 0.55, 0.27, 0.07, 1 )"> + </constant> + <constant name="salmon" value="Color( 0.98, 0.5, 0.45, 1 )"> + </constant> + <constant name="sandybrown" value="Color( 0.96, 0.64, 0.38, 1 )"> + </constant> + <constant name="seagreen" value="Color( 0.18, 0.55, 0.34, 1 )"> + </constant> + <constant name="seashell" value="Color( 1, 0.96, 0.93, 1 )"> + </constant> + <constant name="sienna" value="Color( 0.63, 0.32, 0.18, 1 )"> + </constant> + <constant name="silver" value="Color( 0.75, 0.75, 0.75, 1 )"> + </constant> + <constant name="skyblue" value="Color( 0.53, 0.81, 0.92, 1 )"> + </constant> + <constant name="slateblue" value="Color( 0.42, 0.35, 0.8, 1 )"> + </constant> + <constant name="slategray" value="Color( 0.44, 0.5, 0.56, 1 )"> + </constant> + <constant name="snow" value="Color( 1, 0.98, 0.98, 1 )"> + </constant> + <constant name="springgreen" value="Color( 0, 1, 0.5, 1 )"> + </constant> + <constant name="steelblue" value="Color( 0.27, 0.51, 0.71, 1 )"> + </constant> + <constant name="tan" value="Color( 0.82, 0.71, 0.55, 1 )"> + </constant> + <constant name="teal" value="Color( 0, 0.5, 0.5, 1 )"> + </constant> + <constant name="thistle" value="Color( 0.85, 0.75, 0.85, 1 )"> + </constant> + <constant name="tomato" value="Color( 1, 0.39, 0.28, 1 )"> + </constant> + <constant name="turquoise" value="Color( 0.25, 0.88, 0.82, 1 )"> + </constant> + <constant name="violet" value="Color( 0.93, 0.51, 0.93, 1 )"> + </constant> + <constant name="webgray" value="Color( 0.5, 0.5, 0.5, 1 )"> + </constant> + <constant name="webgreen" value="Color( 0, 0.5, 0, 1 )"> + </constant> + <constant name="webmaroon" value="Color( 0.5, 0, 0, 1 )"> + </constant> + <constant name="webpurple" value="Color( 0.5, 0, 0.5, 1 )"> + </constant> + <constant name="wheat" value="Color( 0.96, 0.87, 0.7, 1 )"> + </constant> + <constant name="white" value="Color( 1, 1, 1, 1 )"> + </constant> + <constant name="whitesmoke" value="Color( 0.96, 0.96, 0.96, 1 )"> + </constant> + <constant name="yellow" value="Color( 1, 1, 0, 1 )"> + </constant> + <constant name="yellowgreen" value="Color( 0.6, 0.8, 0.2, 1 )"> + </constant> </constants> </class> diff --git a/doc/classes/ColorPicker.xml b/doc/classes/ColorPicker.xml index 232357f822..4d52eacba8 100644 --- a/doc/classes/ColorPicker.xml +++ b/doc/classes/ColorPicker.xml @@ -4,7 +4,7 @@ Color picker control. </brief_description> <description> - This is a simple color picker [Control]. It's useful for selecting a color from an RGB/RGBA colorspace. + [Control] node displaying a color picker widget. It's useful for selecting a color from an RGB/RGBA colorspace. </description> <tutorials> </tutorials> @@ -17,7 +17,7 @@ <argument index="0" name="color" type="Color"> </argument> <description> - Adds the current selected to color to a list of colors (presets), the presets will be displayed in the color picker and the user will be able to select them, notice that the presets list is only for this color picker. + Adds the given color to a list of color presets. The presets are displayed in the color picker and the user will be able to select them. Note: the presets list is only for [i]this[/i] color picker. </description> </method> </methods> @@ -26,13 +26,13 @@ The currently selected color. </member> <member name="deferred_mode" type="bool" setter="set_deferred_mode" getter="is_deferred_mode"> - If [code]true[/code], the color will apply only after user releases mouse button, otherwise it will apply immediatly even in mouse motion event (which can cause performance issues). + If [code]true[/code] the color will apply only after the user releases the mouse button, otherwise it will apply immediatly even in mouse motion event (which can cause performance issues). </member> <member name="edit_alpha" type="bool" setter="set_edit_alpha" getter="is_editing_alpha"> - If [code]true[/code], shows an alpha channel slider (transparency). + If [code]true[/code] shows an alpha channel slider (transparency). </member> <member name="raw_mode" type="bool" setter="set_raw_mode" getter="is_raw_mode"> - If [code]true[/code], allows the color R, G, B component values to go beyond 1.0, which can be used for certain special operations that require it (like tinting without darkening or rendering sprites in HDR). + If [code]true[/code] allows the color R, G, B component values to go beyond 1.0, which can be used for certain special operations that require it (like tinting without darkening or rendering sprites in HDR). </member> </members> <signals> diff --git a/doc/classes/ColorPickerButton.xml b/doc/classes/ColorPickerButton.xml index d049e936a8..6ac2911c11 100644 --- a/doc/classes/ColorPickerButton.xml +++ b/doc/classes/ColorPickerButton.xml @@ -4,7 +4,7 @@ Button that pops out a [ColorPicker]. </brief_description> <description> - Encapsulates a [ColorPicker] making it accesible by pressing a button, pressing the button will toggle the [ColorPicker] visibility + Encapsulates a [ColorPicker] making it accesible by pressing a button. Pressing the button will toggle the [ColorPicker] visibility. </description> <tutorials> </tutorials> @@ -15,14 +15,14 @@ <return type="ColorPicker"> </return> <description> - Returns the [code]ColorPicker[/code] that this [code]ColorPickerButton[/code] toggles. + Returns the [ColorPicker] that this node toggles. </description> </method> <method name="get_popup"> <return type="PopupPanel"> </return> <description> - Returns the control's [PopupPanel] which allows you to connect to Popup Signals. This allows you to handle events when the ColorPicker is shown or hidden. + Returns the control's [PopupPanel] which allows you to connect to popup signals. This allows you to handle events when the ColorPicker is shown or hidden. </description> </method> </methods> diff --git a/doc/classes/ColorRect.xml b/doc/classes/ColorRect.xml index 69a70cfa39..e1bffb719e 100644 --- a/doc/classes/ColorRect.xml +++ b/doc/classes/ColorRect.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="ColorRect" inherits="Control" category="Core" version="3.1"> <brief_description> - Colored rect for canvas. + Colored rectangle. </brief_description> <description> - An object that is represented on the canvas as a rect with color. [Color] is used to set or get color info for the rect. + Displays a colored rectangle. </description> <tutorials> </tutorials> @@ -14,9 +14,9 @@ </methods> <members> <member name="color" type="Color" setter="set_frame_color" getter="get_frame_color"> - The color to fill the [code]ColorRect[/code]. + The fill color. [codeblock] - $ColorRect.color = Color(1, 0, 0, 1) # Set ColorRect node's color to red + $ColorRect.color = Color(1, 0, 0, 1) # Set ColorRect's color to red. [/codeblock] </member> </members> diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index d11b369e68..4301102e4a 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="Control" inherits="CanvasItem" category="Core" version="3.1"> <brief_description> - All User Interface nodes inherit from Control. Features anchors and margins to adapt its position and size to its parent. + All User Interface nodes inherit from Control. A control's anchors and margins adapt its position and size relative to its parent. </brief_description> <description> Base class for all User Interface or [i]UI[/i] related nodes. [code]Control[/code] features a bounding rectangle that defines its extents, an anchor position relative to its parent and margins that represent an offset to the anchor. The margins update automatically when the node, any of its parents, or the screen size change. @@ -19,11 +19,17 @@ <demos> </demos> <methods> + <method name="_clips_input" qualifiers="virtual"> + <return type="bool"> + </return> + <description> + </description> + </method> <method name="_get_minimum_size" qualifiers="virtual"> <return type="Vector2"> </return> <description> - Returns the minimum size this Control can shrink to. The node can never be smaller than this minimum size. + Returns the minimum size for this control. See [member rect_min_size]. </description> </method> <method name="_gui_input" qualifiers="virtual"> @@ -129,7 +135,7 @@ This method should only be used to test the data. Process the data in [method drop_data]. [codeblock] extends Control - + func can_drop_data(position, data): # check position if it is relevant to you # otherwise just check data @@ -148,10 +154,10 @@ Godot calls this method to pass you the [code]data[/code] from a control's [method get_drag_data] result. Godot first calls [method can_drop_data] to test if [code]data[/code] is allowed to drop at [code]position[/code] where [code]position[/code] is local to this control. [codeblock] extends ColorRect - + func can_drop_data(position, data): return typeof(data) == TYPE_DICTIONARY and data.has('color') - + func drop_data(position, data): color = data['color'] [/codeblock] @@ -173,6 +179,7 @@ <return type="Vector2"> </return> <description> + Returns [member margin_left] and [member margin_top]. See also [member rect_position]. </description> </method> <method name="get_color" qualifiers="const"> @@ -207,7 +214,7 @@ <argument index="0" name="position" type="Vector2" default="Vector2( 0, 0 )"> </argument> <description> - Returns the mouse cursor shape the control displays on mouse hover, one of the [code]CURSOR_*[/code] constants. + Returns the mouse cursor shape the control displays on mouse hover. See [enum CursorShape]. </description> </method> <method name="get_drag_data" qualifiers="virtual"> @@ -220,7 +227,7 @@ A preview that will follow the mouse that should represent the data can be set with [method set_drag_preview]. A good time to set the preview is in this method. [codeblock] extends Control - + func get_drag_data(position): var mydata = make_data() set_drag_preview(make_preview(mydata)) @@ -232,14 +239,14 @@ <return type="Vector2"> </return> <description> - Returns MARGIN_LEFT and MARGIN_TOP at the same time. This is a helper (see [method set_margin]). + Returns [member margin_right] and [member margin_bottom]. </description> </method> <method name="get_focus_owner" qualifiers="const"> <return type="Control"> </return> <description> - Return which control is owning the keyboard focus, or null if no one. + Returns the control that has the keyboard focus or [code]null[/code] if none. </description> </method> <method name="get_font" qualifiers="const"> @@ -256,7 +263,7 @@ <return type="Rect2"> </return> <description> - Return position and size of the Control, relative to the top-left corner of the [i]window[/i] Control. This is a helper (see [method get_global_position], [method get_size]). + Returns the position and size of the control relative to the top-left corner of the screen. See [member rect_position] and [member rect_size]. </description> </method> <method name="get_icon" qualifiers="const"> @@ -273,33 +280,35 @@ <return type="Vector2"> </return> <description> - Return the minimum size this Control can shrink to. A control will never be displayed or resized smaller than its minimum size. + Returns the minimum size for this control. See [member rect_min_size]. </description> </method> <method name="get_parent_area_size" qualifiers="const"> <return type="Vector2"> </return> <description> + Returns the width/height occupied in the parent control. </description> </method> <method name="get_parent_control" qualifiers="const"> <return type="Control"> </return> <description> + Returns the parent control node. </description> </method> <method name="get_rect" qualifiers="const"> <return type="Rect2"> </return> <description> - Return position and size of the Control, relative to the top-left corner of the parent Control. This is a helper (see [method get_position], [method get_size]). + Returns the position and size of the control relative to the top-left corner of the parent Control. See [member rect_position] and [member rect_size]. </description> </method> <method name="get_rotation" qualifiers="const"> <return type="float"> </return> <description> - Return the rotation (in radians) + Returns the rotation (in radians). </description> </method> <method name="get_stylebox" qualifiers="const"> @@ -318,7 +327,7 @@ <argument index="0" name="at_position" type="Vector2" default="Vector2( 0, 0 )"> </argument> <description> - Return the tooltip, which will appear when the cursor is resting over this control. + Returns the tooltip, which will appear when the cursor is resting over this control. </description> </method> <method name="grab_click_focus"> @@ -374,7 +383,7 @@ <return type="bool"> </return> <description> - Return whether the Control is the current focused control (see [method set_focus_mode]). + Returns [code]true[/code] if this is the current focused control. See [member focus_mode]. </description> </method> <method name="has_font" qualifiers="const"> @@ -457,7 +466,7 @@ <return type="void"> </return> <description> - Give up the focus, no other control will be able to receive keyboard input. + Give up the focus. No other control will be able to receive keyboard input. </description> </method> <method name="set_anchor"> @@ -516,7 +525,7 @@ <argument index="0" name="position" type="Vector2"> </argument> <description> - Sets MARGIN_LEFT and MARGIN_TOP at the same time. This is a helper (see [method set_margin]). + Sets [member margin_left] and [member margin_top] at the same time. </description> </method> <method name="set_drag_forwarding"> @@ -534,15 +543,15 @@ extends Control func _ready(): set_drag_forwarding(target_control) - + # TargetControl.gd extends Control func can_drop_data_fw(position, data, from_control): return true - + func drop_data_fw(position, data, from_control): my_handle_data(data) - + func get_drag_data_fw(position, from_control): set_drag_preview(my_preview) return my_data() @@ -564,7 +573,7 @@ <argument index="0" name="position" type="Vector2"> </argument> <description> - Sets MARGIN_RIGHT and MARGIN_BOTTOM at the same time. This is a helper (see [method set_margin]). + Sets [member margin_right] and [member margin_bottom] at the same time. </description> </method> <method name="set_margins_preset"> @@ -585,7 +594,7 @@ <argument index="0" name="radians" type="float"> </argument> <description> - Set the rotation (in radians). + Sets the rotation (in radians). </description> </method> <method name="show_modal"> @@ -594,7 +603,7 @@ <argument index="0" name="exclusive" type="bool" default="false"> </argument> <description> - Display a Control as modal. Control must be a subwindow. Modal controls capture the input signals until closed or the area outside them is accessed. When a modal control loses focus, or the ESC key is pressed, they automatically hide. Modal controls are used extensively for popup dialogs and menus. + Displays a control as modal. Control must be a subwindow. Modal controls capture the input signals until closed or the area outside them is accessed. When a modal control loses focus, or the ESC key is pressed, they automatically hide. Modal controls are used extensively for popup dialogs and menus. </description> </method> <method name="warp_mouse"> @@ -753,22 +762,22 @@ </signals> <constants> <constant name="FOCUS_NONE" value="0" enum="FocusMode"> - The node cannot grab focus. Use with [member set_focus_mode]. + The node cannot grab focus. Use with [member focus_mode]. </constant> <constant name="FOCUS_CLICK" value="1" enum="FocusMode"> - The node can only grab focus on mouse clicks. Use with [member set_focus_mode]. + The node can only grab focus on mouse clicks. Use with [member focus_mode]. </constant> <constant name="FOCUS_ALL" value="2" enum="FocusMode"> - The node can grab focus on mouse click or using the arrows and the Tab keys on the keyboard. Use with [member set_focus_mode]. + The node can grab focus on mouse click or using the arrows and the Tab keys on the keyboard. Use with [member focus_mode]. </constant> <constant name="NOTIFICATION_RESIZED" value="40"> Sent when the node changes size. Use [member rect_size] to get the new size. </constant> <constant name="NOTIFICATION_MOUSE_ENTER" value="41"> - Sent when the mouse pointer enters the node's [code]Rect[/code] area. + Sent when the mouse pointer enters the node. </constant> <constant name="NOTIFICATION_MOUSE_EXIT" value="42"> - Sent when the mouse pointer exits the node's [code]Rect[/code] area. + Sent when the mouse pointer exits the node. </constant> <constant name="NOTIFICATION_FOCUS_ENTER" value="43"> Sent when the node grabs focus. @@ -777,7 +786,7 @@ Sent when the node loses focus. </constant> <constant name="NOTIFICATION_THEME_CHANGED" value="45"> - Sent when the node's [member theme] changes, right before Godot redraws the [code]Control[/code]. Happens when you call one of the [code]add_*_override[/code] + Sent when the node's [member theme] changes, right before Godot redraws the control. Happens when you call one of the [code]add_*_override[/code] </constant> <constant name="NOTIFICATION_MODAL_CLOSE" value="46"> Sent when an open modal dialog closes. See [member show_modal]. @@ -903,7 +912,7 @@ Sets the node's size flags to both fill and expand. See the 2 constants above for more information. </constant> <constant name="SIZE_SHRINK_CENTER" value="4" enum="SizeFlags"> - Tells the parent [Container] to center the node in itself. It centers the [code]Control[/code] based on its bounding box, so it doesn't work with the fill or expand size flags. Use with [member size_flags_horizontal] and [member size_flags_vertical]. + Tells the parent [Container] to center the node in itself. It centers the control based on its bounding box, so it doesn't work with the fill or expand size flags. Use with [member size_flags_horizontal] and [member size_flags_vertical]. </constant> <constant name="SIZE_SHRINK_END" value="8" enum="SizeFlags"> Tells the parent [Container] to align the node with its end, either the bottom or the right edge. It doesn't work with the fill or expand size flags. Use with [member size_flags_horizontal] and [member size_flags_vertical]. diff --git a/doc/classes/Dictionary.xml b/doc/classes/Dictionary.xml index 9fa1e3ea6c..800a76ccf1 100644 --- a/doc/classes/Dictionary.xml +++ b/doc/classes/Dictionary.xml @@ -33,6 +33,8 @@ </description> </method> <method name="erase"> + <return type="bool"> + </return> <argument index="0" name="key" type="var"> </argument> <description> diff --git a/doc/classes/DirectionalLight.xml b/doc/classes/DirectionalLight.xml index ef75182811..2dc522083d 100644 --- a/doc/classes/DirectionalLight.xml +++ b/doc/classes/DirectionalLight.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="DirectionalLight" inherits="Light" category="Core" version="3.1"> <brief_description> - Directional Light, such as the Sun or the Moon. + Directional light from a distance, as from the Sun. </brief_description> <description> - A DirectionalLight is a type of [Light] node that emits light constantly in one direction (the negative z axis of the node). It is used lights with strong intensity that are located far away from the scene to model sunlight or moonlight. The worldspace location of the DirectionalLight transform (origin) is ignored, only the basis is used do determine light direction. + A directional light is a type of [Light] node that models an infinite number of parallel rays covering the entire scene. It is used for lights with strong intensity that are located far away from the scene to model sunlight or moonlight. The worldspace location of the DirectionalLight transform (origin) is ignored. Only the basis is used do determine light direction. </description> <tutorials> <link>http://docs.godotengine.org/en/3.0/tutorials/3d/lights_and_shadows.html</link> @@ -15,34 +15,48 @@ </methods> <members> <member name="directional_shadow_bias_split_scale" type="float" setter="set_param" getter="get_param"> + Amount of extra bias for shadow splits that are far away. If self shadowing occurs only on the splits far away, this value can fix them. </member> <member name="directional_shadow_blend_splits" type="bool" setter="set_blend_splits" getter="is_blend_splits_enabled"> + If [code]true[/code] shadow detail is sacrificed in exchange for smoother transitions between splits. Default value:[code]false[/code]. </member> <member name="directional_shadow_depth_range" type="int" setter="set_shadow_depth_range" getter="get_shadow_depth_range" enum="DirectionalLight.ShadowDepthRange"> + Optimizes shadow rendering for detail versus movement. See [enum ShadowDepthRange]. </member> <member name="directional_shadow_max_distance" type="float" setter="set_param" getter="get_param"> + The maximum distance for shadow splits. </member> <member name="directional_shadow_mode" type="int" setter="set_shadow_mode" getter="get_shadow_mode" enum="DirectionalLight.ShadowMode"> + The light's shadow rendering algorithm. See [enum ShadowMode]. </member> <member name="directional_shadow_normal_bias" type="float" setter="set_param" getter="get_param"> + Can be used to fix special cases of self shadowing when objects are perpendicular to the light. </member> <member name="directional_shadow_split_1" type="float" setter="set_param" getter="get_param"> + The distance from camera to shadow split 1. Relative to [member directional_shadow_max_distance]. Only used in [enum directional_shadow_mode] SHADOW_PARALLEL_*_SPLITS. </member> <member name="directional_shadow_split_2" type="float" setter="set_param" getter="get_param"> + The distance from shadow split 1 to split 2. Relative to [member directional_shadow_max_distance]. Only used in [enum directional_shadow_mode] SHADOW_PARALLEL_*_SPLITS. </member> <member name="directional_shadow_split_3" type="float" setter="set_param" getter="get_param"> + The distance from shadow split 2 to split 3. Relative to [member directional_shadow_max_distance]. Only used in [enum directional_shadow_mode] SHADOW_PARALLEL_4_SPLITS. </member> </members> <constants> <constant name="SHADOW_ORTHOGONAL" value="0" enum="ShadowMode"> + Renders the entire scene's shadow map from an orthogonal point of view. May result in blockier shadows on close objects. </constant> <constant name="SHADOW_PARALLEL_2_SPLITS" value="1" enum="ShadowMode"> + Splits the view frustum in 2 areas, each with its own shadow map. </constant> <constant name="SHADOW_PARALLEL_4_SPLITS" value="2" enum="ShadowMode"> + Splits the view frustum in 4 areas, each with its own shadow map. </constant> <constant name="SHADOW_DEPTH_RANGE_STABLE" value="0" enum="ShadowDepthRange"> + Keeps the shadow stable when the camera moves, at the cost of lower effective shadow resolution. Default value. </constant> <constant name="SHADOW_DEPTH_RANGE_OPTIMIZED" value="1" enum="ShadowDepthRange"> + Tries to achieve maximum shadow resolution. May result in saw effect on shadow edges. </constant> </constants> </class> diff --git a/doc/classes/EditorFileSystem.xml b/doc/classes/EditorFileSystem.xml index 5a8b506f9e..ade6d2034d 100644 --- a/doc/classes/EditorFileSystem.xml +++ b/doc/classes/EditorFileSystem.xml @@ -93,6 +93,10 @@ Remitted if a resource is reimported. </description> </signal> + <signal name="script_classes_updated"> + <description> + </description> + </signal> <signal name="sources_changed"> <argument index="0" name="exist" type="bool"> </argument> diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml index f5fbf8e313..62fc56e990 100644 --- a/doc/classes/EditorPlugin.xml +++ b/doc/classes/EditorPlugin.xml @@ -156,15 +156,6 @@ Clear all the state and reset the object being edited to zero. This ensures your plugin does not keep editing a currently existing node, or a node from the wrong scene. </description> </method> - <method name="create_spatial_gizmo" qualifiers="virtual"> - <return type="EditorSpatialGizmo"> - </return> - <argument index="0" name="for_spatial" type="Spatial"> - </argument> - <description> - This is used for plugins that create gizmos used by the spatial editor. Just check that the node passed in the "for_spatial" argument matches your plugin. - </description> - </method> <method name="edit" qualifiers="virtual"> <return type="void"> </return> diff --git a/doc/classes/EditorSpatialGizmo.xml b/doc/classes/EditorSpatialGizmo.xml index 3636442b85..2081ae7a4d 100644 --- a/doc/classes/EditorSpatialGizmo.xml +++ b/doc/classes/EditorSpatialGizmo.xml @@ -33,9 +33,11 @@ </return> <argument index="0" name="handles" type="PoolVector3Array"> </argument> - <argument index="1" name="billboard" type="bool" default="false"> + <argument index="1" name="material" type="Material"> </argument> - <argument index="2" name="secondary" type="bool" default="false"> + <argument index="2" name="billboard" type="bool" default="false"> + </argument> + <argument index="3" name="secondary" type="bool" default="false"> </argument> <description> Add a list of handles (points) which can be used to deform the object being edited. @@ -138,6 +140,14 @@ The [Camera] is also provided so screen coordinates can be converted to raycasts. </description> </method> + <method name="set_hidden"> + <return type="void"> + </return> + <argument index="0" name="hidden" type="bool"> + </argument> + <description> + </description> + </method> <method name="set_spatial_node"> <return type="void"> </return> diff --git a/doc/classes/Expression.xml b/doc/classes/Expression.xml new file mode 100644 index 0000000000..d5b831a61a --- /dev/null +++ b/doc/classes/Expression.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="Expression" inherits="Reference" category="Core" version="3.1"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="execute"> + <return type="Variant"> + </return> + <argument index="0" name="inputs" type="Array" default="[ ]"> + </argument> + <argument index="1" name="base_instance" type="Object" default="null"> + </argument> + <argument index="2" name="show_error" type="bool" default="true"> + </argument> + <description> + </description> + </method> + <method name="get_error_text" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="has_execute_failed" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="parse"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="expression" type="String"> + </argument> + <argument index="1" name="input_names" type="PoolStringArray" default="PoolStringArray( )"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/InputEventKey.xml b/doc/classes/InputEventKey.xml index 7503e53188..a013ee6266 100644 --- a/doc/classes/InputEventKey.xml +++ b/doc/classes/InputEventKey.xml @@ -16,6 +16,7 @@ <return type="int"> </return> <description> + Returns the scancode combined with modifier keys such as [code]Shift[/code] or [code]Alt[/code]. See also [InputEventWithModifiers]. </description> </method> </methods> diff --git a/doc/classes/InputMap.xml b/doc/classes/InputMap.xml index 2f5fb49dba..7fd1d7e8ac 100644 --- a/doc/classes/InputMap.xml +++ b/doc/classes/InputMap.xml @@ -40,6 +40,7 @@ <argument index="0" name="action" type="String"> </argument> <description> + Removes all events from an action. </description> </method> <method name="action_has_event"> @@ -50,15 +51,15 @@ <argument index="1" name="event" type="InputEvent"> </argument> <description> - Returns [true] if an action has an [InputEvent] associated with it. + Returns [code]true[/code] if the action has the given [InputEvent] associated with it. </description> </method> <method name="action_set_deadzone"> <return type="void"> </return> - <argument index="0" name="deadzone" type="String"> + <argument index="0" name="action" type="String"> </argument> - <argument index="1" name="arg1" type="float"> + <argument index="1" name="deadzone" type="float"> </argument> <description> </description> @@ -71,7 +72,7 @@ <argument index="1" name="deadzone" type="float" default="0.5"> </argument> <description> - Adds an (empty) action to the [code]InputMap[/code], with a configurable [code]deadzone[/code]. + Adds an empty action to the [code]InputMap[/code] with a configurable [code]deadzone[/code]. An [InputEvent] can then be added to this action with [method action_add_event]. </description> </method> diff --git a/doc/classes/KinematicBody.xml b/doc/classes/KinematicBody.xml index e6d537b895..0c66319ae7 100644 --- a/doc/classes/KinematicBody.xml +++ b/doc/classes/KinematicBody.xml @@ -65,8 +65,11 @@ </argument> <argument index="1" name="infinite_inertia" type="bool" default="true"> </argument> + <argument index="2" name="test_only" type="bool" default="false"> + </argument> <description> Moves the body along the vector [code]rel_vec[/code]. The body will stop if it collides. Returns a [KinematicCollision], which contains information about the collision. + If [code]test_only[/code] is [code]true[/true], the body does not move but the would-be collision information is given. </description> </method> <method name="move_and_slide"> @@ -76,7 +79,7 @@ </argument> <argument index="1" name="floor_normal" type="Vector3" default="Vector3( 0, 0, 0 )"> </argument> - <argument index="2" name="slope_stop_min_velocity" type="float" default="0.05"> + <argument index="2" name="stop_on_slope" type="bool" default="false"> </argument> <argument index="3" name="max_slides" type="int" default="4"> </argument> @@ -88,12 +91,32 @@ Moves the body along a vector. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a [code]KinematicBody[/code] or [RigidBody], it will also be affected by the motion of the other body. You can use this to make moving or rotating platforms, or to make nodes push other nodes. [code]linear_velocity[/code] is a value in pixels per second. Unlike in for example [method move_and_collide], you should [i]not[/i] multiply it with [code]delta[/code] — this is done by the method. [code]floor_normal[/code] is the up direction, used to determine what is a wall and what is a floor or a ceiling. If set to the default value of [code]Vector3(0, 0, 0)[/code], everything is considered a wall. This is useful for topdown games. - If the body is standing on a slope and the horizontal speed (relative to the floor's speed) goes below [code]slope_stop_min_velocity[/code], the body will stop completely. This prevents the body from sliding down slopes when you include gravity in [code]linear_velocity[/code]. When set to lower values, the body will not be able to stand still on steep slopes. + [i]TODO: Update for new stop_on_slode argument.[/i] If the body is standing on a slope and the horizontal speed (relative to the floor's speed) goes below [code]slope_stop_min_velocity[/code], the body will stop completely. This prevents the body from sliding down slopes when you include gravity in [code]linear_velocity[/code]. When set to lower values, the body will not be able to stand still on steep slopes. If the body collides, it will change direction a maximum of [code]max_slides[/code] times before it stops. [code]floor_max_angle[/code] is the maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall. The default value equals 45 degrees. Returns the movement that remained when the body stopped. To get more detailed information about collisions that occurred, use [method get_slide_collision]. </description> </method> + <method name="move_and_slide_with_snap"> + <return type="Vector3"> + </return> + <argument index="0" name="linear_velocity" type="Vector3"> + </argument> + <argument index="1" name="snap" type="Vector3"> + </argument> + <argument index="2" name="floor_normal" type="Vector3" default="Vector3( 0, 0, 0 )"> + </argument> + <argument index="3" name="infinite_inertia" type="bool" default="true"> + </argument> + <argument index="4" name="stop_on_slope" type="bool" default="false"> + </argument> + <argument index="5" name="max_bounces" type="int" default="4"> + </argument> + <argument index="6" name="floor_max_angle" type="float" default="0.785398"> + </argument> + <description> + </description> + </method> <method name="test_move"> <return type="bool"> </return> @@ -109,20 +132,14 @@ </method> </methods> <members> - <member name="axis_lock_angular_x" type="bool" setter="set_axis_lock" getter="get_axis_lock"> - </member> - <member name="axis_lock_angular_y" type="bool" setter="set_axis_lock" getter="get_axis_lock"> - </member> - <member name="axis_lock_angular_z" type="bool" setter="set_axis_lock" getter="get_axis_lock"> - </member> - <member name="axis_lock_linear_x" type="bool" setter="set_axis_lock" getter="get_axis_lock"> + <member name="collision/safe_margin" type="float" setter="set_safe_margin" getter="get_safe_margin"> + If the body is at least this close to another body, this body will consider them to be colliding. </member> - <member name="axis_lock_linear_y" type="bool" setter="set_axis_lock" getter="get_axis_lock"> + <member name="move_lock_x" type="bool" setter="set_axis_lock" getter="get_axis_lock"> </member> - <member name="axis_lock_linear_z" type="bool" setter="set_axis_lock" getter="get_axis_lock"> + <member name="move_lock_y" type="bool" setter="set_axis_lock" getter="get_axis_lock"> </member> - <member name="collision/safe_margin" type="float" setter="set_safe_margin" getter="get_safe_margin"> - If the body is at least this close to another body, this body will consider them to be colliding. + <member name="move_lock_z" type="bool" setter="set_axis_lock" getter="get_axis_lock"> </member> </members> <constants> diff --git a/doc/classes/KinematicBody2D.xml b/doc/classes/KinematicBody2D.xml index fdc974630f..e48660a889 100644 --- a/doc/classes/KinematicBody2D.xml +++ b/doc/classes/KinematicBody2D.xml @@ -81,7 +81,7 @@ </argument> <argument index="2" name="infinite_inertia" type="bool" default="true"> </argument> - <argument index="3" name="slope_stop_min_velocity" type="float" default="5"> + <argument index="3" name="stop_on_slope" type="bool" default="false"> </argument> <argument index="4" name="max_bounces" type="int" default="4"> </argument> @@ -91,7 +91,7 @@ Moves the body along a vector. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a [code]KinematicBody2D[/code] or [RigidBody2D], it will also be affected by the motion of the other body. You can use this to make moving or rotating platforms, or to make nodes push other nodes. [code]linear_velocity[/code] is a value in pixels per second. Unlike in for example [method move_and_collide], you should [i]not[/i] multiply it with [code]delta[/code] — this is done by the method. [code]floor_normal[/code] is the up direction, used to determine what is a wall and what is a floor or a ceiling. If set to the default value of [code]Vector2(0, 0)[/code], everything is considered a wall. This is useful for topdown games. - If the body is standing on a slope and the horizontal speed (relative to the floor's speed) goes below [code]slope_stop_min_velocity[/code], the body will stop completely. This prevents the body from sliding down slopes when you include gravity in [code]linear_velocity[/code]. When set to lower values, the body will not be able to stand still on steep slopes. + [i]TODO: Update for stop_on_slope argument.[/i] If the body is standing on a slope and the horizontal speed (relative to the floor's speed) goes below [code]slope_stop_min_velocity[/code], the body will stop completely. This prevents the body from sliding down slopes when you include gravity in [code]linear_velocity[/code]. When set to lower values, the body will not be able to stand still on steep slopes. If the body collides, it will change direction a maximum of [code]max_bounces[/code] times before it stops. [code]floor_max_angle[/code] is the maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall. The default value equals 45 degrees. Returns the movement that remained when the body stopped. To get more detailed information about collisions that occurred, use [method get_slide_collision]. @@ -108,13 +108,15 @@ </argument> <argument index="3" name="infinite_inertia" type="bool" default="true"> </argument> - <argument index="4" name="slope_stop_min_velocity" type="float" default="5"> + <argument index="4" name="stop_on_slope" type="bool" default="false"> </argument> <argument index="5" name="max_bounces" type="int" default="4"> </argument> <argument index="6" name="floor_max_angle" type="float" default="0.785398"> </argument> <description> + Moves the body while keeping it attached to slopes. Similar to [method move_and_slide]. + As long as the [code]snap[/code] vector is in contact with the ground, the body will remain attached to the surface. This means you must disable snap in order to jump, for example. You can do this by setting[code]snap[/code] to[code](0, 0)[/code] or by using [method move_and_slide] instead. </description> </method> <method name="test_move"> @@ -136,6 +138,7 @@ If the body is at least this close to another body, this body will consider them to be colliding. </member> <member name="motion/sync_to_physics" type="bool" setter="set_sync_to_physics" getter="is_sync_to_physics_enabled"> + If [code]true[/code] the body's movement will be synchronized to the physics frame. This is useful when animating movement via [AnimationPlayer], for example on moving platforms. </member> </members> <constants> diff --git a/doc/classes/Light.xml b/doc/classes/Light.xml index e9b36c2f9d..04191136a8 100644 --- a/doc/classes/Light.xml +++ b/doc/classes/Light.xml @@ -15,28 +15,40 @@ </methods> <members> <member name="editor_only" type="bool" setter="set_editor_only" getter="is_editor_only"> + If [code]true[/code] the light only appears in the editor and will not be visible at runtime. Default value:[code]false[/code]. </member> <member name="light_bake_mode" type="int" setter="set_bake_mode" getter="get_bake_mode" enum="Light.BakeMode"> + The light's bake mode. See [enum BakeMode]. </member> <member name="light_color" type="Color" setter="set_color" getter="get_color"> + The light's color. </member> <member name="light_cull_mask" type="int" setter="set_cull_mask" getter="get_cull_mask"> + The light will affect objects in the selected layers. </member> <member name="light_energy" type="float" setter="set_param" getter="get_param"> + The light's strength multiplier. </member> <member name="light_indirect_energy" type="float" setter="set_param" getter="get_param"> + Secondary multiplier used with indirect light (light bounces). This works in baked light or GIProbe. </member> <member name="light_negative" type="bool" setter="set_negative" getter="is_negative"> + If [code]true[/code] the light's effect is reversed, darkening areas and casting bright shadows. Default value: [code]false[/code]. </member> <member name="light_specular" type="float" setter="set_param" getter="get_param"> + The intensity of the specular blob in objects affected by the light. At [code]0[/code] the light becomes a pure diffuse light. </member> <member name="shadow_bias" type="float" setter="set_param" getter="get_param"> + Used to adjust shadow appearance. Too small a value results in self shadowing, while too large a value causes shadows to separate from casters. Adjust as needed. </member> <member name="shadow_color" type="Color" setter="set_shadow_color" getter="get_shadow_color"> + The color of shadows cast by this light. </member> <member name="shadow_contact" type="float" setter="set_param" getter="get_param"> + Attempts to reduce [member shadow_bias] gap. </member> <member name="shadow_enabled" type="bool" setter="set_shadow" getter="has_shadow"> + If [code]true[/code] the light will cast shadows. Default value: [code]false[/code]. </member> <member name="shadow_reverse_cull_face" type="bool" setter="set_shadow_reverse_cull_face" getter="get_shadow_reverse_cull_face"> </member> @@ -75,10 +87,13 @@ <constant name="PARAM_MAX" value="15" enum="Param"> </constant> <constant name="BAKE_DISABLED" value="0" enum="BakeMode"> + Light is ignored when baking. Note: hiding a light does [i]not[/i] affect baking. </constant> <constant name="BAKE_INDIRECT" value="1" enum="BakeMode"> + Only indirect lighting will be baked. Default value. </constant> <constant name="BAKE_ALL" value="2" enum="BakeMode"> + Both direct and indirect light will be baked. Note: you should hide the light if you don't want it to appear twice (dynamic and baked). </constant> </constants> </class> diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml index d7a0385bb3..c244b8b7a7 100644 --- a/doc/classes/LineEdit.xml +++ b/doc/classes/LineEdit.xml @@ -88,6 +88,8 @@ <member name="caret_position" type="int" setter="set_cursor_position" getter="get_cursor_position"> The cursor's position inside the [code]LineEdit[/code]. When set, the text may scroll to accommodate it. </member> + <member name="clear_button_enabled" type="bool" setter="set_clear_button_enabled" getter="is_clear_button_enabled"> + </member> <member name="context_menu_enabled" type="bool" setter="set_context_menu_enabled" getter="is_context_menu_enabled"> If [code]true[/code] the context menu will appear when right clicked. </member> @@ -172,6 +174,12 @@ </constant> </constants> <theme_items> + <theme_item name="clear" type="Texture"> + </theme_item> + <theme_item name="clear_button_color" type="Color"> + </theme_item> + <theme_item name="clear_button_color_pressed" type="Color"> + </theme_item> <theme_item name="cursor_color" type="Color"> </theme_item> <theme_item name="focus" type="StyleBox"> diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index bfef3c8588..d02e3dfdfa 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -38,6 +38,12 @@ Corresponds to the NOTIFICATION_EXIT_TREE notification in [method Object._notification] and signal [signal tree_exiting]. To get notified when the node has already left the active tree, connect to the [signal tree_exited] </description> </method> + <method name="_get_configuration_warning" qualifiers="virtual"> + <return type="String"> + </return> + <description> + </description> + </method> <method name="_input" qualifiers="virtual"> <return type="void"> </return> diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml index a830468042..f4ad196ad2 100644 --- a/doc/classes/Object.xml +++ b/doc/classes/Object.xml @@ -420,5 +420,7 @@ <constant name="CONNECT_ONESHOT" value="4" enum="ConnectFlags"> One shot connections disconnect themselves after emission. </constant> + <constant name="CONNECT_REFERENCE_COUNTED" value="8" enum="ConnectFlags"> + </constant> </constants> </class> diff --git a/doc/classes/OmniLight.xml b/doc/classes/OmniLight.xml index ff2e77ffbe..5ed058bb06 100644 --- a/doc/classes/OmniLight.xml +++ b/doc/classes/OmniLight.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="OmniLight" inherits="Light" category="Core" version="3.1"> <brief_description> - OmniDirectional Light, such as a light bulb or a candle. + Omnidirectional light, such as a light bulb or a candle. </brief_description> <description> - An OmniDirectional light is a type of [Light] node that emits lights in all directions. The light is attenuated through the distance and this attenuation can be configured by changing the energy, radius and attenuation parameters of [Light]. + An Omnidirectional light is a type of [Light] that emits light in all directions. The light is attenuated by distance and this attenuation can be configured by changing its energy, radius, and attenuation parameters. </description> <tutorials> <link>http://docs.godotengine.org/en/3.0/tutorials/3d/lights_and_shadows.html</link> @@ -15,12 +15,16 @@ </methods> <members> <member name="omni_attenuation" type="float" setter="set_param" getter="get_param"> + The light's attenuation (drop-off) curve. A number of presets are available in the Inspector. </member> <member name="omni_range" type="float" setter="set_param" getter="get_param"> + Maximum distance the light affects. </member> <member name="omni_shadow_detail" type="int" setter="set_shadow_detail" getter="get_shadow_detail" enum="OmniLight.ShadowDetail"> + See [enum ShadowDetail]. </member> <member name="omni_shadow_mode" type="int" setter="set_shadow_mode" getter="get_shadow_mode" enum="OmniLight.ShadowMode"> + See [enum ShadowMode]. </member> </members> <constants> diff --git a/doc/classes/PhysicalBone.xml b/doc/classes/PhysicalBone.xml index 99f551b865..5eb4550e93 100644 --- a/doc/classes/PhysicalBone.xml +++ b/doc/classes/PhysicalBone.xml @@ -9,6 +9,12 @@ <demos> </demos> <methods> + <method name="get_bone_id" qualifiers="const"> + <return type="int"> + </return> + <description> + </description> + </method> <method name="get_simulate_physics"> <return type="bool"> </return> diff --git a/doc/classes/PhysicsDirectBodyState.xml b/doc/classes/PhysicsDirectBodyState.xml index 5117c9ef6c..91fc4df4ff 100644 --- a/doc/classes/PhysicsDirectBodyState.xml +++ b/doc/classes/PhysicsDirectBodyState.xml @@ -121,7 +121,7 @@ <argument index="0" name="contact_idx" type="int"> </argument> <description> - Impulse created by the contact. Only implemented for Bullet physics. + Impulse created by the contact. Only implemented for Bullet physics. </description> </method> <method name="get_contact_local_normal" qualifiers="const"> diff --git a/doc/classes/PhysicsMaterial.xml b/doc/classes/PhysicsMaterial.xml index 5512c4605a..bfebb472a5 100644 --- a/doc/classes/PhysicsMaterial.xml +++ b/doc/classes/PhysicsMaterial.xml @@ -10,6 +10,16 @@ </demos> <methods> </methods> + <members> + <member name="absorbent" type="bool" setter="set_absorbent" getter="is_absorbent"> + </member> + <member name="bounce" type="float" setter="set_bounce" getter="get_bounce"> + </member> + <member name="friction" type="float" setter="set_friction" getter="get_friction"> + </member> + <member name="rough" type="bool" setter="set_rough" getter="is_rough"> + </member> + </members> <constants> </constants> </class> diff --git a/doc/classes/Plane.xml b/doc/classes/Plane.xml index 6f616401cb..62e4fc5d9d 100644 --- a/doc/classes/Plane.xml +++ b/doc/classes/Plane.xml @@ -157,5 +157,11 @@ </member> </members> <constants> + <constant name="X" value="Plane( 1, 0, 0, 0 )"> + </constant> + <constant name="Y" value="Plane( 0, 1, 0, 0 )"> + </constant> + <constant name="Z" value="Plane( 0, 0, 1, 0 )"> + </constant> </constants> </class> diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml index 0c8769714b..fe7dbe52b0 100644 --- a/doc/classes/PopupMenu.xml +++ b/doc/classes/PopupMenu.xml @@ -260,6 +260,12 @@ <description> </description> </method> + <method name="is_hide_on_window_lose_focus" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> <method name="is_item_checkable" qualifiers="const"> <return type="bool"> </return> @@ -322,6 +328,14 @@ Removes the item at index "idx" from the menu. Note that the indexes of items after the removed item are going to be shifted by one. </description> </method> + <method name="set_hide_on_window_lose_focus"> + <return type="void"> + </return> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + </description> + </method> <method name="set_item_accelerator"> <return type="void"> </return> diff --git a/doc/classes/ProgressBar.xml b/doc/classes/ProgressBar.xml index 919ecd7c86..0f03b7b80a 100644 --- a/doc/classes/ProgressBar.xml +++ b/doc/classes/ProgressBar.xml @@ -14,6 +14,7 @@ </methods> <members> <member name="percent_visible" type="bool" setter="set_percent_visible" getter="is_percent_visible"> + If [code]true[/code] the fill percentage is displayed on the bar. Default value: [code]true[/code]. </member> </members> <constants> diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index a4af5509a6..358b7292a5 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -224,6 +224,58 @@ </member> <member name="compression/formats/zstd/window_log_size" type="int" setter="" getter=""> </member> + <member name="debug/gdscript/warnings/constant_used_as_function" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/enable" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/function_conflicts_constant" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/function_conflicts_variable" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/function_may_yield" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/function_used_as_property" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/incompatible_ternary" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/integer_division" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/narrowing_conversion" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/property_used_as_function" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/return_value_discarded" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/standalone_expression" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/treat_warnings_as_errors" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unassigned_variable" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unassigned_variable_op_assign" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unreachable_code" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unsafe_call_argument" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unsafe_cast" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unsafe_method_access" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unsafe_property_access" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unused_argument" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unused_class_variable" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unused_signal" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/unused_variable" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/variable_conflicts_function" type="bool" setter="" getter=""> + </member> + <member name="debug/gdscript/warnings/void_assignment" type="bool" setter="" getter=""> + </member> <member name="debug/settings/crash_handler/message" type="String" setter="" getter=""> </member> <member name="debug/settings/fps/force_fps" type="int" setter="" getter=""> @@ -315,31 +367,31 @@ <member name="gui/timers/text_edit_idle_detect_sec" type="int" setter="" getter=""> Timer for detecting idle in the editor. </member> - <member name="input/ui_accept" type="Array" setter="" getter=""> + <member name="input/ui_accept" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_cancel" type="Array" setter="" getter=""> + <member name="input/ui_cancel" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_down" type="Array" setter="" getter=""> + <member name="input/ui_down" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_end" type="Array" setter="" getter=""> + <member name="input/ui_end" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_focus_next" type="Array" setter="" getter=""> + <member name="input/ui_focus_next" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_focus_prev" type="Array" setter="" getter=""> + <member name="input/ui_focus_prev" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_home" type="Array" setter="" getter=""> + <member name="input/ui_home" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_left" type="Array" setter="" getter=""> + <member name="input/ui_left" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_page_down" type="Array" setter="" getter=""> + <member name="input/ui_page_down" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_page_up" type="Array" setter="" getter=""> + <member name="input/ui_page_up" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_right" type="Array" setter="" getter=""> + <member name="input/ui_right" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_select" type="Array" setter="" getter=""> + <member name="input/ui_select" type="Dictionary" setter="" getter=""> </member> - <member name="input/ui_up" type="Array" setter="" getter=""> + <member name="input/ui_up" type="Dictionary" setter="" getter=""> </member> <member name="input_devices/pointing/emulate_mouse_from_touch" type="bool" setter="" getter=""> </member> diff --git a/doc/classes/Quat.xml b/doc/classes/Quat.xml index c755e6b02a..67631bbc92 100644 --- a/doc/classes/Quat.xml +++ b/doc/classes/Quat.xml @@ -188,5 +188,7 @@ </member> </members> <constants> + <constant name="IDENTITY" value="Quat( 0, 0, 0, 1 )"> + </constant> </constants> </class> diff --git a/doc/classes/Range.xml b/doc/classes/Range.xml index fa7e20eff6..46a6132b94 100644 --- a/doc/classes/Range.xml +++ b/doc/classes/Range.xml @@ -17,30 +17,32 @@ <argument index="0" name="with" type="Node"> </argument> <description> - Binds two Ranges together along with any Ranges previously grouped with either of them. When any of Range's member variables change, it will share the new value with all other Ranges in its group. + Binds two ranges together along with any ranges previously grouped with either of them. When any of range's member variables change, it will share the new value with all other ranges in its group. </description> </method> <method name="unshare"> <return type="void"> </return> <description> - Stop Range from sharing its member variables with any other Range. + Stop range from sharing its member variables with any other. </description> </method> </methods> <members> <member name="allow_greater" type="bool" setter="set_allow_greater" getter="is_greater_allowed"> + If [code]true[/code] [member value] may be greater than [member max_value]. Default value: [code]false[/code]. </member> <member name="allow_lesser" type="bool" setter="set_allow_lesser" getter="is_lesser_allowed"> + If [code]true[/code] [member value] may be less than [member min_value]. Default value: [code]false[/code]. </member> <member name="exp_edit" type="bool" setter="set_exp_ratio" getter="is_ratio_exp"> If [code]true[/code] and [code]min_value[/code] is greater than 0, [code]value[/code] will be represented exponentially rather than linearly. </member> <member name="max_value" type="float" setter="set_max" getter="get_max"> - Maximum value. Range is clamped if [code]value[/code] is greater than [code]max_value[/code]. Default value: 100. + Maximum value. Range is clamped if [code]value[/code] is greater than [code]max_value[/code]. Default value: [code]100[/code]. </member> <member name="min_value" type="float" setter="set_min" getter="get_min"> - Minimum value. Range is clamped if [code]value[/code] is less than [code]min_value[/code]. Default value: 0. + Minimum value. Range is clamped if [code]value[/code] is less than [code]min_value[/code]. Default value: [code]0[/code]. </member> <member name="page" type="float" setter="set_page" getter="get_page"> Page size. Used mainly for [ScrollBar]. ScrollBar's length is its size multiplied by [code]page[/code] over the difference between [code]min_value[/code] and [code]max_value[/code]. @@ -49,7 +51,7 @@ The value mapped between 0 and 1. </member> <member name="rounded" type="bool" setter="set_use_rounded_values" getter="is_using_rounded_values"> - If [code]true[/code], [code]value[/code] will always be rounded to the nearest integer. + If [code]true[/code] [code]value[/code] will always be rounded to the nearest integer. Default value: [code]false[/code]. </member> <member name="step" type="float" setter="set_step" getter="get_step"> If greater than 0, [code]value[/code] will always be rounded to a multiple of [code]step[/code]. If [code]rounded[/code] is also [code]true[/code], [code]value[/code] will first be rounded to a multiple of [code]step[/code] then rounded to the nearest integer. @@ -61,14 +63,14 @@ <signals> <signal name="changed"> <description> - This signal is emitted when min, max, range or step change. + Emitted when [member min_value], [member max_value], [member page], or [member step] change. </description> </signal> <signal name="value_changed"> <argument index="0" name="value" type="float"> </argument> <description> - This signal is emitted when value changes. + Emitted when [member value] changes. </description> </signal> </signals> diff --git a/doc/classes/ReferenceRect.xml b/doc/classes/ReferenceRect.xml index 4c6f014965..e1cb104e40 100644 --- a/doc/classes/ReferenceRect.xml +++ b/doc/classes/ReferenceRect.xml @@ -12,10 +12,10 @@ </demos> <methods> </methods> - <constants> - </constants> <members> <member name="border_color" type="Color" setter="set_border_color" getter="get_border_color"> </member> </members> + <constants> + </constants> </class> diff --git a/doc/classes/ResourceLoader.xml b/doc/classes/ResourceLoader.xml index ac00c13b2f..ae900e34ef 100644 --- a/doc/classes/ResourceLoader.xml +++ b/doc/classes/ResourceLoader.xml @@ -11,6 +11,16 @@ <demos> </demos> <methods> + <method name="exists"> + <return type="bool"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <argument index="1" name="type_hint" type="String" default=""""> + </argument> + <description> + </description> + </method> <method name="get_dependencies"> <return type="PoolStringArray"> </return> @@ -36,6 +46,14 @@ <description> </description> </method> + <method name="has_cached"> + <return type="bool"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> <method name="load"> <return type="Resource"> </return> diff --git a/doc/classes/Skeleton.xml b/doc/classes/Skeleton.xml index 4d826002fe..233df28255 100644 --- a/doc/classes/Skeleton.xml +++ b/doc/classes/Skeleton.xml @@ -196,6 +196,16 @@ <description> </description> </method> + <method name="set_bone_ignore_animation"> + <return type="void"> + </return> + <argument index="0" name="bone" type="int"> + </argument> + <argument index="1" name="ignore" type="bool"> + </argument> + <description> + </description> + </method> <method name="set_bone_parent"> <return type="void"> </return> diff --git a/doc/classes/Skeleton2D.xml b/doc/classes/Skeleton2D.xml index 654c816ba8..712b9ca2a5 100644 --- a/doc/classes/Skeleton2D.xml +++ b/doc/classes/Skeleton2D.xml @@ -12,7 +12,7 @@ <method name="get_bone"> <return type="Bone2D"> </return> - <argument index="0" name="arg0" type="int"> + <argument index="0" name="idx" type="int"> </argument> <description> </description> diff --git a/doc/classes/SkeletonIK.xml b/doc/classes/SkeletonIK.xml new file mode 100644 index 0000000000..50246f1b18 --- /dev/null +++ b/doc/classes/SkeletonIK.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="SkeletonIK" inherits="Node" category="Core" version="3.1"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_parent_skeleton" qualifiers="const"> + <return type="Skeleton"> + </return> + <description> + </description> + </method> + <method name="is_running"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="start"> + <return type="void"> + </return> + <argument index="0" name="one_time" type="bool" default="false"> + </argument> + <description> + </description> + </method> + <method name="stop"> + <return type="void"> + </return> + <description> + </description> + </method> + </methods> + <members> + <member name="interpolation" type="float" setter="set_interpolation" getter="get_interpolation"> + </member> + <member name="magnet" type="Vector3" setter="set_magnet_position" getter="get_magnet_position"> + </member> + <member name="max_iterations" type="int" setter="set_max_iterations" getter="get_max_iterations"> + </member> + <member name="min_distance" type="float" setter="set_min_distance" getter="get_min_distance"> + </member> + <member name="root_bone" type="String" setter="set_root_bone" getter="get_root_bone"> + </member> + <member name="target" type="Transform" setter="set_target_transform" getter="get_target_transform"> + </member> + <member name="target_node" type="NodePath" setter="set_target_node" getter="get_target_node"> + </member> + <member name="tip_bone" type="String" setter="set_tip_bone" getter="get_tip_bone"> + </member> + <member name="use_magnet" type="bool" setter="set_use_magnet" getter="is_using_magnet"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/doc/classes/SpringArm.xml b/doc/classes/SpringArm.xml new file mode 100644 index 0000000000..198ff4a81d --- /dev/null +++ b/doc/classes/SpringArm.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="SpringArm" inherits="Spatial" category="Core" version="3.1"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="add_excluded_object"> + <return type="void"> + </return> + <argument index="0" name="RID" type="RID"> + </argument> + <description> + </description> + </method> + <method name="clear_excluded_objects"> + <return type="void"> + </return> + <description> + </description> + </method> + <method name="get_hit_length"> + <return type="float"> + </return> + <description> + </description> + </method> + <method name="remove_excluded_object"> + <return type="bool"> + </return> + <argument index="0" name="RID" type="RID"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask"> + </member> + <member name="margin" type="float" setter="set_margin" getter="get_margin"> + </member> + <member name="shape" type="Shape" setter="set_shape" getter="get_shape"> + </member> + <member name="spring_length" type="float" setter="set_length" getter="get_length"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/doc/classes/Tabs.xml b/doc/classes/Tabs.xml index 0d5f1f0ba9..fc1d0476ed 100644 --- a/doc/classes/Tabs.xml +++ b/doc/classes/Tabs.xml @@ -35,6 +35,12 @@ <description> </description> </method> + <method name="get_select_with_rmb" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> <method name="get_tab_count" qualifiers="const"> <return type="int"> </return> @@ -105,6 +111,14 @@ <description> </description> </method> + <method name="set_select_with_rmb"> + <return type="void"> + </return> + <argument index="0" name="enabled" type="bool"> + </argument> + <description> + </description> + </method> <method name="set_tab_disabled"> <return type="void"> </return> diff --git a/doc/classes/Texture.xml b/doc/classes/Texture.xml index eb7cfac87b..a9be42d1a1 100644 --- a/doc/classes/Texture.xml +++ b/doc/classes/Texture.xml @@ -128,7 +128,7 @@ <constant name="FLAG_MIRRORED_REPEAT" value="32" enum="Flags"> Repeats texture with alternate sections mirrored. </constant> - <constant name="FLAG_VIDEO_SURFACE" value="4096" enum="Flags"> + <constant name="FLAG_VIDEO_SURFACE" value="2048" enum="Flags"> Texture is a video surface. </constant> </constants> diff --git a/doc/classes/Texture3D.xml b/doc/classes/Texture3D.xml new file mode 100644 index 0000000000..691d1f229e --- /dev/null +++ b/doc/classes/Texture3D.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="Texture3D" inherits="TextureLayered" category="Core" version="3.1"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/TextureArray.xml b/doc/classes/TextureArray.xml new file mode 100644 index 0000000000..a08d8421f1 --- /dev/null +++ b/doc/classes/TextureArray.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="TextureArray" inherits="TextureLayered" category="Core" version="3.1"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/doc/classes/TextureLayered.xml b/doc/classes/TextureLayered.xml new file mode 100644 index 0000000000..026144cf5a --- /dev/null +++ b/doc/classes/TextureLayered.xml @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="TextureLayered" inherits="Resource" category="Core" version="3.1"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="create"> + <return type="void"> + </return> + <argument index="0" name="width" type="int"> + </argument> + <argument index="1" name="height" type="int"> + </argument> + <argument index="2" name="depth" type="int"> + </argument> + <argument index="3" name="format" type="int" enum="Image.Format"> + </argument> + <argument index="4" name="flags" type="int" default="4"> + </argument> + <description> + </description> + </method> + <method name="get_depth" qualifiers="const"> + <return type="int"> + </return> + <description> + </description> + </method> + <method name="get_format" qualifiers="const"> + <return type="int" enum="Image.Format"> + </return> + <description> + </description> + </method> + <method name="get_height" qualifiers="const"> + <return type="int"> + </return> + <description> + </description> + </method> + <method name="get_layer_data" qualifiers="const"> + <return type="Image"> + </return> + <argument index="0" name="layer" type="int"> + </argument> + <description> + </description> + </method> + <method name="get_width" qualifiers="const"> + <return type="int"> + </return> + <description> + </description> + </method> + <method name="set_data_partial"> + <return type="void"> + </return> + <argument index="0" name="image" type="Image"> + </argument> + <argument index="1" name="x_offset" type="int"> + </argument> + <argument index="2" name="y_offset" type="int"> + </argument> + <argument index="3" name="layer" type="int"> + </argument> + <argument index="4" name="mipmap" type="int" default="0"> + </argument> + <description> + </description> + </method> + <method name="set_layer_data"> + <return type="void"> + </return> + <argument index="0" name="image" type="Image"> + </argument> + <argument index="1" name="layer" type="int"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="data" type="Dictionary" setter="_set_data" getter="_get_data"> + </member> + <member name="flags" type="int" setter="set_flags" getter="get_flags"> + </member> + </members> + <constants> + <constant name="FLAG_MIPMAPS" value="1" enum="Flags"> + </constant> + <constant name="FLAG_REPEAT" value="2" enum="Flags"> + </constant> + <constant name="FLAG_FILTER" value="4" enum="Flags"> + </constant> + <constant name="FLAGS_DEFAULT" value="4" enum="Flags"> + </constant> + </constants> +</class> diff --git a/doc/classes/TileSet.xml b/doc/classes/TileSet.xml index 7121bc8b9c..56bb33c5e1 100644 --- a/doc/classes/TileSet.xml +++ b/doc/classes/TileSet.xml @@ -58,7 +58,7 @@ <return type="void"> </return> <description> - Clear all tiles. + Clears all tiles. </description> </method> <method name="create_tile"> @@ -67,7 +67,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Create a new tile which will be referenced by the given ID. + Creates a new tile which will be referenced by the given ID. </description> </method> <method name="find_tile_by_name" qualifiers="const"> @@ -76,21 +76,21 @@ <argument index="0" name="name" type="String"> </argument> <description> - Find the first tile matching the given name. + Returns the first tile matching the given name. </description> </method> <method name="get_last_unused_tile_id" qualifiers="const"> <return type="int"> </return> <description> - Return the ID following the last currently used ID, useful when creating a new tile. + Returns the ID following the last currently used ID, useful when creating a new tile. </description> </method> <method name="get_tiles_ids" qualifiers="const"> <return type="Array"> </return> <description> - Return an array of all currently used tile IDs. + Returns an array of all currently used tile IDs. </description> </method> <method name="remove_tile"> @@ -99,7 +99,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Remove the tile referenced by the given ID. + Removes the tile referenced by the given ID. </description> </method> <method name="tile_add_shape"> @@ -124,7 +124,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the light occluder of the tile. + Returns the light occluder of the tile. </description> </method> <method name="tile_get_material" qualifiers="const"> @@ -133,7 +133,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the material of the tile. + Returns the material of the tile. </description> </method> <method name="tile_get_modulate" qualifiers="const"> @@ -150,7 +150,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the name of the tile. + Returns the name of the tile. </description> </method> <method name="tile_get_navigation_polygon" qualifiers="const"> @@ -159,7 +159,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the navigation polygon of the tile. + Returns the navigation polygon of the tile. </description> </method> <method name="tile_get_navigation_polygon_offset" qualifiers="const"> @@ -168,7 +168,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the offset of the tile's navigation polygon. + Returns the offset of the tile's navigation polygon. </description> </method> <method name="tile_get_normal_map" qualifiers="const"> @@ -185,7 +185,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the offset of the tile's light occluder. + Returns the offset of the tile's light occluder. </description> </method> <method name="tile_get_region" qualifiers="const"> @@ -194,7 +194,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the tile sub-region in the texture. + Returns the tile sub-region in the texture. </description> </method> <method name="tile_get_shape" qualifiers="const"> @@ -241,7 +241,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the array of shapes of the tile. + Returns the array of shapes of the tile. </description> </method> <method name="tile_get_texture" qualifiers="const"> @@ -250,7 +250,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the texture of the tile. + Returns the texture of the tile. </description> </method> <method name="tile_get_texture_offset" qualifiers="const"> @@ -259,7 +259,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the texture offset of the tile. + Returns the texture offset of the tile. </description> </method> <method name="tile_get_tile_mode" qualifiers="const"> @@ -286,7 +286,7 @@ <argument index="1" name="light_occluder" type="OccluderPolygon2D"> </argument> <description> - Set a light occluder for the tile. + Sets a light occluder for the tile. </description> </method> <method name="tile_set_material"> @@ -297,7 +297,7 @@ <argument index="1" name="material" type="ShaderMaterial"> </argument> <description> - Set the material of the tile. + Sets the tile's material. </description> </method> <method name="tile_set_modulate"> @@ -308,6 +308,7 @@ <argument index="1" name="color" type="Color"> </argument> <description> + Sets the tile's modulation color. </description> </method> <method name="tile_set_name"> @@ -318,7 +319,7 @@ <argument index="1" name="name" type="String"> </argument> <description> - Set the name of the tile, for descriptive purposes. + Sets the tile's name. </description> </method> <method name="tile_set_navigation_polygon"> @@ -329,7 +330,7 @@ <argument index="1" name="navigation_polygon" type="NavigationPolygon"> </argument> <description> - Set a navigation polygon for the tile. + Sets the tile's navigation polygon. </description> </method> <method name="tile_set_navigation_polygon_offset"> @@ -340,7 +341,7 @@ <argument index="1" name="navigation_polygon_offset" type="Vector2"> </argument> <description> - Set an offset for the tile's navigation polygon. + Sets an offset for the tile's navigation polygon. </description> </method> <method name="tile_set_normal_map"> @@ -351,6 +352,7 @@ <argument index="1" name="normal_map" type="Texture"> </argument> <description> + Sets the tile's normal map texture. </description> </method> <method name="tile_set_occluder_offset"> @@ -372,7 +374,7 @@ <argument index="1" name="region" type="Rect2"> </argument> <description> - Set the tile sub-region in the texture. This is common in texture atlases. + Set the tile's sub-region in the texture. This is common in texture atlases. </description> </method> <method name="tile_set_shape"> @@ -419,7 +421,7 @@ <argument index="1" name="shapes" type="Array"> </argument> <description> - Set an array of shapes for the tile, enabling physics to collide with it. + Sets an array of shapes for the tile, enabling collision. </description> </method> <method name="tile_set_texture"> @@ -430,7 +432,7 @@ <argument index="1" name="texture" type="Texture"> </argument> <description> - Set the texture of the tile. + Sets the tile's texture. </description> </method> <method name="tile_set_texture_offset"> @@ -441,7 +443,7 @@ <argument index="1" name="texture_offset" type="Vector2"> </argument> <description> - Set the texture offset of the tile. + Sets the tile's texture offset. </description> </method> <method name="tile_set_tile_mode"> @@ -452,6 +454,7 @@ <argument index="1" name="tilemode" type="int" enum="TileSet.TileMode"> </argument> <description> + Sets the tile's [enum TileMode]. </description> </method> <method name="tile_set_z_index"> @@ -462,6 +465,7 @@ <argument index="1" name="z_index" type="int"> </argument> <description> + Sets the tile's drawing index. </description> </method> </methods> @@ -492,7 +496,7 @@ </constant> <constant name="AUTO_TILE" value="1" enum="TileMode"> </constant> - <constant name="ANIMATED_TILE" value="2" enum="TileMode"> + <constant name="ATLAS_TILE" value="2" enum="TileMode"> </constant> </constants> </class> diff --git a/doc/classes/Transform.xml b/doc/classes/Transform.xml index 0dd8038b36..24c009d922 100644 --- a/doc/classes/Transform.xml +++ b/doc/classes/Transform.xml @@ -168,5 +168,13 @@ </member> </members> <constants> + <constant name="IDENTITY" value="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )"> + </constant> + <constant name="FLIP_X" value="Transform( -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )"> + </constant> + <constant name="FLIP_Y" value="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )"> + </constant> + <constant name="FLIP_Z" value="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )"> + </constant> </constants> </class> diff --git a/doc/classes/Transform2D.xml b/doc/classes/Transform2D.xml index d5427ad7f8..b38d9a1a86 100644 --- a/doc/classes/Transform2D.xml +++ b/doc/classes/Transform2D.xml @@ -173,5 +173,11 @@ </member> </members> <constants> + <constant name="IDENTITY" value="Transform2D( 1, 0, 0, 1, 0, 0 )"> + </constant> + <constant name="FLIP_X" value="Transform2D( -1, 0, 0, 1, 0, 0 )"> + </constant> + <constant name="FLIP_Y" value="Transform2D( 1, 0, 0, -1, 0, 0 )"> + </constant> </constants> </class> diff --git a/doc/classes/Vector2.xml b/doc/classes/Vector2.xml index 9b18962a6f..4bc18b926e 100644 --- a/doc/classes/Vector2.xml +++ b/doc/classes/Vector2.xml @@ -130,15 +130,6 @@ Returns the distance to vector [code]b[/code]. </description> </method> - <method name="project"> - <return type="Vector2"> - </return> - <argument index="0" name="b" type="Vector2"> - </argument> - <description> - Returns the vector projected onto the vector [code]b[/code]. - </description> - </method> <method name="dot"> <return type="float"> </return> @@ -194,6 +185,15 @@ Returns the vector scaled to unit length. Equivalent to [code]v / v.length()[/code]. </description> </method> + <method name="project"> + <return type="Vector2"> + </return> + <argument index="0" name="b" type="Vector2"> + </argument> + <description> + Returns the vector projected onto the vector [code]b[/code]. + </description> + </method> <method name="reflect"> <return type="Vector2"> </return> @@ -266,5 +266,17 @@ </member> </members> <constants> + <constant name="ZERO" value="Vector2( 0, 0 )"> + </constant> + <constant name="INF" value="Vector2( inf, inf )"> + </constant> + <constant name="LEFT" value="Vector2( -1, 0 )"> + </constant> + <constant name="RIGHT" value="Vector2( 1, 0 )"> + </constant> + <constant name="UP" value="Vector2( 0, -1 )"> + </constant> + <constant name="DOWN" value="Vector2( 0, 1 )"> + </constant> </constants> </class> diff --git a/doc/classes/Vector3.xml b/doc/classes/Vector3.xml index 22384c5012..b4dcc6c6aa 100644 --- a/doc/classes/Vector3.xml +++ b/doc/classes/Vector3.xml @@ -99,15 +99,6 @@ Returns the distance to [code]b[/code]. </description> </method> - <method name="project_onto"> - <return type="Vector3"> - </return> - <argument index="0" name="b" type="Vector3"> - </argument> - <description> - Returns the vector projected onto the vector [code]b[/code]. - </description> - </method> <method name="dot"> <return type="float"> </return> @@ -193,6 +184,15 @@ Returns the outer product with [code]b[/code]. </description> </method> + <method name="project"> + <return type="Vector3"> + </return> + <argument index="0" name="b" type="Vector3"> + </argument> + <description> + Returns the vector projected onto the vector [code]b[/code]. + </description> + </method> <method name="reflect"> <return type="Vector3"> </return> @@ -279,5 +279,21 @@ <constant name="AXIS_Z" value="2"> Enumerated value for the Z axis. </constant> + <constant name="ZERO" value="Vector3( 0, 0, 0 )"> + </constant> + <constant name="INF" value="Vector3( inf, inf, inf )"> + </constant> + <constant name="LEFT" value="Vector3( -1, 0, 0 )"> + </constant> + <constant name="RIGHT" value="Vector3( 1, 0, 0 )"> + </constant> + <constant name="UP" value="Vector3( 0, 1, 0 )"> + </constant> + <constant name="DOWN" value="Vector3( 0, -1, 0 )"> + </constant> + <constant name="FORWARD" value="Vector3( 0, 0, -1 )"> + </constant> + <constant name="BACK" value="Vector3( 0, 0, 1 )"> + </constant> </constants> </class> diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index af0712d357..05649193a6 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -22,35 +22,35 @@ <return type="World"> </return> <description> - Return the 3D world of the viewport, or if no such present, the one of the parent viewport. + Returns the 3D world of the viewport, or if none the world of the parent viewport. </description> </method> <method name="find_world_2d" qualifiers="const"> <return type="World2D"> </return> <description> - Return the 2D world of the viewport. + Returns the 2D world of the viewport. </description> </method> <method name="get_camera" qualifiers="const"> <return type="Camera"> </return> <description> - Return the active 3D camera. + Returns the active 3D camera. </description> </method> <method name="get_final_transform" qualifiers="const"> <return type="Transform2D"> </return> <description> - Get the total transform of the viewport. + Returns the total transform of the viewport. </description> </method> <method name="get_mouse_position" qualifiers="const"> <return type="Vector2"> </return> <description> - Get the mouse position, relative to the viewport. + Returns the mouse position relative to the viewport. </description> </method> <method name="get_render_info"> @@ -59,35 +59,35 @@ <argument index="0" name="info" type="int" enum="Viewport.RenderInfo"> </argument> <description> - Get the specific information about the viewport from rendering pipeline. + Returns information about the viewport from the rendering pipeline. </description> </method> <method name="get_size_override" qualifiers="const"> <return type="Vector2"> </return> <description> - Get the size override set with [method set_size_override]. + Returns the size override set with [method set_size_override]. </description> </method> <method name="get_texture" qualifiers="const"> <return type="ViewportTexture"> </return> <description> - Get the viewport's texture, for use with various objects that you want to texture with the viewport. + Returns the viewport's texture. </description> </method> <method name="get_viewport_rid" qualifiers="const"> <return type="RID"> </return> <description> - Get the viewport RID from the [VisualServer]. + Returns the viewport's RID from the [VisualServer]. </description> </method> <method name="get_visible_rect" qualifiers="const"> <return type="Rect2"> </return> <description> - Return the final, visible rect in global screen coordinates. + Returns the visible rectangle in global screen coordinates. </description> </method> <method name="gui_get_drag_data" qualifiers="const"> @@ -101,7 +101,7 @@ <return type="bool"> </return> <description> - Returns whether there are shown modals on-screen. + Returns [code]true[/code] if there are visible modals on-screen. </description> </method> <method name="input"> @@ -116,14 +116,14 @@ <return type="bool"> </return> <description> - Get the enabled status of the size override set with [method set_size_override]. + Returns [code]true[/code] if the size override is enabled. See [method set_size_override]. </description> </method> <method name="is_size_override_stretch_enabled" qualifiers="const"> <return type="bool"> </return> <description> - Get the enabled status of the size stretch override set with [method set_size_override_stretch]. + Returns [code]true[/code] if the size stretch override is enabled. See [method set_size_override_stretch]. </description> </method> <method name="set_attach_to_screen_rect"> @@ -144,7 +144,7 @@ <argument index="2" name="margin" type="Vector2" default="Vector2( 0, 0 )"> </argument> <description> - Set the size override of the viewport. If the enable parameter is true, it would use the override, otherwise it would use the default size. If the size parameter is equal to [code](-1, -1)[/code], it won't update the size. + Sets the size override of the viewport. If the [code]enable[/code] parameter is [code]true[/code] the override is used, otherwise it uses the default size. If the size parameter is [code](-1, -1)[/code], it won't update the size. </description> </method> <method name="set_size_override_stretch"> @@ -153,7 +153,7 @@ <argument index="0" name="enabled" type="bool"> </argument> <description> - Set whether the size override affects stretch as well. + If [code]true[/code] the size override affects stretch as well. </description> </method> <method name="unhandled_input"> @@ -168,7 +168,7 @@ <return type="void"> </return> <description> - Force update of the 2D and 3D worlds. + Forces update of the 2D and 3D worlds. </description> </method> <method name="warp_mouse"> @@ -177,7 +177,7 @@ <argument index="0" name="to_position" type="Vector2"> </argument> <description> - Warp the mouse to a position, relative to the viewport. + Warps the mouse to a position relative to the viewport. </description> </method> </methods> diff --git a/doc/classes/VisualInstance.xml b/doc/classes/VisualInstance.xml index 502209fac5..30dedb06f4 100644 --- a/doc/classes/VisualInstance.xml +++ b/doc/classes/VisualInstance.xml @@ -16,6 +16,14 @@ Returns the [AABB] (also known as the bounding box) for this VisualInstance. </description> </method> + <method name="get_layer_mask_bit" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="layer" type="int"> + </argument> + <description> + </description> + </method> <method name="get_transformed_aabb" qualifiers="const"> <return type="AABB"> </return> @@ -34,6 +42,16 @@ It is recommended to only use set_base if you know what you're doing. </description> </method> + <method name="set_layer_mask_bit"> + <return type="void"> + </return> + <argument index="0" name="layer" type="int"> + </argument> + <argument index="1" name="enabled" type="bool"> + </argument> + <description> + </description> + </method> </methods> <members> <member name="layers" type="int" setter="set_layer_mask" getter="get_layer_mask"> diff --git a/doc/classes/VisualServer.xml b/doc/classes/VisualServer.xml index c4ebf7c96f..395fb9e829 100644 --- a/doc/classes/VisualServer.xml +++ b/doc/classes/VisualServer.xml @@ -1336,7 +1336,7 @@ <method name="gi_probe_get_bias" qualifiers="const"> <return type="float"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> <description> </description> @@ -1360,7 +1360,7 @@ <method name="gi_probe_get_dynamic_data" qualifiers="const"> <return type="PoolIntArray"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> <description> </description> @@ -1368,7 +1368,7 @@ <method name="gi_probe_get_dynamic_range" qualifiers="const"> <return type="int"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> <description> </description> @@ -1376,7 +1376,7 @@ <method name="gi_probe_get_energy" qualifiers="const"> <return type="float"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> <description> </description> @@ -1384,7 +1384,7 @@ <method name="gi_probe_get_normal_bias" qualifiers="const"> <return type="float"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> <description> </description> @@ -1392,7 +1392,7 @@ <method name="gi_probe_get_propagation" qualifiers="const"> <return type="float"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> <description> </description> @@ -1400,7 +1400,7 @@ <method name="gi_probe_get_to_cell_xform" qualifiers="const"> <return type="Transform"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> <description> </description> @@ -1408,7 +1408,7 @@ <method name="gi_probe_is_compressed" qualifiers="const"> <return type="bool"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> <description> </description> @@ -1416,7 +1416,7 @@ <method name="gi_probe_is_interior" qualifiers="const"> <return type="bool"> </return> - <argument index="0" name="arg0" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> <description> </description> @@ -1424,9 +1424,9 @@ <method name="gi_probe_set_bias"> <return type="void"> </return> - <argument index="0" name="bias" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> - <argument index="1" name="arg1" type="float"> + <argument index="1" name="bias" type="float"> </argument> <description> </description> @@ -1454,9 +1454,9 @@ <method name="gi_probe_set_compress"> <return type="void"> </return> - <argument index="0" name="enable" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> - <argument index="1" name="arg1" type="bool"> + <argument index="1" name="enable" type="bool"> </argument> <description> </description> @@ -1464,9 +1464,9 @@ <method name="gi_probe_set_dynamic_data"> <return type="void"> </return> - <argument index="0" name="data" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> - <argument index="1" name="arg1" type="PoolIntArray"> + <argument index="1" name="data" type="PoolIntArray"> </argument> <description> </description> @@ -1474,9 +1474,9 @@ <method name="gi_probe_set_dynamic_range"> <return type="void"> </return> - <argument index="0" name="range" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> - <argument index="1" name="arg1" type="int"> + <argument index="1" name="range" type="int"> </argument> <description> </description> @@ -1484,9 +1484,9 @@ <method name="gi_probe_set_energy"> <return type="void"> </return> - <argument index="0" name="energy" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> - <argument index="1" name="arg1" type="float"> + <argument index="1" name="energy" type="float"> </argument> <description> </description> @@ -1494,9 +1494,9 @@ <method name="gi_probe_set_interior"> <return type="void"> </return> - <argument index="0" name="enable" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> - <argument index="1" name="arg1" type="bool"> + <argument index="1" name="enable" type="bool"> </argument> <description> </description> @@ -1504,9 +1504,9 @@ <method name="gi_probe_set_normal_bias"> <return type="void"> </return> - <argument index="0" name="bias" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> - <argument index="1" name="arg1" type="float"> + <argument index="1" name="bias" type="float"> </argument> <description> </description> @@ -1514,9 +1514,9 @@ <method name="gi_probe_set_propagation"> <return type="void"> </return> - <argument index="0" name="propagation" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> - <argument index="1" name="arg1" type="float"> + <argument index="1" name="propagation" type="float"> </argument> <description> </description> @@ -1524,9 +1524,9 @@ <method name="gi_probe_set_to_cell_xform"> <return type="void"> </return> - <argument index="0" name="xform" type="RID"> + <argument index="0" name="probe" type="RID"> </argument> - <argument index="1" name="arg1" type="Transform"> + <argument index="1" name="xform" type="Transform"> </argument> <description> </description> @@ -3300,12 +3300,15 @@ </argument> <argument index="2" name="height" type="int"> </argument> - <argument index="3" name="format" type="int" enum="Image.Format"> + <argument index="3" name="depth_3d" type="int"> </argument> - <argument index="4" name="flags" type="int" default="7"> + <argument index="4" name="format" type="int" enum="Image.Format"> + </argument> + <argument index="5" name="type" type="int" enum="VisualServer.TextureType"> + </argument> + <argument index="6" name="flags" type="int" default="7"> </argument> <description> - Allocates space for a texture's image or video. </description> </method> <method name="texture_create"> @@ -3338,12 +3341,20 @@ </return> <argument index="0" name="texture" type="RID"> </argument> - <argument index="1" name="cube_side" type="int" enum="VisualServer.CubeMapSide" default="0"> + <argument index="1" name="cube_side" type="int" default="0"> </argument> <description> Returns a copy of a texture's image unless it's a CubeMap, in which case it returns the [RID] of the image at one of the cubes sides. </description> </method> + <method name="texture_get_depth" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <description> + </description> + </method> <method name="texture_get_flags" qualifiers="const"> <return type="int"> </return> @@ -3389,6 +3400,14 @@ Returns the opengl id of the texture's image. </description> </method> + <method name="texture_get_type" qualifiers="const"> + <return type="int" enum="VisualServer.TextureType"> + </return> + <argument index="0" name="texture" type="RID"> + </argument> + <description> + </description> + </method> <method name="texture_get_width" qualifiers="const"> <return type="int"> </return> @@ -3405,7 +3424,7 @@ </argument> <argument index="1" name="image" type="Image"> </argument> - <argument index="2" name="cube_side" type="int" enum="VisualServer.CubeMapSide" default="0"> + <argument index="2" name="layer" type="int" default="0"> </argument> <description> Sets the texture's image data. If it's a CubeMap, it sets the image data at a cube side. @@ -3432,7 +3451,7 @@ </argument> <argument index="8" name="dst_mip" type="int"> </argument> - <argument index="9" name="cube_side" type="int" enum="VisualServer.CubeMapSide" default="0"> + <argument index="9" name="layer" type="int" default="0"> </argument> <description> </description> @@ -3477,8 +3496,9 @@ </argument> <argument index="2" name="height" type="int"> </argument> + <argument index="3" name="depth" type="int"> + </argument> <description> - Overwrites the texture's width and height. </description> </method> <method name="textures_keep_original"> @@ -3873,6 +3893,14 @@ <constant name="CUBEMAP_BACK" value="5" enum="CubeMapSide"> Marks the back side of a cubemap. </constant> + <constant name="TEXTURE_TYPE_2D" value="0" enum="TextureType"> + </constant> + <constant name="TEXTURE_TYPE_CUBEMAP" value="1" enum="TextureType"> + </constant> + <constant name="TEXTURE_TYPE_2D_ARRAY" value="2" enum="TextureType"> + </constant> + <constant name="TEXTURE_TYPE_3D" value="3" enum="TextureType"> + </constant> <constant name="TEXTURE_FLAG_MIPMAPS" value="1" enum="TextureFlags"> Generate mipmaps, which are smaller versions of the same texture to use when zoomed out, keeping the aspect ratio. </constant> @@ -3892,10 +3920,7 @@ <constant name="TEXTURE_FLAG_MIRRORED_REPEAT" value="32" enum="TextureFlags"> Repeat texture with alternate sections mirrored. </constant> - <constant name="TEXTURE_FLAG_CUBEMAP" value="2048" enum="TextureFlags"> - Texture is a cubemap. - </constant> - <constant name="TEXTURE_FLAG_USED_FOR_STREAMING" value="4096" enum="TextureFlags"> + <constant name="TEXTURE_FLAG_USED_FOR_STREAMING" value="2048" enum="TextureFlags"> Texture is a video surface. </constant> <constant name="TEXTURE_FLAGS_DEFAULT" value="7" enum="TextureFlags"> @@ -4208,7 +4233,7 @@ </constant> <constant name="INSTANCE_FLAG_USE_BAKED_LIGHT" value="0" enum="InstanceFlags"> </constant> - <constant name="INSTANCE_FLAG_REDRAW_FRAME_IF_VISIBLE" value="1" enum="InstanceFlags"> + <constant name="INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE" value="1" enum="InstanceFlags"> </constant> <constant name="INSTANCE_FLAG_MAX" value="2" enum="InstanceFlags"> </constant> diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 6ff6bd7ced..e2d8ec1178 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -61,11 +61,12 @@ void RasterizerStorageGLES2::bind_quad_array() const { glEnableVertexAttribArray(VS::ARRAY_TEX_UV); } -Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed) { +Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed) const { r_gl_format = 0; Ref<Image> image = p_image; r_compressed = false; + r_real_format = p_format; bool need_decompress = false; @@ -317,6 +318,7 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_ r_gl_format = GL_RGBA; r_gl_internal_format = GL_RGBA; r_gl_type = GL_UNSIGNED_BYTE; + r_real_format = Image::FORMAT_RGBA8; return image; } @@ -384,7 +386,8 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_ } break; } - _get_gl_image_and_format(Ref<Image>(), texture->format, texture->flags, format, internal_format, type, compressed); + Image::Format real_format; + _get_gl_image_and_format(Ref<Image>(), texture->format, texture->flags, real_format, format, internal_format, type, compressed); texture->alloc_width = texture->width; texture->alloc_height = texture->height; @@ -426,7 +429,8 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p texture->images.write[p_layer] = p_image; } - Ref<Image> img = _get_gl_image_and_format(p_image, p_image->get_format(), texture->flags, format, internal_format, type, compressed); + Image::Format real_format; + Ref<Image> img = _get_gl_image_and_format(p_image, p_image->get_format(), texture->flags, real_format, format, internal_format, type, compressed); if (config.shrink_textures_x2 && (p_image->has_mipmaps() || !p_image->is_compressed()) && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) { @@ -570,11 +574,19 @@ Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer) if (texture->type == VS::TEXTURE_TYPE_CUBEMAP && p_layer < 6 && p_layer >= 0 && !texture->images[p_layer].is_null()) { return texture->images[p_layer]; } + #ifdef GLES_OVER_GL + Image::Format real_format; + GLenum gl_format; + GLenum gl_internal_format; + GLenum gl_type; + bool compressed; + _get_gl_image_and_format(Ref<Image>(), texture->format, texture->flags, real_format, gl_format, gl_internal_format, gl_type, compressed); + PoolVector<uint8_t> data; - int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, texture->format, texture->mipmaps > 1 ? -1 : 0); + int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, texture->mipmaps > 1 ? -1 : 0); data.resize(data_size * 2); //add some memory at the end, just in case for buggy drivers PoolVector<uint8_t>::Write wb = data.write(); @@ -591,7 +603,7 @@ Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer) int ofs = 0; if (i > 0) { - ofs = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, texture->format, i - 1); + ofs = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, i - 1); } if (texture->compressed) { @@ -607,7 +619,7 @@ Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer) data.resize(data_size); - Image *img = memnew(Image(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, texture->format, data)); + Image *img = memnew(Image(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, real_format, data)); return Ref<Image>(img); #else diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index c1fbf73254..88783d7160 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -325,7 +325,7 @@ public: mutable RID_Owner<Texture> texture_owner; - Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed); + Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed) const; virtual RID texture_create(); virtual void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, VS::TextureType p_type, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index a5c81d6c4d..3697cccef4 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -118,10 +118,11 @@ void glTexStorage2DCustom(GLenum target, GLsizei levels, GLenum internalformat, GLuint RasterizerStorageGLES3::system_fbo = 0; -Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb) { +Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb) const { r_compressed = false; r_gl_format = 0; + r_real_format = p_format; Ref<Image> image = p_image; srgb = false; @@ -565,6 +566,7 @@ Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_ r_gl_internal_format = (config.srgb_decode_supported || (p_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) ? GL_SRGB8_ALPHA8 : GL_RGBA8; r_gl_type = GL_UNSIGNED_BYTE; r_compressed = false; + r_real_format = Image::FORMAT_RGBA8; srgb = true; return image; @@ -638,7 +640,8 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_ } break; } - _get_gl_image_and_format(Ref<Image>(), texture->format, texture->flags, format, internal_format, type, compressed, srgb); + Image::Format real_format; + _get_gl_image_and_format(Ref<Image>(), texture->format, texture->flags, real_format, format, internal_format, type, compressed, srgb); texture->alloc_width = texture->width; texture->alloc_height = texture->height; @@ -710,7 +713,8 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref<Image> &p texture->images.write[p_layer] = p_image; } - Ref<Image> img = _get_gl_image_and_format(p_image, p_image->get_format(), texture->flags, format, internal_format, type, compressed, srgb); + Image::Format real_format; + Ref<Image> img = _get_gl_image_and_format(p_image, p_image->get_format(), texture->flags, real_format, format, internal_format, type, compressed, srgb); if (config.shrink_textures_x2 && (p_image->has_mipmaps() || !p_image->is_compressed()) && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) { @@ -941,7 +945,8 @@ void RasterizerStorageGLES3::texture_set_data_partial(RID p_texture, const Ref<I p_sub_img = p_image->get_rect(Rect2(src_x, src_y, src_w, src_h)); } - Ref<Image> img = _get_gl_image_and_format(p_sub_img, p_sub_img->get_format(), texture->flags, format, internal_format, type, compressed, srgb); + Image::Format real_format; + Ref<Image> img = _get_gl_image_and_format(p_sub_img, p_sub_img->get_format(), texture->flags, real_format, format, internal_format, type, compressed, srgb); GLenum blit_target; @@ -1014,9 +1019,17 @@ Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer) #ifdef GLES_OVER_GL + Image::Format real_format; + GLenum gl_format; + GLenum gl_internal_format; + GLenum gl_type; + bool compressed; + bool srgb; + _get_gl_image_and_format(Ref<Image>(), texture->format, texture->flags, real_format, gl_format, gl_internal_format, gl_type, compressed, srgb); + PoolVector<uint8_t> data; - int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, texture->format, texture->mipmaps > 1 ? -1 : 0); + int data_size = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, texture->mipmaps > 1 ? -1 : 0); data.resize(data_size * 2); //add some memory at the end, just in case for buggy drivers PoolVector<uint8_t>::Write wb = data.write(); @@ -1033,7 +1046,7 @@ Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer) int ofs = 0; if (i > 0) { - ofs = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, texture->format, i - 1); + ofs = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, i - 1); } if (texture->compressed) { @@ -1069,7 +1082,7 @@ Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer) (a | a << 2 | a << 4 | a << 6) << 24; } } else { - img_format = texture->format; + img_format = real_format; } wb = PoolVector<uint8_t>::Write(); @@ -7368,6 +7381,9 @@ bool RasterizerStorageGLES3::free(RID p_rid) { bool RasterizerStorageGLES3::has_os_feature(const String &p_feature) const { + if (p_feature == "bptc") + return config.bptc_supported; + if (p_feature == "s3tc") return config.s3tc_supported; diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index f55c8026ea..b74dd77e26 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -340,7 +340,7 @@ public: mutable RID_Owner<Texture> texture_owner; - Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb); + Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb) const; virtual RID texture_create(); virtual void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, VS::TextureType p_type, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT); diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 05dfd69f58..8aab4cb521 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -329,7 +329,7 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo return OK; } -Error OS_Unix::kill(const ProcessID &p_pid) { +Error OS_Unix::kill(const ProcessID &p_pid, const int p_max_wait_msec) { int ret = ::kill(p_pid, SIGKILL); if (!ret) { diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 95b74d23ff..c5240231fa 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -91,7 +91,7 @@ public: virtual uint64_t get_ticks_usec() const; virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false); - virtual Error kill(const ProcessID &p_pid); + virtual Error kill(const ProcessID &p_pid, const int p_max_wait_msec = -1); virtual int get_process_id() const; virtual bool has_environment(const String &p_var) const; diff --git a/editor/audio_stream_preview.cpp b/editor/audio_stream_preview.cpp index 6ae5ec43a9..6e6a7d7935 100644 --- a/editor/audio_stream_preview.cpp +++ b/editor/audio_stream_preview.cpp @@ -169,7 +169,8 @@ Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref< preview->preview->preview = maxmin; preview->preview->length = len_s; - preview->thread = Thread::create(_preview_thread, preview); + if (preview->playback.is_valid()) + preview->thread = Thread::create(_preview_thread, preview); return preview->preview; } diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 5c911a00ca..721158cebb 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -661,6 +661,21 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & List<String> remaps; config->get_section_keys("remap", &remaps); + Set<String> remap_features; + + for (List<String>::Element *F = remaps.front(); F; F = F->next()) { + + String remap = F->get(); + String feature = remap.get_slice(".", 1); + if (feature == "fallback" || features.has(feature)) { + remap_features.insert(feature); + } + } + + if (remap_features.size() > 1) { + this->resolve_platform_feature_priorities(p_preset, remap_features); + } + for (List<String>::Element *F = remaps.front(); F; F = F->next()) { String remap = F->get(); @@ -670,7 +685,8 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & p_func(p_udata, remapped_path, array, idx, total); } else if (remap.begins_with("path.")) { String feature = remap.get_slice(".", 1); - if (features.has(feature)) { + + if (remap_features.has(feature)) { String remapped_path = config->get_value("remap", remap); Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path); p_func(p_udata, remapped_path, array, idx, total); @@ -1249,9 +1265,11 @@ void EditorExportPlatformPC::get_preset_features(const Ref<EditorExportPreset> & void EditorExportPlatformPC::get_export_options(List<ExportOption> *r_options) { + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/bptc"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/no_bptc_fallbacks"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "binary_format/64_bits"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE), "")); @@ -1434,6 +1452,16 @@ void EditorExportPlatformPC::get_platform_features(List<String> *r_features) { } } +void EditorExportPlatformPC::resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) { + + if (p_features.has("bptc")) { + if (p_preset->has("texture_format/no_bptc_fallbacks")) { + p_features.erase("s3tc"); + p_features.erase("fallback"); + } + } +} + int EditorExportPlatformPC::get_chmod_flags() const { return chmod_flags; diff --git a/editor/editor_export.h b/editor/editor_export.h index 1d0b89cf16..b984d66a1b 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -246,6 +246,7 @@ public: virtual Error export_pack(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0); virtual Error export_zip(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0); virtual void get_platform_features(List<String> *r_features) = 0; + virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) = 0; EditorExportPlatform(); }; @@ -403,6 +404,7 @@ public: void add_platform_feature(const String &p_feature); virtual void get_platform_features(List<String> *r_features); + virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features); int get_chmod_flags() const; void set_chmod_flags(int p_flags); diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 60826aa81b..50b3810e52 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -624,6 +624,22 @@ void EditorHelp::_add_type(const String &p_type, const String &p_enum) { class_desc->pop(); } +String EditorHelp::_fix_constant(const String &p_constant) const { + + if (p_constant.strip_edges() == "4294967295") { + return "0xFFFFFFFF"; + } + + if (p_constant.strip_edges() == "2147483647") { + return "0x7FFFFFFF"; + } + if (p_constant.strip_edges() == "1048575") { + return "0xfffff"; + } + + return p_constant; +} + void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview) { method_line[p_method.name] = class_desc->get_line_count() - 2; //gets overridden if description @@ -673,7 +689,7 @@ void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview class_desc->push_color(symbol_color); class_desc->add_text("="); class_desc->pop(); - _add_text(p_method.arguments[j].default_value); + _add_text(_fix_constant(p_method.arguments[j].default_value)); } class_desc->pop(); @@ -1781,7 +1797,7 @@ void EditorHelp::_notification(int p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - class_desc->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor")); + class_desc->add_color_override("selection_color", EditorSettings::get_singleton()->get("text_editor/theme/selection_color")); _update_doc(); } break; @@ -1863,7 +1879,7 @@ EditorHelp::EditorHelp() { class_desc = memnew(RichTextLabel); add_child(class_desc); class_desc->set_v_size_flags(SIZE_EXPAND_FILL); - class_desc->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor")); + class_desc->add_color_override("selection_color", EditorSettings::get_singleton()->get("text_editor/theme/selection_color")); class_desc->connect("meta_clicked", this, "_class_desc_select"); class_desc->connect("gui_input", this, "_class_desc_input"); @@ -1929,7 +1945,7 @@ void EditorHelpBit::_notification(int p_what) { switch (p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - rich_text->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor")); + rich_text->add_color_override("selection_color", EditorSettings::get_singleton()->get("text_editor/theme/selection_color")); } break; default: break; @@ -1948,7 +1964,7 @@ EditorHelpBit::EditorHelpBit() { add_child(rich_text); //rich_text->set_anchors_and_margins_preset(Control::PRESET_WIDE); rich_text->connect("meta_clicked", this, "_meta_clicked"); - rich_text->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor")); + rich_text->add_color_override("selection_color", EditorSettings::get_singleton()->get("text_editor/theme/selection_color")); rich_text->set_override_selected_font_color(false); set_custom_minimum_size(Size2(0, 70 * EDSCALE)); } diff --git a/editor/editor_help.h b/editor/editor_help.h index dbea97e98b..ad81a39945 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -244,6 +244,8 @@ class EditorHelp : public VBoxContainer { void _unhandled_key_input(const Ref<InputEvent> &p_ev); + String _fix_constant(const String &p_constant) const; + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 99a2b2aa67..852e1930d2 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1533,9 +1533,10 @@ void EditorInspector::update_tree() { if (capitalize_paths) path_name = path_name.capitalize(); + Color c = sscolor; c.a /= level; - section->setup(path_name, acc_path, object, c, use_folding); + section->setup(acc_path, path_name, object, c, use_folding); item_path[acc_path] = section->get_vbox(); } @@ -2221,7 +2222,7 @@ EditorInspector::EditorInspector() { show_categories = false; hide_script = true; use_doc_hints = false; - capitalize_paths = false; + capitalize_paths = true; use_filter = false; autoclear = false; changing = 0; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 0be6ee8759..0ca70c41fa 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -74,6 +74,7 @@ #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/animation_state_machine_editor.h" #include "editor/plugins/animation_tree_editor_plugin.h" +#include "editor/plugins/animation_tree_player_editor_plugin.h" #include "editor/plugins/asset_library_editor_plugin.h" #include "editor/plugins/audio_stream_editor_plugin.h" #include "editor/plugins/baked_lightmap_editor_plugin.h" @@ -83,7 +84,6 @@ #include "editor/plugins/collision_polygon_editor_plugin.h" #include "editor/plugins/collision_shape_2d_editor_plugin.h" #include "editor/plugins/cpu_particles_editor_plugin.h" -#include "editor/plugins/cube_grid_theme_editor_plugin.h" #include "editor/plugins/curve_editor_plugin.h" #include "editor/plugins/editor_preview_plugins.h" #include "editor/plugins/gi_probe_editor_plugin.h" @@ -94,6 +94,7 @@ #include "editor/plugins/material_editor_plugin.h" #include "editor/plugins/mesh_editor_plugin.h" #include "editor/plugins/mesh_instance_editor_plugin.h" +#include "editor/plugins/mesh_library_editor_plugin.h" #include "editor/plugins/multimesh_editor_plugin.h" #include "editor/plugins/navigation_polygon_editor_plugin.h" #include "editor/plugins/particles_2d_editor_plugin.h" @@ -4591,6 +4592,10 @@ EditorNode::EditorNode() { VisualServer::get_singleton()->textures_keep_original(true); VisualServer::get_singleton()->set_debug_generate_wireframes(true); + PhysicsServer::get_singleton()->set_active(false); // no physics by default if editor + Physics2DServer::get_singleton()->set_active(false); // no physics by default if editor + ScriptServer::set_scripting_enabled(false); // no scripting by default if editor + EditorHelp::generate_doc(); //before any editor classes are crated SceneState::set_disable_placeholders(true); ResourceLoader::clear_translation_remaps(); //no remaps using during editor @@ -5589,16 +5594,13 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(ShaderEditorPlugin(this))); add_editor_plugin(memnew(VisualShaderEditorPlugin(this))); - add_editor_plugin(memnew(AnimationNodeBlendTreeEditorPlugin(this))); - add_editor_plugin(memnew(AnimationNodeBlendSpace1DEditorPlugin(this))); - add_editor_plugin(memnew(AnimationNodeBlendSpace2DEditorPlugin(this))); - add_editor_plugin(memnew(AnimationNodeStateMachineEditorPlugin(this))); add_editor_plugin(memnew(CameraEditorPlugin(this))); add_editor_plugin(memnew(ThemeEditorPlugin(this))); add_editor_plugin(memnew(MultiMeshEditorPlugin(this))); add_editor_plugin(memnew(MeshInstanceEditorPlugin(this))); add_editor_plugin(memnew(AnimationTreeEditorPlugin(this))); + add_editor_plugin(memnew(AnimationTreePlayerEditorPlugin(this))); add_editor_plugin(memnew(MeshLibraryEditorPlugin(this))); add_editor_plugin(memnew(StyleBoxEditorPlugin(this))); add_editor_plugin(memnew(SpriteEditorPlugin(this))); @@ -5683,10 +5685,6 @@ EditorNode::EditorNode() { _edit_current(); current = NULL; - PhysicsServer::get_singleton()->set_active(false); // no physics by default if editor - Physics2DServer::get_singleton()->set_active(false); // no physics by default if editor - ScriptServer::set_scripting_enabled(false); // no scripting by default if editor - reference_resource_mem = true; save_external_resources_mem = true; diff --git a/editor/editor_plugin_settings.h b/editor/editor_plugin_settings.h index 310cab699f..194fac6b92 100644 --- a/editor/editor_plugin_settings.h +++ b/editor/editor_plugin_settings.h @@ -31,7 +31,7 @@ #ifndef EDITORPLUGINSETTINGS_H #define EDITORPLUGINSETTINGS_H -#include "editor/plugin_config_dialog.h"; +#include "editor/plugin_config_dialog.h" #include "editor_data.h" #include "property_editor.h" #include "scene/gui/dialogs.h" diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 0cbd5f0bff..5f1e7273e5 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -61,7 +61,7 @@ void EditorPropertyText::_text_changed(const String &p_string) { if (updating) return; - emit_signal("property_changed", get_edited_property(), p_string); + emit_signal("property_changed", get_edited_property(), p_string, true); } void EditorPropertyText::update_property() { @@ -72,6 +72,10 @@ void EditorPropertyText::update_property() { updating = false; } +void EditorPropertyText::set_placeholder(const String &p_string) { + text->set_placeholder(p_string); +} + void EditorPropertyText::_bind_methods() { ClassDB::bind_method(D_METHOD("_text_changed", "txt"), &EditorPropertyText::_text_changed); @@ -92,12 +96,11 @@ EditorPropertyText::EditorPropertyText() { void EditorPropertyMultilineText::_big_text_changed() { text->set_text(big_text->get_text()); - emit_signal("property_changed", get_edited_property(), big_text->get_text()); + emit_signal("property_changed", get_edited_property(), big_text->get_text(), true); } void EditorPropertyMultilineText::_text_changed() { - - emit_signal("property_changed", get_edited_property(), text->get_text()); + emit_signal("property_changed", get_edited_property(), text->get_text(), true); } void EditorPropertyMultilineText::_open_big_text() { @@ -1735,12 +1738,18 @@ EditorPropertyTransform::EditorPropertyTransform() { void EditorPropertyColor::_color_changed(const Color &p_color) { - emit_signal("property_changed", get_edited_property(), p_color); + emit_signal("property_changed", get_edited_property(), p_color, true); +} + +void EditorPropertyColor::_popup_closed() { + + emit_signal("property_changed", get_edited_property(), picker->get_pick_color(), false); } void EditorPropertyColor::_bind_methods() { ClassDB::bind_method(D_METHOD("_color_changed"), &EditorPropertyColor::_color_changed); + ClassDB::bind_method(D_METHOD("_popup_closed"), &EditorPropertyColor::_popup_closed); } void EditorPropertyColor::update_property() { @@ -1758,6 +1767,7 @@ EditorPropertyColor::EditorPropertyColor() { add_child(picker); picker->set_flat(true); picker->connect("color_changed", this, "_color_changed"); + picker->connect("popup_closed", this, "_popup_closed"); } ////////////// NODE PATH ////////////////////// @@ -2777,6 +2787,9 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } else { EditorPropertyText *editor = memnew(EditorPropertyText); + if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) { + editor->set_placeholder(p_hint_text); + } add_property_editor(p_path, editor); } } break; diff --git a/editor/editor_properties.h b/editor/editor_properties.h index d5fac9c1a0..5726ccfa41 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -61,6 +61,7 @@ protected: public: virtual void update_property(); + void set_placeholder(const String &p_string); EditorPropertyText(); }; @@ -476,6 +477,7 @@ class EditorPropertyColor : public EditorProperty { GDCLASS(EditorPropertyColor, EditorProperty) ColorPickerButton *picker; void _color_changed(const Color &p_color); + void _popup_closed(); protected: static void _bind_methods(); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 8203c85c6a..23dbb026dd 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -125,13 +125,13 @@ EditorPropertyDictionaryObject::EditorPropertyDictionaryObject() { ///////////////////// ARRAY /////////////////////////// -void EditorPropertyArray::_property_changed(const String &p_prop, Variant p_value) { +void EditorPropertyArray::_property_changed(const String &p_prop, Variant p_value, bool changing) { if (p_prop.begins_with("indices")) { int idx = p_prop.get_slice("/", 1).to_int(); Variant array = object->get_array(); array.set(idx, p_value); - emit_signal("property_changed", get_edited_property(), array); + emit_signal("property_changed", get_edited_property(), array, true); if (array.get_type() == Variant::ARRAY) { array = array.call("duplicate"); //dupe, so undo/redo works better @@ -544,7 +544,7 @@ void EditorPropertyArray::_bind_methods() { ClassDB::bind_method("_edit_pressed", &EditorPropertyArray::_edit_pressed); ClassDB::bind_method("_page_changed", &EditorPropertyArray::_page_changed); ClassDB::bind_method("_length_changed", &EditorPropertyArray::_length_changed); - ClassDB::bind_method("_property_changed", &EditorPropertyArray::_property_changed); + ClassDB::bind_method("_property_changed", &EditorPropertyArray::_property_changed, DEFVAL(false)); ClassDB::bind_method("_change_type", &EditorPropertyArray::_change_type); ClassDB::bind_method("_change_type_menu", &EditorPropertyArray::_change_type_menu); } @@ -579,7 +579,7 @@ EditorPropertyArray::EditorPropertyArray() { ///////////////////// DICTIONARY /////////////////////////// -void EditorPropertyDictionary::_property_changed(const String &p_prop, Variant p_value) { +void EditorPropertyDictionary::_property_changed(const String &p_prop, Variant p_value, bool changing) { if (p_prop == "new_item_key") { @@ -593,7 +593,7 @@ void EditorPropertyDictionary::_property_changed(const String &p_prop, Variant p Variant key = dict.get_key_at_index(idx); dict[key] = p_value; - emit_signal("property_changed", get_edited_property(), dict); + emit_signal("property_changed", get_edited_property(), dict, true); dict = dict.duplicate(); //dupe, so undo/redo works better object->set_dict(dict); @@ -1006,7 +1006,7 @@ void EditorPropertyDictionary::_page_changed(double p_page) { void EditorPropertyDictionary::_bind_methods() { ClassDB::bind_method("_edit_pressed", &EditorPropertyDictionary::_edit_pressed); ClassDB::bind_method("_page_changed", &EditorPropertyDictionary::_page_changed); - ClassDB::bind_method("_property_changed", &EditorPropertyDictionary::_property_changed); + ClassDB::bind_method("_property_changed", &EditorPropertyDictionary::_property_changed, DEFVAL(false)); ClassDB::bind_method("_change_type", &EditorPropertyDictionary::_change_type); ClassDB::bind_method("_change_type_menu", &EditorPropertyDictionary::_change_type_menu); ClassDB::bind_method("_add_key_value", &EditorPropertyDictionary::_add_key_value); diff --git a/editor/editor_properties_array_dict.h b/editor/editor_properties_array_dict.h index 75c67d280d..a8ddb02e9d 100644 --- a/editor/editor_properties_array_dict.h +++ b/editor/editor_properties_array_dict.h @@ -67,7 +67,7 @@ class EditorPropertyArray : public EditorProperty { void _page_changed(double p_page); void _length_changed(double p_page); void _edit_pressed(); - void _property_changed(const String &p_prop, Variant p_value); + void _property_changed(const String &p_prop, Variant p_value, bool changing = false); void _change_type(Object *p_button, int p_index); void _change_type_menu(int p_index); @@ -99,7 +99,7 @@ class EditorPropertyDictionary : public EditorProperty { void _page_changed(double p_page); void _edit_pressed(); - void _property_changed(const String &p_prop, Variant p_value); + void _property_changed(const String &p_prop, Variant p_value, bool changing = false); void _change_type(Object *p_button, int p_index); void _change_type_menu(int p_index); diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index 62870ab35c..bbd18306a2 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -196,8 +196,8 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li void EditorRun::stop() { if (status != STATUS_STOP && pid != 0) { - - OS::get_singleton()->kill(pid); + const int max_wait_msec = GLOBAL_DEF("editor/stop_max_wait_msec", 10000); + OS::get_singleton()->kill(pid, max_wait_msec); } status = STATUS_STOP; diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index e1ec48a9f9..9278d7676a 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -357,6 +357,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { hints["text_editor/theme/color_theme"] = PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, "Adaptive,Default,Custom"); _initial_set("text_editor/theme/line_spacing", 4); + _initial_set("text_editor/theme/selection_color", Color::html("40808080")); _load_default_text_editor_theme(); @@ -473,6 +474,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { hints["editors/3d/freelook/freelook_modifier_speed_factor"] = PropertyInfo(Variant::REAL, "editors/3d/freelook/freelook_modifier_speed_factor", PROPERTY_HINT_RANGE, "0.0, 10.0, 0.1"); _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false); + _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07)); _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8)); _initial_set("editors/2d/bone_width", 5); _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.9)); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 69a013dd00..50d71f1c98 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -381,12 +381,6 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_color("error_color", "Editor", error_color); theme->set_color("property_color", "Editor", property_color); - // 2d grid color - const Color grid_minor_color = mono_color * Color(1.0, 1.0, 1.0, 0.07); - const Color grid_major_color = Color(font_color_disabled.r, font_color_disabled.g, font_color_disabled.b, 0.15); - theme->set_color("grid_major_color", "Editor", grid_major_color); - theme->set_color("grid_minor_color", "Editor", grid_minor_color); - const int thumb_size = EDITOR_DEF("filesystem/file_dialog/thumbnail_size", 64); theme->set_constant("scale", "Editor", EDSCALE); theme->set_constant("thumb_size", "Editor", thumb_size); @@ -971,8 +965,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // GraphEdit theme->set_stylebox("bg", "GraphEdit", style_tree_bg); - theme->set_color("grid_major", "GraphEdit", grid_major_color); - theme->set_color("grid_minor", "GraphEdit", grid_minor_color); + theme->set_color("grid_major", "GraphEdit", Color(1.0, 1.0, 1.0, 0.15)); + theme->set_color("grid_minor", "GraphEdit", Color(1.0, 1.0, 1.0, 0.07)); theme->set_color("activity", "GraphEdit", accent_color); theme->set_icon("minus", "GraphEdit", theme->get_icon("ZoomLess", "EditorIcons")); theme->set_icon("more", "GraphEdit", theme->get_icon("ZoomMore", "EditorIcons")); diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index 2be1f1644e..ef7409fd43 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -37,10 +37,10 @@ #include "scene/gui/check_box.h" #include "scene/gui/file_dialog.h" #include "scene/gui/grid_container.h" -#include "scene/gui/item_list.h" #include "scene/gui/label.h" #include "scene/gui/line_edit.h" #include "scene/gui/progress_bar.h" +#include "scene/gui/tree.h" #define ROOT_PREFIX "res://" @@ -58,6 +58,34 @@ static bool is_text_char(CharType c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } +static bool find_next(const String &line, String pattern, int from, bool match_case, bool whole_words, int &out_begin, int &out_end) { + + int end = from; + + while (true) { + int begin = match_case ? line.find(pattern, end) : line.findn(pattern, end); + + if (begin == -1) + return false; + + end = begin + pattern.length(); + out_begin = begin; + out_end = end; + + if (whole_words) { + if (begin > 0 && is_text_char(line[begin - 1])) { + continue; + } + if (end < line.size() && is_text_char(line[end])) { + continue; + } + } + + return true; + } +} + +//-------------------------------------------------------------------------------- FindInFiles::FindInFiles() { _root_prefix = ROOT_PREFIX; _extension_filter.insert("gd"); @@ -246,24 +274,7 @@ void FindInFiles::_scan_file(String fpath) { String line = f->get_line(); - // Find all occurrences in the current line - while (true) { - begin = _match_case ? line.find(_pattern, end) : line.findn(_pattern, end); - - if (begin == -1) - break; - - end = begin + _pattern.length(); - - if (_whole_words) { - if (begin > 0 && is_text_char(line[begin - 1])) { - continue; - } - if (end < line.size() && is_text_char(line[end])) { - continue; - } - } - + while (find_next(line, _pattern, end, _match_case, _whole_words, begin, end)) { emit_signal(SIGNAL_RESULT_FOUND, fpath, line_number, begin, end, line); } } @@ -567,14 +578,18 @@ FindInFilesPanel::FindInFilesPanel() { vbc->add_child(hbc); } - // In the future, this should be replaced by a more specific list container, - // which can highlight text regions and change opacity for enabled/disabled states - _results_display = memnew(ItemList); + _results_display = memnew(Tree); _results_display->add_font_override("font", get_font("source", "EditorFonts")); _results_display->set_v_size_flags(SIZE_EXPAND_FILL); _results_display->connect("item_selected", this, "_on_result_selected"); + _results_display->connect("item_edited", this, "_on_item_edited"); + _results_display->set_hide_root(true); + _results_display->set_select_mode(Tree::SELECT_ROW); + _results_display->create_item(); // Root vbc->add_child(_results_display); + _with_replace = false; + { _replace_container = memnew(HBoxContainer); @@ -600,12 +615,33 @@ FindInFilesPanel::FindInFilesPanel() { void FindInFilesPanel::set_with_replace(bool with_replace) { + _with_replace = with_replace; _replace_container->set_visible(with_replace); + + if (with_replace) { + // Results show checkboxes on their left so they can be opted out + _results_display->set_columns(2); + _results_display->set_column_expand(0, false); + _results_display->set_column_min_width(0, 48 * EDSCALE); + + } else { + // Results are single-cell items + _results_display->set_column_expand(0, true); + _results_display->set_columns(1); + } +} + +void FindInFilesPanel::clear() { + _file_items.clear(); + _result_items.clear(); + _results_display->clear(); + _results_display->create_item(); // Root } void FindInFilesPanel::start_search() { - _results_display->clear(); + clear(); + _status_label->set_text(TTR("Searching...")); _search_text_label->set_text(_finder->get_search_text()); @@ -636,9 +672,90 @@ void FindInFilesPanel::_notification(int p_what) { void FindInFilesPanel::_on_result_found(String fpath, int line_number, int begin, int end, String text) { - int i = _results_display->get_item_count(); - _results_display->add_item(fpath + ": " + String::num(line_number) + ": " + text.replace("\t", " ")); - _results_display->set_item_metadata(i, varray(fpath, line_number, begin, end)); + TreeItem *file_item; + Map<String, TreeItem *>::Element *E = _file_items.find(fpath); + + if (E == NULL) { + file_item = _results_display->create_item(); + file_item->set_text(0, fpath); + file_item->set_metadata(0, fpath); + + // The width of this column is restrained to checkboxes, but that doesn't make sense for the parent items, + // so we override their width so they can expand to full width + file_item->set_expand_right(0, true); + + _file_items[fpath] = file_item; + + } else { + file_item = E->value(); + } + + int text_index = _with_replace ? 1 : 0; + + TreeItem *item = _results_display->create_item(file_item); + + // Do this first because it resets properties of the cell... + item->set_cell_mode(text_index, TreeItem::CELL_MODE_CUSTOM); + + String item_text = String::num_int64(line_number) + ": " + text.replace("\t", " "); + + item->set_text(text_index, item_text); + item->set_custom_draw(text_index, this, "_draw_result_text"); + + Ref<Font> font = _results_display->get_font("font"); + + float raw_text_width = font->get_string_size(text).x; + float item_text_width = font->get_string_size(item_text).x; + + Result r; + r.line_number = line_number; + r.begin = begin; + r.end = end; + r.draw_begin = (item_text_width - raw_text_width) + font->get_string_size(text.left(r.begin)).x; + r.draw_width = font->get_string_size(text.substr(r.begin, r.end - r.begin + 1)).x; + _result_items[item] = r; + + if (_with_replace) { + item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + item->set_checked(0, true); + item->set_editable(0, true); + } +} + +void FindInFilesPanel::draw_result_text(Object *item_obj, Rect2 rect) { + + TreeItem *item = Object::cast_to<TreeItem>(item_obj); + if (!item) + return; + + Map<TreeItem *, Result>::Element *E = _result_items.find(item); + if (!E) + return; + Result r = E->value(); + + Rect2 match_rect = rect; + match_rect.position.x += r.draw_begin; + match_rect.size.x = r.draw_width; + match_rect.position.y += 1 * EDSCALE; + match_rect.size.y -= 2 * EDSCALE; + + _results_display->draw_rect(match_rect, Color(0, 0, 0, 0.5)); + // Text is drawn by Tree already +} + +void FindInFilesPanel::_on_item_edited() { + + TreeItem *item = _results_display->get_selected(); + + if (item->is_checked(0)) { + item->set_custom_color(1, _results_display->get_color("font_color")); + + } else { + // Grey out + Color color = _results_display->get_color("font_color"); + color.a /= 2.0; + item->set_custom_color(1, color); + } } void FindInFilesPanel::_on_finished() { @@ -653,10 +770,19 @@ void FindInFilesPanel::_on_cancel_button_clicked() { stop_search(); } -void FindInFilesPanel::_on_result_selected(int i) { +void FindInFilesPanel::_on_result_selected() { + + TreeItem *item = _results_display->get_selected(); + Map<TreeItem *, Result>::Element *E = _result_items.find(item); + + if (E == NULL) + return; + Result r = E->value(); + + TreeItem *file_item = item->get_parent(); + String fpath = file_item->get_metadata(0); - Array meta = _results_display->get_item_metadata(i); - emit_signal(SIGNAL_RESULT_SELECTED, meta[0], meta[1], meta[2], meta[3]); + emit_signal(SIGNAL_RESULT_SELECTED, fpath, r.line_number, r.begin, r.end); } void FindInFilesPanel::_on_replace_text_changed(String text) { @@ -668,39 +794,33 @@ void FindInFilesPanel::_on_replace_all_clicked() { String replace_text = get_replace_text(); ERR_FAIL_COND(replace_text.empty()); - String last_fpath; - PoolIntArray locations; PoolStringArray modified_files; - for (int i = 0; i < _results_display->get_item_count(); ++i) { + for (Map<String, TreeItem *>::Element *E = _file_items.front(); E; E = E->next()) { - Array meta = _results_display->get_item_metadata(i); + TreeItem *file_item = E->value(); + String fpath = file_item->get_metadata(0); - String fpath = meta[0]; + Vector<Result> locations; + for (TreeItem *item = file_item->get_children(); item; item = item->get_next()) { - // Results are sorted by file, so we can batch replaces - if (fpath != last_fpath) { - if (locations.size() != 0) { - apply_replaces_in_file(last_fpath, locations, replace_text); - modified_files.append(last_fpath); - locations.resize(0); - } - } + if (!item->is_checked(0)) + continue; - locations.append(meta[1]); // line_number - locations.append(meta[2]); // begin - locations.append(meta[3]); // end - - last_fpath = fpath; - } + Map<TreeItem *, Result>::Element *E = _result_items.find(item); + ERR_FAIL_COND(E == NULL); + locations.push_back(E->value()); + } - if (locations.size() != 0) { - apply_replaces_in_file(last_fpath, locations, replace_text); - modified_files.append(last_fpath); + if (locations.size() != 0) { + // Results are sorted by file, so we can batch replaces + apply_replaces_in_file(fpath, locations, replace_text); + modified_files.append(fpath); + } } // Hide replace bar so we can't trigger the action twice without doing a new search - set_with_replace(false); + _replace_container->hide(); emit_signal(SIGNAL_FILES_MODIFIED, modified_files); } @@ -740,11 +860,7 @@ private: Vector<char> _line_buffer; }; -void FindInFilesPanel::apply_replaces_in_file(String fpath, PoolIntArray locations, String text) { - - ERR_FAIL_COND(locations.size() % 3 != 0); - - //print_line(String("Replacing {0} occurrences in {1}").format(varray(fpath, locations.size() / 3))); +void FindInFilesPanel::apply_replaces_in_file(String fpath, const Vector<Result> &locations, String new_text) { // If the file is already open, I assume the editor will reload it. // If there are unsaved changes, the user will be asked on focus, @@ -759,21 +875,34 @@ void FindInFilesPanel::apply_replaces_in_file(String fpath, PoolIntArray locatio ConservativeGetLine conservative; String line = conservative.get_line(f); + String search_text = _finder->get_search_text(); + + int offset = 0; - PoolIntArray::Read locations_read = locations.read(); - for (int i = 0; i < locations.size(); i += 3) { + for (int i = 0; i < locations.size(); ++i) { - int repl_line_number = locations_read[i]; - int repl_begin = locations_read[i + 1]; - int repl_end = locations_read[i + 2]; + int repl_line_number = locations[i].line_number; while (current_line < repl_line_number) { buffer += line; line = conservative.get_line(f); ++current_line; + offset = 0; + } + + int repl_begin = locations[i].begin + offset; + int repl_end = locations[i].end + offset; + + int _; + if (!find_next(line, search_text, repl_begin, _finder->is_match_case(), _finder->is_whole_words(), _, _)) { + // Make sure the replace is still valid in case the file was tampered with. + print_line(String("Occurrence no longer matches, replace will be ignored in {0}: line {1}, col {2}").format(varray(fpath, repl_line_number, repl_begin))); + continue; } - line = line.left(repl_begin) + text + line.right(repl_end); + line = line.left(repl_begin) + new_text + line.right(repl_end); + // keep an offset in case there are successive replaces in the same line + offset += new_text.length() - (repl_end - repl_begin); } buffer += line; @@ -811,11 +940,13 @@ void FindInFilesPanel::set_progress_visible(bool visible) { void FindInFilesPanel::_bind_methods() { ClassDB::bind_method("_on_result_found", &FindInFilesPanel::_on_result_found); + ClassDB::bind_method("_on_item_edited", &FindInFilesPanel::_on_item_edited); ClassDB::bind_method("_on_finished", &FindInFilesPanel::_on_finished); ClassDB::bind_method("_on_cancel_button_clicked", &FindInFilesPanel::_on_cancel_button_clicked); ClassDB::bind_method("_on_result_selected", &FindInFilesPanel::_on_result_selected); ClassDB::bind_method("_on_replace_text_changed", &FindInFilesPanel::_on_replace_text_changed); ClassDB::bind_method("_on_replace_all_clicked", &FindInFilesPanel::_on_replace_all_clicked); + ClassDB::bind_method("_draw_result_text", &FindInFilesPanel::draw_result_text); ADD_SIGNAL(MethodInfo(SIGNAL_RESULT_SELECTED, PropertyInfo(Variant::STRING, "path"), diff --git a/editor/find_in_files.h b/editor/find_in_files.h index d57184960b..75ea1c3161 100644 --- a/editor/find_in_files.h +++ b/editor/find_in_files.h @@ -131,7 +131,8 @@ private: }; class Button; -class ItemList; +class Tree; +class TreeItem; class ProgressBar; // Display search results @@ -159,22 +160,37 @@ private: void _on_result_found(String fpath, int line_number, int begin, int end, String text); void _on_finished(); void _on_cancel_button_clicked(); - void _on_result_selected(int i); + void _on_result_selected(); + void _on_item_edited(); void _on_replace_text_changed(String text); void _on_replace_all_clicked(); - void apply_replaces_in_file(String fpath, PoolIntArray locations, String text); + struct Result { + int line_number; + int begin; + int end; + float draw_begin; + float draw_width; + }; + void apply_replaces_in_file(String fpath, const Vector<Result> &locations, String new_text); void update_replace_buttons(); String get_replace_text(); + + void draw_result_text(Object *item_obj, Rect2 rect); + void set_progress_visible(bool visible); + void clear(); FindInFiles *_finder; Label *_search_text_label; - ItemList *_results_display; + Tree *_results_display; Label *_status_label; Button *_cancel_button; ProgressBar *_progress_bar; + Map<String, TreeItem *> _file_items; + Map<TreeItem *, Result> _result_items; + bool _with_replace; HBoxContainer *_replace_container; LineEdit *_replace_line_edit; diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp index 2f958a6fdd..211bb7bcc9 100644 --- a/editor/import/resource_importer_layered_texture.cpp +++ b/editor/import/resource_importer_layered_texture.cpp @@ -163,6 +163,7 @@ void ResourceImporterLayeredTexture::_save_tex(const Vector<Ref<Image> > &p_imag Error ResourceImporterLayeredTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { int compress_mode = p_options["compress/mode"]; + int no_bptc_if_rgb = p_options["compress/no_bptc_if_rgb"]; int repeat = p_options["flags/repeat"]; bool filter = p_options["flags/filter"]; bool mipmaps = p_options["flags/mipmaps"]; @@ -226,6 +227,26 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const //Android, GLES 2.x bool ok_on_pc = false; + bool encode_bptc = false; + + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_bptc")) { + + encode_bptc = true; + + if (no_bptc_if_rgb) { + Image::DetectChannels channels = image->get_detected_channels(); + if (channels != Image::DETECTED_LA && channels != Image::DETECTED_RGBA) { + encode_bptc = false; + } + } + } + + if (encode_bptc) { + + _save_tex(slices, p_save_path + ".bptc." + extension, compress_mode, Image::COMPRESS_BPTC, mipmaps, tex_flags); + r_platform_variants->push_back("bptc"); + ok_on_pc = true; + } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_s3tc")) { diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index 17a9394b51..7feb506270 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -188,7 +188,8 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options, r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Lossless,Lossy,Video RAM,Uncompressed", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), p_preset == PRESET_3D ? 2 : 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "compress/lossy_quality", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.7)); - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/hdr_mode", PROPERTY_HINT_ENUM, "Compress,Force RGBE"), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress/no_bptc_if_rgb"), false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/hdr_mode", PROPERTY_HINT_ENUM, "LDR Fallback,Force RGBE,RGBE Fallback"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/normal_map", PROPERTY_HINT_ENUM, "Detect,Enable,Disabled"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "flags/repeat", PROPERTY_HINT_ENUM, "Disabled,Enabled,Mirrored"), p_preset == PRESET_3D ? 1 : 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "flags/filter"), p_preset == PRESET_2D_PIXEL ? false : true)); @@ -198,6 +199,7 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options, r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/fix_alpha_border"), p_preset != PRESET_3D ? true : false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/premult_alpha"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/HDR_as_SRGB"), false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/invert_color"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "stream"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "size_limit", PROPERTY_HINT_RANGE, "0,4096,1"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "detect_3d"), p_preset == PRESET_DETECT)); @@ -346,6 +348,7 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String Error ResourceImporterTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { int compress_mode = p_options["compress/mode"]; + int no_bptc_if_rgb = p_options["compress/no_bptc_if_rgb"]; float lossy = p_options["compress/lossy_quality"]; int repeat = p_options["flags/repeat"]; bool filter = p_options["flags/filter"]; @@ -354,9 +357,11 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String int srgb = p_options["flags/srgb"]; bool fix_alpha_border = p_options["process/fix_alpha_border"]; bool premult_alpha = p_options["process/premult_alpha"]; + bool invert_color = p_options["process/invert_color"]; bool stream = p_options["stream"]; int size_limit = p_options["size_limit"]; bool force_rgbe = int(p_options["compress/hdr_mode"]) == 1; + bool rgbe_fallback = int(p_options["compress/hdr_mode"]) == 2; bool hdr_as_srgb = p_options["process/HDR_as_SRGB"]; int normal = p_options["compress/normal_map"]; float scale = p_options["svg/scale"]; @@ -409,6 +414,19 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String image->premultiply_alpha(); } + if (invert_color) { + int height = image->get_height(); + int width = image->get_width(); + + image->lock(); + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + image->set_pixel(i, j, image->get_pixel(i, j).inverted()); + } + } + image->unlock(); + } + bool detect_3d = p_options["detect_3d"]; bool detect_srgb = srgb == 2; bool detect_normal = normal == 0; @@ -419,31 +437,59 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String //Android, GLES 2.x bool ok_on_pc = false; + bool encode_bptc = false; + bool is_hdr = (image->get_format() >= Image::FORMAT_RF && image->get_format() <= Image::FORMAT_RGBE9995); + bool no_ldr_compression = (is_hdr && rgbe_fallback); + + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_bptc")) { + + encode_bptc = true; + + if (no_bptc_if_rgb && !is_hdr) { + Image::DetectChannels channels = image->get_detected_channels(); + if (channels != Image::DETECTED_LA && channels != Image::DETECTED_RGBA) { + encode_bptc = false; + } + } + } + + if (encode_bptc) { - if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_s3tc")) { + _save_stex(image, p_save_path + ".bptc.stex", compress_mode, lossy, Image::COMPRESS_BPTC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + r_platform_variants->push_back("bptc"); + ok_on_pc = true; + } + + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_s3tc") && !no_ldr_compression) { _save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, Image::COMPRESS_S3TC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); r_platform_variants->push_back("s3tc"); ok_on_pc = true; } - if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) { + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2") && !no_ldr_compression) { _save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); r_platform_variants->push_back("etc2"); } - if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc")) { + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc") && !no_ldr_compression) { _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); r_platform_variants->push_back("etc"); } - if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { + if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc") && !no_ldr_compression) { _save_stex(image, p_save_path + ".pvrtc.stex", compress_mode, lossy, Image::COMPRESS_PVRTC4, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); r_platform_variants->push_back("pvrtc"); } + if (is_hdr && rgbe_fallback) { + _save_stex(image, p_save_path + ".fallback.stex", compress_mode, lossy, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, tex_flags, stream, detect_3d, detect_srgb, true, detect_normal, force_normal); + r_platform_variants->push_back("fallback"); + ok_on_pc = true; + } + if (!ok_on_pc) { EditorNode::add_io_error("Warning, no suitable PC VRAM compression enabled in Project Settings. This texture will not display correcly on PC."); } diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index 41f5a892eb..9e99dcc5c8 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -157,15 +157,18 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s //Consider revision for engine version 3.0 compression_code = file->get_16(); if (compression_code != 1 && compression_code != 3) { - ERR_PRINT("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead."); - break; + file->close(); + memdelete(file); + ERR_EXPLAIN("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead."); + ERR_FAIL_V(ERR_INVALID_DATA); } format_channels = file->get_16(); if (format_channels != 1 && format_channels != 2) { - - ERR_PRINT("Format not supported for WAVE file (not stereo or mono)"); - break; + file->close(); + memdelete(file); + ERR_EXPLAIN("Format not supported for WAVE file (not stereo or mono)."); + ERR_FAIL_V(ERR_INVALID_DATA); } format_freq = file->get_32(); //sampling rate @@ -174,10 +177,11 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s file->get_16(); // block align (unused) format_bits = file->get_16(); // bits per sample - if (format_bits % 8) { - - ERR_PRINT("Strange number of bits in sample (not 8,16,24,32)"); - break; + if (format_bits % 8 || format_bits == 0) { + file->close(); + memdelete(file); + ERR_EXPLAIN("Invalid amount of bits in the sample (should be one of 8, 16, 24 or 32)."); + ERR_FAIL_V(ERR_INVALID_DATA); } /* Don't need anything else, continue */ @@ -185,7 +189,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s } if (chunkID[0] == 'd' && chunkID[1] == 'a' && chunkID[2] == 't' && chunkID[3] == 'a' && !data_found) { - /* IS FORMAT CHUNK */ + /* IS DATA CHUNK */ data_found = true; if (!format_found) { diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index f91802b352..31eb193461 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -420,10 +420,9 @@ ImportDock::ImportDock() { preset->get_popup()->connect("index_pressed", this, "_preset_selected"); hb->add_child(preset); - import_opts = memnew(PropertyEditor); + import_opts = memnew(EditorInspector); add_child(import_opts); import_opts->set_v_size_flags(SIZE_EXPAND_FILL); - import_opts->hide_top_label(); hb = memnew(HBoxContainer); add_child(hb); diff --git a/editor/import_dock.h b/editor/import_dock.h index a7a7eda8d8..41c7298d9a 100644 --- a/editor/import_dock.h +++ b/editor/import_dock.h @@ -31,10 +31,12 @@ #ifndef IMPORTDOCK_H #define IMPORTDOCK_H -#include "editor_file_system.h" -#include "io/resource_import.h" -#include "property_editor.h" +#include "core/io/config_file.h" +#include "core/io/resource_import.h" +#include "editor/editor_file_system.h" +#include "editor/editor_inspector.h" #include "scene/gui/box_container.h" +#include "scene/gui/menu_button.h" #include "scene/gui/option_button.h" #include "scene/gui/popup_menu.h" @@ -45,7 +47,7 @@ class ImportDock : public VBoxContainer { Label *imported; OptionButton *import_as; MenuButton *preset; - PropertyEditor *import_opts; + EditorInspector *import_opts; List<PropertyInfo> properties; Map<StringName, Variant> property_values; diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index 615e9df043..0335053162 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -36,6 +36,16 @@ void InspectorDock::_menu_option(int p_option) { switch (p_option) { + case RESOURCE_MAKE_BUILT_IN: { + _unref_resource(); + } break; + case RESOURCE_COPY: { + _copy_resource(); + } break; + case RESOURCE_EDIT_CLIPBOARD: { + _paste_resource(); + } break; + case RESOURCE_SAVE: { _save_resource(false); } break; @@ -400,10 +410,11 @@ void InspectorDock::update(Object *p_object) { p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTR("Copy Params")), OBJECT_COPY_PARAMS); p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTR("Paste Params")), OBJECT_PASTE_PARAMS); p->add_separator(); - p->add_shortcut(ED_SHORTCUT("property_editor/paste_resource", TTR("Paste Resource")), RESOURCE_PASTE); + + p->add_shortcut(ED_SHORTCUT("property_editor/paste_resource", TTR("Edit Resource Clipboard")), RESOURCE_EDIT_CLIPBOARD); if (is_resource) { p->add_shortcut(ED_SHORTCUT("property_editor/copy_resource", TTR("Copy Resource")), RESOURCE_COPY); - p->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTR("Make Built-In")), RESOURCE_UNREF); + p->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTR("Make Built-In")), RESOURCE_MAKE_BUILT_IN); } if (is_resource || is_node) { diff --git a/editor/inspector_dock.h b/editor/inspector_dock.h index f347056158..97ef6899dc 100644 --- a/editor/inspector_dock.h +++ b/editor/inspector_dock.h @@ -51,13 +51,12 @@ class InspectorDock : public VBoxContainer { GDCLASS(InspectorDock, VBoxContainer); enum MenuOptions { - RESOURCE_NEW, RESOURCE_LOAD, RESOURCE_SAVE, RESOURCE_SAVE_AS, - RESOURCE_UNREF, + RESOURCE_MAKE_BUILT_IN, RESOURCE_COPY, - RESOURCE_PASTE, + RESOURCE_EDIT_CLIPBOARD, OBJECT_COPY_PARAMS, OBJECT_PASTE_PARAMS, OBJECT_UNIQUE_RESOURCES, diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index 2e128db883..5373015654 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -3,40 +3,9 @@ #include "os/keyboard.h" #include "scene/animation/animation_blend_tree.h" -void AnimationNodeBlendSpace1DEditorPlugin::edit(Object *p_object) { - anim_tree_editor->edit(Object::cast_to<AnimationNodeBlendSpace1D>(p_object)); -} - -bool AnimationNodeBlendSpace1DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("AnimationNodeBlendSpace1D"); -} - -void AnimationNodeBlendSpace1DEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - button->show(); - editor->make_bottom_panel_item_visible(anim_tree_editor); - anim_tree_editor->set_process(true); - } else { - if (anim_tree_editor->is_visible_in_tree()) { - editor->hide_bottom_panel(); - } - - button->hide(); - anim_tree_editor->set_process(false); - } -} - -AnimationNodeBlendSpace1DEditorPlugin::AnimationNodeBlendSpace1DEditorPlugin(EditorNode *p_node) { - editor = p_node; - anim_tree_editor = memnew(AnimationNodeBlendSpace1DEditor); - anim_tree_editor->set_custom_minimum_size(Size2(0, 150 * EDSCALE)); - - button = editor->add_bottom_panel_item(TTR("BlendSpace1D"), anim_tree_editor); - button->hide(); -} - -AnimationNodeBlendSpace1DEditorPlugin::~AnimationNodeBlendSpace1DEditorPlugin() { +StringName AnimationNodeBlendSpace1DEditor::get_blend_position_path() const { + StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + "blend_position"; + return path; } void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) { @@ -62,7 +31,7 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven menu->add_submenu_item(TTR("Add Animation"), "animations"); - AnimationTree *gp = blend_space->get_tree(); + AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_tree(); ERR_FAIL_COND(!gp); if (gp->has_node(gp->get_animation_player())) { @@ -85,10 +54,18 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven continue; int idx = menu->get_item_count(); - menu->add_item(vformat("Add %s", name)); + menu->add_item(vformat("Add %s", name), idx); menu->set_item_metadata(idx, E->get()); } + Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard(); + if (clipb.is_valid()) { + menu->add_separator(); + menu->add_item(TTR("Paste"), MENU_PASTE); + } + menu->add_separator(); + menu->add_item(TTR("Load.."), MENU_LOAD_FILE); + menu->set_global_position(blend_space_draw->get_global_transform().xform(mb->get_position())); menu->popup(); @@ -158,7 +135,7 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven blend_pos *= blend_space->get_max_space() - blend_space->get_min_space(); blend_pos += blend_space->get_min_space(); - blend_space->set_blend_pos(blend_pos); + AnimationTreeEditor::get_singleton()->get_tree()->set(get_blend_position_path(), blend_pos); blend_space_draw->update(); } @@ -181,7 +158,8 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven blend_pos *= blend_space->get_max_space() - blend_space->get_min_space(); blend_pos += blend_space->get_min_space(); - blend_space->set_blend_pos(blend_pos); + AnimationTreeEditor::get_singleton()->get_tree()->set(get_blend_position_path(), blend_pos); + blend_space_draw->update(); } } @@ -277,7 +255,8 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() { color.a *= 0.5; } - float point = blend_space->get_blend_pos(); + float point = AnimationTreeEditor::get_singleton()->get_tree()->get(get_blend_position_path()); + point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space()); point *= s.width; @@ -299,12 +278,6 @@ void AnimationNodeBlendSpace1DEditor::_update_space() { updating = true; - if (blend_space->get_parent().is_valid()) { - goto_parent_hb->show(); - } else { - goto_parent_hb->hide(); - } - max_value->set_value(blend_space->get_max_space()); min_value->set_value(blend_space->get_min_space()); @@ -355,15 +328,47 @@ void AnimationNodeBlendSpace1DEditor::_snap_toggled() { blend_space_draw->update(); } +void AnimationNodeBlendSpace1DEditor::_file_opened(const String &p_file) { + + file_loaded = ResourceLoader::load(p_file); + if (file_loaded.is_valid()) { + _add_menu_type(MENU_LOAD_FILE_CONFIRM); + } +} + void AnimationNodeBlendSpace1DEditor::_add_menu_type(int p_index) { - String type = menu->get_item_metadata(p_index); + Ref<AnimationRootNode> node; + if (p_index == MENU_LOAD_FILE) { + + open_file->clear_filters(); + List<String> filters; + ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters); + for (List<String>::Element *E = filters.front(); E; E = E->next()) { + open_file->add_filter("*." + E->get()); + } + open_file->popup_centered_ratio(); + return; + } else if (p_index == MENU_LOAD_FILE_CONFIRM) { + node = file_loaded; + file_loaded.unref(); + } else if (p_index == MENU_PASTE) { + + node = EditorSettings::get_singleton()->get_resource_clipboard(); + } else { + String type = menu->get_item_metadata(p_index); + + Object *obj = ClassDB::instance(type); + ERR_FAIL_COND(!obj); + AnimationNode *an = Object::cast_to<AnimationNode>(obj); + ERR_FAIL_COND(!an); - Object *obj = ClassDB::instance(type); - ERR_FAIL_COND(!obj); - AnimationNode *an = Object::cast_to<AnimationNode>(obj); - ERR_FAIL_COND(!an); + node = Ref<AnimationNode>(an); + } - Ref<AnimationNode> node(an); + if (!node.is_valid()) { + EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only root nodes are allowed.")); + return; + } updating = true; undo_redo->create_action("Add Node Point"); @@ -438,7 +443,7 @@ void AnimationNodeBlendSpace1DEditor::_update_tool_erase() { if (point_valid) { Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point); - if (EditorNode::get_singleton()->item_has_editor(an.ptr())) { + if (AnimationTreeEditor::get_singleton()->can_edit(an)) { open_editor->show(); } else { open_editor->hide(); @@ -490,18 +495,10 @@ void AnimationNodeBlendSpace1DEditor::_open_editor() { if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) { Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point); ERR_FAIL_COND(an.is_null()); - EditorNode::get_singleton()->edit_item(an.ptr()); + AnimationTreeEditor::get_singleton()->enter_editor(itos(selected_point)); } } -void AnimationNodeBlendSpace1DEditor::_goto_parent() { - EditorNode::get_singleton()->edit_item(blend_space->get_parent().ptr()); -} - -void AnimationNodeBlendSpace1DEditor::_removed_from_graph() { - EditorNode::get_singleton()->edit_item(NULL); -} - void AnimationNodeBlendSpace1DEditor::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { error_panel->add_style_override("panel", get_stylebox("bg", "Tree")); @@ -513,18 +510,15 @@ void AnimationNodeBlendSpace1DEditor::_notification(int p_what) { tool_erase->set_icon(get_icon("Remove", "EditorIcons")); snap->set_icon(get_icon("SnapGrid", "EditorIcons")); open_editor->set_icon(get_icon("Edit", "EditorIcons")); - goto_parent->set_icon(get_icon("MoveUp", "EditorIcons")); } if (p_what == NOTIFICATION_PROCESS) { String error; - if (!blend_space->get_tree()) { - error = TTR("BlendSpace1D does not belong to an AnimationTree node."); - } else if (!blend_space->get_tree()->is_active()) { + if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (blend_space->get_tree()->is_state_invalid()) { - error = blend_space->get_tree()->get_invalid_state_reason(); + } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { + error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); } if (error != error_label->get_text()) { @@ -536,6 +530,10 @@ void AnimationNodeBlendSpace1DEditor::_notification(int p_what) { } } } + + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + set_process(is_visible_in_tree()); + } } void AnimationNodeBlendSpace1DEditor::_bind_methods() { @@ -556,28 +554,21 @@ void AnimationNodeBlendSpace1DEditor::_bind_methods() { ClassDB::bind_method("_update_edited_point_pos", &AnimationNodeBlendSpace1DEditor::_update_edited_point_pos); ClassDB::bind_method("_open_editor", &AnimationNodeBlendSpace1DEditor::_open_editor); - ClassDB::bind_method("_goto_parent", &AnimationNodeBlendSpace1DEditor::_goto_parent); - ClassDB::bind_method("_removed_from_graph", &AnimationNodeBlendSpace1DEditor::_removed_from_graph); + ClassDB::bind_method("_file_opened", &AnimationNodeBlendSpace1DEditor::_file_opened); } -void AnimationNodeBlendSpace1DEditor::edit(AnimationNodeBlendSpace1D *p_blend_space) { +bool AnimationNodeBlendSpace1DEditor::can_edit(const Ref<AnimationNode> &p_node) { - if (blend_space.is_valid()) { - blend_space->disconnect("removed_from_graph", this, "_removed_from_graph"); - } + Ref<AnimationNodeBlendSpace1D> b1d = p_node; + return b1d.is_valid(); +} - if (p_blend_space) { - blend_space = Ref<AnimationNodeBlendSpace1D>(p_blend_space); - } else { - blend_space.unref(); - } +void AnimationNodeBlendSpace1DEditor::edit(const Ref<AnimationNode> &p_node) { - if (blend_space.is_null()) { - hide(); - } else { - blend_space->connect("removed_from_graph", this, "_removed_from_graph"); + blend_space = p_node; + if (!blend_space.is_null()) { _update_space(); } } @@ -594,15 +585,6 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() { Ref<ButtonGroup> bg; bg.instance(); - goto_parent_hb = memnew(HBoxContainer); - top_hb->add_child(goto_parent_hb); - - goto_parent = memnew(ToolButton); - goto_parent->connect("pressed", this, "_goto_parent", varray(), CONNECT_DEFERRED); - goto_parent_hb->add_child(goto_parent); - goto_parent_hb->add_child(memnew(VSeparator)); - goto_parent_hb->hide(); - tool_blend = memnew(ToolButton); tool_blend->set_toggle_mode(true); tool_blend->set_button_group(bg); @@ -726,13 +708,20 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() { menu = memnew(PopupMenu); add_child(menu); - menu->connect("index_pressed", this, "_add_menu_type"); + menu->connect("id_pressed", this, "_add_menu_type"); animations_menu = memnew(PopupMenu); menu->add_child(animations_menu); animations_menu->set_name("animations"); animations_menu->connect("index_pressed", this, "_add_animation_type"); + open_file = memnew(EditorFileDialog); + add_child(open_file); + open_file->set_title(TTR("Open Animation Node")); + open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE); + open_file->connect("file_selected", this, "_file_opened"); + undo_redo = EditorNode::get_singleton()->get_undo_redo(); + selected_point = -1; dragging_selected = false; dragging_selected_attempt = false; diff --git a/editor/plugins/animation_blend_space_1d_editor.h b/editor/plugins/animation_blend_space_1d_editor.h index 52139626e6..278357b9c7 100644 --- a/editor/plugins/animation_blend_space_1d_editor.h +++ b/editor/plugins/animation_blend_space_1d_editor.h @@ -3,6 +3,7 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" +#include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/property_editor.h" #include "scene/animation/animation_blend_space_1d.h" #include "scene/gui/button.h" @@ -10,9 +11,9 @@ #include "scene/gui/popup.h" #include "scene/gui/tree.h" -class AnimationNodeBlendSpace1DEditor : public VBoxContainer { +class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin { - GDCLASS(AnimationNodeBlendSpace1DEditor, VBoxContainer) + GDCLASS(AnimationNodeBlendSpace1DEditor, AnimationTreeNodeEditorPlugin) Ref<AnimationNodeBlendSpace1D> blend_space; @@ -81,7 +82,17 @@ class AnimationNodeBlendSpace1DEditor : public VBoxContainer { void _goto_parent(); - void _removed_from_graph(); + EditorFileDialog *open_file; + Ref<AnimationNode> file_loaded; + void _file_opened(const String &p_file); + + enum { + MENU_LOAD_FILE = 1000, + MENU_PASTE = 1001, + MENU_LOAD_FILE_CONFIRM = 1002 + }; + + StringName get_blend_position_path() const; protected: void _notification(int p_what); @@ -89,29 +100,9 @@ protected: public: static AnimationNodeBlendSpace1DEditor *get_singleton() { return singleton; } - void edit(AnimationNodeBlendSpace1D *p_blend_space); + virtual bool can_edit(const Ref<AnimationNode> &p_node); + virtual void edit(const Ref<AnimationNode> &p_node); AnimationNodeBlendSpace1DEditor(); }; -class AnimationNodeBlendSpace1DEditorPlugin : public EditorPlugin { - - GDCLASS(AnimationNodeBlendSpace1DEditorPlugin, EditorPlugin) - - AnimationNodeBlendSpace1DEditor *anim_tree_editor; - EditorNode *editor; - Button *button; - -public: - virtual String get_name() const { return "BlendSpace1D"; } - - bool has_main_screen() const { return false; } - - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - - AnimationNodeBlendSpace1DEditorPlugin(EditorNode *p_node); - ~AnimationNodeBlendSpace1DEditorPlugin(); -}; - #endif // ANIMATION_BLEND_SPACE_1D_EDITOR_H diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 27df60f87a..e5476aaf08 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -11,27 +11,26 @@ #include "scene/gui/panel.h" #include "scene/main/viewport.h" -void AnimationNodeBlendSpace2DEditor::edit(AnimationNodeBlendSpace2D *p_blend_space) { +bool AnimationNodeBlendSpace2DEditor::can_edit(const Ref<AnimationNode> &p_node) { - if (blend_space.is_valid()) { - blend_space->disconnect("removed_from_graph", this, "_removed_from_graph"); - } + Ref<AnimationNodeBlendSpace2D> bs2d = p_node; + return bs2d.is_valid(); +} - if (p_blend_space) { - blend_space = Ref<AnimationNodeBlendSpace2D>(p_blend_space); - } else { - blend_space.unref(); - } +void AnimationNodeBlendSpace2DEditor::edit(const Ref<AnimationNode> &p_node) { - if (blend_space.is_null()) { - hide(); - } else { - blend_space->connect("removed_from_graph", this, "_removed_from_graph"); + blend_space = p_node; + if (!blend_space.is_null()) { _update_space(); } } +StringName AnimationNodeBlendSpace2DEditor::get_blend_position_path() const { + StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + "blend_position"; + return path; +} + void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; @@ -54,7 +53,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven ClassDB::get_inheriters_from_class("AnimationRootNode", &classes); menu->add_submenu_item(TTR("Add Animation"), "animations"); - AnimationTree *gp = blend_space->get_tree(); + AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_tree(); ERR_FAIL_COND(!gp); if (gp && gp->has_node(gp->get_animation_player())) { AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player())); @@ -74,10 +73,18 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven if (name == "Animation") continue; // nope int idx = menu->get_item_count(); - menu->add_item(vformat("Add %s", name)); + menu->add_item(vformat("Add %s", name), idx); menu->set_item_metadata(idx, E->get()); } + Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard(); + if (clipb.is_valid()) { + menu->add_separator(); + menu->add_item(TTR("Paste"), MENU_PASTE); + } + menu->add_separator(); + menu->add_item(TTR("Load.."), MENU_LOAD_FILE); + menu->set_global_position(blend_space_draw->get_global_transform().xform(mb->get_position())); menu->popup(); add_point_pos = (mb->get_position() / blend_space_draw->get_size()); @@ -203,7 +210,8 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space()); blend_pos += blend_space->get_min_space(); - blend_space->set_blend_position(blend_pos); + AnimationTreeEditor::get_singleton()->get_tree()->set(get_blend_position_path(), blend_pos); + blend_space_draw->update(); } @@ -237,21 +245,54 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space()); blend_pos += blend_space->get_min_space(); - blend_space->set_blend_position(blend_pos); + AnimationTreeEditor::get_singleton()->get_tree()->set(get_blend_position_path(), blend_pos); + blend_space_draw->update(); } } +void AnimationNodeBlendSpace2DEditor::_file_opened(const String &p_file) { + + file_loaded = ResourceLoader::load(p_file); + if (file_loaded.is_valid()) { + _add_menu_type(MENU_LOAD_FILE_CONFIRM); + } +} + void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) { - String type = menu->get_item_metadata(p_index); + Ref<AnimationRootNode> node; + if (p_index == MENU_LOAD_FILE) { + + open_file->clear_filters(); + List<String> filters; + ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters); + for (List<String>::Element *E = filters.front(); E; E = E->next()) { + open_file->add_filter("*." + E->get()); + } + open_file->popup_centered_ratio(); + return; + } else if (p_index == MENU_LOAD_FILE_CONFIRM) { + node = file_loaded; + file_loaded.unref(); + } else if (p_index == MENU_PASTE) { + + node = EditorSettings::get_singleton()->get_resource_clipboard(); + } else { + String type = menu->get_item_metadata(p_index); + + Object *obj = ClassDB::instance(type); + ERR_FAIL_COND(!obj); + AnimationNode *an = Object::cast_to<AnimationNode>(obj); + ERR_FAIL_COND(!an); - Object *obj = ClassDB::instance(type); - ERR_FAIL_COND(!obj); - AnimationNode *an = Object::cast_to<AnimationNode>(obj); - ERR_FAIL_COND(!an); + node = Ref<AnimationNode>(an); + } - Ref<AnimationNode> node(an); + if (!node.is_valid()) { + EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only root nodes are allowed.")); + return; + } updating = true; undo_redo->create_action("Add Node Point"); @@ -288,7 +329,7 @@ void AnimationNodeBlendSpace2DEditor::_update_tool_erase() { tool_erase->set_disabled(!(selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) && !(selected_triangle >= 0 && selected_triangle < blend_space->get_triangle_count())); if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) { Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point); - if (EditorNode::get_singleton()->item_has_editor(an.ptr())) { + if (AnimationTreeEditor::get_singleton()->can_edit(an)) { open_editor->show(); } else { open_editor->hide(); @@ -490,13 +531,15 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() { color.a *= 0.5; } - Vector2 point = blend_space->get_blend_position(); + Vector2 blend_pos = AnimationTreeEditor::get_singleton()->get_tree()->get(get_blend_position_path()); + Vector2 point = blend_pos; + point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space()); point *= s; point.y = s.height - point.y; if (blend_space->get_triangle_count()) { - Vector2 closest = blend_space->get_closest_point(blend_space->get_blend_position()); + Vector2 closest = blend_space->get_closest_point(blend_pos); closest = (closest - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space()); closest *= s; closest.y = s.height - closest.y; @@ -527,12 +570,6 @@ void AnimationNodeBlendSpace2DEditor::_update_space() { updating = true; - if (blend_space->get_parent().is_valid()) { - goto_parent_hb->show(); - } else { - goto_parent_hb->hide(); - } - if (blend_space->get_auto_triangles()) { tool_triangle->hide(); } else { @@ -685,7 +722,6 @@ void AnimationNodeBlendSpace2DEditor::_notification(int p_what) { tool_erase->set_icon(get_icon("Remove", "EditorIcons")); snap->set_icon(get_icon("SnapGrid", "EditorIcons")); open_editor->set_icon(get_icon("Edit", "EditorIcons")); - goto_parent->set_icon(get_icon("MoveUp", "EditorIcons")); auto_triangles->set_icon(get_icon("AutoTriangle", "EditorIcons")); } @@ -693,12 +729,12 @@ void AnimationNodeBlendSpace2DEditor::_notification(int p_what) { String error; - if (!blend_space->get_tree()) { + if (!AnimationTreeEditor::get_singleton()->get_tree()) { error = TTR("BlendSpace2D does not belong to an AnimationTree node."); - } else if (!blend_space->get_tree()->is_active()) { + } else if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (blend_space->get_tree()->is_state_invalid()) { - error = blend_space->get_tree()->get_invalid_state_reason(); + } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { + error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); } else if (blend_space->get_triangle_count() == 0) { error = TTR("No triangles exist, so no blending can take place."); } @@ -712,22 +748,21 @@ void AnimationNodeBlendSpace2DEditor::_notification(int p_what) { } } } + + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + set_process(is_visible_in_tree()); + } } void AnimationNodeBlendSpace2DEditor::_open_editor() { if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) { Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point); - ERR_FAIL_COND(!an.is_valid()); - EditorNode::get_singleton()->edit_item(an.ptr()); + ERR_FAIL_COND(an.is_null()); + AnimationTreeEditor::get_singleton()->enter_editor(itos(selected_point)); } } -void AnimationNodeBlendSpace2DEditor::_goto_parent() { - - EditorNode::get_singleton()->edit_item(blend_space->get_parent().ptr()); -} - void AnimationNodeBlendSpace2DEditor::_removed_from_graph() { EditorNode::get_singleton()->edit_item(NULL); } @@ -761,11 +796,12 @@ void AnimationNodeBlendSpace2DEditor::_bind_methods() { ClassDB::bind_method("_update_edited_point_pos", &AnimationNodeBlendSpace2DEditor::_update_edited_point_pos); ClassDB::bind_method("_open_editor", &AnimationNodeBlendSpace2DEditor::_open_editor); - ClassDB::bind_method("_goto_parent", &AnimationNodeBlendSpace2DEditor::_goto_parent); ClassDB::bind_method("_removed_from_graph", &AnimationNodeBlendSpace2DEditor::_removed_from_graph); ClassDB::bind_method("_auto_triangles_toggled", &AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled); + + ClassDB::bind_method("_file_opened", &AnimationNodeBlendSpace2DEditor::_file_opened); } AnimationNodeBlendSpace2DEditor *AnimationNodeBlendSpace2DEditor::singleton = NULL; @@ -781,14 +817,6 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() { Ref<ButtonGroup> bg; bg.instance(); - goto_parent_hb = memnew(HBoxContainer); - top_hb->add_child(goto_parent_hb); - goto_parent = memnew(ToolButton); - goto_parent->connect("pressed", this, "_goto_parent", varray(), CONNECT_DEFERRED); - goto_parent_hb->add_child(goto_parent); - goto_parent_hb->add_child(memnew(VSeparator)); - goto_parent_hb->hide(); - tool_blend = memnew(ToolButton); tool_blend->set_toggle_mode(true); tool_blend->set_button_group(bg); @@ -968,56 +996,23 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() { menu = memnew(PopupMenu); add_child(menu); - menu->connect("index_pressed", this, "_add_menu_type"); + menu->connect("id_pressed", this, "_add_menu_type"); animations_menu = memnew(PopupMenu); menu->add_child(animations_menu); animations_menu->set_name("animations"); animations_menu->connect("index_pressed", this, "_add_animation_type"); + open_file = memnew(EditorFileDialog); + add_child(open_file); + open_file->set_title(TTR("Open Animation Node")); + open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE); + open_file->connect("file_selected", this, "_file_opened"); + undo_redo = EditorNode::get_singleton()->get_undo_redo(); + selected_point = -1; selected_triangle = -1; dragging_selected = false; dragging_selected_attempt = false; } - -void AnimationNodeBlendSpace2DEditorPlugin::edit(Object *p_object) { - - anim_tree_editor->edit(Object::cast_to<AnimationNodeBlendSpace2D>(p_object)); -} - -bool AnimationNodeBlendSpace2DEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("AnimationNodeBlendSpace2D"); -} - -void AnimationNodeBlendSpace2DEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - //editor->hide_animation_player_editors(); - //editor->animation_panel_make_visible(true); - button->show(); - editor->make_bottom_panel_item_visible(anim_tree_editor); - anim_tree_editor->set_process(true); - } else { - - if (anim_tree_editor->is_visible_in_tree()) - editor->hide_bottom_panel(); - button->hide(); - anim_tree_editor->set_process(false); - } -} - -AnimationNodeBlendSpace2DEditorPlugin::AnimationNodeBlendSpace2DEditorPlugin(EditorNode *p_node) { - - editor = p_node; - anim_tree_editor = memnew(AnimationNodeBlendSpace2DEditor); - anim_tree_editor->set_custom_minimum_size(Size2(0, 300)); - - button = editor->add_bottom_panel_item(TTR("BlendSpace2D"), anim_tree_editor); - button->hide(); -} - -AnimationNodeBlendSpace2DEditorPlugin::~AnimationNodeBlendSpace2DEditorPlugin() { -} diff --git a/editor/plugins/animation_blend_space_2d_editor.h b/editor/plugins/animation_blend_space_2d_editor.h index a0e497804e..0bf1e25d7a 100644 --- a/editor/plugins/animation_blend_space_2d_editor.h +++ b/editor/plugins/animation_blend_space_2d_editor.h @@ -3,6 +3,7 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" +#include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/property_editor.h" #include "scene/animation/animation_blend_space_2d.h" #include "scene/gui/button.h" @@ -13,15 +14,12 @@ @author Juan Linietsky <reduzio@gmail.com> */ -class AnimationNodeBlendSpace2DEditor : public VBoxContainer { +class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin { - GDCLASS(AnimationNodeBlendSpace2DEditor, VBoxContainer); + GDCLASS(AnimationNodeBlendSpace2DEditor, AnimationTreeNodeEditorPlugin); Ref<AnimationNodeBlendSpace2D> blend_space; - HBoxContainer *goto_parent_hb; - ToolButton *goto_parent; - PanelContainer *panel; ToolButton *tool_blend; ToolButton *tool_select; @@ -93,38 +91,31 @@ class AnimationNodeBlendSpace2DEditor : public VBoxContainer { void _edit_point_pos(double); void _open_editor(); - void _goto_parent(); - void _removed_from_graph(); void _auto_triangles_toggled(); + StringName get_blend_position_path() const; + + EditorFileDialog *open_file; + Ref<AnimationNode> file_loaded; + void _file_opened(const String &p_file); + + enum { + MENU_LOAD_FILE = 1000, + MENU_PASTE = 1001, + MENU_LOAD_FILE_CONFIRM = 1002 + }; + protected: void _notification(int p_what); static void _bind_methods(); public: static AnimationNodeBlendSpace2DEditor *get_singleton() { return singleton; } - void edit(AnimationNodeBlendSpace2D *p_blend_space); + virtual bool can_edit(const Ref<AnimationNode> &p_node); + virtual void edit(const Ref<AnimationNode> &p_node); AnimationNodeBlendSpace2DEditor(); }; -class AnimationNodeBlendSpace2DEditorPlugin : public EditorPlugin { - - GDCLASS(AnimationNodeBlendSpace2DEditorPlugin, EditorPlugin); - - AnimationNodeBlendSpace2DEditor *anim_tree_editor; - EditorNode *editor; - Button *button; - -public: - virtual String get_name() const { return "BlendSpace2D"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - - AnimationNodeBlendSpace2DEditorPlugin(EditorNode *p_node); - ~AnimationNodeBlendSpace2DEditorPlugin(); -}; #endif // ANIMATION_BLEND_SPACE_2D_EDITOR_H diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index c00ad451fa..42e32b9788 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -2,6 +2,7 @@ #include "core/io/resource_loader.h" #include "core/project_settings.h" +#include "editor/editor_inspector.h" #include "os/input.h" #include "os/keyboard.h" #include "scene/animation/animation_player.h" @@ -9,27 +10,6 @@ #include "scene/gui/panel.h" #include "scene/main/viewport.h" -void AnimationNodeBlendTreeEditor::edit(AnimationNodeBlendTree *p_blend_tree) { - - if (blend_tree.is_valid()) { - blend_tree->disconnect("removed_from_graph", this, "_removed_from_graph"); - } - - if (p_blend_tree) { - blend_tree = Ref<AnimationNodeBlendTree>(p_blend_tree); - } else { - blend_tree.unref(); - } - - if (blend_tree.is_null()) { - hide(); - } else { - blend_tree->connect("removed_from_graph", this, "_removed_from_graph"); - - _update_graph(); - } -} - void AnimationNodeBlendTreeEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script) { for (int i = 0; i < add_options.size(); i++) { @@ -58,10 +38,19 @@ void AnimationNodeBlendTreeEditor::remove_custom_type(const Ref<Script> &p_scrip void AnimationNodeBlendTreeEditor::_update_options_menu() { + print_line("update options"); add_node->get_popup()->clear(); for (int i = 0; i < add_options.size(); i++) { - add_node->get_popup()->add_item(add_options[i].name); + add_node->get_popup()->add_item(add_options[i].name, i); } + + Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard(); + if (clipb.is_valid()) { + add_node->get_popup()->add_separator(); + add_node->get_popup()->add_item(TTR("Paste"), MENU_PASTE); + } + add_node->get_popup()->add_separator(); + add_node->get_popup()->add_item(TTR("Load.."), MENU_LOAD_FILE); } Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const { @@ -69,18 +58,28 @@ Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const { return Size2(10, 200); } +void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_property, const Variant &p_value) { + + AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_tree(); + updating = true; + undo_redo->create_action("Parameter Changed: " + String(p_property), UndoRedo::MERGE_ENDS); + undo_redo->add_do_property(tree, p_property, p_value); + undo_redo->add_undo_property(tree, p_property, tree->get(p_property)); + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); + updating = false; +} + void AnimationNodeBlendTreeEditor::_update_graph() { if (updating) return; + visible_properties.clear(); + graph->set_scroll_ofs(blend_tree->get_graph_offset() * EDSCALE); - if (blend_tree->get_parent().is_valid()) { - goto_parent->show(); - } else { - goto_parent->hide(); - } graph->clear_connections(); //erase all nodes for (int i = 0; i < graph->get_child_count(); i++) { @@ -107,7 +106,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { agnode->connect("changed", this, "_node_changed", varray(agnode->get_instance_id()), CONNECT_DEFERRED); } - node->set_offset(agnode->get_position() * EDSCALE); + node->set_offset(blend_tree->get_node_position(E->get()) * EDSCALE); node->set_title(agnode->get_caption()); node->set_name(E->get()); @@ -133,9 +132,28 @@ void AnimationNodeBlendTreeEditor::_update_graph() { node->set_slot(base + i, true, 0, get_color("font_color", "Label"), false, 0, Color()); } - node->connect("dragged", this, "_node_dragged", varray(agnode)); + List<PropertyInfo> pinfo; + agnode->get_parameter_list(&pinfo); + for (List<PropertyInfo>::Element *F = pinfo.front(); F; F = F->next()) { + + if (!(F->get().usage & PROPERTY_USAGE_EDITOR)) { + continue; + } + String base_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E->get()) + "/" + F->get().name; + EditorProperty *prop = EditorInspector::instantiate_property_editor(AnimationTreeEditor::get_singleton()->get_tree(), F->get().type, base_path, F->get().hint, F->get().hint_string, F->get().usage); + if (prop) { + prop->set_object_and_property(AnimationTreeEditor::get_singleton()->get_tree(), base_path); + prop->update_property(); + prop->set_name_split_ratio(0); + prop->connect("property_changed", this, "_property_changed"); + node->add_child(prop); + visible_properties.push_back(prop); + } + } + + node->connect("dragged", this, "_node_dragged", varray(E->get())); - if (EditorNode::get_singleton()->item_has_editor(agnode.ptr())) { + if (AnimationTreeEditor::get_singleton()->can_edit(agnode)) { node->add_child(memnew(HSeparator)); Button *open_in_editor = memnew(Button); open_in_editor->set_text(TTR("Open Editor")); @@ -169,7 +187,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { ProgressBar *pb = memnew(ProgressBar); - AnimationTree *player = anim->get_tree(); + AnimationTree *player = AnimationTreeEditor::get_singleton()->get_tree(); if (player->has_node(player->get_animation_player())) { AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(player->get_node(player->get_animation_player())); if (ap) { @@ -194,6 +212,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { mb->get_popup()->connect("index_pressed", this, "_anim_selected", varray(options, E->get()), CONNECT_DEFERRED); } + /* should be no longer necesary, as the boolean works Ref<AnimationNodeOneShot> oneshot = agnode; if (oneshot.is_valid()) { @@ -209,7 +228,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { play_stop->add_child(stop); play_stop->add_spacer(); node->add_child(play_stop); - } + } */ } List<AnimationNodeBlendTree::NodeConnection> connections; @@ -225,16 +244,44 @@ void AnimationNodeBlendTreeEditor::_update_graph() { } } -void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { +void AnimationNodeBlendTreeEditor::_file_opened(const String &p_file) { - ERR_FAIL_INDEX(p_idx, add_options.size()); + file_loaded = ResourceLoader::load(p_file); + if (file_loaded.is_valid()) { + _add_node(MENU_LOAD_FILE_CONFIRM); + } +} + +void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { Ref<AnimationNode> anode; - if (add_options[p_idx].type != String()) { + String base_name; + + if (p_idx == MENU_LOAD_FILE) { + + open_file->clear_filters(); + List<String> filters; + ResourceLoader::get_recognized_extensions_for_type("AnimationNode", &filters); + for (List<String>::Element *E = filters.front(); E; E = E->next()) { + open_file->add_filter("*." + E->get()); + } + open_file->popup_centered_ratio(); + return; + } else if (p_idx == MENU_LOAD_FILE_CONFIRM) { + anode = file_loaded; + file_loaded.unref(); + base_name = anode->get_class(); + } else if (p_idx == MENU_PASTE) { + + anode = EditorSettings::get_singleton()->get_resource_clipboard(); + ERR_FAIL_COND(!anode.is_valid()); + base_name = anode->get_class(); + } else if (add_options[p_idx].type != String()) { AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instance(add_options[p_idx].type)); ERR_FAIL_COND(!an); anode = Ref<AnimationNode>(an); + base_name = add_options[p_idx].name; } else { ERR_FAIL_COND(add_options[p_idx].script.is_null()); String base_type = add_options[p_idx].script->get_instance_base_type(); @@ -242,13 +289,16 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { ERR_FAIL_COND(!an); anode = Ref<AnimationNode>(an); anode->set_script(add_options[p_idx].script.get_ref_ptr()); + base_name = add_options[p_idx].name; } + Ref<AnimationNodeOutput> out = anode; + if (out.is_valid()) { + EditorNode::get_singleton()->show_warning(TTR("Output node can't be added to the blend tree.")); + return; + } Point2 instance_pos = graph->get_scroll_ofs() + graph->get_size() * 0.5; - anode->set_position(instance_pos / EDSCALE); - - String base_name = add_options[p_idx].name; int base = 1; String name = base_name; while (blend_tree->has_node(name)) { @@ -257,19 +307,19 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { } undo_redo->create_action("Add Node to BlendTree"); - undo_redo->add_do_method(blend_tree.ptr(), "add_node", name, anode); + undo_redo->add_do_method(blend_tree.ptr(), "add_node", name, anode, instance_pos / EDSCALE); undo_redo->add_undo_method(blend_tree.ptr(), "remove_node", name); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); } -void AnimationNodeBlendTreeEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, Ref<AnimationNode> p_node) { +void AnimationNodeBlendTreeEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which) { updating = true; undo_redo->create_action("Node Moved"); - undo_redo->add_do_method(p_node.ptr(), "set_position", p_to / EDSCALE); - undo_redo->add_undo_method(p_node.ptr(), "set_position", p_from / EDSCALE); + undo_redo->add_do_method(blend_tree.ptr(), "set_node_position", p_which, p_to / EDSCALE); + undo_redo->add_undo_method(blend_tree.ptr(), "set_node_position", p_which, p_from / EDSCALE); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); @@ -342,20 +392,6 @@ void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) { undo_redo->commit_action(); } -void AnimationNodeBlendTreeEditor::_oneshot_start(const StringName &p_name) { - - Ref<AnimationNodeOneShot> os = blend_tree->get_node(p_name); - ERR_FAIL_COND(!os.is_valid()); - os->start(); -} - -void AnimationNodeBlendTreeEditor::_oneshot_stop(const StringName &p_name) { - - Ref<AnimationNodeOneShot> os = blend_tree->get_node(p_name); - ERR_FAIL_COND(!os.is_valid()); - os->stop(); -} - void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) { GraphNode *gn = Object::cast_to<GraphNode>(p_node); @@ -373,13 +409,7 @@ void AnimationNodeBlendTreeEditor::_open_in_editor(const String &p_which) { Ref<AnimationNode> an = blend_tree->get_node(p_which); ERR_FAIL_COND(!an.is_valid()) - EditorNode::get_singleton()->edit_item(an.ptr()); -} - -void AnimationNodeBlendTreeEditor::_open_parent() { - if (blend_tree->get_parent().is_valid()) { - EditorNode::get_singleton()->edit_item(blend_tree->get_parent().ptr()); - } + AnimationTreeEditor::get_singleton()->enter_editor(p_which); } void AnimationNodeBlendTreeEditor::_filter_toggled() { @@ -417,14 +447,14 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano if (updating || _filter_edit != anode) return false; - NodePath player_path = anode->get_tree()->get_animation_player(); + NodePath player_path = AnimationTreeEditor::get_singleton()->get_tree()->get_animation_player(); - if (!anode->get_tree()->has_node(player_path)) { + if (!AnimationTreeEditor::get_singleton()->get_tree()->has_node(player_path)) { EditorNode::get_singleton()->show_warning(TTR("No animation player set, so unable to retrieve track names.")); return false; } - AnimationPlayer *player = Object::cast_to<AnimationPlayer>(anode->get_tree()->get_node(player_path)); + AnimationPlayer *player = Object::cast_to<AnimationPlayer>(AnimationTreeEditor::get_singleton()->get_tree()->get_node(player_path)); if (!player) { EditorNode::get_singleton()->show_warning(TTR("Player path set is invalid, so unable to retrieve track names.")); return false; @@ -593,8 +623,6 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - goto_parent->set_icon(get_icon("MoveUp", "EditorIcons")); - error_panel->add_style_override("panel", get_stylebox("bg", "Tree")); error_label->add_color_override("font_color", get_color("error_color", "Editor")); } @@ -603,12 +631,10 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { String error; - if (!blend_tree->get_tree()) { - error = TTR("BlendTree does not belong to an AnimationTree node."); - } else if (!blend_tree->get_tree()->is_active()) { + if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (blend_tree->get_tree()->is_state_invalid()) { - error = blend_tree->get_tree()->get_invalid_state_reason(); + } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { + error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); } if (error != error_label->get_text()) { @@ -624,13 +650,13 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { blend_tree->get_node_connections(&conns); for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = conns.front(); E; E = E->next()) { float activity = 0; - if (blend_tree->get_tree() && !blend_tree->get_tree()->is_state_invalid()) { + if (AnimationTreeEditor::get_singleton()->get_tree() && !AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { activity = blend_tree->get_connection_activity(E->get().input_node, E->get().input_index); } graph->set_connection_activity(E->get().output_node, 0, E->get().input_node, E->get().input_index, activity); } - AnimationTree *graph_player = blend_tree->get_tree(); + AnimationTree *graph_player = AnimationTreeEditor::get_singleton()->get_tree(); AnimationPlayer *player = NULL; if (graph_player->has_node(graph_player->get_animation_player())) { player = Object::cast_to<AnimationPlayer>(graph_player->get_node(graph_player->get_animation_player())); @@ -650,6 +676,14 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { } } } + + for (int i = 0; i < visible_properties.size(); i++) { + visible_properties[i]->update_property(); + } + } + + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + set_process(is_visible_in_tree()); } } @@ -664,9 +698,9 @@ void AnimationNodeBlendTreeEditor::_scroll_changed(const Vector2 &p_scroll) { void AnimationNodeBlendTreeEditor::_node_changed(ObjectID p_node) { AnimationNode *an = Object::cast_to<AnimationNode>(ObjectDB::get_instance(p_node)); - if (an && an->get_parent() == blend_tree) { - _update_graph(); - } + //if (an && an->get_parent() == blend_tree) { + _update_graph(); + //} } void AnimationNodeBlendTreeEditor::_bind_methods() { @@ -680,17 +714,17 @@ void AnimationNodeBlendTreeEditor::_bind_methods() { ClassDB::bind_method("_disconnection_request", &AnimationNodeBlendTreeEditor::_disconnection_request); ClassDB::bind_method("_node_selected", &AnimationNodeBlendTreeEditor::_node_selected); ClassDB::bind_method("_open_in_editor", &AnimationNodeBlendTreeEditor::_open_in_editor); - ClassDB::bind_method("_open_parent", &AnimationNodeBlendTreeEditor::_open_parent); ClassDB::bind_method("_scroll_changed", &AnimationNodeBlendTreeEditor::_scroll_changed); ClassDB::bind_method("_delete_request", &AnimationNodeBlendTreeEditor::_delete_request); ClassDB::bind_method("_edit_filters", &AnimationNodeBlendTreeEditor::_edit_filters); ClassDB::bind_method("_update_filters", &AnimationNodeBlendTreeEditor::_update_filters); ClassDB::bind_method("_filter_edited", &AnimationNodeBlendTreeEditor::_filter_edited); ClassDB::bind_method("_filter_toggled", &AnimationNodeBlendTreeEditor::_filter_toggled); - ClassDB::bind_method("_oneshot_start", &AnimationNodeBlendTreeEditor::_oneshot_start); - ClassDB::bind_method("_oneshot_stop", &AnimationNodeBlendTreeEditor::_oneshot_stop); ClassDB::bind_method("_node_changed", &AnimationNodeBlendTreeEditor::_node_changed); ClassDB::bind_method("_removed_from_graph", &AnimationNodeBlendTreeEditor::_removed_from_graph); + ClassDB::bind_method("_property_changed", &AnimationNodeBlendTreeEditor::_property_changed); + ClassDB::bind_method("_file_opened", &AnimationNodeBlendTreeEditor::_file_opened); + ClassDB::bind_method("_update_options_menu", &AnimationNodeBlendTreeEditor::_update_options_menu); ClassDB::bind_method("_anim_selected", &AnimationNodeBlendTreeEditor::_anim_selected); } @@ -708,7 +742,9 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima ERR_FAIL_COND(new_name == "" || new_name.find(".") != -1 || new_name.find("/") != -1) - ERR_FAIL_COND(new_name == prev_name); + if (new_name == prev_name) { + return; //nothing to do + } String base_name = new_name; int base = 1; @@ -718,22 +754,61 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima name = base_name + " " + itos(base); } + String base_path = AnimationTreeEditor::get_singleton()->get_base_path(); + updating = true; undo_redo->create_action("Node Renamed"); undo_redo->add_do_method(blend_tree.ptr(), "rename_node", prev_name, name); undo_redo->add_undo_method(blend_tree.ptr(), "rename_node", name, prev_name); + undo_redo->add_do_method(AnimationTreeEditor::get_singleton()->get_tree(), "rename_parameter", base_path + prev_name, base_path + name); + undo_redo->add_undo_method(AnimationTreeEditor::get_singleton()->get_tree(), "rename_parameter", base_path + name, base_path + prev_name); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); updating = false; gn->set_name(new_name); gn->set_size(gn->get_minimum_size()); + + //change editors accordingly + for (int i = 0; i < visible_properties.size(); i++) { + String pname = visible_properties[i]->get_edited_property().operator String(); + if (pname.begins_with(base_path + prev_name)) { + String new_name = pname.replace_first(base_path + prev_name, base_path + name); + visible_properties[i]->set_object_and_property(visible_properties[i]->get_edited_object(), new_name); + } + } } void AnimationNodeBlendTreeEditor::_node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node) { _node_renamed(le->call("get_text"), p_node); } +bool AnimationNodeBlendTreeEditor::can_edit(const Ref<AnimationNode> &p_node) { + Ref<AnimationNodeBlendTree> bt = p_node; + return bt.is_valid(); +} + +void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) { + + if (blend_tree.is_valid()) { + blend_tree->disconnect("removed_from_graph", this, "_removed_from_graph"); + } + + if (p_node.is_valid()) { + blend_tree = p_node; + } else { + blend_tree.unref(); + } + + if (blend_tree.is_null()) { + hide(); + } else { + blend_tree->connect("removed_from_graph", this, "_removed_from_graph"); + + _update_graph(); + } +} + AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() { singleton = this; @@ -757,13 +832,8 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() { graph->get_zoom_hbox()->add_child(add_node); add_node->set_text(TTR("Add Node..")); graph->get_zoom_hbox()->move_child(add_node, 0); - add_node->get_popup()->connect("index_pressed", this, "_add_node"); - - goto_parent = memnew(Button); - graph->get_zoom_hbox()->add_child(goto_parent); - graph->get_zoom_hbox()->move_child(goto_parent, 0); - goto_parent->hide(); - goto_parent->connect("pressed", this, "_open_parent"); + add_node->get_popup()->connect("id_pressed", this, "_add_node"); + add_node->connect("about_to_show", this, "_update_options_menu"); add_options.push_back(AddOption("Animation", "AnimationNodeAnimation")); add_options.push_back(AddOption("OneShot", "AnimationNodeOneShot")); @@ -804,45 +874,10 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() { filters->set_hide_root(true); filters->connect("item_edited", this, "_filter_edited"); + open_file = memnew(EditorFileDialog); + add_child(open_file); + open_file->set_title(TTR("Open Animation Node")); + open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE); + open_file->connect("file_selected", this, "_file_opened"); undo_redo = EditorNode::get_singleton()->get_undo_redo(); } - -void AnimationNodeBlendTreeEditorPlugin::edit(Object *p_object) { - - anim_tree_editor->edit(Object::cast_to<AnimationNodeBlendTree>(p_object)); -} - -bool AnimationNodeBlendTreeEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("AnimationNodeBlendTree"); -} - -void AnimationNodeBlendTreeEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - //editor->hide_animation_player_editors(); - //editor->animation_panel_make_visible(true); - button->show(); - editor->make_bottom_panel_item_visible(anim_tree_editor); - anim_tree_editor->set_process(true); - } else { - - if (anim_tree_editor->is_visible_in_tree()) - editor->hide_bottom_panel(); - button->hide(); - anim_tree_editor->set_process(false); - } -} - -AnimationNodeBlendTreeEditorPlugin::AnimationNodeBlendTreeEditorPlugin(EditorNode *p_node) { - - editor = p_node; - anim_tree_editor = memnew(AnimationNodeBlendTreeEditor); - anim_tree_editor->set_custom_minimum_size(Size2(0, 300)); - - button = editor->add_bottom_panel_item(TTR("BlendTree"), anim_tree_editor); - button->hide(); -} - -AnimationNodeBlendTreeEditorPlugin::~AnimationNodeBlendTreeEditorPlugin() { -} diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index deba3b2b0e..35ecc32979 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -3,6 +3,7 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" +#include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/property_editor.h" #include "scene/animation/animation_blend_tree.h" #include "scene/gui/button.h" @@ -13,14 +14,13 @@ @author Juan Linietsky <reduzio@gmail.com> */ -class AnimationNodeBlendTreeEditor : public VBoxContainer { +class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { - GDCLASS(AnimationNodeBlendTreeEditor, VBoxContainer); + GDCLASS(AnimationNodeBlendTreeEditor, AnimationTreeNodeEditorPlugin); Ref<AnimationNodeBlendTree> blend_tree; GraphEdit *graph; MenuButton *add_node; - Button *goto_parent; PanelContainer *error_panel; Label *error_label; @@ -32,6 +32,7 @@ class AnimationNodeBlendTreeEditor : public VBoxContainer { CheckBox *filter_enabled; Map<StringName, ProgressBar *> animations; + Vector<EditorProperty *> visible_properties; void _update_graph(); @@ -52,7 +53,7 @@ class AnimationNodeBlendTreeEditor : public VBoxContainer { static AnimationNodeBlendTreeEditor *singleton; - void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, Ref<AnimationNode> p_node); + void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which); void _node_renamed(const String &p_text, Ref<AnimationNode> p_node); void _node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node); @@ -64,11 +65,8 @@ class AnimationNodeBlendTreeEditor : public VBoxContainer { void _scroll_changed(const Vector2 &p_scroll); void _node_selected(Object *p_node); void _open_in_editor(const String &p_which); - void _open_parent(); void _anim_selected(int p_index, Array p_options, const String &p_node); void _delete_request(const String &p_which); - void _oneshot_start(const StringName &p_name); - void _oneshot_stop(const StringName &p_name); bool _update_filters(const Ref<AnimationNode> &anode); void _edit_filters(const String &p_which); @@ -78,8 +76,19 @@ class AnimationNodeBlendTreeEditor : public VBoxContainer { void _node_changed(ObjectID p_node); + void _property_changed(const StringName &p_property, const Variant &p_value); void _removed_from_graph(); + EditorFileDialog *open_file; + Ref<AnimationNode> file_loaded; + void _file_opened(const String &p_file); + + enum { + MENU_LOAD_FILE = 1000, + MENU_PASTE = 1001, + MENU_LOAD_FILE_CONFIRM = 1002 + }; + protected: void _notification(int p_what); static void _bind_methods(); @@ -91,27 +100,11 @@ public: void remove_custom_type(const Ref<Script> &p_script); virtual Size2 get_minimum_size() const; - void edit(AnimationNodeBlendTree *p_blend_tree); - AnimationNodeBlendTreeEditor(); -}; -class AnimationNodeBlendTreeEditorPlugin : public EditorPlugin { + virtual bool can_edit(const Ref<AnimationNode> &p_node); + virtual void edit(const Ref<AnimationNode> &p_node); - GDCLASS(AnimationNodeBlendTreeEditorPlugin, EditorPlugin); - - AnimationNodeBlendTreeEditor *anim_tree_editor; - EditorNode *editor; - Button *button; - -public: - virtual String get_name() const { return "BlendTree"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - - AnimationNodeBlendTreeEditorPlugin(EditorNode *p_node); - ~AnimationNodeBlendTreeEditorPlugin(); + AnimationNodeBlendTreeEditor(); }; #endif // ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index ee450333c8..3a65cb9b38 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -11,22 +11,17 @@ #include "scene/gui/panel.h" #include "scene/main/viewport.h" -void AnimationNodeStateMachineEditor::edit(AnimationNodeStateMachine *p_state_machine) { +bool AnimationNodeStateMachineEditor::can_edit(const Ref<AnimationNode> &p_node) { - if (state_machine.is_valid()) { - state_machine->disconnect("removed_from_graph", this, "_removed_from_graph"); - } + Ref<AnimationNodeStateMachine> ansm = p_node; + return ansm.is_valid(); +} - if (p_state_machine) { - state_machine = Ref<AnimationNodeStateMachine>(p_state_machine); - } else { - state_machine.unref(); - } +void AnimationNodeStateMachineEditor::edit(const Ref<AnimationNode> &p_node) { - if (state_machine.is_null()) { - hide(); - } else { - state_machine->connect("removed_from_graph", this, "_removed_from_graph"); + state_machine = p_node; + + if (state_machine.is_valid()) { selected_transition_from = StringName(); selected_transition_to = StringName(); @@ -38,6 +33,10 @@ void AnimationNodeStateMachineEditor::edit(AnimationNodeStateMachine *p_state_ma void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEvent> &p_event) { + Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); + if (playback.is_null()) + return; + Ref<InputEventKey> k = p_event; if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && !k->is_echo()) { if (selected_node != StringName() || selected_transition_to != StringName() || selected_transition_from != StringName()) { @@ -59,7 +58,7 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv ClassDB::get_inheriters_from_class("AnimationRootNode", &classes); menu->add_submenu_item(TTR("Add Animation"), "animations"); - AnimationTree *gp = state_machine->get_tree(); + AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_tree(); ERR_FAIL_COND(!gp); if (gp && gp->has_node(gp->get_animation_player())) { AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player())); @@ -79,9 +78,17 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv if (name == "Animation") continue; // nope int idx = menu->get_item_count(); - menu->add_item(vformat("Add %s", name)); + menu->add_item(vformat("Add %s", name), idx); menu->set_item_metadata(idx, E->get()); } + Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard(); + + if (clipb.is_valid()) { + menu->add_separator(); + menu->add_item(TTR("Paste"), MENU_PASTE); + } + menu->add_separator(); + menu->add_item(TTR("Load.."), MENU_LOAD_FILE); menu->set_global_position(state_machine_draw->get_global_transform().xform(mb->get_position())); menu->popup(); @@ -98,18 +105,12 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv for (int i = node_rects.size() - 1; i >= 0; i--) { //inverse to draw order if (node_rects[i].play.has_point(mb->get_position())) { //edit name - if (play_mode->get_selected() == 1 || !state_machine->is_playing()) { + if (play_mode->get_selected() == 1 || !playback->is_playing()) { //start - state_machine->start(node_rects[i].node_name); + playback->start(node_rects[i].node_name); } else { //travel - if (!state_machine->travel(node_rects[i].node_name)) { - - state_machine->start(node_rects[i].node_name); - //removing this due to usability.. - //error_time = 5; - //error_text = vformat(TTR("No path found from '%s' to '%s'."), state_machine->get_current_node(), node_rects[i].node_name); - } + playback->travel(node_rects[i].node_name); } state_machine_draw->update(); return; @@ -196,8 +197,8 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv Ref<AnimationNode> an = state_machine->get_node(selected_node); updating = true; undo_redo->create_action("Move Node"); - undo_redo->add_do_method(an.ptr(), "set_position", an->get_position() + drag_ofs / EDSCALE); - undo_redo->add_undo_method(an.ptr(), "set_position", an->get_position()); + undo_redo->add_do_method(state_machine.ptr(), "set_node_position", selected_node, state_machine->get_node_position(selected_node) + drag_ofs / EDSCALE); + undo_redo->add_undo_method(state_machine.ptr(), "set_node_position", selected_node, state_machine->get_node_position(selected_node)); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); @@ -293,7 +294,7 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv snap_y = StringName(); { //snap - Vector2 cpos = state_machine->get_node(selected_node)->get_position() + drag_ofs / EDSCALE; + Vector2 cpos = state_machine->get_node_position(selected_node) + drag_ofs / EDSCALE; List<StringName> nodes; state_machine->get_node_list(&nodes); @@ -303,7 +304,7 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) { if (E->get() == selected_node) continue; - Vector2 npos = state_machine->get_node(E->get())->get_position(); + Vector2 npos = state_machine->get_node_position(E->get()); float d_x = ABS(npos.x - cpos.x); if (d_x < MIN(5, best_d_x)) { @@ -372,19 +373,58 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv } } +void AnimationNodeStateMachineEditor::_file_opened(const String &p_file) { + + file_loaded = ResourceLoader::load(p_file); + if (file_loaded.is_valid()) { + _add_menu_type(MENU_LOAD_FILE_CONFIRM); + } +} + void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) { - String type = menu->get_item_metadata(p_index); + String base_name; + Ref<AnimationRootNode> node; - Object *obj = ClassDB::instance(type); - ERR_FAIL_COND(!obj); - AnimationNode *an = Object::cast_to<AnimationNode>(obj); - ERR_FAIL_COND(!an); + if (p_index == MENU_LOAD_FILE) { - Ref<AnimationNode> node(an); - node->set_position(add_node_pos); + open_file->clear_filters(); + List<String> filters; + ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters); + for (List<String>::Element *E = filters.front(); E; E = E->next()) { + open_file->add_filter("*." + E->get()); + } + open_file->popup_centered_ratio(); + return; + } else if (p_index == MENU_LOAD_FILE_CONFIRM) { + node = file_loaded; + file_loaded.unref(); + } else if (p_index == MENU_PASTE) { + + node = EditorSettings::get_singleton()->get_resource_clipboard(); + + } else { + String type = menu->get_item_metadata(p_index); + + Object *obj = ClassDB::instance(type); + ERR_FAIL_COND(!obj); + AnimationNode *an = Object::cast_to<AnimationNode>(obj); + ERR_FAIL_COND(!an); + + node = Ref<AnimationNode>(an); + base_name = type.replace_first("AnimationNode", ""); + } + + if (!node.is_valid()) { + EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only root nodes are allowed.")); + return; + } + + if (base_name == String()) { + + base_name = node->get_class().replace_first("AnimationNode", ""); + } - String base_name = type.replace_first("AnimationNode", ""); int base = 1; String name = base_name; while (state_machine->has_node(name)) { @@ -394,7 +434,7 @@ void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) { updating = true; undo_redo->create_action("Add Node"); - undo_redo->add_do_method(state_machine.ptr(), "add_node", name, node); + undo_redo->add_do_method(state_machine.ptr(), "add_node", name, node, add_node_pos); undo_redo->add_undo_method(state_machine.ptr(), "remove_node", name); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); @@ -419,11 +459,9 @@ void AnimationNodeStateMachineEditor::_add_animation_type(int p_index) { name = base_name + " " + itos(base); } - anim->set_position(add_node_pos); - updating = true; undo_redo->create_action("Add Node"); - undo_redo->add_do_method(state_machine.ptr(), "add_node", name, anim); + undo_redo->add_do_method(state_machine.ptr(), "add_node", name, anim, add_node_pos); undo_redo->add_undo_method(state_machine.ptr(), "remove_node", name); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); @@ -502,6 +540,8 @@ void AnimationNodeStateMachineEditor::_clip_dst_line_to_rect(Vector2 &r_from, Ve void AnimationNodeStateMachineEditor::_state_machine_draw() { + Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); + Ref<StyleBox> style = get_stylebox("frame", "GraphNode"); Ref<StyleBox> style_selected = get_stylebox("selectedframe", "GraphNode"); @@ -515,10 +555,17 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { linecolor.a *= 0.3; Ref<StyleBox> playing_overlay = get_stylebox("position", "GraphNode"); - bool playing = state_machine->is_playing(); - StringName current = state_machine->get_current_node(); - StringName blend_from = state_machine->get_blend_from_node(); - Vector<StringName> travel_path = state_machine->get_travel_path(); + bool playing = false; + StringName current; + StringName blend_from; + Vector<StringName> travel_path; + + if (playback.is_valid()) { + playing = playback->is_playing(); + current = playback->get_current_node(); + blend_from = playback->get_blend_from_node(); + travel_path = playback->get_travel_path(); + } if (state_machine_draw->has_focus()) { state_machine_draw->draw_rect(Rect2(Point2(), state_machine_draw->get_size()), accent, false); @@ -534,13 +581,13 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { //snap lines if (dragging_selected) { - Vector2 from = (state_machine->get_node(selected_node)->get_position() * EDSCALE) + drag_ofs - state_machine->get_graph_offset() * EDSCALE; + Vector2 from = (state_machine->get_node_position(selected_node) * EDSCALE) + drag_ofs - state_machine->get_graph_offset() * EDSCALE; if (snap_x != StringName()) { - Vector2 to = (state_machine->get_node(snap_x)->get_position() * EDSCALE) - state_machine->get_graph_offset() * EDSCALE; + Vector2 to = (state_machine->get_node_position(snap_x) * EDSCALE) - state_machine->get_graph_offset() * EDSCALE; state_machine_draw->draw_line(from, to, linecolor, 2); } if (snap_y != StringName()) { - Vector2 to = (state_machine->get_node(snap_y)->get_position() * EDSCALE) - state_machine->get_graph_offset() * EDSCALE; + Vector2 to = (state_machine->get_node_position(snap_y) * EDSCALE) - state_machine->get_graph_offset() * EDSCALE; state_machine_draw->draw_line(from, to, linecolor, 2); } } @@ -563,7 +610,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } Vector2 offset; - offset += anode->get_position() * EDSCALE; + offset += state_machine->get_node_position(E->get()) * EDSCALE; if (selected_node == E->get() && dragging_selected) { offset += drag_ofs; } @@ -588,10 +635,10 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { //draw conecting line for potential new transition if (connecting) { - Vector2 from = (state_machine->get_node(connecting_from)->get_position() * EDSCALE) - state_machine->get_graph_offset() * EDSCALE; + Vector2 from = (state_machine->get_node_position(connecting_from) * EDSCALE) - state_machine->get_graph_offset() * EDSCALE; Vector2 to; if (connecting_to_node != StringName()) { - to = (state_machine->get_node(connecting_to_node)->get_position() * EDSCALE) - state_machine->get_graph_offset() * EDSCALE; + to = (state_machine->get_node_position(connecting_to_node) * EDSCALE) - state_machine->get_graph_offset() * EDSCALE; } else { to = connecting_to; } @@ -617,15 +664,17 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { TransitionLine tl; tl.from_node = state_machine->get_transition_from(i); Vector2 ofs_from = (dragging_selected && tl.from_node == selected_node) ? drag_ofs : Vector2(); - tl.from = (state_machine->get_node(tl.from_node)->get_position() * EDSCALE) + ofs_from - state_machine->get_graph_offset() * EDSCALE; + tl.from = (state_machine->get_node_position(tl.from_node) * EDSCALE) + ofs_from - state_machine->get_graph_offset() * EDSCALE; tl.to_node = state_machine->get_transition_to(i); Vector2 ofs_to = (dragging_selected && tl.to_node == selected_node) ? drag_ofs : Vector2(); - tl.to = (state_machine->get_node(tl.to_node)->get_position() * EDSCALE) + ofs_to - state_machine->get_graph_offset() * EDSCALE; + tl.to = (state_machine->get_node_position(tl.to_node) * EDSCALE) + ofs_to - state_machine->get_graph_offset() * EDSCALE; Ref<AnimationNodeStateMachineTransition> tr = state_machine->get_transition(i); tl.disabled = tr->is_disabled(); tl.auto_advance = tr->has_auto_advance(); + tl.advance_condition_name = tr->get_advance_condition_name(); + tl.advance_condition_state = false; tl.mode = tr->get_switch_mode(); tl.width = tr_bidi_offset; @@ -665,7 +714,14 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } } } - _connection_draw(tl.from, tl.to, tl.mode, !tl.disabled, selected, travel, tl.auto_advance); + + bool auto_advance = tl.auto_advance; + StringName fullpath = AnimationTreeEditor::get_singleton()->get_base_path() + String(tl.advance_condition_name); + if (tl.advance_condition_name != StringName() && bool(AnimationTreeEditor::get_singleton()->get_tree()->get(fullpath))) { + tl.advance_condition_state = true; + auto_advance = true; + } + _connection_draw(tl.from, tl.to, tl.mode, !tl.disabled, selected, travel, auto_advance); transition_lines.push_back(tl); } @@ -675,7 +731,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { String name = node_rects[i].node_name; Ref<AnimationNode> anode = state_machine->get_node(name); - bool needs_editor = EditorNode::get_singleton()->item_has_editor(anode.ptr()); + bool needs_editor = AnimationTreeEditor::get_singleton()->can_edit(anode); Ref<StyleBox> sb = name == selected_node ? style_selected : style; int strsize = font->get_string_size(name).width; @@ -757,12 +813,14 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { void AnimationNodeStateMachineEditor::_state_machine_pos_draw() { - if (!state_machine->is_playing()) + Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); + + if (!playback.is_valid() || !playback->is_playing()) return; int idx = -1; for (int i = 0; node_rects.size(); i++) { - if (node_rects[i].node_name == state_machine->get_current_node()) { + if (node_rects[i].node_name == playback->get_current_node()) { idx = i; break; } @@ -785,9 +843,9 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() { } to.y = from.y; - float len = MAX(0.0001, state_machine->get_current_length()); + float len = MAX(0.0001, playback->get_current_length()); - float pos = CLAMP(state_machine->get_current_play_pos(), 0, len); + float pos = CLAMP(playback->get_current_play_pos(), 0, len); float c = pos / len; Color fg = get_color("font_color", "Label"); Color bg = fg; @@ -807,12 +865,6 @@ void AnimationNodeStateMachineEditor::_update_graph() { updating = true; - if (state_machine->get_parent().is_valid()) { - goto_parent_hbox->show(); - } else { - goto_parent_hbox->hide(); - } - state_machine_draw->update(); updating = false; @@ -824,7 +876,6 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { error_panel->add_style_override("panel", get_stylebox("bg", "Tree")); error_label->add_color_override("font_color", get_color("error_color", "Editor")); panel->add_style_override("panel", get_stylebox("bg", "Tree")); - goto_parent->set_icon(get_icon("MoveUp", "EditorIcons")); tool_select->set_icon(get_icon("ToolSelect", "EditorIcons")); tool_create->set_icon(get_icon("ToolAddNode", "EditorIcons")); @@ -856,19 +907,21 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { String error; + Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); + if (error_time > 0) { error = error_text; error_time -= get_process_delta_time(); - } else if (!state_machine->get_tree()) { - error = TTR("StateMachine does not belong to an AnimationTree node."); - } else if (!state_machine->get_tree()->is_active()) { + } else if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) { error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails."); - } else if (state_machine->get_tree()->is_state_invalid()) { - error = state_machine->get_tree()->get_invalid_state_reason(); - } else if (state_machine->get_parent().is_valid() && state_machine->get_parent()->is_class("AnimationNodeStateMachine")) { + } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { + error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason(); + /*} else if (state_machine->get_parent().is_valid() && state_machine->get_parent()->is_class("AnimationNodeStateMachine")) { if (state_machine->get_start_node() == StringName() || state_machine->get_end_node() == StringName()) { error = TTR("Start and end nodes are needed for a sub-transition."); - } + }*/ + } else if (playback.is_null()) { + error = vformat(TTR("No playback resource set at path: %s."), AnimationTreeEditor::get_singleton()->get_base_path() + "playback"); } if (error != error_label->get_text()) { @@ -904,14 +957,38 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { break; } + if (transition_lines[i].advance_condition_name != state_machine->get_transition(tidx)->get_advance_condition_name()) { + state_machine_draw->update(); + break; + } + if (transition_lines[i].mode != state_machine->get_transition(tidx)->get_switch_mode()) { state_machine_draw->update(); break; } + + bool acstate = transition_lines[i].advance_condition_name != StringName() && bool(AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + String(transition_lines[i].advance_condition_name))); + + if (transition_lines[i].advance_condition_state != acstate) { + state_machine_draw->update(); + break; + } } bool same_travel_path = true; - Vector<StringName> tp = state_machine->get_travel_path(); + Vector<StringName> tp; + bool is_playing = false; + StringName current_node; + StringName blend_from_node; + float play_pos = 0; + + if (playback.is_valid()) { + tp = playback->get_travel_path(); + is_playing = playback->is_playing(); + current_node = playback->get_current_node(); + blend_from_node = playback->get_blend_from_node(); + play_pos = playback->get_current_play_pos(); + } { @@ -928,37 +1005,32 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) { } //update if travel state changed - if (!same_travel_path || last_active != state_machine->is_playing() || last_current_node != state_machine->get_current_node() || last_blend_from_node != state_machine->get_blend_from_node()) { + if (!same_travel_path || last_active != is_playing || last_current_node != current_node || last_blend_from_node != blend_from_node) { state_machine_draw->update(); last_travel_path = tp; - last_current_node = state_machine->get_current_node(); - last_active = state_machine->is_playing(); - last_blend_from_node = state_machine->get_blend_from_node(); + last_current_node = current_node; + last_active = is_playing; + last_blend_from_node = blend_from_node; state_machine_play_pos->update(); } - if (last_play_pos != state_machine->get_current_play_pos()) { + if (last_play_pos != play_pos) { - last_play_pos = state_machine->get_current_play_pos(); + last_play_pos = play_pos; state_machine_play_pos->update(); } } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { over_node = StringName(); + set_process(is_visible_in_tree()); } } void AnimationNodeStateMachineEditor::_open_editor(const String &p_name) { - Ref<AnimationNode> an = state_machine->get_node(p_name); - ERR_FAIL_COND(!an.is_valid()); - EditorNode::get_singleton()->edit_item(an.ptr()); -} - -void AnimationNodeStateMachineEditor::_goto_parent() { - EditorNode::get_singleton()->edit_item(state_machine->get_parent().ptr()); + AnimationTreeEditor::get_singleton()->enter_editor(p_name); } void AnimationNodeStateMachineEditor::_removed_from_graph() { @@ -1114,7 +1186,6 @@ void AnimationNodeStateMachineEditor::_bind_methods() { ClassDB::bind_method("_name_edited", &AnimationNodeStateMachineEditor::_name_edited); - ClassDB::bind_method("_goto_parent", &AnimationNodeStateMachineEditor::_goto_parent); ClassDB::bind_method("_removed_from_graph", &AnimationNodeStateMachineEditor::_removed_from_graph); ClassDB::bind_method("_open_editor", &AnimationNodeStateMachineEditor::_open_editor); @@ -1124,6 +1195,7 @@ void AnimationNodeStateMachineEditor::_bind_methods() { ClassDB::bind_method("_autoplay_selected", &AnimationNodeStateMachineEditor::_autoplay_selected); ClassDB::bind_method("_end_selected", &AnimationNodeStateMachineEditor::_end_selected); ClassDB::bind_method("_update_mode", &AnimationNodeStateMachineEditor::_update_mode); + ClassDB::bind_method("_file_opened", &AnimationNodeStateMachineEditor::_file_opened); } AnimationNodeStateMachineEditor *AnimationNodeStateMachineEditor::singleton = NULL; @@ -1136,13 +1208,6 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { HBoxContainer *top_hb = memnew(HBoxContainer); add_child(top_hb); - goto_parent_hbox = memnew(HBoxContainer); - goto_parent = memnew(ToolButton); - goto_parent->connect("pressed", this, "_goto_parent", varray(), CONNECT_DEFERRED); - goto_parent_hbox->add_child(goto_parent); - goto_parent_hbox->add_child(memnew(VSeparator)); - top_hb->add_child(goto_parent_hbox); - Ref<ButtonGroup> bg; bg.instance(); @@ -1248,7 +1313,7 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { menu = memnew(PopupMenu); add_child(menu); - menu->connect("index_pressed", this, "_add_menu_type"); + menu->connect("id_pressed", this, "_add_menu_type"); animations_menu = memnew(PopupMenu); menu->add_child(animations_menu); @@ -1261,6 +1326,13 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { name_edit->connect("text_entered", this, "_name_edited"); name_edit->set_as_toplevel(true); + open_file = memnew(EditorFileDialog); + add_child(open_file); + open_file->set_title(TTR("Open Animation Node")); + open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE); + open_file->connect("file_selected", this, "_file_opened"); + undo_redo = EditorNode::get_singleton()->get_undo_redo(); + over_text = false; over_node_what = -1; @@ -1271,43 +1343,3 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { error_time = 0; } - -void AnimationNodeStateMachineEditorPlugin::edit(Object *p_object) { - - anim_tree_editor->edit(Object::cast_to<AnimationNodeStateMachine>(p_object)); -} - -bool AnimationNodeStateMachineEditorPlugin::handles(Object *p_object) const { - - return p_object->is_class("AnimationNodeStateMachine"); -} - -void AnimationNodeStateMachineEditorPlugin::make_visible(bool p_visible) { - - if (p_visible) { - //editor->hide_animation_player_editors(); - //editor->animation_panel_make_visible(true); - button->show(); - editor->make_bottom_panel_item_visible(anim_tree_editor); - anim_tree_editor->set_process(true); - } else { - - if (anim_tree_editor->is_visible_in_tree()) - editor->hide_bottom_panel(); - button->hide(); - anim_tree_editor->set_process(false); - } -} - -AnimationNodeStateMachineEditorPlugin::AnimationNodeStateMachineEditorPlugin(EditorNode *p_node) { - - editor = p_node; - anim_tree_editor = memnew(AnimationNodeStateMachineEditor); - anim_tree_editor->set_custom_minimum_size(Size2(0, 300)); - - button = editor->add_bottom_panel_item(TTR("StateMachine"), anim_tree_editor); - button->hide(); -} - -AnimationNodeStateMachineEditorPlugin::~AnimationNodeStateMachineEditorPlugin() { -} diff --git a/editor/plugins/animation_state_machine_editor.h b/editor/plugins/animation_state_machine_editor.h index efd3de7415..49d08607cf 100644 --- a/editor/plugins/animation_state_machine_editor.h +++ b/editor/plugins/animation_state_machine_editor.h @@ -3,6 +3,7 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" +#include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/property_editor.h" #include "scene/animation/animation_node_state_machine.h" #include "scene/gui/button.h" @@ -10,9 +11,9 @@ #include "scene/gui/popup.h" #include "scene/gui/tree.h" -class AnimationNodeStateMachineEditor : public VBoxContainer { +class AnimationNodeStateMachineEditor : public AnimationTreeNodeEditorPlugin { - GDCLASS(AnimationNodeStateMachineEditor, VBoxContainer); + GDCLASS(AnimationNodeStateMachineEditor, AnimationTreeNodeEditorPlugin); Ref<AnimationNodeStateMachine> state_machine; @@ -29,9 +30,6 @@ class AnimationNodeStateMachineEditor : public VBoxContainer { OptionButton *transition_mode; OptionButton *play_mode; - HBoxContainer *goto_parent_hbox; - ToolButton *goto_parent; - PanelContainer *panel; StringName selected_node; @@ -79,8 +77,6 @@ class AnimationNodeStateMachineEditor : public VBoxContainer { void _add_menu_type(int p_index); void _add_animation_type(int p_index); - void _goto_parent(); - void _removed_from_graph(); struct NodeRect { @@ -99,6 +95,8 @@ class AnimationNodeStateMachineEditor : public VBoxContainer { Vector2 from; Vector2 to; AnimationNodeStateMachineTransition::SwitchMode mode; + StringName advance_condition_name; + bool advance_condition_state; bool disabled; bool auto_advance; float width; @@ -135,33 +133,25 @@ class AnimationNodeStateMachineEditor : public VBoxContainer { float error_time; String error_text; + EditorFileDialog *open_file; + Ref<AnimationNode> file_loaded; + void _file_opened(const String &p_file); + + enum { + MENU_LOAD_FILE = 1000, + MENU_PASTE = 1001, + MENU_LOAD_FILE_CONFIRM = 1002 + }; + protected: void _notification(int p_what); static void _bind_methods(); public: static AnimationNodeStateMachineEditor *get_singleton() { return singleton; } - void edit(AnimationNodeStateMachine *p_state_machine); + virtual bool can_edit(const Ref<AnimationNode> &p_node); + virtual void edit(const Ref<AnimationNode> &p_node); AnimationNodeStateMachineEditor(); }; -class AnimationNodeStateMachineEditorPlugin : public EditorPlugin { - - GDCLASS(AnimationNodeStateMachineEditorPlugin, EditorPlugin); - - AnimationNodeStateMachineEditor *anim_tree_editor; - EditorNode *editor; - Button *button; - -public: - virtual String get_name() const { return "StateMachine"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - - AnimationNodeStateMachineEditorPlugin(EditorNode *p_node); - ~AnimationNodeStateMachineEditorPlugin(); -}; - #endif // ANIMATION_STATE_MACHINE_EDITOR_H diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index 25582ae0b9..19921ef54f 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -1,1418 +1,247 @@ -/*************************************************************************/ -/* animation_tree_editor_plugin.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - #include "animation_tree_editor_plugin.h" +#include "animation_blend_space_1d_editor.h" +#include "animation_blend_space_2d_editor.h" +#include "animation_blend_tree_editor_plugin.h" +#include "animation_state_machine_editor.h" #include "core/io/resource_loader.h" #include "core/project_settings.h" +#include "math/delaunay.h" #include "os/input.h" #include "os/keyboard.h" +#include "scene/animation/animation_blend_tree.h" +#include "scene/animation/animation_player.h" #include "scene/gui/menu_button.h" #include "scene/gui/panel.h" #include "scene/main/viewport.h" +#include "scene/scene_string_names.h" -void AnimationTreeEditor::edit(AnimationTreePlayer *p_anim_tree) { +void AnimationTreeEditor::edit(AnimationTree *p_tree) { - anim_tree = p_anim_tree; + if (tree == p_tree) + return; - if (!anim_tree) { - hide(); - } else { - order.clear(); - p_anim_tree->get_node_list(&order); - /* - for(List<StringName>::Element* E=order.front();E;E=E->next()) { + tree = p_tree; - if (E->get() >= (int)last_id) - last_id=E->get()+1; - }*/ - play_button->set_pressed(p_anim_tree->is_active()); - //read the orders + Vector<String> path; + if (tree->has_meta("_tree_edit_path")) { + path = tree->get_meta("_tree_edit_path"); + edit_path(path); + } else { + current_root = 0; } } -Size2 AnimationTreeEditor::_get_maximum_size() { - - Size2 max; - - for (List<StringName>::Element *E = order.front(); E; E = E->next()) { +void AnimationTreeEditor::_path_button_pressed(int p_path) { - Point2 pos = anim_tree->node_get_position(E->get()); - - if (click_type == CLICK_NODE && click_node == E->get()) { + Ref<AnimationNode> node = tree->get_tree_root(); + if (node.is_null()) + return; - pos += click_motion - click_pos; + edited_path.clear(); + if (p_path >= 0) { + for (int i = 0; i <= p_path; i++) { + Ref<AnimationNode> child = node->get_child_by_name(button_path[i]); + ERR_BREAK(child.is_null()); + node = child; + edited_path.push_back(button_path[i]); } - pos += get_node_size(E->get()); - if (pos.x > max.x) - max.x = pos.x; - if (pos.y > max.y) - max.y = pos.y; } - return max; -} - -const char *AnimationTreeEditor::_node_type_names[] = { "Output", "Animation", "OneShot", "Mix", "Blend2", "Blend3", "Blend4", "TimeScale", "TimeSeek", "Transition" }; - -Size2 AnimationTreeEditor::get_node_size(const StringName &p_node) const { - - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node); - - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Ref<Font> font = get_font("font", "PopupMenu"); - - Size2 size = style->get_minimum_size(); - - int count = 2; // title and name - int inputs = anim_tree->node_get_input_count(p_node); - count += inputs ? inputs : 1; - String name = p_node; - - float name_w = font->get_string_size(name).width; - float type_w = font->get_string_size(String(_node_type_names[type])).width; - float max_w = MAX(name_w, type_w); - - switch (type) { - case AnimationTreePlayer::NODE_TIMESEEK: - case AnimationTreePlayer::NODE_OUTPUT: { - } break; - case AnimationTreePlayer::NODE_ANIMATION: - case AnimationTreePlayer::NODE_ONESHOT: - case AnimationTreePlayer::NODE_MIX: - case AnimationTreePlayer::NODE_BLEND2: - case AnimationTreePlayer::NODE_BLEND3: - case AnimationTreePlayer::NODE_BLEND4: - case AnimationTreePlayer::NODE_TIMESCALE: - case AnimationTreePlayer::NODE_TRANSITION: { - - size.height += font->get_height(); - } break; - case AnimationTreePlayer::NODE_MAX: { + for (int i = 0; i < editors.size(); i++) { + if (editors[i]->can_edit(node)) { + editors[i]->edit(node); + editors[i]->show(); + } else { + editors[i]->edit(Ref<AnimationNode>()); + editors[i]->hide(); } } - - size.x += max_w + 20; - size.y += count * (font->get_height() + get_constant("vseparation", "PopupMenu")); - - return size; } -void AnimationTreeEditor::_edit_dialog_changede(String) { - - edit_dialog->hide(); -} - -void AnimationTreeEditor::_edit_dialog_changeds(String s) { - - _edit_dialog_changed(); -} - -void AnimationTreeEditor::_edit_dialog_changedf(float) { - - _edit_dialog_changed(); -} - -void AnimationTreeEditor::_edit_dialog_changed() { - - if (updating_edit) - return; - - if (renaming_edit) { - - if (anim_tree->node_rename(edited_node, edit_line[0]->get_text()) == OK) { - for (List<StringName>::Element *E = order.front(); E; E = E->next()) { - - if (E->get() == edited_node) - E->get() = edit_line[0]->get_text(); - } - edited_node = edit_line[0]->get_text(); - } - update(); - return; +void AnimationTreeEditor::_update_path() { + while (path_hb->get_child_count()) { + memdelete(path_hb->get_child(0)); } - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node); - - switch (type) { - - case AnimationTreePlayer::NODE_TIMESCALE: - anim_tree->timescale_node_set_scale(edited_node, edit_line[0]->get_text().to_double()); - break; - case AnimationTreePlayer::NODE_ONESHOT: - anim_tree->oneshot_node_set_fadein_time(edited_node, edit_line[0]->get_text().to_double()); - anim_tree->oneshot_node_set_fadeout_time(edited_node, edit_line[1]->get_text().to_double()); - anim_tree->oneshot_node_set_autorestart_delay(edited_node, edit_line[2]->get_text().to_double()); - anim_tree->oneshot_node_set_autorestart_random_delay(edited_node, edit_line[3]->get_text().to_double()); - anim_tree->oneshot_node_set_autorestart(edited_node, edit_check->is_pressed()); - anim_tree->oneshot_node_set_mix_mode(edited_node, edit_option->get_selected()); - - break; - - case AnimationTreePlayer::NODE_MIX: - - anim_tree->mix_node_set_amount(edited_node, edit_scroll[0]->get_value()); - break; - case AnimationTreePlayer::NODE_BLEND2: - anim_tree->blend2_node_set_amount(edited_node, edit_scroll[0]->get_value()); - - break; - - case AnimationTreePlayer::NODE_BLEND3: - anim_tree->blend3_node_set_amount(edited_node, edit_scroll[0]->get_value()); - - break; - case AnimationTreePlayer::NODE_BLEND4: - - anim_tree->blend4_node_set_amount(edited_node, Point2(edit_scroll[0]->get_value(), edit_scroll[1]->get_value())); - - break; - - case AnimationTreePlayer::NODE_TRANSITION: { - anim_tree->transition_node_set_xfade_time(edited_node, edit_line[0]->get_text().to_double()); - if (anim_tree->transition_node_get_current(edited_node) != edit_option->get_selected()) - anim_tree->transition_node_set_current(edited_node, edit_option->get_selected()); - } break; - default: {} - } -} - -void AnimationTreeEditor::_edit_dialog_animation_changed() { - - Ref<Animation> anim = property_editor->get_variant().operator RefPtr(); - anim_tree->animation_node_set_animation(edited_node, anim); - update(); -} - -void AnimationTreeEditor::_edit_dialog_edit_animation() { - - if (Engine::get_singleton()->is_editor_hint()) { - get_tree()->get_root()->get_child(0)->call("_resource_selected", property_editor->get_variant().operator RefPtr()); - }; -}; - -void AnimationTreeEditor::_edit_oneshot_start() { - - anim_tree->oneshot_node_start(edited_node); -} - -void AnimationTreeEditor::_play_toggled() { - - anim_tree->set_active(play_button->is_pressed()); -} - -void AnimationTreeEditor::_master_anim_menu_item(int p_item) { - - if (p_item == 0) - _edit_filters(); - else { - - String str = master_anim_popup->get_item_text(p_item); - anim_tree->animation_node_set_master_animation(edited_node, str); + Ref<ButtonGroup> group; + group.instance(); + + Button *b = memnew(Button); + b->set_text("root"); + b->set_toggle_mode(true); + b->set_button_group(group); + b->set_pressed(true); + b->set_focus_mode(FOCUS_NONE); + b->connect("pressed", this, "_path_button_pressed", varray(-1)); + path_hb->add_child(b); + for (int i = 0; i < button_path.size(); i++) { + b = memnew(Button); + b->set_text(button_path[i]); + b->set_toggle_mode(true); + b->set_button_group(group); + path_hb->add_child(b); + b->set_pressed(true); + b->set_focus_mode(FOCUS_NONE); + b->connect("pressed", this, "_path_button_pressed", varray(i)); } - update(); } -void AnimationTreeEditor::_popup_edit_dialog() { - - updating_edit = true; - - for (int i = 0; i < 2; i++) - edit_scroll[i]->hide(); - - for (int i = 0; i < 4; i++) { - - edit_line[i]->hide(); - edit_label[i]->hide(); - } - - edit_option->hide(); - edit_button->hide(); - filter_button->hide(); - edit_check->hide(); - - Point2 pos = anim_tree->node_get_position(edited_node) - Point2(h_scroll->get_value(), v_scroll->get_value()); - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Size2 size = get_node_size(edited_node); - Point2 popup_pos(pos.x + style->get_margin(MARGIN_LEFT), pos.y + size.y - style->get_margin(MARGIN_BOTTOM)); - popup_pos += get_global_position(); - - if (renaming_edit) { - - edit_label[0]->set_text(TTR("New name:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15, 25)); - edit_line[0]->set_text(edited_node); - edit_line[0]->show(); - edit_dialog->set_size(Size2(150, 50)); - - } else { - - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node); - - switch (type) { - - case AnimationTreePlayer::NODE_ANIMATION: - - if (anim_tree->get_master_player() != NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && Object::cast_to<AnimationPlayer>(anim_tree->get_node(anim_tree->get_master_player()))) { - - AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(anim_tree->get_node(anim_tree->get_master_player())); - master_anim_popup->clear(); - master_anim_popup->add_item(TTR("Edit Filters")); - master_anim_popup->add_separator(); - List<StringName> sn; - ap->get_animation_list(&sn); - sn.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = sn.front(); E; E = E->next()) { - master_anim_popup->add_item(E->get()); - } - - master_anim_popup->set_position(popup_pos); - master_anim_popup->popup(); - } else { - property_editor->edit(this, "", Variant::OBJECT, anim_tree->animation_node_get_animation(edited_node), PROPERTY_HINT_RESOURCE_TYPE, "Animation"); - property_editor->set_position(popup_pos); - property_editor->popup(); - updating_edit = false; - } - return; - case AnimationTreePlayer::NODE_TIMESCALE: - edit_label[0]->set_text(TTR("Scale:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15, 25)); - edit_line[0]->set_text(rtos(anim_tree->timescale_node_get_scale(edited_node))); - edit_line[0]->show(); - edit_dialog->set_size(Size2(150, 50)); - break; - case AnimationTreePlayer::NODE_ONESHOT: - edit_label[0]->set_text(TTR("Fade In (s):")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15, 25)); - edit_line[0]->set_text(rtos(anim_tree->oneshot_node_get_fadein_time(edited_node))); - edit_line[0]->show(); - edit_label[1]->set_text(TTR("Fade Out (s):")); - edit_label[1]->set_position(Point2(5, 55)); - edit_label[1]->show(); - edit_line[1]->set_begin(Point2(15, 75)); - edit_line[1]->set_text(rtos(anim_tree->oneshot_node_get_fadeout_time(edited_node))); - edit_line[1]->show(); - - edit_option->clear(); - edit_option->add_item(TTR("Blend"), 0); - edit_option->add_item(TTR("Mix"), 1); - edit_option->set_begin(Point2(15, 105)); - - edit_option->select(anim_tree->oneshot_node_get_mix_mode(edited_node)); - edit_option->show(); - - edit_check->set_text(TTR("Auto Restart:")); - edit_check->set_begin(Point2(15, 125)); - edit_check->set_pressed(anim_tree->oneshot_node_has_autorestart(edited_node)); - edit_check->show(); - - edit_label[2]->set_text(TTR("Restart (s):")); - edit_label[2]->set_position(Point2(5, 145)); - edit_label[2]->show(); - edit_line[2]->set_begin(Point2(15, 165)); - edit_line[2]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_delay(edited_node))); - edit_line[2]->show(); - edit_label[3]->set_text(TTR("Random Restart (s):")); - edit_label[3]->set_position(Point2(5, 195)); - edit_label[3]->show(); - edit_line[3]->set_begin(Point2(15, 215)); - edit_line[3]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_random_delay(edited_node))); - edit_line[3]->show(); - - filter_button->set_begin(Point2(10, 245)); - filter_button->show(); - - edit_button->set_begin(Point2(10, 268)); - edit_button->set_text(TTR("Start!")); - - edit_button->show(); +void AnimationTreeEditor::edit_path(const Vector<String> &p_path) { - edit_dialog->set_size(Size2(180, 293)); + button_path.clear(); - break; + Ref<AnimationNode> node = tree->get_tree_root(); - case AnimationTreePlayer::NODE_MIX: + if (node.is_valid()) { + current_root = node->get_instance_id(); - edit_label[0]->set_text(TTR("Amount:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(0); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_step(0.01); - edit_scroll[0]->set_value(anim_tree->mix_node_get_amount(edited_node)); - edit_scroll[0]->set_begin(Point2(15, 25)); - edit_scroll[0]->show(); - edit_dialog->set_size(Size2(150, 50)); + for (int i = 0; i < p_path.size(); i++) { - break; - case AnimationTreePlayer::NODE_BLEND2: - edit_label[0]->set_text(TTR("Blend:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(0); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_step(0.01); - edit_scroll[0]->set_value(anim_tree->blend2_node_get_amount(edited_node)); - edit_scroll[0]->set_begin(Point2(15, 25)); - edit_scroll[0]->show(); - filter_button->set_begin(Point2(10, 47)); - filter_button->show(); - edit_dialog->set_size(Size2(150, 74)); - - break; - - case AnimationTreePlayer::NODE_BLEND3: - edit_label[0]->set_text(TTR("Blend:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(-1); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_step(0.01); - edit_scroll[0]->set_value(anim_tree->blend3_node_get_amount(edited_node)); - edit_scroll[0]->set_begin(Point2(15, 25)); - edit_scroll[0]->show(); - edit_dialog->set_size(Size2(150, 50)); - - break; - case AnimationTreePlayer::NODE_BLEND4: - - edit_label[0]->set_text(TTR("Blend 0:")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(0); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_step(0.01); - edit_scroll[0]->set_value(anim_tree->blend4_node_get_amount(edited_node).x); - edit_scroll[0]->set_begin(Point2(15, 25)); - edit_scroll[0]->show(); - edit_label[1]->set_text(TTR("Blend 1:")); - edit_label[1]->set_position(Point2(5, 55)); - edit_label[1]->show(); - edit_scroll[1]->set_min(0); - edit_scroll[1]->set_max(1); - edit_scroll[1]->set_step(0.01); - edit_scroll[1]->set_value(anim_tree->blend4_node_get_amount(edited_node).y); - edit_scroll[1]->set_begin(Point2(15, 75)); - edit_scroll[1]->show(); - edit_dialog->set_size(Size2(150, 100)); - - break; - - case AnimationTreePlayer::NODE_TRANSITION: { - - edit_label[0]->set_text(TTR("X-Fade Time (s):")); - edit_label[0]->set_position(Point2(5, 5)); - edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15, 25)); - edit_line[0]->set_text(rtos(anim_tree->transition_node_get_xfade_time(edited_node))); - edit_line[0]->show(); - - edit_label[1]->set_text(TTR("Current:")); - edit_label[1]->set_position(Point2(5, 55)); - edit_label[1]->show(); - edit_option->set_begin(Point2(15, 75)); - - edit_option->clear(); - - for (int i = 0; i < anim_tree->transition_node_get_input_count(edited_node); i++) { - edit_option->add_item(itos(i), i); - } - - edit_option->select(anim_tree->transition_node_get_current(edited_node)); - edit_option->show(); - edit_dialog->set_size(Size2(150, 100)); - - } break; - default: {} + Ref<AnimationNode> child = node->get_child_by_name(p_path[i]); + ERR_BREAK(child.is_null()); + node = child; + button_path.push_back(p_path[i]); } - } - - edit_dialog->set_position(popup_pos); - edit_dialog->popup(); - - updating_edit = false; -} - -void AnimationTreeEditor::_draw_node(const StringName &p_node) { - - RID ci = get_canvas_item(); - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node); - - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Ref<Font> font = get_font("font", "PopupMenu"); - Color font_color = get_color("font_color", "PopupMenu"); - Color font_color_title = get_color("font_color_hover", "PopupMenu"); - font_color_title.a *= 0.8; - Ref<Texture> slot_icon = get_icon("VisualShaderPort", "EditorIcons"); - - Size2 size = get_node_size(p_node); - Point2 pos = anim_tree->node_get_position(p_node); - if (click_type == CLICK_NODE && click_node == p_node) { - - pos += click_motion - click_pos; - if (pos.x < 5) - pos.x = 5; - if (pos.y < 5) - pos.y = 5; - } - - pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - style->draw(ci, Rect2(pos, size)); - - float w = size.width - style->get_minimum_size().width; - float h = font->get_height() + get_constant("vseparation", "PopupMenu"); - - Point2 ofs = style->get_offset() + pos; - Point2 ascofs(0, font->get_ascent()); - - Color bx = font_color_title; - bx.a *= 0.1; - draw_rect(Rect2(ofs, Size2(size.width - style->get_minimum_size().width, font->get_height())), bx); - font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, String(_node_type_names[type]), font_color_title); - - ofs.y += h; - font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, p_node, font_color); - ofs.y += h; - - int count = 2; // title and name - int inputs = anim_tree->node_get_input_count(p_node); - count += inputs ? inputs : 1; - - float icon_h_ofs = Math::floor((font->get_height() - slot_icon->get_height()) / 2.0) + 1; - - if (type != AnimationTreePlayer::NODE_OUTPUT) - slot_icon->draw(ci, ofs + Point2(w, icon_h_ofs)); //output - - if (inputs) { - for (int i = 0; i < inputs; i++) { - - slot_icon->draw(ci, ofs + Point2(-slot_icon->get_width(), icon_h_ofs)); - String text; - switch (type) { - - case AnimationTreePlayer::NODE_TIMESCALE: - case AnimationTreePlayer::NODE_TIMESEEK: text = "in"; break; - case AnimationTreePlayer::NODE_OUTPUT: text = "out"; break; - case AnimationTreePlayer::NODE_ANIMATION: break; - case AnimationTreePlayer::NODE_ONESHOT: text = (i == 0 ? "in" : "add"); break; - case AnimationTreePlayer::NODE_BLEND2: - case AnimationTreePlayer::NODE_MIX: text = (i == 0 ? "a" : "b"); break; - case AnimationTreePlayer::NODE_BLEND3: - switch (i) { - case 0: text = "b-"; break; - case 1: text = "a"; break; - case 2: text = "b+"; break; - } - break; - - case AnimationTreePlayer::NODE_BLEND4: - switch (i) { - case 0: text = "a0"; break; - case 1: text = "b0"; break; - case 2: text = "a1"; break; - case 3: text = "b1"; break; - } - break; - - case AnimationTreePlayer::NODE_TRANSITION: - text = itos(i); - if (anim_tree->transition_node_has_input_auto_advance(p_node, i)) - text += "->"; - - break; - default: {} + for (int i = 0; i < editors.size(); i++) { + if (editors[i]->can_edit(node)) { + editors[i]->edit(node); + editors[i]->show(); + } else { + editors[i]->edit(Ref<AnimationNode>()); + editors[i]->hide(); } - font->draw(ci, ofs + ascofs + Point2(3, 0), text, font_color); - - ofs.y += h; } } else { - ofs.y += h; + current_root = 0; } - Ref<StyleBox> pg_bg = get_stylebox("bg", "ProgressBar"); - Ref<StyleBox> pg_fill = get_stylebox("fill", "ProgressBar"); - Rect2 pg_rect(ofs, Size2(w, h)); - - bool editable = true; - switch (type) { - case AnimationTreePlayer::NODE_ANIMATION: { - - Ref<Animation> anim = anim_tree->animation_node_get_animation(p_node); - String text; - if (anim_tree->animation_node_get_master_animation(p_node) != "") - text = anim_tree->animation_node_get_master_animation(p_node); - else if (anim.is_null()) - text = "load..."; - else - text = anim->get_name(); - - font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, text, font_color_title); + edited_path = button_path; - } break; - case AnimationTreePlayer::NODE_ONESHOT: - case AnimationTreePlayer::NODE_MIX: - case AnimationTreePlayer::NODE_BLEND2: - case AnimationTreePlayer::NODE_BLEND3: - case AnimationTreePlayer::NODE_BLEND4: - case AnimationTreePlayer::NODE_TIMESCALE: - case AnimationTreePlayer::NODE_TRANSITION: { - - font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, "edit...", font_color_title); - } break; - default: editable = false; - } - - if (editable) { - - Ref<Texture> arrow = get_icon("GuiDropdown", "EditorIcons"); - Point2 arrow_ofs(w - arrow->get_width(), Math::floor((h - arrow->get_height()) / 2)); - arrow->draw(ci, ofs + arrow_ofs); - } + _update_path(); } -AnimationTreeEditor::ClickType AnimationTreeEditor::_locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const { - - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Ref<Font> font = get_font("font", "PopupMenu"); - - float h = (font->get_height() + get_constant("vseparation", "PopupMenu")); - - for (const List<StringName>::Element *E = order.back(); E; E = E->prev()) { - - StringName node = E->get(); - - AnimationTreePlayer::NodeType type = anim_tree->node_get_type(node); - - Point2 pos = anim_tree->node_get_position(node); - Size2 size = get_node_size(node); - - pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - - if (!Rect2(pos, size).has_point(p_click)) - continue; - - if (p_node_id) - *p_node_id = node; - - pos = p_click - pos; - - float y = pos.y - style->get_offset().height; - - if (y < 2 * h) - return CLICK_NODE; - y -= 2 * h; - - int inputs = anim_tree->node_get_input_count(node); - int count = MAX(inputs, 1); - - if (inputs == 0 || (pos.x > size.width / 2 && type != AnimationTreePlayer::NODE_OUTPUT)) { - - if (y < count * h) { - - if (p_slot_index) - *p_slot_index = 0; - return CLICK_OUTPUT_SLOT; - } - } - - for (int i = 0; i < count; i++) { - - if (y < h) { - if (p_slot_index) - *p_slot_index = i; - return CLICK_INPUT_SLOT; - } - y -= h; - } - - bool has_parameters = type != AnimationTreePlayer::NODE_OUTPUT && type != AnimationTreePlayer::NODE_TIMESEEK; - return has_parameters ? CLICK_PARAMETER : CLICK_NODE; - } - - return CLICK_NONE; -} - -Point2 AnimationTreeEditor::_get_slot_pos(const StringName &p_node_id, bool p_input, int p_slot) { - - Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); - Ref<Font> font = get_font("font", "PopupMenu"); - Ref<Texture> slot_icon = get_icon("VisualShaderPort", "EditorIcons"); - - Size2 size = get_node_size(p_node_id); - Point2 pos = anim_tree->node_get_position(p_node_id); - - if (click_type == CLICK_NODE && click_node == p_node_id) { - - pos += click_motion - click_pos; - if (pos.x < 5) - pos.x = 5; - if (pos.y < 5) - pos.y = 5; - } - - pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - - float w = size.width - style->get_minimum_size().width; - float h = font->get_height() + get_constant("vseparation", "PopupMenu"); - - pos += style->get_offset(); - - pos.y += h * 2; - - pos.y += h * p_slot; - - pos += Point2(-slot_icon->get_width() / 2.0, h / 2.0).floor(); - - if (!p_input) { - pos.x += w + slot_icon->get_width(); - } - - return pos; +Vector<String> AnimationTreeEditor::get_edited_path() const { + return button_path; } -void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid()) { - - if (mb->is_pressed()) { +void AnimationTreeEditor::enter_editor(const String &p_path) { - if (mb->get_button_index() == 1) { - click_pos = Point2(mb->get_position().x, mb->get_position().y); - click_motion = click_pos; - click_type = _locate_click(click_pos, &click_node, &click_slot); - if (click_type != CLICK_NONE) { - - order.erase(click_node); - order.push_back(click_node); - update(); - } - - switch (click_type) { - case CLICK_INPUT_SLOT: { - click_pos = _get_slot_pos(click_node, true, click_slot); - } break; - case CLICK_OUTPUT_SLOT: { - click_pos = _get_slot_pos(click_node, false, click_slot); - } break; - case CLICK_PARAMETER: { - - edited_node = click_node; - renaming_edit = false; - _popup_edit_dialog(); - //open editor - //_node_edit_property(click_node); - } break; - default: {} - } - } - if (mb->get_button_index() == 2) { - - if (click_type != CLICK_NONE) { - click_type = CLICK_NONE; - update(); - } else { - // try to disconnect/remove - - Point2 rclick_pos = Point2(mb->get_position().x, mb->get_position().y); - rclick_type = _locate_click(rclick_pos, &rclick_node, &rclick_slot); - if (rclick_type == CLICK_INPUT_SLOT || rclick_type == CLICK_OUTPUT_SLOT) { - - node_popup->clear(); - node_popup->set_size(Size2(1, 1)); - node_popup->add_item(TTR("Disconnect"), NODE_DISCONNECT); - if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) { - node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT); - if (rclick_type == CLICK_INPUT_SLOT) { - if (anim_tree->transition_node_has_input_auto_advance(rclick_node, rclick_slot)) - node_popup->add_item(TTR("Clear Auto-Advance"), NODE_CLEAR_AUTOADVANCE); - else - node_popup->add_item(TTR("Set Auto-Advance"), NODE_SET_AUTOADVANCE); - node_popup->add_item(TTR("Delete Input"), NODE_DELETE_INPUT); - } - } - - node_popup->set_position(rclick_pos + get_global_position()); - node_popup->popup(); - } - - if (rclick_type == CLICK_NODE) { - node_popup->clear(); - node_popup->set_size(Size2(1, 1)); - node_popup->add_item(TTR("Rename"), NODE_RENAME); - node_popup->add_item(TTR("Remove"), NODE_ERASE); - if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) - node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT); - node_popup->set_position(rclick_pos + get_global_position()); - node_popup->popup(); - } - } - } - } else { - - if (mb->get_button_index() == 1 && click_type != CLICK_NONE) { - - switch (click_type) { - case CLICK_INPUT_SLOT: - case CLICK_OUTPUT_SLOT: { - - Point2 dst_click_pos = Point2(mb->get_position().x, mb->get_position().y); - StringName id; - int slot; - ClickType dst_click_type = _locate_click(dst_click_pos, &id, &slot); - - if (dst_click_type == CLICK_INPUT_SLOT && click_type == CLICK_OUTPUT_SLOT) { - - anim_tree->connect_nodes(click_node, id, slot); - } - if (click_type == CLICK_INPUT_SLOT && dst_click_type == CLICK_OUTPUT_SLOT) { - - anim_tree->connect_nodes(id, click_node, click_slot); - } - - } break; - case CLICK_NODE: { - Point2 new_pos = anim_tree->node_get_position(click_node) + (click_motion - click_pos); - if (new_pos.x < 5) - new_pos.x = 5; - if (new_pos.y < 5) - new_pos.y = 5; - anim_tree->node_set_position(click_node, new_pos); - - } break; - default: {} - } - - click_type = CLICK_NONE; - update(); - } - } - } - - Ref<InputEventMouseMotion> mm = p_event; - - if (mm.is_valid()) { - - if (mm->get_button_mask() & 1 && click_type != CLICK_NONE) { - - click_motion = Point2(mm->get_position().x, mm->get_position().y); - update(); - } - if ((mm->get_button_mask() & 4 || Input::get_singleton()->is_key_pressed(KEY_SPACE))) { - - h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x); - v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y); - update(); - } - } + Vector<String> path = edited_path; + path.push_back(p_path); + edit_path(path); } -void AnimationTreeEditor::_draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color) { - - static const int steps = 20; - - Rect2 r; - r.position = p_from; - r.expand_to(p_to); - Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1); - bool flip = sign.x * sign.y < 0; - - Vector2 prev; - for (int i = 0; i <= steps; i++) { - - float d = i / float(steps); - float c = -Math::cos(d * Math_PI) * 0.5 + 0.5; - if (flip) - c = 1.0 - c; - Vector2 p = r.position + Vector2(d * r.size.width, c * r.size.height); - - if (i > 0) { - - draw_line(prev, p, p_color, 2); - } - - prev = p; - } +void AnimationTreeEditor::_about_to_show_root() { } void AnimationTreeEditor::_notification(int p_what) { + if (p_what == NOTIFICATION_PROCESS) { + ObjectID root = 0; + if (tree && tree->get_tree_root().is_valid()) { + root = tree->get_tree_root()->get_instance_id(); + } - switch (p_what) { - - case NOTIFICATION_ENTER_TREE: { - - play_button->set_icon(get_icon("Play", "EditorIcons")); - add_menu->set_icon(get_icon("Add", "EditorIcons")); - } break; - case NOTIFICATION_DRAW: { - - _update_scrollbars(); - //VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(Point2(),get_size()),Color(0,0,0,1)); - get_stylebox("bg", "Tree")->draw(get_canvas_item(), Rect2(Point2(), get_size())); - - for (List<StringName>::Element *E = order.front(); E; E = E->next()) { - - _draw_node(E->get()); - } - - if (click_type == CLICK_INPUT_SLOT || click_type == CLICK_OUTPUT_SLOT) { - - _draw_cos_line(click_pos, click_motion, Color(0.5, 1, 0.5, 0.8)); - } - - List<AnimationTreePlayer::Connection> connections; - anim_tree->get_connection_list(&connections); - - for (List<AnimationTreePlayer::Connection>::Element *E = connections.front(); E; E = E->next()) { - - const AnimationTreePlayer::Connection &c = E->get(); - Point2 source = _get_slot_pos(c.src_node, false, 0); - Point2 dest = _get_slot_pos(c.dst_node, true, c.dst_input); - Color col = Color(1, 1, 0.5, 0.8); - /* - if (click_type==CLICK_NODE && click_node==c.src_node) { - - source+=click_motion-click_pos; - } - - if (click_type==CLICK_NODE && click_node==c.dst_node) { - - dest+=click_motion-click_pos; - }*/ - - _draw_cos_line(source, dest, col); - } - - switch (anim_tree->get_last_error()) { - - case AnimationTreePlayer::CONNECT_OK: { - - Ref<Font> f = get_font("font", "Label"); - f->draw(get_canvas_item(), Point2(5, 25 + f->get_ascent()), TTR("Animation tree is valid."), Color(0, 1, 0.6, 0.8)); - } break; - default: { - - Ref<Font> f = get_font("font", "Label"); - f->draw(get_canvas_item(), Point2(5, 25 + f->get_ascent()), TTR("Animation tree is invalid."), Color(1, 0.6, 0.0, 0.8)); - } break; - } - - } break; + if (root != current_root) { + edit_path(Vector<String>()); + } } } -void AnimationTreeEditor::_update_scrollbars() { - - Size2 size = get_size(); - Size2 hmin = h_scroll->get_combined_minimum_size(); - Size2 vmin = v_scroll->get_combined_minimum_size(); - - v_scroll->set_begin(Point2(size.width - vmin.width, 0)); - v_scroll->set_end(Point2(size.width, size.height)); - - h_scroll->set_begin(Point2(0, size.height - hmin.height)); - h_scroll->set_end(Point2(size.width - vmin.width, size.height)); - - Size2 min = _get_maximum_size(); - - if (min.height < size.height - hmin.height) { - - v_scroll->hide(); - offset.y = 0; - } else { - - v_scroll->show(); - v_scroll->set_max(min.height); - v_scroll->set_page(size.height - hmin.height); - offset.y = v_scroll->get_value(); - } - - if (min.width < size.width - vmin.width) { - - h_scroll->hide(); - offset.x = 0; - } else { - - h_scroll->show(); - h_scroll->set_max(min.width); - h_scroll->set_page(size.width - vmin.width); - offset.x = h_scroll->get_value(); - } +void AnimationTreeEditor::_bind_methods() { + ClassDB::bind_method("_path_button_pressed", &AnimationTreeEditor::_path_button_pressed); } -void AnimationTreeEditor::_scroll_moved(float) { +AnimationTreeEditor *AnimationTreeEditor::singleton = NULL; - offset.x = h_scroll->get_value(); - offset.y = v_scroll->get_value(); - update(); +void AnimationTreeEditor::add_plugin(AnimationTreeNodeEditorPlugin *p_editor) { + ERR_FAIL_COND(p_editor->get_parent()); + editor_base->add_child(p_editor); + editors.push_back(p_editor); + p_editor->set_h_size_flags(SIZE_EXPAND_FILL); + p_editor->set_v_size_flags(SIZE_EXPAND_FILL); + p_editor->hide(); } -void AnimationTreeEditor::_node_menu_item(int p_item) { - - switch (p_item) { - - case NODE_DISCONNECT: { - - if (rclick_type == CLICK_INPUT_SLOT) { - - anim_tree->disconnect_nodes(rclick_node, rclick_slot); - update(); - } - - if (rclick_type == CLICK_OUTPUT_SLOT) { - - List<AnimationTreePlayer::Connection> connections; - anim_tree->get_connection_list(&connections); - - for (List<AnimationTreePlayer::Connection>::Element *E = connections.front(); E; E = E->next()) { - - const AnimationTreePlayer::Connection &c = E->get(); - if (c.dst_node == rclick_node) { - - anim_tree->disconnect_nodes(c.dst_node, c.dst_input); - } - } - update(); - } - - } break; - case NODE_RENAME: { - - renaming_edit = true; - edited_node = rclick_node; - _popup_edit_dialog(); - - } break; - case NODE_ADD_INPUT: { - - anim_tree->transition_node_set_input_count(rclick_node, anim_tree->transition_node_get_input_count(rclick_node) + 1); - update(); - } break; - case NODE_DELETE_INPUT: { - - anim_tree->transition_node_delete_input(rclick_node, rclick_slot); - update(); - } break; - case NODE_SET_AUTOADVANCE: { - - anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, true); - update(); - - } break; - case NODE_CLEAR_AUTOADVANCE: { - - anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, false); - update(); - - } break; - - case NODE_ERASE: { - - if (rclick_node == "out") - break; - order.erase(rclick_node); - anim_tree->remove_node(rclick_node); - update(); - } break; - } +void AnimationTreeEditor::remove_plugin(AnimationTreeNodeEditorPlugin *p_editor) { + ERR_FAIL_COND(p_editor->get_parent() != editor_base); + editor_base->remove_child(p_editor); + editors.erase(p_editor); } -StringName AnimationTreeEditor::_add_node(int p_item) { - - static const char *bname[] = { - "out", - "anim", - "oneshot", - "mix", - "blend2", - "blend3", - "blend4", - "scale", - "seek", - "transition" - }; - - String name; - int idx = 1; - - while (true) { - - name = bname[p_item]; - if (idx > 1) - name += " " + itos(idx); - if (anim_tree->node_exists(name)) - idx++; - else - break; +String AnimationTreeEditor::get_base_path() { + String path = SceneStringNames::get_singleton()->parameters_base_path; + for (int i = 0; i < edited_path.size(); i++) { + path += edited_path[i] + "/"; } - - anim_tree->add_node((AnimationTreePlayer::NodeType)p_item, name); - anim_tree->node_set_position(name, Point2(last_x, last_y)); - order.push_back(name); - last_x += 10; - last_y += 10; - last_x = last_x % (int)get_size().width; - last_y = last_y % (int)get_size().height; - update(); - - return name; -}; - -void AnimationTreeEditor::_file_dialog_selected(String p_path) { - - switch (file_op) { - - case MENU_IMPORT_ANIMATIONS: { - Vector<String> files = file_dialog->get_selected_files(); - - for (int i = 0; i < files.size(); i++) { - - StringName node = _add_node(AnimationTreePlayer::NODE_ANIMATION); - - RES anim = ResourceLoader::load(files[i]); - anim_tree->animation_node_set_animation(node, anim); - //anim_tree->node_set_name(node, files[i].get_file()); - }; - } break; - - default: - break; - }; -}; - -void AnimationTreeEditor::_add_menu_item(int p_item) { - - if (p_item == MENU_GRAPH_CLEAR) { - - //clear - } else if (p_item == MENU_IMPORT_ANIMATIONS) { - - file_op = MENU_IMPORT_ANIMATIONS; - file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); - file_dialog->popup_centered_ratio(); - - } else { - - _add_node(p_item); - } -} - -Size2 AnimationTreeEditor::get_minimum_size() const { - - return Size2(10, 200); + return path; } -void AnimationTreeEditor::_find_paths_for_filter(const StringName &p_node, Set<String> &paths) { - - ERR_FAIL_COND(!anim_tree->node_exists(p_node)); - - for (int i = 0; i < anim_tree->node_get_input_count(p_node); i++) { - - StringName port = anim_tree->node_get_input_source(p_node, i); - if (port == StringName()) - continue; - _find_paths_for_filter(port, paths); - } - - if (anim_tree->node_get_type(p_node) == AnimationTreePlayer::NODE_ANIMATION) { - - Ref<Animation> anim = anim_tree->animation_node_get_animation(p_node); - if (anim.is_valid()) { - - for (int i = 0; i < anim->get_track_count(); i++) { - paths.insert(anim->track_get_path(i)); - } +bool AnimationTreeEditor::can_edit(const Ref<AnimationNode> &p_node) const { + for (int i = 0; i < editors.size(); i++) { + if (editors[i]->can_edit(p_node)) { + return true; } } + return false; } -void AnimationTreeEditor::_filter_edited() { - - TreeItem *ed = filter->get_edited(); - if (!ed) - return; +Vector<String> AnimationTreeEditor::get_animation_list() { - if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) { - anim_tree->oneshot_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); - } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) { - anim_tree->blend2_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); - } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) { - anim_tree->animation_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); + if (!singleton->is_visible()) { + return Vector<String>(); } -} - -void AnimationTreeEditor::_edit_filters() { - - filter_dialog->popup_centered_ratio(); - filter->clear(); - - Set<String> npb; - _find_paths_for_filter(edited_node, npb); - - TreeItem *root = filter->create_item(); - filter->set_hide_root(true); - Map<String, TreeItem *> pm; - - Node *base = anim_tree->get_node(anim_tree->get_base_path()); - - for (Set<String>::Element *E = npb.front(); E; E = E->next()) { - - TreeItem *parent = root; - String descr = E->get(); - if (base) { - NodePath np = E->get(); - if (np.get_subname_count() == 1) { - Node *n = base->get_node(np); - Skeleton *s = Object::cast_to<Skeleton>(n); - if (s) { + AnimationTree *tree = singleton->tree; + if (!tree || !tree->has_node(tree->get_animation_player())) + return Vector<String>(); - String skelbase = E->get().substr(0, E->get().find(":")); + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player())); - int bidx = s->find_bone(np.get_subname(0)); + if (!ap) + return Vector<String>(); - if (bidx != -1) { - int bparent = s->get_bone_parent(bidx); - // - if (bparent != -1) { - - String bpn = skelbase + ":" + s->get_bone_name(bparent); - if (pm.has(bpn)) { - parent = pm[bpn]; - descr = np.get_subname(0); - } - } else { - - if (pm.has(skelbase)) { - parent = pm[skelbase]; - } - } - } - } - } - } - - TreeItem *it = filter->create_item(parent); - it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); - it->set_text(0, descr); - it->set_metadata(0, NodePath(E->get())); - it->set_editable(0, true); - if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) { - it->set_checked(0, anim_tree->oneshot_node_is_path_filtered(edited_node, E->get())); - } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) { - it->set_checked(0, anim_tree->blend2_node_is_path_filtered(edited_node, E->get())); - } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) { - it->set_checked(0, anim_tree->animation_node_is_path_filtered(edited_node, E->get())); - } - pm[E->get()] = it; + List<StringName> anims; + ap->get_animation_list(&anims); + Vector<String> ret; + for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { + ret.push_back(E->get()); } -} - -void AnimationTreeEditor::_bind_methods() { - ClassDB::bind_method("_add_menu_item", &AnimationTreeEditor::_add_menu_item); - ClassDB::bind_method("_node_menu_item", &AnimationTreeEditor::_node_menu_item); - ClassDB::bind_method("_gui_input", &AnimationTreeEditor::_gui_input); - //ClassDB::bind_method( "_node_param_changed", &AnimationTreeEditor::_node_param_changed ); - ClassDB::bind_method("_scroll_moved", &AnimationTreeEditor::_scroll_moved); - ClassDB::bind_method("_edit_dialog_changeds", &AnimationTreeEditor::_edit_dialog_changeds); - ClassDB::bind_method("_edit_dialog_changede", &AnimationTreeEditor::_edit_dialog_changede); - ClassDB::bind_method("_edit_dialog_changedf", &AnimationTreeEditor::_edit_dialog_changedf); - ClassDB::bind_method("_edit_dialog_changed", &AnimationTreeEditor::_edit_dialog_changed); - ClassDB::bind_method("_edit_dialog_animation_changed", &AnimationTreeEditor::_edit_dialog_animation_changed); - ClassDB::bind_method("_edit_dialog_edit_animation", &AnimationTreeEditor::_edit_dialog_edit_animation); - ClassDB::bind_method("_play_toggled", &AnimationTreeEditor::_play_toggled); - ClassDB::bind_method("_edit_oneshot_start", &AnimationTreeEditor::_edit_oneshot_start); - ClassDB::bind_method("_file_dialog_selected", &AnimationTreeEditor::_file_dialog_selected); - ClassDB::bind_method("_master_anim_menu_item", &AnimationTreeEditor::_master_anim_menu_item); - ClassDB::bind_method("_edit_filters", &AnimationTreeEditor::_edit_filters); - ClassDB::bind_method("_filter_edited", &AnimationTreeEditor::_filter_edited); + return ret; } AnimationTreeEditor::AnimationTreeEditor() { - set_focus_mode(FOCUS_ALL); - - PopupMenu *p; - List<PropertyInfo> defaults; - - add_menu = memnew(MenuButton); - //add_menu->set_ - add_menu->set_position(Point2(0, 0)); - add_menu->set_size(Point2(25, 15)); - add_child(add_menu); - - p = add_menu->get_popup(); - p->add_item(TTR("Animation Node"), AnimationTreePlayer::NODE_ANIMATION); - p->add_item(TTR("OneShot Node"), AnimationTreePlayer::NODE_ONESHOT); - p->add_item(TTR("Mix Node"), AnimationTreePlayer::NODE_MIX); - p->add_item(TTR("Blend2 Node"), AnimationTreePlayer::NODE_BLEND2); - p->add_item(TTR("Blend3 Node"), AnimationTreePlayer::NODE_BLEND3); - p->add_item(TTR("Blend4 Node"), AnimationTreePlayer::NODE_BLEND4); - p->add_item(TTR("TimeScale Node"), AnimationTreePlayer::NODE_TIMESCALE); - p->add_item(TTR("TimeSeek Node"), AnimationTreePlayer::NODE_TIMESEEK); - p->add_item(TTR("Transition Node"), AnimationTreePlayer::NODE_TRANSITION); - p->add_separator(); - p->add_item(TTR("Import Animations..."), MENU_IMPORT_ANIMATIONS); // wtf - p->add_separator(); - p->add_item(TTR("Clear"), MENU_GRAPH_CLEAR); - - p->connect("id_pressed", this, "_add_menu_item"); - - play_button = memnew(Button); - play_button->set_position(Point2(25, 0)); - play_button->set_size(Point2(25, 15)); - add_child(play_button); - play_button->set_toggle_mode(true); - play_button->connect("pressed", this, "_play_toggled"); - - last_x = 50; - last_y = 50; - - property_editor = memnew(CustomPropertyEditor); - add_child(property_editor); - property_editor->connect("variant_changed", this, "_edit_dialog_animation_changed"); - property_editor->connect("resource_edit_request", this, "_edit_dialog_edit_animation"); - - h_scroll = memnew(HScrollBar); - v_scroll = memnew(VScrollBar); - - add_child(h_scroll); - add_child(v_scroll); - - h_scroll->connect("value_changed", this, "_scroll_moved"); - v_scroll->connect("value_changed", this, "_scroll_moved"); - - node_popup = memnew(PopupMenu); - add_child(node_popup); - node_popup->set_as_toplevel(true); - - master_anim_popup = memnew(PopupMenu); - add_child(master_anim_popup); - master_anim_popup->connect("id_pressed", this, "_master_anim_menu_item"); - - node_popup->connect("id_pressed", this, "_node_menu_item"); - - updating_edit = false; - - edit_dialog = memnew(PopupPanel); - //edit_dialog->get_ok()->hide(); - //edit_dialog->get_cancel()->hide(); - add_child(edit_dialog); - - edit_option = memnew(OptionButton); - edit_option->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_option->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_option); - edit_option->connect("item_selected", this, "_edit_dialog_changedf"); - edit_option->hide(); - - for (int i = 0; i < 2; i++) { - edit_scroll[i] = memnew(HSlider); - edit_scroll[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_scroll[i]->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_scroll[i]); - edit_scroll[i]->hide(); - edit_scroll[i]->connect("value_changed", this, "_edit_dialog_changedf"); - } - for (int i = 0; i < 4; i++) { - edit_line[i] = memnew(LineEdit); - edit_line[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_line[i]->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_line[i]); - edit_line[i]->hide(); - edit_line[i]->connect("text_changed", this, "_edit_dialog_changeds"); - edit_line[i]->connect("text_entered", this, "_edit_dialog_changede"); - edit_label[i] = memnew(Label); - edit_dialog->add_child(edit_label[i]); - edit_label[i]->hide(); - } - - edit_button = memnew(Button); - edit_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_button->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_button); - edit_button->hide(); - edit_button->connect("pressed", this, "_edit_oneshot_start"); - - edit_check = memnew(CheckButton); - edit_check->set_anchor(MARGIN_RIGHT, ANCHOR_END); - edit_check->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(edit_check); - edit_check->hide(); - edit_check->connect("pressed", this, "_edit_dialog_changed"); - - file_dialog = memnew(EditorFileDialog); - file_dialog->set_enable_multiple_selection(true); - file_dialog->set_current_dir(ProjectSettings::get_singleton()->get_resource_path()); - add_child(file_dialog); - file_dialog->connect("file_selected", this, "_file_dialog_selected"); - - filter_dialog = memnew(AcceptDialog); - filter_dialog->set_title(TTR("Edit Node Filters")); - add_child(filter_dialog); - - filter = memnew(Tree); - filter_dialog->add_child(filter); - //filter_dialog->set_child_rect(filter); - filter->connect("item_edited", this, "_filter_edited"); + AnimationNodeAnimation::get_editable_animation_list = get_animation_list; + path_edit = memnew(ScrollContainer); + add_child(path_edit); + path_edit->set_enable_h_scroll(true); + path_edit->set_enable_v_scroll(false); + path_hb = memnew(HBoxContainer); + path_edit->add_child(path_hb); - filter_button = memnew(Button); - filter_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); - filter_button->set_margin(MARGIN_RIGHT, -10); - edit_dialog->add_child(filter_button); - filter_button->hide(); - filter_button->set_text(TTR("Filters...")); - filter_button->connect("pressed", this, "_edit_filters"); + current_root = 0; + singleton = this; + editor_base = memnew(PanelContainer); + editor_base->set_v_size_flags(SIZE_EXPAND_FILL); + add_child(editor_base); - set_clip_contents(true); + add_plugin(memnew(AnimationNodeBlendTreeEditor)); + add_plugin(memnew(AnimationNodeBlendSpace1DEditor)); + add_plugin(memnew(AnimationNodeBlendSpace2DEditor)); + add_plugin(memnew(AnimationNodeStateMachineEditor)); } void AnimationTreeEditorPlugin::edit(Object *p_object) { - anim_tree_editor->edit(Object::cast_to<AnimationTreePlayer>(p_object)); + anim_tree_editor->edit(Object::cast_to<AnimationTree>(p_object)); } bool AnimationTreeEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("AnimationTreePlayer"); + return p_object->is_class("AnimationTree"); } void AnimationTreeEditorPlugin::make_visible(bool p_visible) { @@ -1422,13 +251,13 @@ void AnimationTreeEditorPlugin::make_visible(bool p_visible) { //editor->animation_panel_make_visible(true); button->show(); editor->make_bottom_panel_item_visible(anim_tree_editor); - anim_tree_editor->set_physics_process(true); + anim_tree_editor->set_process(true); } else { if (anim_tree_editor->is_visible_in_tree()) editor->hide_bottom_panel(); button->hide(); - anim_tree_editor->set_physics_process(false); + anim_tree_editor->set_process(false); } } diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h index aeb5b1744f..b12054bb62 100644 --- a/editor/plugins/animation_tree_editor_plugin.h +++ b/editor/plugins/animation_tree_editor_plugin.h @@ -1,167 +1,65 @@ -/*************************************************************************/ -/* animation_tree_editor_plugin.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - #ifndef ANIMATION_TREE_EDITOR_PLUGIN_H #define ANIMATION_TREE_EDITOR_PLUGIN_H #include "editor/editor_node.h" #include "editor/editor_plugin.h" #include "editor/property_editor.h" -#include "scene/animation/animation_tree_player.h" +#include "scene/animation/animation_tree.h" #include "scene/gui/button.h" +#include "scene/gui/graph_edit.h" #include "scene/gui/popup.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - -class AnimationTreeEditor : public Control { - - GDCLASS(AnimationTreeEditor, Control); - - static const char *_node_type_names[]; - - enum ClickType { - CLICK_NONE, - CLICK_NAME, - CLICK_NODE, - CLICK_INPUT_SLOT, - CLICK_OUTPUT_SLOT, - CLICK_PARAMETER - }; - - enum { - - MENU_GRAPH_CLEAR = 100, - MENU_IMPORT_ANIMATIONS = 101, - NODE_DISCONNECT, - NODE_RENAME, - NODE_ERASE, - NODE_ADD_INPUT, - NODE_DELETE_INPUT, - NODE_SET_AUTOADVANCE, - NODE_CLEAR_AUTOADVANCE - }; - - bool renaming_edit; - StringName edited_node; - bool updating_edit; - Popup *edit_dialog; - HSlider *edit_scroll[2]; - LineEdit *edit_line[4]; - OptionButton *edit_option; - Label *edit_label[4]; - Button *edit_button; - Button *filter_button; - CheckButton *edit_check; - EditorFileDialog *file_dialog; - int file_op; - - void _popup_edit_dialog(); - - void _setup_edit_dialog(const StringName &p_node); - PopupMenu *master_anim_popup; - PopupMenu *node_popup; - PopupMenu *add_popup; - HScrollBar *h_scroll; - VScrollBar *v_scroll; - MenuButton *add_menu; - - CustomPropertyEditor *property_editor; - - AnimationTreePlayer *anim_tree; - List<StringName> order; - Set<StringName> active_nodes; - - int last_x, last_y; - - Point2 offset; - ClickType click_type; - Point2 click_pos; - StringName click_node; - int click_slot; - Point2 click_motion; - ClickType rclick_type; - StringName rclick_node; - int rclick_slot; - - Button *play_button; - - Size2 _get_maximum_size(); - Size2 get_node_size(const StringName &p_node) const; - void _draw_node(const StringName &p_node); - - AcceptDialog *filter_dialog; - Tree *filter; - - void _draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color); - void _update_scrollbars(); - void _scroll_moved(float); - void _play_toggled(); - /* - void _node_param_changed(); - void _node_add_callback(); - void _node_add(VisualServer::AnimationTreeNodeType p_type); - void _node_edit_property(const StringName& p_node); -*/ - - void _master_anim_menu_item(int p_item); - void _node_menu_item(int p_item); - void _add_menu_item(int p_item); - - void _filter_edited(); - void _find_paths_for_filter(const StringName &p_node, Set<String> &paths); - void _edit_filters(); - - void _edit_oneshot_start(); - void _edit_dialog_animation_changed(); - void _edit_dialog_edit_animation(); - void _edit_dialog_changeds(String); - void _edit_dialog_changede(String); - void _edit_dialog_changedf(float); - void _edit_dialog_changed(); - void _dialog_changed() const; - ClickType _locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const; - Point2 _get_slot_pos(const StringName &p_node_id, bool p_input, int p_slot); - - StringName _add_node(int p_item); - void _file_dialog_selected(String p_path); + +class AnimationTreeNodeEditorPlugin : public VBoxContainer { + GDCLASS(AnimationTreeNodeEditorPlugin, VBoxContainer) +public: + virtual bool can_edit(const Ref<AnimationNode> &p_node) = 0; + virtual void edit(const Ref<AnimationNode> &p_node) = 0; +}; + +class AnimationTreeEditor : public VBoxContainer { + + GDCLASS(AnimationTreeEditor, VBoxContainer); + + ScrollContainer *path_edit; + HBoxContainer *path_hb; + + AnimationTree *tree; + PanelContainer *editor_base; + + Vector<String> button_path; + Vector<String> edited_path; + Vector<AnimationTreeNodeEditorPlugin *> editors; + + void _update_path(); + void _about_to_show_root(); + ObjectID current_root; + + void _path_button_pressed(int p_path); + + static Vector<String> get_animation_list(); protected: void _notification(int p_what); - void _gui_input(Ref<InputEvent> p_event); static void _bind_methods(); + static AnimationTreeEditor *singleton; + public: - virtual Size2 get_minimum_size() const; - void edit(AnimationTreePlayer *p_anim_tree); + AnimationTree *get_tree() { return tree; } + void add_plugin(AnimationTreeNodeEditorPlugin *p_editor); + void remove_plugin(AnimationTreeNodeEditorPlugin *p_editor); + + String get_base_path(); + + bool can_edit(const Ref<AnimationNode> &p_node) const; + + void edit_path(const Vector<String> &p_path); + Vector<String> get_edited_path() const; + + void enter_editor(const String &p_path = ""); + static AnimationTreeEditor *get_singleton() { return singleton; } + void edit(AnimationTree *p_tree); AnimationTreeEditor(); }; @@ -174,7 +72,7 @@ class AnimationTreeEditorPlugin : public EditorPlugin { Button *button; public: - virtual String get_name() const { return "AnimTree"; } + virtual String get_name() const { return "AnimationTree"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_object); virtual bool handles(Object *p_object) const; diff --git a/editor/plugins/animation_tree_player_editor_plugin.cpp b/editor/plugins/animation_tree_player_editor_plugin.cpp new file mode 100644 index 0000000000..36d10ab99e --- /dev/null +++ b/editor/plugins/animation_tree_player_editor_plugin.cpp @@ -0,0 +1,1446 @@ +/*************************************************************************/ +/* animation_tree_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "animation_tree_player_editor_plugin.h" + +#include "core/io/resource_loader.h" +#include "core/project_settings.h" +#include "os/input.h" +#include "os/keyboard.h" +#include "scene/gui/menu_button.h" +#include "scene/gui/panel.h" +#include "scene/main/viewport.h" + +void AnimationTreePlayerEditor::edit(AnimationTreePlayer *p_anim_tree) { + + anim_tree = p_anim_tree; + + if (!anim_tree) { + hide(); + } else { + order.clear(); + p_anim_tree->get_node_list(&order); + /* + for(List<StringName>::Element* E=order.front();E;E=E->next()) { + + if (E->get() >= (int)last_id) + last_id=E->get()+1; + }*/ + play_button->set_pressed(p_anim_tree->is_active()); + //read the orders + } +} + +Size2 AnimationTreePlayerEditor::_get_maximum_size() { + + Size2 max; + + for (List<StringName>::Element *E = order.front(); E; E = E->next()) { + + Point2 pos = anim_tree->node_get_position(E->get()); + + if (click_type == CLICK_NODE && click_node == E->get()) { + + pos += click_motion - click_pos; + } + pos += get_node_size(E->get()); + if (pos.x > max.x) + max.x = pos.x; + if (pos.y > max.y) + max.y = pos.y; + } + + return max; +} + +const char *AnimationTreePlayerEditor::_node_type_names[] = { "Output", "Animation", "OneShot", "Mix", "Blend2", "Blend3", "Blend4", "TimeScale", "TimeSeek", "Transition" }; + +Size2 AnimationTreePlayerEditor::get_node_size(const StringName &p_node) const { + + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node); + + Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Ref<Font> font = get_font("font", "PopupMenu"); + + Size2 size = style->get_minimum_size(); + + int count = 2; // title and name + int inputs = anim_tree->node_get_input_count(p_node); + count += inputs ? inputs : 1; + String name = p_node; + + float name_w = font->get_string_size(name).width; + float type_w = font->get_string_size(String(_node_type_names[type])).width; + float max_w = MAX(name_w, type_w); + + switch (type) { + case AnimationTreePlayer::NODE_TIMESEEK: + case AnimationTreePlayer::NODE_OUTPUT: { + } break; + case AnimationTreePlayer::NODE_ANIMATION: + case AnimationTreePlayer::NODE_ONESHOT: + case AnimationTreePlayer::NODE_MIX: + case AnimationTreePlayer::NODE_BLEND2: + case AnimationTreePlayer::NODE_BLEND3: + case AnimationTreePlayer::NODE_BLEND4: + case AnimationTreePlayer::NODE_TIMESCALE: + case AnimationTreePlayer::NODE_TRANSITION: { + + size.height += font->get_height(); + } break; + case AnimationTreePlayer::NODE_MAX: { + } + } + + size.x += max_w + 20; + size.y += count * (font->get_height() + get_constant("vseparation", "PopupMenu")); + + return size; +} + +void AnimationTreePlayerEditor::_edit_dialog_changede(String) { + + edit_dialog->hide(); +} + +void AnimationTreePlayerEditor::_edit_dialog_changeds(String s) { + + _edit_dialog_changed(); +} + +void AnimationTreePlayerEditor::_edit_dialog_changedf(float) { + + _edit_dialog_changed(); +} + +void AnimationTreePlayerEditor::_edit_dialog_changed() { + + if (updating_edit) + return; + + if (renaming_edit) { + + if (anim_tree->node_rename(edited_node, edit_line[0]->get_text()) == OK) { + for (List<StringName>::Element *E = order.front(); E; E = E->next()) { + + if (E->get() == edited_node) + E->get() = edit_line[0]->get_text(); + } + edited_node = edit_line[0]->get_text(); + } + update(); + return; + } + + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node); + + switch (type) { + + case AnimationTreePlayer::NODE_TIMESCALE: + anim_tree->timescale_node_set_scale(edited_node, edit_line[0]->get_text().to_double()); + break; + case AnimationTreePlayer::NODE_ONESHOT: + anim_tree->oneshot_node_set_fadein_time(edited_node, edit_line[0]->get_text().to_double()); + anim_tree->oneshot_node_set_fadeout_time(edited_node, edit_line[1]->get_text().to_double()); + anim_tree->oneshot_node_set_autorestart_delay(edited_node, edit_line[2]->get_text().to_double()); + anim_tree->oneshot_node_set_autorestart_random_delay(edited_node, edit_line[3]->get_text().to_double()); + anim_tree->oneshot_node_set_autorestart(edited_node, edit_check->is_pressed()); + anim_tree->oneshot_node_set_mix_mode(edited_node, edit_option->get_selected()); + + break; + + case AnimationTreePlayer::NODE_MIX: + + anim_tree->mix_node_set_amount(edited_node, edit_scroll[0]->get_value()); + break; + case AnimationTreePlayer::NODE_BLEND2: + anim_tree->blend2_node_set_amount(edited_node, edit_scroll[0]->get_value()); + + break; + + case AnimationTreePlayer::NODE_BLEND3: + anim_tree->blend3_node_set_amount(edited_node, edit_scroll[0]->get_value()); + + break; + case AnimationTreePlayer::NODE_BLEND4: + + anim_tree->blend4_node_set_amount(edited_node, Point2(edit_scroll[0]->get_value(), edit_scroll[1]->get_value())); + + break; + + case AnimationTreePlayer::NODE_TRANSITION: { + anim_tree->transition_node_set_xfade_time(edited_node, edit_line[0]->get_text().to_double()); + if (anim_tree->transition_node_get_current(edited_node) != edit_option->get_selected()) + anim_tree->transition_node_set_current(edited_node, edit_option->get_selected()); + } break; + default: {} + } +} + +void AnimationTreePlayerEditor::_edit_dialog_animation_changed() { + + Ref<Animation> anim = property_editor->get_variant().operator RefPtr(); + anim_tree->animation_node_set_animation(edited_node, anim); + update(); +} + +void AnimationTreePlayerEditor::_edit_dialog_edit_animation() { + + if (Engine::get_singleton()->is_editor_hint()) { + get_tree()->get_root()->get_child(0)->call("_resource_selected", property_editor->get_variant().operator RefPtr()); + }; +}; + +void AnimationTreePlayerEditor::_edit_oneshot_start() { + + anim_tree->oneshot_node_start(edited_node); +} + +void AnimationTreePlayerEditor::_play_toggled() { + + anim_tree->set_active(play_button->is_pressed()); +} + +void AnimationTreePlayerEditor::_master_anim_menu_item(int p_item) { + + if (p_item == 0) + _edit_filters(); + else { + + String str = master_anim_popup->get_item_text(p_item); + anim_tree->animation_node_set_master_animation(edited_node, str); + } + update(); +} + +void AnimationTreePlayerEditor::_popup_edit_dialog() { + + updating_edit = true; + + for (int i = 0; i < 2; i++) + edit_scroll[i]->hide(); + + for (int i = 0; i < 4; i++) { + + edit_line[i]->hide(); + edit_label[i]->hide(); + } + + edit_option->hide(); + edit_button->hide(); + filter_button->hide(); + edit_check->hide(); + + Point2 pos = anim_tree->node_get_position(edited_node) - Point2(h_scroll->get_value(), v_scroll->get_value()); + Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Size2 size = get_node_size(edited_node); + Point2 popup_pos(pos.x + style->get_margin(MARGIN_LEFT), pos.y + size.y - style->get_margin(MARGIN_BOTTOM)); + popup_pos += get_global_position(); + + if (renaming_edit) { + + edit_label[0]->set_text(TTR("New name:")); + edit_label[0]->set_position(Point2(5, 5)); + edit_label[0]->show(); + edit_line[0]->set_begin(Point2(15, 25)); + edit_line[0]->set_text(edited_node); + edit_line[0]->show(); + edit_dialog->set_size(Size2(150, 50)); + + } else { + + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node); + + switch (type) { + + case AnimationTreePlayer::NODE_ANIMATION: + + if (anim_tree->get_master_player() != NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && Object::cast_to<AnimationPlayer>(anim_tree->get_node(anim_tree->get_master_player()))) { + + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(anim_tree->get_node(anim_tree->get_master_player())); + master_anim_popup->clear(); + master_anim_popup->add_item(TTR("Edit Filters")); + master_anim_popup->add_separator(); + List<StringName> sn; + ap->get_animation_list(&sn); + sn.sort_custom<StringName::AlphCompare>(); + for (List<StringName>::Element *E = sn.front(); E; E = E->next()) { + master_anim_popup->add_item(E->get()); + } + + master_anim_popup->set_position(popup_pos); + master_anim_popup->popup(); + } else { + property_editor->edit(this, "", Variant::OBJECT, anim_tree->animation_node_get_animation(edited_node), PROPERTY_HINT_RESOURCE_TYPE, "Animation"); + property_editor->set_position(popup_pos); + property_editor->popup(); + updating_edit = false; + } + return; + case AnimationTreePlayer::NODE_TIMESCALE: + edit_label[0]->set_text(TTR("Scale:")); + edit_label[0]->set_position(Point2(5, 5)); + edit_label[0]->show(); + edit_line[0]->set_begin(Point2(15, 25)); + edit_line[0]->set_text(rtos(anim_tree->timescale_node_get_scale(edited_node))); + edit_line[0]->show(); + edit_dialog->set_size(Size2(150, 50)); + break; + case AnimationTreePlayer::NODE_ONESHOT: + edit_label[0]->set_text(TTR("Fade In (s):")); + edit_label[0]->set_position(Point2(5, 5)); + edit_label[0]->show(); + edit_line[0]->set_begin(Point2(15, 25)); + edit_line[0]->set_text(rtos(anim_tree->oneshot_node_get_fadein_time(edited_node))); + edit_line[0]->show(); + edit_label[1]->set_text(TTR("Fade Out (s):")); + edit_label[1]->set_position(Point2(5, 55)); + edit_label[1]->show(); + edit_line[1]->set_begin(Point2(15, 75)); + edit_line[1]->set_text(rtos(anim_tree->oneshot_node_get_fadeout_time(edited_node))); + edit_line[1]->show(); + + edit_option->clear(); + edit_option->add_item(TTR("Blend"), 0); + edit_option->add_item(TTR("Mix"), 1); + edit_option->set_begin(Point2(15, 105)); + + edit_option->select(anim_tree->oneshot_node_get_mix_mode(edited_node)); + edit_option->show(); + + edit_check->set_text(TTR("Auto Restart:")); + edit_check->set_begin(Point2(15, 125)); + edit_check->set_pressed(anim_tree->oneshot_node_has_autorestart(edited_node)); + edit_check->show(); + + edit_label[2]->set_text(TTR("Restart (s):")); + edit_label[2]->set_position(Point2(5, 145)); + edit_label[2]->show(); + edit_line[2]->set_begin(Point2(15, 165)); + edit_line[2]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_delay(edited_node))); + edit_line[2]->show(); + edit_label[3]->set_text(TTR("Random Restart (s):")); + edit_label[3]->set_position(Point2(5, 195)); + edit_label[3]->show(); + edit_line[3]->set_begin(Point2(15, 215)); + edit_line[3]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_random_delay(edited_node))); + edit_line[3]->show(); + + filter_button->set_begin(Point2(10, 245)); + filter_button->show(); + + edit_button->set_begin(Point2(10, 268)); + edit_button->set_text(TTR("Start!")); + + edit_button->show(); + + edit_dialog->set_size(Size2(180, 293)); + + break; + + case AnimationTreePlayer::NODE_MIX: + + edit_label[0]->set_text(TTR("Amount:")); + edit_label[0]->set_position(Point2(5, 5)); + edit_label[0]->show(); + edit_scroll[0]->set_min(0); + edit_scroll[0]->set_max(1); + edit_scroll[0]->set_step(0.01); + edit_scroll[0]->set_value(anim_tree->mix_node_get_amount(edited_node)); + edit_scroll[0]->set_begin(Point2(15, 25)); + edit_scroll[0]->show(); + edit_dialog->set_size(Size2(150, 50)); + + break; + case AnimationTreePlayer::NODE_BLEND2: + edit_label[0]->set_text(TTR("Blend:")); + edit_label[0]->set_position(Point2(5, 5)); + edit_label[0]->show(); + edit_scroll[0]->set_min(0); + edit_scroll[0]->set_max(1); + edit_scroll[0]->set_step(0.01); + edit_scroll[0]->set_value(anim_tree->blend2_node_get_amount(edited_node)); + edit_scroll[0]->set_begin(Point2(15, 25)); + edit_scroll[0]->show(); + filter_button->set_begin(Point2(10, 47)); + filter_button->show(); + edit_dialog->set_size(Size2(150, 74)); + + break; + + case AnimationTreePlayer::NODE_BLEND3: + edit_label[0]->set_text(TTR("Blend:")); + edit_label[0]->set_position(Point2(5, 5)); + edit_label[0]->show(); + edit_scroll[0]->set_min(-1); + edit_scroll[0]->set_max(1); + edit_scroll[0]->set_step(0.01); + edit_scroll[0]->set_value(anim_tree->blend3_node_get_amount(edited_node)); + edit_scroll[0]->set_begin(Point2(15, 25)); + edit_scroll[0]->show(); + edit_dialog->set_size(Size2(150, 50)); + + break; + case AnimationTreePlayer::NODE_BLEND4: + + edit_label[0]->set_text(TTR("Blend 0:")); + edit_label[0]->set_position(Point2(5, 5)); + edit_label[0]->show(); + edit_scroll[0]->set_min(0); + edit_scroll[0]->set_max(1); + edit_scroll[0]->set_step(0.01); + edit_scroll[0]->set_value(anim_tree->blend4_node_get_amount(edited_node).x); + edit_scroll[0]->set_begin(Point2(15, 25)); + edit_scroll[0]->show(); + edit_label[1]->set_text(TTR("Blend 1:")); + edit_label[1]->set_position(Point2(5, 55)); + edit_label[1]->show(); + edit_scroll[1]->set_min(0); + edit_scroll[1]->set_max(1); + edit_scroll[1]->set_step(0.01); + edit_scroll[1]->set_value(anim_tree->blend4_node_get_amount(edited_node).y); + edit_scroll[1]->set_begin(Point2(15, 75)); + edit_scroll[1]->show(); + edit_dialog->set_size(Size2(150, 100)); + + break; + + case AnimationTreePlayer::NODE_TRANSITION: { + + edit_label[0]->set_text(TTR("X-Fade Time (s):")); + edit_label[0]->set_position(Point2(5, 5)); + edit_label[0]->show(); + edit_line[0]->set_begin(Point2(15, 25)); + edit_line[0]->set_text(rtos(anim_tree->transition_node_get_xfade_time(edited_node))); + edit_line[0]->show(); + + edit_label[1]->set_text(TTR("Current:")); + edit_label[1]->set_position(Point2(5, 55)); + edit_label[1]->show(); + edit_option->set_begin(Point2(15, 75)); + + edit_option->clear(); + + for (int i = 0; i < anim_tree->transition_node_get_input_count(edited_node); i++) { + edit_option->add_item(itos(i), i); + } + + edit_option->select(anim_tree->transition_node_get_current(edited_node)); + edit_option->show(); + edit_dialog->set_size(Size2(150, 100)); + + } break; + default: {} + } + } + + edit_dialog->set_position(popup_pos); + edit_dialog->popup(); + + updating_edit = false; +} + +void AnimationTreePlayerEditor::_draw_node(const StringName &p_node) { + + RID ci = get_canvas_item(); + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node); + + Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Ref<Font> font = get_font("font", "PopupMenu"); + Color font_color = get_color("font_color", "PopupMenu"); + Color font_color_title = get_color("font_color_hover", "PopupMenu"); + font_color_title.a *= 0.8; + Ref<Texture> slot_icon = get_icon("VisualShaderPort", "EditorIcons"); + + Size2 size = get_node_size(p_node); + Point2 pos = anim_tree->node_get_position(p_node); + if (click_type == CLICK_NODE && click_node == p_node) { + + pos += click_motion - click_pos; + if (pos.x < 5) + pos.x = 5; + if (pos.y < 5) + pos.y = 5; + } + + pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); + + style->draw(ci, Rect2(pos, size)); + + float w = size.width - style->get_minimum_size().width; + float h = font->get_height() + get_constant("vseparation", "PopupMenu"); + + Point2 ofs = style->get_offset() + pos; + Point2 ascofs(0, font->get_ascent()); + + Color bx = font_color_title; + bx.a *= 0.1; + draw_rect(Rect2(ofs, Size2(size.width - style->get_minimum_size().width, font->get_height())), bx); + font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, String(_node_type_names[type]), font_color_title); + + ofs.y += h; + font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, p_node, font_color); + ofs.y += h; + + int count = 2; // title and name + int inputs = anim_tree->node_get_input_count(p_node); + count += inputs ? inputs : 1; + + float icon_h_ofs = Math::floor((font->get_height() - slot_icon->get_height()) / 2.0) + 1; + + if (type != AnimationTreePlayer::NODE_OUTPUT) + slot_icon->draw(ci, ofs + Point2(w, icon_h_ofs)); //output + + if (inputs) { + for (int i = 0; i < inputs; i++) { + + slot_icon->draw(ci, ofs + Point2(-slot_icon->get_width(), icon_h_ofs)); + String text; + switch (type) { + + case AnimationTreePlayer::NODE_TIMESCALE: + case AnimationTreePlayer::NODE_TIMESEEK: text = "in"; break; + case AnimationTreePlayer::NODE_OUTPUT: text = "out"; break; + case AnimationTreePlayer::NODE_ANIMATION: break; + case AnimationTreePlayer::NODE_ONESHOT: text = (i == 0 ? "in" : "add"); break; + case AnimationTreePlayer::NODE_BLEND2: + case AnimationTreePlayer::NODE_MIX: text = (i == 0 ? "a" : "b"); break; + case AnimationTreePlayer::NODE_BLEND3: + switch (i) { + case 0: text = "b-"; break; + case 1: text = "a"; break; + case 2: text = "b+"; break; + } + break; + + case AnimationTreePlayer::NODE_BLEND4: + switch (i) { + case 0: text = "a0"; break; + case 1: text = "b0"; break; + case 2: text = "a1"; break; + case 3: text = "b1"; break; + } + break; + + case AnimationTreePlayer::NODE_TRANSITION: + text = itos(i); + if (anim_tree->transition_node_has_input_auto_advance(p_node, i)) + text += "->"; + + break; + default: {} + } + font->draw(ci, ofs + ascofs + Point2(3, 0), text, font_color); + + ofs.y += h; + } + } else { + ofs.y += h; + } + + Ref<StyleBox> pg_bg = get_stylebox("bg", "ProgressBar"); + Ref<StyleBox> pg_fill = get_stylebox("fill", "ProgressBar"); + Rect2 pg_rect(ofs, Size2(w, h)); + + bool editable = true; + switch (type) { + case AnimationTreePlayer::NODE_ANIMATION: { + + Ref<Animation> anim = anim_tree->animation_node_get_animation(p_node); + String text; + if (anim_tree->animation_node_get_master_animation(p_node) != "") + text = anim_tree->animation_node_get_master_animation(p_node); + else if (anim.is_null()) + text = "load..."; + else + text = anim->get_name(); + + font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, text, font_color_title); + + } break; + case AnimationTreePlayer::NODE_ONESHOT: + case AnimationTreePlayer::NODE_MIX: + case AnimationTreePlayer::NODE_BLEND2: + case AnimationTreePlayer::NODE_BLEND3: + case AnimationTreePlayer::NODE_BLEND4: + case AnimationTreePlayer::NODE_TIMESCALE: + case AnimationTreePlayer::NODE_TRANSITION: { + + font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, "edit...", font_color_title); + } break; + default: editable = false; + } + + if (editable) { + + Ref<Texture> arrow = get_icon("GuiDropdown", "EditorIcons"); + Point2 arrow_ofs(w - arrow->get_width(), Math::floor((h - arrow->get_height()) / 2)); + arrow->draw(ci, ofs + arrow_ofs); + } +} + +AnimationTreePlayerEditor::ClickType AnimationTreePlayerEditor::_locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const { + + Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Ref<Font> font = get_font("font", "PopupMenu"); + + float h = (font->get_height() + get_constant("vseparation", "PopupMenu")); + + for (const List<StringName>::Element *E = order.back(); E; E = E->prev()) { + + StringName node = E->get(); + + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(node); + + Point2 pos = anim_tree->node_get_position(node); + Size2 size = get_node_size(node); + + pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); + + if (!Rect2(pos, size).has_point(p_click)) + continue; + + if (p_node_id) + *p_node_id = node; + + pos = p_click - pos; + + float y = pos.y - style->get_offset().height; + + if (y < 2 * h) + return CLICK_NODE; + y -= 2 * h; + + int inputs = anim_tree->node_get_input_count(node); + int count = MAX(inputs, 1); + + if (inputs == 0 || (pos.x > size.width / 2 && type != AnimationTreePlayer::NODE_OUTPUT)) { + + if (y < count * h) { + + if (p_slot_index) + *p_slot_index = 0; + return CLICK_OUTPUT_SLOT; + } + } + + for (int i = 0; i < count; i++) { + + if (y < h) { + if (p_slot_index) + *p_slot_index = i; + return CLICK_INPUT_SLOT; + } + y -= h; + } + + bool has_parameters = type != AnimationTreePlayer::NODE_OUTPUT && type != AnimationTreePlayer::NODE_TIMESEEK; + return has_parameters ? CLICK_PARAMETER : CLICK_NODE; + } + + return CLICK_NONE; +} + +Point2 AnimationTreePlayerEditor::_get_slot_pos(const StringName &p_node_id, bool p_input, int p_slot) { + + Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Ref<Font> font = get_font("font", "PopupMenu"); + Ref<Texture> slot_icon = get_icon("VisualShaderPort", "EditorIcons"); + + Size2 size = get_node_size(p_node_id); + Point2 pos = anim_tree->node_get_position(p_node_id); + + if (click_type == CLICK_NODE && click_node == p_node_id) { + + pos += click_motion - click_pos; + if (pos.x < 5) + pos.x = 5; + if (pos.y < 5) + pos.y = 5; + } + + pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); + + float w = size.width - style->get_minimum_size().width; + float h = font->get_height() + get_constant("vseparation", "PopupMenu"); + + pos += style->get_offset(); + + pos.y += h * 2; + + pos.y += h * p_slot; + + pos += Point2(-slot_icon->get_width() / 2.0, h / 2.0).floor(); + + if (!p_input) { + pos.x += w + slot_icon->get_width(); + } + + return pos; +} + +void AnimationTreePlayerEditor::_gui_input(Ref<InputEvent> p_event) { + + Ref<InputEventMouseButton> mb = p_event; + + if (mb.is_valid()) { + + if (mb->is_pressed()) { + + if (mb->get_button_index() == 1) { + click_pos = Point2(mb->get_position().x, mb->get_position().y); + click_motion = click_pos; + click_type = _locate_click(click_pos, &click_node, &click_slot); + if (click_type != CLICK_NONE) { + + order.erase(click_node); + order.push_back(click_node); + update(); + } + + switch (click_type) { + case CLICK_INPUT_SLOT: { + click_pos = _get_slot_pos(click_node, true, click_slot); + } break; + case CLICK_OUTPUT_SLOT: { + click_pos = _get_slot_pos(click_node, false, click_slot); + } break; + case CLICK_PARAMETER: { + + edited_node = click_node; + renaming_edit = false; + _popup_edit_dialog(); + //open editor + //_node_edit_property(click_node); + } break; + default: {} + } + } + if (mb->get_button_index() == 2) { + + if (click_type != CLICK_NONE) { + click_type = CLICK_NONE; + update(); + } else { + // try to disconnect/remove + + Point2 rclick_pos = Point2(mb->get_position().x, mb->get_position().y); + rclick_type = _locate_click(rclick_pos, &rclick_node, &rclick_slot); + if (rclick_type == CLICK_INPUT_SLOT || rclick_type == CLICK_OUTPUT_SLOT) { + + node_popup->clear(); + node_popup->set_size(Size2(1, 1)); + node_popup->add_item(TTR("Disconnect"), NODE_DISCONNECT); + if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) { + node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT); + if (rclick_type == CLICK_INPUT_SLOT) { + if (anim_tree->transition_node_has_input_auto_advance(rclick_node, rclick_slot)) + node_popup->add_item(TTR("Clear Auto-Advance"), NODE_CLEAR_AUTOADVANCE); + else + node_popup->add_item(TTR("Set Auto-Advance"), NODE_SET_AUTOADVANCE); + node_popup->add_item(TTR("Delete Input"), NODE_DELETE_INPUT); + } + } + + node_popup->set_position(rclick_pos + get_global_position()); + node_popup->popup(); + } + + if (rclick_type == CLICK_NODE) { + node_popup->clear(); + node_popup->set_size(Size2(1, 1)); + node_popup->add_item(TTR("Rename"), NODE_RENAME); + node_popup->add_item(TTR("Remove"), NODE_ERASE); + if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) + node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT); + node_popup->set_position(rclick_pos + get_global_position()); + node_popup->popup(); + } + } + } + } else { + + if (mb->get_button_index() == 1 && click_type != CLICK_NONE) { + + switch (click_type) { + case CLICK_INPUT_SLOT: + case CLICK_OUTPUT_SLOT: { + + Point2 dst_click_pos = Point2(mb->get_position().x, mb->get_position().y); + StringName id; + int slot; + ClickType dst_click_type = _locate_click(dst_click_pos, &id, &slot); + + if (dst_click_type == CLICK_INPUT_SLOT && click_type == CLICK_OUTPUT_SLOT) { + + anim_tree->connect_nodes(click_node, id, slot); + } + if (click_type == CLICK_INPUT_SLOT && dst_click_type == CLICK_OUTPUT_SLOT) { + + anim_tree->connect_nodes(id, click_node, click_slot); + } + + } break; + case CLICK_NODE: { + Point2 new_pos = anim_tree->node_get_position(click_node) + (click_motion - click_pos); + if (new_pos.x < 5) + new_pos.x = 5; + if (new_pos.y < 5) + new_pos.y = 5; + anim_tree->node_set_position(click_node, new_pos); + + } break; + default: {} + } + + click_type = CLICK_NONE; + update(); + } + } + } + + Ref<InputEventMouseMotion> mm = p_event; + + if (mm.is_valid()) { + + if (mm->get_button_mask() & 1 && click_type != CLICK_NONE) { + + click_motion = Point2(mm->get_position().x, mm->get_position().y); + update(); + } + if ((mm->get_button_mask() & 4 || Input::get_singleton()->is_key_pressed(KEY_SPACE))) { + + h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x); + v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y); + update(); + } + } +} + +void AnimationTreePlayerEditor::_draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color) { + + static const int steps = 20; + + Rect2 r; + r.position = p_from; + r.expand_to(p_to); + Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1); + bool flip = sign.x * sign.y < 0; + + Vector2 prev; + for (int i = 0; i <= steps; i++) { + + float d = i / float(steps); + float c = -Math::cos(d * Math_PI) * 0.5 + 0.5; + if (flip) + c = 1.0 - c; + Vector2 p = r.position + Vector2(d * r.size.width, c * r.size.height); + + if (i > 0) { + + draw_line(prev, p, p_color, 2); + } + + prev = p; + } +} + +void AnimationTreePlayerEditor::_notification(int p_what) { + + switch (p_what) { + + case NOTIFICATION_ENTER_TREE: { + + play_button->set_icon(get_icon("Play", "EditorIcons")); + add_menu->set_icon(get_icon("Add", "EditorIcons")); + } break; + case NOTIFICATION_DRAW: { + + _update_scrollbars(); + //VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(Point2(),get_size()),Color(0,0,0,1)); + get_stylebox("bg", "Tree")->draw(get_canvas_item(), Rect2(Point2(), get_size())); + + for (List<StringName>::Element *E = order.front(); E; E = E->next()) { + + _draw_node(E->get()); + } + + if (click_type == CLICK_INPUT_SLOT || click_type == CLICK_OUTPUT_SLOT) { + + _draw_cos_line(click_pos, click_motion, Color(0.5, 1, 0.5, 0.8)); + } + + List<AnimationTreePlayer::Connection> connections; + anim_tree->get_connection_list(&connections); + + for (List<AnimationTreePlayer::Connection>::Element *E = connections.front(); E; E = E->next()) { + + const AnimationTreePlayer::Connection &c = E->get(); + Point2 source = _get_slot_pos(c.src_node, false, 0); + Point2 dest = _get_slot_pos(c.dst_node, true, c.dst_input); + Color col = Color(1, 1, 0.5, 0.8); + /* + if (click_type==CLICK_NODE && click_node==c.src_node) { + + source+=click_motion-click_pos; + } + + if (click_type==CLICK_NODE && click_node==c.dst_node) { + + dest+=click_motion-click_pos; + }*/ + + _draw_cos_line(source, dest, col); + } + + switch (anim_tree->get_last_error()) { + + case AnimationTreePlayer::CONNECT_OK: { + + Ref<Font> f = get_font("font", "Label"); + f->draw(get_canvas_item(), Point2(5, 25 + f->get_ascent()), TTR("Animation tree is valid."), Color(0, 1, 0.6, 0.8)); + } break; + default: { + + Ref<Font> f = get_font("font", "Label"); + f->draw(get_canvas_item(), Point2(5, 25 + f->get_ascent()), TTR("Animation tree is invalid."), Color(1, 0.6, 0.0, 0.8)); + } break; + } + + } break; + } +} + +void AnimationTreePlayerEditor::_update_scrollbars() { + + Size2 size = get_size(); + Size2 hmin = h_scroll->get_combined_minimum_size(); + Size2 vmin = v_scroll->get_combined_minimum_size(); + + v_scroll->set_begin(Point2(size.width - vmin.width, 0)); + v_scroll->set_end(Point2(size.width, size.height)); + + h_scroll->set_begin(Point2(0, size.height - hmin.height)); + h_scroll->set_end(Point2(size.width - vmin.width, size.height)); + + Size2 min = _get_maximum_size(); + + if (min.height < size.height - hmin.height) { + + v_scroll->hide(); + offset.y = 0; + } else { + + v_scroll->show(); + v_scroll->set_max(min.height); + v_scroll->set_page(size.height - hmin.height); + offset.y = v_scroll->get_value(); + } + + if (min.width < size.width - vmin.width) { + + h_scroll->hide(); + offset.x = 0; + } else { + + h_scroll->show(); + h_scroll->set_max(min.width); + h_scroll->set_page(size.width - vmin.width); + offset.x = h_scroll->get_value(); + } +} + +void AnimationTreePlayerEditor::_scroll_moved(float) { + + offset.x = h_scroll->get_value(); + offset.y = v_scroll->get_value(); + update(); +} + +void AnimationTreePlayerEditor::_node_menu_item(int p_item) { + + switch (p_item) { + + case NODE_DISCONNECT: { + + if (rclick_type == CLICK_INPUT_SLOT) { + + anim_tree->disconnect_nodes(rclick_node, rclick_slot); + update(); + } + + if (rclick_type == CLICK_OUTPUT_SLOT) { + + List<AnimationTreePlayer::Connection> connections; + anim_tree->get_connection_list(&connections); + + for (List<AnimationTreePlayer::Connection>::Element *E = connections.front(); E; E = E->next()) { + + const AnimationTreePlayer::Connection &c = E->get(); + if (c.dst_node == rclick_node) { + + anim_tree->disconnect_nodes(c.dst_node, c.dst_input); + } + } + update(); + } + + } break; + case NODE_RENAME: { + + renaming_edit = true; + edited_node = rclick_node; + _popup_edit_dialog(); + + } break; + case NODE_ADD_INPUT: { + + anim_tree->transition_node_set_input_count(rclick_node, anim_tree->transition_node_get_input_count(rclick_node) + 1); + update(); + } break; + case NODE_DELETE_INPUT: { + + anim_tree->transition_node_delete_input(rclick_node, rclick_slot); + update(); + } break; + case NODE_SET_AUTOADVANCE: { + + anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, true); + update(); + + } break; + case NODE_CLEAR_AUTOADVANCE: { + + anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, false); + update(); + + } break; + + case NODE_ERASE: { + + if (rclick_node == "out") + break; + order.erase(rclick_node); + anim_tree->remove_node(rclick_node); + update(); + } break; + } +} + +StringName AnimationTreePlayerEditor::_add_node(int p_item) { + + static const char *bname[] = { + "out", + "anim", + "oneshot", + "mix", + "blend2", + "blend3", + "blend4", + "scale", + "seek", + "transition" + }; + + String name; + int idx = 1; + + while (true) { + + name = bname[p_item]; + if (idx > 1) + name += " " + itos(idx); + if (anim_tree->node_exists(name)) + idx++; + else + break; + } + + anim_tree->add_node((AnimationTreePlayer::NodeType)p_item, name); + anim_tree->node_set_position(name, Point2(last_x, last_y)); + order.push_back(name); + last_x += 10; + last_y += 10; + last_x = last_x % (int)get_size().width; + last_y = last_y % (int)get_size().height; + update(); + + return name; +}; + +void AnimationTreePlayerEditor::_file_dialog_selected(String p_path) { + + switch (file_op) { + + case MENU_IMPORT_ANIMATIONS: { + Vector<String> files = file_dialog->get_selected_files(); + + for (int i = 0; i < files.size(); i++) { + + StringName node = _add_node(AnimationTreePlayer::NODE_ANIMATION); + + RES anim = ResourceLoader::load(files[i]); + anim_tree->animation_node_set_animation(node, anim); + //anim_tree->node_set_name(node, files[i].get_file()); + }; + } break; + + default: + break; + }; +}; + +void AnimationTreePlayerEditor::_add_menu_item(int p_item) { + + if (p_item == MENU_GRAPH_CLEAR) { + + //clear + } else if (p_item == MENU_IMPORT_ANIMATIONS) { + + file_op = MENU_IMPORT_ANIMATIONS; + file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); + file_dialog->popup_centered_ratio(); + + } else { + + _add_node(p_item); + } +} + +Size2 AnimationTreePlayerEditor::get_minimum_size() const { + + return Size2(10, 200); +} + +void AnimationTreePlayerEditor::_find_paths_for_filter(const StringName &p_node, Set<String> &paths) { + + ERR_FAIL_COND(!anim_tree->node_exists(p_node)); + + for (int i = 0; i < anim_tree->node_get_input_count(p_node); i++) { + + StringName port = anim_tree->node_get_input_source(p_node, i); + if (port == StringName()) + continue; + _find_paths_for_filter(port, paths); + } + + if (anim_tree->node_get_type(p_node) == AnimationTreePlayer::NODE_ANIMATION) { + + Ref<Animation> anim = anim_tree->animation_node_get_animation(p_node); + if (anim.is_valid()) { + + for (int i = 0; i < anim->get_track_count(); i++) { + paths.insert(anim->track_get_path(i)); + } + } + } +} + +void AnimationTreePlayerEditor::_filter_edited() { + + TreeItem *ed = filter->get_edited(); + if (!ed) + return; + + if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) { + anim_tree->oneshot_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); + } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) { + anim_tree->blend2_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); + } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) { + anim_tree->animation_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); + } +} + +void AnimationTreePlayerEditor::_edit_filters() { + + filter_dialog->popup_centered_ratio(); + filter->clear(); + + Set<String> npb; + _find_paths_for_filter(edited_node, npb); + + TreeItem *root = filter->create_item(); + filter->set_hide_root(true); + Map<String, TreeItem *> pm; + + Node *base = anim_tree->get_node(anim_tree->get_base_path()); + + for (Set<String>::Element *E = npb.front(); E; E = E->next()) { + + TreeItem *parent = root; + String descr = E->get(); + if (base) { + NodePath np = E->get(); + + if (np.get_subname_count() == 1) { + Node *n = base->get_node(np); + Skeleton *s = Object::cast_to<Skeleton>(n); + if (s) { + + String skelbase = E->get().substr(0, E->get().find(":")); + + int bidx = s->find_bone(np.get_subname(0)); + + if (bidx != -1) { + int bparent = s->get_bone_parent(bidx); + // + if (bparent != -1) { + + String bpn = skelbase + ":" + s->get_bone_name(bparent); + if (pm.has(bpn)) { + parent = pm[bpn]; + descr = np.get_subname(0); + } + } else { + + if (pm.has(skelbase)) { + parent = pm[skelbase]; + } + } + } + } + } + } + + TreeItem *it = filter->create_item(parent); + it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + it->set_text(0, descr); + it->set_metadata(0, NodePath(E->get())); + it->set_editable(0, true); + if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) { + it->set_checked(0, anim_tree->oneshot_node_is_path_filtered(edited_node, E->get())); + } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) { + it->set_checked(0, anim_tree->blend2_node_is_path_filtered(edited_node, E->get())); + } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) { + it->set_checked(0, anim_tree->animation_node_is_path_filtered(edited_node, E->get())); + } + pm[E->get()] = it; + } +} + +void AnimationTreePlayerEditor::_bind_methods() { + + ClassDB::bind_method("_add_menu_item", &AnimationTreePlayerEditor::_add_menu_item); + ClassDB::bind_method("_node_menu_item", &AnimationTreePlayerEditor::_node_menu_item); + ClassDB::bind_method("_gui_input", &AnimationTreePlayerEditor::_gui_input); + //ClassDB::bind_method( "_node_param_changed", &AnimationTreeEditor::_node_param_changed ); + ClassDB::bind_method("_scroll_moved", &AnimationTreePlayerEditor::_scroll_moved); + ClassDB::bind_method("_edit_dialog_changeds", &AnimationTreePlayerEditor::_edit_dialog_changeds); + ClassDB::bind_method("_edit_dialog_changede", &AnimationTreePlayerEditor::_edit_dialog_changede); + ClassDB::bind_method("_edit_dialog_changedf", &AnimationTreePlayerEditor::_edit_dialog_changedf); + ClassDB::bind_method("_edit_dialog_changed", &AnimationTreePlayerEditor::_edit_dialog_changed); + ClassDB::bind_method("_edit_dialog_animation_changed", &AnimationTreePlayerEditor::_edit_dialog_animation_changed); + ClassDB::bind_method("_edit_dialog_edit_animation", &AnimationTreePlayerEditor::_edit_dialog_edit_animation); + ClassDB::bind_method("_play_toggled", &AnimationTreePlayerEditor::_play_toggled); + ClassDB::bind_method("_edit_oneshot_start", &AnimationTreePlayerEditor::_edit_oneshot_start); + ClassDB::bind_method("_file_dialog_selected", &AnimationTreePlayerEditor::_file_dialog_selected); + ClassDB::bind_method("_master_anim_menu_item", &AnimationTreePlayerEditor::_master_anim_menu_item); + ClassDB::bind_method("_edit_filters", &AnimationTreePlayerEditor::_edit_filters); + ClassDB::bind_method("_filter_edited", &AnimationTreePlayerEditor::_filter_edited); +} + +AnimationTreePlayerEditor::AnimationTreePlayerEditor() { + + set_focus_mode(FOCUS_ALL); + + PopupMenu *p; + List<PropertyInfo> defaults; + + add_menu = memnew(MenuButton); + //add_menu->set_ + add_menu->set_position(Point2(0, 0)); + add_menu->set_size(Point2(25, 15)); + add_child(add_menu); + + p = add_menu->get_popup(); + p->add_item(TTR("Animation Node"), AnimationTreePlayer::NODE_ANIMATION); + p->add_item(TTR("OneShot Node"), AnimationTreePlayer::NODE_ONESHOT); + p->add_item(TTR("Mix Node"), AnimationTreePlayer::NODE_MIX); + p->add_item(TTR("Blend2 Node"), AnimationTreePlayer::NODE_BLEND2); + p->add_item(TTR("Blend3 Node"), AnimationTreePlayer::NODE_BLEND3); + p->add_item(TTR("Blend4 Node"), AnimationTreePlayer::NODE_BLEND4); + p->add_item(TTR("TimeScale Node"), AnimationTreePlayer::NODE_TIMESCALE); + p->add_item(TTR("TimeSeek Node"), AnimationTreePlayer::NODE_TIMESEEK); + p->add_item(TTR("Transition Node"), AnimationTreePlayer::NODE_TRANSITION); + p->add_separator(); + p->add_item(TTR("Import Animations..."), MENU_IMPORT_ANIMATIONS); // wtf + p->add_separator(); + p->add_item(TTR("Clear"), MENU_GRAPH_CLEAR); + + p->connect("id_pressed", this, "_add_menu_item"); + + play_button = memnew(Button); + play_button->set_position(Point2(25, 0)); + play_button->set_size(Point2(25, 15)); + add_child(play_button); + play_button->set_toggle_mode(true); + play_button->connect("pressed", this, "_play_toggled"); + + last_x = 50; + last_y = 50; + + property_editor = memnew(CustomPropertyEditor); + add_child(property_editor); + property_editor->connect("variant_changed", this, "_edit_dialog_animation_changed"); + property_editor->connect("resource_edit_request", this, "_edit_dialog_edit_animation"); + + h_scroll = memnew(HScrollBar); + v_scroll = memnew(VScrollBar); + + add_child(h_scroll); + add_child(v_scroll); + + h_scroll->connect("value_changed", this, "_scroll_moved"); + v_scroll->connect("value_changed", this, "_scroll_moved"); + + node_popup = memnew(PopupMenu); + add_child(node_popup); + node_popup->set_as_toplevel(true); + + master_anim_popup = memnew(PopupMenu); + add_child(master_anim_popup); + master_anim_popup->connect("id_pressed", this, "_master_anim_menu_item"); + + node_popup->connect("id_pressed", this, "_node_menu_item"); + + updating_edit = false; + + edit_dialog = memnew(PopupPanel); + //edit_dialog->get_ok()->hide(); + //edit_dialog->get_cancel()->hide(); + add_child(edit_dialog); + + edit_option = memnew(OptionButton); + edit_option->set_anchor(MARGIN_RIGHT, ANCHOR_END); + edit_option->set_margin(MARGIN_RIGHT, -10); + edit_dialog->add_child(edit_option); + edit_option->connect("item_selected", this, "_edit_dialog_changedf"); + edit_option->hide(); + + for (int i = 0; i < 2; i++) { + edit_scroll[i] = memnew(HSlider); + edit_scroll[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); + edit_scroll[i]->set_margin(MARGIN_RIGHT, -10); + edit_dialog->add_child(edit_scroll[i]); + edit_scroll[i]->hide(); + edit_scroll[i]->connect("value_changed", this, "_edit_dialog_changedf"); + } + for (int i = 0; i < 4; i++) { + edit_line[i] = memnew(LineEdit); + edit_line[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); + edit_line[i]->set_margin(MARGIN_RIGHT, -10); + edit_dialog->add_child(edit_line[i]); + edit_line[i]->hide(); + edit_line[i]->connect("text_changed", this, "_edit_dialog_changeds"); + edit_line[i]->connect("text_entered", this, "_edit_dialog_changede"); + edit_label[i] = memnew(Label); + edit_dialog->add_child(edit_label[i]); + edit_label[i]->hide(); + } + + edit_button = memnew(Button); + edit_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); + edit_button->set_margin(MARGIN_RIGHT, -10); + edit_dialog->add_child(edit_button); + edit_button->hide(); + edit_button->connect("pressed", this, "_edit_oneshot_start"); + + edit_check = memnew(CheckButton); + edit_check->set_anchor(MARGIN_RIGHT, ANCHOR_END); + edit_check->set_margin(MARGIN_RIGHT, -10); + edit_dialog->add_child(edit_check); + edit_check->hide(); + edit_check->connect("pressed", this, "_edit_dialog_changed"); + + file_dialog = memnew(EditorFileDialog); + file_dialog->set_enable_multiple_selection(true); + file_dialog->set_current_dir(ProjectSettings::get_singleton()->get_resource_path()); + add_child(file_dialog); + file_dialog->connect("file_selected", this, "_file_dialog_selected"); + + filter_dialog = memnew(AcceptDialog); + filter_dialog->set_title(TTR("Edit Node Filters")); + add_child(filter_dialog); + + filter = memnew(Tree); + filter_dialog->add_child(filter); + //filter_dialog->set_child_rect(filter); + filter->connect("item_edited", this, "_filter_edited"); + + filter_button = memnew(Button); + filter_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); + filter_button->set_margin(MARGIN_RIGHT, -10); + edit_dialog->add_child(filter_button); + filter_button->hide(); + filter_button->set_text(TTR("Filters...")); + filter_button->connect("pressed", this, "_edit_filters"); + + set_clip_contents(true); +} + +void AnimationTreePlayerEditorPlugin::edit(Object *p_object) { + + anim_tree_editor->edit(Object::cast_to<AnimationTreePlayer>(p_object)); +} + +bool AnimationTreePlayerEditorPlugin::handles(Object *p_object) const { + + return p_object->is_class("AnimationTreePlayer"); +} + +void AnimationTreePlayerEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + //editor->hide_animation_player_editors(); + //editor->animation_panel_make_visible(true); + button->show(); + editor->make_bottom_panel_item_visible(anim_tree_editor); + anim_tree_editor->set_physics_process(true); + } else { + + if (anim_tree_editor->is_visible_in_tree()) + editor->hide_bottom_panel(); + button->hide(); + anim_tree_editor->set_physics_process(false); + } +} + +AnimationTreePlayerEditorPlugin::AnimationTreePlayerEditorPlugin(EditorNode *p_node) { + + editor = p_node; + anim_tree_editor = memnew(AnimationTreePlayerEditor); + anim_tree_editor->set_custom_minimum_size(Size2(0, 300)); + + button = editor->add_bottom_panel_item(TTR("AnimationTree"), anim_tree_editor); + button->hide(); +} + +AnimationTreePlayerEditorPlugin::~AnimationTreePlayerEditorPlugin() { +} diff --git a/editor/plugins/animation_tree_player_editor_plugin.h b/editor/plugins/animation_tree_player_editor_plugin.h new file mode 100644 index 0000000000..d1c5f395e4 --- /dev/null +++ b/editor/plugins/animation_tree_player_editor_plugin.h @@ -0,0 +1,187 @@ +/*************************************************************************/ +/* animation_tree_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef ANIMATION_TREE_PLAYER_EDITOR_PLUGIN_H +#define ANIMATION_TREE_PLAYER_EDITOR_PLUGIN_H + +#include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "editor/property_editor.h" +#include "scene/animation/animation_tree_player.h" +#include "scene/gui/button.h" +#include "scene/gui/popup.h" +#include "scene/gui/tree.h" +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ + +class AnimationTreePlayerEditor : public Control { + + GDCLASS(AnimationTreePlayerEditor, Control); + + static const char *_node_type_names[]; + + enum ClickType { + CLICK_NONE, + CLICK_NAME, + CLICK_NODE, + CLICK_INPUT_SLOT, + CLICK_OUTPUT_SLOT, + CLICK_PARAMETER + }; + + enum { + + MENU_GRAPH_CLEAR = 100, + MENU_IMPORT_ANIMATIONS = 101, + NODE_DISCONNECT, + NODE_RENAME, + NODE_ERASE, + NODE_ADD_INPUT, + NODE_DELETE_INPUT, + NODE_SET_AUTOADVANCE, + NODE_CLEAR_AUTOADVANCE + }; + + bool renaming_edit; + StringName edited_node; + bool updating_edit; + Popup *edit_dialog; + HSlider *edit_scroll[2]; + LineEdit *edit_line[4]; + OptionButton *edit_option; + Label *edit_label[4]; + Button *edit_button; + Button *filter_button; + CheckButton *edit_check; + EditorFileDialog *file_dialog; + int file_op; + + void _popup_edit_dialog(); + + void _setup_edit_dialog(const StringName &p_node); + PopupMenu *master_anim_popup; + PopupMenu *node_popup; + PopupMenu *add_popup; + HScrollBar *h_scroll; + VScrollBar *v_scroll; + MenuButton *add_menu; + + CustomPropertyEditor *property_editor; + + AnimationTreePlayer *anim_tree; + List<StringName> order; + Set<StringName> active_nodes; + + int last_x, last_y; + + Point2 offset; + ClickType click_type; + Point2 click_pos; + StringName click_node; + int click_slot; + Point2 click_motion; + ClickType rclick_type; + StringName rclick_node; + int rclick_slot; + + Button *play_button; + + Size2 _get_maximum_size(); + Size2 get_node_size(const StringName &p_node) const; + void _draw_node(const StringName &p_node); + + AcceptDialog *filter_dialog; + Tree *filter; + + void _draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color); + void _update_scrollbars(); + void _scroll_moved(float); + void _play_toggled(); + /* + void _node_param_changed(); + void _node_add_callback(); + void _node_add(VisualServer::AnimationTreeNodeType p_type); + void _node_edit_property(const StringName& p_node); +*/ + + void _master_anim_menu_item(int p_item); + void _node_menu_item(int p_item); + void _add_menu_item(int p_item); + + void _filter_edited(); + void _find_paths_for_filter(const StringName &p_node, Set<String> &paths); + void _edit_filters(); + + void _edit_oneshot_start(); + void _edit_dialog_animation_changed(); + void _edit_dialog_edit_animation(); + void _edit_dialog_changeds(String); + void _edit_dialog_changede(String); + void _edit_dialog_changedf(float); + void _edit_dialog_changed(); + void _dialog_changed() const; + ClickType _locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const; + Point2 _get_slot_pos(const StringName &p_node_id, bool p_input, int p_slot); + + StringName _add_node(int p_item); + void _file_dialog_selected(String p_path); + +protected: + void _notification(int p_what); + void _gui_input(Ref<InputEvent> p_event); + static void _bind_methods(); + +public: + virtual Size2 get_minimum_size() const; + void edit(AnimationTreePlayer *p_anim_tree); + AnimationTreePlayerEditor(); +}; + +class AnimationTreePlayerEditorPlugin : public EditorPlugin { + + GDCLASS(AnimationTreePlayerEditorPlugin, EditorPlugin); + + AnimationTreePlayerEditor *anim_tree_editor; + EditorNode *editor; + Button *button; + +public: + virtual String get_name() const { return "AnimTree"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_object); + virtual bool handles(Object *p_object) const; + virtual void make_visible(bool p_visible); + + AnimationTreePlayerEditorPlugin(EditorNode *p_node); + ~AnimationTreePlayerEditorPlugin(); +}; + +#endif // ANIMATION_TREE_EDITOR_PLUGIN_H diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 4ed2b051aa..66770d98e5 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -421,7 +421,16 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { int cstatus = download->get_http_client_status(); if (cstatus == HTTPClient::STATUS_BODY) { - status->set_text(vformat(TTR("Downloading (%s / %s)..."), String::humanize_size(download->get_downloaded_bytes()), String::humanize_size(download->get_body_size()))); + if (download->get_body_size() > 0) { + status->set_text( + vformat( + TTR("Downloading (%s / %s)..."), + String::humanize_size(download->get_downloaded_bytes()), + String::humanize_size(download->get_body_size()))); + } else { + // Total file size is unknown, so it cannot be displayed + status->set_text(TTR("Downloading...")); + } } if (cstatus != prev_status) { diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 145a2ef9bb..72248b62a3 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -2276,14 +2276,14 @@ void CanvasItemEditor::_draw_grid() { real_grid_offset = grid_offset; } - const Color grid_minor_color = get_color("grid_minor_color", "Editor"); + const Color grid_color = EditorSettings::get_singleton()->get("editors/2d/grid_color"); if (grid_step.x != 0) { for (int i = 0; i < s.width; i++) { int cell = Math::fast_ftoi(Math::floor((xform.xform(Vector2(i, 0)).x - real_grid_offset.x) / (grid_step.x * Math::pow(2.0, grid_step_multiplier)))); if (i == 0) last_cell = cell; if (last_cell != cell) - viewport->draw_line(Point2(i, 0), Point2(i, s.height), grid_minor_color); + viewport->draw_line(Point2(i, 0), Point2(i, s.height), grid_color); last_cell = cell; } } @@ -2294,7 +2294,7 @@ void CanvasItemEditor::_draw_grid() { if (i == 0) last_cell = cell; if (last_cell != cell) - viewport->draw_line(Point2(0, i), Point2(s.width, i), grid_minor_color); + viewport->draw_line(Point2(0, i), Point2(s.width, i), grid_color); last_cell = cell; } } diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 49c54ad67d..f5bdf77973 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -616,8 +616,8 @@ void CurveEditor::_draw() { Vector2 min_edge = get_world_pos(Vector2(0, view_size.y)); Vector2 max_edge = get_world_pos(Vector2(view_size.x, 0)); - const Color grid_color0 = get_color("grid_major_color", "Editor"); - const Color grid_color1 = get_color("grid_minor_color", "Editor"); + const Color grid_color0 = Color(1.0, 1.0, 1.0, 0.15); + const Color grid_color1 = Color(1.0, 1.0, 1.0, 0.07); draw_line(Vector2(min_edge.x, curve.get_min_value()), Vector2(max_edge.x, curve.get_min_value()), grid_color0); draw_line(Vector2(max_edge.x, curve.get_max_value()), Vector2(min_edge.x, curve.get_max_value()), grid_color0); draw_line(Vector2(0, min_edge.y), Vector2(0, max_edge.y), grid_color0); diff --git a/editor/plugins/cube_grid_theme_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp index 68d5ea5247..a4d2905c0e 100644 --- a/editor/plugins/cube_grid_theme_editor_plugin.cpp +++ b/editor/plugins/mesh_library_editor_plugin.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* cube_grid_theme_editor_plugin.cpp */ +/* mesh_library_editor_plugin.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "cube_grid_theme_editor_plugin.h" +#include "mesh_library_editor_plugin.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" @@ -38,6 +38,7 @@ #include "scene/3d/physics_body.h" #include "scene/main/viewport.h" #include "scene/resources/packed_scene.h" +#include "spatial_editor_plugin.h" void MeshLibraryEditor::edit(const Ref<MeshLibrary> &p_theme) { @@ -241,21 +242,20 @@ MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) { add_child(file); file->connect("file_selected", this, "_import_scene_cbk"); - Panel *panel = memnew(Panel); - panel->set_anchors_and_margins_preset(Control::PRESET_WIDE); - add_child(panel); - MenuButton *options = memnew(MenuButton); - panel->add_child(options); - options->set_position(Point2(1, 1)); - options->set_text("Theme"); - options->get_popup()->add_item(TTR("Add Item"), MENU_OPTION_ADD_ITEM); - options->get_popup()->add_item(TTR("Remove Selected Item"), MENU_OPTION_REMOVE_ITEM); - options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Import from Scene"), MENU_OPTION_IMPORT_FROM_SCENE); - options->get_popup()->add_item(TTR("Update from Scene"), MENU_OPTION_UPDATE_FROM_SCENE); - options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), true); - options->get_popup()->connect("id_pressed", this, "_menu_cbk"); - menu = options; + menu = memnew(MenuButton); + SpatialEditor::get_singleton()->add_control_to_menu_panel(menu); + menu->set_position(Point2(1, 1)); + menu->set_text("Mesh Library"); + menu->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshLibrary", "EditorIcons")); + menu->get_popup()->add_item(TTR("Add Item"), MENU_OPTION_ADD_ITEM); + menu->get_popup()->add_item(TTR("Remove Selected Item"), MENU_OPTION_REMOVE_ITEM); + menu->get_popup()->add_separator(); + menu->get_popup()->add_item(TTR("Import from Scene"), MENU_OPTION_IMPORT_FROM_SCENE); + menu->get_popup()->add_item(TTR("Update from Scene"), MENU_OPTION_UPDATE_FROM_SCENE); + menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), true); + menu->get_popup()->connect("id_pressed", this, "_menu_cbk"); + menu->hide(); + editor = p_editor; cd = memnew(ConfirmationDialog); add_child(cd); @@ -278,10 +278,13 @@ bool MeshLibraryEditorPlugin::handles(Object *p_node) const { void MeshLibraryEditorPlugin::make_visible(bool p_visible) { - if (p_visible) + if (p_visible) { theme_editor->show(); - else + theme_editor->get_menu_button()->show(); + } else { theme_editor->hide(); + theme_editor->get_menu_button()->hide(); + } } MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) { diff --git a/editor/plugins/cube_grid_theme_editor_plugin.h b/editor/plugins/mesh_library_editor_plugin.h index 36a8f8f203..dc2d488bd6 100644 --- a/editor/plugins/cube_grid_theme_editor_plugin.h +++ b/editor/plugins/mesh_library_editor_plugin.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* cube_grid_theme_editor_plugin.h */ +/* mesh_library_editor_plugin.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef CUBE_GRID_THEME_EDITOR_PLUGIN_H -#define CUBE_GRID_THEME_EDITOR_PLUGIN_H +#ifndef MESH_LIBRARY_EDITOR_PLUGIN_H +#define MESH_LIBRARY_EDITOR_PLUGIN_H #include "editor/editor_node.h" #include "scene/resources/mesh_library.h" @@ -65,6 +65,8 @@ protected: static void _bind_methods(); public: + MenuButton *get_menu_button() const { return menu; } + void edit(const Ref<MeshLibrary> &p_theme); static Error update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge = true); @@ -88,4 +90,4 @@ public: MeshLibraryEditorPlugin(EditorNode *p_node); }; -#endif // CUBE_GRID_THEME_EDITOR_PLUGIN_H +#endif // MESH_LIBRARY_EDITOR_PLUGIN_H diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 9782b9d1f4..7ad117deb6 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -4352,10 +4352,13 @@ void SpatialEditor::_menu_item_pressed(int p_option) { bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); - is_checked = !is_checked; - VisualServer::get_singleton()->instance_set_visible(origin_instance, is_checked); + origin_enabled = !is_checked; + VisualServer::get_singleton()->instance_set_visible(origin_instance, origin_enabled); + // Update the grid since its appearance depends on whether the origin is enabled + _finish_grid(); + _init_grid(); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), is_checked); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), origin_enabled); } break; case MENU_VIEW_GRID: { @@ -4778,7 +4781,11 @@ void SpatialEditor::_init_grid() { Vector3 p2_dest = p2 * (-axis_n1 + axis_n2); Color line_color = secondary_grid_color; - if (j % primary_grid_steps == 0) { + if (origin_enabled && j == 0) { + // Don't draw the center lines of the grid if the origin is enabled + // The origin would overlap the grid lines in this case, causing flickering + continue; + } else if (j % primary_grid_steps == 0) { line_color = primary_grid_color; } @@ -5187,9 +5194,10 @@ void SpatialEditor::_register_all_gizmos() { register_gizmo_plugin(Ref<MeshInstanceSpatialGizmoPlugin>(memnew(MeshInstanceSpatialGizmoPlugin))); register_gizmo_plugin(Ref<SoftBodySpatialGizmoPlugin>(memnew(SoftBodySpatialGizmoPlugin))); register_gizmo_plugin(Ref<Sprite3DSpatialGizmoPlugin>(memnew(Sprite3DSpatialGizmoPlugin))); - register_gizmo_plugin(Ref<Position3DSpatialGizmoPlugin>(memnew(Position3DSpatialGizmoPlugin))); register_gizmo_plugin(Ref<SkeletonSpatialGizmoPlugin>(memnew(SkeletonSpatialGizmoPlugin))); + register_gizmo_plugin(Ref<Position3DSpatialGizmoPlugin>(memnew(Position3DSpatialGizmoPlugin))); register_gizmo_plugin(Ref<RayCastSpatialGizmoPlugin>(memnew(RayCastSpatialGizmoPlugin))); + register_gizmo_plugin(Ref<SpringArmSpatialGizmoPlugin>(memnew(SpringArmSpatialGizmoPlugin))); register_gizmo_plugin(Ref<VehicleWheelSpatialGizmoPlugin>(memnew(VehicleWheelSpatialGizmoPlugin))); register_gizmo_plugin(Ref<VisibilityNotifierGizmoPlugin>(memnew(VisibilityNotifierGizmoPlugin))); register_gizmo_plugin(Ref<ParticlesGizmoPlugin>(memnew(ParticlesGizmoPlugin))); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 4057145c2f..5850c0dbf1 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -508,6 +508,7 @@ private: RID origin; RID origin_instance; + bool origin_enabled; RID grid[3]; RID grid_instance[3]; bool grid_visible[3]; //currently visible diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index d13e01dc1e..4a9cbfe535 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -70,7 +70,7 @@ void TextureRegionEditor::_region_draw() { VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), Transform2D()); if (snap_mode == SNAP_GRID) { - Color grid_color = get_color("grid_major_color", "Editor"); + Color grid_color = Color(1.0, 1.0, 1.0, 0.15); Size2 s = edit_draw->get_size(); int last_cell = 0; diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 3d14db7d0e..0ba42cb101 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -426,6 +426,9 @@ void TileMapEditor::_update_palette() { Ref<Texture> tex = tileset->tile_get_texture(entries[i].id); if (tex.is_valid()) { + Color color = tileset->tile_get_modulate(entries[i].id); + palette->set_item_icon_modulate(palette->get_item_count() - 1, color); + Rect2 region = tileset->tile_get_region(entries[i].id); if (tileset->tile_get_tile_mode(entries[i].id) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(entries[i].id) == TileSet::ATLAS_TILE) { @@ -759,10 +762,13 @@ void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h rect.position = p_xform.xform(rect.position); rect.size *= sc; + Color modulate = node->get_tileset()->tile_get_modulate(p_cell); + modulate.a = 0.5; + if (r.has_no_area()) - canvas_item_editor->draw_texture_rect(t, rect, false, Color(1, 1, 1, 0.5), p_transpose); + canvas_item_editor->draw_texture_rect(t, rect, false, modulate, p_transpose); else - canvas_item_editor->draw_texture_rect_region(t, rect, r, Color(1, 1, 1, 0.5), p_transpose); + canvas_item_editor->draw_texture_rect_region(t, rect, r, modulate, p_transpose); } void TileMapEditor::_draw_fill_preview(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform) { diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 490ebeca26..1f891fe0fd 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -900,12 +900,13 @@ void TileSetEditor::_on_workspace_overlay_draw() { else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) c = COLOR_ATLAS; c.a = tile_names_opacity; + String tile_id_name = String::num(t_id, 0) + ": " + tileset->tile_get_name(t_id); Ref<Font> font = get_font("font", "Label"); - region.set_size(font->get_string_size(tileset->tile_get_name(t_id))); + region.set_size(font->get_string_size(tile_id_name)); workspace_overlay->draw_rect(region, c); region.position.y += region.size.y - 2; c = Color(0.1, 0.1, 0.1, tile_names_opacity); - workspace_overlay->draw_string(font, region.position, tileset->tile_get_name(t_id), c); + workspace_overlay->draw_string(font, region.position, tile_id_name, c); } } } diff --git a/editor/project_export.cpp b/editor/project_export.cpp index 3cebbb5d21..019d5d382c 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "project_export.h" + #include "compressed_translation.h" #include "editor_data.h" #include "editor_node.h" @@ -389,7 +390,6 @@ void ProjectExportDialog::_patch_deleted() { void ProjectExportDialog::_update_parameters(const String &p_edited_property) { _edit_preset(presets->get_current()); - parameters->update_tree(); } void ProjectExportDialog::_runnable_pressed() { @@ -842,12 +842,10 @@ ProjectExportDialog::ProjectExportDialog() { settings_vb->add_child(sections); sections->set_v_size_flags(SIZE_EXPAND_FILL); - parameters = memnew(PropertyEditor); + parameters = memnew(EditorInspector); sections->add_child(parameters); parameters->set_name(TTR("Options")); - parameters->hide_top_label(); parameters->set_v_size_flags(SIZE_EXPAND_FILL); - parameters->connect("property_edited", this, "_update_parameters"); VBoxContainer *resources_vb = memnew(VBoxContainer); diff --git a/editor/project_export.h b/editor/project_export.h index b62254974d..1f8723febd 100644 --- a/editor/project_export.h +++ b/editor/project_export.h @@ -31,26 +31,27 @@ #ifndef PROJECT_EXPORT_SETTINGS_H #define PROJECT_EXPORT_SETTINGS_H +#include "core/os/dir_access.h" +#include "core/os/thread.h" +#include "editor/editor_export.h" #include "editor/editor_file_dialog.h" -#include "os/dir_access.h" -#include "os/thread.h" +#include "editor/editor_file_system.h" +#include "editor/editor_inspector.h" #include "scene/gui/button.h" +#include "scene/gui/check_button.h" #include "scene/gui/control.h" #include "scene/gui/dialogs.h" #include "scene/gui/file_dialog.h" #include "scene/gui/label.h" #include "scene/gui/link_button.h" +#include "scene/gui/menu_button.h" #include "scene/gui/option_button.h" #include "scene/gui/rich_text_label.h" +#include "scene/gui/slider.h" #include "scene/gui/tab_container.h" #include "scene/gui/tree.h" #include "scene/main/timer.h" -#include "editor/editor_file_system.h" -#include "editor_export.h" -#include "property_editor.h" -#include "scene/gui/slider.h" - class EditorNode; class ProjectExportDialog : public ConfirmationDialog { @@ -64,12 +65,9 @@ private: ItemList *presets; LineEdit *name; - PropertyEditor *parameters; + EditorInspector *parameters; CheckButton *runnable; - //EditorFileDialog *pck_export; - //EditorFileDialog *file_export; - Button *button_export; bool updating; diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 970302e058..65b2e2301b 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -1007,6 +1007,7 @@ void ProjectSettingsEditor::_copy_to_platform_about_to_show() { Set<String> presets; + presets.insert("bptc"); presets.insert("s3tc"); presets.insert("etc"); presets.insert("etc2"); diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index 97147535c0..746e1cd28f 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -1240,6 +1240,9 @@ void ScriptEditorDebugger::stop() { if (connection.is_valid()) { EditorNode::get_log()->add_message("** Debug Process Stopped **"); connection.unref(); + + reason->set_text(""); + reason->set_tooltip(""); } pending_in_queue = 0; diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 64fdc778d0..64638cdb1e 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -677,7 +677,7 @@ void EditorSpatialGizmo::_bind_methods() { ClassDB::bind_method(D_METHOD("add_collision_segments", "segments"), &EditorSpatialGizmo::add_collision_segments); ClassDB::bind_method(D_METHOD("add_collision_triangles", "triangles"), &EditorSpatialGizmo::add_collision_triangles); ClassDB::bind_method(D_METHOD("add_unscaled_billboard", "material", "default_scale"), &EditorSpatialGizmo::add_unscaled_billboard, DEFVAL(1)); - ClassDB::bind_method(D_METHOD("add_handles", "handles", "billboard", "secondary"), &EditorSpatialGizmo::add_handles, DEFVAL(false), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("add_handles", "handles", "material", "billboard", "secondary"), &EditorSpatialGizmo::add_handles, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("set_spatial_node", "node"), &EditorSpatialGizmo::_set_spatial_node); ClassDB::bind_method(D_METHOD("clear"), &EditorSpatialGizmo::clear); ClassDB::bind_method(D_METHOD("set_hidden", "hidden"), &EditorSpatialGizmo::set_hidden); @@ -1337,6 +1337,48 @@ void CameraSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { p_gizmo->add_collision_segments(lines); p_gizmo->add_unscaled_billboard(icon, 0.05); p_gizmo->add_handles(handles, get_material("handles")); + + ClippedCamera *clipcam = Object::cast_to<ClippedCamera>(camera); + if (clipcam) { + Spatial *parent = Object::cast_to<Spatial>(camera->get_parent()); + if (!parent) { + return; + } + Vector3 cam_normal = -camera->get_global_transform().basis.get_axis(Vector3::AXIS_Z).normalized(); + Vector3 cam_x = camera->get_global_transform().basis.get_axis(Vector3::AXIS_X).normalized(); + Vector3 cam_y = camera->get_global_transform().basis.get_axis(Vector3::AXIS_Y).normalized(); + Vector3 cam_pos = camera->get_global_transform().origin; + Vector3 parent_pos = parent->get_global_transform().origin; + + Plane parent_plane(parent_pos, cam_normal); + Vector3 ray_from = parent_plane.project(cam_pos); + + lines.clear(); + lines.push_back(ray_from + cam_x * 0.5 + cam_y * 0.5); + lines.push_back(ray_from + cam_x * 0.5 + cam_y * -0.5); + + lines.push_back(ray_from + cam_x * 0.5 + cam_y * -0.5); + lines.push_back(ray_from + cam_x * -0.5 + cam_y * -0.5); + + lines.push_back(ray_from + cam_x * -0.5 + cam_y * -0.5); + lines.push_back(ray_from + cam_x * -0.5 + cam_y * 0.5); + + lines.push_back(ray_from + cam_x * -0.5 + cam_y * 0.5); + lines.push_back(ray_from + cam_x * 0.5 + cam_y * 0.5); + + if (parent_plane.distance_to(cam_pos) < 0) { + lines.push_back(ray_from); + lines.push_back(cam_pos); + } + + Transform local = camera->get_global_transform().affine_inverse(); + for (int i = 0; i < lines.size(); i++) { + lines.write[i] = local.xform(lines[i]); + } + + p_gizmo->add_lines(lines, material); + p_gizmo->add_collision_segments(lines); + } } ////// @@ -1920,6 +1962,38 @@ void RayCastSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { ///// +void SpringArmSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { + + SpringArm *spring_arm = Object::cast_to<SpringArm>(p_gizmo->get_spatial_node()); + + p_gizmo->clear(); + + Vector<Vector3> lines; + + lines.push_back(Vector3()); + lines.push_back(Vector3(0, 0, 1.0) * spring_arm->get_length()); + + Ref<SpatialMaterial> material = get_material("shape_material", p_gizmo); + + p_gizmo->add_lines(lines, material); + p_gizmo->add_collision_segments(lines); +} + +SpringArmSpatialGizmoPlugin::SpringArmSpatialGizmoPlugin() { + Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); + create_material("shape_material", gizmo_color); +} + +bool SpringArmSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) { + return Object::cast_to<SpringArm>(p_spatial) != NULL; +} + +String SpringArmSpatialGizmoPlugin::get_name() const { + return "SpringArm"; +} + +///// + VehicleWheelSpatialGizmoPlugin::VehicleWheelSpatialGizmoPlugin() { Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); diff --git a/editor/spatial_editor_gizmos.h b/editor/spatial_editor_gizmos.h index 877590b91d..6f29e9d999 100644 --- a/editor/spatial_editor_gizmos.h +++ b/editor/spatial_editor_gizmos.h @@ -49,6 +49,7 @@ #include "scene/3d/ray_cast.h" #include "scene/3d/reflection_probe.h" #include "scene/3d/room_instance.h" +#include "scene/3d/spring_arm.h" #include "scene/3d/sprite_3d.h" #include "scene/3d/vehicle_body.h" #include "scene/3d/visibility_notifier.h" @@ -196,6 +197,18 @@ public: RayCastSpatialGizmoPlugin(); }; +class SpringArmSpatialGizmoPlugin : public EditorSpatialGizmoPlugin { + + GDCLASS(SpringArmSpatialGizmoPlugin, EditorSpatialGizmoPlugin); + +public: + bool has_gizmo(Spatial *p_spatial); + String get_name() const; + void redraw(EditorSpatialGizmo *p_gizmo); + + SpringArmSpatialGizmoPlugin(); +}; + class VehicleWheelSpatialGizmoPlugin : public EditorSpatialGizmoPlugin { GDCLASS(VehicleWheelSpatialGizmoPlugin, EditorSpatialGizmoPlugin); @@ -330,14 +343,12 @@ public: }; class CollisionPolygonSpatialGizmoPlugin : public EditorSpatialGizmoPlugin { - GDCLASS(CollisionPolygonSpatialGizmoPlugin, EditorSpatialGizmoPlugin); public: bool has_gizmo(Spatial *p_spatial); String get_name() const; void redraw(EditorSpatialGizmo *p_gizmo); - CollisionPolygonSpatialGizmoPlugin(); }; diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index 0857635492..70f70e7e5f 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -163,6 +163,18 @@ Variant BulletPhysicsServer::shape_get_data(RID p_shape) const { return shape->get_data(); } +void BulletPhysicsServer::shape_set_margin(RID p_shape, real_t p_margin) { + ShapeBullet *shape = shape_owner.get(p_shape); + ERR_FAIL_COND(!shape); + shape->set_margin(p_margin); +} + +real_t BulletPhysicsServer::shape_get_margin(RID p_shape) const { + ShapeBullet *shape = shape_owner.get(p_shape); + ERR_FAIL_COND_V(!shape, 0.0); + return shape->get_margin(); +} + real_t BulletPhysicsServer::shape_get_custom_solver_bias(RID p_shape) const { //WARN_PRINT("Bias not supported by Bullet physics engine"); return 0.; @@ -861,12 +873,20 @@ PhysicsDirectBodyState *BulletPhysicsServer::body_get_direct_state(RID p_body) { return BulletPhysicsDirectBodyState::get_singleton(body); } -bool BulletPhysicsServer::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result) { +bool BulletPhysicsServer::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes) { RigidBodyBullet *body = rigid_body_owner.get(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); - return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, r_result); + return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, r_result, p_exclude_raycast_shapes); +} + +int BulletPhysicsServer::body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) { + RigidBodyBullet *body = rigid_body_owner.get(p_body); + ERR_FAIL_COND_V(!body, 0); + ERR_FAIL_COND_V(!body->get_space(), 0); + + return body->get_space()->test_ray_separation(body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin); } RID BulletPhysicsServer::soft_body_create(bool p_init_sleeping) { diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h index 0e858ff311..e9c568d605 100644 --- a/modules/bullet/bullet_physics_server.h +++ b/modules/bullet/bullet_physics_server.h @@ -99,6 +99,9 @@ public: virtual ShapeType shape_get_type(RID p_shape) const; virtual Variant shape_get_data(RID p_shape) const; + virtual void shape_set_margin(RID p_shape, real_t p_margin); + virtual real_t shape_get_margin(RID p_shape) const; + /// Not supported virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias); /// Not supported @@ -258,7 +261,8 @@ public: // this function only works on physics process, errors and returns null otherwise virtual PhysicsDirectBodyState *body_get_direct_state(RID p_body); - virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = NULL); + virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true); + virtual int body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001); /* SOFT BODY API */ diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp index 197550d686..534034d707 100644 --- a/modules/bullet/godot_result_callbacks.cpp +++ b/modules/bullet/godot_result_callbacks.cpp @@ -30,6 +30,7 @@ #include "godot_result_callbacks.h" +#include "area_bullet.h" #include "bullet_types_converter.h" #include "collision_object_bullet.h" #include "rigid_body_bullet.h" @@ -51,11 +52,23 @@ bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) co if (needs) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); - if (m_pickRay && gObj->is_ray_pickable()) { - return true; - } else if (m_exclude->has(gObj->get_self())) { + + if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { + if (!collide_with_areas) + return false; + } else { + if (!collide_with_bodies) + return false; + } + + if (m_pickRay && !gObj->is_ray_pickable()) { + return false; + } + + if (m_exclude->has(gObj->get_self())) { return false; } + return true; } else { return false; @@ -124,6 +137,15 @@ bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) if (needs) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); + + if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { + if (!collide_with_areas) + return false; + } else { + if (!collide_with_bodies) + return false; + } + if (m_exclude->has(gObj->get_self())) { return false; } @@ -144,6 +166,15 @@ bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) co if (needs) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); + + if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { + if (!collide_with_areas) + return false; + } else { + if (!collide_with_bodies) + return false; + } + if (m_exclude->has(gObj->get_self())) { return false; } @@ -189,6 +220,15 @@ bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *pr if (needs) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); + + if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { + if (!collide_with_areas) + return false; + } else { + if (!collide_with_bodies) + return false; + } + if (m_exclude->has(gObj->get_self())) { return false; } @@ -218,6 +258,15 @@ bool GodotRestInfoContactResultCallback::needsCollision(btBroadphaseProxy *proxy if (needs) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); + + if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { + if (!collide_with_areas) + return false; + } else { + if (!collide_with_bodies) + return false; + } + if (m_exclude->has(gObj->get_self())) { return false; } @@ -260,10 +309,19 @@ void GodotDeepPenetrationContactResultCallback::addContactPoint(const btVector3 if (m_penetration_distance > depth) { // Has penetration? - bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject(); + const bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject(); m_penetration_distance = depth; m_other_compound_shape_index = isSwapped ? m_index0 : m_index1; - m_pointNormalWorld = isSwapped ? normalOnBInWorld * -1 : normalOnBInWorld; m_pointWorld = isSwapped ? (pointInWorldOnB + (normalOnBInWorld * depth)) : pointInWorldOnB; + + const btCollisionObjectWrapper *bw0 = m_body0Wrap; + if (isSwapped) + bw0 = m_body1Wrap; + + if (bw0->getCollisionShape()->getShapeType() == CUSTOM_CONVEX_SHAPE_TYPE) { + m_pointNormalWorld = bw0->m_worldTransform.getBasis().transpose() * btVector3(0, 0, 1); + } else { + m_pointNormalWorld = isSwapped ? normalOnBInWorld * -1 : normalOnBInWorld; + } } } diff --git a/modules/bullet/godot_result_callbacks.h b/modules/bullet/godot_result_callbacks.h index 363051f24c..3948f43c00 100644 --- a/modules/bullet/godot_result_callbacks.h +++ b/modules/bullet/godot_result_callbacks.h @@ -56,12 +56,17 @@ struct GodotClosestRayResultCallback : public btCollisionWorld::ClosestRayResult bool m_pickRay; int m_shapeId; + bool collide_with_bodies; + bool collide_with_areas; + public: - GodotClosestRayResultCallback(const btVector3 &rayFromWorld, const btVector3 &rayToWorld, const Set<RID> *p_exclude) : + GodotClosestRayResultCallback(const btVector3 &rayFromWorld, const btVector3 &rayToWorld, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld), m_exclude(p_exclude), m_pickRay(false), - m_shapeId(0) {} + m_shapeId(0), + collide_with_bodies(p_collide_with_bodies), + collide_with_areas(p_collide_with_areas) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -108,9 +113,14 @@ public: const Set<RID> *m_exclude; int m_shapeId; - GodotClosestConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, const Set<RID> *p_exclude) : + bool collide_with_bodies; + bool collide_with_areas; + + GodotClosestConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : btCollisionWorld::ClosestConvexResultCallback(convexFromWorld, convexToWorld), - m_exclude(p_exclude) {} + m_exclude(p_exclude), + collide_with_bodies(p_collide_with_bodies), + collide_with_areas(p_collide_with_areas) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -125,12 +135,17 @@ public: int m_count; const Set<RID> *m_exclude; - GodotAllContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude) : + bool collide_with_bodies; + bool collide_with_areas; + + GodotAllContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : m_self_object(p_self_object), m_results(p_results), m_exclude(p_exclude), m_resultMax(p_resultMax), - m_count(0) {} + m_count(0), + collide_with_bodies(p_collide_with_bodies), + collide_with_areas(p_collide_with_areas) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -146,12 +161,17 @@ public: int m_count; const Set<RID> *m_exclude; - GodotContactPairContactResultCallback(btCollisionObject *p_self_object, Vector3 *p_results, int p_resultMax, const Set<RID> *p_exclude) : + bool collide_with_bodies; + bool collide_with_areas; + + GodotContactPairContactResultCallback(btCollisionObject *p_self_object, Vector3 *p_results, int p_resultMax, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : m_self_object(p_self_object), m_results(p_results), m_exclude(p_exclude), m_resultMax(p_resultMax), - m_count(0) {} + m_count(0), + collide_with_bodies(p_collide_with_bodies), + collide_with_areas(p_collide_with_areas) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -167,13 +187,17 @@ public: const btCollisionObject *m_rest_info_collision_object; btVector3 m_rest_info_bt_point; const Set<RID> *m_exclude; + bool collide_with_bodies; + bool collide_with_areas; - GodotRestInfoContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeRestInfo *p_result, const Set<RID> *p_exclude) : + GodotRestInfoContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeRestInfo *p_result, const Set<RID> *p_exclude, bool p_collide_with_bodies, bool p_collide_with_areas) : m_self_object(p_self_object), m_result(p_result), m_exclude(p_exclude), m_collided(false), - m_min_distance(0) {} + m_min_distance(0), + collide_with_bodies(p_collide_with_bodies), + collide_with_areas(p_collide_with_areas) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp index e4c1a5f9b5..fab8d0cf3d 100644 --- a/modules/bullet/shape_bullet.cpp +++ b/modules/bullet/shape_bullet.cpp @@ -44,19 +44,20 @@ @author AndreaCatania */ -ShapeBullet::ShapeBullet() {} +ShapeBullet::ShapeBullet() : + margin(0.04) {} ShapeBullet::~ShapeBullet() {} -btCollisionShape *ShapeBullet::create_bt_shape(const Vector3 &p_implicit_scale, real_t p_margin) { +btCollisionShape *ShapeBullet::create_bt_shape(const Vector3 &p_implicit_scale, real_t p_extra_edge) { btVector3 s; G_TO_B(p_implicit_scale, s); - return create_bt_shape(s, p_margin); + return create_bt_shape(s, p_extra_edge); } btCollisionShape *ShapeBullet::prepare(btCollisionShape *p_btShape) const { p_btShape->setUserPointer(const_cast<ShapeBullet *>(this)); - p_btShape->setMargin(0.); + p_btShape->setMargin(margin); return p_btShape; } @@ -93,6 +94,15 @@ const Map<ShapeOwnerBullet *, int> &ShapeBullet::get_owners() const { return owners; } +void ShapeBullet::set_margin(real_t p_margin) { + margin = p_margin; + notifyShapeChanged(); +} + +real_t ShapeBullet::get_margin() const { + return margin; +} + btEmptyShape *ShapeBullet::create_shape_empty() { return bulletnew(btEmptyShape); } @@ -166,7 +176,7 @@ void PlaneShapeBullet::setup(const Plane &p_plane) { notifyShapeChanged(); } -btCollisionShape *PlaneShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { +btCollisionShape *PlaneShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btVector3 btPlaneNormal; G_TO_B(plane.normal, btPlaneNormal); return prepare(PlaneShapeBullet::create_shape_plane(btPlaneNormal, plane.d)); @@ -194,8 +204,8 @@ void SphereShapeBullet::setup(real_t p_radius) { notifyShapeChanged(); } -btCollisionShape *SphereShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { - return prepare(ShapeBullet::create_shape_sphere(radius * p_implicit_scale[0] + p_margin)); +btCollisionShape *SphereShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { + return prepare(ShapeBullet::create_shape_sphere(radius * p_implicit_scale[0] + p_extra_edge)); } /* Box */ @@ -221,8 +231,8 @@ void BoxShapeBullet::setup(const Vector3 &p_half_extents) { notifyShapeChanged(); } -btCollisionShape *BoxShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { - return prepare(ShapeBullet::create_shape_box((half_extents * p_implicit_scale) + btVector3(p_margin, p_margin, p_margin))); +btCollisionShape *BoxShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { + return prepare(ShapeBullet::create_shape_box((half_extents * p_implicit_scale) + btVector3(p_extra_edge, p_extra_edge, p_extra_edge))); } /* Capsule */ @@ -254,8 +264,8 @@ void CapsuleShapeBullet::setup(real_t p_height, real_t p_radius) { notifyShapeChanged(); } -btCollisionShape *CapsuleShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { - return prepare(ShapeBullet::create_shape_capsule(radius * p_implicit_scale[0] + p_margin, height * p_implicit_scale[1] + p_margin)); +btCollisionShape *CapsuleShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { + return prepare(ShapeBullet::create_shape_capsule(radius * p_implicit_scale[0] + p_extra_edge, height * p_implicit_scale[1] + p_extra_edge)); } /* Cylinder */ @@ -329,11 +339,10 @@ void ConvexPolygonShapeBullet::setup(const Vector<Vector3> &p_vertices) { notifyShapeChanged(); } -btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { +btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btCollisionShape *cs(ShapeBullet::create_shape_convex(vertices)); cs->setLocalScaling(p_implicit_scale); prepare(cs); - cs->setMargin(p_margin); return cs; } @@ -402,14 +411,13 @@ void ConcavePolygonShapeBullet::setup(PoolVector<Vector3> p_faces) { notifyShapeChanged(); } -btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { +btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btCollisionShape *cs = ShapeBullet::create_shape_concave(meshShape); if (!cs) // This is necessary since if 0 faces the creation of concave return NULL cs = ShapeBullet::create_shape_empty(); cs->setLocalScaling(p_implicit_scale); prepare(cs); - cs->setMargin(p_margin); return cs; } @@ -495,11 +503,10 @@ void HeightMapShapeBullet::setup(PoolVector<real_t> &p_heights, int p_width, int notifyShapeChanged(); } -btCollisionShape *HeightMapShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { +btCollisionShape *HeightMapShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btCollisionShape *cs(ShapeBullet::create_shape_height_field(heights, width, depth, min_height, max_height)); cs->setLocalScaling(p_implicit_scale); prepare(cs); - cs->setMargin(p_margin); return cs; } @@ -533,6 +540,6 @@ void RayShapeBullet::setup(real_t p_length, bool p_slips_on_slope) { notifyShapeChanged(); } -btCollisionShape *RayShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { - return prepare(ShapeBullet::create_shape_ray(length * p_implicit_scale[1] + p_margin, slips_on_slope)); +btCollisionShape *RayShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { + return prepare(ShapeBullet::create_shape_ray(length * p_implicit_scale[1] + p_extra_edge, slips_on_slope)); } diff --git a/modules/bullet/shape_bullet.h b/modules/bullet/shape_bullet.h index 16a5ac1fc6..638e044e6a 100644 --- a/modules/bullet/shape_bullet.h +++ b/modules/bullet/shape_bullet.h @@ -52,6 +52,7 @@ class btBvhTriangleMeshShape; class ShapeBullet : public RIDBullet { Map<ShapeOwnerBullet *, int> owners; + real_t margin; protected: /// return self @@ -62,14 +63,17 @@ public: ShapeBullet(); virtual ~ShapeBullet(); - btCollisionShape *create_bt_shape(const Vector3 &p_implicit_scale, real_t p_margin = 0); - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0) = 0; + btCollisionShape *create_bt_shape(const Vector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0) = 0; void add_owner(ShapeOwnerBullet *p_owner); void remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFromThisBody = false); bool is_owner(ShapeOwnerBullet *p_owner) const; const Map<ShapeOwnerBullet *, int> &get_owners() const; + void set_margin(real_t p_margin); + real_t get_margin() const; + /// Setup the shape virtual void set_data(const Variant &p_data) = 0; virtual Variant get_data() const = 0; @@ -100,7 +104,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(const Plane &p_plane); @@ -117,7 +121,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(real_t p_radius); @@ -134,7 +138,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(const Vector3 &p_half_extents); @@ -153,7 +157,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(real_t p_height, real_t p_radius); @@ -189,7 +193,7 @@ public: void get_vertices(Vector<Vector3> &out_vertices); virtual Variant get_data() const; virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(const Vector<Vector3> &p_vertices); @@ -207,7 +211,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(PoolVector<Vector3> p_faces); @@ -227,7 +231,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(PoolVector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height); @@ -244,7 +248,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(real_t p_length, bool p_slips_on_slope); diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index 97228a972f..b5329bc347 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -61,7 +61,7 @@ BulletPhysicsDirectSpaceState::BulletPhysicsDirectSpaceState(SpaceBullet *p_spac PhysicsDirectSpaceState(), space(p_space) {} -int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { if (p_result_max <= 0) return 0; @@ -69,13 +69,13 @@ int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, Shape btVector3 bt_point; G_TO_B(p_point, bt_point); - btSphereShape sphere_point(0.f); + btSphereShape sphere_point(0.001f); btCollisionObject collision_object_point; collision_object_point.setCollisionShape(&sphere_point); collision_object_point.setWorldTransform(btTransform(btQuaternion::getIdentity(), bt_point)); // Setup query - GodotAllContactResultCallback btResult(&collision_object_point, r_results, p_result_max, &p_exclude); + GodotAllContactResultCallback btResult(&collision_object_point, r_results, p_result_max, &p_exclude, p_collide_with_bodies, p_collide_with_areas); btResult.m_collisionFilterGroup = 0; btResult.m_collisionFilterMask = p_collision_mask; space->dynamicsWorld->contactTest(&collision_object_point, btResult); @@ -84,7 +84,7 @@ int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, Shape return btResult.m_count; } -bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_pick_ray) { +bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_pick_ray) { btVector3 btVec_from; btVector3 btVec_to; @@ -93,7 +93,7 @@ bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const V G_TO_B(p_to, btVec_to); // setup query - GodotClosestRayResultCallback btResult(btVec_from, btVec_to, &p_exclude); + GodotClosestRayResultCallback btResult(btVec_from, btVec_to, &p_exclude, p_collide_with_bodies, p_collide_with_areas); btResult.m_collisionFilterGroup = 0; btResult.m_collisionFilterMask = p_collision_mask; btResult.m_pickRay = p_pick_ray; @@ -117,7 +117,7 @@ bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const V } } -int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { if (p_result_max <= 0) return 0; @@ -139,7 +139,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra collision_object.setCollisionShape(btConvex); collision_object.setWorldTransform(bt_xform); - GodotAllContactResultCallback btQuery(&collision_object, r_results, p_result_max, &p_exclude); + GodotAllContactResultCallback btQuery(&collision_object, r_results, p_result_max, &p_exclude, p_collide_with_bodies, p_collide_with_areas); btQuery.m_collisionFilterGroup = 0; btQuery.m_collisionFilterMask = p_collision_mask; btQuery.m_closestDistanceThreshold = 0; @@ -150,7 +150,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra return btQuery.m_count; } -bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, ShapeRestInfo *r_info) { +bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, ShapeRestInfo *r_info) { ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale(), p_margin); @@ -171,7 +171,7 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf btTransform bt_xform_to(bt_xform_from); bt_xform_to.getOrigin() += bt_motion; - GodotClosestConvexResultCallback btResult(bt_xform_from.getOrigin(), bt_xform_to.getOrigin(), &p_exclude); + GodotClosestConvexResultCallback btResult(bt_xform_from.getOrigin(), bt_xform_to.getOrigin(), &p_exclude, p_collide_with_bodies, p_collide_with_areas); btResult.m_collisionFilterGroup = 0; btResult.m_collisionFilterMask = p_collision_mask; @@ -197,7 +197,7 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf } /// Returns the list of contacts pairs in this order: Local contact, other body contact -bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { if (p_result_max <= 0) return 0; @@ -219,7 +219,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & collision_object.setCollisionShape(btConvex); collision_object.setWorldTransform(bt_xform); - GodotContactPairContactResultCallback btQuery(&collision_object, r_results, p_result_max, &p_exclude); + GodotContactPairContactResultCallback btQuery(&collision_object, r_results, p_result_max, &p_exclude, p_collide_with_bodies, p_collide_with_areas); btQuery.m_collisionFilterGroup = 0; btQuery.m_collisionFilterMask = p_collision_mask; btQuery.m_closestDistanceThreshold = 0; @@ -231,7 +231,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & return btQuery.m_count; } -bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); @@ -251,7 +251,7 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh collision_object.setCollisionShape(btConvex); collision_object.setWorldTransform(bt_xform); - GodotRestInfoContactResultCallback btQuery(&collision_object, r_info, &p_exclude); + GodotRestInfoContactResultCallback btQuery(&collision_object, r_info, &p_exclude, p_collide_with_bodies, p_collide_with_areas); btQuery.m_collisionFilterGroup = 0; btQuery.m_collisionFilterMask = p_collision_mask; btQuery.m_closestDistanceThreshold = 0; @@ -819,7 +819,7 @@ static Ref<SpatialMaterial> red_mat; static Ref<SpatialMaterial> blue_mat; #endif -bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer::MotionResult *r_result) { +bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer::MotionResult *r_result, bool p_exclude_raycast_shapes) { #if debug_test_motion /// Yes I know this is not good, but I've used it as fast debugging hack. @@ -894,6 +894,12 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f // Skip no convex shape continue; } + + if (p_exclude_raycast_shapes && p_body->get_bt_shape(shIndex)->getShapeType() == CUSTOM_CONVEX_SHAPE_TYPE) { + // Skip rayshape in order to implement custom separation process + continue; + } + btConvexShape *convex_shape_test(static_cast<btConvexShape *>(p_body->get_bt_shape(shIndex))); btTransform shape_world_from = body_transform * p_body->get_kinematic_utilities()->shapes[shIndex].transform; @@ -924,11 +930,11 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f btVector3 __rec(0, 0, 0); RecoverResult r_recover_result; - has_penetration = recover_from_penetration(p_body, body_transform, 0, p_infinite_inertia, __rec, &r_recover_result); + has_penetration = recover_from_penetration(p_body, body_transform, 1, p_infinite_inertia, __rec, &r_recover_result); // Parse results if (r_result) { - B_TO_G(motion + initial_recover_motion, r_result->motion); + B_TO_G(motion + initial_recover_motion + __rec, r_result->motion); if (has_penetration) { @@ -964,6 +970,39 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f return has_penetration; } +int SpaceBullet::test_ray_separation(RigidBodyBullet *p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, PhysicsServer::SeparationResult *r_results, int p_result_max, float p_margin) { + + btTransform body_transform; + G_TO_B(p_transform, body_transform); + UNSCALE_BT_BASIS(body_transform); + + btVector3 recover_motion(0, 0, 0); + + int rays_found; + + for (int t(RECOVERING_MOVEMENT_CYCLES); 0 < t; --t) { + int last_ray_index = recover_from_penetration_ray(p_body, body_transform, RECOVERING_MOVEMENT_SCALE, p_infinite_inertia, p_result_max, recover_motion, r_results); + + rays_found = MAX(last_ray_index, rays_found); + if (!rays_found) { + break; + } else { + body_transform.getOrigin() += recover_motion; + } + } + + //optimize results (remove non colliding) + for (int i = 0; i < rays_found; i++) { + if (r_results[i].collision_depth >= 0) { + rays_found--; + SWAP(r_results[i], r_results[rays_found]); + } + } + + B_TO_G(recover_motion, r_recover_motion); + return rays_found; +} + struct RecoverPenetrationBroadPhaseCallback : public btBroadphaseAabbCallback { private: const btCollisionObject *self_collision_object; @@ -1020,6 +1059,11 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran continue; } + if (kin_shape.shape->getShapeType() == CUSTOM_CONVEX_SHAPE_TYPE) { + // Skip rayshape in order to implement custom separation process + continue; + } + body_shape_position = p_body_position * kin_shape.transform; body_shape_position_recovered = body_shape_position; body_shape_position_recovered.getOrigin() += r_delta_recover_movement; @@ -1122,7 +1166,6 @@ bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btC if (contactPointResult.hasHit()) { r_delta_recover_movement += contactPointResult.m_pointNormalWorld * (contactPointResult.m_penetration_distance * -1 * p_recover_movement_scale); - if (r_recover_result) { if (contactPointResult.m_penetration_distance < r_recover_result->penetration_distance) { r_recover_result->hasPenetration = true; @@ -1138,3 +1181,79 @@ bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btC } return false; } + +int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, int p_result_max, btVector3 &r_delta_recover_movement, PhysicsServer::SeparationResult *r_results) { + + RecoverPenetrationBroadPhaseCallback recover_broad_result(p_body->get_bt_collision_object(), p_body->get_collision_layer(), p_body->get_collision_mask()); + + btTransform body_shape_position; + btTransform body_shape_position_recovered; + + // Broad phase support + btVector3 minAabb, maxAabb; + + int ray_index = 0; + + // For each shape + for (int kinIndex = p_body->get_kinematic_utilities()->shapes.size() - 1; 0 <= kinIndex; --kinIndex) { + + recover_broad_result.reset(); + + if (ray_index >= p_result_max) { + break; + } + + const RigidBodyBullet::KinematicShape &kin_shape(p_body->get_kinematic_utilities()->shapes[kinIndex]); + if (!kin_shape.is_active()) { + continue; + } + + if (kin_shape.shape->getShapeType() != CUSTOM_CONVEX_SHAPE_TYPE) { + continue; + } + + body_shape_position = p_body_position * kin_shape.transform; + body_shape_position_recovered = body_shape_position; + body_shape_position_recovered.getOrigin() += r_delta_recover_movement; + + kin_shape.shape->getAabb(body_shape_position_recovered, minAabb, maxAabb); + dynamicsWorld->getBroadphase()->aabbTest(minAabb, maxAabb, recover_broad_result); + + for (int i = recover_broad_result.result_collision_objects.size() - 1; 0 <= i; --i) { + btCollisionObject *otherObject = recover_broad_result.result_collision_objects[i]; + if (p_infinite_inertia && !otherObject->isStaticOrKinematicObject()) { + otherObject->activate(); // Force activation of hitten rigid, soft body + continue; + } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) + continue; + + if (otherObject->getCollisionShape()->isCompound()) { + + // Each convex shape + btCompoundShape *cs = static_cast<btCompoundShape *>(otherObject->getCollisionShape()); + for (int x = cs->getNumChildShapes() - 1; 0 <= x; --x) { + + RecoverResult r_recover_result; + if (RFP_convex_world_test(kin_shape.shape, cs->getChildShape(x), p_body->get_bt_collision_object(), otherObject, kinIndex, x, body_shape_position, otherObject->getWorldTransform() * cs->getChildTransform(x), p_recover_movement_scale, r_delta_recover_movement, &r_recover_result)) { + + const btRigidBody *btRigid = static_cast<const btRigidBody *>(otherObject); + CollisionObjectBullet *collisionObject = static_cast<CollisionObjectBullet *>(otherObject->getUserPointer()); + + r_results[ray_index].collision_depth = r_recover_result.penetration_distance; + B_TO_G(r_recover_result.pointWorld, r_results[ray_index].collision_point); + B_TO_G(r_recover_result.normal, r_results[ray_index].collision_normal); + B_TO_G(btRigid->getVelocityInLocalPoint(r_recover_result.pointWorld - btRigid->getWorldTransform().getOrigin()), r_results[ray_index].collider_velocity); + r_results[ray_index].collision_local_shape = kinIndex; + r_results[ray_index].collider_id = collisionObject->get_instance_id(); + r_results[ray_index].collider = collisionObject->get_self(); + r_results[ray_index].collider_shape = r_recover_result.other_compound_shape_index; + } + } + } + } + + ++ray_index; + } + + return ray_index; +} diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h index 6b86fc2f03..517ec67ffa 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -73,13 +73,13 @@ private: public: BulletPhysicsDirectSpaceState(SpaceBullet *p_space); - virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_pick_ray = false); - virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, ShapeRestInfo *r_info = NULL); + virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false); + virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = NULL); /// Returns the list of contacts pairs in this order: Local contact, other body contact - virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); + virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const; }; @@ -174,7 +174,8 @@ public: void update_gravity(); - bool test_body_motion(RigidBodyBullet *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer::MotionResult *r_result); + bool test_body_motion(RigidBodyBullet *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer::MotionResult *r_result, bool p_exclude_raycast_shapes); + int test_ray_separation(RigidBodyBullet *p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, PhysicsServer::SeparationResult *r_results, int p_result_max, float p_margin); private: void create_empty_world(bool p_create_soft_world); @@ -208,5 +209,7 @@ private: /// This is an API that recover a kinematic object from penetration /// Using this we leave Bullet to select the best algorithm, For example GJK in case we have Convex Convex, or a Bullet accelerated algorithm bool RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result = NULL); + + int recover_from_penetration_ray(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, int p_result_max, btVector3 &r_delta_recover_movement, PhysicsServer::SeparationResult *r_results); }; #endif diff --git a/modules/cvtt/SCsub b/modules/cvtt/SCsub new file mode 100644 index 0000000000..5c396482aa --- /dev/null +++ b/modules/cvtt/SCsub @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_cvtt = env_modules.Clone() + +# Thirdparty source files +if env['builtin_squish']: + thirdparty_dir = "#thirdparty/cvtt/" + thirdparty_sources = [ + "ConvectionKernels.cpp" + ] + + thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + + env_cvtt.add_source_files(env.modules_sources, thirdparty_sources) + env_cvtt.Append(CPPPATH=[thirdparty_dir]) + +# Godot source files +env_cvtt.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/cvtt/config.py b/modules/cvtt/config.py new file mode 100644 index 0000000000..098f1eafa9 --- /dev/null +++ b/modules/cvtt/config.py @@ -0,0 +1,5 @@ +def can_build(env, platform): + return env['tools'] + +def configure(env): + pass diff --git a/modules/cvtt/image_compress_cvtt.cpp b/modules/cvtt/image_compress_cvtt.cpp new file mode 100644 index 0000000000..c860942d33 --- /dev/null +++ b/modules/cvtt/image_compress_cvtt.cpp @@ -0,0 +1,300 @@ +/*************************************************************************/ +/* image_compress_cvtt.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "image_compress_cvtt.h" + +#include "print_string.h" + +#include <ConvectionKernels.h> + +void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::CompressSource p_source) { + + if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA) + return; //do not compress, already compressed + + int w = p_image->get_width(); + int h = p_image->get_height(); + + bool is_ldr = (p_image->get_format() <= Image::FORMAT_RGBA8); + bool is_hdr = (p_image->get_format() == Image::FORMAT_RGBH); + + if (!is_ldr && !is_hdr) { + return; // Not a usable source format + } + + cvtt::Options options; + uint32_t flags = cvtt::Flags::Fastest; + + if (p_lossy_quality > 0.85) + flags = cvtt::Flags::Ultra; + else if (p_lossy_quality > 0.75) + flags = cvtt::Flags::Better; + else if (p_lossy_quality > 0.55) + flags = cvtt::Flags::Default; + else if (p_lossy_quality > 0.35) + flags = cvtt::Flags::Fast; + else if (p_lossy_quality > 0.15) + flags = cvtt::Flags::Faster; + + flags |= cvtt::Flags::BC7_RespectPunchThrough; + + if (p_source == Image::COMPRESS_SOURCE_NORMAL) { + flags |= cvtt::Flags::Uniform; + } + + Image::Format target_format = Image::FORMAT_BPTC_RGBA; + + bool is_signed = false; + if (is_hdr) { + PoolVector<uint8_t>::Read rb = p_image->get_data().read(); + + const uint16_t *source_data = reinterpret_cast<const uint16_t *>(&rb[0]); + int pixel_element_count = w * h * 3; + for (int i = 0; i < pixel_element_count; i++) { + if ((source_data[i] & 0x8000) != 0 && (source_data[i] & 0x7fff) != 0) { + is_signed = true; + break; + } + } + + target_format = is_signed ? Image::FORMAT_BPTC_RGBF : Image::FORMAT_BPTC_RGBFU; + } else { + p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert + } + + PoolVector<uint8_t>::Read rb = p_image->get_data().read(); + + PoolVector<uint8_t> data; + int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps()); + int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w, h, target_format) : 0; + data.resize(target_size); + int shift = Image::get_format_pixel_rshift(target_format); + + PoolVector<uint8_t>::Write wb = data.write(); + + int dst_ofs = 0; + + for (int i = 0; i <= mm_count; i++) { + + int bw = w % 4 != 0 ? w + (4 - w % 4) : w; + int bh = h % 4 != 0 ? h + (4 - h % 4) : h; + + int src_ofs = p_image->get_mipmap_offset(i); + + const uint8_t *in_bytes = &rb[src_ofs]; + uint8_t *out_bytes = &wb[dst_ofs]; + + cvtt::PixelBlockU8 input_blocks_ldr[cvtt::NumParallelBlocks]; + cvtt::PixelBlockF16 input_blocks_hdr[cvtt::NumParallelBlocks]; + + int bytes_per_pixel = is_hdr ? 6 : 4; + + for (int y_start = 0; y_start < h; y_start += 4) { + int y_end = y_start + 4; + + for (int x_start = 0; x_start < w; x_start += 4 * cvtt::NumParallelBlocks) { + int x_end = x_start + 4 * cvtt::NumParallelBlocks; + + for (int y = y_start; y < y_end; y++) { + int first_input_element = (y - y_start) * 4; + const uint8_t *row_start; + if (y >= h) { + row_start = in_bytes + (h - 1) * (w * bytes_per_pixel); + } else { + row_start = in_bytes + y * (w * bytes_per_pixel); + } + + for (int x = x_start; x < x_end; x++) { + const uint8_t *pixel_start; + if (x >= w) { + pixel_start = row_start + (w - 1) * bytes_per_pixel; + } else { + pixel_start = row_start + x * bytes_per_pixel; + } + + int block_index = (x - x_start) / 4; + int block_element = (x - x_start) % 4 + first_input_element; + if (is_hdr) { + memcpy(input_blocks_hdr[block_index].m_pixels[block_element], pixel_start, bytes_per_pixel); + input_blocks_hdr[block_index].m_pixels[block_element][3] = 0x3c00; // 1.0 (unused) + } else { + memcpy(input_blocks_ldr[block_index].m_pixels[block_element], pixel_start, bytes_per_pixel); + } + } + } + + uint8_t output_blocks[16 * cvtt::NumParallelBlocks]; + + if (is_hdr) { + if (is_signed) { + cvtt::Kernels::EncodeBC6HS(output_blocks, input_blocks_hdr, options); + } else { + cvtt::Kernels::EncodeBC6HU(output_blocks, input_blocks_hdr, options); + } + } else { + cvtt::Kernels::EncodeBC7(output_blocks, input_blocks_ldr, options); + } + + int num_real_blocks = ((w - x_start) + 3) / 4; + if (num_real_blocks > cvtt::NumParallelBlocks) { + num_real_blocks = cvtt::NumParallelBlocks; + } + + memcpy(out_bytes, output_blocks, 16 * num_real_blocks); + out_bytes += 16 * num_real_blocks; + } + } + + dst_ofs += (MAX(4, bw) * MAX(4, bh)) >> shift; + w >>= 1; + h >>= 1; + } + + rb = PoolVector<uint8_t>::Read(); + wb = PoolVector<uint8_t>::Write(); + + p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); +} + +void image_decompress_cvtt(Image *p_image) { + + Image::Format target_format; + bool is_signed = false; + bool is_hdr = false; + + Image::Format input_format = p_image->get_format(); + + switch (input_format) { + case Image::FORMAT_BPTC_RGBA: + target_format = Image::FORMAT_RGBA8; + break; + case Image::FORMAT_BPTC_RGBF: + case Image::FORMAT_BPTC_RGBFU: + target_format = Image::FORMAT_RGBH; + is_signed = (input_format == Image::FORMAT_BPTC_RGBF); + is_hdr = true; + break; + default: + return; // Invalid input format + }; + + int w = p_image->get_width(); + int h = p_image->get_height(); + + PoolVector<uint8_t>::Read rb = p_image->get_data().read(); + + PoolVector<uint8_t> data; + int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps()); + int mm_count = p_image->get_mipmap_count(); + data.resize(target_size); + int shift = Image::get_format_pixel_rshift(target_format); + + PoolVector<uint8_t>::Write wb = data.write(); + + int bytes_per_pixel = is_hdr ? 6 : 4; + + int dst_ofs = 0; + + for (int i = 0; i <= mm_count; i++) { + + int src_ofs = p_image->get_mipmap_offset(i); + + const uint8_t *in_bytes = &rb[src_ofs]; + uint8_t *out_bytes = &wb[dst_ofs]; + + cvtt::PixelBlockU8 output_blocks_ldr[cvtt::NumParallelBlocks]; + cvtt::PixelBlockF16 output_blocks_hdr[cvtt::NumParallelBlocks]; + + for (int y_start = 0; y_start < h; y_start += 4) { + int y_end = y_start + 4; + + for (int x_start = 0; x_start < w; x_start += 4 * cvtt::NumParallelBlocks) { + int x_end = x_start + 4 * cvtt::NumParallelBlocks; + + uint8_t input_blocks[16 * cvtt::NumParallelBlocks]; + memset(input_blocks, 0, sizeof(input_blocks)); + + int num_real_blocks = ((w - x_start) + 3) / 4; + if (num_real_blocks > cvtt::NumParallelBlocks) { + num_real_blocks = cvtt::NumParallelBlocks; + } + + memcpy(input_blocks, in_bytes, 16 * num_real_blocks); + in_bytes += 16 * num_real_blocks; + + if (is_hdr) { + if (is_signed) { + cvtt::Kernels::DecodeBC6HS(output_blocks_hdr, input_blocks); + } else { + cvtt::Kernels::DecodeBC6HU(output_blocks_hdr, input_blocks); + } + } else { + cvtt::Kernels::DecodeBC7(output_blocks_ldr, input_blocks); + } + + for (int y = y_start; y < y_end; y++) { + int first_input_element = (y - y_start) * 4; + uint8_t *row_start; + if (y >= h) { + row_start = out_bytes + (h - 1) * (w * bytes_per_pixel); + } else { + row_start = out_bytes + y * (w * bytes_per_pixel); + } + + for (int x = x_start; x < x_end; x++) { + uint8_t *pixel_start; + if (x >= w) { + pixel_start = row_start + (w - 1) * bytes_per_pixel; + } else { + pixel_start = row_start + x * bytes_per_pixel; + } + + int block_index = (x - x_start) / 4; + int block_element = (x - x_start) % 4 + first_input_element; + if (is_hdr) { + memcpy(pixel_start, output_blocks_hdr[block_index].m_pixels[block_element], bytes_per_pixel); + } else { + memcpy(pixel_start, output_blocks_ldr[block_index].m_pixels[block_element], bytes_per_pixel); + } + } + } + } + } + + dst_ofs += w * h * bytes_per_pixel; + w >>= 1; + h >>= 1; + } + + rb = PoolVector<uint8_t>::Read(); + wb = PoolVector<uint8_t>::Write(); + + p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); +} diff --git a/modules/cvtt/image_compress_cvtt.h b/modules/cvtt/image_compress_cvtt.h new file mode 100644 index 0000000000..0e18b247e5 --- /dev/null +++ b/modules/cvtt/image_compress_cvtt.h @@ -0,0 +1,39 @@ +/*************************************************************************/ +/* image_compress_cvtt.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef IMAGE_COMPRESS_CVTT_H +#define IMAGE_COMPRESS_CVTT_H + +#include "image.h" + +void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::CompressSource p_source); +void image_decompress_cvtt(Image *p_image); + +#endif // IMAGE_COMPRESS_CVTT_H diff --git a/modules/cvtt/register_types.cpp b/modules/cvtt/register_types.cpp new file mode 100644 index 0000000000..c96fbbf340 --- /dev/null +++ b/modules/cvtt/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "register_types.h" + +#ifdef TOOLS_ENABLED + +#include "image_compress_cvtt.h" + +void register_cvtt_types() { + + Image::set_compress_bptc_func(image_compress_cvtt); + Image::_image_decompress_bptc = image_decompress_cvtt; +} + +void unregister_cvtt_types() {} + +#endif diff --git a/modules/cvtt/register_types.h b/modules/cvtt/register_types.h new file mode 100644 index 0000000000..73de9728d3 --- /dev/null +++ b/modules/cvtt/register_types.h @@ -0,0 +1,34 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifdef TOOLS_ENABLED +void register_cvtt_types(); +void unregister_cvtt_types(); +#endif diff --git a/modules/gdnative/doc_classes/NativeScript.xml b/modules/gdnative/doc_classes/NativeScript.xml index 1d3053244b..37d5b79e7a 100644 --- a/modules/gdnative/doc_classes/NativeScript.xml +++ b/modules/gdnative/doc_classes/NativeScript.xml @@ -57,6 +57,10 @@ </member> <member name="library" type="GDNativeLibrary" setter="set_library" getter="get_library"> </member> + <member name="script_class_icon_path" type="String" setter="set_script_class_icon_path" getter="get_script_class_icon_path"> + </member> + <member name="script_class_name" type="String" setter="set_script_class_name" getter="get_script_class_name"> + </member> </members> <constants> </constants> diff --git a/modules/gdnative/include/nativescript/godot_nativescript.h b/modules/gdnative/include/nativescript/godot_nativescript.h index f28ba352ab..1c5422d723 100644 --- a/modules/gdnative/include/nativescript/godot_nativescript.h +++ b/modules/gdnative/include/nativescript/godot_nativescript.h @@ -68,6 +68,7 @@ typedef enum { GODOT_PROPERTY_HINT_GLOBAL_DIR, ///< a directort path must be passed GODOT_PROPERTY_HINT_RESOURCE_TYPE, ///< a resource object type GODOT_PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines + GODOT_PROPERTY_HINT_PLACEHOLDER_TEXT, ///< used to set a placeholder text for string properties GODOT_PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSY, GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS, diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index b987d2897f..5125b58b41 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -606,9 +606,11 @@ Error GDScript::reload(bool p_keep_state) { } #if DEBUG_ENABLED for (const List<GDScriptWarning>::Element *E = parser.get_warnings().front(); E; E = E->next()) { - String msg = "Script warning: " + E->get().get_name() + " (" + path + ") line " + itos(E->get().line) + ": "; - msg += E->get().get_message(); - WARN_PRINTS(msg); + const GDScriptWarning &warning = E->get(); + if (ScriptDebugger::get_singleton()) { + Vector<ScriptLanguage::StackInfo> si; + ScriptDebugger::get_singleton()->send_error("", get_path(), warning.line, warning.get_name(), warning.get_message(), ERR_HANDLER_WARNING, si); + } } #endif diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index fe393957db..368601127d 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1994,8 +1994,11 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, GDScript *p_owner p_script->_signals[name] = p_class->_signals[i].arguments; } - if (!p_class->owner) { + if (p_class->owner) { parsed_classes.insert(p_class->name); + if (parsing_classes.has(p_class->name)) { + parsing_classes.erase(p_class->name); + } } //parse sub-classes @@ -2011,7 +2014,6 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, GDScript *p_owner Error err = _parse_class_level(subclass.ptr(), p_script, p_class->subclasses[i], p_keep_state); if (err) return err; - parsing_classes.erase(name); } #ifdef TOOLS_ENABLED diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index abd56d2757..934c93059a 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -46,12 +46,12 @@ void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { p_delimiters->push_back("#"); - p_delimiters->push_back("\"\"\" \"\"\""); } void GDScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { p_delimiters->push_back("\" \""); p_delimiters->push_back("' '"); + p_delimiters->push_back("\"\"\" \"\"\""); } Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { #ifdef TOOLS_ENABLED diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index bec314866d..2c0d541d8f 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2024,12 +2024,20 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) { // bind case GDScriptTokenizer::TK_PR_VAR: { tokenizer->advance(); + if (!tokenizer->is_token_literal()) { + _set_error("Expected identifier for binding variable name."); + return NULL; + } pattern->pt_type = GDScriptParser::PatternNode::PT_BIND; pattern->bind = tokenizer->get_token_identifier(); - // Check if binding is already used - if (current_block->variables.has(pattern->bind)) { - _set_error("Binding name of '" + pattern->bind.operator String() + "' was already used in the pattern."); - return NULL; + // Check if variable name is already used + BlockNode *bl = current_block; + while (bl) { + if (bl->variables.has(pattern->bind)) { + _set_error("Binding name of '" + pattern->bind.operator String() + "' is already declared in this scope."); + return NULL; + } + bl = bl->parent_block; } // Create local variable for proper identifier detection later LocalVarNode *lv = alloc_node<LocalVarNode>(); @@ -7389,7 +7397,7 @@ void GDScriptParser::_check_function_types(FunctionNode *p_function) { } } #ifdef DEBUG_ENABLED - if (p_function->arguments_usage[i] == 0) { + if (p_function->arguments_usage[i] == 0 && !p_function->arguments[i].operator String().begins_with("_")) { _add_warning(GDScriptWarning::UNUSED_ARGUMENT, p_function->line, p_function->name, p_function->arguments[i].operator String()); } #endif // DEBUG_ENABLED @@ -7847,10 +7855,12 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) { // Warnings check for (Map<StringName, LocalVarNode *>::Element *E = p_block->variables.front(); E; E = E->next()) { LocalVarNode *lv = E->get(); - if (lv->usages == 0) { - _add_warning(GDScriptWarning::UNUSED_VARIABLE, lv->line, lv->name); - } else if (lv->assignments == 0) { - _add_warning(GDScriptWarning::UNASSIGNED_VARIABLE, lv->line, lv->name); + if (!lv->name.operator String().begins_with("_")) { + if (lv->usages == 0) { + _add_warning(GDScriptWarning::UNUSED_VARIABLE, lv->line, lv->name); + } else if (lv->assignments == 0) { + _add_warning(GDScriptWarning::UNASSIGNED_VARIABLE, lv->line, lv->name); + } } } #endif // DEBUG_ENABLED diff --git a/modules/gdscript/gdscript_tokenizer.h b/modules/gdscript/gdscript_tokenizer.h index 28a08bfaf8..11a291cb2e 100644 --- a/modules/gdscript/gdscript_tokenizer.h +++ b/modules/gdscript/gdscript_tokenizer.h @@ -283,8 +283,14 @@ public: virtual String get_token_error(int p_offset = 0) const; virtual void advance(int p_amount = 1); #ifdef DEBUG_ENABLED - virtual const Vector<Pair<int, String> > &get_warning_skips() const { return Vector<Pair<int, String> >(); } - virtual const Set<String> &get_warning_global_skips() const { return Set<String>(); } + virtual const Vector<Pair<int, String> > &get_warning_skips() const { + static Vector<Pair<int, String> > v; + return v; + } + virtual const Set<String> &get_warning_global_skips() const { + static Set<String> s; + return s; + } virtual const bool is_ignoring_warnings() const { return true; } #endif // DEBUG_ENABLED GDScriptTokenizerBuffer(); diff --git a/modules/mono/config.py b/modules/mono/config.py index c4f8dcfde8..70fd1a35f1 100644 --- a/modules/mono/config.py +++ b/modules/mono/config.py @@ -265,11 +265,13 @@ def pkgconfig_try_find_mono_root(mono_lib_names, sharedlib_ext): def pkgconfig_try_find_mono_version(): + from compat import decode_utf8 + lines = subprocess.check_output(['pkg-config', 'monosgen-2', '--modversion']).splitlines() greater_version = None for line in lines: try: - version = LooseVersion(line) + version = LooseVersion(decode_utf8(line)) if greater_version is None or version > greater_version: greater_version = version except ValueError: diff --git a/modules/mono/glue/cs_files/Color.cs b/modules/mono/glue/cs_files/Color.cs index 1195071bd3..49e04b333a 100644 --- a/modules/mono/glue/cs_files/Color.cs +++ b/modules/mono/glue/cs_files/Color.cs @@ -258,11 +258,6 @@ namespace Godot return res; } - public float Gray() - { - return (r + g + b) / 3.0f; - } - public Color Inverted() { return new Color( diff --git a/modules/mono/glue/cs_files/Plane.cs b/modules/mono/glue/cs_files/Plane.cs index 1020f06bf5..9611dce11e 100644 --- a/modules/mono/glue/cs_files/Plane.cs +++ b/modules/mono/glue/cs_files/Plane.cs @@ -145,6 +145,15 @@ namespace Godot return point - _normal * DistanceTo(point); } + // Constants + private static readonly Plane _planeYZ = new Plane(1, 0, 0, 0); + private static readonly Plane _planeXZ = new Plane(0, 1, 0, 0); + private static readonly Plane _planeXY = new Plane(0, 0, 1, 0); + + public static Plane PlaneYZ { get { return _planeYZ; } } + public static Plane PlaneXZ { get { return _planeXZ; } } + public static Plane PlaneXY { get { return _planeXY; } } + // Constructors public Plane(real_t a, real_t b, real_t c, real_t d) { diff --git a/modules/mono/mono_gd/gd_mono_assembly.cpp b/modules/mono/mono_gd/gd_mono_assembly.cpp index 9d3bee2176..27ce39b6d7 100644 --- a/modules/mono/mono_gd/gd_mono_assembly.cpp +++ b/modules/mono/mono_gd/gd_mono_assembly.cpp @@ -42,8 +42,25 @@ #include "gd_mono_class.h" bool GDMonoAssembly::no_search = false; +bool GDMonoAssembly::in_preload = false; + Vector<String> GDMonoAssembly::search_dirs; +void GDMonoAssembly::assembly_load_hook(MonoAssembly *assembly, void *user_data) { + + if (no_search) + return; + + // If our search and preload hooks fail to load the assembly themselves, the mono runtime still might. + // Just do Assembly.LoadFrom("/Full/Path/On/Disk.dll"); + // In this case, we wouldn't have the assembly known in GDMono, which causes crashes + // if any class inside the assembly is looked up by Godot. + // And causing a lookup like that is as easy as throwing an exception defined in it... + // No, we can't make the assembly load hooks smart enough because they get passed a MonoAssemblyName* only, + // not the disk path passed to say Assembly.LoadFrom(). + _wrap_mono_assembly(assembly); +} + MonoAssembly *GDMonoAssembly::assembly_search_hook(MonoAssemblyName *aname, void *user_data) { return GDMonoAssembly::_search_hook(aname, user_data, false); } @@ -111,6 +128,8 @@ MonoAssembly *GDMonoAssembly::_search_hook(MonoAssemblyName *aname, void *user_d return res ? res->get_assembly() : NULL; } +static _THREAD_LOCAL_(MonoImage *) image_corlib_loading = NULL; + MonoAssembly *GDMonoAssembly::_preload_hook(MonoAssemblyName *aname, char **assemblies_path, void *user_data, bool refonly) { (void)user_data; // UNUSED @@ -138,16 +157,38 @@ MonoAssembly *GDMonoAssembly::_preload_hook(MonoAssemblyName *aname, char **asse } } + { + // If we find the assembly here, we load it with `mono_assembly_load_from_full`, + // which in turn invokes load hooks before returning the MonoAssembly to us. + // One of the load hooks is `load_aot_module`. This hook can end up calling preload hooks + // again for the same assembly in certain in certain circumstances (the `do_load_image` part). + // If this is the case and we return NULL due to the no_search condition below, + // it will result in an internal crash later on. Therefore we need to return the assembly we didn't + // get yet from `mono_assembly_load_from_full`. Luckily we have the image, which already got it. + // This must be done here. If done in search hooks, it would cause `mono_assembly_load_from_full` + // to think another MonoAssembly for this assembly was already loaded, making it delete its own, + // when in fact both pointers were the same... This hooks thing is confusing. + if (image_corlib_loading) { + return mono_image_get_assembly(image_corlib_loading); + } + } + + if (no_search) + return NULL; + + no_search = true; + in_preload = true; + String name = mono_assembly_name_get_name(aname); bool has_extension = name.ends_with(".dll"); + GDMonoAssembly *res = NULL; if (has_extension ? name == "mscorlib.dll" : name == "mscorlib") { GDMonoAssembly **stored_assembly = GDMono::get_singleton()->get_loaded_assembly(has_extension ? name.get_basename() : name); if (stored_assembly) return (*stored_assembly)->get_assembly(); String path; - GDMonoAssembly *res = NULL; for (int i = 0; i < search_dirs.size(); i++) { const String &search_dir = search_dirs[i]; @@ -168,11 +209,12 @@ MonoAssembly *GDMonoAssembly::_preload_hook(MonoAssemblyName *aname, char **asse } } } - - return res ? res->get_assembly() : NULL; } - return NULL; + no_search = false; + in_preload = false; + + return res ? res->get_assembly() : NULL; } GDMonoAssembly *GDMonoAssembly::_load_assembly_from(const String &p_name, const String &p_path, bool p_refonly) { @@ -192,12 +234,30 @@ GDMonoAssembly *GDMonoAssembly::_load_assembly_from(const String &p_name, const return assembly; } +void GDMonoAssembly::_wrap_mono_assembly(MonoAssembly *assembly) { + String name = mono_assembly_name_get_name(mono_assembly_get_name(assembly)); + + MonoImage *image = mono_assembly_get_image(assembly); + + GDMonoAssembly *gdassembly = memnew(GDMonoAssembly(name, mono_image_get_filename(image))); + Error err = gdassembly->wrapper_for_image(image); + + if (err != OK) { + memdelete(gdassembly); + ERR_FAIL(); + } + + MonoDomain *domain = mono_domain_get(); + GDMono::get_singleton()->add_assembly(domain ? mono_domain_get_id(domain) : 0, gdassembly); +} + void GDMonoAssembly::initialize() { mono_install_assembly_search_hook(&assembly_search_hook, NULL); mono_install_assembly_refonly_search_hook(&assembly_refonly_search_hook, NULL); mono_install_assembly_preload_hook(&assembly_preload_hook, NULL); mono_install_assembly_refonly_preload_hook(&assembly_refonly_preload_hook, NULL); + mono_install_assembly_load_hook(&assembly_load_hook, NULL); } Error GDMonoAssembly::load(bool p_refonly) { @@ -241,8 +301,16 @@ no_pdb: #endif + bool is_corlib_preload = in_preload && name == "mscorlib"; + + if (is_corlib_preload) + image_corlib_loading = image; + assembly = mono_assembly_load_from_full(image, image_filename.utf8().get_data(), &status, refonly); + if (is_corlib_preload) + image_corlib_loading = NULL; + ERR_FAIL_COND_V(status != MONO_IMAGE_OK || assembly == NULL, ERR_FILE_CANT_OPEN); loaded = true; diff --git a/modules/mono/mono_gd/gd_mono_assembly.h b/modules/mono/mono_gd/gd_mono_assembly.h index 5cf744a5a2..2c6d367fc6 100644 --- a/modules/mono/mono_gd/gd_mono_assembly.h +++ b/modules/mono/mono_gd/gd_mono_assembly.h @@ -89,8 +89,10 @@ class GDMonoAssembly { #endif static bool no_search; + static bool in_preload; static Vector<String> search_dirs; + static void assembly_load_hook(MonoAssembly *assembly, void *user_data); static MonoAssembly *assembly_search_hook(MonoAssemblyName *aname, void *user_data); static MonoAssembly *assembly_refonly_search_hook(MonoAssemblyName *aname, void *user_data); static MonoAssembly *assembly_preload_hook(MonoAssemblyName *aname, char **assemblies_path, void *user_data); @@ -100,6 +102,7 @@ class GDMonoAssembly { static MonoAssembly *_preload_hook(MonoAssemblyName *aname, char **assemblies_path, void *user_data, bool refonly); static GDMonoAssembly *_load_assembly_from(const String &p_name, const String &p_path, bool p_refonly); + static void _wrap_mono_assembly(MonoAssembly *assembly); friend class GDMono; static void initialize(); diff --git a/modules/mono/utils/thread_local.cpp b/modules/mono/utils/thread_local.cpp index ae9f130518..a0e28fca5f 100644 --- a/modules/mono/utils/thread_local.cpp +++ b/modules/mono/utils/thread_local.cpp @@ -69,7 +69,7 @@ struct ThreadLocalStorage::Impl { #define _CALLBACK_FUNC_ #endif - Impl(void (_CALLBACK_FUNC_ *p_destr_callback_func)(void *)) { + Impl(void(_CALLBACK_FUNC_ *p_destr_callback_func)(void *)) { #ifdef WINDOWS_ENABLED dwFlsIndex = FlsAlloc(p_destr_callback_func); ERR_FAIL_COND(dwFlsIndex == FLS_OUT_OF_INDEXES); @@ -95,7 +95,7 @@ void ThreadLocalStorage::set_value(void *p_value) const { pimpl->set_value(p_value); } -void ThreadLocalStorage::alloc(void (_CALLBACK_FUNC_ *p_destr_callback)(void *)) { +void ThreadLocalStorage::alloc(void(_CALLBACK_FUNC_ *p_destr_callback)(void *)) { pimpl = memnew(ThreadLocalStorage::Impl(p_destr_callback)); } diff --git a/modules/mono/utils/thread_local.h b/modules/mono/utils/thread_local.h index 783e40dc01..84dae1d86b 100644 --- a/modules/mono/utils/thread_local.h +++ b/modules/mono/utils/thread_local.h @@ -76,7 +76,7 @@ struct ThreadLocalStorage { void *get_value() const; void set_value(void *p_value) const; - void alloc(void (_CALLBACK_FUNC_ *p_dest_callback)(void *)); + void alloc(void(_CALLBACK_FUNC_ *p_dest_callback)(void *)); void free(); private: @@ -95,7 +95,6 @@ class ThreadLocal { memdelete(static_cast<T *>(tls_data)); } - T *_tls_get_value() const { void *tls_data = storage.get_value(); diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index f6be537413..6aaabb9d9b 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -32,12 +32,6 @@ #include "print_string.h" -#if defined(__SSE2__) -#define SQUISH_USE_SSE 2 -#elif defined(__SSE__) -#define SQUISH_USE_SSE 1 -#endif - #include <squish.h> void image_decompress_squish(Image *p_image) { diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 9ad0219746..e8ab1558cc 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -1086,7 +1086,6 @@ public: virtual void get_export_options(List<ExportOption> *r_options) { - /*r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "graphics/api", PROPERTY_HINT_ENUM, "OpenGL ES 2.0,OpenGL ES 3.0"), 1));*/ r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "graphics/32_bits_framebuffer"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "one_click_deploy/clear_previous_install"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "apk"), "")); @@ -1094,8 +1093,8 @@ public: r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "command_line/extra_args"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "version/code", PROPERTY_HINT_RANGE, "1,4096,1,or_greater"), 1)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "version/name"), "1.0")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/unique_name"), "org.godotengine.$genname")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/name"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/unique_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.$genname"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "package/signed"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "screen/immersive_mode"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "screen/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait"), 0)); @@ -1133,8 +1132,6 @@ public: r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "user_permissions/" + itos(i)), false)); } - - //r_options->push_back( PropertyInfo( Variant::INT, "resources/pack_mode", PROPERTY_HINT_ENUM,"Copy,Single Exec.,Pack (.pck),Bundles (Optical)")); } virtual String get_name() const { @@ -1336,12 +1333,28 @@ public: virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const { + String err; r_missing_templates = find_export_template("android_debug.apk") == String() || find_export_template("android_release.apk") == String(); + if (p_preset->get("custom_package/debug") != "") { + if (FileAccess::exists(p_preset->get("custom_package/debug"))) { + r_missing_templates = false; + } else { + err += "Custom debug package not found.\n"; + } + } + + if (p_preset->get("custom_package/release") != "") { + if (FileAccess::exists(p_preset->get("custom_package/release"))) { + r_missing_templates = false; + } else { + err += "Custom release package not found.\n"; + } + } + bool valid = !r_missing_templates; String adb = EditorSettings::get_singleton()->get("export/android/adb"); - String err; if (!FileAccess::exists(adb)) { @@ -1847,6 +1860,9 @@ public: r_features->push_back("Android"); } + virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) { + } + EditorExportAndroid() { Ref<Image> img = memnew(Image(_android_logo)); diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index e59c81a148..ab8d9909a0 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -119,6 +119,9 @@ public: r_features->push_back("iOS"); } + virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) { + } + EditorExportPlatformIOS(); ~EditorExportPlatformIOS(); }; @@ -175,17 +178,17 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug"), "iPhone Developer")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Developer"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release"), "iPhone Distribution")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Distribution"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0)); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier"), "org.godotengine.iosgame")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "????")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "come.example.game"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), "")); diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 7cff6ba172..78e60af3e0 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -74,6 +74,9 @@ public: r_features->push_back(get_os_name()); } + virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) { + } + EditorExportPlatformJavaScript(); }; @@ -140,14 +143,35 @@ Ref<Texture> EditorExportPlatformJavaScript::get_logo() const { bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const { - r_missing_templates = false; + bool valid = false; + String err; + + if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE) != "") + valid = true; + else if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG) != "") + valid = true; + + if (p_preset->get("custom_template/debug") != "") { + if (FileAccess::exists(p_preset->get("custom_template/debug"))) { + valid = true; + } else { + err += "Custom debug template not found.\n"; + } + } + + if (p_preset->get("custom_template/release") != "") { + if (FileAccess::exists(p_preset->get("custom_template/release"))) { + valid = true; + } else { + err += "Custom release template not found.\n"; + } + } - if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE) == String()) - r_missing_templates = true; - else if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG) == String()) - r_missing_templates = true; + if (!err.empty()) + r_error = err; - return !r_missing_templates; + r_missing_templates = !valid; + return valid; } String EditorExportPlatformJavaScript::get_binary_extension(const Ref<EditorExportPreset> &p_preset) const { diff --git a/platform/javascript/http_request.js b/platform/javascript/http_request.js index c420052e54..ee1c06c623 100644 --- a/platform/javascript/http_request.js +++ b/platform/javascript/http_request.js @@ -82,7 +82,7 @@ var GodotHTTPRequest = { godot_xhr_send_string: function(xhrId, strPtr) { if (!strPtr) { - Module.printErr("Failed to send string per XHR: null pointer"); + console.warn("Failed to send string per XHR: null pointer"); return; } GodotHTTPRequest.requests[xhrId].send(UTF8ToString(strPtr)); @@ -90,11 +90,11 @@ var GodotHTTPRequest = { godot_xhr_send_data: function(xhrId, ptr, len) { if (!ptr) { - Module.printErr("Failed to send data per XHR: null pointer"); + console.warn("Failed to send data per XHR: null pointer"); return; } if (len < 0) { - Module.printErr("Failed to send data per XHR: buffer length less than 0"); + console.warn("Failed to send data per XHR: buffer length less than 0"); return; } GodotHTTPRequest.requests[xhrId].send(HEAPU8.subarray(ptr, ptr + len)); diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp index 2ef88345f6..07b4c192e6 100644 --- a/platform/javascript/javascript_eval.cpp +++ b/platform/javascript/javascript_eval.cpp @@ -69,7 +69,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { eval_ret = eval(UTF8ToString(CODE)); } } catch (e) { - Module.printErr(e); + console.warn(e); eval_ret = null; } @@ -97,7 +97,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { if (array_ptr!==0) { _free(array_ptr) } - Module.printErr(e); + console.warn(e); // fall through } break; diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index b9d586e233..a2c6bdd629 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -788,7 +788,7 @@ bool OS_JavaScript::main_loop_iterate() { /* clang-format off */ EM_ASM( FS.syncfs(function(err) { - if (err) { Module.printErr('Failed to save IDB file system: ' + err.message); } + if (err) { console.warn('Failed to save IDB file system: ' + err.message); } }); ); /* clang-format on */ diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index b630e4f223..f0945e2e1e 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -86,6 +86,9 @@ public: r_features->push_back("OSX"); } + virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) { + } + EditorExportPlatformOSX(); ~EditorExportPlatformOSX(); }; @@ -109,11 +112,11 @@ void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "zip"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "zip"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "png"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier"), "org.godotengine.macgame")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "godotmacgame")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), "")); diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index ebc2c2d7a2..cb6633434b 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -1050,15 +1050,15 @@ public: r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "command_line/extra_args"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/display_name"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/short_name"), "Godot")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/unique_name"), "Godot.Engine")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/description"), "Godot Engine")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/publisher"), "CN=GodotEngine")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/publisher_display_name"), "Godot Engine")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/display_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/short_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/unique_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game.Name"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/description"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/publisher", PROPERTY_HINT_PLACEHOLDER_TEXT, "CN=CompanyName"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/publisher_display_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "identity/product_guid"), "00000000-0000-0000-0000-000000000000")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "identity/publisher_guid"), "00000000-0000-0000-0000-000000000000")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "identity/product_guid", PROPERTY_HINT_PLACEHOLDER_TEXT, "00000000-0000-0000-0000-000000000000"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "identity/publisher_guid", PROPERTY_HINT_PLACEHOLDER_TEXT, "00000000-0000-0000-0000-000000000000"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "signing/certificate", PROPERTY_HINT_GLOBAL_FILE, "*.pfx"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "signing/password"), "")); @@ -1454,6 +1454,9 @@ public: r_features->push_back("UWP"); } + virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) { + } + EditorExportUWP() { Ref<Image> img = memnew(Image(_uwp_logo)); logo.instance(); diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 34fc3e09b5..dcd3597e88 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -172,6 +172,7 @@ def configure_msvc(env, manual_msvc_config): env.Append(CCFLAGS=['/O1']) env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS']) env.Append(LINKFLAGS=['/ENTRY:mainCRTStartup']) + env.Append(LINKFLAGS=['/OPT:REF']) elif (env["target"] == "release_debug"): if (env["optimize"] == "speed"): #optimize for speed (default) @@ -180,12 +181,7 @@ def configure_msvc(env, manual_msvc_config): env.Append(CCFLAGS=['/O1']) env.AppendUnique(CPPDEFINES = ['DEBUG_ENABLED']) env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE']) - - elif (env["target"] == "debug_release"): - env.Append(CCFLAGS=['/Z7', '/Od']) - env.Append(LINKFLAGS=['/DEBUG']) - env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS']) - env.Append(LINKFLAGS=['/ENTRY:mainCRTStartup']) + env.Append(LINKFLAGS=['/OPT:REF']) elif (env["target"] == "debug"): env.AppendUnique(CCFLAGS=['/Z7', '/Od', '/EHsc']) @@ -194,6 +190,10 @@ def configure_msvc(env, manual_msvc_config): env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE']) env.Append(LINKFLAGS=['/DEBUG']) + if (env["debug_symbols"] == "full" or env["debug_symbols"] == "yes"): + env.AppendUnique(CCFLAGS=['/Z7']) + env.AppendUnique(LINKFLAGS=['/DEBUG']) + ## Compile/link flags env.AppendUnique(CCFLAGS=['/MT', '/Gd', '/GR', '/nologo']) diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp index 97544c18f5..38fd6366c7 100644 --- a/platform/windows/export/export.cpp +++ b/platform/windows/export/export.cpp @@ -137,14 +137,14 @@ Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset> void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_options) { EditorExportPlatformPC::get_export_options(r_options); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_GLOBAL_FILE, "*.ico"), String())); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version"), String())); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version"), String())); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name"), String())); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name"), String())); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), String())); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), String())); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), String())); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_GLOBAL_FILE, "*.ico"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), "")); } void register_windows_exporter() { diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index d6cfd039d9..c6a651bc7d 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -190,6 +190,28 @@ BOOL WINAPI HandlerRoutine(_In_ DWORD dwCtrlType) { } } +BOOL CALLBACK _CloseWindowsEnum(HWND hWnd, LPARAM lParam) { + DWORD dwID; + + GetWindowThreadProcessId(hWnd, &dwID); + + if (dwID == (DWORD)lParam) { + PostMessage(hWnd, WM_CLOSE, 0, 0); + } + + return TRUE; +} + +bool _close_gracefully(const PROCESS_INFORMATION &pi, const DWORD dwStopWaitMsec) { + if (!EnumWindows(_CloseWindowsEnum, pi.dwProcessId)) + return false; + + if (WaitForSingleObject(pi.hProcess, dwStopWaitMsec) != WAIT_OBJECT_0) + return false; + + return true; +} + void OS_Windows::initialize_debugging() { SetConsoleCtrlHandler(HandlerRoutine, TRUE); @@ -2322,20 +2344,26 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments, return OK; }; -Error OS_Windows::kill(const ProcessID &p_pid) { - +Error OS_Windows::kill(const ProcessID &p_pid, const int p_max_wait_msec) { ERR_FAIL_COND_V(!process_map->has(p_pid), FAILED); const PROCESS_INFORMATION pi = (*process_map)[p_pid].pi; process_map->erase(p_pid); - const int ret = TerminateProcess(pi.hProcess, 0); + Error result; + + if (p_max_wait_msec != -1 && _close_gracefully(pi, p_max_wait_msec)) { + result = OK; + } else { + const int ret = TerminateProcess(pi.hProcess, 0); + result = ret != 0 ? OK : FAILED; + } CloseHandle(pi.hProcess); CloseHandle(pi.hThread); - return ret != 0 ? OK : FAILED; -}; + return result; +} int OS_Windows::get_process_id() const { return _getpid(); @@ -2777,7 +2805,7 @@ int OS_Windows::get_power_percent_left() { bool OS_Windows::_check_internal_feature_support(const String &p_feature) { - return p_feature == "pc" || p_feature == "s3tc"; + return p_feature == "pc" || p_feature == "s3tc" || p_feature == "bptc"; } void OS_Windows::disable_crash_handler() { @@ -2790,9 +2818,13 @@ bool OS_Windows::is_disable_crash_handler() const { Error OS_Windows::move_to_trash(const String &p_path) { SHFILEOPSTRUCTW sf; + WCHAR *from = new WCHAR[p_path.length() + 2]; + wcscpy(from, p_path.c_str()); + from[p_path.length() + 1] = 0; + sf.hwnd = hWnd; sf.wFunc = FO_DELETE; - sf.pFrom = p_path.c_str(); + sf.pFrom = from; sf.pTo = NULL; sf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; sf.fAnyOperationsAborted = FALSE; @@ -2800,6 +2832,7 @@ Error OS_Windows::move_to_trash(const String &p_path) { sf.lpszProgressTitle = NULL; int ret = SHFileOperationW(&sf); + delete[] from; if (ret) { ERR_PRINTS("SHFileOperation error: " + itos(ret)); diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 69c7d851b8..8e39e4c990 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -258,7 +258,7 @@ public: virtual uint64_t get_ticks_usec() const; virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false); - virtual Error kill(const ProcessID &p_pid); + virtual Error kill(const ProcessID &p_pid, const int p_stop_max_wait_msec = -1); virtual int get_process_id() const; virtual bool has_environment(const String &p_var) const; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index a1e844898e..733d2509f7 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -2344,7 +2344,7 @@ Error OS_X11::shell_open(String p_uri) { bool OS_X11::_check_internal_feature_support(const String &p_feature) { - return p_feature == "pc" || p_feature == "s3tc"; + return p_feature == "pc" || p_feature == "s3tc" || p_feature == "bptc"; } String OS_X11::get_config_path() const { diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 507499a324..559e041dbf 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -296,6 +296,7 @@ float AudioStreamPlayer2D::get_volume_db() const { } void AudioStreamPlayer2D::set_pitch_scale(float p_pitch_scale) { + ERR_FAIL_COND(p_pitch_scale <= 0.0); pitch_scale = p_pitch_scale; } float AudioStreamPlayer2D::get_pitch_scale() const { diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index a035d9021f..7f7e3542ed 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -349,23 +349,12 @@ void CanvasItem::_update_callback() { Transform2D CanvasItem::get_global_transform_with_canvas() const { - const CanvasItem *ci = this; - Transform2D xform; - const CanvasItem *last_valid = NULL; - - while (ci) { - - last_valid = ci; - xform = ci->get_transform() * xform; - ci = ci->get_parent_item(); - } - - if (last_valid->canvas_layer) - return last_valid->canvas_layer->get_transform() * xform; + if (canvas_layer) + return canvas_layer->get_transform() * get_global_transform(); else if (is_inside_tree()) - return get_viewport()->get_canvas_transform() * xform; - - return xform; + return get_viewport()->get_canvas_transform() * get_global_transform(); + else + return get_global_transform(); } Transform2D CanvasItem::get_global_transform() const { diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 1e6a251c9c..85f8564ac2 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -139,6 +139,8 @@ class CanvasItem : public Node { GDCLASS(CanvasItem, Node); + friend class CanvasLayer; + public: enum BlendMode { diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 1e2184bd41..52d04ac10a 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -38,7 +38,7 @@ void CollisionObject2D::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { - Transform2D global_transform = get_global_transform(); + Transform2D global_transform = get_global_transform_with_canvas(); if (area) Physics2DServer::get_singleton()->area_set_transform(rid, global_transform); @@ -64,7 +64,7 @@ void CollisionObject2D::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - Transform2D global_transform = get_global_transform(); + Transform2D global_transform = get_global_transform_with_canvas(); if (only_update_transform_changes && global_transform == last_transform) { return; diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 83ef4df8f4..ff5f7062c4 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -119,7 +119,7 @@ void CollisionShape2D::_notification(int p_what) { Color draw_col = get_tree()->get_debug_collisions_color(); if (disabled) { - float g = draw_col.gray(); + float g = draw_col.get_v(); draw_col.r = g; draw_col.g = g; draw_col.b = g; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 8758ffef9f..66686f10a8 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -35,19 +35,6 @@ #include "engine.h" #include "math_funcs.h" #include "scene/scene_string_names.h" -void PhysicsBody2D::_notification(int p_what) { - - /* - switch(p_what) { - - case NOTIFICATION_TRANSFORM_CHANGED: { - - Physics2DServer::get_singleton()->body_set_state(get_rid(),Physics2DServer::BODY_STATE_TRANSFORM,get_global_transform()); - - } break; - } - */ -} void PhysicsBody2D::_set_layers(uint32_t p_mask) { @@ -436,7 +423,7 @@ bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, Physics2DServer::MotionResult *r = NULL; if (p_result.is_valid()) r = p_result->get_result_ptr(); - return Physics2DServer::get_singleton()->body_test_motion(get_rid(), get_global_transform(), p_motion, p_infinite_inertia, p_margin, r); + return Physics2DServer::get_singleton()->body_test_motion(get_rid(), get_global_transform_with_canvas(), p_motion, p_infinite_inertia, p_margin, r); } void RigidBody2D::_direct_state_changed(Object *p_state) { @@ -449,7 +436,7 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { set_block_transform_notify(true); // don't want notify (would feedback loop) if (mode != MODE_KINEMATIC) - set_global_transform(state->get_transform()); + set_global_transform(get_canvas_transform().affine_inverse() * state->get_transform()); linear_velocity = state->get_linear_velocity(); angular_velocity = state->get_angular_velocity(); if (sleeping != state->is_sleeping()) { @@ -1144,7 +1131,7 @@ bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision Physics2DServer::SeparationResult sep_res[8]; //max 8 rays - Transform2D gt = get_global_transform(); + Transform2D gt = get_global_transform_with_canvas(); Vector2 recover; int hits = Physics2DServer::get_singleton()->body_test_ray_separation(get_rid(), gt, p_infinite_inertia, recover, sep_res, 8, margin); @@ -1158,7 +1145,7 @@ bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision } gt.elements[2] += recover; - set_global_transform(gt); + set_global_transform(get_canvas_transform().affine_inverse() * gt); if (deepest != -1) { r_collision.collider = sep_res[deepest].collider_id; @@ -1179,7 +1166,7 @@ bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes, bool p_test_only) { - Transform2D gt = get_global_transform(); + Transform2D gt = get_global_transform_with_canvas(); Physics2DServer::MotionResult result; bool colliding = Physics2DServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, margin, &result, p_exclude_raycast_shapes); @@ -1198,7 +1185,7 @@ bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_ if (!p_test_only) { gt.elements[2] += result.motion; - set_global_transform(gt); + set_global_transform(get_canvas_transform().affine_inverse() * gt); } return colliding; @@ -1207,7 +1194,7 @@ bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_ //so, if you pass 45 as limit, avoid numerical precision erros when angle is 45. #define FLOOR_ANGLE_THRESHOLD 0.01 -Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction, bool p_infinite_inertia, float p_slope_stop_min_velocity, int p_max_slides, float p_floor_max_angle) { +Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction, bool p_infinite_inertia, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle) { Vector2 floor_motion = floor_velocity; if (on_floor && on_floor_body.is_valid()) { @@ -1228,6 +1215,8 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const colliders.clear(); floor_velocity = Vector2(); + Vector2 lv_n = p_linear_velocity.normalized(); + while (p_max_slides) { Collision collision; @@ -1254,8 +1243,10 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const if (collided) { + colliders.push_back(collision); motion = collision.remainder; + bool is_on_slope = false; if (p_floor_direction == Vector2()) { //all is a wall on_wall = true; @@ -1266,15 +1257,17 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const on_floor_body = collision.collider_rid; floor_velocity = collision.collider_vel; - Vector2 rel_v = lv - floor_velocity; - Vector2 hv = rel_v - p_floor_direction * p_floor_direction.dot(rel_v); - - if (collision.travel.length() < 1 && hv.length() < p_slope_stop_min_velocity) { - Transform2D gt = get_global_transform(); - gt.elements[2] -= collision.travel; - set_global_transform(gt); - return Vector2(); + if (p_stop_on_slope) { + if (Vector2() == lv_n + p_floor_direction) { + Transform2D gt = get_global_transform_with_canvas(); + gt.elements[2] -= collision.travel; + set_global_transform(get_canvas_transform().affine_inverse() * gt); + return Vector2(); + } } + + is_on_slope = true; + } else if (collision.normal.dot(-p_floor_direction) >= Math::cos(p_floor_max_angle + FLOOR_ANGLE_THRESHOLD)) { //ceiling on_ceiling = true; } else { @@ -1282,12 +1275,18 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const } } - Vector2 n = collision.normal; - motion = motion.slide(n); - lv = lv.slide(n); - - colliders.push_back(collision); + if (p_stop_on_slope && is_on_slope) { + motion = motion.slide(p_floor_direction); + lv = lv.slide(p_floor_direction); + } else { + Vector2 n = collision.normal; + motion = motion.slide(n); + lv = lv.slide(n); + } } + + if (p_stop_on_slope) + break; } if (!found_collision) { @@ -1301,17 +1300,17 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const return lv; } -Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction, bool p_infinite_inertia, float p_slope_stop_min_velocity, int p_max_slides, float p_floor_max_angle) { +Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction, bool p_infinite_inertia, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle) { bool was_on_floor = on_floor; - Vector2 ret = move_and_slide(p_linear_velocity, p_floor_direction, p_infinite_inertia, p_slope_stop_min_velocity, p_max_slides, p_floor_max_angle); + Vector2 ret = move_and_slide(p_linear_velocity, p_floor_direction, p_infinite_inertia, p_stop_on_slope, p_max_slides, p_floor_max_angle); if (!was_on_floor || p_snap == Vector2()) { return ret; } Collision col; - Transform2D gt = get_global_transform(); + Transform2D gt = get_global_transform_with_canvas(); if (move_and_collide(p_snap, p_infinite_inertia, col, false, true)) { gt.elements[2] += col.travel; @@ -1320,7 +1319,7 @@ Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_veloci on_floor_body = col.collider_rid; floor_velocity = col.collider_vel; } - set_global_transform(gt); + set_global_transform(get_canvas_transform().affine_inverse() * gt); } return ret; @@ -1417,30 +1416,30 @@ void KinematicBody2D::_direct_state_changed(Object *p_state) { last_valid_transform = state->get_transform(); set_notify_local_transform(false); - set_global_transform(last_valid_transform); + set_global_transform(get_canvas_transform().affine_inverse() * last_valid_transform); set_notify_local_transform(true); } void KinematicBody2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - last_valid_transform = get_global_transform(); + last_valid_transform = get_global_transform_with_canvas(); } if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { //used by sync to physics, send the new transform to the physics - Transform2D new_transform = get_global_transform(); + Transform2D new_transform = get_global_transform_with_canvas(); Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_TRANSFORM, new_transform); //but then revert changes set_notify_local_transform(false); - set_global_transform(last_valid_transform); + set_global_transform(get_canvas_transform().affine_inverse() * last_valid_transform); set_notify_local_transform(true); } } void KinematicBody2D::_bind_methods() { ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "exclude_raycast_shapes", "test_only"), &KinematicBody2D::_move, DEFVAL(true), DEFVAL(true), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "infinite_inertia", "slope_stop_min_velocity", "max_bounces", "floor_max_angle"), &KinematicBody2D::move_and_slide, DEFVAL(Vector2(0, 0)), DEFVAL(true), DEFVAL(5), DEFVAL(4), DEFVAL(Math::deg2rad((float)45))); - ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "floor_normal", "infinite_inertia", "slope_stop_min_velocity", "max_bounces", "floor_max_angle"), &KinematicBody2D::move_and_slide_with_snap, DEFVAL(Vector2(0, 0)), DEFVAL(true), DEFVAL(5), DEFVAL(4), DEFVAL(Math::deg2rad((float)45))); + ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "infinite_inertia", "stop_on_slope", "max_bounces", "floor_max_angle"), &KinematicBody2D::move_and_slide, DEFVAL(Vector2(0, 0)), DEFVAL(true), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45))); + ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "floor_normal", "infinite_inertia", "stop_on_slope", "max_bounces", "floor_max_angle"), &KinematicBody2D::move_and_slide_with_snap, DEFVAL(Vector2(0, 0)), DEFVAL(true), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45))); ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec", "infinite_inertia"), &KinematicBody2D::test_move); diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 0a2ce0918b..0900438e3c 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -49,7 +49,6 @@ class PhysicsBody2D : public CollisionObject2D { uint32_t _get_layers() const; protected: - void _notification(int p_what); PhysicsBody2D(Physics2DServer::BodyMode p_mode); static void _bind_methods(); @@ -338,8 +337,8 @@ public: void set_safe_margin(float p_margin); float get_safe_margin() const; - Vector2 move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_infinite_inertia = true, float p_slope_stop_min_velocity = 5, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45)); - Vector2 move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_infinite_inertia = true, float p_slope_stop_min_velocity = 5, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45)); + Vector2 move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_infinite_inertia = true, bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45)); + Vector2 move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_infinite_inertia = true, bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45)); bool is_on_floor() const; bool is_on_wall() const; bool is_on_ceiling() const; diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 255d2d38d5..9582c08110 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -209,7 +209,7 @@ void RayCast2D::_update_raycast_state() { Physics2DDirectSpaceState::RayResult rr; - if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask)) { + if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, collide_with_bodies, collide_with_areas)) { collided = true; against = rr.collider_id; @@ -258,6 +258,26 @@ void RayCast2D::clear_exceptions() { exclude.clear(); } +void RayCast2D::set_collide_with_areas(bool p_clip) { + + collide_with_areas = p_clip; +} + +bool RayCast2D::is_collide_with_areas_enabled() const { + + return collide_with_areas; +} + +void RayCast2D::set_collide_with_bodies(bool p_clip) { + + collide_with_bodies = p_clip; +} + +bool RayCast2D::is_collide_with_bodies_enabled() const { + + return collide_with_bodies; +} + void RayCast2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast2D::set_enabled); @@ -291,10 +311,20 @@ void RayCast2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast2D::set_exclude_parent_body); ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast2D::get_exclude_parent_body); + ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &RayCast2D::set_collide_with_areas); + ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &RayCast2D::is_collide_with_areas_enabled); + + ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &RayCast2D::set_collide_with_bodies); + ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &RayCast2D::is_collide_with_bodies_enabled); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "cast_to"), "set_cast_to", "get_cast_to"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask"); + + ADD_GROUP("Collide With", "collide_with"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_areas", "is_collide_with_areas_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_bodies", "is_collide_with_bodies_enabled"); } RayCast2D::RayCast2D() { @@ -306,4 +336,6 @@ RayCast2D::RayCast2D() { collision_mask = 1; cast_to = Vector2(0, 50); exclude_parent_body = true; + collide_with_bodies = true; + collide_with_areas = false; } diff --git a/scene/2d/ray_cast_2d.h b/scene/2d/ray_cast_2d.h index 0850cdc7cc..a438be87b6 100644 --- a/scene/2d/ray_cast_2d.h +++ b/scene/2d/ray_cast_2d.h @@ -49,12 +49,21 @@ class RayCast2D : public Node2D { Vector2 cast_to; + bool collide_with_areas; + bool collide_with_bodies; + protected: void _notification(int p_what); void _update_raycast_state(); static void _bind_methods(); public: + void set_collide_with_areas(bool p_clip); + bool is_collide_with_areas_enabled() const; + + void set_collide_with_bodies(bool p_clip); + bool is_collide_with_bodies_enabled() const; + void set_enabled(bool p_enabled); bool is_enabled() const; diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index e6e9bde20a..2c362f1b31 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -288,7 +288,7 @@ void Skeleton2D::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_transform"), &Skeleton2D::_update_transform); ClassDB::bind_method(D_METHOD("get_bone_count"), &Skeleton2D::get_bone_count); - ClassDB::bind_method(D_METHOD("get_bone"), &Skeleton2D::get_bone); + ClassDB::bind_method(D_METHOD("get_bone", "idx"), &Skeleton2D::get_bone); ClassDB::bind_method(D_METHOD("get_skeleton"), &Skeleton2D::get_skeleton); } diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 5f0ac3dd80..8504a18f54 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -626,6 +626,7 @@ float AudioStreamPlayer3D::get_max_db() const { } void AudioStreamPlayer3D::set_pitch_scale(float p_pitch_scale) { + ERR_FAIL_COND(p_pitch_scale <= 0.0); pitch_scale = p_pitch_scale; } float AudioStreamPlayer3D::get_pitch_scale() const { diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 2176b45faf..bcd015875b 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -31,9 +31,10 @@ #include "camera.h" #include "camera_matrix.h" +#include "collision_object.h" +#include "engine.h" #include "scene/resources/material.h" #include "scene/resources/surface_tool.h" - void Camera::_update_audio_listener_state() { } @@ -313,6 +314,32 @@ bool Camera::is_position_behind(const Vector3 &p_pos) const { return eyedir.dot(p_pos) < (eyedir.dot(t.origin) + near); } +Vector<Vector3> Camera::get_near_plane_points() const { + if (!is_inside_tree()) { + ERR_EXPLAIN("Camera is not inside scene."); + ERR_FAIL_COND_V(!is_inside_tree(), Vector<Vector3>()); + } + + Size2 viewport_size = get_viewport()->get_visible_rect().size; + + CameraMatrix cm; + + if (mode == PROJECTION_ORTHOGONAL) + cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); + else + cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); + + Vector3 endpoints[8]; + cm.get_endpoints(Transform(), endpoints); + + Vector<Vector3> points; + points.push_back(Vector3()); + for (int i = 0; i < 4; i++) { + points.push_back(endpoints[i + 4]); + } + return points; +} + Point2 Camera::unproject_position(const Vector3 &p_pos) const { if (!is_inside_tree()) { @@ -484,7 +511,7 @@ void Camera::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "set_current", "is_current"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "fov", PROPERTY_HINT_RANGE, "1,179,0.1"), "set_fov", "get_fov"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "size", PROPERTY_HINT_RANGE, "0.1,16384,0.01"), "set_size", "get_size"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "near", PROPERTY_HINT_EXP_RANGE, "0.1,8192,0.1,or_greater"), "set_znear", "get_znear"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "near", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01,or_greater"), "set_znear", "get_znear"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "far", PROPERTY_HINT_EXP_RANGE, "0.1,8192,0.1,or_greater"), "set_zfar", "get_zfar"); BIND_ENUM_CONSTANT(PROJECTION_PERSPECTIVE); @@ -638,3 +665,221 @@ Camera::~Camera() { VisualServer::get_singleton()->free(camera); } + +//////////////////////////////////////// + +void ClippedCamera::set_margin(float p_margin) { + margin = p_margin; +} +float ClippedCamera::get_margin() const { + return margin; +} +void ClippedCamera::set_process_mode(ProcessMode p_mode) { + + if (process_mode == p_mode) { + return; + } + set_process_internal(p_mode == CLIP_PROCESS_IDLE); + set_physics_process_internal(p_mode == CLIP_PROCESS_PHYSICS); +} +ClippedCamera::ProcessMode ClippedCamera::get_process_mode() const { + return process_mode; +} + +Transform ClippedCamera::get_camera_transform() const { + + Transform t = Camera::get_camera_transform(); + t.origin += -t.basis.get_axis(Vector3::AXIS_Z).normalized() * clip_offset; + return t; +} + +void ClippedCamera::_notification(int p_what) { + if (p_what == NOTIFICATION_INTERNAL_PROCESS || p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { + + Spatial *parent = Object::cast_to<Spatial>(get_parent()); + if (!parent) { + return; + } + + PhysicsDirectSpaceState *dspace = get_world()->get_direct_space_state(); + ERR_FAIL_COND(!dspace); // most likely physics set to threads + + Vector3 cam_fw = -get_global_transform().basis.get_axis(Vector3::AXIS_Z).normalized(); + Vector3 cam_pos = get_global_transform().origin; + Vector3 parent_pos = parent->get_global_transform().origin; + + Plane parent_plane(parent_pos, cam_fw); + + if (parent_plane.is_point_over(cam_pos)) { + //cam is beyond parent plane + return; + } + + Vector3 ray_from = parent_plane.project(cam_pos); + + clip_offset = 0; //reset by defau;t + + { //check if points changed + Vector<Vector3> local_points = get_near_plane_points(); + + bool all_equal = true; + + for (int i = 0; i < 5; i++) { + if (points[i] != local_points[i]) { + all_equal = false; + break; + } + } + + if (!all_equal) { + PhysicsServer::get_singleton()->shape_set_data(pyramid_shape, local_points); + points = local_points; + } + } + + Transform xf = get_global_transform(); + xf.origin = ray_from; + xf.orthonormalize(); + + float csafe, cunsafe; + if (dspace->cast_motion(pyramid_shape, xf, cam_pos - ray_from, margin, csafe, cunsafe, exclude, collision_mask, clip_to_bodies, clip_to_areas)) { + clip_offset = cam_pos.distance_to(ray_from + (cam_pos - ray_from).normalized() * csafe); + } + + _update_camera(); + } + + if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { + update_gizmo(); + } +} + +void ClippedCamera::set_collision_mask(uint32_t p_mask) { + + collision_mask = p_mask; +} + +uint32_t ClippedCamera::get_collision_mask() const { + + return collision_mask; +} + +void ClippedCamera::set_collision_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_collision_mask(); + if (p_value) + mask |= 1 << p_bit; + else + mask &= ~(1 << p_bit); + set_collision_mask(mask); +} + +bool ClippedCamera::get_collision_mask_bit(int p_bit) const { + + return get_collision_mask() & (1 << p_bit); +} + +void ClippedCamera::add_exception_rid(const RID &p_rid) { + + exclude.insert(p_rid); +} + +void ClippedCamera::add_exception(const Object *p_object) { + + ERR_FAIL_NULL(p_object); + const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + if (!co) + return; + add_exception_rid(co->get_rid()); +} + +void ClippedCamera::remove_exception_rid(const RID &p_rid) { + + exclude.erase(p_rid); +} + +void ClippedCamera::remove_exception(const Object *p_object) { + + ERR_FAIL_NULL(p_object); + const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + if (!co) + return; + remove_exception_rid(co->get_rid()); +} + +void ClippedCamera::clear_exceptions() { + + exclude.clear(); +} + +void ClippedCamera::set_clip_to_areas(bool p_clip) { + + clip_to_areas = p_clip; +} + +bool ClippedCamera::is_clip_to_areas_enabled() const { + + return clip_to_areas; +} + +void ClippedCamera::set_clip_to_bodies(bool p_clip) { + + clip_to_bodies = p_clip; +} + +bool ClippedCamera::is_clip_to_bodies_enabled() const { + + return clip_to_bodies; +} + +void ClippedCamera::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_margin", "margin"), &ClippedCamera::set_margin); + ClassDB::bind_method(D_METHOD("get_margin"), &ClippedCamera::get_margin); + + ClassDB::bind_method(D_METHOD("set_process_mode", "process_mode"), &ClippedCamera::set_process_mode); + ClassDB::bind_method(D_METHOD("get_process_mode"), &ClippedCamera::get_process_mode); + + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &ClippedCamera::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &ClippedCamera::get_collision_mask); + + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &ClippedCamera::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &ClippedCamera::get_collision_mask_bit); + + ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &ClippedCamera::add_exception_rid); + ClassDB::bind_method(D_METHOD("add_exception", "node"), &ClippedCamera::add_exception); + + ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &ClippedCamera::remove_exception_rid); + ClassDB::bind_method(D_METHOD("remove_exception", "node"), &ClippedCamera::remove_exception); + + ClassDB::bind_method(D_METHOD("set_clip_to_areas", "enable"), &ClippedCamera::set_clip_to_areas); + ClassDB::bind_method(D_METHOD("is_clip_to_areas_enabled"), &ClippedCamera::is_clip_to_areas_enabled); + + ClassDB::bind_method(D_METHOD("set_clip_to_bodies", "enable"), &ClippedCamera::set_clip_to_bodies); + ClassDB::bind_method(D_METHOD("is_clip_to_bodies_enabled"), &ClippedCamera::is_clip_to_bodies_enabled); + + ClassDB::bind_method(D_METHOD("clear_exceptions"), &ClippedCamera::clear_exceptions); + + ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_margin", "get_margin"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); + + ADD_GROUP("Clip To", "clip_to"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_to_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_clip_to_areas", "is_clip_to_areas_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_to_bodies", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_clip_to_bodies", "is_clip_to_bodies_enabled"); +} +ClippedCamera::ClippedCamera() { + margin = 0; + clip_offset = 0; + process_mode = CLIP_PROCESS_PHYSICS; + set_physics_process_internal(true); + collision_mask = 1; + set_notify_local_transform(Engine::get_singleton()->is_editor_hint()); + points.resize(5); + pyramid_shape = PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON); + clip_to_areas = false; + clip_to_bodies = true; +} +ClippedCamera::~ClippedCamera() { + PhysicsServer::get_singleton()->free(pyramid_shape); +} diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 97705d8ae0..a35c9d6e7f 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -139,6 +139,8 @@ public: bool is_position_behind(const Vector3 &p_pos) const; virtual Vector3 project_position(const Point2 &p_point) const; + Vector<Vector3> get_near_plane_points() const; + void set_cull_mask(uint32_t p_layers); uint32_t get_cull_mask() const; @@ -172,4 +174,62 @@ VARIANT_ENUM_CAST(Camera::Projection); VARIANT_ENUM_CAST(Camera::KeepAspect); VARIANT_ENUM_CAST(Camera::DopplerTracking); +class ClippedCamera : public Camera { + + GDCLASS(ClippedCamera, Camera); + +public: + enum ProcessMode { + CLIP_PROCESS_PHYSICS, + CLIP_PROCESS_IDLE, + }; + +private: + ProcessMode process_mode; + RID pyramid_shape; + float margin; + float clip_offset; + uint32_t collision_mask; + bool clip_to_areas; + bool clip_to_bodies; + + Set<RID> exclude; + + Vector<Vector3> points; + +protected: + void _notification(int p_what); + static void _bind_methods(); + virtual Transform get_camera_transform() const; + +public: + void set_clip_to_areas(bool p_clip); + bool is_clip_to_areas_enabled() const; + + void set_clip_to_bodies(bool p_clip); + bool is_clip_to_bodies_enabled() const; + + void set_margin(float p_margin); + float get_margin() const; + + void set_process_mode(ProcessMode p_mode); + ProcessMode get_process_mode() const; + + void set_collision_mask(uint32_t p_mask); + uint32_t get_collision_mask() const; + + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; + + void add_exception_rid(const RID &p_rid); + void add_exception(const Object *p_object); + void remove_exception_rid(const RID &p_rid); + void remove_exception(const Object *p_object); + void clear_exceptions(); + + ClippedCamera(); + ~ClippedCamera(); +}; + +VARIANT_ENUM_CAST(ClippedCamera::ProcessMode); #endif diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index e53ccb4cf4..2df6ef7c8a 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -1078,10 +1078,10 @@ void RigidBody::_reload_physics_characteristics() { ////////////////////////////////////////////////////// ////////////////////////// -Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_infinite_inertia) { +Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_infinite_inertia, bool p_test_only) { Collision col; - if (move_and_collide(p_motion, p_infinite_inertia, col)) { + if (move_and_collide(p_motion, p_infinite_inertia, col, p_test_only)) { if (motion_cache.is_null()) { motion_cache.instance(); motion_cache->owner = this; @@ -1095,7 +1095,7 @@ Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_inf return Ref<KinematicCollision>(); } -bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collision) { +bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_test_only) { Transform gt = get_global_transform(); PhysicsServer::MotionResult result; @@ -1108,6 +1108,7 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_in r_collision.collision = result.collision_point; r_collision.normal = result.collision_normal; r_collision.collider = result.collider_id; + r_collision.collider_rid = result.collider; r_collision.travel = result.motion; r_collision.remainder = result.remainder; r_collision.local_shape = result.collision_local_shape; @@ -1119,8 +1120,10 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_in } } - gt.origin += result.motion; - set_global_transform(gt); + if (!p_test_only) { + gt.origin += result.motion; + set_global_transform(gt); + } return colliding; } @@ -1128,7 +1131,7 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_in //so, if you pass 45 as limit, avoid numerical precision erros when angle is 45. #define FLOOR_ANGLE_THRESHOLD 0.01 -Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction, float p_slope_stop_min_velocity, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { +Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { Vector3 lv = p_linear_velocity; @@ -1146,69 +1149,127 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve colliders.clear(); floor_velocity = Vector3(); + Vector3 lv_n = p_linear_velocity.normalized(); + while (p_max_slides) { Collision collision; - bool collided = move_and_collide(motion, p_infinite_inertia, collision); - - if (collided) { + bool found_collision = false; - motion = collision.remainder; + int test_type = 0; - if (p_floor_direction == Vector3()) { - //all is a wall - on_wall = true; + do { + bool collided; + if (test_type == 0) { //collide + collided = move_and_collide(motion, p_infinite_inertia, collision); + if (!collided) { + motion = Vector3(); //clear because no collision happened and motion completed + } } else { - if (collision.normal.dot(p_floor_direction) >= Math::cos(p_floor_max_angle + FLOOR_ANGLE_THRESHOLD)) { //floor + collided = separate_raycast_shapes(p_infinite_inertia, collision); + if (collided) { + collision.remainder = motion; //keep + collision.travel = Vector3(); + } + } - on_floor = true; - floor_velocity = collision.collider_vel; + if (collided) { + found_collision = true; + } - Vector3 rel_v = lv - floor_velocity; - Vector3 hv = rel_v - p_floor_direction * p_floor_direction.dot(rel_v); + if (collided) { - if (collision.travel.length() < 0.05 && hv.length() < p_slope_stop_min_velocity) { - Transform gt = get_global_transform(); - gt.origin -= collision.travel; - set_global_transform(gt); - return floor_velocity - p_floor_direction * p_floor_direction.dot(floor_velocity); - } - } else if (collision.normal.dot(-p_floor_direction) >= Math::cos(p_floor_max_angle + FLOOR_ANGLE_THRESHOLD)) { //ceiling - on_ceiling = true; - } else { + colliders.push_back(collision); + motion = collision.remainder; + + bool is_on_slope = false; + if (p_floor_direction == Vector3()) { + //all is a wall on_wall = true; + } else { + if (collision.normal.dot(p_floor_direction) >= Math::cos(p_floor_max_angle + FLOOR_ANGLE_THRESHOLD)) { //floor + + on_floor = true; + on_floor_body = collision.collider_rid; + floor_velocity = collision.collider_vel; + + if (p_stop_on_slope) { + if (Vector3() == lv_n + p_floor_direction) { + Transform gt = get_global_transform(); + gt.origin -= collision.travel; + set_global_transform(gt); + return Vector3(); + } + } + + is_on_slope = true; + + } else if (collision.normal.dot(-p_floor_direction) >= Math::cos(p_floor_max_angle + FLOOR_ANGLE_THRESHOLD)) { //ceiling + on_ceiling = true; + } else { + on_wall = true; + } } - } - Vector3 n = collision.normal; - motion = motion.slide(n); - lv = lv.slide(n); + if (p_stop_on_slope && is_on_slope) { + motion = motion.slide(p_floor_direction); + lv = lv.slide(p_floor_direction); + } else { + Vector3 n = collision.normal; + motion = motion.slide(n); + lv = lv.slide(n); + } - for (int i = 0; i < 3; i++) { - if (locked_axis & (1 << i)) { - lv[i] = 0; + for (int i = 0; i < 3; i++) { + if (locked_axis & (1 << i)) { + lv[i] = 0; + } } } - colliders.push_back(collision); + ++test_type; + } while (!p_stop_on_slope && test_type < 2); - } else { + if (!found_collision || motion == Vector3()) break; - } - p_max_slides--; - if (motion == Vector3()) - break; + --p_max_slides; } return lv; } +Vector3 KinematicBody::move_and_slide_with_snap(const Vector3 &p_linear_velocity, const Vector3 &p_snap, const Vector3 &p_floor_direction, bool p_infinite_inertia, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle) { + + bool was_on_floor = on_floor; + + Vector3 ret = move_and_slide(p_linear_velocity, p_floor_direction, p_stop_on_slope, p_max_slides, p_floor_max_angle, p_infinite_inertia); + if (!was_on_floor || p_snap == Vector3()) { + return ret; + } + + Collision col; + Transform gt = get_global_transform(); + + if (move_and_collide(p_snap, p_infinite_inertia, col, true)) { + gt.origin += col.travel; + if (p_floor_direction != Vector3() && Math::acos(p_floor_direction.normalized().dot(col.normal)) < p_floor_max_angle) { + on_floor = true; + on_floor_body = col.collider_rid; + floor_velocity = col.collider_vel; + } + set_global_transform(gt); + } + + return ret; +} + bool KinematicBody::is_on_floor() const { return on_floor; } + bool KinematicBody::is_on_wall() const { return on_wall; @@ -1230,6 +1291,43 @@ bool KinematicBody::test_move(const Transform &p_from, const Vector3 &p_motion, return PhysicsServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia); } +bool KinematicBody::separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision) { + + PhysicsServer::SeparationResult sep_res[8]; //max 8 rays + + Transform gt = get_global_transform(); + + Vector3 recover; + int hits = PhysicsServer::get_singleton()->body_test_ray_separation(get_rid(), gt, p_infinite_inertia, recover, sep_res, 8, margin); + int deepest = -1; + float deepest_depth; + for (int i = 0; i < hits; i++) { + if (deepest == -1 || sep_res[i].collision_depth > deepest_depth) { + deepest = i; + deepest_depth = sep_res[i].collision_depth; + } + } + + gt.origin += recover; + set_global_transform(gt); + + if (deepest != -1) { + r_collision.collider = sep_res[deepest].collider_id; + r_collision.collider_metadata = sep_res[deepest].collider_metadata; + r_collision.collider_shape = sep_res[deepest].collider_shape; + r_collision.collider_vel = sep_res[deepest].collider_velocity; + r_collision.collision = sep_res[deepest].collision_point; + r_collision.normal = sep_res[deepest].collision_normal; + r_collision.local_shape = sep_res[deepest].collision_local_shape; + r_collision.travel = recover; + r_collision.remainder = Vector3(); + + return true; + } else { + return false; + } +} + void KinematicBody::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock) { PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); } @@ -1276,8 +1374,9 @@ Ref<KinematicCollision> KinematicBody::_get_slide_collision(int p_bounce) { void KinematicBody::_bind_methods() { - ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia"), &KinematicBody::_move, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "slope_stop_min_velocity", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody::move_and_slide, DEFVAL(Vector3(0, 0, 0)), DEFVAL(0.05), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "test_only"), &KinematicBody::_move, DEFVAL(true), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody::move_and_slide, DEFVAL(Vector3(0, 0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "floor_normal", "infinite_inertia", "stop_on_slope", "max_bounces", "floor_max_angle"), &KinematicBody::move_and_slide_with_snap, DEFVAL(Vector3(0, 0, 0)), DEFVAL(true), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45))); ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec", "infinite_inertia"), &KinematicBody::test_move); @@ -1295,13 +1394,9 @@ void KinematicBody::_bind_methods() { ClassDB::bind_method(D_METHOD("get_slide_count"), &KinematicBody::get_slide_count); ClassDB::bind_method(D_METHOD("get_slide_collision", "slide_idx"), &KinematicBody::_get_slide_collision); - ADD_GROUP("Axis Lock", "axis_lock_"); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_x"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_X); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_y"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Y); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_z"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Z); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_x"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_ANGULAR_X); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_y"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_ANGULAR_Y); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_z"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_ANGULAR_Z); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_x", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_y", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_z", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Z); ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision/safe_margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_safe_margin", "get_safe_margin"); } diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index 80bf422c98..c4db41f577 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -285,6 +285,7 @@ public: Vector3 normal; Vector3 collider_vel; ObjectID collider; + RID collider_rid; int collider_shape; Variant collider_metadata; Vector3 remainder; @@ -298,6 +299,7 @@ private: float margin; Vector3 floor_velocity; + RID on_floor_body; bool on_floor; bool on_ceiling; bool on_wall; @@ -307,23 +309,26 @@ private: _FORCE_INLINE_ bool _ignores_mode(PhysicsServer::BodyMode) const; - Ref<KinematicCollision> _move(const Vector3 &p_motion, bool p_infinite_inertia = true); + Ref<KinematicCollision> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_test_only = false); Ref<KinematicCollision> _get_slide_collision(int p_bounce); protected: static void _bind_methods(); public: - bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collisionz); + bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collisionz, bool p_test_only = false); bool test_move(const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia); + bool separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision); + void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock); bool get_axis_lock(PhysicsServer::BodyAxis p_axis) const; void set_safe_margin(float p_margin); float get_safe_margin() const; - Vector3 move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction = Vector3(0, 0, 0), float p_slope_stop_min_velocity = 0.05, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45), bool p_infinite_inertia = true); + Vector3 move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction = Vector3(0, 0, 0), bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45), bool p_infinite_inertia = true); + Vector3 move_and_slide_with_snap(const Vector3 &p_linear_velocity, const Vector3 &p_snap, const Vector3 &p_floor_direction = Vector3(0, 0, 0), bool p_infinite_inertia = true, bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45)); bool is_on_floor() const; bool is_on_wall() const; bool is_on_ceiling() const; diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index 7f83e2c3ea..b846a5b6c0 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -208,7 +208,7 @@ void RayCast::_update_raycast_state() { PhysicsDirectSpaceState::RayResult rr; - if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask)) { + if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, collide_with_bodies, collide_with_areas)) { collided = true; against = rr.collider_id; @@ -259,6 +259,26 @@ void RayCast::clear_exceptions() { exclude.clear(); } +void RayCast::set_collide_with_areas(bool p_clip) { + + collide_with_areas = p_clip; +} + +bool RayCast::is_collide_with_areas_enabled() const { + + return collide_with_areas; +} + +void RayCast::set_collide_with_bodies(bool p_clip) { + + collide_with_bodies = p_clip; +} + +bool RayCast::is_collide_with_bodies_enabled() const { + + return collide_with_bodies; +} + void RayCast::_bind_methods() { ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast::set_enabled); @@ -292,10 +312,20 @@ void RayCast::_bind_methods() { ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast::set_exclude_parent_body); ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast::get_exclude_parent_body); + ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &RayCast::set_collide_with_areas); + ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &RayCast::is_collide_with_areas_enabled); + + ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &RayCast::set_collide_with_bodies); + ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &RayCast::is_collide_with_bodies_enabled); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cast_to"), "set_cast_to", "get_cast_to"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); + + ADD_GROUP("Collide With", "collide_with"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_areas", "is_collide_with_areas_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_bodies", "is_collide_with_bodies_enabled"); } void RayCast::_create_debug_shape() { @@ -370,4 +400,6 @@ RayCast::RayCast() { cast_to = Vector3(0, -1, 0); debug_shape = NULL; exclude_parent_body = true; + collide_with_areas = false; + collide_with_bodies = true; } diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast.h index 20cea80700..e95382e1fe 100644 --- a/scene/3d/ray_cast.h +++ b/scene/3d/ray_cast.h @@ -45,7 +45,6 @@ class RayCast : public Spatial { Vector3 collision_normal; Vector3 cast_to; - Set<RID> exclude; uint32_t collision_mask; @@ -58,12 +57,21 @@ class RayCast : public Spatial { void _update_debug_shape(); void _clear_debug_shape(); + bool collide_with_areas; + bool collide_with_bodies; + protected: void _notification(int p_what); void _update_raycast_state(); static void _bind_methods(); public: + void set_collide_with_areas(bool p_clip); + bool is_collide_with_areas_enabled() const; + + void set_collide_with_bodies(bool p_clip); + bool is_collide_with_bodies_enabled() const; + void set_enabled(bool p_enabled); bool is_enabled() const; diff --git a/scene/3d/spring_arm.cpp b/scene/3d/spring_arm.cpp new file mode 100644 index 0000000000..492c6b806e --- /dev/null +++ b/scene/3d/spring_arm.cpp @@ -0,0 +1,172 @@ +/*************************************************************************/ +/* spring_arm.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "spring_arm.h" +#include "engine.h" +#include "scene/3d/collision_object.h" +#include "scene/resources/sphere_shape.h" +#include "servers/physics_server.h" + +SpringArm::SpringArm() : + spring_length(1), + mask(1), + current_spring_length(0), + margin(0.01) {} + +void SpringArm::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + if (!Engine::get_singleton()->is_editor_hint()) { + set_process_internal(true); + } + break; + case NOTIFICATION_EXIT_TREE: + if (!Engine::get_singleton()->is_editor_hint()) { + set_process_internal(false); + } + break; + case NOTIFICATION_INTERNAL_PROCESS: + process_spring(); + break; + } +} + +void SpringArm::_bind_methods() { + + ClassDB::bind_method(D_METHOD("get_hit_length"), &SpringArm::get_hit_length); + + ClassDB::bind_method(D_METHOD("set_length", "length"), &SpringArm::set_length); + ClassDB::bind_method(D_METHOD("get_length"), &SpringArm::get_length); + + ClassDB::bind_method(D_METHOD("set_shape", "shape"), &SpringArm::set_shape); + ClassDB::bind_method(D_METHOD("get_shape"), &SpringArm::get_shape); + + ClassDB::bind_method(D_METHOD("add_excluded_object", "RID"), &SpringArm::add_excluded_object); + ClassDB::bind_method(D_METHOD("remove_excluded_object", "RID"), &SpringArm::remove_excluded_object); + ClassDB::bind_method(D_METHOD("clear_excluded_objects"), &SpringArm::clear_excluded_objects); + + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &SpringArm::set_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &SpringArm::get_mask); + + ClassDB::bind_method(D_METHOD("set_margin", "margin"), &SpringArm::set_margin); + ClassDB::bind_method(D_METHOD("get_margin"), &SpringArm::get_margin); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape"), "set_shape", "get_shape"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "spring_length"), "set_length", "get_length"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin"), "set_margin", "get_margin"); +} + +float SpringArm::get_length() const { + return spring_length; +} + +void SpringArm::set_length(float p_length) { + if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) + update_gizmo(); + + spring_length = p_length; +} + +void SpringArm::set_shape(Ref<Shape> p_shape) { + shape = p_shape; +} + +Ref<Shape> SpringArm::get_shape() const { + return shape; +} + +void SpringArm::set_mask(uint32_t p_mask) { + mask = p_mask; +} + +uint32_t SpringArm::get_mask() { + return mask; +} + +float SpringArm::get_margin() { + return margin; +} + +void SpringArm::set_margin(float p_margin) { + margin = p_margin; +} + +void SpringArm::add_excluded_object(RID p_rid) { + excluded_objects.insert(p_rid); +} + +bool SpringArm::remove_excluded_object(RID p_rid) { + return excluded_objects.erase(p_rid); +} + +void SpringArm::clear_excluded_objects() { + excluded_objects.clear(); +} + +float SpringArm::get_hit_length() { + return current_spring_length; +} + +void SpringArm::process_spring() { + // From + real_t motion_delta(1); + real_t motion_delta_unsafe(1); + + Vector3 motion; + const Vector3 cast_direction(get_global_transform().basis.xform(Vector3(0, 0, 1))); + + if (shape.is_null()) { + motion = Vector3(cast_direction * (spring_length)); + PhysicsDirectSpaceState::RayResult r; + bool intersected = get_world()->get_direct_space_state()->intersect_ray(get_global_transform().origin, get_global_transform().origin + motion, r, excluded_objects, mask); + if (intersected) { + float dist = get_global_transform().origin.distance_to(r.position); + dist -= margin; + motion_delta = dist / (spring_length); + } + } else { + motion = Vector3(cast_direction * spring_length); + get_world()->get_direct_space_state()->cast_motion(shape->get_rid(), get_global_transform(), motion, 0, motion_delta, motion_delta_unsafe, excluded_objects, mask); + } + + current_spring_length = spring_length * motion_delta; + Transform childs_transform; + childs_transform.origin = get_global_transform().origin + cast_direction * (spring_length * motion_delta); + + for (int i = get_child_count() - 1; 0 <= i; --i) { + + Spatial *child = Object::cast_to<Spatial>(get_child(i)); + if (child) { + childs_transform.basis = child->get_global_transform().basis; + child->set_global_transform(childs_transform); + } + } +} diff --git a/scene/3d/spring_arm.h b/scene/3d/spring_arm.h new file mode 100644 index 0000000000..24d912d371 --- /dev/null +++ b/scene/3d/spring_arm.h @@ -0,0 +1,71 @@ +/*************************************************************************/ +/* spring_arm.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef SPRING_ARM_H +#define SPRING_ARM_H + +#include "scene/3d/spatial.h" + +class SpringArm : public Spatial { + GDCLASS(SpringArm, Spatial); + + Ref<Shape> shape; + Set<RID> excluded_objects; + float spring_length; + bool keep_child_basis; + float current_spring_length; + uint32_t mask; + float margin; + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + void set_length(float p_length); + float get_length() const; + void set_shape(Ref<Shape> p_shape); + Ref<Shape> get_shape() const; + void set_mask(uint32_t p_mask); + uint32_t get_mask(); + void add_excluded_object(RID p_rid); + bool remove_excluded_object(RID p_rid); + void clear_excluded_objects(); + float get_hit_length(); + void set_margin(float p_margin); + float get_margin(); + + SpringArm(); + +private: + void process_spring(); +}; + +#endif diff --git a/scene/animation/animation_blend_space_1d.cpp b/scene/animation/animation_blend_space_1d.cpp index 1bc9fa4b12..289cf7a3a7 100644 --- a/scene/animation/animation_blend_space_1d.cpp +++ b/scene/animation/animation_blend_space_1d.cpp @@ -1,12 +1,14 @@ #include "animation_blend_space_1d.h" -void AnimationNodeBlendSpace1D::set_tree(AnimationTree *p_player) { - - AnimationRootNode::set_tree(p_player); +void AnimationNodeBlendSpace1D::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::REAL, blend_position)); +} +Variant AnimationNodeBlendSpace1D::get_parameter_default_value(const StringName &p_parameter) const { + return 0; +} - for (int i = 0; i < blend_points_used; i++) { - blend_points[i].node->set_tree(p_player); - } +Ref<AnimationNode> AnimationNodeBlendSpace1D::get_child_by_name(const StringName &p_name) { + return get_blend_point_node(p_name.operator String().to_int()); } void AnimationNodeBlendSpace1D::_validate_property(PropertyInfo &property) const { @@ -20,6 +22,10 @@ void AnimationNodeBlendSpace1D::_validate_property(PropertyInfo &property) const AnimationRootNode::_validate_property(property); } +void AnimationNodeBlendSpace1D::_tree_changed() { + emit_signal("tree_changed"); +} + void AnimationNodeBlendSpace1D::_bind_methods() { ClassDB::bind_method(D_METHOD("add_blend_point", "node", "pos", "at_index"), &AnimationNodeBlendSpace1D::add_blend_point, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("set_blend_point_position", "point", "pos"), &AnimationNodeBlendSpace1D::set_blend_point_position); @@ -38,30 +44,37 @@ void AnimationNodeBlendSpace1D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_snap", "snap"), &AnimationNodeBlendSpace1D::set_snap); ClassDB::bind_method(D_METHOD("get_snap"), &AnimationNodeBlendSpace1D::get_snap); - ClassDB::bind_method(D_METHOD("set_blend_pos", "pos"), &AnimationNodeBlendSpace1D::set_blend_pos); - ClassDB::bind_method(D_METHOD("get_blend_pos"), &AnimationNodeBlendSpace1D::get_blend_pos); - ClassDB::bind_method(D_METHOD("set_value_label", "text"), &AnimationNodeBlendSpace1D::set_value_label); ClassDB::bind_method(D_METHOD("get_value_label"), &AnimationNodeBlendSpace1D::get_value_label); ClassDB::bind_method(D_METHOD("_add_blend_point", "index", "node"), &AnimationNodeBlendSpace1D::_add_blend_point); + ClassDB::bind_method(D_METHOD("_tree_changed"), &AnimationNodeBlendSpace1D::_tree_changed); + for (int i = 0; i < MAX_BLEND_POINTS; i++) { - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "_add_blend_point", "get_blend_point_node", i); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_add_blend_point", "get_blend_point_node", i); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "blend_point_" + itos(i) + "/pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_blend_point_position", "get_blend_point_position", i); } ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_min_space", "get_min_space"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_max_space", "get_max_space"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "snap", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_snap", "get_snap"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "blend_pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_blend_pos", "get_blend_pos"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "value_label", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_value_label", "get_value_label"); } +void AnimationNodeBlendSpace1D::get_child_nodes(List<ChildNode> *r_child_nodes) { + for (int i = 0; i < blend_points_used; i++) { + ChildNode cn; + cn.name = itos(i); + cn.node = blend_points[i].node; + r_child_nodes->push_back(cn); + } +} + void AnimationNodeBlendSpace1D::add_blend_point(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index) { ERR_FAIL_COND(blend_points_used >= MAX_BLEND_POINTS); ERR_FAIL_COND(p_node.is_null()); - ERR_FAIL_COND(p_node->get_parent().is_valid()); + ERR_FAIL_COND(p_at_index < -1 || p_at_index > blend_points_used); if (p_at_index == -1 || p_at_index == blend_points_used) { @@ -75,10 +88,10 @@ void AnimationNodeBlendSpace1D::add_blend_point(const Ref<AnimationRootNode> &p_ blend_points[p_at_index].node = p_node; blend_points[p_at_index].position = p_position; - blend_points[p_at_index].node->set_parent(this); - blend_points[p_at_index].node->set_tree(get_tree()); + blend_points[p_at_index].node->connect("tree_changed", this, "_tree_changed", varray(), CONNECT_REFERENCE_COUNTED); blend_points_used++; + emit_signal("tree_changed"); } void AnimationNodeBlendSpace1D::set_blend_point_position(int p_point, float p_position) { @@ -92,13 +105,13 @@ void AnimationNodeBlendSpace1D::set_blend_point_node(int p_point, const Ref<Anim ERR_FAIL_COND(p_node.is_null()); if (blend_points[p_point].node.is_valid()) { - blend_points[p_point].node->set_parent(NULL); - blend_points[p_point].node->set_tree(NULL); + blend_points[p_point].node->disconnect("tree_changed", this, "_tree_changed"); } blend_points[p_point].node = p_node; - blend_points[p_point].node->set_parent(this); - blend_points[p_point].node->set_tree(get_tree()); + blend_points[p_point].node->connect("tree_changed", this, "_tree_changed", varray(), CONNECT_REFERENCE_COUNTED); + + emit_signal("tree_changed"); } float AnimationNodeBlendSpace1D::get_blend_point_position(int p_point) const { @@ -114,14 +127,14 @@ Ref<AnimationRootNode> AnimationNodeBlendSpace1D::get_blend_point_node(int p_poi void AnimationNodeBlendSpace1D::remove_blend_point(int p_point) { ERR_FAIL_INDEX(p_point, blend_points_used); - blend_points[p_point].node->set_parent(NULL); - blend_points[p_point].node->set_tree(NULL); + blend_points[p_point].node->disconnect("tree_changed", this, "_tree_changed"); for (int i = p_point; i < blend_points_used - 1; i++) { blend_points[i] = blend_points[i + 1]; } blend_points_used--; + emit_signal("tree_changed"); } int AnimationNodeBlendSpace1D::get_blend_point_count() const { @@ -161,14 +174,6 @@ float AnimationNodeBlendSpace1D::get_snap() const { return snap; } -void AnimationNodeBlendSpace1D::set_blend_pos(float p_pos) { - blend_pos = p_pos; -} - -float AnimationNodeBlendSpace1D::get_blend_pos() const { - return blend_pos; -} - void AnimationNodeBlendSpace1D::set_value_label(const String &p_label) { value_label = p_label; } @@ -193,9 +198,11 @@ float AnimationNodeBlendSpace1D::process(float p_time, bool p_seek) { if (blend_points_used == 1) { // only one point available, just play that animation - return blend_node(blend_points[0].node, p_time, p_seek, 1.0, FILTER_IGNORE, false); + return blend_node(blend_points[0].name, blend_points[0].node, p_time, p_seek, 1.0, FILTER_IGNORE, false); } + float blend_pos = get_parameter(blend_position); + float weights[MAX_BLEND_POINTS] = {}; int point_lower = -1; @@ -262,7 +269,7 @@ float AnimationNodeBlendSpace1D::process(float p_time, bool p_seek) { float max_time_remaining = 0.0; for (int i = 0; i < blend_points_used; i++) { - float remaining = blend_node(blend_points[i].node, p_time, p_seek, weights[i], FILTER_IGNORE, false); + float remaining = blend_node(blend_points[i].name, blend_points[i].node, p_time, p_seek, weights[i], FILTER_IGNORE, false); max_time_remaining = MAX(max_time_remaining, remaining); } @@ -276,18 +283,18 @@ String AnimationNodeBlendSpace1D::get_caption() const { AnimationNodeBlendSpace1D::AnimationNodeBlendSpace1D() { + for (int i = 0; i < MAX_BLEND_POINTS; i++) { + blend_points[i].name = itos(i); + } blend_points_used = 0; max_space = 1; min_space = -1; snap = 0.1; value_label = "value"; + + blend_position = "blend_position"; } AnimationNodeBlendSpace1D::~AnimationNodeBlendSpace1D() { - - for (int i = 0; i < blend_points_used; i++) { - blend_points[i].node->set_parent(this); - blend_points[i].node->set_tree(get_tree()); - } } diff --git a/scene/animation/animation_blend_space_1d.h b/scene/animation/animation_blend_space_1d.h index d1ed4c6a1f..f4e20f0d70 100644 --- a/scene/animation/animation_blend_space_1d.h +++ b/scene/animation/animation_blend_space_1d.h @@ -11,6 +11,7 @@ class AnimationNodeBlendSpace1D : public AnimationRootNode { }; struct BlendPoint { + StringName name; Ref<AnimationRootNode> node; float position; }; @@ -18,8 +19,6 @@ class AnimationNodeBlendSpace1D : public AnimationRootNode { BlendPoint blend_points[MAX_BLEND_POINTS]; int blend_points_used; - float blend_pos; - float max_space; float min_space; @@ -29,12 +28,19 @@ class AnimationNodeBlendSpace1D : public AnimationRootNode { void _add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node); + void _tree_changed(); + + StringName blend_position; + protected: virtual void _validate_property(PropertyInfo &property) const; static void _bind_methods(); public: - virtual void set_tree(AnimationTree *p_player); + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; + + virtual void get_child_nodes(List<ChildNode> *r_child_nodes); void add_blend_point(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index = -1); void set_blend_point_position(int p_point, float p_position); @@ -54,15 +60,14 @@ public: void set_snap(float p_snap); float get_snap() const; - void set_blend_pos(float p_pos); - float get_blend_pos() const; - void set_value_label(const String &p_label); String get_value_label() const; float process(float p_time, bool p_seek); String get_caption() const; + Ref<AnimationNode> get_child_by_name(const StringName &p_name); + AnimationNodeBlendSpace1D(); ~AnimationNodeBlendSpace1D(); }; diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp index 3c93a0c8ec..3dc7f2a86f 100644 --- a/scene/animation/animation_blend_space_2d.cpp +++ b/scene/animation/animation_blend_space_2d.cpp @@ -1,18 +1,25 @@ #include "animation_blend_space_2d.h" #include "math/delaunay.h" -void AnimationNodeBlendSpace2D::set_tree(AnimationTree *p_player) { - AnimationRootNode::set_tree(p_player); +void AnimationNodeBlendSpace2D::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::VECTOR2, blend_position)); +} +Variant AnimationNodeBlendSpace2D::get_parameter_default_value(const StringName &p_parameter) const { + return Vector2(); +} +void AnimationNodeBlendSpace2D::get_child_nodes(List<ChildNode> *r_child_nodes) { for (int i = 0; i < blend_points_used; i++) { - blend_points[i].node->set_tree(p_player); + ChildNode cn; + cn.name = itos(i); + cn.node = blend_points[i].node; + r_child_nodes->push_back(cn); } } void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index) { ERR_FAIL_COND(blend_points_used >= MAX_BLEND_POINTS); ERR_FAIL_COND(p_node.is_null()); - ERR_FAIL_COND(p_node->get_parent().is_valid()); ERR_FAIL_COND(p_at_index < -1 || p_at_index > blend_points_used); if (p_at_index == -1 || p_at_index == blend_points_used) { @@ -32,13 +39,13 @@ void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_ blend_points[p_at_index].node = p_node; blend_points[p_at_index].position = p_position; - blend_points[p_at_index].node->set_parent(this); - blend_points[p_at_index].node->set_tree(get_tree()); + blend_points[p_at_index].node->connect("tree_changed", this, "_tree_changed", varray(), CONNECT_REFERENCE_COUNTED); blend_points_used++; if (auto_triangles) { trianges_dirty = true; } + emit_signal("tree_changed"); } void AnimationNodeBlendSpace2D::set_blend_point_position(int p_point, const Vector2 &p_position) { @@ -53,12 +60,12 @@ void AnimationNodeBlendSpace2D::set_blend_point_node(int p_point, const Ref<Anim ERR_FAIL_COND(p_node.is_null()); if (blend_points[p_point].node.is_valid()) { - blend_points[p_point].node->set_parent(NULL); - blend_points[p_point].node->set_tree(NULL); + blend_points[p_point].node->disconnect("tree_changed", this, "_tree_changed"); } blend_points[p_point].node = p_node; - blend_points[p_point].node->set_parent(this); - blend_points[p_point].node->set_tree(get_tree()); + blend_points[p_point].node->connect("tree_changed", this, "_tree_changed", varray(), CONNECT_REFERENCE_COUNTED); + + emit_signal("tree_changed"); } Vector2 AnimationNodeBlendSpace2D::get_blend_point_position(int p_point) const { ERR_FAIL_INDEX_V(p_point, blend_points_used, Vector2()); @@ -71,8 +78,7 @@ Ref<AnimationRootNode> AnimationNodeBlendSpace2D::get_blend_point_node(int p_poi void AnimationNodeBlendSpace2D::remove_blend_point(int p_point) { ERR_FAIL_INDEX(p_point, blend_points_used); - blend_points[p_point].node->set_parent(NULL); - blend_points[p_point].node->set_tree(NULL); + blend_points[p_point].node->disconnect("tree_changed", this, "_tree_changed"); for (int i = 0; i < triangles.size(); i++) { bool erase = false; @@ -95,6 +101,7 @@ void AnimationNodeBlendSpace2D::remove_blend_point(int p_point) { blend_points[i] = blend_points[i + 1]; } blend_points_used--; + emit_signal("tree_changed"); } int AnimationNodeBlendSpace2D::get_blend_point_count() const { @@ -217,13 +224,6 @@ Vector2 AnimationNodeBlendSpace2D::get_snap() const { return snap; } -void AnimationNodeBlendSpace2D::set_blend_position(const Vector2 &p_pos) { - blend_pos = p_pos; -} -Vector2 AnimationNodeBlendSpace2D::get_blend_position() const { - return blend_pos; -} - void AnimationNodeBlendSpace2D::set_x_label(const String &p_label) { x_label = p_label; } @@ -381,6 +381,8 @@ float AnimationNodeBlendSpace2D::process(float p_time, bool p_seek) { _update_triangles(); + Vector2 blend_pos = get_parameter(blend_position); + if (triangles.size() == 0) return 0; @@ -443,7 +445,7 @@ float AnimationNodeBlendSpace2D::process(float p_time, bool p_seek) { for (int j = 0; j < 3; j++) { if (i == triangle_points[j]) { //blend with the given weight - float t = blend_node(blend_points[i].node, p_time, p_seek, blend_weights[j], FILTER_IGNORE, false); + float t = blend_node(blend_points[i].name, blend_points[i].node, p_time, p_seek, blend_weights[j], FILTER_IGNORE, false); if (first || t < mind) { mind = t; first = false; @@ -455,7 +457,7 @@ float AnimationNodeBlendSpace2D::process(float p_time, bool p_seek) { if (!found) { //ignore - blend_node(blend_points[i].node, p_time, p_seek, 0, FILTER_IGNORE, false); + blend_node(blend_points[i].name, blend_points[i].node, p_time, p_seek, 0, FILTER_IGNORE, false); } } return mind; @@ -487,6 +489,14 @@ bool AnimationNodeBlendSpace2D::get_auto_triangles() const { return auto_triangles; } +Ref<AnimationNode> AnimationNodeBlendSpace2D::get_child_by_name(const StringName &p_name) { + return get_blend_point_node(p_name.operator String().to_int()); +} + +void AnimationNodeBlendSpace2D::_tree_changed() { + emit_signal("tree_changed"); +} + void AnimationNodeBlendSpace2D::_bind_methods() { ClassDB::bind_method(D_METHOD("add_blend_point", "node", "pos", "at_index"), &AnimationNodeBlendSpace2D::add_blend_point, DEFVAL(-1)); @@ -511,9 +521,6 @@ void AnimationNodeBlendSpace2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_snap", "snap"), &AnimationNodeBlendSpace2D::set_snap); ClassDB::bind_method(D_METHOD("get_snap"), &AnimationNodeBlendSpace2D::get_snap); - ClassDB::bind_method(D_METHOD("set_blend_position", "pos"), &AnimationNodeBlendSpace2D::set_blend_position); - ClassDB::bind_method(D_METHOD("get_blend_position"), &AnimationNodeBlendSpace2D::get_blend_position); - ClassDB::bind_method(D_METHOD("set_x_label", "text"), &AnimationNodeBlendSpace2D::set_x_label); ClassDB::bind_method(D_METHOD("get_x_label"), &AnimationNodeBlendSpace2D::get_x_label); @@ -528,10 +535,12 @@ void AnimationNodeBlendSpace2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_auto_triangles", "enable"), &AnimationNodeBlendSpace2D::set_auto_triangles); ClassDB::bind_method(D_METHOD("get_auto_triangles"), &AnimationNodeBlendSpace2D::get_auto_triangles); + ClassDB::bind_method(D_METHOD("_tree_changed"), &AnimationNodeBlendSpace2D::_tree_changed); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_triangles", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_auto_triangles", "get_auto_triangles"); for (int i = 0; i < MAX_BLEND_POINTS; i++) { - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "_add_blend_point", "get_blend_point_node", i); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_add_blend_point", "get_blend_point_node", i); ADD_PROPERTYI(PropertyInfo(Variant::VECTOR2, "blend_point_" + itos(i) + "/pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_blend_point_position", "get_blend_point_position", i); } @@ -540,13 +549,15 @@ void AnimationNodeBlendSpace2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "min_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_min_space", "get_min_space"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "max_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_max_space", "get_max_space"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "snap", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_snap", "get_snap"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "blend_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_blend_position", "get_blend_position"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "x_label", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_x_label", "get_x_label"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "y_label", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_y_label", "get_y_label"); } AnimationNodeBlendSpace2D::AnimationNodeBlendSpace2D() { + for (int i = 0; i < MAX_BLEND_POINTS; i++) { + blend_points[i].name = itos(i); + } auto_triangles = true; blend_points_used = 0; max_space = Vector2(1, 1); @@ -555,12 +566,8 @@ AnimationNodeBlendSpace2D::AnimationNodeBlendSpace2D() { x_label = "x"; y_label = "y"; trianges_dirty = false; + blend_position = "blend_position"; } AnimationNodeBlendSpace2D::~AnimationNodeBlendSpace2D() { - - for (int i = 0; i < blend_points_used; i++) { - blend_points[i].node->set_parent(this); - blend_points[i].node->set_tree(get_tree()); - } } diff --git a/scene/animation/animation_blend_space_2d.h b/scene/animation/animation_blend_space_2d.h index 74d20b6013..3e1c66c924 100644 --- a/scene/animation/animation_blend_space_2d.h +++ b/scene/animation/animation_blend_space_2d.h @@ -11,6 +11,7 @@ class AnimationNodeBlendSpace2D : public AnimationRootNode { }; struct BlendPoint { + StringName name; Ref<AnimationRootNode> node; Vector2 position; }; @@ -24,7 +25,7 @@ class AnimationNodeBlendSpace2D : public AnimationRootNode { Vector<BlendTriangle> triangles; - Vector2 blend_pos; + StringName blend_position; Vector2 max_space; Vector2 min_space; Vector2 snap; @@ -42,12 +43,17 @@ class AnimationNodeBlendSpace2D : public AnimationRootNode { void _update_triangles(); + void _tree_changed(); + protected: virtual void _validate_property(PropertyInfo &property) const; static void _bind_methods(); public: - virtual void set_tree(AnimationTree *p_player); + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; + + virtual void get_child_nodes(List<ChildNode> *r_child_nodes); void add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index = -1); void set_blend_point_position(int p_point, const Vector2 &p_position); @@ -72,9 +78,6 @@ public: void set_snap(const Vector2 &p_snap); Vector2 get_snap() const; - void set_blend_position(const Vector2 &p_pos); - Vector2 get_blend_position() const; - void set_x_label(const String &p_label); String get_x_label() const; @@ -89,6 +92,8 @@ public: void set_auto_triangles(bool p_enable); bool get_auto_triangles() const; + virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name); + AnimationNodeBlendSpace2D(); ~AnimationNodeBlendSpace2D(); }; diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 65904410d3..66a9c5babd 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -3,6 +3,7 @@ void AnimationNodeAnimation::set_animation(const StringName &p_name) { animation = p_name; + _change_notify("animation"); } StringName AnimationNodeAnimation::get_animation() const { @@ -13,43 +14,36 @@ float AnimationNodeAnimation::get_playback_time() const { return time; } +Vector<String> (*AnimationNodeAnimation::get_editable_animation_list)() = NULL; + void AnimationNodeAnimation::_validate_property(PropertyInfo &property) const { - if (property.name == "animation") { - AnimationTree *gp = get_tree(); - if (gp && gp->has_node(gp->get_animation_player())) { - AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player())); - if (ap) { - List<StringName> names; - ap->get_animation_list(&names); - String anims; - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (E != names.front()) { - anims += ","; - } - anims += String(E->get()); - } - if (anims != String()) { - property.hint = PROPERTY_HINT_ENUM; - property.hint_string = anims; - } + if (property.name == "animation" && get_editable_animation_list) { + Vector<String> names = get_editable_animation_list(); + String anims; + for (int i = 0; i < names.size(); i++) { + + if (i > 0) { + anims += ","; } + anims += String(names[i]); + } + if (anims != String()) { + property.hint = PROPERTY_HINT_ENUM; + property.hint_string = anims; } } - - AnimationRootNode::_validate_property(property); } float AnimationNodeAnimation::process(float p_time, bool p_seek) { - AnimationPlayer *ap = get_player(); + AnimationPlayer *ap = state->player; ERR_FAIL_COND_V(!ap, 0); - Ref<Animation> anim = ap->get_animation(animation); - if (!anim.is_valid()) { + if (!ap->has_animation(animation)) { - Ref<AnimationNodeBlendTree> tree = get_parent(); - if (tree.is_valid()) { + AnimationNodeBlendTree *tree = Object::cast_to<AnimationNodeBlendTree>(parent); + if (tree) { String name = tree->get_node_name(Ref<AnimationNodeAnimation>(this)); make_invalid(vformat(RTR("On BlendTree node '%s', animation not found: '%s'"), name, animation)); @@ -60,6 +54,8 @@ float AnimationNodeAnimation::process(float p_time, bool p_seek) { return 0; } + Ref<Animation> anim = ap->get_animation(animation); + if (p_seek) { time = p_time; step = 0; @@ -108,6 +104,20 @@ AnimationNodeAnimation::AnimationNodeAnimation() { //////////////////////////////////////////////////////// +void AnimationNodeOneShot::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::BOOL, active)); + r_list->push_back(PropertyInfo(Variant::BOOL, prev_active, PROPERTY_HINT_NONE, "", 0)); + r_list->push_back(PropertyInfo(Variant::REAL, time, PROPERTY_HINT_NONE, "", 0)); + r_list->push_back(PropertyInfo(Variant::REAL, remaining, PROPERTY_HINT_NONE, "", 0)); +} +Variant AnimationNodeOneShot::get_parameter_default_value(const StringName &p_parameter) const { + if (p_parameter == active || p_parameter == prev_active) { + return false; + } else { + return 0.0; + } +} + void AnimationNodeOneShot::set_fadein_time(float p_time) { fade_in = p_time; @@ -162,18 +172,6 @@ AnimationNodeOneShot::MixMode AnimationNodeOneShot::get_mix_mode() const { return mix; } -void AnimationNodeOneShot::start() { - active = true; - do_start = true; -} -void AnimationNodeOneShot::stop() { - active = false; -} -bool AnimationNodeOneShot::is_active() const { - - return active; -} - String AnimationNodeOneShot::get_caption() const { return "OneShot"; } @@ -184,8 +182,16 @@ bool AnimationNodeOneShot::has_filter() const { float AnimationNodeOneShot::process(float p_time, bool p_seek) { + bool active = get_parameter(this->active); + bool prev_active = get_parameter(this->prev_active); + float time = get_parameter(this->time); + float remaining = get_parameter(this->remaining); + if (!active) { //make it as if this node doesn't exist, pass input 0 by. + if (prev_active) { + set_parameter(this->prev_active, false); + } return blend_input(0, p_time, p_seek, 1.0, FILTER_IGNORE, !sync); } @@ -193,9 +199,12 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) { if (p_seek) time = p_time; + bool do_start = !prev_active; + if (do_start) { time = 0; os_seek = true; + set_parameter(this->prev_active, true); } float blend; @@ -233,10 +242,15 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) { if (!p_seek) { time += p_time; remaining = os_rem; - if (remaining <= 0) - active = false; + if (remaining <= 0) { + set_parameter(this->active, false); + set_parameter(this->prev_active, false); + } } + set_parameter(this->time, time); + set_parameter(this->remaining, remaining); + return MAX(main_rem, remaining); } void AnimationNodeOneShot::set_use_sync(bool p_sync) { @@ -269,10 +283,6 @@ void AnimationNodeOneShot::_bind_methods() { ClassDB::bind_method(D_METHOD("set_mix_mode", "mode"), &AnimationNodeOneShot::set_mix_mode); ClassDB::bind_method(D_METHOD("get_mix_mode"), &AnimationNodeOneShot::get_mix_mode); - ClassDB::bind_method(D_METHOD("start"), &AnimationNodeOneShot::start); - ClassDB::bind_method(D_METHOD("stop"), &AnimationNodeOneShot::stop); - ClassDB::bind_method(D_METHOD("is_active"), &AnimationNodeOneShot::is_active); - ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationNodeOneShot::set_use_sync); ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeOneShot::is_using_sync); @@ -297,26 +307,27 @@ AnimationNodeOneShot::AnimationNodeOneShot() { add_input("in"); add_input("shot"); - time = 0; fade_in = 0.1; fade_out = 0.1; autorestart = false; autorestart_delay = 1; - autorestart_remaining = 0; + mix = MIX_MODE_BLEND; - active = false; - do_start = false; sync = false; + + active = "active"; + prev_active = "prev_active"; + time = "time"; + remaining = "remaining"; } //////////////////////////////////////////////// -void AnimationNodeAdd2::set_amount(float p_amount) { - amount = p_amount; +void AnimationNodeAdd2::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::REAL, add_amount, PROPERTY_HINT_RANGE, "0,1,0.01")); } - -float AnimationNodeAdd2::get_amount() const { - return amount; +Variant AnimationNodeAdd2::get_parameter_default_value(const StringName &p_parameter) const { + return 0; } String AnimationNodeAdd2::get_caption() const { @@ -339,6 +350,7 @@ bool AnimationNodeAdd2::has_filter() const { float AnimationNodeAdd2::process(float p_time, bool p_seek) { + float amount = get_parameter(add_amount); float rem0 = blend_input(0, p_time, p_seek, 1.0, FILTER_IGNORE, !sync); blend_input(1, p_time, p_seek, amount, FILTER_PASS, !sync); @@ -347,32 +359,27 @@ float AnimationNodeAdd2::process(float p_time, bool p_seek) { void AnimationNodeAdd2::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_amount", "amount"), &AnimationNodeAdd2::set_amount); - ClassDB::bind_method(D_METHOD("get_amount"), &AnimationNodeAdd2::get_amount); - ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationNodeAdd2::set_use_sync); ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeAdd2::is_using_sync); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_amount", "get_amount"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync"), "set_use_sync", "is_using_sync"); } AnimationNodeAdd2::AnimationNodeAdd2() { + add_amount = "add_amount"; add_input("in"); add_input("add"); - amount = 0; sync = false; } //////////////////////////////////////////////// -void AnimationNodeAdd3::set_amount(float p_amount) { - amount = p_amount; +void AnimationNodeAdd3::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::REAL, add_amount, PROPERTY_HINT_RANGE, "-1,1,0.01")); } - -float AnimationNodeAdd3::get_amount() const { - return amount; +Variant AnimationNodeAdd3::get_parameter_default_value(const StringName &p_parameter) const { + return 0; } String AnimationNodeAdd3::get_caption() const { @@ -395,6 +402,7 @@ bool AnimationNodeAdd3::has_filter() const { float AnimationNodeAdd3::process(float p_time, bool p_seek) { + float amount = get_parameter(add_amount); blend_input(0, p_time, p_seek, MAX(0, -amount), FILTER_PASS, !sync); float rem0 = blend_input(1, p_time, p_seek, 1.0, FILTER_IGNORE, !sync); blend_input(2, p_time, p_seek, MAX(0, amount), FILTER_PASS, !sync); @@ -404,39 +412,37 @@ float AnimationNodeAdd3::process(float p_time, bool p_seek) { void AnimationNodeAdd3::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_amount", "amount"), &AnimationNodeAdd3::set_amount); - ClassDB::bind_method(D_METHOD("get_amount"), &AnimationNodeAdd3::get_amount); - ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationNodeAdd3::set_use_sync); ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeAdd3::is_using_sync); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_amount", "get_amount"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync"), "set_use_sync", "is_using_sync"); } AnimationNodeAdd3::AnimationNodeAdd3() { + add_amount = "add_amount"; add_input("-add"); add_input("in"); add_input("+add"); - amount = 0; sync = false; } ///////////////////////////////////////////// -void AnimationNodeBlend2::set_amount(float p_amount) { - amount = p_amount; +void AnimationNodeBlend2::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::REAL, blend_amount, PROPERTY_HINT_RANGE, "0,1,0.01")); } - -float AnimationNodeBlend2::get_amount() const { - return amount; +Variant AnimationNodeBlend2::get_parameter_default_value(const StringName &p_parameter) const { + return 0; //for blend amount } + String AnimationNodeBlend2::get_caption() const { return "Blend2"; } float AnimationNodeBlend2::process(float p_time, bool p_seek) { + float amount = get_parameter(blend_amount); + float rem0 = blend_input(0, p_time, p_seek, 1.0 - amount, FILTER_BLEND, !sync); float rem1 = blend_input(1, p_time, p_seek, amount, FILTER_PASS, !sync); @@ -459,31 +465,25 @@ bool AnimationNodeBlend2::has_filter() const { } void AnimationNodeBlend2::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_amount", "amount"), &AnimationNodeBlend2::set_amount); - ClassDB::bind_method(D_METHOD("get_amount"), &AnimationNodeBlend2::get_amount); - ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationNodeBlend2::set_use_sync); ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeBlend2::is_using_sync); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_amount", "get_amount"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync"), "set_use_sync", "is_using_sync"); } AnimationNodeBlend2::AnimationNodeBlend2() { + blend_amount = "blend_amount"; add_input("in"); add_input("blend"); sync = false; - - amount = 0; } ////////////////////////////////////// -void AnimationNodeBlend3::set_amount(float p_amount) { - amount = p_amount; +void AnimationNodeBlend3::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::REAL, blend_amount, PROPERTY_HINT_RANGE, "-1,1,0.01")); } - -float AnimationNodeBlend3::get_amount() const { - return amount; +Variant AnimationNodeBlend3::get_parameter_default_value(const StringName &p_parameter) const { + return 0; //for blend amount } String AnimationNodeBlend3::get_caption() const { @@ -502,6 +502,7 @@ bool AnimationNodeBlend3::is_using_sync() const { float AnimationNodeBlend3::process(float p_time, bool p_seek) { + float amount = get_parameter(blend_amount); float rem0 = blend_input(0, p_time, p_seek, MAX(0, -amount), FILTER_IGNORE, !sync); float rem1 = blend_input(1, p_time, p_seek, 1.0 - ABS(amount), FILTER_IGNORE, !sync); float rem2 = blend_input(2, p_time, p_seek, MAX(0, amount), FILTER_IGNORE, !sync); @@ -511,31 +512,26 @@ float AnimationNodeBlend3::process(float p_time, bool p_seek) { void AnimationNodeBlend3::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_amount", "amount"), &AnimationNodeBlend3::set_amount); - ClassDB::bind_method(D_METHOD("get_amount"), &AnimationNodeBlend3::get_amount); - ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationNodeBlend3::set_use_sync); ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeBlend3::is_using_sync); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_amount", "get_amount"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync"), "set_use_sync", "is_using_sync"); } AnimationNodeBlend3::AnimationNodeBlend3() { + blend_amount = "blend_amount"; add_input("-blend"); add_input("in"); add_input("+blend"); sync = false; - amount = 0; } ///////////////////////////////// -void AnimationNodeTimeScale::set_scale(float p_scale) { - scale = p_scale; +void AnimationNodeTimeScale::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::REAL, scale, PROPERTY_HINT_RANGE, "0,32,0.01,or_greater")); } - -float AnimationNodeTimeScale::get_scale() const { - return scale; +Variant AnimationNodeTimeScale::get_parameter_default_value(const StringName &p_parameter) const { + return 1.0; //initial timescale } String AnimationNodeTimeScale::get_caption() const { @@ -544,6 +540,7 @@ String AnimationNodeTimeScale::get_caption() const { float AnimationNodeTimeScale::process(float p_time, bool p_seek) { + float scale = get_parameter(this->scale); if (p_seek) { return blend_input(0, p_time, true, 1.0, FILTER_IGNORE, false); } else { @@ -552,25 +549,19 @@ float AnimationNodeTimeScale::process(float p_time, bool p_seek) { } void AnimationNodeTimeScale::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_scale", "scale"), &AnimationNodeTimeScale::set_scale); - ClassDB::bind_method(D_METHOD("get_scale"), &AnimationNodeTimeScale::get_scale); - - ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale", PROPERTY_HINT_RANGE, "0,32,0.01,or_greater"), "set_scale", "get_scale"); } AnimationNodeTimeScale::AnimationNodeTimeScale() { + scale = "scale"; add_input("in"); - scale = 1.0; } //////////////////////////////////// -void AnimationNodeTimeSeek::set_seek_pos(float p_seek_pos) { - seek_pos = p_seek_pos; +void AnimationNodeTimeSeek::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::REAL, seek_pos, PROPERTY_HINT_RANGE, "-1,3600,0.01,or_greater")); } - -float AnimationNodeTimeSeek::get_seek_pos() const { - return seek_pos; +Variant AnimationNodeTimeSeek::get_parameter_default_value(const StringName &p_parameter) const { + return 1.0; //initial timescale } String AnimationNodeTimeSeek::get_caption() const { @@ -579,11 +570,12 @@ String AnimationNodeTimeSeek::get_caption() const { float AnimationNodeTimeSeek::process(float p_time, bool p_seek) { + float seek_pos = get_parameter(this->seek_pos); if (p_seek) { return blend_input(0, p_time, true, 1.0, FILTER_IGNORE, false); } else if (seek_pos >= 0) { float ret = blend_input(0, seek_pos, true, 1.0, FILTER_IGNORE, false); - seek_pos = -1; + set_parameter(this->seek_pos, -1.0); //reset _change_notify("seek_pos"); return ret; } else { @@ -592,19 +584,41 @@ float AnimationNodeTimeSeek::process(float p_time, bool p_seek) { } void AnimationNodeTimeSeek::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_seek_pos", "seek_pos"), &AnimationNodeTimeSeek::set_seek_pos); - ClassDB::bind_method(D_METHOD("get_seek_pos"), &AnimationNodeTimeSeek::get_seek_pos); - - ADD_PROPERTY(PropertyInfo(Variant::REAL, "seek_pos", PROPERTY_HINT_RANGE, "-1,3600,0.01,or_greater"), "set_seek_pos", "get_seek_pos"); } + AnimationNodeTimeSeek::AnimationNodeTimeSeek() { add_input("in"); - seek_pos = -1; + seek_pos = "seek_position"; } ///////////////////////////////////////////////// +void AnimationNodeTransition::get_parameter_list(List<PropertyInfo> *r_list) const { + + String anims; + for (int i = 0; i < enabled_inputs; i++) { + if (i > 0) { + anims += ","; + } + anims += inputs[i].name; + } + + r_list->push_back(PropertyInfo(Variant::INT, current, PROPERTY_HINT_ENUM, anims)); + r_list->push_back(PropertyInfo(Variant::INT, prev_current, PROPERTY_HINT_NONE, "", 0)); + r_list->push_back(PropertyInfo(Variant::INT, prev, PROPERTY_HINT_NONE, "", 0)); + r_list->push_back(PropertyInfo(Variant::REAL, time, PROPERTY_HINT_NONE, "", 0)); + r_list->push_back(PropertyInfo(Variant::REAL, prev_xfading, PROPERTY_HINT_NONE, "", 0)); +} +Variant AnimationNodeTransition::get_parameter_default_value(const StringName &p_parameter) const { + if (p_parameter == time || p_parameter == prev_xfading) { + return 0.0; + } else if (p_parameter == prev || p_parameter == prev_current) { + return -1; + } else { + return 0; + } +} + String AnimationNodeTransition::get_caption() const { return "Transition"; } @@ -650,18 +664,12 @@ String AnimationNodeTransition::get_input_caption(int p_input) const { return inputs[p_input].name; } -void AnimationNodeTransition::set_current(int p_current) { - - if (current == p_current) - return; - ERR_FAIL_INDEX(p_current, enabled_inputs); - +#if 0 Ref<AnimationNodeBlendTree> tree = get_parent(); if (tree.is_valid() && current >= 0) { prev = current; - prev_xfading = xfade; - prev_time = time; + prev_xfading = xfade; time = 0; current = p_current; switched = true; @@ -669,11 +677,8 @@ void AnimationNodeTransition::set_current(int p_current) { } else { current = p_current; } -} +#endif -int AnimationNodeTransition::get_current() const { - return current; -} void AnimationNodeTransition::set_cross_fade_time(float p_fade) { xfade = p_fade; } @@ -684,9 +689,34 @@ float AnimationNodeTransition::get_cross_fade_time() const { float AnimationNodeTransition::process(float p_time, bool p_seek) { + int current = get_parameter(this->current); + int prev = get_parameter(this->prev); + int prev_current = get_parameter(this->prev_current); + + float time = get_parameter(this->time); + float prev_xfading = get_parameter(this->prev_xfading); + + bool switched = current != prev_current; + + if (switched) { + set_parameter(this->prev_current, current); + set_parameter(this->prev, prev_current); + + prev = prev_current; + prev_xfading = xfade; + time = 0; + switched = true; + } + + if (current < 0 || current >= enabled_inputs || prev >= enabled_inputs) { + return 0; + } + + float rem = 0; + if (prev < 0) { // process current animation, check for transition - float rem = blend_input(current, p_time, p_seek, 1.0, FILTER_IGNORE, false); + rem = blend_input(current, p_time, p_seek, 1.0, FILTER_IGNORE, false); if (p_seek) time = p_time; @@ -695,16 +725,13 @@ float AnimationNodeTransition::process(float p_time, bool p_seek) { if (inputs[current].auto_advance && rem <= xfade) { - set_current((current + 1) % enabled_inputs); + set_parameter(this->current, (current + 1) % enabled_inputs); } - return rem; } else { // cross-fading from prev to current float blend = xfade ? (prev_xfading / xfade) : 1; - float rem; - if (!p_seek && switched) { //just switched, seek to start of current rem = blend_input(current, 0, true, 1.0 - blend, FILTER_IGNORE, false); @@ -723,28 +750,19 @@ float AnimationNodeTransition::process(float p_time, bool p_seek) { time += p_time; prev_xfading -= p_time; if (prev_xfading < 0) { - prev = -1; + set_parameter(this->prev, -1); } } - - return rem; } + + set_parameter(this->time, time); + set_parameter(this->prev_xfading, prev_xfading); + + return rem; } void AnimationNodeTransition::_validate_property(PropertyInfo &property) const { - if (property.name == "current" && enabled_inputs > 0) { - property.hint = PROPERTY_HINT_ENUM; - String anims; - for (int i = 0; i < enabled_inputs; i++) { - if (i > 0) { - anims += ","; - } - anims += inputs[i].name; - } - property.hint_string = anims; - } - if (property.name.begins_with("input_")) { String n = property.name.get_slicec('/', 0).get_slicec('_', 1); if (n != "count") { @@ -769,14 +787,10 @@ void AnimationNodeTransition::_bind_methods() { ClassDB::bind_method(D_METHOD("set_input_caption", "input", "caption"), &AnimationNodeTransition::set_input_caption); ClassDB::bind_method(D_METHOD("get_input_caption", "input"), &AnimationNodeTransition::get_input_caption); - ClassDB::bind_method(D_METHOD("set_current", "index"), &AnimationNodeTransition::set_current); - ClassDB::bind_method(D_METHOD("get_current"), &AnimationNodeTransition::get_current); - ClassDB::bind_method(D_METHOD("set_cross_fade_time", "time"), &AnimationNodeTransition::set_cross_fade_time); ClassDB::bind_method(D_METHOD("get_cross_fade_time"), &AnimationNodeTransition::get_cross_fade_time); ADD_PROPERTY(PropertyInfo(Variant::INT, "input_count", PROPERTY_HINT_RANGE, "0,64,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_enabled_inputs", "get_enabled_inputs"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "current", PROPERTY_HINT_RANGE, "0,64,1"), "set_current", "get_current"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "xfade_time", PROPERTY_HINT_RANGE, "0,120,0.01"), "set_cross_fade_time", "get_cross_fade_time"); for (int i = 0; i < MAX_INPUTS; i++) { @@ -786,13 +800,15 @@ void AnimationNodeTransition::_bind_methods() { } AnimationNodeTransition::AnimationNodeTransition() { + + prev_xfading = "prev_xfading"; + prev = "prev"; + time = "time"; + current = "current"; + prev_current = "prev_current"; + ; + enabled_inputs = 0; - xfade = 0; - current = -1; - prev = -1; - prev_time = 0; - prev_xfading = 0; - switched = false; for (int i = 0; i < MAX_INPUTS; i++) { inputs[i].auto_advance = false; inputs[i].name = itos(i + 1); @@ -814,69 +830,102 @@ AnimationNodeOutput::AnimationNodeOutput() { } /////////////////////////////////////////////////////// -void AnimationNodeBlendTree::add_node(const StringName &p_name, Ref<AnimationNode> p_node) { +void AnimationNodeBlendTree::add_node(const StringName &p_name, Ref<AnimationNode> p_node, const Vector2 &p_position) { ERR_FAIL_COND(nodes.has(p_name)); ERR_FAIL_COND(p_node.is_null()); - ERR_FAIL_COND(p_node->get_parent().is_valid()); - ERR_FAIL_COND(p_node->get_tree() != NULL); ERR_FAIL_COND(p_name == SceneStringNames::get_singleton()->output); ERR_FAIL_COND(String(p_name).find("/") != -1); - nodes[p_name] = p_node; - p_node->set_parent(this); - p_node->set_tree(get_tree()); + Node n; + n.node = p_node; + n.position = p_position; + n.connections.resize(n.node->get_input_count()); + nodes[p_name] = n; emit_changed(); + emit_signal("tree_changed"); + + p_node->connect("tree_changed", this, "_tree_changed", varray(), CONNECT_REFERENCE_COUNTED); + p_node->connect("changed", this, "_node_changed", varray(p_name), CONNECT_REFERENCE_COUNTED); } Ref<AnimationNode> AnimationNodeBlendTree::get_node(const StringName &p_name) const { ERR_FAIL_COND_V(!nodes.has(p_name), Ref<AnimationNode>()); - return nodes[p_name]; + return nodes[p_name].node; } StringName AnimationNodeBlendTree::get_node_name(const Ref<AnimationNode> &p_node) const { - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { - if (E->get() == p_node) { + for (Map<StringName, Node>::Element *E = nodes.front(); E; E = E->next()) { + if (E->get().node == p_node) { return E->key(); } } ERR_FAIL_V(StringName()); } + +void AnimationNodeBlendTree::set_node_position(const StringName &p_node, const Vector2 &p_position) { + ERR_FAIL_COND(!nodes.has(p_node)); + nodes[p_node].position = p_position; +} + +Vector2 AnimationNodeBlendTree::get_node_position(const StringName &p_node) const { + ERR_FAIL_COND_V(!nodes.has(p_node), Vector2()); + return nodes[p_node].position; +} + +void AnimationNodeBlendTree::get_child_nodes(List<ChildNode> *r_child_nodes) { + Vector<StringName> ns; + + for (Map<StringName, Node>::Element *E = nodes.front(); E; E = E->next()) { + ns.push_back(E->key()); + } + + ns.sort_custom<StringName::AlphCompare>(); + + for (int i = 0; i < ns.size(); i++) { + ChildNode cn; + cn.name = ns[i]; + cn.node = nodes[cn.name].node; + r_child_nodes->push_back(cn); + } +} + bool AnimationNodeBlendTree::has_node(const StringName &p_name) const { return nodes.has(p_name); } +Vector<StringName> AnimationNodeBlendTree::get_node_connection_array(const StringName &p_name) const { + + ERR_FAIL_COND_V(!nodes.has(p_name), Vector<StringName>()); + return nodes[p_name].connections; +} void AnimationNodeBlendTree::remove_node(const StringName &p_name) { ERR_FAIL_COND(!nodes.has(p_name)); ERR_FAIL_COND(p_name == SceneStringNames::get_singleton()->output); //can't delete output { - //erase node connections - Ref<AnimationNode> node = nodes[p_name]; - for (int i = 0; i < node->get_input_count(); i++) { - node->set_input_connection(i, StringName()); - } - node->set_parent(NULL); - node->set_tree(NULL); + Ref<AnimationNode> node = nodes[p_name].node; + node->disconnect("tree_changed", this, "_tree_changed"); + node->disconnect("changed", this, "_node_changed"); } nodes.erase(p_name); //erase connections to name - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { - Ref<AnimationNode> node = E->get(); - for (int i = 0; i < node->get_input_count(); i++) { - if (node->get_input_connection(i) == p_name) { - node->set_input_connection(i, StringName()); + for (Map<StringName, Node>::Element *E = nodes.front(); E; E = E->next()) { + for (int i = 0; i < E->get().connections.size(); i++) { + if (E->get().connections[i] == p_name) { + E->get().connections.write[i] = StringName(); } } } emit_changed(); + emit_signal("tree_changed"); } void AnimationNodeBlendTree::rename_node(const StringName &p_name, const StringName &p_new_name) { @@ -886,18 +935,24 @@ void AnimationNodeBlendTree::rename_node(const StringName &p_name, const StringN ERR_FAIL_COND(p_name == SceneStringNames::get_singleton()->output); ERR_FAIL_COND(p_new_name == SceneStringNames::get_singleton()->output); + nodes[p_name].node->disconnect("changed", this, "_node_changed"); + nodes[p_new_name] = nodes[p_name]; nodes.erase(p_name); //rename connections - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { - Ref<AnimationNode> node = E->get(); - for (int i = 0; i < node->get_input_count(); i++) { - if (node->get_input_connection(i) == p_name) { - node->set_input_connection(i, p_new_name); + for (Map<StringName, Node>::Element *E = nodes.front(); E; E = E->next()) { + + for (int i = 0; i < E->get().connections.size(); i++) { + if (E->get().connections[i] == p_name) { + E->get().connections.write[i] = p_new_name; } } } + //connection must be done with new name + nodes[p_new_name].node->connect("changed", this, "_node_changed", varray(p_new_name), CONNECT_REFERENCE_COUNTED); + + emit_signal("tree_changed"); } void AnimationNodeBlendTree::connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node) { @@ -907,18 +962,18 @@ void AnimationNodeBlendTree::connect_node(const StringName &p_input_node, int p_ ERR_FAIL_COND(p_output_node == SceneStringNames::get_singleton()->output); ERR_FAIL_COND(p_input_node == p_output_node); - Ref<AnimationNode> input = nodes[p_input_node]; - ERR_FAIL_INDEX(p_input_index, input->get_input_count()); + Ref<AnimationNode> input = nodes[p_input_node].node; + ERR_FAIL_INDEX(p_input_index, nodes[p_input_node].connections.size()); - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { - Ref<AnimationNode> node = E->get(); - for (int i = 0; i < node->get_input_count(); i++) { - StringName output = node->get_input_connection(i); + for (Map<StringName, Node>::Element *E = nodes.front(); E; E = E->next()) { + for (int i = 0; i < E->get().connections.size(); i++) { + StringName output = E->get().connections[i]; ERR_FAIL_COND(output == p_output_node); } } - input->set_input_connection(p_input_index, p_output_node); + nodes[p_input_node].connections.write[p_input_index] = p_output_node; + emit_changed(); } @@ -926,20 +981,21 @@ void AnimationNodeBlendTree::disconnect_node(const StringName &p_node, int p_inp ERR_FAIL_COND(!nodes.has(p_node)); - Ref<AnimationNode> input = nodes[p_node]; - ERR_FAIL_INDEX(p_input_index, input->get_input_count()); + Ref<AnimationNode> input = nodes[p_node].node; + ERR_FAIL_INDEX(p_input_index, nodes[p_node].connections.size()); - input->set_input_connection(p_input_index, StringName()); + nodes[p_node].connections.write[p_input_index] = StringName(); } float AnimationNodeBlendTree::get_connection_activity(const StringName &p_input_node, int p_input_index) const { ERR_FAIL_COND_V(!nodes.has(p_input_node), 0); - Ref<AnimationNode> input = nodes[p_input_node]; - ERR_FAIL_INDEX_V(p_input_index, input->get_input_count(), 0); + Ref<AnimationNode> input = nodes[p_input_node].node; + ERR_FAIL_INDEX_V(p_input_index, nodes[p_input_node].connections.size(), 0); - return input->get_input_activity(p_input_index); + //return input->get_input_activity(p_input_index); + return 0; } AnimationNodeBlendTree::ConnectionError AnimationNodeBlendTree::can_connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node) const { @@ -956,20 +1012,19 @@ AnimationNodeBlendTree::ConnectionError AnimationNodeBlendTree::can_connect_node return CONNECTION_ERROR_SAME_NODE; } - Ref<AnimationNode> input = nodes[p_input_node]; + Ref<AnimationNode> input = nodes[p_input_node].node; - if (p_input_index < 0 || p_input_index >= input->get_input_count()) { + if (p_input_index < 0 || p_input_index >= nodes[p_input_node].connections.size()) { return CONNECTION_ERROR_NO_INPUT_INDEX; } - if (input->get_input_connection(p_input_index) != StringName()) { + if (nodes[p_input_node].connections[p_input_index] != StringName()) { return CONNECTION_ERROR_CONNECTION_EXISTS; } - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { - Ref<AnimationNode> node = E->get(); - for (int i = 0; i < node->get_input_count(); i++) { - StringName output = node->get_input_connection(i); + for (Map<StringName, Node>::Element *E = nodes.front(); E; E = E->next()) { + for (int i = 0; i < E->get().connections.size(); i++) { + StringName output = E->get().connections[i]; if (output == p_output_node) { return CONNECTION_ERROR_CONNECTION_EXISTS; } @@ -980,10 +1035,9 @@ AnimationNodeBlendTree::ConnectionError AnimationNodeBlendTree::can_connect_node void AnimationNodeBlendTree::get_node_connections(List<NodeConnection> *r_connections) const { - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { - Ref<AnimationNode> node = E->get(); - for (int i = 0; i < node->get_input_count(); i++) { - StringName output = node->get_input_connection(i); + for (Map<StringName, Node>::Element *E = nodes.front(); E; E = E->next()) { + for (int i = 0; i < E->get().connections.size(); i++) { + StringName output = E->get().connections[i]; if (output != StringName()) { NodeConnection nc; nc.input_node = E->key(); @@ -1001,13 +1055,13 @@ String AnimationNodeBlendTree::get_caption() const { float AnimationNodeBlendTree::process(float p_time, bool p_seek) { - Ref<AnimationNodeOutput> output = nodes[SceneStringNames::get_singleton()->output]; - return blend_node(output, p_time, p_seek, 1.0); + Ref<AnimationNodeOutput> output = nodes[SceneStringNames::get_singleton()->output].node; + return _blend_node("output", nodes[SceneStringNames::get_singleton()->output].connections, this, output, p_time, p_seek, 1.0); } void AnimationNodeBlendTree::get_node_list(List<StringName> *r_list) { - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { + for (Map<StringName, Node>::Element *E = nodes.front(); E; E = E->next()) { r_list->push_back(E->key()); } } @@ -1022,14 +1076,8 @@ Vector2 AnimationNodeBlendTree::get_graph_offset() const { return graph_offset; } -void AnimationNodeBlendTree::set_tree(AnimationTree *p_player) { - - AnimationNode::set_tree(p_player); - - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { - Ref<AnimationNode> node = E->get(); - node->set_tree(p_player); - } +Ref<AnimationNode> AnimationNodeBlendTree::get_child_by_name(const StringName &p_name) { + return get_node(p_name); } bool AnimationNodeBlendTree::_set(const StringName &p_name, const Variant &p_value) { @@ -1051,7 +1099,7 @@ bool AnimationNodeBlendTree::_set(const StringName &p_name, const Variant &p_val if (what == "position") { if (nodes.has(node_name)) { - nodes[node_name]->set_position(p_value); + nodes[node_name].position = p_value; } return true; } @@ -1078,7 +1126,7 @@ bool AnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_ret) cons if (what == "node") { if (nodes.has(node_name)) { - r_ret = nodes[node_name]; + r_ret = nodes[node_name].node; return true; } } @@ -1086,7 +1134,7 @@ bool AnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_ret) cons if (what == "position") { if (nodes.has(node_name)) { - r_ret = nodes[node_name]->get_position(); + r_ret = nodes[node_name].position; return true; } } @@ -1113,7 +1161,7 @@ bool AnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_ret) cons void AnimationNodeBlendTree::_get_property_list(List<PropertyInfo> *p_list) const { List<StringName> names; - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { + for (Map<StringName, Node>::Element *E = nodes.front(); E; E = E->next()) { names.push_back(E->key()); } names.sort_custom<StringName::AlphCompare>(); @@ -1121,7 +1169,7 @@ void AnimationNodeBlendTree::_get_property_list(List<PropertyInfo> *p_list) cons for (List<StringName>::Element *E = names.front(); E; E = E->next()) { String name = E->get(); if (name != "output") { - p_list->push_back(PropertyInfo(Variant::OBJECT, "nodes/" + name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE)); + p_list->push_back(PropertyInfo(Variant::OBJECT, "nodes/" + name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NOEDITOR)); } p_list->push_back(PropertyInfo(Variant::VECTOR2, "nodes/" + name + "/position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } @@ -1129,9 +1177,19 @@ void AnimationNodeBlendTree::_get_property_list(List<PropertyInfo> *p_list) cons p_list->push_back(PropertyInfo(Variant::ARRAY, "node_connections", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } +void AnimationNodeBlendTree::_tree_changed() { + emit_signal("tree_changed"); +} + +void AnimationNodeBlendTree::_node_changed(const StringName &p_node) { + + ERR_FAIL_COND(!nodes.has(p_node)); + nodes[p_node].connections.resize(nodes[p_node].node->get_input_count()); +} + void AnimationNodeBlendTree::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_node", "name", "node"), &AnimationNodeBlendTree::add_node); + ClassDB::bind_method(D_METHOD("add_node", "name", "node", "position"), &AnimationNodeBlendTree::add_node, DEFVAL(Vector2())); ClassDB::bind_method(D_METHOD("get_node", "name"), &AnimationNodeBlendTree::get_node); ClassDB::bind_method(D_METHOD("remove_node", "name"), &AnimationNodeBlendTree::remove_node); ClassDB::bind_method(D_METHOD("rename_node", "name", "new_name"), &AnimationNodeBlendTree::rename_node); @@ -1139,9 +1197,15 @@ void AnimationNodeBlendTree::_bind_methods() { ClassDB::bind_method(D_METHOD("connect_node", "input_node", "input_index", "output_node"), &AnimationNodeBlendTree::connect_node); ClassDB::bind_method(D_METHOD("disconnect_node", "input_node", "input_index"), &AnimationNodeBlendTree::disconnect_node); + ClassDB::bind_method(D_METHOD("set_node_position", "name", "position"), &AnimationNodeBlendTree::set_node_position); + ClassDB::bind_method(D_METHOD("get_node_position", "name"), &AnimationNodeBlendTree::get_node_position); + ClassDB::bind_method(D_METHOD("set_graph_offset", "offset"), &AnimationNodeBlendTree::set_graph_offset); ClassDB::bind_method(D_METHOD("get_graph_offset"), &AnimationNodeBlendTree::get_graph_offset); + ClassDB::bind_method(D_METHOD("_tree_changed"), &AnimationNodeBlendTree::_tree_changed); + ClassDB::bind_method(D_METHOD("_node_changed", "node"), &AnimationNodeBlendTree::_node_changed); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "graph_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_graph_offset", "get_graph_offset"); BIND_CONSTANT(CONNECTION_OK); @@ -1156,15 +1220,12 @@ AnimationNodeBlendTree::AnimationNodeBlendTree() { Ref<AnimationNodeOutput> output; output.instance(); - output->set_position(Vector2(300, 150)); - output->set_parent(this); - nodes["output"] = output; + Node n; + n.node = output; + n.position = Vector2(300, 150); + n.connections.resize(1); + nodes["output"] = n; } AnimationNodeBlendTree::~AnimationNodeBlendTree() { - - for (Map<StringName, Ref<AnimationNode> >::Element *E = nodes.front(); E; E = E->next()) { - E->get()->set_parent(NULL); - E->get()->set_tree(NULL); - } } diff --git a/scene/animation/animation_blend_tree.h b/scene/animation/animation_blend_tree.h index e86cc2e823..37bd45c74a 100644 --- a/scene/animation/animation_blend_tree.h +++ b/scene/animation/animation_blend_tree.h @@ -20,6 +20,8 @@ protected: static void _bind_methods(); public: + static Vector<String> (*get_editable_animation_list)(); + virtual String get_caption() const; virtual float process(float p_time, bool p_seek); @@ -41,8 +43,6 @@ public: }; private: - bool active; - bool do_start; float fade_in; float fade_out; @@ -51,15 +51,25 @@ private: float autorestart_random_delay; MixMode mix; - float time; - float remaining; - float autorestart_remaining; bool sync; + /* bool active; + bool do_start; + float time; + float remaining;*/ + + StringName active; + StringName prev_active; + StringName time; + StringName remaining; + protected: static void _bind_methods(); public: + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; + virtual String get_caption() const; void set_fadein_time(float p_time); @@ -79,10 +89,6 @@ public: void set_mix_mode(MixMode p_mix); MixMode get_mix_mode() const; - void start(); - void stop(); - bool is_active() const; - void set_use_sync(bool p_sync); bool is_using_sync() const; @@ -97,17 +103,17 @@ VARIANT_ENUM_CAST(AnimationNodeOneShot::MixMode) class AnimationNodeAdd2 : public AnimationNode { GDCLASS(AnimationNodeAdd2, AnimationNode); - float amount; + StringName add_amount; bool sync; protected: static void _bind_methods(); public: - virtual String get_caption() const; + void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; - void set_amount(float p_amount); - float get_amount() const; + virtual String get_caption() const; void set_use_sync(bool p_sync); bool is_using_sync() const; @@ -121,17 +127,17 @@ public: class AnimationNodeAdd3 : public AnimationNode { GDCLASS(AnimationNodeAdd3, AnimationNode); - float amount; + StringName add_amount; bool sync; protected: static void _bind_methods(); public: - virtual String get_caption() const; + void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; - void set_amount(float p_amount); - float get_amount() const; + virtual String get_caption() const; void set_use_sync(bool p_sync); bool is_using_sync() const; @@ -145,19 +151,19 @@ public: class AnimationNodeBlend2 : public AnimationNode { GDCLASS(AnimationNodeBlend2, AnimationNode); - float amount; + StringName blend_amount; bool sync; protected: static void _bind_methods(); public: + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; + virtual String get_caption() const; virtual float process(float p_time, bool p_seek); - void set_amount(float p_amount); - float get_amount() const; - void set_use_sync(bool p_sync); bool is_using_sync() const; @@ -168,17 +174,17 @@ public: class AnimationNodeBlend3 : public AnimationNode { GDCLASS(AnimationNodeBlend3, AnimationNode); - float amount; + StringName blend_amount; bool sync; protected: static void _bind_methods(); public: - virtual String get_caption() const; + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; - void set_amount(float p_amount); - float get_amount() const; + virtual String get_caption() const; void set_use_sync(bool p_sync); bool is_using_sync() const; @@ -190,16 +196,16 @@ public: class AnimationNodeTimeScale : public AnimationNode { GDCLASS(AnimationNodeTimeScale, AnimationNode); - float scale; + StringName scale; protected: static void _bind_methods(); public: - virtual String get_caption() const; + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; - void set_scale(float p_scale); - float get_scale() const; + virtual String get_caption() const; float process(float p_time, bool p_seek); @@ -209,16 +215,16 @@ public: class AnimationNodeTimeSeek : public AnimationNode { GDCLASS(AnimationNodeTimeSeek, AnimationNode); - float seek_pos; + StringName seek_pos; protected: static void _bind_methods(); public: - virtual String get_caption() const; + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; - void set_seek_pos(float p_sec); - float get_seek_pos() const; + virtual String get_caption() const; float process(float p_time, bool p_seek); @@ -241,13 +247,18 @@ class AnimationNodeTransition : public AnimationNode { InputData inputs[MAX_INPUTS]; int enabled_inputs; - float prev_time; + /* float prev_xfading; int prev; - bool switched; - float time; int current; + int prev_current; */ + + StringName prev_xfading; + StringName prev; + StringName time; + StringName current; + StringName prev_current; float xfade; @@ -258,6 +269,9 @@ protected: void _validate_property(PropertyInfo &property) const; public: + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; + virtual String get_caption() const; void set_enabled_inputs(int p_inputs); @@ -269,9 +283,6 @@ public: void set_input_caption(int p_input, const String &p_name); String get_input_caption(int p_input) const; - void set_current(int p_current); - int get_current() const; - void set_cross_fade_time(float p_fade); float get_cross_fade_time() const; @@ -293,10 +304,19 @@ public: class AnimationNodeBlendTree : public AnimationRootNode { GDCLASS(AnimationNodeBlendTree, AnimationRootNode) - Map<StringName, Ref<AnimationNode> > nodes; + struct Node { + Ref<AnimationNode> node; + Vector2 position; + Vector<StringName> connections; + }; + + Map<StringName, Node> nodes; Vector2 graph_offset; + void _tree_changed(); + void _node_changed(const StringName &p_node); + protected: static void _bind_methods(); bool _set(const StringName &p_name, const Variant &p_value); @@ -314,12 +334,18 @@ public: //no need to check for cycles due to tree topology }; - void add_node(const StringName &p_name, Ref<AnimationNode> p_node); + void add_node(const StringName &p_name, Ref<AnimationNode> p_node, const Vector2 &p_position = Vector2()); Ref<AnimationNode> get_node(const StringName &p_name) const; void remove_node(const StringName &p_name); void rename_node(const StringName &p_name, const StringName &p_new_name); bool has_node(const StringName &p_name) const; StringName get_node_name(const Ref<AnimationNode> &p_node) const; + Vector<StringName> get_node_connection_array(const StringName &p_name) const; + + void set_node_position(const StringName &p_node, const Vector2 &p_position); + Vector2 get_node_position(const StringName &p_node) const; + + virtual void get_child_nodes(List<ChildNode> *r_child_nodes); void connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node); void disconnect_node(const StringName &p_node, int p_input_index); @@ -342,7 +368,8 @@ public: void set_graph_offset(const Vector2 &p_graph_offset); Vector2 get_graph_offset() const; - virtual void set_tree(AnimationTree *p_player); + virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name); + AnimationNodeBlendTree(); ~AnimationNodeBlendTree(); }; diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index f478112a36..c28e918a16 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -20,6 +20,26 @@ bool AnimationNodeStateMachineTransition::has_auto_advance() const { return auto_advance; } +void AnimationNodeStateMachineTransition::set_advance_condition(const StringName &p_condition) { + String cs = p_condition; + ERR_FAIL_COND(cs.find("/") != -1 || cs.find(":") != -1); + advance_condition = p_condition; + if (cs != String()) { + advance_condition_name = "conditions/" + cs; + } else { + advance_condition_name = StringName(); + } + emit_signal("advance_condition_changed"); +} + +StringName AnimationNodeStateMachineTransition::get_advance_condition() const { + return advance_condition; +} + +StringName AnimationNodeStateMachineTransition::get_advance_condition_name() const { + return advance_condition_name; +} + void AnimationNodeStateMachineTransition::set_xfade_time(float p_xfade) { ERR_FAIL_COND(p_xfade < 0); @@ -56,6 +76,9 @@ void AnimationNodeStateMachineTransition::_bind_methods() { ClassDB::bind_method(D_METHOD("set_auto_advance", "auto_advance"), &AnimationNodeStateMachineTransition::set_auto_advance); ClassDB::bind_method(D_METHOD("has_auto_advance"), &AnimationNodeStateMachineTransition::has_auto_advance); + ClassDB::bind_method(D_METHOD("set_advance_condition", "name"), &AnimationNodeStateMachineTransition::set_advance_condition); + ClassDB::bind_method(D_METHOD("get_advance_condition"), &AnimationNodeStateMachineTransition::get_advance_condition); + ClassDB::bind_method(D_METHOD("set_xfade_time", "secs"), &AnimationNodeStateMachineTransition::set_xfade_time); ClassDB::bind_method(D_METHOD("get_xfade_time"), &AnimationNodeStateMachineTransition::get_xfade_time); @@ -67,6 +90,7 @@ void AnimationNodeStateMachineTransition::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "switch_mode", PROPERTY_HINT_ENUM, "Immediate,Sync,AtEnd"), "set_switch_mode", "get_switch_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_advance"), "set_auto_advance", "has_auto_advance"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "advance_condition"), "set_advance_condition", "get_advance_condition"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "xfade_time", PROPERTY_HINT_RANGE, "0,240,0.01"), "set_xfade_time", "get_xfade_time"); ADD_PROPERTY(PropertyInfo(Variant::INT, "priority", PROPERTY_HINT_RANGE, "0,32,1"), "set_priority", "get_priority"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled"); @@ -74,6 +98,8 @@ void AnimationNodeStateMachineTransition::_bind_methods() { BIND_ENUM_CONSTANT(SWITCH_MODE_IMMEDIATE); BIND_ENUM_CONSTANT(SWITCH_MODE_SYNC); BIND_ENUM_CONSTANT(SWITCH_MODE_AT_END); + + ADD_SIGNAL(MethodInfo("advance_condition_changed")); } AnimationNodeStateMachineTransition::AnimationNodeStateMachineTransition() { @@ -85,277 +111,241 @@ AnimationNodeStateMachineTransition::AnimationNodeStateMachineTransition() { priority = 1; } -/////////////////////////////////////////////////////// -void AnimationNodeStateMachine::add_node(const StringName &p_name, Ref<AnimationNode> p_node) { - - ERR_FAIL_COND(states.has(p_name)); - ERR_FAIL_COND(p_node.is_null()); - ERR_FAIL_COND(p_node->get_parent().is_valid()); - ERR_FAIL_COND(p_node->get_tree() != NULL); - ERR_FAIL_COND(String(p_name).find("/") != -1); - states[p_name] = p_node; +//////////////////////////////////////////////////////// - p_node->set_parent(this); - p_node->set_tree(get_tree()); +void AnimationNodeStateMachinePlayback::travel(const StringName &p_state) { - emit_changed(); + start_request_travel = true; + start_request = p_state; + stop_request = false; } -Ref<AnimationNode> AnimationNodeStateMachine::get_node(const StringName &p_name) const { - - ERR_FAIL_COND_V(!states.has(p_name), Ref<AnimationNode>()); - - return states[p_name]; +void AnimationNodeStateMachinePlayback::start(const StringName &p_state) { + start_request_travel = false; + start_request = p_state; + stop_request = false; + print_line("wants start"); } +void AnimationNodeStateMachinePlayback::stop() { -StringName AnimationNodeStateMachine::get_node_name(const Ref<AnimationNode> &p_node) const { - for (Map<StringName, Ref<AnimationRootNode> >::Element *E = states.front(); E; E = E->next()) { - if (E->get() == p_node) { - return E->key(); - } - } - - ERR_FAIL_V(StringName()); + stop_request = true; } - -bool AnimationNodeStateMachine::has_node(const StringName &p_name) const { - return states.has(p_name); +bool AnimationNodeStateMachinePlayback::is_playing() const { + return playing; +} +StringName AnimationNodeStateMachinePlayback::get_current_node() const { + return current; +} +StringName AnimationNodeStateMachinePlayback::get_blend_from_node() const { + return fading_from; +} +Vector<StringName> AnimationNodeStateMachinePlayback::get_travel_path() const { + return path; +} +float AnimationNodeStateMachinePlayback::get_current_play_pos() const { + return pos_current; +} +float AnimationNodeStateMachinePlayback::get_current_length() const { + return len_current; } -void AnimationNodeStateMachine::remove_node(const StringName &p_name) { - - ERR_FAIL_COND(!states.has(p_name)); - - { - //erase node connections - Ref<AnimationNode> node = states[p_name]; - for (int i = 0; i < node->get_input_count(); i++) { - node->set_input_connection(i, StringName()); - } - node->set_parent(NULL); - node->set_tree(NULL); - } - states.erase(p_name); - path.erase(p_name); +bool AnimationNodeStateMachinePlayback::_travel(AnimationNodeStateMachine *sm, const StringName &p_travel) { - for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == p_name || transitions[i].to == p_name) { - transitions.remove(i); - i--; - } - } + ERR_FAIL_COND_V(!playing, false); + ERR_FAIL_COND_V(!sm->states.has(p_travel), false); + ERR_FAIL_COND_V(!sm->states.has(current), false); - if (start_node == p_name) { - start_node = StringName(); - } + path.clear(); //a new one will be needed - if (end_node == p_name) { - end_node = StringName(); - } + if (current == p_travel) + return true; //nothing to do - if (playing && current == p_name) { - stop(); - } - emit_changed(); -} + loops_current = 0; // reset loops, so fade does not happen immediately -void AnimationNodeStateMachine::rename_node(const StringName &p_name, const StringName &p_new_name) { + Vector2 current_pos = sm->states[current].position; + Vector2 target_pos = sm->states[p_travel].position; - ERR_FAIL_COND(!states.has(p_name)); - ERR_FAIL_COND(states.has(p_new_name)); + Map<StringName, AStarCost> cost_map; - states[p_new_name] = states[p_name]; - states.erase(p_name); + List<int> open_list; - for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == p_name) { - transitions.write[i].from = p_new_name; - } + //build open list + for (int i = 0; i < sm->transitions.size(); i++) { + if (sm->transitions[i].from == current) { + open_list.push_back(i); + float cost = sm->states[sm->transitions[i].to].position.distance_to(current_pos); + cost *= sm->transitions[i].transition->get_priority(); + AStarCost ap; + ap.prev = current; + ap.distance = cost; + cost_map[sm->transitions[i].to] = ap; - if (transitions[i].to == p_name) { - transitions.write[i].to = p_new_name; + if (sm->transitions[i].to == p_travel) { //prematurely found it! :D + path.push_back(p_travel); + return true; + } } } - if (start_node == p_name) { - start_node = p_new_name; - } + //begin astar + bool found_route = false; + while (!found_route) { - if (end_node == p_name) { - end_node = p_new_name; - } + if (open_list.size() == 0) { + return false; //no path found + } - if (playing && current == p_name) { - current = p_new_name; - } + //find the last cost transition + List<int>::Element *least_cost_transition = NULL; + float least_cost = 1e20; - path.clear(); //clear path -} + for (List<int>::Element *E = open_list.front(); E; E = E->next()) { -void AnimationNodeStateMachine::get_node_list(List<StringName> *r_nodes) const { + float cost = cost_map[sm->transitions[E->get()].to].distance; + cost += sm->states[sm->transitions[E->get()].to].position.distance_to(target_pos); - List<StringName> nodes; - for (Map<StringName, Ref<AnimationRootNode> >::Element *E = states.front(); E; E = E->next()) { - nodes.push_back(E->key()); - } - nodes.sort_custom<StringName::AlphCompare>(); + if (cost < least_cost) { + least_cost_transition = E; + } + } - for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) { - r_nodes->push_back(E->get()); - } -} + StringName transition_prev = sm->transitions[least_cost_transition->get()].from; + StringName transition = sm->transitions[least_cost_transition->get()].to; -bool AnimationNodeStateMachine::has_transition(const StringName &p_from, const StringName &p_to) const { + for (int i = 0; i < sm->transitions.size(); i++) { + if (sm->transitions[i].from != transition || sm->transitions[i].to == transition_prev) { + continue; //not interested on those + } - for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == p_from && transitions[i].to == p_to) - return true; - } - return false; -} + float distance = sm->states[sm->transitions[i].from].position.distance_to(sm->states[sm->transitions[i].to].position); + distance *= sm->transitions[i].transition->get_priority(); + distance += cost_map[sm->transitions[i].from].distance; -int AnimationNodeStateMachine::find_transition(const StringName &p_from, const StringName &p_to) const { + if (cost_map.has(sm->transitions[i].to)) { + //oh this was visited already, can we win the cost? + if (distance < cost_map[sm->transitions[i].to].distance) { + cost_map[sm->transitions[i].to].distance = distance; + cost_map[sm->transitions[i].to].prev = sm->transitions[i].from; + } + } else { + //add to open list + AStarCost ac; + ac.prev = sm->transitions[i].from; + ac.distance = distance; + cost_map[sm->transitions[i].to] = ac; - for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == p_from && transitions[i].to == p_to) - return i; - } - return -1; -} + open_list.push_back(i); -void AnimationNodeStateMachine::add_transition(const StringName &p_from, const StringName &p_to, const Ref<AnimationNodeStateMachineTransition> &p_transition) { + if (sm->transitions[i].to == p_travel) { + found_route = true; + break; + } + } + } - ERR_FAIL_COND(p_from == p_to); - ERR_FAIL_COND(!states.has(p_from)); - ERR_FAIL_COND(!states.has(p_to)); - ERR_FAIL_COND(p_transition.is_null()); + if (found_route) { + break; + } - for (int i = 0; i < transitions.size(); i++) { - ERR_FAIL_COND(transitions[i].from == p_from && transitions[i].to == p_to); + open_list.erase(least_cost_transition); } - Transition tr; - tr.from = p_from; - tr.to = p_to; - tr.transition = p_transition; - - transitions.push_back(tr); -} - -Ref<AnimationNodeStateMachineTransition> AnimationNodeStateMachine::get_transition(int p_transition) const { - ERR_FAIL_INDEX_V(p_transition, transitions.size(), Ref<AnimationNodeStateMachineTransition>()); - return transitions[p_transition].transition; -} -StringName AnimationNodeStateMachine::get_transition_from(int p_transition) const { + //make path + StringName at = p_travel; + while (at != current) { + path.push_back(at); + at = cost_map[at].prev; + } - ERR_FAIL_INDEX_V(p_transition, transitions.size(), StringName()); - return transitions[p_transition].from; -} -StringName AnimationNodeStateMachine::get_transition_to(int p_transition) const { + path.invert(); - ERR_FAIL_INDEX_V(p_transition, transitions.size(), StringName()); - return transitions[p_transition].to; + return true; } -int AnimationNodeStateMachine::get_transition_count() const { - - return transitions.size(); -} -void AnimationNodeStateMachine::remove_transition(const StringName &p_from, const StringName &p_to) { +float AnimationNodeStateMachinePlayback::process(AnimationNodeStateMachine *sm, float p_time, bool p_seek) { - for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == p_from && transitions[i].to == p_to) { - transitions.remove(i); - return; + //if not playing and it can restart, then restart + if (!playing && start_request == StringName()) { + if (!stop_request && sm->start_node) { + start(sm->start_node); + } else { + return 0; } } - if (playing) { - path.clear(); - } -} - -void AnimationNodeStateMachine::remove_transition_by_index(int p_transition) { - - transitions.remove(p_transition); - if (playing) { - path.clear(); + if (playing && stop_request) { + stop_request = false; + playing = false; + return 0; } -} - -void AnimationNodeStateMachine::set_start_node(const StringName &p_node) { - - ERR_FAIL_COND(p_node != StringName() && !states.has(p_node)); - start_node = p_node; -} - -String AnimationNodeStateMachine::get_start_node() const { - - return start_node; -} - -void AnimationNodeStateMachine::set_end_node(const StringName &p_node) { - - ERR_FAIL_COND(p_node != StringName() && !states.has(p_node)); - end_node = p_node; -} - -String AnimationNodeStateMachine::get_end_node() const { - - return end_node; -} -void AnimationNodeStateMachine::set_graph_offset(const Vector2 &p_offset) { - graph_offset = p_offset; -} + bool play_start = false; -Vector2 AnimationNodeStateMachine::get_graph_offset() const { - return graph_offset; -} + if (start_request != StringName()) { -float AnimationNodeStateMachine::process(float p_time, bool p_seek) { + if (start_request_travel) { + if (!playing) { + start_request = StringName(); + ERR_EXPLAIN("Can't travel to '" + String(start_request) + "' if state machine is not active."); + ERR_FAIL_V(0); + } - //if not playing and it can restart, then restart - if (!playing) { - if (start_node) { - start(start_node); + if (!_travel(sm, start_request)) { + //cant travel, then teleport + path.clear(); + current = start_request; + } } else { - return 0; + path.clear(); + current = start_request; + playing = true; + play_start = true; } + + start_request = StringName(); //clear start request } bool do_start = (p_seek && p_time == 0) || play_start || current == StringName(); if (do_start) { - if (start_node != StringName() && p_seek && p_time == 0) { - current = start_node; + if (sm->start_node != StringName() && p_seek && p_time == 0) { + current = sm->start_node; } - len_current = blend_node(states[current], 0, true, 1.0, FILTER_IGNORE, false); + len_current = sm->blend_node(current, sm->states[current].node, 0, true, 1.0, AnimationNode::FILTER_IGNORE, false); pos_current = 0; loops_current = 0; play_start = false; } + if (!sm->states.has(current)) { + playing = false; //current does not exist + current = StringName(); + return 0; + } float fade_blend = 1.0; if (fading_from != StringName()) { - if (!p_seek) { - fading_pos += p_time; - } - fade_blend = MIN(1.0, fading_pos / fading_time); - if (fade_blend >= 1.0) { + if (!sm->states.has(fading_from)) { fading_from = StringName(); + } else { + if (!p_seek) { + fading_pos += p_time; + } + fade_blend = MIN(1.0, fading_pos / fading_time); + if (fade_blend >= 1.0) { + fading_from = StringName(); + } } } - float rem = blend_node(states[current], p_time, p_seek, fade_blend, FILTER_IGNORE, false); + float rem = sm->blend_node(current, sm->states[current].node, p_time, p_seek, fade_blend, AnimationNode::FILTER_IGNORE, false); if (fading_from != StringName()) { - blend_node(states[fading_from], p_time, p_seek, 1.0 - fade_blend, FILTER_IGNORE, false); + sm->blend_node(current, sm->states[fading_from].node, p_time, p_seek, 1.0 - fade_blend, AnimationNode::FILTER_IGNORE, false); } //guess playback position @@ -380,29 +370,39 @@ float AnimationNodeStateMachine::process(float p_time, bool p_seek) { if (path.size()) { - for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == current && transitions[i].to == path[0]) { - next_xfade = transitions[i].transition->get_xfade_time(); - switch_mode = transitions[i].transition->get_switch_mode(); + for (int i = 0; i < sm->transitions.size(); i++) { + if (sm->transitions[i].from == current && sm->transitions[i].to == path[0]) { + next_xfade = sm->transitions[i].transition->get_xfade_time(); + switch_mode = sm->transitions[i].transition->get_switch_mode(); next = path[0]; } } } else { float priority_best = 1e20; int auto_advance_to = -1; - for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == current && transitions[i].transition->has_auto_advance()) { + for (int i = 0; i < sm->transitions.size(); i++) { + + bool auto_advance = false; + if (sm->transitions[i].transition->has_auto_advance()) { + auto_advance = true; + } + StringName advance_condition_name = sm->transitions[i].transition->get_advance_condition_name(); + if (advance_condition_name != StringName() && bool(sm->get_parameter(advance_condition_name))) { + auto_advance = true; + } + + if (sm->transitions[i].from == current && sm->transitions[i].transition->has_auto_advance()) { - if (transitions[i].transition->get_priority() < priority_best) { + if (sm->transitions[i].transition->get_priority() < priority_best) { auto_advance_to = i; } } } if (auto_advance_to != -1) { - next = transitions[auto_advance_to].to; - next_xfade = transitions[auto_advance_to].transition->get_xfade_time(); - switch_mode = transitions[auto_advance_to].transition->get_switch_mode(); + next = sm->transitions[auto_advance_to].to; + next_xfade = sm->transitions[auto_advance_to].transition->get_xfade_time(); + switch_mode = sm->transitions[auto_advance_to].transition->get_switch_mode(); } } @@ -437,12 +437,12 @@ float AnimationNodeStateMachine::process(float p_time, bool p_seek) { } current = next; if (switch_mode == AnimationNodeStateMachineTransition::SWITCH_MODE_SYNC) { - len_current = blend_node(states[current], 0, true, 0, FILTER_IGNORE, false); + len_current = sm->blend_node(current, sm->states[current].node, 0, true, 0, AnimationNode::FILTER_IGNORE, false); pos_current = MIN(pos_current, len_current); - blend_node(states[current], pos_current, true, 0, FILTER_IGNORE, false); + sm->blend_node(current, sm->states[current].node, pos_current, true, 0, AnimationNode::FILTER_IGNORE, false); } else { - len_current = blend_node(states[current], 0, true, 0, FILTER_IGNORE, false); + len_current = sm->blend_node(current, sm->states[current].node, 0, true, 0, AnimationNode::FILTER_IGNORE, false); pos_current = 0; } @@ -453,169 +453,321 @@ float AnimationNodeStateMachine::process(float p_time, bool p_seek) { //compute time left for transitions by using the end node - if (end_node != StringName() && end_node != current) { + if (sm->end_node != StringName() && sm->end_node != current) { - rem = blend_node(states[end_node], 0, true, 0, FILTER_IGNORE, false); + rem = sm->blend_node(current, sm->states[sm->end_node].node, 0, true, 0, AnimationNode::FILTER_IGNORE, false); } return rem; } -bool AnimationNodeStateMachine::travel(const StringName &p_state) { - ERR_FAIL_COND_V(!playing, false); - ERR_FAIL_COND_V(!states.has(p_state), false); - ERR_FAIL_COND_V(!states.has(current), false); +void AnimationNodeStateMachinePlayback::_bind_methods() { - path.clear(); //a new one will be needed + ClassDB::bind_method(D_METHOD("travel", "to_node"), &AnimationNodeStateMachinePlayback::travel); + ClassDB::bind_method(D_METHOD("start", "node"), &AnimationNodeStateMachinePlayback::start); + ClassDB::bind_method(D_METHOD("stop"), &AnimationNodeStateMachinePlayback::stop); + ClassDB::bind_method(D_METHOD("is_playing"), &AnimationNodeStateMachinePlayback::is_playing); + ClassDB::bind_method(D_METHOD("get_current_node"), &AnimationNodeStateMachinePlayback::get_current_node); + ClassDB::bind_method(D_METHOD("get_travel_path"), &AnimationNodeStateMachinePlayback::get_travel_path); +} - if (current == p_state) - return true; //nothing to do +AnimationNodeStateMachinePlayback::AnimationNodeStateMachinePlayback() { + set_local_to_scene(true); //only one per instanced scene - loops_current = 0; // reset loops, so fade does not happen immediately + playing = false; + len_current = 0; + fading_time = 0; + stop_request = false; +} - Vector2 current_pos = states[current]->get_position(); - Vector2 target_pos = states[p_state]->get_position(); +/////////////////////////////////////////////////////// - Map<StringName, AStarCost> cost_map; +void AnimationNodeStateMachine::get_parameter_list(List<PropertyInfo> *r_list) const { + r_list->push_back(PropertyInfo(Variant::OBJECT, playback, PROPERTY_HINT_RESOURCE_TYPE, "AnimationNodeStateMachinePlayback", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE)); + List<StringName> advance_conditions; + for (int i = 0; i < transitions.size(); i++) { + StringName ac = transitions[i].transition->get_advance_condition_name(); + if (ac != StringName() && advance_conditions.find(ac) == NULL) { + advance_conditions.push_back(ac); + } + } - List<int> open_list; + advance_conditions.sort_custom<StringName::AlphCompare>(); + for (List<StringName>::Element *E = advance_conditions.front(); E; E = E->next()) { + r_list->push_back(PropertyInfo(Variant::BOOL, E->get())); + } +} - //build open list - for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == current) { - open_list.push_back(i); - float cost = states[transitions[i].to]->get_position().distance_to(current_pos); - cost *= transitions[i].transition->get_priority(); - AStarCost ap; - ap.prev = current; - ap.distance = cost; - cost_map[transitions[i].to] = ap; +Variant AnimationNodeStateMachine::get_parameter_default_value(const StringName &p_parameter) const { - if (transitions[i].to == p_state) { //prematurely found it! :D - path.push_back(p_state); - return true; - } - } + if (p_parameter == playback) { + Ref<AnimationNodeStateMachinePlayback> p; + p.instance(); + return p; + } else { + return false; //advance condition } +} - //begin astar - bool found_route = false; - while (!found_route) { +void AnimationNodeStateMachine::add_node(const StringName &p_name, Ref<AnimationNode> p_node, const Vector2 &p_position) { - if (open_list.size() == 0) { - return false; //no path found + ERR_FAIL_COND(states.has(p_name)); + ERR_FAIL_COND(p_node.is_null()); + ERR_FAIL_COND(String(p_name).find("/") != -1); + + State state; + state.node = p_node; + state.position = p_position; + + states[p_name] = state; + + emit_changed(); + emit_signal("tree_changed"); + + p_node->connect("tree_changed", this, "_tree_changed", varray(), CONNECT_REFERENCE_COUNTED); +} + +Ref<AnimationNode> AnimationNodeStateMachine::get_node(const StringName &p_name) const { + + ERR_FAIL_COND_V(!states.has(p_name), Ref<AnimationNode>()); + + return states[p_name].node; +} + +StringName AnimationNodeStateMachine::get_node_name(const Ref<AnimationNode> &p_node) const { + for (Map<StringName, State>::Element *E = states.front(); E; E = E->next()) { + if (E->get().node == p_node) { + return E->key(); } + } - //find the last cost transition - List<int>::Element *least_cost_transition = NULL; - float least_cost = 1e20; + ERR_FAIL_V(StringName()); +} - for (List<int>::Element *E = open_list.front(); E; E = E->next()) { +void AnimationNodeStateMachine::get_child_nodes(List<ChildNode> *r_child_nodes) { + Vector<StringName> nodes; - float cost = cost_map[transitions[E->get()].to].distance; - cost += states[transitions[E->get()].to]->get_position().distance_to(target_pos); + for (Map<StringName, State>::Element *E = states.front(); E; E = E->next()) { + nodes.push_back(E->key()); + } - if (cost < least_cost) { - least_cost_transition = E; - } + nodes.sort_custom<StringName::AlphCompare>(); + + for (int i = 0; i < nodes.size(); i++) { + ChildNode cn; + cn.name = nodes[i]; + cn.node = states[cn.name].node; + r_child_nodes->push_back(cn); + } +} + +bool AnimationNodeStateMachine::has_node(const StringName &p_name) const { + return states.has(p_name); +} +void AnimationNodeStateMachine::remove_node(const StringName &p_name) { + + ERR_FAIL_COND(!states.has(p_name)); + + { + Ref<AnimationNode> node = states[p_name].node; + node->disconnect("tree_changed", this, "_tree_changed"); + } + + states.erase(p_name); + //path.erase(p_name); + + for (int i = 0; i < transitions.size(); i++) { + if (transitions[i].from == p_name || transitions[i].to == p_name) { + transitions.write[i].transition->disconnect("advance_condition_changed", this, "_tree_changed"); + transitions.remove(i); + i--; } + } - StringName transition_prev = transitions[least_cost_transition->get()].from; - StringName transition = transitions[least_cost_transition->get()].to; + if (start_node == p_name) { + start_node = StringName(); + } - for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from != transition || transitions[i].to == transition_prev) { - continue; //not interested on those - } + if (end_node == p_name) { + end_node = StringName(); + } - float distance = states[transitions[i].from]->get_position().distance_to(states[transitions[i].to]->get_position()); - distance *= transitions[i].transition->get_priority(); - distance += cost_map[transitions[i].from].distance; + /*if (playing && current == p_name) { + stop(); + }*/ - if (cost_map.has(transitions[i].to)) { - //oh this was visited already, can we win the cost? - if (distance < cost_map[transitions[i].to].distance) { - cost_map[transitions[i].to].distance = distance; - cost_map[transitions[i].to].prev = transitions[i].from; - } - } else { - //add to open list - AStarCost ac; - ac.prev = transitions[i].from; - ac.distance = distance; - cost_map[transitions[i].to] = ac; + emit_changed(); + emit_signal("tree_changed"); +} - open_list.push_back(i); +void AnimationNodeStateMachine::rename_node(const StringName &p_name, const StringName &p_new_name) { - if (transitions[i].to == p_state) { - found_route = true; - break; - } - } + ERR_FAIL_COND(!states.has(p_name)); + ERR_FAIL_COND(states.has(p_new_name)); + + states[p_new_name] = states[p_name]; + states.erase(p_name); + + for (int i = 0; i < transitions.size(); i++) { + if (transitions[i].from == p_name) { + transitions.write[i].from = p_new_name; } - if (found_route) { - break; + if (transitions[i].to == p_name) { + transitions.write[i].to = p_new_name; } + } - open_list.erase(least_cost_transition); + if (start_node == p_name) { + start_node = p_new_name; } - //make path - StringName at = p_state; - while (at != current) { - path.push_back(at); - at = cost_map[at].prev; + if (end_node == p_name) { + end_node = p_new_name; } - path.invert(); + /*if (playing && current == p_name) { + current = p_new_name; + }*/ - return true; + //path.clear(); //clear path + emit_signal("tree_changed"); } -void AnimationNodeStateMachine::start(const StringName &p_state) { +void AnimationNodeStateMachine::get_node_list(List<StringName> *r_nodes) const { - ERR_FAIL_COND(!states.has(p_state)); - path.clear(); - current = p_state; - playing = true; - play_start = true; + List<StringName> nodes; + for (Map<StringName, State>::Element *E = states.front(); E; E = E->next()) { + nodes.push_back(E->key()); + } + nodes.sort_custom<StringName::AlphCompare>(); + + for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) { + r_nodes->push_back(E->get()); + } } -void AnimationNodeStateMachine::stop() { - playing = false; - play_start = false; - current = StringName(); + +bool AnimationNodeStateMachine::has_transition(const StringName &p_from, const StringName &p_to) const { + + for (int i = 0; i < transitions.size(); i++) { + if (transitions[i].from == p_from && transitions[i].to == p_to) + return true; + } + return false; } -bool AnimationNodeStateMachine::is_playing() const { - return playing; +int AnimationNodeStateMachine::find_transition(const StringName &p_from, const StringName &p_to) const { + + for (int i = 0; i < transitions.size(); i++) { + if (transitions[i].from == p_from && transitions[i].to == p_to) + return i; + } + return -1; } -StringName AnimationNodeStateMachine::get_current_node() const { - if (!playing) { - return StringName(); + +void AnimationNodeStateMachine::add_transition(const StringName &p_from, const StringName &p_to, const Ref<AnimationNodeStateMachineTransition> &p_transition) { + + ERR_FAIL_COND(p_from == p_to); + ERR_FAIL_COND(!states.has(p_from)); + ERR_FAIL_COND(!states.has(p_to)); + ERR_FAIL_COND(p_transition.is_null()); + + for (int i = 0; i < transitions.size(); i++) { + ERR_FAIL_COND(transitions[i].from == p_from && transitions[i].to == p_to); } - return current; + Transition tr; + tr.from = p_from; + tr.to = p_to; + tr.transition = p_transition; + + tr.transition->connect("advance_condition_changed", this, "_tree_changed", varray(), CONNECT_REFERENCE_COUNTED); + + transitions.push_back(tr); +} + +Ref<AnimationNodeStateMachineTransition> AnimationNodeStateMachine::get_transition(int p_transition) const { + ERR_FAIL_INDEX_V(p_transition, transitions.size(), Ref<AnimationNodeStateMachineTransition>()); + return transitions[p_transition].transition; } +StringName AnimationNodeStateMachine::get_transition_from(int p_transition) const { + + ERR_FAIL_INDEX_V(p_transition, transitions.size(), StringName()); + return transitions[p_transition].from; +} +StringName AnimationNodeStateMachine::get_transition_to(int p_transition) const { + + ERR_FAIL_INDEX_V(p_transition, transitions.size(), StringName()); + return transitions[p_transition].to; +} + +int AnimationNodeStateMachine::get_transition_count() const { + + return transitions.size(); +} +void AnimationNodeStateMachine::remove_transition(const StringName &p_from, const StringName &p_to) { -StringName AnimationNodeStateMachine::get_blend_from_node() const { - if (!playing) { - return StringName(); + for (int i = 0; i < transitions.size(); i++) { + if (transitions[i].from == p_from && transitions[i].to == p_to) { + transitions.write[i].transition->disconnect("advance_condition_changed", this, "_tree_changed"); + transitions.remove(i); + return; + } } - return fading_from; + /*if (playing) { + path.clear(); + }*/ } -float AnimationNodeStateMachine::get_current_play_pos() const { - return pos_current; +void AnimationNodeStateMachine::remove_transition_by_index(int p_transition) { + + ERR_FAIL_INDEX(p_transition, transitions.size()); + transitions.write[p_transition].transition->disconnect("advance_condition_changed", this, "_tree_changed"); + transitions.remove(p_transition); + /*if (playing) { + path.clear(); + }*/ } -float AnimationNodeStateMachine::get_current_length() const { - return len_current; + +void AnimationNodeStateMachine::set_start_node(const StringName &p_node) { + + ERR_FAIL_COND(p_node != StringName() && !states.has(p_node)); + start_node = p_node; } -Vector<StringName> AnimationNodeStateMachine::get_travel_path() const { - return path; +String AnimationNodeStateMachine::get_start_node() const { + + return start_node; +} + +void AnimationNodeStateMachine::set_end_node(const StringName &p_node) { + + ERR_FAIL_COND(p_node != StringName() && !states.has(p_node)); + end_node = p_node; +} + +String AnimationNodeStateMachine::get_end_node() const { + + return end_node; +} + +void AnimationNodeStateMachine::set_graph_offset(const Vector2 &p_offset) { + graph_offset = p_offset; +} + +Vector2 AnimationNodeStateMachine::get_graph_offset() const { + return graph_offset; +} + +float AnimationNodeStateMachine::process(float p_time, bool p_seek) { + + Ref<AnimationNodeStateMachinePlayback> playback = get_parameter(this->playback); + ERR_FAIL_COND_V(playback.is_null(), 0.0); + + return playback->process(this, p_time, p_seek); } + String AnimationNodeStateMachine::get_caption() const { return "StateMachine"; } @@ -623,14 +775,8 @@ String AnimationNodeStateMachine::get_caption() const { void AnimationNodeStateMachine::_notification(int p_what) { } -void AnimationNodeStateMachine::set_tree(AnimationTree *p_player) { - - AnimationNode::set_tree(p_player); - - for (Map<StringName, Ref<AnimationRootNode> >::Element *E = states.front(); E; E = E->next()) { - Ref<AnimationRootNode> node = E->get(); - node->set_tree(p_player); - } +Ref<AnimationNode> AnimationNodeStateMachine::get_child_by_name(const StringName &p_name) { + return get_node(p_name); } bool AnimationNodeStateMachine::_set(const StringName &p_name, const Variant &p_value) { @@ -651,7 +797,7 @@ bool AnimationNodeStateMachine::_set(const StringName &p_name, const Variant &p_ if (what == "position") { if (states.has(node_name)) { - states[node_name]->set_position(p_value); + states[node_name].position = p_value; } return true; } @@ -687,7 +833,7 @@ bool AnimationNodeStateMachine::_get(const StringName &p_name, Variant &r_ret) c if (what == "node") { if (states.has(node_name)) { - r_ret = states[node_name]; + r_ret = states[node_name].node; return true; } } @@ -695,7 +841,7 @@ bool AnimationNodeStateMachine::_get(const StringName &p_name, Variant &r_ret) c if (what == "position") { if (states.has(node_name)) { - r_ret = states[node_name]->get_position(); + r_ret = states[node_name].position; return true; } } @@ -727,14 +873,14 @@ bool AnimationNodeStateMachine::_get(const StringName &p_name, Variant &r_ret) c void AnimationNodeStateMachine::_get_property_list(List<PropertyInfo> *p_list) const { List<StringName> names; - for (Map<StringName, Ref<AnimationRootNode> >::Element *E = states.front(); E; E = E->next()) { + for (Map<StringName, State>::Element *E = states.front(); E; E = E->next()) { names.push_back(E->key()); } names.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { String name = E->get(); - p_list->push_back(PropertyInfo(Variant::OBJECT, "states/" + name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE)); + p_list->push_back(PropertyInfo(Variant::OBJECT, "states/" + name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NOEDITOR)); p_list->push_back(PropertyInfo(Variant::VECTOR2, "states/" + name + "/position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } @@ -744,16 +890,34 @@ void AnimationNodeStateMachine::_get_property_list(List<PropertyInfo> *p_list) c p_list->push_back(PropertyInfo(Variant::VECTOR2, "graph_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } +void AnimationNodeStateMachine::set_node_position(const StringName &p_name, const Vector2 &p_position) { + ERR_FAIL_COND(!states.has(p_name)); + states[p_name].position = p_position; +} + +Vector2 AnimationNodeStateMachine::get_node_position(const StringName &p_name) const { + + ERR_FAIL_COND_V(!states.has(p_name), Vector2()); + return states[p_name].position; +} + +void AnimationNodeStateMachine::_tree_changed() { + emit_signal("tree_changed"); +} + void AnimationNodeStateMachine::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_node", "name", "node"), &AnimationNodeStateMachine::add_node); + ClassDB::bind_method(D_METHOD("add_node", "name", "node", "position"), &AnimationNodeStateMachine::add_node, DEFVAL(Vector2())); ClassDB::bind_method(D_METHOD("get_node", "name"), &AnimationNodeStateMachine::get_node); ClassDB::bind_method(D_METHOD("remove_node", "name"), &AnimationNodeStateMachine::remove_node); ClassDB::bind_method(D_METHOD("rename_node", "name", "new_name"), &AnimationNodeStateMachine::rename_node); ClassDB::bind_method(D_METHOD("has_node", "name"), &AnimationNodeStateMachine::has_node); ClassDB::bind_method(D_METHOD("get_node_name", "node"), &AnimationNodeStateMachine::get_node_name); - ClassDB::bind_method(D_METHOD("has_transition", "from", "to"), &AnimationNodeStateMachine::add_transition); + ClassDB::bind_method(D_METHOD("set_node_position", "name", "position"), &AnimationNodeStateMachine::set_node_position); + ClassDB::bind_method(D_METHOD("get_node_position", "name"), &AnimationNodeStateMachine::get_node_position); + + ClassDB::bind_method(D_METHOD("has_transition", "from", "to"), &AnimationNodeStateMachine::has_transition); ClassDB::bind_method(D_METHOD("add_transition", "from", "to", "transition"), &AnimationNodeStateMachine::add_transition); ClassDB::bind_method(D_METHOD("get_transition", "idx"), &AnimationNodeStateMachine::get_transition); ClassDB::bind_method(D_METHOD("get_transition_from", "idx"), &AnimationNodeStateMachine::get_transition_from); @@ -771,20 +935,10 @@ void AnimationNodeStateMachine::_bind_methods() { ClassDB::bind_method(D_METHOD("set_graph_offset", "name"), &AnimationNodeStateMachine::set_graph_offset); ClassDB::bind_method(D_METHOD("get_graph_offset"), &AnimationNodeStateMachine::get_graph_offset); - ClassDB::bind_method(D_METHOD("travel", "to_node"), &AnimationNodeStateMachine::travel); - ClassDB::bind_method(D_METHOD("start", "node"), &AnimationNodeStateMachine::start); - ClassDB::bind_method(D_METHOD("stop"), &AnimationNodeStateMachine::stop); - ClassDB::bind_method(D_METHOD("is_playing"), &AnimationNodeStateMachine::is_playing); - ClassDB::bind_method(D_METHOD("get_current_node"), &AnimationNodeStateMachine::get_current_node); - ClassDB::bind_method(D_METHOD("get_travel_path"), &AnimationNodeStateMachine::get_travel_path); + ClassDB::bind_method(D_METHOD("_tree_changed"), &AnimationNodeStateMachine::_tree_changed); } AnimationNodeStateMachine::AnimationNodeStateMachine() { - play_start = false; - - playing = false; - len_current = 0; - - fading_time = 0; + playback = "playback"; } diff --git a/scene/animation/animation_node_state_machine.h b/scene/animation/animation_node_state_machine.h index e7357e09ea..5d633d6334 100644 --- a/scene/animation/animation_node_state_machine.h +++ b/scene/animation/animation_node_state_machine.h @@ -15,6 +15,8 @@ public: private: SwitchMode switch_mode; bool auto_advance; + StringName advance_condition; + StringName advance_condition_name; float xfade; bool disabled; int priority; @@ -29,6 +31,11 @@ public: void set_auto_advance(bool p_enable); bool has_auto_advance() const; + void set_advance_condition(const StringName &p_condition); + StringName get_advance_condition() const; + + StringName get_advance_condition_name() const; + void set_xfade_time(float p_xfade); float get_xfade_time() const; @@ -43,39 +50,24 @@ public: VARIANT_ENUM_CAST(AnimationNodeStateMachineTransition::SwitchMode) -class AnimationNodeStateMachine : public AnimationRootNode { - - GDCLASS(AnimationNodeStateMachine, AnimationRootNode); +class AnimationNodeStateMachine; -private: - Map<StringName, Ref<AnimationRootNode> > states; +class AnimationNodeStateMachinePlayback : public Resource { + GDCLASS(AnimationNodeStateMachinePlayback, Resource); - struct Transition { - - StringName from; - StringName to; - Ref<AnimationNodeStateMachineTransition> transition; - }; + friend class AnimationNodeStateMachine; struct AStarCost { float distance; StringName prev; }; - Vector<Transition> transitions; - float len_total; float len_current; float pos_current; int loops_current; - bool play_start; - StringName start_node; - StringName end_node; - - Vector2 graph_offset; - StringName current; StringName fading_from; @@ -85,6 +77,63 @@ private: Vector<StringName> path; bool playing; + StringName start_request; + bool start_request_travel; + bool stop_request; + + bool _travel(AnimationNodeStateMachine *p_state_machine, const StringName &p_travel); + + float process(AnimationNodeStateMachine *p_state_machine, float p_time, bool p_seek); + +protected: + static void _bind_methods(); + +public: + void travel(const StringName &p_state); + void start(const StringName &p_state); + void stop(); + bool is_playing() const; + StringName get_current_node() const; + StringName get_blend_from_node() const; + Vector<StringName> get_travel_path() const; + float get_current_play_pos() const; + float get_current_length() const; + + AnimationNodeStateMachinePlayback(); +}; + +class AnimationNodeStateMachine : public AnimationRootNode { + + GDCLASS(AnimationNodeStateMachine, AnimationRootNode); + +private: + friend class AnimationNodeStateMachinePlayback; + + struct State { + Ref<AnimationRootNode> node; + Vector2 position; + }; + + Map<StringName, State> states; + + struct Transition { + + StringName from; + StringName to; + Ref<AnimationNodeStateMachineTransition> transition; + }; + + Vector<Transition> transitions; + + StringName playback; + + StringName start_node; + StringName end_node; + + Vector2 graph_offset; + + void _tree_changed(); + protected: void _notification(int p_what); static void _bind_methods(); @@ -94,7 +143,10 @@ protected: void _get_property_list(List<PropertyInfo> *p_list) const; public: - void add_node(const StringName &p_name, Ref<AnimationNode> p_node); + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; + + void add_node(const StringName &p_name, Ref<AnimationNode> p_node, const Vector2 &p_position = Vector2()); Ref<AnimationNode> get_node(const StringName &p_name) const; void remove_node(const StringName &p_name); void rename_node(const StringName &p_name, const StringName &p_new_name); @@ -102,6 +154,11 @@ public: StringName get_node_name(const Ref<AnimationNode> &p_node) const; void get_node_list(List<StringName> *r_nodes) const; + void set_node_position(const StringName &p_name, const Vector2 &p_position); + Vector2 get_node_position(const StringName &p_name) const; + + virtual void get_child_nodes(List<ChildNode> *r_child_nodes); + bool has_transition(const StringName &p_from, const StringName &p_to) const; int find_transition(const StringName &p_from, const StringName &p_to) const; void add_transition(const StringName &p_from, const StringName &p_to, const Ref<AnimationNodeStateMachineTransition> &p_transition); @@ -124,17 +181,7 @@ public: virtual float process(float p_time, bool p_seek); virtual String get_caption() const; - bool travel(const StringName &p_state); - void start(const StringName &p_state); - void stop(); - bool is_playing() const; - StringName get_current_node() const; - StringName get_blend_from_node() const; - Vector<StringName> get_travel_path() const; - float get_current_play_pos() const; - float get_current_length() const; - - virtual void set_tree(AnimationTree *p_player); + virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name); AnimationNodeStateMachine(); }; diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 8bbc05eed3..1513010a8a 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -5,6 +5,34 @@ #include "scene/scene_string_names.h" #include "servers/audio/audio_stream.h" +void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const { +} + +Variant AnimationNode::get_parameter_default_value(const StringName &p_parameter) const { + return Variant(); +} + +void AnimationNode::set_parameter(const StringName &p_name, const Variant &p_value) { + ERR_FAIL_COND(!state); + ERR_FAIL_COND(!state->tree->property_parent_map.has(base_path)); + ERR_FAIL_COND(!state->tree->property_parent_map[base_path].has(p_name)); + StringName path = state->tree->property_parent_map[base_path][p_name]; + + state->tree->property_map[path] = p_value; +} + +Variant AnimationNode::get_parameter(const StringName &p_name) const { + ERR_FAIL_COND_V(!state, Variant()); + ERR_FAIL_COND_V(!state->tree->property_parent_map.has(base_path), Variant()); + ERR_FAIL_COND_V(!state->tree->property_parent_map[base_path].has(p_name), Variant()); + + StringName path = state->tree->property_parent_map[base_path][p_name]; + return state->tree->property_map[path]; +} + +void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) { +} + void AnimationNode::blend_animation(const StringName &p_animation, float p_time, float p_delta, bool p_seeked, float p_blend) { ERR_FAIL_COND(!state); @@ -14,8 +42,8 @@ void AnimationNode::blend_animation(const StringName &p_animation, float p_time, if (animation.is_null()) { - Ref<AnimationNodeBlendTree> btree = get_parent(); - if (btree.is_valid()) { + AnimationNodeBlendTree *btree = Object::cast_to<AnimationNodeBlendTree>(parent); + if (btree) { String name = btree->get_node_name(Ref<AnimationNodeAnimation>(this)); make_invalid(vformat(RTR("In node '%s', invalid animation: '%s'."), name, p_animation)); } else { @@ -37,10 +65,20 @@ void AnimationNode::blend_animation(const StringName &p_animation, float p_time, state->animation_states.push_back(anim_state); } -float AnimationNode::_pre_process(State *p_state, float p_time, bool p_seek) { +float AnimationNode::_pre_process(const StringName &p_base_path, AnimationNode *p_parent, State *p_state, float p_time, bool p_seek, const Vector<StringName> &p_connections) { + + base_path = p_base_path; + parent = p_parent; + connections = p_connections; state = p_state; + float t = process(p_time, p_seek); + state = NULL; + parent = NULL; + base_path = StringName(); + connections.clear(); + return t; } @@ -56,39 +94,31 @@ void AnimationNode::make_invalid(const String &p_reason) { float AnimationNode::blend_input(int p_input, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize) { ERR_FAIL_INDEX_V(p_input, inputs.size(), 0); ERR_FAIL_COND_V(!state, 0); - ERR_FAIL_COND_V(!get_tree(), 0); //should not happen, but used to catch bugs - - Ref<AnimationNodeBlendTree> tree = get_parent(); - - if (!tree.is_valid() && get_tree()->get_tree_root().ptr() != this) { - make_invalid(RTR("Can't blend input because node is not in a tree")); - return 0; - } - ERR_FAIL_COND_V(!tree.is_valid(), 0); //should not happen + AnimationNodeBlendTree *blend_tree = Object::cast_to<AnimationNodeBlendTree>(parent); + ERR_FAIL_COND_V(!blend_tree, 0); - StringName anim_name = inputs[p_input].connected_to; + StringName node_name = connections[p_input]; - Ref<AnimationNode> node = tree->get_node(anim_name); - - if (node.is_null()) { - - String name = tree->get_node_name(Ref<AnimationNodeAnimation>(this)); + if (!blend_tree->has_node(node_name)) { + String name = blend_tree->get_node_name(Ref<AnimationNode>(this)); make_invalid(vformat(RTR("Nothing connected to input '%s' of node '%s'."), get_input_name(p_input), name)); return 0; } - inputs.write[p_input].last_pass = state->last_pass; + Ref<AnimationNode> node = blend_tree->get_node(node_name); - return _blend_node(node, p_time, p_seek, p_blend, p_filter, p_optimize, &inputs.write[p_input].activity); + //inputs.write[p_input].last_pass = state->last_pass; + float activity; + return _blend_node(node_name, blend_tree->get_node_connection_array(node_name), NULL, node, p_time, p_seek, p_blend, p_filter, p_optimize, &activity); } -float AnimationNode::blend_node(Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize) { +float AnimationNode::blend_node(const StringName &p_sub_path, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize) { - return _blend_node(p_node, p_time, p_seek, p_blend, p_filter, p_optimize); + return _blend_node(p_sub_path, Vector<StringName>(), this, p_node, p_time, p_seek, p_blend, p_filter, p_optimize); } -float AnimationNode::_blend_node(Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize, float *r_max) { +float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<StringName> &p_connections, AnimationNode *p_new_parent, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize, float *r_max) { ERR_FAIL_COND_V(!p_node.is_valid(), 0); ERR_FAIL_COND_V(!state, 0); @@ -189,7 +219,19 @@ float AnimationNode::_blend_node(Ref<AnimationNode> p_node, float p_time, bool p if (!p_seek && p_optimize && !any_valid) //pointless to go on, all are zero return 0; - return p_node->_pre_process(state, p_time, p_seek); + String new_path; + AnimationNode *new_parent; + + //this is the slowest part of processing, but as strings process in powers of 2, and the paths always exist, it will not result in that many allocations + if (p_new_parent) { + new_parent = p_new_parent; + new_path = String(base_path) + String(p_subpath) + "/"; + } else { + ERR_FAIL_COND_V(!parent, 0); + new_parent = parent; + new_path = String(parent->base_path) + String(p_subpath) + "/"; + } + return p_node->_pre_process(new_path, new_parent, state, p_time, p_seek, p_connections); } int AnimationNode::get_input_count() const { @@ -201,29 +243,6 @@ String AnimationNode::get_input_name(int p_input) { return inputs[p_input].name; } -float AnimationNode::get_input_activity(int p_input) const { - - ERR_FAIL_INDEX_V(p_input, inputs.size(), 0); - if (!get_tree()) - return 0; - - if (get_tree()->get_last_process_pass() != inputs[p_input].last_pass) { - return 0; - } - return inputs[p_input].activity; -} -StringName AnimationNode::get_input_connection(int p_input) { - - ERR_FAIL_INDEX_V(p_input, inputs.size(), StringName()); - return inputs[p_input].connected_to; -} - -void AnimationNode::set_input_connection(int p_input, const StringName &p_connection) { - - ERR_FAIL_INDEX(p_input, inputs.size()); - inputs.write[p_input].connected_to = p_connection; -} - String AnimationNode::get_caption() const { if (get_script_instance()) { @@ -239,8 +258,6 @@ void AnimationNode::add_input(const String &p_name) { Input input; ERR_FAIL_COND(p_name.find(".") != -1 || p_name.find("/") != -1); input.name = p_name; - input.activity = 0; - input.last_pass = 0; inputs.push_back(input); emit_changed(); } @@ -258,35 +275,6 @@ void AnimationNode::remove_input(int p_index) { emit_changed(); } -void AnimationNode::_set_parent(Object *p_parent) { - set_parent(Object::cast_to<AnimationNode>(p_parent)); -} - -void AnimationNode::set_parent(AnimationNode *p_parent) { - parent = p_parent; //do not use ref because parent contains children - if (get_script_instance()) { - get_script_instance()->call("_parent_set", p_parent); - } -} - -Ref<AnimationNode> AnimationNode::get_parent() const { - if (parent) { - return Ref<AnimationNode>(parent); - } - - return Ref<AnimationNode>(); -} - -AnimationTree *AnimationNode::get_tree() const { - - return player; -} - -AnimationPlayer *AnimationNode::get_player() const { - ERR_FAIL_COND_V(!state, NULL); - return state->player; -} - float AnimationNode::process(float p_time, bool p_seek) { if (get_script_instance()) { @@ -320,22 +308,6 @@ bool AnimationNode::has_filter() const { return false; } -void AnimationNode::set_position(const Vector2 &p_position) { - position = p_position; -} - -Vector2 AnimationNode::get_position() const { - return position; -} - -void AnimationNode::set_tree(AnimationTree *p_player) { - - if (player != NULL && p_player == NULL) { - emit_signal("removed_from_graph"); - } - player = p_player; -} - Array AnimationNode::_get_filters() const { Array paths; @@ -361,12 +333,14 @@ void AnimationNode::_validate_property(PropertyInfo &property) const { } } +Ref<AnimationNode> AnimationNode::get_child_by_name(const StringName &p_name) { + return Ref<AnimationNode>(); +} + void AnimationNode::_bind_methods() { ClassDB::bind_method(D_METHOD("get_input_count"), &AnimationNode::get_input_count); ClassDB::bind_method(D_METHOD("get_input_name", "input"), &AnimationNode::get_input_name); - ClassDB::bind_method(D_METHOD("get_input_connection", "input"), &AnimationNode::get_input_connection); - ClassDB::bind_method(D_METHOD("get_input_activity", "input"), &AnimationNode::get_input_activity); ClassDB::bind_method(D_METHOD("add_input", "name"), &AnimationNode::add_input); ClassDB::bind_method(D_METHOD("remove_input", "index"), &AnimationNode::remove_input); @@ -377,19 +351,15 @@ void AnimationNode::_bind_methods() { ClassDB::bind_method(D_METHOD("set_filter_enabled", "enable"), &AnimationNode::set_filter_enabled); ClassDB::bind_method(D_METHOD("is_filter_enabled"), &AnimationNode::is_filter_enabled); - ClassDB::bind_method(D_METHOD("set_position", "position"), &AnimationNode::set_position); - ClassDB::bind_method(D_METHOD("get_position"), &AnimationNode::get_position); - ClassDB::bind_method(D_METHOD("_set_filters", "filters"), &AnimationNode::_set_filters); ClassDB::bind_method(D_METHOD("_get_filters"), &AnimationNode::_get_filters); ClassDB::bind_method(D_METHOD("blend_animation", "animation", "time", "delta", "seeked", "blend"), &AnimationNode::blend_animation); - ClassDB::bind_method(D_METHOD("blend_node", "node", "time", "seek", "blend", "filter", "optimize"), &AnimationNode::blend_node, DEFVAL(FILTER_IGNORE), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("blend_node", "name", "node", "time", "seek", "blend", "filter", "optimize"), &AnimationNode::blend_node, DEFVAL(FILTER_IGNORE), DEFVAL(true)); ClassDB::bind_method(D_METHOD("blend_input", "input_index", "time", "seek", "blend", "filter", "optimize"), &AnimationNode::blend_input, DEFVAL(FILTER_IGNORE), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("set_parent", "parent"), &AnimationNode::_set_parent); - ClassDB::bind_method(D_METHOD("get_parent"), &AnimationNode::get_parent); - ClassDB::bind_method(D_METHOD("get_tree"), &AnimationNode::get_tree); + ClassDB::bind_method(D_METHOD("set_parameter", "name", "value"), &AnimationNode::set_parameter); + ClassDB::bind_method(D_METHOD("get_parameter", "name"), &AnimationNode::get_parameter); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_filter_enabled", "is_filter_enabled"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "filters", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_filters", "_get_filters"); @@ -397,9 +367,11 @@ void AnimationNode::_bind_methods() { BIND_VMETHOD(MethodInfo("process", PropertyInfo(Variant::REAL, "time"), PropertyInfo(Variant::BOOL, "seek"))); BIND_VMETHOD(MethodInfo(Variant::STRING, "get_caption")); BIND_VMETHOD(MethodInfo(Variant::STRING, "has_filter")); - BIND_VMETHOD(MethodInfo("_parent_set", PropertyInfo(Variant::OBJECT, "parent"))); ADD_SIGNAL(MethodInfo("removed_from_graph")); + + ADD_SIGNAL(MethodInfo("tree_changed")); + BIND_ENUM_CONSTANT(FILTER_IGNORE); BIND_ENUM_CONSTANT(FILTER_PASS); BIND_ENUM_CONSTANT(FILTER_STOP); @@ -410,8 +382,6 @@ AnimationNode::AnimationNode() { state = NULL; parent = NULL; - player = NULL; - set_local_to_scene(true); filter_enabled = false; } @@ -420,18 +390,17 @@ AnimationNode::AnimationNode() { void AnimationTree::set_tree_root(const Ref<AnimationNode> &p_root) { if (root.is_valid()) { - root->set_tree(NULL); - } - if (p_root.is_valid()) { - ERR_EXPLAIN("root node already set to another player"); - ERR_FAIL_COND(p_root->player); + root->disconnect("tree_changed", this, "_tree_changed"); } + root = p_root; if (root.is_valid()) { - root->set_tree(this); + root->connect("tree_changed", this, "_tree_changed"); } + properties_dirty = true; + update_configuration_warning(); } @@ -699,7 +668,10 @@ void AnimationTree::_clear_caches() { void AnimationTree::_process_graph(float p_delta) { + _update_properties(); //if properties need updating, update them + //check all tracks, see if they need modification + root_motion_transform = Transform(); if (!root.is_valid()) { @@ -741,6 +713,7 @@ void AnimationTree::_process_graph(float p_delta) { state.valid = true; state.player = player; state.last_pass = process_pass; + state.tree = this; // root source blends @@ -757,11 +730,11 @@ void AnimationTree::_process_graph(float p_delta) { if (started) { //if started, seek - root->_pre_process(&state, 0, true); + root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, NULL, &state, 0, true, Vector<StringName>()); started = false; } - root->_pre_process(&state, p_delta, false); + root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, NULL, &state, p_delta, false, Vector<StringName>()); } if (!state.valid) { @@ -1297,6 +1270,116 @@ Transform AnimationTree::get_root_motion_transform() const { return root_motion_transform; } +void AnimationTree::_tree_changed() { + if (properties_dirty) { + return; + } + + call_deferred("_update_properties"); + properties_dirty = true; +} + +void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref<AnimationNode> node) { + + if (!property_parent_map.has(p_base_path)) { + property_parent_map[p_base_path] = HashMap<StringName, StringName>(); + } + + List<PropertyInfo> plist; + node->get_parameter_list(&plist); + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { + PropertyInfo pinfo = E->get(); + + StringName key = pinfo.name; + + if (!property_map.has(p_base_path + key)) { + property_map[p_base_path + key] = node->get_parameter_default_value(key); + } + + property_parent_map[p_base_path][key] = p_base_path + key; + + pinfo.name = p_base_path + key; + properties.push_back(pinfo); + } + + List<AnimationNode::ChildNode> children; + node->get_child_nodes(&children); + + for (List<AnimationNode::ChildNode>::Element *E = children.front(); E; E = E->next()) { + _update_properties_for_node(p_base_path + E->get().name + "/", E->get().node); + } +} + +void AnimationTree::_update_properties() { + if (!properties_dirty) { + return; + } + + properties.clear(); + property_parent_map.clear(); + + if (root.is_valid()) { + _update_properties_for_node(SceneStringNames::get_singleton()->parameters_base_path, root); + } + + properties_dirty = false; + + _change_notify(); +} + +bool AnimationTree::_set(const StringName &p_name, const Variant &p_value) { + if (properties_dirty) { + _update_properties(); + } + + if (property_map.has(p_name)) { + property_map[p_name] = p_value; +#ifdef TOOLS_ENABLED + _change_notify(p_name.operator String().utf8().get_data()); +#endif + return true; + } + + return false; +} + +bool AnimationTree::_get(const StringName &p_name, Variant &r_ret) const { + if (properties_dirty) { + const_cast<AnimationTree *>(this)->_update_properties(); + } + + if (property_map.has(p_name)) { + r_ret = property_map[p_name]; + return true; + } + + return false; +} +void AnimationTree::_get_property_list(List<PropertyInfo> *p_list) const { + if (properties_dirty) { + const_cast<AnimationTree *>(this)->_update_properties(); + } + + for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { + p_list->push_back(E->get()); + } +} + +void AnimationTree::rename_parameter(const String &p_base, const String &p_new_base) { + + //rename values first + for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { + if (E->get().name.begins_with(p_base)) { + String new_name = E->get().name.replace_first(p_base, p_new_base); + property_map[new_name] = property_map[E->get().name]; + } + } + + //update tree second + properties_dirty = true; + _update_properties(); +} + void AnimationTree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_active", "active"), &AnimationTree::set_active); ClassDB::bind_method(D_METHOD("is_active"), &AnimationTree::is_active); @@ -1315,11 +1398,16 @@ void AnimationTree::_bind_methods() { ClassDB::bind_method(D_METHOD("get_root_motion_transform"), &AnimationTree::get_root_motion_transform); + ClassDB::bind_method(D_METHOD("_tree_changed"), &AnimationTree::_tree_changed); + ClassDB::bind_method(D_METHOD("_update_properties"), &AnimationTree::_update_properties); + + ClassDB::bind_method(D_METHOD("rename_parameter", "old_name", "new_name"), &AnimationTree::rename_parameter); + ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationTree::advance); ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationTree::_node_removed); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tree_root", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "set_tree_root", "get_tree_root"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tree_root", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode"), "set_tree_root", "get_tree_root"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "anim_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_animation_player", "get_animation_player"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "is_active"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_process_mode", "get_process_mode"); @@ -1338,10 +1426,8 @@ AnimationTree::AnimationTree() { cache_valid = false; setup_pass = 1; started = true; + properties_dirty = true; } AnimationTree::~AnimationTree() { - if (root.is_valid()) { - root->player = NULL; - } } diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h index 87092a4a0e..3c615b2f92 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -23,9 +23,6 @@ public: struct Input { String name; - StringName connected_to; - float activity; - uint64_t last_pass; }; Vector<Input> inputs; @@ -51,30 +48,33 @@ public: List<AnimationState> animation_states; bool valid; AnimationPlayer *player; + AnimationTree *tree; String invalid_reasons; uint64_t last_pass; }; Vector<float> blends; State *state; - float _pre_process(State *p_state, float p_time, bool p_seek); + String path; + float _pre_process(const StringName &p_base_path, AnimationNode *p_parent, State *p_state, float p_time, bool p_seek, const Vector<StringName> &p_connections); void _pre_update_animations(HashMap<NodePath, int> *track_map); - Vector2 position; + //all this is temporary + StringName base_path; + Vector<StringName> connections; AnimationNode *parent; - AnimationTree *player; - - float _blend_node(Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true, float *r_max = NULL); HashMap<NodePath, bool> filter; bool filter_enabled; Array _get_filters() const; void _set_filters(const Array &p_filters); + friend class AnimationNodeBlendTree; + float _blend_node(const StringName &p_subpath, const Vector<StringName> &p_connections, AnimationNode *p_new_parent, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true, float *r_max = NULL); protected: void blend_animation(const StringName &p_animation, float p_time, float p_delta, bool p_seeked, float p_blend); - float blend_node(Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true); + float blend_node(const StringName &p_sub_path, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true); float blend_input(int p_input, float p_time, bool p_seek, float p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true); void make_invalid(const String &p_reason); @@ -85,20 +85,24 @@ protected: void _set_parent(Object *p_parent); public: - void set_parent(AnimationNode *p_parent); - Ref<AnimationNode> get_parent() const; - virtual void set_tree(AnimationTree *p_player); - AnimationTree *get_tree() const; - AnimationPlayer *get_player() const; + virtual void get_parameter_list(List<PropertyInfo> *r_list) const; + virtual Variant get_parameter_default_value(const StringName &p_parameter) const; + + void set_parameter(const StringName &p_name, const Variant &p_value); + Variant get_parameter(const StringName &p_name) const; + + struct ChildNode { + StringName name; + Ref<AnimationNode> node; + }; + + virtual void get_child_nodes(List<ChildNode> *r_child_nodes); virtual float process(float p_time, bool p_seek); virtual String get_caption() const; int get_input_count() const; String get_input_name(int p_input); - StringName get_input_connection(int p_input); - void set_input_connection(int p_input, const StringName &p_connection); - float get_input_activity(int p_input) const; void add_input(const String &p_name); void set_input_name(int p_input, const String &p_name); @@ -112,8 +116,7 @@ public: virtual bool has_filter() const; - void set_position(const Vector2 &p_position); - Vector2 get_position() const; + virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name); AnimationNode(); }; @@ -245,7 +248,21 @@ private: NodePath root_motion_track; Transform root_motion_transform; + friend class AnimationNode; + bool properties_dirty; + void _tree_changed(); + void _update_properties(); + List<PropertyInfo> properties; + HashMap<StringName, HashMap<StringName, StringName> > property_parent_map; + HashMap<StringName, Variant> property_map; + + void _update_properties_for_node(const String &p_base_path, Ref<AnimationNode> node); + protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; + void _notification(int p_what); static void _bind_methods(); @@ -274,6 +291,8 @@ public: void advance(float p_time); + void rename_parameter(const String &p_base, const String &p_new_base); + uint64_t get_last_process_pass() const; AnimationTree(); ~AnimationTree(); diff --git a/scene/animation/skeleton_ik.cpp b/scene/animation/skeleton_ik.cpp index 4991cedfab..9b1cb1369a 100644 --- a/scene/animation/skeleton_ik.cpp +++ b/scene/animation/skeleton_ik.cpp @@ -34,6 +34,8 @@ #include "skeleton_ik.h" +#ifndef _3D_DISABLED + FabrikInverseKinematic::ChainItem *FabrikInverseKinematic::ChainItem::find_child(const BoneId p_bone_id) { for (int i = childs.size() - 1; 0 <= i; --i) { if (p_bone_id == childs[i].bone) { @@ -549,3 +551,5 @@ void SkeletonIK::_solve_chain() { return; FabrikInverseKinematic::solve(task, interpolation, use_magnet, magnet_position); } + +#endif // _3D_DISABLED diff --git a/scene/animation/skeleton_ik.h b/scene/animation/skeleton_ik.h index 366c599c01..08fb00e798 100644 --- a/scene/animation/skeleton_ik.h +++ b/scene/animation/skeleton_ik.h @@ -31,6 +31,8 @@ #ifndef SKELETON_IK_H #define SKELETON_IK_H +#ifndef _3D_DISABLED + /** * @author AndreaCatania */ @@ -209,4 +211,6 @@ private: void _solve_chain(); }; +#endif // _3D_DISABLED + #endif // SKELETON_IK_H diff --git a/scene/audio/audio_player.cpp b/scene/audio/audio_player.cpp index 863b278b62..7a9f2bd8d0 100644 --- a/scene/audio/audio_player.cpp +++ b/scene/audio/audio_player.cpp @@ -192,6 +192,7 @@ float AudioStreamPlayer::get_volume_db() const { } void AudioStreamPlayer::set_pitch_scale(float p_pitch_scale) { + ERR_FAIL_COND(p_pitch_scale <= 0.0); pitch_scale = p_pitch_scale; } float AudioStreamPlayer::get_pitch_scale() const { diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 25cb74a494..635f812805 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -582,7 +582,8 @@ void FileDialog::set_current_file(const String &p_file) { int lp = p_file.find_last("."); if (lp != -1) { file->select(0, lp); - file->grab_focus(); + if (file->is_inside_tree()) + file->grab_focus(); } } void FileDialog::set_current_path(const String &p_path) { diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp index 749efe8364..e82c0c4ad1 100644 --- a/scene/gui/gradient_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -147,7 +147,6 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { grabbed = _get_point_from_pos(x); //grab or select if (grabbed != -1) { - grabbed = false; return; } diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index d95ec9e495..a7163adbe6 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -356,14 +356,14 @@ bool GraphEdit::_filter_input(const Point2 &p_point) { for (int j = 0; j < gn->get_connection_output_count(); j++) { Vector2 pos = gn->get_connection_output_position(j) + gn->get_position(); - if (create_hot_zone(pos).has_point(p_point)) + if (is_in_hot_zone(pos, p_point)) return true; } for (int j = 0; j < gn->get_connection_input_count(); j++) { Vector2 pos = gn->get_connection_input_position(j) + gn->get_position(); - if (create_hot_zone(pos).has_point(p_point)) { + if (is_in_hot_zone(pos, p_point)) { return true; } } @@ -388,7 +388,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { for (int j = 0; j < gn->get_connection_output_count(); j++) { Vector2 pos = gn->get_connection_output_position(j) + gn->get_position(); - if (create_hot_zone(pos).has_point(mpos)) { + if (is_in_hot_zone(pos, mpos)) { if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) { //check disconnect @@ -435,7 +435,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { for (int j = 0; j < gn->get_connection_input_count(); j++) { Vector2 pos = gn->get_connection_input_position(j) + gn->get_position(); - if (create_hot_zone(pos).has_point(mpos)) { + if (is_in_hot_zone(pos, mpos)) { if (right_disconnects || valid_right_disconnect_types.has(gn->get_connection_input_type(j))) { //check disconnect @@ -502,7 +502,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { Vector2 pos = gn->get_connection_output_position(j) + gn->get_position(); int type = gn->get_connection_output_type(j); - if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && create_hot_zone(pos).has_point(mpos)) { + if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos, mpos)) { connecting_target = true; connecting_to = pos; @@ -517,7 +517,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { Vector2 pos = gn->get_connection_input_position(j) + gn->get_position(); int type = gn->get_connection_input_type(j); - if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && create_hot_zone(pos).has_point(mpos)) { + if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos, mpos)) { connecting_target = true; connecting_to = pos; connecting_target_to = gn->get_name(); @@ -557,8 +557,55 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { } } -Rect2 GraphEdit::create_hot_zone(const Vector2 &pos) { - return Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2); +bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos) { + + if (p_control->is_set_as_toplevel() || !p_control->is_visible()) + return false; + + if (!p_control->has_point(pos) || p_control->get_mouse_filter() == MOUSE_FILTER_IGNORE) { + //test children + for (int i = 0; i < p_control->get_child_count(); i++) { + Control *subchild = Object::cast_to<Control>(p_control->get_child(i)); + if (!subchild) + continue; + if (_check_clickable_control(subchild, pos - subchild->get_position())) { + return true; + } + } + + return false; + } else { + return true; + } +} + +bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) { + if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos)) + return false; + + for (int i = 0; i < get_child_count(); i++) { + Control *child = Object::cast_to<Control>(get_child(i)); + if (!child) + continue; + Rect2 rect = child->get_rect(); + if (rect.has_point(p_mouse_pos)) { + + //check sub-controls + Vector2 subpos = p_mouse_pos - rect.position; + + for (int j = 0; j < child->get_child_count(); j++) { + Control *subchild = Object::cast_to<Control>(child->get_child(j)); + if (!subchild) + continue; + + if (_check_clickable_control(subchild, subpos - subchild->get_position())) { + return false; + } + } + } + } + + return true; } template <class Vector2> diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index 64ba18681e..31a449eb59 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -131,7 +131,7 @@ private: GraphEditFilter *top_layer; void _top_layer_input(const Ref<InputEvent> &p_ev); - Rect2 create_hot_zone(const Vector2 &pos); + bool is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos); void _top_layer_draw(); void _connections_layer_draw(); @@ -172,6 +172,8 @@ private: void _snap_toggled(); void _snap_value_changed(double); + bool _check_clickable_control(Control *p_control, const Vector2 &pos); + protected: static void _bind_methods(); virtual void add_child_notify(Node *p_child); diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index a2e890e7a7..c044443b51 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "canvas_layer.h" +#include "scene/2d/canvas_item.h" #include "viewport.h" void CanvasLayer::set_layer(int p_xform) { @@ -62,6 +63,24 @@ void CanvasLayer::_update_xform() { transform.set_origin(ofs); if (viewport.is_valid()) VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); + + if (!is_inside_tree()) + return; + + _notify_xform(this); +} + +void CanvasLayer::_notify_xform(Node *p_node) { + + for (int i = 0; i < p_node->get_child_count(); i++) { + + CanvasItem *ci = Object::cast_to<CanvasItem>(p_node->get_child(i)); + if (ci) { + ci->_notify_transform(ci); + } else { + _notify_xform(p_node->get_child(i)); + } + } } void CanvasLayer::_update_locrotscale() { diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h index aae23fbb12..fd347c4739 100644 --- a/scene/main/canvas_layer.h +++ b/scene/main/canvas_layer.h @@ -56,6 +56,7 @@ class CanvasLayer : public Node { int sort_index; void _update_xform(); + void _notify_xform(Node *p_node); void _update_locrotscale(); protected: diff --git a/scene/main/node.cpp b/scene/main/node.cpp index d6a80bfb1a..f6905e7c2e 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -240,7 +240,7 @@ void Node::_propagate_enter_tree() { void Node::_propagate_exit_tree() { -//block while removing children + //block while removing children #ifdef DEBUG_ENABLED diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index e43c2da02d..f92b6e7583 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -444,7 +444,7 @@ void Viewport::_notification(int p_what) { Vector2 point = get_canvas_transform().affine_inverse().xform(pos); Physics2DDirectSpaceState::ShapeResult res[64]; - int rc = ss2d->intersect_point(point, res, 64, Set<RID>(), 0xFFFFFFFF, true); + int rc = ss2d->intersect_point(point, res, 64, Set<RID>(), 0xFFFFFFFF, true, true, true); for (int i = 0; i < rc; i++) { if (res[i].collider_id && res[i].collider) { @@ -527,7 +527,7 @@ void Viewport::_notification(int p_what) { PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); if (space) { - bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, true); + bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, true, true, true); ObjectID new_collider = 0; if (col) { @@ -563,7 +563,7 @@ void Viewport::_notification(int p_what) { PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); if (space) { - bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, true); + bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, true, true, true); ObjectID new_collider = 0; if (col) { CollisionObject *co = Object::cast_to<CollisionObject>(result.collider); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 382bddfb4e..da4e2f991d 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -51,7 +51,6 @@ #include "scene/2d/parallax_background.h" #include "scene/2d/parallax_layer.h" #include "scene/2d/particles_2d.h" - #include "scene/2d/path_2d.h" #include "scene/2d/physics_body_2d.h" #include "scene/2d/polygon_2d.h" @@ -201,6 +200,7 @@ #include "scene/3d/room_instance.h" #include "scene/3d/skeleton.h" #include "scene/3d/soft_body.h" +#include "scene/3d/spring_arm.h" #include "scene/3d/sprite_3d.h" #include "scene/3d/vehicle_body.h" #include "scene/3d/visibility_notifier.h" @@ -366,17 +366,16 @@ void register_scene_types() { ClassDB::register_class<Spatial>(); ClassDB::register_virtual_class<SpatialGizmo>(); ClassDB::register_class<Skeleton>(); - ClassDB::register_class<SkeletonIK>(); ClassDB::register_class<AnimationPlayer>(); ClassDB::register_class<Tween>(); OS::get_singleton()->yield(); //may take time to init #ifndef _3D_DISABLED - ClassDB::register_class<BoneAttachment>(); ClassDB::register_virtual_class<VisualInstance>(); ClassDB::register_virtual_class<GeometryInstance>(); ClassDB::register_class<Camera>(); + ClassDB::register_class<ClippedCamera>(); ClassDB::register_class<Listener>(); ClassDB::register_class<ARVRCamera>(); ClassDB::register_class<ARVRController>(); @@ -415,6 +414,8 @@ void register_scene_types() { ClassDB::register_class<AnimationNodeBlendSpace1D>(); ClassDB::register_class<AnimationNodeBlendSpace2D>(); ClassDB::register_class<AnimationNodeStateMachine>(); + ClassDB::register_class<AnimationNodeStateMachinePlayback>(); + ClassDB::register_class<AnimationNodeStateMachineTransition>(); ClassDB::register_class<AnimationNodeOutput>(); ClassDB::register_class<AnimationNodeOneShot>(); @@ -435,9 +436,14 @@ void register_scene_types() { ClassDB::register_class<RigidBody>(); ClassDB::register_class<KinematicCollision>(); ClassDB::register_class<KinematicBody>(); + ClassDB::register_class<SpringArm>(); + ClassDB::register_class<PhysicalBone>(); ClassDB::register_class<SoftBody>(); + ClassDB::register_class<SkeletonIK>(); + ClassDB::register_class<BoneAttachment>(); + ClassDB::register_class<VehicleBody>(); ClassDB::register_class<VehicleWheel>(); ClassDB::register_class<Area>(); diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 875b72159a..d4e16d488b 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -34,6 +34,8 @@ void Material::set_next_pass(const Ref<Material> &p_pass) { + ERR_FAIL_COND(p_pass == this); + if (next_pass == p_pass) return; @@ -398,8 +400,10 @@ void SpatialMaterial::_update_shader() { if (flags[FLAG_USE_VERTEX_LIGHTING]) { code += ",vertex_lighting"; } + bool using_world = false; if (flags[FLAG_TRIPLANAR_USE_WORLD] && (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR])) { code += ",world_vertex_coords"; + using_world = true; } if (flags[FLAG_DONT_RECEIVE_SHADOWS]) { code += ",shadows_disabled"; @@ -423,7 +427,7 @@ void SpatialMaterial::_update_shader() { if (proximity_fade_enabled) { code += "uniform float proximity_fade_distance;\n"; } - if (distance_fade_enabled) { + if (distance_fade != DISTANCE_FADE_DISABLED) { code += "uniform float distance_fade_min;\n"; code += "uniform float distance_fade_max;\n"; } @@ -782,7 +786,7 @@ void SpatialMaterial::_update_shader() { code += "\tALBEDO *= 1.0 - ref_amount;\n"; code += "\tALPHA = 1.0;\n"; - } else if (features[FEATURE_TRANSPARENT] || flags[FLAG_USE_ALPHA_SCISSOR] || distance_fade_enabled || proximity_fade_enabled) { + } else if (features[FEATURE_TRANSPARENT] || flags[FLAG_USE_ALPHA_SCISSOR] || (distance_fade == DISTANCE_FADE_PIXEL_ALPHA) || proximity_fade_enabled) { code += "\tALPHA = albedo.a * albedo_tex.a;\n"; } @@ -793,8 +797,47 @@ void SpatialMaterial::_update_shader() { code += "\tALPHA*=clamp(1.0-smoothstep(world_pos.z+proximity_fade_distance,world_pos.z,VERTEX.z),0.0,1.0);\n"; } - if (distance_fade_enabled) { - code += "\tALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n"; + if (distance_fade != DISTANCE_FADE_DISABLED) { + if (distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER) { + + code += "\t{\n"; + if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) { + code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n"; + + } else { + code += "\t\tfloat fade_distance=-VERTEX.z;\n"; + } + + code += "\t\tfloat fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n"; + code += "\t\tint x = int(FRAGCOORD.x) % 4;\n"; + code += "\t\tint y = int(FRAGCOORD.y) % 4;\n"; + code += "\t\tint index = x + y * 4;\n"; + code += "\t\tfloat limit = 0.0;\n\n"; + code += "\t\tif (x < 8) {\n"; + code += "\t\t\tif (index == 0) limit = 0.0625;\n"; + code += "\t\t\tif (index == 1) limit = 0.5625;\n"; + code += "\t\t\tif (index == 2) limit = 0.1875;\n"; + code += "\t\t\tif (index == 3) limit = 0.6875;\n"; + code += "\t\t\tif (index == 4) limit = 0.8125;\n"; + code += "\t\t\tif (index == 5) limit = 0.3125;\n"; + code += "\t\t\tif (index == 6) limit = 0.9375;\n"; + code += "\t\t\tif (index == 7) limit = 0.4375;\n"; + code += "\t\t\tif (index == 8) limit = 0.25;\n"; + code += "\t\t\tif (index == 9) limit = 0.75;\n"; + code += "\t\t\tif (index == 10) limit = 0.125;\n"; + code += "\t\t\tif (index == 11) limit = 0.625;\n"; + code += "\t\t\tif (index == 12) limit = 1.0;\n"; + code += "\t\t\tif (index == 13) limit = 0.5;\n"; + code += "\t\t\tif (index == 14) limit = 0.875;\n"; + code += "\t\t\tif (index == 15) limit = 0.375;\n"; + code += "\t\t}\n\n"; + code += "\tif (fade < limit)\n"; + code += "\t\tdiscard;\n"; + code += "\t}\n\n"; + + } else { + code += "\tALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n"; + } } if (features[FEATURE_RIM]) { @@ -1324,7 +1367,7 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const { property.usage = 0; } - if ((property.name == "distance_fade_max_distance" || property.name == "distance_fade_min_distance") && !distance_fade_enabled) { + if ((property.name == "distance_fade_max_distance" || property.name == "distance_fade_min_distance") && distance_fade == DISTANCE_FADE_DISABLED) { property.usage = 0; } @@ -1645,15 +1688,15 @@ float SpatialMaterial::get_proximity_fade_distance() const { return proximity_fade_distance; } -void SpatialMaterial::set_distance_fade(bool p_enable) { +void SpatialMaterial::set_distance_fade(DistanceFadeMode p_mode) { - distance_fade_enabled = p_enable; + distance_fade = p_mode; _queue_shader_change(); _change_notify(); } -bool SpatialMaterial::is_distance_fade_enabled() const { +SpatialMaterial::DistanceFadeMode SpatialMaterial::get_distance_fade() const { - return distance_fade_enabled; + return distance_fade; } void SpatialMaterial::set_distance_fade_max_distance(float p_distance) { @@ -1859,8 +1902,8 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_proximity_fade_distance", "distance"), &SpatialMaterial::set_proximity_fade_distance); ClassDB::bind_method(D_METHOD("get_proximity_fade_distance"), &SpatialMaterial::get_proximity_fade_distance); - ClassDB::bind_method(D_METHOD("set_distance_fade", "enabled"), &SpatialMaterial::set_distance_fade); - ClassDB::bind_method(D_METHOD("is_distance_fade_enabled"), &SpatialMaterial::is_distance_fade_enabled); + ClassDB::bind_method(D_METHOD("set_distance_fade", "mode"), &SpatialMaterial::set_distance_fade); + ClassDB::bind_method(D_METHOD("get_distance_fade"), &SpatialMaterial::get_distance_fade); ClassDB::bind_method(D_METHOD("set_distance_fade_max_distance", "distance"), &SpatialMaterial::set_distance_fade_max_distance); ClassDB::bind_method(D_METHOD("get_distance_fade_max_distance"), &SpatialMaterial::get_distance_fade_max_distance); @@ -2003,7 +2046,7 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "proximity_fade_enable"), "set_proximity_fade", "is_proximity_fade_enabled"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "proximity_fade_distance", PROPERTY_HINT_RANGE, "0,4096,0.1"), "set_proximity_fade_distance", "get_proximity_fade_distance"); ADD_GROUP("Distance Fade", "distance_fade_"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "distance_fade_enable"), "set_distance_fade", "is_distance_fade_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "distance_fade_mode", PROPERTY_HINT_ENUM, "Disabled,PixelAlpha,PixelDither,ObjectDither"), "set_distance_fade", "get_distance_fade"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "distance_fade_min_distance", PROPERTY_HINT_RANGE, "0,4096,0.1"), "set_distance_fade_min_distance", "get_distance_fade_min_distance"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "distance_fade_max_distance", PROPERTY_HINT_RANGE, "0,4096,0.1"), "set_distance_fade_max_distance", "get_distance_fade_max_distance"); @@ -2101,6 +2144,11 @@ void SpatialMaterial::_bind_methods() { BIND_ENUM_CONSTANT(EMISSION_OP_ADD); BIND_ENUM_CONSTANT(EMISSION_OP_MULTIPLY); + + BIND_ENUM_CONSTANT(DISTANCE_FADE_DISABLED); + BIND_ENUM_CONSTANT(DISTANCE_FADE_PIXEL_ALPHA); + BIND_ENUM_CONSTANT(DISTANCE_FADE_PIXEL_DITHER); + BIND_ENUM_CONSTANT(DISTANCE_FADE_OBJECT_DITHER); } SpatialMaterial::SpatialMaterial() : @@ -2139,7 +2187,7 @@ SpatialMaterial::SpatialMaterial() : emission_op = EMISSION_OP_ADD; proximity_fade_enabled = false; - distance_fade_enabled = false; + distance_fade = DISTANCE_FADE_DISABLED; set_proximity_fade_distance(1); set_distance_fade_min_distance(0); set_distance_fade_max_distance(10); diff --git a/scene/resources/material.h b/scene/resources/material.h index 7a1a4acfbf..f43d240a53 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -233,6 +233,13 @@ public: EMISSION_OP_MULTIPLY }; + enum DistanceFadeMode { + DISTANCE_FADE_DISABLED, + DISTANCE_FADE_PIXEL_ALPHA, + DISTANCE_FADE_PIXEL_DITHER, + DISTANCE_FADE_OBJECT_DITHER, + }; + private: union MaterialKey { @@ -251,7 +258,7 @@ private: uint64_t billboard_mode : 2; uint64_t grow : 1; uint64_t proximity_fade : 1; - uint64_t distance_fade : 1; + uint64_t distance_fade : 2; uint64_t emission_op : 1; }; @@ -296,7 +303,7 @@ private: mk.deep_parallax = deep_parallax ? 1 : 0; mk.grow = grow_enabled; mk.proximity_fade = proximity_fade_enabled; - mk.distance_fade = distance_fade_enabled; + mk.distance_fade = distance_fade; mk.emission_op = emission_op; return mk; @@ -402,7 +409,7 @@ private: bool proximity_fade_enabled; float proximity_fade_distance; - bool distance_fade_enabled; + DistanceFadeMode distance_fade; float distance_fade_max_distance; float distance_fade_min_distance; @@ -583,8 +590,8 @@ public: void set_proximity_fade_distance(float p_distance); float get_proximity_fade_distance() const; - void set_distance_fade(bool p_enable); - bool is_distance_fade_enabled() const; + void set_distance_fade(DistanceFadeMode p_mode); + DistanceFadeMode get_distance_fade() const; void set_distance_fade_max_distance(float p_distance); float get_distance_fade_max_distance() const; @@ -630,6 +637,7 @@ VARIANT_ENUM_CAST(SpatialMaterial::SpecularMode) VARIANT_ENUM_CAST(SpatialMaterial::BillboardMode) VARIANT_ENUM_CAST(SpatialMaterial::TextureChannel) VARIANT_ENUM_CAST(SpatialMaterial::EmissionOperator) +VARIANT_ENUM_CAST(SpatialMaterial::DistanceFadeMode) ////////////////////// diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 4e6004709e..dcd87a2a61 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -1334,7 +1334,7 @@ void ArrayMesh::_bind_methods() { ClassDB::set_method_flags(get_class_static(), _scs_create("center_geometry"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); ClassDB::bind_method(D_METHOD("regen_normalmaps"), &ArrayMesh::regen_normalmaps); ClassDB::set_method_flags(get_class_static(), _scs_create("regen_normalmaps"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); - ClassDB::bind_method(D_METHOD("lightmap_unwrap"), &ArrayMesh::lightmap_unwrap); + ClassDB::bind_method(D_METHOD("lightmap_unwrap", "transform", "texel_size"), &ArrayMesh::lightmap_unwrap); ClassDB::set_method_flags(get_class_static(), _scs_create("lightmap_unwrap"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); ClassDB::bind_method(D_METHOD("get_faces"), &ArrayMesh::get_faces); ClassDB::bind_method(D_METHOD("generate_triangle_mesh"), &ArrayMesh::generate_triangle_mesh); diff --git a/scene/resources/physics_material.h b/scene/resources/physics_material.h index dfe48d94cf..c69e44a7da 100644 --- a/scene/resources/physics_material.h +++ b/scene/resources/physics_material.h @@ -37,7 +37,7 @@ class PhysicsMaterial : public Resource { GDCLASS(PhysicsMaterial, Resource); OBJ_SAVE_TYPE(PhysicsMaterial); - RES_BASE_EXTENSION("PhyMat"); + RES_BASE_EXTENSION("phymat"); real_t friction; bool rough; diff --git a/scene/resources/shape.cpp b/scene/resources/shape.cpp index 418d8ce819..a48ce0564b 100644 --- a/scene/resources/shape.cpp +++ b/scene/resources/shape.cpp @@ -50,6 +50,15 @@ void Shape::add_vertices_to_array(PoolVector<Vector3> &array, const Transform &p } } +real_t Shape::get_margin() const { + return margin; +} + +void Shape::set_margin(real_t p_margin) { + margin = p_margin; + PhysicsServer::get_singleton()->shape_set_margin(shape, margin); +} + Ref<ArrayMesh> Shape::get_debug_mesh() { if (debug_mesh_cache.is_valid()) @@ -87,12 +96,22 @@ Ref<ArrayMesh> Shape::get_debug_mesh() { return debug_mesh_cache; } -Shape::Shape() { +void Shape::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_margin", "margin"), &Shape::set_margin); + ClassDB::bind_method(D_METHOD("get_margin"), &Shape::get_margin); + + ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin", PROPERTY_HINT_RANGE, "0.04,10,0.01"), "set_margin", "get_margin"); +} + +Shape::Shape() : + margin(0.04) { ERR_PRINT("Constructor must not be called!"); } -Shape::Shape(RID p_shape) { +Shape::Shape(RID p_shape) : + margin(0.04) { shape = p_shape; } diff --git a/scene/resources/shape.h b/scene/resources/shape.h index ad87a69679..0c44b86e92 100644 --- a/scene/resources/shape.h +++ b/scene/resources/shape.h @@ -40,10 +40,13 @@ class Shape : public Resource { OBJ_SAVE_TYPE(Shape); RES_BASE_EXTENSION("shape"); RID shape; + real_t margin; Ref<ArrayMesh> debug_mesh_cache; protected: + static void _bind_methods(); + _FORCE_INLINE_ RID get_shape() const { return shape; } Shape(RID p_shape); @@ -55,6 +58,9 @@ public: void add_vertices_to_array(PoolVector<Vector3> &array, const Transform &p_xform); + real_t get_margin() const; + void set_margin(real_t p_margin); + Shape(); ~Shape(); }; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 96edb17eea..d8efbeba17 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -1990,7 +1990,7 @@ void TextureLayered::_bind_methods() { ClassDB::bind_method(D_METHOD("create", "width", "height", "depth", "format", "flags"), &TextureLayered::create, DEFVAL(FLAGS_DEFAULT)); ClassDB::bind_method(D_METHOD("set_layer_data", "image", "layer"), &TextureLayered::set_layer_data); - ClassDB::bind_method(D_METHOD("get_layer_data", "layer"), &TextureLayered::set_layer_data); + ClassDB::bind_method(D_METHOD("get_layer_data", "layer"), &TextureLayered::get_layer_data); ClassDB::bind_method(D_METHOD("set_data_partial", "image", "x_offset", "y_offset", "layer", "mipmap"), &TextureLayered::set_data_partial, DEFVAL(0)); ClassDB::bind_method(D_METHOD("_set_data", "data"), &TextureLayered::_set_data); diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index 661606c7ef..e468b3dab4 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -201,4 +201,6 @@ SceneStringNames::SceneStringNames() { } _mesh_changed = StaticCString::create("_mesh_changed"); + + parameters_base_path = "parameters/"; } diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index 817158f9f3..dbbcf79b9f 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -203,6 +203,8 @@ public: StringName output; + StringName parameters_base_path; + enum { MAX_MATERIALS = 32 }; diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index ddd0a0db6b..c6d1217308 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -305,9 +305,9 @@ Ref<AudioEffectInstance> AudioEffectPitchShift::instance() { return ins; } -void AudioEffectPitchShift::set_pitch_scale(float p_adjust) { - - pitch_scale = p_adjust; +void AudioEffectPitchShift::set_pitch_scale(float p_pitch_scale) { + ERR_FAIL_COND(p_pitch_scale <= 0.0); + pitch_scale = p_pitch_scale; } float AudioEffectPitchShift::get_pitch_scale() const { diff --git a/servers/audio/effects/audio_effect_pitch_shift.h b/servers/audio/effects/audio_effect_pitch_shift.h index f1c78d752f..78f92a0261 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.h +++ b/servers/audio/effects/audio_effect_pitch_shift.h @@ -100,7 +100,7 @@ protected: public: Ref<AudioEffectInstance> instance(); - void set_pitch_scale(float p_adjust); + void set_pitch_scale(float p_pitch_scale); float get_pitch_scale() const; AudioEffectPitchShift(); diff --git a/servers/audio/effects/audio_effect_record.cpp b/servers/audio/effects/audio_effect_record.cpp index 74a6838d1a..78ba658ed8 100644 --- a/servers/audio/effects/audio_effect_record.cpp +++ b/servers/audio/effects/audio_effect_record.cpp @@ -233,7 +233,7 @@ Ref<AudioStreamSample> AudioEffectRecord::get_recording() const { w[i * 2 + 1] = rr[i]; } } else { - ERR_EXPLAIN("format not implemented"); + ERR_PRINT("Format not implemented."); } Ref<AudioStreamSample> sample; diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index f3934e5c01..b737f4681d 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -1281,11 +1281,11 @@ void AudioServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_mix_rate"), &AudioServer::get_mix_rate); ClassDB::bind_method(D_METHOD("get_device_list"), &AudioServer::get_device_list); ClassDB::bind_method(D_METHOD("get_device"), &AudioServer::get_device); - ClassDB::bind_method(D_METHOD("set_device"), &AudioServer::set_device); + ClassDB::bind_method(D_METHOD("set_device", "device"), &AudioServer::set_device); ClassDB::bind_method(D_METHOD("capture_get_device_list"), &AudioServer::capture_get_device_list); ClassDB::bind_method(D_METHOD("capture_get_device"), &AudioServer::capture_get_device); - ClassDB::bind_method(D_METHOD("capture_set_device"), &AudioServer::capture_set_device); + ClassDB::bind_method(D_METHOD("capture_set_device", "name"), &AudioServer::capture_set_device); ClassDB::bind_method(D_METHOD("set_bus_layout", "bus_layout"), &AudioServer::set_bus_layout); ClassDB::bind_method(D_METHOD("generate_bus_layout"), &AudioServer::generate_bus_layout); diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 3a32c46a9b..472283833e 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -124,6 +124,13 @@ Variant PhysicsServerSW::shape_get_data(RID p_shape) const { return shape->get_data(); }; +void PhysicsServerSW::shape_set_margin(RID p_shape, real_t p_margin) { +} + +real_t PhysicsServerSW::shape_get_margin(RID p_shape) const { + return 0.0; +} + real_t PhysicsServerSW::shape_get_custom_solver_bias(RID p_shape) const { const ShapeSW *shape = shape_owner.get(p_shape); @@ -292,6 +299,7 @@ void PhysicsServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) { area->set_shape(p_shape_idx, shape); } + void PhysicsServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) { AreaSW *area = area_owner.get(p_area); @@ -941,7 +949,19 @@ bool PhysicsServerSW::body_is_ray_pickable(RID p_body) const { return body->is_ray_pickable(); } -bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result) { +bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes) { + + BodySW *body = body_owner.get(p_body); + ERR_FAIL_COND_V(!body, false); + ERR_FAIL_COND_V(!body->get_space(), false); + ERR_FAIL_COND_V(body->get_space()->is_locked(), false); + + _update_shapes(); + + return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, body->get_kinematic_margin(), r_result, p_exclude_raycast_shapes); +} + +int PhysicsServerSW::body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body, false); @@ -950,7 +970,7 @@ bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, cons _update_shapes(); - return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, body->get_kinematic_margin(), r_result); + return body->get_space()->test_body_ray_separation(body, p_transform, p_infinite_inertia, r_recover_motion, r_results, p_result_max, p_margin); } PhysicsDirectBodyState *PhysicsServerSW::body_get_direct_state(RID p_body) { diff --git a/servers/physics/physics_server_sw.h b/servers/physics/physics_server_sw.h index 1c5754124d..4131c5e248 100644 --- a/servers/physics/physics_server_sw.h +++ b/servers/physics/physics_server_sw.h @@ -85,6 +85,10 @@ public: virtual ShapeType shape_get_type(RID p_shape) const; virtual Variant shape_get_data(RID p_shape) const; + + virtual void shape_set_margin(RID p_shape, real_t p_margin); + virtual real_t shape_get_margin(RID p_shape) const; + virtual real_t shape_get_custom_solver_bias(RID p_shape) const; /* SPACE API */ @@ -230,7 +234,8 @@ public: virtual void body_set_ray_pickable(RID p_body, bool p_enable); virtual bool body_is_ray_pickable(RID p_body) const; - virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = NULL); + virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true); + virtual int body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001); // this function only works on physics process, errors and returns null otherwise virtual PhysicsDirectBodyState *body_get_direct_state(RID p_body); diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index b604e5cdf6..cae2e6fb00 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -34,12 +34,22 @@ #include "physics_server_sw.h" #include "project_settings.h" -_FORCE_INLINE_ static bool _can_collide_with(CollisionObjectSW *p_object, uint32_t p_collision_mask) { +_FORCE_INLINE_ static bool _can_collide_with(CollisionObjectSW *p_object, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - return p_object->get_collision_layer() & p_collision_mask; + if (!(p_object->get_collision_layer() & p_collision_mask)) { + return false; + } + + if (p_object->get_type() == CollisionObjectSW::TYPE_AREA && !p_collide_with_areas) + return false; + + if (p_object->get_type() == CollisionObjectSW::TYPE_BODY && !p_collide_with_bodies) + return false; + + return true; } -int PhysicsDirectSpaceStateSW::intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +int PhysicsDirectSpaceStateSW::intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { ERR_FAIL_COND_V(space->locked, false); int amount = space->broadphase->cull_point(p_point, space->intersection_query_results, SpaceSW::INTERSECTION_QUERY_MAX, space->intersection_query_subindex_results); @@ -52,7 +62,7 @@ int PhysicsDirectSpaceStateSW::intersect_point(const Vector3 &p_point, ShapeResu if (cc >= p_result_max) break; - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; //area can't be picked by ray (default) @@ -83,7 +93,7 @@ int PhysicsDirectSpaceStateSW::intersect_point(const Vector3 &p_point, ShapeResu return cc; } -bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_pick_ray) { +bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_pick_ray) { ERR_FAIL_COND_V(space->locked, false); @@ -105,7 +115,7 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vecto for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; if (p_pick_ray && !(static_cast<CollisionObjectSW *>(space->intersection_query_results[i])->is_ray_pickable())) @@ -161,7 +171,7 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vecto return true; } -int PhysicsDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transform &p_xform, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +int PhysicsDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transform &p_xform, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { if (p_result_max <= 0) return 0; @@ -182,7 +192,7 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transfo if (cc >= p_result_max) break; - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; //area can't be picked by ray (default) @@ -212,7 +222,7 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transfo return cc; } -bool PhysicsDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, ShapeRestInfo *r_info) { +bool PhysicsDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, ShapeRestInfo *r_info) { ShapeSW *shape = static_cast<PhysicsServerSW *>(PhysicsServer::get_singleton())->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape, false); @@ -242,7 +252,7 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; if (p_exclude.has(space->intersection_query_results[i]->get_self())) @@ -326,7 +336,7 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform return true; } -bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform &p_shape_xform, real_t p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform &p_shape_xform, real_t p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { if (p_result_max <= 0) return 0; @@ -356,7 +366,7 @@ bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform &p_sh for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; const CollisionObjectSW *col_obj = space->intersection_query_results[i]; @@ -405,7 +415,7 @@ static void _rest_cbk_result(const Vector3 &p_point_A, const Vector3 &p_point_B, rd->best_object = rd->object; rd->best_shape = rd->shape; } -bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform &p_shape_xform, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform &p_shape_xform, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { ShapeSW *shape = static_cast<PhysicsServerSW *>(PhysicsServer::get_singleton())->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape, 0); @@ -422,7 +432,7 @@ bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform &p_shape_ for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; const CollisionObjectSW *col_obj = space->intersection_query_results[i]; @@ -541,7 +551,144 @@ int SpaceSW::_cull_aabb_for_body(BodySW *p_body, const AABB &p_aabb) { return amount; } -bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, real_t p_margin, PhysicsServer::MotionResult *r_result) { +int SpaceSW::test_body_ray_separation(BodySW *p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, PhysicsServer::SeparationResult *r_results, int p_result_max, real_t p_margin) { + + AABB body_aabb; + + for (int i = 0; i < p_body->get_shape_count(); i++) { + + if (i == 0) + body_aabb = p_body->get_shape_aabb(i); + else + body_aabb = body_aabb.merge(p_body->get_shape_aabb(i)); + } + + // Undo the currently transform the physics server is aware of and apply the provided one + body_aabb = p_transform.xform(p_body->get_inv_transform().xform(body_aabb)); + body_aabb = body_aabb.grow(p_margin); + + Transform body_transform = p_transform; + + for (int i = 0; i < p_result_max; i++) { + //reset results + r_results[i].collision_depth = 0; + } + + int rays_found = 0; + + { + // raycast AND separate + + const int max_results = 32; + int recover_attempts = 4; + Vector3 sr[max_results * 2]; + PhysicsServerSW::CollCbkData cbk; + cbk.max = max_results; + PhysicsServerSW::CollCbkData *cbkptr = &cbk; + CollisionSolverSW::CallbackResult cbkres = PhysicsServerSW::_shape_col_cbk; + + do { + + Vector3 recover_motion; + + bool collided = false; + + int amount = _cull_aabb_for_body(p_body, body_aabb); + int ray_index = 0; + + for (int j = 0; j < p_body->get_shape_count(); j++) { + if (p_body->is_shape_set_as_disabled(j)) + continue; + + ShapeSW *body_shape = p_body->get_shape(j); + + if (body_shape->get_type() != PhysicsServer::SHAPE_RAY) + continue; + + Transform body_shape_xform = body_transform * p_body->get_shape_transform(j); + + for (int i = 0; i < amount; i++) { + + const CollisionObjectSW *col_obj = intersection_query_results[i]; + int shape_idx = intersection_query_subindex_results[i]; + + cbk.amount = 0; + cbk.ptr = sr; + + if (CollisionObjectSW::TYPE_BODY == col_obj->get_type()) { + const BodySW *b = static_cast<const BodySW *>(col_obj); + if (p_infinite_inertia && PhysicsServer::BODY_MODE_STATIC != b->get_mode() && PhysicsServer::BODY_MODE_KINEMATIC != b->get_mode()) { + continue; + } + } + + ShapeSW *against_shape = col_obj->get_shape(shape_idx); + if (CollisionSolverSW::solve_static(body_shape, body_shape_xform, against_shape, col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), cbkres, cbkptr, NULL, p_margin)) { + if (cbk.amount > 0) { + collided = true; + } + + if (ray_index < p_result_max) { + PhysicsServer::SeparationResult &result = r_results[ray_index]; + + for (int k = 0; k < cbk.amount; k++) { + Vector3 a = sr[k * 2 + 0]; + Vector3 b = sr[k * 2 + 1]; + + recover_motion += (b - a) * 0.4; + + float depth = a.distance_to(b); + if (depth > result.collision_depth) { + + result.collision_depth = depth; + result.collision_point = b; + result.collision_normal = (b - a).normalized(); + result.collision_local_shape = shape_idx; + result.collider = col_obj->get_self(); + result.collider_id = col_obj->get_instance_id(); + //result.collider_metadata = col_obj->get_shape_metadata(shape_idx); + if (col_obj->get_type() == CollisionObjectSW::TYPE_BODY) { + BodySW *body = (BodySW *)col_obj; + + Vector3 rel_vec = b - body->get_transform().get_origin(); + //result.collider_velocity = Vector3(-body->get_angular_velocity() * rel_vec.y, body->get_angular_velocity() * rel_vec.x) + body->get_linear_velocity(); + result.collider_velocity = body->get_linear_velocity() + (body->get_angular_velocity()).cross(body->get_transform().origin - rel_vec); // * mPos); + } + } + } + } + } + } + + ray_index++; + } + + rays_found = MAX(ray_index, rays_found); + + if (!collided || recover_motion == Vector3()) { + break; + } + + body_transform.origin += recover_motion; + body_aabb.position += recover_motion; + + recover_attempts--; + } while (recover_attempts); + } + + //optimize results (remove non colliding) + for (int i = 0; i < rays_found; i++) { + if (r_results[i].collision_depth == 0) { + rays_found--; + SWAP(r_results[i], r_results[rays_found]); + } + } + + r_recover_motion = body_transform.origin - p_transform.origin; + return rays_found; +} + +bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, real_t p_margin, PhysicsServer::MotionResult *r_result, bool p_exclude_raycast_shapes) { //give me back regular physics engine logic //this is madness @@ -597,6 +744,10 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve Transform body_shape_xform = body_transform * p_body->get_shape_transform(j); ShapeSW *body_shape = p_body->get_shape(j); + if (p_exclude_raycast_shapes && body_shape->get_type() == PhysicsServer::SHAPE_RAY) { + continue; + } + for (int i = 0; i < amount; i++) { const CollisionObjectSW *col_obj = intersection_query_results[i]; @@ -655,6 +806,10 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve Transform body_shape_xform = body_transform * p_body->get_shape_transform(j); ShapeSW *body_shape = p_body->get_shape(j); + if (p_exclude_raycast_shapes && body_shape->get_type() == PhysicsServer::SHAPE_RAY) { + continue; + } + Transform body_shape_xform_inv = body_shape_xform.affine_inverse(); MotionShapeSW mshape; mshape.shape = body_shape; diff --git a/servers/physics/space_sw.h b/servers/physics/space_sw.h index 4d864e9a51..e7231df532 100644 --- a/servers/physics/space_sw.h +++ b/servers/physics/space_sw.h @@ -48,12 +48,12 @@ class PhysicsDirectSpaceStateSW : public PhysicsDirectSpaceState { public: SpaceSW *space; - virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_pick_ray = false); - virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, ShapeRestInfo *r_info = NULL); - virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, real_t p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); + virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false); + virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = NULL); + virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, real_t p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const; PhysicsDirectSpaceStateSW(); @@ -197,7 +197,8 @@ public: void set_elapsed_time(ElapsedTime p_time, uint64_t p_msec) { elapsed_time[p_time] = p_msec; } uint64_t get_elapsed_time(ElapsedTime p_time) const { return elapsed_time[p_time]; } - bool test_body_motion(BodySW *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, real_t p_margin, PhysicsServer::MotionResult *r_result); + int test_body_ray_separation(BodySW *p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, PhysicsServer::SeparationResult *r_results, int p_result_max, real_t p_margin); + bool test_body_motion(BodySW *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, real_t p_margin, PhysicsServer::MotionResult *r_result, bool p_exclude_raycast_shapes); SpaceSW(); ~SpaceSW(); diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 6e45951f42..ecebd09436 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -34,12 +34,22 @@ #include "pair.h" #include "physics_2d_server_sw.h" -_FORCE_INLINE_ static bool _can_collide_with(CollisionObject2DSW *p_object, uint32_t p_collision_mask) { +_FORCE_INLINE_ static bool _can_collide_with(CollisionObject2DSW *p_object, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - return p_object->get_collision_layer() & p_collision_mask; + if (!(p_object->get_collision_layer() & p_collision_mask)) { + return false; + } + + if (p_object->get_type() == CollisionObject2DSW::TYPE_AREA && !p_collide_with_areas) + return false; + + if (p_object->get_type() == CollisionObject2DSW::TYPE_BODY && !p_collide_with_bodies) + return false; + + return true; } -int Physics2DDirectSpaceStateSW::intersect_point(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_pick_point) { +int Physics2DDirectSpaceStateSW::intersect_point(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_pick_point) { if (p_result_max <= 0) return 0; @@ -54,7 +64,7 @@ int Physics2DDirectSpaceStateSW::intersect_point(const Vector2 &p_point, ShapeRe for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; if (p_exclude.has(space->intersection_query_results[i]->get_self())) @@ -90,7 +100,7 @@ int Physics2DDirectSpaceStateSW::intersect_point(const Vector2 &p_point, ShapeRe return cc; } -bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2 &p_from, const Vector2 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2 &p_from, const Vector2 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { ERR_FAIL_COND_V(space->locked, false); @@ -112,7 +122,7 @@ bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2 &p_from, const Vec for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; if (p_exclude.has(space->intersection_query_results[i]->get_self())) @@ -170,7 +180,7 @@ bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2 &p_from, const Vec return true; } -int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { if (p_result_max <= 0) return 0; @@ -190,7 +200,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Trans if (cc >= p_result_max) break; - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; if (p_exclude.has(space->intersection_query_results[i]->get_self())) @@ -215,7 +225,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Trans return cc; } -bool Physics2DDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +bool Physics2DDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape, false); @@ -236,7 +246,7 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transfor for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; if (p_exclude.has(space->intersection_query_results[i]->get_self())) @@ -299,7 +309,7 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transfor return true; } -bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { if (p_result_max <= 0) return 0; @@ -330,7 +340,7 @@ bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D & for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; const CollisionObject2DSW *col_obj = space->intersection_query_results[i]; @@ -388,7 +398,7 @@ static void _rest_cbk_result(const Vector2 &p_point_A, const Vector2 &p_point_B, rd->best_shape = rd->shape; } -bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask) { +bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); ERR_FAIL_COND_V(!shape, 0); @@ -406,7 +416,7 @@ bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Transform2D &p_sh for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) continue; const CollisionObject2DSW *col_obj = space->intersection_query_results[i]; diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h index 1247317b03..6e2e025185 100644 --- a/servers/physics_2d/space_2d_sw.h +++ b/servers/physics_2d/space_2d_sw.h @@ -48,12 +48,12 @@ class Physics2DDirectSpaceStateSW : public Physics2DDirectSpaceState { public: Space2DSW *space; - virtual int intersect_point(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_pick_point = false); - virtual bool intersect_ray(const Vector2 &p_from, const Vector2 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual int intersect_shape(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual bool cast_motion(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual bool collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); - virtual bool rest_info(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); + virtual int intersect_point(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_point = false); + virtual bool intersect_ray(const Vector2 &p_from, const Vector2 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual int intersect_shape(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual bool cast_motion(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual bool collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + virtual bool rest_info(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); Physics2DDirectSpaceStateSW(); }; diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp index 37c4bc83ad..a51b938541 100644 --- a/servers/physics_2d_server.cpp +++ b/servers/physics_2d_server.cpp @@ -203,6 +203,22 @@ Vector<RID> Physics2DShapeQueryParameters::get_exclude() const { return ret; } +void Physics2DShapeQueryParameters::set_collide_with_bodies(bool p_enable) { + collide_with_bodies = p_enable; +} + +bool Physics2DShapeQueryParameters::is_collide_with_bodies_enabled() const { + return collide_with_bodies; +} + +void Physics2DShapeQueryParameters::set_collide_with_areas(bool p_enable) { + collide_with_areas = p_enable; +} + +bool Physics2DShapeQueryParameters::is_collide_with_areas_enabled() const { + return collide_with_areas; +} + void Physics2DShapeQueryParameters::_bind_methods() { ClassDB::bind_method(D_METHOD("set_shape", "shape"), &Physics2DShapeQueryParameters::set_shape); @@ -224,6 +240,12 @@ void Physics2DShapeQueryParameters::_bind_methods() { ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &Physics2DShapeQueryParameters::set_exclude); ClassDB::bind_method(D_METHOD("get_exclude"), &Physics2DShapeQueryParameters::get_exclude); + ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &Physics2DShapeQueryParameters::set_collide_with_bodies); + ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &Physics2DShapeQueryParameters::is_collide_with_bodies_enabled); + + ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &Physics2DShapeQueryParameters::set_collide_with_areas); + ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &Physics2DShapeQueryParameters::is_collide_with_areas_enabled); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_layer", "get_collision_layer"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_NONE, itos(Variant::_RID) + ":"), "set_exclude", "get_exclude"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_margin", "get_margin"); @@ -231,22 +253,26 @@ void Physics2DShapeQueryParameters::_bind_methods() { //ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", ""); // FIXME: Lacks a getter ADD_PROPERTY(PropertyInfo(Variant::_RID, "shape_rid"), "set_shape_rid", "get_shape_rid"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform"), "set_transform", "get_transform"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled"); } Physics2DShapeQueryParameters::Physics2DShapeQueryParameters() { margin = 0; collision_mask = 0x7FFFFFFF; + collide_with_bodies = true; + collide_with_areas = false; } -Dictionary Physics2DDirectSpaceState::_intersect_ray(const Vector2 &p_from, const Vector2 &p_to, const Vector<RID> &p_exclude, uint32_t p_layers) { +Dictionary Physics2DDirectSpaceState::_intersect_ray(const Vector2 &p_from, const Vector2 &p_to, const Vector<RID> &p_exclude, uint32_t p_layers, bool p_collide_with_bodies, bool p_collide_with_areas) { RayResult inters; Set<RID> exclude; for (int i = 0; i < p_exclude.size(); i++) exclude.insert(p_exclude[i]); - bool res = intersect_ray(p_from, p_to, inters, exclude, p_layers); + bool res = intersect_ray(p_from, p_to, inters, exclude, p_layers, p_collide_with_bodies, p_collide_with_areas); if (!res) return Dictionary(); @@ -267,7 +293,7 @@ Array Physics2DDirectSpaceState::_intersect_shape(const Ref<Physics2DShapeQueryP Vector<ShapeResult> sr; sr.resize(p_max_results); - int rc = intersect_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, sr.ptrw(), sr.size(), p_shape_query->exclude, p_shape_query->collision_mask); + int rc = intersect_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, sr.ptrw(), sr.size(), p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas); Array ret; ret.resize(rc); for (int i = 0; i < rc; i++) { @@ -287,7 +313,7 @@ Array Physics2DDirectSpaceState::_intersect_shape(const Ref<Physics2DShapeQueryP Array Physics2DDirectSpaceState::_cast_motion(const Ref<Physics2DShapeQueryParameters> &p_shape_query) { float closest_safe, closest_unsafe; - bool res = cast_motion(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, closest_safe, closest_unsafe, p_shape_query->exclude, p_shape_query->collision_mask); + bool res = cast_motion(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, closest_safe, closest_unsafe, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas); if (!res) return Array(); Array ret; @@ -297,7 +323,7 @@ Array Physics2DDirectSpaceState::_cast_motion(const Ref<Physics2DShapeQueryParam return ret; } -Array Physics2DDirectSpaceState::_intersect_point(const Vector2 &p_point, int p_max_results, const Vector<RID> &p_exclude, uint32_t p_layers) { +Array Physics2DDirectSpaceState::_intersect_point(const Vector2 &p_point, int p_max_results, const Vector<RID> &p_exclude, uint32_t p_layers, bool p_collide_with_bodies, bool p_collide_with_areas) { Set<RID> exclude; for (int i = 0; i < p_exclude.size(); i++) @@ -306,7 +332,7 @@ Array Physics2DDirectSpaceState::_intersect_point(const Vector2 &p_point, int p_ Vector<ShapeResult> ret; ret.resize(p_max_results); - int rc = intersect_point(p_point, ret.ptrw(), ret.size(), exclude, p_layers); + int rc = intersect_point(p_point, ret.ptrw(), ret.size(), exclude, p_layers, p_collide_with_bodies, p_collide_with_areas); if (rc == 0) return Array(); @@ -330,7 +356,7 @@ Array Physics2DDirectSpaceState::_collide_shape(const Ref<Physics2DShapeQueryPar Vector<Vector2> ret; ret.resize(p_max_results * 2); int rc = 0; - bool res = collide_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, ret.ptrw(), p_max_results, rc, p_shape_query->exclude, p_shape_query->collision_mask); + bool res = collide_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, ret.ptrw(), p_max_results, rc, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas); if (!res) return Array(); Array r; @@ -343,7 +369,7 @@ Dictionary Physics2DDirectSpaceState::_get_rest_info(const Ref<Physics2DShapeQue ShapeRestInfo sri; - bool res = rest_info(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, &sri, p_shape_query->exclude, p_shape_query->collision_mask); + bool res = rest_info(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, &sri, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas); Dictionary r; if (!res) return r; @@ -364,8 +390,8 @@ Physics2DDirectSpaceState::Physics2DDirectSpaceState() { void Physics2DDirectSpaceState::_bind_methods() { - ClassDB::bind_method(D_METHOD("intersect_point", "point", "max_results", "exclude", "collision_layer"), &Physics2DDirectSpaceState::_intersect_point, DEFVAL(32), DEFVAL(Array()), DEFVAL(0x7FFFFFFF)); - ClassDB::bind_method(D_METHOD("intersect_ray", "from", "to", "exclude", "collision_layer"), &Physics2DDirectSpaceState::_intersect_ray, DEFVAL(Array()), DEFVAL(0x7FFFFFFF)); + ClassDB::bind_method(D_METHOD("intersect_point", "point", "max_results", "exclude", "collision_layer", "collide_with_bodies", "collide_with_areas"), &Physics2DDirectSpaceState::_intersect_point, DEFVAL(32), DEFVAL(Array()), DEFVAL(0x7FFFFFFF), DEFVAL(true), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("intersect_ray", "from", "to", "exclude", "collision_layer", "collide_with_bodies", "collide_with_areas"), &Physics2DDirectSpaceState::_intersect_ray, DEFVAL(Array()), DEFVAL(0x7FFFFFFF), DEFVAL(true), DEFVAL(false)); ClassDB::bind_method(D_METHOD("intersect_shape", "shape", "max_results"), &Physics2DDirectSpaceState::_intersect_shape, DEFVAL(32)); ClassDB::bind_method(D_METHOD("cast_motion", "shape"), &Physics2DDirectSpaceState::_cast_motion); ClassDB::bind_method(D_METHOD("collide_shape", "shape", "max_results"), &Physics2DDirectSpaceState::_collide_shape, DEFVAL(32)); diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index f42d9868f0..82b4eb75d8 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -107,6 +107,9 @@ class Physics2DShapeQueryParameters : public Reference { Set<RID> exclude; uint32_t collision_mask; + bool collide_with_bodies; + bool collide_with_areas; + protected: static void _bind_methods(); @@ -127,6 +130,12 @@ public: void set_collision_mask(int p_collision_mask); int get_collision_mask() const; + void set_collide_with_bodies(bool p_enable); + bool is_collide_with_bodies_enabled() const; + + void set_collide_with_areas(bool p_enable); + bool is_collide_with_areas_enabled() const; + void set_exclude(const Vector<RID> &p_exclude); Vector<RID> get_exclude() const; @@ -137,9 +146,9 @@ class Physics2DDirectSpaceState : public Object { GDCLASS(Physics2DDirectSpaceState, Object); - Dictionary _intersect_ray(const Vector2 &p_from, const Vector2 &p_to, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0); + Dictionary _intersect_ray(const Vector2 &p_from, const Vector2 &p_to, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - Array _intersect_point(const Vector2 &p_point, int p_max_results = 32, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0); + Array _intersect_point(const Vector2 &p_point, int p_max_results = 32, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); Array _intersect_shape(const Ref<Physics2DShapeQueryParameters> &p_shape_query, int p_max_results = 32); Array _cast_motion(const Ref<Physics2DShapeQueryParameters> &p_shape_query); Array _collide_shape(const Ref<Physics2DShapeQueryParameters> &p_shape_query, int p_max_results = 32); @@ -160,7 +169,7 @@ public: Variant metadata; }; - virtual bool intersect_ray(const Vector2 &p_from, const Vector2 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF) = 0; + virtual bool intersect_ray(const Vector2 &p_from, const Vector2 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; struct ShapeResult { @@ -171,13 +180,13 @@ public: Variant metadata; }; - virtual int intersect_point(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, bool p_pick_point = false) = 0; + virtual int intersect_point(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_point = false) = 0; - virtual int intersect_shape(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF) = 0; + virtual int intersect_shape(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; - virtual bool cast_motion(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF) = 0; + virtual bool cast_motion(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; - virtual bool collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, float p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF) = 0; + virtual bool collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, float p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; struct ShapeRestInfo { @@ -190,7 +199,7 @@ public: Variant metadata; }; - virtual bool rest_info(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF) = 0; + virtual bool rest_info(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; Physics2DDirectSpaceState(); }; diff --git a/servers/physics_server.cpp b/servers/physics_server.cpp index cda3856ecc..deb3cd9bbe 100644 --- a/servers/physics_server.cpp +++ b/servers/physics_server.cpp @@ -29,7 +29,9 @@ /*************************************************************************/ #include "physics_server.h" + #include "core/project_settings.h" +#include "method_bind_ext.gen.inc" #include "print_string.h" PhysicsServer *PhysicsServer::singleton = NULL; @@ -198,6 +200,22 @@ Vector<RID> PhysicsShapeQueryParameters::get_exclude() const { return ret; } +void PhysicsShapeQueryParameters::set_collide_with_bodies(bool p_enable) { + collide_with_bodies = p_enable; +} + +bool PhysicsShapeQueryParameters::is_collide_with_bodies_enabled() const { + return collide_with_bodies; +} + +void PhysicsShapeQueryParameters::set_collide_with_areas(bool p_enable) { + collide_with_areas = p_enable; +} + +bool PhysicsShapeQueryParameters::is_collide_with_areas_enabled() const { + return collide_with_areas; +} + void PhysicsShapeQueryParameters::_bind_methods() { ClassDB::bind_method(D_METHOD("set_shape", "shape"), &PhysicsShapeQueryParameters::set_shape); @@ -216,18 +234,28 @@ void PhysicsShapeQueryParameters::_bind_methods() { ClassDB::bind_method(D_METHOD("set_exclude", "exclude"), &PhysicsShapeQueryParameters::set_exclude); ClassDB::bind_method(D_METHOD("get_exclude"), &PhysicsShapeQueryParameters::get_exclude); + ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &PhysicsShapeQueryParameters::set_collide_with_bodies); + ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &PhysicsShapeQueryParameters::is_collide_with_bodies_enabled); + + ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &PhysicsShapeQueryParameters::set_collide_with_areas); + ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &PhysicsShapeQueryParameters::is_collide_with_areas_enabled); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_NONE, itos(Variant::_RID) + ":"), "set_exclude", "get_exclude"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_margin", "get_margin"); //ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", ""); // FIXME: Lacks a getter ADD_PROPERTY(PropertyInfo(Variant::_RID, "shape_rid"), "set_shape_rid", "get_shape_rid"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform"), "set_transform", "get_transform"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas"), "set_collide_with_areas", "is_collide_with_areas_enabled"); } PhysicsShapeQueryParameters::PhysicsShapeQueryParameters() { margin = 0; collision_mask = 0x7FFFFFFF; + collide_with_bodies = true; + collide_with_areas = false; } ///////////////////////////////////// @@ -262,14 +290,14 @@ Variant PhysicsDirectSpaceState::_intersect_shape(const RID& p_shape, const Tran } */ -Dictionary PhysicsDirectSpaceState::_intersect_ray(const Vector3 &p_from, const Vector3 &p_to, const Vector<RID> &p_exclude, uint32_t p_collision_mask) { +Dictionary PhysicsDirectSpaceState::_intersect_ray(const Vector3 &p_from, const Vector3 &p_to, const Vector<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { RayResult inters; Set<RID> exclude; for (int i = 0; i < p_exclude.size(); i++) exclude.insert(p_exclude[i]); - bool res = intersect_ray(p_from, p_to, inters, exclude, p_collision_mask); + bool res = intersect_ray(p_from, p_to, inters, exclude, p_collision_mask, p_collide_with_bodies, p_collide_with_areas); if (!res) return Dictionary(); @@ -289,7 +317,7 @@ Array PhysicsDirectSpaceState::_intersect_shape(const Ref<PhysicsShapeQueryParam Vector<ShapeResult> sr; sr.resize(p_max_results); - int rc = intersect_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, sr.ptrw(), sr.size(), p_shape_query->exclude, p_shape_query->collision_mask); + int rc = intersect_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, sr.ptrw(), sr.size(), p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas); Array ret; ret.resize(rc); for (int i = 0; i < rc; i++) { @@ -308,7 +336,7 @@ Array PhysicsDirectSpaceState::_intersect_shape(const Ref<PhysicsShapeQueryParam Array PhysicsDirectSpaceState::_cast_motion(const Ref<PhysicsShapeQueryParameters> &p_shape_query, const Vector3 &p_motion) { float closest_safe, closest_unsafe; - bool res = cast_motion(p_shape_query->shape, p_shape_query->transform, p_motion, p_shape_query->margin, closest_safe, closest_unsafe, p_shape_query->exclude, p_shape_query->collision_mask); + bool res = cast_motion(p_shape_query->shape, p_shape_query->transform, p_motion, p_shape_query->margin, closest_safe, closest_unsafe, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas); if (!res) return Array(); Array ret; @@ -322,7 +350,7 @@ Array PhysicsDirectSpaceState::_collide_shape(const Ref<PhysicsShapeQueryParamet Vector<Vector3> ret; ret.resize(p_max_results * 2); int rc = 0; - bool res = collide_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, ret.ptrw(), p_max_results, rc, p_shape_query->exclude, p_shape_query->collision_mask); + bool res = collide_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, ret.ptrw(), p_max_results, rc, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas); if (!res) return Array(); Array r; @@ -335,7 +363,7 @@ Dictionary PhysicsDirectSpaceState::_get_rest_info(const Ref<PhysicsShapeQueryPa ShapeRestInfo sri; - bool res = rest_info(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, &sri, p_shape_query->exclude, p_shape_query->collision_mask); + bool res = rest_info(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, &sri, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas); Dictionary r; if (!res) return r; @@ -358,7 +386,7 @@ void PhysicsDirectSpaceState::_bind_methods() { //ClassDB::bind_method(D_METHOD("intersect_ray","from","to","exclude","umask"),&PhysicsDirectSpaceState::_intersect_ray,DEFVAL(Array()),DEFVAL(0)); //ClassDB::bind_method(D_METHOD("intersect_shape","shape","xform","result_max","exclude","umask"),&PhysicsDirectSpaceState::_intersect_shape,DEFVAL(Array()),DEFVAL(0)); - ClassDB::bind_method(D_METHOD("intersect_ray", "from", "to", "exclude", "collision_layer"), &PhysicsDirectSpaceState::_intersect_ray, DEFVAL(Array()), DEFVAL(0x7FFFFFFF)); + ClassDB::bind_method(D_METHOD("intersect_ray", "from", "to", "exclude", "collision_mask", "collide_with_bodies", "collide_with_areas"), &PhysicsDirectSpaceState::_intersect_ray, DEFVAL(Array()), DEFVAL(0x7FFFFFFF), DEFVAL(true), DEFVAL(false)); ClassDB::bind_method(D_METHOD("intersect_shape", "shape", "max_results"), &PhysicsDirectSpaceState::_intersect_shape, DEFVAL(32)); ClassDB::bind_method(D_METHOD("cast_motion", "shape", "motion"), &PhysicsDirectSpaceState::_cast_motion); ClassDB::bind_method(D_METHOD("collide_shape", "shape", "max_results"), &PhysicsDirectSpaceState::_collide_shape, DEFVAL(32)); diff --git a/servers/physics_server.h b/servers/physics_server.h index 948aec1a2d..f2aa33a6cc 100644 --- a/servers/physics_server.h +++ b/servers/physics_server.h @@ -108,6 +108,9 @@ class PhysicsShapeQueryParameters : public Reference { Set<RID> exclude; uint32_t collision_mask; + bool collide_with_bodies; + bool collide_with_areas; + protected: static void _bind_methods(); @@ -128,6 +131,12 @@ public: void set_exclude(const Vector<RID> &p_exclude); Vector<RID> get_exclude() const; + void set_collide_with_bodies(bool p_enable); + bool is_collide_with_bodies_enabled() const; + + void set_collide_with_areas(bool p_enable); + bool is_collide_with_areas_enabled() const; + PhysicsShapeQueryParameters(); }; @@ -136,7 +145,7 @@ class PhysicsDirectSpaceState : public Object { GDCLASS(PhysicsDirectSpaceState, Object); private: - Dictionary _intersect_ray(const Vector3 &p_from, const Vector3 &p_to, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_collision_mask = 0); + Dictionary _intersect_ray(const Vector3 &p_from, const Vector3 &p_to, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_collision_mask = 0, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); Array _intersect_shape(const Ref<PhysicsShapeQueryParameters> &p_shape_query, int p_max_results = 32); Array _cast_motion(const Ref<PhysicsShapeQueryParameters> &p_shape_query, const Vector3 &p_motion); Array _collide_shape(const Ref<PhysicsShapeQueryParameters> &p_shape_query, int p_max_results = 32); @@ -154,7 +163,7 @@ public: int shape; }; - virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF) = 0; + virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; struct RayResult { @@ -166,9 +175,9 @@ public: int shape; }; - virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_pick_ray = false) = 0; + virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false) = 0; - virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF) = 0; + virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; struct ShapeRestInfo { @@ -180,11 +189,11 @@ public: Vector3 linear_velocity; //velocity at contact point }; - virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, ShapeRestInfo *r_info = NULL) = 0; + virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = NULL) = 0; - virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF) = 0; + virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; - virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF) = 0; + virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const = 0; @@ -243,6 +252,10 @@ public: virtual ShapeType shape_get_type(RID p_shape) const = 0; virtual Variant shape_get_data(RID p_shape) const = 0; + + virtual void shape_set_margin(RID p_shape, real_t p_margin) = 0; + virtual real_t shape_get_margin(RID p_shape) const = 0; + virtual real_t shape_get_custom_solver_bias(RID p_shape) const = 0; /* SPACE API */ @@ -482,7 +495,22 @@ public: Variant collider_metadata; }; - virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = NULL) = 0; + virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = NULL, bool p_exclude_raycast_shapes = true) = 0; + + struct SeparationResult { + + float collision_depth; + Vector3 collision_point; + Vector3 collision_normal; + Vector3 collider_velocity; + int collision_local_shape; + ObjectID collider_id; + RID collider; + int collider_shape; + Variant collider_metadata; + }; + + virtual int body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001) = 0; /* SOFT BODY */ diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index ca50d0d049..8705033326 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -3875,8 +3875,8 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } - if (!uniform && (type < TYPE_FLOAT || type > TYPE_VEC4)) { - _set_error("Invalid type for varying, only float,vec2,vec3,vec4 allowed."); + if (!uniform && (type < TYPE_FLOAT || type > TYPE_MAT4)) { + _set_error("Invalid type for varying, only float,vec2,vec3,vec4,mat2,mat3,mat4 allowed."); return ERR_PARSE_ERROR; } diff --git a/servers/visual/shader_types.cpp b/servers/visual/shader_types.cpp index 0de8676f32..caa454b98e 100644 --- a/servers/visual/shader_types.cpp +++ b/servers/visual/shader_types.cpp @@ -127,6 +127,7 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT); shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["VIEWPORT_SIZE"] = constt(ShaderLanguage::TYPE_VEC2); + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["FRAGCOORD"] = constt(ShaderLanguage::TYPE_VEC4); shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["NORMAL"] = constt(ShaderLanguage::TYPE_VEC3); shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["VIEW"] = constt(ShaderLanguage::TYPE_VEC3); shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["LIGHT"] = constt(ShaderLanguage::TYPE_VEC3); diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index bc9e9042ec..18a04e9a4b 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -1806,24 +1806,24 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("gi_probe_get_bounds", "probe"), &VisualServer::gi_probe_get_bounds); ClassDB::bind_method(D_METHOD("gi_probe_set_cell_size", "probe", "range"), &VisualServer::gi_probe_set_cell_size); ClassDB::bind_method(D_METHOD("gi_probe_get_cell_size", "probe"), &VisualServer::gi_probe_get_cell_size); - ClassDB::bind_method(D_METHOD("gi_probe_set_to_cell_xform", "xform"), &VisualServer::gi_probe_set_to_cell_xform); - ClassDB::bind_method(D_METHOD("gi_probe_get_to_cell_xform"), &VisualServer::gi_probe_get_to_cell_xform); - ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_data", "data"), &VisualServer::gi_probe_set_dynamic_data); - ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_data"), &VisualServer::gi_probe_get_dynamic_data); - ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_range", "range"), &VisualServer::gi_probe_set_dynamic_range); - ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_range"), &VisualServer::gi_probe_get_dynamic_range); - ClassDB::bind_method(D_METHOD("gi_probe_set_energy", "energy"), &VisualServer::gi_probe_set_energy); - ClassDB::bind_method(D_METHOD("gi_probe_get_energy"), &VisualServer::gi_probe_get_energy); - ClassDB::bind_method(D_METHOD("gi_probe_set_bias", "bias"), &VisualServer::gi_probe_set_bias); - ClassDB::bind_method(D_METHOD("gi_probe_get_bias"), &VisualServer::gi_probe_get_bias); - ClassDB::bind_method(D_METHOD("gi_probe_set_normal_bias", "bias"), &VisualServer::gi_probe_set_normal_bias); - ClassDB::bind_method(D_METHOD("gi_probe_get_normal_bias"), &VisualServer::gi_probe_get_normal_bias); - ClassDB::bind_method(D_METHOD("gi_probe_set_propagation", "propagation"), &VisualServer::gi_probe_set_propagation); - ClassDB::bind_method(D_METHOD("gi_probe_get_propagation"), &VisualServer::gi_probe_get_propagation); - ClassDB::bind_method(D_METHOD("gi_probe_set_interior", "enable"), &VisualServer::gi_probe_set_interior); - ClassDB::bind_method(D_METHOD("gi_probe_is_interior"), &VisualServer::gi_probe_is_interior); - ClassDB::bind_method(D_METHOD("gi_probe_set_compress", "enable"), &VisualServer::gi_probe_set_compress); - ClassDB::bind_method(D_METHOD("gi_probe_is_compressed"), &VisualServer::gi_probe_is_compressed); + ClassDB::bind_method(D_METHOD("gi_probe_set_to_cell_xform", "probe", "xform"), &VisualServer::gi_probe_set_to_cell_xform); + ClassDB::bind_method(D_METHOD("gi_probe_get_to_cell_xform", "probe"), &VisualServer::gi_probe_get_to_cell_xform); + ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_data", "probe", "data"), &VisualServer::gi_probe_set_dynamic_data); + ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_data", "probe"), &VisualServer::gi_probe_get_dynamic_data); + ClassDB::bind_method(D_METHOD("gi_probe_set_dynamic_range", "probe", "range"), &VisualServer::gi_probe_set_dynamic_range); + ClassDB::bind_method(D_METHOD("gi_probe_get_dynamic_range", "probe"), &VisualServer::gi_probe_get_dynamic_range); + ClassDB::bind_method(D_METHOD("gi_probe_set_energy", "probe", "energy"), &VisualServer::gi_probe_set_energy); + ClassDB::bind_method(D_METHOD("gi_probe_get_energy", "probe"), &VisualServer::gi_probe_get_energy); + ClassDB::bind_method(D_METHOD("gi_probe_set_bias", "probe", "bias"), &VisualServer::gi_probe_set_bias); + ClassDB::bind_method(D_METHOD("gi_probe_get_bias", "probe"), &VisualServer::gi_probe_get_bias); + ClassDB::bind_method(D_METHOD("gi_probe_set_normal_bias", "probe", "bias"), &VisualServer::gi_probe_set_normal_bias); + ClassDB::bind_method(D_METHOD("gi_probe_get_normal_bias", "probe"), &VisualServer::gi_probe_get_normal_bias); + ClassDB::bind_method(D_METHOD("gi_probe_set_propagation", "probe", "propagation"), &VisualServer::gi_probe_set_propagation); + ClassDB::bind_method(D_METHOD("gi_probe_get_propagation", "probe"), &VisualServer::gi_probe_get_propagation); + ClassDB::bind_method(D_METHOD("gi_probe_set_interior", "probe", "enable"), &VisualServer::gi_probe_set_interior); + ClassDB::bind_method(D_METHOD("gi_probe_is_interior", "probe"), &VisualServer::gi_probe_is_interior); + ClassDB::bind_method(D_METHOD("gi_probe_set_compress", "probe", "enable"), &VisualServer::gi_probe_set_compress); + ClassDB::bind_method(D_METHOD("gi_probe_is_compressed", "probe"), &VisualServer::gi_probe_is_compressed); ClassDB::bind_method(D_METHOD("lightmap_capture_create"), &VisualServer::lightmap_capture_create); ClassDB::bind_method(D_METHOD("lightmap_capture_set_bounds", "capture", "bounds"), &VisualServer::lightmap_capture_set_bounds); @@ -2361,6 +2361,7 @@ VisualServer::VisualServer() { //ERR_FAIL_COND(singleton); singleton = this; + GLOBAL_DEF("rendering/vram_compression/import_bptc", false); GLOBAL_DEF("rendering/vram_compression/import_s3tc", true); GLOBAL_DEF("rendering/vram_compression/import_etc", false); GLOBAL_DEF("rendering/vram_compression/import_etc2", true); diff --git a/thirdparty/README.md b/thirdparty/README.md index 11745bc532..9da3d857a6 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -40,6 +40,17 @@ File extracted from a recent Fedora install: as it's generated on the user's system.) +## cvtt + +- Upstream: https://github.com/elasota/cvtt +- Version: 1.0.0-beta4 +- License: MIT + +Files extracted from upstream source: + +- all .cpp, .h, and .txt files in ConvectionKernels/ + + ## enet - Upstream: http://enet.bespin.org diff --git a/thirdparty/cvtt/ConvectionKernels.cpp b/thirdparty/cvtt/ConvectionKernels.cpp new file mode 100644 index 0000000000..6661d8120d --- /dev/null +++ b/thirdparty/cvtt/ConvectionKernels.cpp @@ -0,0 +1,7576 @@ +/* +Convection Texture Tools +Copyright (c) 2018 Eric Lasota + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------------- + +Portions based on DirectX Texture Library (DirectXTex) + +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the MIT License. + +http://go.microsoft.com/fwlink/?LinkId=248926 +*/ +#include "ConvectionKernels.h" +#include "ConvectionKernels_BC7_SingleColor.h" + +#if (defined(_M_IX86_FP) && _M_IX86_FP >= 2) || defined(_M_X64) || defined(__SSE2__) +#define CVTT_USE_SSE2 +#endif + +#ifdef CVTT_USE_SSE2 +#include <emmintrin.h> +#endif + +#include <float.h> +#include <assert.h> +#include <string.h> +#include <algorithm> +#include <math.h> + +#define UNREFERENCED_PARAMETER(n) ((void)n) + +namespace cvtt +{ +#ifdef CVTT_USE_SSE2 + // SSE2 version + struct ParallelMath + { + typedef uint16_t ScalarUInt16; + typedef int16_t ScalarSInt16; + + template<unsigned int TRoundingMode> + struct RoundForScope + { + unsigned int m_oldCSR; + + RoundForScope() + { + m_oldCSR = _mm_getcsr(); + _mm_setcsr((m_oldCSR & ~_MM_ROUND_MASK) | (TRoundingMode)); + } + + ~RoundForScope() + { + _mm_setcsr(m_oldCSR); + } + }; + + struct RoundTowardZeroForScope : RoundForScope<_MM_ROUND_TOWARD_ZERO> + { + }; + + struct RoundTowardNearestForScope : RoundForScope<_MM_ROUND_NEAREST> + { + }; + + struct RoundUpForScope : RoundForScope<_MM_ROUND_UP> + { + }; + + struct RoundDownForScope : RoundForScope<_MM_ROUND_DOWN> + { + }; + + static const int ParallelSize = 8; + + enum Int16Subtype + { + IntSubtype_Signed, + IntSubtype_UnsignedFull, + IntSubtype_UnsignedTruncated, + IntSubtype_Abstract, + }; + + template<int TSubtype> + struct VInt16 + { + __m128i m_value; + + inline VInt16 operator+(int16_t other) const + { + VInt16 result; + result.m_value = _mm_add_epi16(m_value, _mm_set1_epi16(static_cast<int16_t>(other))); + return result; + } + + inline VInt16 operator+(const VInt16 &other) const + { + VInt16 result; + result.m_value = _mm_add_epi16(m_value, other.m_value); + return result; + } + + inline VInt16 operator|(const VInt16 &other) const + { + VInt16 result; + result.m_value = _mm_or_si128(m_value, other.m_value); + return result; + } + + inline VInt16 operator&(const VInt16 &other) const + { + VInt16 result; + result.m_value = _mm_and_si128(m_value, other.m_value); + return result; + } + + inline VInt16 operator-(const VInt16 &other) const + { + VInt16 result; + result.m_value = _mm_sub_epi16(m_value, other.m_value); + return result; + } + + inline VInt16 operator<<(int bits) const + { + VInt16 result; + result.m_value = _mm_slli_epi16(m_value, bits); + return result; + } + }; + + typedef VInt16<IntSubtype_Signed> SInt16; + typedef VInt16<IntSubtype_UnsignedFull> UInt16; + typedef VInt16<IntSubtype_UnsignedTruncated> UInt15; + typedef VInt16<IntSubtype_Abstract> AInt16; + + template<int TSubtype> + struct VInt32 + { + __m128i m_values[2]; + + inline VInt32 operator+(const VInt32& other) const + { + VInt32 result; + result.m_values[0] = _mm_add_epi32(m_values[0], other.m_values[0]); + result.m_values[1] = _mm_add_epi32(m_values[1], other.m_values[1]); + return result; + } + + inline VInt32 operator-(const VInt32& other) const + { + VInt32 result; + result.m_values[0] = _mm_sub_epi32(m_values[0], other.m_values[0]); + result.m_values[1] = _mm_sub_epi32(m_values[1], other.m_values[1]); + return result; + } + + inline VInt32 operator<<(const int other) const + { + VInt32 result; + result.m_values[0] = _mm_slli_epi32(m_values[0], other); + result.m_values[1] = _mm_slli_epi32(m_values[1], other); + return result; + } + }; + + typedef VInt32<IntSubtype_Signed> SInt32; + typedef VInt32<IntSubtype_UnsignedTruncated> UInt31; + typedef VInt32<IntSubtype_UnsignedFull> UInt32; + typedef VInt32<IntSubtype_Abstract> AInt32; + + template<class TTargetType> + struct LosslessCast + { +#ifdef CVTT_PERMIT_ALIASING + template<int TSrcSubtype> + static const TTargetType& Cast(const VInt32<TSrcSubtype> &src) + { + return reinterpret_cast<VInt32<TSubtype>&>(src); + } + + template<int TSrcSubtype> + static const TTargetType& Cast(const VInt16<TSrcSubtype> &src) + { + return reinterpret_cast<VInt16<TSubtype>&>(src); + } +#else + template<int TSrcSubtype> + static TTargetType Cast(const VInt32<TSrcSubtype> &src) + { + TTargetType result; + result.m_values[0] = src.m_values[0]; + result.m_values[1] = src.m_values[1]; + return result; + } + + template<int TSrcSubtype> + static TTargetType Cast(const VInt16<TSrcSubtype> &src) + { + TTargetType result; + result.m_value = src.m_value; + return result; + } +#endif + }; + + struct Int64 + { + __m128i m_values[4]; + }; + + struct Float + { + __m128 m_values[2]; + + inline Float operator+(const Float& other) const + { + Float result; + result.m_values[0] = _mm_add_ps(m_values[0], other.m_values[0]); + result.m_values[1] = _mm_add_ps(m_values[1], other.m_values[1]); + return result; + } + + inline Float operator+(float other) const + { + Float result; + result.m_values[0] = _mm_add_ps(m_values[0], _mm_set1_ps(other)); + result.m_values[1] = _mm_add_ps(m_values[1], _mm_set1_ps(other)); + return result; + } + + inline Float operator-(const Float& other) const + { + Float result; + result.m_values[0] = _mm_sub_ps(m_values[0], other.m_values[0]); + result.m_values[1] = _mm_sub_ps(m_values[1], other.m_values[1]); + return result; + } + + inline Float operator-() const + { + Float result; + result.m_values[0] = _mm_sub_ps(_mm_setzero_ps(), m_values[0]); + result.m_values[1] = _mm_sub_ps(_mm_setzero_ps(), m_values[1]); + return result; + } + + inline Float operator*(const Float& other) const + { + Float result; + result.m_values[0] = _mm_mul_ps(m_values[0], other.m_values[0]); + result.m_values[1] = _mm_mul_ps(m_values[1], other.m_values[1]); + return result; + } + + inline Float operator*(float other) const + { + Float result; + result.m_values[0] = _mm_mul_ps(m_values[0], _mm_set1_ps(other)); + result.m_values[1] = _mm_mul_ps(m_values[1], _mm_set1_ps(other)); + return result; + } + + inline Float operator/(const Float& other) const + { + Float result; + result.m_values[0] = _mm_div_ps(m_values[0], other.m_values[0]); + result.m_values[1] = _mm_div_ps(m_values[1], other.m_values[1]); + return result; + } + + inline Float operator/(float other) const + { + Float result; + result.m_values[0] = _mm_div_ps(m_values[0], _mm_set1_ps(other)); + result.m_values[1] = _mm_div_ps(m_values[1], _mm_set1_ps(other)); + return result; + } + }; + + struct Int16CompFlag + { + __m128i m_value; + + inline Int16CompFlag operator&(const Int16CompFlag& other) const + { + Int16CompFlag result; + result.m_value = _mm_and_si128(m_value, other.m_value); + return result; + } + + inline Int16CompFlag operator|(const Int16CompFlag& other) const + { + Int16CompFlag result; + result.m_value = _mm_or_si128(m_value, other.m_value); + return result; + } + }; + + struct FloatCompFlag + { + __m128 m_values[2]; + }; + + template<int TSubtype> + static VInt16<TSubtype> AbstractAdd(const VInt16<TSubtype> &a, const VInt16<TSubtype> &b) + { + VInt16<TSubtype> result; + result.m_value = _mm_add_epi16(a.m_value, b.m_value); + return result; + } + + template<int TSubtype> + static VInt16<TSubtype> AbstractSubtract(const VInt16<TSubtype> &a, const VInt16<TSubtype> &b) + { + VInt16<TSubtype> result; + result.m_value = _mm_sub_epi16(a.m_value, b.m_value); + return result; + } + + static Float Select(FloatCompFlag flag, Float a, Float b) + { + Float result; + for (int i = 0; i < 2; i++) + result.m_values[i] = _mm_or_ps(_mm_and_ps(flag.m_values[i], a.m_values[i]), _mm_andnot_ps(flag.m_values[i], b.m_values[i])); + return result; + } + + template<int TSubtype> + static VInt16<TSubtype> Select(Int16CompFlag flag, const VInt16<TSubtype> &a, const VInt16<TSubtype> &b) + { + VInt16<TSubtype> result; + result.m_value = _mm_or_si128(_mm_and_si128(flag.m_value, a.m_value), _mm_andnot_si128(flag.m_value, b.m_value)); + return result; + } + + template<int TSubtype> + static VInt16<TSubtype> SelectOrZero(Int16CompFlag flag, const VInt16<TSubtype> &a) + { + VInt16<TSubtype> result; + result.m_value = _mm_and_si128(flag.m_value, a.m_value); + return result; + } + + template<int TSubtype> + static void ConditionalSet(VInt16<TSubtype>& dest, Int16CompFlag flag, const VInt16<TSubtype> src) + { + dest.m_value = _mm_or_si128(_mm_andnot_si128(flag.m_value, dest.m_value), _mm_and_si128(flag.m_value, src.m_value)); + } + + static SInt16 ConditionalNegate(const Int16CompFlag &flag, const SInt16& v) + { + SInt16 result; + result.m_value = _mm_add_epi16(_mm_xor_si128(flag.m_value, v.m_value), _mm_srli_epi16(flag.m_value, 15)); + return result; + } + + template<int TSubtype> + static void NotConditionalSet(VInt16<TSubtype>& dest, Int16CompFlag flag, const VInt16<TSubtype> src) + { + dest.m_value = _mm_or_si128(_mm_and_si128(flag.m_value, dest.m_value), _mm_andnot_si128(flag.m_value, src.m_value)); + } + + static void ConditionalSet(Float& dest, FloatCompFlag flag, const Float src) + { + for (int i = 0; i < 2; i++) + dest.m_values[i] = _mm_or_ps(_mm_andnot_ps(flag.m_values[i], dest.m_values[i]), _mm_and_ps(flag.m_values[i], src.m_values[i])); + } + + static void NotConditionalSet(Float& dest, FloatCompFlag flag, const Float src) + { + for (int i = 0; i < 2; i++) + dest.m_values[i] = _mm_or_ps(_mm_and_ps(flag.m_values[i], dest.m_values[i]), _mm_andnot_ps(flag.m_values[i], src.m_values[i])); + } + + static void MakeSafeDenominator(Float& v) + { + ConditionalSet(v, Equal(v, MakeFloatZero()), MakeFloat(1.0f)); + } + + static SInt16 TruncateToPrecisionSigned(const SInt16 &v, int precision) + { + int lostBits = 16 - precision; + if (lostBits == 0) + return v; + + SInt16 result; + result.m_value = _mm_srai_epi16(_mm_slli_epi16(v.m_value, lostBits), lostBits); + return result; + } + + static UInt16 TruncateToPrecisionUnsigned(const UInt16 &v, int precision) + { + int lostBits = 16 - precision; + if (lostBits == 0) + return v; + + UInt16 result; + result.m_value = _mm_srli_epi16(_mm_slli_epi16(v.m_value, lostBits), lostBits); + return result; + } + + static UInt16 Min(const UInt16 &a, const UInt16 &b) + { + __m128i bitFlip = _mm_set1_epi16(-32768); + + UInt16 result; + result.m_value = _mm_xor_si128(_mm_min_epi16(_mm_xor_si128(a.m_value, bitFlip), _mm_xor_si128(b.m_value, bitFlip)), bitFlip); + return result; + } + + static SInt16 Min(const SInt16 &a, const SInt16 &b) + { + SInt16 result; + result.m_value = _mm_min_epi16(a.m_value, b.m_value); + return result; + } + + static UInt15 Min(const UInt15 &a, const UInt15 &b) + { + UInt15 result; + result.m_value = _mm_min_epi16(a.m_value, b.m_value); + return result; + } + + static Float Min(Float a, Float b) + { + Float result; + for (int i = 0; i < 2; i++) + result.m_values[i] = _mm_min_ps(a.m_values[i], b.m_values[i]); + return result; + } + + static UInt16 Max(const UInt16 &a, const UInt16 &b) + { + __m128i bitFlip = _mm_set1_epi16(-32768); + + UInt16 result; + result.m_value = _mm_xor_si128(_mm_max_epi16(_mm_xor_si128(a.m_value, bitFlip), _mm_xor_si128(b.m_value, bitFlip)), bitFlip); + return result; + } + + static SInt16 Max(const SInt16 &a, const SInt16 &b) + { + SInt16 result; + result.m_value = _mm_max_epi16(a.m_value, b.m_value); + return result; + } + + static UInt15 Max(const UInt15 &a, const UInt15 &b) + { + UInt15 result; + result.m_value = _mm_max_epi16(a.m_value, b.m_value); + return result; + } + + static Float Max(Float a, Float b) + { + Float result; + for (int i = 0; i < 2; i++) + result.m_values[i] = _mm_max_ps(a.m_values[i], b.m_values[i]); + return result; + } + + static Float Clamp(Float v, float min, float max) + { + Float result; + for (int i = 0; i < 2; i++) + result.m_values[i] = _mm_max_ps(_mm_min_ps(v.m_values[i], _mm_set1_ps(max)), _mm_set1_ps(min)); + return result; + } + + static Float Reciprocal(Float v) + { + Float result; + for (int i = 0; i < 2; i++) + result.m_values[i] = _mm_rcp_ps(v.m_values[i]); + return result; + } + + static void ConvertLDRInputs(const PixelBlockU8* inputBlocks, int pxOffset, int channel, UInt15& chOut) + { + int16_t values[8]; + for (int i = 0; i < 8; i++) + values[i] = inputBlocks[i].m_pixels[pxOffset][channel]; + + chOut.m_value = _mm_set_epi16(values[7], values[6], values[5], values[4], values[3], values[2], values[1], values[0]); + } + + static void ConvertHDRInputs(const PixelBlockF16* inputBlocks, int pxOffset, int channel, SInt16& chOut) + { + int16_t values[8]; + for (int i = 0; i < 8; i++) + values[i] = inputBlocks[i].m_pixels[pxOffset][channel]; + + chOut.m_value = _mm_set_epi16(values[7], values[6], values[5], values[4], values[3], values[2], values[1], values[0]); + } + + static Float MakeFloat(float v) + { + Float f; + f.m_values[0] = f.m_values[1] = _mm_set1_ps(v); + return f; + } + + static Float MakeFloatZero() + { + Float f; + f.m_values[0] = f.m_values[1] = _mm_setzero_ps(); + return f; + } + + static UInt16 MakeUInt16(uint16_t v) + { + UInt16 result; + result.m_value = _mm_set1_epi16(static_cast<short>(v)); + return result; + } + + static SInt16 MakeSInt16(int16_t v) + { + SInt16 result; + result.m_value = _mm_set1_epi16(static_cast<short>(v)); + return result; + } + + static AInt16 MakeAInt16(int16_t v) + { + AInt16 result; + result.m_value = _mm_set1_epi16(static_cast<short>(v)); + return result; + } + + static UInt15 MakeUInt15(uint16_t v) + { + UInt15 result; + result.m_value = _mm_set1_epi16(static_cast<short>(v)); + return result; + } + + static SInt32 MakeSInt32(int32_t v) + { + SInt32 result; + result.m_values[0] = _mm_set1_epi32(v); + result.m_values[1] = _mm_set1_epi32(v); + return result; + } + + static UInt31 MakeUInt31(uint32_t v) + { + UInt31 result; + result.m_values[0] = _mm_set1_epi32(v); + result.m_values[1] = _mm_set1_epi32(v); + return result; + } + + static uint16_t Extract(const UInt16 &v, int offset) + { + return reinterpret_cast<const uint16_t*>(&v.m_value)[offset]; + } + + static int16_t Extract(const SInt16 &v, int offset) + { + return reinterpret_cast<const int16_t*>(&v.m_value)[offset]; + } + + static uint16_t Extract(const UInt15 &v, int offset) + { + return reinterpret_cast<const uint16_t*>(&v.m_value)[offset]; + } + + static int16_t Extract(const AInt16 &v, int offset) + { + return reinterpret_cast<const int16_t*>(&v.m_value)[offset]; + } + + static void PutUInt16(UInt16 &dest, int offset, uint16_t v) + { + reinterpret_cast<uint16_t*>(&dest)[offset] = v; + } + + static void PutUInt15(UInt15 &dest, int offset, uint16_t v) + { + reinterpret_cast<uint16_t*>(&dest)[offset] = v; + } + + static void PutSInt16(SInt16 &dest, int offset, int16_t v) + { + reinterpret_cast<int16_t*>(&dest)[offset] = v; + } + + static float ExtractFloat(const Float& v, int offset) + { + return reinterpret_cast<const float*>(&v)[offset]; + } + + static void PutFloat(Float &dest, int offset, float v) + { + reinterpret_cast<float*>(&dest)[offset] = v; + } + + static Int16CompFlag Less(const SInt16 &a, const SInt16 &b) + { + Int16CompFlag result; + result.m_value = _mm_cmplt_epi16(a.m_value, b.m_value); + return result; + } + + static Int16CompFlag Less(const UInt15 &a, const UInt15 &b) + { + Int16CompFlag result; + result.m_value = _mm_cmplt_epi16(a.m_value, b.m_value); + return result; + } + + static Int16CompFlag LessOrEqual(const UInt15 &a, const UInt15 &b) + { + Int16CompFlag result; + result.m_value = _mm_cmplt_epi16(a.m_value, b.m_value); + return result; + } + + static FloatCompFlag Less(const Float &a, const Float &b) + { + FloatCompFlag result; + for (int i = 0; i < 2; i++) + result.m_values[i] = _mm_cmplt_ps(a.m_values[i], b.m_values[i]); + return result; + } + + static FloatCompFlag LessOrEqual(Float a, Float b) + { + FloatCompFlag result; + for (int i = 0; i < 2; i++) + result.m_values[i] = _mm_cmple_ps(a.m_values[i], b.m_values[i]); + return result; + } + + template<int TSubtype> + static Int16CompFlag Equal(const VInt16<TSubtype> &a, const VInt16<TSubtype> &b) + { + Int16CompFlag result; + result.m_value = _mm_cmpeq_epi16(a.m_value, b.m_value); + return result; + } + + static FloatCompFlag Equal(Float a, Float b) + { + FloatCompFlag result; + for (int i = 0; i < 2; i++) + result.m_values[i] = _mm_cmpeq_ps(a.m_values[i], b.m_values[i]); + return result; + } + + static Float ToFloat(const UInt16 &v) + { + Float result; + result.m_values[0] = _mm_cvtepi32_ps(_mm_unpacklo_epi16(v.m_value, _mm_setzero_si128())); + result.m_values[1] = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v.m_value, _mm_setzero_si128())); + return result; + } + + static UInt31 ToUInt31(const UInt16 &v) + { + UInt31 result; + result.m_values[0] = _mm_unpacklo_epi16(v.m_value, _mm_setzero_si128()); + result.m_values[1] = _mm_unpackhi_epi16(v.m_value, _mm_setzero_si128()); + return result; + } + + static SInt32 ToInt32(const UInt16 &v) + { + SInt32 result; + result.m_values[0] = _mm_unpacklo_epi16(v.m_value, _mm_setzero_si128()); + result.m_values[1] = _mm_unpackhi_epi16(v.m_value, _mm_setzero_si128()); + return result; + } + + static SInt32 ToInt32(const SInt16 &v) + { + SInt32 result; + result.m_values[0] = _mm_srai_epi32(_mm_unpacklo_epi16(_mm_setzero_si128(), v.m_value), 16); + result.m_values[1] = _mm_srai_epi32(_mm_unpackhi_epi16(_mm_setzero_si128(), v.m_value), 16); + return result; + } + + static Float ToFloat(const SInt16 &v) + { + Float result; + result.m_values[0] = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpacklo_epi16(_mm_setzero_si128(), v.m_value), 16)); + result.m_values[1] = _mm_cvtepi32_ps(_mm_srai_epi32(_mm_unpackhi_epi16(_mm_setzero_si128(), v.m_value), 16)); + return result; + } + + static Float ToFloat(const UInt15 &v) + { + Float result; + result.m_values[0] = _mm_cvtepi32_ps(_mm_unpacklo_epi16(v.m_value, _mm_setzero_si128())); + result.m_values[1] = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v.m_value, _mm_setzero_si128())); + return result; + } + + static Float ToFloat(const UInt31 &v) + { + Float result; + result.m_values[0] = _mm_cvtepi32_ps(v.m_values[0]); + result.m_values[1] = _mm_cvtepi32_ps(v.m_values[1]); + return result; + } + + static Int16CompFlag FloatFlagToInt16(const FloatCompFlag &v) + { + __m128i lo = _mm_castps_si128(v.m_values[0]); + __m128i hi = _mm_castps_si128(v.m_values[1]); + + Int16CompFlag result; + result.m_value = _mm_packs_epi32(lo, hi); + return result; + } + + static FloatCompFlag Int16FlagToFloat(const Int16CompFlag &v) + { + __m128i lo = _mm_unpacklo_epi16(v.m_value, v.m_value); + __m128i hi = _mm_unpackhi_epi16(v.m_value, v.m_value); + + FloatCompFlag result; + result.m_values[0] = _mm_castsi128_ps(lo); + result.m_values[1] = _mm_castsi128_ps(hi); + return result; + } + + static Int16CompFlag MakeBoolInt16(bool b) + { + Int16CompFlag result; + if (b) + result.m_value = _mm_set1_epi16(-1); + else + result.m_value = _mm_setzero_si128(); + return result; + } + + static FloatCompFlag MakeBoolFloat(bool b) + { + FloatCompFlag result; + if (b) + result.m_values[0] = result.m_values[1] = _mm_castsi128_ps(_mm_set1_epi32(-1)); + else + result.m_values[0] = result.m_values[1] = _mm_setzero_ps(); + return result; + } + + static Int16CompFlag AndNot(const Int16CompFlag &a, const Int16CompFlag &b) + { + Int16CompFlag result; + result.m_value = _mm_andnot_si128(b.m_value, a.m_value); + return result; + } + + static UInt16 RoundAndConvertToU16(Float v, const void* /*roundingMode*/) + { + __m128i lo = _mm_cvtps_epi32(_mm_add_ps(v.m_values[0], _mm_set1_ps(-32768))); + __m128i hi = _mm_cvtps_epi32(_mm_add_ps(v.m_values[1], _mm_set1_ps(-32768))); + + __m128i packed = _mm_packs_epi32(lo, hi); + + UInt16 result; + result.m_value = _mm_xor_si128(packed, _mm_set1_epi16(-32768)); + return result; + } + + static UInt15 RoundAndConvertToU15(Float v, const void* /*roundingMode*/) + { + __m128i lo = _mm_cvtps_epi32(v.m_values[0]); + __m128i hi = _mm_cvtps_epi32(v.m_values[1]); + + __m128i packed = _mm_packs_epi32(lo, hi); + + UInt15 result; + result.m_value = _mm_packs_epi32(lo, hi); + return result; + } + + static SInt16 RoundAndConvertToS16(Float v, const void* /*roundingMode*/) + { + __m128i lo = _mm_cvtps_epi32(v.m_values[0]); + __m128i hi = _mm_cvtps_epi32(v.m_values[1]); + + __m128i packed = _mm_packs_epi32(lo, hi); + + SInt16 result; + result.m_value = _mm_packs_epi32(lo, hi); + return result; + } + + static Float Sqrt(Float f) + { + Float result; + for (int i = 0; i < 2; i++) + result.m_values[i] = _mm_sqrt_ps(f.m_values[i]); + return result; + } + + static UInt16 Abs(const SInt16 &a) + { + __m128i signBitsXor = _mm_srai_epi16(a.m_value, 15); + __m128i signBitsAdd = _mm_srli_epi16(a.m_value, 15); + + UInt16 result; + result.m_value = _mm_add_epi16(_mm_xor_si128(a.m_value, signBitsXor), signBitsAdd); + return result; + } + + static Float Abs(const Float& a) + { + __m128 invMask = _mm_set1_ps(-0.0f); + + Float result; + result.m_values[0] = _mm_andnot_ps(invMask, a.m_values[0]); + result.m_values[1] = _mm_andnot_ps(invMask, a.m_values[1]); + return result; + } + + static UInt16 SqDiffUInt8(const UInt15 &a, const UInt15 &b) + { + __m128i diff = _mm_sub_epi16(a.m_value, b.m_value); + + UInt16 result; + result.m_value = _mm_mullo_epi16(diff, diff); + return result; + } + + static Float SqDiffSInt16(const SInt16 &a, const SInt16 &b) + { + __m128i diffU = _mm_sub_epi16(_mm_max_epi16(a.m_value, b.m_value), _mm_min_epi16(a.m_value, b.m_value)); + + __m128i mulHi = _mm_mulhi_epu16(diffU, diffU); + __m128i mulLo = _mm_mullo_epi16(diffU, diffU); + __m128i sqDiffHi = _mm_unpackhi_epi16(mulLo, mulHi); + __m128i sqDiffLo = _mm_unpacklo_epi16(mulLo, mulHi); + + Float result; + result.m_values[0] = _mm_cvtepi32_ps(sqDiffLo); + result.m_values[1] = _mm_cvtepi32_ps(sqDiffHi); + + return result; + } + + static Float TwosCLHalfToFloat(const SInt16 &v) + { + __m128i absV = _mm_add_epi16(_mm_xor_si128(v.m_value, _mm_srai_epi16(v.m_value, 15)), _mm_srli_epi16(v.m_value, 15)); + + __m128i signBits = _mm_and_si128(v.m_value, _mm_set1_epi16(-32768)); + __m128i mantissa = _mm_and_si128(v.m_value, _mm_set1_epi16(0x03ff)); + __m128i exponent = _mm_and_si128(v.m_value, _mm_set1_epi16(0x7c00)); + + __m128i isDenormal = _mm_cmpeq_epi16(exponent, _mm_setzero_si128()); + + // Convert exponent to high-bits + exponent = _mm_add_epi16(_mm_srli_epi16(exponent, 3), _mm_set1_epi16(14336)); + + __m128i denormalCorrectionHigh = _mm_and_si128(isDenormal, _mm_or_si128(signBits, _mm_set1_epi16(14336))); + + __m128i highBits = _mm_or_si128(signBits, _mm_or_si128(exponent, _mm_srli_epi16(mantissa, 3))); + __m128i lowBits = _mm_slli_epi16(mantissa, 13); + + __m128i flow = _mm_unpacklo_epi16(lowBits, highBits); + __m128i fhigh = _mm_unpackhi_epi16(lowBits, highBits); + + __m128i correctionLow = _mm_unpacklo_epi16(_mm_setzero_si128(), denormalCorrectionHigh); + __m128i correctionHigh = _mm_unpackhi_epi16(_mm_setzero_si128(), denormalCorrectionHigh); + + Float result; + result.m_values[0] = _mm_sub_ps(_mm_castsi128_ps(flow), _mm_castsi128_ps(correctionLow)); + result.m_values[1] = _mm_sub_ps(_mm_castsi128_ps(fhigh), _mm_castsi128_ps(correctionHigh)); + + return result; + } + + static Float SqDiff2CLFloat(const SInt16 &a, const Float &b) + { + Float fa = TwosCLHalfToFloat(a); + + Float diff = fa - b; + return diff * diff; + } + + static Float SqDiff2CL(const SInt16 &a, const SInt16 &b) + { + Float fa = TwosCLHalfToFloat(a); + Float fb = TwosCLHalfToFloat(b); + + Float diff = fa - fb; + return diff * diff; + } + + static Float SqDiff2CLFloat(const SInt16 &a, float aWeight, const Float &b) + { + Float fa = TwosCLHalfToFloat(a) * aWeight; + + Float diff = fa - b; + return diff * diff; + } + + static UInt16 RightShift(const UInt16 &v, int bits) + { + UInt16 result; + result.m_value = _mm_srli_epi16(v.m_value, bits); + return result; + } + + static UInt31 RightShift(const UInt31 &v, int bits) + { + UInt31 result; + result.m_values[0] = _mm_srli_epi32(v.m_values[0], bits); + result.m_values[1] = _mm_srli_epi32(v.m_values[1], bits); + return result; + } + + static SInt16 RightShift(const SInt16 &v, int bits) + { + SInt16 result; + result.m_value = _mm_srai_epi16(v.m_value, bits); + return result; + } + + static UInt15 RightShift(const UInt15 &v, int bits) + { + UInt15 result; + result.m_value = _mm_srli_epi16(v.m_value, bits); + return result; + } + + static SInt32 RightShift(const SInt32 &v, int bits) + { + SInt32 result; + result.m_values[0] = _mm_srai_epi32(v.m_values[0], bits); + result.m_values[1] = _mm_srai_epi32(v.m_values[1], bits); + return result; + } + + static SInt16 ToSInt16(const SInt32 &v) + { + SInt16 result; + result.m_value = _mm_packs_epi32(v.m_values[0], v.m_values[1]); + return result; + } + + static UInt16 ToUInt16(const UInt32 &v) + { + __m128i low = _mm_srai_epi32(_mm_slli_epi32(v.m_values[0], 16), 16); + __m128i high = _mm_srai_epi32(_mm_slli_epi32(v.m_values[1], 16), 16); + + UInt16 result; + result.m_value = _mm_packs_epi32(low, high); + return result; + } + + static UInt16 ToUInt16(const UInt31 &v) + { + __m128i low = _mm_srai_epi32(_mm_slli_epi32(v.m_values[0], 16), 16); + __m128i high = _mm_srai_epi32(_mm_slli_epi32(v.m_values[1], 16), 16); + + UInt16 result; + result.m_value = _mm_packs_epi32(low, high); + return result; + } + + static UInt15 ToUInt15(const UInt31 &v) + { + UInt15 result; + result.m_value = _mm_packs_epi32(v.m_values[0], v.m_values[1]); + return result; + } + + static SInt32 XMultiply(const SInt16 &a, const SInt16 &b) + { + __m128i high = _mm_mulhi_epi16(a.m_value, b.m_value); + __m128i low = _mm_mullo_epi16(a.m_value, b.m_value); + + SInt32 result; + result.m_values[0] = _mm_unpacklo_epi16(low, high); + result.m_values[1] = _mm_unpackhi_epi16(low, high); + return result; + } + + static SInt32 XMultiply(const SInt16 &a, const UInt15 &b) + { + __m128i high = _mm_mulhi_epi16(a.m_value, b.m_value); + __m128i low = _mm_mullo_epi16(a.m_value, b.m_value); + + SInt32 result; + result.m_values[0] = _mm_unpacklo_epi16(low, high); + result.m_values[1] = _mm_unpackhi_epi16(low, high); + return result; + } + + static SInt32 XMultiply(const UInt15 &a, const SInt16 &b) + { + return XMultiply(b, a); + } + + static UInt32 XMultiply(const UInt16 &a, const UInt16 &b) + { + __m128i high = _mm_mulhi_epu16(a.m_value, b.m_value); + __m128i low = _mm_mullo_epi16(a.m_value, b.m_value); + + UInt32 result; + result.m_values[0] = _mm_unpacklo_epi16(low, high); + result.m_values[1] = _mm_unpackhi_epi16(low, high); + return result; + } + + static UInt16 CompactMultiply(const UInt16 &a, const UInt15 &b) + { + UInt16 result; + result.m_value = _mm_mullo_epi16(a.m_value, b.m_value); + return result; + } + + static UInt16 CompactMultiply(const UInt15 &a, const UInt15 &b) + { + UInt16 result; + result.m_value = _mm_mullo_epi16(a.m_value, b.m_value); + return result; + } + + static UInt31 XMultiply(const UInt15 &a, const UInt15 &b) + { + __m128i high = _mm_mulhi_epu16(a.m_value, b.m_value); + __m128i low = _mm_mullo_epi16(a.m_value, b.m_value); + + UInt31 result; + result.m_values[0] = _mm_unpacklo_epi16(low, high); + result.m_values[1] = _mm_unpackhi_epi16(low, high); + return result; + } + + static UInt31 XMultiply(const UInt16 &a, const UInt15 &b) + { + __m128i high = _mm_mulhi_epu16(a.m_value, b.m_value); + __m128i low = _mm_mullo_epi16(a.m_value, b.m_value); + + UInt31 result; + result.m_values[0] = _mm_unpacklo_epi16(low, high); + result.m_values[1] = _mm_unpackhi_epi16(low, high); + return result; + } + + static UInt31 XMultiply(const UInt15 &a, const UInt16 &b) + { + return XMultiply(b, a); + } + + static bool AnySet(Int16CompFlag v) + { + return _mm_movemask_epi8(v.m_value) != 0; + } + + static bool AllSet(Int16CompFlag v) + { + return _mm_movemask_epi8(v.m_value) == 0xffff; + } + + static bool AnySet(FloatCompFlag v) + { + return _mm_movemask_ps(v.m_values[0]) != 0 || _mm_movemask_ps(v.m_values[1]) != 0; + } + + static bool AllSet(FloatCompFlag v) + { + return _mm_movemask_ps(v.m_values[0]) == 0xf && _mm_movemask_ps(v.m_values[1]) == 0xf; + } + }; + +#else + // Scalar version + struct ParallelMath + { + struct RoundTowardZeroForScope + { + }; + + struct RoundTowardNearestForScope + { + }; + + struct RoundUpForScope + { + }; + + struct RoundDownForScope + { + }; + + static const int ParallelSize = 1; + + enum Int16Subtype + { + IntSubtype_Signed, + IntSubtype_UnsignedFull, + IntSubtype_UnsignedTruncated, + IntSubtype_Abstract, + }; + + typedef int32_t SInt16; + typedef int32_t UInt15; + typedef int32_t UInt16; + typedef int32_t AInt16; + + typedef int32_t SInt32; + typedef int32_t UInt31; + typedef int32_t UInt32; + typedef int32_t AInt32; + + typedef int32_t ScalarUInt16; + typedef int32_t ScalarSInt16; + + typedef float Float; + + template<class TTargetType> + struct LosslessCast + { + static const int32_t& Cast(const int32_t &src) + { + return src; + } + }; + + typedef bool Int16CompFlag; + typedef bool FloatCompFlag; + + static int32_t AbstractAdd(const int32_t &a, const int32_t &b) + { + return a + b; + } + + static int32_t AbstractSubtract(const int32_t &a, const int32_t &b) + { + return a - b; + } + + static float Select(bool flag, float a, float b) + { + return flag ? a : b; + } + + static int32_t Select(bool flag, int32_t a, int32_t b) + { + return flag ? a : b; + } + + static int32_t SelectOrZero(bool flag, int32_t a) + { + return flag ? a : 0; + } + + static void ConditionalSet(int32_t& dest, bool flag, int32_t src) + { + if (flag) + dest = src; + } + + static int32_t ConditionalNegate(bool flag, int32_t v) + { + return (flag) ? -v : v; + } + + static void NotConditionalSet(int32_t& dest, bool flag, int32_t src) + { + if (!flag) + dest = src; + } + + static void ConditionalSet(float& dest, bool flag, float src) + { + if (flag) + dest = src; + } + + static void NotConditionalSet(float& dest, bool flag, float src) + { + if (!flag) + dest = src; + } + + static void MakeSafeDenominator(float& v) + { + if (v == 0.0f) + v = 1.0f; + } + + static int32_t SignedRightShift(int32_t v, int bits) + { + return v >> bits; + } + + static int32_t TruncateToPrecisionSigned(int32_t v, int precision) + { + v = (v << (32 - precision)) & 0xffffffff; + return SignedRightShift(v, 32 - precision); + } + + static int32_t TruncateToPrecisionUnsigned(int32_t v, int precision) + { + return v & ((1 << precision) - 1); + } + + static int32_t Min(int32_t a, int32_t b) + { + if (a < b) + return a; + return b; + } + + static float Min(float a, float b) + { + if (a < b) + return a; + return b; + } + + static int32_t Max(int32_t a, int32_t b) + { + if (a > b) + return a; + return b; + } + + static float Max(float a, float b) + { + if (a > b) + return a; + return b; + } + + static float Abs(float a) + { + return fabsf(a); + } + + static int32_t Abs(int32_t a) + { + if (a < 0) + return -a; + return a; + } + + static float Clamp(float v, float min, float max) + { + if (v < min) + return min; + if (v > max) + return max; + return v; + } + + static float Reciprocal(float v) + { + return 1.0f / v; + } + + static void ConvertLDRInputs(const PixelBlockU8* inputBlocks, int pxOffset, int channel, int32_t& chOut) + { + chOut = inputBlocks[0].m_pixels[pxOffset][channel]; + } + + static void ConvertHDRInputs(const PixelBlockF16* inputBlocks, int pxOffset, int channel, int32_t& chOut) + { + chOut = inputBlocks[0].m_pixels[pxOffset][channel]; + } + + static float MakeFloat(float v) + { + return v; + } + + static float MakeFloatZero() + { + return 0.0f; + } + + static int32_t MakeUInt16(uint16_t v) + { + return v; + } + + static int32_t MakeSInt16(int16_t v) + { + return v; + } + + static int32_t MakeAInt16(int16_t v) + { + return v; + } + + static int32_t MakeUInt15(uint16_t v) + { + return v; + } + + static int32_t MakeSInt32(int32_t v) + { + return v; + } + + static int32_t MakeUInt31(int32_t v) + { + return v; + } + + static int32_t Extract(int32_t v, int offset) + { + UNREFERENCED_PARAMETER(offset); + return v; + } + + static void PutUInt16(int32_t &dest, int offset, ParallelMath::ScalarUInt16 v) + { + UNREFERENCED_PARAMETER(offset); + dest = v; + } + + static void PutUInt15(int32_t &dest, int offset, ParallelMath::ScalarUInt16 v) + { + UNREFERENCED_PARAMETER(offset); + dest = v; + } + + static void PutSInt16(int32_t &dest, int offset, ParallelMath::ScalarSInt16 v) + { + UNREFERENCED_PARAMETER(offset); + dest = v; + } + + static float ExtractFloat(float v, int offset) + { + UNREFERENCED_PARAMETER(offset); + return v; + } + + static void PutFloat(float &dest, int offset, float v) + { + UNREFERENCED_PARAMETER(offset); + dest = v; + } + + static bool Less(int32_t a, int32_t b) + { + return a < b; + } + + static bool Less(float a, float b) + { + return a < b; + } + + static bool LessOrEqual(int32_t a, int32_t b) + { + return a < b; + } + + static bool LessOrEqual(float a, float b) + { + return a < b; + } + + static bool Equal(int32_t a, int32_t b) + { + return a == b; + } + + static bool Equal(float a, float b) + { + return a == b; + } + + static float ToFloat(int32_t v) + { + return static_cast<float>(v); + } + + static int32_t ToUInt31(int32_t v) + { + return v; + } + + static int32_t ToInt32(int32_t v) + { + return v; + } + + static bool FloatFlagToInt16(bool v) + { + return v; + } + + static bool Int16FlagToFloat(bool v) + { + return v; + } + + static bool AndNot(bool a, bool b) + { + return a && !b; + } + + static int32_t RoundAndConvertToInt(float v, const ParallelMath::RoundTowardZeroForScope *rtz) + { + UNREFERENCED_PARAMETER(rtz); + return static_cast<int>(v); + } + + static int32_t RoundAndConvertToInt(float v, const ParallelMath::RoundUpForScope *ru) + { + UNREFERENCED_PARAMETER(ru); + return static_cast<int>(ceilf(v)); + } + + static int32_t RoundAndConvertToInt(float v, const ParallelMath::RoundDownForScope *rd) + { + UNREFERENCED_PARAMETER(rd); + return static_cast<int>(floorf(v)); + } + + static int32_t RoundAndConvertToInt(float v, const ParallelMath::RoundTowardNearestForScope *rtn) + { + UNREFERENCED_PARAMETER(rtn); + return static_cast<int>(floorf(v + 0.5f)); + } + + template<class TRoundMode> + static int32_t RoundAndConvertToU16(float v, const TRoundMode *roundingMode) + { + return RoundAndConvertToInt(v, roundingMode); + } + + template<class TRoundMode> + static int32_t RoundAndConvertToU15(float v, const TRoundMode *roundingMode) + { + return RoundAndConvertToInt(v, roundingMode); + } + + template<class TRoundMode> + static int32_t RoundAndConvertToS16(float v, const TRoundMode *roundingMode) + { + return RoundAndConvertToInt(v, roundingMode); + } + + static float Sqrt(float f) + { + return sqrtf(f); + } + + static int32_t SqDiffUInt8(int32_t a, int32_t b) + { + int32_t delta = a - b; + return delta * delta; + } + + static int32_t SqDiffInt16(int32_t a, int32_t b) + { + int32_t delta = a - b; + return delta * delta; + } + + static int32_t SqDiffSInt16(int32_t a, int32_t b) + { + int32_t delta = a - b; + return delta * delta; + } + + static float TwosCLHalfToFloat(int32_t v) + { + int32_t absV = (v < 0) ? -v : v; + + int32_t signBits = (absV & -32768); + int32_t mantissa = (absV & 0x03ff); + int32_t exponent = (absV & 0x7c00); + + bool isDenormal = (exponent == 0); + + // Convert exponent to high-bits + exponent = (exponent >> 3) + 14336; + + int32_t denormalCorrection = (isDenormal ? (signBits | 14336) : 0) << 16; + + int32_t fBits = ((exponent | signBits) << 16) | (mantissa << 13); + + float f, correction; + memcpy(&f, &fBits, 4); + memcpy(&correction, &denormalCorrection, 4); + + return f - correction; + } + + static Float SqDiff2CLFloat(const SInt16 &a, const Float &b) + { + Float fa = TwosCLHalfToFloat(a); + + Float diff = fa - b; + return diff * diff; + } + + static Float SqDiff2CL(const SInt16 &a, const SInt16 &b) + { + Float fa = TwosCLHalfToFloat(a); + Float fb = TwosCLHalfToFloat(b); + + Float diff = fa - fb; + return diff * diff; + } + + static Float SqDiff2CLFloat(const SInt16 &a, float aWeight, const Float &b) + { + Float fa = TwosCLHalfToFloat(a) * aWeight; + + Float diff = fa - b; + return diff * diff; + } + + static int32_t RightShift(int32_t v, int bits) + { + return SignedRightShift(v, bits); + } + + static int32_t ToSInt16(int32_t v) + { + return v; + } + + static int32_t ToUInt16(int32_t v) + { + return v; + } + + static int32_t ToUInt15(int32_t v) + { + return v; + } + + static int32_t XMultiply(int32_t a, int32_t b) + { + return a * b; + } + + static int32_t CompactMultiply(int32_t a, int32_t b) + { + return a * b; + } + + static bool AnySet(bool v) + { + return v; + } + + static bool AllSet(bool v) + { + return v; + } + }; + +#endif + + namespace Internal + { + namespace BC7Data + { + enum AlphaMode + { + AlphaMode_Combined, + AlphaMode_Separate, + AlphaMode_None, + }; + + enum PBitMode + { + PBitMode_PerEndpoint, + PBitMode_PerSubset, + PBitMode_None + }; + + struct BC7ModeInfo + { + PBitMode m_pBitMode; + AlphaMode m_alphaMode; + int m_rgbBits; + int m_alphaBits; + int m_partitionBits; + int m_numSubsets; + int m_indexBits; + int m_alphaIndexBits; + bool m_hasIndexSelector; + }; + + BC7ModeInfo g_modes[] = + { + { PBitMode_PerEndpoint, AlphaMode_None, 4, 0, 4, 3, 3, 0, false }, // 0 + { PBitMode_PerSubset, AlphaMode_None, 6, 0, 6, 2, 3, 0, false }, // 1 + { PBitMode_None, AlphaMode_None, 5, 0, 6, 3, 2, 0, false }, // 2 + { PBitMode_PerEndpoint, AlphaMode_None, 7, 0, 6, 2, 2, 0, false }, // 3 (Mode reference has an error, P-bit is really per-endpoint) + + { PBitMode_None, AlphaMode_Separate, 5, 6, 0, 1, 2, 3, true }, // 4 + { PBitMode_None, AlphaMode_Separate, 7, 8, 0, 1, 2, 2, false }, // 5 + { PBitMode_PerEndpoint, AlphaMode_Combined, 7, 7, 0, 1, 4, 0, false }, // 6 + { PBitMode_PerEndpoint, AlphaMode_Combined, 5, 5, 6, 2, 2, 0, false } // 7 + }; + + const int g_weight2[] = { 0, 21, 43, 64 }; + const int g_weight3[] = { 0, 9, 18, 27, 37, 46, 55, 64 }; + const int g_weight4[] = { 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64 }; + + const int *g_weightTables[] = + { + NULL, + NULL, + g_weight2, + g_weight3, + g_weight4 + }; + + struct BC6HModeInfo + { + uint16_t m_modeID; + bool m_partitioned; + bool m_transformed; + int m_aPrec; + int m_bPrec[3]; + }; + + // [partitioned][precision] + bool g_hdrModesExistForPrecision[2][17] = + { + //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 + { false, false, false, false, false, false, false, false, false, false, true, true, true, false, false, false, true }, + { false, false, false, false, false, false, true, true, true, true, true, true, false, false, false, false, false }, + }; + + BC6HModeInfo g_hdrModes[] = + { + { 0x00, true, true, 10,{ 5, 5, 5 } }, + { 0x01, true, true, 7,{ 6, 6, 6 } }, + { 0x02, true, true, 11,{ 5, 4, 4 } }, + { 0x06, true, true, 11,{ 4, 5, 4 } }, + { 0x0a, true, true, 11,{ 4, 4, 5 } }, + { 0x0e, true, true, 9,{ 5, 5, 5 } }, + { 0x12, true, true, 8,{ 6, 5, 5 } }, + { 0x16, true, true, 8,{ 5, 6, 5 } }, + { 0x1a, true, true, 8,{ 5, 5, 6 } }, + { 0x1e, true, false, 6,{ 6, 6, 6 } }, + { 0x03, false, false, 10,{ 10, 10, 10 } }, + { 0x07, false, true, 11,{ 9, 9, 9 } }, + { 0x0b, false, true, 12,{ 8, 8, 8 } }, + { 0x0f, false, true, 16,{ 4, 4, 4 } }, + }; + + const int g_maxHDRPrecision = 16; + + static const size_t g_numHDRModes = sizeof(g_hdrModes) / sizeof(g_hdrModes[0]); + + static uint16_t g_partitionMap[64] = + { + 0xCCCC, 0x8888, 0xEEEE, 0xECC8, + 0xC880, 0xFEEC, 0xFEC8, 0xEC80, + 0xC800, 0xFFEC, 0xFE80, 0xE800, + 0xFFE8, 0xFF00, 0xFFF0, 0xF000, + 0xF710, 0x008E, 0x7100, 0x08CE, + 0x008C, 0x7310, 0x3100, 0x8CCE, + 0x088C, 0x3110, 0x6666, 0x366C, + 0x17E8, 0x0FF0, 0x718E, 0x399C, + 0xaaaa, 0xf0f0, 0x5a5a, 0x33cc, + 0x3c3c, 0x55aa, 0x9696, 0xa55a, + 0x73ce, 0x13c8, 0x324c, 0x3bdc, + 0x6996, 0xc33c, 0x9966, 0x660, + 0x272, 0x4e4, 0x4e40, 0x2720, + 0xc936, 0x936c, 0x39c6, 0x639c, + 0x9336, 0x9cc6, 0x817e, 0xe718, + 0xccf0, 0xfcc, 0x7744, 0xee22, + }; + + static uint32_t g_partitionMap2[64] = + { + 0xaa685050, 0x6a5a5040, 0x5a5a4200, 0x5450a0a8, + 0xa5a50000, 0xa0a05050, 0x5555a0a0, 0x5a5a5050, + 0xaa550000, 0xaa555500, 0xaaaa5500, 0x90909090, + 0x94949494, 0xa4a4a4a4, 0xa9a59450, 0x2a0a4250, + 0xa5945040, 0x0a425054, 0xa5a5a500, 0x55a0a0a0, + 0xa8a85454, 0x6a6a4040, 0xa4a45000, 0x1a1a0500, + 0x0050a4a4, 0xaaa59090, 0x14696914, 0x69691400, + 0xa08585a0, 0xaa821414, 0x50a4a450, 0x6a5a0200, + 0xa9a58000, 0x5090a0a8, 0xa8a09050, 0x24242424, + 0x00aa5500, 0x24924924, 0x24499224, 0x50a50a50, + 0x500aa550, 0xaaaa4444, 0x66660000, 0xa5a0a5a0, + 0x50a050a0, 0x69286928, 0x44aaaa44, 0x66666600, + 0xaa444444, 0x54a854a8, 0x95809580, 0x96969600, + 0xa85454a8, 0x80959580, 0xaa141414, 0x96960000, + 0xaaaa1414, 0xa05050a0, 0xa0a5a5a0, 0x96000000, + 0x40804080, 0xa9a8a9a8, 0xaaaaaa44, 0x2a4a5254, + }; + + static int g_fixupIndexes2[64] = + { + 15,15,15,15, + 15,15,15,15, + 15,15,15,15, + 15,15,15,15, + 15, 2, 8, 2, + 2, 8, 8,15, + 2, 8, 2, 2, + 8, 8, 2, 2, + + 15,15, 6, 8, + 2, 8,15,15, + 2, 8, 2, 2, + 2,15,15, 6, + 6, 2, 6, 8, + 15,15, 2, 2, + 15,15,15,15, + 15, 2, 2,15, + }; + + static int g_fixupIndexes3[64][2] = + { + { 3,15 },{ 3, 8 },{ 15, 8 },{ 15, 3 }, + { 8,15 },{ 3,15 },{ 15, 3 },{ 15, 8 }, + { 8,15 },{ 8,15 },{ 6,15 },{ 6,15 }, + { 6,15 },{ 5,15 },{ 3,15 },{ 3, 8 }, + { 3,15 },{ 3, 8 },{ 8,15 },{ 15, 3 }, + { 3,15 },{ 3, 8 },{ 6,15 },{ 10, 8 }, + { 5, 3 },{ 8,15 },{ 8, 6 },{ 6,10 }, + { 8,15 },{ 5,15 },{ 15,10 },{ 15, 8 }, + + { 8,15 },{ 15, 3 },{ 3,15 },{ 5,10 }, + { 6,10 },{ 10, 8 },{ 8, 9 },{ 15,10 }, + { 15, 6 },{ 3,15 },{ 15, 8 },{ 5,15 }, + { 15, 3 },{ 15, 6 },{ 15, 6 },{ 15, 8 }, + { 3,15 },{ 15, 3 },{ 5,15 },{ 5,15 }, + { 5,15 },{ 8,15 },{ 5,15 },{ 10,15 }, + { 5,15 },{ 10,15 },{ 8,15 },{ 13,15 }, + { 15, 3 },{ 12,15 },{ 3,15 },{ 3, 8 }, + }; + + static const unsigned char g_fragments[] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 0, 16 + 0, 1, 2, 3, // 16, 4 + 0, 1, 4, // 20, 3 + 0, 1, 2, 4, // 23, 4 + 2, 3, 7, // 27, 3 + 1, 2, 3, 7, // 30, 4 + 0, 1, 2, 3, 4, 5, 6, 7, // 34, 8 + 0, 1, 4, 8, // 42, 4 + 0, 1, 2, 4, 5, 8, // 46, 6 + 0, 1, 2, 3, 4, 5, 6, 8, // 52, 8 + 1, 4, 5, 6, 9, // 60, 5 + 2, 5, 6, 7, 10, // 65, 5 + 5, 6, 9, 10, // 70, 4 + 2, 3, 7, 11, // 74, 4 + 1, 2, 3, 6, 7, 11, // 78, 6 + 0, 1, 2, 3, 5, 6, 7, 11, // 84, 8 + 0, 1, 2, 3, 8, 9, 10, 11, // 92, 8 + 2, 3, 6, 7, 8, 9, 10, 11, // 100, 8 + 4, 5, 6, 7, 8, 9, 10, 11, // 108, 8 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, // 116, 12 + 0, 4, 8, 12, // 128, 4 + 0, 2, 3, 4, 6, 7, 8, 12, // 132, 8 + 0, 1, 2, 4, 5, 8, 9, 12, // 140, 8 + 0, 1, 2, 3, 4, 5, 6, 8, 9, 12, // 148, 10 + 3, 6, 7, 8, 9, 12, // 158, 6 + 3, 5, 6, 7, 8, 9, 10, 12, // 164, 8 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, // 172, 12 + 0, 1, 2, 5, 6, 7, 11, 12, // 184, 8 + 5, 8, 9, 10, 13, // 192, 5 + 8, 12, 13, // 197, 3 + 4, 8, 12, 13, // 200, 4 + 2, 3, 6, 9, 12, 13, // 204, 6 + 0, 1, 2, 3, 8, 9, 12, 13, // 210, 8 + 0, 1, 4, 5, 8, 9, 12, 13, // 218, 8 + 2, 3, 6, 7, 8, 9, 12, 13, // 226, 8 + 2, 3, 5, 6, 9, 10, 12, 13, // 234, 8 + 0, 3, 6, 7, 9, 10, 12, 13, // 242, 8 + 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 13, // 250, 12 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, // 262, 13 + 2, 3, 4, 7, 8, 11, 12, 13, // 275, 8 + 1, 2, 6, 7, 8, 11, 12, 13, // 283, 8 + 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, // 291, 10 + 2, 3, 4, 5, 10, 11, 12, 13, // 301, 8 + 0, 1, 6, 7, 10, 11, 12, 13, // 309, 8 + 6, 9, 10, 11, 14, // 317, 5 + 0, 2, 4, 6, 8, 10, 12, 14, // 322, 8 + 1, 3, 5, 7, 8, 10, 12, 14, // 330, 8 + 1, 3, 4, 6, 9, 11, 12, 14, // 338, 8 + 0, 2, 5, 7, 9, 11, 12, 14, // 346, 8 + 0, 3, 4, 5, 8, 9, 13, 14, // 354, 8 + 2, 3, 4, 7, 8, 9, 13, 14, // 362, 8 + 1, 2, 5, 6, 9, 10, 13, 14, // 370, 8 + 0, 3, 4, 7, 9, 10, 13, 14, // 378, 8 + 0, 3, 5, 6, 8, 11, 13, 14, // 386, 8 + 1, 2, 4, 7, 8, 11, 13, 14, // 394, 8 + 0, 1, 4, 7, 10, 11, 13, 14, // 402, 8 + 0, 3, 6, 7, 10, 11, 13, 14, // 410, 8 + 8, 12, 13, 14, // 418, 4 + 1, 2, 3, 7, 8, 12, 13, 14, // 422, 8 + 4, 8, 9, 12, 13, 14, // 430, 6 + 0, 4, 5, 8, 9, 12, 13, 14, // 436, 8 + 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, // 444, 10 + 2, 6, 8, 9, 10, 12, 13, 14, // 454, 8 + 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, // 462, 12 + 0, 7, 9, 10, 11, 12, 13, 14, // 474, 8 + 1, 2, 3, 4, 5, 6, 8, 15, // 482, 8 + 3, 7, 11, 15, // 490, 4 + 0, 1, 3, 4, 5, 7, 11, 15, // 494, 8 + 0, 4, 5, 10, 11, 15, // 502, 6 + 1, 2, 3, 6, 7, 10, 11, 15, // 508, 8 + 0, 1, 2, 3, 5, 6, 7, 10, 11, 15, // 516, 10 + 0, 4, 5, 6, 9, 10, 11, 15, // 526, 8 + 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 15, // 534, 12 + 1, 2, 4, 5, 8, 9, 12, 15, // 546, 8 + 2, 3, 5, 6, 8, 9, 12, 15, // 554, 8 + 0, 3, 5, 6, 9, 10, 12, 15, // 562, 8 + 1, 2, 4, 7, 9, 10, 12, 15, // 570, 8 + 1, 2, 5, 6, 8, 11, 12, 15, // 578, 8 + 0, 3, 4, 7, 8, 11, 12, 15, // 586, 8 + 0, 1, 5, 6, 10, 11, 12, 15, // 594, 8 + 1, 2, 6, 7, 10, 11, 12, 15, // 602, 8 + 1, 3, 4, 6, 8, 10, 13, 15, // 610, 8 + 0, 2, 5, 7, 8, 10, 13, 15, // 618, 8 + 0, 2, 4, 6, 9, 11, 13, 15, // 626, 8 + 1, 3, 5, 7, 9, 11, 13, 15, // 634, 8 + 0, 1, 2, 3, 4, 5, 7, 8, 12, 13, 15, // 642, 11 + 2, 3, 4, 5, 8, 9, 14, 15, // 653, 8 + 0, 1, 6, 7, 8, 9, 14, 15, // 661, 8 + 0, 1, 5, 10, 14, 15, // 669, 6 + 0, 3, 4, 5, 9, 10, 14, 15, // 675, 8 + 0, 1, 5, 6, 9, 10, 14, 15, // 683, 8 + 11, 14, 15, // 691, 3 + 7, 11, 14, 15, // 694, 4 + 1, 2, 4, 5, 8, 11, 14, 15, // 698, 8 + 0, 1, 4, 7, 8, 11, 14, 15, // 706, 8 + 0, 1, 4, 5, 10, 11, 14, 15, // 714, 8 + 2, 3, 6, 7, 10, 11, 14, 15, // 722, 8 + 4, 5, 6, 7, 10, 11, 14, 15, // 730, 8 + 0, 1, 4, 5, 7, 8, 10, 11, 14, 15, // 738, 10 + 0, 1, 2, 3, 5, 6, 7, 9, 10, 11, 14, 15, // 748, 12 + 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 14, 15, // 760, 13 + 0, 1, 2, 3, 4, 6, 7, 11, 12, 14, 15, // 773, 11 + 3, 4, 8, 9, 10, 13, 14, 15, // 784, 8 + 11, 13, 14, 15, // 792, 4 + 0, 1, 2, 4, 11, 13, 14, 15, // 796, 8 + 0, 1, 2, 4, 5, 10, 11, 13, 14, 15, // 804, 10 + 7, 10, 11, 13, 14, 15, // 814, 6 + 3, 6, 7, 10, 11, 13, 14, 15, // 820, 8 + 1, 5, 9, 10, 11, 13, 14, 15, // 828, 8 + 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15, // 836, 12 + 12, 13, 14, 15, // 848, 4 + 0, 1, 2, 3, 12, 13, 14, 15, // 852, 8 + 0, 1, 4, 5, 12, 13, 14, 15, // 860, 8 + 4, 5, 6, 7, 12, 13, 14, 15, // 868, 8 + 4, 8, 9, 10, 12, 13, 14, 15, // 876, 8 + 0, 4, 5, 8, 9, 10, 12, 13, 14, 15, // 884, 10 + 0, 1, 4, 5, 6, 8, 9, 10, 12, 13, 14, 15, // 894, 12 + 0, 1, 2, 3, 4, 7, 8, 11, 12, 13, 14, 15, // 906, 12 + 0, 1, 3, 4, 8, 9, 11, 12, 13, 14, 15, // 918, 11 + 0, 2, 3, 7, 8, 10, 11, 12, 13, 14, 15, // 929, 11 + 7, 9, 10, 11, 12, 13, 14, 15, // 940, 8 + 3, 6, 7, 9, 10, 11, 12, 13, 14, 15, // 948, 10 + 2, 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, // 958, 12 + 8, 9, 10, 11, 12, 13, 14, 15, // 970, 8 + 0, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, // 978, 12 + 0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, // 990, 13 + 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 1003, 12 + 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 1015, 13 + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 1028, 12 + 0, 2, // 1040, 2 + 1, 3, // 1042, 2 + 0, 1, 4, 5, // 1044, 4 + 0, 1, 2, 4, 5, // 1048, 5 + 2, 3, 6, // 1053, 3 + 0, 2, 4, 6, // 1056, 4 + 1, 2, 5, 6, // 1060, 4 + 0, 1, 2, 3, 5, 6, // 1064, 6 + 0, 1, 2, 4, 5, 6, // 1070, 6 + 0, 1, 2, 3, 4, 5, 6, // 1076, 7 + 0, 3, 4, 7, // 1083, 4 + 0, 1, 2, 3, 4, 7, // 1087, 6 + 1, 3, 5, 7, // 1093, 4 + 2, 3, 6, 7, // 1097, 4 + 1, 2, 3, 6, 7, // 1101, 5 + 1, 2, 3, 5, 6, 7, // 1106, 6 + 0, 1, 2, 3, 5, 6, 7, // 1112, 7 + 4, 5, 6, 7, // 1119, 4 + 0, 8, // 1123, 2 + 0, 1, 4, 5, 8, // 1125, 5 + 0, 1, 8, 9, // 1130, 4 + 4, 5, 8, 9, // 1134, 4 + 0, 1, 4, 5, 8, 9, // 1138, 6 + 2, 6, 8, 9, // 1144, 4 + 6, 7, 8, 9, // 1148, 4 + 0, 2, 4, 6, 8, 10, // 1152, 6 + 1, 2, 5, 6, 9, 10, // 1158, 6 + 0, 3, 4, 7, 9, 10, // 1164, 6 + 0, 1, 2, 8, 9, 10, // 1170, 6 + 4, 5, 6, 8, 9, 10, // 1176, 6 + 3, 11, // 1182, 2 + 2, 3, 6, 7, 11, // 1184, 5 + 0, 3, 8, 11, // 1189, 4 + 0, 3, 4, 7, 8, 11, // 1193, 6 + 1, 3, 5, 7, 9, 11, // 1199, 6 + 2, 3, 10, 11, // 1205, 4 + 1, 5, 10, 11, // 1209, 4 + 4, 5, 10, 11, // 1213, 4 + 6, 7, 10, 11, // 1217, 4 + 2, 3, 6, 7, 10, 11, // 1221, 6 + 1, 2, 3, 9, 10, 11, // 1227, 6 + 5, 6, 7, 9, 10, 11, // 1233, 6 + 8, 9, 10, 11, // 1239, 4 + 4, 12, // 1243, 2 + 0, 1, 2, 3, 4, 5, 8, 12, // 1245, 8 + 8, 9, 12, // 1253, 3 + 0, 4, 5, 8, 9, 12, // 1256, 6 + 0, 1, 4, 5, 8, 9, 12, // 1262, 7 + 2, 3, 5, 6, 8, 9, 12, // 1269, 7 + 1, 5, 9, 13, // 1276, 4 + 6, 7, 9, 13, // 1280, 4 + 1, 4, 7, 10, 13, // 1284, 5 + 1, 6, 8, 11, 13, // 1289, 5 + 0, 1, 12, 13, // 1294, 4 + 4, 5, 12, 13, // 1298, 4 + 0, 1, 6, 7, 12, 13, // 1302, 6 + 0, 1, 4, 8, 12, 13, // 1308, 6 + 8, 9, 12, 13, // 1314, 4 + 4, 8, 9, 12, 13, // 1318, 5 + 4, 5, 8, 9, 12, 13, // 1323, 6 + 0, 4, 5, 8, 9, 12, 13, // 1329, 7 + 0, 1, 6, 10, 12, 13, // 1336, 6 + 3, 6, 7, 9, 10, 12, 13, // 1342, 7 + 0, 1, 10, 11, 12, 13, // 1349, 6 + 2, 4, 7, 9, 14, // 1355, 5 + 4, 5, 10, 14, // 1360, 4 + 2, 6, 10, 14, // 1364, 4 + 2, 5, 8, 11, 14, // 1368, 5 + 0, 2, 12, 14, // 1373, 4 + 8, 10, 12, 14, // 1377, 4 + 4, 6, 8, 10, 12, 14, // 1381, 6 + 13, 14, // 1387, 2 + 9, 10, 13, 14, // 1389, 4 + 5, 6, 9, 10, 13, 14, // 1393, 6 + 0, 1, 2, 12, 13, 14, // 1399, 6 + 4, 5, 6, 12, 13, 14, // 1405, 6 + 8, 9, 12, 13, 14, // 1411, 5 + 8, 9, 10, 12, 13, 14, // 1416, 6 + 7, 15, // 1422, 2 + 0, 5, 10, 15, // 1424, 4 + 0, 1, 2, 3, 6, 7, 11, 15, // 1428, 8 + 10, 11, 15, // 1436, 3 + 0, 1, 5, 6, 10, 11, 15, // 1439, 7 + 3, 6, 7, 10, 11, 15, // 1446, 6 + 12, 15, // 1452, 2 + 0, 3, 12, 15, // 1454, 4 + 4, 7, 12, 15, // 1458, 4 + 0, 3, 6, 9, 12, 15, // 1462, 6 + 0, 3, 5, 10, 12, 15, // 1468, 6 + 8, 11, 12, 15, // 1474, 4 + 5, 6, 8, 11, 12, 15, // 1478, 6 + 4, 7, 8, 11, 12, 15, // 1484, 6 + 1, 3, 13, 15, // 1490, 4 + 9, 11, 13, 15, // 1494, 4 + 5, 7, 9, 11, 13, 15, // 1498, 6 + 2, 3, 14, 15, // 1504, 4 + 2, 3, 4, 5, 14, 15, // 1508, 6 + 6, 7, 14, 15, // 1514, 4 + 2, 3, 5, 9, 14, 15, // 1518, 6 + 2, 3, 8, 9, 14, 15, // 1524, 6 + 10, 14, 15, // 1530, 3 + 0, 4, 5, 9, 10, 14, 15, // 1533, 7 + 2, 3, 7, 11, 14, 15, // 1540, 6 + 10, 11, 14, 15, // 1546, 4 + 7, 10, 11, 14, 15, // 1550, 5 + 6, 7, 10, 11, 14, 15, // 1555, 6 + 1, 2, 3, 13, 14, 15, // 1561, 6 + 5, 6, 7, 13, 14, 15, // 1567, 6 + 10, 11, 13, 14, 15, // 1573, 5 + 9, 10, 11, 13, 14, 15, // 1578, 6 + 0, 4, 8, 9, 12, 13, 14, 15, // 1584, 8 + 9, 10, 12, 13, 14, 15, // 1592, 6 + 8, 11, 12, 13, 14, 15, // 1598, 6 + 3, 7, 10, 11, 12, 13, 14, 15, // 1604, 8 + }; + static const int g_shapeRanges[][2] = + { + { 0, 16 },{ 16, 4 },{ 20, 3 },{ 23, 4 },{ 27, 3 },{ 30, 4 },{ 34, 8 },{ 42, 4 },{ 46, 6 },{ 52, 8 },{ 60, 5 }, + { 65, 5 },{ 70, 4 },{ 74, 4 },{ 78, 6 },{ 84, 8 },{ 92, 8 },{ 100, 8 },{ 108, 8 },{ 116, 12 },{ 128, 4 },{ 132, 8 }, + { 140, 8 },{ 148, 10 },{ 158, 6 },{ 164, 8 },{ 172, 12 },{ 184, 8 },{ 192, 5 },{ 197, 3 },{ 200, 4 },{ 204, 6 },{ 210, 8 }, + { 218, 8 },{ 226, 8 },{ 234, 8 },{ 242, 8 },{ 250, 12 },{ 262, 13 },{ 275, 8 },{ 283, 8 },{ 291, 10 },{ 301, 8 },{ 309, 8 }, + { 317, 5 },{ 322, 8 },{ 330, 8 },{ 338, 8 },{ 346, 8 },{ 354, 8 },{ 362, 8 },{ 370, 8 },{ 378, 8 },{ 386, 8 },{ 394, 8 }, + { 402, 8 },{ 410, 8 },{ 418, 4 },{ 422, 8 },{ 430, 6 },{ 436, 8 },{ 444, 10 },{ 454, 8 },{ 462, 12 },{ 474, 8 },{ 482, 8 }, + { 490, 4 },{ 494, 8 },{ 502, 6 },{ 508, 8 },{ 516, 10 },{ 526, 8 },{ 534, 12 },{ 546, 8 },{ 554, 8 },{ 562, 8 },{ 570, 8 }, + { 578, 8 },{ 586, 8 },{ 594, 8 },{ 602, 8 },{ 610, 8 },{ 618, 8 },{ 626, 8 },{ 634, 8 },{ 642, 11 },{ 653, 8 },{ 661, 8 }, + { 669, 6 },{ 675, 8 },{ 683, 8 },{ 691, 3 },{ 694, 4 },{ 698, 8 },{ 706, 8 },{ 714, 8 },{ 722, 8 },{ 730, 8 },{ 738, 10 }, + { 748, 12 },{ 760, 13 },{ 773, 11 },{ 784, 8 },{ 792, 4 },{ 796, 8 },{ 804, 10 },{ 814, 6 },{ 820, 8 },{ 828, 8 },{ 836, 12 }, + { 848, 4 },{ 852, 8 },{ 860, 8 },{ 868, 8 },{ 876, 8 },{ 884, 10 },{ 894, 12 },{ 906, 12 },{ 918, 11 },{ 929, 11 },{ 940, 8 }, + { 948, 10 },{ 958, 12 },{ 970, 8 },{ 978, 12 },{ 990, 13 },{ 1003, 12 },{ 1015, 13 },{ 1028, 12 },{ 1040, 2 },{ 1042, 2 },{ 1044, 4 }, + { 1048, 5 },{ 1053, 3 },{ 1056, 4 },{ 1060, 4 },{ 1064, 6 },{ 1070, 6 },{ 1076, 7 },{ 1083, 4 },{ 1087, 6 },{ 1093, 4 },{ 1097, 4 }, + { 1101, 5 },{ 1106, 6 },{ 1112, 7 },{ 1119, 4 },{ 1123, 2 },{ 1125, 5 },{ 1130, 4 },{ 1134, 4 },{ 1138, 6 },{ 1144, 4 },{ 1148, 4 }, + { 1152, 6 },{ 1158, 6 },{ 1164, 6 },{ 1170, 6 },{ 1176, 6 },{ 1182, 2 },{ 1184, 5 },{ 1189, 4 },{ 1193, 6 },{ 1199, 6 },{ 1205, 4 }, + { 1209, 4 },{ 1213, 4 },{ 1217, 4 },{ 1221, 6 },{ 1227, 6 },{ 1233, 6 },{ 1239, 4 },{ 1243, 2 },{ 1245, 8 },{ 1253, 3 },{ 1256, 6 }, + { 1262, 7 },{ 1269, 7 },{ 1276, 4 },{ 1280, 4 },{ 1284, 5 },{ 1289, 5 },{ 1294, 4 },{ 1298, 4 },{ 1302, 6 },{ 1308, 6 },{ 1314, 4 }, + { 1318, 5 },{ 1323, 6 },{ 1329, 7 },{ 1336, 6 },{ 1342, 7 },{ 1349, 6 },{ 1355, 5 },{ 1360, 4 },{ 1364, 4 },{ 1368, 5 },{ 1373, 4 }, + { 1377, 4 },{ 1381, 6 },{ 1387, 2 },{ 1389, 4 },{ 1393, 6 },{ 1399, 6 },{ 1405, 6 },{ 1411, 5 },{ 1416, 6 },{ 1422, 2 },{ 1424, 4 }, + { 1428, 8 },{ 1436, 3 },{ 1439, 7 },{ 1446, 6 },{ 1452, 2 },{ 1454, 4 },{ 1458, 4 },{ 1462, 6 },{ 1468, 6 },{ 1474, 4 },{ 1478, 6 }, + { 1484, 6 },{ 1490, 4 },{ 1494, 4 },{ 1498, 6 },{ 1504, 4 },{ 1508, 6 },{ 1514, 4 },{ 1518, 6 },{ 1524, 6 },{ 1530, 3 },{ 1533, 7 }, + { 1540, 6 },{ 1546, 4 },{ 1550, 5 },{ 1555, 6 },{ 1561, 6 },{ 1567, 6 },{ 1573, 5 },{ 1578, 6 },{ 1584, 8 },{ 1592, 6 },{ 1598, 6 }, + { 1604, 8 }, + }; + static const int g_shapes1[][2] = + { + { 0, 16 } + }; + static const int g_shapes2[64][2] = + { + { 33, 96 },{ 63, 66 },{ 20, 109 },{ 22, 107 },{ 37, 92 },{ 7, 122 },{ 8, 121 },{ 23, 106 }, + { 38, 91 },{ 2, 127 },{ 9, 120 },{ 26, 103 },{ 3, 126 },{ 6, 123 },{ 1, 128 },{ 19, 110 }, + { 15, 114 },{ 124, 5 },{ 72, 57 },{ 115, 14 },{ 125, 4 },{ 70, 59 },{ 100, 29 },{ 60, 69 }, + { 116, 13 },{ 99, 30 },{ 78, 51 },{ 94, 35 },{ 104, 25 },{ 111, 18 },{ 71, 58 },{ 90, 39 }, + { 45, 84 },{ 16, 113 },{ 82, 47 },{ 95, 34 },{ 87, 42 },{ 83, 46 },{ 53, 76 },{ 48, 81 }, + { 68, 61 },{ 105, 24 },{ 98, 31 },{ 88, 41 },{ 75, 54 },{ 43, 86 },{ 52, 77 },{ 117, 12 }, + { 119, 10 },{ 118, 11 },{ 85, 44 },{ 101, 28 },{ 36, 93 },{ 55, 74 },{ 89, 40 },{ 79, 50 }, + { 56, 73 },{ 49, 80 },{ 64, 65 },{ 27, 102 },{ 32, 97 },{ 112, 17 },{ 67, 62 },{ 21, 108 }, + }; + static const int g_shapes3[64][3] = + { + { 148, 160, 240 },{ 132, 212, 205 },{ 136, 233, 187 },{ 175, 237, 143 },{ 6, 186, 232 },{ 33, 142, 232 },{ 131, 123, 142 },{ 131, 96, 186 }, + { 6, 171, 110 },{ 1, 18, 110 },{ 1, 146, 123 },{ 33, 195, 66 },{ 20, 51, 66 },{ 20, 178, 96 },{ 2, 177, 106 },{ 211, 4, 59 }, + { 8, 191, 91 },{ 230, 14, 29 },{ 1, 188, 234 },{ 151, 110, 168 },{ 20, 144, 238 },{ 137, 66, 206 },{ 173, 179, 232 },{ 209, 194, 186 }, + { 239, 165, 142 },{ 131, 152, 242 },{ 214, 54, 12 },{ 140, 219, 201 },{ 190, 150, 231 },{ 156, 135, 241 },{ 185, 227, 167 },{ 145, 210, 59 }, + { 138, 174, 106 },{ 189, 229, 14 },{ 176, 133, 106 },{ 78, 178, 195 },{ 111, 146, 171 },{ 216, 180, 196 },{ 217, 181, 193 },{ 184, 228, 166 }, + { 192, 225, 153 },{ 134, 141, 123 },{ 6, 222, 198 },{ 149, 183, 96 },{ 33, 226, 164 },{ 161, 215, 51 },{ 197, 221, 18 },{ 1, 223, 199 }, + { 154, 163, 110 },{ 20, 236, 169 },{ 157, 204, 66 },{ 1, 202, 220 },{ 20, 170, 235 },{ 203, 158, 66 },{ 162, 155, 110 },{ 6, 201, 218 }, + { 139, 135, 123 },{ 33, 167, 224 },{ 182, 150, 96 },{ 19, 200, 213 },{ 63, 207, 159 },{ 147, 172, 109 },{ 129, 130, 128 },{ 208, 14, 59 }, + }; + + static const int g_shapeList1[] = + { + 0, + }; + + static const int g_shapeList1Collapse[] = + { + 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, + }; + static const int g_shapeList2[] = + { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, + 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, + 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, + 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, + 122, 123, 124, 125, 126, 127, 128, + }; + static const int g_shapeList2Collapse[] = + { + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, + 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, + 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, + 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, + }; + + static const int g_shapeList12[] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, + 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, + }; + + static const int g_shapeList12Collapse[] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, + 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, + }; + + static const int g_shapeList3[] = + { + 1, 2, 4, 6, 8, 12, 14, 18, 19, 20, 29, + 33, 51, 54, 59, 63, 66, 78, 91, 96, 106, 109, + 110, 111, 123, 128, 129, 130, 131, 132, 133, 134, 135, + 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, + 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, + 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, + 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, + 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, + 235, 236, 237, 238, 239, 240, 241, 242, + }; + + static const int g_shapeList3Collapse[] = + { + -1, 0, 1, -1, 2, -1, 3, -1, 4, -1, -1, + -1, 5, -1, 6, -1, -1, -1, 7, 8, 9, -1, + -1, -1, -1, -1, -1, -1, -1, 10, -1, -1, -1, + 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 12, -1, -1, 13, + -1, -1, -1, -1, 14, -1, -1, -1, 15, -1, -1, + 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 17, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 18, -1, -1, -1, -1, 19, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 20, -1, -1, 21, + 22, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 24, -1, -1, -1, -1, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, + 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, + 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, + 139, + }; + + static const int g_shapeList3Short[] = + { + 1, 2, 4, 6, 18, 20, 33, 51, 59, 66, 96, + 106, 110, 123, 131, 132, 136, 142, 143, 146, 148, 160, + 171, 175, 177, 178, 186, 187, 195, 205, 211, 212, 232, + 233, 237, 240, + }; + + static const int g_shapeList3ShortCollapse[] = + { + -1, 0, 1, -1, 2, -1, 3, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 4, -1, 5, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 7, -1, -1, -1, + -1, -1, -1, -1, 8, -1, -1, -1, -1, -1, -1, + 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 10, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 11, -1, -1, -1, + 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 13, -1, -1, -1, -1, -1, -1, -1, 14, + 15, -1, -1, -1, 16, -1, -1, -1, -1, -1, 17, + 18, -1, -1, 19, -1, 20, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 21, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, -1, -1, -1, 23, + -1, 24, 25, -1, -1, -1, -1, -1, -1, -1, 26, + 27, -1, -1, -1, -1, -1, -1, -1, 28, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 29, -1, -1, -1, + -1, -1, 30, 31, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 32, 33, -1, -1, -1, 34, -1, -1, 35, -1, + -1, + }; + + static const int g_shapeListAll[] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, + 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, + 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, + 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, + 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, + 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, + 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, + 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, + 242, + }; + + static const int g_numShapes1 = sizeof(g_shapeList1) / sizeof(g_shapeList1[0]); + static const int g_numShapes2 = sizeof(g_shapeList2) / sizeof(g_shapeList2[0]); + static const int g_numShapes12 = sizeof(g_shapeList12) / sizeof(g_shapeList12[0]); + static const int g_numShapes3 = sizeof(g_shapeList3) / sizeof(g_shapeList3[0]); + static const int g_numShapes3Short = sizeof(g_shapeList3Short) / sizeof(g_shapeList3Short[0]); + static const int g_numShapesAll = sizeof(g_shapeListAll) / sizeof(g_shapeListAll[0]); + static const int g_numFragments = sizeof(g_fragments) / sizeof(g_fragments[0]); + + static const int g_maxFragmentsPerMode = (g_numShapes2 > g_numShapes3) ? g_numShapes2 : g_numShapes3; + } + + namespace BC6HData + { + enum EField + { + NA, // N/A + M, // Mode + D, // Shape + RW, + RX, + RY, + RZ, + GW, + GX, + GY, + GZ, + BW, + BX, + BY, + BZ, + }; + + struct ModeDescriptor + { + EField m_eField; + uint8_t m_uBit; + }; + + const ModeDescriptor g_modeDescriptors[14][82] = + { + { // Mode 1 (0x00) - 10 5 5 5 + { M, 0 },{ M, 1 },{ GY, 4 },{ BY, 4 },{ BZ, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ RW, 8 },{ RW, 9 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GW, 8 },{ GW, 9 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BW, 8 },{ BW, 9 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { GZ, 4 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { BZ, 0 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BZ, 1 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ RY, 4 }, + { BZ, 2 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ RZ, 4 },{ BZ, 3 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 2 (0x01) - 7 6 6 6 + { M, 0 },{ M, 1 },{ GY, 5 },{ GZ, 4 },{ GZ, 5 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ BZ, 0 },{ BZ, 1 },{ BY, 4 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ BY, 5 },{ BZ, 2 },{ GY, 4 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BZ, 3 },{ BZ, 5 },{ BZ, 4 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { RX, 5 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { GX, 5 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BX, 5 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ RY, 4 }, + { RY, 5 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ RZ, 4 },{ RZ, 5 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 3 (0x02) - 11 5 4 4 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ RW, 8 },{ RW, 9 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GW, 8 },{ GW, 9 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BW, 8 },{ BW, 9 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { RW,10 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GW,10 }, + { BZ, 0 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BW,10 }, + { BZ, 1 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ RY, 4 }, + { BZ, 2 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ RZ, 4 },{ BZ, 3 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 4 (0x06) - 11 4 5 4 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ RW, 8 },{ RW, 9 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GW, 8 },{ GW, 9 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BW, 8 },{ BW, 9 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RW,10 }, + { GZ, 4 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { GW,10 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BW,10 }, + { BZ, 1 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ BZ, 0 }, + { BZ, 2 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ GY, 4 },{ BZ, 3 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 5 (0x0a) - 11 4 4 5 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ RW, 8 },{ RW, 9 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GW, 8 },{ GW, 9 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BW, 8 },{ BW, 9 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RW,10 }, + { BY, 4 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GW,10 }, + { BZ, 0 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BW,10 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ BZ, 1 }, + { BZ, 2 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ BZ, 4 },{ BZ, 3 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 6 (0x0e) - 9 5 5 5 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ RW, 8 },{ BY, 4 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GW, 8 },{ GY, 4 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BW, 8 },{ BZ, 4 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { GZ, 4 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { BZ, 0 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BZ, 1 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ RY, 4 }, + { BZ, 2 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ RZ, 4 },{ BZ, 3 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 7 (0x12) - 8 6 5 5 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ GZ, 4 },{ BY, 4 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ BZ, 2 },{ GY, 4 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BZ, 3 },{ BZ, 4 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { RX, 5 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { BZ, 0 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BZ, 1 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ RY, 4 }, + { RY, 5 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ RZ, 4 },{ RZ, 5 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 8 (0x16) - 8 5 6 5 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ BZ, 0 },{ BY, 4 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GY, 5 },{ GY, 4 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ GZ, 5 },{ BZ, 4 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { GZ, 4 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { GX, 5 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BZ, 1 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ RY, 4 }, + { BZ, 2 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ RZ, 4 },{ BZ, 3 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 9 (0x1a) - 8 5 5 6 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ BZ, 1 },{ BY, 4 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ BY, 5 },{ GY, 4 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BZ, 5 },{ BZ, 4 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { GZ, 4 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { BZ, 0 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BX, 5 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ RY, 4 }, + { BZ, 2 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ RZ, 4 },{ BZ, 3 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 10 (0x1e) - 6 6 6 6 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ GZ, 4 },{ BZ, 0 },{ BZ, 1 },{ BY, 4 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GY, 5 },{ BY, 5 },{ BZ, 2 },{ GY, 4 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ GZ, 5 },{ BZ, 3 },{ BZ, 5 },{ BZ, 4 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { RX, 5 },{ GY, 0 },{ GY, 1 },{ GY, 2 },{ GY, 3 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { GX, 5 },{ GZ, 0 },{ GZ, 1 },{ GZ, 2 },{ GZ, 3 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BX, 5 },{ BY, 0 },{ BY, 1 },{ BY, 2 },{ BY, 3 },{ RY, 0 },{ RY, 1 },{ RY, 2 },{ RY, 3 },{ RY, 4 }, + { RY, 5 },{ RZ, 0 },{ RZ, 1 },{ RZ, 2 },{ RZ, 3 },{ RZ, 4 },{ RZ, 5 },{ D, 0 },{ D, 1 },{ D, 2 }, + { D, 3 },{ D, 4 }, + }, + + { // Mode 11 (0x03) - 10 10 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ RW, 8 },{ RW, 9 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GW, 8 },{ GW, 9 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BW, 8 },{ BW, 9 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { RX, 5 },{ RX, 6 },{ RX, 7 },{ RX, 8 },{ RX, 9 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { GX, 5 },{ GX, 6 },{ GX, 7 },{ GX, 8 },{ GX, 9 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BX, 5 },{ BX, 6 },{ BX, 7 },{ BX, 8 },{ BX, 9 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 }, + { NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 }, + { NA, 0 },{ NA, 0 }, + }, + + { // Mode 12 (0x07) - 11 9 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ RW, 8 },{ RW, 9 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GW, 8 },{ GW, 9 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BW, 8 },{ BW, 9 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { RX, 5 },{ RX, 6 },{ RX, 7 },{ RX, 8 },{ RW,10 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { GX, 5 },{ GX, 6 },{ GX, 7 },{ GX, 8 },{ GW,10 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BX, 5 },{ BX, 6 },{ BX, 7 },{ BX, 8 },{ BW,10 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 }, + { NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 }, + { NA, 0 },{ NA, 0 }, + }, + + { // Mode 13 (0x0b) - 12 8 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ RW, 8 },{ RW, 9 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GW, 8 },{ GW, 9 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BW, 8 },{ BW, 9 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RX, 4 }, + { RX, 5 },{ RX, 6 },{ RX, 7 },{ RW,11 },{ RW,10 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GX, 4 }, + { GX, 5 },{ GX, 6 },{ GX, 7 },{ GW,11 },{ GW,10 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BX, 4 }, + { BX, 5 },{ BX, 6 },{ BX, 7 },{ BW,11 },{ BW,10 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 }, + { NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 }, + { NA, 0 },{ NA, 0 }, + }, + + { // Mode 14 (0x0f) - 16 4 + { M, 0 },{ M, 1 },{ M, 2 },{ M, 3 },{ M, 4 },{ RW, 0 },{ RW, 1 },{ RW, 2 },{ RW, 3 },{ RW, 4 }, + { RW, 5 },{ RW, 6 },{ RW, 7 },{ RW, 8 },{ RW, 9 },{ GW, 0 },{ GW, 1 },{ GW, 2 },{ GW, 3 },{ GW, 4 }, + { GW, 5 },{ GW, 6 },{ GW, 7 },{ GW, 8 },{ GW, 9 },{ BW, 0 },{ BW, 1 },{ BW, 2 },{ BW, 3 },{ BW, 4 }, + { BW, 5 },{ BW, 6 },{ BW, 7 },{ BW, 8 },{ BW, 9 },{ RX, 0 },{ RX, 1 },{ RX, 2 },{ RX, 3 },{ RW,15 }, + { RW,14 },{ RW,13 },{ RW,12 },{ RW,11 },{ RW,10 },{ GX, 0 },{ GX, 1 },{ GX, 2 },{ GX, 3 },{ GW,15 }, + { GW,14 },{ GW,13 },{ GW,12 },{ GW,11 },{ GW,10 },{ BX, 0 },{ BX, 1 },{ BX, 2 },{ BX, 3 },{ BW,15 }, + { BW,14 },{ BW,13 },{ BW,12 },{ BW,11 },{ BW,10 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 }, + { NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 },{ NA, 0 }, + { NA, 0 },{ NA, 0 }, + }, + }; + } + + struct PackingVector + { + uint32_t m_vector[4]; + int m_offset; + + void Init() + { + for (int i = 0; i < 4; i++) + m_vector[i] = 0; + + m_offset = 0; + } + + inline void Pack(ParallelMath::ScalarUInt16 value, int bits) + { + int vOffset = m_offset >> 5; + int bitOffset = m_offset & 0x1f; + + m_vector[vOffset] |= (static_cast<uint32_t>(value) << bitOffset) & static_cast<uint32_t>(0xffffffff); + + int overflowBits = bitOffset + bits - 32; + if (overflowBits > 0) + m_vector[vOffset + 1] |= (static_cast<uint32_t>(value) >> (bits - overflowBits)); + + m_offset += bits; + } + + inline void Flush(uint8_t* output) + { + assert(m_offset == 128); + + for (int v = 0; v < 4; v++) + { + uint32_t chunk = m_vector[v]; + for (int b = 0; b < 4; b++) + output[v * 4 + b] = static_cast<uint8_t>((chunk >> (b * 8)) & 0xff); + } + } + }; + + + struct UnpackingVector + { + uint32_t m_vector[4]; + + void Init(const uint8_t *bytes) + { + for (int i = 0; i < 4; i++) + m_vector[i] = 0; + + for (int b = 0; b < 16; b++) + m_vector[b / 4] |= (bytes[b] << ((b % 4) * 8)); + } + + inline ParallelMath::ScalarUInt16 Unpack(int bits) + { + uint32_t bitMask = (1 << bits) - 1; + + ParallelMath::ScalarUInt16 result = static_cast<ParallelMath::ScalarUInt16>(m_vector[0] & bitMask); + + for (int i = 0; i < 4; i++) + { + m_vector[i] >>= bits; + if (i != 3) + m_vector[i] |= (m_vector[i + 1] & bitMask) << (32 - bits); + } + + return result; + } + }; + + void ComputeTweakFactors2(int tweak, int range, float* outFactors) + { + int totalUnits = range - 1; + int minOutsideUnits = ((tweak >> 1) & 1); + int maxOutsideUnits = (tweak & 1); + int insideUnits = totalUnits - minOutsideUnits - maxOutsideUnits; + + outFactors[0] = -static_cast<float>(minOutsideUnits) / static_cast<float>(insideUnits); + outFactors[1] = static_cast<float>(maxOutsideUnits) / static_cast<float>(insideUnits) + 1.0f; + } + + ParallelMath::Float ScaleHDRValue(ParallelMath::Float v, bool isSigned) + { + if (isSigned) + { + ParallelMath::Float offset = ParallelMath::Select(ParallelMath::Less(v, ParallelMath::MakeFloatZero()), ParallelMath::MakeFloat(-30.0f), ParallelMath::MakeFloat(30.0f)); + return (v * 32.0f + offset) / 31.0f; + } + else + return (v * 64.0f + 30.0f) / 31.0f; + } + + ParallelMath::SInt16 UnscaleHDRValueSigned(const ParallelMath::SInt16 &v) + { +#ifdef CVTT_ENABLE_ASSERTS + for (int i = 0; i < ParallelMath::ParallelSize; i++) + assert(ParallelMath::Extract(v, i) != -32768) +#endif + + ParallelMath::Int16CompFlag negative = ParallelMath::Less(v, ParallelMath::MakeSInt16(0)); + ParallelMath::UInt15 absComp = ParallelMath::LosslessCast<ParallelMath::UInt15>::Cast(ParallelMath::Select(negative, ParallelMath::SInt16(ParallelMath::MakeSInt16(0) - v), v)); + + ParallelMath::UInt31 multiplied = ParallelMath::XMultiply(absComp, ParallelMath::MakeUInt15(31)); + ParallelMath::UInt31 shifted = ParallelMath::RightShift(multiplied, 5); + ParallelMath::UInt15 absCompScaled = ParallelMath::ToUInt15(shifted); + ParallelMath::SInt16 signBits = ParallelMath::SelectOrZero(negative, ParallelMath::MakeSInt16(-32768)); + + return ParallelMath::LosslessCast<ParallelMath::SInt16>::Cast(absCompScaled) | signBits; + } + + ParallelMath::UInt15 UnscaleHDRValueUnsigned(const ParallelMath::UInt16 &v) + { + return ParallelMath::ToUInt15(ParallelMath::RightShift(ParallelMath::XMultiply(v, ParallelMath::MakeUInt15(31)), 6)); + } + + void UnscaleHDREndpoints(const ParallelMath::AInt16 inEP[2][3], ParallelMath::AInt16 outEP[2][3], bool isSigned) + { + for (int epi = 0; epi < 2; epi++) + { + for (int ch = 0; ch < 3; ch++) + { + if (isSigned) + outEP[epi][ch] = ParallelMath::LosslessCast<ParallelMath::AInt16>::Cast(UnscaleHDRValueSigned(ParallelMath::LosslessCast<ParallelMath::SInt16>::Cast(inEP[epi][ch]))); + else + outEP[epi][ch] = ParallelMath::LosslessCast<ParallelMath::AInt16>::Cast(UnscaleHDRValueUnsigned(ParallelMath::LosslessCast<ParallelMath::UInt16>::Cast(inEP[epi][ch]))); + } + } + } + + template<int TVectorSize> + class UnfinishedEndpoints + { + public: + typedef ParallelMath::Float MFloat; + typedef ParallelMath::UInt16 MUInt16; + typedef ParallelMath::UInt15 MUInt15; + typedef ParallelMath::SInt16 MSInt16; + typedef ParallelMath::SInt32 MSInt32; + + UnfinishedEndpoints() + { + } + + UnfinishedEndpoints(const MFloat base[TVectorSize], const MFloat offset[TVectorSize]) + { + for (int ch = 0; ch < TVectorSize; ch++) + m_base[ch] = base[ch]; + for (int ch = 0; ch < TVectorSize; ch++) + m_offset[ch] = offset[ch]; + } + + UnfinishedEndpoints(const UnfinishedEndpoints& other) + { + for (int ch = 0; ch < TVectorSize; ch++) + m_base[ch] = other.m_base[ch]; + for (int ch = 0; ch < TVectorSize; ch++) + m_offset[ch] = other.m_offset[ch]; + } + + void FinishHDRUnsigned(int tweak, int range, MSInt16* outEP0, MSInt16* outEP1, ParallelMath::RoundTowardNearestForScope* roundingMode) + { + float tweakFactors[2]; + ComputeTweakFactors2(tweak, range, tweakFactors); + + for (int ch = 0; ch < TVectorSize; ch++) + { + MUInt15 channelEPs[2]; + for (int epi = 0; epi < 2; epi++) + { + MFloat f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[epi], 0.0f, 31743.0f); + channelEPs[epi] = ParallelMath::RoundAndConvertToU15(f, roundingMode); + } + + outEP0[ch] = ParallelMath::LosslessCast<MSInt16>::Cast(channelEPs[0]); + outEP1[ch] = ParallelMath::LosslessCast<MSInt16>::Cast(channelEPs[1]); + } + } + + void FinishHDRSigned(int tweak, int range, MSInt16* outEP0, MSInt16* outEP1, ParallelMath::RoundTowardNearestForScope* roundingMode) + { + float tweakFactors[2]; + ComputeTweakFactors2(tweak, range, tweakFactors); + + for (int ch = 0; ch < TVectorSize; ch++) + { + MSInt16 channelEPs[2]; + for (int epi = 0; epi < 2; epi++) + { + MFloat f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[epi], -31743.0f, 31743.0f); + channelEPs[epi] = ParallelMath::RoundAndConvertToS16(f, roundingMode); + } + + outEP0[ch] = channelEPs[0]; + outEP1[ch] = channelEPs[1]; + } + } + + void FinishLDR(int tweak, int range, MUInt15* outEP0, MUInt15* outEP1) + { + ParallelMath::RoundTowardNearestForScope roundingMode; + + float tweakFactors[2]; + ComputeTweakFactors2(tweak, range, tweakFactors); + + for (int ch = 0; ch < TVectorSize; ch++) + { + MFloat ep0f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[0], 0.0f, 255.0f); + MFloat ep1f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[1], 0.0f, 255.0f); + outEP0[ch] = ParallelMath::RoundAndConvertToU15(ep0f, &roundingMode); + outEP1[ch] = ParallelMath::RoundAndConvertToU15(ep1f, &roundingMode); + } + } + + template<int TNewVectorSize> + UnfinishedEndpoints<TNewVectorSize> ExpandTo(float filler) + { + MFloat newBase[TNewVectorSize]; + MFloat newOffset[TNewVectorSize]; + + for (int ch = 0; ch < TNewVectorSize && ch < TVectorSize; ch++) + { + newBase[ch] = m_base[ch]; + newOffset[ch] = m_offset[ch]; + } + + MFloat fillerV = ParallelMath::MakeFloat(filler); + + for (int ch = TVectorSize; ch < TNewVectorSize; ch++) + { + newBase[ch] = fillerV; + newOffset[ch] = ParallelMath::MakeFloatZero(); + } + + return UnfinishedEndpoints<TNewVectorSize>(newBase, newOffset); + } + + private: + MFloat m_base[TVectorSize]; + MFloat m_offset[TVectorSize]; + }; + + template<int TMatrixSize> + class PackedCovarianceMatrix + { + public: + // 0: xx, + // 1: xy, yy + // 3: xz, yz, zz + // 6: xw, yw, zw, ww + // ... etc. + static const int PyramidSize = (TMatrixSize * (TMatrixSize + 1)) / 2; + + typedef ParallelMath::Float MFloat; + + PackedCovarianceMatrix() + { + for (int i = 0; i < PyramidSize; i++) + m_values[i] = ParallelMath::MakeFloatZero(); + } + + void Add(const ParallelMath::Float vec[TMatrixSize], ParallelMath::Float weight) + { + int index = 0; + for (int row = 0; row < TMatrixSize; row++) + { + for (int col = 0; col <= row; col++) + { + m_values[index] = m_values[index] + vec[row] * vec[col] * weight; + index++; + } + } + } + + void Product(MFloat outVec[TMatrixSize], const MFloat inVec[TMatrixSize]) + { + for (int row = 0; row < TMatrixSize; row++) + { + MFloat sum = ParallelMath::MakeFloatZero(); + + int index = (row * (row + 1)) >> 1; + for (int col = 0; col < TMatrixSize; col++) + { + sum = sum + inVec[col] * m_values[index]; + if (col >= row) + index += col + 1; + else + index++; + } + + outVec[row] = sum; + } + } + + private: + ParallelMath::Float m_values[PyramidSize]; + }; + + static const int NumEndpointSelectorPasses = 3; + + template<int TVectorSize, int TIterationCount> + class EndpointSelector + { + public: + typedef ParallelMath::Float MFloat; + + EndpointSelector() + { + for (int ch = 0; ch < TVectorSize; ch++) + { + m_centroid[ch] = ParallelMath::MakeFloatZero(); + m_direction[ch] = ParallelMath::MakeFloatZero(); + } + m_weightTotal = ParallelMath::MakeFloatZero(); + m_minDist = ParallelMath::MakeFloat(FLT_MAX); + m_maxDist = ParallelMath::MakeFloat(-FLT_MAX); + } + + void ContributePass(const MFloat value[TVectorSize], int pass, MFloat weight) + { + if (pass == 0) + ContributeCentroid(value, weight); + else if (pass == 1) + ContributeDirection(value, weight); + else if (pass == 2) + ContributeMinMax(value); + } + + void FinishPass(int pass) + { + if (pass == 0) + FinishCentroid(); + else if (pass == 1) + FinishDirection(); + } + + UnfinishedEndpoints<TVectorSize> GetEndpoints(const float channelWeights[TVectorSize]) const + { + MFloat unweightedBase[TVectorSize]; + MFloat unweightedOffset[TVectorSize]; + + for (int ch = 0; ch < TVectorSize; ch++) + { + MFloat min = m_centroid[ch] + m_direction[ch] * m_minDist; + MFloat max = m_centroid[ch] + m_direction[ch] * m_maxDist; + + float safeWeight = channelWeights[ch]; + if (safeWeight == 0.f) + safeWeight = 1.0f; + + unweightedBase[ch] = min / channelWeights[ch]; + unweightedOffset[ch] = (max - min) / channelWeights[ch]; + } + + return UnfinishedEndpoints<TVectorSize>(unweightedBase, unweightedOffset); + } + + private: + void ContributeCentroid(const MFloat value[TVectorSize], MFloat weight) + { + for (int ch = 0; ch < TVectorSize; ch++) + m_centroid[ch] = m_centroid[ch] + value[ch] * weight; + m_weightTotal = m_weightTotal + weight; + } + + void FinishCentroid() + { + MFloat denom = m_weightTotal; + ParallelMath::MakeSafeDenominator(denom); + + for (int ch = 0; ch < TVectorSize; ch++) + m_centroid[ch] = m_centroid[ch] / denom; + } + + void ContributeDirection(const MFloat value[TVectorSize], MFloat weight) + { + MFloat diff[TVectorSize]; + for (int ch = 0; ch < TVectorSize; ch++) + diff[ch] = value[ch] - m_centroid[ch]; + + m_covarianceMatrix.Add(diff, weight); + } + + void FinishDirection() + { + MFloat approx[TVectorSize]; + for (int ch = 0; ch < TVectorSize; ch++) + approx[ch] = ParallelMath::MakeFloat(1.0f); + + for (int i = 0; i < TIterationCount; i++) + { + MFloat product[TVectorSize]; + m_covarianceMatrix.Product(product, approx); + + MFloat largestComponent = product[0]; + for (int ch = 1; ch < TVectorSize; ch++) + largestComponent = ParallelMath::Max(largestComponent, product[ch]); + + // product = largestComponent*newApprox + ParallelMath::MakeSafeDenominator(largestComponent); + for (int ch = 0; ch < TVectorSize; ch++) + approx[ch] = product[ch] / largestComponent; + } + + // Normalize + MFloat approxLen = ParallelMath::MakeFloatZero(); + for (int ch = 0; ch < TVectorSize; ch++) + approxLen = approxLen + approx[ch] * approx[ch]; + + approxLen = ParallelMath::Sqrt(approxLen); + + ParallelMath::MakeSafeDenominator(approxLen); + + for (int ch = 0; ch < TVectorSize; ch++) + m_direction[ch] = approx[ch] / approxLen; + } + + void ContributeMinMax(const MFloat value[TVectorSize]) + { + MFloat dist = ParallelMath::MakeFloatZero(); + for (int ch = 0; ch < TVectorSize; ch++) + dist = dist + m_direction[ch] * (value[ch] - m_centroid[ch]); + + m_minDist = ParallelMath::Min(m_minDist, dist); + m_maxDist = ParallelMath::Max(m_maxDist, dist); + } + + ParallelMath::Float m_centroid[TVectorSize]; + ParallelMath::Float m_direction[TVectorSize]; + PackedCovarianceMatrix<TVectorSize> m_covarianceMatrix; + ParallelMath::Float m_weightTotal; + + ParallelMath::Float m_minDist; + ParallelMath::Float m_maxDist; + }; + + static const ParallelMath::UInt16 g_weightReciprocals[] = + { + ParallelMath::MakeUInt16(0), // -1 + ParallelMath::MakeUInt16(0), // 0 + ParallelMath::MakeUInt16(32768), // 1 + ParallelMath::MakeUInt16(16384), // 2 + ParallelMath::MakeUInt16(10923), // 3 + ParallelMath::MakeUInt16(8192), // 4 + ParallelMath::MakeUInt16(6554), // 5 + ParallelMath::MakeUInt16(5461), // 6 + ParallelMath::MakeUInt16(4681), // 7 + ParallelMath::MakeUInt16(4096), // 8 + ParallelMath::MakeUInt16(3641), // 9 + ParallelMath::MakeUInt16(3277), // 10 + ParallelMath::MakeUInt16(2979), // 11 + ParallelMath::MakeUInt16(2731), // 12 + ParallelMath::MakeUInt16(2521), // 13 + ParallelMath::MakeUInt16(2341), // 14 + ParallelMath::MakeUInt16(2185), // 15 + }; + + template<int TVectorSize> + class IndexSelector + { + public: + typedef ParallelMath::Float MFloat; + typedef ParallelMath::UInt16 MUInt16; + typedef ParallelMath::UInt15 MUInt15; + typedef ParallelMath::SInt16 MSInt16; + typedef ParallelMath::AInt16 MAInt16; + typedef ParallelMath::SInt32 MSInt32; + typedef ParallelMath::UInt31 MUInt31; + + template<class TInterpolationEPType, class TColorEPType> + void Init(const float channelWeights[TVectorSize], const TInterpolationEPType interpolationEndPoints[2][TVectorSize], const TColorEPType colorSpaceEndpoints[2][TVectorSize], int range) + { + // In BC6H, the interpolation endpoints are higher-precision than the endpoints in color space. + // We need to select indexes using the color-space endpoints. + + m_isUniform = true; + for (int ch = 1; ch < TVectorSize; ch++) + { + if (channelWeights[ch] != channelWeights[0]) + m_isUniform = false; + } + + // To work with channel weights, we need something where: + // pxDiff = px - ep[0] + // epDiff = ep[1] - ep[0] + // + // weightedEPDiff = epDiff * channelWeights + // normalizedWeightedAxis = weightedEPDiff / len(weightedEPDiff) + // normalizedIndex = dot(pxDiff * channelWeights, normalizedWeightedAxis) / len(weightedEPDiff) + // index = normalizedIndex * maxValue + // + // Equivalent to: + // axis = channelWeights * maxValue * epDiff * channelWeights / lenSquared(epDiff * channelWeights) + // index = dot(axis, pxDiff) + + for (int ep = 0; ep < 2; ep++) + for (int ch = 0; ch < TVectorSize; ch++) + m_endPoint[ep][ch] = ParallelMath::LosslessCast<MAInt16>::Cast(interpolationEndPoints[ep][ch]); + + m_range = range; + m_maxValue = static_cast<float>(range - 1); + + MFloat epDiffWeighted[TVectorSize]; + for (int ch = 0; ch < TVectorSize; ch++) + { + m_origin[ch] = ParallelMath::ToFloat(colorSpaceEndpoints[0][ch]); + MFloat opposingOriginCh = ParallelMath::ToFloat(colorSpaceEndpoints[1][ch]); + epDiffWeighted[ch] = (opposingOriginCh - m_origin[ch]) * channelWeights[ch]; + } + + MFloat lenSquared = epDiffWeighted[0] * epDiffWeighted[0]; + for (int ch = 1; ch < TVectorSize; ch++) + lenSquared = lenSquared + epDiffWeighted[ch] * epDiffWeighted[ch]; + + ParallelMath::MakeSafeDenominator(lenSquared); + + MFloat maxValueDividedByLengthSquared = ParallelMath::MakeFloat(m_maxValue) / lenSquared; + + for (int ch = 0; ch < TVectorSize; ch++) + m_axis[ch] = epDiffWeighted[ch] * channelWeights[ch] * maxValueDividedByLengthSquared; + } + + template<bool TSigned> + void Init(const float channelWeights[TVectorSize], const MUInt15 endPoints[2][TVectorSize], int range) + { + MAInt16 converted[2][TVectorSize]; + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < TVectorSize; ch++) + converted[epi][ch] = ParallelMath::LosslessCast<MAInt16>::Cast(endPoints[epi][ch]); + + Init<MUInt15, MUInt15>(channelWeights, endPoints, endPoints, range); + } + + void ReconstructLDR_BC7(const MUInt15 &index, MUInt15* pixel, int numRealChannels) + { + MUInt15 weight = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::RightShift(ParallelMath::CompactMultiply(g_weightReciprocals[m_range], index) + 256, 9)); + + for (int ch = 0; ch < numRealChannels; ch++) + { + MUInt15 ep0f = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::CompactMultiply((ParallelMath::MakeUInt15(64) - weight), ParallelMath::LosslessCast<MUInt15>::Cast(m_endPoint[0][ch]))); + MUInt15 ep1f = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::CompactMultiply(weight, ParallelMath::LosslessCast<MUInt15>::Cast(m_endPoint[1][ch]))); + pixel[ch] = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::RightShift(ep0f + ep1f + ParallelMath::MakeUInt15(32), 6)); + } + } + + void ReconstructLDRPrecise(const MUInt15 &index, MUInt15* pixel, int numRealChannels) + { + MUInt15 weight = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::RightShift(ParallelMath::CompactMultiply(g_weightReciprocals[m_range], index) + 64, 7)); + + for (int ch = 0; ch < numRealChannels; ch++) + { + MUInt15 ep0f = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::CompactMultiply((ParallelMath::MakeUInt15(256) - weight), ParallelMath::LosslessCast<MUInt15>::Cast(m_endPoint[0][ch]))); + MUInt15 ep1f = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::CompactMultiply(weight, ParallelMath::LosslessCast<MUInt15>::Cast(m_endPoint[1][ch]))); + pixel[ch] = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::RightShift(ep0f + ep1f + ParallelMath::MakeUInt15(128), 8)); + } + } + + void ReconstructLDR_BC7(const MUInt15 &index, MUInt15* pixel) + { + ReconstructLDR_BC7(index, pixel, TVectorSize); + } + + void ReconstructLDRPrecise(const MUInt15 &index, MUInt15* pixel) + { + ReconstructLDRPrecise(index, pixel, TVectorSize); + } + + MUInt15 SelectIndexLDR(const MFloat* pixel, const ParallelMath::RoundTowardNearestForScope* rtn) const + { + MFloat dist = (pixel[0] - m_origin[0]) * m_axis[0]; + for (int ch = 1; ch < TVectorSize; ch++) + dist = dist + (pixel[ch] - m_origin[ch]) * m_axis[ch]; + + return ParallelMath::RoundAndConvertToU15(ParallelMath::Clamp(dist, 0.0f, m_maxValue), rtn); + } + + protected: + MAInt16 m_endPoint[2][TVectorSize]; + + private: + MFloat m_origin[TVectorSize]; + MFloat m_axis[TVectorSize]; + int m_range; + float m_maxValue; + bool m_isUniform; + }; + + + template<int TVectorSize> + class IndexSelectorHDR : public IndexSelector<TVectorSize> + { + public: + typedef ParallelMath::UInt15 MUInt15; + typedef ParallelMath::UInt16 MUInt16; + typedef ParallelMath::UInt31 MUInt31; + typedef ParallelMath::SInt16 MSInt16; + typedef ParallelMath::SInt32 MSInt32; + typedef ParallelMath::Float MFloat; + + private: + + MUInt15 InvertSingle(const MUInt15& anIndex) const + { + MUInt15 inverted = m_maxValueMinusOne - anIndex; + return ParallelMath::Select(m_isInverted, inverted, anIndex); + } + + void ReconstructHDRSignedUninverted(const MUInt15 &index, MSInt16* pixel) const + { + MUInt15 weight = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::RightShift(ParallelMath::CompactMultiply(g_weightReciprocals[m_range], index) + 256, 9)); + + for (int ch = 0; ch < TVectorSize; ch++) + { + MSInt16 ep0 = ParallelMath::LosslessCast<MSInt16>::Cast(this->m_endPoint[0][ch]); + MSInt16 ep1 = ParallelMath::LosslessCast<MSInt16>::Cast(this->m_endPoint[1][ch]); + + MSInt32 pixel32 = ParallelMath::XMultiply((ParallelMath::MakeUInt15(64) - weight), ep0) + ParallelMath::XMultiply(weight, ep1); + + pixel32 = ParallelMath::RightShift(pixel32 + ParallelMath::MakeSInt32(32), 6); + + pixel[ch] = UnscaleHDRValueSigned(ParallelMath::ToSInt16(pixel32)); + } + } + + void ReconstructHDRUnsignedUninverted(const MUInt15 &index, MSInt16* pixel) const + { + MUInt15 weight = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::RightShift(ParallelMath::CompactMultiply(g_weightReciprocals[m_range], index) + 256, 9)); + + for (int ch = 0; ch < TVectorSize; ch++) + { + MUInt16 ep0 = ParallelMath::LosslessCast<MUInt16>::Cast(this->m_endPoint[0][ch]); + MUInt16 ep1 = ParallelMath::LosslessCast<MUInt16>::Cast(this->m_endPoint[1][ch]); + + MUInt31 pixel31 = ParallelMath::XMultiply((ParallelMath::MakeUInt15(64) - weight), ep0) + ParallelMath::XMultiply(weight, ep1); + + pixel31 = ParallelMath::RightShift(pixel31 + ParallelMath::MakeUInt31(32), 6); + + pixel[ch] = ParallelMath::LosslessCast<MSInt16>::Cast(UnscaleHDRValueUnsigned(ParallelMath::ToUInt16(pixel31))); + } + } + + MFloat ErrorForInterpolatorComponent(int index, int ch, const MFloat *pixel) const + { + MFloat diff = pixel[ch] - m_reconstructedInterpolators[index][ch]; + return diff * diff; + } + + MFloat ErrorForInterpolator(int index, const MFloat *pixel) const + { + MFloat error = ErrorForInterpolatorComponent(index, 0, pixel); + for (int ch = 1; ch < TVectorSize; ch++) + error = error + ErrorForInterpolatorComponent(index, ch, pixel); + return error; + } + + public: + + void InitHDR(int range, bool isSigned, bool fastIndexing, const float *channelWeights) + { + assert(range <= 16); + + m_range = range; + + m_isInverted = ParallelMath::MakeBoolInt16(false); + m_maxValueMinusOne = ParallelMath::MakeUInt15(static_cast<uint16_t>(range - 1)); + + if (!fastIndexing) + { + for (int i = 0; i < range; i++) + { + MSInt16 recon2CL[TVectorSize]; + + if (isSigned) + ReconstructHDRSignedUninverted(ParallelMath::MakeUInt15(static_cast<uint16_t>(i)), recon2CL); + else + ReconstructHDRUnsignedUninverted(ParallelMath::MakeUInt15(static_cast<uint16_t>(i)), recon2CL); + + for (int ch = 0; ch < TVectorSize; ch++) + m_reconstructedInterpolators[i][ch] = ParallelMath::TwosCLHalfToFloat(recon2CL[ch]) * channelWeights[ch]; + } + } + } + + void ReconstructHDRSigned(const MUInt15 &index, MSInt16* pixel) const + { + ReconstructHDRSignedUninverted(InvertSingle(index), pixel); + } + + void ReconstructHDRUnsigned(const MUInt15 &index, MSInt16* pixel) const + { + ReconstructHDRUnsignedUninverted(InvertSingle(index), pixel); + } + + void ConditionalInvert(ParallelMath::Int16CompFlag invert) + { + m_isInverted = invert; + } + + MUInt15 SelectIndexHDRSlow(const MFloat* pixel, const ParallelMath::RoundTowardNearestForScope*) const + { + MUInt15 index = ParallelMath::MakeUInt15(0); + + MFloat bestError = ErrorForInterpolator(0, pixel); + for (int i = 1; i < m_range; i++) + { + MFloat error = ErrorForInterpolator(i, pixel); + ParallelMath::FloatCompFlag errorBetter = ParallelMath::Less(error, bestError); + ParallelMath::ConditionalSet(index, ParallelMath::FloatFlagToInt16(errorBetter), ParallelMath::MakeUInt15(static_cast<uint16_t>(i))); + bestError = ParallelMath::Min(bestError, error); + } + + return InvertSingle(index); + } + + MUInt15 SelectIndexHDRFast(const MFloat* pixel, const ParallelMath::RoundTowardNearestForScope* rtn) const + { + return InvertSingle(this->SelectIndexLDR(pixel, rtn)); + } + + private: + MFloat m_reconstructedInterpolators[16][TVectorSize]; + ParallelMath::Int16CompFlag m_isInverted; + MUInt15 m_maxValueMinusOne; + int m_range; + }; + + // Solve for a, b where v = a*t + b + // This allows endpoints to be mapped to where T=0 and T=1 + // Least squares from totals: + // a = (tv - t*v/w)/(tt - t*t/w) + // b = (v - a*t)/w + template<int TVectorSize> + class EndpointRefiner + { + public: + typedef ParallelMath::Float MFloat; + typedef ParallelMath::UInt16 MUInt16; + typedef ParallelMath::UInt15 MUInt15; + typedef ParallelMath::AInt16 MAInt16; + typedef ParallelMath::SInt16 MSInt16; + typedef ParallelMath::SInt32 MSInt32; + + MFloat m_tv[TVectorSize]; + MFloat m_v[TVectorSize]; + MFloat m_tt; + MFloat m_t; + MFloat m_w; + int m_wu; + + float m_rcpMaxIndex; + float m_channelWeights[TVectorSize]; + float m_rcpChannelWeights[TVectorSize]; + + void Init(int indexRange, const float channelWeights[TVectorSize]) + { + for (int ch = 0; ch < TVectorSize; ch++) + { + m_tv[ch] = ParallelMath::MakeFloatZero(); + m_v[ch] = ParallelMath::MakeFloatZero(); + } + m_tt = ParallelMath::MakeFloatZero(); + m_t = ParallelMath::MakeFloatZero(); + m_w = ParallelMath::MakeFloatZero(); + + m_rcpMaxIndex = 1.0f / static_cast<float>(indexRange - 1); + + for (int ch = 0; ch < TVectorSize; ch++) + { + m_channelWeights[ch] = channelWeights[ch]; + m_rcpChannelWeights[ch] = 1.0f; + if (m_channelWeights[ch] != 0.0f) + m_rcpChannelWeights[ch] = 1.0f / channelWeights[ch]; + } + + m_wu = 0; + } + + void ContributePW(const MFloat *pwFloatPixel, const MUInt15 &index, MFloat weight) + { + MFloat t = ParallelMath::ToFloat(index) * m_rcpMaxIndex; + + for (int ch = 0; ch < TVectorSize; ch++) + { + MFloat v = pwFloatPixel[ch] * weight; + + m_tv[ch] = m_tv[ch] + t * v; + m_v[ch] = m_v[ch] + v; + } + m_tt = m_tt + weight * t * t; + m_t = m_t + weight * t; + m_w = m_w + weight; + } + + void ContributeUnweightedPW(const MFloat *pwFloatPixel, const MUInt15 &index, int numRealChannels) + { + MFloat t = ParallelMath::ToFloat(index) * m_rcpMaxIndex; + + for (int ch = 0; ch < numRealChannels; ch++) + { + MFloat v = pwFloatPixel[ch]; + + m_tv[ch] = m_tv[ch] + t * v; + m_v[ch] = m_v[ch] + v; + } + m_tt = m_tt + t * t; + m_t = m_t + t; + m_wu++; + } + + void ContributeUnweightedPW(const MFloat *floatPixel, const MUInt15 &index) + { + ContributeUnweightedPW(floatPixel, index, TVectorSize); + } + + void GetRefinedEndpoints(MFloat endPoint[2][TVectorSize]) + { + // a = (tv - t*v/w)/(tt - t*t/w) + // b = (v - a*t)/w + MFloat w = m_w + ParallelMath::MakeFloat(static_cast<float>(m_wu)); + + ParallelMath::MakeSafeDenominator(w); + MFloat wRcp = ParallelMath::Reciprocal(w); + + MFloat adenom = (m_tt * w - m_t * m_t) * wRcp; + + ParallelMath::FloatCompFlag adenomZero = ParallelMath::Equal(adenom, ParallelMath::MakeFloatZero()); + ParallelMath::ConditionalSet(adenom, adenomZero, ParallelMath::MakeFloat(1.0f)); + + for (int ch = 0; ch < TVectorSize; ch++) + { + /* + if (adenom == 0.0) + p1 = p2 = er.v / er.w; + else + { + float4 a = (er.tv - er.t*er.v / er.w) / adenom; + float4 b = (er.v - a * er.t) / er.w; + p1 = b; + p2 = a + b; + } + */ + + MFloat a = (m_tv[ch] - m_t * m_v[ch] * wRcp) / adenom; + MFloat b = (m_v[ch] - a * m_t) * wRcp; + + MFloat p1 = b; + MFloat p2 = a + b; + + ParallelMath::ConditionalSet(p1, adenomZero, (m_v[ch] * wRcp)); + ParallelMath::ConditionalSet(p2, adenomZero, p1); + + // Unweight + float inverseWeight = m_rcpChannelWeights[ch]; + + endPoint[0][ch] = p1 * inverseWeight; + endPoint[1][ch] = p2 * inverseWeight; + } + } + + void GetRefinedEndpointsLDR(MUInt15 endPoint[2][TVectorSize], int numRealChannels, const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + MFloat floatEndPoint[2][TVectorSize]; + GetRefinedEndpoints(floatEndPoint); + + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < TVectorSize; ch++) + endPoint[epi][ch] = ParallelMath::RoundAndConvertToU15(ParallelMath::Clamp(floatEndPoint[epi][ch], 0.0f, 255.0f), roundingMode); + } + + void GetRefinedEndpointsLDR(MUInt15 endPoint[2][TVectorSize], const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + GetRefinedEndpointsLDR(endPoint, TVectorSize, roundingMode); + } + + void GetRefinedEndpointsHDR(MSInt16 endPoint[2][TVectorSize], bool isSigned, const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + MFloat floatEndPoint[2][TVectorSize]; + GetRefinedEndpoints(floatEndPoint); + + for (int epi = 0; epi < 2; epi++) + { + for (int ch = 0; ch < TVectorSize; ch++) + { + MFloat f = floatEndPoint[epi][ch]; + if (isSigned) + endPoint[epi][ch] = ParallelMath::LosslessCast<MSInt16>::Cast(ParallelMath::RoundAndConvertToS16(ParallelMath::Clamp(f, -31743.0f, 31743.0f), roundingMode)); + else + endPoint[epi][ch] = ParallelMath::LosslessCast<MSInt16>::Cast(ParallelMath::RoundAndConvertToU15(ParallelMath::Clamp(f, 0.0f, 31743.0f), roundingMode)); + } + } + } + }; + + template<int TVectorSize> + class AggregatedError + { + public: + typedef ParallelMath::UInt16 MUInt16; + typedef ParallelMath::UInt31 MUInt31; + typedef ParallelMath::Float MFloat; + + AggregatedError() + { + for (int ch = 0; ch < TVectorSize; ch++) + m_errorUnweighted[ch] = ParallelMath::MakeUInt31(0); + } + + void Add(const MUInt16 &channelErrorUnweighted, int ch) + { + m_errorUnweighted[ch] = m_errorUnweighted[ch] + ParallelMath::ToUInt31(channelErrorUnweighted); + } + + MFloat Finalize(uint32_t flags, const float channelWeightsSq[TVectorSize]) const + { + if (flags & cvtt::Flags::Uniform) + { + MUInt31 total = m_errorUnweighted[0]; + for (int ch = 1; ch < TVectorSize; ch++) + total = total + m_errorUnweighted[ch]; + return ParallelMath::ToFloat(total); + } + else + { + MFloat total = ParallelMath::ToFloat(m_errorUnweighted[0]) * channelWeightsSq[0]; + for (int ch = 1; ch < TVectorSize; ch++) + total = total + ParallelMath::ToFloat(m_errorUnweighted[ch]) * channelWeightsSq[ch]; + return total; + } + } + + private: + MUInt31 m_errorUnweighted[TVectorSize]; + }; + + class BCCommon + { + public: + typedef ParallelMath::Float MFloat; + typedef ParallelMath::UInt16 MUInt16; + typedef ParallelMath::UInt15 MUInt15; + typedef ParallelMath::AInt16 MAInt16; + typedef ParallelMath::SInt16 MSInt16; + typedef ParallelMath::SInt32 MSInt32; + + static int TweakRoundsForRange(int range) + { + if (range == 3) + return 3; + return 4; + } + + template<int TVectorSize> + static void ComputeErrorLDR(uint32_t flags, const MUInt15 reconstructed[TVectorSize], const MUInt15 original[TVectorSize], int numRealChannels, AggregatedError<TVectorSize> &aggError) + { + for (int ch = 0; ch < numRealChannels; ch++) + aggError.Add(ParallelMath::SqDiffUInt8(reconstructed[ch], original[ch]), ch); + } + + template<int TVectorSize> + static void ComputeErrorLDR(uint32_t flags, const MUInt15 reconstructed[TVectorSize], const MUInt15 original[TVectorSize], AggregatedError<TVectorSize> &aggError) + { + ComputeErrorLDR<TVectorSize>(flags, reconstructed, original, TVectorSize, aggError); + } + + template<int TVectorSize> + static MFloat ComputeErrorLDRSimple(uint32_t flags, const MUInt15 reconstructed[TVectorSize], const MUInt15 original[TVectorSize], int numRealChannels, const float *channelWeightsSq) + { + AggregatedError<TVectorSize> aggError; + ComputeErrorLDR<TVectorSize>(flags, reconstructed, original, numRealChannels, aggError); + return aggError.Finalize(flags, channelWeightsSq); + } + + template<int TVectorSize> + static MFloat ComputeErrorHDRFast(uint32_t flags, const MSInt16 reconstructed[TVectorSize], const MSInt16 original[TVectorSize], const float channelWeightsSq[TVectorSize]) + { + MFloat error = ParallelMath::MakeFloatZero(); + if (flags & Flags::Uniform) + { + for (int ch = 0; ch < TVectorSize; ch++) + error = error + ParallelMath::SqDiffSInt16(reconstructed[ch], original[ch]); + } + else + { + for (int ch = 0; ch < TVectorSize; ch++) + error = error + ParallelMath::SqDiffSInt16(reconstructed[ch], original[ch]) * ParallelMath::MakeFloat(channelWeightsSq[ch]); + } + + return error; + } + + template<int TVectorSize> + static MFloat ComputeErrorHDRSlow(uint32_t flags, const MSInt16 reconstructed[TVectorSize], const MSInt16 original[TVectorSize], const float channelWeightsSq[TVectorSize]) + { + MFloat error = ParallelMath::MakeFloatZero(); + if (flags & Flags::Uniform) + { + for (int ch = 0; ch < TVectorSize; ch++) + error = error + ParallelMath::SqDiff2CL(reconstructed[ch], original[ch]); + } + else + { + for (int ch = 0; ch < TVectorSize; ch++) + error = error + ParallelMath::SqDiff2CL(reconstructed[ch], original[ch]) * ParallelMath::MakeFloat(channelWeightsSq[ch]); + } + + return error; + } + + template<int TChannelCount> + static void PreWeightPixelsLDR(MFloat preWeightedPixels[16][TChannelCount], const MUInt15 pixels[16][TChannelCount], const float channelWeights[TChannelCount]) + { + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < TChannelCount; ch++) + preWeightedPixels[px][ch] = ParallelMath::ToFloat(pixels[px][ch]) * channelWeights[ch]; + } + } + + template<int TChannelCount> + static void PreWeightPixelsHDR(MFloat preWeightedPixels[16][TChannelCount], const MSInt16 pixels[16][TChannelCount], const float channelWeights[TChannelCount]) + { + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < TChannelCount; ch++) + preWeightedPixels[px][ch] = ParallelMath::ToFloat(pixels[px][ch]) * channelWeights[ch]; + } + } + }; + + class BC7Computer + { + public: + static const int MaxTweakRounds = 4; + + typedef ParallelMath::SInt16 MSInt16; + typedef ParallelMath::UInt15 MUInt15; + typedef ParallelMath::UInt16 MUInt16; + typedef ParallelMath::SInt32 MSInt32; + typedef ParallelMath::Float MFloat; + + struct WorkInfo + { + MUInt15 m_mode; + MFloat m_error; + MUInt15 m_ep[3][2][4]; + MUInt15 m_indexes[16]; + MUInt15 m_indexes2[16]; + + union + { + MUInt15 m_partition; + struct IndexSelectorAndRotation + { + MUInt15 m_indexSelector; + MUInt15 m_rotation; + } m_isr; + } m_u; + }; + + static void TweakAlpha(const MUInt15 original[2], int tweak, int range, MUInt15 result[2]) + { + ParallelMath::RoundTowardNearestForScope roundingMode; + + float tf[2]; + ComputeTweakFactors2(tweak, range, tf); + + MFloat base = ParallelMath::ToFloat(original[0]); + MFloat offs = ParallelMath::ToFloat(original[1]) - base; + + result[0] = ParallelMath::RoundAndConvertToU15(ParallelMath::Clamp(base + offs * tf[0], 0.0f, 255.0f), &roundingMode); + result[1] = ParallelMath::RoundAndConvertToU15(ParallelMath::Clamp(base + offs * tf[1], 0.0f, 255.0f), &roundingMode); + } + + static void Quantize(MUInt15* color, int bits, int channels, const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + float maxColor = static_cast<float>((1 << bits) - 1); + + for (int i = 0; i < channels; i++) + color[i] = ParallelMath::RoundAndConvertToU15(ParallelMath::Clamp(ParallelMath::ToFloat(color[i]) * ParallelMath::MakeFloat(1.0f / 255.0f) * maxColor, 0.f, 255.f), roundingMode); + } + + static void QuantizeP(MUInt15* color, int bits, uint16_t p, int channels, const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + uint16_t pShift = static_cast<uint16_t>(1 << (7 - bits)); + MUInt15 pShiftV = ParallelMath::MakeUInt15(pShift); + + float maxColorF = static_cast<float>(255 - (1 << (7 - bits))); + + float maxQuantized = static_cast<float>((1 << bits) - 1); + + for (int ch = 0; ch < channels; ch++) + { + MUInt15 clr = color[ch]; + if (p) + clr = ParallelMath::Max(clr, pShiftV) - pShiftV; + + MFloat rerangedColor = ParallelMath::ToFloat(clr) * maxQuantized / maxColorF; + + clr = ParallelMath::RoundAndConvertToU15(ParallelMath::Clamp(rerangedColor, 0.0f, maxQuantized), roundingMode) << 1; + if (p) + clr = clr | ParallelMath::MakeUInt15(1); + + color[ch] = clr; + } + } + + static void Unquantize(MUInt15* color, int bits, int channels) + { + for (int ch = 0; ch < channels; ch++) + { + MUInt15 clr = color[ch]; + clr = clr << (8 - bits); + color[ch] = clr | ParallelMath::RightShift(clr, bits); + } + } + + static void CompressEndpoints0(MUInt15 ep[2][4], uint16_t p[2], const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + for (int j = 0; j < 2; j++) + { + QuantizeP(ep[j], 4, p[j], 3, roundingMode); + Unquantize(ep[j], 5, 3); + ep[j][3] = ParallelMath::MakeUInt15(255); + } + } + + static void CompressEndpoints1(MUInt15 ep[2][4], uint16_t p, const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + for (int j = 0; j < 2; j++) + { + QuantizeP(ep[j], 6, p, 3, roundingMode); + Unquantize(ep[j], 7, 3); + ep[j][3] = ParallelMath::MakeUInt15(255); + } + } + + static void CompressEndpoints2(MUInt15 ep[2][4], const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + for (int j = 0; j < 2; j++) + { + Quantize(ep[j], 5, 3, roundingMode); + Unquantize(ep[j], 5, 3); + ep[j][3] = ParallelMath::MakeUInt15(255); + } + } + + static void CompressEndpoints3(MUInt15 ep[2][4], uint16_t p[2], const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + for (int j = 0; j < 2; j++) + { + QuantizeP(ep[j], 7, p[j], 3, roundingMode); + ep[j][3] = ParallelMath::MakeUInt15(255); + } + } + + static void CompressEndpoints4(MUInt15 epRGB[2][3], MUInt15 epA[2], const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + for (int j = 0; j < 2; j++) + { + Quantize(epRGB[j], 5, 3, roundingMode); + Unquantize(epRGB[j], 5, 3); + + Quantize(epA + j, 6, 1, roundingMode); + Unquantize(epA + j, 6, 1); + } + } + + static void CompressEndpoints5(MUInt15 epRGB[2][3], MUInt15 epA[2], const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + for (int j = 0; j < 2; j++) + { + Quantize(epRGB[j], 7, 3, roundingMode); + Unquantize(epRGB[j], 7, 3); + } + + // Alpha is full precision + (void)epA; + } + + static void CompressEndpoints6(MUInt15 ep[2][4], uint16_t p[2], const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + for (int j = 0; j < 2; j++) + QuantizeP(ep[j], 7, p[j], 4, roundingMode); + } + + static void CompressEndpoints7(MUInt15 ep[2][4], uint16_t p[2], const ParallelMath::RoundTowardNearestForScope *roundingMode) + { + for (int j = 0; j < 2; j++) + { + QuantizeP(ep[j], 5, p[j], 4, roundingMode); + Unquantize(ep[j], 6, 4); + } + } + + struct SinglePlaneTemporaries + { + UnfinishedEndpoints<3> unfinishedRGB[BC7Data::g_numShapesAll]; + UnfinishedEndpoints<4> unfinishedRGBA[BC7Data::g_numShapes12]; + + MUInt15 fragmentBestIndexes[BC7Data::g_numFragments]; + MUInt15 shapeBestEP[BC7Data::g_maxFragmentsPerMode][2][4]; + MFloat shapeBestError[BC7Data::g_maxFragmentsPerMode]; + }; + + static void TrySingleColorRGBAMultiTable(uint32_t flags, const MUInt15 pixels[16][4], const MFloat average[4], int numRealChannels, const uint8_t *fragmentStart, int shapeLength, const MFloat &staticAlphaError, const ParallelMath::Int16CompFlag punchThroughInvalid[4], MFloat& shapeBestError, MUInt15 shapeBestEP[2][4], MUInt15 *fragmentBestIndexes, const float *channelWeightsSq, const cvtt::Tables::BC7SC::Table*const* tables, int numTables, const ParallelMath::RoundTowardNearestForScope *rtn) + { + MFloat bestAverageError = ParallelMath::MakeFloat(FLT_MAX); + + MUInt15 intAverage[4]; + for (int ch = 0; ch < 4; ch++) + intAverage[ch] = ParallelMath::RoundAndConvertToU15(average[ch], rtn); + + MUInt15 eps[2][4]; + MUInt15 reconstructed[4]; + MUInt15 index = ParallelMath::MakeUInt15(0); + + for (int epi = 0; epi < 2; epi++) + { + for (int ch = 0; ch < 3; ch++) + eps[epi][ch] = ParallelMath::MakeUInt15(0); + eps[epi][3] = ParallelMath::MakeUInt15(255); + } + + for (int ch = 0; ch < 3; ch++) + reconstructed[ch] = ParallelMath::MakeUInt15(0); + reconstructed[3] = ParallelMath::MakeUInt15(255); + + // Depending on the target index and parity bits, there are multiple valid solid colors. + // We want to find the one closest to the actual average. + MFloat epsAverageDiff = ParallelMath::MakeFloat(FLT_MAX); + for (int t = 0; t < numTables; t++) + { + const cvtt::Tables::BC7SC::Table& table = *(tables[t]); + + ParallelMath::Int16CompFlag pti = punchThroughInvalid[table.m_pBits]; + + MUInt15 candidateReconstructed[4]; + MUInt15 candidateEPs[2][4]; + + for (int i = 0; i < ParallelMath::ParallelSize; i++) + { + for (int ch = 0; ch < numRealChannels; ch++) + { + ParallelMath::ScalarUInt16 avgValue = ParallelMath::Extract(intAverage[ch], i); + assert(avgValue >= 0 && avgValue <= 255); + + const cvtt::Tables::BC7SC::TableEntry &entry = table.m_entries[avgValue]; + + ParallelMath::PutUInt15(candidateEPs[0][ch], i, entry.m_min); + ParallelMath::PutUInt15(candidateEPs[1][ch], i, entry.m_max); + ParallelMath::PutUInt15(candidateReconstructed[ch], i, entry.m_actualColor); + } + } + + MFloat avgError = ParallelMath::MakeFloatZero(); + for (int ch = 0; ch < numRealChannels; ch++) + { + MFloat delta = ParallelMath::ToFloat(candidateReconstructed[ch]) - average[ch]; + avgError = avgError + delta * delta * channelWeightsSq[ch]; + } + + ParallelMath::Int16CompFlag better = ParallelMath::FloatFlagToInt16(ParallelMath::Less(avgError, bestAverageError)); + better = ParallelMath::AndNot(pti, better); // Mask out punch-through invalidations + + if (ParallelMath::AnySet(better)) + { + ParallelMath::ConditionalSet(bestAverageError, ParallelMath::Int16FlagToFloat(better), avgError); + + MUInt15 candidateIndex = ParallelMath::MakeUInt15(table.m_index); + + ParallelMath::ConditionalSet(index, better, candidateIndex); + + for (int ch = 0; ch < numRealChannels; ch++) + ParallelMath::ConditionalSet(reconstructed[ch], better, candidateReconstructed[ch]); + + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < numRealChannels; ch++) + ParallelMath::ConditionalSet(eps[epi][ch], better, candidateEPs[epi][ch]); + } + } + + AggregatedError<4> aggError; + for (int pxi = 0; pxi < shapeLength; pxi++) + { + int px = fragmentStart[pxi]; + + BCCommon::ComputeErrorLDR<4>(flags, reconstructed, pixels[px], numRealChannels, aggError); + } + + MFloat error = aggError.Finalize(flags, channelWeightsSq) + staticAlphaError; + + ParallelMath::Int16CompFlag better = ParallelMath::FloatFlagToInt16(ParallelMath::Less(error, shapeBestError)); + if (ParallelMath::AnySet(better)) + { + shapeBestError = ParallelMath::Min(shapeBestError, error); + for (int epi = 0; epi < 2; epi++) + { + for (int ch = 0; ch < numRealChannels; ch++) + ParallelMath::ConditionalSet(shapeBestEP[epi][ch], better, eps[epi][ch]); + } + + for (int pxi = 0; pxi < shapeLength; pxi++) + ParallelMath::ConditionalSet(fragmentBestIndexes[pxi], better, index); + } + } + + + static void TrySinglePlane(uint32_t flags, const MUInt15 pixels[16][4], const MFloat floatPixels[16][4], const float channelWeights[4], int numTweakRounds, int numRefineRounds, WorkInfo& work, const ParallelMath::RoundTowardNearestForScope *rtn) + { + if (numRefineRounds < 1) + numRefineRounds = 1; + + if (numTweakRounds < 1) + numTweakRounds = 1; + else if (numTweakRounds > MaxTweakRounds) + numTweakRounds = MaxTweakRounds; + + float channelWeightsSq[4]; + + for (int ch = 0; ch < 4; ch++) + channelWeightsSq[ch] = channelWeights[ch] * channelWeights[ch]; + + SinglePlaneTemporaries temps; + + MUInt15 maxAlpha = ParallelMath::MakeUInt15(0); + MUInt15 minAlpha = ParallelMath::MakeUInt15(255); + ParallelMath::Int16CompFlag isPunchThrough = ParallelMath::MakeBoolInt16(true); + for (int px = 0; px < 16; px++) + { + MUInt15 a = pixels[px][3]; + maxAlpha = ParallelMath::Max(maxAlpha, a); + minAlpha = ParallelMath::Min(minAlpha, a); + + isPunchThrough = (isPunchThrough & (ParallelMath::Equal(a, ParallelMath::MakeUInt15(0)) | ParallelMath::Equal(a, ParallelMath::MakeUInt15(255)))); + } + + ParallelMath::Int16CompFlag blockHasNonMaxAlpha = ParallelMath::Less(minAlpha, ParallelMath::MakeUInt15(255)); + ParallelMath::Int16CompFlag blockHasNonZeroAlpha = ParallelMath::Less(ParallelMath::MakeUInt15(0), maxAlpha); + + bool anyBlockHasAlpha = ParallelMath::AnySet(blockHasNonMaxAlpha); + + // Try RGB modes if any block has a min alpha 251 or higher + bool allowRGBModes = ParallelMath::AnySet(ParallelMath::Less(ParallelMath::MakeUInt15(250), minAlpha)); + + // Try mode 7 if any block has alpha. + // Mode 7 is almost never selected for RGB blocks because mode 4 has very accurate 7.7.7.1 endpoints + // and its parity bit doesn't affect alpha, meaning mode 7 can only be better in extremely specific + // situations, and only by at most 1 unit of error per pixel. + bool allowMode7 = anyBlockHasAlpha; + + MFloat preWeightedPixels[16][4]; + + BCCommon::PreWeightPixelsLDR<4>(preWeightedPixels, pixels, channelWeights); + + const int *rgbInitialEPCollapseList = NULL; + + // Get initial RGB endpoints + if (allowRGBModes) + { + const int *shapeList; + int numShapesToEvaluate; + + if (flags & Flags::BC7_EnablePartitioning) + { + if (flags & Flags::BC7_Enable3Subsets) + { + shapeList = BC7Data::g_shapeListAll; + rgbInitialEPCollapseList = BC7Data::g_shapeListAll; + numShapesToEvaluate = BC7Data::g_numShapesAll; + } + else + { + shapeList = BC7Data::g_shapeList12; + rgbInitialEPCollapseList = BC7Data::g_shapeList12Collapse; + numShapesToEvaluate = BC7Data::g_numShapes12; + } + } + else + { + shapeList = BC7Data::g_shapeList1; + rgbInitialEPCollapseList = BC7Data::g_shapeList1Collapse; + numShapesToEvaluate = BC7Data::g_numShapes1; + } + + for (int shapeIter = 0; shapeIter < numShapesToEvaluate; shapeIter++) + { + int shape = shapeList[shapeIter]; + + int shapeStart = BC7Data::g_shapeRanges[shape][0]; + int shapeSize = BC7Data::g_shapeRanges[shape][1]; + + EndpointSelector<3, 8> epSelector; + + for (int epPass = 0; epPass < NumEndpointSelectorPasses; epPass++) + { + for (int spx = 0; spx < shapeSize; spx++) + { + int px = BC7Data::g_fragments[shapeStart + spx]; + epSelector.ContributePass(preWeightedPixels[px], epPass, ParallelMath::MakeFloat(1.0f)); + } + epSelector.FinishPass(epPass); + } + temps.unfinishedRGB[shapeIter] = epSelector.GetEndpoints(channelWeights); + } + } + + const int *rgbaInitialEPCollapseList = BC7Data::g_shapeList12Collapse; + + // Get initial RGBA endpoints + { + const int *shapeList = BC7Data::g_shapeList12; + int numShapesToEvaluate = BC7Data::g_numShapes12; + + for (int shapeIter = 0; shapeIter < numShapesToEvaluate; shapeIter++) + { + int shape = shapeList[shapeIter]; + + if (anyBlockHasAlpha || !allowRGBModes) + { + int shapeStart = BC7Data::g_shapeRanges[shape][0]; + int shapeSize = BC7Data::g_shapeRanges[shape][1]; + + EndpointSelector<4, 8> epSelector; + + for (int epPass = 0; epPass < NumEndpointSelectorPasses; epPass++) + { + for (int spx = 0; spx < shapeSize; spx++) + { + int px = BC7Data::g_fragments[shapeStart + spx]; + epSelector.ContributePass(preWeightedPixels[px], epPass, ParallelMath::MakeFloat(1.0f)); + } + epSelector.FinishPass(epPass); + } + temps.unfinishedRGBA[shapeIter] = epSelector.GetEndpoints(channelWeights); + } + else + { + temps.unfinishedRGBA[shapeIter] = temps.unfinishedRGB[rgbInitialEPCollapseList[shape]].ExpandTo<4>(255); + } + } + } + + for (uint16_t mode = 0; mode <= 7; mode++) + { + if (!(flags & Flags::BC7_EnablePartitioning) && BC7Data::g_modes[mode].m_numSubsets != 1) + continue; + + if (!(flags & Flags::BC7_Enable3Subsets) && BC7Data::g_modes[mode].m_numSubsets == 3) + continue; + + if (mode == 4 || mode == 5) + continue; + + if (mode < 4 && !allowRGBModes) + continue; + + if (mode == 7 && !allowMode7) + continue; + + bool isRGB = (mode < 4); + + unsigned int numPartitions = 1 << BC7Data::g_modes[mode].m_partitionBits; + int numSubsets = BC7Data::g_modes[mode].m_numSubsets; + int indexPrec = BC7Data::g_modes[mode].m_indexBits; + + int parityBitMax = 1; + if (BC7Data::g_modes[mode].m_pBitMode == BC7Data::PBitMode_PerEndpoint) + parityBitMax = 4; + else if (BC7Data::g_modes[mode].m_pBitMode == BC7Data::PBitMode_PerSubset) + parityBitMax = 2; + + int numRealChannels = isRGB ? 3 : 4; + + int numShapes; + const int *shapeList; + const int *shapeCollapseList; + + if (numSubsets == 1) + { + numShapes = BC7Data::g_numShapes1; + shapeList = BC7Data::g_shapeList1; + shapeCollapseList = BC7Data::g_shapeList1Collapse; + } + else if (numSubsets == 2) + { + numShapes = BC7Data::g_numShapes2; + shapeList = BC7Data::g_shapeList2; + shapeCollapseList = BC7Data::g_shapeList2Collapse; + } + else + { + assert(numSubsets == 3); + if (numPartitions == 16) + { + numShapes = BC7Data::g_numShapes3Short; + shapeList = BC7Data::g_shapeList3Short; + shapeCollapseList = BC7Data::g_shapeList3ShortCollapse; + } + else + { + assert(numPartitions == 64); + numShapes = BC7Data::g_numShapes3; + shapeList = BC7Data::g_shapeList3; + shapeCollapseList = BC7Data::g_shapeList3Collapse; + } + } + + for (int slot = 0; slot < BC7Data::g_maxFragmentsPerMode; slot++) + temps.shapeBestError[slot] = ParallelMath::MakeFloat(FLT_MAX); + + for (int shapeIter = 0; shapeIter < numShapes; shapeIter++) + { + int shape = shapeList[shapeIter]; + int shapeStart = BC7Data::g_shapeRanges[shape][0]; + int shapeLength = BC7Data::g_shapeRanges[shape][1]; + int shapeCollapsedEvalIndex = shapeCollapseList[shape]; + + AggregatedError<1> alphaAggError; + if (isRGB && anyBlockHasAlpha) + { + MUInt15 filledAlpha[1] = { ParallelMath::MakeUInt15(255) }; + + for (int pxi = 0; pxi < shapeLength; pxi++) + { + int px = BC7Data::g_fragments[shapeStart + pxi]; + MUInt15 original[1] = { pixels[px][3] }; + BCCommon::ComputeErrorLDR<1>(flags, filledAlpha, original, alphaAggError); + } + } + + float alphaWeightsSq[1] = { channelWeightsSq[3] }; + MFloat staticAlphaError = alphaAggError.Finalize(flags, alphaWeightsSq); + + assert(shapeCollapsedEvalIndex >= 0); + + MUInt15 tweakBaseEP[MaxTweakRounds][2][4]; + + for (int tweak = 0; tweak < numTweakRounds; tweak++) + { + if (isRGB) + { + temps.unfinishedRGB[rgbInitialEPCollapseList[shape]].FinishLDR(tweak, 1 << indexPrec, tweakBaseEP[tweak][0], tweakBaseEP[tweak][1]); + tweakBaseEP[tweak][0][3] = tweakBaseEP[tweak][1][3] = ParallelMath::MakeUInt15(255); + } + else + { + temps.unfinishedRGBA[rgbaInitialEPCollapseList[shape]].FinishLDR(tweak, 1 << indexPrec, tweakBaseEP[tweak][0], tweakBaseEP[tweak][1]); + } + } + + ParallelMath::Int16CompFlag punchThroughInvalid[4]; + for (int pIter = 0; pIter < parityBitMax; pIter++) + { + punchThroughInvalid[pIter] = ParallelMath::MakeBoolInt16(false); + + if ((flags & Flags::BC7_RespectPunchThrough) && (mode == 6 || mode == 7)) + { + // Modes 6 and 7 have parity bits that affect alpha + if (pIter == 0) + punchThroughInvalid[pIter] = (isPunchThrough & blockHasNonZeroAlpha); + else if (pIter == parityBitMax - 1) + punchThroughInvalid[pIter] = (isPunchThrough & blockHasNonMaxAlpha); + else + punchThroughInvalid[pIter] = isPunchThrough; + } + } + + for (int pIter = 0; pIter < parityBitMax; pIter++) + { + if (ParallelMath::AllSet(punchThroughInvalid[pIter])) + continue; + + bool needPunchThroughCheck = ParallelMath::AnySet(punchThroughInvalid[pIter]); + + for (int tweak = 0; tweak < numTweakRounds; tweak++) + { + uint16_t p[2]; + p[0] = (pIter & 1); + p[1] = ((pIter >> 1) & 1); + + MUInt15 ep[2][4]; + + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < 4; ch++) + ep[epi][ch] = tweakBaseEP[tweak][epi][ch]; + + for (int refine = 0; refine < numRefineRounds; refine++) + { + switch (mode) + { + case 0: + CompressEndpoints0(ep, p, rtn); + break; + case 1: + CompressEndpoints1(ep, p[0], rtn); + break; + case 2: + CompressEndpoints2(ep, rtn); + break; + case 3: + CompressEndpoints3(ep, p, rtn); + break; + case 6: + CompressEndpoints6(ep, p, rtn); + break; + case 7: + CompressEndpoints7(ep, p, rtn); + break; + default: + assert(false); + break; + }; + + MFloat shapeError = ParallelMath::MakeFloatZero(); + + IndexSelector<4> indexSelector; + indexSelector.Init<false>(channelWeights, ep, 1 << indexPrec); + + EndpointRefiner<4> epRefiner; + epRefiner.Init(1 << indexPrec, channelWeights); + + MUInt15 indexes[16]; + + AggregatedError<4> aggError; + for (int pxi = 0; pxi < shapeLength; pxi++) + { + int px = BC7Data::g_fragments[shapeStart + pxi]; + + MUInt15 index; + MUInt15 reconstructed[4]; + + index = indexSelector.SelectIndexLDR(floatPixels[px], rtn); + indexSelector.ReconstructLDR_BC7(index, reconstructed, numRealChannels); + + if (flags & cvtt::Flags::BC7_FastIndexing) + BCCommon::ComputeErrorLDR<4>(flags, reconstructed, pixels[px], numRealChannels, aggError); + else + { + MFloat error = BCCommon::ComputeErrorLDRSimple<4>(flags, reconstructed, pixels[px], numRealChannels, channelWeightsSq); + + MUInt15 altIndexes[2]; + altIndexes[0] = ParallelMath::Max(index, ParallelMath::MakeUInt15(1)) - ParallelMath::MakeUInt15(1); + altIndexes[1] = ParallelMath::Min(index + ParallelMath::MakeUInt15(1), ParallelMath::MakeUInt15(static_cast<uint16_t>((1 << indexPrec) - 1))); + + for (int ii = 0; ii < 2; ii++) + { + indexSelector.ReconstructLDR_BC7(altIndexes[ii], reconstructed, numRealChannels); + + MFloat altError = BCCommon::ComputeErrorLDRSimple<4>(flags, reconstructed, pixels[px], numRealChannels, channelWeightsSq); + ParallelMath::Int16CompFlag better = ParallelMath::FloatFlagToInt16(ParallelMath::Less(altError, error)); + error = ParallelMath::Min(error, altError); + ParallelMath::ConditionalSet(index, better, altIndexes[ii]); + } + + shapeError = shapeError + error; + } + + if (refine != numRefineRounds - 1) + epRefiner.ContributeUnweightedPW(preWeightedPixels[px], index, numRealChannels); + + indexes[pxi] = index; + } + + if (flags & cvtt::Flags::BC7_FastIndexing) + shapeError = aggError.Finalize(flags, channelWeightsSq); + + if (isRGB) + shapeError = shapeError + staticAlphaError; + + ParallelMath::FloatCompFlag shapeErrorBetter; + ParallelMath::Int16CompFlag shapeErrorBetter16; + + shapeErrorBetter = ParallelMath::Less(shapeError, temps.shapeBestError[shapeCollapsedEvalIndex]); + shapeErrorBetter16 = ParallelMath::FloatFlagToInt16(shapeErrorBetter); + + if (ParallelMath::AnySet(shapeErrorBetter16)) + { + bool punchThroughOK = true; + if (needPunchThroughCheck) + { + shapeErrorBetter16 = ParallelMath::AndNot(punchThroughInvalid[pIter], shapeErrorBetter16); + shapeErrorBetter = ParallelMath::Int16FlagToFloat(shapeErrorBetter16); + + if (!ParallelMath::AnySet(shapeErrorBetter16)) + punchThroughOK = false; + } + + if (punchThroughOK) + { + ParallelMath::ConditionalSet(temps.shapeBestError[shapeCollapsedEvalIndex], shapeErrorBetter, shapeError); + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < numRealChannels; ch++) + ParallelMath::ConditionalSet(temps.shapeBestEP[shapeCollapsedEvalIndex][epi][ch], shapeErrorBetter16, ep[epi][ch]); + + for (int pxi = 0; pxi < shapeLength; pxi++) + ParallelMath::ConditionalSet(temps.fragmentBestIndexes[shapeStart + pxi], shapeErrorBetter16, indexes[pxi]); + } + } + + if (refine != numRefineRounds - 1) + epRefiner.GetRefinedEndpointsLDR(ep, numRealChannels, rtn); + } // refine + } // tweak + } // p + + if (flags & cvtt::Flags::BC7_TrySingleColor) + { + MUInt15 total[4]; + for (int ch = 0; ch < 4; ch++) + total[ch] = ParallelMath::MakeUInt15(0); + + for (int pxi = 0; pxi < shapeLength; pxi++) + { + int px = BC7Data::g_fragments[shapeStart + pxi]; + for (int ch = 0; ch < 4; ch++) + total[ch] = total[ch] + pixels[pxi][ch]; + } + + MFloat rcpShapeLength = ParallelMath::MakeFloat(1.0f / static_cast<float>(shapeLength)); + MFloat average[4]; + for (int ch = 0; ch < 4; ch++) + average[ch] = ParallelMath::ToFloat(total[ch]) * rcpShapeLength; + + const uint8_t *fragment = BC7Data::g_fragments + shapeStart; + MFloat &shapeBestError = temps.shapeBestError[shapeCollapsedEvalIndex]; + MUInt15(&shapeBestEP)[2][4] = temps.shapeBestEP[shapeCollapsedEvalIndex]; + MUInt15 *fragmentBestIndexes = temps.fragmentBestIndexes + shapeStart; + + const cvtt::Tables::BC7SC::Table **scTables = NULL; + int numSCTables = 0; + + switch (mode) + { + case 0: + { + const cvtt::Tables::BC7SC::Table *tables[] = + { + &cvtt::Tables::BC7SC::g_mode0_p00_i1, + &cvtt::Tables::BC7SC::g_mode0_p00_i2, + &cvtt::Tables::BC7SC::g_mode0_p00_i3, + &cvtt::Tables::BC7SC::g_mode0_p01_i1, + &cvtt::Tables::BC7SC::g_mode0_p01_i2, + &cvtt::Tables::BC7SC::g_mode0_p01_i3, + &cvtt::Tables::BC7SC::g_mode0_p10_i1, + &cvtt::Tables::BC7SC::g_mode0_p10_i2, + &cvtt::Tables::BC7SC::g_mode0_p10_i3, + &cvtt::Tables::BC7SC::g_mode0_p11_i1, + &cvtt::Tables::BC7SC::g_mode0_p11_i2, + &cvtt::Tables::BC7SC::g_mode0_p11_i3, + }; + scTables = tables; + numSCTables = sizeof(tables) / sizeof(tables[0]); + } + break; + case 1: + { + const cvtt::Tables::BC7SC::Table *tables[] = + { + &cvtt::Tables::BC7SC::g_mode1_p0_i1, + &cvtt::Tables::BC7SC::g_mode1_p0_i2, + &cvtt::Tables::BC7SC::g_mode1_p0_i3, + &cvtt::Tables::BC7SC::g_mode1_p1_i1, + &cvtt::Tables::BC7SC::g_mode1_p1_i2, + &cvtt::Tables::BC7SC::g_mode1_p1_i3, + }; + scTables = tables; + numSCTables = sizeof(tables) / sizeof(tables[0]); + } + break; + case 2: + { + const cvtt::Tables::BC7SC::Table *tables[] = + { + &cvtt::Tables::BC7SC::g_mode2, + }; + scTables = tables; + numSCTables = sizeof(tables) / sizeof(tables[0]); + } + break; + case 3: + { + const cvtt::Tables::BC7SC::Table *tables[] = + { + &cvtt::Tables::BC7SC::g_mode3_p0, + &cvtt::Tables::BC7SC::g_mode3_p1, + }; + scTables = tables; + numSCTables = sizeof(tables) / sizeof(tables[0]); + } + break; + case 6: + { + const cvtt::Tables::BC7SC::Table *tables[] = + { + &cvtt::Tables::BC7SC::g_mode6_p0_i1, + &cvtt::Tables::BC7SC::g_mode6_p0_i2, + &cvtt::Tables::BC7SC::g_mode6_p0_i3, + &cvtt::Tables::BC7SC::g_mode6_p0_i4, + &cvtt::Tables::BC7SC::g_mode6_p0_i5, + &cvtt::Tables::BC7SC::g_mode6_p0_i6, + &cvtt::Tables::BC7SC::g_mode6_p0_i7, + &cvtt::Tables::BC7SC::g_mode6_p1_i1, + &cvtt::Tables::BC7SC::g_mode6_p1_i2, + &cvtt::Tables::BC7SC::g_mode6_p1_i3, + &cvtt::Tables::BC7SC::g_mode6_p1_i4, + &cvtt::Tables::BC7SC::g_mode6_p1_i5, + &cvtt::Tables::BC7SC::g_mode6_p1_i6, + &cvtt::Tables::BC7SC::g_mode6_p1_i7, + }; + scTables = tables; + numSCTables = sizeof(tables) / sizeof(tables[0]); + } + break; + case 7: + { + const cvtt::Tables::BC7SC::Table *tables[] = + { + &cvtt::Tables::BC7SC::g_mode7_p00, + &cvtt::Tables::BC7SC::g_mode7_p01, + &cvtt::Tables::BC7SC::g_mode7_p10, + &cvtt::Tables::BC7SC::g_mode7_p11, + }; + scTables = tables; + numSCTables = sizeof(tables) / sizeof(tables[0]); + } + break; + default: + assert(false); + break; + } + + TrySingleColorRGBAMultiTable(flags, pixels, average, numRealChannels, fragment, shapeLength, staticAlphaError, punchThroughInvalid, shapeBestError, shapeBestEP, fragmentBestIndexes, channelWeightsSq, scTables, numSCTables, rtn); + } + } // shapeIter + + for (uint16_t partition = 0; partition < numPartitions; partition++) + { + const int *partitionShapes; + if (numSubsets == 1) + partitionShapes = BC7Data::g_shapes1[partition]; + else if (numSubsets == 2) + partitionShapes = BC7Data::g_shapes2[partition]; + else + { + assert(numSubsets == 3); + partitionShapes = BC7Data::g_shapes3[partition]; + } + + MFloat totalError = ParallelMath::MakeFloatZero(); + for (int subset = 0; subset < numSubsets; subset++) + totalError = totalError + temps.shapeBestError[shapeCollapseList[partitionShapes[subset]]]; + + ParallelMath::FloatCompFlag errorBetter = ParallelMath::Less(totalError, work.m_error); + ParallelMath::Int16CompFlag errorBetter16 = ParallelMath::FloatFlagToInt16(errorBetter); + + if (ParallelMath::AnySet(errorBetter16)) + { + for (int subset = 0; subset < numSubsets; subset++) + { + int shape = partitionShapes[subset]; + int shapeStart = BC7Data::g_shapeRanges[shape][0]; + int shapeLength = BC7Data::g_shapeRanges[shape][1]; + int shapeCollapsedEvalIndex = shapeCollapseList[shape]; + + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < 4; ch++) + ParallelMath::ConditionalSet(work.m_ep[subset][epi][ch], errorBetter16, temps.shapeBestEP[shapeCollapsedEvalIndex][epi][ch]); + + for (int pxi = 0; pxi < shapeLength; pxi++) + { + int px = BC7Data::g_fragments[shapeStart + pxi]; + ParallelMath::ConditionalSet(work.m_indexes[px], errorBetter16, temps.fragmentBestIndexes[shapeStart + pxi]); + } + } + + work.m_error = ParallelMath::Min(totalError, work.m_error); + ParallelMath::ConditionalSet(work.m_mode, errorBetter16, ParallelMath::MakeUInt15(mode)); + ParallelMath::ConditionalSet(work.m_u.m_partition, errorBetter16, ParallelMath::MakeUInt15(partition)); + } + } + } + } + + static void TryDualPlane(uint32_t flags, const MUInt15 pixels[16][4], const MFloat floatPixels[16][4], const float channelWeights[4], int numTweakRounds, int numRefineRounds, WorkInfo& work, const ParallelMath::RoundTowardNearestForScope *rtn) + { + // TODO: These error calculations are not optimal for weight-by-alpha, but this routine needs to be mostly rewritten for that. + // The alpha/color solutions are co-dependent in that case, but a good way to solve it would probably be to + // solve the alpha channel first, then solve the RGB channels, which in turn breaks down into two cases: + // - Separate alpha channel, then weighted RGB + // - Alpha+2 other channels, then the independent channel + + if (!(flags & Flags::BC7_EnableDualPlane)) + return; + + if (numRefineRounds < 1) + numRefineRounds = 1; + + if (numTweakRounds < 1) + numTweakRounds = 1; + else if (numTweakRounds > MaxTweakRounds) + numTweakRounds = MaxTweakRounds; + + float channelWeightsSq[4]; + for (int ch = 0; ch < 4; ch++) + channelWeightsSq[ch] = channelWeights[ch] * channelWeights[ch]; + + for (uint16_t mode = 4; mode <= 5; mode++) + { + for (uint16_t rotation = 0; rotation < 4; rotation++) + { + int alphaChannel = (rotation + 3) & 3; + int redChannel = (rotation == 1) ? 3 : 0; + int greenChannel = (rotation == 2) ? 3 : 1; + int blueChannel = (rotation == 3) ? 3 : 2; + + MUInt15 rotatedRGB[16][3]; + MFloat floatRotatedRGB[16][3]; + + for (int px = 0; px < 16; px++) + { + rotatedRGB[px][0] = pixels[px][redChannel]; + rotatedRGB[px][1] = pixels[px][greenChannel]; + rotatedRGB[px][2] = pixels[px][blueChannel]; + + for (int ch = 0; ch < 3; ch++) + floatRotatedRGB[px][ch] = ParallelMath::ToFloat(rotatedRGB[px][ch]); + } + + uint16_t maxIndexSelector = (mode == 4) ? 2 : 1; + + float rotatedRGBWeights[3] = { channelWeights[redChannel], channelWeights[greenChannel], channelWeights[blueChannel] }; + float rotatedRGBWeightsSq[3] = { channelWeightsSq[redChannel], channelWeightsSq[greenChannel], channelWeightsSq[blueChannel] }; + float rotatedAlphaWeight[1] = { channelWeights[alphaChannel] }; + float rotatedAlphaWeightSq[1] = { channelWeightsSq[alphaChannel] }; + + float uniformWeight[1] = { 1.0f }; // Since the alpha channel is independent, there's no need to bother with weights when doing refinement or selection, only error + + MFloat preWeightedRotatedRGB[16][3]; + BCCommon::PreWeightPixelsLDR<3>(preWeightedRotatedRGB, rotatedRGB, rotatedRGBWeights); + + for (uint16_t indexSelector = 0; indexSelector < maxIndexSelector; indexSelector++) + { + EndpointSelector<3, 8> rgbSelector; + + for (int epPass = 0; epPass < NumEndpointSelectorPasses; epPass++) + { + for (int px = 0; px < 16; px++) + rgbSelector.ContributePass(preWeightedRotatedRGB[px], epPass, ParallelMath::MakeFloat(1.0f)); + + rgbSelector.FinishPass(epPass); + } + + MUInt15 alphaRange[2]; + + alphaRange[0] = alphaRange[1] = pixels[0][alphaChannel]; + for (int px = 1; px < 16; px++) + { + alphaRange[0] = ParallelMath::Min(pixels[px][alphaChannel], alphaRange[0]); + alphaRange[1] = ParallelMath::Max(pixels[px][alphaChannel], alphaRange[1]); + } + + int rgbPrec = 0; + int alphaPrec = 0; + + if (mode == 4) + { + rgbPrec = indexSelector ? 3 : 2; + alphaPrec = indexSelector ? 2 : 3; + } + else + rgbPrec = alphaPrec = 2; + + UnfinishedEndpoints<3> unfinishedRGB = rgbSelector.GetEndpoints(rotatedRGBWeights); + + MFloat bestRGBError = ParallelMath::MakeFloat(FLT_MAX); + MFloat bestAlphaError = ParallelMath::MakeFloat(FLT_MAX); + + MUInt15 bestRGBIndexes[16]; + MUInt15 bestAlphaIndexes[16]; + MUInt15 bestEP[2][4]; + + for (int px = 0; px < 16; px++) + bestRGBIndexes[px] = bestAlphaIndexes[px] = ParallelMath::MakeUInt15(0); + + for (int tweak = 0; tweak < numTweakRounds; tweak++) + { + MUInt15 rgbEP[2][3]; + MUInt15 alphaEP[2]; + + unfinishedRGB.FinishLDR(tweak, 1 << rgbPrec, rgbEP[0], rgbEP[1]); + + TweakAlpha(alphaRange, tweak, 1 << alphaPrec, alphaEP); + + for (int refine = 0; refine < numRefineRounds; refine++) + { + if (mode == 4) + CompressEndpoints4(rgbEP, alphaEP, rtn); + else + CompressEndpoints5(rgbEP, alphaEP, rtn); + + + IndexSelector<1> alphaIndexSelector; + IndexSelector<3> rgbIndexSelector; + + { + MUInt15 alphaEPTemp[2][1] = { { alphaEP[0] },{ alphaEP[1] } }; + alphaIndexSelector.Init<false>(uniformWeight, alphaEPTemp, 1 << alphaPrec); + } + rgbIndexSelector.Init<false>(rotatedRGBWeights, rgbEP, 1 << rgbPrec); + + EndpointRefiner<3> rgbRefiner; + EndpointRefiner<1> alphaRefiner; + + rgbRefiner.Init(1 << rgbPrec, rotatedRGBWeights); + alphaRefiner.Init(1 << alphaPrec, uniformWeight); + + MFloat errorRGB = ParallelMath::MakeFloatZero(); + MFloat errorA = ParallelMath::MakeFloatZero(); + + MUInt15 rgbIndexes[16]; + MUInt15 alphaIndexes[16]; + + AggregatedError<3> rgbAggError; + AggregatedError<1> alphaAggError; + + for (int px = 0; px < 16; px++) + { + MUInt15 rgbIndex = rgbIndexSelector.SelectIndexLDR(floatRotatedRGB[px], rtn); + MUInt15 alphaIndex = alphaIndexSelector.SelectIndexLDR(floatPixels[px] + alphaChannel, rtn); + + MUInt15 reconstructedRGB[3]; + MUInt15 reconstructedAlpha[1]; + + rgbIndexSelector.ReconstructLDR_BC7(rgbIndex, reconstructedRGB); + alphaIndexSelector.ReconstructLDR_BC7(alphaIndex, reconstructedAlpha); + + if (flags & cvtt::Flags::BC7_FastIndexing) + { + BCCommon::ComputeErrorLDR<3>(flags, reconstructedRGB, rotatedRGB[px], rgbAggError); + BCCommon::ComputeErrorLDR<1>(flags, reconstructedAlpha, pixels[px] + alphaChannel, alphaAggError); + } + else + { + AggregatedError<3> baseRGBAggError; + AggregatedError<1> baseAlphaAggError; + + BCCommon::ComputeErrorLDR<3>(flags, reconstructedRGB, rotatedRGB[px], baseRGBAggError); + BCCommon::ComputeErrorLDR<1>(flags, reconstructedAlpha, pixels[px] + alphaChannel, baseAlphaAggError); + + MFloat rgbError = baseRGBAggError.Finalize(flags, rotatedRGBWeightsSq); + MFloat alphaError = baseAlphaAggError.Finalize(flags, rotatedAlphaWeightSq); + + MUInt15 altRGBIndexes[2]; + MUInt15 altAlphaIndexes[2]; + + altRGBIndexes[0] = ParallelMath::Max(rgbIndex, ParallelMath::MakeUInt15(1)) - ParallelMath::MakeUInt15(1); + altRGBIndexes[1] = ParallelMath::Min(rgbIndex + ParallelMath::MakeUInt15(1), ParallelMath::MakeUInt15(static_cast<uint16_t>((1 << rgbPrec) - 1))); + + altAlphaIndexes[0] = ParallelMath::Max(alphaIndex, ParallelMath::MakeUInt15(1)) - ParallelMath::MakeUInt15(1); + altAlphaIndexes[1] = ParallelMath::Min(alphaIndex + ParallelMath::MakeUInt15(1), ParallelMath::MakeUInt15(static_cast<uint16_t>((1 << alphaPrec) - 1))); + + for (int ii = 0; ii < 2; ii++) + { + rgbIndexSelector.ReconstructLDR_BC7(altRGBIndexes[ii], reconstructedRGB); + alphaIndexSelector.ReconstructLDR_BC7(altAlphaIndexes[ii], reconstructedAlpha); + + AggregatedError<3> altRGBAggError; + AggregatedError<1> altAlphaAggError; + + BCCommon::ComputeErrorLDR<3>(flags, reconstructedRGB, rotatedRGB[px], altRGBAggError); + BCCommon::ComputeErrorLDR<1>(flags, reconstructedAlpha, pixels[px] + alphaChannel, altAlphaAggError); + + MFloat altRGBError = altRGBAggError.Finalize(flags, rotatedRGBWeightsSq); + MFloat altAlphaError = altAlphaAggError.Finalize(flags, rotatedAlphaWeightSq); + + ParallelMath::Int16CompFlag rgbBetter = ParallelMath::FloatFlagToInt16(ParallelMath::Less(altRGBError, rgbError)); + ParallelMath::Int16CompFlag alphaBetter = ParallelMath::FloatFlagToInt16(ParallelMath::Less(altAlphaError, alphaError)); + + rgbError = ParallelMath::Min(altRGBError, rgbError); + alphaError = ParallelMath::Min(altAlphaError, alphaError); + + ParallelMath::ConditionalSet(rgbIndex, rgbBetter, altRGBIndexes[ii]); + ParallelMath::ConditionalSet(alphaIndex, alphaBetter, altAlphaIndexes[ii]); + } + + errorRGB = errorRGB + rgbError; + errorA = errorA + alphaError; + } + + if (refine != numRefineRounds - 1) + { + rgbRefiner.ContributeUnweightedPW(preWeightedRotatedRGB[px], rgbIndex); + alphaRefiner.ContributeUnweightedPW(floatPixels[px] + alphaChannel, alphaIndex); + } + + if (flags & Flags::BC7_FastIndexing) + { + errorRGB = rgbAggError.Finalize(flags, rotatedRGBWeightsSq); + errorA = rgbAggError.Finalize(flags, rotatedAlphaWeightSq); + } + + rgbIndexes[px] = rgbIndex; + alphaIndexes[px] = alphaIndex; + } + + ParallelMath::FloatCompFlag rgbBetter = ParallelMath::Less(errorRGB, bestRGBError); + ParallelMath::FloatCompFlag alphaBetter = ParallelMath::Less(errorA, bestAlphaError); + + ParallelMath::Int16CompFlag rgbBetterInt16 = ParallelMath::FloatFlagToInt16(rgbBetter); + ParallelMath::Int16CompFlag alphaBetterInt16 = ParallelMath::FloatFlagToInt16(alphaBetter); + + if (ParallelMath::AnySet(rgbBetterInt16)) + { + bestRGBError = ParallelMath::Min(errorRGB, bestRGBError); + + for (int px = 0; px < 16; px++) + ParallelMath::ConditionalSet(bestRGBIndexes[px], rgbBetterInt16, rgbIndexes[px]); + + for (int ep = 0; ep < 2; ep++) + { + for (int ch = 0; ch < 3; ch++) + ParallelMath::ConditionalSet(bestEP[ep][ch], rgbBetterInt16, rgbEP[ep][ch]); + } + } + + if (ParallelMath::AnySet(alphaBetterInt16)) + { + bestAlphaError = ParallelMath::Min(errorA, bestAlphaError); + + for (int px = 0; px < 16; px++) + ParallelMath::ConditionalSet(bestAlphaIndexes[px], alphaBetterInt16, alphaIndexes[px]); + + for (int ep = 0; ep < 2; ep++) + ParallelMath::ConditionalSet(bestEP[ep][3], alphaBetterInt16, alphaEP[ep]); + } + + if (refine != numRefineRounds - 1) + { + rgbRefiner.GetRefinedEndpointsLDR(rgbEP, rtn); + + MUInt15 alphaEPTemp[2][1]; + alphaRefiner.GetRefinedEndpointsLDR(alphaEPTemp, rtn); + + for (int i = 0; i < 2; i++) + alphaEP[i] = alphaEPTemp[i][0]; + } + } // refine + } // tweak + + MFloat combinedError = bestRGBError + bestAlphaError; + + ParallelMath::FloatCompFlag errorBetter = ParallelMath::Less(combinedError, work.m_error); + ParallelMath::Int16CompFlag errorBetter16 = ParallelMath::FloatFlagToInt16(errorBetter); + + work.m_error = ParallelMath::Min(combinedError, work.m_error); + + ParallelMath::ConditionalSet(work.m_mode, errorBetter16, ParallelMath::MakeUInt15(mode)); + ParallelMath::ConditionalSet(work.m_u.m_isr.m_rotation, errorBetter16, ParallelMath::MakeUInt15(rotation)); + ParallelMath::ConditionalSet(work.m_u.m_isr.m_indexSelector, errorBetter16, ParallelMath::MakeUInt15(indexSelector)); + + for (int px = 0; px < 16; px++) + { + ParallelMath::ConditionalSet(work.m_indexes[px], errorBetter16, indexSelector ? bestAlphaIndexes[px] : bestRGBIndexes[px]); + ParallelMath::ConditionalSet(work.m_indexes2[px], errorBetter16, indexSelector ? bestRGBIndexes[px] : bestAlphaIndexes[px]); + } + + for (int ep = 0; ep < 2; ep++) + for (int ch = 0; ch < 4; ch++) + ParallelMath::ConditionalSet(work.m_ep[0][ep][ch], errorBetter16, bestEP[ep][ch]); + } + } + } + } + + template<class T> + static void Swap(T& a, T& b) + { + T temp = a; + a = b; + b = temp; + } + + static void Pack(uint32_t flags, const PixelBlockU8* inputs, uint8_t* packedBlocks, const float channelWeights[4], int numTweakRounds, int numRefineRounds) + { + MUInt15 pixels[16][4]; + MFloat floatPixels[16][4]; + + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < 4; ch++) + ParallelMath::ConvertLDRInputs(inputs, px, ch, pixels[px][ch]); + } + + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < 4; ch++) + floatPixels[px][ch] = ParallelMath::ToFloat(pixels[px][ch]); + } + + WorkInfo work; + memset(&work, 0, sizeof(work)); + + work.m_error = ParallelMath::MakeFloat(FLT_MAX); + + { + ParallelMath::RoundTowardNearestForScope rtn; + TrySinglePlane(flags, pixels, floatPixels, channelWeights, numTweakRounds, numRefineRounds, work, &rtn); + TryDualPlane(flags, pixels, floatPixels, channelWeights, numTweakRounds, numRefineRounds, work, &rtn); + } + + for (int block = 0; block < ParallelMath::ParallelSize; block++) + { + PackingVector pv; + pv.Init(); + + ParallelMath::ScalarUInt16 mode = ParallelMath::Extract(work.m_mode, block); + ParallelMath::ScalarUInt16 partition = ParallelMath::Extract(work.m_u.m_partition, block); + ParallelMath::ScalarUInt16 indexSelector = ParallelMath::Extract(work.m_u.m_isr.m_indexSelector, block); + + const BC7Data::BC7ModeInfo& modeInfo = BC7Data::g_modes[mode]; + + ParallelMath::ScalarUInt16 indexes[16]; + ParallelMath::ScalarUInt16 indexes2[16]; + ParallelMath::ScalarUInt16 endPoints[3][2][4]; + + for (int i = 0; i < 16; i++) + { + indexes[i] = ParallelMath::Extract(work.m_indexes[i], block); + if (modeInfo.m_alphaMode == BC7Data::AlphaMode_Separate) + indexes2[i] = ParallelMath::Extract(work.m_indexes2[i], block); + } + + for (int subset = 0; subset < 3; subset++) + { + for (int ep = 0; ep < 2; ep++) + { + for (int ch = 0; ch < 4; ch++) + endPoints[subset][ep][ch] = ParallelMath::Extract(work.m_ep[subset][ep][ch], block); + } + } + + int fixups[3] = { 0, 0, 0 }; + + if (modeInfo.m_alphaMode == BC7Data::AlphaMode_Separate) + { + bool flipRGB = ((indexes[0] & (1 << (modeInfo.m_indexBits - 1))) != 0); + bool flipAlpha = ((indexes2[0] & (1 << (modeInfo.m_alphaIndexBits - 1))) != 0); + + if (flipRGB) + { + uint16_t highIndex = (1 << modeInfo.m_indexBits) - 1; + for (int px = 0; px < 16; px++) + indexes[px] = highIndex - indexes[px]; + } + + if (flipAlpha) + { + uint16_t highIndex = (1 << modeInfo.m_alphaIndexBits) - 1; + for (int px = 0; px < 16; px++) + indexes2[px] = highIndex - indexes2[px]; + } + + if (indexSelector) + Swap(flipRGB, flipAlpha); + + if (flipRGB) + { + for (int ch = 0; ch < 3; ch++) + Swap(endPoints[0][0][ch], endPoints[0][1][ch]); + } + if (flipAlpha) + Swap(endPoints[0][0][3], endPoints[0][1][3]); + + } + else + { + if (modeInfo.m_numSubsets == 2) + fixups[1] = BC7Data::g_fixupIndexes2[partition]; + else if (modeInfo.m_numSubsets == 3) + { + fixups[1] = BC7Data::g_fixupIndexes3[partition][0]; + fixups[2] = BC7Data::g_fixupIndexes3[partition][1]; + } + + bool flip[3] = { false, false, false }; + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + flip[subset] = ((indexes[fixups[subset]] & (1 << (modeInfo.m_indexBits - 1))) != 0); + + if (flip[0] || flip[1] || flip[2]) + { + uint16_t highIndex = (1 << modeInfo.m_indexBits) - 1; + for (int px = 0; px < 16; px++) + { + int subset = 0; + if (modeInfo.m_numSubsets == 2) + subset = (BC7Data::g_partitionMap[partition] >> px) & 1; + else if (modeInfo.m_numSubsets == 3) + subset = (BC7Data::g_partitionMap2[partition] >> (px * 2)) & 3; + + if (flip[subset]) + indexes[px] = highIndex - indexes[px]; + } + + int maxCH = (modeInfo.m_alphaMode == BC7Data::AlphaMode_Combined) ? 4 : 3; + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + if (flip[subset]) + for (int ch = 0; ch < maxCH; ch++) + Swap(endPoints[subset][0][ch], endPoints[subset][1][ch]); + } + } + } + + pv.Pack(static_cast<uint8_t>(1 << mode), mode + 1); + + if (modeInfo.m_partitionBits) + pv.Pack(partition, modeInfo.m_partitionBits); + + if (modeInfo.m_alphaMode == BC7Data::AlphaMode_Separate) + { + ParallelMath::ScalarUInt16 rotation = ParallelMath::Extract(work.m_u.m_isr.m_rotation, block); + pv.Pack(rotation, 2); + } + + if (modeInfo.m_hasIndexSelector) + pv.Pack(indexSelector, 1); + + // Encode RGB + for (int ch = 0; ch < 3; ch++) + { + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + for (int ep = 0; ep < 2; ep++) + { + ParallelMath::ScalarUInt16 epPart = endPoints[subset][ep][ch]; + epPart >>= (8 - modeInfo.m_rgbBits); + + pv.Pack(epPart, modeInfo.m_rgbBits); + } + } + } + + // Encode alpha + if (modeInfo.m_alphaMode != BC7Data::AlphaMode_None) + { + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + for (int ep = 0; ep < 2; ep++) + { + ParallelMath::ScalarUInt16 epPart = endPoints[subset][ep][3]; + epPart >>= (8 - modeInfo.m_alphaBits); + + pv.Pack(epPart, modeInfo.m_alphaBits); + } + } + } + + // Encode parity bits + if (modeInfo.m_pBitMode == BC7Data::PBitMode_PerSubset) + { + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + ParallelMath::ScalarUInt16 epPart = endPoints[subset][0][0]; + epPart >>= (7 - modeInfo.m_rgbBits); + epPart &= 1; + + pv.Pack(epPart, 1); + } + } + else if (modeInfo.m_pBitMode == BC7Data::PBitMode_PerEndpoint) + { + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + for (int ep = 0; ep < 2; ep++) + { + ParallelMath::ScalarUInt16 epPart = endPoints[subset][ep][0]; + epPart >>= (7 - modeInfo.m_rgbBits); + epPart &= 1; + + pv.Pack(epPart, 1); + } + } + } + + // Encode indexes + for (int px = 0; px < 16; px++) + { + int bits = modeInfo.m_indexBits; + if ((px == 0) || (px == fixups[1]) || (px == fixups[2])) + bits--; + + pv.Pack(indexes[px], bits); + } + + // Encode secondary indexes + if (modeInfo.m_alphaMode == BC7Data::AlphaMode_Separate) + { + for (int px = 0; px < 16; px++) + { + int bits = modeInfo.m_alphaIndexBits; + if (px == 0) + bits--; + + pv.Pack(indexes2[px], bits); + } + } + + pv.Flush(packedBlocks); + + packedBlocks += 16; + } + } + + static void UnpackOne(PixelBlockU8 &output, const uint8_t* packedBlock) + { + UnpackingVector pv; + pv.Init(packedBlock); + + int mode = 8; + for (int i = 0; i < 8; i++) + { + if (pv.Unpack(1) == 1) + { + mode = i; + break; + } + } + + if (mode > 7) + { + for (int px = 0; px < 16; px++) + for (int ch = 0; ch < 4; ch++) + output.m_pixels[px][ch] = 0; + + return; + } + + const BC7Data::BC7ModeInfo &modeInfo = BC7Data::g_modes[mode]; + + int partition = 0; + if (modeInfo.m_partitionBits) + partition = pv.Unpack(modeInfo.m_partitionBits); + + int rotation = 0; + if (modeInfo.m_alphaMode == BC7Data::AlphaMode_Separate) + rotation = pv.Unpack(2); + + int indexSelector = 0; + if (modeInfo.m_hasIndexSelector) + indexSelector = pv.Unpack(1); + + // Resolve fixups + int fixups[3] = { 0, 0, 0 }; + + if (modeInfo.m_alphaMode != BC7Data::AlphaMode_Separate) + { + if (modeInfo.m_numSubsets == 2) + fixups[1] = BC7Data::g_fixupIndexes2[partition]; + else if (modeInfo.m_numSubsets == 3) + { + fixups[1] = BC7Data::g_fixupIndexes3[partition][0]; + fixups[2] = BC7Data::g_fixupIndexes3[partition][1]; + } + } + + int endPoints[3][2][4]; + + // Decode RGB + for (int ch = 0; ch < 3; ch++) + { + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + for (int ep = 0; ep < 2; ep++) + endPoints[subset][ep][ch] = (pv.Unpack(modeInfo.m_rgbBits) << (8 - modeInfo.m_rgbBits)); + } + } + + // Decode alpha + if (modeInfo.m_alphaMode != BC7Data::AlphaMode_None) + { + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + for (int ep = 0; ep < 2; ep++) + endPoints[subset][ep][3] = (pv.Unpack(modeInfo.m_alphaBits) << (8 - modeInfo.m_alphaBits)); + } + } + else + { + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + for (int ep = 0; ep < 2; ep++) + endPoints[subset][ep][3] = 255; + } + } + + int parityBits = 0; + + // Decode parity bits + if (modeInfo.m_pBitMode == BC7Data::PBitMode_PerSubset) + { + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + int p = pv.Unpack(1); + + for (int ep = 0; ep < 2; ep++) + { + for (int ch = 0; ch < 3; ch++) + endPoints[subset][ep][ch] |= p << (7 - modeInfo.m_rgbBits); + + if (modeInfo.m_alphaMode != BC7Data::AlphaMode_None) + endPoints[subset][ep][3] |= p << (7 - modeInfo.m_alphaBits); + } + } + + parityBits = 1; + } + else if (modeInfo.m_pBitMode == BC7Data::PBitMode_PerEndpoint) + { + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + for (int ep = 0; ep < 2; ep++) + { + int p = pv.Unpack(1); + + for (int ch = 0; ch < 3; ch++) + endPoints[subset][ep][ch] |= p << (7 - modeInfo.m_rgbBits); + + if (modeInfo.m_alphaMode != BC7Data::AlphaMode_None) + endPoints[subset][ep][3] |= p << (7 - modeInfo.m_alphaBits); + } + } + + parityBits = 1; + } + + // Fill endpoint bits + for (int subset = 0; subset < modeInfo.m_numSubsets; subset++) + { + for (int ep = 0; ep < 2; ep++) + { + for (int ch = 0; ch < 3; ch++) + endPoints[subset][ep][ch] |= (endPoints[subset][ep][ch] >> (modeInfo.m_rgbBits + parityBits)); + + if (modeInfo.m_alphaMode != BC7Data::AlphaMode_None) + endPoints[subset][ep][3] |= (endPoints[subset][ep][3] >> (modeInfo.m_alphaBits + parityBits)); + } + } + + int indexes[16]; + int indexes2[16]; + + // Decode indexes + for (int px = 0; px < 16; px++) + { + int bits = modeInfo.m_indexBits; + if ((px == 0) || (px == fixups[1]) || (px == fixups[2])) + bits--; + + indexes[px] = pv.Unpack(bits); + } + + // Decode secondary indexes + if (modeInfo.m_alphaMode == BC7Data::AlphaMode_Separate) + { + for (int px = 0; px < 16; px++) + { + int bits = modeInfo.m_alphaIndexBits; + if (px == 0) + bits--; + + indexes2[px] = pv.Unpack(bits); + } + } + else + { + for (int px = 0; px < 16; px++) + indexes2[px] = 0; + } + + const int *alphaWeights = BC7Data::g_weightTables[modeInfo.m_alphaIndexBits]; + const int *rgbWeights = BC7Data::g_weightTables[modeInfo.m_indexBits]; + + // Decode each pixel + for (int px = 0; px < 16; px++) + { + int rgbWeight = 0; + int alphaWeight = 0; + + int rgbIndex = indexes[px]; + + rgbWeight = rgbWeights[indexes[px]]; + + if (modeInfo.m_alphaMode == BC7Data::AlphaMode_Combined) + alphaWeight = rgbWeight; + else if (modeInfo.m_alphaMode == BC7Data::AlphaMode_Separate) + alphaWeight = alphaWeights[indexes2[px]]; + + if (indexSelector == 1) + { + int temp = rgbWeight; + rgbWeight = alphaWeight; + alphaWeight = temp; + } + + int pixel[4] = { 0, 0, 0, 255 }; + + int subset = 0; + + if (modeInfo.m_numSubsets == 2) + subset = (BC7Data::g_partitionMap[partition] >> px) & 1; + else if (modeInfo.m_numSubsets == 3) + subset = (BC7Data::g_partitionMap2[partition] >> (px * 2)) & 3; + + for (int ch = 0; ch < 3; ch++) + pixel[ch] = ((64 - rgbWeight) * endPoints[subset][0][ch] + rgbWeight * endPoints[subset][1][ch] + 32) >> 6; + + if (modeInfo.m_alphaMode != BC7Data::AlphaMode_None) + pixel[3] = ((64 - alphaWeight) * endPoints[subset][0][3] + alphaWeight * endPoints[subset][1][3] + 32) >> 6; + + if (rotation != 0) + { + int ch = rotation - 1; + int temp = pixel[ch]; + pixel[ch] = pixel[3]; + pixel[3] = temp; + } + + for (int ch = 0; ch < 4; ch++) + output.m_pixels[px][ch] = static_cast<uint8_t>(pixel[ch]); + } + } + }; + + class BC6HComputer + { + public: + typedef ParallelMath::Float MFloat; + typedef ParallelMath::SInt16 MSInt16; + typedef ParallelMath::UInt16 MUInt16; + typedef ParallelMath::UInt15 MUInt15; + typedef ParallelMath::AInt16 MAInt16; + typedef ParallelMath::SInt32 MSInt32; + typedef ParallelMath::UInt31 MUInt31; + + static const int MaxTweakRounds = 4; + static const int MaxRefineRounds = 3; + + static MSInt16 QuantizeSingleEndpointElementSigned(const MSInt16 &elem2CL, int precision, const ParallelMath::RoundUpForScope* ru) + { + assert(ParallelMath::AllSet(ParallelMath::Less(elem2CL, ParallelMath::MakeSInt16(31744)))); + assert(ParallelMath::AllSet(ParallelMath::Less(ParallelMath::MakeSInt16(-31744), elem2CL))); + + // Expand to full range + ParallelMath::Int16CompFlag isNegative = ParallelMath::Less(elem2CL, ParallelMath::MakeSInt16(0)); + MUInt15 absElem = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::Select(isNegative, ParallelMath::MakeSInt16(0) - elem2CL, elem2CL)); + + absElem = ParallelMath::RightShift(ParallelMath::RoundAndConvertToU15(ParallelMath::ToFloat(absElem) * 32.0f / 31.0f, ru), 16 - precision); + + MSInt16 absElemS16 = ParallelMath::LosslessCast<MSInt16>::Cast(absElem); + + return ParallelMath::Select(isNegative, ParallelMath::MakeSInt16(0) - absElemS16, absElemS16); + } + + static MUInt15 QuantizeSingleEndpointElementUnsigned(const MUInt15 &elem, int precision, const ParallelMath::RoundUpForScope* ru) + { + MUInt16 expandedElem = ParallelMath::RoundAndConvertToU16(ParallelMath::Min(ParallelMath::ToFloat(elem) * 64.0f / 31.0f, ParallelMath::MakeFloat(65535.0f)), ru); + return ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::RightShift(expandedElem, 16 - precision)); + } + + static void UnquantizeSingleEndpointElementSigned(const MSInt16 &comp, int precision, MSInt16 &outUnquantized, MSInt16 &outUnquantizedFinished2CL) + { + MSInt16 zero = ParallelMath::MakeSInt16(0); + + ParallelMath::Int16CompFlag negative = ParallelMath::Less(comp, zero); + MUInt15 absComp = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::Select(negative, MSInt16(zero - comp), comp)); + + MSInt16 unq; + MUInt15 absUnq; + + if (precision >= 16) + { + unq = comp; + absUnq = absComp; + } + else + { + MSInt16 maxCompMinusOne = ParallelMath::MakeSInt16(static_cast<int16_t>((1 << (precision - 1)) - 2)); + ParallelMath::Int16CompFlag isZero = ParallelMath::Equal(comp, zero); + ParallelMath::Int16CompFlag isMax = ParallelMath::Less(maxCompMinusOne, comp); + + absUnq = (absComp << (16 - precision)) + ParallelMath::MakeUInt15(static_cast<uint16_t>(0x4000 >> (precision - 1))); + ParallelMath::ConditionalSet(absUnq, isZero, ParallelMath::MakeUInt15(0)); + ParallelMath::ConditionalSet(absUnq, isMax, ParallelMath::MakeUInt15(0x7fff)); + + unq = ParallelMath::ConditionalNegate(negative, ParallelMath::LosslessCast<MSInt16>::Cast(absUnq)); + } + + outUnquantized = unq; + + MUInt15 funq = ParallelMath::ToUInt15(ParallelMath::RightShift(ParallelMath::XMultiply(absUnq, ParallelMath::MakeUInt15(31)), 5)); + + outUnquantizedFinished2CL = ParallelMath::ConditionalNegate(negative, ParallelMath::LosslessCast<MSInt16>::Cast(funq)); + } + + static void UnquantizeSingleEndpointElementUnsigned(const MUInt15 &comp, int precision, MUInt16 &outUnquantized, MUInt16 &outUnquantizedFinished) + { + MUInt16 unq = ParallelMath::LosslessCast<MUInt16>::Cast(comp); + if (precision < 15) + { + MUInt15 zero = ParallelMath::MakeUInt15(0); + MUInt15 maxCompMinusOne = ParallelMath::MakeUInt15(static_cast<uint16_t>((1 << precision) - 2)); + + ParallelMath::Int16CompFlag isZero = ParallelMath::Equal(comp, zero); + ParallelMath::Int16CompFlag isMax = ParallelMath::Less(maxCompMinusOne, comp); + + unq = (ParallelMath::LosslessCast<MUInt16>::Cast(comp) << (16 - precision)) + ParallelMath::MakeUInt16(static_cast<uint16_t>(0x8000 >> precision)); + + ParallelMath::ConditionalSet(unq, isZero, ParallelMath::MakeUInt16(0)); + ParallelMath::ConditionalSet(unq, isMax, ParallelMath::MakeUInt16(0xffff)); + } + + outUnquantized = unq; + outUnquantizedFinished = ParallelMath::ToUInt16(ParallelMath::RightShift(ParallelMath::XMultiply(unq, ParallelMath::MakeUInt15(31)), 6)); + } + + static void QuantizeEndpointsSigned(const MSInt16 endPoints[2][3], const MFloat floatPixelsColorSpace[16][3], const MFloat floatPixelsLinearWeighted[16][3], MAInt16 quantizedEndPoints[2][3], MUInt15 indexes[16], IndexSelectorHDR<3> &indexSelector, int fixupIndex, int precision, int indexRange, const float *channelWeights, bool fastIndexing, const ParallelMath::RoundTowardNearestForScope *rtn) + { + MSInt16 unquantizedEP[2][3]; + MSInt16 finishedUnquantizedEP[2][3]; + + { + ParallelMath::RoundUpForScope ru; + + for (int epi = 0; epi < 2; epi++) + { + for (int ch = 0; ch < 3; ch++) + { + MSInt16 qee = QuantizeSingleEndpointElementSigned(endPoints[epi][ch], precision, &ru); + UnquantizeSingleEndpointElementSigned(qee, precision, unquantizedEP[epi][ch], finishedUnquantizedEP[epi][ch]); + quantizedEndPoints[epi][ch] = ParallelMath::LosslessCast<MAInt16>::Cast(qee); + } + } + } + + indexSelector.Init(channelWeights, unquantizedEP, finishedUnquantizedEP, indexRange); + indexSelector.InitHDR(indexRange, true, fastIndexing, channelWeights); + + MUInt15 halfRangeMinusOne = ParallelMath::MakeUInt15(static_cast<uint16_t>(indexRange / 2) - 1); + + MUInt15 index = fastIndexing ? indexSelector.SelectIndexHDRFast(floatPixelsColorSpace[fixupIndex], rtn) : indexSelector.SelectIndexHDRSlow(floatPixelsLinearWeighted[fixupIndex], rtn); + + ParallelMath::Int16CompFlag invert = ParallelMath::Less(halfRangeMinusOne, index); + + if (ParallelMath::AnySet(invert)) + { + ParallelMath::ConditionalSet(index, invert, MUInt15(ParallelMath::MakeUInt15(static_cast<uint16_t>(indexRange - 1)) - index)); + + indexSelector.ConditionalInvert(invert); + + for (int ch = 0; ch < 3; ch++) + { + MAInt16 firstEP = quantizedEndPoints[0][ch]; + MAInt16 secondEP = quantizedEndPoints[1][ch]; + + quantizedEndPoints[0][ch] = ParallelMath::Select(invert, secondEP, firstEP); + quantizedEndPoints[1][ch] = ParallelMath::Select(invert, firstEP, secondEP); + } + } + + indexes[fixupIndex] = index; + } + + static void QuantizeEndpointsUnsigned(const MSInt16 endPoints[2][3], const MFloat floatPixelsColorSpace[16][3], const MFloat floatPixelsLinearWeighted[16][3], MAInt16 quantizedEndPoints[2][3], MUInt15 indexes[16], IndexSelectorHDR<3> &indexSelector, int fixupIndex, int precision, int indexRange, const float *channelWeights, bool fastIndexing, const ParallelMath::RoundTowardNearestForScope *rtn) + { + MUInt16 unquantizedEP[2][3]; + MUInt16 finishedUnquantizedEP[2][3]; + + { + ParallelMath::RoundUpForScope ru; + + for (int epi = 0; epi < 2; epi++) + { + for (int ch = 0; ch < 3; ch++) + { + MUInt15 qee = QuantizeSingleEndpointElementUnsigned(ParallelMath::LosslessCast<MUInt15>::Cast(endPoints[epi][ch]), precision, &ru); + UnquantizeSingleEndpointElementUnsigned(qee, precision, unquantizedEP[epi][ch], finishedUnquantizedEP[epi][ch]); + quantizedEndPoints[epi][ch] = ParallelMath::LosslessCast<MAInt16>::Cast(qee); + } + } + } + + indexSelector.Init(channelWeights, unquantizedEP, finishedUnquantizedEP, indexRange); + indexSelector.InitHDR(indexRange, false, fastIndexing, channelWeights); + + MUInt15 halfRangeMinusOne = ParallelMath::MakeUInt15(static_cast<uint16_t>(indexRange / 2) - 1); + + MUInt15 index = fastIndexing ? indexSelector.SelectIndexHDRFast(floatPixelsColorSpace[fixupIndex], rtn) : indexSelector.SelectIndexHDRSlow(floatPixelsLinearWeighted[fixupIndex], rtn); + + ParallelMath::Int16CompFlag invert = ParallelMath::Less(halfRangeMinusOne, index); + + if (ParallelMath::AnySet(invert)) + { + ParallelMath::ConditionalSet(index, invert, MUInt15(ParallelMath::MakeUInt15(static_cast<uint16_t>(indexRange - 1)) - index)); + + indexSelector.ConditionalInvert(invert); + + for (int ch = 0; ch < 3; ch++) + { + MAInt16 firstEP = quantizedEndPoints[0][ch]; + MAInt16 secondEP = quantizedEndPoints[1][ch]; + + quantizedEndPoints[0][ch] = ParallelMath::Select(invert, secondEP, firstEP); + quantizedEndPoints[1][ch] = ParallelMath::Select(invert, firstEP, secondEP); + } + } + + indexes[fixupIndex] = index; + } + + static void EvaluatePartitionedLegality(const MAInt16 ep0[2][3], const MAInt16 ep1[2][3], int aPrec, const int bPrec[3], bool isTransformed, MAInt16 outEncodedEPs[2][2][3], ParallelMath::Int16CompFlag& outIsLegal) + { + ParallelMath::Int16CompFlag allLegal = ParallelMath::MakeBoolInt16(true); + + MAInt16 aSignificantMask = ParallelMath::MakeAInt16(static_cast<int16_t>((1 << aPrec) - 1)); + + for (int ch = 0; ch < 3; ch++) + { + outEncodedEPs[0][0][ch] = ep0[0][ch]; + outEncodedEPs[0][1][ch] = ep0[1][ch]; + outEncodedEPs[1][0][ch] = ep1[0][ch]; + outEncodedEPs[1][1][ch] = ep1[1][ch]; + + if (isTransformed) + { + for (int subset = 0; subset < 2; subset++) + { + for (int epi = 0; epi < 2; epi++) + { + if (epi == 0 && subset == 0) + continue; + + MAInt16 bReduced = (outEncodedEPs[subset][epi][ch] & aSignificantMask); + + MSInt16 delta = ParallelMath::TruncateToPrecisionSigned(ParallelMath::LosslessCast<MSInt16>::Cast(ParallelMath::AbstractSubtract(outEncodedEPs[subset][epi][ch], outEncodedEPs[0][0][ch])), bPrec[ch]); + + outEncodedEPs[subset][epi][ch] = ParallelMath::LosslessCast<MAInt16>::Cast(delta); + + MAInt16 reconstructed = (ParallelMath::AbstractAdd(outEncodedEPs[subset][epi][ch], outEncodedEPs[0][0][ch]) & aSignificantMask); + allLegal = allLegal & ParallelMath::Equal(reconstructed, bReduced); + } + } + } + + if (!ParallelMath::AnySet(allLegal)) + break; + } + + outIsLegal = allLegal; + } + + static void EvaluateSingleLegality(const MAInt16 ep[2][3], int aPrec, const int bPrec[3], bool isTransformed, MAInt16 outEncodedEPs[2][3], ParallelMath::Int16CompFlag& outIsLegal) + { + ParallelMath::Int16CompFlag allLegal = ParallelMath::MakeBoolInt16(true); + + MAInt16 aSignificantMask = ParallelMath::MakeAInt16(static_cast<int16_t>((1 << aPrec) - 1)); + + for (int ch = 0; ch < 3; ch++) + { + outEncodedEPs[0][ch] = ep[0][ch]; + outEncodedEPs[1][ch] = ep[1][ch]; + + if (isTransformed) + { + MAInt16 bReduced = (outEncodedEPs[1][ch] & aSignificantMask); + + MSInt16 delta = ParallelMath::TruncateToPrecisionSigned(ParallelMath::LosslessCast<MSInt16>::Cast(ParallelMath::AbstractSubtract(outEncodedEPs[1][ch], outEncodedEPs[0][ch])), bPrec[ch]); + + outEncodedEPs[1][ch] = ParallelMath::LosslessCast<MAInt16>::Cast(delta); + + MAInt16 reconstructed = (ParallelMath::AbstractAdd(outEncodedEPs[1][ch], outEncodedEPs[0][ch]) & aSignificantMask); + allLegal = allLegal & ParallelMath::Equal(reconstructed, bReduced); + } + } + + outIsLegal = allLegal; + } + + static void Pack(uint32_t flags, const PixelBlockF16* inputs, uint8_t* packedBlocks, const float channelWeights[4], bool isSigned, int numTweakRounds, int numRefineRounds) + { + if (numTweakRounds < 1) + numTweakRounds = 1; + else if (numTweakRounds > MaxTweakRounds) + numTweakRounds = MaxTweakRounds; + + if (numRefineRounds < 1) + numRefineRounds = 1; + else if (numRefineRounds > MaxRefineRounds) + numRefineRounds = MaxRefineRounds; + + bool fastIndexing = (flags & cvtt::Flags::BC6H_FastIndexing); + float channelWeightsSq[3]; + + ParallelMath::RoundTowardNearestForScope rtn; + + MSInt16 pixels[16][3]; + MFloat floatPixels2CL[16][3]; + MFloat floatPixelsLinearWeighted[16][3]; + + MSInt16 low15Bits = ParallelMath::MakeSInt16(32767); + + for (int ch = 0; ch < 3; ch++) + channelWeightsSq[ch] = channelWeights[ch] * channelWeights[ch]; + + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < 3; ch++) + { + MSInt16 pixelValue; + ParallelMath::ConvertHDRInputs(inputs, px, ch, pixelValue); + + // Convert from sign+magnitude to 2CL + if (isSigned) + { + ParallelMath::Int16CompFlag negative = ParallelMath::Less(pixelValue, ParallelMath::MakeSInt16(0)); + MSInt16 magnitude = (pixelValue & low15Bits); + ParallelMath::ConditionalSet(pixelValue, negative, ParallelMath::MakeSInt16(0) - magnitude); + pixelValue = ParallelMath::Max(pixelValue, ParallelMath::MakeSInt16(-31743)); + } + else + pixelValue = ParallelMath::Max(pixelValue, ParallelMath::MakeSInt16(0)); + + pixelValue = ParallelMath::Min(pixelValue, ParallelMath::MakeSInt16(31743)); + + pixels[px][ch] = pixelValue; + floatPixels2CL[px][ch] = ParallelMath::ToFloat(pixelValue); + floatPixelsLinearWeighted[px][ch] = ParallelMath::TwosCLHalfToFloat(pixelValue) * channelWeights[ch]; + } + } + + MFloat preWeightedPixels[16][3]; + + BCCommon::PreWeightPixelsHDR<3>(preWeightedPixels, pixels, channelWeights); + + MAInt16 bestEndPoints[2][2][3]; + MUInt15 bestIndexes[16]; + MFloat bestError = ParallelMath::MakeFloat(FLT_MAX); + MUInt15 bestMode = ParallelMath::MakeUInt15(0); + MUInt15 bestPartition = ParallelMath::MakeUInt15(0); + + for (int px = 0; px < 16; px++) + bestIndexes[px] = ParallelMath::MakeUInt15(0); + + for (int subset = 0; subset < 2; subset++) + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < 3; ch++) + bestEndPoints[subset][epi][ch] = ParallelMath::MakeAInt16(0); + + UnfinishedEndpoints<3> partitionedUFEP[32][2]; + UnfinishedEndpoints<3> singleUFEP; + + // Generate UFEP for partitions + for (int p = 0; p < 32; p++) + { + int partitionMask = BC7Data::g_partitionMap[p]; + + EndpointSelector<3, 8> epSelectors[2]; + + for (int pass = 0; pass < NumEndpointSelectorPasses; pass++) + { + for (int px = 0; px < 16; px++) + { + int subset = (partitionMask >> px) & 1; + epSelectors[subset].ContributePass(preWeightedPixels[px], pass, ParallelMath::MakeFloat(1.0f)); + } + + for (int subset = 0; subset < 2; subset++) + epSelectors[subset].FinishPass(pass); + } + + for (int subset = 0; subset < 2; subset++) + partitionedUFEP[p][subset] = epSelectors[subset].GetEndpoints(channelWeights); + } + + // Generate UFEP for single + { + EndpointSelector<3, 8> epSelector; + + for (int pass = 0; pass < NumEndpointSelectorPasses; pass++) + { + for (int px = 0; px < 16; px++) + epSelector.ContributePass(preWeightedPixels[px], pass, ParallelMath::MakeFloat(1.0f)); + + epSelector.FinishPass(pass); + } + + singleUFEP = epSelector.GetEndpoints(channelWeights); + } + + for (int partitionedInt = 0; partitionedInt < 2; partitionedInt++) + { + bool partitioned = (partitionedInt == 1); + + for (int aPrec = BC7Data::g_maxHDRPrecision; aPrec >= 0; aPrec--) + { + if (!BC7Data::g_hdrModesExistForPrecision[partitionedInt][aPrec]) + continue; + + int numPartitions = partitioned ? 32 : 1; + int numSubsets = partitioned ? 2 : 1; + int indexBits = partitioned ? 3 : 4; + int indexRange = (1 << indexBits); + + for (int p = 0; p < numPartitions; p++) + { + int partitionMask = partitioned ? BC7Data::g_partitionMap[p] : 0; + + const int MaxMetaRounds = MaxTweakRounds * MaxRefineRounds; + + MAInt16 metaEndPointsQuantized[MaxMetaRounds][2][2][3]; + MUInt15 metaIndexes[MaxMetaRounds][16]; + MFloat metaError[MaxMetaRounds][2]; + + bool roundValid[MaxMetaRounds][2]; + + for (int r = 0; r < MaxMetaRounds; r++) + for (int subset = 0; subset < 2; subset++) + roundValid[r][subset] = true; + + for (int subset = 0; subset < numSubsets; subset++) + { + for (int tweak = 0; tweak < MaxTweakRounds; tweak++) + { + EndpointRefiner<3> refiners[2]; + + bool abortRemainingRefines = false; + for (int refinePass = 0; refinePass < MaxRefineRounds; refinePass++) + { + int metaRound = tweak * MaxRefineRounds + refinePass; + + if (tweak >= numTweakRounds || refinePass >= numRefineRounds) + abortRemainingRefines = true; + + if (abortRemainingRefines) + { + roundValid[metaRound][subset] = false; + continue; + } + + MAInt16(&mrQuantizedEndPoints)[2][2][3] = metaEndPointsQuantized[metaRound]; + MUInt15(&mrIndexes)[16] = metaIndexes[metaRound]; + + MSInt16 endPointsColorSpace[2][3]; + + if (refinePass == 0) + { + UnfinishedEndpoints<3> ufep = partitioned ? partitionedUFEP[p][subset] : singleUFEP; + + if (isSigned) + ufep.FinishHDRSigned(tweak, indexRange, endPointsColorSpace[0], endPointsColorSpace[1], &rtn); + else + ufep.FinishHDRUnsigned(tweak, indexRange, endPointsColorSpace[0], endPointsColorSpace[1], &rtn); + } + else + refiners[subset].GetRefinedEndpointsHDR(endPointsColorSpace, isSigned, &rtn); + + refiners[subset].Init(indexRange, channelWeights); + + int fixupIndex = (subset == 0) ? 0 : BC7Data::g_fixupIndexes2[p]; + + IndexSelectorHDR<3> indexSelector; + if (isSigned) + QuantizeEndpointsSigned(endPointsColorSpace, floatPixels2CL, floatPixelsLinearWeighted, mrQuantizedEndPoints[subset], mrIndexes, indexSelector, fixupIndex, aPrec, indexRange, channelWeights, fastIndexing, &rtn); + else + QuantizeEndpointsUnsigned(endPointsColorSpace, floatPixels2CL, floatPixelsLinearWeighted, mrQuantizedEndPoints[subset], mrIndexes, indexSelector, fixupIndex, aPrec, indexRange, channelWeights, fastIndexing, &rtn); + + if (metaRound > 0) + { + ParallelMath::Int16CompFlag anySame = ParallelMath::MakeBoolInt16(false); + + for (int prevRound = 0; prevRound < metaRound; prevRound++) + { + MAInt16(&prevRoundEPs)[2][3] = metaEndPointsQuantized[prevRound][subset]; + + ParallelMath::Int16CompFlag same = ParallelMath::MakeBoolInt16(true); + + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < 3; ch++) + same = (same & ParallelMath::Equal(prevRoundEPs[epi][ch], mrQuantizedEndPoints[subset][epi][ch])); + + anySame = (anySame | same); + if (ParallelMath::AllSet(anySame)) + break; + } + + if (ParallelMath::AllSet(anySame)) + { + roundValid[metaRound][subset] = false; + continue; + } + } + + MFloat subsetError = ParallelMath::MakeFloatZero(); + + { + for (int px = 0; px < 16; px++) + { + if (subset != ((partitionMask >> px) & 1)) + continue; + + MUInt15 index; + if (px == fixupIndex) + index = mrIndexes[px]; + else + { + index = fastIndexing ? indexSelector.SelectIndexHDRFast(floatPixels2CL[px], &rtn) : indexSelector.SelectIndexHDRSlow(floatPixelsLinearWeighted[px], &rtn); + mrIndexes[px] = index; + } + + MSInt16 reconstructed[3]; + if (isSigned) + indexSelector.ReconstructHDRSigned(mrIndexes[px], reconstructed); + else + indexSelector.ReconstructHDRUnsigned(mrIndexes[px], reconstructed); + + subsetError = subsetError + (fastIndexing ? BCCommon::ComputeErrorHDRFast<3>(flags, reconstructed, pixels[px], channelWeightsSq) : BCCommon::ComputeErrorHDRSlow<3>(flags, reconstructed, pixels[px], channelWeightsSq)); + + if (refinePass != numRefineRounds - 1) + refiners[subset].ContributeUnweightedPW(preWeightedPixels[px], index); + } + } + + metaError[metaRound][subset] = subsetError; + } + } + } + + // Now we have a bunch of attempts, but not all of them will fit in the delta coding scheme + int numMeta1 = partitioned ? MaxMetaRounds : 1; + for (int meta0 = 0; meta0 < MaxMetaRounds; meta0++) + { + if (!roundValid[meta0][0]) + continue; + + for (int meta1 = 0; meta1 < numMeta1; meta1++) + { + MFloat combinedError = metaError[meta0][0]; + if (partitioned) + { + if (!roundValid[meta1][1]) + continue; + + combinedError = combinedError + metaError[meta1][1]; + } + + ParallelMath::FloatCompFlag errorBetter = ParallelMath::Less(combinedError, bestError); + if (!ParallelMath::AnySet(errorBetter)) + continue; + + ParallelMath::Int16CompFlag needsCommit = ParallelMath::FloatFlagToInt16(errorBetter); + + // Figure out if this is encodable + for (int mode = 0; mode < BC7Data::g_numHDRModes; mode++) + { + const BC7Data::BC6HModeInfo &modeInfo = BC7Data::g_hdrModes[mode]; + + if (modeInfo.m_partitioned != partitioned || modeInfo.m_aPrec != aPrec) + continue; + + MAInt16 encodedEPs[2][2][3]; + ParallelMath::Int16CompFlag isLegal; + if (partitioned) + EvaluatePartitionedLegality(metaEndPointsQuantized[meta0][0], metaEndPointsQuantized[meta1][1], modeInfo.m_aPrec, modeInfo.m_bPrec, modeInfo.m_transformed, encodedEPs, isLegal); + else + EvaluateSingleLegality(metaEndPointsQuantized[meta0][0], modeInfo.m_aPrec, modeInfo.m_bPrec, modeInfo.m_transformed, encodedEPs[0], isLegal); + + ParallelMath::Int16CompFlag isLegalAndBetter = (ParallelMath::FloatFlagToInt16(errorBetter) & isLegal); + if (!ParallelMath::AnySet(isLegalAndBetter)) + continue; + + ParallelMath::FloatCompFlag isLegalAndBetterFloat = ParallelMath::Int16FlagToFloat(isLegalAndBetter); + + ParallelMath::ConditionalSet(bestError, isLegalAndBetterFloat, combinedError); + ParallelMath::ConditionalSet(bestMode, isLegalAndBetter, ParallelMath::MakeUInt15(static_cast<uint16_t>(mode))); + ParallelMath::ConditionalSet(bestPartition, isLegalAndBetter, ParallelMath::MakeUInt15(static_cast<uint16_t>(p))); + + for (int subset = 0; subset < numSubsets; subset++) + { + for (int epi = 0; epi < 2; epi++) + { + for (int ch = 0; ch < 3; ch++) + ParallelMath::ConditionalSet(bestEndPoints[subset][epi][ch], isLegalAndBetter, encodedEPs[subset][epi][ch]); + } + } + + for (int px = 0; px < 16; px++) + { + int subset = ((partitionMask >> px) & 1); + if (subset == 0) + ParallelMath::ConditionalSet(bestIndexes[px], isLegalAndBetter, metaIndexes[meta0][px]); + else + ParallelMath::ConditionalSet(bestIndexes[px], isLegalAndBetter, metaIndexes[meta1][px]); + } + + needsCommit = ParallelMath::AndNot(needsCommit, isLegalAndBetter); + if (!ParallelMath::AnySet(needsCommit)) + break; + } + } + } + } + } + } + + // At this point, everything should be set + for (int block = 0; block < ParallelMath::ParallelSize; block++) + { + ParallelMath::ScalarUInt16 mode = ParallelMath::Extract(bestMode, block); + ParallelMath::ScalarUInt16 partition = ParallelMath::Extract(bestPartition, block); + int32_t eps[2][2][3]; + ParallelMath::ScalarUInt16 indexes[16]; + + const BC7Data::BC6HModeInfo& modeInfo = BC7Data::g_hdrModes[mode]; + + const BC6HData::ModeDescriptor* desc = BC6HData::g_modeDescriptors[mode]; + + const size_t headerBits = modeInfo.m_partitioned ? 82 : 65; + + for (int subset = 0; subset < 2; subset++) + { + for (int epi = 0; epi < 2; epi++) + { + for (int ch = 0; ch < 3; ch++) + eps[subset][epi][ch] = ParallelMath::Extract(bestEndPoints[subset][epi][ch], block); + } + } + + for (int px = 0; px < 16; px++) + indexes[px] = ParallelMath::Extract(bestIndexes[px], block); + + uint16_t modeID = modeInfo.m_modeID; + + PackingVector pv; + pv.Init(); + + for (size_t i = 0; i < headerBits; i++) + { + int32_t codedValue = 0; + switch (desc[i].m_eField) + { + case BC6HData::M: codedValue = modeID; break; + case BC6HData::D: codedValue = partition; break; + case BC6HData::RW: codedValue = eps[0][0][0]; break; + case BC6HData::RX: codedValue = eps[0][1][0]; break; + case BC6HData::RY: codedValue = eps[1][0][0]; break; + case BC6HData::RZ: codedValue = eps[1][1][0]; break; + case BC6HData::GW: codedValue = eps[0][0][1]; break; + case BC6HData::GX: codedValue = eps[0][1][1]; break; + case BC6HData::GY: codedValue = eps[1][0][1]; break; + case BC6HData::GZ: codedValue = eps[1][1][1]; break; + case BC6HData::BW: codedValue = eps[0][0][2]; break; + case BC6HData::BX: codedValue = eps[0][1][2]; break; + case BC6HData::BY: codedValue = eps[1][0][2]; break; + case BC6HData::BZ: codedValue = eps[1][1][2]; break; + default: assert(false); break; + } + + pv.Pack(static_cast<uint16_t>((codedValue >> desc[i].m_uBit) & 1), 1); + } + + int fixupIndex1 = 0; + int indexBits = 4; + if (modeInfo.m_partitioned) + { + fixupIndex1 = BC7Data::g_fixupIndexes2[partition]; + indexBits = 3; + } + + for (int px = 0; px < 16; px++) + { + ParallelMath::ScalarUInt16 index = ParallelMath::Extract(bestIndexes[px], block); + if (px == 0 || px == fixupIndex1) + pv.Pack(index, indexBits - 1); + else + pv.Pack(index, indexBits); + } + + pv.Flush(packedBlocks + 16 * block); + } + } + + static void SignExtendSingle(int &v, int bits) + { + if (v & (1 << (bits - 1))) + v |= -(1 << bits); + } + + static void UnpackOne(PixelBlockF16 &output, const uint8_t *pBC, bool isSigned) + { + UnpackingVector pv; + pv.Init(pBC); + + int numModeBits = 2; + int modeBits = pv.Unpack(2); + if (modeBits != 0 && modeBits != 1) + { + modeBits |= pv.Unpack(3) << 2; + numModeBits += 3; + } + + int mode = -1; + for (int possibleMode = 0; possibleMode < BC7Data::g_numHDRModes; possibleMode++) + { + if (BC7Data::g_hdrModes[possibleMode].m_modeID == modeBits) + { + mode = possibleMode; + break; + } + } + + if (mode < 0) + { + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < 3; ch++) + output.m_pixels[px][ch] = 0; + output.m_pixels[px][3] = 0x3c00; // 1.0 + } + return; + } + + const BC7Data::BC6HModeInfo& modeInfo = BC7Data::g_hdrModes[mode]; + const size_t headerBits = modeInfo.m_partitioned ? 82 : 65; + const BC6HData::ModeDescriptor* desc = BC6HData::g_modeDescriptors[mode]; + + int32_t partition = 0; + int32_t eps[2][2][3]; + + for (int subset = 0; subset < 2; subset++) + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < 3; ch++) + eps[subset][epi][ch] = 0; + + for (size_t i = numModeBits; i < headerBits; i++) + { + int32_t *pCodedValue = NULL; + + switch (desc[i].m_eField) + { + case BC6HData::D: pCodedValue = &partition; break; + case BC6HData::RW: pCodedValue = &eps[0][0][0]; break; + case BC6HData::RX: pCodedValue = &eps[0][1][0]; break; + case BC6HData::RY: pCodedValue = &eps[1][0][0]; break; + case BC6HData::RZ: pCodedValue = &eps[1][1][0]; break; + case BC6HData::GW: pCodedValue = &eps[0][0][1]; break; + case BC6HData::GX: pCodedValue = &eps[0][1][1]; break; + case BC6HData::GY: pCodedValue = &eps[1][0][1]; break; + case BC6HData::GZ: pCodedValue = &eps[1][1][1]; break; + case BC6HData::BW: pCodedValue = &eps[0][0][2]; break; + case BC6HData::BX: pCodedValue = &eps[0][1][2]; break; + case BC6HData::BY: pCodedValue = &eps[1][0][2]; break; + case BC6HData::BZ: pCodedValue = &eps[1][1][2]; break; + default: assert(false); break; + } + + (*pCodedValue) |= pv.Unpack(1) << desc[i].m_uBit; + } + + + uint16_t modeID = modeInfo.m_modeID; + + int fixupIndex1 = 0; + int indexBits = 4; + int numSubsets = 1; + if (modeInfo.m_partitioned) + { + fixupIndex1 = BC7Data::g_fixupIndexes2[partition]; + indexBits = 3; + numSubsets = 2; + } + + int indexes[16]; + for (int px = 0; px < 16; px++) + { + if (px == 0 || px == fixupIndex1) + indexes[px] = pv.Unpack(indexBits - 1); + else + indexes[px] = pv.Unpack(indexBits); + } + + if (modeInfo.m_partitioned) + { + for (int ch = 0; ch < 3; ch++) + { + if (isSigned) + SignExtendSingle(eps[0][0][ch], modeInfo.m_aPrec); + if (modeInfo.m_transformed || isSigned) + { + SignExtendSingle(eps[0][1][ch], modeInfo.m_bPrec[ch]); + SignExtendSingle(eps[1][0][ch], modeInfo.m_bPrec[ch]); + SignExtendSingle(eps[1][1][ch], modeInfo.m_bPrec[ch]); + } + } + } + else + { + for (int ch = 0; ch < 3; ch++) + { + if (isSigned) + SignExtendSingle(eps[0][0][ch], modeInfo.m_aPrec); + if (modeInfo.m_transformed || isSigned) + SignExtendSingle(eps[0][1][ch], modeInfo.m_bPrec[ch]); + } + } + + int aPrec = modeInfo.m_aPrec; + + if (modeInfo.m_transformed) + { + for (int ch = 0; ch < 3; ch++) + { + int wrapMask = (1 << aPrec) - 1; + + eps[0][1][ch] = ((eps[0][0][ch] + eps[0][1][ch]) & wrapMask); + if (isSigned) + SignExtendSingle(eps[0][1][ch], aPrec); + + if (modeInfo.m_partitioned) + { + eps[1][0][ch] = ((eps[0][0][ch] + eps[1][0][ch]) & wrapMask); + eps[1][1][ch] = ((eps[0][0][ch] + eps[1][1][ch]) & wrapMask); + + if (isSigned) + { + SignExtendSingle(eps[1][0][ch], aPrec); + SignExtendSingle(eps[1][1][ch], aPrec); + } + } + } + } + + // Unquantize endpoints + for (int subset = 0; subset < numSubsets; subset++) + { + for (int epi = 0; epi < 2; epi++) + { + for (int ch = 0; ch < 3; ch++) + { + int &v = eps[subset][epi][ch]; + + if (isSigned) + { + if (aPrec >= 16) + { + // Nothing + } + else + { + bool s = false; + int comp = v; + if (v < 0) + { + s = true; + comp = -comp; + } + + int unq = 0; + if (comp == 0) + unq = 0; + else if (comp >= ((1 << (aPrec - 1)) - 1)) + unq = 0x7fff; + else + unq = ((comp << 15) + 0x4000) >> (aPrec - 1); + + if (s) + unq = -unq; + + v = unq; + } + } + else + { + if (aPrec >= 15) + { + // Nothing + } + else if (v == 0) + { + // Nothing + } + else if (v == ((1 << aPrec) - 1)) + v = 0xffff; + else + v = ((v << 16) + 0x8000) >> aPrec; + } + } + } + } + + const int *weights = BC7Data::g_weightTables[indexBits]; + + for (int px = 0; px < 16; px++) + { + int subset = 0; + if (modeInfo.m_partitioned) + subset = (BC7Data::g_partitionMap[partition] >> px) & 1; + + int w = weights[indexes[px]]; + for (int ch = 0; ch < 3; ch++) + { + int comp = ((64 - w) * eps[subset][0][ch] + w * eps[subset][1][ch] + 32) >> 6; + + if (isSigned) + { + if (comp < 0) + comp = -(((-comp) * 31) >> 5); + else + comp = (comp * 31) >> 5; + + int s = 0; + if (comp < 0) + { + s = 0x8000; + comp = -comp; + } + + output.m_pixels[px][ch] = static_cast<uint16_t>(s | comp); + } + else + { + comp = (comp * 31) >> 6; + output.m_pixels[px][ch] = static_cast<uint16_t>(comp); + } + } + output.m_pixels[px][3] = 0x3c00; // 1.0 + } + } + }; + + namespace S3TCSingleColorTables + { + struct SingleColorTableEntry + { + uint8_t m_min; + uint8_t m_max; + uint8_t m_actualColor; + uint8_t m_span; + }; + + SingleColorTableEntry g_singleColor5_3[256] = + { + { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 8, 0, 2, 8 }, { 8, 0, 2, 8 }, { 0, 8, 5, 8 }, { 0, 8, 5, 8 }, { 0, 8, 5, 8 }, { 8, 8, 8, 0 }, + { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, { 16, 8, 10, 8 }, { 33, 0, 11, 33 }, { 8, 16, 13, 8 }, { 8, 16, 13, 8 }, { 8, 16, 13, 8 }, { 16, 16, 16, 0 }, + { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, { 24, 16, 18, 8 }, { 41, 8, 19, 33 }, { 16, 24, 21, 8 }, { 16, 24, 21, 8 }, { 0, 33, 22, 33 }, { 24, 24, 24, 0 }, + { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, { 33, 24, 27, 9 }, { 33, 24, 27, 9 }, { 33, 24, 27, 9 }, { 41, 24, 29, 17 }, { 24, 33, 30, 9 }, { 24, 33, 30, 9 }, + { 16, 41, 32, 25 }, { 33, 33, 33, 0 }, { 33, 33, 33, 0 }, { 41, 33, 35, 8 }, { 41, 33, 35, 8 }, { 33, 41, 38, 8 }, { 33, 41, 38, 8 }, { 33, 41, 38, 8 }, + { 24, 49, 40, 25 }, { 41, 41, 41, 0 }, { 41, 41, 41, 0 }, { 49, 41, 43, 8 }, { 66, 33, 44, 33 }, { 41, 49, 46, 8 }, { 41, 49, 46, 8 }, { 41, 49, 46, 8 }, + { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 57, 49, 51, 8 }, { 74, 41, 52, 33 }, { 49, 57, 54, 8 }, { 49, 57, 54, 8 }, { 33, 66, 55, 33 }, + { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 66, 57, 60, 9 }, { 66, 57, 60, 9 }, { 66, 57, 60, 9 }, { 74, 57, 62, 17 }, { 57, 66, 63, 9 }, + { 57, 66, 63, 9 }, { 49, 74, 65, 25 }, { 66, 66, 66, 0 }, { 66, 66, 66, 0 }, { 74, 66, 68, 8 }, { 74, 66, 68, 8 }, { 66, 74, 71, 8 }, { 66, 74, 71, 8 }, + { 66, 74, 71, 8 }, { 57, 82, 73, 25 }, { 74, 74, 74, 0 }, { 74, 74, 74, 0 }, { 82, 74, 76, 8 }, { 99, 66, 77, 33 }, { 74, 82, 79, 8 }, { 74, 82, 79, 8 }, + { 74, 82, 79, 8 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 90, 82, 84, 8 }, { 107, 74, 85, 33 }, { 82, 90, 87, 8 }, { 82, 90, 87, 8 }, + { 66, 99, 88, 33 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 99, 90, 93, 9 }, { 99, 90, 93, 9 }, { 99, 90, 93, 9 }, { 107, 90, 95, 17 }, + { 90, 99, 96, 9 }, { 90, 99, 96, 9 }, { 82, 107, 98, 25 }, { 99, 99, 99, 0 }, { 99, 99, 99, 0 }, { 107, 99, 101, 8 }, { 107, 99, 101, 8 }, { 99, 107, 104, 8 }, + { 99, 107, 104, 8 }, { 99, 107, 104, 8 }, { 90, 115, 106, 25 }, { 107, 107, 107, 0 }, { 107, 107, 107, 0 }, { 115, 107, 109, 8 }, { 132, 99, 110, 33 }, { 107, 115, 112, 8 }, + { 107, 115, 112, 8 }, { 107, 115, 112, 8 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 123, 115, 117, 8 }, { 140, 107, 118, 33 }, { 115, 123, 120, 8 }, + { 115, 123, 120, 8 }, { 99, 132, 121, 33 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 132, 123, 126, 9 }, { 132, 123, 126, 9 }, { 132, 123, 126, 9 }, + { 140, 123, 128, 17 }, { 123, 132, 129, 9 }, { 123, 132, 129, 9 }, { 115, 140, 131, 25 }, { 132, 132, 132, 0 }, { 132, 132, 132, 0 }, { 140, 132, 134, 8 }, { 140, 132, 134, 8 }, + { 132, 140, 137, 8 }, { 132, 140, 137, 8 }, { 132, 140, 137, 8 }, { 123, 148, 139, 25 }, { 140, 140, 140, 0 }, { 140, 140, 140, 0 }, { 148, 140, 142, 8 }, { 165, 132, 143, 33 }, + { 140, 148, 145, 8 }, { 140, 148, 145, 8 }, { 140, 148, 145, 8 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 156, 148, 150, 8 }, { 173, 140, 151, 33 }, + { 148, 156, 153, 8 }, { 148, 156, 153, 8 }, { 132, 165, 154, 33 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 165, 156, 159, 9 }, { 165, 156, 159, 9 }, + { 165, 156, 159, 9 }, { 173, 156, 161, 17 }, { 156, 165, 162, 9 }, { 156, 165, 162, 9 }, { 148, 173, 164, 25 }, { 165, 165, 165, 0 }, { 165, 165, 165, 0 }, { 173, 165, 167, 8 }, + { 173, 165, 167, 8 }, { 165, 173, 170, 8 }, { 165, 173, 170, 8 }, { 165, 173, 170, 8 }, { 156, 181, 172, 25 }, { 173, 173, 173, 0 }, { 173, 173, 173, 0 }, { 181, 173, 175, 8 }, + { 198, 165, 176, 33 }, { 173, 181, 178, 8 }, { 173, 181, 178, 8 }, { 173, 181, 178, 8 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 189, 181, 183, 8 }, + { 206, 173, 184, 33 }, { 181, 189, 186, 8 }, { 181, 189, 186, 8 }, { 165, 198, 187, 33 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 198, 189, 192, 9 }, + { 198, 189, 192, 9 }, { 198, 189, 192, 9 }, { 206, 189, 194, 17 }, { 189, 198, 195, 9 }, { 189, 198, 195, 9 }, { 181, 206, 197, 25 }, { 198, 198, 198, 0 }, { 198, 198, 198, 0 }, + { 206, 198, 200, 8 }, { 206, 198, 200, 8 }, { 198, 206, 203, 8 }, { 198, 206, 203, 8 }, { 198, 206, 203, 8 }, { 189, 214, 205, 25 }, { 206, 206, 206, 0 }, { 206, 206, 206, 0 }, + { 214, 206, 208, 8 }, { 231, 198, 209, 33 }, { 206, 214, 211, 8 }, { 206, 214, 211, 8 }, { 206, 214, 211, 8 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, + { 222, 214, 216, 8 }, { 239, 206, 217, 33 }, { 214, 222, 219, 8 }, { 214, 222, 219, 8 }, { 198, 231, 220, 33 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, + { 231, 222, 225, 9 }, { 231, 222, 225, 9 }, { 231, 222, 225, 9 }, { 239, 222, 227, 17 }, { 222, 231, 228, 9 }, { 222, 231, 228, 9 }, { 214, 239, 230, 25 }, { 231, 231, 231, 0 }, + { 231, 231, 231, 0 }, { 239, 231, 233, 8 }, { 239, 231, 233, 8 }, { 231, 239, 236, 8 }, { 231, 239, 236, 8 }, { 231, 239, 236, 8 }, { 222, 247, 238, 25 }, { 239, 239, 239, 0 }, + { 239, 239, 239, 0 }, { 247, 239, 241, 8 }, { 247, 239, 241, 8 }, { 239, 247, 244, 8 }, { 239, 247, 244, 8 }, { 239, 247, 244, 8 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, + { 247, 247, 247, 0 }, { 255, 247, 249, 8 }, { 255, 247, 249, 8 }, { 247, 255, 252, 8 }, { 247, 255, 252, 8 }, { 247, 255, 252, 8 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, + }; + + SingleColorTableEntry g_singleColor6_3[256] = + { + { 0, 0, 0, 0 }, { 4, 0, 1, 4 }, { 0, 4, 2, 4 }, { 4, 4, 4, 0 }, { 4, 4, 4, 0 }, { 8, 4, 5, 4 }, { 4, 8, 6, 4 }, { 8, 8, 8, 0 }, + { 8, 8, 8, 0 }, { 12, 8, 9, 4 }, { 8, 12, 10, 4 }, { 12, 12, 12, 0 }, { 12, 12, 12, 0 }, { 16, 12, 13, 4 }, { 12, 16, 14, 4 }, { 16, 16, 16, 0 }, + { 16, 16, 16, 0 }, { 20, 16, 17, 4 }, { 16, 20, 18, 4 }, { 20, 20, 20, 0 }, { 20, 20, 20, 0 }, { 24, 20, 21, 4 }, { 20, 24, 22, 4 }, { 69, 0, 23, 69 }, + { 24, 24, 24, 0 }, { 28, 24, 25, 4 }, { 24, 28, 26, 4 }, { 65, 8, 27, 57 }, { 28, 28, 28, 0 }, { 32, 28, 29, 4 }, { 28, 32, 30, 4 }, { 69, 12, 31, 57 }, + { 32, 32, 32, 0 }, { 36, 32, 33, 4 }, { 32, 36, 34, 4 }, { 65, 20, 35, 45 }, { 36, 36, 36, 0 }, { 40, 36, 37, 4 }, { 36, 40, 38, 4 }, { 69, 24, 39, 45 }, + { 40, 40, 40, 0 }, { 44, 40, 41, 4 }, { 40, 44, 42, 4 }, { 65, 32, 43, 33 }, { 44, 44, 44, 0 }, { 48, 44, 45, 4 }, { 44, 48, 46, 4 }, { 69, 36, 47, 33 }, + { 48, 48, 48, 0 }, { 52, 48, 49, 4 }, { 48, 52, 50, 4 }, { 65, 44, 51, 21 }, { 52, 52, 52, 0 }, { 56, 52, 53, 4 }, { 52, 56, 54, 4 }, { 69, 48, 55, 21 }, + { 56, 56, 56, 0 }, { 60, 56, 57, 4 }, { 56, 60, 58, 4 }, { 65, 56, 59, 9 }, { 60, 60, 60, 0 }, { 65, 60, 61, 5 }, { 56, 65, 62, 9 }, { 60, 65, 63, 5 }, + { 56, 69, 64, 13 }, { 65, 65, 65, 0 }, { 69, 65, 66, 4 }, { 65, 69, 67, 4 }, { 60, 73, 68, 13 }, { 69, 69, 69, 0 }, { 73, 69, 70, 4 }, { 69, 73, 71, 4 }, + { 56, 81, 72, 25 }, { 73, 73, 73, 0 }, { 77, 73, 74, 4 }, { 73, 77, 75, 4 }, { 60, 85, 76, 25 }, { 77, 77, 77, 0 }, { 81, 77, 78, 4 }, { 77, 81, 79, 4 }, + { 56, 93, 80, 37 }, { 81, 81, 81, 0 }, { 85, 81, 82, 4 }, { 81, 85, 83, 4 }, { 60, 97, 84, 37 }, { 85, 85, 85, 0 }, { 89, 85, 86, 4 }, { 85, 89, 87, 4 }, + { 56, 105, 88, 49 }, { 89, 89, 89, 0 }, { 93, 89, 90, 4 }, { 89, 93, 91, 4 }, { 60, 109, 92, 49 }, { 93, 93, 93, 0 }, { 97, 93, 94, 4 }, { 93, 97, 95, 4 }, + { 134, 77, 96, 57 }, { 97, 97, 97, 0 }, { 101, 97, 98, 4 }, { 97, 101, 99, 4 }, { 130, 85, 100, 45 }, { 101, 101, 101, 0 }, { 105, 101, 102, 4 }, { 101, 105, 103, 4 }, + { 134, 89, 104, 45 }, { 105, 105, 105, 0 }, { 109, 105, 106, 4 }, { 105, 109, 107, 4 }, { 130, 97, 108, 33 }, { 109, 109, 109, 0 }, { 113, 109, 110, 4 }, { 109, 113, 111, 4 }, + { 134, 101, 112, 33 }, { 113, 113, 113, 0 }, { 117, 113, 114, 4 }, { 113, 117, 115, 4 }, { 130, 109, 116, 21 }, { 117, 117, 117, 0 }, { 121, 117, 118, 4 }, { 117, 121, 119, 4 }, + { 134, 113, 120, 21 }, { 121, 121, 121, 0 }, { 125, 121, 122, 4 }, { 121, 125, 123, 4 }, { 130, 121, 124, 9 }, { 125, 125, 125, 0 }, { 130, 125, 126, 5 }, { 121, 130, 127, 9 }, + { 125, 130, 128, 5 }, { 121, 134, 129, 13 }, { 130, 130, 130, 0 }, { 134, 130, 131, 4 }, { 130, 134, 132, 4 }, { 125, 138, 133, 13 }, { 134, 134, 134, 0 }, { 138, 134, 135, 4 }, + { 134, 138, 136, 4 }, { 121, 146, 137, 25 }, { 138, 138, 138, 0 }, { 142, 138, 139, 4 }, { 138, 142, 140, 4 }, { 125, 150, 141, 25 }, { 142, 142, 142, 0 }, { 146, 142, 143, 4 }, + { 142, 146, 144, 4 }, { 121, 158, 145, 37 }, { 146, 146, 146, 0 }, { 150, 146, 147, 4 }, { 146, 150, 148, 4 }, { 125, 162, 149, 37 }, { 150, 150, 150, 0 }, { 154, 150, 151, 4 }, + { 150, 154, 152, 4 }, { 121, 170, 153, 49 }, { 154, 154, 154, 0 }, { 158, 154, 155, 4 }, { 154, 158, 156, 4 }, { 125, 174, 157, 49 }, { 158, 158, 158, 0 }, { 162, 158, 159, 4 }, + { 158, 162, 160, 4 }, { 199, 142, 161, 57 }, { 162, 162, 162, 0 }, { 166, 162, 163, 4 }, { 162, 166, 164, 4 }, { 195, 150, 165, 45 }, { 166, 166, 166, 0 }, { 170, 166, 167, 4 }, + { 166, 170, 168, 4 }, { 199, 154, 169, 45 }, { 170, 170, 170, 0 }, { 174, 170, 171, 4 }, { 170, 174, 172, 4 }, { 195, 162, 173, 33 }, { 174, 174, 174, 0 }, { 178, 174, 175, 4 }, + { 174, 178, 176, 4 }, { 199, 166, 177, 33 }, { 178, 178, 178, 0 }, { 182, 178, 179, 4 }, { 178, 182, 180, 4 }, { 195, 174, 181, 21 }, { 182, 182, 182, 0 }, { 186, 182, 183, 4 }, + { 182, 186, 184, 4 }, { 199, 178, 185, 21 }, { 186, 186, 186, 0 }, { 190, 186, 187, 4 }, { 186, 190, 188, 4 }, { 195, 186, 189, 9 }, { 190, 190, 190, 0 }, { 195, 190, 191, 5 }, + { 186, 195, 192, 9 }, { 190, 195, 193, 5 }, { 186, 199, 194, 13 }, { 195, 195, 195, 0 }, { 199, 195, 196, 4 }, { 195, 199, 197, 4 }, { 190, 203, 198, 13 }, { 199, 199, 199, 0 }, + { 203, 199, 200, 4 }, { 199, 203, 201, 4 }, { 186, 211, 202, 25 }, { 203, 203, 203, 0 }, { 207, 203, 204, 4 }, { 203, 207, 205, 4 }, { 190, 215, 206, 25 }, { 207, 207, 207, 0 }, + { 211, 207, 208, 4 }, { 207, 211, 209, 4 }, { 186, 223, 210, 37 }, { 211, 211, 211, 0 }, { 215, 211, 212, 4 }, { 211, 215, 213, 4 }, { 190, 227, 214, 37 }, { 215, 215, 215, 0 }, + { 219, 215, 216, 4 }, { 215, 219, 217, 4 }, { 186, 235, 218, 49 }, { 219, 219, 219, 0 }, { 223, 219, 220, 4 }, { 219, 223, 221, 4 }, { 190, 239, 222, 49 }, { 223, 223, 223, 0 }, + { 227, 223, 224, 4 }, { 223, 227, 225, 4 }, { 186, 247, 226, 61 }, { 227, 227, 227, 0 }, { 231, 227, 228, 4 }, { 227, 231, 229, 4 }, { 190, 251, 230, 61 }, { 231, 231, 231, 0 }, + { 235, 231, 232, 4 }, { 231, 235, 233, 4 }, { 235, 235, 235, 0 }, { 235, 235, 235, 0 }, { 239, 235, 236, 4 }, { 235, 239, 237, 4 }, { 239, 239, 239, 0 }, { 239, 239, 239, 0 }, + { 243, 239, 240, 4 }, { 239, 243, 241, 4 }, { 243, 243, 243, 0 }, { 243, 243, 243, 0 }, { 247, 243, 244, 4 }, { 243, 247, 245, 4 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, + { 251, 247, 248, 4 }, { 247, 251, 249, 4 }, { 251, 251, 251, 0 }, { 251, 251, 251, 0 }, { 255, 251, 252, 4 }, { 251, 255, 253, 4 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, + }; + + SingleColorTableEntry g_singleColor5_2[256] = + { + { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 8, 4, 8 }, { 0, 8, 4, 8 }, { 0, 8, 4, 8 }, { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, + { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, { 8, 16, 12, 8 }, { 8, 16, 12, 8 }, { 8, 16, 12, 8 }, { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, + { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, { 16, 24, 20, 8 }, { 16, 24, 20, 8 }, { 16, 24, 20, 8 }, { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, + { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, { 24, 33, 28, 9 }, { 24, 33, 28, 9 }, { 24, 33, 28, 9 }, { 24, 33, 28, 9 }, { 24, 41, 32, 17 }, + { 24, 41, 32, 17 }, { 33, 33, 33, 0 }, { 33, 33, 33, 0 }, { 24, 49, 36, 25 }, { 24, 49, 36, 25 }, { 33, 41, 37, 8 }, { 33, 41, 37, 8 }, { 24, 57, 40, 33 }, + { 24, 57, 40, 33 }, { 41, 41, 41, 0 }, { 41, 41, 41, 0 }, { 41, 41, 41, 0 }, { 41, 49, 45, 8 }, { 41, 49, 45, 8 }, { 41, 49, 45, 8 }, { 49, 49, 49, 0 }, + { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 49, 57, 53, 8 }, { 49, 57, 53, 8 }, { 49, 57, 53, 8 }, { 57, 57, 57, 0 }, + { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 57, 66, 61, 9 }, { 57, 66, 61, 9 }, { 57, 66, 61, 9 }, { 57, 66, 61, 9 }, + { 57, 74, 65, 17 }, { 57, 74, 65, 17 }, { 66, 66, 66, 0 }, { 66, 66, 66, 0 }, { 57, 82, 69, 25 }, { 57, 82, 69, 25 }, { 66, 74, 70, 8 }, { 66, 74, 70, 8 }, + { 57, 90, 73, 33 }, { 57, 90, 73, 33 }, { 74, 74, 74, 0 }, { 74, 74, 74, 0 }, { 74, 74, 74, 0 }, { 74, 82, 78, 8 }, { 74, 82, 78, 8 }, { 74, 82, 78, 8 }, + { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 90, 86, 8 }, { 82, 90, 86, 8 }, { 82, 90, 86, 8 }, + { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 99, 94, 9 }, { 90, 99, 94, 9 }, { 90, 99, 94, 9 }, + { 90, 99, 94, 9 }, { 90, 107, 98, 17 }, { 90, 107, 98, 17 }, { 99, 99, 99, 0 }, { 99, 99, 99, 0 }, { 90, 115, 102, 25 }, { 90, 115, 102, 25 }, { 99, 107, 103, 8 }, + { 99, 107, 103, 8 }, { 90, 123, 106, 33 }, { 90, 123, 106, 33 }, { 107, 107, 107, 0 }, { 107, 107, 107, 0 }, { 107, 107, 107, 0 }, { 107, 115, 111, 8 }, { 107, 115, 111, 8 }, + { 107, 115, 111, 8 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 123, 119, 8 }, { 115, 123, 119, 8 }, + { 115, 123, 119, 8 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 132, 127, 9 }, { 123, 132, 127, 9 }, + { 123, 132, 127, 9 }, { 123, 132, 127, 9 }, { 123, 140, 131, 17 }, { 123, 140, 131, 17 }, { 132, 132, 132, 0 }, { 132, 132, 132, 0 }, { 123, 148, 135, 25 }, { 123, 148, 135, 25 }, + { 132, 140, 136, 8 }, { 132, 140, 136, 8 }, { 123, 156, 139, 33 }, { 123, 156, 139, 33 }, { 140, 140, 140, 0 }, { 140, 140, 140, 0 }, { 140, 140, 140, 0 }, { 140, 148, 144, 8 }, + { 140, 148, 144, 8 }, { 140, 148, 144, 8 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 156, 152, 8 }, + { 148, 156, 152, 8 }, { 148, 156, 152, 8 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 165, 160, 9 }, + { 156, 165, 160, 9 }, { 156, 165, 160, 9 }, { 156, 165, 160, 9 }, { 156, 173, 164, 17 }, { 156, 173, 164, 17 }, { 165, 165, 165, 0 }, { 165, 165, 165, 0 }, { 156, 181, 168, 25 }, + { 156, 181, 168, 25 }, { 165, 173, 169, 8 }, { 165, 173, 169, 8 }, { 156, 189, 172, 33 }, { 156, 189, 172, 33 }, { 173, 173, 173, 0 }, { 173, 173, 173, 0 }, { 173, 173, 173, 0 }, + { 173, 181, 177, 8 }, { 173, 181, 177, 8 }, { 173, 181, 177, 8 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, + { 181, 189, 185, 8 }, { 181, 189, 185, 8 }, { 181, 189, 185, 8 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, + { 189, 198, 193, 9 }, { 189, 198, 193, 9 }, { 189, 198, 193, 9 }, { 189, 198, 193, 9 }, { 189, 206, 197, 17 }, { 189, 206, 197, 17 }, { 198, 198, 198, 0 }, { 198, 198, 198, 0 }, + { 189, 214, 201, 25 }, { 189, 214, 201, 25 }, { 198, 206, 202, 8 }, { 198, 206, 202, 8 }, { 189, 222, 205, 33 }, { 189, 222, 205, 33 }, { 206, 206, 206, 0 }, { 206, 206, 206, 0 }, + { 206, 206, 206, 0 }, { 206, 214, 210, 8 }, { 206, 214, 210, 8 }, { 206, 214, 210, 8 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, + { 214, 214, 214, 0 }, { 214, 222, 218, 8 }, { 214, 222, 218, 8 }, { 214, 222, 218, 8 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, + { 222, 222, 222, 0 }, { 222, 231, 226, 9 }, { 222, 231, 226, 9 }, { 222, 231, 226, 9 }, { 222, 231, 226, 9 }, { 222, 239, 230, 17 }, { 222, 239, 230, 17 }, { 231, 231, 231, 0 }, + { 231, 231, 231, 0 }, { 222, 247, 234, 25 }, { 222, 247, 234, 25 }, { 231, 239, 235, 8 }, { 231, 239, 235, 8 }, { 222, 255, 238, 33 }, { 222, 255, 238, 33 }, { 239, 239, 239, 0 }, + { 239, 239, 239, 0 }, { 239, 239, 239, 0 }, { 239, 247, 243, 8 }, { 239, 247, 243, 8 }, { 239, 247, 243, 8 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, + { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, { 247, 255, 251, 8 }, { 247, 255, 251, 8 }, { 247, 255, 251, 8 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, + }; + + SingleColorTableEntry g_singleColor6_2[256] = + { + { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 4, 2, 4 }, { 4, 4, 4, 0 }, { 4, 4, 4, 0 }, { 4, 4, 4, 0 }, { 4, 8, 6, 4 }, { 8, 8, 8, 0 }, + { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, { 8, 12, 10, 4 }, { 12, 12, 12, 0 }, { 12, 12, 12, 0 }, { 12, 12, 12, 0 }, { 12, 16, 14, 4 }, { 16, 16, 16, 0 }, + { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, { 16, 20, 18, 4 }, { 20, 20, 20, 0 }, { 20, 20, 20, 0 }, { 20, 20, 20, 0 }, { 20, 24, 22, 4 }, { 24, 24, 24, 0 }, + { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, { 24, 28, 26, 4 }, { 28, 28, 28, 0 }, { 28, 28, 28, 0 }, { 28, 28, 28, 0 }, { 28, 32, 30, 4 }, { 32, 32, 32, 0 }, + { 32, 32, 32, 0 }, { 32, 32, 32, 0 }, { 32, 36, 34, 4 }, { 36, 36, 36, 0 }, { 36, 36, 36, 0 }, { 36, 36, 36, 0 }, { 36, 40, 38, 4 }, { 40, 40, 40, 0 }, + { 40, 40, 40, 0 }, { 40, 40, 40, 0 }, { 40, 44, 42, 4 }, { 44, 44, 44, 0 }, { 44, 44, 44, 0 }, { 44, 44, 44, 0 }, { 44, 48, 46, 4 }, { 48, 48, 48, 0 }, + { 48, 48, 48, 0 }, { 48, 48, 48, 0 }, { 48, 52, 50, 4 }, { 52, 52, 52, 0 }, { 52, 52, 52, 0 }, { 52, 52, 52, 0 }, { 52, 56, 54, 4 }, { 56, 56, 56, 0 }, + { 56, 56, 56, 0 }, { 56, 56, 56, 0 }, { 56, 60, 58, 4 }, { 60, 60, 60, 0 }, { 60, 60, 60, 0 }, { 60, 60, 60, 0 }, { 60, 65, 62, 5 }, { 60, 65, 62, 5 }, + { 60, 69, 64, 9 }, { 65, 65, 65, 0 }, { 60, 73, 66, 13 }, { 65, 69, 67, 4 }, { 60, 77, 68, 17 }, { 69, 69, 69, 0 }, { 60, 81, 70, 21 }, { 69, 73, 71, 4 }, + { 60, 85, 72, 25 }, { 73, 73, 73, 0 }, { 60, 89, 74, 29 }, { 73, 77, 75, 4 }, { 60, 93, 76, 33 }, { 77, 77, 77, 0 }, { 60, 97, 78, 37 }, { 77, 81, 79, 4 }, + { 60, 101, 80, 41 }, { 81, 81, 81, 0 }, { 60, 105, 82, 45 }, { 81, 85, 83, 4 }, { 60, 109, 84, 49 }, { 85, 85, 85, 0 }, { 60, 113, 86, 53 }, { 85, 89, 87, 4 }, + { 60, 117, 88, 57 }, { 89, 89, 89, 0 }, { 60, 121, 90, 61 }, { 89, 93, 91, 4 }, { 60, 125, 92, 65 }, { 93, 93, 93, 0 }, { 93, 93, 93, 0 }, { 93, 97, 95, 4 }, + { 97, 97, 97, 0 }, { 97, 97, 97, 0 }, { 97, 97, 97, 0 }, { 97, 101, 99, 4 }, { 101, 101, 101, 0 }, { 101, 101, 101, 0 }, { 101, 101, 101, 0 }, { 101, 105, 103, 4 }, + { 105, 105, 105, 0 }, { 105, 105, 105, 0 }, { 105, 105, 105, 0 }, { 105, 109, 107, 4 }, { 109, 109, 109, 0 }, { 109, 109, 109, 0 }, { 109, 109, 109, 0 }, { 109, 113, 111, 4 }, + { 113, 113, 113, 0 }, { 113, 113, 113, 0 }, { 113, 113, 113, 0 }, { 113, 117, 115, 4 }, { 117, 117, 117, 0 }, { 117, 117, 117, 0 }, { 117, 117, 117, 0 }, { 117, 121, 119, 4 }, + { 121, 121, 121, 0 }, { 121, 121, 121, 0 }, { 121, 121, 121, 0 }, { 121, 125, 123, 4 }, { 125, 125, 125, 0 }, { 125, 125, 125, 0 }, { 125, 125, 125, 0 }, { 125, 130, 127, 5 }, + { 125, 130, 127, 5 }, { 125, 134, 129, 9 }, { 130, 130, 130, 0 }, { 125, 138, 131, 13 }, { 130, 134, 132, 4 }, { 125, 142, 133, 17 }, { 134, 134, 134, 0 }, { 125, 146, 135, 21 }, + { 134, 138, 136, 4 }, { 125, 150, 137, 25 }, { 138, 138, 138, 0 }, { 125, 154, 139, 29 }, { 138, 142, 140, 4 }, { 125, 158, 141, 33 }, { 142, 142, 142, 0 }, { 125, 162, 143, 37 }, + { 142, 146, 144, 4 }, { 125, 166, 145, 41 }, { 146, 146, 146, 0 }, { 125, 170, 147, 45 }, { 146, 150, 148, 4 }, { 125, 174, 149, 49 }, { 150, 150, 150, 0 }, { 125, 178, 151, 53 }, + { 150, 154, 152, 4 }, { 125, 182, 153, 57 }, { 154, 154, 154, 0 }, { 125, 186, 155, 61 }, { 154, 158, 156, 4 }, { 125, 190, 157, 65 }, { 158, 158, 158, 0 }, { 158, 158, 158, 0 }, + { 158, 162, 160, 4 }, { 162, 162, 162, 0 }, { 162, 162, 162, 0 }, { 162, 162, 162, 0 }, { 162, 166, 164, 4 }, { 166, 166, 166, 0 }, { 166, 166, 166, 0 }, { 166, 166, 166, 0 }, + { 166, 170, 168, 4 }, { 170, 170, 170, 0 }, { 170, 170, 170, 0 }, { 170, 170, 170, 0 }, { 170, 174, 172, 4 }, { 174, 174, 174, 0 }, { 174, 174, 174, 0 }, { 174, 174, 174, 0 }, + { 174, 178, 176, 4 }, { 178, 178, 178, 0 }, { 178, 178, 178, 0 }, { 178, 178, 178, 0 }, { 178, 182, 180, 4 }, { 182, 182, 182, 0 }, { 182, 182, 182, 0 }, { 182, 182, 182, 0 }, + { 182, 186, 184, 4 }, { 186, 186, 186, 0 }, { 186, 186, 186, 0 }, { 186, 186, 186, 0 }, { 186, 190, 188, 4 }, { 190, 190, 190, 0 }, { 190, 190, 190, 0 }, { 190, 190, 190, 0 }, + { 190, 195, 192, 5 }, { 190, 195, 192, 5 }, { 190, 199, 194, 9 }, { 195, 195, 195, 0 }, { 190, 203, 196, 13 }, { 195, 199, 197, 4 }, { 190, 207, 198, 17 }, { 199, 199, 199, 0 }, + { 190, 211, 200, 21 }, { 199, 203, 201, 4 }, { 190, 215, 202, 25 }, { 203, 203, 203, 0 }, { 190, 219, 204, 29 }, { 203, 207, 205, 4 }, { 190, 223, 206, 33 }, { 207, 207, 207, 0 }, + { 190, 227, 208, 37 }, { 207, 211, 209, 4 }, { 190, 231, 210, 41 }, { 211, 211, 211, 0 }, { 190, 235, 212, 45 }, { 211, 215, 213, 4 }, { 190, 239, 214, 49 }, { 215, 215, 215, 0 }, + { 190, 243, 216, 53 }, { 215, 219, 217, 4 }, { 190, 247, 218, 57 }, { 219, 219, 219, 0 }, { 190, 251, 220, 61 }, { 219, 223, 221, 4 }, { 190, 255, 222, 65 }, { 223, 223, 223, 0 }, + { 223, 223, 223, 0 }, { 223, 227, 225, 4 }, { 227, 227, 227, 0 }, { 227, 227, 227, 0 }, { 227, 227, 227, 0 }, { 227, 231, 229, 4 }, { 231, 231, 231, 0 }, { 231, 231, 231, 0 }, + { 231, 231, 231, 0 }, { 231, 235, 233, 4 }, { 235, 235, 235, 0 }, { 235, 235, 235, 0 }, { 235, 235, 235, 0 }, { 235, 239, 237, 4 }, { 239, 239, 239, 0 }, { 239, 239, 239, 0 }, + { 239, 239, 239, 0 }, { 239, 243, 241, 4 }, { 243, 243, 243, 0 }, { 243, 243, 243, 0 }, { 243, 243, 243, 0 }, { 243, 247, 245, 4 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, + { 247, 247, 247, 0 }, { 247, 251, 249, 4 }, { 251, 251, 251, 0 }, { 251, 251, 251, 0 }, { 251, 251, 251, 0 }, { 251, 255, 253, 4 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, + }; + + SingleColorTableEntry g_singleColor5_3_p[256] = + { + { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 8, 0, 2, 8 }, { 8, 0, 2, 8 }, { 0, 8, 5, 8 }, { 0, 8, 5, 8 }, { 0, 8, 5, 8 }, { 8, 8, 8, 0 }, + { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, { 16, 8, 10, 8 }, { 33, 0, 11, 33 }, { 8, 16, 13, 8 }, { 8, 16, 13, 8 }, { 8, 16, 13, 8 }, { 16, 16, 16, 0 }, + { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, { 24, 16, 18, 8 }, { 41, 8, 19, 33 }, { 16, 24, 21, 8 }, { 16, 24, 21, 8 }, { 0, 33, 22, 33 }, { 24, 24, 24, 0 }, + { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, { 33, 24, 27, 9 }, { 33, 24, 27, 9 }, { 33, 24, 27, 9 }, { 41, 24, 29, 17 }, { 24, 33, 30, 9 }, { 24, 33, 30, 9 }, + { 16, 41, 32, 25 }, { 33, 33, 33, 0 }, { 33, 33, 33, 0 }, { 41, 33, 35, 8 }, { 41, 33, 35, 8 }, { 33, 41, 38, 8 }, { 33, 41, 38, 8 }, { 33, 41, 38, 8 }, + { 24, 49, 40, 25 }, { 41, 41, 41, 0 }, { 41, 41, 41, 0 }, { 49, 41, 43, 8 }, { 66, 33, 44, 33 }, { 41, 49, 46, 8 }, { 41, 49, 46, 8 }, { 41, 49, 46, 8 }, + { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 57, 49, 51, 8 }, { 74, 41, 52, 33 }, { 49, 57, 54, 8 }, { 49, 57, 54, 8 }, { 33, 66, 55, 33 }, + { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 66, 57, 60, 9 }, { 66, 57, 60, 9 }, { 66, 57, 60, 9 }, { 74, 57, 62, 17 }, { 57, 66, 63, 9 }, + { 57, 66, 63, 9 }, { 49, 74, 65, 25 }, { 66, 66, 66, 0 }, { 66, 66, 66, 0 }, { 74, 66, 68, 8 }, { 74, 66, 68, 8 }, { 66, 74, 71, 8 }, { 66, 74, 71, 8 }, + { 66, 74, 71, 8 }, { 57, 82, 73, 25 }, { 74, 74, 74, 0 }, { 74, 74, 74, 0 }, { 82, 74, 76, 8 }, { 99, 66, 77, 33 }, { 74, 82, 79, 8 }, { 74, 82, 79, 8 }, + { 74, 82, 79, 8 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 90, 82, 84, 8 }, { 107, 74, 85, 33 }, { 82, 90, 87, 8 }, { 82, 90, 87, 8 }, + { 66, 99, 88, 33 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 99, 90, 93, 9 }, { 99, 90, 93, 9 }, { 99, 90, 93, 9 }, { 107, 90, 95, 17 }, + { 90, 99, 96, 9 }, { 90, 99, 96, 9 }, { 82, 107, 98, 25 }, { 99, 99, 99, 0 }, { 99, 99, 99, 0 }, { 107, 99, 101, 8 }, { 107, 99, 101, 8 }, { 99, 107, 104, 8 }, + { 99, 107, 104, 8 }, { 99, 107, 104, 8 }, { 90, 115, 106, 25 }, { 107, 107, 107, 0 }, { 107, 107, 107, 0 }, { 115, 107, 109, 8 }, { 132, 99, 110, 33 }, { 107, 115, 112, 8 }, + { 107, 115, 112, 8 }, { 107, 115, 112, 8 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 123, 115, 117, 8 }, { 140, 107, 118, 33 }, { 115, 123, 120, 8 }, + { 115, 123, 120, 8 }, { 99, 132, 121, 33 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 132, 123, 126, 9 }, { 132, 123, 126, 9 }, { 132, 123, 126, 9 }, + { 140, 123, 128, 17 }, { 123, 132, 129, 9 }, { 123, 132, 129, 9 }, { 115, 140, 131, 25 }, { 132, 132, 132, 0 }, { 132, 132, 132, 0 }, { 140, 132, 134, 8 }, { 140, 132, 134, 8 }, + { 132, 140, 137, 8 }, { 132, 140, 137, 8 }, { 132, 140, 137, 8 }, { 123, 148, 139, 25 }, { 140, 140, 140, 0 }, { 140, 140, 140, 0 }, { 148, 140, 142, 8 }, { 165, 132, 143, 33 }, + { 140, 148, 145, 8 }, { 140, 148, 145, 8 }, { 140, 148, 145, 8 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 156, 148, 150, 8 }, { 173, 140, 151, 33 }, + { 148, 156, 153, 8 }, { 148, 156, 153, 8 }, { 132, 165, 154, 33 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 165, 156, 159, 9 }, { 165, 156, 159, 9 }, + { 165, 156, 159, 9 }, { 173, 156, 161, 17 }, { 156, 165, 162, 9 }, { 156, 165, 162, 9 }, { 148, 173, 164, 25 }, { 165, 165, 165, 0 }, { 165, 165, 165, 0 }, { 173, 165, 167, 8 }, + { 173, 165, 167, 8 }, { 165, 173, 170, 8 }, { 165, 173, 170, 8 }, { 165, 173, 170, 8 }, { 156, 181, 172, 25 }, { 173, 173, 173, 0 }, { 173, 173, 173, 0 }, { 181, 173, 175, 8 }, + { 198, 165, 176, 33 }, { 173, 181, 178, 8 }, { 173, 181, 178, 8 }, { 173, 181, 178, 8 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 189, 181, 183, 8 }, + { 206, 173, 184, 33 }, { 181, 189, 186, 8 }, { 181, 189, 186, 8 }, { 165, 198, 187, 33 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 198, 189, 192, 9 }, + { 198, 189, 192, 9 }, { 198, 189, 192, 9 }, { 206, 189, 194, 17 }, { 189, 198, 195, 9 }, { 189, 198, 195, 9 }, { 181, 206, 197, 25 }, { 198, 198, 198, 0 }, { 198, 198, 198, 0 }, + { 206, 198, 200, 8 }, { 206, 198, 200, 8 }, { 198, 206, 203, 8 }, { 198, 206, 203, 8 }, { 198, 206, 203, 8 }, { 189, 214, 205, 25 }, { 206, 206, 206, 0 }, { 206, 206, 206, 0 }, + { 214, 206, 208, 8 }, { 231, 198, 209, 33 }, { 206, 214, 211, 8 }, { 206, 214, 211, 8 }, { 206, 214, 211, 8 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, + { 222, 214, 216, 8 }, { 239, 206, 217, 33 }, { 214, 222, 219, 8 }, { 214, 222, 219, 8 }, { 198, 231, 220, 33 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, + { 231, 222, 225, 9 }, { 231, 222, 225, 9 }, { 231, 222, 225, 9 }, { 239, 222, 227, 17 }, { 222, 231, 228, 9 }, { 222, 231, 228, 9 }, { 214, 239, 230, 25 }, { 231, 231, 231, 0 }, + { 231, 231, 231, 0 }, { 239, 231, 233, 8 }, { 239, 231, 233, 8 }, { 231, 239, 236, 8 }, { 231, 239, 236, 8 }, { 231, 239, 236, 8 }, { 222, 247, 238, 25 }, { 239, 239, 239, 0 }, + { 239, 239, 239, 0 }, { 247, 239, 241, 8 }, { 247, 239, 241, 8 }, { 239, 247, 244, 8 }, { 239, 247, 244, 8 }, { 239, 247, 244, 8 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, + { 247, 247, 247, 0 }, { 255, 247, 249, 8 }, { 255, 247, 249, 8 }, { 247, 255, 252, 8 }, { 247, 255, 252, 8 }, { 247, 255, 252, 8 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, + }; + + SingleColorTableEntry g_singleColor6_3_p[256] = + { + { 0, 0, 0, 0 }, { 4, 0, 1, 4 }, { 0, 4, 2, 4 }, { 4, 4, 4, 0 }, { 4, 4, 4, 0 }, { 8, 4, 5, 4 }, { 4, 8, 6, 4 }, { 8, 8, 8, 0 }, + { 8, 8, 8, 0 }, { 12, 8, 9, 4 }, { 8, 12, 10, 4 }, { 12, 12, 12, 0 }, { 12, 12, 12, 0 }, { 16, 12, 13, 4 }, { 12, 16, 14, 4 }, { 16, 16, 16, 0 }, + { 16, 16, 16, 0 }, { 20, 16, 17, 4 }, { 16, 20, 18, 4 }, { 20, 20, 20, 0 }, { 20, 20, 20, 0 }, { 24, 20, 21, 4 }, { 20, 24, 22, 4 }, { 24, 24, 24, 0 }, + { 24, 24, 24, 0 }, { 28, 24, 25, 4 }, { 24, 28, 26, 4 }, { 28, 28, 28, 0 }, { 28, 28, 28, 0 }, { 32, 28, 29, 4 }, { 28, 32, 30, 4 }, { 32, 32, 32, 0 }, + { 32, 32, 32, 0 }, { 36, 32, 33, 4 }, { 32, 36, 34, 4 }, { 36, 36, 36, 0 }, { 36, 36, 36, 0 }, { 40, 36, 37, 4 }, { 36, 40, 38, 4 }, { 40, 40, 40, 0 }, + { 40, 40, 40, 0 }, { 44, 40, 41, 4 }, { 40, 44, 42, 4 }, { 65, 32, 43, 33 }, { 44, 44, 44, 0 }, { 48, 44, 45, 4 }, { 44, 48, 46, 4 }, { 69, 36, 47, 33 }, + { 48, 48, 48, 0 }, { 52, 48, 49, 4 }, { 48, 52, 50, 4 }, { 65, 44, 51, 21 }, { 52, 52, 52, 0 }, { 56, 52, 53, 4 }, { 52, 56, 54, 4 }, { 69, 48, 55, 21 }, + { 56, 56, 56, 0 }, { 60, 56, 57, 4 }, { 56, 60, 58, 4 }, { 65, 56, 59, 9 }, { 60, 60, 60, 0 }, { 65, 60, 61, 5 }, { 56, 65, 62, 9 }, { 60, 65, 63, 5 }, + { 56, 69, 64, 13 }, { 65, 65, 65, 0 }, { 69, 65, 66, 4 }, { 65, 69, 67, 4 }, { 60, 73, 68, 13 }, { 69, 69, 69, 0 }, { 73, 69, 70, 4 }, { 69, 73, 71, 4 }, + { 56, 81, 72, 25 }, { 73, 73, 73, 0 }, { 77, 73, 74, 4 }, { 73, 77, 75, 4 }, { 60, 85, 76, 25 }, { 77, 77, 77, 0 }, { 81, 77, 78, 4 }, { 77, 81, 79, 4 }, + { 81, 81, 81, 0 }, { 81, 81, 81, 0 }, { 85, 81, 82, 4 }, { 81, 85, 83, 4 }, { 85, 85, 85, 0 }, { 85, 85, 85, 0 }, { 89, 85, 86, 4 }, { 85, 89, 87, 4 }, + { 89, 89, 89, 0 }, { 89, 89, 89, 0 }, { 93, 89, 90, 4 }, { 89, 93, 91, 4 }, { 93, 93, 93, 0 }, { 93, 93, 93, 0 }, { 97, 93, 94, 4 }, { 93, 97, 95, 4 }, + { 97, 97, 97, 0 }, { 97, 97, 97, 0 }, { 101, 97, 98, 4 }, { 97, 101, 99, 4 }, { 101, 101, 101, 0 }, { 101, 101, 101, 0 }, { 105, 101, 102, 4 }, { 101, 105, 103, 4 }, + { 105, 105, 105, 0 }, { 105, 105, 105, 0 }, { 109, 105, 106, 4 }, { 105, 109, 107, 4 }, { 130, 97, 108, 33 }, { 109, 109, 109, 0 }, { 113, 109, 110, 4 }, { 109, 113, 111, 4 }, + { 134, 101, 112, 33 }, { 113, 113, 113, 0 }, { 117, 113, 114, 4 }, { 113, 117, 115, 4 }, { 130, 109, 116, 21 }, { 117, 117, 117, 0 }, { 121, 117, 118, 4 }, { 117, 121, 119, 4 }, + { 134, 113, 120, 21 }, { 121, 121, 121, 0 }, { 125, 121, 122, 4 }, { 121, 125, 123, 4 }, { 130, 121, 124, 9 }, { 125, 125, 125, 0 }, { 130, 125, 126, 5 }, { 121, 130, 127, 9 }, + { 125, 130, 128, 5 }, { 121, 134, 129, 13 }, { 130, 130, 130, 0 }, { 134, 130, 131, 4 }, { 130, 134, 132, 4 }, { 125, 138, 133, 13 }, { 134, 134, 134, 0 }, { 138, 134, 135, 4 }, + { 134, 138, 136, 4 }, { 121, 146, 137, 25 }, { 138, 138, 138, 0 }, { 142, 138, 139, 4 }, { 138, 142, 140, 4 }, { 125, 150, 141, 25 }, { 142, 142, 142, 0 }, { 146, 142, 143, 4 }, + { 142, 146, 144, 4 }, { 146, 146, 146, 0 }, { 146, 146, 146, 0 }, { 150, 146, 147, 4 }, { 146, 150, 148, 4 }, { 150, 150, 150, 0 }, { 150, 150, 150, 0 }, { 154, 150, 151, 4 }, + { 150, 154, 152, 4 }, { 154, 154, 154, 0 }, { 154, 154, 154, 0 }, { 158, 154, 155, 4 }, { 154, 158, 156, 4 }, { 158, 158, 158, 0 }, { 158, 158, 158, 0 }, { 162, 158, 159, 4 }, + { 158, 162, 160, 4 }, { 162, 162, 162, 0 }, { 162, 162, 162, 0 }, { 166, 162, 163, 4 }, { 162, 166, 164, 4 }, { 166, 166, 166, 0 }, { 166, 166, 166, 0 }, { 170, 166, 167, 4 }, + { 166, 170, 168, 4 }, { 170, 170, 170, 0 }, { 170, 170, 170, 0 }, { 174, 170, 171, 4 }, { 170, 174, 172, 4 }, { 195, 162, 173, 33 }, { 174, 174, 174, 0 }, { 178, 174, 175, 4 }, + { 174, 178, 176, 4 }, { 199, 166, 177, 33 }, { 178, 178, 178, 0 }, { 182, 178, 179, 4 }, { 178, 182, 180, 4 }, { 195, 174, 181, 21 }, { 182, 182, 182, 0 }, { 186, 182, 183, 4 }, + { 182, 186, 184, 4 }, { 199, 178, 185, 21 }, { 186, 186, 186, 0 }, { 190, 186, 187, 4 }, { 186, 190, 188, 4 }, { 195, 186, 189, 9 }, { 190, 190, 190, 0 }, { 195, 190, 191, 5 }, + { 186, 195, 192, 9 }, { 190, 195, 193, 5 }, { 186, 199, 194, 13 }, { 195, 195, 195, 0 }, { 199, 195, 196, 4 }, { 195, 199, 197, 4 }, { 190, 203, 198, 13 }, { 199, 199, 199, 0 }, + { 203, 199, 200, 4 }, { 199, 203, 201, 4 }, { 186, 211, 202, 25 }, { 203, 203, 203, 0 }, { 207, 203, 204, 4 }, { 203, 207, 205, 4 }, { 190, 215, 206, 25 }, { 207, 207, 207, 0 }, + { 211, 207, 208, 4 }, { 207, 211, 209, 4 }, { 211, 211, 211, 0 }, { 211, 211, 211, 0 }, { 215, 211, 212, 4 }, { 211, 215, 213, 4 }, { 215, 215, 215, 0 }, { 215, 215, 215, 0 }, + { 219, 215, 216, 4 }, { 215, 219, 217, 4 }, { 219, 219, 219, 0 }, { 219, 219, 219, 0 }, { 223, 219, 220, 4 }, { 219, 223, 221, 4 }, { 223, 223, 223, 0 }, { 223, 223, 223, 0 }, + { 227, 223, 224, 4 }, { 223, 227, 225, 4 }, { 227, 227, 227, 0 }, { 227, 227, 227, 0 }, { 231, 227, 228, 4 }, { 227, 231, 229, 4 }, { 231, 231, 231, 0 }, { 231, 231, 231, 0 }, + { 235, 231, 232, 4 }, { 231, 235, 233, 4 }, { 235, 235, 235, 0 }, { 235, 235, 235, 0 }, { 239, 235, 236, 4 }, { 235, 239, 237, 4 }, { 239, 239, 239, 0 }, { 239, 239, 239, 0 }, + { 243, 239, 240, 4 }, { 239, 243, 241, 4 }, { 243, 243, 243, 0 }, { 243, 243, 243, 0 }, { 247, 243, 244, 4 }, { 243, 247, 245, 4 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, + { 251, 247, 248, 4 }, { 247, 251, 249, 4 }, { 251, 251, 251, 0 }, { 251, 251, 251, 0 }, { 255, 251, 252, 4 }, { 251, 255, 253, 4 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, + }; + + SingleColorTableEntry g_singleColor5_2_p[256] = + { + { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 8, 4, 8 }, { 0, 8, 4, 8 }, { 0, 8, 4, 8 }, { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, + { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, { 8, 16, 12, 8 }, { 8, 16, 12, 8 }, { 8, 16, 12, 8 }, { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, + { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, { 16, 24, 20, 8 }, { 16, 24, 20, 8 }, { 16, 24, 20, 8 }, { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, + { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, { 24, 33, 28, 9 }, { 24, 33, 28, 9 }, { 24, 33, 28, 9 }, { 24, 33, 28, 9 }, { 24, 41, 32, 17 }, + { 24, 41, 32, 17 }, { 33, 33, 33, 0 }, { 33, 33, 33, 0 }, { 24, 49, 36, 25 }, { 24, 49, 36, 25 }, { 33, 41, 37, 8 }, { 33, 41, 37, 8 }, { 24, 57, 40, 33 }, + { 24, 57, 40, 33 }, { 41, 41, 41, 0 }, { 41, 41, 41, 0 }, { 41, 41, 41, 0 }, { 41, 49, 45, 8 }, { 41, 49, 45, 8 }, { 41, 49, 45, 8 }, { 49, 49, 49, 0 }, + { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 49, 49, 49, 0 }, { 49, 57, 53, 8 }, { 49, 57, 53, 8 }, { 49, 57, 53, 8 }, { 57, 57, 57, 0 }, + { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 57, 57, 57, 0 }, { 57, 66, 61, 9 }, { 57, 66, 61, 9 }, { 57, 66, 61, 9 }, { 57, 66, 61, 9 }, + { 57, 74, 65, 17 }, { 57, 74, 65, 17 }, { 66, 66, 66, 0 }, { 66, 66, 66, 0 }, { 57, 82, 69, 25 }, { 57, 82, 69, 25 }, { 66, 74, 70, 8 }, { 66, 74, 70, 8 }, + { 57, 90, 73, 33 }, { 57, 90, 73, 33 }, { 74, 74, 74, 0 }, { 74, 74, 74, 0 }, { 74, 74, 74, 0 }, { 74, 82, 78, 8 }, { 74, 82, 78, 8 }, { 74, 82, 78, 8 }, + { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 82, 82, 0 }, { 82, 90, 86, 8 }, { 82, 90, 86, 8 }, { 82, 90, 86, 8 }, + { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 90, 90, 0 }, { 90, 99, 94, 9 }, { 90, 99, 94, 9 }, { 90, 99, 94, 9 }, + { 90, 99, 94, 9 }, { 90, 107, 98, 17 }, { 90, 107, 98, 17 }, { 99, 99, 99, 0 }, { 99, 99, 99, 0 }, { 90, 115, 102, 25 }, { 90, 115, 102, 25 }, { 99, 107, 103, 8 }, + { 99, 107, 103, 8 }, { 90, 123, 106, 33 }, { 90, 123, 106, 33 }, { 107, 107, 107, 0 }, { 107, 107, 107, 0 }, { 107, 107, 107, 0 }, { 107, 115, 111, 8 }, { 107, 115, 111, 8 }, + { 107, 115, 111, 8 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 115, 115, 0 }, { 115, 123, 119, 8 }, { 115, 123, 119, 8 }, + { 115, 123, 119, 8 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 123, 123, 0 }, { 123, 132, 127, 9 }, { 123, 132, 127, 9 }, + { 123, 132, 127, 9 }, { 123, 132, 127, 9 }, { 123, 140, 131, 17 }, { 123, 140, 131, 17 }, { 132, 132, 132, 0 }, { 132, 132, 132, 0 }, { 123, 148, 135, 25 }, { 123, 148, 135, 25 }, + { 132, 140, 136, 8 }, { 132, 140, 136, 8 }, { 123, 156, 139, 33 }, { 123, 156, 139, 33 }, { 140, 140, 140, 0 }, { 140, 140, 140, 0 }, { 140, 140, 140, 0 }, { 140, 148, 144, 8 }, + { 140, 148, 144, 8 }, { 140, 148, 144, 8 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 148, 148, 0 }, { 148, 156, 152, 8 }, + { 148, 156, 152, 8 }, { 148, 156, 152, 8 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 156, 156, 0 }, { 156, 165, 160, 9 }, + { 156, 165, 160, 9 }, { 156, 165, 160, 9 }, { 156, 165, 160, 9 }, { 156, 173, 164, 17 }, { 156, 173, 164, 17 }, { 165, 165, 165, 0 }, { 165, 165, 165, 0 }, { 156, 181, 168, 25 }, + { 156, 181, 168, 25 }, { 165, 173, 169, 8 }, { 165, 173, 169, 8 }, { 156, 189, 172, 33 }, { 156, 189, 172, 33 }, { 173, 173, 173, 0 }, { 173, 173, 173, 0 }, { 173, 173, 173, 0 }, + { 173, 181, 177, 8 }, { 173, 181, 177, 8 }, { 173, 181, 177, 8 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, { 181, 181, 181, 0 }, + { 181, 189, 185, 8 }, { 181, 189, 185, 8 }, { 181, 189, 185, 8 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, { 189, 189, 189, 0 }, + { 189, 198, 193, 9 }, { 189, 198, 193, 9 }, { 189, 198, 193, 9 }, { 189, 198, 193, 9 }, { 189, 206, 197, 17 }, { 189, 206, 197, 17 }, { 198, 198, 198, 0 }, { 198, 198, 198, 0 }, + { 189, 214, 201, 25 }, { 189, 214, 201, 25 }, { 198, 206, 202, 8 }, { 198, 206, 202, 8 }, { 189, 222, 205, 33 }, { 189, 222, 205, 33 }, { 206, 206, 206, 0 }, { 206, 206, 206, 0 }, + { 206, 206, 206, 0 }, { 206, 214, 210, 8 }, { 206, 214, 210, 8 }, { 206, 214, 210, 8 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, { 214, 214, 214, 0 }, + { 214, 214, 214, 0 }, { 214, 222, 218, 8 }, { 214, 222, 218, 8 }, { 214, 222, 218, 8 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, { 222, 222, 222, 0 }, + { 222, 222, 222, 0 }, { 222, 231, 226, 9 }, { 222, 231, 226, 9 }, { 222, 231, 226, 9 }, { 222, 231, 226, 9 }, { 222, 239, 230, 17 }, { 222, 239, 230, 17 }, { 231, 231, 231, 0 }, + { 231, 231, 231, 0 }, { 222, 247, 234, 25 }, { 222, 247, 234, 25 }, { 231, 239, 235, 8 }, { 231, 239, 235, 8 }, { 222, 255, 238, 33 }, { 222, 255, 238, 33 }, { 239, 239, 239, 0 }, + { 239, 239, 239, 0 }, { 239, 239, 239, 0 }, { 239, 247, 243, 8 }, { 239, 247, 243, 8 }, { 239, 247, 243, 8 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, + { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, { 247, 255, 251, 8 }, { 247, 255, 251, 8 }, { 247, 255, 251, 8 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, + }; + + SingleColorTableEntry g_singleColor6_2_p[256] = + { + { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 4, 2, 4 }, { 4, 4, 4, 0 }, { 4, 4, 4, 0 }, { 4, 4, 4, 0 }, { 4, 8, 6, 4 }, { 8, 8, 8, 0 }, + { 8, 8, 8, 0 }, { 8, 8, 8, 0 }, { 8, 12, 10, 4 }, { 12, 12, 12, 0 }, { 12, 12, 12, 0 }, { 12, 12, 12, 0 }, { 12, 16, 14, 4 }, { 16, 16, 16, 0 }, + { 16, 16, 16, 0 }, { 16, 16, 16, 0 }, { 16, 20, 18, 4 }, { 20, 20, 20, 0 }, { 20, 20, 20, 0 }, { 20, 20, 20, 0 }, { 20, 24, 22, 4 }, { 24, 24, 24, 0 }, + { 24, 24, 24, 0 }, { 24, 24, 24, 0 }, { 24, 28, 26, 4 }, { 28, 28, 28, 0 }, { 28, 28, 28, 0 }, { 28, 28, 28, 0 }, { 28, 32, 30, 4 }, { 32, 32, 32, 0 }, + { 32, 32, 32, 0 }, { 32, 32, 32, 0 }, { 32, 36, 34, 4 }, { 36, 36, 36, 0 }, { 36, 36, 36, 0 }, { 36, 36, 36, 0 }, { 36, 40, 38, 4 }, { 40, 40, 40, 0 }, + { 40, 40, 40, 0 }, { 40, 40, 40, 0 }, { 40, 44, 42, 4 }, { 44, 44, 44, 0 }, { 44, 44, 44, 0 }, { 44, 44, 44, 0 }, { 44, 48, 46, 4 }, { 48, 48, 48, 0 }, + { 48, 48, 48, 0 }, { 48, 48, 48, 0 }, { 48, 52, 50, 4 }, { 52, 52, 52, 0 }, { 52, 52, 52, 0 }, { 52, 52, 52, 0 }, { 52, 56, 54, 4 }, { 56, 56, 56, 0 }, + { 56, 56, 56, 0 }, { 56, 56, 56, 0 }, { 56, 60, 58, 4 }, { 60, 60, 60, 0 }, { 60, 60, 60, 0 }, { 60, 60, 60, 0 }, { 60, 65, 62, 5 }, { 60, 65, 62, 5 }, + { 60, 69, 64, 9 }, { 65, 65, 65, 0 }, { 60, 73, 66, 13 }, { 65, 69, 67, 4 }, { 60, 77, 68, 17 }, { 69, 69, 69, 0 }, { 60, 81, 70, 21 }, { 69, 73, 71, 4 }, + { 60, 85, 72, 25 }, { 73, 73, 73, 0 }, { 60, 89, 74, 29 }, { 73, 77, 75, 4 }, { 60, 93, 76, 33 }, { 77, 77, 77, 0 }, { 77, 77, 77, 0 }, { 77, 81, 79, 4 }, + { 81, 81, 81, 0 }, { 81, 81, 81, 0 }, { 81, 81, 81, 0 }, { 81, 85, 83, 4 }, { 85, 85, 85, 0 }, { 85, 85, 85, 0 }, { 85, 85, 85, 0 }, { 85, 89, 87, 4 }, + { 89, 89, 89, 0 }, { 89, 89, 89, 0 }, { 89, 89, 89, 0 }, { 89, 93, 91, 4 }, { 93, 93, 93, 0 }, { 93, 93, 93, 0 }, { 93, 93, 93, 0 }, { 93, 97, 95, 4 }, + { 97, 97, 97, 0 }, { 97, 97, 97, 0 }, { 97, 97, 97, 0 }, { 97, 101, 99, 4 }, { 101, 101, 101, 0 }, { 101, 101, 101, 0 }, { 101, 101, 101, 0 }, { 101, 105, 103, 4 }, + { 105, 105, 105, 0 }, { 105, 105, 105, 0 }, { 105, 105, 105, 0 }, { 105, 109, 107, 4 }, { 109, 109, 109, 0 }, { 109, 109, 109, 0 }, { 109, 109, 109, 0 }, { 109, 113, 111, 4 }, + { 113, 113, 113, 0 }, { 113, 113, 113, 0 }, { 113, 113, 113, 0 }, { 113, 117, 115, 4 }, { 117, 117, 117, 0 }, { 117, 117, 117, 0 }, { 117, 117, 117, 0 }, { 117, 121, 119, 4 }, + { 121, 121, 121, 0 }, { 121, 121, 121, 0 }, { 121, 121, 121, 0 }, { 121, 125, 123, 4 }, { 125, 125, 125, 0 }, { 125, 125, 125, 0 }, { 125, 125, 125, 0 }, { 125, 130, 127, 5 }, + { 125, 130, 127, 5 }, { 125, 134, 129, 9 }, { 130, 130, 130, 0 }, { 125, 138, 131, 13 }, { 130, 134, 132, 4 }, { 125, 142, 133, 17 }, { 134, 134, 134, 0 }, { 125, 146, 135, 21 }, + { 134, 138, 136, 4 }, { 125, 150, 137, 25 }, { 138, 138, 138, 0 }, { 125, 154, 139, 29 }, { 138, 142, 140, 4 }, { 125, 158, 141, 33 }, { 142, 142, 142, 0 }, { 142, 142, 142, 0 }, + { 142, 146, 144, 4 }, { 146, 146, 146, 0 }, { 146, 146, 146, 0 }, { 146, 146, 146, 0 }, { 146, 150, 148, 4 }, { 150, 150, 150, 0 }, { 150, 150, 150, 0 }, { 150, 150, 150, 0 }, + { 150, 154, 152, 4 }, { 154, 154, 154, 0 }, { 154, 154, 154, 0 }, { 154, 154, 154, 0 }, { 154, 158, 156, 4 }, { 158, 158, 158, 0 }, { 158, 158, 158, 0 }, { 158, 158, 158, 0 }, + { 158, 162, 160, 4 }, { 162, 162, 162, 0 }, { 162, 162, 162, 0 }, { 162, 162, 162, 0 }, { 162, 166, 164, 4 }, { 166, 166, 166, 0 }, { 166, 166, 166, 0 }, { 166, 166, 166, 0 }, + { 166, 170, 168, 4 }, { 170, 170, 170, 0 }, { 170, 170, 170, 0 }, { 170, 170, 170, 0 }, { 170, 174, 172, 4 }, { 174, 174, 174, 0 }, { 174, 174, 174, 0 }, { 174, 174, 174, 0 }, + { 174, 178, 176, 4 }, { 178, 178, 178, 0 }, { 178, 178, 178, 0 }, { 178, 178, 178, 0 }, { 178, 182, 180, 4 }, { 182, 182, 182, 0 }, { 182, 182, 182, 0 }, { 182, 182, 182, 0 }, + { 182, 186, 184, 4 }, { 186, 186, 186, 0 }, { 186, 186, 186, 0 }, { 186, 186, 186, 0 }, { 186, 190, 188, 4 }, { 190, 190, 190, 0 }, { 190, 190, 190, 0 }, { 190, 190, 190, 0 }, + { 190, 195, 192, 5 }, { 190, 195, 192, 5 }, { 190, 199, 194, 9 }, { 195, 195, 195, 0 }, { 190, 203, 196, 13 }, { 195, 199, 197, 4 }, { 190, 207, 198, 17 }, { 199, 199, 199, 0 }, + { 190, 211, 200, 21 }, { 199, 203, 201, 4 }, { 190, 215, 202, 25 }, { 203, 203, 203, 0 }, { 190, 219, 204, 29 }, { 203, 207, 205, 4 }, { 190, 223, 206, 33 }, { 207, 207, 207, 0 }, + { 207, 207, 207, 0 }, { 207, 211, 209, 4 }, { 211, 211, 211, 0 }, { 211, 211, 211, 0 }, { 211, 211, 211, 0 }, { 211, 215, 213, 4 }, { 215, 215, 215, 0 }, { 215, 215, 215, 0 }, + { 215, 215, 215, 0 }, { 215, 219, 217, 4 }, { 219, 219, 219, 0 }, { 219, 219, 219, 0 }, { 219, 219, 219, 0 }, { 219, 223, 221, 4 }, { 223, 223, 223, 0 }, { 223, 223, 223, 0 }, + { 223, 223, 223, 0 }, { 223, 227, 225, 4 }, { 227, 227, 227, 0 }, { 227, 227, 227, 0 }, { 227, 227, 227, 0 }, { 227, 231, 229, 4 }, { 231, 231, 231, 0 }, { 231, 231, 231, 0 }, + { 231, 231, 231, 0 }, { 231, 235, 233, 4 }, { 235, 235, 235, 0 }, { 235, 235, 235, 0 }, { 235, 235, 235, 0 }, { 235, 239, 237, 4 }, { 239, 239, 239, 0 }, { 239, 239, 239, 0 }, + { 239, 239, 239, 0 }, { 239, 243, 241, 4 }, { 243, 243, 243, 0 }, { 243, 243, 243, 0 }, { 243, 243, 243, 0 }, { 243, 247, 245, 4 }, { 247, 247, 247, 0 }, { 247, 247, 247, 0 }, + { 247, 247, 247, 0 }, { 247, 251, 249, 4 }, { 251, 251, 251, 0 }, { 251, 251, 251, 0 }, { 251, 251, 251, 0 }, { 251, 255, 253, 4 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, + }; + } + + class S3TCComputer + { + public: + typedef ParallelMath::Float MFloat; + typedef ParallelMath::SInt16 MSInt16; + typedef ParallelMath::UInt15 MUInt15; + typedef ParallelMath::UInt16 MUInt16; + typedef ParallelMath::SInt32 MSInt32; + + static void Init(MFloat& error) + { + error = ParallelMath::MakeFloat(FLT_MAX); + } + + static void QuantizeTo6Bits(MUInt15& v) + { + MUInt15 reduced = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::RightShift(ParallelMath::CompactMultiply(v, ParallelMath::MakeUInt15(253)) + ParallelMath::MakeUInt16(512), 10)); + v = (reduced << 2) | ParallelMath::RightShift(reduced, 4); + } + + static void QuantizeTo5Bits(MUInt15& v) + { + MUInt15 reduced = ParallelMath::LosslessCast<MUInt15>::Cast(ParallelMath::RightShift(ParallelMath::CompactMultiply(v, ParallelMath::MakeUInt15(249)) + ParallelMath::MakeUInt16(1024), 11)); + v = (reduced << 3) | ParallelMath::RightShift(reduced, 2); + } + + static void QuantizeTo565(MUInt15 endPoint[3]) + { + QuantizeTo5Bits(endPoint[0]); + QuantizeTo6Bits(endPoint[1]); + QuantizeTo5Bits(endPoint[2]); + } + + static MFloat ParanoidFactorForSpan(const MSInt16& span) + { + return ParallelMath::Abs(ParallelMath::ToFloat(span)) * 0.03f; + } + + static MFloat ParanoidDiff(const MUInt15& a, const MUInt15& b, const MFloat& d) + { + MFloat absDiff = ParallelMath::Abs(ParallelMath::ToFloat(ParallelMath::LosslessCast<MSInt16>::Cast(a) - ParallelMath::LosslessCast<MSInt16>::Cast(b))); + absDiff = absDiff + d; + return absDiff * absDiff; + } + + static void TestSingleColor(uint32_t flags, const MUInt15 pixels[16][4], const MFloat floatPixels[16][4], int range, const float* channelWeights, + MFloat &bestError, MUInt15 bestEndpoints[2][3], MUInt15 bestIndexes[16], MUInt15 &bestRange, const ParallelMath::RoundTowardNearestForScope *rtn) + { + float channelWeightsSq[3]; + + for (int ch = 0; ch < 3; ch++) + channelWeightsSq[ch] = channelWeights[ch] * channelWeights[ch]; + + MUInt15 totals[3] = { ParallelMath::MakeUInt15(0), ParallelMath::MakeUInt15(0), ParallelMath::MakeUInt15(0) }; + + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < 3; ch++) + totals[ch] = totals[ch] + pixels[px][ch]; + } + + MUInt15 average[3]; + for (int ch = 0; ch < 3; ch++) + average[ch] = ParallelMath::RightShift(totals[ch] + ParallelMath::MakeUInt15(8), 4); + + const S3TCSingleColorTables::SingleColorTableEntry* rbTable = NULL; + const S3TCSingleColorTables::SingleColorTableEntry* gTable = NULL; + if (flags & cvtt::Flags::S3TC_Paranoid) + { + if (range == 4) + { + rbTable = S3TCSingleColorTables::g_singleColor5_3_p; + gTable = S3TCSingleColorTables::g_singleColor6_3_p; + } + else + { + assert(range == 3); + rbTable = S3TCSingleColorTables::g_singleColor5_2_p; + gTable = S3TCSingleColorTables::g_singleColor6_2_p; + } + } + else + { + if (range == 4) + { + rbTable = S3TCSingleColorTables::g_singleColor5_3; + gTable = S3TCSingleColorTables::g_singleColor6_3; + } + else + { + assert(range == 3); + rbTable = S3TCSingleColorTables::g_singleColor5_2; + gTable = S3TCSingleColorTables::g_singleColor6_2; + } + } + + MUInt15 interpolated[3]; + MUInt15 eps[2][3]; + MSInt16 spans[3]; + for (int i = 0; i < ParallelMath::ParallelSize; i++) + { + for (int ch = 0; ch < 3; ch++) + { + uint16_t avg = ParallelMath::Extract(average[ch], i); + const S3TCSingleColorTables::SingleColorTableEntry& tableEntry = ((ch == 1) ? gTable[avg] : rbTable[avg]); + ParallelMath::PutUInt15(eps[0][ch], i, tableEntry.m_min); + ParallelMath::PutUInt15(eps[1][ch], i, tableEntry.m_max); + ParallelMath::PutUInt15(interpolated[ch], i, tableEntry.m_actualColor); + ParallelMath::PutSInt16(spans[ch], i, tableEntry.m_span); + } + } + + MFloat error = ParallelMath::MakeFloatZero(); + if (flags & cvtt::Flags::S3TC_Paranoid) + { + MFloat spanParanoidFactors[3]; + for (int ch = 0; ch < 3; ch++) + spanParanoidFactors[ch] = ParanoidFactorForSpan(spans[ch]); + + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < 3; ch++) + error = error + ParanoidDiff(interpolated[ch], pixels[px][ch], spanParanoidFactors[ch]) * channelWeightsSq[ch]; + } + } + else + { + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < 3; ch++) + error = error + ParallelMath::ToFloat(ParallelMath::SqDiffUInt8(interpolated[ch], pixels[px][ch])) * channelWeightsSq[ch]; + } + } + + ParallelMath::FloatCompFlag better = ParallelMath::Less(error, bestError); + ParallelMath::Int16CompFlag better16 = ParallelMath::FloatFlagToInt16(better); + + if (ParallelMath::AnySet(better16)) + { + bestError = ParallelMath::Min(bestError, error); + for (int epi = 0; epi < 2; epi++) + for (int ch = 0; ch < 3; ch++) + ParallelMath::ConditionalSet(bestEndpoints[epi][ch], better16, eps[epi][ch]); + + MUInt15 vindexes = ParallelMath::MakeUInt15(1); + for (int px = 0; px < 16; px++) + ParallelMath::ConditionalSet(bestIndexes[px], better16, vindexes); + + ParallelMath::ConditionalSet(bestRange, better16, ParallelMath::MakeUInt15(range)); + } + } + + static void TestEndpoints(uint32_t flags, const MUInt15 pixels[16][4], const MFloat floatPixels[16][4], const MFloat preWeightedPixels[16][4], const MUInt15 unquantizedEndPoints[2][3], int range, const float* channelWeights, + MFloat &bestError, MUInt15 bestEndpoints[2][3], MUInt15 bestIndexes[16], MUInt15 &bestRange, EndpointRefiner<3> *refiner, const ParallelMath::RoundTowardNearestForScope *rtn) + { + float channelWeightsSq[3]; + + for (int ch = 0; ch < 3; ch++) + channelWeightsSq[ch] = channelWeights[ch] * channelWeights[ch]; + + MUInt15 endPoints[2][3]; + + for (int ep = 0; ep < 2; ep++) + for (int ch = 0; ch < 3; ch++) + endPoints[ep][ch] = unquantizedEndPoints[ep][ch]; + + QuantizeTo565(endPoints[0]); + QuantizeTo565(endPoints[1]); + + IndexSelector<3> selector; + selector.Init<false>(channelWeights, endPoints, range); + + MUInt15 indexes[16]; + + MFloat paranoidFactors[3]; + for (int ch = 0; ch < 3; ch++) + paranoidFactors[ch] = ParanoidFactorForSpan(ParallelMath::LosslessCast<MSInt16>::Cast(endPoints[0][ch]) - ParallelMath::LosslessCast<MSInt16>::Cast(endPoints[1][ch])); + + MFloat error = ParallelMath::MakeFloatZero(); + AggregatedError<3> aggError; + for (int px = 0; px < 16; px++) + { + MUInt15 index = selector.SelectIndexLDR(floatPixels[px], rtn); + indexes[px] = index; + + if (refiner) + refiner->ContributeUnweightedPW(preWeightedPixels[px], index); + + MUInt15 reconstructed[3]; + selector.ReconstructLDRPrecise(index, reconstructed); + + if (flags & Flags::S3TC_Paranoid) + { + for (int ch = 0; ch < 3; ch++) + error = error + ParanoidDiff(reconstructed[ch], pixels[px][ch], paranoidFactors[ch]) * channelWeightsSq[ch]; + } + else + BCCommon::ComputeErrorLDR<3>(flags, reconstructed, pixels[px], aggError); + } + + if (!(flags & Flags::S3TC_Paranoid)) + error = aggError.Finalize(flags, channelWeightsSq); + + ParallelMath::FloatCompFlag better = ParallelMath::Less(error, bestError); + + if (ParallelMath::AnySet(better)) + { + ParallelMath::Int16CompFlag betterInt16 = ParallelMath::FloatFlagToInt16(better); + + ParallelMath::ConditionalSet(bestError, better, error); + + for (int ep = 0; ep < 2; ep++) + for (int ch = 0; ch < 3; ch++) + ParallelMath::ConditionalSet(bestEndpoints[ep][ch], betterInt16, endPoints[ep][ch]); + + for (int px = 0; px < 16; px++) + ParallelMath::ConditionalSet(bestIndexes[px], betterInt16, indexes[px]); + + ParallelMath::ConditionalSet(bestRange, betterInt16, ParallelMath::MakeUInt15(static_cast<uint16_t>(range))); + } + } + + static void TestCounts(uint32_t flags, const int *counts, int nCounts, MUInt15 numElements, const MUInt15 pixels[16][4], const MFloat floatPixels[16][4], const MFloat preWeightedPixels[16][4], bool alphaTest, + const MFloat floatSortedInputs[16][4], const MFloat preWeightedFloatSortedInputs[16][4], const float *channelWeights, MFloat &bestError, MUInt15 bestEndpoints[2][3], MUInt15 bestIndexes[16], MUInt15 &bestRange, + const ParallelMath::RoundTowardNearestForScope* rtn) + { + UNREFERENCED_PARAMETER(alphaTest); + UNREFERENCED_PARAMETER(flags); + + EndpointRefiner<3> refiner; + + refiner.Init(nCounts, channelWeights); + + bool escape = false; + int e = 0; + for (int i = 0; i < nCounts; i++) + { + for (int n = 0; n < counts[i]; n++) + { + ParallelMath::Int16CompFlag valid = ParallelMath::Less(ParallelMath::MakeUInt15(static_cast<uint16_t>(n)), numElements); + if (!ParallelMath::AnySet(valid)) + { + escape = true; + break; + } + + if (ParallelMath::AllSet(valid)) + refiner.ContributeUnweightedPW(preWeightedFloatSortedInputs[e++], ParallelMath::MakeUInt15(static_cast<uint16_t>(i))); + else + { + MFloat weight = ParallelMath::Select(ParallelMath::Int16FlagToFloat(valid), ParallelMath::MakeFloat(1.0f), ParallelMath::MakeFloat(0.0f)); + refiner.ContributePW(preWeightedFloatSortedInputs[e++], ParallelMath::MakeUInt15(static_cast<uint16_t>(i)), weight); + } + } + + if (escape) + break; + } + + MUInt15 endPoints[2][3]; + refiner.GetRefinedEndpointsLDR(endPoints, rtn); + + TestEndpoints(flags, pixels, floatPixels, preWeightedPixels, endPoints, nCounts, channelWeights, bestError, bestEndpoints, bestIndexes, bestRange, NULL, rtn); + } + + static void PackExplicitAlpha(uint32_t flags, const PixelBlockU8* inputs, int inputChannel, uint8_t* packedBlocks, size_t packedBlockStride) + { + UNREFERENCED_PARAMETER(flags); + ParallelMath::RoundTowardNearestForScope rtn; + + float weights[1] = { 1.0f }; + + MUInt15 pixels[16]; + MFloat floatPixels[16]; + + for (int px = 0; px < 16; px++) + { + ParallelMath::ConvertLDRInputs(inputs, px, inputChannel, pixels[px]); + floatPixels[px] = ParallelMath::ToFloat(pixels[px]); + } + + MUInt15 ep[2][1] = { { ParallelMath::MakeUInt15(0) },{ ParallelMath::MakeUInt15(255) } }; + + IndexSelector<1> selector; + selector.Init<false>(weights, ep, 16); + + MUInt15 indexes[16]; + + for (int px = 0; px < 16; px++) + indexes[px] = selector.SelectIndexLDR(&floatPixels[px], &rtn); + + for (int block = 0; block < ParallelMath::ParallelSize; block++) + { + for (int px = 0; px < 16; px += 8) + { + int index0 = ParallelMath::Extract(indexes[px], block); + int index1 = ParallelMath::Extract(indexes[px], block); + + packedBlocks[px / 2] = static_cast<uint8_t>(index0 | (index1 << 4)); + } + + packedBlocks += packedBlockStride; + } + } + + static void PackInterpolatedAlpha(uint32_t flags, const PixelBlockU8* inputs, int inputChannel, uint8_t* packedBlocks, size_t packedBlockStride, bool isSigned, int maxTweakRounds, int numRefineRounds) + { + if (maxTweakRounds < 1) + maxTweakRounds = 1; + + if (numRefineRounds < 1) + numRefineRounds = 1; + + ParallelMath::RoundTowardNearestForScope rtn; + + float oneWeight[1] = { 1.0f }; + + MUInt15 pixels[16]; + MFloat floatPixels[16]; + + MUInt15 highTerminal = isSigned ? ParallelMath::MakeUInt15(254) : ParallelMath::MakeUInt15(255); + MUInt15 highTerminalMinusOne = highTerminal - ParallelMath::MakeUInt15(1); + + for (int px = 0; px < 16; px++) + { + ParallelMath::ConvertLDRInputs(inputs, px, inputChannel, pixels[px]); + + if (isSigned) + pixels[px] = ParallelMath::Min(pixels[px], highTerminal); + + floatPixels[px] = ParallelMath::ToFloat(pixels[px]); + } + + MUInt15 sortedPixels[16]; + for (int px = 0; px < 16; px++) + sortedPixels[px] = pixels[px]; + + for (int sortEnd = 15; sortEnd > 0; sortEnd--) + { + for (int sortOffset = 0; sortOffset < sortEnd; sortOffset++) + { + MUInt15 a = sortedPixels[sortOffset]; + MUInt15 b = sortedPixels[sortOffset + 1]; + + sortedPixels[sortOffset] = ParallelMath::Min(a, b); + sortedPixels[sortOffset + 1] = ParallelMath::Max(a, b); + } + } + + MUInt15 zero = ParallelMath::MakeUInt15(0); + MUInt15 one = ParallelMath::MakeUInt15(1); + + MUInt15 bestIsFullRange = zero; + MFloat bestError = ParallelMath::MakeFloat(FLT_MAX); + MUInt15 bestEP[2] = { zero, zero }; + MUInt15 bestIndexes[16] = { + zero, zero, zero, zero, + zero, zero, zero, zero, + zero, zero, zero, zero, + zero, zero, zero, zero + }; + + // Full-precision + { + MUInt15 minEP = sortedPixels[0]; + MUInt15 maxEP = sortedPixels[15]; + + MFloat base[1] = { ParallelMath::ToFloat(minEP) }; + MFloat offset[1] = { ParallelMath::ToFloat(maxEP - minEP) }; + + UnfinishedEndpoints<1> ufep = UnfinishedEndpoints<1>(base, offset); + + int numTweakRounds = BCCommon::TweakRoundsForRange(8); + if (numTweakRounds > maxTweakRounds) + numTweakRounds = maxTweakRounds; + + for (int tweak = 0; tweak < numTweakRounds; tweak++) + { + MUInt15 ep[2][1]; + + ufep.FinishLDR(tweak, 8, ep[0], ep[1]); + + for (int refinePass = 0; refinePass < numRefineRounds; refinePass++) + { + EndpointRefiner<1> refiner; + refiner.Init(8, oneWeight); + + if (isSigned) + for (int epi = 0; epi < 2; epi++) + ep[epi][0] = ParallelMath::Min(ep[epi][0], highTerminal); + + IndexSelector<1> indexSelector; + indexSelector.Init<false>(oneWeight, ep, 8); + + MUInt15 indexes[16]; + + AggregatedError<1> aggError; + for (int px = 0; px < 16; px++) + { + MUInt15 index = indexSelector.SelectIndexLDR(&floatPixels[px], &rtn); + + MUInt15 reconstructedPixel; + + indexSelector.ReconstructLDRPrecise(index, &reconstructedPixel); + BCCommon::ComputeErrorLDR<1>(flags, &reconstructedPixel, &pixels[px], aggError); + + if (refinePass != numRefineRounds - 1) + refiner.ContributeUnweightedPW(&floatPixels[px], index); + + indexes[px] = index; + } + MFloat error = aggError.Finalize(flags | Flags::Uniform, oneWeight); + + ParallelMath::FloatCompFlag errorBetter = ParallelMath::Less(error, bestError); + ParallelMath::Int16CompFlag errorBetter16 = ParallelMath::FloatFlagToInt16(errorBetter); + + if (ParallelMath::AnySet(errorBetter16)) + { + bestError = ParallelMath::Min(error, bestError); + ParallelMath::ConditionalSet(bestIsFullRange, errorBetter16, one); + for (int px = 0; px < 16; px++) + ParallelMath::ConditionalSet(bestIndexes[px], errorBetter16, indexes[px]); + + for (int epi = 0; epi < 2; epi++) + ParallelMath::ConditionalSet(bestEP[epi], errorBetter16, ep[epi][0]); + } + + if (refinePass != numRefineRounds - 1) + refiner.GetRefinedEndpointsLDR(ep, &rtn); + } + } + } + + // Reduced precision with special endpoints + { + MUInt15 bestHeuristicMin = sortedPixels[0]; + MUInt15 bestHeuristicMax = sortedPixels[15]; + + ParallelMath::Int16CompFlag canTryClipping; + + // In reduced precision, we want try putting endpoints at the reserved indexes at the ends. + // The heuristic we use is to assign indexes to the end as long as they aren't off by more than half of the index range. + // This will usually not find anything, but it's cheap to check. + + { + MUInt15 largestPossibleRange = bestHeuristicMax - bestHeuristicMin; // Max: 255 + MUInt15 lowestPossibleClearance = ParallelMath::Min(bestHeuristicMin, static_cast<MUInt15>(highTerminal - bestHeuristicMax)); + + MUInt15 lowestPossibleClearanceTimes10 = (lowestPossibleClearance << 2) + (lowestPossibleClearance << 4); + canTryClipping = ParallelMath::LessOrEqual(lowestPossibleClearanceTimes10, largestPossibleRange); + } + + if (ParallelMath::AnySet(canTryClipping)) + { + MUInt15 lowClearances[16]; + MUInt15 highClearances[16]; + MUInt15 bestSkipCount = ParallelMath::MakeUInt15(0); + + lowClearances[0] = highClearances[0] = ParallelMath::MakeUInt15(0); + + for (int px = 1; px < 16; px++) + { + lowClearances[px] = sortedPixels[px - 1]; + highClearances[px] = highTerminal - sortedPixels[16 - px]; + } + + for (uint16_t firstIndex = 0; firstIndex < 16; firstIndex++) + { + uint16_t numSkippedLow = firstIndex; + + MUInt15 lowClearance = lowClearances[firstIndex]; + + for (uint16_t lastIndex = firstIndex; lastIndex < 16; lastIndex++) + { + uint16_t numSkippedHigh = 15 - lastIndex; + uint16_t numSkipped = numSkippedLow + numSkippedHigh; + + MUInt15 numSkippedV = ParallelMath::MakeUInt15(numSkipped); + + ParallelMath::Int16CompFlag areMoreSkipped = ParallelMath::Less(bestSkipCount, numSkippedV); + + if (!ParallelMath::AnySet(areMoreSkipped)) + continue; + + MUInt15 clearance = ParallelMath::Max(highClearances[numSkippedHigh], lowClearance); + MUInt15 clearanceTimes10 = (clearance << 2) + (clearance << 4); + + MUInt15 range = sortedPixels[lastIndex] - sortedPixels[firstIndex]; + + ParallelMath::Int16CompFlag isBetter = (areMoreSkipped & ParallelMath::LessOrEqual(clearanceTimes10, range)); + ParallelMath::ConditionalSet(bestHeuristicMin, isBetter, sortedPixels[firstIndex]); + ParallelMath::ConditionalSet(bestHeuristicMax, isBetter, sortedPixels[lastIndex]); + } + } + } + + MUInt15 bestSimpleMin = one; + MUInt15 bestSimpleMax = highTerminalMinusOne; + + for (int px = 0; px < 16; px++) + { + ParallelMath::ConditionalSet(bestSimpleMin, ParallelMath::Less(zero, sortedPixels[15 - px]), sortedPixels[15 - px]); + ParallelMath::ConditionalSet(bestSimpleMax, ParallelMath::Less(sortedPixels[px], highTerminal), sortedPixels[px]); + } + + MUInt15 minEPs[2] = { bestSimpleMin, bestHeuristicMin }; + MUInt15 maxEPs[2] = { bestSimpleMax, bestHeuristicMax }; + + int minEPRange = 2; + if (ParallelMath::AllSet(ParallelMath::Equal(minEPs[0], minEPs[1]))) + minEPRange = 1; + + int maxEPRange = 2; + if (ParallelMath::AllSet(ParallelMath::Equal(maxEPs[0], maxEPs[1]))) + maxEPRange = 1; + + for (int minEPIndex = 0; minEPIndex < minEPRange; minEPIndex++) + { + for (int maxEPIndex = 0; maxEPIndex < maxEPRange; maxEPIndex++) + { + MFloat base[1] = { ParallelMath::ToFloat(minEPs[minEPIndex]) }; + MFloat offset[1] = { ParallelMath::ToFloat(maxEPs[maxEPIndex] - minEPs[minEPIndex]) }; + + UnfinishedEndpoints<1> ufep = UnfinishedEndpoints<1>(base, offset); + + int numTweakRounds = BCCommon::TweakRoundsForRange(6); + if (numTweakRounds > maxTweakRounds) + numTweakRounds = maxTweakRounds; + + for (int tweak = 0; tweak < numTweakRounds; tweak++) + { + MUInt15 ep[2][1]; + + ufep.FinishLDR(tweak, 8, ep[0], ep[1]); + + for (int refinePass = 0; refinePass < numRefineRounds; refinePass++) + { + EndpointRefiner<1> refiner; + refiner.Init(6, oneWeight); + + if (isSigned) + for (int epi = 0; epi < 2; epi++) + ep[epi][0] = ParallelMath::Min(ep[epi][0], highTerminal); + + IndexSelector<1> indexSelector; + indexSelector.Init<false>(oneWeight, ep, 6); + + MUInt15 indexes[16]; + MFloat error = ParallelMath::MakeFloatZero(); + + for (int px = 0; px < 16; px++) + { + MUInt15 selectedIndex = indexSelector.SelectIndexLDR(&floatPixels[px], &rtn); + + MUInt15 reconstructedPixel; + + indexSelector.ReconstructLDRPrecise(selectedIndex, &reconstructedPixel); + + MFloat zeroError = BCCommon::ComputeErrorLDRSimple<1>(flags | Flags::Uniform, &zero, &pixels[px], 1, oneWeight); + MFloat highTerminalError = BCCommon::ComputeErrorLDRSimple<1>(flags | Flags::Uniform, &highTerminal, &pixels[px], 1, oneWeight); + MFloat selectedIndexError = BCCommon::ComputeErrorLDRSimple<1>(flags | Flags::Uniform, &reconstructedPixel, &pixels[px], 1, oneWeight); + + MFloat bestPixelError = zeroError; + MUInt15 index = ParallelMath::MakeUInt15(6); + + ParallelMath::ConditionalSet(index, ParallelMath::FloatFlagToInt16(ParallelMath::Less(highTerminalError, bestPixelError)), ParallelMath::MakeUInt15(7)); + bestPixelError = ParallelMath::Min(bestPixelError, highTerminalError); + + ParallelMath::FloatCompFlag selectedIndexBetter = ParallelMath::Less(selectedIndexError, bestPixelError); + + if (ParallelMath::AllSet(selectedIndexBetter)) + { + if (refinePass != numRefineRounds - 1) + refiner.ContributeUnweightedPW(&floatPixels[px], selectedIndex); + } + else + { + MFloat refineWeight = ParallelMath::Select(selectedIndexBetter, ParallelMath::MakeFloat(1.0f), ParallelMath::MakeFloatZero()); + + if (refinePass != numRefineRounds - 1) + refiner.ContributePW(&floatPixels[px], selectedIndex, refineWeight); + } + + ParallelMath::ConditionalSet(index, ParallelMath::FloatFlagToInt16(selectedIndexBetter), selectedIndex); + bestPixelError = ParallelMath::Min(bestPixelError, selectedIndexError); + + error = error + bestPixelError; + + indexes[px] = index; + } + + ParallelMath::FloatCompFlag errorBetter = ParallelMath::Less(error, bestError); + ParallelMath::Int16CompFlag errorBetter16 = ParallelMath::FloatFlagToInt16(errorBetter); + + if (ParallelMath::AnySet(errorBetter16)) + { + bestError = ParallelMath::Min(error, bestError); + ParallelMath::ConditionalSet(bestIsFullRange, errorBetter16, zero); + for (int px = 0; px < 16; px++) + ParallelMath::ConditionalSet(bestIndexes[px], errorBetter16, indexes[px]); + + for (int epi = 0; epi < 2; epi++) + ParallelMath::ConditionalSet(bestEP[epi], errorBetter16, ep[epi][0]); + } + + if (refinePass != numRefineRounds - 1) + refiner.GetRefinedEndpointsLDR(ep, &rtn); + } + } + } + } + } + + for (int block = 0; block < ParallelMath::ParallelSize; block++) + { + int ep0 = ParallelMath::Extract(bestEP[0], block); + int ep1 = ParallelMath::Extract(bestEP[1], block); + int isFullRange = ParallelMath::Extract(bestIsFullRange, block); + + if (isSigned) + { + ep0 -= 127; + ep1 -= 127; + + assert(ep0 >= -127 && ep0 <= 127); + assert(ep1 >= -127 && ep1 <= 127); + } + + + bool swapEndpoints = (isFullRange != 0) != (ep0 > ep1); + + if (swapEndpoints) + std::swap(ep0, ep1); + + uint16_t dumpBits = 0; + int dumpBitsOffset = 0; + int dumpByteOffset = 2; + packedBlocks[0] = static_cast<uint8_t>(ep0 & 0xff); + packedBlocks[1] = static_cast<uint8_t>(ep1 & 0xff); + + int maxValue = (isFullRange != 0) ? 7 : 5; + + for (int px = 0; px < 16; px++) + { + int index = ParallelMath::Extract(bestIndexes[px], block); + + if (swapEndpoints && index <= maxValue) + index = maxValue - index; + + if (index != 0) + { + if (index == maxValue) + index = 1; + else if (index < maxValue) + index++; + } + + assert(index >= 0 && index < 8); + + dumpBits |= static_cast<uint16_t>(index << dumpBitsOffset); + dumpBitsOffset += 3; + + if (dumpBitsOffset >= 8) + { + assert(dumpByteOffset < 8); + packedBlocks[dumpByteOffset] = static_cast<uint8_t>(dumpBits & 0xff); + dumpBits >>= 8; + dumpBitsOffset -= 8; + dumpByteOffset++; + } + } + + assert(dumpBitsOffset == 0); + assert(dumpByteOffset == 8); + + packedBlocks += packedBlockStride; + } + } + + static void PackRGB(uint32_t flags, const PixelBlockU8* inputs, uint8_t* packedBlocks, size_t packedBlockStride, const float channelWeights[4], bool alphaTest, float alphaThreshold, bool exhaustive, int maxTweakRounds, int numRefineRounds) + { + ParallelMath::RoundTowardNearestForScope rtn; + + if (numRefineRounds < 1) + numRefineRounds = 1; + + if (maxTweakRounds < 1) + maxTweakRounds = 1; + + EndpointSelector<3, 8> endpointSelector; + + MUInt15 pixels[16][4]; + MFloat floatPixels[16][4]; + + MFloat preWeightedPixels[16][4]; + + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < 4; ch++) + ParallelMath::ConvertLDRInputs(inputs, px, ch, pixels[px][ch]); + } + + for (int px = 0; px < 16; px++) + { + for (int ch = 0; ch < 4; ch++) + floatPixels[px][ch] = ParallelMath::ToFloat(pixels[px][ch]); + } + + if (alphaTest) + { + MUInt15 threshold = ParallelMath::MakeUInt15(static_cast<uint16_t>(floor(alphaThreshold * 255.0f + 0.5f))); + + for (int px = 0; px < 16; px++) + { + ParallelMath::Int16CompFlag belowThreshold = ParallelMath::Less(pixels[px][3], threshold); + pixels[px][3] = ParallelMath::Select(belowThreshold, ParallelMath::MakeUInt15(0), ParallelMath::MakeUInt15(255)); + } + } + + BCCommon::PreWeightPixelsLDR<4>(preWeightedPixels, pixels, channelWeights); + + MUInt15 minAlpha = ParallelMath::MakeUInt15(255); + + for (int px = 0; px < 16; px++) + minAlpha = ParallelMath::Min(minAlpha, pixels[px][3]); + + MFloat pixelWeights[16]; + for (int px = 0; px < 16; px++) + { + pixelWeights[px] = ParallelMath::MakeFloat(1.0f); + if (alphaTest) + { + ParallelMath::Int16CompFlag isTransparent = ParallelMath::Less(pixels[px][3], ParallelMath::MakeUInt15(255)); + + ParallelMath::ConditionalSet(pixelWeights[px], ParallelMath::Int16FlagToFloat(isTransparent), ParallelMath::MakeFloatZero()); + } + } + + for (int pass = 0; pass < NumEndpointSelectorPasses; pass++) + { + for (int px = 0; px < 16; px++) + endpointSelector.ContributePass(preWeightedPixels[px], pass, pixelWeights[px]); + + endpointSelector.FinishPass(pass); + } + + UnfinishedEndpoints<3> ufep = endpointSelector.GetEndpoints(channelWeights); + + MUInt15 bestEndpoints[2][3]; + MUInt15 bestIndexes[16]; + MUInt15 bestRange = ParallelMath::MakeUInt15(0); + MFloat bestError = ParallelMath::MakeFloat(FLT_MAX); + + for (int px = 0; px < 16; px++) + bestIndexes[px] = ParallelMath::MakeUInt15(0); + + for (int ep = 0; ep < 2; ep++) + for (int ch = 0; ch < 3; ch++) + bestEndpoints[ep][ch] = ParallelMath::MakeUInt15(0); + + if (exhaustive) + { + MSInt16 sortBins[16]; + + { + // Compute an 11-bit index, change it to signed, stuff it in the high bits of the sort bins, + // and pack the original indexes into the low bits. + + MUInt15 sortEP[2][3]; + ufep.FinishLDR(0, 11, sortEP[0], sortEP[1]); + + IndexSelector<3> sortSelector; + sortSelector.Init<false>(channelWeights, sortEP, 1 << 11); + + for (int16_t px = 0; px < 16; px++) + { + MSInt16 sortBin = ParallelMath::LosslessCast<MSInt16>::Cast(sortSelector.SelectIndexLDR(floatPixels[px], &rtn) << 4); + + if (alphaTest) + { + ParallelMath::Int16CompFlag isTransparent = ParallelMath::Less(pixels[px][3], ParallelMath::MakeUInt15(255)); + + ParallelMath::ConditionalSet(sortBin, isTransparent, ParallelMath::MakeSInt16(-16)); // 0xfff0 + } + + sortBin = sortBin + ParallelMath::MakeSInt16(px); + + sortBins[px] = sortBin; + } + } + + // Sort bins + for (int sortEnd = 1; sortEnd < 16; sortEnd++) + { + for (int sortLoc = sortEnd; sortLoc > 0; sortLoc--) + { + MSInt16 a = sortBins[sortLoc]; + MSInt16 b = sortBins[sortLoc - 1]; + + sortBins[sortLoc] = ParallelMath::Max(a, b); + sortBins[sortLoc - 1] = ParallelMath::Min(a, b); + } + } + + MUInt15 firstElement = ParallelMath::MakeUInt15(0); + for (uint16_t e = 0; e < 16; e++) + { + ParallelMath::Int16CompFlag isInvalid = ParallelMath::Less(sortBins[e], ParallelMath::MakeSInt16(0)); + ParallelMath::ConditionalSet(firstElement, isInvalid, ParallelMath::MakeUInt15(e + 1)); + if (!ParallelMath::AnySet(isInvalid)) + break; + } + + MUInt15 numElements = ParallelMath::MakeUInt15(16) - firstElement; + + MUInt15 sortedInputs[16][4]; + MFloat floatSortedInputs[16][4]; + MFloat pwFloatSortedInputs[16][4]; + + for (int e = 0; e < 16; e++) + { + for (int ch = 0; ch < 4; ch++) + sortedInputs[e][ch] = ParallelMath::MakeUInt15(0); + } + + for (int block = 0; block < ParallelMath::ParallelSize; block++) + { + for (int e = ParallelMath::Extract(firstElement, block); e < 16; e++) + { + ParallelMath::ScalarUInt16 sortBin = ParallelMath::Extract(sortBins[e], block); + int originalIndex = (sortBin & 15); + + for (int ch = 0; ch < 4; ch++) + ParallelMath::PutUInt15(sortedInputs[15 - e][ch], block, ParallelMath::Extract(pixels[originalIndex][ch], block)); + } + } + + for (int e = 0; e < 16; e++) + { + for (int ch = 0; ch < 4; ch++) + { + MFloat f = ParallelMath::ToFloat(sortedInputs[e][ch]); + floatSortedInputs[e][ch] = f; + pwFloatSortedInputs[e][ch] = f * channelWeights[ch]; + } + } + + for (int n0 = 0; n0 <= 15; n0++) + { + int remainingFor1 = 16 - n0; + if (remainingFor1 == 16) + remainingFor1 = 15; + + for (int n1 = 0; n1 <= remainingFor1; n1++) + { + int remainingFor2 = 16 - n1 - n0; + if (remainingFor2 == 16) + remainingFor2 = 15; + + for (int n2 = 0; n2 <= remainingFor2; n2++) + { + int n3 = 16 - n2 - n1 - n0; + + if (n3 == 16) + continue; + + int counts[4] = { n0, n1, n2, n3 }; + + TestCounts(flags, counts, 4, numElements, pixels, floatPixels, preWeightedPixels, alphaTest, floatSortedInputs, pwFloatSortedInputs, channelWeights, bestError, bestEndpoints, bestIndexes, bestRange, &rtn); + } + } + } + + TestSingleColor(flags, pixels, floatPixels, 4, channelWeights, bestError, bestEndpoints, bestIndexes, bestRange, &rtn); + + if (alphaTest) + { + for (int n0 = 0; n0 <= 15; n0++) + { + int remainingFor1 = 16 - n0; + if (remainingFor1 == 16) + remainingFor1 = 15; + + for (int n1 = 0; n1 <= remainingFor1; n1++) + { + int n2 = 16 - n1 - n0; + + if (n2 == 16) + continue; + + int counts[3] = { n0, n1, n2 }; + + TestCounts(flags, counts, 3, numElements, pixels, floatPixels, preWeightedPixels, alphaTest, floatSortedInputs, pwFloatSortedInputs, channelWeights, bestError, bestEndpoints, bestIndexes, bestRange, &rtn); + } + } + + TestSingleColor(flags, pixels, floatPixels, 3, channelWeights, bestError, bestEndpoints, bestIndexes, bestRange, &rtn); + } + } + else + { + int minRange = alphaTest ? 3 : 4; + + for (int range = minRange; range <= 4; range++) + { + int tweakRounds = BCCommon::TweakRoundsForRange(range); + if (tweakRounds > maxTweakRounds) + tweakRounds = maxTweakRounds; + + for (int tweak = 0; tweak < tweakRounds; tweak++) + { + MUInt15 endPoints[2][3]; + + ufep.FinishLDR(tweak, range, endPoints[0], endPoints[1]); + + for (int refine = 0; refine < numRefineRounds; refine++) + { + EndpointRefiner<3> refiner; + refiner.Init(range, channelWeights); + + TestEndpoints(flags, pixels, floatPixels, preWeightedPixels, endPoints, range, channelWeights, bestError, bestEndpoints, bestIndexes, bestRange, &refiner, &rtn); + + if (refine != numRefineRounds - 1) + refiner.GetRefinedEndpointsLDR(endPoints, &rtn); + } + } + } + } + + for (int block = 0; block < ParallelMath::ParallelSize; block++) + { + ParallelMath::ScalarUInt16 range = ParallelMath::Extract(bestRange, block); + assert(range == 3 || range == 4); + + ParallelMath::ScalarUInt16 compressedEP[2]; + for (int ep = 0; ep < 2; ep++) + { + ParallelMath::ScalarUInt16 endPoint[3]; + for (int ch = 0; ch < 3; ch++) + endPoint[ch] = ParallelMath::Extract(bestEndpoints[ep][ch], block); + + int compressed = (endPoint[0] & 0xf8) << 8; + compressed |= (endPoint[1] & 0xfc) << 3; + compressed |= (endPoint[2] & 0xf8) >> 3; + + compressedEP[ep] = static_cast<ParallelMath::ScalarUInt16>(compressed); + } + + int indexOrder[4]; + + if (range == 4) + { + if (compressedEP[0] == compressedEP[1]) + { + indexOrder[0] = 0; + indexOrder[1] = 0; + indexOrder[2] = 0; + indexOrder[3] = 0; + } + else if (compressedEP[0] < compressedEP[1]) + { + std::swap(compressedEP[0], compressedEP[1]); + indexOrder[0] = 1; + indexOrder[1] = 3; + indexOrder[2] = 2; + indexOrder[3] = 0; + } + else + { + indexOrder[0] = 0; + indexOrder[1] = 2; + indexOrder[2] = 3; + indexOrder[3] = 1; + } + } + else + { + assert(range == 3); + + if (compressedEP[0] > compressedEP[1]) + { + std::swap(compressedEP[0], compressedEP[1]); + indexOrder[0] = 1; + indexOrder[1] = 2; + indexOrder[2] = 0; + } + else + { + indexOrder[0] = 0; + indexOrder[1] = 2; + indexOrder[2] = 1; + } + indexOrder[3] = 3; + } + + packedBlocks[0] = static_cast<uint8_t>(compressedEP[0] & 0xff); + packedBlocks[1] = static_cast<uint8_t>((compressedEP[0] >> 8) & 0xff); + packedBlocks[2] = static_cast<uint8_t>(compressedEP[1] & 0xff); + packedBlocks[3] = static_cast<uint8_t>((compressedEP[1] >> 8) & 0xff); + + for (int i = 0; i < 16; i += 4) + { + int packedIndexes = 0; + for (int subi = 0; subi < 4; subi++) + { + ParallelMath::ScalarUInt16 index = ParallelMath::Extract(bestIndexes[i + subi], block); + packedIndexes |= (indexOrder[index] << (subi * 2)); + } + + packedBlocks[4 + i / 4] = static_cast<uint8_t>(packedIndexes); + } + + packedBlocks += packedBlockStride; + } + } + }; + + // Signed input blocks are converted into unsigned space, with the maximum value being 254 + void BiasSignedInput(PixelBlockU8 inputNormalized[ParallelMath::ParallelSize], const PixelBlockS8 inputSigned[ParallelMath::ParallelSize]) + { + for (size_t block = 0; block < ParallelMath::ParallelSize; block++) + { + const PixelBlockS8& inputSignedBlock = inputSigned[block]; + PixelBlockU8& inputNormalizedBlock = inputNormalized[block]; + + for (size_t px = 0; px < 16; px++) + { + for (size_t ch = 0; ch < 4; ch++) + inputNormalizedBlock.m_pixels[px][ch] = static_cast<uint8_t>(std::max<int>(inputSignedBlock.m_pixels[px][ch], -127) + 127); + } + } + } + + void FillWeights(const Options &options, float channelWeights[4]) + { + if (options.flags & Flags::Uniform) + channelWeights[0] = channelWeights[1] = channelWeights[2] = channelWeights[3] = 1.0f; + else + { + channelWeights[0] = options.redWeight; + channelWeights[1] = options.greenWeight; + channelWeights[2] = options.blueWeight; + channelWeights[3] = options.alphaWeight; + } + } + } + + namespace Kernels + { + void EncodeBC7(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + Internal::BC7Computer::Pack(options.flags, pBlocks + blockBase, pBC, channelWeights, options.seedPoints, options.refineRoundsBC7); + pBC += ParallelMath::ParallelSize * 16; + } + } + + void EncodeBC6HU(uint8_t *pBC, const PixelBlockF16 *pBlocks, const cvtt::Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + Internal::BC6HComputer::Pack(options.flags, pBlocks + blockBase, pBC, channelWeights, false, options.seedPoints, options.refineRoundsBC6H); + pBC += ParallelMath::ParallelSize * 16; + } + } + + void EncodeBC6HS(uint8_t *pBC, const PixelBlockF16 *pBlocks, const cvtt::Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + Internal::BC6HComputer::Pack(options.flags, pBlocks + blockBase, pBC, channelWeights, true, options.seedPoints, options.refineRoundsBC6H); + pBC += ParallelMath::ParallelSize * 16; + } + } + + void EncodeBC1(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + Internal::S3TCComputer::PackRGB(options.flags, pBlocks + blockBase, pBC, 8, channelWeights, true, options.threshold, (options.flags & Flags::S3TC_Exhaustive) != 0, options.seedPoints, options.refineRoundsS3TC); + pBC += ParallelMath::ParallelSize * 8; + } + } + + void EncodeBC2(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + Internal::S3TCComputer::PackRGB(options.flags, pBlocks + blockBase, pBC + 8, 16, channelWeights, false, 1.0f, (options.flags & Flags::S3TC_Exhaustive) != 0, options.seedPoints, options.refineRoundsS3TC); + Internal::S3TCComputer::PackExplicitAlpha(options.flags, pBlocks + blockBase, 3, pBC, 16); + pBC += ParallelMath::ParallelSize * 16; + } + } + + void EncodeBC3(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + Internal::S3TCComputer::PackRGB(options.flags, pBlocks + blockBase, pBC + 8, 16, channelWeights, false, 1.0f, (options.flags & Flags::S3TC_Exhaustive) != 0, options.seedPoints, options.refineRoundsS3TC); + Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, pBlocks + blockBase, 3, pBC, 16, false, options.seedPoints, options.refineRoundsIIC); + pBC += ParallelMath::ParallelSize * 16; + } + } + + void EncodeBC4U(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, pBlocks + blockBase, 0, pBC, 8, false, options.seedPoints, options.refineRoundsIIC); + pBC += ParallelMath::ParallelSize * 8; + } + } + + void EncodeBC4S(uint8_t *pBC, const PixelBlockS8 *pBlocks, const Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + PixelBlockU8 inputBlocks[ParallelMath::ParallelSize]; + Internal::BiasSignedInput(inputBlocks, pBlocks + blockBase); + + Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, inputBlocks, 0, pBC, 8, true, options.seedPoints, options.refineRoundsIIC); + pBC += ParallelMath::ParallelSize * 8; + } + } + + void EncodeBC5U(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, pBlocks + blockBase, 0, pBC, 16, false, options.seedPoints, options.refineRoundsIIC); + Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, pBlocks + blockBase, 1, pBC + 8, 16, false, options.seedPoints, options.refineRoundsIIC); + pBC += ParallelMath::ParallelSize * 16; + } + } + + void EncodeBC5S(uint8_t *pBC, const PixelBlockS8 *pBlocks, const Options &options) + { + assert(pBlocks); + assert(pBC); + + float channelWeights[4]; + Internal::FillWeights(options, channelWeights); + + for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize) + { + PixelBlockU8 inputBlocks[ParallelMath::ParallelSize]; + Internal::BiasSignedInput(inputBlocks, pBlocks + blockBase); + + Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, inputBlocks, 0, pBC, 16, true, options.seedPoints, options.refineRoundsIIC); + Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, inputBlocks, 1, pBC + 8, 16, true, options.seedPoints, options.refineRoundsIIC); + pBC += ParallelMath::ParallelSize * 16; + } + } + + void DecodeBC7(PixelBlockU8 *pBlocks, const uint8_t *pBC) + { + assert(pBlocks); + assert(pBC); + + for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase++) + { + Internal::BC7Computer::UnpackOne(pBlocks[blockBase], pBC); + pBC += 16; + } + } + + void DecodeBC6HU(PixelBlockF16 *pBlocks, const uint8_t *pBC) + { + assert(pBlocks); + assert(pBC); + + for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase++) + { + Internal::BC6HComputer::UnpackOne(pBlocks[blockBase], pBC, false); + pBC += 16; + } + } + + void DecodeBC6HS(PixelBlockF16 *pBlocks, const uint8_t *pBC) + { + assert(pBlocks); + assert(pBC); + + for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase++) + { + Internal::BC6HComputer::UnpackOne(pBlocks[blockBase], pBC, true); + pBC += 16; + } + } + } +} diff --git a/thirdparty/cvtt/ConvectionKernels.h b/thirdparty/cvtt/ConvectionKernels.h new file mode 100644 index 0000000000..fb5ca130f9 --- /dev/null +++ b/thirdparty/cvtt/ConvectionKernels.h @@ -0,0 +1,145 @@ +/* +Convection Texture Tools +Copyright (c) 2018 Eric Lasota + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +#pragma once +#ifndef __CVTT_CONVECTION_KERNELS__ +#define __CVTT_CONVECTION_KERNELS__ + +#include <stdint.h> + +namespace cvtt +{ + namespace Flags + { + // Enable partitioned modes in BC7 encoding (slower, better quality) + const uint32_t BC7_EnablePartitioning = 0x001; + + // Enable 3-partition modes in BC7 encoding (slower, better quality, requires BC7_EnablePartitioning) + const uint32_t BC7_Enable3Subsets = 0x002; + + // Enable dual-plane modes in BC7 encoding (slower, better quality) + const uint32_t BC7_EnableDualPlane = 0x004; + + // Use fast indexing in BC7 encoding (about 2x faster, slightly worse quality) + const uint32_t BC7_FastIndexing = 0x008; + + // Try precomputed single-color lookups where applicable (slightly slower, small quality increase on specific blocks) + const uint32_t BC7_TrySingleColor = 0x010; + + // Don't allow non-zero or non-max alpha values in blocks that only contain one or the other + const uint32_t BC7_RespectPunchThrough = 0x020; + + // Use fast indexing in HDR formats (faster, worse quality) + const uint32_t BC6H_FastIndexing = 0x040; + + // Exhaustive search RGB orderings when encoding BC1-BC3 (much slower, better quality) + const uint32_t S3TC_Exhaustive = 0x080; + + // Penalize distant endpoints, improving quality on inaccurate GPU decoders + const uint32_t S3TC_Paranoid = 0x100; + + // Uniform color channel importance + const uint32_t Uniform = 0x200; + + // Misc useful default flag combinations + const uint32_t Fastest = (BC6H_FastIndexing | S3TC_Paranoid); + const uint32_t Faster = (BC7_EnableDualPlane | BC6H_FastIndexing | S3TC_Paranoid); + const uint32_t Fast = (BC7_EnablePartitioning | BC7_EnableDualPlane | BC7_FastIndexing | S3TC_Paranoid); + const uint32_t Default = (BC7_EnablePartitioning | BC7_EnableDualPlane | BC7_Enable3Subsets | BC7_FastIndexing | S3TC_Paranoid); + const uint32_t Better = (BC7_EnablePartitioning | BC7_EnableDualPlane | BC7_Enable3Subsets | S3TC_Paranoid | S3TC_Exhaustive); + const uint32_t Ultra = (BC7_EnablePartitioning | BC7_EnableDualPlane | BC7_Enable3Subsets | BC7_TrySingleColor | S3TC_Paranoid | S3TC_Exhaustive); + } + + const unsigned int NumParallelBlocks = 8; + + struct Options + { + uint32_t flags; // Bitmask of cvtt::Flags values + float threshold; // Alpha test threshold for BC1 + float redWeight; // Red channel importance + float greenWeight; // Green channel importance + float blueWeight; // Blue channel importance + float alphaWeight; // Alpha channel importance + + int refineRoundsBC7; // Number of refine rounds for BC7 + int refineRoundsBC6H; // Number of refine rounds for BC6H (max 3) + int refineRoundsIIC; // Number of refine rounds for independent interpolated channels (BC3 alpha, BC4, BC5) + int refineRoundsS3TC; // Number of refine rounds for S3TC RGB + + int seedPoints; // Number of seed points (min 1, max 4) + + Options() + : flags(Flags::Default) + , threshold(0.5f) + , redWeight(0.2125f / 0.7154f) + , greenWeight(1.0f) + , blueWeight(0.0721f / 0.7154f) + , alphaWeight(1.0f) + , refineRoundsBC7(2) + , refineRoundsBC6H(3) + , refineRoundsIIC(8) + , refineRoundsS3TC(2) + , seedPoints(4) + { + } + }; + + // RGBA input block for unsigned 8-bit formats + struct PixelBlockU8 + { + uint8_t m_pixels[16][4]; + }; + + // RGBA input block for signed 8-bit formats + struct PixelBlockS8 + { + int8_t m_pixels[16][4]; + }; + + // RGBA input block for half-precision float formats (bit-cast to int16_t) + struct PixelBlockF16 + { + int16_t m_pixels[16][4]; + }; + + namespace Kernels + { + // NOTE: All functions accept and output NumParallelBlocks blocks at once + void EncodeBC1(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options); + void EncodeBC2(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options); + void EncodeBC3(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options); + void EncodeBC4U(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options); + void EncodeBC4S(uint8_t *pBC, const PixelBlockS8 *pBlocks, const Options &options); + void EncodeBC5U(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options); + void EncodeBC5S(uint8_t *pBC, const PixelBlockS8 *pBlocks, const Options &options); + void EncodeBC6HU(uint8_t *pBC, const PixelBlockF16 *pBlocks, const Options &options); + void EncodeBC6HS(uint8_t *pBC, const PixelBlockF16 *pBlocks, const Options &options); + void EncodeBC7(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options); + + void DecodeBC6HU(PixelBlockF16 *pBlocks, const uint8_t *pBC); + void DecodeBC6HS(PixelBlockF16 *pBlocks, const uint8_t *pBC); + void DecodeBC7(PixelBlockU8 *pBlocks, const uint8_t *pBC); + } +} + +#endif diff --git a/thirdparty/cvtt/ConvectionKernels_BC7_SingleColor.h b/thirdparty/cvtt/ConvectionKernels_BC7_SingleColor.h new file mode 100644 index 0000000000..b5564c0dab --- /dev/null +++ b/thirdparty/cvtt/ConvectionKernels_BC7_SingleColor.h @@ -0,0 +1,1940 @@ +#pragma once +#include <stdint.h> + +namespace cvtt { namespace Tables { namespace BC7SC { + +struct TableEntry +{ + uint8_t m_min; + uint8_t m_max; + uint8_t m_actualColor; +}; + +struct Table +{ + uint8_t m_index; + uint8_t m_pBits; + TableEntry m_entries[256]; +}; + +Table g_mode0_p00_i1= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 16, 2 }, { 0, 16, 2 }, { 0, 33, 5 }, { 0, 33, 5 }, { 0, 33, 5 }, { 0, 49, 7 }, + { 0, 49, 7 }, { 0, 66, 9 }, { 0, 66, 9 }, { 0, 82, 12 }, { 0, 82, 12 }, { 0, 82, 12 }, { 0, 99, 14 }, { 0, 99, 14 }, + { 0, 115, 16 }, { 0, 115, 16 }, { 16, 33, 18 }, { 0, 132, 19 }, { 0, 132, 19 }, { 0, 148, 21 }, { 0, 148, 21 }, { 0, 165, 23 }, + { 0, 165, 23 }, { 0, 181, 25 }, { 0, 181, 25 }, { 0, 198, 28 }, { 0, 198, 28 }, { 0, 198, 28 }, { 0, 214, 30 }, { 33, 16, 31 }, + { 0, 231, 32 }, { 33, 33, 33 }, { 0, 247, 35 }, { 0, 247, 35 }, { 0, 247, 35 }, { 16, 165, 37 }, { 33, 66, 38 }, { 16, 181, 39 }, + { 33, 82, 40 }, { 16, 198, 42 }, { 16, 198, 42 }, { 16, 198, 42 }, { 16, 214, 44 }, { 33, 115, 45 }, { 16, 231, 46 }, { 33, 132, 47 }, + { 16, 247, 48 }, { 33, 148, 49 }, { 33, 148, 49 }, { 49, 66, 51 }, { 33, 165, 52 }, { 33, 165, 52 }, { 33, 181, 54 }, { 33, 181, 54 }, + { 33, 198, 56 }, { 66, 0, 57 }, { 33, 214, 58 }, { 66, 16, 59 }, { 33, 231, 61 }, { 33, 231, 61 }, { 33, 231, 61 }, { 33, 247, 63 }, + { 66, 49, 64 }, { 49, 165, 65 }, { 66, 66, 66 }, { 49, 181, 68 }, { 49, 181, 68 }, { 49, 181, 68 }, { 49, 198, 70 }, { 66, 99, 71 }, + { 49, 214, 72 }, { 66, 115, 73 }, { 49, 231, 75 }, { 49, 231, 75 }, { 49, 231, 75 }, { 49, 247, 77 }, { 66, 148, 78 }, { 66, 148, 78 }, + { 66, 165, 80 }, { 66, 165, 80 }, { 66, 181, 82 }, { 66, 181, 82 }, { 82, 99, 84 }, { 66, 198, 85 }, { 66, 198, 85 }, { 66, 214, 87 }, + { 66, 214, 87 }, { 66, 231, 89 }, { 99, 33, 90 }, { 66, 247, 91 }, { 99, 49, 92 }, { 82, 165, 94 }, { 82, 165, 94 }, { 82, 165, 94 }, + { 82, 181, 96 }, { 99, 82, 97 }, { 82, 198, 98 }, { 99, 99, 99 }, { 82, 214, 101 }, { 82, 214, 101 }, { 82, 214, 101 }, { 82, 231, 103 }, + { 99, 132, 104 }, { 82, 247, 105 }, { 99, 148, 106 }, { 99, 148, 106 }, { 99, 165, 108 }, { 99, 165, 108 }, { 115, 82, 110 }, { 99, 181, 111 }, + { 99, 181, 111 }, { 99, 198, 113 }, { 99, 198, 113 }, { 99, 214, 115 }, { 132, 16, 116 }, { 115, 132, 117 }, { 99, 231, 118 }, { 99, 231, 118 }, + { 99, 247, 120 }, { 99, 247, 120 }, { 115, 165, 122 }, { 132, 66, 123 }, { 115, 181, 124 }, { 132, 82, 125 }, { 115, 198, 127 }, { 115, 198, 127 }, + { 115, 198, 127 }, { 115, 214, 129 }, { 132, 115, 130 }, { 115, 231, 131 }, { 132, 132, 132 }, { 115, 247, 134 }, { 115, 247, 134 }, { 115, 247, 134 }, + { 148, 66, 136 }, { 132, 165, 137 }, { 132, 165, 137 }, { 132, 181, 139 }, { 132, 181, 139 }, { 132, 198, 141 }, { 165, 0, 142 }, { 148, 115, 143 }, + { 132, 214, 144 }, { 132, 214, 144 }, { 132, 231, 146 }, { 132, 231, 146 }, { 132, 247, 148 }, { 165, 49, 149 }, { 148, 165, 150 }, { 165, 66, 151 }, + { 148, 181, 153 }, { 148, 181, 153 }, { 148, 181, 153 }, { 148, 198, 155 }, { 165, 99, 156 }, { 148, 214, 157 }, { 165, 115, 158 }, { 148, 231, 160 }, + { 148, 231, 160 }, { 148, 231, 160 }, { 148, 247, 162 }, { 165, 148, 163 }, { 165, 148, 163 }, { 165, 165, 165 }, { 165, 165, 165 }, { 165, 181, 167 }, + { 165, 181, 167 }, { 181, 99, 169 }, { 165, 198, 170 }, { 165, 198, 170 }, { 165, 214, 172 }, { 165, 214, 172 }, { 165, 231, 174 }, { 198, 33, 175 }, + { 181, 148, 176 }, { 165, 247, 177 }, { 165, 247, 177 }, { 181, 165, 179 }, { 181, 165, 179 }, { 181, 181, 181 }, { 198, 82, 182 }, { 181, 198, 183 }, + { 198, 99, 184 }, { 181, 214, 186 }, { 181, 214, 186 }, { 181, 214, 186 }, { 181, 231, 188 }, { 198, 132, 189 }, { 181, 247, 190 }, { 198, 148, 191 }, + { 198, 148, 191 }, { 198, 165, 193 }, { 198, 165, 193 }, { 214, 82, 195 }, { 198, 181, 196 }, { 198, 181, 196 }, { 198, 198, 198 }, { 231, 0, 199 }, + { 198, 214, 200 }, { 231, 16, 201 }, { 214, 132, 202 }, { 198, 231, 203 }, { 198, 231, 203 }, { 198, 247, 205 }, { 198, 247, 205 }, { 214, 165, 207 }, + { 231, 66, 208 }, { 214, 181, 209 }, { 231, 82, 210 }, { 214, 198, 212 }, { 214, 198, 212 }, { 214, 198, 212 }, { 214, 214, 214 }, { 231, 115, 215 }, + { 214, 231, 216 }, { 231, 132, 217 }, { 214, 247, 219 }, { 214, 247, 219 }, { 214, 247, 219 }, { 231, 165, 222 }, { 231, 165, 222 }, { 231, 165, 222 }, + { 231, 181, 224 }, { 231, 181, 224 }, { 231, 198, 226 }, { 231, 198, 226 }, { 247, 115, 228 }, { 231, 214, 229 }, { 231, 214, 229 }, { 231, 231, 231 }, + { 231, 231, 231 }, { 231, 247, 233 }, { 231, 247, 233 }, { 247, 165, 235 }, { 247, 165, 235 }, { 247, 181, 238 }, { 247, 181, 238 }, { 247, 181, 238 }, + { 247, 198, 240 }, { 247, 198, 240 }, { 247, 214, 242 }, { 247, 214, 242 }, { 247, 231, 245 }, { 247, 231, 245 }, { 247, 231, 245 }, { 247, 247, 247 }, + { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, + } +}; + +Table g_mode0_p00_i2= +{ + 2, + 0, + { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 16, 5 }, { 0, 16, 5 }, { 0, 16, 5 }, { 0, 16, 5 }, { 0, 16, 5 }, + { 0, 33, 9 }, { 0, 33, 9 }, { 0, 33, 9 }, { 16, 0, 12 }, { 16, 0, 12 }, { 0, 49, 14 }, { 0, 49, 14 }, { 0, 49, 14 }, + { 16, 16, 16 }, { 16, 16, 16 }, { 0, 66, 19 }, { 0, 66, 19 }, { 0, 66, 19 }, { 16, 33, 21 }, { 0, 82, 23 }, { 0, 82, 23 }, + { 33, 0, 24 }, { 16, 49, 25 }, { 16, 49, 25 }, { 0, 99, 28 }, { 0, 99, 28 }, { 0, 99, 28 }, { 16, 66, 30 }, { 0, 115, 32 }, + { 0, 115, 32 }, { 33, 33, 33 }, { 16, 82, 35 }, { 16, 82, 35 }, { 0, 132, 37 }, { 0, 132, 37 }, { 33, 49, 38 }, { 16, 99, 39 }, + { 49, 16, 40 }, { 0, 148, 42 }, { 0, 148, 42 }, { 0, 148, 42 }, { 16, 115, 44 }, { 49, 33, 45 }, { 0, 165, 46 }, { 33, 82, 47 }, + { 16, 132, 49 }, { 16, 132, 49 }, { 0, 181, 51 }, { 0, 181, 51 }, { 33, 99, 52 }, { 16, 148, 53 }, { 49, 66, 54 }, { 0, 198, 56 }, + { 0, 198, 56 }, { 66, 33, 57 }, { 16, 165, 58 }, { 82, 0, 59 }, { 0, 214, 60 }, { 33, 132, 61 }, { 16, 181, 62 }, { 49, 99, 63 }, + { 0, 231, 65 }, { 0, 231, 65 }, { 66, 66, 66 }, { 16, 198, 67 }, { 49, 115, 68 }, { 0, 247, 69 }, { 33, 165, 70 }, { 66, 82, 71 }, + { 16, 214, 72 }, { 82, 49, 73 }, { 33, 181, 75 }, { 33, 181, 75 }, { 16, 231, 76 }, { 49, 148, 77 }, { 82, 66, 78 }, { 33, 198, 79 }, + { 66, 115, 80 }, { 16, 247, 81 }, { 49, 165, 82 }, { 115, 0, 83 }, { 33, 214, 84 }, { 66, 132, 85 }, { 49, 181, 86 }, { 82, 99, 87 }, + { 33, 231, 89 }, { 33, 231, 89 }, { 99, 66, 90 }, { 49, 198, 91 }, { 115, 33, 92 }, { 33, 247, 93 }, { 66, 165, 94 }, { 49, 214, 95 }, + { 82, 132, 96 }, { 66, 181, 98 }, { 66, 181, 98 }, { 99, 99, 99 }, { 49, 231, 100 }, { 82, 148, 101 }, { 66, 198, 103 }, { 66, 198, 103 }, + { 99, 115, 104 }, { 49, 247, 105 }, { 115, 82, 106 }, { 66, 214, 108 }, { 66, 214, 108 }, { 132, 49, 109 }, { 82, 181, 110 }, { 115, 99, 111 }, + { 66, 231, 112 }, { 99, 148, 113 }, { 82, 198, 115 }, { 82, 198, 115 }, { 148, 33, 116 }, { 66, 247, 117 }, { 99, 165, 118 }, { 82, 214, 119 }, + { 115, 132, 120 }, { 99, 181, 122 }, { 99, 181, 122 }, { 132, 99, 123 }, { 82, 231, 124 }, { 148, 66, 125 }, { 99, 198, 127 }, { 99, 198, 127 }, + { 82, 247, 128 }, { 115, 165, 129 }, { 181, 0, 130 }, { 99, 214, 131 }, { 132, 132, 132 }, { 115, 181, 134 }, { 115, 181, 134 }, { 181, 16, 135 }, + { 99, 231, 136 }, { 132, 148, 137 }, { 115, 198, 138 }, { 148, 115, 139 }, { 99, 247, 141 }, { 99, 247, 141 }, { 165, 82, 142 }, { 115, 214, 143 }, + { 148, 132, 144 }, { 132, 181, 146 }, { 132, 181, 146 }, { 198, 16, 147 }, { 115, 231, 148 }, { 181, 66, 149 }, { 132, 198, 151 }, { 132, 198, 151 }, + { 115, 247, 152 }, { 148, 165, 153 }, { 214, 0, 154 }, { 132, 214, 155 }, { 165, 132, 156 }, { 148, 181, 157 }, { 181, 99, 158 }, { 132, 231, 160 }, + { 132, 231, 160 }, { 198, 66, 161 }, { 148, 198, 162 }, { 214, 33, 163 }, { 132, 247, 164 }, { 165, 165, 165 }, { 231, 0, 166 }, { 148, 214, 167 }, + { 214, 49, 168 }, { 165, 181, 170 }, { 165, 181, 170 }, { 148, 231, 171 }, { 181, 148, 172 }, { 165, 198, 174 }, { 165, 198, 174 }, { 198, 115, 175 }, + { 148, 247, 176 }, { 181, 165, 177 }, { 247, 0, 178 }, { 165, 214, 179 }, { 231, 49, 180 }, { 181, 181, 181 }, { 214, 99, 182 }, { 165, 231, 184 }, + { 165, 231, 184 }, { 231, 66, 185 }, { 181, 198, 186 }, { 247, 33, 187 }, { 165, 247, 188 }, { 198, 165, 189 }, { 181, 214, 190 }, { 214, 132, 191 }, + { 198, 181, 193 }, { 198, 181, 193 }, { 231, 99, 194 }, { 181, 231, 195 }, { 247, 66, 196 }, { 198, 198, 198 }, { 198, 198, 198 }, { 181, 247, 200 }, + { 181, 247, 200 }, { 247, 82, 201 }, { 198, 214, 203 }, { 198, 214, 203 }, { 198, 214, 203 }, { 214, 181, 205 }, { 198, 231, 207 }, { 198, 231, 207 }, + { 231, 148, 208 }, { 214, 198, 210 }, { 214, 198, 210 }, { 198, 247, 212 }, { 198, 247, 212 }, { 198, 247, 212 }, { 214, 214, 214 }, { 247, 132, 215 }, + { 231, 181, 217 }, { 231, 181, 217 }, { 214, 231, 219 }, { 214, 231, 219 }, { 214, 231, 219 }, { 231, 198, 222 }, { 231, 198, 222 }, { 214, 247, 223 }, + { 247, 165, 224 }, { 231, 214, 226 }, { 231, 214, 226 }, { 231, 214, 226 }, { 247, 181, 228 }, { 247, 181, 228 }, { 231, 231, 231 }, { 231, 231, 231 }, + { 231, 231, 231 }, { 247, 198, 233 }, { 247, 198, 233 }, { 231, 247, 236 }, { 231, 247, 236 }, { 231, 247, 236 }, { 247, 214, 238 }, { 247, 214, 238 }, + { 247, 214, 238 }, { 247, 231, 243 }, { 247, 231, 243 }, { 247, 231, 243 }, { 247, 231, 243 }, { 247, 231, 243 }, { 247, 247, 247 }, { 247, 247, 247 }, + { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, + } +}; + +Table g_mode0_p00_i3= +{ + 3, + 0, + { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 16, 7 }, { 0, 16, 7 }, { 0, 16, 7 }, { 0, 16, 7 }, + { 0, 16, 7 }, { 16, 0, 9 }, { 16, 0, 9 }, { 16, 0, 9 }, { 0, 33, 14 }, { 0, 33, 14 }, { 0, 33, 14 }, { 0, 33, 14 }, + { 16, 16, 16 }, { 16, 16, 16 }, { 33, 0, 19 }, { 33, 0, 19 }, { 0, 49, 21 }, { 0, 49, 21 }, { 0, 49, 21 }, { 16, 33, 23 }, + { 16, 33, 23 }, { 33, 16, 26 }, { 33, 16, 26 }, { 0, 66, 28 }, { 0, 66, 28 }, { 0, 66, 28 }, { 16, 49, 30 }, { 16, 49, 30 }, + { 33, 33, 33 }, { 33, 33, 33 }, { 0, 82, 35 }, { 0, 82, 35 }, { 0, 82, 35 }, { 16, 66, 37 }, { 66, 0, 38 }, { 33, 49, 40 }, + { 33, 49, 40 }, { 0, 99, 42 }, { 0, 99, 42 }, { 0, 99, 42 }, { 16, 82, 44 }, { 66, 16, 45 }, { 33, 66, 47 }, { 33, 66, 47 }, + { 0, 115, 49 }, { 0, 115, 49 }, { 0, 115, 49 }, { 16, 99, 51 }, { 66, 33, 52 }, { 33, 82, 54 }, { 33, 82, 54 }, { 0, 132, 56 }, + { 0, 132, 56 }, { 99, 0, 57 }, { 16, 115, 58 }, { 66, 49, 59 }, { 33, 99, 61 }, { 33, 99, 61 }, { 0, 148, 62 }, { 49, 82, 63 }, + { 99, 16, 64 }, { 16, 132, 65 }, { 66, 66, 66 }, { 33, 115, 68 }, { 33, 115, 68 }, { 0, 165, 70 }, { 0, 165, 70 }, { 99, 33, 71 }, + { 16, 148, 72 }, { 66, 82, 73 }, { 33, 132, 75 }, { 33, 132, 75 }, { 0, 181, 76 }, { 49, 115, 77 }, { 99, 49, 78 }, { 16, 165, 79 }, + { 66, 99, 80 }, { 33, 148, 82 }, { 33, 148, 82 }, { 132, 16, 83 }, { 0, 198, 84 }, { 99, 66, 85 }, { 16, 181, 86 }, { 66, 115, 87 }, + { 33, 165, 89 }, { 33, 165, 89 }, { 0, 214, 90 }, { 49, 148, 91 }, { 99, 82, 92 }, { 16, 198, 93 }, { 66, 132, 94 }, { 33, 181, 95 }, + { 82, 115, 96 }, { 0, 231, 97 }, { 49, 165, 98 }, { 99, 99, 99 }, { 16, 214, 100 }, { 66, 148, 101 }, { 165, 16, 102 }, { 33, 198, 103 }, + { 0, 247, 104 }, { 49, 181, 105 }, { 99, 115, 106 }, { 16, 231, 107 }, { 66, 165, 108 }, { 33, 214, 109 }, { 82, 148, 110 }, { 132, 82, 111 }, + { 49, 198, 112 }, { 16, 247, 113 }, { 198, 0, 114 }, { 66, 181, 115 }, { 165, 49, 116 }, { 33, 231, 117 }, { 132, 99, 118 }, { 49, 214, 119 }, + { 99, 148, 120 }, { 198, 16, 121 }, { 66, 198, 122 }, { 33, 247, 123 }, { 82, 181, 124 }, { 132, 115, 125 }, { 49, 231, 126 }, { 99, 165, 127 }, + { 66, 214, 128 }, { 115, 148, 129 }, { 165, 82, 130 }, { 82, 198, 131 }, { 132, 132, 132 }, { 49, 247, 133 }, { 99, 181, 134 }, { 198, 49, 135 }, + { 66, 231, 136 }, { 165, 99, 137 }, { 82, 214, 138 }, { 132, 148, 139 }, { 231, 16, 140 }, { 99, 198, 141 }, { 66, 247, 142 }, { 115, 181, 143 }, + { 165, 115, 144 }, { 82, 231, 145 }, { 132, 165, 146 }, { 231, 33, 147 }, { 99, 214, 148 }, { 198, 82, 149 }, { 115, 198, 150 }, { 165, 132, 151 }, + { 82, 247, 152 }, { 132, 181, 153 }, { 231, 49, 154 }, { 99, 231, 155 }, { 198, 99, 156 }, { 115, 214, 157 }, { 165, 148, 158 }, { 132, 198, 160 }, + { 132, 198, 160 }, { 99, 247, 161 }, { 148, 181, 162 }, { 198, 115, 163 }, { 115, 231, 164 }, { 165, 165, 165 }, { 132, 214, 167 }, { 132, 214, 167 }, + { 231, 82, 168 }, { 148, 198, 169 }, { 198, 132, 170 }, { 115, 247, 171 }, { 165, 181, 172 }, { 132, 231, 174 }, { 132, 231, 174 }, { 231, 99, 175 }, + { 148, 214, 176 }, { 198, 148, 177 }, { 165, 198, 179 }, { 165, 198, 179 }, { 132, 247, 181 }, { 132, 247, 181 }, { 231, 115, 182 }, { 148, 231, 183 }, + { 198, 165, 184 }, { 247, 99, 185 }, { 165, 214, 186 }, { 165, 214, 186 }, { 181, 198, 188 }, { 231, 132, 189 }, { 148, 247, 190 }, { 198, 181, 191 }, + { 165, 231, 193 }, { 165, 231, 193 }, { 165, 231, 193 }, { 181, 214, 195 }, { 231, 148, 196 }, { 198, 198, 198 }, { 198, 198, 198 }, { 165, 247, 200 }, + { 165, 247, 200 }, { 165, 247, 200 }, { 181, 231, 202 }, { 231, 165, 203 }, { 198, 214, 205 }, { 198, 214, 205 }, { 198, 214, 205 }, { 214, 198, 207 }, + { 181, 247, 209 }, { 181, 247, 209 }, { 231, 181, 210 }, { 198, 231, 212 }, { 198, 231, 212 }, { 198, 231, 212 }, { 214, 214, 214 }, { 214, 214, 214 }, + { 231, 198, 217 }, { 231, 198, 217 }, { 198, 247, 219 }, { 198, 247, 219 }, { 198, 247, 219 }, { 214, 231, 221 }, { 214, 231, 221 }, { 231, 214, 224 }, + { 231, 214, 224 }, { 231, 214, 224 }, { 247, 198, 226 }, { 214, 247, 228 }, { 214, 247, 228 }, { 214, 247, 228 }, { 231, 231, 231 }, { 231, 231, 231 }, + { 231, 231, 231 }, { 247, 214, 233 }, { 247, 214, 233 }, { 247, 214, 233 }, { 231, 247, 238 }, { 231, 247, 238 }, { 231, 247, 238 }, { 231, 247, 238 }, + { 247, 231, 240 }, { 247, 231, 240 }, { 247, 231, 240 }, { 247, 231, 240 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, + { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, { 247, 247, 247 }, + } +}; + +Table g_mode0_p01_i1= +{ + 1, + 2, + { + { 0, 8, 1 }, { 0, 8, 1 }, { 0, 8, 1 }, { 0, 24, 3 }, { 0, 24, 3 }, { 0, 41, 6 }, { 0, 41, 6 }, { 0, 41, 6 }, + { 0, 57, 8 }, { 0, 57, 8 }, { 0, 74, 10 }, { 0, 74, 10 }, { 0, 90, 13 }, { 0, 90, 13 }, { 0, 90, 13 }, { 0, 107, 15 }, + { 0, 107, 15 }, { 0, 123, 17 }, { 0, 123, 17 }, { 0, 140, 20 }, { 0, 140, 20 }, { 0, 140, 20 }, { 0, 156, 22 }, { 0, 156, 22 }, + { 0, 173, 24 }, { 0, 173, 24 }, { 16, 90, 26 }, { 0, 189, 27 }, { 0, 189, 27 }, { 0, 206, 29 }, { 0, 206, 29 }, { 0, 222, 31 }, + { 33, 24, 32 }, { 16, 140, 33 }, { 0, 239, 34 }, { 0, 239, 34 }, { 0, 255, 36 }, { 0, 255, 36 }, { 16, 173, 38 }, { 33, 74, 39 }, + { 16, 189, 40 }, { 33, 90, 41 }, { 16, 206, 43 }, { 16, 206, 43 }, { 16, 206, 43 }, { 16, 222, 45 }, { 33, 123, 46 }, { 16, 239, 47 }, + { 33, 140, 48 }, { 16, 255, 50 }, { 16, 255, 50 }, { 16, 255, 50 }, { 33, 173, 53 }, { 33, 173, 53 }, { 33, 173, 53 }, { 33, 189, 55 }, + { 33, 189, 55 }, { 33, 206, 57 }, { 66, 8, 58 }, { 49, 123, 59 }, { 33, 222, 60 }, { 33, 222, 60 }, { 33, 239, 62 }, { 33, 239, 62 }, + { 33, 255, 64 }, { 66, 57, 65 }, { 49, 173, 66 }, { 66, 74, 67 }, { 49, 189, 69 }, { 49, 189, 69 }, { 49, 189, 69 }, { 49, 206, 71 }, + { 66, 107, 72 }, { 49, 222, 73 }, { 66, 123, 74 }, { 49, 239, 76 }, { 49, 239, 76 }, { 49, 239, 76 }, { 49, 255, 78 }, { 66, 156, 79 }, + { 66, 156, 79 }, { 66, 173, 81 }, { 66, 173, 81 }, { 66, 189, 83 }, { 66, 189, 83 }, { 66, 206, 86 }, { 66, 206, 86 }, { 66, 206, 86 }, + { 66, 222, 88 }, { 66, 222, 88 }, { 66, 239, 90 }, { 99, 41, 91 }, { 82, 156, 92 }, { 66, 255, 93 }, { 66, 255, 93 }, { 82, 173, 95 }, + { 82, 173, 95 }, { 82, 189, 97 }, { 99, 90, 98 }, { 82, 206, 99 }, { 99, 107, 100 }, { 82, 222, 102 }, { 82, 222, 102 }, { 82, 222, 102 }, + { 82, 239, 104 }, { 99, 140, 105 }, { 82, 255, 106 }, { 99, 156, 107 }, { 99, 156, 107 }, { 99, 173, 109 }, { 99, 173, 109 }, { 115, 90, 111 }, + { 99, 189, 112 }, { 99, 189, 112 }, { 99, 206, 114 }, { 132, 8, 115 }, { 99, 222, 116 }, { 132, 24, 117 }, { 99, 239, 119 }, { 99, 239, 119 }, + { 99, 239, 119 }, { 99, 255, 121 }, { 99, 255, 121 }, { 115, 173, 123 }, { 132, 74, 124 }, { 115, 189, 125 }, { 132, 90, 126 }, { 115, 206, 128 }, + { 115, 206, 128 }, { 115, 206, 128 }, { 115, 222, 130 }, { 132, 123, 131 }, { 115, 239, 132 }, { 132, 140, 133 }, { 115, 255, 135 }, { 115, 255, 135 }, + { 115, 255, 135 }, { 132, 173, 138 }, { 132, 173, 138 }, { 132, 173, 138 }, { 132, 189, 140 }, { 132, 189, 140 }, { 132, 206, 142 }, { 165, 8, 143 }, + { 148, 123, 144 }, { 132, 222, 145 }, { 132, 222, 145 }, { 132, 239, 147 }, { 165, 41, 148 }, { 132, 255, 149 }, { 165, 57, 150 }, { 148, 173, 152 }, + { 148, 173, 152 }, { 148, 173, 152 }, { 148, 189, 154 }, { 148, 189, 154 }, { 148, 206, 156 }, { 165, 107, 157 }, { 148, 222, 158 }, { 165, 123, 159 }, + { 148, 239, 161 }, { 148, 239, 161 }, { 148, 239, 161 }, { 148, 255, 163 }, { 165, 156, 164 }, { 165, 156, 164 }, { 165, 173, 166 }, { 165, 173, 166 }, + { 165, 189, 168 }, { 165, 189, 168 }, { 165, 206, 171 }, { 165, 206, 171 }, { 165, 206, 171 }, { 165, 222, 173 }, { 198, 24, 174 }, { 165, 239, 175 }, + { 198, 41, 176 }, { 181, 156, 177 }, { 165, 255, 178 }, { 165, 255, 178 }, { 181, 173, 180 }, { 198, 74, 181 }, { 181, 189, 182 }, { 198, 90, 183 }, + { 181, 206, 185 }, { 181, 206, 185 }, { 181, 206, 185 }, { 181, 222, 187 }, { 181, 222, 187 }, { 181, 239, 189 }, { 198, 140, 190 }, { 181, 255, 191 }, + { 198, 156, 192 }, { 198, 156, 192 }, { 198, 173, 194 }, { 198, 173, 194 }, { 198, 189, 197 }, { 198, 189, 197 }, { 198, 189, 197 }, { 198, 206, 199 }, + { 231, 8, 200 }, { 198, 222, 201 }, { 231, 24, 202 }, { 198, 239, 204 }, { 198, 239, 204 }, { 198, 239, 204 }, { 198, 255, 206 }, { 231, 57, 207 }, + { 214, 173, 208 }, { 231, 74, 209 }, { 214, 189, 210 }, { 231, 90, 211 }, { 214, 206, 213 }, { 214, 206, 213 }, { 231, 107, 214 }, { 214, 222, 215 }, + { 231, 123, 216 }, { 214, 239, 218 }, { 214, 239, 218 }, { 214, 239, 218 }, { 214, 255, 220 }, { 214, 255, 220 }, { 231, 173, 223 }, { 231, 173, 223 }, + { 231, 173, 223 }, { 231, 189, 225 }, { 231, 189, 225 }, { 231, 206, 227 }, { 231, 206, 227 }, { 231, 222, 230 }, { 231, 222, 230 }, { 231, 222, 230 }, + { 231, 239, 232 }, { 231, 239, 232 }, { 231, 255, 234 }, { 231, 255, 234 }, { 247, 173, 237 }, { 247, 173, 237 }, { 247, 173, 237 }, { 247, 189, 239 }, + { 247, 189, 239 }, { 247, 206, 241 }, { 247, 206, 241 }, { 247, 222, 243 }, { 247, 222, 243 }, { 247, 239, 246 }, { 247, 239, 246 }, { 247, 239, 246 }, + { 247, 255, 248 }, { 247, 255, 248 }, { 247, 255, 248 }, { 247, 255, 248 }, { 247, 255, 248 }, { 247, 255, 248 }, { 247, 255, 248 }, { 247, 255, 248 }, + } +}; + +Table g_mode0_p01_i2= +{ + 2, + 2, + { + { 0, 8, 2 }, { 0, 8, 2 }, { 0, 8, 2 }, { 0, 8, 2 }, { 0, 8, 2 }, { 0, 24, 7 }, { 0, 24, 7 }, { 0, 24, 7 }, + { 0, 24, 7 }, { 0, 24, 7 }, { 0, 41, 12 }, { 0, 41, 12 }, { 0, 41, 12 }, { 0, 41, 12 }, { 16, 8, 14 }, { 0, 57, 16 }, + { 0, 57, 16 }, { 0, 57, 16 }, { 16, 24, 18 }, { 16, 24, 18 }, { 0, 74, 21 }, { 0, 74, 21 }, { 0, 74, 21 }, { 16, 41, 23 }, + { 0, 90, 25 }, { 0, 90, 25 }, { 33, 8, 26 }, { 16, 57, 28 }, { 16, 57, 28 }, { 0, 107, 30 }, { 0, 107, 30 }, { 0, 107, 30 }, + { 16, 74, 32 }, { 16, 74, 32 }, { 0, 123, 35 }, { 0, 123, 35 }, { 0, 123, 35 }, { 16, 90, 37 }, { 0, 140, 39 }, { 0, 140, 39 }, + { 33, 57, 40 }, { 16, 107, 42 }, { 16, 107, 42 }, { 0, 156, 44 }, { 0, 156, 44 }, { 33, 74, 45 }, { 16, 123, 46 }, { 49, 41, 47 }, + { 0, 173, 49 }, { 0, 173, 49 }, { 66, 8, 50 }, { 16, 140, 51 }, { 0, 189, 53 }, { 0, 189, 53 }, { 33, 107, 54 }, { 16, 156, 55 }, + { 49, 74, 56 }, { 0, 206, 58 }, { 0, 206, 58 }, { 66, 41, 59 }, { 16, 173, 60 }, { 49, 90, 61 }, { 0, 222, 62 }, { 33, 140, 63 }, + { 16, 189, 65 }, { 16, 189, 65 }, { 82, 24, 66 }, { 0, 239, 67 }, { 33, 156, 68 }, { 16, 206, 69 }, { 49, 123, 70 }, { 0, 255, 72 }, + { 0, 255, 72 }, { 66, 90, 73 }, { 16, 222, 74 }, { 49, 140, 75 }, { 33, 189, 77 }, { 33, 189, 77 }, { 66, 107, 78 }, { 16, 239, 79 }, + { 82, 74, 80 }, { 33, 206, 82 }, { 33, 206, 82 }, { 16, 255, 83 }, { 49, 173, 84 }, { 115, 8, 85 }, { 33, 222, 86 }, { 66, 140, 87 }, + { 49, 189, 88 }, { 82, 107, 89 }, { 33, 239, 91 }, { 33, 239, 91 }, { 99, 74, 92 }, { 49, 206, 93 }, { 82, 123, 94 }, { 33, 255, 95 }, + { 66, 173, 96 }, { 132, 8, 97 }, { 49, 222, 98 }, { 115, 57, 99 }, { 66, 189, 101 }, { 66, 189, 101 }, { 49, 239, 102 }, { 82, 156, 103 }, + { 66, 206, 105 }, { 66, 206, 105 }, { 99, 123, 106 }, { 49, 255, 107 }, { 82, 173, 108 }, { 148, 8, 109 }, { 66, 222, 110 }, { 99, 140, 111 }, + { 82, 189, 112 }, { 115, 107, 113 }, { 66, 239, 115 }, { 66, 239, 115 }, { 132, 74, 116 }, { 82, 206, 117 }, { 148, 41, 118 }, { 66, 255, 119 }, + { 99, 173, 120 }, { 82, 222, 121 }, { 115, 140, 122 }, { 99, 189, 124 }, { 99, 189, 124 }, { 132, 107, 125 }, { 82, 239, 126 }, { 115, 156, 127 }, + { 99, 206, 129 }, { 99, 206, 129 }, { 165, 41, 130 }, { 82, 255, 131 }, { 148, 90, 132 }, { 99, 222, 134 }, { 99, 222, 134 }, { 165, 57, 135 }, + { 115, 189, 136 }, { 181, 24, 137 }, { 99, 239, 138 }, { 132, 156, 139 }, { 115, 206, 141 }, { 115, 206, 141 }, { 181, 41, 142 }, { 99, 255, 143 }, + { 132, 173, 144 }, { 115, 222, 145 }, { 148, 140, 146 }, { 132, 189, 148 }, { 132, 189, 148 }, { 165, 107, 149 }, { 115, 239, 150 }, { 181, 74, 151 }, + { 132, 206, 153 }, { 132, 206, 153 }, { 115, 255, 154 }, { 148, 173, 155 }, { 214, 8, 156 }, { 132, 222, 157 }, { 165, 140, 158 }, { 148, 189, 160 }, + { 148, 189, 160 }, { 214, 24, 161 }, { 132, 239, 162 }, { 198, 74, 163 }, { 148, 206, 164 }, { 181, 123, 165 }, { 132, 255, 167 }, { 132, 255, 167 }, + { 198, 90, 168 }, { 148, 222, 169 }, { 214, 57, 170 }, { 165, 189, 172 }, { 165, 189, 172 }, { 231, 24, 173 }, { 148, 239, 174 }, { 214, 74, 175 }, + { 165, 206, 177 }, { 165, 206, 177 }, { 148, 255, 178 }, { 181, 173, 179 }, { 247, 8, 180 }, { 165, 222, 181 }, { 198, 140, 182 }, { 181, 189, 183 }, + { 214, 107, 184 }, { 165, 239, 186 }, { 165, 239, 186 }, { 231, 74, 187 }, { 181, 206, 188 }, { 247, 41, 189 }, { 165, 255, 190 }, { 198, 173, 191 }, + { 181, 222, 193 }, { 181, 222, 193 }, { 247, 57, 194 }, { 198, 189, 195 }, { 231, 107, 196 }, { 181, 239, 197 }, { 214, 156, 198 }, { 198, 206, 200 }, + { 198, 206, 200 }, { 231, 123, 201 }, { 181, 255, 202 }, { 247, 90, 203 }, { 198, 222, 205 }, { 198, 222, 205 }, { 198, 222, 205 }, { 214, 189, 207 }, + { 247, 107, 208 }, { 198, 239, 210 }, { 198, 239, 210 }, { 198, 239, 210 }, { 214, 206, 212 }, { 198, 255, 214 }, { 198, 255, 214 }, { 231, 173, 215 }, + { 214, 222, 216 }, { 247, 140, 217 }, { 231, 189, 219 }, { 231, 189, 219 }, { 214, 239, 221 }, { 214, 239, 221 }, { 214, 239, 221 }, { 231, 206, 224 }, + { 231, 206, 224 }, { 214, 255, 226 }, { 214, 255, 226 }, { 214, 255, 226 }, { 231, 222, 228 }, { 231, 222, 228 }, { 247, 189, 231 }, { 247, 189, 231 }, + { 231, 239, 233 }, { 231, 239, 233 }, { 231, 239, 233 }, { 247, 206, 235 }, { 247, 206, 235 }, { 231, 255, 238 }, { 231, 255, 238 }, { 231, 255, 238 }, + { 247, 222, 240 }, { 247, 222, 240 }, { 247, 222, 240 }, { 247, 239, 245 }, { 247, 239, 245 }, { 247, 239, 245 }, { 247, 239, 245 }, { 247, 239, 245 }, + { 247, 255, 249 }, { 247, 255, 249 }, { 247, 255, 249 }, { 247, 255, 249 }, { 247, 255, 249 }, { 247, 255, 249 }, { 247, 255, 249 }, { 247, 255, 249 }, + } +}; + +Table g_mode0_p01_i3= +{ + 3, + 2, + { + { 0, 8, 3 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 24, 10 }, + { 0, 24, 10 }, { 0, 24, 10 }, { 0, 24, 10 }, { 0, 24, 10 }, { 16, 8, 13 }, { 16, 8, 13 }, { 16, 8, 13 }, { 0, 41, 17 }, + { 0, 41, 17 }, { 0, 41, 17 }, { 0, 41, 17 }, { 16, 24, 19 }, { 16, 24, 19 }, { 33, 8, 22 }, { 33, 8, 22 }, { 0, 57, 24 }, + { 0, 57, 24 }, { 0, 57, 24 }, { 16, 41, 27 }, { 16, 41, 27 }, { 16, 41, 27 }, { 33, 24, 29 }, { 0, 74, 31 }, { 0, 74, 31 }, + { 49, 8, 32 }, { 16, 57, 33 }, { 16, 57, 33 }, { 33, 41, 36 }, { 33, 41, 36 }, { 0, 90, 38 }, { 0, 90, 38 }, { 0, 90, 38 }, + { 16, 74, 40 }, { 16, 74, 40 }, { 66, 8, 42 }, { 33, 57, 43 }, { 0, 107, 45 }, { 0, 107, 45 }, { 49, 41, 46 }, { 16, 90, 47 }, + { 66, 24, 48 }, { 33, 74, 50 }, { 33, 74, 50 }, { 82, 8, 51 }, { 0, 123, 52 }, { 0, 123, 52 }, { 16, 107, 54 }, { 66, 41, 55 }, + { 33, 90, 57 }, { 33, 90, 57 }, { 82, 24, 58 }, { 0, 140, 59 }, { 49, 74, 60 }, { 16, 123, 61 }, { 66, 57, 62 }, { 33, 107, 64 }, + { 33, 107, 64 }, { 82, 41, 65 }, { 0, 156, 66 }, { 99, 24, 67 }, { 16, 140, 68 }, { 66, 74, 69 }, { 115, 8, 70 }, { 33, 123, 71 }, + { 0, 173, 73 }, { 0, 173, 73 }, { 0, 173, 73 }, { 16, 156, 75 }, { 66, 90, 76 }, { 115, 24, 77 }, { 33, 140, 78 }, { 82, 74, 79 }, + { 0, 189, 80 }, { 99, 57, 81 }, { 16, 173, 82 }, { 66, 107, 83 }, { 115, 41, 84 }, { 33, 156, 85 }, { 132, 24, 86 }, { 0, 206, 87 }, + { 99, 74, 88 }, { 16, 189, 89 }, { 66, 123, 90 }, { 115, 57, 91 }, { 33, 173, 92 }, { 82, 107, 93 }, { 0, 222, 94 }, { 99, 90, 95 }, + { 16, 206, 96 }, { 66, 140, 97 }, { 115, 74, 98 }, { 33, 189, 99 }, { 132, 57, 100 }, { 0, 239, 101 }, { 99, 107, 102 }, { 16, 222, 103 }, + { 66, 156, 104 }, { 33, 206, 106 }, { 33, 206, 106 }, { 0, 255, 108 }, { 0, 255, 108 }, { 99, 123, 109 }, { 16, 239, 110 }, { 66, 173, 111 }, + { 115, 107, 112 }, { 33, 222, 113 }, { 132, 90, 114 }, { 49, 206, 115 }, { 99, 140, 116 }, { 16, 255, 117 }, { 66, 189, 118 }, { 165, 57, 119 }, + { 33, 239, 120 }, { 132, 107, 121 }, { 49, 222, 122 }, { 99, 156, 123 }, { 148, 90, 124 }, { 66, 206, 125 }, { 115, 140, 126 }, { 33, 255, 127 }, + { 132, 123, 128 }, { 49, 239, 129 }, { 99, 173, 130 }, { 148, 107, 131 }, { 66, 222, 132 }, { 165, 90, 133 }, { 82, 206, 134 }, { 132, 140, 135 }, + { 49, 255, 136 }, { 99, 189, 137 }, { 66, 239, 139 }, { 66, 239, 139 }, { 66, 239, 139 }, { 82, 222, 141 }, { 132, 156, 142 }, { 181, 90, 143 }, + { 99, 206, 144 }, { 148, 140, 145 }, { 66, 255, 146 }, { 165, 123, 147 }, { 82, 239, 148 }, { 132, 173, 149 }, { 181, 107, 150 }, { 99, 222, 151 }, + { 198, 90, 152 }, { 115, 206, 153 }, { 165, 140, 154 }, { 82, 255, 155 }, { 132, 189, 156 }, { 181, 123, 157 }, { 99, 239, 158 }, { 148, 173, 159 }, + { 115, 222, 160 }, { 165, 156, 161 }, { 214, 90, 162 }, { 132, 206, 163 }, { 181, 140, 164 }, { 99, 255, 165 }, { 198, 123, 166 }, { 115, 239, 167 }, + { 165, 173, 168 }, { 214, 107, 169 }, { 132, 222, 170 }, { 132, 222, 170 }, { 148, 206, 172 }, { 115, 255, 174 }, { 115, 255, 174 }, { 165, 189, 175 }, + { 214, 123, 176 }, { 132, 239, 177 }, { 181, 173, 178 }, { 148, 222, 179 }, { 198, 156, 180 }, { 247, 90, 181 }, { 165, 206, 182 }, { 214, 140, 183 }, + { 132, 255, 184 }, { 231, 123, 185 }, { 148, 239, 186 }, { 198, 173, 187 }, { 247, 107, 188 }, { 165, 222, 189 }, { 214, 156, 190 }, { 181, 206, 192 }, + { 181, 206, 192 }, { 148, 255, 193 }, { 198, 189, 194 }, { 247, 123, 195 }, { 165, 239, 196 }, { 214, 173, 197 }, { 181, 222, 198 }, { 231, 156, 199 }, + { 198, 206, 201 }, { 198, 206, 201 }, { 247, 140, 202 }, { 165, 255, 203 }, { 165, 255, 203 }, { 181, 239, 205 }, { 181, 239, 205 }, { 231, 173, 207 }, + { 198, 222, 208 }, { 247, 156, 209 }, { 214, 206, 211 }, { 214, 206, 211 }, { 181, 255, 212 }, { 231, 189, 213 }, { 198, 239, 215 }, { 198, 239, 215 }, + { 247, 173, 216 }, { 214, 222, 217 }, { 214, 222, 217 }, { 231, 206, 220 }, { 231, 206, 220 }, { 198, 255, 222 }, { 198, 255, 222 }, { 247, 189, 223 }, + { 214, 239, 225 }, { 214, 239, 225 }, { 214, 239, 225 }, { 231, 222, 227 }, { 231, 222, 227 }, { 247, 206, 230 }, { 247, 206, 230 }, { 214, 255, 231 }, + { 214, 255, 231 }, { 231, 239, 234 }, { 231, 239, 234 }, { 231, 239, 234 }, { 247, 222, 236 }, { 247, 222, 236 }, { 247, 222, 236 }, { 231, 255, 241 }, + { 231, 255, 241 }, { 231, 255, 241 }, { 231, 255, 241 }, { 247, 239, 244 }, { 247, 239, 244 }, { 247, 239, 244 }, { 247, 239, 244 }, { 247, 239, 244 }, + { 247, 255, 250 }, { 247, 255, 250 }, { 247, 255, 250 }, { 247, 255, 250 }, { 247, 255, 250 }, { 247, 255, 250 }, { 247, 255, 250 }, { 247, 255, 250 }, + } +}; + +Table g_mode0_p10_i1= +{ + 1, + 1, + { + { 8, 0, 7 }, { 8, 0, 7 }, { 8, 0, 7 }, { 8, 0, 7 }, { 8, 0, 7 }, { 8, 0, 7 }, { 8, 0, 7 }, { 8, 0, 7 }, + { 8, 0, 7 }, { 8, 16, 9 }, { 8, 16, 9 }, { 8, 33, 12 }, { 8, 33, 12 }, { 8, 33, 12 }, { 8, 49, 14 }, { 8, 49, 14 }, + { 8, 66, 16 }, { 8, 66, 16 }, { 8, 82, 18 }, { 8, 82, 18 }, { 8, 99, 21 }, { 8, 99, 21 }, { 8, 99, 21 }, { 8, 115, 23 }, + { 8, 115, 23 }, { 8, 132, 25 }, { 8, 132, 25 }, { 8, 148, 28 }, { 8, 148, 28 }, { 8, 148, 28 }, { 8, 165, 30 }, { 8, 165, 30 }, + { 8, 181, 32 }, { 8, 181, 32 }, { 8, 198, 35 }, { 8, 198, 35 }, { 8, 198, 35 }, { 8, 214, 37 }, { 8, 214, 37 }, { 8, 231, 39 }, + { 41, 33, 40 }, { 24, 148, 41 }, { 8, 247, 42 }, { 8, 247, 42 }, { 24, 165, 44 }, { 41, 66, 45 }, { 24, 181, 46 }, { 41, 82, 47 }, + { 24, 198, 48 }, { 41, 99, 49 }, { 24, 214, 51 }, { 24, 214, 51 }, { 24, 214, 51 }, { 24, 231, 53 }, { 41, 132, 54 }, { 24, 247, 55 }, + { 41, 148, 56 }, { 41, 148, 56 }, { 41, 165, 58 }, { 41, 165, 58 }, { 41, 181, 61 }, { 41, 181, 61 }, { 41, 181, 61 }, { 41, 198, 63 }, + { 74, 0, 64 }, { 41, 214, 65 }, { 74, 16, 66 }, { 41, 231, 68 }, { 41, 231, 68 }, { 41, 231, 68 }, { 41, 247, 70 }, { 41, 247, 70 }, + { 57, 165, 72 }, { 74, 66, 73 }, { 57, 181, 74 }, { 74, 82, 75 }, { 57, 198, 77 }, { 57, 198, 77 }, { 74, 99, 78 }, { 57, 214, 79 }, + { 74, 115, 80 }, { 57, 231, 81 }, { 74, 132, 82 }, { 57, 247, 84 }, { 57, 247, 84 }, { 57, 247, 84 }, { 74, 165, 87 }, { 74, 165, 87 }, + { 74, 165, 87 }, { 74, 181, 89 }, { 74, 181, 89 }, { 74, 198, 91 }, { 107, 0, 92 }, { 74, 214, 94 }, { 74, 214, 94 }, { 74, 214, 94 }, + { 74, 231, 96 }, { 107, 33, 97 }, { 74, 247, 98 }, { 107, 49, 99 }, { 90, 165, 101 }, { 90, 165, 101 }, { 90, 165, 101 }, { 90, 181, 103 }, + { 90, 181, 103 }, { 90, 198, 105 }, { 107, 99, 106 }, { 90, 214, 107 }, { 107, 115, 108 }, { 90, 231, 110 }, { 90, 231, 110 }, { 107, 132, 111 }, + { 90, 247, 112 }, { 107, 148, 113 }, { 107, 148, 113 }, { 107, 165, 115 }, { 107, 165, 115 }, { 107, 181, 117 }, { 107, 181, 117 }, { 107, 198, 120 }, + { 107, 198, 120 }, { 107, 198, 120 }, { 107, 214, 122 }, { 140, 16, 123 }, { 107, 231, 124 }, { 140, 33, 125 }, { 107, 247, 127 }, { 107, 247, 127 }, + { 107, 247, 127 }, { 123, 165, 129 }, { 140, 66, 130 }, { 123, 181, 131 }, { 140, 82, 132 }, { 123, 198, 134 }, { 123, 198, 134 }, { 123, 198, 134 }, + { 123, 214, 136 }, { 123, 214, 136 }, { 123, 231, 138 }, { 140, 132, 139 }, { 123, 247, 140 }, { 140, 148, 141 }, { 140, 148, 141 }, { 156, 66, 143 }, + { 140, 165, 144 }, { 140, 165, 144 }, { 140, 181, 146 }, { 140, 181, 146 }, { 140, 198, 148 }, { 173, 0, 149 }, { 140, 214, 150 }, { 173, 16, 151 }, + { 140, 231, 153 }, { 140, 231, 153 }, { 140, 231, 153 }, { 140, 247, 155 }, { 173, 49, 156 }, { 156, 165, 157 }, { 173, 66, 158 }, { 156, 181, 160 }, + { 156, 181, 160 }, { 156, 181, 160 }, { 156, 198, 162 }, { 173, 99, 163 }, { 156, 214, 164 }, { 173, 115, 165 }, { 156, 231, 167 }, { 156, 231, 167 }, + { 156, 231, 167 }, { 156, 247, 169 }, { 156, 247, 169 }, { 173, 165, 172 }, { 173, 165, 172 }, { 173, 165, 172 }, { 173, 181, 174 }, { 173, 181, 174 }, + { 189, 99, 176 }, { 173, 198, 177 }, { 173, 198, 177 }, { 173, 214, 179 }, { 173, 214, 179 }, { 173, 231, 181 }, { 206, 33, 182 }, { 173, 247, 183 }, + { 206, 49, 184 }, { 189, 165, 186 }, { 189, 165, 186 }, { 189, 165, 186 }, { 189, 181, 188 }, { 206, 82, 189 }, { 189, 198, 190 }, { 206, 99, 191 }, + { 189, 214, 193 }, { 189, 214, 193 }, { 189, 214, 193 }, { 189, 231, 195 }, { 206, 132, 196 }, { 189, 247, 197 }, { 206, 148, 198 }, { 206, 148, 198 }, + { 206, 165, 200 }, { 206, 165, 200 }, { 206, 181, 202 }, { 206, 181, 202 }, { 206, 198, 205 }, { 206, 198, 205 }, { 206, 198, 205 }, { 206, 214, 207 }, + { 239, 16, 208 }, { 222, 132, 209 }, { 206, 231, 210 }, { 206, 231, 210 }, { 206, 247, 212 }, { 206, 247, 212 }, { 222, 165, 214 }, { 239, 66, 215 }, + { 222, 181, 216 }, { 239, 82, 217 }, { 222, 198, 219 }, { 222, 198, 219 }, { 222, 198, 219 }, { 222, 214, 221 }, { 239, 115, 222 }, { 222, 231, 223 }, + { 239, 132, 224 }, { 222, 247, 226 }, { 222, 247, 226 }, { 222, 247, 226 }, { 255, 66, 228 }, { 239, 165, 229 }, { 239, 165, 229 }, { 239, 181, 231 }, + { 239, 181, 231 }, { 239, 198, 233 }, { 239, 198, 233 }, { 239, 214, 235 }, { 239, 214, 235 }, { 239, 231, 238 }, { 239, 231, 238 }, { 239, 231, 238 }, + { 239, 247, 240 }, { 239, 247, 240 }, { 255, 165, 242 }, { 255, 165, 242 }, { 255, 181, 245 }, { 255, 181, 245 }, { 255, 181, 245 }, { 255, 198, 247 }, + { 255, 198, 247 }, { 255, 214, 249 }, { 255, 214, 249 }, { 255, 231, 252 }, { 255, 231, 252 }, { 255, 231, 252 }, { 255, 247, 254 }, { 255, 247, 254 }, + } +}; + +Table g_mode0_p10_i2= +{ + 2, + 1, + { + { 8, 0, 6 }, { 8, 0, 6 }, { 8, 0, 6 }, { 8, 0, 6 }, { 8, 0, 6 }, { 8, 0, 6 }, { 8, 0, 6 }, { 8, 0, 6 }, + { 8, 0, 6 }, { 8, 16, 10 }, { 8, 16, 10 }, { 8, 16, 10 }, { 8, 16, 10 }, { 8, 33, 15 }, { 8, 33, 15 }, { 8, 33, 15 }, + { 8, 33, 15 }, { 24, 0, 17 }, { 24, 0, 17 }, { 8, 49, 20 }, { 8, 49, 20 }, { 8, 49, 20 }, { 24, 16, 22 }, { 8, 66, 24 }, + { 8, 66, 24 }, { 8, 66, 24 }, { 24, 33, 27 }, { 24, 33, 27 }, { 8, 82, 29 }, { 8, 82, 29 }, { 8, 82, 29 }, { 24, 49, 31 }, + { 24, 49, 31 }, { 8, 99, 34 }, { 8, 99, 34 }, { 8, 99, 34 }, { 24, 66, 36 }, { 8, 115, 38 }, { 8, 115, 38 }, { 41, 33, 39 }, + { 24, 82, 40 }, { 57, 0, 41 }, { 8, 132, 43 }, { 8, 132, 43 }, { 8, 132, 43 }, { 24, 99, 45 }, { 8, 148, 47 }, { 8, 148, 47 }, + { 41, 66, 48 }, { 24, 115, 50 }, { 24, 115, 50 }, { 8, 165, 52 }, { 8, 165, 52 }, { 41, 82, 53 }, { 24, 132, 54 }, { 57, 49, 55 }, + { 8, 181, 57 }, { 8, 181, 57 }, { 74, 16, 58 }, { 24, 148, 59 }, { 57, 66, 60 }, { 8, 198, 61 }, { 41, 115, 62 }, { 24, 165, 64 }, + { 24, 165, 64 }, { 90, 0, 65 }, { 8, 214, 66 }, { 41, 132, 67 }, { 24, 181, 68 }, { 57, 99, 69 }, { 8, 231, 71 }, { 8, 231, 71 }, + { 74, 66, 72 }, { 24, 198, 73 }, { 90, 33, 74 }, { 8, 247, 75 }, { 41, 165, 76 }, { 24, 214, 77 }, { 57, 132, 78 }, { 41, 181, 80 }, + { 41, 181, 80 }, { 74, 99, 81 }, { 24, 231, 82 }, { 57, 148, 83 }, { 41, 198, 85 }, { 41, 198, 85 }, { 74, 115, 86 }, { 24, 247, 87 }, + { 90, 82, 88 }, { 41, 214, 90 }, { 41, 214, 90 }, { 107, 49, 91 }, { 57, 181, 92 }, { 90, 99, 93 }, { 41, 231, 94 }, { 74, 148, 95 }, + { 57, 198, 97 }, { 57, 198, 97 }, { 123, 33, 98 }, { 41, 247, 99 }, { 74, 165, 100 }, { 57, 214, 101 }, { 90, 132, 102 }, { 74, 181, 104 }, + { 74, 181, 104 }, { 107, 99, 105 }, { 57, 231, 106 }, { 123, 66, 107 }, { 74, 198, 109 }, { 74, 198, 109 }, { 57, 247, 110 }, { 90, 165, 111 }, + { 156, 0, 112 }, { 74, 214, 113 }, { 107, 132, 114 }, { 90, 181, 116 }, { 90, 181, 116 }, { 156, 16, 117 }, { 74, 231, 118 }, { 107, 148, 119 }, + { 90, 198, 120 }, { 123, 115, 121 }, { 74, 247, 123 }, { 74, 247, 123 }, { 140, 82, 124 }, { 90, 214, 125 }, { 123, 132, 126 }, { 107, 181, 128 }, + { 107, 181, 128 }, { 173, 16, 129 }, { 90, 231, 130 }, { 156, 66, 131 }, { 107, 198, 133 }, { 107, 198, 133 }, { 90, 247, 134 }, { 123, 165, 135 }, + { 189, 0, 136 }, { 107, 214, 137 }, { 140, 132, 138 }, { 123, 181, 139 }, { 156, 99, 140 }, { 107, 231, 142 }, { 107, 231, 142 }, { 173, 66, 143 }, + { 123, 198, 144 }, { 189, 33, 145 }, { 107, 247, 146 }, { 140, 165, 147 }, { 206, 0, 148 }, { 123, 214, 149 }, { 189, 49, 150 }, { 140, 181, 152 }, + { 140, 181, 152 }, { 123, 231, 153 }, { 156, 148, 154 }, { 140, 198, 156 }, { 140, 198, 156 }, { 173, 115, 157 }, { 123, 247, 158 }, { 156, 165, 159 }, + { 222, 0, 160 }, { 140, 214, 161 }, { 206, 49, 162 }, { 156, 181, 163 }, { 189, 99, 164 }, { 140, 231, 166 }, { 140, 231, 166 }, { 206, 66, 167 }, + { 156, 198, 168 }, { 222, 33, 169 }, { 140, 247, 170 }, { 173, 165, 171 }, { 156, 214, 172 }, { 189, 132, 173 }, { 173, 181, 175 }, { 173, 181, 175 }, + { 206, 99, 176 }, { 156, 231, 177 }, { 222, 66, 178 }, { 173, 198, 180 }, { 173, 198, 180 }, { 239, 33, 181 }, { 156, 247, 182 }, { 222, 82, 183 }, + { 173, 214, 185 }, { 173, 214, 185 }, { 239, 49, 186 }, { 189, 181, 187 }, { 255, 16, 188 }, { 173, 231, 189 }, { 206, 148, 190 }, { 189, 198, 192 }, + { 189, 198, 192 }, { 255, 33, 193 }, { 173, 247, 194 }, { 239, 82, 195 }, { 189, 214, 196 }, { 222, 132, 197 }, { 206, 181, 199 }, { 206, 181, 199 }, + { 239, 99, 200 }, { 189, 231, 201 }, { 255, 66, 202 }, { 206, 198, 204 }, { 206, 198, 204 }, { 189, 247, 205 }, { 222, 165, 206 }, { 206, 214, 208 }, + { 206, 214, 208 }, { 239, 132, 209 }, { 222, 181, 210 }, { 255, 99, 211 }, { 206, 231, 213 }, { 206, 231, 213 }, { 206, 231, 213 }, { 222, 198, 215 }, + { 255, 115, 216 }, { 206, 247, 218 }, { 206, 247, 218 }, { 206, 247, 218 }, { 222, 214, 220 }, { 222, 214, 220 }, { 239, 181, 223 }, { 239, 181, 223 }, + { 222, 231, 225 }, { 222, 231, 225 }, { 222, 231, 225 }, { 239, 198, 227 }, { 222, 247, 229 }, { 222, 247, 229 }, { 255, 165, 230 }, { 239, 214, 232 }, + { 239, 214, 232 }, { 239, 214, 232 }, { 255, 181, 234 }, { 255, 181, 234 }, { 239, 231, 237 }, { 239, 231, 237 }, { 239, 231, 237 }, { 255, 198, 239 }, + { 239, 247, 241 }, { 239, 247, 241 }, { 239, 247, 241 }, { 255, 214, 243 }, { 255, 214, 243 }, { 255, 214, 243 }, { 255, 231, 248 }, { 255, 231, 248 }, + { 255, 231, 248 }, { 255, 231, 248 }, { 255, 231, 248 }, { 255, 247, 253 }, { 255, 247, 253 }, { 255, 247, 253 }, { 255, 247, 253 }, { 255, 247, 253 }, + } +}; + +Table g_mode0_p10_i3= +{ + 3, + 3, + { + { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, + { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 24, 15 }, { 8, 24, 15 }, { 8, 24, 15 }, { 8, 24, 15 }, + { 8, 24, 15 }, { 24, 8, 17 }, { 24, 8, 17 }, { 24, 8, 17 }, { 8, 41, 22 }, { 8, 41, 22 }, { 8, 41, 22 }, { 8, 41, 22 }, + { 24, 24, 24 }, { 24, 24, 24 }, { 41, 8, 27 }, { 41, 8, 27 }, { 8, 57, 29 }, { 8, 57, 29 }, { 8, 57, 29 }, { 24, 41, 31 }, + { 24, 41, 31 }, { 41, 24, 34 }, { 41, 24, 34 }, { 8, 74, 36 }, { 8, 74, 36 }, { 8, 74, 36 }, { 24, 57, 38 }, { 24, 57, 38 }, + { 41, 41, 41 }, { 41, 41, 41 }, { 8, 90, 43 }, { 8, 90, 43 }, { 8, 90, 43 }, { 24, 74, 45 }, { 74, 8, 46 }, { 41, 57, 48 }, + { 41, 57, 48 }, { 8, 107, 50 }, { 8, 107, 50 }, { 8, 107, 50 }, { 24, 90, 52 }, { 74, 24, 53 }, { 41, 74, 55 }, { 41, 74, 55 }, + { 8, 123, 57 }, { 8, 123, 57 }, { 8, 123, 57 }, { 24, 107, 59 }, { 74, 41, 60 }, { 41, 90, 62 }, { 41, 90, 62 }, { 8, 140, 64 }, + { 8, 140, 64 }, { 107, 8, 65 }, { 24, 123, 66 }, { 74, 57, 67 }, { 41, 107, 69 }, { 41, 107, 69 }, { 8, 156, 70 }, { 57, 90, 71 }, + { 107, 24, 72 }, { 24, 140, 73 }, { 74, 74, 74 }, { 41, 123, 76 }, { 41, 123, 76 }, { 8, 173, 78 }, { 8, 173, 78 }, { 107, 41, 79 }, + { 24, 156, 80 }, { 74, 90, 81 }, { 41, 140, 83 }, { 41, 140, 83 }, { 8, 189, 84 }, { 57, 123, 85 }, { 107, 57, 86 }, { 24, 173, 87 }, + { 74, 107, 88 }, { 41, 156, 90 }, { 41, 156, 90 }, { 140, 24, 91 }, { 8, 206, 92 }, { 107, 74, 93 }, { 24, 189, 94 }, { 74, 123, 95 }, + { 41, 173, 97 }, { 41, 173, 97 }, { 8, 222, 98 }, { 57, 156, 99 }, { 107, 90, 100 }, { 24, 206, 101 }, { 74, 140, 102 }, { 41, 189, 103 }, + { 90, 123, 104 }, { 8, 239, 105 }, { 57, 173, 106 }, { 107, 107, 107 }, { 24, 222, 108 }, { 74, 156, 109 }, { 173, 24, 110 }, { 41, 206, 111 }, + { 8, 255, 112 }, { 57, 189, 113 }, { 107, 123, 114 }, { 24, 239, 115 }, { 74, 173, 116 }, { 41, 222, 117 }, { 90, 156, 118 }, { 140, 90, 119 }, + { 57, 206, 120 }, { 24, 255, 121 }, { 206, 8, 122 }, { 74, 189, 123 }, { 173, 57, 124 }, { 41, 239, 125 }, { 140, 107, 126 }, { 57, 222, 127 }, + { 107, 156, 128 }, { 206, 24, 129 }, { 74, 206, 130 }, { 41, 255, 131 }, { 90, 189, 132 }, { 140, 123, 133 }, { 57, 239, 134 }, { 107, 173, 135 }, + { 74, 222, 136 }, { 123, 156, 137 }, { 173, 90, 138 }, { 90, 206, 139 }, { 140, 140, 140 }, { 57, 255, 141 }, { 107, 189, 142 }, { 206, 57, 143 }, + { 74, 239, 144 }, { 173, 107, 145 }, { 90, 222, 146 }, { 140, 156, 147 }, { 239, 24, 148 }, { 107, 206, 149 }, { 74, 255, 150 }, { 123, 189, 151 }, + { 173, 123, 152 }, { 90, 239, 153 }, { 140, 173, 154 }, { 239, 41, 155 }, { 107, 222, 156 }, { 206, 90, 157 }, { 123, 206, 158 }, { 173, 140, 159 }, + { 90, 255, 160 }, { 140, 189, 161 }, { 239, 57, 162 }, { 107, 239, 163 }, { 206, 107, 164 }, { 123, 222, 165 }, { 173, 156, 166 }, { 140, 206, 168 }, + { 140, 206, 168 }, { 107, 255, 169 }, { 156, 189, 170 }, { 206, 123, 171 }, { 123, 239, 172 }, { 173, 173, 173 }, { 140, 222, 175 }, { 140, 222, 175 }, + { 239, 90, 176 }, { 156, 206, 177 }, { 206, 140, 178 }, { 123, 255, 179 }, { 173, 189, 180 }, { 140, 239, 182 }, { 140, 239, 182 }, { 239, 107, 183 }, + { 156, 222, 184 }, { 206, 156, 185 }, { 173, 206, 187 }, { 173, 206, 187 }, { 140, 255, 189 }, { 140, 255, 189 }, { 239, 123, 190 }, { 156, 239, 191 }, + { 206, 173, 192 }, { 255, 107, 193 }, { 173, 222, 194 }, { 173, 222, 194 }, { 189, 206, 196 }, { 239, 140, 197 }, { 156, 255, 198 }, { 206, 189, 199 }, + { 173, 239, 201 }, { 173, 239, 201 }, { 173, 239, 201 }, { 189, 222, 203 }, { 239, 156, 204 }, { 206, 206, 206 }, { 206, 206, 206 }, { 173, 255, 208 }, + { 173, 255, 208 }, { 173, 255, 208 }, { 189, 239, 210 }, { 239, 173, 211 }, { 206, 222, 213 }, { 206, 222, 213 }, { 206, 222, 213 }, { 222, 206, 215 }, + { 189, 255, 217 }, { 189, 255, 217 }, { 239, 189, 218 }, { 206, 239, 220 }, { 206, 239, 220 }, { 206, 239, 220 }, { 222, 222, 222 }, { 222, 222, 222 }, + { 239, 206, 225 }, { 239, 206, 225 }, { 206, 255, 227 }, { 206, 255, 227 }, { 206, 255, 227 }, { 222, 239, 229 }, { 222, 239, 229 }, { 239, 222, 232 }, + { 239, 222, 232 }, { 239, 222, 232 }, { 255, 206, 234 }, { 222, 255, 236 }, { 222, 255, 236 }, { 222, 255, 236 }, { 239, 239, 239 }, { 239, 239, 239 }, + { 239, 239, 239 }, { 255, 222, 241 }, { 255, 222, 241 }, { 255, 222, 241 }, { 239, 255, 246 }, { 239, 255, 246 }, { 239, 255, 246 }, { 239, 255, 246 }, + { 255, 239, 248 }, { 255, 239, 248 }, { 255, 239, 248 }, { 255, 239, 248 }, { 255, 255, 255 }, { 255, 255, 255 }, { 255, 255, 255 }, { 255, 255, 255 }, + } +}; + +Table g_mode0_p11_i1= +{ + 1, + 3, + { + { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, + { 8, 8, 8 }, { 8, 8, 8 }, { 8, 24, 10 }, { 8, 24, 10 }, { 8, 41, 13 }, { 8, 41, 13 }, { 8, 41, 13 }, { 8, 57, 15 }, + { 8, 57, 15 }, { 8, 74, 17 }, { 8, 74, 17 }, { 8, 90, 20 }, { 8, 90, 20 }, { 8, 90, 20 }, { 8, 107, 22 }, { 8, 107, 22 }, + { 8, 123, 24 }, { 8, 123, 24 }, { 24, 41, 26 }, { 8, 140, 27 }, { 8, 140, 27 }, { 8, 156, 29 }, { 8, 156, 29 }, { 8, 173, 31 }, + { 8, 173, 31 }, { 8, 189, 33 }, { 8, 189, 33 }, { 8, 206, 36 }, { 8, 206, 36 }, { 8, 206, 36 }, { 8, 222, 38 }, { 41, 24, 39 }, + { 8, 239, 40 }, { 41, 41, 41 }, { 8, 255, 43 }, { 8, 255, 43 }, { 8, 255, 43 }, { 24, 173, 45 }, { 41, 74, 46 }, { 24, 189, 47 }, + { 41, 90, 48 }, { 24, 206, 50 }, { 24, 206, 50 }, { 24, 206, 50 }, { 24, 222, 52 }, { 41, 123, 53 }, { 24, 239, 54 }, { 41, 140, 55 }, + { 24, 255, 56 }, { 41, 156, 57 }, { 41, 156, 57 }, { 57, 74, 59 }, { 41, 173, 60 }, { 41, 173, 60 }, { 41, 189, 62 }, { 41, 189, 62 }, + { 41, 206, 64 }, { 74, 8, 65 }, { 41, 222, 66 }, { 74, 24, 67 }, { 41, 239, 69 }, { 41, 239, 69 }, { 41, 239, 69 }, { 41, 255, 71 }, + { 74, 57, 72 }, { 57, 173, 73 }, { 74, 74, 74 }, { 57, 189, 76 }, { 57, 189, 76 }, { 57, 189, 76 }, { 57, 206, 78 }, { 74, 107, 79 }, + { 57, 222, 80 }, { 74, 123, 81 }, { 57, 239, 83 }, { 57, 239, 83 }, { 57, 239, 83 }, { 57, 255, 85 }, { 74, 156, 86 }, { 74, 156, 86 }, + { 74, 173, 88 }, { 74, 173, 88 }, { 74, 189, 90 }, { 74, 189, 90 }, { 90, 107, 92 }, { 74, 206, 93 }, { 74, 206, 93 }, { 74, 222, 95 }, + { 74, 222, 95 }, { 74, 239, 97 }, { 107, 41, 98 }, { 74, 255, 99 }, { 107, 57, 100 }, { 90, 173, 102 }, { 90, 173, 102 }, { 90, 173, 102 }, + { 90, 189, 104 }, { 107, 90, 105 }, { 90, 206, 106 }, { 107, 107, 107 }, { 90, 222, 109 }, { 90, 222, 109 }, { 90, 222, 109 }, { 90, 239, 111 }, + { 107, 140, 112 }, { 90, 255, 113 }, { 107, 156, 114 }, { 107, 156, 114 }, { 107, 173, 116 }, { 107, 173, 116 }, { 123, 90, 118 }, { 107, 189, 119 }, + { 107, 189, 119 }, { 107, 206, 121 }, { 107, 206, 121 }, { 107, 222, 123 }, { 140, 24, 124 }, { 123, 140, 125 }, { 107, 239, 126 }, { 107, 239, 126 }, + { 107, 255, 128 }, { 107, 255, 128 }, { 123, 173, 130 }, { 140, 74, 131 }, { 123, 189, 132 }, { 140, 90, 133 }, { 123, 206, 135 }, { 123, 206, 135 }, + { 123, 206, 135 }, { 123, 222, 137 }, { 140, 123, 138 }, { 123, 239, 139 }, { 140, 140, 140 }, { 123, 255, 142 }, { 123, 255, 142 }, { 123, 255, 142 }, + { 156, 74, 144 }, { 140, 173, 145 }, { 140, 173, 145 }, { 140, 189, 147 }, { 140, 189, 147 }, { 140, 206, 149 }, { 173, 8, 150 }, { 156, 123, 151 }, + { 140, 222, 152 }, { 140, 222, 152 }, { 140, 239, 154 }, { 140, 239, 154 }, { 140, 255, 156 }, { 173, 57, 157 }, { 156, 173, 158 }, { 173, 74, 159 }, + { 156, 189, 161 }, { 156, 189, 161 }, { 156, 189, 161 }, { 156, 206, 163 }, { 173, 107, 164 }, { 156, 222, 165 }, { 173, 123, 166 }, { 156, 239, 168 }, + { 156, 239, 168 }, { 156, 239, 168 }, { 156, 255, 170 }, { 173, 156, 171 }, { 173, 156, 171 }, { 173, 173, 173 }, { 173, 173, 173 }, { 173, 189, 175 }, + { 173, 189, 175 }, { 189, 107, 177 }, { 173, 206, 178 }, { 173, 206, 178 }, { 173, 222, 180 }, { 173, 222, 180 }, { 173, 239, 182 }, { 206, 41, 183 }, + { 189, 156, 184 }, { 173, 255, 185 }, { 173, 255, 185 }, { 189, 173, 187 }, { 189, 173, 187 }, { 189, 189, 189 }, { 206, 90, 190 }, { 189, 206, 191 }, + { 206, 107, 192 }, { 189, 222, 194 }, { 189, 222, 194 }, { 189, 222, 194 }, { 189, 239, 196 }, { 206, 140, 197 }, { 189, 255, 198 }, { 206, 156, 199 }, + { 206, 156, 199 }, { 206, 173, 201 }, { 206, 173, 201 }, { 222, 90, 203 }, { 206, 189, 204 }, { 206, 189, 204 }, { 206, 206, 206 }, { 239, 8, 207 }, + { 206, 222, 208 }, { 239, 24, 209 }, { 222, 140, 210 }, { 206, 239, 211 }, { 206, 239, 211 }, { 206, 255, 213 }, { 206, 255, 213 }, { 222, 173, 215 }, + { 239, 74, 216 }, { 222, 189, 217 }, { 239, 90, 218 }, { 222, 206, 220 }, { 222, 206, 220 }, { 222, 206, 220 }, { 222, 222, 222 }, { 239, 123, 223 }, + { 222, 239, 224 }, { 239, 140, 225 }, { 222, 255, 227 }, { 222, 255, 227 }, { 222, 255, 227 }, { 239, 173, 230 }, { 239, 173, 230 }, { 239, 173, 230 }, + { 239, 189, 232 }, { 239, 189, 232 }, { 239, 206, 234 }, { 239, 206, 234 }, { 255, 123, 236 }, { 239, 222, 237 }, { 239, 222, 237 }, { 239, 239, 239 }, + { 239, 239, 239 }, { 239, 255, 241 }, { 239, 255, 241 }, { 255, 173, 243 }, { 255, 173, 243 }, { 255, 189, 246 }, { 255, 189, 246 }, { 255, 189, 246 }, + { 255, 206, 248 }, { 255, 206, 248 }, { 255, 222, 250 }, { 255, 222, 250 }, { 255, 239, 253 }, { 255, 239, 253 }, { 255, 239, 253 }, { 255, 255, 255 }, + } +}; + +Table g_mode0_p11_i2= +{ + 2, + 3, + { + { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, + { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 24, 13 }, { 8, 24, 13 }, { 8, 24, 13 }, { 8, 24, 13 }, { 8, 24, 13 }, + { 8, 41, 17 }, { 8, 41, 17 }, { 8, 41, 17 }, { 24, 8, 20 }, { 24, 8, 20 }, { 8, 57, 22 }, { 8, 57, 22 }, { 8, 57, 22 }, + { 24, 24, 24 }, { 24, 24, 24 }, { 8, 74, 27 }, { 8, 74, 27 }, { 8, 74, 27 }, { 24, 41, 29 }, { 8, 90, 31 }, { 8, 90, 31 }, + { 41, 8, 32 }, { 24, 57, 33 }, { 24, 57, 33 }, { 8, 107, 36 }, { 8, 107, 36 }, { 8, 107, 36 }, { 24, 74, 38 }, { 8, 123, 40 }, + { 8, 123, 40 }, { 41, 41, 41 }, { 24, 90, 43 }, { 24, 90, 43 }, { 8, 140, 45 }, { 8, 140, 45 }, { 41, 57, 46 }, { 24, 107, 47 }, + { 57, 24, 48 }, { 8, 156, 50 }, { 8, 156, 50 }, { 8, 156, 50 }, { 24, 123, 52 }, { 57, 41, 53 }, { 8, 173, 54 }, { 41, 90, 55 }, + { 24, 140, 57 }, { 24, 140, 57 }, { 8, 189, 59 }, { 8, 189, 59 }, { 41, 107, 60 }, { 24, 156, 61 }, { 57, 74, 62 }, { 8, 206, 64 }, + { 8, 206, 64 }, { 74, 41, 65 }, { 24, 173, 66 }, { 90, 8, 67 }, { 8, 222, 68 }, { 41, 140, 69 }, { 24, 189, 70 }, { 57, 107, 71 }, + { 8, 239, 73 }, { 8, 239, 73 }, { 74, 74, 74 }, { 24, 206, 75 }, { 57, 123, 76 }, { 8, 255, 77 }, { 41, 173, 78 }, { 74, 90, 79 }, + { 24, 222, 80 }, { 90, 57, 81 }, { 41, 189, 83 }, { 41, 189, 83 }, { 24, 239, 84 }, { 57, 156, 85 }, { 90, 74, 86 }, { 41, 206, 87 }, + { 74, 123, 88 }, { 24, 255, 89 }, { 57, 173, 90 }, { 123, 8, 91 }, { 41, 222, 92 }, { 74, 140, 93 }, { 57, 189, 94 }, { 90, 107, 95 }, + { 41, 239, 97 }, { 41, 239, 97 }, { 107, 74, 98 }, { 57, 206, 99 }, { 123, 41, 100 }, { 41, 255, 101 }, { 74, 173, 102 }, { 57, 222, 103 }, + { 90, 140, 104 }, { 74, 189, 106 }, { 74, 189, 106 }, { 107, 107, 107 }, { 57, 239, 108 }, { 90, 156, 109 }, { 74, 206, 111 }, { 74, 206, 111 }, + { 107, 123, 112 }, { 57, 255, 113 }, { 123, 90, 114 }, { 74, 222, 116 }, { 74, 222, 116 }, { 140, 57, 117 }, { 90, 189, 118 }, { 123, 107, 119 }, + { 74, 239, 120 }, { 107, 156, 121 }, { 90, 206, 123 }, { 90, 206, 123 }, { 156, 41, 124 }, { 74, 255, 125 }, { 107, 173, 126 }, { 90, 222, 127 }, + { 123, 140, 128 }, { 107, 189, 130 }, { 107, 189, 130 }, { 140, 107, 131 }, { 90, 239, 132 }, { 156, 74, 133 }, { 107, 206, 135 }, { 107, 206, 135 }, + { 90, 255, 136 }, { 123, 173, 137 }, { 189, 8, 138 }, { 107, 222, 139 }, { 140, 140, 140 }, { 123, 189, 142 }, { 123, 189, 142 }, { 189, 24, 143 }, + { 107, 239, 144 }, { 140, 156, 145 }, { 123, 206, 146 }, { 156, 123, 147 }, { 107, 255, 149 }, { 107, 255, 149 }, { 173, 90, 150 }, { 123, 222, 151 }, + { 156, 140, 152 }, { 140, 189, 154 }, { 140, 189, 154 }, { 206, 24, 155 }, { 123, 239, 156 }, { 189, 74, 157 }, { 140, 206, 159 }, { 140, 206, 159 }, + { 123, 255, 160 }, { 156, 173, 161 }, { 222, 8, 162 }, { 140, 222, 163 }, { 173, 140, 164 }, { 156, 189, 165 }, { 189, 107, 166 }, { 140, 239, 168 }, + { 140, 239, 168 }, { 206, 74, 169 }, { 156, 206, 170 }, { 222, 41, 171 }, { 140, 255, 172 }, { 173, 173, 173 }, { 239, 8, 174 }, { 156, 222, 175 }, + { 222, 57, 176 }, { 173, 189, 178 }, { 173, 189, 178 }, { 156, 239, 179 }, { 189, 156, 180 }, { 173, 206, 182 }, { 173, 206, 182 }, { 206, 123, 183 }, + { 156, 255, 184 }, { 189, 173, 185 }, { 255, 8, 186 }, { 173, 222, 187 }, { 239, 57, 188 }, { 189, 189, 189 }, { 222, 107, 190 }, { 173, 239, 192 }, + { 173, 239, 192 }, { 239, 74, 193 }, { 189, 206, 194 }, { 255, 41, 195 }, { 173, 255, 196 }, { 206, 173, 197 }, { 189, 222, 198 }, { 222, 140, 199 }, + { 206, 189, 201 }, { 206, 189, 201 }, { 239, 107, 202 }, { 189, 239, 203 }, { 255, 74, 204 }, { 206, 206, 206 }, { 206, 206, 206 }, { 189, 255, 208 }, + { 189, 255, 208 }, { 255, 90, 209 }, { 206, 222, 211 }, { 206, 222, 211 }, { 206, 222, 211 }, { 222, 189, 213 }, { 206, 239, 215 }, { 206, 239, 215 }, + { 239, 156, 216 }, { 222, 206, 218 }, { 222, 206, 218 }, { 206, 255, 220 }, { 206, 255, 220 }, { 206, 255, 220 }, { 222, 222, 222 }, { 255, 140, 223 }, + { 239, 189, 225 }, { 239, 189, 225 }, { 222, 239, 227 }, { 222, 239, 227 }, { 222, 239, 227 }, { 239, 206, 230 }, { 239, 206, 230 }, { 222, 255, 231 }, + { 255, 173, 232 }, { 239, 222, 234 }, { 239, 222, 234 }, { 239, 222, 234 }, { 255, 189, 236 }, { 255, 189, 236 }, { 239, 239, 239 }, { 239, 239, 239 }, + { 239, 239, 239 }, { 255, 206, 241 }, { 255, 206, 241 }, { 239, 255, 244 }, { 239, 255, 244 }, { 239, 255, 244 }, { 255, 222, 246 }, { 255, 222, 246 }, + { 255, 222, 246 }, { 255, 239, 251 }, { 255, 239, 251 }, { 255, 239, 251 }, { 255, 239, 251 }, { 255, 239, 251 }, { 255, 255, 255 }, { 255, 255, 255 }, + } +}; + +Table g_mode0_p11_i3= +{ + 3, + 3, + { + { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, + { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 8, 8 }, { 8, 24, 15 }, { 8, 24, 15 }, { 8, 24, 15 }, { 8, 24, 15 }, + { 8, 24, 15 }, { 24, 8, 17 }, { 24, 8, 17 }, { 24, 8, 17 }, { 8, 41, 22 }, { 8, 41, 22 }, { 8, 41, 22 }, { 8, 41, 22 }, + { 24, 24, 24 }, { 24, 24, 24 }, { 41, 8, 27 }, { 41, 8, 27 }, { 8, 57, 29 }, { 8, 57, 29 }, { 8, 57, 29 }, { 24, 41, 31 }, + { 24, 41, 31 }, { 41, 24, 34 }, { 41, 24, 34 }, { 8, 74, 36 }, { 8, 74, 36 }, { 8, 74, 36 }, { 24, 57, 38 }, { 24, 57, 38 }, + { 41, 41, 41 }, { 41, 41, 41 }, { 8, 90, 43 }, { 8, 90, 43 }, { 8, 90, 43 }, { 24, 74, 45 }, { 74, 8, 46 }, { 41, 57, 48 }, + { 41, 57, 48 }, { 8, 107, 50 }, { 8, 107, 50 }, { 8, 107, 50 }, { 24, 90, 52 }, { 74, 24, 53 }, { 41, 74, 55 }, { 41, 74, 55 }, + { 8, 123, 57 }, { 8, 123, 57 }, { 8, 123, 57 }, { 24, 107, 59 }, { 74, 41, 60 }, { 41, 90, 62 }, { 41, 90, 62 }, { 8, 140, 64 }, + { 8, 140, 64 }, { 107, 8, 65 }, { 24, 123, 66 }, { 74, 57, 67 }, { 41, 107, 69 }, { 41, 107, 69 }, { 8, 156, 70 }, { 57, 90, 71 }, + { 107, 24, 72 }, { 24, 140, 73 }, { 74, 74, 74 }, { 41, 123, 76 }, { 41, 123, 76 }, { 8, 173, 78 }, { 8, 173, 78 }, { 107, 41, 79 }, + { 24, 156, 80 }, { 74, 90, 81 }, { 41, 140, 83 }, { 41, 140, 83 }, { 8, 189, 84 }, { 57, 123, 85 }, { 107, 57, 86 }, { 24, 173, 87 }, + { 74, 107, 88 }, { 41, 156, 90 }, { 41, 156, 90 }, { 140, 24, 91 }, { 8, 206, 92 }, { 107, 74, 93 }, { 24, 189, 94 }, { 74, 123, 95 }, + { 41, 173, 97 }, { 41, 173, 97 }, { 8, 222, 98 }, { 57, 156, 99 }, { 107, 90, 100 }, { 24, 206, 101 }, { 74, 140, 102 }, { 41, 189, 103 }, + { 90, 123, 104 }, { 8, 239, 105 }, { 57, 173, 106 }, { 107, 107, 107 }, { 24, 222, 108 }, { 74, 156, 109 }, { 173, 24, 110 }, { 41, 206, 111 }, + { 8, 255, 112 }, { 57, 189, 113 }, { 107, 123, 114 }, { 24, 239, 115 }, { 74, 173, 116 }, { 41, 222, 117 }, { 90, 156, 118 }, { 140, 90, 119 }, + { 57, 206, 120 }, { 24, 255, 121 }, { 206, 8, 122 }, { 74, 189, 123 }, { 173, 57, 124 }, { 41, 239, 125 }, { 140, 107, 126 }, { 57, 222, 127 }, + { 107, 156, 128 }, { 206, 24, 129 }, { 74, 206, 130 }, { 41, 255, 131 }, { 90, 189, 132 }, { 140, 123, 133 }, { 57, 239, 134 }, { 107, 173, 135 }, + { 74, 222, 136 }, { 123, 156, 137 }, { 173, 90, 138 }, { 90, 206, 139 }, { 140, 140, 140 }, { 57, 255, 141 }, { 107, 189, 142 }, { 206, 57, 143 }, + { 74, 239, 144 }, { 173, 107, 145 }, { 90, 222, 146 }, { 140, 156, 147 }, { 239, 24, 148 }, { 107, 206, 149 }, { 74, 255, 150 }, { 123, 189, 151 }, + { 173, 123, 152 }, { 90, 239, 153 }, { 140, 173, 154 }, { 239, 41, 155 }, { 107, 222, 156 }, { 206, 90, 157 }, { 123, 206, 158 }, { 173, 140, 159 }, + { 90, 255, 160 }, { 140, 189, 161 }, { 239, 57, 162 }, { 107, 239, 163 }, { 206, 107, 164 }, { 123, 222, 165 }, { 173, 156, 166 }, { 140, 206, 168 }, + { 140, 206, 168 }, { 107, 255, 169 }, { 156, 189, 170 }, { 206, 123, 171 }, { 123, 239, 172 }, { 173, 173, 173 }, { 140, 222, 175 }, { 140, 222, 175 }, + { 239, 90, 176 }, { 156, 206, 177 }, { 206, 140, 178 }, { 123, 255, 179 }, { 173, 189, 180 }, { 140, 239, 182 }, { 140, 239, 182 }, { 239, 107, 183 }, + { 156, 222, 184 }, { 206, 156, 185 }, { 173, 206, 187 }, { 173, 206, 187 }, { 140, 255, 189 }, { 140, 255, 189 }, { 239, 123, 190 }, { 156, 239, 191 }, + { 206, 173, 192 }, { 255, 107, 193 }, { 173, 222, 194 }, { 173, 222, 194 }, { 189, 206, 196 }, { 239, 140, 197 }, { 156, 255, 198 }, { 206, 189, 199 }, + { 173, 239, 201 }, { 173, 239, 201 }, { 173, 239, 201 }, { 189, 222, 203 }, { 239, 156, 204 }, { 206, 206, 206 }, { 206, 206, 206 }, { 173, 255, 208 }, + { 173, 255, 208 }, { 173, 255, 208 }, { 189, 239, 210 }, { 239, 173, 211 }, { 206, 222, 213 }, { 206, 222, 213 }, { 206, 222, 213 }, { 222, 206, 215 }, + { 189, 255, 217 }, { 189, 255, 217 }, { 239, 189, 218 }, { 206, 239, 220 }, { 206, 239, 220 }, { 206, 239, 220 }, { 222, 222, 222 }, { 222, 222, 222 }, + { 239, 206, 225 }, { 239, 206, 225 }, { 206, 255, 227 }, { 206, 255, 227 }, { 206, 255, 227 }, { 222, 239, 229 }, { 222, 239, 229 }, { 239, 222, 232 }, + { 239, 222, 232 }, { 239, 222, 232 }, { 255, 206, 234 }, { 222, 255, 236 }, { 222, 255, 236 }, { 222, 255, 236 }, { 239, 239, 239 }, { 239, 239, 239 }, + { 239, 239, 239 }, { 255, 222, 241 }, { 255, 222, 241 }, { 255, 222, 241 }, { 239, 255, 246 }, { 239, 255, 246 }, { 239, 255, 246 }, { 239, 255, 246 }, + { 255, 239, 248 }, { 255, 239, 248 }, { 255, 239, 248 }, { 255, 239, 248 }, { 255, 255, 255 }, { 255, 255, 255 }, { 255, 255, 255 }, { 255, 255, 255 }, + } +}; + +Table g_mode1_p0_i1= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 4, 1 }, { 0, 12, 2 }, { 0, 20, 3 }, { 0, 28, 4 }, { 0, 32, 5 }, { 0, 40, 6 }, { 0, 48, 7 }, + { 0, 56, 8 }, { 0, 64, 9 }, { 0, 68, 10 }, { 0, 76, 11 }, { 0, 84, 12 }, { 0, 92, 13 }, { 0, 96, 14 }, { 0, 104, 15 }, + { 0, 112, 16 }, { 0, 120, 17 }, { 0, 129, 18 }, { 0, 133, 19 }, { 0, 141, 20 }, { 0, 149, 21 }, { 0, 153, 22 }, { 0, 161, 23 }, + { 0, 169, 24 }, { 0, 177, 25 }, { 0, 185, 26 }, { 0, 189, 27 }, { 0, 197, 28 }, { 0, 205, 29 }, { 0, 213, 30 }, { 0, 217, 31 }, + { 0, 225, 32 }, { 0, 233, 33 }, { 0, 241, 34 }, { 0, 249, 35 }, { 0, 253, 36 }, { 4, 237, 37 }, { 4, 245, 38 }, { 4, 253, 39 }, + { 8, 233, 40 }, { 8, 241, 41 }, { 8, 249, 42 }, { 12, 229, 43 }, { 12, 237, 44 }, { 12, 245, 45 }, { 12, 253, 46 }, { 16, 233, 47 }, + { 16, 241, 48 }, { 16, 249, 49 }, { 20, 233, 50 }, { 20, 237, 51 }, { 20, 245, 52 }, { 20, 253, 53 }, { 24, 237, 54 }, { 24, 241, 55 }, + { 24, 249, 56 }, { 28, 233, 57 }, { 28, 241, 58 }, { 28, 245, 59 }, { 28, 253, 60 }, { 32, 237, 61 }, { 32, 245, 62 }, { 32, 249, 63 }, + { 36, 233, 64 }, { 36, 241, 65 }, { 36, 249, 66 }, { 36, 253, 67 }, { 40, 237, 68 }, { 40, 245, 69 }, { 40, 253, 70 }, { 44, 233, 71 }, + { 44, 241, 72 }, { 44, 249, 73 }, { 48, 233, 74 }, { 48, 237, 75 }, { 48, 245, 76 }, { 48, 253, 77 }, { 52, 237, 78 }, { 52, 241, 79 }, + { 52, 249, 80 }, { 56, 233, 81 }, { 56, 241, 82 }, { 56, 245, 83 }, { 56, 253, 84 }, { 60, 237, 85 }, { 60, 245, 86 }, { 60, 249, 87 }, + { 64, 233, 88 }, { 64, 241, 89 }, { 64, 249, 90 }, { 64, 253, 91 }, { 68, 237, 92 }, { 68, 245, 93 }, { 68, 253, 94 }, { 72, 233, 95 }, + { 72, 241, 96 }, { 72, 249, 97 }, { 76, 229, 98 }, { 76, 237, 99 }, { 76, 245, 100 }, { 76, 253, 101 }, { 80, 233, 102 }, { 80, 241, 103 }, + { 80, 249, 104 }, { 84, 233, 105 }, { 84, 237, 106 }, { 84, 245, 107 }, { 84, 253, 108 }, { 88, 237, 109 }, { 88, 241, 110 }, { 88, 249, 111 }, + { 92, 233, 112 }, { 92, 241, 113 }, { 92, 245, 114 }, { 92, 253, 115 }, { 96, 237, 116 }, { 96, 245, 117 }, { 96, 249, 118 }, { 100, 233, 119 }, + { 100, 241, 120 }, { 100, 249, 121 }, { 100, 253, 122 }, { 104, 237, 123 }, { 104, 245, 124 }, { 104, 253, 125 }, { 108, 233, 126 }, { 108, 241, 127 }, + { 108, 249, 128 }, { 112, 233, 129 }, { 112, 237, 130 }, { 112, 245, 131 }, { 112, 253, 132 }, { 116, 237, 133 }, { 116, 241, 134 }, { 116, 249, 135 }, + { 120, 233, 136 }, { 120, 241, 137 }, { 120, 245, 138 }, { 120, 253, 139 }, { 124, 237, 140 }, { 124, 245, 141 }, { 124, 249, 142 }, { 129, 225, 143 }, + { 129, 233, 144 }, { 129, 241, 145 }, { 129, 249, 146 }, { 133, 229, 147 }, { 133, 237, 148 }, { 133, 245, 149 }, { 133, 253, 150 }, { 137, 233, 151 }, + { 137, 241, 152 }, { 137, 249, 153 }, { 141, 233, 154 }, { 141, 237, 155 }, { 141, 245, 156 }, { 141, 253, 157 }, { 145, 237, 158 }, { 145, 241, 159 }, + { 145, 249, 160 }, { 149, 233, 161 }, { 149, 241, 162 }, { 149, 245, 163 }, { 149, 253, 164 }, { 153, 237, 165 }, { 153, 245, 166 }, { 153, 249, 167 }, + { 157, 233, 168 }, { 157, 241, 169 }, { 157, 249, 170 }, { 157, 253, 171 }, { 161, 237, 172 }, { 161, 245, 173 }, { 161, 253, 174 }, { 165, 233, 175 }, + { 165, 241, 176 }, { 165, 249, 177 }, { 169, 233, 178 }, { 169, 237, 179 }, { 169, 245, 180 }, { 169, 253, 181 }, { 173, 237, 182 }, { 173, 241, 183 }, + { 173, 249, 184 }, { 177, 233, 185 }, { 177, 241, 186 }, { 177, 245, 187 }, { 177, 253, 188 }, { 181, 237, 189 }, { 181, 245, 190 }, { 181, 249, 191 }, + { 185, 233, 192 }, { 185, 241, 193 }, { 185, 249, 194 }, { 185, 253, 195 }, { 189, 237, 196 }, { 189, 245, 197 }, { 189, 253, 198 }, { 193, 233, 199 }, + { 193, 241, 200 }, { 193, 249, 201 }, { 197, 229, 202 }, { 197, 237, 203 }, { 197, 245, 204 }, { 197, 253, 205 }, { 201, 233, 206 }, { 201, 241, 207 }, + { 201, 249, 208 }, { 205, 233, 209 }, { 205, 237, 210 }, { 205, 245, 211 }, { 205, 253, 212 }, { 209, 237, 213 }, { 209, 241, 214 }, { 209, 249, 215 }, + { 213, 233, 216 }, { 213, 241, 217 }, { 213, 245, 218 }, { 213, 253, 219 }, { 217, 237, 220 }, { 217, 245, 221 }, { 217, 249, 222 }, { 221, 233, 223 }, + { 221, 241, 224 }, { 221, 249, 225 }, { 221, 253, 226 }, { 225, 237, 227 }, { 225, 245, 228 }, { 225, 253, 229 }, { 229, 233, 230 }, { 229, 241, 231 }, + { 229, 249, 232 }, { 233, 233, 233 }, { 233, 237, 234 }, { 233, 245, 235 }, { 233, 253, 236 }, { 237, 237, 237 }, { 237, 241, 238 }, { 237, 249, 239 }, + { 241, 233, 240 }, { 241, 241, 241 }, { 241, 245, 242 }, { 241, 253, 243 }, { 245, 237, 244 }, { 245, 245, 245 }, { 245, 249, 246 }, { 249, 233, 247 }, + { 249, 241, 248 }, { 249, 249, 249 }, { 249, 253, 250 }, { 253, 237, 251 }, { 253, 245, 252 }, { 253, 253, 253 }, { 253, 253, 253 }, { 253, 253, 253 }, + } +}; + +Table g_mode1_p0_i2= +{ + 2, + 0, + { + { 0, 0, 0 }, { 0, 4, 1 }, { 0, 8, 2 }, { 0, 12, 3 }, { 4, 4, 4 }, { 0, 16, 5 }, { 0, 20, 6 }, { 0, 24, 7 }, + { 0, 28, 8 }, { 0, 32, 9 }, { 0, 36, 10 }, { 0, 40, 11 }, { 0, 44, 12 }, { 4, 36, 13 }, { 0, 48, 14 }, { 0, 52, 15 }, + { 0, 56, 16 }, { 0, 60, 17 }, { 0, 64, 18 }, { 0, 68, 19 }, { 0, 72, 20 }, { 0, 76, 21 }, { 4, 68, 22 }, { 0, 80, 23 }, + { 0, 84, 24 }, { 0, 88, 25 }, { 0, 92, 26 }, { 0, 96, 27 }, { 0, 100, 28 }, { 0, 104, 29 }, { 0, 108, 30 }, { 4, 100, 31 }, + { 0, 112, 32 }, { 0, 116, 33 }, { 0, 120, 34 }, { 0, 124, 35 }, { 0, 129, 36 }, { 0, 133, 37 }, { 4, 124, 38 }, { 0, 137, 39 }, + { 0, 141, 40 }, { 0, 145, 41 }, { 0, 149, 42 }, { 0, 153, 43 }, { 0, 157, 44 }, { 0, 161, 45 }, { 0, 165, 46 }, { 4, 157, 47 }, + { 0, 169, 48 }, { 0, 173, 49 }, { 0, 177, 50 }, { 0, 181, 51 }, { 0, 185, 52 }, { 0, 189, 53 }, { 0, 193, 54 }, { 0, 197, 55 }, + { 4, 189, 56 }, { 0, 201, 57 }, { 0, 205, 58 }, { 0, 209, 59 }, { 0, 213, 60 }, { 0, 217, 61 }, { 0, 221, 62 }, { 0, 225, 63 }, + { 0, 229, 64 }, { 4, 221, 65 }, { 0, 233, 66 }, { 0, 237, 67 }, { 0, 241, 68 }, { 0, 245, 69 }, { 0, 249, 70 }, { 0, 253, 71 }, + { 4, 245, 72 }, { 4, 249, 73 }, { 4, 253, 74 }, { 8, 245, 75 }, { 8, 249, 76 }, { 8, 253, 77 }, { 12, 245, 78 }, { 12, 249, 79 }, + { 12, 253, 80 }, { 20, 237, 81 }, { 16, 249, 82 }, { 16, 253, 83 }, { 20, 249, 84 }, { 24, 241, 85 }, { 20, 253, 86 }, { 24, 249, 87 }, + { 24, 253, 88 }, { 28, 245, 89 }, { 28, 249, 90 }, { 28, 253, 91 }, { 32, 245, 92 }, { 32, 249, 93 }, { 32, 253, 94 }, { 36, 245, 95 }, + { 36, 249, 96 }, { 36, 253, 97 }, { 40, 245, 98 }, { 40, 249, 99 }, { 40, 253, 100 }, { 44, 245, 101 }, { 44, 249, 102 }, { 44, 253, 103 }, + { 52, 237, 104 }, { 48, 249, 105 }, { 48, 253, 106 }, { 52, 249, 107 }, { 56, 241, 108 }, { 52, 253, 109 }, { 56, 249, 110 }, { 56, 253, 111 }, + { 60, 245, 112 }, { 60, 249, 113 }, { 60, 253, 114 }, { 64, 245, 115 }, { 64, 249, 116 }, { 64, 253, 117 }, { 68, 245, 118 }, { 68, 249, 119 }, + { 68, 253, 120 }, { 72, 245, 121 }, { 72, 249, 122 }, { 72, 253, 123 }, { 76, 245, 124 }, { 76, 249, 125 }, { 76, 253, 126 }, { 84, 237, 127 }, + { 80, 249, 128 }, { 80, 253, 129 }, { 84, 249, 130 }, { 88, 241, 131 }, { 84, 253, 132 }, { 88, 249, 133 }, { 88, 253, 134 }, { 92, 245, 135 }, + { 92, 249, 136 }, { 92, 253, 137 }, { 96, 245, 138 }, { 96, 249, 139 }, { 96, 253, 140 }, { 100, 245, 141 }, { 100, 249, 142 }, { 100, 253, 143 }, + { 104, 245, 144 }, { 104, 249, 145 }, { 104, 253, 146 }, { 108, 245, 147 }, { 108, 249, 148 }, { 108, 253, 149 }, { 116, 237, 150 }, { 112, 249, 151 }, + { 112, 253, 152 }, { 116, 249, 153 }, { 120, 241, 154 }, { 116, 253, 155 }, { 120, 249, 156 }, { 120, 253, 157 }, { 124, 245, 158 }, { 124, 249, 159 }, + { 124, 253, 160 }, { 129, 241, 161 }, { 129, 245, 162 }, { 129, 249, 163 }, { 129, 253, 164 }, { 133, 245, 165 }, { 133, 249, 166 }, { 133, 253, 167 }, + { 141, 237, 168 }, { 137, 249, 169 }, { 137, 253, 170 }, { 141, 249, 171 }, { 145, 241, 172 }, { 141, 253, 173 }, { 145, 249, 174 }, { 145, 253, 175 }, + { 149, 245, 176 }, { 149, 249, 177 }, { 149, 253, 178 }, { 153, 245, 179 }, { 153, 249, 180 }, { 153, 253, 181 }, { 157, 245, 182 }, { 157, 249, 183 }, + { 157, 253, 184 }, { 161, 245, 185 }, { 161, 249, 186 }, { 161, 253, 187 }, { 165, 245, 188 }, { 165, 249, 189 }, { 165, 253, 190 }, { 173, 237, 191 }, + { 169, 249, 192 }, { 169, 253, 193 }, { 173, 249, 194 }, { 177, 241, 195 }, { 173, 253, 196 }, { 177, 249, 197 }, { 177, 253, 198 }, { 181, 245, 199 }, + { 181, 249, 200 }, { 181, 253, 201 }, { 185, 245, 202 }, { 185, 249, 203 }, { 185, 253, 204 }, { 189, 245, 205 }, { 189, 249, 206 }, { 189, 253, 207 }, + { 193, 245, 208 }, { 193, 249, 209 }, { 193, 253, 210 }, { 197, 245, 211 }, { 197, 249, 212 }, { 197, 253, 213 }, { 205, 237, 214 }, { 201, 249, 215 }, + { 201, 253, 216 }, { 205, 249, 217 }, { 209, 241, 218 }, { 205, 253, 219 }, { 209, 249, 220 }, { 209, 253, 221 }, { 213, 245, 222 }, { 213, 249, 223 }, + { 213, 253, 224 }, { 217, 245, 225 }, { 217, 249, 226 }, { 217, 253, 227 }, { 221, 245, 228 }, { 221, 249, 229 }, { 221, 253, 230 }, { 225, 245, 231 }, + { 225, 249, 232 }, { 225, 253, 233 }, { 229, 245, 234 }, { 229, 249, 235 }, { 229, 253, 236 }, { 237, 237, 237 }, { 233, 249, 238 }, { 233, 253, 239 }, + { 237, 249, 240 }, { 241, 241, 241 }, { 237, 253, 242 }, { 241, 249, 243 }, { 241, 253, 244 }, { 245, 245, 245 }, { 245, 249, 246 }, { 245, 253, 247 }, + { 249, 245, 248 }, { 249, 249, 249 }, { 249, 253, 250 }, { 253, 245, 251 }, { 253, 249, 252 }, { 253, 253, 253 }, { 253, 253, 253 }, { 253, 253, 253 }, + } +}; + +Table g_mode1_p0_i3= +{ + 3, + 0, + { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 4, 2 }, { 0, 8, 3 }, { 4, 4, 4 }, { 0, 12, 5 }, { 4, 8, 6 }, { 0, 16, 7 }, + { 0, 20, 8 }, { 4, 16, 9 }, { 0, 24, 10 }, { 4, 20, 11 }, { 0, 28, 12 }, { 8, 20, 13 }, { 0, 32, 14 }, { 0, 36, 15 }, + { 4, 32, 16 }, { 0, 40, 17 }, { 4, 36, 18 }, { 0, 44, 19 }, { 0, 48, 20 }, { 4, 44, 21 }, { 0, 52, 22 }, { 4, 48, 23 }, + { 0, 56, 24 }, { 0, 60, 25 }, { 4, 56, 26 }, { 0, 64, 27 }, { 4, 60, 28 }, { 0, 68, 29 }, { 0, 72, 30 }, { 4, 68, 31 }, + { 0, 76, 32 }, { 4, 72, 33 }, { 0, 80, 34 }, { 0, 84, 35 }, { 4, 80, 36 }, { 0, 88, 37 }, { 4, 84, 38 }, { 0, 92, 39 }, + { 8, 84, 40 }, { 0, 96, 41 }, { 0, 100, 42 }, { 4, 96, 43 }, { 0, 104, 44 }, { 4, 100, 45 }, { 0, 108, 46 }, { 0, 112, 47 }, + { 4, 108, 48 }, { 0, 116, 49 }, { 4, 112, 50 }, { 0, 120, 51 }, { 0, 124, 52 }, { 4, 120, 53 }, { 0, 129, 54 }, { 4, 124, 55 }, + { 0, 133, 56 }, { 4, 129, 57 }, { 0, 137, 58 }, { 0, 141, 59 }, { 4, 137, 60 }, { 0, 145, 61 }, { 4, 141, 62 }, { 0, 149, 63 }, + { 8, 141, 64 }, { 0, 153, 65 }, { 0, 157, 66 }, { 4, 153, 67 }, { 0, 161, 68 }, { 4, 157, 69 }, { 0, 165, 70 }, { 0, 169, 71 }, + { 4, 165, 72 }, { 0, 173, 73 }, { 4, 169, 74 }, { 0, 177, 75 }, { 0, 181, 76 }, { 4, 177, 77 }, { 0, 185, 78 }, { 4, 181, 79 }, + { 0, 189, 80 }, { 0, 193, 81 }, { 4, 189, 82 }, { 0, 197, 83 }, { 4, 193, 84 }, { 0, 201, 85 }, { 0, 205, 86 }, { 4, 201, 87 }, + { 0, 209, 88 }, { 4, 205, 89 }, { 0, 213, 90 }, { 8, 205, 91 }, { 0, 217, 92 }, { 0, 221, 93 }, { 4, 217, 94 }, { 0, 225, 95 }, + { 4, 221, 96 }, { 0, 229, 97 }, { 0, 233, 98 }, { 4, 229, 99 }, { 0, 237, 100 }, { 4, 233, 101 }, { 0, 241, 102 }, { 0, 245, 103 }, + { 4, 241, 104 }, { 0, 249, 105 }, { 4, 245, 106 }, { 0, 253, 107 }, { 8, 245, 108 }, { 4, 253, 109 }, { 8, 249, 110 }, { 8, 253, 111 }, + { 12, 249, 112 }, { 16, 245, 113 }, { 12, 253, 114 }, { 20, 245, 115 }, { 16, 253, 116 }, { 20, 249, 117 }, { 20, 253, 118 }, { 24, 249, 119 }, + { 28, 245, 120 }, { 24, 253, 121 }, { 32, 245, 122 }, { 28, 253, 123 }, { 32, 249, 124 }, { 32, 253, 125 }, { 36, 249, 126 }, { 44, 241, 127 }, + { 36, 253, 128 }, { 44, 245, 129 }, { 40, 253, 130 }, { 48, 245, 131 }, { 44, 253, 132 }, { 48, 249, 133 }, { 48, 253, 134 }, { 52, 249, 135 }, + { 56, 245, 136 }, { 52, 253, 137 }, { 60, 245, 138 }, { 56, 253, 139 }, { 60, 249, 140 }, { 60, 253, 141 }, { 64, 249, 142 }, { 68, 245, 143 }, + { 64, 253, 144 }, { 72, 245, 145 }, { 68, 253, 146 }, { 72, 249, 147 }, { 72, 253, 148 }, { 76, 249, 149 }, { 80, 245, 150 }, { 76, 253, 151 }, + { 84, 245, 152 }, { 80, 253, 153 }, { 84, 249, 154 }, { 84, 253, 155 }, { 88, 249, 156 }, { 92, 245, 157 }, { 88, 253, 158 }, { 96, 245, 159 }, + { 92, 253, 160 }, { 96, 249, 161 }, { 96, 253, 162 }, { 100, 249, 163 }, { 108, 241, 164 }, { 100, 253, 165 }, { 108, 245, 166 }, { 104, 253, 167 }, + { 112, 245, 168 }, { 108, 253, 169 }, { 112, 249, 170 }, { 112, 253, 171 }, { 116, 249, 172 }, { 120, 245, 173 }, { 116, 253, 174 }, { 124, 245, 175 }, + { 120, 253, 176 }, { 124, 249, 177 }, { 124, 253, 178 }, { 133, 241, 179 }, { 129, 249, 180 }, { 129, 253, 181 }, { 133, 249, 182 }, { 137, 245, 183 }, + { 133, 253, 184 }, { 141, 245, 185 }, { 137, 253, 186 }, { 141, 249, 187 }, { 141, 253, 188 }, { 145, 249, 189 }, { 149, 245, 190 }, { 145, 253, 191 }, + { 153, 245, 192 }, { 149, 253, 193 }, { 153, 249, 194 }, { 153, 253, 195 }, { 157, 249, 196 }, { 165, 241, 197 }, { 157, 253, 198 }, { 165, 245, 199 }, + { 161, 253, 200 }, { 169, 245, 201 }, { 165, 253, 202 }, { 169, 249, 203 }, { 169, 253, 204 }, { 173, 249, 205 }, { 177, 245, 206 }, { 173, 253, 207 }, + { 181, 245, 208 }, { 177, 253, 209 }, { 181, 249, 210 }, { 181, 253, 211 }, { 185, 249, 212 }, { 189, 245, 213 }, { 185, 253, 214 }, { 193, 245, 215 }, + { 189, 253, 216 }, { 193, 249, 217 }, { 193, 253, 218 }, { 197, 249, 219 }, { 201, 245, 220 }, { 197, 253, 221 }, { 205, 245, 222 }, { 201, 253, 223 }, + { 205, 249, 224 }, { 205, 253, 225 }, { 209, 249, 226 }, { 213, 245, 227 }, { 209, 253, 228 }, { 217, 245, 229 }, { 213, 253, 230 }, { 217, 249, 231 }, + { 217, 253, 232 }, { 221, 249, 233 }, { 229, 241, 234 }, { 221, 253, 235 }, { 229, 245, 236 }, { 225, 253, 237 }, { 233, 245, 238 }, { 229, 253, 239 }, + { 233, 249, 240 }, { 233, 253, 241 }, { 237, 249, 242 }, { 241, 245, 243 }, { 237, 253, 244 }, { 245, 245, 245 }, { 241, 253, 246 }, { 245, 249, 247 }, + { 245, 253, 248 }, { 249, 249, 249 }, { 253, 245, 250 }, { 249, 253, 251 }, { 249, 253, 251 }, { 253, 253, 253 }, { 253, 253, 253 }, { 253, 253, 253 }, + } +}; + +Table g_mode1_p1_i1= +{ + 1, + 1, + { + { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 6, 3 }, { 2, 14, 4 }, { 2, 22, 5 }, { 2, 30, 6 }, { 2, 34, 7 }, + { 2, 42, 8 }, { 2, 50, 9 }, { 2, 58, 10 }, { 2, 66, 11 }, { 2, 70, 12 }, { 2, 78, 13 }, { 2, 86, 14 }, { 2, 94, 15 }, + { 2, 98, 16 }, { 2, 106, 17 }, { 2, 114, 18 }, { 2, 122, 19 }, { 2, 131, 20 }, { 2, 135, 21 }, { 2, 143, 22 }, { 2, 151, 23 }, + { 2, 155, 24 }, { 2, 163, 25 }, { 2, 171, 26 }, { 2, 179, 27 }, { 2, 187, 28 }, { 2, 191, 29 }, { 2, 199, 30 }, { 2, 207, 31 }, + { 2, 215, 32 }, { 2, 219, 33 }, { 2, 227, 34 }, { 2, 235, 35 }, { 2, 243, 36 }, { 2, 251, 37 }, { 2, 255, 38 }, { 6, 239, 39 }, + { 6, 247, 40 }, { 6, 255, 41 }, { 10, 235, 42 }, { 10, 243, 43 }, { 10, 251, 44 }, { 14, 231, 45 }, { 14, 239, 46 }, { 14, 247, 47 }, + { 14, 255, 48 }, { 18, 235, 49 }, { 18, 243, 50 }, { 18, 251, 51 }, { 22, 235, 52 }, { 22, 239, 53 }, { 22, 247, 54 }, { 22, 255, 55 }, + { 26, 239, 56 }, { 26, 243, 57 }, { 26, 251, 58 }, { 30, 235, 59 }, { 30, 243, 60 }, { 30, 247, 61 }, { 30, 255, 62 }, { 34, 239, 63 }, + { 34, 247, 64 }, { 34, 251, 65 }, { 38, 235, 66 }, { 38, 243, 67 }, { 38, 251, 68 }, { 38, 255, 69 }, { 42, 239, 70 }, { 42, 247, 71 }, + { 42, 255, 72 }, { 46, 235, 73 }, { 46, 243, 74 }, { 46, 251, 75 }, { 50, 235, 76 }, { 50, 239, 77 }, { 50, 247, 78 }, { 50, 255, 79 }, + { 54, 239, 80 }, { 54, 243, 81 }, { 54, 251, 82 }, { 58, 235, 83 }, { 58, 243, 84 }, { 58, 247, 85 }, { 58, 255, 86 }, { 62, 239, 87 }, + { 62, 247, 88 }, { 62, 251, 89 }, { 66, 235, 90 }, { 66, 243, 91 }, { 66, 251, 92 }, { 66, 255, 93 }, { 70, 239, 94 }, { 70, 247, 95 }, + { 70, 255, 96 }, { 74, 235, 97 }, { 74, 243, 98 }, { 74, 251, 99 }, { 78, 231, 100 }, { 78, 239, 101 }, { 78, 247, 102 }, { 78, 255, 103 }, + { 82, 235, 104 }, { 82, 243, 105 }, { 82, 251, 106 }, { 86, 235, 107 }, { 86, 239, 108 }, { 86, 247, 109 }, { 86, 255, 110 }, { 90, 239, 111 }, + { 90, 243, 112 }, { 90, 251, 113 }, { 94, 235, 114 }, { 94, 243, 115 }, { 94, 247, 116 }, { 94, 255, 117 }, { 98, 239, 118 }, { 98, 247, 119 }, + { 98, 251, 120 }, { 102, 235, 121 }, { 102, 243, 122 }, { 102, 251, 123 }, { 102, 255, 124 }, { 106, 239, 125 }, { 106, 247, 126 }, { 106, 255, 127 }, + { 110, 235, 128 }, { 110, 243, 129 }, { 110, 251, 130 }, { 114, 235, 131 }, { 114, 239, 132 }, { 114, 247, 133 }, { 114, 255, 134 }, { 118, 239, 135 }, + { 118, 243, 136 }, { 118, 251, 137 }, { 122, 235, 138 }, { 122, 243, 139 }, { 122, 247, 140 }, { 122, 255, 141 }, { 126, 239, 142 }, { 126, 247, 143 }, + { 126, 251, 144 }, { 131, 227, 145 }, { 131, 235, 146 }, { 131, 243, 147 }, { 131, 251, 148 }, { 135, 231, 149 }, { 135, 239, 150 }, { 135, 247, 151 }, + { 135, 255, 152 }, { 139, 235, 153 }, { 139, 243, 154 }, { 139, 251, 155 }, { 143, 235, 156 }, { 143, 239, 157 }, { 143, 247, 158 }, { 143, 255, 159 }, + { 147, 239, 160 }, { 147, 243, 161 }, { 147, 251, 162 }, { 151, 235, 163 }, { 151, 243, 164 }, { 151, 247, 165 }, { 151, 255, 166 }, { 155, 239, 167 }, + { 155, 247, 168 }, { 155, 251, 169 }, { 159, 235, 170 }, { 159, 243, 171 }, { 159, 251, 172 }, { 159, 255, 173 }, { 163, 239, 174 }, { 163, 247, 175 }, + { 163, 255, 176 }, { 167, 235, 177 }, { 167, 243, 178 }, { 167, 251, 179 }, { 171, 235, 180 }, { 171, 239, 181 }, { 171, 247, 182 }, { 171, 255, 183 }, + { 175, 239, 184 }, { 175, 243, 185 }, { 175, 251, 186 }, { 179, 235, 187 }, { 179, 243, 188 }, { 179, 247, 189 }, { 179, 255, 190 }, { 183, 239, 191 }, + { 183, 247, 192 }, { 183, 251, 193 }, { 187, 235, 194 }, { 187, 243, 195 }, { 187, 251, 196 }, { 187, 255, 197 }, { 191, 239, 198 }, { 191, 247, 199 }, + { 191, 255, 200 }, { 195, 235, 201 }, { 195, 243, 202 }, { 195, 251, 203 }, { 199, 231, 204 }, { 199, 239, 205 }, { 199, 247, 206 }, { 199, 255, 207 }, + { 203, 235, 208 }, { 203, 243, 209 }, { 203, 251, 210 }, { 207, 235, 211 }, { 207, 239, 212 }, { 207, 247, 213 }, { 207, 255, 214 }, { 211, 239, 215 }, + { 211, 243, 216 }, { 211, 251, 217 }, { 215, 235, 218 }, { 215, 243, 219 }, { 215, 247, 220 }, { 215, 255, 221 }, { 219, 239, 222 }, { 219, 247, 223 }, + { 219, 251, 224 }, { 223, 235, 225 }, { 223, 243, 226 }, { 223, 251, 227 }, { 223, 255, 228 }, { 227, 239, 229 }, { 227, 247, 230 }, { 227, 255, 231 }, + { 231, 235, 232 }, { 231, 243, 233 }, { 231, 251, 234 }, { 235, 235, 235 }, { 235, 239, 236 }, { 235, 247, 237 }, { 235, 255, 238 }, { 239, 239, 239 }, + { 239, 243, 240 }, { 239, 251, 241 }, { 243, 235, 242 }, { 243, 243, 243 }, { 243, 247, 244 }, { 243, 255, 245 }, { 247, 239, 246 }, { 247, 247, 247 }, + { 247, 251, 248 }, { 251, 235, 249 }, { 251, 243, 250 }, { 251, 251, 251 }, { 251, 255, 252 }, { 255, 239, 253 }, { 255, 247, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode1_p1_i2= +{ + 2, + 1, + { + { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 6, 3 }, { 2, 10, 4 }, { 2, 14, 5 }, { 6, 6, 6 }, { 2, 18, 7 }, + { 2, 22, 8 }, { 2, 26, 9 }, { 2, 30, 10 }, { 2, 34, 11 }, { 2, 38, 12 }, { 2, 42, 13 }, { 2, 46, 14 }, { 6, 38, 15 }, + { 2, 50, 16 }, { 2, 54, 17 }, { 2, 58, 18 }, { 2, 62, 19 }, { 2, 66, 20 }, { 2, 70, 21 }, { 2, 74, 22 }, { 2, 78, 23 }, + { 6, 70, 24 }, { 2, 82, 25 }, { 2, 86, 26 }, { 2, 90, 27 }, { 2, 94, 28 }, { 2, 98, 29 }, { 2, 102, 30 }, { 2, 106, 31 }, + { 2, 110, 32 }, { 6, 102, 33 }, { 2, 114, 34 }, { 2, 118, 35 }, { 2, 122, 36 }, { 2, 126, 37 }, { 2, 131, 38 }, { 2, 135, 39 }, + { 6, 126, 40 }, { 2, 139, 41 }, { 2, 143, 42 }, { 2, 147, 43 }, { 2, 151, 44 }, { 2, 155, 45 }, { 2, 159, 46 }, { 2, 163, 47 }, + { 2, 167, 48 }, { 6, 159, 49 }, { 2, 171, 50 }, { 2, 175, 51 }, { 2, 179, 52 }, { 2, 183, 53 }, { 2, 187, 54 }, { 2, 191, 55 }, + { 2, 195, 56 }, { 2, 199, 57 }, { 6, 191, 58 }, { 2, 203, 59 }, { 2, 207, 60 }, { 2, 211, 61 }, { 2, 215, 62 }, { 2, 219, 63 }, + { 2, 223, 64 }, { 2, 227, 65 }, { 2, 231, 66 }, { 6, 223, 67 }, { 2, 235, 68 }, { 2, 239, 69 }, { 2, 243, 70 }, { 2, 247, 71 }, + { 2, 251, 72 }, { 2, 255, 73 }, { 6, 247, 74 }, { 6, 251, 75 }, { 6, 255, 76 }, { 10, 247, 77 }, { 10, 251, 78 }, { 10, 255, 79 }, + { 14, 247, 80 }, { 14, 251, 81 }, { 14, 255, 82 }, { 22, 239, 83 }, { 18, 251, 84 }, { 18, 255, 85 }, { 22, 251, 86 }, { 26, 243, 87 }, + { 22, 255, 88 }, { 26, 251, 89 }, { 26, 255, 90 }, { 30, 247, 91 }, { 30, 251, 92 }, { 30, 255, 93 }, { 34, 247, 94 }, { 34, 251, 95 }, + { 34, 255, 96 }, { 38, 247, 97 }, { 38, 251, 98 }, { 38, 255, 99 }, { 42, 247, 100 }, { 42, 251, 101 }, { 42, 255, 102 }, { 46, 247, 103 }, + { 46, 251, 104 }, { 46, 255, 105 }, { 54, 239, 106 }, { 50, 251, 107 }, { 50, 255, 108 }, { 54, 251, 109 }, { 58, 243, 110 }, { 54, 255, 111 }, + { 58, 251, 112 }, { 58, 255, 113 }, { 62, 247, 114 }, { 62, 251, 115 }, { 62, 255, 116 }, { 66, 247, 117 }, { 66, 251, 118 }, { 66, 255, 119 }, + { 70, 247, 120 }, { 70, 251, 121 }, { 70, 255, 122 }, { 74, 247, 123 }, { 74, 251, 124 }, { 74, 255, 125 }, { 78, 247, 126 }, { 78, 251, 127 }, + { 78, 255, 128 }, { 86, 239, 129 }, { 82, 251, 130 }, { 82, 255, 131 }, { 86, 251, 132 }, { 90, 243, 133 }, { 86, 255, 134 }, { 90, 251, 135 }, + { 90, 255, 136 }, { 94, 247, 137 }, { 94, 251, 138 }, { 94, 255, 139 }, { 98, 247, 140 }, { 98, 251, 141 }, { 98, 255, 142 }, { 102, 247, 143 }, + { 102, 251, 144 }, { 102, 255, 145 }, { 106, 247, 146 }, { 106, 251, 147 }, { 106, 255, 148 }, { 110, 247, 149 }, { 110, 251, 150 }, { 110, 255, 151 }, + { 118, 239, 152 }, { 114, 251, 153 }, { 114, 255, 154 }, { 118, 251, 155 }, { 122, 243, 156 }, { 118, 255, 157 }, { 122, 251, 158 }, { 122, 255, 159 }, + { 126, 247, 160 }, { 126, 251, 161 }, { 126, 255, 162 }, { 131, 243, 163 }, { 131, 247, 164 }, { 131, 251, 165 }, { 131, 255, 166 }, { 135, 247, 167 }, + { 135, 251, 168 }, { 135, 255, 169 }, { 143, 239, 170 }, { 139, 251, 171 }, { 139, 255, 172 }, { 143, 251, 173 }, { 147, 243, 174 }, { 143, 255, 175 }, + { 147, 251, 176 }, { 147, 255, 177 }, { 151, 247, 178 }, { 151, 251, 179 }, { 151, 255, 180 }, { 155, 247, 181 }, { 155, 251, 182 }, { 155, 255, 183 }, + { 159, 247, 184 }, { 159, 251, 185 }, { 159, 255, 186 }, { 163, 247, 187 }, { 163, 251, 188 }, { 163, 255, 189 }, { 167, 247, 190 }, { 167, 251, 191 }, + { 167, 255, 192 }, { 175, 239, 193 }, { 171, 251, 194 }, { 171, 255, 195 }, { 175, 251, 196 }, { 179, 243, 197 }, { 175, 255, 198 }, { 179, 251, 199 }, + { 179, 255, 200 }, { 183, 247, 201 }, { 183, 251, 202 }, { 183, 255, 203 }, { 187, 247, 204 }, { 187, 251, 205 }, { 187, 255, 206 }, { 191, 247, 207 }, + { 191, 251, 208 }, { 191, 255, 209 }, { 195, 247, 210 }, { 195, 251, 211 }, { 195, 255, 212 }, { 199, 247, 213 }, { 199, 251, 214 }, { 199, 255, 215 }, + { 207, 239, 216 }, { 203, 251, 217 }, { 203, 255, 218 }, { 207, 251, 219 }, { 211, 243, 220 }, { 207, 255, 221 }, { 211, 251, 222 }, { 211, 255, 223 }, + { 215, 247, 224 }, { 215, 251, 225 }, { 215, 255, 226 }, { 219, 247, 227 }, { 219, 251, 228 }, { 219, 255, 229 }, { 223, 247, 230 }, { 223, 251, 231 }, + { 223, 255, 232 }, { 227, 247, 233 }, { 227, 251, 234 }, { 227, 255, 235 }, { 231, 247, 236 }, { 231, 251, 237 }, { 231, 255, 238 }, { 239, 239, 239 }, + { 235, 251, 240 }, { 235, 255, 241 }, { 239, 251, 242 }, { 243, 243, 243 }, { 239, 255, 244 }, { 243, 251, 245 }, { 243, 255, 246 }, { 247, 247, 247 }, + { 247, 251, 248 }, { 247, 255, 249 }, { 251, 247, 250 }, { 251, 251, 251 }, { 251, 255, 252 }, { 255, 247, 253 }, { 255, 251, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode1_p1_i3= +{ + 3, + 1, + { + { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 6, 4 }, { 2, 10, 5 }, { 6, 6, 6 }, { 2, 14, 7 }, + { 6, 10, 8 }, { 2, 18, 9 }, { 2, 22, 10 }, { 6, 18, 11 }, { 2, 26, 12 }, { 6, 22, 13 }, { 2, 30, 14 }, { 10, 22, 15 }, + { 2, 34, 16 }, { 2, 38, 17 }, { 6, 34, 18 }, { 2, 42, 19 }, { 6, 38, 20 }, { 2, 46, 21 }, { 2, 50, 22 }, { 6, 46, 23 }, + { 2, 54, 24 }, { 6, 50, 25 }, { 2, 58, 26 }, { 2, 62, 27 }, { 6, 58, 28 }, { 2, 66, 29 }, { 6, 62, 30 }, { 2, 70, 31 }, + { 2, 74, 32 }, { 6, 70, 33 }, { 2, 78, 34 }, { 6, 74, 35 }, { 2, 82, 36 }, { 2, 86, 37 }, { 6, 82, 38 }, { 2, 90, 39 }, + { 6, 86, 40 }, { 2, 94, 41 }, { 10, 86, 42 }, { 2, 98, 43 }, { 2, 102, 44 }, { 6, 98, 45 }, { 2, 106, 46 }, { 6, 102, 47 }, + { 2, 110, 48 }, { 2, 114, 49 }, { 6, 110, 50 }, { 2, 118, 51 }, { 6, 114, 52 }, { 2, 122, 53 }, { 2, 126, 54 }, { 6, 122, 55 }, + { 2, 131, 56 }, { 6, 126, 57 }, { 2, 135, 58 }, { 6, 131, 59 }, { 2, 139, 60 }, { 2, 143, 61 }, { 6, 139, 62 }, { 2, 147, 63 }, + { 6, 143, 64 }, { 2, 151, 65 }, { 10, 143, 66 }, { 2, 155, 67 }, { 2, 159, 68 }, { 6, 155, 69 }, { 2, 163, 70 }, { 6, 159, 71 }, + { 2, 167, 72 }, { 2, 171, 73 }, { 6, 167, 74 }, { 2, 175, 75 }, { 6, 171, 76 }, { 2, 179, 77 }, { 2, 183, 78 }, { 6, 179, 79 }, + { 2, 187, 80 }, { 6, 183, 81 }, { 2, 191, 82 }, { 2, 195, 83 }, { 6, 191, 84 }, { 2, 199, 85 }, { 6, 195, 86 }, { 2, 203, 87 }, + { 2, 207, 88 }, { 6, 203, 89 }, { 2, 211, 90 }, { 6, 207, 91 }, { 2, 215, 92 }, { 10, 207, 93 }, { 2, 219, 94 }, { 2, 223, 95 }, + { 6, 219, 96 }, { 2, 227, 97 }, { 6, 223, 98 }, { 2, 231, 99 }, { 2, 235, 100 }, { 6, 231, 101 }, { 2, 239, 102 }, { 6, 235, 103 }, + { 2, 243, 104 }, { 2, 247, 105 }, { 6, 243, 106 }, { 2, 251, 107 }, { 6, 247, 108 }, { 2, 255, 109 }, { 10, 247, 110 }, { 6, 255, 111 }, + { 10, 251, 112 }, { 10, 255, 113 }, { 14, 251, 114 }, { 18, 247, 115 }, { 14, 255, 116 }, { 22, 247, 117 }, { 18, 255, 118 }, { 22, 251, 119 }, + { 22, 255, 120 }, { 26, 251, 121 }, { 30, 247, 122 }, { 26, 255, 123 }, { 34, 247, 124 }, { 30, 255, 125 }, { 34, 251, 126 }, { 34, 255, 127 }, + { 38, 251, 128 }, { 46, 243, 129 }, { 38, 255, 130 }, { 46, 247, 131 }, { 42, 255, 132 }, { 50, 247, 133 }, { 46, 255, 134 }, { 50, 251, 135 }, + { 50, 255, 136 }, { 54, 251, 137 }, { 58, 247, 138 }, { 54, 255, 139 }, { 62, 247, 140 }, { 58, 255, 141 }, { 62, 251, 142 }, { 62, 255, 143 }, + { 66, 251, 144 }, { 70, 247, 145 }, { 66, 255, 146 }, { 74, 247, 147 }, { 70, 255, 148 }, { 74, 251, 149 }, { 74, 255, 150 }, { 78, 251, 151 }, + { 82, 247, 152 }, { 78, 255, 153 }, { 86, 247, 154 }, { 82, 255, 155 }, { 86, 251, 156 }, { 86, 255, 157 }, { 90, 251, 158 }, { 94, 247, 159 }, + { 90, 255, 160 }, { 98, 247, 161 }, { 94, 255, 162 }, { 98, 251, 163 }, { 98, 255, 164 }, { 102, 251, 165 }, { 110, 243, 166 }, { 102, 255, 167 }, + { 110, 247, 168 }, { 106, 255, 169 }, { 114, 247, 170 }, { 110, 255, 171 }, { 114, 251, 172 }, { 114, 255, 173 }, { 118, 251, 174 }, { 122, 247, 175 }, + { 118, 255, 176 }, { 126, 247, 177 }, { 122, 255, 178 }, { 126, 251, 179 }, { 126, 255, 180 }, { 135, 243, 181 }, { 131, 251, 182 }, { 131, 255, 183 }, + { 135, 251, 184 }, { 139, 247, 185 }, { 135, 255, 186 }, { 143, 247, 187 }, { 139, 255, 188 }, { 143, 251, 189 }, { 143, 255, 190 }, { 147, 251, 191 }, + { 151, 247, 192 }, { 147, 255, 193 }, { 155, 247, 194 }, { 151, 255, 195 }, { 155, 251, 196 }, { 155, 255, 197 }, { 159, 251, 198 }, { 167, 243, 199 }, + { 159, 255, 200 }, { 167, 247, 201 }, { 163, 255, 202 }, { 171, 247, 203 }, { 167, 255, 204 }, { 171, 251, 205 }, { 171, 255, 206 }, { 175, 251, 207 }, + { 179, 247, 208 }, { 175, 255, 209 }, { 183, 247, 210 }, { 179, 255, 211 }, { 183, 251, 212 }, { 183, 255, 213 }, { 187, 251, 214 }, { 191, 247, 215 }, + { 187, 255, 216 }, { 195, 247, 217 }, { 191, 255, 218 }, { 195, 251, 219 }, { 195, 255, 220 }, { 199, 251, 221 }, { 203, 247, 222 }, { 199, 255, 223 }, + { 207, 247, 224 }, { 203, 255, 225 }, { 207, 251, 226 }, { 207, 255, 227 }, { 211, 251, 228 }, { 215, 247, 229 }, { 211, 255, 230 }, { 219, 247, 231 }, + { 215, 255, 232 }, { 219, 251, 233 }, { 219, 255, 234 }, { 223, 251, 235 }, { 231, 243, 236 }, { 223, 255, 237 }, { 231, 247, 238 }, { 227, 255, 239 }, + { 235, 247, 240 }, { 231, 255, 241 }, { 235, 251, 242 }, { 235, 255, 243 }, { 239, 251, 244 }, { 243, 247, 245 }, { 239, 255, 246 }, { 247, 247, 247 }, + { 243, 255, 248 }, { 247, 251, 249 }, { 247, 255, 250 }, { 251, 251, 251 }, { 255, 247, 252 }, { 251, 255, 253 }, { 251, 255, 253 }, { 255, 255, 255 }, + } +}; + +Table g_mode2= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 16, 5 }, { 0, 16, 5 }, { 0, 24, 8 }, + { 0, 24, 8 }, { 0, 24, 8 }, { 0, 33, 11 }, { 0, 33, 11 }, { 0, 33, 11 }, { 0, 41, 13 }, { 0, 41, 13 }, { 0, 49, 16 }, + { 0, 49, 16 }, { 0, 49, 16 }, { 0, 57, 19 }, { 0, 57, 19 }, { 0, 57, 19 }, { 8, 49, 21 }, { 0, 66, 22 }, { 0, 66, 22 }, + { 0, 74, 24 }, { 33, 8, 25 }, { 0, 82, 27 }, { 0, 82, 27 }, { 41, 0, 28 }, { 16, 57, 29 }, { 0, 90, 30 }, { 0, 90, 30 }, + { 0, 99, 32 }, { 33, 33, 33 }, { 0, 107, 35 }, { 0, 107, 35 }, { 33, 41, 36 }, { 0, 115, 38 }, { 0, 115, 38 }, { 0, 115, 38 }, + { 0, 123, 40 }, { 33, 57, 41 }, { 0, 132, 43 }, { 0, 132, 43 }, { 33, 66, 44 }, { 0, 140, 46 }, { 0, 140, 46 }, { 66, 8, 47 }, + { 16, 115, 48 }, { 0, 148, 49 }, { 66, 16, 50 }, { 0, 156, 51 }, { 33, 90, 52 }, { 0, 165, 54 }, { 0, 165, 54 }, { 33, 99, 55 }, + { 24, 123, 56 }, { 0, 173, 57 }, { 66, 41, 58 }, { 0, 181, 59 }, { 8, 165, 60 }, { 74, 33, 61 }, { 0, 189, 62 }, { 33, 123, 63 }, + { 0, 198, 65 }, { 0, 198, 65 }, { 66, 66, 66 }, { 8, 189, 67 }, { 0, 206, 68 }, { 66, 74, 69 }, { 0, 214, 70 }, { 33, 148, 71 }, + { 99, 16, 72 }, { 0, 222, 73 }, { 66, 90, 74 }, { 107, 8, 75 }, { 0, 231, 76 }, { 66, 99, 77 }, { 0, 239, 78 }, { 33, 173, 79 }, + { 99, 41, 80 }, { 0, 247, 81 }, { 33, 181, 82 }, { 99, 49, 83 }, { 0, 255, 84 }, { 66, 123, 85 }, { 8, 247, 86 }, { 16, 231, 87 }, + { 66, 132, 88 }, { 8, 255, 89 }, { 33, 206, 90 }, { 99, 74, 91 }, { 16, 247, 92 }, { 41, 198, 93 }, { 16, 255, 94 }, { 24, 239, 95 }, + { 66, 156, 96 }, { 24, 247, 97 }, { 33, 231, 98 }, { 99, 99, 99 }, { 24, 255, 100 }, { 33, 239, 101 }, { 99, 107, 102 }, { 33, 247, 103 }, + { 66, 181, 104 }, { 132, 49, 105 }, { 33, 255, 106 }, { 99, 123, 107 }, { 140, 41, 108 }, { 41, 247, 109 }, { 99, 132, 110 }, { 41, 255, 111 }, + { 66, 206, 112 }, { 132, 74, 113 }, { 49, 247, 114 }, { 66, 214, 115 }, { 132, 82, 116 }, { 49, 255, 117 }, { 99, 156, 118 }, { 57, 247, 119 }, + { 66, 231, 120 }, { 99, 165, 121 }, { 57, 255, 122 }, { 66, 239, 123 }, { 132, 107, 124 }, { 66, 247, 125 }, { 74, 231, 126 }, { 140, 99, 127 }, + { 66, 255, 128 }, { 99, 189, 129 }, { 165, 57, 130 }, { 74, 247, 131 }, { 132, 132, 132 }, { 74, 255, 133 }, { 82, 239, 134 }, { 132, 140, 135 }, + { 82, 247, 136 }, { 99, 214, 137 }, { 165, 82, 138 }, { 82, 255, 139 }, { 132, 156, 140 }, { 173, 74, 141 }, { 90, 247, 142 }, { 132, 165, 143 }, + { 90, 255, 144 }, { 99, 239, 145 }, { 165, 107, 146 }, { 115, 214, 147 }, { 99, 247, 148 }, { 165, 115, 149 }, { 99, 255, 150 }, { 132, 189, 151 }, + { 198, 57, 152 }, { 107, 247, 153 }, { 132, 198, 154 }, { 123, 222, 155 }, { 107, 255, 156 }, { 165, 140, 157 }, { 115, 247, 158 }, { 132, 214, 159 }, + { 173, 132, 160 }, { 115, 255, 161 }, { 132, 222, 162 }, { 198, 90, 163 }, { 123, 247, 164 }, { 165, 165, 165 }, { 123, 255, 166 }, { 132, 239, 167 }, + { 165, 173, 168 }, { 231, 41, 169 }, { 132, 247, 170 }, { 198, 115, 171 }, { 132, 255, 172 }, { 165, 189, 173 }, { 206, 107, 174 }, { 140, 247, 175 }, + { 165, 198, 176 }, { 231, 66, 177 }, { 140, 255, 178 }, { 198, 140, 179 }, { 148, 247, 180 }, { 156, 231, 181 }, { 198, 148, 182 }, { 148, 255, 183 }, + { 165, 222, 184 }, { 231, 90, 185 }, { 156, 247, 186 }, { 165, 231, 187 }, { 156, 255, 188 }, { 165, 239, 189 }, { 198, 173, 190 }, { 165, 247, 192 }, + { 165, 247, 192 }, { 206, 165, 193 }, { 181, 222, 194 }, { 165, 255, 195 }, { 231, 123, 196 }, { 173, 247, 197 }, { 198, 198, 198 }, { 231, 132, 199 }, + { 173, 255, 200 }, { 198, 206, 201 }, { 181, 247, 203 }, { 181, 247, 203 }, { 231, 148, 204 }, { 181, 255, 205 }, { 198, 222, 206 }, { 239, 140, 207 }, + { 189, 247, 208 }, { 198, 231, 209 }, { 189, 255, 211 }, { 189, 255, 211 }, { 231, 173, 212 }, { 198, 247, 214 }, { 198, 247, 214 }, { 231, 181, 215 }, + { 198, 255, 217 }, { 198, 255, 217 }, { 198, 255, 217 }, { 206, 247, 219 }, { 214, 231, 220 }, { 206, 255, 222 }, { 206, 255, 222 }, { 231, 206, 223 }, + { 214, 247, 225 }, { 214, 247, 225 }, { 239, 198, 226 }, { 214, 255, 227 }, { 222, 239, 228 }, { 222, 239, 228 }, { 222, 247, 230 }, { 231, 231, 231 }, + { 222, 255, 233 }, { 222, 255, 233 }, { 231, 239, 234 }, { 231, 239, 234 }, { 231, 247, 236 }, { 231, 247, 236 }, { 231, 255, 239 }, { 231, 255, 239 }, + { 231, 255, 239 }, { 239, 247, 242 }, { 239, 247, 242 }, { 239, 247, 242 }, { 239, 255, 244 }, { 239, 255, 244 }, { 247, 247, 247 }, { 247, 247, 247 }, + { 247, 247, 247 }, { 247, 255, 250 }, { 247, 255, 250 }, { 247, 255, 250 }, { 255, 247, 252 }, { 255, 247, 252 }, { 255, 255, 255 }, { 255, 255, 255 }, + } +}; + +Table g_mode3_p0= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 2, 1 }, { 0, 6, 2 }, { 0, 8, 3 }, { 0, 12, 4 }, { 0, 14, 5 }, { 0, 18, 6 }, { 0, 20, 7 }, + { 0, 24, 8 }, { 0, 26, 9 }, { 0, 30, 10 }, { 0, 32, 11 }, { 0, 36, 12 }, { 0, 40, 13 }, { 0, 42, 14 }, { 0, 46, 15 }, + { 0, 48, 16 }, { 0, 52, 17 }, { 0, 54, 18 }, { 0, 58, 19 }, { 0, 60, 20 }, { 0, 64, 21 }, { 0, 66, 22 }, { 0, 70, 23 }, + { 0, 72, 24 }, { 0, 76, 25 }, { 0, 78, 26 }, { 0, 82, 27 }, { 0, 84, 28 }, { 0, 88, 29 }, { 0, 90, 30 }, { 0, 94, 31 }, + { 0, 96, 32 }, { 0, 100, 33 }, { 0, 104, 34 }, { 0, 106, 35 }, { 0, 110, 36 }, { 0, 112, 37 }, { 0, 116, 38 }, { 0, 118, 39 }, + { 0, 122, 40 }, { 0, 124, 41 }, { 0, 128, 42 }, { 0, 130, 43 }, { 0, 134, 44 }, { 0, 136, 45 }, { 0, 140, 46 }, { 0, 142, 47 }, + { 0, 146, 48 }, { 0, 148, 49 }, { 0, 152, 50 }, { 0, 154, 51 }, { 0, 158, 52 }, { 0, 160, 53 }, { 0, 164, 54 }, { 0, 168, 55 }, + { 0, 170, 56 }, { 0, 174, 57 }, { 0, 176, 58 }, { 0, 180, 59 }, { 0, 182, 60 }, { 0, 186, 61 }, { 0, 188, 62 }, { 0, 192, 63 }, + { 0, 194, 64 }, { 0, 198, 65 }, { 0, 200, 66 }, { 0, 204, 67 }, { 0, 206, 68 }, { 0, 210, 69 }, { 0, 212, 70 }, { 0, 216, 71 }, + { 0, 218, 72 }, { 0, 222, 73 }, { 0, 224, 74 }, { 0, 228, 75 }, { 0, 232, 76 }, { 0, 234, 77 }, { 0, 238, 78 }, { 0, 240, 79 }, + { 0, 244, 80 }, { 0, 246, 81 }, { 0, 250, 82 }, { 0, 252, 83 }, { 2, 252, 84 }, { 2, 254, 85 }, { 4, 254, 86 }, { 6, 252, 87 }, + { 8, 252, 88 }, { 8, 254, 89 }, { 10, 254, 90 }, { 12, 252, 91 }, { 14, 252, 92 }, { 14, 254, 93 }, { 16, 254, 94 }, { 18, 252, 95 }, + { 20, 252, 96 }, { 20, 254, 97 }, { 22, 254, 98 }, { 24, 252, 99 }, { 26, 250, 100 }, { 26, 254, 101 }, { 28, 252, 102 }, { 30, 252, 103 }, + { 30, 254, 104 }, { 32, 254, 105 }, { 34, 252, 106 }, { 36, 252, 107 }, { 36, 254, 108 }, { 38, 254, 109 }, { 40, 252, 110 }, { 42, 252, 111 }, + { 42, 254, 112 }, { 44, 254, 113 }, { 46, 252, 114 }, { 48, 252, 115 }, { 48, 254, 116 }, { 50, 254, 117 }, { 52, 252, 118 }, { 54, 252, 119 }, + { 54, 254, 120 }, { 56, 254, 121 }, { 58, 252, 122 }, { 60, 252, 123 }, { 60, 254, 124 }, { 62, 254, 125 }, { 64, 252, 126 }, { 66, 252, 127 }, + { 66, 254, 128 }, { 68, 254, 129 }, { 70, 252, 130 }, { 72, 252, 131 }, { 72, 254, 132 }, { 74, 254, 133 }, { 76, 252, 134 }, { 78, 252, 135 }, + { 78, 254, 136 }, { 80, 254, 137 }, { 82, 252, 138 }, { 84, 252, 139 }, { 84, 254, 140 }, { 86, 254, 141 }, { 88, 252, 142 }, { 90, 250, 143 }, + { 90, 254, 144 }, { 92, 252, 145 }, { 94, 252, 146 }, { 94, 254, 147 }, { 96, 254, 148 }, { 98, 252, 149 }, { 100, 252, 150 }, { 100, 254, 151 }, + { 102, 254, 152 }, { 104, 252, 153 }, { 106, 252, 154 }, { 106, 254, 155 }, { 108, 254, 156 }, { 110, 252, 157 }, { 112, 252, 158 }, { 112, 254, 159 }, + { 114, 254, 160 }, { 116, 252, 161 }, { 118, 252, 162 }, { 118, 254, 163 }, { 120, 254, 164 }, { 122, 252, 165 }, { 124, 252, 166 }, { 124, 254, 167 }, + { 126, 254, 168 }, { 128, 252, 169 }, { 130, 252, 170 }, { 130, 254, 171 }, { 132, 254, 172 }, { 134, 252, 173 }, { 136, 252, 174 }, { 136, 254, 175 }, + { 138, 254, 176 }, { 140, 252, 177 }, { 142, 252, 178 }, { 142, 254, 179 }, { 144, 254, 180 }, { 146, 252, 181 }, { 148, 252, 182 }, { 148, 254, 183 }, + { 150, 254, 184 }, { 152, 252, 185 }, { 154, 250, 186 }, { 154, 254, 187 }, { 156, 252, 188 }, { 158, 252, 189 }, { 158, 254, 190 }, { 160, 254, 191 }, + { 162, 252, 192 }, { 164, 252, 193 }, { 164, 254, 194 }, { 166, 254, 195 }, { 168, 252, 196 }, { 170, 252, 197 }, { 170, 254, 198 }, { 172, 254, 199 }, + { 174, 252, 200 }, { 176, 252, 201 }, { 176, 254, 202 }, { 178, 254, 203 }, { 180, 252, 204 }, { 182, 252, 205 }, { 182, 254, 206 }, { 184, 254, 207 }, + { 186, 252, 208 }, { 188, 252, 209 }, { 188, 254, 210 }, { 190, 254, 211 }, { 192, 252, 212 }, { 194, 252, 213 }, { 194, 254, 214 }, { 196, 254, 215 }, + { 198, 252, 216 }, { 200, 252, 217 }, { 200, 254, 218 }, { 202, 254, 219 }, { 204, 252, 220 }, { 206, 252, 221 }, { 206, 254, 222 }, { 208, 254, 223 }, + { 210, 252, 224 }, { 212, 252, 225 }, { 212, 254, 226 }, { 214, 254, 227 }, { 216, 252, 228 }, { 218, 250, 229 }, { 218, 254, 230 }, { 220, 252, 231 }, + { 222, 252, 232 }, { 222, 254, 233 }, { 224, 254, 234 }, { 226, 252, 235 }, { 228, 252, 236 }, { 228, 254, 237 }, { 230, 254, 238 }, { 232, 252, 239 }, + { 234, 252, 240 }, { 234, 254, 241 }, { 236, 254, 242 }, { 238, 252, 243 }, { 240, 252, 244 }, { 240, 254, 245 }, { 242, 254, 246 }, { 244, 252, 247 }, + { 246, 252, 248 }, { 246, 254, 249 }, { 248, 254, 250 }, { 250, 252, 251 }, { 252, 252, 252 }, { 252, 254, 253 }, { 254, 254, 254 }, { 254, 254, 254 }, + } +}; + +Table g_mode3_p1= +{ + 1, + 1, + { + { 1, 1, 1 }, { 1, 1, 1 }, { 1, 3, 2 }, { 1, 7, 3 }, { 1, 9, 4 }, { 1, 13, 5 }, { 1, 15, 6 }, { 1, 19, 7 }, + { 1, 21, 8 }, { 1, 25, 9 }, { 1, 27, 10 }, { 1, 31, 11 }, { 1, 33, 12 }, { 1, 37, 13 }, { 1, 41, 14 }, { 1, 43, 15 }, + { 1, 47, 16 }, { 1, 49, 17 }, { 1, 53, 18 }, { 1, 55, 19 }, { 1, 59, 20 }, { 1, 61, 21 }, { 1, 65, 22 }, { 1, 67, 23 }, + { 1, 71, 24 }, { 1, 73, 25 }, { 1, 77, 26 }, { 1, 79, 27 }, { 1, 83, 28 }, { 1, 85, 29 }, { 1, 89, 30 }, { 1, 91, 31 }, + { 1, 95, 32 }, { 1, 97, 33 }, { 1, 101, 34 }, { 1, 105, 35 }, { 1, 107, 36 }, { 1, 111, 37 }, { 1, 113, 38 }, { 1, 117, 39 }, + { 1, 119, 40 }, { 1, 123, 41 }, { 1, 125, 42 }, { 1, 129, 43 }, { 1, 131, 44 }, { 1, 135, 45 }, { 1, 137, 46 }, { 1, 141, 47 }, + { 1, 143, 48 }, { 1, 147, 49 }, { 1, 149, 50 }, { 1, 153, 51 }, { 1, 155, 52 }, { 1, 159, 53 }, { 1, 161, 54 }, { 1, 165, 55 }, + { 1, 169, 56 }, { 1, 171, 57 }, { 1, 175, 58 }, { 1, 177, 59 }, { 1, 181, 60 }, { 1, 183, 61 }, { 1, 187, 62 }, { 1, 189, 63 }, + { 1, 193, 64 }, { 1, 195, 65 }, { 1, 199, 66 }, { 1, 201, 67 }, { 1, 205, 68 }, { 1, 207, 69 }, { 1, 211, 70 }, { 1, 213, 71 }, + { 1, 217, 72 }, { 1, 219, 73 }, { 1, 223, 74 }, { 1, 225, 75 }, { 1, 229, 76 }, { 1, 233, 77 }, { 1, 235, 78 }, { 1, 239, 79 }, + { 1, 241, 80 }, { 1, 245, 81 }, { 1, 247, 82 }, { 1, 251, 83 }, { 1, 253, 84 }, { 3, 253, 85 }, { 3, 255, 86 }, { 5, 255, 87 }, + { 7, 253, 88 }, { 9, 253, 89 }, { 9, 255, 90 }, { 11, 255, 91 }, { 13, 253, 92 }, { 15, 253, 93 }, { 15, 255, 94 }, { 17, 255, 95 }, + { 19, 253, 96 }, { 21, 253, 97 }, { 21, 255, 98 }, { 23, 255, 99 }, { 25, 253, 100 }, { 27, 251, 101 }, { 27, 255, 102 }, { 29, 253, 103 }, + { 31, 253, 104 }, { 31, 255, 105 }, { 33, 255, 106 }, { 35, 253, 107 }, { 37, 253, 108 }, { 37, 255, 109 }, { 39, 255, 110 }, { 41, 253, 111 }, + { 43, 253, 112 }, { 43, 255, 113 }, { 45, 255, 114 }, { 47, 253, 115 }, { 49, 253, 116 }, { 49, 255, 117 }, { 51, 255, 118 }, { 53, 253, 119 }, + { 55, 253, 120 }, { 55, 255, 121 }, { 57, 255, 122 }, { 59, 253, 123 }, { 61, 253, 124 }, { 61, 255, 125 }, { 63, 255, 126 }, { 65, 253, 127 }, + { 67, 253, 128 }, { 67, 255, 129 }, { 69, 255, 130 }, { 71, 253, 131 }, { 73, 253, 132 }, { 73, 255, 133 }, { 75, 255, 134 }, { 77, 253, 135 }, + { 79, 253, 136 }, { 79, 255, 137 }, { 81, 255, 138 }, { 83, 253, 139 }, { 85, 253, 140 }, { 85, 255, 141 }, { 87, 255, 142 }, { 89, 253, 143 }, + { 91, 251, 144 }, { 91, 255, 145 }, { 93, 253, 146 }, { 95, 253, 147 }, { 95, 255, 148 }, { 97, 255, 149 }, { 99, 253, 150 }, { 101, 253, 151 }, + { 101, 255, 152 }, { 103, 255, 153 }, { 105, 253, 154 }, { 107, 253, 155 }, { 107, 255, 156 }, { 109, 255, 157 }, { 111, 253, 158 }, { 113, 253, 159 }, + { 113, 255, 160 }, { 115, 255, 161 }, { 117, 253, 162 }, { 119, 253, 163 }, { 119, 255, 164 }, { 121, 255, 165 }, { 123, 253, 166 }, { 125, 253, 167 }, + { 125, 255, 168 }, { 127, 255, 169 }, { 129, 253, 170 }, { 131, 253, 171 }, { 131, 255, 172 }, { 133, 255, 173 }, { 135, 253, 174 }, { 137, 253, 175 }, + { 137, 255, 176 }, { 139, 255, 177 }, { 141, 253, 178 }, { 143, 253, 179 }, { 143, 255, 180 }, { 145, 255, 181 }, { 147, 253, 182 }, { 149, 253, 183 }, + { 149, 255, 184 }, { 151, 255, 185 }, { 153, 253, 186 }, { 155, 251, 187 }, { 155, 255, 188 }, { 157, 253, 189 }, { 159, 253, 190 }, { 159, 255, 191 }, + { 161, 255, 192 }, { 163, 253, 193 }, { 165, 253, 194 }, { 165, 255, 195 }, { 167, 255, 196 }, { 169, 253, 197 }, { 171, 253, 198 }, { 171, 255, 199 }, + { 173, 255, 200 }, { 175, 253, 201 }, { 177, 253, 202 }, { 177, 255, 203 }, { 179, 255, 204 }, { 181, 253, 205 }, { 183, 253, 206 }, { 183, 255, 207 }, + { 185, 255, 208 }, { 187, 253, 209 }, { 189, 253, 210 }, { 189, 255, 211 }, { 191, 255, 212 }, { 193, 253, 213 }, { 195, 253, 214 }, { 195, 255, 215 }, + { 197, 255, 216 }, { 199, 253, 217 }, { 201, 253, 218 }, { 201, 255, 219 }, { 203, 255, 220 }, { 205, 253, 221 }, { 207, 253, 222 }, { 207, 255, 223 }, + { 209, 255, 224 }, { 211, 253, 225 }, { 213, 253, 226 }, { 213, 255, 227 }, { 215, 255, 228 }, { 217, 253, 229 }, { 219, 251, 230 }, { 219, 255, 231 }, + { 221, 253, 232 }, { 223, 253, 233 }, { 223, 255, 234 }, { 225, 255, 235 }, { 227, 253, 236 }, { 229, 253, 237 }, { 229, 255, 238 }, { 231, 255, 239 }, + { 233, 253, 240 }, { 235, 253, 241 }, { 235, 255, 242 }, { 237, 255, 243 }, { 239, 253, 244 }, { 241, 253, 245 }, { 241, 255, 246 }, { 243, 255, 247 }, + { 245, 253, 248 }, { 247, 253, 249 }, { 247, 255, 250 }, { 249, 255, 251 }, { 251, 253, 252 }, { 253, 253, 253 }, { 253, 255, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode4_rgb_low= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 16, 5 }, { 0, 16, 5 }, { 0, 24, 8 }, + { 0, 24, 8 }, { 0, 24, 8 }, { 0, 33, 11 }, { 0, 33, 11 }, { 0, 33, 11 }, { 0, 41, 13 }, { 0, 41, 13 }, { 0, 49, 16 }, + { 0, 49, 16 }, { 0, 49, 16 }, { 0, 57, 19 }, { 0, 57, 19 }, { 0, 57, 19 }, { 8, 49, 21 }, { 0, 66, 22 }, { 0, 66, 22 }, + { 0, 74, 24 }, { 33, 8, 25 }, { 0, 82, 27 }, { 0, 82, 27 }, { 41, 0, 28 }, { 16, 57, 29 }, { 0, 90, 30 }, { 0, 90, 30 }, + { 0, 99, 32 }, { 33, 33, 33 }, { 0, 107, 35 }, { 0, 107, 35 }, { 33, 41, 36 }, { 0, 115, 38 }, { 0, 115, 38 }, { 0, 115, 38 }, + { 0, 123, 40 }, { 33, 57, 41 }, { 0, 132, 43 }, { 0, 132, 43 }, { 33, 66, 44 }, { 0, 140, 46 }, { 0, 140, 46 }, { 66, 8, 47 }, + { 16, 115, 48 }, { 0, 148, 49 }, { 66, 16, 50 }, { 0, 156, 51 }, { 33, 90, 52 }, { 0, 165, 54 }, { 0, 165, 54 }, { 33, 99, 55 }, + { 24, 123, 56 }, { 0, 173, 57 }, { 66, 41, 58 }, { 0, 181, 59 }, { 8, 165, 60 }, { 74, 33, 61 }, { 0, 189, 62 }, { 33, 123, 63 }, + { 0, 198, 65 }, { 0, 198, 65 }, { 66, 66, 66 }, { 8, 189, 67 }, { 0, 206, 68 }, { 66, 74, 69 }, { 0, 214, 70 }, { 33, 148, 71 }, + { 99, 16, 72 }, { 0, 222, 73 }, { 66, 90, 74 }, { 107, 8, 75 }, { 0, 231, 76 }, { 66, 99, 77 }, { 0, 239, 78 }, { 33, 173, 79 }, + { 99, 41, 80 }, { 0, 247, 81 }, { 33, 181, 82 }, { 99, 49, 83 }, { 0, 255, 84 }, { 66, 123, 85 }, { 8, 247, 86 }, { 16, 231, 87 }, + { 66, 132, 88 }, { 8, 255, 89 }, { 33, 206, 90 }, { 99, 74, 91 }, { 16, 247, 92 }, { 41, 198, 93 }, { 16, 255, 94 }, { 24, 239, 95 }, + { 66, 156, 96 }, { 24, 247, 97 }, { 33, 231, 98 }, { 99, 99, 99 }, { 24, 255, 100 }, { 33, 239, 101 }, { 99, 107, 102 }, { 33, 247, 103 }, + { 66, 181, 104 }, { 132, 49, 105 }, { 33, 255, 106 }, { 99, 123, 107 }, { 140, 41, 108 }, { 41, 247, 109 }, { 99, 132, 110 }, { 41, 255, 111 }, + { 66, 206, 112 }, { 132, 74, 113 }, { 49, 247, 114 }, { 66, 214, 115 }, { 132, 82, 116 }, { 49, 255, 117 }, { 99, 156, 118 }, { 57, 247, 119 }, + { 66, 231, 120 }, { 99, 165, 121 }, { 57, 255, 122 }, { 66, 239, 123 }, { 132, 107, 124 }, { 66, 247, 125 }, { 74, 231, 126 }, { 140, 99, 127 }, + { 66, 255, 128 }, { 99, 189, 129 }, { 165, 57, 130 }, { 74, 247, 131 }, { 132, 132, 132 }, { 74, 255, 133 }, { 82, 239, 134 }, { 132, 140, 135 }, + { 82, 247, 136 }, { 99, 214, 137 }, { 165, 82, 138 }, { 82, 255, 139 }, { 132, 156, 140 }, { 173, 74, 141 }, { 90, 247, 142 }, { 132, 165, 143 }, + { 90, 255, 144 }, { 99, 239, 145 }, { 165, 107, 146 }, { 115, 214, 147 }, { 99, 247, 148 }, { 165, 115, 149 }, { 99, 255, 150 }, { 132, 189, 151 }, + { 198, 57, 152 }, { 107, 247, 153 }, { 132, 198, 154 }, { 123, 222, 155 }, { 107, 255, 156 }, { 165, 140, 157 }, { 115, 247, 158 }, { 132, 214, 159 }, + { 173, 132, 160 }, { 115, 255, 161 }, { 132, 222, 162 }, { 198, 90, 163 }, { 123, 247, 164 }, { 165, 165, 165 }, { 123, 255, 166 }, { 132, 239, 167 }, + { 165, 173, 168 }, { 231, 41, 169 }, { 132, 247, 170 }, { 198, 115, 171 }, { 132, 255, 172 }, { 165, 189, 173 }, { 206, 107, 174 }, { 140, 247, 175 }, + { 165, 198, 176 }, { 231, 66, 177 }, { 140, 255, 178 }, { 198, 140, 179 }, { 148, 247, 180 }, { 156, 231, 181 }, { 198, 148, 182 }, { 148, 255, 183 }, + { 165, 222, 184 }, { 231, 90, 185 }, { 156, 247, 186 }, { 165, 231, 187 }, { 156, 255, 188 }, { 165, 239, 189 }, { 198, 173, 190 }, { 165, 247, 192 }, + { 165, 247, 192 }, { 206, 165, 193 }, { 181, 222, 194 }, { 165, 255, 195 }, { 231, 123, 196 }, { 173, 247, 197 }, { 198, 198, 198 }, { 231, 132, 199 }, + { 173, 255, 200 }, { 198, 206, 201 }, { 181, 247, 203 }, { 181, 247, 203 }, { 231, 148, 204 }, { 181, 255, 205 }, { 198, 222, 206 }, { 239, 140, 207 }, + { 189, 247, 208 }, { 198, 231, 209 }, { 189, 255, 211 }, { 189, 255, 211 }, { 231, 173, 212 }, { 198, 247, 214 }, { 198, 247, 214 }, { 231, 181, 215 }, + { 198, 255, 217 }, { 198, 255, 217 }, { 198, 255, 217 }, { 206, 247, 219 }, { 214, 231, 220 }, { 206, 255, 222 }, { 206, 255, 222 }, { 231, 206, 223 }, + { 214, 247, 225 }, { 214, 247, 225 }, { 239, 198, 226 }, { 214, 255, 227 }, { 222, 239, 228 }, { 222, 239, 228 }, { 222, 247, 230 }, { 231, 231, 231 }, + { 222, 255, 233 }, { 222, 255, 233 }, { 231, 239, 234 }, { 231, 239, 234 }, { 231, 247, 236 }, { 231, 247, 236 }, { 231, 255, 239 }, { 231, 255, 239 }, + { 231, 255, 239 }, { 239, 247, 242 }, { 239, 247, 242 }, { 239, 247, 242 }, { 239, 255, 244 }, { 239, 255, 244 }, { 247, 247, 247 }, { 247, 247, 247 }, + { 247, 247, 247 }, { 247, 255, 250 }, { 247, 255, 250 }, { 247, 255, 250 }, { 255, 247, 252 }, { 255, 247, 252 }, { 255, 255, 255 }, { 255, 255, 255 }, + } +}; + +Table g_mode4_rgb_high_i1= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 8, 1 }, { 0, 16, 2 }, { 0, 24, 3 }, { 0, 24, 3 }, { 0, 33, 5 }, { 0, 41, 6 }, { 0, 49, 7 }, + { 0, 57, 8 }, { 0, 66, 9 }, { 0, 74, 10 }, { 0, 74, 10 }, { 0, 82, 12 }, { 0, 90, 13 }, { 0, 99, 14 }, { 0, 107, 15 }, + { 0, 115, 16 }, { 0, 123, 17 }, { 8, 82, 18 }, { 0, 132, 19 }, { 0, 140, 20 }, { 0, 148, 21 }, { 0, 156, 22 }, { 0, 165, 23 }, + { 0, 173, 24 }, { 0, 181, 25 }, { 16, 90, 26 }, { 0, 189, 27 }, { 0, 198, 28 }, { 0, 206, 29 }, { 0, 214, 30 }, { 0, 222, 31 }, + { 0, 231, 32 }, { 8, 189, 33 }, { 0, 239, 34 }, { 0, 247, 35 }, { 0, 255, 36 }, { 8, 214, 37 }, { 8, 222, 38 }, { 8, 231, 39 }, + { 8, 239, 40 }, { 24, 148, 41 }, { 8, 247, 42 }, { 8, 255, 43 }, { 16, 214, 44 }, { 16, 222, 45 }, { 16, 231, 46 }, { 16, 239, 47 }, + { 16, 247, 48 }, { 33, 148, 49 }, { 16, 255, 50 }, { 24, 214, 51 }, { 24, 222, 52 }, { 24, 231, 53 }, { 24, 239, 54 }, { 24, 247, 55 }, + { 24, 255, 56 }, { 33, 206, 57 }, { 33, 214, 58 }, { 49, 123, 59 }, { 33, 222, 60 }, { 33, 231, 61 }, { 33, 239, 62 }, { 33, 247, 63 }, + { 33, 255, 64 }, { 41, 214, 65 }, { 41, 222, 66 }, { 66, 74, 67 }, { 41, 231, 68 }, { 41, 239, 69 }, { 41, 247, 70 }, { 41, 255, 71 }, + { 49, 214, 72 }, { 49, 222, 73 }, { 57, 181, 74 }, { 49, 231, 75 }, { 49, 239, 76 }, { 49, 247, 77 }, { 49, 255, 78 }, { 57, 214, 79 }, + { 57, 222, 80 }, { 57, 231, 81 }, { 66, 181, 82 }, { 57, 239, 83 }, { 57, 247, 84 }, { 57, 255, 85 }, { 66, 206, 86 }, { 66, 214, 87 }, + { 66, 222, 88 }, { 66, 231, 89 }, { 66, 239, 90 }, { 66, 247, 91 }, { 82, 156, 92 }, { 66, 255, 93 }, { 74, 214, 94 }, { 74, 222, 95 }, + { 74, 231, 96 }, { 74, 239, 97 }, { 74, 247, 98 }, { 74, 255, 99 }, { 99, 107, 100 }, { 82, 214, 101 }, { 82, 222, 102 }, { 82, 231, 103 }, + { 82, 239, 104 }, { 82, 247, 105 }, { 82, 255, 106 }, { 90, 214, 107 }, { 99, 165, 108 }, { 90, 222, 109 }, { 90, 231, 110 }, { 90, 239, 111 }, + { 90, 247, 112 }, { 90, 255, 113 }, { 99, 206, 114 }, { 99, 214, 115 }, { 99, 222, 116 }, { 107, 181, 117 }, { 99, 231, 118 }, { 99, 239, 119 }, + { 99, 247, 120 }, { 99, 255, 121 }, { 107, 214, 122 }, { 107, 222, 123 }, { 107, 231, 124 }, { 115, 189, 125 }, { 107, 239, 126 }, { 107, 247, 127 }, + { 107, 255, 128 }, { 115, 214, 129 }, { 115, 222, 130 }, { 115, 231, 131 }, { 115, 239, 132 }, { 132, 140, 133 }, { 115, 247, 134 }, { 115, 255, 135 }, + { 123, 214, 136 }, { 123, 222, 137 }, { 123, 231, 138 }, { 123, 239, 139 }, { 123, 247, 140 }, { 132, 198, 141 }, { 123, 255, 142 }, { 148, 115, 143 }, + { 132, 214, 144 }, { 132, 222, 145 }, { 132, 231, 146 }, { 132, 239, 147 }, { 132, 247, 148 }, { 132, 255, 149 }, { 140, 214, 150 }, { 156, 123, 151 }, + { 140, 222, 152 }, { 140, 231, 153 }, { 140, 239, 154 }, { 140, 247, 155 }, { 140, 255, 156 }, { 148, 214, 157 }, { 148, 222, 158 }, { 165, 123, 159 }, + { 148, 231, 160 }, { 148, 239, 161 }, { 148, 247, 162 }, { 148, 255, 163 }, { 156, 214, 164 }, { 156, 222, 165 }, { 165, 173, 166 }, { 156, 231, 167 }, + { 156, 239, 168 }, { 156, 247, 169 }, { 156, 255, 170 }, { 165, 206, 171 }, { 165, 214, 172 }, { 165, 222, 173 }, { 165, 231, 174 }, { 165, 239, 175 }, + { 181, 148, 176 }, { 165, 247, 177 }, { 165, 255, 178 }, { 173, 214, 179 }, { 173, 222, 180 }, { 173, 231, 181 }, { 173, 239, 182 }, { 173, 247, 183 }, + { 189, 156, 184 }, { 173, 255, 185 }, { 181, 214, 186 }, { 181, 222, 187 }, { 181, 231, 188 }, { 181, 239, 189 }, { 181, 247, 190 }, { 181, 255, 191 }, + { 198, 156, 192 }, { 189, 214, 193 }, { 189, 222, 194 }, { 189, 231, 195 }, { 189, 239, 196 }, { 189, 247, 197 }, { 189, 255, 198 }, { 198, 206, 199 }, + { 198, 214, 200 }, { 198, 222, 201 }, { 206, 181, 202 }, { 198, 231, 203 }, { 198, 239, 204 }, { 198, 247, 205 }, { 198, 255, 206 }, { 206, 214, 207 }, + { 206, 222, 208 }, { 214, 181, 209 }, { 206, 231, 210 }, { 206, 239, 211 }, { 206, 247, 212 }, { 206, 255, 213 }, { 214, 214, 214 }, { 214, 222, 215 }, + { 214, 231, 216 }, { 222, 189, 217 }, { 214, 239, 218 }, { 214, 247, 219 }, { 214, 255, 220 }, { 222, 214, 221 }, { 222, 222, 222 }, { 222, 231, 223 }, + { 222, 239, 224 }, { 231, 189, 225 }, { 222, 247, 226 }, { 222, 255, 227 }, { 247, 115, 228 }, { 231, 214, 229 }, { 231, 222, 230 }, { 231, 231, 231 }, + { 231, 239, 232 }, { 231, 247, 233 }, { 231, 255, 234 }, { 239, 214, 235 }, { 255, 123, 236 }, { 239, 222, 237 }, { 239, 231, 238 }, { 239, 239, 239 }, + { 239, 247, 240 }, { 239, 255, 241 }, { 247, 214, 242 }, { 247, 222, 243 }, { 247, 222, 243 }, { 247, 231, 245 }, { 247, 239, 246 }, { 247, 247, 247 }, + { 247, 255, 248 }, { 255, 214, 249 }, { 255, 222, 250 }, { 255, 222, 250 }, { 255, 231, 252 }, { 255, 239, 253 }, { 255, 247, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode4_rgb_high_i2= +{ + 2, + 0, + { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 8, 2 }, { 0, 8, 2 }, { 0, 16, 5 }, { 0, 16, 5 }, { 8, 0, 6 }, { 0, 24, 7 }, + { 8, 8, 8 }, { 0, 33, 9 }, { 8, 16, 10 }, { 0, 41, 12 }, { 0, 41, 12 }, { 8, 24, 13 }, { 0, 49, 14 }, { 8, 33, 15 }, + { 0, 57, 16 }, { 8, 41, 17 }, { 16, 24, 18 }, { 0, 66, 19 }, { 8, 49, 20 }, { 0, 74, 21 }, { 8, 57, 22 }, { 0, 82, 23 }, + { 8, 66, 24 }, { 0, 90, 25 }, { 33, 8, 26 }, { 8, 74, 27 }, { 0, 99, 28 }, { 8, 82, 29 }, { 0, 107, 30 }, { 8, 90, 31 }, + { 0, 115, 32 }, { 24, 57, 33 }, { 8, 99, 34 }, { 0, 123, 35 }, { 8, 107, 36 }, { 0, 132, 37 }, { 8, 115, 38 }, { 0, 140, 39 }, + { 8, 123, 40 }, { 41, 41, 41 }, { 0, 148, 42 }, { 8, 132, 43 }, { 0, 156, 44 }, { 8, 140, 45 }, { 0, 165, 46 }, { 8, 148, 47 }, + { 41, 66, 48 }, { 0, 173, 49 }, { 8, 156, 50 }, { 0, 181, 51 }, { 8, 165, 52 }, { 0, 189, 53 }, { 8, 173, 54 }, { 16, 156, 55 }, + { 0, 198, 56 }, { 8, 181, 57 }, { 0, 206, 58 }, { 8, 189, 59 }, { 0, 214, 60 }, { 8, 198, 61 }, { 0, 222, 62 }, { 33, 140, 63 }, + { 8, 206, 64 }, { 0, 231, 65 }, { 8, 214, 66 }, { 0, 239, 67 }, { 8, 222, 68 }, { 0, 247, 69 }, { 24, 189, 70 }, { 8, 231, 71 }, + { 0, 255, 72 }, { 8, 239, 73 }, { 16, 222, 74 }, { 8, 247, 75 }, { 16, 231, 76 }, { 8, 255, 77 }, { 41, 173, 78 }, { 16, 239, 79 }, + { 24, 222, 80 }, { 16, 247, 81 }, { 24, 231, 82 }, { 16, 255, 83 }, { 24, 239, 84 }, { 41, 198, 85 }, { 33, 222, 86 }, { 24, 247, 87 }, + { 49, 189, 88 }, { 24, 255, 89 }, { 41, 214, 90 }, { 33, 239, 91 }, { 41, 222, 92 }, { 33, 247, 93 }, { 41, 231, 94 }, { 33, 255, 95 }, + { 66, 173, 96 }, { 41, 239, 97 }, { 49, 222, 98 }, { 41, 247, 99 }, { 49, 231, 100 }, { 41, 255, 101 }, { 49, 239, 102 }, { 57, 222, 103 }, + { 74, 181, 104 }, { 49, 247, 105 }, { 57, 231, 106 }, { 49, 255, 107 }, { 57, 239, 108 }, { 74, 198, 109 }, { 57, 247, 110 }, { 74, 206, 111 }, + { 66, 231, 112 }, { 57, 255, 113 }, { 107, 132, 114 }, { 66, 239, 115 }, { 74, 222, 116 }, { 66, 247, 117 }, { 74, 231, 118 }, { 66, 255, 119 }, + { 74, 239, 120 }, { 82, 222, 121 }, { 99, 181, 122 }, { 74, 247, 123 }, { 82, 231, 124 }, { 74, 255, 125 }, { 82, 239, 126 }, { 90, 222, 127 }, + { 82, 247, 128 }, { 99, 206, 129 }, { 90, 231, 130 }, { 82, 255, 131 }, { 90, 239, 132 }, { 107, 198, 133 }, { 90, 247, 134 }, { 107, 206, 135 }, + { 90, 255, 136 }, { 107, 214, 137 }, { 99, 239, 138 }, { 107, 222, 139 }, { 140, 140, 140 }, { 99, 247, 141 }, { 107, 231, 142 }, { 99, 255, 143 }, + { 107, 239, 144 }, { 115, 222, 145 }, { 107, 247, 146 }, { 140, 165, 147 }, { 115, 231, 148 }, { 107, 255, 149 }, { 115, 239, 150 }, { 123, 222, 151 }, + { 115, 247, 152 }, { 123, 231, 153 }, { 115, 255, 154 }, { 132, 214, 155 }, { 123, 239, 156 }, { 132, 222, 157 }, { 123, 247, 158 }, { 140, 206, 159 }, + { 123, 255, 160 }, { 140, 214, 161 }, { 132, 239, 162 }, { 140, 222, 163 }, { 132, 247, 164 }, { 156, 189, 165 }, { 140, 231, 166 }, { 132, 255, 167 }, + { 140, 239, 168 }, { 148, 222, 169 }, { 140, 247, 170 }, { 148, 231, 171 }, { 140, 255, 172 }, { 173, 173, 173 }, { 148, 239, 174 }, { 156, 222, 175 }, + { 148, 247, 176 }, { 156, 231, 177 }, { 148, 255, 178 }, { 156, 239, 179 }, { 173, 198, 180 }, { 165, 222, 181 }, { 156, 247, 182 }, { 181, 189, 183 }, + { 156, 255, 184 }, { 173, 214, 185 }, { 165, 239, 186 }, { 173, 222, 187 }, { 165, 247, 188 }, { 173, 231, 189 }, { 165, 255, 190 }, { 198, 173, 191 }, + { 173, 239, 192 }, { 181, 222, 193 }, { 173, 247, 194 }, { 181, 231, 195 }, { 173, 255, 196 }, { 181, 239, 197 }, { 189, 222, 198 }, { 206, 181, 199 }, + { 181, 247, 200 }, { 189, 231, 201 }, { 181, 255, 202 }, { 189, 239, 203 }, { 206, 198, 204 }, { 189, 247, 205 }, { 206, 206, 206 }, { 198, 231, 207 }, + { 189, 255, 208 }, { 239, 132, 209 }, { 198, 239, 210 }, { 206, 222, 211 }, { 198, 247, 212 }, { 206, 231, 213 }, { 198, 255, 214 }, { 206, 239, 215 }, + { 214, 222, 216 }, { 231, 181, 217 }, { 206, 247, 218 }, { 214, 231, 219 }, { 206, 255, 220 }, { 214, 239, 221 }, { 222, 222, 222 }, { 214, 247, 223 }, + { 231, 206, 224 }, { 222, 231, 225 }, { 214, 255, 226 }, { 222, 239, 227 }, { 231, 222, 228 }, { 222, 247, 229 }, { 239, 206, 230 }, { 222, 255, 231 }, + { 239, 214, 232 }, { 231, 239, 233 }, { 239, 222, 234 }, { 247, 206, 235 }, { 231, 247, 236 }, { 239, 231, 237 }, { 231, 255, 238 }, { 239, 239, 239 }, + { 247, 222, 240 }, { 239, 247, 241 }, { 239, 247, 241 }, { 247, 231, 243 }, { 239, 255, 244 }, { 247, 239, 245 }, { 255, 222, 246 }, { 247, 247, 247 }, + { 255, 231, 248 }, { 247, 255, 249 }, { 247, 255, 249 }, { 255, 239, 251 }, { 255, 239, 251 }, { 255, 247, 253 }, { 255, 247, 253 }, { 255, 255, 255 }, + } +}; + +Table g_mode4_rgb_high_i3= +{ + 3, + 0, + { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 8, 3 }, { 0, 8, 3 }, { 0, 8, 3 }, { 8, 0, 5 }, { 0, 16, 7 }, { 0, 16, 7 }, + { 8, 8, 8 }, { 16, 0, 9 }, { 0, 24, 10 }, { 8, 16, 11 }, { 8, 16, 11 }, { 16, 8, 13 }, { 0, 33, 14 }, { 8, 24, 15 }, + { 16, 16, 16 }, { 0, 41, 17 }, { 0, 41, 17 }, { 8, 33, 19 }, { 0, 49, 21 }, { 0, 49, 21 }, { 8, 41, 22 }, { 16, 33, 23 }, + { 0, 57, 24 }, { 8, 49, 25 }, { 33, 16, 26 }, { 16, 41, 27 }, { 0, 66, 28 }, { 8, 57, 29 }, { 16, 49, 30 }, { 0, 74, 31 }, + { 8, 66, 32 }, { 16, 57, 33 }, { 41, 24, 34 }, { 0, 82, 35 }, { 8, 74, 36 }, { 16, 66, 37 }, { 0, 90, 38 }, { 8, 82, 39 }, + { 16, 74, 40 }, { 41, 41, 41 }, { 0, 99, 42 }, { 8, 90, 43 }, { 16, 82, 44 }, { 0, 107, 45 }, { 8, 99, 46 }, { 16, 90, 47 }, + { 24, 82, 48 }, { 0, 115, 49 }, { 8, 107, 50 }, { 16, 99, 51 }, { 0, 123, 52 }, { 8, 115, 53 }, { 16, 107, 54 }, { 41, 74, 55 }, + { 0, 132, 56 }, { 8, 123, 57 }, { 16, 115, 58 }, { 0, 140, 59 }, { 8, 132, 60 }, { 16, 123, 61 }, { 0, 148, 62 }, { 49, 82, 63 }, + { 8, 140, 64 }, { 16, 132, 65 }, { 0, 156, 66 }, { 8, 148, 67 }, { 16, 140, 68 }, { 41, 107, 69 }, { 0, 165, 70 }, { 33, 123, 71 }, + { 16, 148, 72 }, { 0, 173, 73 }, { 8, 165, 74 }, { 16, 156, 75 }, { 0, 181, 76 }, { 49, 115, 77 }, { 8, 173, 78 }, { 16, 165, 79 }, + { 0, 189, 80 }, { 8, 181, 81 }, { 16, 173, 82 }, { 24, 165, 83 }, { 0, 198, 84 }, { 33, 156, 85 }, { 16, 181, 86 }, { 0, 206, 87 }, + { 8, 198, 88 }, { 16, 189, 89 }, { 0, 214, 90 }, { 49, 148, 91 }, { 8, 206, 92 }, { 16, 198, 93 }, { 0, 222, 94 }, { 8, 214, 95 }, + { 16, 206, 96 }, { 0, 231, 97 }, { 8, 222, 98 }, { 33, 189, 99 }, { 16, 214, 100 }, { 0, 239, 101 }, { 8, 231, 102 }, { 16, 222, 103 }, + { 0, 247, 104 }, { 8, 239, 105 }, { 33, 206, 106 }, { 16, 231, 107 }, { 0, 255, 108 }, { 8, 247, 109 }, { 16, 239, 110 }, { 24, 231, 111 }, + { 8, 255, 112 }, { 16, 247, 113 }, { 41, 214, 114 }, { 24, 239, 115 }, { 57, 198, 116 }, { 16, 255, 117 }, { 24, 247, 118 }, { 49, 214, 119 }, + { 33, 239, 120 }, { 24, 255, 121 }, { 49, 222, 122 }, { 33, 247, 123 }, { 82, 181, 124 }, { 41, 239, 125 }, { 49, 231, 126 }, { 33, 255, 127 }, + { 41, 247, 128 }, { 49, 239, 129 }, { 57, 231, 130 }, { 41, 255, 131 }, { 66, 222, 132 }, { 49, 247, 133 }, { 57, 239, 134 }, { 107, 173, 135 }, + { 49, 255, 136 }, { 57, 247, 137 }, { 82, 214, 138 }, { 66, 239, 139 }, { 74, 231, 140 }, { 57, 255, 141 }, { 66, 247, 142 }, { 115, 181, 143 }, + { 74, 239, 144 }, { 82, 231, 145 }, { 66, 255, 146 }, { 74, 247, 147 }, { 82, 239, 148 }, { 90, 231, 149 }, { 74, 255, 150 }, { 99, 222, 151 }, + { 82, 247, 152 }, { 90, 239, 153 }, { 140, 173, 154 }, { 82, 255, 155 }, { 90, 247, 156 }, { 115, 214, 157 }, { 99, 239, 158 }, { 107, 231, 159 }, + { 90, 255, 160 }, { 99, 247, 161 }, { 148, 181, 162 }, { 107, 239, 163 }, { 115, 231, 164 }, { 99, 255, 165 }, { 107, 247, 166 }, { 115, 239, 167 }, + { 140, 206, 168 }, { 107, 255, 169 }, { 132, 222, 170 }, { 115, 247, 171 }, { 123, 239, 172 }, { 173, 173, 173 }, { 115, 255, 174 }, { 123, 247, 175 }, + { 148, 214, 176 }, { 132, 239, 177 }, { 140, 231, 178 }, { 123, 255, 179 }, { 156, 214, 180 }, { 132, 247, 181 }, { 140, 239, 182 }, { 148, 231, 183 }, + { 132, 255, 184 }, { 140, 247, 185 }, { 148, 239, 186 }, { 173, 206, 187 }, { 156, 231, 188 }, { 140, 255, 189 }, { 148, 247, 190 }, { 156, 239, 191 }, + { 181, 206, 192 }, { 148, 255, 193 }, { 156, 247, 194 }, { 181, 214, 195 }, { 165, 239, 196 }, { 173, 231, 197 }, { 156, 255, 198 }, { 206, 189, 199 }, + { 165, 247, 200 }, { 173, 239, 201 }, { 181, 231, 202 }, { 165, 255, 203 }, { 173, 247, 204 }, { 181, 239, 205 }, { 206, 206, 206 }, { 189, 231, 207 }, + { 173, 255, 208 }, { 181, 247, 209 }, { 189, 239, 210 }, { 214, 206, 211 }, { 181, 255, 212 }, { 189, 247, 213 }, { 214, 214, 214 }, { 198, 239, 215 }, + { 247, 173, 216 }, { 189, 255, 217 }, { 239, 189, 218 }, { 198, 247, 219 }, { 206, 239, 220 }, { 214, 231, 221 }, { 198, 255, 222 }, { 206, 247, 223 }, + { 231, 214, 224 }, { 214, 239, 225 }, { 222, 231, 226 }, { 206, 255, 227 }, { 214, 247, 228 }, { 222, 239, 229 }, { 247, 206, 230 }, { 214, 255, 231 }, + { 239, 222, 232 }, { 222, 247, 233 }, { 231, 239, 234 }, { 222, 255, 236 }, { 222, 255, 236 }, { 222, 255, 236 }, { 231, 247, 238 }, { 239, 239, 239 }, + { 247, 231, 240 }, { 231, 255, 241 }, { 239, 247, 242 }, { 239, 247, 242 }, { 247, 239, 244 }, { 255, 231, 245 }, { 239, 255, 246 }, { 247, 247, 247 }, + { 255, 239, 248 }, { 247, 255, 250 }, { 247, 255, 250 }, { 247, 255, 250 }, { 255, 247, 252 }, { 255, 247, 252 }, { 255, 255, 255 }, { 255, 255, 255 }, + } +}; + +Table g_mode4_a_low= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 4, 1 }, { 0, 4, 1 }, { 0, 8, 3 }, { 0, 12, 4 }, { 0, 16, 5 }, { 0, 16, 5 }, { 0, 20, 7 }, + { 0, 24, 8 }, { 0, 28, 9 }, { 0, 28, 9 }, { 0, 32, 11 }, { 0, 36, 12 }, { 0, 40, 13 }, { 0, 44, 14 }, { 4, 36, 15 }, + { 0, 48, 16 }, { 0, 52, 17 }, { 0, 56, 18 }, { 8, 40, 19 }, { 0, 60, 20 }, { 0, 65, 21 }, { 4, 60, 22 }, { 0, 69, 23 }, + { 0, 73, 24 }, { 0, 77, 25 }, { 12, 56, 26 }, { 0, 81, 27 }, { 0, 85, 28 }, { 0, 89, 29 }, { 16, 60, 30 }, { 0, 93, 31 }, + { 0, 97, 32 }, { 0, 101, 33 }, { 0, 105, 34 }, { 4, 97, 35 }, { 0, 109, 36 }, { 0, 113, 37 }, { 0, 117, 38 }, { 8, 101, 39 }, + { 0, 121, 40 }, { 0, 125, 41 }, { 4, 121, 42 }, { 0, 130, 43 }, { 0, 134, 44 }, { 0, 138, 45 }, { 8, 125, 46 }, { 0, 142, 47 }, + { 0, 146, 48 }, { 0, 150, 49 }, { 16, 121, 50 }, { 0, 154, 51 }, { 0, 158, 52 }, { 0, 162, 53 }, { 0, 166, 54 }, { 4, 158, 55 }, + { 0, 170, 56 }, { 0, 174, 57 }, { 0, 178, 58 }, { 8, 162, 59 }, { 0, 182, 60 }, { 0, 186, 61 }, { 0, 190, 62 }, { 12, 166, 63 }, + { 0, 195, 64 }, { 0, 199, 65 }, { 8, 186, 66 }, { 0, 203, 67 }, { 0, 207, 68 }, { 0, 211, 69 }, { 12, 190, 70 }, { 0, 215, 71 }, + { 0, 219, 72 }, { 0, 223, 73 }, { 0, 227, 74 }, { 4, 219, 75 }, { 0, 231, 76 }, { 0, 235, 77 }, { 0, 239, 78 }, { 8, 223, 79 }, + { 0, 243, 80 }, { 0, 247, 81 }, { 0, 251, 82 }, { 12, 227, 83 }, { 0, 255, 84 }, { 4, 251, 85 }, { 4, 255, 86 }, { 16, 231, 87 }, + { 8, 251, 88 }, { 8, 255, 89 }, { 12, 251, 90 }, { 20, 235, 91 }, { 12, 255, 92 }, { 16, 251, 93 }, { 16, 255, 94 }, { 24, 239, 95 }, + { 20, 251, 96 }, { 20, 255, 97 }, { 24, 251, 98 }, { 28, 243, 99 }, { 24, 255, 100 }, { 28, 251, 101 }, { 28, 255, 102 }, { 32, 247, 103 }, + { 32, 251, 104 }, { 32, 255, 105 }, { 56, 207, 106 }, { 36, 251, 107 }, { 36, 255, 108 }, { 40, 251, 109 }, { 60, 211, 110 }, { 40, 255, 111 }, + { 44, 251, 112 }, { 44, 255, 113 }, { 65, 215, 114 }, { 48, 251, 115 }, { 48, 255, 116 }, { 52, 251, 117 }, { 65, 227, 118 }, { 52, 255, 119 }, + { 56, 251, 120 }, { 56, 255, 121 }, { 65, 239, 122 }, { 60, 251, 123 }, { 60, 255, 124 }, { 65, 247, 125 }, { 65, 251, 126 }, { 65, 255, 127 }, + { 77, 231, 128 }, { 69, 251, 129 }, { 69, 255, 130 }, { 73, 251, 131 }, { 81, 235, 132 }, { 73, 255, 133 }, { 77, 251, 134 }, { 77, 255, 135 }, + { 85, 239, 136 }, { 81, 251, 137 }, { 81, 255, 138 }, { 85, 251, 139 }, { 89, 243, 140 }, { 85, 255, 141 }, { 89, 251, 142 }, { 89, 255, 143 }, + { 93, 247, 144 }, { 93, 251, 145 }, { 93, 255, 146 }, { 117, 207, 147 }, { 97, 251, 148 }, { 97, 255, 149 }, { 101, 251, 150 }, { 121, 211, 151 }, + { 101, 255, 152 }, { 105, 251, 153 }, { 105, 255, 154 }, { 125, 215, 155 }, { 109, 251, 156 }, { 109, 255, 157 }, { 113, 251, 158 }, { 130, 219, 159 }, + { 113, 255, 160 }, { 117, 251, 161 }, { 117, 255, 162 }, { 130, 231, 163 }, { 121, 251, 164 }, { 121, 255, 165 }, { 125, 251, 166 }, { 130, 243, 167 }, + { 125, 255, 168 }, { 138, 231, 169 }, { 130, 251, 170 }, { 130, 255, 171 }, { 134, 251, 172 }, { 142, 235, 173 }, { 134, 255, 174 }, { 138, 251, 175 }, + { 138, 255, 176 }, { 146, 239, 177 }, { 142, 251, 178 }, { 142, 255, 179 }, { 146, 251, 180 }, { 150, 243, 181 }, { 146, 255, 182 }, { 150, 251, 183 }, + { 150, 255, 184 }, { 154, 247, 185 }, { 154, 251, 186 }, { 154, 255, 187 }, { 178, 207, 188 }, { 158, 251, 189 }, { 158, 255, 190 }, { 162, 251, 191 }, + { 182, 211, 192 }, { 162, 255, 193 }, { 166, 251, 194 }, { 166, 255, 195 }, { 186, 215, 196 }, { 170, 251, 197 }, { 170, 255, 198 }, { 174, 251, 199 }, + { 190, 219, 200 }, { 174, 255, 201 }, { 178, 251, 202 }, { 178, 255, 203 }, { 195, 223, 204 }, { 182, 251, 205 }, { 182, 255, 206 }, { 186, 251, 207 }, + { 195, 235, 208 }, { 186, 255, 209 }, { 190, 251, 210 }, { 190, 255, 211 }, { 195, 247, 212 }, { 195, 251, 213 }, { 203, 235, 214 }, { 195, 255, 215 }, + { 199, 251, 216 }, { 199, 255, 217 }, { 207, 239, 218 }, { 203, 251, 219 }, { 203, 255, 220 }, { 207, 251, 221 }, { 211, 243, 222 }, { 207, 255, 223 }, + { 211, 251, 224 }, { 211, 255, 225 }, { 215, 247, 226 }, { 215, 251, 227 }, { 215, 255, 228 }, { 239, 207, 229 }, { 219, 251, 230 }, { 219, 255, 231 }, + { 223, 251, 232 }, { 243, 211, 233 }, { 223, 255, 234 }, { 227, 251, 235 }, { 227, 255, 236 }, { 247, 215, 237 }, { 231, 251, 238 }, { 231, 255, 239 }, + { 235, 251, 240 }, { 251, 219, 241 }, { 235, 255, 242 }, { 239, 251, 243 }, { 239, 255, 244 }, { 255, 223, 245 }, { 243, 251, 246 }, { 243, 255, 247 }, + { 247, 251, 248 }, { 247, 251, 248 }, { 247, 255, 250 }, { 251, 251, 251 }, { 251, 255, 252 }, { 251, 255, 252 }, { 255, 251, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode4_a_high_i1= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 4, 1 }, { 0, 12, 2 }, { 0, 20, 3 }, { 0, 28, 4 }, { 0, 32, 5 }, { 0, 40, 6 }, { 0, 48, 7 }, + { 0, 56, 8 }, { 0, 65, 9 }, { 0, 69, 10 }, { 0, 77, 11 }, { 0, 85, 12 }, { 0, 89, 13 }, { 0, 97, 14 }, { 0, 105, 15 }, + { 0, 113, 16 }, { 0, 121, 17 }, { 0, 125, 18 }, { 0, 134, 19 }, { 0, 142, 20 }, { 0, 146, 21 }, { 0, 154, 22 }, { 0, 162, 23 }, + { 0, 170, 24 }, { 0, 178, 25 }, { 0, 182, 26 }, { 0, 190, 27 }, { 0, 199, 28 }, { 0, 203, 29 }, { 0, 211, 30 }, { 0, 219, 31 }, + { 0, 227, 32 }, { 0, 235, 33 }, { 0, 239, 34 }, { 0, 247, 35 }, { 0, 255, 36 }, { 4, 239, 37 }, { 4, 243, 38 }, { 4, 251, 39 }, + { 8, 235, 40 }, { 8, 243, 41 }, { 8, 247, 42 }, { 8, 255, 43 }, { 12, 239, 44 }, { 12, 247, 45 }, { 12, 251, 46 }, { 16, 235, 47 }, + { 16, 243, 48 }, { 16, 251, 49 }, { 16, 255, 50 }, { 20, 239, 51 }, { 20, 247, 52 }, { 20, 255, 53 }, { 24, 235, 54 }, { 24, 243, 55 }, + { 24, 251, 56 }, { 28, 231, 57 }, { 28, 239, 58 }, { 28, 247, 59 }, { 28, 255, 60 }, { 32, 235, 61 }, { 32, 243, 62 }, { 32, 251, 63 }, + { 36, 235, 64 }, { 36, 239, 65 }, { 36, 247, 66 }, { 36, 255, 67 }, { 40, 239, 68 }, { 40, 243, 69 }, { 40, 251, 70 }, { 44, 235, 71 }, + { 44, 243, 72 }, { 44, 247, 73 }, { 44, 255, 74 }, { 48, 239, 75 }, { 48, 247, 76 }, { 48, 251, 77 }, { 52, 235, 78 }, { 52, 243, 79 }, + { 52, 251, 80 }, { 52, 255, 81 }, { 56, 239, 82 }, { 56, 247, 83 }, { 56, 255, 84 }, { 60, 235, 85 }, { 60, 243, 86 }, { 60, 251, 87 }, + { 65, 227, 88 }, { 65, 235, 89 }, { 65, 243, 90 }, { 65, 247, 91 }, { 65, 255, 92 }, { 69, 239, 93 }, { 69, 247, 94 }, { 69, 251, 95 }, + { 73, 235, 96 }, { 73, 243, 97 }, { 73, 251, 98 }, { 73, 255, 99 }, { 77, 239, 100 }, { 77, 247, 101 }, { 77, 255, 102 }, { 81, 235, 103 }, + { 81, 243, 104 }, { 81, 251, 105 }, { 85, 231, 106 }, { 85, 239, 107 }, { 85, 247, 108 }, { 85, 255, 109 }, { 89, 235, 110 }, { 89, 243, 111 }, + { 89, 251, 112 }, { 93, 235, 113 }, { 93, 239, 114 }, { 93, 247, 115 }, { 93, 255, 116 }, { 97, 239, 117 }, { 97, 243, 118 }, { 97, 251, 119 }, + { 101, 235, 120 }, { 101, 243, 121 }, { 101, 247, 122 }, { 101, 255, 123 }, { 105, 239, 124 }, { 105, 247, 125 }, { 105, 251, 126 }, { 109, 235, 127 }, + { 109, 243, 128 }, { 109, 251, 129 }, { 109, 255, 130 }, { 113, 239, 131 }, { 113, 247, 132 }, { 113, 255, 133 }, { 117, 235, 134 }, { 117, 243, 135 }, + { 117, 251, 136 }, { 121, 235, 137 }, { 121, 239, 138 }, { 121, 247, 139 }, { 121, 255, 140 }, { 125, 239, 141 }, { 125, 243, 142 }, { 125, 251, 143 }, + { 130, 227, 144 }, { 130, 235, 145 }, { 130, 243, 146 }, { 130, 251, 147 }, { 130, 255, 148 }, { 134, 239, 149 }, { 134, 247, 150 }, { 134, 255, 151 }, + { 138, 235, 152 }, { 138, 243, 153 }, { 138, 251, 154 }, { 142, 231, 155 }, { 142, 239, 156 }, { 142, 247, 157 }, { 142, 255, 158 }, { 146, 235, 159 }, + { 146, 243, 160 }, { 146, 251, 161 }, { 150, 235, 162 }, { 150, 239, 163 }, { 150, 247, 164 }, { 150, 255, 165 }, { 154, 239, 166 }, { 154, 243, 167 }, + { 154, 251, 168 }, { 158, 235, 169 }, { 158, 243, 170 }, { 158, 247, 171 }, { 158, 255, 172 }, { 162, 239, 173 }, { 162, 247, 174 }, { 162, 251, 175 }, + { 166, 235, 176 }, { 166, 243, 177 }, { 166, 251, 178 }, { 166, 255, 179 }, { 170, 239, 180 }, { 170, 247, 181 }, { 170, 255, 182 }, { 174, 235, 183 }, + { 174, 243, 184 }, { 174, 251, 185 }, { 178, 235, 186 }, { 178, 239, 187 }, { 178, 247, 188 }, { 178, 255, 189 }, { 182, 239, 190 }, { 182, 243, 191 }, + { 182, 251, 192 }, { 186, 235, 193 }, { 186, 243, 194 }, { 186, 247, 195 }, { 186, 255, 196 }, { 190, 239, 197 }, { 190, 247, 198 }, { 190, 251, 199 }, + { 195, 227, 200 }, { 195, 235, 201 }, { 195, 243, 202 }, { 195, 251, 203 }, { 199, 231, 204 }, { 199, 239, 205 }, { 199, 247, 206 }, { 199, 255, 207 }, + { 203, 235, 208 }, { 203, 243, 209 }, { 203, 251, 210 }, { 207, 235, 211 }, { 207, 239, 212 }, { 207, 247, 213 }, { 207, 255, 214 }, { 211, 239, 215 }, + { 211, 243, 216 }, { 211, 251, 217 }, { 215, 235, 218 }, { 215, 243, 219 }, { 215, 247, 220 }, { 215, 255, 221 }, { 219, 239, 222 }, { 219, 247, 223 }, + { 219, 251, 224 }, { 223, 235, 225 }, { 223, 243, 226 }, { 223, 251, 227 }, { 223, 255, 228 }, { 227, 239, 229 }, { 227, 247, 230 }, { 227, 255, 231 }, + { 231, 235, 232 }, { 231, 243, 233 }, { 231, 251, 234 }, { 235, 235, 235 }, { 235, 239, 236 }, { 235, 247, 237 }, { 235, 255, 238 }, { 239, 239, 239 }, + { 239, 243, 240 }, { 239, 251, 241 }, { 243, 235, 242 }, { 243, 243, 243 }, { 243, 247, 244 }, { 243, 255, 245 }, { 247, 239, 246 }, { 247, 247, 247 }, + { 247, 251, 248 }, { 251, 235, 249 }, { 251, 243, 250 }, { 251, 251, 251 }, { 251, 255, 252 }, { 255, 239, 253 }, { 255, 247, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode4_a_high_i2= +{ + 2, + 0, + { + { 0, 0, 0 }, { 0, 4, 1 }, { 0, 8, 2 }, { 0, 12, 3 }, { 4, 4, 4 }, { 0, 16, 5 }, { 0, 20, 6 }, { 0, 24, 7 }, + { 0, 28, 8 }, { 0, 32, 9 }, { 0, 36, 10 }, { 0, 40, 11 }, { 0, 44, 12 }, { 4, 36, 13 }, { 0, 48, 14 }, { 0, 52, 15 }, + { 0, 56, 16 }, { 0, 60, 17 }, { 0, 65, 18 }, { 0, 69, 19 }, { 4, 60, 20 }, { 0, 73, 21 }, { 0, 77, 22 }, { 0, 81, 23 }, + { 0, 85, 24 }, { 0, 89, 25 }, { 0, 93, 26 }, { 0, 97, 27 }, { 0, 101, 28 }, { 4, 93, 29 }, { 0, 105, 30 }, { 0, 109, 31 }, + { 0, 113, 32 }, { 0, 117, 33 }, { 0, 121, 34 }, { 0, 125, 35 }, { 4, 117, 36 }, { 0, 130, 37 }, { 0, 134, 38 }, { 0, 138, 39 }, + { 0, 142, 40 }, { 0, 146, 41 }, { 0, 150, 42 }, { 0, 154, 43 }, { 0, 158, 44 }, { 4, 150, 45 }, { 0, 162, 46 }, { 0, 166, 47 }, + { 0, 170, 48 }, { 0, 174, 49 }, { 0, 178, 50 }, { 0, 182, 51 }, { 0, 186, 52 }, { 0, 190, 53 }, { 4, 182, 54 }, { 0, 195, 55 }, + { 0, 199, 56 }, { 0, 203, 57 }, { 0, 207, 58 }, { 0, 211, 59 }, { 0, 215, 60 }, { 4, 207, 61 }, { 0, 219, 62 }, { 0, 223, 63 }, + { 0, 227, 64 }, { 0, 231, 65 }, { 0, 235, 66 }, { 0, 239, 67 }, { 0, 243, 68 }, { 0, 247, 69 }, { 4, 239, 70 }, { 0, 251, 71 }, + { 0, 255, 72 }, { 4, 251, 73 }, { 8, 243, 74 }, { 4, 255, 75 }, { 8, 251, 76 }, { 8, 255, 77 }, { 12, 247, 78 }, { 12, 251, 79 }, + { 12, 255, 80 }, { 16, 247, 81 }, { 16, 251, 82 }, { 16, 255, 83 }, { 20, 247, 84 }, { 20, 251, 85 }, { 20, 255, 86 }, { 24, 247, 87 }, + { 24, 251, 88 }, { 24, 255, 89 }, { 28, 247, 90 }, { 28, 251, 91 }, { 28, 255, 92 }, { 36, 239, 93 }, { 32, 251, 94 }, { 32, 255, 95 }, + { 36, 251, 96 }, { 40, 243, 97 }, { 36, 255, 98 }, { 40, 251, 99 }, { 40, 255, 100 }, { 44, 247, 101 }, { 44, 251, 102 }, { 44, 255, 103 }, + { 48, 247, 104 }, { 48, 251, 105 }, { 48, 255, 106 }, { 52, 247, 107 }, { 52, 251, 108 }, { 52, 255, 109 }, { 56, 247, 110 }, { 56, 251, 111 }, + { 56, 255, 112 }, { 60, 247, 113 }, { 60, 251, 114 }, { 60, 255, 115 }, { 65, 247, 116 }, { 65, 251, 117 }, { 65, 255, 118 }, { 69, 247, 119 }, + { 69, 251, 120 }, { 69, 255, 121 }, { 73, 247, 122 }, { 73, 251, 123 }, { 73, 255, 124 }, { 77, 247, 125 }, { 77, 251, 126 }, { 77, 255, 127 }, + { 81, 247, 128 }, { 81, 251, 129 }, { 81, 255, 130 }, { 85, 247, 131 }, { 85, 251, 132 }, { 85, 255, 133 }, { 93, 239, 134 }, { 89, 251, 135 }, + { 89, 255, 136 }, { 93, 251, 137 }, { 97, 243, 138 }, { 93, 255, 139 }, { 97, 251, 140 }, { 97, 255, 141 }, { 101, 247, 142 }, { 101, 251, 143 }, + { 101, 255, 144 }, { 105, 247, 145 }, { 105, 251, 146 }, { 105, 255, 147 }, { 109, 247, 148 }, { 109, 251, 149 }, { 109, 255, 150 }, { 113, 247, 151 }, + { 113, 251, 152 }, { 113, 255, 153 }, { 117, 247, 154 }, { 117, 251, 155 }, { 117, 255, 156 }, { 125, 239, 157 }, { 121, 251, 158 }, { 121, 255, 159 }, + { 125, 251, 160 }, { 130, 239, 161 }, { 125, 255, 162 }, { 130, 247, 163 }, { 130, 251, 164 }, { 130, 255, 165 }, { 134, 247, 166 }, { 134, 251, 167 }, + { 134, 255, 168 }, { 138, 247, 169 }, { 138, 251, 170 }, { 138, 255, 171 }, { 142, 247, 172 }, { 142, 251, 173 }, { 142, 255, 174 }, { 150, 239, 175 }, + { 146, 251, 176 }, { 146, 255, 177 }, { 150, 251, 178 }, { 154, 243, 179 }, { 150, 255, 180 }, { 154, 251, 181 }, { 154, 255, 182 }, { 158, 247, 183 }, + { 158, 251, 184 }, { 158, 255, 185 }, { 162, 247, 186 }, { 162, 251, 187 }, { 162, 255, 188 }, { 166, 247, 189 }, { 166, 251, 190 }, { 166, 255, 191 }, + { 170, 247, 192 }, { 170, 251, 193 }, { 170, 255, 194 }, { 174, 247, 195 }, { 174, 251, 196 }, { 174, 255, 197 }, { 182, 239, 198 }, { 178, 251, 199 }, + { 178, 255, 200 }, { 182, 251, 201 }, { 186, 243, 202 }, { 182, 255, 203 }, { 186, 251, 204 }, { 186, 255, 205 }, { 190, 247, 206 }, { 190, 251, 207 }, + { 190, 255, 208 }, { 195, 243, 209 }, { 195, 247, 210 }, { 195, 251, 211 }, { 195, 255, 212 }, { 199, 247, 213 }, { 199, 251, 214 }, { 199, 255, 215 }, + { 207, 239, 216 }, { 203, 251, 217 }, { 203, 255, 218 }, { 207, 251, 219 }, { 211, 243, 220 }, { 207, 255, 221 }, { 211, 251, 222 }, { 211, 255, 223 }, + { 215, 247, 224 }, { 215, 251, 225 }, { 215, 255, 226 }, { 219, 247, 227 }, { 219, 251, 228 }, { 219, 255, 229 }, { 223, 247, 230 }, { 223, 251, 231 }, + { 223, 255, 232 }, { 227, 247, 233 }, { 227, 251, 234 }, { 227, 255, 235 }, { 231, 247, 236 }, { 231, 251, 237 }, { 231, 255, 238 }, { 239, 239, 239 }, + { 235, 251, 240 }, { 235, 255, 241 }, { 239, 251, 242 }, { 243, 243, 243 }, { 239, 255, 244 }, { 243, 251, 245 }, { 243, 255, 246 }, { 247, 247, 247 }, + { 247, 251, 248 }, { 247, 255, 249 }, { 251, 247, 250 }, { 251, 251, 251 }, { 251, 255, 252 }, { 255, 247, 253 }, { 255, 251, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode4_a_high_i3= +{ + 3, + 0, + { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 4, 2 }, { 0, 8, 3 }, { 4, 4, 4 }, { 0, 12, 5 }, { 4, 8, 6 }, { 0, 16, 7 }, + { 0, 20, 8 }, { 4, 16, 9 }, { 0, 24, 10 }, { 4, 20, 11 }, { 0, 28, 12 }, { 8, 20, 13 }, { 0, 32, 14 }, { 0, 36, 15 }, + { 4, 32, 16 }, { 0, 40, 17 }, { 4, 36, 18 }, { 0, 44, 19 }, { 0, 48, 20 }, { 4, 44, 21 }, { 0, 52, 22 }, { 4, 48, 23 }, + { 0, 56, 24 }, { 0, 60, 25 }, { 4, 56, 26 }, { 0, 65, 27 }, { 4, 60, 28 }, { 0, 69, 29 }, { 4, 65, 30 }, { 0, 73, 31 }, + { 0, 77, 32 }, { 4, 73, 33 }, { 0, 81, 34 }, { 4, 77, 35 }, { 0, 85, 36 }, { 8, 77, 37 }, { 0, 89, 38 }, { 0, 93, 39 }, + { 4, 89, 40 }, { 0, 97, 41 }, { 4, 93, 42 }, { 0, 101, 43 }, { 0, 105, 44 }, { 4, 101, 45 }, { 0, 109, 46 }, { 4, 105, 47 }, + { 0, 113, 48 }, { 0, 117, 49 }, { 4, 113, 50 }, { 0, 121, 51 }, { 4, 117, 52 }, { 0, 125, 53 }, { 8, 117, 54 }, { 0, 130, 55 }, + { 8, 121, 56 }, { 0, 134, 57 }, { 0, 138, 58 }, { 4, 134, 59 }, { 0, 142, 60 }, { 4, 138, 61 }, { 0, 146, 62 }, { 0, 150, 63 }, + { 4, 146, 64 }, { 0, 154, 65 }, { 4, 150, 66 }, { 0, 158, 67 }, { 0, 162, 68 }, { 4, 158, 69 }, { 0, 166, 70 }, { 4, 162, 71 }, + { 0, 170, 72 }, { 0, 174, 73 }, { 4, 170, 74 }, { 0, 178, 75 }, { 4, 174, 76 }, { 0, 182, 77 }, { 0, 186, 78 }, { 4, 182, 79 }, + { 0, 190, 80 }, { 4, 186, 81 }, { 0, 195, 82 }, { 8, 186, 83 }, { 0, 199, 84 }, { 4, 195, 85 }, { 0, 203, 86 }, { 0, 207, 87 }, + { 4, 203, 88 }, { 0, 211, 89 }, { 4, 207, 90 }, { 0, 215, 91 }, { 0, 219, 92 }, { 4, 215, 93 }, { 0, 223, 94 }, { 4, 219, 95 }, + { 0, 227, 96 }, { 0, 231, 97 }, { 4, 227, 98 }, { 0, 235, 99 }, { 4, 231, 100 }, { 0, 239, 101 }, { 8, 231, 102 }, { 0, 243, 103 }, + { 0, 247, 104 }, { 4, 243, 105 }, { 0, 251, 106 }, { 4, 247, 107 }, { 0, 255, 108 }, { 8, 247, 109 }, { 4, 255, 110 }, { 8, 251, 111 }, + { 8, 255, 112 }, { 12, 251, 113 }, { 20, 243, 114 }, { 12, 255, 115 }, { 20, 247, 116 }, { 16, 255, 117 }, { 24, 247, 118 }, { 20, 255, 119 }, + { 24, 251, 120 }, { 24, 255, 121 }, { 28, 251, 122 }, { 32, 247, 123 }, { 28, 255, 124 }, { 36, 247, 125 }, { 32, 255, 126 }, { 36, 251, 127 }, + { 36, 255, 128 }, { 40, 251, 129 }, { 44, 247, 130 }, { 40, 255, 131 }, { 48, 247, 132 }, { 44, 255, 133 }, { 48, 251, 134 }, { 48, 255, 135 }, + { 52, 251, 136 }, { 56, 247, 137 }, { 52, 255, 138 }, { 60, 247, 139 }, { 56, 255, 140 }, { 60, 251, 141 }, { 60, 255, 142 }, { 65, 251, 143 }, + { 69, 247, 144 }, { 65, 255, 145 }, { 69, 251, 146 }, { 69, 255, 147 }, { 73, 251, 148 }, { 77, 247, 149 }, { 73, 255, 150 }, { 81, 247, 151 }, + { 77, 255, 152 }, { 81, 251, 153 }, { 81, 255, 154 }, { 85, 251, 155 }, { 89, 247, 156 }, { 85, 255, 157 }, { 93, 247, 158 }, { 89, 255, 159 }, + { 93, 251, 160 }, { 93, 255, 161 }, { 97, 251, 162 }, { 101, 247, 163 }, { 97, 255, 164 }, { 105, 247, 165 }, { 101, 255, 166 }, { 105, 251, 167 }, + { 105, 255, 168 }, { 109, 251, 169 }, { 113, 247, 170 }, { 109, 255, 171 }, { 117, 247, 172 }, { 113, 255, 173 }, { 117, 251, 174 }, { 117, 255, 175 }, + { 121, 251, 176 }, { 134, 235, 177 }, { 121, 255, 178 }, { 130, 247, 179 }, { 125, 255, 180 }, { 130, 251, 181 }, { 134, 247, 182 }, { 130, 255, 183 }, + { 138, 247, 184 }, { 134, 255, 185 }, { 138, 251, 186 }, { 138, 255, 187 }, { 142, 251, 188 }, { 146, 247, 189 }, { 142, 255, 190 }, { 150, 247, 191 }, + { 146, 255, 192 }, { 150, 251, 193 }, { 150, 255, 194 }, { 154, 251, 195 }, { 158, 247, 196 }, { 154, 255, 197 }, { 162, 247, 198 }, { 158, 255, 199 }, + { 162, 251, 200 }, { 162, 255, 201 }, { 166, 251, 202 }, { 174, 243, 203 }, { 166, 255, 204 }, { 174, 247, 205 }, { 170, 255, 206 }, { 178, 247, 207 }, + { 174, 255, 208 }, { 178, 251, 209 }, { 178, 255, 210 }, { 182, 251, 211 }, { 186, 247, 212 }, { 182, 255, 213 }, { 190, 247, 214 }, { 186, 255, 215 }, + { 190, 251, 216 }, { 190, 255, 217 }, { 199, 243, 218 }, { 195, 251, 219 }, { 195, 255, 220 }, { 199, 251, 221 }, { 203, 247, 222 }, { 199, 255, 223 }, + { 207, 247, 224 }, { 203, 255, 225 }, { 207, 251, 226 }, { 207, 255, 227 }, { 211, 251, 228 }, { 215, 247, 229 }, { 211, 255, 230 }, { 219, 247, 231 }, + { 215, 255, 232 }, { 219, 251, 233 }, { 219, 255, 234 }, { 223, 251, 235 }, { 231, 243, 236 }, { 223, 255, 237 }, { 231, 247, 238 }, { 227, 255, 239 }, + { 235, 247, 240 }, { 231, 255, 241 }, { 235, 251, 242 }, { 235, 255, 243 }, { 239, 251, 244 }, { 243, 247, 245 }, { 239, 255, 246 }, { 247, 247, 247 }, + { 243, 255, 248 }, { 247, 251, 249 }, { 247, 255, 250 }, { 251, 251, 251 }, { 255, 247, 252 }, { 251, 255, 253 }, { 251, 255, 253 }, { 255, 255, 255 }, + } +}; + +Table g_mode5_rgb_low= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 2, 1 }, { 0, 6, 2 }, { 0, 8, 3 }, { 0, 12, 4 }, { 0, 14, 5 }, { 0, 18, 6 }, { 0, 20, 7 }, + { 0, 24, 8 }, { 0, 26, 9 }, { 0, 30, 10 }, { 0, 32, 11 }, { 0, 36, 12 }, { 0, 40, 13 }, { 0, 42, 14 }, { 0, 46, 15 }, + { 0, 48, 16 }, { 0, 52, 17 }, { 0, 54, 18 }, { 0, 58, 19 }, { 0, 60, 20 }, { 0, 64, 21 }, { 0, 66, 22 }, { 0, 70, 23 }, + { 0, 72, 24 }, { 0, 76, 25 }, { 0, 78, 26 }, { 0, 82, 27 }, { 0, 84, 28 }, { 0, 88, 29 }, { 0, 90, 30 }, { 0, 94, 31 }, + { 0, 96, 32 }, { 0, 100, 33 }, { 0, 104, 34 }, { 0, 106, 35 }, { 0, 110, 36 }, { 0, 112, 37 }, { 0, 116, 38 }, { 0, 118, 39 }, + { 0, 122, 40 }, { 0, 124, 41 }, { 0, 129, 42 }, { 0, 131, 43 }, { 0, 133, 44 }, { 0, 137, 45 }, { 0, 139, 46 }, { 0, 143, 47 }, + { 0, 145, 48 }, { 0, 149, 49 }, { 0, 151, 50 }, { 0, 155, 51 }, { 0, 157, 52 }, { 0, 161, 53 }, { 0, 165, 54 }, { 0, 167, 55 }, + { 0, 171, 56 }, { 0, 173, 57 }, { 0, 177, 58 }, { 0, 179, 59 }, { 0, 183, 60 }, { 0, 185, 61 }, { 0, 189, 62 }, { 0, 191, 63 }, + { 0, 195, 64 }, { 0, 197, 65 }, { 0, 201, 66 }, { 0, 203, 67 }, { 0, 207, 68 }, { 0, 209, 69 }, { 0, 213, 70 }, { 0, 215, 71 }, + { 0, 219, 72 }, { 0, 221, 73 }, { 0, 225, 74 }, { 0, 229, 75 }, { 0, 231, 76 }, { 0, 235, 77 }, { 0, 237, 78 }, { 0, 241, 79 }, + { 0, 243, 80 }, { 0, 247, 81 }, { 0, 249, 82 }, { 0, 253, 83 }, { 0, 255, 84 }, { 2, 255, 85 }, { 4, 253, 86 }, { 6, 253, 87 }, + { 6, 255, 88 }, { 8, 255, 89 }, { 10, 253, 90 }, { 12, 253, 91 }, { 12, 255, 92 }, { 14, 255, 93 }, { 16, 253, 94 }, { 18, 253, 95 }, + { 18, 255, 96 }, { 20, 255, 97 }, { 22, 253, 98 }, { 24, 253, 99 }, { 24, 255, 100 }, { 26, 255, 101 }, { 28, 253, 102 }, { 30, 251, 103 }, + { 30, 255, 104 }, { 32, 253, 105 }, { 34, 253, 106 }, { 34, 255, 107 }, { 36, 255, 108 }, { 38, 253, 109 }, { 40, 253, 110 }, { 40, 255, 111 }, + { 42, 255, 112 }, { 44, 253, 113 }, { 46, 253, 114 }, { 46, 255, 115 }, { 48, 255, 116 }, { 50, 253, 117 }, { 52, 253, 118 }, { 52, 255, 119 }, + { 54, 255, 120 }, { 56, 253, 121 }, { 58, 253, 122 }, { 58, 255, 123 }, { 60, 255, 124 }, { 62, 253, 125 }, { 64, 253, 126 }, { 64, 255, 127 }, + { 66, 255, 128 }, { 68, 253, 129 }, { 70, 253, 130 }, { 70, 255, 131 }, { 72, 255, 132 }, { 74, 253, 133 }, { 76, 253, 134 }, { 76, 255, 135 }, + { 78, 255, 136 }, { 80, 253, 137 }, { 82, 253, 138 }, { 82, 255, 139 }, { 84, 255, 140 }, { 86, 253, 141 }, { 88, 253, 142 }, { 88, 255, 143 }, + { 90, 255, 144 }, { 92, 253, 145 }, { 94, 251, 146 }, { 94, 255, 147 }, { 96, 253, 148 }, { 98, 253, 149 }, { 98, 255, 150 }, { 100, 255, 151 }, + { 102, 253, 152 }, { 104, 253, 153 }, { 104, 255, 154 }, { 106, 255, 155 }, { 108, 253, 156 }, { 110, 253, 157 }, { 110, 255, 158 }, { 112, 255, 159 }, + { 114, 253, 160 }, { 116, 253, 161 }, { 116, 255, 162 }, { 118, 255, 163 }, { 120, 253, 164 }, { 122, 253, 165 }, { 122, 255, 166 }, { 124, 255, 167 }, + { 126, 253, 168 }, { 129, 251, 169 }, { 129, 253, 170 }, { 131, 253, 171 }, { 131, 255, 172 }, { 133, 255, 173 }, { 135, 253, 174 }, { 137, 253, 175 }, + { 137, 255, 176 }, { 139, 255, 177 }, { 141, 253, 178 }, { 143, 253, 179 }, { 143, 255, 180 }, { 145, 255, 181 }, { 147, 253, 182 }, { 149, 253, 183 }, + { 149, 255, 184 }, { 151, 255, 185 }, { 153, 253, 186 }, { 155, 251, 187 }, { 155, 255, 188 }, { 157, 253, 189 }, { 159, 253, 190 }, { 159, 255, 191 }, + { 161, 255, 192 }, { 163, 253, 193 }, { 165, 253, 194 }, { 165, 255, 195 }, { 167, 255, 196 }, { 169, 253, 197 }, { 171, 253, 198 }, { 171, 255, 199 }, + { 173, 255, 200 }, { 175, 253, 201 }, { 177, 253, 202 }, { 177, 255, 203 }, { 179, 255, 204 }, { 181, 253, 205 }, { 183, 253, 206 }, { 183, 255, 207 }, + { 185, 255, 208 }, { 187, 253, 209 }, { 189, 253, 210 }, { 189, 255, 211 }, { 191, 255, 212 }, { 193, 253, 213 }, { 195, 253, 214 }, { 195, 255, 215 }, + { 197, 255, 216 }, { 199, 253, 217 }, { 201, 253, 218 }, { 201, 255, 219 }, { 203, 255, 220 }, { 205, 253, 221 }, { 207, 253, 222 }, { 207, 255, 223 }, + { 209, 255, 224 }, { 211, 253, 225 }, { 213, 253, 226 }, { 213, 255, 227 }, { 215, 255, 228 }, { 217, 253, 229 }, { 219, 251, 230 }, { 219, 255, 231 }, + { 221, 253, 232 }, { 223, 253, 233 }, { 223, 255, 234 }, { 225, 255, 235 }, { 227, 253, 236 }, { 229, 253, 237 }, { 229, 255, 238 }, { 231, 255, 239 }, + { 233, 253, 240 }, { 235, 253, 241 }, { 235, 255, 242 }, { 237, 255, 243 }, { 239, 253, 244 }, { 241, 253, 245 }, { 241, 255, 246 }, { 243, 255, 247 }, + { 245, 253, 248 }, { 247, 253, 249 }, { 247, 255, 250 }, { 249, 255, 251 }, { 251, 253, 252 }, { 253, 253, 253 }, { 253, 255, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode6_p0_i1= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 8, 1 }, { 0, 24, 2 }, { 0, 40, 3 }, { 0, 56, 4 }, { 0, 72, 5 }, { 0, 88, 6 }, { 0, 104, 7 }, + { 0, 120, 8 }, { 0, 136, 9 }, { 0, 152, 10 }, { 0, 168, 11 }, { 0, 184, 12 }, { 0, 200, 13 }, { 0, 216, 14 }, { 0, 232, 15 }, + { 0, 248, 16 }, { 2, 234, 17 }, { 2, 250, 18 }, { 4, 236, 19 }, { 4, 252, 20 }, { 6, 238, 21 }, { 6, 254, 22 }, { 8, 240, 23 }, + { 10, 226, 24 }, { 10, 242, 25 }, { 12, 228, 26 }, { 12, 244, 27 }, { 14, 230, 28 }, { 14, 246, 29 }, { 16, 232, 30 }, { 16, 248, 31 }, + { 18, 234, 32 }, { 18, 250, 33 }, { 20, 236, 34 }, { 20, 252, 35 }, { 22, 238, 36 }, { 22, 254, 37 }, { 24, 240, 38 }, { 26, 226, 39 }, + { 26, 242, 40 }, { 28, 228, 41 }, { 28, 244, 42 }, { 30, 230, 43 }, { 30, 246, 44 }, { 32, 232, 45 }, { 32, 248, 46 }, { 34, 234, 47 }, + { 34, 250, 48 }, { 36, 236, 49 }, { 36, 252, 50 }, { 38, 238, 51 }, { 38, 254, 52 }, { 40, 240, 53 }, { 42, 226, 54 }, { 42, 242, 55 }, + { 44, 228, 56 }, { 44, 244, 57 }, { 46, 230, 58 }, { 46, 246, 59 }, { 48, 232, 60 }, { 48, 248, 61 }, { 50, 234, 62 }, { 50, 250, 63 }, + { 52, 236, 64 }, { 52, 252, 65 }, { 54, 238, 66 }, { 54, 254, 67 }, { 56, 240, 68 }, { 58, 226, 69 }, { 58, 242, 70 }, { 60, 228, 71 }, + { 60, 244, 72 }, { 62, 230, 73 }, { 62, 246, 74 }, { 64, 232, 75 }, { 64, 248, 76 }, { 66, 234, 77 }, { 66, 250, 78 }, { 68, 236, 79 }, + { 68, 252, 80 }, { 70, 238, 81 }, { 70, 254, 82 }, { 72, 240, 83 }, { 74, 226, 84 }, { 74, 242, 85 }, { 76, 228, 86 }, { 76, 244, 87 }, + { 78, 230, 88 }, { 78, 246, 89 }, { 80, 232, 90 }, { 80, 248, 91 }, { 82, 234, 92 }, { 82, 250, 93 }, { 84, 236, 94 }, { 84, 252, 95 }, + { 86, 238, 96 }, { 86, 254, 97 }, { 88, 240, 98 }, { 90, 226, 99 }, { 90, 242, 100 }, { 92, 228, 101 }, { 92, 244, 102 }, { 94, 230, 103 }, + { 94, 246, 104 }, { 96, 232, 105 }, { 96, 248, 106 }, { 98, 234, 107 }, { 98, 250, 108 }, { 100, 236, 109 }, { 100, 252, 110 }, { 102, 238, 111 }, + { 102, 254, 112 }, { 104, 240, 113 }, { 106, 226, 114 }, { 106, 242, 115 }, { 108, 228, 116 }, { 108, 244, 117 }, { 110, 230, 118 }, { 110, 246, 119 }, + { 112, 232, 120 }, { 112, 248, 121 }, { 114, 234, 122 }, { 114, 250, 123 }, { 116, 236, 124 }, { 116, 252, 125 }, { 118, 238, 126 }, { 118, 254, 127 }, + { 120, 240, 128 }, { 122, 226, 129 }, { 122, 242, 130 }, { 124, 228, 131 }, { 124, 244, 132 }, { 126, 230, 133 }, { 126, 246, 134 }, { 128, 232, 135 }, + { 128, 248, 136 }, { 130, 234, 137 }, { 130, 250, 138 }, { 132, 236, 139 }, { 132, 252, 140 }, { 134, 238, 141 }, { 134, 254, 142 }, { 136, 240, 143 }, + { 138, 226, 144 }, { 138, 242, 145 }, { 140, 228, 146 }, { 140, 244, 147 }, { 142, 230, 148 }, { 142, 246, 149 }, { 144, 232, 150 }, { 144, 248, 151 }, + { 146, 234, 152 }, { 146, 250, 153 }, { 148, 236, 154 }, { 148, 252, 155 }, { 150, 238, 156 }, { 150, 254, 157 }, { 152, 240, 158 }, { 154, 226, 159 }, + { 154, 242, 160 }, { 156, 228, 161 }, { 156, 244, 162 }, { 158, 230, 163 }, { 158, 246, 164 }, { 160, 232, 165 }, { 160, 248, 166 }, { 162, 234, 167 }, + { 162, 250, 168 }, { 164, 236, 169 }, { 164, 252, 170 }, { 166, 238, 171 }, { 166, 254, 172 }, { 168, 240, 173 }, { 170, 226, 174 }, { 170, 242, 175 }, + { 172, 228, 176 }, { 172, 244, 177 }, { 174, 230, 178 }, { 174, 246, 179 }, { 176, 232, 180 }, { 176, 248, 181 }, { 178, 234, 182 }, { 178, 250, 183 }, + { 180, 236, 184 }, { 180, 252, 185 }, { 182, 238, 186 }, { 182, 254, 187 }, { 184, 240, 188 }, { 186, 226, 189 }, { 186, 242, 190 }, { 188, 228, 191 }, + { 188, 244, 192 }, { 190, 230, 193 }, { 190, 246, 194 }, { 192, 232, 195 }, { 192, 248, 196 }, { 194, 234, 197 }, { 194, 250, 198 }, { 196, 236, 199 }, + { 196, 252, 200 }, { 198, 238, 201 }, { 198, 254, 202 }, { 200, 240, 203 }, { 202, 226, 204 }, { 202, 242, 205 }, { 204, 228, 206 }, { 204, 244, 207 }, + { 206, 230, 208 }, { 206, 246, 209 }, { 208, 232, 210 }, { 208, 248, 211 }, { 210, 234, 212 }, { 210, 250, 213 }, { 212, 236, 214 }, { 212, 252, 215 }, + { 214, 238, 216 }, { 214, 254, 217 }, { 216, 240, 218 }, { 218, 226, 219 }, { 218, 242, 220 }, { 220, 228, 221 }, { 220, 244, 222 }, { 222, 230, 223 }, + { 222, 246, 224 }, { 224, 232, 225 }, { 224, 248, 226 }, { 226, 234, 227 }, { 226, 250, 228 }, { 228, 236, 229 }, { 228, 252, 230 }, { 230, 238, 231 }, + { 230, 254, 232 }, { 232, 240, 233 }, { 234, 226, 234 }, { 234, 242, 235 }, { 236, 228, 236 }, { 236, 244, 237 }, { 238, 230, 238 }, { 238, 246, 239 }, + { 240, 232, 240 }, { 240, 248, 241 }, { 242, 234, 242 }, { 242, 250, 243 }, { 244, 236, 244 }, { 244, 252, 245 }, { 246, 238, 246 }, { 246, 254, 247 }, + { 248, 240, 248 }, { 250, 226, 249 }, { 250, 242, 250 }, { 252, 228, 251 }, { 252, 244, 252 }, { 254, 230, 253 }, { 254, 246, 254 }, { 254, 246, 254 }, + } +}; + +Table g_mode6_p0_i2= +{ + 2, + 0, + { + { 0, 0, 0 }, { 0, 4, 1 }, { 0, 12, 2 }, { 0, 18, 3 }, { 0, 26, 4 }, { 0, 32, 5 }, { 0, 40, 6 }, { 0, 48, 7 }, + { 0, 54, 8 }, { 0, 62, 9 }, { 0, 68, 10 }, { 0, 76, 11 }, { 0, 82, 12 }, { 0, 90, 13 }, { 0, 96, 14 }, { 0, 104, 15 }, + { 0, 112, 16 }, { 0, 118, 17 }, { 0, 126, 18 }, { 0, 132, 19 }, { 0, 140, 20 }, { 0, 146, 21 }, { 0, 154, 22 }, { 0, 160, 23 }, + { 0, 168, 24 }, { 0, 176, 25 }, { 0, 182, 26 }, { 0, 190, 27 }, { 0, 196, 28 }, { 0, 204, 29 }, { 0, 210, 30 }, { 0, 218, 31 }, + { 0, 224, 32 }, { 0, 232, 33 }, { 0, 240, 34 }, { 0, 246, 35 }, { 0, 254, 36 }, { 2, 248, 37 }, { 4, 244, 38 }, { 4, 250, 39 }, + { 6, 246, 40 }, { 6, 252, 41 }, { 8, 248, 42 }, { 8, 254, 43 }, { 10, 250, 44 }, { 12, 244, 45 }, { 12, 252, 46 }, { 14, 246, 47 }, + { 14, 254, 48 }, { 16, 248, 49 }, { 18, 242, 50 }, { 18, 250, 51 }, { 20, 244, 52 }, { 20, 252, 53 }, { 22, 246, 54 }, { 22, 254, 55 }, + { 24, 248, 56 }, { 26, 244, 57 }, { 26, 250, 58 }, { 28, 246, 59 }, { 28, 252, 60 }, { 30, 248, 61 }, { 30, 254, 62 }, { 32, 250, 63 }, + { 34, 244, 64 }, { 34, 252, 65 }, { 36, 246, 66 }, { 36, 254, 67 }, { 38, 248, 68 }, { 40, 244, 69 }, { 40, 250, 70 }, { 42, 246, 71 }, + { 42, 252, 72 }, { 44, 248, 73 }, { 44, 254, 74 }, { 46, 250, 75 }, { 48, 244, 76 }, { 48, 252, 77 }, { 50, 246, 78 }, { 50, 254, 79 }, + { 52, 248, 80 }, { 54, 244, 81 }, { 54, 250, 82 }, { 56, 246, 83 }, { 56, 252, 84 }, { 58, 248, 85 }, { 58, 254, 86 }, { 60, 250, 87 }, + { 62, 244, 88 }, { 62, 252, 89 }, { 64, 246, 90 }, { 64, 254, 91 }, { 66, 248, 92 }, { 68, 244, 93 }, { 68, 250, 94 }, { 70, 246, 95 }, + { 70, 252, 96 }, { 72, 248, 97 }, { 72, 254, 98 }, { 74, 250, 99 }, { 76, 244, 100 }, { 76, 252, 101 }, { 78, 246, 102 }, { 78, 254, 103 }, + { 80, 248, 104 }, { 82, 242, 105 }, { 82, 250, 106 }, { 84, 244, 107 }, { 84, 252, 108 }, { 86, 246, 109 }, { 86, 254, 110 }, { 88, 248, 111 }, + { 90, 244, 112 }, { 90, 250, 113 }, { 92, 246, 114 }, { 92, 252, 115 }, { 94, 248, 116 }, { 94, 254, 117 }, { 96, 250, 118 }, { 98, 244, 119 }, + { 98, 252, 120 }, { 100, 246, 121 }, { 100, 254, 122 }, { 102, 248, 123 }, { 104, 244, 124 }, { 104, 250, 125 }, { 106, 246, 126 }, { 106, 252, 127 }, + { 108, 248, 128 }, { 108, 254, 129 }, { 110, 250, 130 }, { 112, 244, 131 }, { 112, 252, 132 }, { 114, 246, 133 }, { 114, 254, 134 }, { 116, 248, 135 }, + { 118, 244, 136 }, { 118, 250, 137 }, { 120, 246, 138 }, { 120, 252, 139 }, { 122, 248, 140 }, { 122, 254, 141 }, { 124, 250, 142 }, { 126, 244, 143 }, + { 126, 252, 144 }, { 128, 246, 145 }, { 128, 254, 146 }, { 130, 248, 147 }, { 132, 244, 148 }, { 132, 250, 149 }, { 134, 246, 150 }, { 134, 252, 151 }, + { 136, 248, 152 }, { 136, 254, 153 }, { 138, 250, 154 }, { 140, 244, 155 }, { 140, 252, 156 }, { 142, 246, 157 }, { 142, 254, 158 }, { 144, 248, 159 }, + { 146, 242, 160 }, { 146, 250, 161 }, { 148, 244, 162 }, { 148, 252, 163 }, { 150, 246, 164 }, { 150, 254, 165 }, { 152, 248, 166 }, { 154, 244, 167 }, + { 154, 250, 168 }, { 156, 246, 169 }, { 156, 252, 170 }, { 158, 248, 171 }, { 158, 254, 172 }, { 160, 250, 173 }, { 162, 244, 174 }, { 162, 252, 175 }, + { 164, 246, 176 }, { 164, 254, 177 }, { 166, 248, 178 }, { 168, 244, 179 }, { 168, 250, 180 }, { 170, 246, 181 }, { 170, 252, 182 }, { 172, 248, 183 }, + { 172, 254, 184 }, { 174, 250, 185 }, { 176, 244, 186 }, { 176, 252, 187 }, { 178, 246, 188 }, { 178, 254, 189 }, { 180, 248, 190 }, { 182, 244, 191 }, + { 182, 250, 192 }, { 184, 246, 193 }, { 184, 252, 194 }, { 186, 248, 195 }, { 186, 254, 196 }, { 188, 250, 197 }, { 190, 244, 198 }, { 190, 252, 199 }, + { 192, 246, 200 }, { 192, 254, 201 }, { 194, 248, 202 }, { 196, 244, 203 }, { 196, 250, 204 }, { 198, 246, 205 }, { 198, 252, 206 }, { 200, 248, 207 }, + { 200, 254, 208 }, { 202, 250, 209 }, { 204, 244, 210 }, { 204, 252, 211 }, { 206, 246, 212 }, { 206, 254, 213 }, { 208, 248, 214 }, { 210, 242, 215 }, + { 210, 250, 216 }, { 212, 244, 217 }, { 212, 252, 218 }, { 214, 246, 219 }, { 214, 254, 220 }, { 216, 248, 221 }, { 218, 244, 222 }, { 218, 250, 223 }, + { 220, 246, 224 }, { 220, 252, 225 }, { 222, 248, 226 }, { 222, 254, 227 }, { 224, 250, 228 }, { 226, 244, 229 }, { 226, 252, 230 }, { 228, 246, 231 }, + { 228, 254, 232 }, { 230, 248, 233 }, { 232, 244, 234 }, { 232, 250, 235 }, { 234, 246, 236 }, { 234, 252, 237 }, { 236, 248, 238 }, { 236, 254, 239 }, + { 238, 250, 240 }, { 240, 244, 241 }, { 240, 252, 242 }, { 242, 246, 243 }, { 242, 254, 244 }, { 244, 248, 245 }, { 246, 244, 246 }, { 246, 250, 247 }, + { 248, 246, 248 }, { 248, 252, 249 }, { 250, 248, 250 }, { 250, 254, 251 }, { 252, 250, 252 }, { 254, 244, 253 }, { 254, 252, 254 }, { 254, 252, 254 }, + } +}; + +Table g_mode6_p0_i3= +{ + 3, + 0, + { + { 0, 0, 0 }, { 0, 4, 1 }, { 0, 8, 2 }, { 0, 14, 3 }, { 0, 18, 4 }, { 0, 24, 5 }, { 0, 28, 6 }, { 0, 32, 7 }, + { 0, 38, 8 }, { 0, 42, 9 }, { 0, 48, 10 }, { 0, 52, 11 }, { 0, 58, 12 }, { 0, 62, 13 }, { 0, 68, 14 }, { 0, 72, 15 }, + { 0, 78, 16 }, { 0, 82, 17 }, { 0, 88, 18 }, { 0, 92, 19 }, { 0, 96, 20 }, { 0, 102, 21 }, { 0, 106, 22 }, { 0, 112, 23 }, + { 0, 116, 24 }, { 0, 122, 25 }, { 0, 126, 26 }, { 0, 132, 27 }, { 0, 136, 28 }, { 0, 142, 29 }, { 0, 146, 30 }, { 0, 152, 31 }, + { 0, 156, 32 }, { 0, 160, 33 }, { 0, 166, 34 }, { 0, 170, 35 }, { 0, 176, 36 }, { 0, 180, 37 }, { 0, 186, 38 }, { 0, 190, 39 }, + { 0, 196, 40 }, { 0, 200, 41 }, { 0, 206, 42 }, { 0, 210, 43 }, { 0, 216, 44 }, { 0, 220, 45 }, { 0, 224, 46 }, { 0, 230, 47 }, + { 0, 234, 48 }, { 0, 240, 49 }, { 0, 244, 50 }, { 0, 250, 51 }, { 0, 254, 52 }, { 2, 252, 53 }, { 4, 248, 54 }, { 4, 254, 55 }, + { 6, 250, 56 }, { 8, 248, 57 }, { 8, 252, 58 }, { 10, 250, 59 }, { 10, 254, 60 }, { 12, 252, 61 }, { 14, 248, 62 }, { 14, 254, 63 }, + { 16, 250, 64 }, { 18, 248, 65 }, { 18, 252, 66 }, { 20, 250, 67 }, { 20, 254, 68 }, { 22, 252, 69 }, { 24, 248, 70 }, { 24, 254, 71 }, + { 26, 250, 72 }, { 28, 248, 73 }, { 28, 252, 74 }, { 30, 250, 75 }, { 30, 254, 76 }, { 32, 252, 77 }, { 34, 250, 78 }, { 34, 254, 79 }, + { 36, 252, 80 }, { 38, 248, 81 }, { 38, 254, 82 }, { 40, 250, 83 }, { 42, 248, 84 }, { 42, 252, 85 }, { 44, 250, 86 }, { 44, 254, 87 }, + { 46, 252, 88 }, { 48, 248, 89 }, { 48, 254, 90 }, { 50, 250, 91 }, { 52, 248, 92 }, { 52, 252, 93 }, { 54, 250, 94 }, { 54, 254, 95 }, + { 56, 252, 96 }, { 58, 248, 97 }, { 58, 254, 98 }, { 60, 250, 99 }, { 62, 248, 100 }, { 62, 252, 101 }, { 64, 250, 102 }, { 64, 254, 103 }, + { 66, 252, 104 }, { 68, 248, 105 }, { 68, 254, 106 }, { 70, 250, 107 }, { 72, 248, 108 }, { 72, 252, 109 }, { 74, 250, 110 }, { 74, 254, 111 }, + { 76, 252, 112 }, { 78, 248, 113 }, { 78, 254, 114 }, { 80, 250, 115 }, { 82, 248, 116 }, { 82, 252, 117 }, { 84, 250, 118 }, { 84, 254, 119 }, + { 86, 252, 120 }, { 88, 248, 121 }, { 88, 254, 122 }, { 90, 250, 123 }, { 92, 248, 124 }, { 92, 252, 125 }, { 94, 250, 126 }, { 94, 254, 127 }, + { 96, 252, 128 }, { 98, 250, 129 }, { 98, 254, 130 }, { 100, 252, 131 }, { 102, 248, 132 }, { 102, 254, 133 }, { 104, 250, 134 }, { 106, 248, 135 }, + { 106, 252, 136 }, { 108, 250, 137 }, { 108, 254, 138 }, { 110, 252, 139 }, { 112, 248, 140 }, { 112, 254, 141 }, { 114, 250, 142 }, { 116, 248, 143 }, + { 116, 252, 144 }, { 118, 250, 145 }, { 118, 254, 146 }, { 120, 252, 147 }, { 122, 248, 148 }, { 122, 254, 149 }, { 124, 250, 150 }, { 126, 248, 151 }, + { 126, 252, 152 }, { 128, 250, 153 }, { 128, 254, 154 }, { 130, 252, 155 }, { 132, 248, 156 }, { 132, 254, 157 }, { 134, 250, 158 }, { 136, 248, 159 }, + { 136, 252, 160 }, { 138, 250, 161 }, { 138, 254, 162 }, { 140, 252, 163 }, { 142, 248, 164 }, { 142, 254, 165 }, { 144, 250, 166 }, { 146, 248, 167 }, + { 146, 252, 168 }, { 148, 250, 169 }, { 148, 254, 170 }, { 150, 252, 171 }, { 152, 248, 172 }, { 152, 254, 173 }, { 154, 250, 174 }, { 156, 248, 175 }, + { 156, 252, 176 }, { 158, 250, 177 }, { 158, 254, 178 }, { 160, 252, 179 }, { 162, 250, 180 }, { 162, 254, 181 }, { 164, 252, 182 }, { 166, 248, 183 }, + { 166, 254, 184 }, { 168, 250, 185 }, { 170, 248, 186 }, { 170, 252, 187 }, { 172, 250, 188 }, { 172, 254, 189 }, { 174, 252, 190 }, { 176, 248, 191 }, + { 176, 254, 192 }, { 178, 250, 193 }, { 180, 248, 194 }, { 180, 252, 195 }, { 182, 250, 196 }, { 182, 254, 197 }, { 184, 252, 198 }, { 186, 248, 199 }, + { 186, 254, 200 }, { 188, 250, 201 }, { 190, 248, 202 }, { 190, 252, 203 }, { 192, 250, 204 }, { 192, 254, 205 }, { 194, 252, 206 }, { 196, 248, 207 }, + { 196, 254, 208 }, { 198, 250, 209 }, { 200, 248, 210 }, { 200, 252, 211 }, { 202, 250, 212 }, { 202, 254, 213 }, { 204, 252, 214 }, { 206, 248, 215 }, + { 206, 254, 216 }, { 208, 250, 217 }, { 210, 248, 218 }, { 210, 252, 219 }, { 212, 250, 220 }, { 212, 254, 221 }, { 214, 252, 222 }, { 216, 248, 223 }, + { 216, 254, 224 }, { 218, 250, 225 }, { 220, 248, 226 }, { 220, 252, 227 }, { 222, 250, 228 }, { 222, 254, 229 }, { 224, 252, 230 }, { 226, 250, 231 }, + { 226, 254, 232 }, { 228, 252, 233 }, { 230, 248, 234 }, { 230, 254, 235 }, { 232, 250, 236 }, { 234, 248, 237 }, { 234, 252, 238 }, { 236, 250, 239 }, + { 236, 254, 240 }, { 238, 252, 241 }, { 240, 248, 242 }, { 240, 254, 243 }, { 242, 250, 244 }, { 244, 248, 245 }, { 244, 252, 246 }, { 246, 250, 247 }, + { 246, 254, 248 }, { 248, 252, 249 }, { 250, 248, 250 }, { 250, 254, 251 }, { 252, 250, 252 }, { 254, 248, 253 }, { 254, 252, 254 }, { 254, 252, 254 }, + } +}; + +Table g_mode6_p0_i4= +{ + 4, + 0, + { + { 0, 0, 0 }, { 0, 2, 1 }, { 0, 6, 2 }, { 0, 10, 3 }, { 0, 14, 4 }, { 0, 18, 5 }, { 0, 22, 6 }, { 0, 26, 7 }, + { 0, 30, 8 }, { 0, 32, 9 }, { 0, 36, 10 }, { 0, 40, 11 }, { 0, 44, 12 }, { 0, 48, 13 }, { 0, 52, 14 }, { 0, 56, 15 }, + { 0, 60, 16 }, { 0, 64, 17 }, { 0, 66, 18 }, { 0, 70, 19 }, { 0, 74, 20 }, { 0, 78, 21 }, { 0, 82, 22 }, { 0, 86, 23 }, + { 0, 90, 24 }, { 0, 94, 25 }, { 0, 96, 26 }, { 0, 100, 27 }, { 0, 104, 28 }, { 0, 108, 29 }, { 0, 112, 30 }, { 0, 116, 31 }, + { 0, 120, 32 }, { 0, 124, 33 }, { 0, 128, 34 }, { 0, 130, 35 }, { 0, 134, 36 }, { 0, 138, 37 }, { 0, 142, 38 }, { 0, 146, 39 }, + { 0, 150, 40 }, { 0, 154, 41 }, { 0, 158, 42 }, { 0, 160, 43 }, { 0, 164, 44 }, { 0, 168, 45 }, { 0, 172, 46 }, { 0, 176, 47 }, + { 0, 180, 48 }, { 0, 184, 49 }, { 0, 188, 50 }, { 0, 192, 51 }, { 0, 194, 52 }, { 0, 198, 53 }, { 0, 202, 54 }, { 0, 206, 55 }, + { 0, 210, 56 }, { 0, 214, 57 }, { 0, 218, 58 }, { 0, 222, 59 }, { 0, 224, 60 }, { 0, 228, 61 }, { 0, 232, 62 }, { 0, 236, 63 }, + { 0, 240, 64 }, { 0, 244, 65 }, { 0, 248, 66 }, { 0, 252, 67 }, { 2, 250, 68 }, { 2, 254, 69 }, { 4, 252, 70 }, { 6, 250, 71 }, + { 6, 254, 72 }, { 8, 252, 73 }, { 10, 250, 74 }, { 10, 254, 75 }, { 12, 252, 76 }, { 14, 250, 77 }, { 14, 254, 78 }, { 16, 252, 79 }, + { 18, 250, 80 }, { 18, 254, 81 }, { 20, 252, 82 }, { 22, 250, 83 }, { 22, 254, 84 }, { 24, 252, 85 }, { 26, 250, 86 }, { 26, 254, 87 }, + { 28, 252, 88 }, { 30, 252, 89 }, { 30, 254, 90 }, { 32, 254, 91 }, { 34, 252, 92 }, { 36, 250, 93 }, { 36, 254, 94 }, { 38, 252, 95 }, + { 40, 250, 96 }, { 40, 254, 97 }, { 42, 252, 98 }, { 44, 250, 99 }, { 44, 254, 100 }, { 46, 252, 101 }, { 48, 250, 102 }, { 48, 254, 103 }, + { 50, 252, 104 }, { 52, 250, 105 }, { 52, 254, 106 }, { 54, 252, 107 }, { 56, 250, 108 }, { 56, 254, 109 }, { 58, 252, 110 }, { 60, 252, 111 }, + { 60, 254, 112 }, { 62, 254, 113 }, { 64, 252, 114 }, { 66, 250, 115 }, { 66, 254, 116 }, { 68, 252, 117 }, { 70, 250, 118 }, { 70, 254, 119 }, + { 72, 252, 120 }, { 74, 250, 121 }, { 74, 254, 122 }, { 76, 252, 123 }, { 78, 250, 124 }, { 78, 254, 125 }, { 80, 252, 126 }, { 82, 250, 127 }, + { 82, 254, 128 }, { 84, 252, 129 }, { 86, 250, 130 }, { 86, 254, 131 }, { 88, 252, 132 }, { 90, 250, 133 }, { 90, 254, 134 }, { 92, 252, 135 }, + { 94, 252, 136 }, { 94, 254, 137 }, { 96, 254, 138 }, { 98, 252, 139 }, { 100, 250, 140 }, { 100, 254, 141 }, { 102, 252, 142 }, { 104, 250, 143 }, + { 104, 254, 144 }, { 106, 252, 145 }, { 108, 250, 146 }, { 108, 254, 147 }, { 110, 252, 148 }, { 112, 250, 149 }, { 112, 254, 150 }, { 114, 252, 151 }, + { 116, 250, 152 }, { 116, 254, 153 }, { 118, 252, 154 }, { 120, 250, 155 }, { 120, 254, 156 }, { 122, 252, 157 }, { 124, 252, 158 }, { 124, 254, 159 }, + { 126, 254, 160 }, { 128, 252, 161 }, { 130, 250, 162 }, { 130, 254, 163 }, { 132, 252, 164 }, { 134, 250, 165 }, { 134, 254, 166 }, { 136, 252, 167 }, + { 138, 250, 168 }, { 138, 254, 169 }, { 140, 252, 170 }, { 142, 250, 171 }, { 142, 254, 172 }, { 144, 252, 173 }, { 146, 250, 174 }, { 146, 254, 175 }, + { 148, 252, 176 }, { 150, 250, 177 }, { 150, 254, 178 }, { 152, 252, 179 }, { 154, 250, 180 }, { 154, 254, 181 }, { 156, 252, 182 }, { 158, 252, 183 }, + { 158, 254, 184 }, { 160, 254, 185 }, { 162, 252, 186 }, { 164, 250, 187 }, { 164, 254, 188 }, { 166, 252, 189 }, { 168, 250, 190 }, { 168, 254, 191 }, + { 170, 252, 192 }, { 172, 250, 193 }, { 172, 254, 194 }, { 174, 252, 195 }, { 176, 250, 196 }, { 176, 254, 197 }, { 178, 252, 198 }, { 180, 250, 199 }, + { 180, 254, 200 }, { 182, 252, 201 }, { 184, 250, 202 }, { 184, 254, 203 }, { 186, 252, 204 }, { 188, 252, 205 }, { 188, 254, 206 }, { 190, 254, 207 }, + { 192, 252, 208 }, { 194, 250, 209 }, { 194, 254, 210 }, { 196, 252, 211 }, { 198, 250, 212 }, { 198, 254, 213 }, { 200, 252, 214 }, { 202, 250, 215 }, + { 202, 254, 216 }, { 204, 252, 217 }, { 206, 250, 218 }, { 206, 254, 219 }, { 208, 252, 220 }, { 210, 250, 221 }, { 210, 254, 222 }, { 212, 252, 223 }, + { 214, 250, 224 }, { 214, 254, 225 }, { 216, 252, 226 }, { 218, 250, 227 }, { 218, 254, 228 }, { 220, 252, 229 }, { 222, 252, 230 }, { 222, 254, 231 }, + { 224, 254, 232 }, { 226, 252, 233 }, { 228, 250, 234 }, { 228, 254, 235 }, { 230, 252, 236 }, { 232, 250, 237 }, { 232, 254, 238 }, { 234, 252, 239 }, + { 236, 250, 240 }, { 236, 254, 241 }, { 238, 252, 242 }, { 240, 250, 243 }, { 240, 254, 244 }, { 242, 252, 245 }, { 244, 250, 246 }, { 244, 254, 247 }, + { 246, 252, 248 }, { 248, 250, 249 }, { 248, 254, 250 }, { 250, 252, 251 }, { 252, 252, 252 }, { 252, 254, 253 }, { 254, 254, 254 }, { 254, 254, 254 }, + } +}; + +Table g_mode6_p0_i5= +{ + 5, + 0, + { + { 0, 0, 0 }, { 0, 2, 1 }, { 0, 6, 2 }, { 0, 8, 3 }, { 0, 12, 4 }, { 0, 14, 5 }, { 0, 18, 6 }, { 0, 20, 7 }, + { 0, 24, 8 }, { 0, 26, 9 }, { 0, 30, 10 }, { 0, 32, 11 }, { 0, 36, 12 }, { 0, 40, 13 }, { 0, 42, 14 }, { 0, 46, 15 }, + { 0, 48, 16 }, { 0, 52, 17 }, { 0, 54, 18 }, { 0, 58, 19 }, { 0, 60, 20 }, { 0, 64, 21 }, { 0, 66, 22 }, { 0, 70, 23 }, + { 0, 72, 24 }, { 0, 76, 25 }, { 0, 78, 26 }, { 0, 82, 27 }, { 0, 84, 28 }, { 0, 88, 29 }, { 0, 90, 30 }, { 0, 94, 31 }, + { 0, 96, 32 }, { 0, 100, 33 }, { 0, 104, 34 }, { 0, 106, 35 }, { 0, 110, 36 }, { 0, 112, 37 }, { 0, 116, 38 }, { 0, 118, 39 }, + { 0, 122, 40 }, { 0, 124, 41 }, { 0, 128, 42 }, { 0, 130, 43 }, { 0, 134, 44 }, { 0, 136, 45 }, { 0, 140, 46 }, { 0, 142, 47 }, + { 0, 146, 48 }, { 0, 148, 49 }, { 0, 152, 50 }, { 0, 154, 51 }, { 0, 158, 52 }, { 0, 160, 53 }, { 0, 164, 54 }, { 0, 168, 55 }, + { 0, 170, 56 }, { 0, 174, 57 }, { 0, 176, 58 }, { 0, 180, 59 }, { 0, 182, 60 }, { 0, 186, 61 }, { 0, 188, 62 }, { 0, 192, 63 }, + { 0, 194, 64 }, { 0, 198, 65 }, { 0, 200, 66 }, { 0, 204, 67 }, { 0, 206, 68 }, { 0, 210, 69 }, { 0, 212, 70 }, { 0, 216, 71 }, + { 0, 218, 72 }, { 0, 222, 73 }, { 0, 224, 74 }, { 0, 228, 75 }, { 0, 232, 76 }, { 0, 234, 77 }, { 0, 238, 78 }, { 0, 240, 79 }, + { 0, 244, 80 }, { 0, 246, 81 }, { 0, 250, 82 }, { 0, 252, 83 }, { 2, 252, 84 }, { 2, 254, 85 }, { 4, 254, 86 }, { 6, 252, 87 }, + { 8, 252, 88 }, { 8, 254, 89 }, { 10, 254, 90 }, { 12, 252, 91 }, { 14, 252, 92 }, { 14, 254, 93 }, { 16, 254, 94 }, { 18, 252, 95 }, + { 20, 252, 96 }, { 20, 254, 97 }, { 22, 254, 98 }, { 24, 252, 99 }, { 26, 250, 100 }, { 26, 254, 101 }, { 28, 252, 102 }, { 30, 252, 103 }, + { 30, 254, 104 }, { 32, 254, 105 }, { 34, 252, 106 }, { 36, 252, 107 }, { 36, 254, 108 }, { 38, 254, 109 }, { 40, 252, 110 }, { 42, 252, 111 }, + { 42, 254, 112 }, { 44, 254, 113 }, { 46, 252, 114 }, { 48, 252, 115 }, { 48, 254, 116 }, { 50, 254, 117 }, { 52, 252, 118 }, { 54, 252, 119 }, + { 54, 254, 120 }, { 56, 254, 121 }, { 58, 252, 122 }, { 60, 252, 123 }, { 60, 254, 124 }, { 62, 254, 125 }, { 64, 252, 126 }, { 66, 252, 127 }, + { 66, 254, 128 }, { 68, 254, 129 }, { 70, 252, 130 }, { 72, 252, 131 }, { 72, 254, 132 }, { 74, 254, 133 }, { 76, 252, 134 }, { 78, 252, 135 }, + { 78, 254, 136 }, { 80, 254, 137 }, { 82, 252, 138 }, { 84, 252, 139 }, { 84, 254, 140 }, { 86, 254, 141 }, { 88, 252, 142 }, { 90, 250, 143 }, + { 90, 254, 144 }, { 92, 252, 145 }, { 94, 252, 146 }, { 94, 254, 147 }, { 96, 254, 148 }, { 98, 252, 149 }, { 100, 252, 150 }, { 100, 254, 151 }, + { 102, 254, 152 }, { 104, 252, 153 }, { 106, 252, 154 }, { 106, 254, 155 }, { 108, 254, 156 }, { 110, 252, 157 }, { 112, 252, 158 }, { 112, 254, 159 }, + { 114, 254, 160 }, { 116, 252, 161 }, { 118, 252, 162 }, { 118, 254, 163 }, { 120, 254, 164 }, { 122, 252, 165 }, { 124, 252, 166 }, { 124, 254, 167 }, + { 126, 254, 168 }, { 128, 252, 169 }, { 130, 252, 170 }, { 130, 254, 171 }, { 132, 254, 172 }, { 134, 252, 173 }, { 136, 252, 174 }, { 136, 254, 175 }, + { 138, 254, 176 }, { 140, 252, 177 }, { 142, 252, 178 }, { 142, 254, 179 }, { 144, 254, 180 }, { 146, 252, 181 }, { 148, 252, 182 }, { 148, 254, 183 }, + { 150, 254, 184 }, { 152, 252, 185 }, { 154, 250, 186 }, { 154, 254, 187 }, { 156, 252, 188 }, { 158, 252, 189 }, { 158, 254, 190 }, { 160, 254, 191 }, + { 162, 252, 192 }, { 164, 252, 193 }, { 164, 254, 194 }, { 166, 254, 195 }, { 168, 252, 196 }, { 170, 252, 197 }, { 170, 254, 198 }, { 172, 254, 199 }, + { 174, 252, 200 }, { 176, 252, 201 }, { 176, 254, 202 }, { 178, 254, 203 }, { 180, 252, 204 }, { 182, 252, 205 }, { 182, 254, 206 }, { 184, 254, 207 }, + { 186, 252, 208 }, { 188, 252, 209 }, { 188, 254, 210 }, { 190, 254, 211 }, { 192, 252, 212 }, { 194, 252, 213 }, { 194, 254, 214 }, { 196, 254, 215 }, + { 198, 252, 216 }, { 200, 252, 217 }, { 200, 254, 218 }, { 202, 254, 219 }, { 204, 252, 220 }, { 206, 252, 221 }, { 206, 254, 222 }, { 208, 254, 223 }, + { 210, 252, 224 }, { 212, 252, 225 }, { 212, 254, 226 }, { 214, 254, 227 }, { 216, 252, 228 }, { 218, 250, 229 }, { 218, 254, 230 }, { 220, 252, 231 }, + { 222, 252, 232 }, { 222, 254, 233 }, { 224, 254, 234 }, { 226, 252, 235 }, { 228, 252, 236 }, { 228, 254, 237 }, { 230, 254, 238 }, { 232, 252, 239 }, + { 234, 252, 240 }, { 234, 254, 241 }, { 236, 254, 242 }, { 238, 252, 243 }, { 240, 252, 244 }, { 240, 254, 245 }, { 242, 254, 246 }, { 244, 252, 247 }, + { 246, 252, 248 }, { 246, 254, 249 }, { 248, 254, 250 }, { 250, 252, 251 }, { 252, 252, 252 }, { 252, 254, 253 }, { 254, 254, 254 }, { 254, 254, 254 }, + } +}; + +Table g_mode6_p0_i6= +{ + 6, + 0, + { + { 0, 0, 0 }, { 0, 2, 1 }, { 0, 4, 2 }, { 0, 8, 3 }, { 0, 10, 4 }, { 0, 12, 5 }, { 0, 14, 6 }, { 0, 16, 7 }, + { 0, 20, 8 }, { 0, 22, 9 }, { 0, 24, 10 }, { 0, 26, 11 }, { 0, 30, 12 }, { 0, 32, 13 }, { 0, 34, 14 }, { 0, 36, 15 }, + { 0, 40, 16 }, { 0, 42, 17 }, { 0, 44, 18 }, { 0, 46, 19 }, { 0, 48, 20 }, { 0, 52, 21 }, { 0, 54, 22 }, { 0, 56, 23 }, + { 0, 58, 24 }, { 0, 62, 25 }, { 0, 64, 26 }, { 0, 66, 27 }, { 0, 68, 28 }, { 0, 72, 29 }, { 0, 74, 30 }, { 0, 76, 31 }, + { 0, 78, 32 }, { 0, 80, 33 }, { 0, 84, 34 }, { 0, 86, 35 }, { 0, 88, 36 }, { 0, 90, 37 }, { 0, 94, 38 }, { 0, 96, 39 }, + { 0, 98, 40 }, { 0, 100, 41 }, { 0, 104, 42 }, { 0, 106, 43 }, { 0, 108, 44 }, { 0, 110, 45 }, { 0, 112, 46 }, { 0, 116, 47 }, + { 0, 118, 48 }, { 0, 120, 49 }, { 0, 122, 50 }, { 0, 126, 51 }, { 0, 128, 52 }, { 0, 130, 53 }, { 0, 132, 54 }, { 0, 136, 55 }, + { 0, 138, 56 }, { 0, 140, 57 }, { 0, 142, 58 }, { 0, 144, 59 }, { 0, 148, 60 }, { 0, 150, 61 }, { 0, 152, 62 }, { 0, 154, 63 }, + { 0, 158, 64 }, { 0, 160, 65 }, { 0, 162, 66 }, { 0, 164, 67 }, { 0, 168, 68 }, { 0, 170, 69 }, { 0, 172, 70 }, { 0, 174, 71 }, + { 0, 176, 72 }, { 0, 180, 73 }, { 0, 182, 74 }, { 0, 184, 75 }, { 0, 186, 76 }, { 0, 190, 77 }, { 0, 192, 78 }, { 0, 194, 79 }, + { 0, 196, 80 }, { 0, 200, 81 }, { 0, 202, 82 }, { 0, 204, 83 }, { 0, 206, 84 }, { 0, 208, 85 }, { 0, 212, 86 }, { 0, 214, 87 }, + { 0, 216, 88 }, { 0, 218, 89 }, { 0, 222, 90 }, { 0, 224, 91 }, { 0, 226, 92 }, { 0, 228, 93 }, { 0, 232, 94 }, { 0, 234, 95 }, + { 0, 236, 96 }, { 0, 238, 97 }, { 0, 240, 98 }, { 0, 244, 99 }, { 0, 246, 100 }, { 0, 248, 101 }, { 0, 250, 102 }, { 0, 254, 103 }, + { 2, 252, 104 }, { 4, 252, 105 }, { 4, 254, 106 }, { 6, 254, 107 }, { 8, 254, 108 }, { 10, 254, 109 }, { 12, 252, 110 }, { 14, 252, 111 }, + { 14, 254, 112 }, { 16, 254, 113 }, { 18, 254, 114 }, { 20, 254, 115 }, { 22, 254, 116 }, { 24, 252, 117 }, { 26, 252, 118 }, { 26, 254, 119 }, + { 28, 254, 120 }, { 30, 254, 121 }, { 32, 254, 122 }, { 34, 252, 123 }, { 36, 252, 124 }, { 36, 254, 125 }, { 38, 254, 126 }, { 40, 254, 127 }, + { 42, 254, 128 }, { 44, 252, 129 }, { 46, 252, 130 }, { 46, 254, 131 }, { 48, 254, 132 }, { 50, 254, 133 }, { 52, 254, 134 }, { 54, 254, 135 }, + { 56, 252, 136 }, { 58, 252, 137 }, { 58, 254, 138 }, { 60, 254, 139 }, { 62, 254, 140 }, { 64, 254, 141 }, { 66, 252, 142 }, { 68, 252, 143 }, + { 68, 254, 144 }, { 70, 254, 145 }, { 72, 254, 146 }, { 74, 254, 147 }, { 76, 252, 148 }, { 78, 252, 149 }, { 78, 254, 150 }, { 80, 254, 151 }, + { 82, 254, 152 }, { 84, 254, 153 }, { 86, 254, 154 }, { 88, 252, 155 }, { 90, 252, 156 }, { 90, 254, 157 }, { 92, 254, 158 }, { 94, 254, 159 }, + { 96, 254, 160 }, { 98, 252, 161 }, { 100, 252, 162 }, { 100, 254, 163 }, { 102, 254, 164 }, { 104, 254, 165 }, { 106, 254, 166 }, { 108, 252, 167 }, + { 110, 252, 168 }, { 110, 254, 169 }, { 112, 254, 170 }, { 114, 254, 171 }, { 116, 254, 172 }, { 118, 254, 173 }, { 120, 252, 174 }, { 122, 252, 175 }, + { 122, 254, 176 }, { 124, 254, 177 }, { 126, 254, 178 }, { 128, 254, 179 }, { 130, 252, 180 }, { 132, 252, 181 }, { 132, 254, 182 }, { 134, 254, 183 }, + { 136, 254, 184 }, { 138, 254, 185 }, { 140, 252, 186 }, { 142, 252, 187 }, { 142, 254, 188 }, { 144, 254, 189 }, { 146, 254, 190 }, { 148, 254, 191 }, + { 150, 254, 192 }, { 152, 252, 193 }, { 154, 252, 194 }, { 154, 254, 195 }, { 156, 254, 196 }, { 158, 254, 197 }, { 160, 254, 198 }, { 162, 252, 199 }, + { 164, 252, 200 }, { 164, 254, 201 }, { 166, 254, 202 }, { 168, 254, 203 }, { 170, 254, 204 }, { 172, 252, 205 }, { 174, 252, 206 }, { 174, 254, 207 }, + { 176, 254, 208 }, { 178, 254, 209 }, { 180, 254, 210 }, { 182, 254, 211 }, { 184, 252, 212 }, { 186, 252, 213 }, { 186, 254, 214 }, { 188, 254, 215 }, + { 190, 254, 216 }, { 192, 254, 217 }, { 194, 252, 218 }, { 196, 252, 219 }, { 196, 254, 220 }, { 198, 254, 221 }, { 200, 254, 222 }, { 202, 254, 223 }, + { 204, 252, 224 }, { 206, 252, 225 }, { 206, 254, 226 }, { 208, 254, 227 }, { 210, 254, 228 }, { 212, 254, 229 }, { 214, 254, 230 }, { 216, 252, 231 }, + { 218, 252, 232 }, { 218, 254, 233 }, { 220, 254, 234 }, { 222, 254, 235 }, { 224, 254, 236 }, { 226, 252, 237 }, { 228, 252, 238 }, { 228, 254, 239 }, + { 230, 254, 240 }, { 232, 254, 241 }, { 234, 254, 242 }, { 236, 252, 243 }, { 238, 252, 244 }, { 238, 254, 245 }, { 240, 254, 246 }, { 242, 254, 247 }, + { 244, 254, 248 }, { 246, 254, 249 }, { 248, 252, 250 }, { 250, 252, 251 }, { 250, 254, 252 }, { 252, 254, 253 }, { 254, 254, 254 }, { 254, 254, 254 }, + } +}; + +Table g_mode6_p0_i7= +{ + 7, + 0, + { + { 0, 0, 0 }, { 0, 2, 1 }, { 0, 4, 2 }, { 0, 6, 3 }, { 0, 8, 4 }, { 0, 10, 5 }, { 0, 12, 6 }, { 0, 14, 7 }, + { 0, 16, 8 }, { 0, 20, 9 }, { 0, 22, 10 }, { 0, 24, 11 }, { 0, 26, 12 }, { 0, 28, 13 }, { 0, 30, 14 }, { 0, 32, 15 }, + { 0, 34, 16 }, { 0, 36, 17 }, { 0, 38, 18 }, { 0, 40, 19 }, { 0, 42, 20 }, { 0, 44, 21 }, { 0, 46, 22 }, { 0, 48, 23 }, + { 0, 52, 24 }, { 0, 54, 25 }, { 0, 56, 26 }, { 0, 58, 27 }, { 0, 60, 28 }, { 0, 62, 29 }, { 0, 64, 30 }, { 0, 66, 31 }, + { 0, 68, 32 }, { 0, 70, 33 }, { 0, 72, 34 }, { 0, 74, 35 }, { 0, 76, 36 }, { 0, 78, 37 }, { 0, 80, 38 }, { 0, 84, 39 }, + { 0, 86, 40 }, { 0, 88, 41 }, { 0, 90, 42 }, { 0, 92, 43 }, { 0, 94, 44 }, { 0, 96, 45 }, { 0, 98, 46 }, { 0, 100, 47 }, + { 0, 102, 48 }, { 0, 104, 49 }, { 0, 106, 50 }, { 0, 108, 51 }, { 0, 110, 52 }, { 0, 112, 53 }, { 0, 116, 54 }, { 0, 118, 55 }, + { 0, 120, 56 }, { 0, 122, 57 }, { 0, 124, 58 }, { 0, 126, 59 }, { 0, 128, 60 }, { 0, 130, 61 }, { 0, 132, 62 }, { 0, 134, 63 }, + { 0, 136, 64 }, { 0, 138, 65 }, { 0, 140, 66 }, { 0, 142, 67 }, { 0, 144, 68 }, { 0, 148, 69 }, { 0, 150, 70 }, { 0, 152, 71 }, + { 0, 154, 72 }, { 0, 156, 73 }, { 0, 158, 74 }, { 0, 160, 75 }, { 0, 162, 76 }, { 0, 164, 77 }, { 0, 166, 78 }, { 0, 168, 79 }, + { 0, 170, 80 }, { 0, 172, 81 }, { 0, 174, 82 }, { 0, 176, 83 }, { 0, 180, 84 }, { 0, 182, 85 }, { 0, 184, 86 }, { 0, 186, 87 }, + { 0, 188, 88 }, { 0, 190, 89 }, { 0, 192, 90 }, { 0, 194, 91 }, { 0, 196, 92 }, { 0, 198, 93 }, { 0, 200, 94 }, { 0, 202, 95 }, + { 0, 204, 96 }, { 0, 206, 97 }, { 0, 208, 98 }, { 0, 212, 99 }, { 0, 214, 100 }, { 0, 216, 101 }, { 0, 218, 102 }, { 0, 220, 103 }, + { 0, 222, 104 }, { 0, 224, 105 }, { 0, 226, 106 }, { 0, 228, 107 }, { 0, 230, 108 }, { 0, 232, 109 }, { 0, 234, 110 }, { 0, 236, 111 }, + { 0, 238, 112 }, { 0, 240, 113 }, { 0, 244, 114 }, { 0, 246, 115 }, { 0, 248, 116 }, { 0, 250, 117 }, { 0, 252, 118 }, { 0, 254, 119 }, + { 2, 254, 120 }, { 4, 254, 121 }, { 6, 254, 122 }, { 8, 254, 123 }, { 10, 254, 124 }, { 12, 252, 125 }, { 14, 252, 126 }, { 14, 254, 127 }, + { 16, 254, 128 }, { 18, 254, 129 }, { 20, 254, 130 }, { 22, 254, 131 }, { 24, 254, 132 }, { 26, 254, 133 }, { 28, 254, 134 }, { 30, 254, 135 }, + { 32, 254, 136 }, { 34, 254, 137 }, { 36, 254, 138 }, { 38, 254, 139 }, { 40, 254, 140 }, { 42, 254, 141 }, { 44, 252, 142 }, { 46, 252, 143 }, + { 46, 254, 144 }, { 48, 254, 145 }, { 50, 254, 146 }, { 52, 254, 147 }, { 54, 254, 148 }, { 56, 254, 149 }, { 58, 254, 150 }, { 60, 254, 151 }, + { 62, 254, 152 }, { 64, 254, 153 }, { 66, 254, 154 }, { 68, 254, 155 }, { 70, 254, 156 }, { 72, 254, 157 }, { 74, 254, 158 }, { 76, 252, 159 }, + { 78, 252, 160 }, { 78, 254, 161 }, { 80, 254, 162 }, { 82, 254, 163 }, { 84, 254, 164 }, { 86, 254, 165 }, { 88, 254, 166 }, { 90, 254, 167 }, + { 92, 254, 168 }, { 94, 254, 169 }, { 96, 254, 170 }, { 98, 254, 171 }, { 100, 254, 172 }, { 102, 254, 173 }, { 104, 254, 174 }, { 106, 254, 175 }, + { 108, 252, 176 }, { 110, 252, 177 }, { 110, 254, 178 }, { 112, 254, 179 }, { 114, 254, 180 }, { 116, 254, 181 }, { 118, 254, 182 }, { 120, 254, 183 }, + { 122, 254, 184 }, { 124, 254, 185 }, { 126, 254, 186 }, { 128, 254, 187 }, { 130, 254, 188 }, { 132, 254, 189 }, { 134, 254, 190 }, { 136, 254, 191 }, + { 138, 254, 192 }, { 140, 252, 193 }, { 142, 252, 194 }, { 142, 254, 195 }, { 144, 254, 196 }, { 146, 254, 197 }, { 148, 254, 198 }, { 150, 254, 199 }, + { 152, 254, 200 }, { 154, 254, 201 }, { 156, 254, 202 }, { 158, 254, 203 }, { 160, 254, 204 }, { 162, 254, 205 }, { 164, 254, 206 }, { 166, 254, 207 }, + { 168, 254, 208 }, { 170, 254, 209 }, { 172, 252, 210 }, { 174, 252, 211 }, { 174, 254, 212 }, { 176, 254, 213 }, { 178, 254, 214 }, { 180, 254, 215 }, + { 182, 254, 216 }, { 184, 254, 217 }, { 186, 254, 218 }, { 188, 254, 219 }, { 190, 254, 220 }, { 192, 254, 221 }, { 194, 254, 222 }, { 196, 254, 223 }, + { 198, 254, 224 }, { 200, 254, 225 }, { 202, 254, 226 }, { 204, 252, 227 }, { 206, 252, 228 }, { 206, 254, 229 }, { 208, 254, 230 }, { 210, 254, 231 }, + { 212, 254, 232 }, { 214, 254, 233 }, { 216, 254, 234 }, { 218, 254, 235 }, { 220, 254, 236 }, { 222, 254, 237 }, { 224, 254, 238 }, { 226, 254, 239 }, + { 228, 254, 240 }, { 230, 254, 241 }, { 232, 254, 242 }, { 234, 254, 243 }, { 236, 252, 244 }, { 238, 252, 245 }, { 238, 254, 246 }, { 240, 254, 247 }, + { 242, 254, 248 }, { 244, 254, 249 }, { 246, 254, 250 }, { 248, 254, 251 }, { 250, 254, 252 }, { 252, 254, 253 }, { 254, 254, 254 }, { 254, 254, 254 }, + } +}; + +Table g_mode6_p1_i1= +{ + 1, + 1, + { + { 1, 1, 1 }, { 1, 1, 1 }, { 1, 9, 2 }, { 1, 25, 3 }, { 1, 41, 4 }, { 1, 57, 5 }, { 1, 73, 6 }, { 1, 89, 7 }, + { 1, 105, 8 }, { 1, 121, 9 }, { 1, 137, 10 }, { 1, 153, 11 }, { 1, 169, 12 }, { 1, 185, 13 }, { 1, 201, 14 }, { 1, 217, 15 }, + { 1, 233, 16 }, { 1, 249, 17 }, { 3, 235, 18 }, { 3, 251, 19 }, { 5, 237, 20 }, { 5, 253, 21 }, { 7, 239, 22 }, { 7, 255, 23 }, + { 9, 241, 24 }, { 11, 227, 25 }, { 11, 243, 26 }, { 13, 229, 27 }, { 13, 245, 28 }, { 15, 231, 29 }, { 15, 247, 30 }, { 17, 233, 31 }, + { 17, 249, 32 }, { 19, 235, 33 }, { 19, 251, 34 }, { 21, 237, 35 }, { 21, 253, 36 }, { 23, 239, 37 }, { 23, 255, 38 }, { 25, 241, 39 }, + { 27, 227, 40 }, { 27, 243, 41 }, { 29, 229, 42 }, { 29, 245, 43 }, { 31, 231, 44 }, { 31, 247, 45 }, { 33, 233, 46 }, { 33, 249, 47 }, + { 35, 235, 48 }, { 35, 251, 49 }, { 37, 237, 50 }, { 37, 253, 51 }, { 39, 239, 52 }, { 39, 255, 53 }, { 41, 241, 54 }, { 43, 227, 55 }, + { 43, 243, 56 }, { 45, 229, 57 }, { 45, 245, 58 }, { 47, 231, 59 }, { 47, 247, 60 }, { 49, 233, 61 }, { 49, 249, 62 }, { 51, 235, 63 }, + { 51, 251, 64 }, { 53, 237, 65 }, { 53, 253, 66 }, { 55, 239, 67 }, { 55, 255, 68 }, { 57, 241, 69 }, { 59, 227, 70 }, { 59, 243, 71 }, + { 61, 229, 72 }, { 61, 245, 73 }, { 63, 231, 74 }, { 63, 247, 75 }, { 65, 233, 76 }, { 65, 249, 77 }, { 67, 235, 78 }, { 67, 251, 79 }, + { 69, 237, 80 }, { 69, 253, 81 }, { 71, 239, 82 }, { 71, 255, 83 }, { 73, 241, 84 }, { 75, 227, 85 }, { 75, 243, 86 }, { 77, 229, 87 }, + { 77, 245, 88 }, { 79, 231, 89 }, { 79, 247, 90 }, { 81, 233, 91 }, { 81, 249, 92 }, { 83, 235, 93 }, { 83, 251, 94 }, { 85, 237, 95 }, + { 85, 253, 96 }, { 87, 239, 97 }, { 87, 255, 98 }, { 89, 241, 99 }, { 91, 227, 100 }, { 91, 243, 101 }, { 93, 229, 102 }, { 93, 245, 103 }, + { 95, 231, 104 }, { 95, 247, 105 }, { 97, 233, 106 }, { 97, 249, 107 }, { 99, 235, 108 }, { 99, 251, 109 }, { 101, 237, 110 }, { 101, 253, 111 }, + { 103, 239, 112 }, { 103, 255, 113 }, { 105, 241, 114 }, { 107, 227, 115 }, { 107, 243, 116 }, { 109, 229, 117 }, { 109, 245, 118 }, { 111, 231, 119 }, + { 111, 247, 120 }, { 113, 233, 121 }, { 113, 249, 122 }, { 115, 235, 123 }, { 115, 251, 124 }, { 117, 237, 125 }, { 117, 253, 126 }, { 119, 239, 127 }, + { 119, 255, 128 }, { 121, 241, 129 }, { 123, 227, 130 }, { 123, 243, 131 }, { 125, 229, 132 }, { 125, 245, 133 }, { 127, 231, 134 }, { 127, 247, 135 }, + { 129, 233, 136 }, { 129, 249, 137 }, { 131, 235, 138 }, { 131, 251, 139 }, { 133, 237, 140 }, { 133, 253, 141 }, { 135, 239, 142 }, { 135, 255, 143 }, + { 137, 241, 144 }, { 139, 227, 145 }, { 139, 243, 146 }, { 141, 229, 147 }, { 141, 245, 148 }, { 143, 231, 149 }, { 143, 247, 150 }, { 145, 233, 151 }, + { 145, 249, 152 }, { 147, 235, 153 }, { 147, 251, 154 }, { 149, 237, 155 }, { 149, 253, 156 }, { 151, 239, 157 }, { 151, 255, 158 }, { 153, 241, 159 }, + { 155, 227, 160 }, { 155, 243, 161 }, { 157, 229, 162 }, { 157, 245, 163 }, { 159, 231, 164 }, { 159, 247, 165 }, { 161, 233, 166 }, { 161, 249, 167 }, + { 163, 235, 168 }, { 163, 251, 169 }, { 165, 237, 170 }, { 165, 253, 171 }, { 167, 239, 172 }, { 167, 255, 173 }, { 169, 241, 174 }, { 171, 227, 175 }, + { 171, 243, 176 }, { 173, 229, 177 }, { 173, 245, 178 }, { 175, 231, 179 }, { 175, 247, 180 }, { 177, 233, 181 }, { 177, 249, 182 }, { 179, 235, 183 }, + { 179, 251, 184 }, { 181, 237, 185 }, { 181, 253, 186 }, { 183, 239, 187 }, { 183, 255, 188 }, { 185, 241, 189 }, { 187, 227, 190 }, { 187, 243, 191 }, + { 189, 229, 192 }, { 189, 245, 193 }, { 191, 231, 194 }, { 191, 247, 195 }, { 193, 233, 196 }, { 193, 249, 197 }, { 195, 235, 198 }, { 195, 251, 199 }, + { 197, 237, 200 }, { 197, 253, 201 }, { 199, 239, 202 }, { 199, 255, 203 }, { 201, 241, 204 }, { 203, 227, 205 }, { 203, 243, 206 }, { 205, 229, 207 }, + { 205, 245, 208 }, { 207, 231, 209 }, { 207, 247, 210 }, { 209, 233, 211 }, { 209, 249, 212 }, { 211, 235, 213 }, { 211, 251, 214 }, { 213, 237, 215 }, + { 213, 253, 216 }, { 215, 239, 217 }, { 215, 255, 218 }, { 217, 241, 219 }, { 219, 227, 220 }, { 219, 243, 221 }, { 221, 229, 222 }, { 221, 245, 223 }, + { 223, 231, 224 }, { 223, 247, 225 }, { 225, 233, 226 }, { 225, 249, 227 }, { 227, 235, 228 }, { 227, 251, 229 }, { 229, 237, 230 }, { 229, 253, 231 }, + { 231, 239, 232 }, { 231, 255, 233 }, { 233, 241, 234 }, { 235, 227, 235 }, { 235, 243, 236 }, { 237, 229, 237 }, { 237, 245, 238 }, { 239, 231, 239 }, + { 239, 247, 240 }, { 241, 233, 241 }, { 241, 249, 242 }, { 243, 235, 243 }, { 243, 251, 244 }, { 245, 237, 245 }, { 245, 253, 246 }, { 247, 239, 247 }, + { 247, 255, 248 }, { 249, 241, 249 }, { 251, 227, 250 }, { 251, 243, 251 }, { 253, 229, 252 }, { 253, 245, 253 }, { 255, 231, 254 }, { 255, 247, 255 }, + } +}; + +Table g_mode6_p1_i2= +{ + 2, + 1, + { + { 1, 1, 1 }, { 1, 1, 1 }, { 1, 5, 2 }, { 1, 13, 3 }, { 1, 19, 4 }, { 1, 27, 5 }, { 1, 33, 6 }, { 1, 41, 7 }, + { 1, 49, 8 }, { 1, 55, 9 }, { 1, 63, 10 }, { 1, 69, 11 }, { 1, 77, 12 }, { 1, 83, 13 }, { 1, 91, 14 }, { 1, 97, 15 }, + { 1, 105, 16 }, { 1, 113, 17 }, { 1, 119, 18 }, { 1, 127, 19 }, { 1, 133, 20 }, { 1, 141, 21 }, { 1, 147, 22 }, { 1, 155, 23 }, + { 1, 161, 24 }, { 1, 169, 25 }, { 1, 177, 26 }, { 1, 183, 27 }, { 1, 191, 28 }, { 1, 197, 29 }, { 1, 205, 30 }, { 1, 211, 31 }, + { 1, 219, 32 }, { 1, 225, 33 }, { 1, 233, 34 }, { 1, 241, 35 }, { 1, 247, 36 }, { 1, 255, 37 }, { 3, 249, 38 }, { 5, 245, 39 }, + { 5, 251, 40 }, { 7, 247, 41 }, { 7, 253, 42 }, { 9, 249, 43 }, { 9, 255, 44 }, { 11, 251, 45 }, { 13, 245, 46 }, { 13, 253, 47 }, + { 15, 247, 48 }, { 15, 255, 49 }, { 17, 249, 50 }, { 19, 243, 51 }, { 19, 251, 52 }, { 21, 245, 53 }, { 21, 253, 54 }, { 23, 247, 55 }, + { 23, 255, 56 }, { 25, 249, 57 }, { 27, 245, 58 }, { 27, 251, 59 }, { 29, 247, 60 }, { 29, 253, 61 }, { 31, 249, 62 }, { 31, 255, 63 }, + { 33, 251, 64 }, { 35, 245, 65 }, { 35, 253, 66 }, { 37, 247, 67 }, { 37, 255, 68 }, { 39, 249, 69 }, { 41, 245, 70 }, { 41, 251, 71 }, + { 43, 247, 72 }, { 43, 253, 73 }, { 45, 249, 74 }, { 45, 255, 75 }, { 47, 251, 76 }, { 49, 245, 77 }, { 49, 253, 78 }, { 51, 247, 79 }, + { 51, 255, 80 }, { 53, 249, 81 }, { 55, 245, 82 }, { 55, 251, 83 }, { 57, 247, 84 }, { 57, 253, 85 }, { 59, 249, 86 }, { 59, 255, 87 }, + { 61, 251, 88 }, { 63, 245, 89 }, { 63, 253, 90 }, { 65, 247, 91 }, { 65, 255, 92 }, { 67, 249, 93 }, { 69, 245, 94 }, { 69, 251, 95 }, + { 71, 247, 96 }, { 71, 253, 97 }, { 73, 249, 98 }, { 73, 255, 99 }, { 75, 251, 100 }, { 77, 245, 101 }, { 77, 253, 102 }, { 79, 247, 103 }, + { 79, 255, 104 }, { 81, 249, 105 }, { 83, 243, 106 }, { 83, 251, 107 }, { 85, 245, 108 }, { 85, 253, 109 }, { 87, 247, 110 }, { 87, 255, 111 }, + { 89, 249, 112 }, { 91, 245, 113 }, { 91, 251, 114 }, { 93, 247, 115 }, { 93, 253, 116 }, { 95, 249, 117 }, { 95, 255, 118 }, { 97, 251, 119 }, + { 99, 245, 120 }, { 99, 253, 121 }, { 101, 247, 122 }, { 101, 255, 123 }, { 103, 249, 124 }, { 105, 245, 125 }, { 105, 251, 126 }, { 107, 247, 127 }, + { 107, 253, 128 }, { 109, 249, 129 }, { 109, 255, 130 }, { 111, 251, 131 }, { 113, 245, 132 }, { 113, 253, 133 }, { 115, 247, 134 }, { 115, 255, 135 }, + { 117, 249, 136 }, { 119, 245, 137 }, { 119, 251, 138 }, { 121, 247, 139 }, { 121, 253, 140 }, { 123, 249, 141 }, { 123, 255, 142 }, { 125, 251, 143 }, + { 127, 245, 144 }, { 127, 253, 145 }, { 129, 247, 146 }, { 129, 255, 147 }, { 131, 249, 148 }, { 133, 245, 149 }, { 133, 251, 150 }, { 135, 247, 151 }, + { 135, 253, 152 }, { 137, 249, 153 }, { 137, 255, 154 }, { 139, 251, 155 }, { 141, 245, 156 }, { 141, 253, 157 }, { 143, 247, 158 }, { 143, 255, 159 }, + { 145, 249, 160 }, { 147, 243, 161 }, { 147, 251, 162 }, { 149, 245, 163 }, { 149, 253, 164 }, { 151, 247, 165 }, { 151, 255, 166 }, { 153, 249, 167 }, + { 155, 245, 168 }, { 155, 251, 169 }, { 157, 247, 170 }, { 157, 253, 171 }, { 159, 249, 172 }, { 159, 255, 173 }, { 161, 251, 174 }, { 163, 245, 175 }, + { 163, 253, 176 }, { 165, 247, 177 }, { 165, 255, 178 }, { 167, 249, 179 }, { 169, 245, 180 }, { 169, 251, 181 }, { 171, 247, 182 }, { 171, 253, 183 }, + { 173, 249, 184 }, { 173, 255, 185 }, { 175, 251, 186 }, { 177, 245, 187 }, { 177, 253, 188 }, { 179, 247, 189 }, { 179, 255, 190 }, { 181, 249, 191 }, + { 183, 245, 192 }, { 183, 251, 193 }, { 185, 247, 194 }, { 185, 253, 195 }, { 187, 249, 196 }, { 187, 255, 197 }, { 189, 251, 198 }, { 191, 245, 199 }, + { 191, 253, 200 }, { 193, 247, 201 }, { 193, 255, 202 }, { 195, 249, 203 }, { 197, 245, 204 }, { 197, 251, 205 }, { 199, 247, 206 }, { 199, 253, 207 }, + { 201, 249, 208 }, { 201, 255, 209 }, { 203, 251, 210 }, { 205, 245, 211 }, { 205, 253, 212 }, { 207, 247, 213 }, { 207, 255, 214 }, { 209, 249, 215 }, + { 211, 243, 216 }, { 211, 251, 217 }, { 213, 245, 218 }, { 213, 253, 219 }, { 215, 247, 220 }, { 215, 255, 221 }, { 217, 249, 222 }, { 219, 245, 223 }, + { 219, 251, 224 }, { 221, 247, 225 }, { 221, 253, 226 }, { 223, 249, 227 }, { 223, 255, 228 }, { 225, 251, 229 }, { 227, 245, 230 }, { 227, 253, 231 }, + { 229, 247, 232 }, { 229, 255, 233 }, { 231, 249, 234 }, { 233, 245, 235 }, { 233, 251, 236 }, { 235, 247, 237 }, { 235, 253, 238 }, { 237, 249, 239 }, + { 237, 255, 240 }, { 239, 251, 241 }, { 241, 245, 242 }, { 241, 253, 243 }, { 243, 247, 244 }, { 243, 255, 245 }, { 245, 249, 246 }, { 247, 245, 247 }, + { 247, 251, 248 }, { 249, 247, 249 }, { 249, 253, 250 }, { 251, 249, 251 }, { 251, 255, 252 }, { 253, 251, 253 }, { 255, 245, 254 }, { 255, 253, 255 }, + } +}; + +Table g_mode6_p1_i3= +{ + 3, + 1, + { + { 1, 1, 1 }, { 1, 1, 1 }, { 1, 5, 2 }, { 1, 9, 3 }, { 1, 15, 4 }, { 1, 19, 5 }, { 1, 25, 6 }, { 1, 29, 7 }, + { 1, 33, 8 }, { 1, 39, 9 }, { 1, 43, 10 }, { 1, 49, 11 }, { 1, 53, 12 }, { 1, 59, 13 }, { 1, 63, 14 }, { 1, 69, 15 }, + { 1, 73, 16 }, { 1, 79, 17 }, { 1, 83, 18 }, { 1, 89, 19 }, { 1, 93, 20 }, { 1, 97, 21 }, { 1, 103, 22 }, { 1, 107, 23 }, + { 1, 113, 24 }, { 1, 117, 25 }, { 1, 123, 26 }, { 1, 127, 27 }, { 1, 133, 28 }, { 1, 137, 29 }, { 1, 143, 30 }, { 1, 147, 31 }, + { 1, 153, 32 }, { 1, 157, 33 }, { 1, 161, 34 }, { 1, 167, 35 }, { 1, 171, 36 }, { 1, 177, 37 }, { 1, 181, 38 }, { 1, 187, 39 }, + { 1, 191, 40 }, { 1, 197, 41 }, { 1, 201, 42 }, { 1, 207, 43 }, { 1, 211, 44 }, { 1, 217, 45 }, { 1, 221, 46 }, { 1, 225, 47 }, + { 1, 231, 48 }, { 1, 235, 49 }, { 1, 241, 50 }, { 1, 245, 51 }, { 1, 251, 52 }, { 1, 255, 53 }, { 3, 253, 54 }, { 5, 249, 55 }, + { 5, 255, 56 }, { 7, 251, 57 }, { 9, 249, 58 }, { 9, 253, 59 }, { 11, 251, 60 }, { 11, 255, 61 }, { 13, 253, 62 }, { 15, 249, 63 }, + { 15, 255, 64 }, { 17, 251, 65 }, { 19, 249, 66 }, { 19, 253, 67 }, { 21, 251, 68 }, { 21, 255, 69 }, { 23, 253, 70 }, { 25, 249, 71 }, + { 25, 255, 72 }, { 27, 251, 73 }, { 29, 249, 74 }, { 29, 253, 75 }, { 31, 251, 76 }, { 31, 255, 77 }, { 33, 253, 78 }, { 35, 251, 79 }, + { 35, 255, 80 }, { 37, 253, 81 }, { 39, 249, 82 }, { 39, 255, 83 }, { 41, 251, 84 }, { 43, 249, 85 }, { 43, 253, 86 }, { 45, 251, 87 }, + { 45, 255, 88 }, { 47, 253, 89 }, { 49, 249, 90 }, { 49, 255, 91 }, { 51, 251, 92 }, { 53, 249, 93 }, { 53, 253, 94 }, { 55, 251, 95 }, + { 55, 255, 96 }, { 57, 253, 97 }, { 59, 249, 98 }, { 59, 255, 99 }, { 61, 251, 100 }, { 63, 249, 101 }, { 63, 253, 102 }, { 65, 251, 103 }, + { 65, 255, 104 }, { 67, 253, 105 }, { 69, 249, 106 }, { 69, 255, 107 }, { 71, 251, 108 }, { 73, 249, 109 }, { 73, 253, 110 }, { 75, 251, 111 }, + { 75, 255, 112 }, { 77, 253, 113 }, { 79, 249, 114 }, { 79, 255, 115 }, { 81, 251, 116 }, { 83, 249, 117 }, { 83, 253, 118 }, { 85, 251, 119 }, + { 85, 255, 120 }, { 87, 253, 121 }, { 89, 249, 122 }, { 89, 255, 123 }, { 91, 251, 124 }, { 93, 249, 125 }, { 93, 253, 126 }, { 95, 251, 127 }, + { 95, 255, 128 }, { 97, 253, 129 }, { 99, 251, 130 }, { 99, 255, 131 }, { 101, 253, 132 }, { 103, 249, 133 }, { 103, 255, 134 }, { 105, 251, 135 }, + { 107, 249, 136 }, { 107, 253, 137 }, { 109, 251, 138 }, { 109, 255, 139 }, { 111, 253, 140 }, { 113, 249, 141 }, { 113, 255, 142 }, { 115, 251, 143 }, + { 117, 249, 144 }, { 117, 253, 145 }, { 119, 251, 146 }, { 119, 255, 147 }, { 121, 253, 148 }, { 123, 249, 149 }, { 123, 255, 150 }, { 125, 251, 151 }, + { 127, 249, 152 }, { 127, 253, 153 }, { 129, 251, 154 }, { 129, 255, 155 }, { 131, 253, 156 }, { 133, 249, 157 }, { 133, 255, 158 }, { 135, 251, 159 }, + { 137, 249, 160 }, { 137, 253, 161 }, { 139, 251, 162 }, { 139, 255, 163 }, { 141, 253, 164 }, { 143, 249, 165 }, { 143, 255, 166 }, { 145, 251, 167 }, + { 147, 249, 168 }, { 147, 253, 169 }, { 149, 251, 170 }, { 149, 255, 171 }, { 151, 253, 172 }, { 153, 249, 173 }, { 153, 255, 174 }, { 155, 251, 175 }, + { 157, 249, 176 }, { 157, 253, 177 }, { 159, 251, 178 }, { 159, 255, 179 }, { 161, 253, 180 }, { 163, 251, 181 }, { 163, 255, 182 }, { 165, 253, 183 }, + { 167, 249, 184 }, { 167, 255, 185 }, { 169, 251, 186 }, { 171, 249, 187 }, { 171, 253, 188 }, { 173, 251, 189 }, { 173, 255, 190 }, { 175, 253, 191 }, + { 177, 249, 192 }, { 177, 255, 193 }, { 179, 251, 194 }, { 181, 249, 195 }, { 181, 253, 196 }, { 183, 251, 197 }, { 183, 255, 198 }, { 185, 253, 199 }, + { 187, 249, 200 }, { 187, 255, 201 }, { 189, 251, 202 }, { 191, 249, 203 }, { 191, 253, 204 }, { 193, 251, 205 }, { 193, 255, 206 }, { 195, 253, 207 }, + { 197, 249, 208 }, { 197, 255, 209 }, { 199, 251, 210 }, { 201, 249, 211 }, { 201, 253, 212 }, { 203, 251, 213 }, { 203, 255, 214 }, { 205, 253, 215 }, + { 207, 249, 216 }, { 207, 255, 217 }, { 209, 251, 218 }, { 211, 249, 219 }, { 211, 253, 220 }, { 213, 251, 221 }, { 213, 255, 222 }, { 215, 253, 223 }, + { 217, 249, 224 }, { 217, 255, 225 }, { 219, 251, 226 }, { 221, 249, 227 }, { 221, 253, 228 }, { 223, 251, 229 }, { 223, 255, 230 }, { 225, 253, 231 }, + { 227, 251, 232 }, { 227, 255, 233 }, { 229, 253, 234 }, { 231, 249, 235 }, { 231, 255, 236 }, { 233, 251, 237 }, { 235, 249, 238 }, { 235, 253, 239 }, + { 237, 251, 240 }, { 237, 255, 241 }, { 239, 253, 242 }, { 241, 249, 243 }, { 241, 255, 244 }, { 243, 251, 245 }, { 245, 249, 246 }, { 245, 253, 247 }, + { 247, 251, 248 }, { 247, 255, 249 }, { 249, 253, 250 }, { 251, 249, 251 }, { 251, 255, 252 }, { 253, 251, 253 }, { 255, 249, 254 }, { 255, 253, 255 }, + } +}; + +Table g_mode6_p1_i4= +{ + 4, + 1, + { + { 1, 1, 1 }, { 1, 1, 1 }, { 1, 3, 2 }, { 1, 7, 3 }, { 1, 11, 4 }, { 1, 15, 5 }, { 1, 19, 6 }, { 1, 23, 7 }, + { 1, 27, 8 }, { 1, 31, 9 }, { 1, 33, 10 }, { 1, 37, 11 }, { 1, 41, 12 }, { 1, 45, 13 }, { 1, 49, 14 }, { 1, 53, 15 }, + { 1, 57, 16 }, { 1, 61, 17 }, { 1, 65, 18 }, { 1, 67, 19 }, { 1, 71, 20 }, { 1, 75, 21 }, { 1, 79, 22 }, { 1, 83, 23 }, + { 1, 87, 24 }, { 1, 91, 25 }, { 1, 95, 26 }, { 1, 97, 27 }, { 1, 101, 28 }, { 1, 105, 29 }, { 1, 109, 30 }, { 1, 113, 31 }, + { 1, 117, 32 }, { 1, 121, 33 }, { 1, 125, 34 }, { 1, 129, 35 }, { 1, 131, 36 }, { 1, 135, 37 }, { 1, 139, 38 }, { 1, 143, 39 }, + { 1, 147, 40 }, { 1, 151, 41 }, { 1, 155, 42 }, { 1, 159, 43 }, { 1, 161, 44 }, { 1, 165, 45 }, { 1, 169, 46 }, { 1, 173, 47 }, + { 1, 177, 48 }, { 1, 181, 49 }, { 1, 185, 50 }, { 1, 189, 51 }, { 1, 193, 52 }, { 1, 195, 53 }, { 1, 199, 54 }, { 1, 203, 55 }, + { 1, 207, 56 }, { 1, 211, 57 }, { 1, 215, 58 }, { 1, 219, 59 }, { 1, 223, 60 }, { 1, 225, 61 }, { 1, 229, 62 }, { 1, 233, 63 }, + { 1, 237, 64 }, { 1, 241, 65 }, { 1, 245, 66 }, { 1, 249, 67 }, { 1, 253, 68 }, { 3, 251, 69 }, { 3, 255, 70 }, { 5, 253, 71 }, + { 7, 251, 72 }, { 7, 255, 73 }, { 9, 253, 74 }, { 11, 251, 75 }, { 11, 255, 76 }, { 13, 253, 77 }, { 15, 251, 78 }, { 15, 255, 79 }, + { 17, 253, 80 }, { 19, 251, 81 }, { 19, 255, 82 }, { 21, 253, 83 }, { 23, 251, 84 }, { 23, 255, 85 }, { 25, 253, 86 }, { 27, 251, 87 }, + { 27, 255, 88 }, { 29, 253, 89 }, { 31, 253, 90 }, { 31, 255, 91 }, { 33, 255, 92 }, { 35, 253, 93 }, { 37, 251, 94 }, { 37, 255, 95 }, + { 39, 253, 96 }, { 41, 251, 97 }, { 41, 255, 98 }, { 43, 253, 99 }, { 45, 251, 100 }, { 45, 255, 101 }, { 47, 253, 102 }, { 49, 251, 103 }, + { 49, 255, 104 }, { 51, 253, 105 }, { 53, 251, 106 }, { 53, 255, 107 }, { 55, 253, 108 }, { 57, 251, 109 }, { 57, 255, 110 }, { 59, 253, 111 }, + { 61, 253, 112 }, { 61, 255, 113 }, { 63, 255, 114 }, { 65, 253, 115 }, { 67, 251, 116 }, { 67, 255, 117 }, { 69, 253, 118 }, { 71, 251, 119 }, + { 71, 255, 120 }, { 73, 253, 121 }, { 75, 251, 122 }, { 75, 255, 123 }, { 77, 253, 124 }, { 79, 251, 125 }, { 79, 255, 126 }, { 81, 253, 127 }, + { 83, 251, 128 }, { 83, 255, 129 }, { 85, 253, 130 }, { 87, 251, 131 }, { 87, 255, 132 }, { 89, 253, 133 }, { 91, 251, 134 }, { 91, 255, 135 }, + { 93, 253, 136 }, { 95, 253, 137 }, { 95, 255, 138 }, { 97, 255, 139 }, { 99, 253, 140 }, { 101, 251, 141 }, { 101, 255, 142 }, { 103, 253, 143 }, + { 105, 251, 144 }, { 105, 255, 145 }, { 107, 253, 146 }, { 109, 251, 147 }, { 109, 255, 148 }, { 111, 253, 149 }, { 113, 251, 150 }, { 113, 255, 151 }, + { 115, 253, 152 }, { 117, 251, 153 }, { 117, 255, 154 }, { 119, 253, 155 }, { 121, 251, 156 }, { 121, 255, 157 }, { 123, 253, 158 }, { 125, 253, 159 }, + { 125, 255, 160 }, { 127, 255, 161 }, { 129, 253, 162 }, { 131, 251, 163 }, { 131, 255, 164 }, { 133, 253, 165 }, { 135, 251, 166 }, { 135, 255, 167 }, + { 137, 253, 168 }, { 139, 251, 169 }, { 139, 255, 170 }, { 141, 253, 171 }, { 143, 251, 172 }, { 143, 255, 173 }, { 145, 253, 174 }, { 147, 251, 175 }, + { 147, 255, 176 }, { 149, 253, 177 }, { 151, 251, 178 }, { 151, 255, 179 }, { 153, 253, 180 }, { 155, 251, 181 }, { 155, 255, 182 }, { 157, 253, 183 }, + { 159, 253, 184 }, { 159, 255, 185 }, { 161, 255, 186 }, { 163, 253, 187 }, { 165, 251, 188 }, { 165, 255, 189 }, { 167, 253, 190 }, { 169, 251, 191 }, + { 169, 255, 192 }, { 171, 253, 193 }, { 173, 251, 194 }, { 173, 255, 195 }, { 175, 253, 196 }, { 177, 251, 197 }, { 177, 255, 198 }, { 179, 253, 199 }, + { 181, 251, 200 }, { 181, 255, 201 }, { 183, 253, 202 }, { 185, 251, 203 }, { 185, 255, 204 }, { 187, 253, 205 }, { 189, 253, 206 }, { 189, 255, 207 }, + { 191, 255, 208 }, { 193, 253, 209 }, { 195, 251, 210 }, { 195, 255, 211 }, { 197, 253, 212 }, { 199, 251, 213 }, { 199, 255, 214 }, { 201, 253, 215 }, + { 203, 251, 216 }, { 203, 255, 217 }, { 205, 253, 218 }, { 207, 251, 219 }, { 207, 255, 220 }, { 209, 253, 221 }, { 211, 251, 222 }, { 211, 255, 223 }, + { 213, 253, 224 }, { 215, 251, 225 }, { 215, 255, 226 }, { 217, 253, 227 }, { 219, 251, 228 }, { 219, 255, 229 }, { 221, 253, 230 }, { 223, 253, 231 }, + { 223, 255, 232 }, { 225, 255, 233 }, { 227, 253, 234 }, { 229, 251, 235 }, { 229, 255, 236 }, { 231, 253, 237 }, { 233, 251, 238 }, { 233, 255, 239 }, + { 235, 253, 240 }, { 237, 251, 241 }, { 237, 255, 242 }, { 239, 253, 243 }, { 241, 251, 244 }, { 241, 255, 245 }, { 243, 253, 246 }, { 245, 251, 247 }, + { 245, 255, 248 }, { 247, 253, 249 }, { 249, 251, 250 }, { 249, 255, 251 }, { 251, 253, 252 }, { 253, 253, 253 }, { 253, 255, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode6_p1_i5= +{ + 5, + 1, + { + { 1, 1, 1 }, { 1, 1, 1 }, { 1, 3, 2 }, { 1, 7, 3 }, { 1, 9, 4 }, { 1, 13, 5 }, { 1, 15, 6 }, { 1, 19, 7 }, + { 1, 21, 8 }, { 1, 25, 9 }, { 1, 27, 10 }, { 1, 31, 11 }, { 1, 33, 12 }, { 1, 37, 13 }, { 1, 41, 14 }, { 1, 43, 15 }, + { 1, 47, 16 }, { 1, 49, 17 }, { 1, 53, 18 }, { 1, 55, 19 }, { 1, 59, 20 }, { 1, 61, 21 }, { 1, 65, 22 }, { 1, 67, 23 }, + { 1, 71, 24 }, { 1, 73, 25 }, { 1, 77, 26 }, { 1, 79, 27 }, { 1, 83, 28 }, { 1, 85, 29 }, { 1, 89, 30 }, { 1, 91, 31 }, + { 1, 95, 32 }, { 1, 97, 33 }, { 1, 101, 34 }, { 1, 105, 35 }, { 1, 107, 36 }, { 1, 111, 37 }, { 1, 113, 38 }, { 1, 117, 39 }, + { 1, 119, 40 }, { 1, 123, 41 }, { 1, 125, 42 }, { 1, 129, 43 }, { 1, 131, 44 }, { 1, 135, 45 }, { 1, 137, 46 }, { 1, 141, 47 }, + { 1, 143, 48 }, { 1, 147, 49 }, { 1, 149, 50 }, { 1, 153, 51 }, { 1, 155, 52 }, { 1, 159, 53 }, { 1, 161, 54 }, { 1, 165, 55 }, + { 1, 169, 56 }, { 1, 171, 57 }, { 1, 175, 58 }, { 1, 177, 59 }, { 1, 181, 60 }, { 1, 183, 61 }, { 1, 187, 62 }, { 1, 189, 63 }, + { 1, 193, 64 }, { 1, 195, 65 }, { 1, 199, 66 }, { 1, 201, 67 }, { 1, 205, 68 }, { 1, 207, 69 }, { 1, 211, 70 }, { 1, 213, 71 }, + { 1, 217, 72 }, { 1, 219, 73 }, { 1, 223, 74 }, { 1, 225, 75 }, { 1, 229, 76 }, { 1, 233, 77 }, { 1, 235, 78 }, { 1, 239, 79 }, + { 1, 241, 80 }, { 1, 245, 81 }, { 1, 247, 82 }, { 1, 251, 83 }, { 1, 253, 84 }, { 3, 253, 85 }, { 3, 255, 86 }, { 5, 255, 87 }, + { 7, 253, 88 }, { 9, 253, 89 }, { 9, 255, 90 }, { 11, 255, 91 }, { 13, 253, 92 }, { 15, 253, 93 }, { 15, 255, 94 }, { 17, 255, 95 }, + { 19, 253, 96 }, { 21, 253, 97 }, { 21, 255, 98 }, { 23, 255, 99 }, { 25, 253, 100 }, { 27, 251, 101 }, { 27, 255, 102 }, { 29, 253, 103 }, + { 31, 253, 104 }, { 31, 255, 105 }, { 33, 255, 106 }, { 35, 253, 107 }, { 37, 253, 108 }, { 37, 255, 109 }, { 39, 255, 110 }, { 41, 253, 111 }, + { 43, 253, 112 }, { 43, 255, 113 }, { 45, 255, 114 }, { 47, 253, 115 }, { 49, 253, 116 }, { 49, 255, 117 }, { 51, 255, 118 }, { 53, 253, 119 }, + { 55, 253, 120 }, { 55, 255, 121 }, { 57, 255, 122 }, { 59, 253, 123 }, { 61, 253, 124 }, { 61, 255, 125 }, { 63, 255, 126 }, { 65, 253, 127 }, + { 67, 253, 128 }, { 67, 255, 129 }, { 69, 255, 130 }, { 71, 253, 131 }, { 73, 253, 132 }, { 73, 255, 133 }, { 75, 255, 134 }, { 77, 253, 135 }, + { 79, 253, 136 }, { 79, 255, 137 }, { 81, 255, 138 }, { 83, 253, 139 }, { 85, 253, 140 }, { 85, 255, 141 }, { 87, 255, 142 }, { 89, 253, 143 }, + { 91, 251, 144 }, { 91, 255, 145 }, { 93, 253, 146 }, { 95, 253, 147 }, { 95, 255, 148 }, { 97, 255, 149 }, { 99, 253, 150 }, { 101, 253, 151 }, + { 101, 255, 152 }, { 103, 255, 153 }, { 105, 253, 154 }, { 107, 253, 155 }, { 107, 255, 156 }, { 109, 255, 157 }, { 111, 253, 158 }, { 113, 253, 159 }, + { 113, 255, 160 }, { 115, 255, 161 }, { 117, 253, 162 }, { 119, 253, 163 }, { 119, 255, 164 }, { 121, 255, 165 }, { 123, 253, 166 }, { 125, 253, 167 }, + { 125, 255, 168 }, { 127, 255, 169 }, { 129, 253, 170 }, { 131, 253, 171 }, { 131, 255, 172 }, { 133, 255, 173 }, { 135, 253, 174 }, { 137, 253, 175 }, + { 137, 255, 176 }, { 139, 255, 177 }, { 141, 253, 178 }, { 143, 253, 179 }, { 143, 255, 180 }, { 145, 255, 181 }, { 147, 253, 182 }, { 149, 253, 183 }, + { 149, 255, 184 }, { 151, 255, 185 }, { 153, 253, 186 }, { 155, 251, 187 }, { 155, 255, 188 }, { 157, 253, 189 }, { 159, 253, 190 }, { 159, 255, 191 }, + { 161, 255, 192 }, { 163, 253, 193 }, { 165, 253, 194 }, { 165, 255, 195 }, { 167, 255, 196 }, { 169, 253, 197 }, { 171, 253, 198 }, { 171, 255, 199 }, + { 173, 255, 200 }, { 175, 253, 201 }, { 177, 253, 202 }, { 177, 255, 203 }, { 179, 255, 204 }, { 181, 253, 205 }, { 183, 253, 206 }, { 183, 255, 207 }, + { 185, 255, 208 }, { 187, 253, 209 }, { 189, 253, 210 }, { 189, 255, 211 }, { 191, 255, 212 }, { 193, 253, 213 }, { 195, 253, 214 }, { 195, 255, 215 }, + { 197, 255, 216 }, { 199, 253, 217 }, { 201, 253, 218 }, { 201, 255, 219 }, { 203, 255, 220 }, { 205, 253, 221 }, { 207, 253, 222 }, { 207, 255, 223 }, + { 209, 255, 224 }, { 211, 253, 225 }, { 213, 253, 226 }, { 213, 255, 227 }, { 215, 255, 228 }, { 217, 253, 229 }, { 219, 251, 230 }, { 219, 255, 231 }, + { 221, 253, 232 }, { 223, 253, 233 }, { 223, 255, 234 }, { 225, 255, 235 }, { 227, 253, 236 }, { 229, 253, 237 }, { 229, 255, 238 }, { 231, 255, 239 }, + { 233, 253, 240 }, { 235, 253, 241 }, { 235, 255, 242 }, { 237, 255, 243 }, { 239, 253, 244 }, { 241, 253, 245 }, { 241, 255, 246 }, { 243, 255, 247 }, + { 245, 253, 248 }, { 247, 253, 249 }, { 247, 255, 250 }, { 249, 255, 251 }, { 251, 253, 252 }, { 253, 253, 253 }, { 253, 255, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode6_p1_i6= +{ + 6, + 1, + { + { 1, 1, 1 }, { 1, 1, 1 }, { 1, 3, 2 }, { 1, 5, 3 }, { 1, 9, 4 }, { 1, 11, 5 }, { 1, 13, 6 }, { 1, 15, 7 }, + { 1, 17, 8 }, { 1, 21, 9 }, { 1, 23, 10 }, { 1, 25, 11 }, { 1, 27, 12 }, { 1, 31, 13 }, { 1, 33, 14 }, { 1, 35, 15 }, + { 1, 37, 16 }, { 1, 41, 17 }, { 1, 43, 18 }, { 1, 45, 19 }, { 1, 47, 20 }, { 1, 49, 21 }, { 1, 53, 22 }, { 1, 55, 23 }, + { 1, 57, 24 }, { 1, 59, 25 }, { 1, 63, 26 }, { 1, 65, 27 }, { 1, 67, 28 }, { 1, 69, 29 }, { 1, 73, 30 }, { 1, 75, 31 }, + { 1, 77, 32 }, { 1, 79, 33 }, { 1, 81, 34 }, { 1, 85, 35 }, { 1, 87, 36 }, { 1, 89, 37 }, { 1, 91, 38 }, { 1, 95, 39 }, + { 1, 97, 40 }, { 1, 99, 41 }, { 1, 101, 42 }, { 1, 105, 43 }, { 1, 107, 44 }, { 1, 109, 45 }, { 1, 111, 46 }, { 1, 113, 47 }, + { 1, 117, 48 }, { 1, 119, 49 }, { 1, 121, 50 }, { 1, 123, 51 }, { 1, 127, 52 }, { 1, 129, 53 }, { 1, 131, 54 }, { 1, 133, 55 }, + { 1, 137, 56 }, { 1, 139, 57 }, { 1, 141, 58 }, { 1, 143, 59 }, { 1, 145, 60 }, { 1, 149, 61 }, { 1, 151, 62 }, { 1, 153, 63 }, + { 1, 155, 64 }, { 1, 159, 65 }, { 1, 161, 66 }, { 1, 163, 67 }, { 1, 165, 68 }, { 1, 169, 69 }, { 1, 171, 70 }, { 1, 173, 71 }, + { 1, 175, 72 }, { 1, 177, 73 }, { 1, 181, 74 }, { 1, 183, 75 }, { 1, 185, 76 }, { 1, 187, 77 }, { 1, 191, 78 }, { 1, 193, 79 }, + { 1, 195, 80 }, { 1, 197, 81 }, { 1, 201, 82 }, { 1, 203, 83 }, { 1, 205, 84 }, { 1, 207, 85 }, { 1, 209, 86 }, { 1, 213, 87 }, + { 1, 215, 88 }, { 1, 217, 89 }, { 1, 219, 90 }, { 1, 223, 91 }, { 1, 225, 92 }, { 1, 227, 93 }, { 1, 229, 94 }, { 1, 233, 95 }, + { 1, 235, 96 }, { 1, 237, 97 }, { 1, 239, 98 }, { 1, 241, 99 }, { 1, 245, 100 }, { 1, 247, 101 }, { 1, 249, 102 }, { 1, 251, 103 }, + { 1, 255, 104 }, { 3, 253, 105 }, { 5, 253, 106 }, { 5, 255, 107 }, { 7, 255, 108 }, { 9, 255, 109 }, { 11, 255, 110 }, { 13, 253, 111 }, + { 15, 253, 112 }, { 15, 255, 113 }, { 17, 255, 114 }, { 19, 255, 115 }, { 21, 255, 116 }, { 23, 255, 117 }, { 25, 253, 118 }, { 27, 253, 119 }, + { 27, 255, 120 }, { 29, 255, 121 }, { 31, 255, 122 }, { 33, 255, 123 }, { 35, 253, 124 }, { 37, 253, 125 }, { 37, 255, 126 }, { 39, 255, 127 }, + { 41, 255, 128 }, { 43, 255, 129 }, { 45, 253, 130 }, { 47, 253, 131 }, { 47, 255, 132 }, { 49, 255, 133 }, { 51, 255, 134 }, { 53, 255, 135 }, + { 55, 255, 136 }, { 57, 253, 137 }, { 59, 253, 138 }, { 59, 255, 139 }, { 61, 255, 140 }, { 63, 255, 141 }, { 65, 255, 142 }, { 67, 253, 143 }, + { 69, 253, 144 }, { 69, 255, 145 }, { 71, 255, 146 }, { 73, 255, 147 }, { 75, 255, 148 }, { 77, 253, 149 }, { 79, 253, 150 }, { 79, 255, 151 }, + { 81, 255, 152 }, { 83, 255, 153 }, { 85, 255, 154 }, { 87, 255, 155 }, { 89, 253, 156 }, { 91, 253, 157 }, { 91, 255, 158 }, { 93, 255, 159 }, + { 95, 255, 160 }, { 97, 255, 161 }, { 99, 253, 162 }, { 101, 253, 163 }, { 101, 255, 164 }, { 103, 255, 165 }, { 105, 255, 166 }, { 107, 255, 167 }, + { 109, 253, 168 }, { 111, 253, 169 }, { 111, 255, 170 }, { 113, 255, 171 }, { 115, 255, 172 }, { 117, 255, 173 }, { 119, 255, 174 }, { 121, 253, 175 }, + { 123, 253, 176 }, { 123, 255, 177 }, { 125, 255, 178 }, { 127, 255, 179 }, { 129, 255, 180 }, { 131, 253, 181 }, { 133, 253, 182 }, { 133, 255, 183 }, + { 135, 255, 184 }, { 137, 255, 185 }, { 139, 255, 186 }, { 141, 253, 187 }, { 143, 253, 188 }, { 143, 255, 189 }, { 145, 255, 190 }, { 147, 255, 191 }, + { 149, 255, 192 }, { 151, 255, 193 }, { 153, 253, 194 }, { 155, 253, 195 }, { 155, 255, 196 }, { 157, 255, 197 }, { 159, 255, 198 }, { 161, 255, 199 }, + { 163, 253, 200 }, { 165, 253, 201 }, { 165, 255, 202 }, { 167, 255, 203 }, { 169, 255, 204 }, { 171, 255, 205 }, { 173, 253, 206 }, { 175, 253, 207 }, + { 175, 255, 208 }, { 177, 255, 209 }, { 179, 255, 210 }, { 181, 255, 211 }, { 183, 255, 212 }, { 185, 253, 213 }, { 187, 253, 214 }, { 187, 255, 215 }, + { 189, 255, 216 }, { 191, 255, 217 }, { 193, 255, 218 }, { 195, 253, 219 }, { 197, 253, 220 }, { 197, 255, 221 }, { 199, 255, 222 }, { 201, 255, 223 }, + { 203, 255, 224 }, { 205, 253, 225 }, { 207, 253, 226 }, { 207, 255, 227 }, { 209, 255, 228 }, { 211, 255, 229 }, { 213, 255, 230 }, { 215, 255, 231 }, + { 217, 253, 232 }, { 219, 253, 233 }, { 219, 255, 234 }, { 221, 255, 235 }, { 223, 255, 236 }, { 225, 255, 237 }, { 227, 253, 238 }, { 229, 253, 239 }, + { 229, 255, 240 }, { 231, 255, 241 }, { 233, 255, 242 }, { 235, 255, 243 }, { 237, 253, 244 }, { 239, 253, 245 }, { 239, 255, 246 }, { 241, 255, 247 }, + { 243, 255, 248 }, { 245, 255, 249 }, { 247, 255, 250 }, { 249, 253, 251 }, { 251, 253, 252 }, { 251, 255, 253 }, { 253, 255, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode6_p1_i7= +{ + 7, + 1, + { + { 1, 1, 1 }, { 1, 1, 1 }, { 1, 3, 2 }, { 1, 5, 3 }, { 1, 7, 4 }, { 1, 9, 5 }, { 1, 11, 6 }, { 1, 13, 7 }, + { 1, 15, 8 }, { 1, 17, 9 }, { 1, 21, 10 }, { 1, 23, 11 }, { 1, 25, 12 }, { 1, 27, 13 }, { 1, 29, 14 }, { 1, 31, 15 }, + { 1, 33, 16 }, { 1, 35, 17 }, { 1, 37, 18 }, { 1, 39, 19 }, { 1, 41, 20 }, { 1, 43, 21 }, { 1, 45, 22 }, { 1, 47, 23 }, + { 1, 49, 24 }, { 1, 53, 25 }, { 1, 55, 26 }, { 1, 57, 27 }, { 1, 59, 28 }, { 1, 61, 29 }, { 1, 63, 30 }, { 1, 65, 31 }, + { 1, 67, 32 }, { 1, 69, 33 }, { 1, 71, 34 }, { 1, 73, 35 }, { 1, 75, 36 }, { 1, 77, 37 }, { 1, 79, 38 }, { 1, 81, 39 }, + { 1, 85, 40 }, { 1, 87, 41 }, { 1, 89, 42 }, { 1, 91, 43 }, { 1, 93, 44 }, { 1, 95, 45 }, { 1, 97, 46 }, { 1, 99, 47 }, + { 1, 101, 48 }, { 1, 103, 49 }, { 1, 105, 50 }, { 1, 107, 51 }, { 1, 109, 52 }, { 1, 111, 53 }, { 1, 113, 54 }, { 1, 117, 55 }, + { 1, 119, 56 }, { 1, 121, 57 }, { 1, 123, 58 }, { 1, 125, 59 }, { 1, 127, 60 }, { 1, 129, 61 }, { 1, 131, 62 }, { 1, 133, 63 }, + { 1, 135, 64 }, { 1, 137, 65 }, { 1, 139, 66 }, { 1, 141, 67 }, { 1, 143, 68 }, { 1, 145, 69 }, { 1, 149, 70 }, { 1, 151, 71 }, + { 1, 153, 72 }, { 1, 155, 73 }, { 1, 157, 74 }, { 1, 159, 75 }, { 1, 161, 76 }, { 1, 163, 77 }, { 1, 165, 78 }, { 1, 167, 79 }, + { 1, 169, 80 }, { 1, 171, 81 }, { 1, 173, 82 }, { 1, 175, 83 }, { 1, 177, 84 }, { 1, 181, 85 }, { 1, 183, 86 }, { 1, 185, 87 }, + { 1, 187, 88 }, { 1, 189, 89 }, { 1, 191, 90 }, { 1, 193, 91 }, { 1, 195, 92 }, { 1, 197, 93 }, { 1, 199, 94 }, { 1, 201, 95 }, + { 1, 203, 96 }, { 1, 205, 97 }, { 1, 207, 98 }, { 1, 209, 99 }, { 1, 213, 100 }, { 1, 215, 101 }, { 1, 217, 102 }, { 1, 219, 103 }, + { 1, 221, 104 }, { 1, 223, 105 }, { 1, 225, 106 }, { 1, 227, 107 }, { 1, 229, 108 }, { 1, 231, 109 }, { 1, 233, 110 }, { 1, 235, 111 }, + { 1, 237, 112 }, { 1, 239, 113 }, { 1, 241, 114 }, { 1, 245, 115 }, { 1, 247, 116 }, { 1, 249, 117 }, { 1, 251, 118 }, { 1, 253, 119 }, + { 1, 255, 120 }, { 3, 255, 121 }, { 5, 255, 122 }, { 7, 255, 123 }, { 9, 255, 124 }, { 11, 255, 125 }, { 13, 253, 126 }, { 15, 253, 127 }, + { 15, 255, 128 }, { 17, 255, 129 }, { 19, 255, 130 }, { 21, 255, 131 }, { 23, 255, 132 }, { 25, 255, 133 }, { 27, 255, 134 }, { 29, 255, 135 }, + { 31, 255, 136 }, { 33, 255, 137 }, { 35, 255, 138 }, { 37, 255, 139 }, { 39, 255, 140 }, { 41, 255, 141 }, { 43, 255, 142 }, { 45, 253, 143 }, + { 47, 253, 144 }, { 47, 255, 145 }, { 49, 255, 146 }, { 51, 255, 147 }, { 53, 255, 148 }, { 55, 255, 149 }, { 57, 255, 150 }, { 59, 255, 151 }, + { 61, 255, 152 }, { 63, 255, 153 }, { 65, 255, 154 }, { 67, 255, 155 }, { 69, 255, 156 }, { 71, 255, 157 }, { 73, 255, 158 }, { 75, 255, 159 }, + { 77, 253, 160 }, { 79, 253, 161 }, { 79, 255, 162 }, { 81, 255, 163 }, { 83, 255, 164 }, { 85, 255, 165 }, { 87, 255, 166 }, { 89, 255, 167 }, + { 91, 255, 168 }, { 93, 255, 169 }, { 95, 255, 170 }, { 97, 255, 171 }, { 99, 255, 172 }, { 101, 255, 173 }, { 103, 255, 174 }, { 105, 255, 175 }, + { 107, 255, 176 }, { 109, 253, 177 }, { 111, 253, 178 }, { 111, 255, 179 }, { 113, 255, 180 }, { 115, 255, 181 }, { 117, 255, 182 }, { 119, 255, 183 }, + { 121, 255, 184 }, { 123, 255, 185 }, { 125, 255, 186 }, { 127, 255, 187 }, { 129, 255, 188 }, { 131, 255, 189 }, { 133, 255, 190 }, { 135, 255, 191 }, + { 137, 255, 192 }, { 139, 255, 193 }, { 141, 253, 194 }, { 143, 253, 195 }, { 143, 255, 196 }, { 145, 255, 197 }, { 147, 255, 198 }, { 149, 255, 199 }, + { 151, 255, 200 }, { 153, 255, 201 }, { 155, 255, 202 }, { 157, 255, 203 }, { 159, 255, 204 }, { 161, 255, 205 }, { 163, 255, 206 }, { 165, 255, 207 }, + { 167, 255, 208 }, { 169, 255, 209 }, { 171, 255, 210 }, { 173, 253, 211 }, { 175, 253, 212 }, { 175, 255, 213 }, { 177, 255, 214 }, { 179, 255, 215 }, + { 181, 255, 216 }, { 183, 255, 217 }, { 185, 255, 218 }, { 187, 255, 219 }, { 189, 255, 220 }, { 191, 255, 221 }, { 193, 255, 222 }, { 195, 255, 223 }, + { 197, 255, 224 }, { 199, 255, 225 }, { 201, 255, 226 }, { 203, 255, 227 }, { 205, 253, 228 }, { 207, 253, 229 }, { 207, 255, 230 }, { 209, 255, 231 }, + { 211, 255, 232 }, { 213, 255, 233 }, { 215, 255, 234 }, { 217, 255, 235 }, { 219, 255, 236 }, { 221, 255, 237 }, { 223, 255, 238 }, { 225, 255, 239 }, + { 227, 255, 240 }, { 229, 255, 241 }, { 231, 255, 242 }, { 233, 255, 243 }, { 235, 255, 244 }, { 237, 253, 245 }, { 239, 253, 246 }, { 239, 255, 247 }, + { 241, 255, 248 }, { 243, 255, 249 }, { 245, 255, 250 }, { 247, 255, 251 }, { 249, 255, 252 }, { 251, 255, 253 }, { 253, 255, 254 }, { 255, 255, 255 }, + } +}; + +Table g_mode7_p00= +{ + 1, + 0, + { + { 0, 0, 0 }, { 0, 2, 1 }, { 0, 6, 2 }, { 0, 8, 3 }, { 0, 12, 4 }, { 0, 14, 5 }, { 0, 18, 6 }, { 0, 20, 7 }, + { 0, 24, 8 }, { 0, 26, 9 }, { 0, 30, 10 }, { 0, 32, 11 }, { 0, 36, 12 }, { 0, 40, 13 }, { 0, 42, 14 }, { 0, 46, 15 }, + { 0, 48, 16 }, { 0, 52, 17 }, { 0, 54, 18 }, { 0, 58, 19 }, { 0, 60, 20 }, { 0, 64, 21 }, { 0, 66, 22 }, { 0, 70, 23 }, + { 0, 72, 24 }, { 0, 76, 25 }, { 0, 78, 26 }, { 0, 82, 27 }, { 0, 84, 28 }, { 0, 88, 29 }, { 0, 90, 30 }, { 0, 94, 31 }, + { 0, 96, 32 }, { 0, 100, 33 }, { 0, 104, 34 }, { 0, 106, 35 }, { 0, 110, 36 }, { 0, 112, 37 }, { 0, 116, 38 }, { 0, 118, 39 }, + { 0, 122, 40 }, { 0, 124, 41 }, { 0, 128, 42 }, { 0, 130, 43 }, { 0, 134, 44 }, { 0, 136, 45 }, { 0, 140, 46 }, { 0, 142, 47 }, + { 0, 146, 48 }, { 0, 148, 49 }, { 0, 152, 50 }, { 0, 154, 51 }, { 0, 158, 52 }, { 0, 160, 53 }, { 0, 164, 54 }, { 0, 168, 55 }, + { 0, 170, 56 }, { 0, 174, 57 }, { 0, 176, 58 }, { 0, 180, 59 }, { 0, 182, 60 }, { 0, 186, 61 }, { 0, 188, 62 }, { 0, 192, 63 }, + { 0, 194, 64 }, { 0, 198, 65 }, { 0, 200, 66 }, { 0, 204, 67 }, { 0, 206, 68 }, { 0, 210, 69 }, { 0, 212, 70 }, { 0, 216, 71 }, + { 0, 218, 72 }, { 0, 222, 73 }, { 0, 224, 74 }, { 0, 228, 75 }, { 0, 232, 76 }, { 0, 234, 77 }, { 0, 238, 78 }, { 0, 240, 79 }, + { 0, 244, 80 }, { 0, 246, 81 }, { 0, 250, 82 }, { 0, 252, 83 }, { 2, 252, 84 }, { 2, 254, 85 }, { 4, 254, 86 }, { 6, 252, 87 }, + { 8, 252, 88 }, { 8, 254, 89 }, { 10, 254, 90 }, { 12, 252, 91 }, { 14, 252, 92 }, { 14, 254, 93 }, { 16, 254, 94 }, { 18, 252, 95 }, + { 20, 252, 96 }, { 20, 254, 97 }, { 22, 254, 98 }, { 24, 252, 99 }, { 26, 250, 100 }, { 26, 254, 101 }, { 28, 252, 102 }, { 30, 252, 103 }, + { 30, 254, 104 }, { 32, 254, 105 }, { 34, 252, 106 }, { 36, 252, 107 }, { 36, 254, 108 }, { 38, 254, 109 }, { 40, 252, 110 }, { 42, 252, 111 }, + { 42, 254, 112 }, { 44, 254, 113 }, { 46, 252, 114 }, { 48, 252, 115 }, { 48, 254, 116 }, { 50, 254, 117 }, { 52, 252, 118 }, { 54, 252, 119 }, + { 54, 254, 120 }, { 56, 254, 121 }, { 58, 252, 122 }, { 60, 252, 123 }, { 60, 254, 124 }, { 62, 254, 125 }, { 64, 252, 126 }, { 66, 252, 127 }, + { 66, 254, 128 }, { 68, 254, 129 }, { 70, 252, 130 }, { 72, 252, 131 }, { 72, 254, 132 }, { 74, 254, 133 }, { 76, 252, 134 }, { 78, 252, 135 }, + { 78, 254, 136 }, { 80, 254, 137 }, { 82, 252, 138 }, { 84, 252, 139 }, { 84, 254, 140 }, { 86, 254, 141 }, { 88, 252, 142 }, { 90, 250, 143 }, + { 90, 254, 144 }, { 92, 252, 145 }, { 94, 252, 146 }, { 94, 254, 147 }, { 96, 254, 148 }, { 98, 252, 149 }, { 100, 252, 150 }, { 100, 254, 151 }, + { 102, 254, 152 }, { 104, 252, 153 }, { 106, 252, 154 }, { 106, 254, 155 }, { 108, 254, 156 }, { 110, 252, 157 }, { 112, 252, 158 }, { 112, 254, 159 }, + { 114, 254, 160 }, { 116, 252, 161 }, { 118, 252, 162 }, { 118, 254, 163 }, { 120, 254, 164 }, { 122, 252, 165 }, { 124, 252, 166 }, { 124, 254, 167 }, + { 126, 254, 168 }, { 128, 252, 169 }, { 130, 252, 170 }, { 130, 254, 171 }, { 132, 254, 172 }, { 134, 252, 173 }, { 136, 252, 174 }, { 136, 254, 175 }, + { 138, 254, 176 }, { 140, 252, 177 }, { 142, 252, 178 }, { 142, 254, 179 }, { 144, 254, 180 }, { 146, 252, 181 }, { 148, 252, 182 }, { 148, 254, 183 }, + { 150, 254, 184 }, { 152, 252, 185 }, { 154, 250, 186 }, { 154, 254, 187 }, { 156, 252, 188 }, { 158, 252, 189 }, { 158, 254, 190 }, { 160, 254, 191 }, + { 162, 252, 192 }, { 164, 252, 193 }, { 164, 254, 194 }, { 166, 254, 195 }, { 168, 252, 196 }, { 170, 252, 197 }, { 170, 254, 198 }, { 172, 254, 199 }, + { 174, 252, 200 }, { 176, 252, 201 }, { 176, 254, 202 }, { 178, 254, 203 }, { 180, 252, 204 }, { 182, 252, 205 }, { 182, 254, 206 }, { 184, 254, 207 }, + { 186, 252, 208 }, { 188, 252, 209 }, { 188, 254, 210 }, { 190, 254, 211 }, { 192, 252, 212 }, { 194, 252, 213 }, { 194, 254, 214 }, { 196, 254, 215 }, + { 198, 252, 216 }, { 200, 252, 217 }, { 200, 254, 218 }, { 202, 254, 219 }, { 204, 252, 220 }, { 206, 252, 221 }, { 206, 254, 222 }, { 208, 254, 223 }, + { 210, 252, 224 }, { 212, 252, 225 }, { 212, 254, 226 }, { 214, 254, 227 }, { 216, 252, 228 }, { 218, 250, 229 }, { 218, 254, 230 }, { 220, 252, 231 }, + { 222, 252, 232 }, { 222, 254, 233 }, { 224, 254, 234 }, { 226, 252, 235 }, { 228, 252, 236 }, { 228, 254, 237 }, { 230, 254, 238 }, { 232, 252, 239 }, + { 234, 252, 240 }, { 234, 254, 241 }, { 236, 254, 242 }, { 238, 252, 243 }, { 240, 252, 244 }, { 240, 254, 245 }, { 242, 254, 246 }, { 244, 252, 247 }, + { 246, 252, 248 }, { 246, 254, 249 }, { 248, 254, 250 }, { 250, 252, 251 }, { 252, 252, 252 }, { 252, 254, 253 }, { 254, 254, 254 }, { 254, 254, 254 }, + } +}; + +Table g_mode7_p01= +{ + 1, + 2, + { + { 0, 1, 0 }, { 0, 3, 1 }, { 0, 5, 2 }, { 0, 9, 3 }, { 0, 11, 4 }, { 0, 15, 5 }, { 0, 17, 6 }, { 0, 21, 7 }, + { 0, 23, 8 }, { 0, 27, 9 }, { 0, 29, 10 }, { 0, 33, 11 }, { 0, 37, 12 }, { 0, 39, 13 }, { 0, 43, 14 }, { 0, 45, 15 }, + { 0, 49, 16 }, { 0, 51, 17 }, { 0, 55, 18 }, { 0, 57, 19 }, { 0, 61, 20 }, { 0, 63, 21 }, { 0, 67, 22 }, { 0, 69, 23 }, + { 0, 73, 24 }, { 0, 75, 25 }, { 0, 79, 26 }, { 0, 81, 27 }, { 0, 85, 28 }, { 0, 87, 29 }, { 0, 91, 30 }, { 0, 93, 31 }, + { 0, 97, 32 }, { 0, 101, 33 }, { 0, 103, 34 }, { 0, 107, 35 }, { 0, 109, 36 }, { 0, 113, 37 }, { 0, 115, 38 }, { 0, 119, 39 }, + { 0, 121, 40 }, { 0, 125, 41 }, { 0, 127, 42 }, { 0, 131, 43 }, { 0, 133, 44 }, { 0, 137, 45 }, { 0, 139, 46 }, { 0, 143, 47 }, + { 0, 145, 48 }, { 0, 149, 49 }, { 0, 151, 50 }, { 0, 155, 51 }, { 0, 157, 52 }, { 0, 161, 53 }, { 0, 165, 54 }, { 0, 167, 55 }, + { 0, 171, 56 }, { 0, 173, 57 }, { 0, 177, 58 }, { 0, 179, 59 }, { 0, 183, 60 }, { 0, 185, 61 }, { 0, 189, 62 }, { 0, 191, 63 }, + { 0, 195, 64 }, { 0, 197, 65 }, { 0, 201, 66 }, { 0, 203, 67 }, { 0, 207, 68 }, { 0, 209, 69 }, { 0, 213, 70 }, { 0, 215, 71 }, + { 0, 219, 72 }, { 0, 221, 73 }, { 0, 225, 74 }, { 0, 229, 75 }, { 0, 231, 76 }, { 0, 235, 77 }, { 0, 237, 78 }, { 0, 241, 79 }, + { 0, 243, 80 }, { 0, 247, 81 }, { 0, 249, 82 }, { 0, 253, 83 }, { 0, 255, 84 }, { 2, 255, 85 }, { 4, 253, 86 }, { 6, 253, 87 }, + { 6, 255, 88 }, { 8, 255, 89 }, { 10, 253, 90 }, { 12, 253, 91 }, { 12, 255, 92 }, { 14, 255, 93 }, { 16, 253, 94 }, { 18, 253, 95 }, + { 18, 255, 96 }, { 20, 255, 97 }, { 22, 253, 98 }, { 24, 253, 99 }, { 24, 255, 100 }, { 26, 255, 101 }, { 28, 253, 102 }, { 30, 251, 103 }, + { 30, 255, 104 }, { 32, 253, 105 }, { 34, 253, 106 }, { 34, 255, 107 }, { 36, 255, 108 }, { 38, 253, 109 }, { 40, 253, 110 }, { 40, 255, 111 }, + { 42, 255, 112 }, { 44, 253, 113 }, { 46, 253, 114 }, { 46, 255, 115 }, { 48, 255, 116 }, { 50, 253, 117 }, { 52, 253, 118 }, { 52, 255, 119 }, + { 54, 255, 120 }, { 56, 253, 121 }, { 58, 253, 122 }, { 58, 255, 123 }, { 60, 255, 124 }, { 62, 253, 125 }, { 64, 253, 126 }, { 64, 255, 127 }, + { 66, 255, 128 }, { 68, 253, 129 }, { 70, 253, 130 }, { 70, 255, 131 }, { 72, 255, 132 }, { 74, 253, 133 }, { 76, 253, 134 }, { 76, 255, 135 }, + { 78, 255, 136 }, { 80, 253, 137 }, { 82, 253, 138 }, { 82, 255, 139 }, { 84, 255, 140 }, { 86, 253, 141 }, { 88, 253, 142 }, { 88, 255, 143 }, + { 90, 255, 144 }, { 92, 253, 145 }, { 94, 251, 146 }, { 94, 255, 147 }, { 96, 253, 148 }, { 98, 253, 149 }, { 98, 255, 150 }, { 100, 255, 151 }, + { 102, 253, 152 }, { 104, 253, 153 }, { 104, 255, 154 }, { 106, 255, 155 }, { 108, 253, 156 }, { 110, 253, 157 }, { 110, 255, 158 }, { 112, 255, 159 }, + { 114, 253, 160 }, { 116, 253, 161 }, { 116, 255, 162 }, { 118, 255, 163 }, { 120, 253, 164 }, { 122, 253, 165 }, { 122, 255, 166 }, { 124, 255, 167 }, + { 126, 253, 168 }, { 128, 253, 169 }, { 128, 255, 170 }, { 130, 255, 171 }, { 132, 253, 172 }, { 134, 253, 173 }, { 134, 255, 174 }, { 136, 255, 175 }, + { 138, 253, 176 }, { 140, 253, 177 }, { 140, 255, 178 }, { 142, 255, 179 }, { 144, 253, 180 }, { 146, 253, 181 }, { 146, 255, 182 }, { 148, 255, 183 }, + { 150, 253, 184 }, { 152, 253, 185 }, { 152, 255, 186 }, { 154, 255, 187 }, { 156, 253, 188 }, { 158, 251, 189 }, { 158, 255, 190 }, { 160, 253, 191 }, + { 162, 253, 192 }, { 162, 255, 193 }, { 164, 255, 194 }, { 166, 253, 195 }, { 168, 253, 196 }, { 168, 255, 197 }, { 170, 255, 198 }, { 172, 253, 199 }, + { 174, 253, 200 }, { 174, 255, 201 }, { 176, 255, 202 }, { 178, 253, 203 }, { 180, 253, 204 }, { 180, 255, 205 }, { 182, 255, 206 }, { 184, 253, 207 }, + { 186, 253, 208 }, { 186, 255, 209 }, { 188, 255, 210 }, { 190, 253, 211 }, { 192, 253, 212 }, { 192, 255, 213 }, { 194, 255, 214 }, { 196, 253, 215 }, + { 198, 253, 216 }, { 198, 255, 217 }, { 200, 255, 218 }, { 202, 253, 219 }, { 204, 253, 220 }, { 204, 255, 221 }, { 206, 255, 222 }, { 208, 253, 223 }, + { 210, 253, 224 }, { 210, 255, 225 }, { 212, 255, 226 }, { 214, 253, 227 }, { 216, 253, 228 }, { 216, 255, 229 }, { 218, 255, 230 }, { 220, 253, 231 }, + { 222, 251, 232 }, { 222, 255, 233 }, { 224, 253, 234 }, { 226, 253, 235 }, { 226, 255, 236 }, { 228, 255, 237 }, { 230, 253, 238 }, { 232, 253, 239 }, + { 232, 255, 240 }, { 234, 255, 241 }, { 236, 253, 242 }, { 238, 253, 243 }, { 238, 255, 244 }, { 240, 255, 245 }, { 242, 253, 246 }, { 244, 253, 247 }, + { 244, 255, 248 }, { 246, 255, 249 }, { 248, 253, 250 }, { 250, 253, 251 }, { 250, 255, 252 }, { 252, 255, 253 }, { 254, 253, 254 }, { 254, 253, 254 }, + } +}; + +Table g_mode7_p10= +{ + 1, + 1, + { + { 1, 0, 1 }, { 1, 0, 1 }, { 1, 4, 2 }, { 1, 6, 3 }, { 1, 10, 4 }, { 1, 12, 5 }, { 1, 16, 6 }, { 1, 18, 7 }, + { 1, 22, 8 }, { 1, 24, 9 }, { 1, 28, 10 }, { 1, 30, 11 }, { 1, 34, 12 }, { 1, 38, 13 }, { 1, 40, 14 }, { 1, 44, 15 }, + { 1, 46, 16 }, { 1, 50, 17 }, { 1, 52, 18 }, { 1, 56, 19 }, { 1, 58, 20 }, { 1, 62, 21 }, { 1, 64, 22 }, { 1, 68, 23 }, + { 1, 70, 24 }, { 1, 74, 25 }, { 1, 76, 26 }, { 1, 80, 27 }, { 1, 82, 28 }, { 1, 86, 29 }, { 1, 88, 30 }, { 1, 92, 31 }, + { 1, 94, 32 }, { 1, 98, 33 }, { 1, 102, 34 }, { 1, 104, 35 }, { 1, 108, 36 }, { 1, 110, 37 }, { 1, 114, 38 }, { 1, 116, 39 }, + { 1, 120, 40 }, { 1, 122, 41 }, { 1, 126, 42 }, { 1, 128, 43 }, { 1, 132, 44 }, { 1, 134, 45 }, { 1, 138, 46 }, { 1, 140, 47 }, + { 1, 144, 48 }, { 1, 146, 49 }, { 1, 150, 50 }, { 1, 152, 51 }, { 1, 156, 52 }, { 1, 158, 53 }, { 1, 162, 54 }, { 1, 166, 55 }, + { 1, 168, 56 }, { 1, 172, 57 }, { 1, 174, 58 }, { 1, 178, 59 }, { 1, 180, 60 }, { 1, 184, 61 }, { 1, 186, 62 }, { 1, 190, 63 }, + { 1, 192, 64 }, { 1, 196, 65 }, { 1, 198, 66 }, { 1, 202, 67 }, { 1, 204, 68 }, { 1, 208, 69 }, { 1, 210, 70 }, { 1, 214, 71 }, + { 1, 216, 72 }, { 1, 220, 73 }, { 1, 222, 74 }, { 1, 226, 75 }, { 1, 230, 76 }, { 1, 232, 77 }, { 1, 236, 78 }, { 1, 238, 79 }, + { 1, 242, 80 }, { 1, 244, 81 }, { 1, 248, 82 }, { 1, 250, 83 }, { 1, 254, 84 }, { 3, 252, 85 }, { 5, 252, 86 }, { 5, 254, 87 }, + { 7, 254, 88 }, { 9, 252, 89 }, { 11, 252, 90 }, { 11, 254, 91 }, { 13, 254, 92 }, { 15, 252, 93 }, { 17, 252, 94 }, { 17, 254, 95 }, + { 19, 254, 96 }, { 21, 252, 97 }, { 23, 252, 98 }, { 23, 254, 99 }, { 25, 254, 100 }, { 27, 252, 101 }, { 29, 250, 102 }, { 29, 254, 103 }, + { 31, 252, 104 }, { 33, 252, 105 }, { 33, 254, 106 }, { 35, 254, 107 }, { 37, 252, 108 }, { 39, 252, 109 }, { 39, 254, 110 }, { 41, 254, 111 }, + { 43, 252, 112 }, { 45, 252, 113 }, { 45, 254, 114 }, { 47, 254, 115 }, { 49, 252, 116 }, { 51, 252, 117 }, { 51, 254, 118 }, { 53, 254, 119 }, + { 55, 252, 120 }, { 57, 252, 121 }, { 57, 254, 122 }, { 59, 254, 123 }, { 61, 252, 124 }, { 63, 252, 125 }, { 63, 254, 126 }, { 65, 254, 127 }, + { 67, 252, 128 }, { 69, 252, 129 }, { 69, 254, 130 }, { 71, 254, 131 }, { 73, 252, 132 }, { 75, 252, 133 }, { 75, 254, 134 }, { 77, 254, 135 }, + { 79, 252, 136 }, { 81, 252, 137 }, { 81, 254, 138 }, { 83, 254, 139 }, { 85, 252, 140 }, { 87, 252, 141 }, { 87, 254, 142 }, { 89, 254, 143 }, + { 91, 252, 144 }, { 93, 250, 145 }, { 93, 254, 146 }, { 95, 252, 147 }, { 97, 252, 148 }, { 97, 254, 149 }, { 99, 254, 150 }, { 101, 252, 151 }, + { 103, 252, 152 }, { 103, 254, 153 }, { 105, 254, 154 }, { 107, 252, 155 }, { 109, 252, 156 }, { 109, 254, 157 }, { 111, 254, 158 }, { 113, 252, 159 }, + { 115, 252, 160 }, { 115, 254, 161 }, { 117, 254, 162 }, { 119, 252, 163 }, { 121, 252, 164 }, { 121, 254, 165 }, { 123, 254, 166 }, { 125, 252, 167 }, + { 127, 252, 168 }, { 127, 254, 169 }, { 129, 254, 170 }, { 131, 252, 171 }, { 133, 252, 172 }, { 133, 254, 173 }, { 135, 254, 174 }, { 137, 252, 175 }, + { 139, 252, 176 }, { 139, 254, 177 }, { 141, 254, 178 }, { 143, 252, 179 }, { 145, 252, 180 }, { 145, 254, 181 }, { 147, 254, 182 }, { 149, 252, 183 }, + { 151, 252, 184 }, { 151, 254, 185 }, { 153, 254, 186 }, { 155, 252, 187 }, { 157, 250, 188 }, { 157, 254, 189 }, { 159, 252, 190 }, { 161, 252, 191 }, + { 161, 254, 192 }, { 163, 254, 193 }, { 165, 252, 194 }, { 167, 252, 195 }, { 167, 254, 196 }, { 169, 254, 197 }, { 171, 252, 198 }, { 173, 252, 199 }, + { 173, 254, 200 }, { 175, 254, 201 }, { 177, 252, 202 }, { 179, 252, 203 }, { 179, 254, 204 }, { 181, 254, 205 }, { 183, 252, 206 }, { 185, 252, 207 }, + { 185, 254, 208 }, { 187, 254, 209 }, { 189, 252, 210 }, { 191, 252, 211 }, { 191, 254, 212 }, { 193, 254, 213 }, { 195, 252, 214 }, { 197, 252, 215 }, + { 197, 254, 216 }, { 199, 254, 217 }, { 201, 252, 218 }, { 203, 252, 219 }, { 203, 254, 220 }, { 205, 254, 221 }, { 207, 252, 222 }, { 209, 252, 223 }, + { 209, 254, 224 }, { 211, 254, 225 }, { 213, 252, 226 }, { 215, 252, 227 }, { 215, 254, 228 }, { 217, 254, 229 }, { 219, 252, 230 }, { 221, 250, 231 }, + { 221, 254, 232 }, { 223, 252, 233 }, { 225, 252, 234 }, { 225, 254, 235 }, { 227, 254, 236 }, { 229, 252, 237 }, { 231, 252, 238 }, { 231, 254, 239 }, + { 233, 254, 240 }, { 235, 252, 241 }, { 237, 252, 242 }, { 237, 254, 243 }, { 239, 254, 244 }, { 241, 252, 245 }, { 243, 252, 246 }, { 243, 254, 247 }, + { 245, 254, 248 }, { 247, 252, 249 }, { 249, 252, 250 }, { 249, 254, 251 }, { 251, 254, 252 }, { 253, 252, 253 }, { 255, 252, 254 }, { 255, 254, 255 }, + } +}; + +Table g_mode7_p11= +{ + 1, + 3, + { + { 1, 1, 1 }, { 1, 1, 1 }, { 1, 3, 2 }, { 1, 7, 3 }, { 1, 9, 4 }, { 1, 13, 5 }, { 1, 15, 6 }, { 1, 19, 7 }, + { 1, 21, 8 }, { 1, 25, 9 }, { 1, 27, 10 }, { 1, 31, 11 }, { 1, 33, 12 }, { 1, 37, 13 }, { 1, 41, 14 }, { 1, 43, 15 }, + { 1, 47, 16 }, { 1, 49, 17 }, { 1, 53, 18 }, { 1, 55, 19 }, { 1, 59, 20 }, { 1, 61, 21 }, { 1, 65, 22 }, { 1, 67, 23 }, + { 1, 71, 24 }, { 1, 73, 25 }, { 1, 77, 26 }, { 1, 79, 27 }, { 1, 83, 28 }, { 1, 85, 29 }, { 1, 89, 30 }, { 1, 91, 31 }, + { 1, 95, 32 }, { 1, 97, 33 }, { 1, 101, 34 }, { 1, 105, 35 }, { 1, 107, 36 }, { 1, 111, 37 }, { 1, 113, 38 }, { 1, 117, 39 }, + { 1, 119, 40 }, { 1, 123, 41 }, { 1, 125, 42 }, { 1, 129, 43 }, { 1, 131, 44 }, { 1, 135, 45 }, { 1, 137, 46 }, { 1, 141, 47 }, + { 1, 143, 48 }, { 1, 147, 49 }, { 1, 149, 50 }, { 1, 153, 51 }, { 1, 155, 52 }, { 1, 159, 53 }, { 1, 161, 54 }, { 1, 165, 55 }, + { 1, 169, 56 }, { 1, 171, 57 }, { 1, 175, 58 }, { 1, 177, 59 }, { 1, 181, 60 }, { 1, 183, 61 }, { 1, 187, 62 }, { 1, 189, 63 }, + { 1, 193, 64 }, { 1, 195, 65 }, { 1, 199, 66 }, { 1, 201, 67 }, { 1, 205, 68 }, { 1, 207, 69 }, { 1, 211, 70 }, { 1, 213, 71 }, + { 1, 217, 72 }, { 1, 219, 73 }, { 1, 223, 74 }, { 1, 225, 75 }, { 1, 229, 76 }, { 1, 233, 77 }, { 1, 235, 78 }, { 1, 239, 79 }, + { 1, 241, 80 }, { 1, 245, 81 }, { 1, 247, 82 }, { 1, 251, 83 }, { 1, 253, 84 }, { 3, 253, 85 }, { 3, 255, 86 }, { 5, 255, 87 }, + { 7, 253, 88 }, { 9, 253, 89 }, { 9, 255, 90 }, { 11, 255, 91 }, { 13, 253, 92 }, { 15, 253, 93 }, { 15, 255, 94 }, { 17, 255, 95 }, + { 19, 253, 96 }, { 21, 253, 97 }, { 21, 255, 98 }, { 23, 255, 99 }, { 25, 253, 100 }, { 27, 251, 101 }, { 27, 255, 102 }, { 29, 253, 103 }, + { 31, 253, 104 }, { 31, 255, 105 }, { 33, 255, 106 }, { 35, 253, 107 }, { 37, 253, 108 }, { 37, 255, 109 }, { 39, 255, 110 }, { 41, 253, 111 }, + { 43, 253, 112 }, { 43, 255, 113 }, { 45, 255, 114 }, { 47, 253, 115 }, { 49, 253, 116 }, { 49, 255, 117 }, { 51, 255, 118 }, { 53, 253, 119 }, + { 55, 253, 120 }, { 55, 255, 121 }, { 57, 255, 122 }, { 59, 253, 123 }, { 61, 253, 124 }, { 61, 255, 125 }, { 63, 255, 126 }, { 65, 253, 127 }, + { 67, 253, 128 }, { 67, 255, 129 }, { 69, 255, 130 }, { 71, 253, 131 }, { 73, 253, 132 }, { 73, 255, 133 }, { 75, 255, 134 }, { 77, 253, 135 }, + { 79, 253, 136 }, { 79, 255, 137 }, { 81, 255, 138 }, { 83, 253, 139 }, { 85, 253, 140 }, { 85, 255, 141 }, { 87, 255, 142 }, { 89, 253, 143 }, + { 91, 251, 144 }, { 91, 255, 145 }, { 93, 253, 146 }, { 95, 253, 147 }, { 95, 255, 148 }, { 97, 255, 149 }, { 99, 253, 150 }, { 101, 253, 151 }, + { 101, 255, 152 }, { 103, 255, 153 }, { 105, 253, 154 }, { 107, 253, 155 }, { 107, 255, 156 }, { 109, 255, 157 }, { 111, 253, 158 }, { 113, 253, 159 }, + { 113, 255, 160 }, { 115, 255, 161 }, { 117, 253, 162 }, { 119, 253, 163 }, { 119, 255, 164 }, { 121, 255, 165 }, { 123, 253, 166 }, { 125, 253, 167 }, + { 125, 255, 168 }, { 127, 255, 169 }, { 129, 253, 170 }, { 131, 253, 171 }, { 131, 255, 172 }, { 133, 255, 173 }, { 135, 253, 174 }, { 137, 253, 175 }, + { 137, 255, 176 }, { 139, 255, 177 }, { 141, 253, 178 }, { 143, 253, 179 }, { 143, 255, 180 }, { 145, 255, 181 }, { 147, 253, 182 }, { 149, 253, 183 }, + { 149, 255, 184 }, { 151, 255, 185 }, { 153, 253, 186 }, { 155, 251, 187 }, { 155, 255, 188 }, { 157, 253, 189 }, { 159, 253, 190 }, { 159, 255, 191 }, + { 161, 255, 192 }, { 163, 253, 193 }, { 165, 253, 194 }, { 165, 255, 195 }, { 167, 255, 196 }, { 169, 253, 197 }, { 171, 253, 198 }, { 171, 255, 199 }, + { 173, 255, 200 }, { 175, 253, 201 }, { 177, 253, 202 }, { 177, 255, 203 }, { 179, 255, 204 }, { 181, 253, 205 }, { 183, 253, 206 }, { 183, 255, 207 }, + { 185, 255, 208 }, { 187, 253, 209 }, { 189, 253, 210 }, { 189, 255, 211 }, { 191, 255, 212 }, { 193, 253, 213 }, { 195, 253, 214 }, { 195, 255, 215 }, + { 197, 255, 216 }, { 199, 253, 217 }, { 201, 253, 218 }, { 201, 255, 219 }, { 203, 255, 220 }, { 205, 253, 221 }, { 207, 253, 222 }, { 207, 255, 223 }, + { 209, 255, 224 }, { 211, 253, 225 }, { 213, 253, 226 }, { 213, 255, 227 }, { 215, 255, 228 }, { 217, 253, 229 }, { 219, 251, 230 }, { 219, 255, 231 }, + { 221, 253, 232 }, { 223, 253, 233 }, { 223, 255, 234 }, { 225, 255, 235 }, { 227, 253, 236 }, { 229, 253, 237 }, { 229, 255, 238 }, { 231, 255, 239 }, + { 233, 253, 240 }, { 235, 253, 241 }, { 235, 255, 242 }, { 237, 255, 243 }, { 239, 253, 244 }, { 241, 253, 245 }, { 241, 255, 246 }, { 243, 255, 247 }, + { 245, 253, 248 }, { 247, 253, 249 }, { 247, 255, 250 }, { 249, 255, 251 }, { 251, 253, 252 }, { 253, 253, 253 }, { 253, 255, 254 }, { 255, 255, 255 }, + } +}; + +}}} diff --git a/thirdparty/cvtt/LICENSE.txt b/thirdparty/cvtt/LICENSE.txt new file mode 100644 index 0000000000..6964f6e43f --- /dev/null +++ b/thirdparty/cvtt/LICENSE.txt @@ -0,0 +1,45 @@ +Convection Texture Tools Stand-Alone Kernels
+
+Copyright (c) 2018 Eric Lasota
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject
+to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************
+
+Based on DirectX Texture Library
+
+Copyright (c) 2018 Microsoft Corp
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this
+software and associated documentation files (the "Software"), to deal in the Software
+without restriction, including without limitation the rights to use, copy, modify,
+merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be included in all copies
+or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file diff --git a/thirdparty/squish/config.h b/thirdparty/squish/config.h index 92edefe966..05f8d72598 100644 --- a/thirdparty/squish/config.h +++ b/thirdparty/squish/config.h @@ -32,6 +32,26 @@ #endif // Set to 1 or 2 when building squish to use SSE or SSE2 instructions. +// -- GODOT start -- +#ifdef _MSC_VER + #if defined(_M_IX86_FP) + #if _M_IX86_FP >= 2 + #define SQUISH_USE_SSE 2 + #elif _M_IX86_FP >= 1 + #define SQUISH_USE_SSE 1 + #endif + #elif defined(_M_X64) + #define SQUISH_USE_SSE 2 + #endif +#else + #if defined(__SSE2__) + #define SQUISH_USE_SSE 2 + #elif defined(__SSE__) + #define SQUISH_USE_SSE 1 + #endif +#endif +// -- GODOT end -- + #ifndef SQUISH_USE_SSE #define SQUISH_USE_SSE 0 #endif |