From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- modules/pvr/register_types.cpp | 2 -- modules/pvr/texture_loader_pvr.cpp | 20 -------------------- 2 files changed, 22 deletions(-) (limited to 'modules/pvr') diff --git a/modules/pvr/register_types.cpp b/modules/pvr/register_types.cpp index 5f900a0256..1eb697bba3 100644 --- a/modules/pvr/register_types.cpp +++ b/modules/pvr/register_types.cpp @@ -35,13 +35,11 @@ static Ref resource_loader_pvr; void register_pvr_types() { - resource_loader_pvr.instance(); ResourceLoader::add_resource_format_loader(resource_loader_pvr); } void unregister_pvr_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_pvr); resource_loader_pvr.unref(); } diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index d498c6d858..6e5cc04f6d 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -52,7 +52,6 @@ enum PVRFLags { }; RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) *r_error = ERR_CANT_OPEN; @@ -109,7 +108,6 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Image::Format format = Image::FORMAT_MAX; switch (flags & 0xFF) { - case 0x18: case 0xC: format = (flags & PVR_HAS_ALPHA) ? Image::FORMAT_PVRTC2A : Image::FORMAT_PVRTC2; @@ -169,22 +167,18 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, } void ResourceFormatPVR::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("pvr"); } bool ResourceFormatPVR::handles_type(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "Texture2D"); } String ResourceFormatPVR::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "pvr") return "Texture2D"; return ""; } static void _compress_pvrtc4(Image *p_img) { - Ref img = p_img->duplicate(); bool make_mipmaps = false; @@ -208,7 +202,6 @@ static void _compress_pvrtc4(Image *p_img) { const uint8_t *r = img->get_data().ptr(); for (int i = 0; i <= new_img->get_mipmap_count(); i++) { - int ofs, size, w, h; img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); Javelin::RgbaBitmap bm(w, h); @@ -226,7 +219,6 @@ static void _compress_pvrtc4(Image *p_img) { } ResourceFormatPVR::ResourceFormatPVR() { - Image::_image_decompress_pvrtc = _pvrtc_decompress; Image::_image_compress_pvrtc4_func = _compress_pvrtc4; Image::_image_compress_pvrtc2_func = _compress_pvrtc4; @@ -259,7 +251,6 @@ struct PVRTCBlock { }; _FORCE_INLINE_ bool is_po2(uint32_t p_input) { - if (p_input == 0) return false; uint32_t minus1 = p_input - 1; @@ -267,15 +258,12 @@ _FORCE_INLINE_ bool is_po2(uint32_t p_input) { } static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { - uint32_t raw_bits[2]; raw_bits[0] = p_block->data[1] & (0xFFFE); raw_bits[1] = p_block->data[1] >> 16; for (int i = 0; i < 2; i++) { - if (raw_bits[i] & (1 << 15)) { - p_ab_colors[i][0] = (raw_bits[i] >> 10) & 0x1F; p_ab_colors[i][1] = (raw_bits[i] >> 5) & 0x1F; p_ab_colors[i][2] = raw_bits[i] & 0x1F; @@ -283,7 +271,6 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4; p_ab_colors[i][3] = 0xF; } else { - p_ab_colors[i][0] = (raw_bits[i] >> (8 - 1)) & 0x1E; p_ab_colors[i][1] = (raw_bits[i] >> (4 - 1)) & 0x1E; @@ -303,15 +290,12 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { } static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int p_modulation[8][16], int p_modulation_modes[8][16], int p_x, int p_y) { - int block_mod_mode = p_block->data[1] & 1; uint32_t modulation_bits = p_block->data[0]; if (p_2bit && block_mod_mode) { - for (int y = 0; y < BLK_Y_SIZE; y++) { for (int x = 0; x < BLK_X_2BPP; x++) { - p_modulation_modes[y + p_y][x + p_x] = block_mod_mode; if (((x ^ y) & 1) == 0) { @@ -322,7 +306,6 @@ static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int } } else if (p_2bit) { - for (int y = 0; y < BLK_Y_SIZE; y++) { for (int x = 0; x < BLK_X_2BPP; x++) { p_modulation_modes[y + p_y][x + p_x] = block_mod_mode; @@ -463,7 +446,6 @@ static void get_modulation_value(int x, int y, const int p_2bit, const int p_mod static int disable_twiddling = 0; static uint32_t twiddle_uv(uint32_t p_height, uint32_t p_width, uint32_t p_y, uint32_t p_x) { - uint32_t twiddled; uint32_t min_dimension; @@ -559,7 +541,6 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int for (y = 0; y < p_height; y++) { for (x = 0; x < p_width; x++) { - block_x = (x - x_block_size / 2); blk_y = (y - BLK_Y_SIZE / 2); @@ -637,7 +618,6 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int } static void _pvrtc_decompress(Image *p_img) { - ERR_FAIL_COND(p_img->get_format() != Image::FORMAT_PVRTC2 && p_img->get_format() != Image::FORMAT_PVRTC2A && p_img->get_format() != Image::FORMAT_PVRTC4 && p_img->get_format() != Image::FORMAT_PVRTC4A); bool _2bit = (p_img->get_format() == Image::FORMAT_PVRTC2 || p_img->get_format() == Image::FORMAT_PVRTC2A); -- cgit v1.2.3 From 07bc4e2f96f8f47991339654ff4ab16acc19d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 14:29:06 +0200 Subject: Style: Enforce separation line between function definitions I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027. --- modules/pvr/texture_loader_pvr.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/pvr') diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 6e5cc04f6d..20f46e1f7a 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -169,9 +169,11 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, void ResourceFormatPVR::get_recognized_extensions(List *p_extensions) const { p_extensions->push_back("pvr"); } + bool ResourceFormatPVR::handles_type(const String &p_type) const { return ClassDB::is_parent_class(p_type, "Texture2D"); } + String ResourceFormatPVR::get_resource_type(const String &p_path) const { if (p_path.get_extension().to_lower() == "pvr") return "Texture2D"; -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- modules/pvr/texture_loader_pvr.cpp | 62 ++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'modules/pvr') diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 20f46e1f7a..36c0913f62 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -52,20 +52,23 @@ enum PVRFLags { }; RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_CANT_OPEN; + } Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (!f) + if (!f) { return RES(); + } FileAccessRef faref(f); ERR_FAIL_COND_V(err, RES()); - if (r_error) + if (r_error) { *r_error = ERR_FILE_CORRUPT; + } uint32_t hsize = f->get_32(); @@ -160,8 +163,9 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Ref texture = memnew(ImageTexture); texture->create_from_image(image); - if (r_error) + if (r_error) { *r_error = OK; + } return texture; } @@ -175,8 +179,9 @@ bool ResourceFormatPVR::handles_type(const String &p_type) const { } String ResourceFormatPVR::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "pvr") + if (p_path.get_extension().to_lower() == "pvr") { return "Texture2D"; + } return ""; } @@ -189,8 +194,9 @@ static void _compress_pvrtc4(Image *p_img) { img->resize_to_po2(true); } img->convert(Image::FORMAT_RGBA8); - if (!img->has_mipmaps() && make_mipmaps) + if (!img->has_mipmaps() && make_mipmaps) { img->generate_mipmaps(); + } bool use_alpha = img->detect_alpha(); @@ -253,8 +259,9 @@ struct PVRTCBlock { }; _FORCE_INLINE_ bool is_po2(uint32_t p_input) { - if (p_input == 0) + if (p_input == 0) { return false; + } uint32_t minus1 = p_input - 1; return ((p_input | minus1) == (p_input ^ minus1)) ? true : false; } @@ -269,8 +276,9 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { p_ab_colors[i][0] = (raw_bits[i] >> 10) & 0x1F; p_ab_colors[i][1] = (raw_bits[i] >> 5) & 0x1F; p_ab_colors[i][2] = raw_bits[i] & 0x1F; - if (i == 0) + if (i == 0) { p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4; + } p_ab_colors[i][3] = 0xF; } else { p_ab_colors[i][0] = (raw_bits[i] >> (8 - 1)) & 0x1E; @@ -281,10 +289,11 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { p_ab_colors[i][2] = (raw_bits[i] & 0xF) << 1; - if (i == 0) + if (i == 0) { p_ab_colors[0][2] |= p_ab_colors[0][2] >> 3; - else + } else { p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4; + } p_ab_colors[i][3] = (raw_bits[i] >> 11) & 0xE; } @@ -312,10 +321,11 @@ static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int for (int x = 0; x < BLK_X_2BPP; x++) { p_modulation_modes[y + p_y][x + p_x] = block_mod_mode; - if (modulation_bits & 1) + if (modulation_bits & 1) { p_modulation[y + p_y][x + p_x] = 0x3; - else + } else { p_modulation[y + p_y][x + p_x] = 0x0; + } modulation_bits >>= 1; } @@ -350,10 +360,11 @@ static void interpolate_colors(const int p_colorp[4], const int p_colorq[4], con v = (y & 0x3) | ((~y & 0x2) << 1); - if (p_2bit) + if (p_2bit) { u = (x & 0x7) | ((~x & 0x4) << 1); - else + } else { u = (x & 0x3) | ((~x & 0x2) << 1); + } v = v - BLK_Y_SIZE / 2; @@ -409,19 +420,20 @@ static void get_modulation_value(int x, int y, const int p_2bit, const int p_mod y = (y & 0x3) | ((~y & 0x2) << 1); - if (p_2bit) + if (p_2bit) { x = (x & 0x7) | ((~x & 0x4) << 1); - else + } else { x = (x & 0x3) | ((~x & 0x2) << 1); + } *p_dopt = 0; if (p_modulation_modes[y][x] == 0) { mod_val = rep_vals0[p_modulation[y][x]]; } else if (p_2bit) { - if (((x ^ y) & 1) == 0) + if (((x ^ y) & 1) == 0) { mod_val = rep_vals0[p_modulation[y][x]]; - else if (p_modulation_modes[y][x] == 1) { + } else if (p_modulation_modes[y][x] == 1) { mod_val = (rep_vals0[p_modulation[y - 1][x]] + rep_vals0[p_modulation[y + 1][x]] + rep_vals0[p_modulation[y][x - 1]] + @@ -472,8 +484,9 @@ static uint32_t twiddle_uv(uint32_t p_height, uint32_t p_width, uint32_t p_y, ui max_value = p_y; } - if (disable_twiddling) + if (disable_twiddling) { return (p_y * p_width + p_x); + } scr_bit_pos = 1; dst_bit_pos = 1; @@ -533,10 +546,11 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int int r_result[4]; - if (p_2bit) + if (p_2bit) { x_block_size = BLK_X_2BPP; - else + } else { x_block_size = BLK_X_4BPP; + } block_width = MAX(2, p_width / x_block_size); block_height = MAX(2, p_height / BLK_Y_SIZE); @@ -607,8 +621,9 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int r_result[i] >>= 3; } - if (DoPT) + if (DoPT) { r_result[3] = 0; + } u_pos = (x + y * p_width) << 2; p_dst[u_pos + 0] = (uint8_t)r_result[0]; @@ -635,6 +650,7 @@ static void _pvrtc_decompress(Image *p_img) { bool make_mipmaps = p_img->has_mipmaps(); p_img->create(p_img->get_width(), p_img->get_height(), false, Image::FORMAT_RGBA8, newdata); - if (make_mipmaps) + if (make_mipmaps) { p_img->generate_mipmaps(); + } } -- cgit v1.2.3