From f0b7627b7d88c1d5bb484961377114b210c8dd53 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 13 Jul 2014 12:20:19 +0300 Subject: Fix code style. --- src/resources/beinginfo.cpp | 2 +- src/resources/db/palettedb.cpp | 9 ++++---- src/resources/dye.cpp | 48 +++++++++++++++++++++++------------------- src/resources/dyepalette.cpp | 32 +++++++++++++++++----------- src/resources/fboinfo.h | 2 -- src/resources/imagewriter.cpp | 2 +- src/resources/iteminfo.cpp | 2 +- 7 files changed, 54 insertions(+), 43 deletions(-) (limited to 'src/resources') diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 757de8238..e3cf9bb91 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -154,7 +154,7 @@ const SoundInfo &BeingInfo::getSound(const ItemSoundEvent::Type event) const if (!vect || vect->empty()) return emptySound; else - return vect->at(rand() % vect->size()); + return vect->at(static_cast(rand()) % vect->size()); } const Attack *BeingInfo::getAttack(const int id) const diff --git a/src/resources/db/palettedb.cpp b/src/resources/db/palettedb.cpp index 8ec238336..08c8ec85d 100644 --- a/src/resources/db/palettedb.cpp +++ b/src/resources/db/palettedb.cpp @@ -82,13 +82,14 @@ void PaletteDB::loadPalette() if (line.empty() || line[0] == '#') continue; - unsigned int r; - unsigned int g; - unsigned int b; + unsigned char r; + unsigned char g; + unsigned char b; - if (sscanf(line.c_str(), "%10u %10u %10u\t%100s", + if (sscanf(line.c_str(), "%10hhu %10hhu %10hhu\t%100s", &r, &g, &b, name) == 4) { + name[100] = 0; mColors[name] = DyeColor(r, g, b); } } diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index ea66b2b6b..3b83780c5 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -162,23 +162,25 @@ void Dye::normalDye(uint32_t *restrict pixels, const int bufSize) const #endif if (!alpha) continue; - int color[3]; + unsigned int color[3]; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - color[0] = (p) & 255; - color[1] = (p >> 8) & 255; - color[2] = (p >> 16) & 255; + color[0] = (p) & 255U; + color[1] = (p >> 8U) & 255U; + color[2] = (p >> 16U) & 255U; #else - color[0] = (p >> 24) & 255; - color[1] = (p >> 16) & 255; - color[2] = (p >> 8) & 255; + color[0] = (p >> 24U) & 255U; + color[1] = (p >> 16U) & 255U; + color[2] = (p >> 8U) & 255U; #endif - const int cmax = std::max(color[0], std::max(color[1], color[2])); + const unsigned int cmax = std::max( + color[0], std::max(color[1], color[2])); if (cmax == 0) continue; - const int cmin = std::min(color[0], std::min(color[1], color[2])); - const int intensity = color[0] + color[1] + color[2]; + const unsigned int cmin = std::min( + color[0], std::min(color[1], color[2])); + const unsigned int intensity = color[0] + color[1] + color[2]; if (cmin != cmax && (cmin != 0 || (intensity != cmax && intensity != 2 * cmax))) @@ -187,7 +189,7 @@ void Dye::normalDye(uint32_t *restrict pixels, const int bufSize) const continue; } - const int i = (color[0] != 0) | ((color[1] != 0) << 1) + const unsigned int i = (color[0] != 0) | ((color[1] != 0) << 1) | ((color[2] != 0) << 2); if (mDyePalettes[i - 1]) @@ -217,23 +219,25 @@ void Dye::normalOGLDye(uint32_t *restrict pixels, const int bufSize) const #endif if (!alpha) continue; - int color[3]; + unsigned int color[3]; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - color[0] = (p >> 24) & 255; - color[1] = (p >> 16) & 255; - color[2] = (p >> 8) & 255; + color[0] = (p >> 24U) & 255U; + color[1] = (p >> 16U) & 255U; + color[2] = (p >> 8U) & 255U; #else - color[0] = (p) & 255; - color[1] = (p >> 8) & 255; - color[2] = (p >> 16) & 255; + color[0] = (p) & 255U; + color[1] = (p >> 8U) & 255U; + color[2] = (p >> 16U) & 255U; #endif - const int cmax = std::max(color[0], std::max(color[1], color[2])); + const unsigned int cmax = std::max( + color[0], std::max(color[1], color[2])); if (cmax == 0) continue; - const int cmin = std::min(color[0], std::min(color[1], color[2])); - const int intensity = color[0] + color[1] + color[2]; + const unsigned int cmin = std::min( + color[0], std::min(color[1], color[2])); + const unsigned int intensity = color[0] + color[1] + color[2]; if (cmin != cmax && (cmin != 0 || (intensity != cmax && intensity != 2 * cmax))) @@ -242,7 +246,7 @@ void Dye::normalOGLDye(uint32_t *restrict pixels, const int bufSize) const continue; } - const int i = (color[0] != 0) | ((color[1] != 0) << 1) + const unsigned int i = (color[0] != 0) | ((color[1] != 0) << 1) | ((color[2] != 0) << 2); if (mDyePalettes[i - 1]) diff --git a/src/resources/dyepalette.cpp b/src/resources/dyepalette.cpp index f20af9086..4c62abd1c 100644 --- a/src/resources/dyepalette.cpp +++ b/src/resources/dyepalette.cpp @@ -234,11 +234,11 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels, const DyeColor &col2 = *it; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[2] << 16) - | (col.value[1] << 8) | (col.value[0]); + const unsigned int coldata = (col.value[2] << 16U) + | (col.value[1] << 8U) | (col.value[0]); #else - const unsigned int coldata = (col.value[2] << 8) - | (col.value[1] << 16) | (col.value[0] << 24); + const unsigned int coldata = (col.value[2] << 8U) + | (col.value[1] << 16U) | (col.value[0] << 24U); #endif // logger->log("coldata: %08x", coldata); if (data == coldata) @@ -280,11 +280,15 @@ void DyePalette::replaceAColor(uint32_t *restrict pixels, const DyeColor &col2 = *it; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[3] << 24) - | (col.value[2] << 16) | (col.value[1] << 8) | (col.value[0]); + const unsigned int coldata = (col.value[3] << 24U) + | (col.value[2] << 16U) + | (col.value[1] << 8U) + | (col.value[0]); #else - const unsigned int coldata = (col.value[3]) | (col.value[2] << 8) - | (col.value[1] << 16) | (col.value[0] << 24); + const unsigned int coldata = (col.value[3]) + | (col.value[2] << 8U) + | (col.value[1] << 16U) | + (col.value[0] << 24U); #endif if (data == coldata) @@ -378,11 +382,15 @@ void DyePalette::replaceAOGLColor(uint32_t *restrict pixels, const DyeColor &col2 = *it; #if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24) - | (col.value[1] << 16) | (col.value[2] << 8) | col.value[3]; + const unsigned int coldata = (col.value[0] << 24U) + | (col.value[1] << 16U) + | (col.value[2] << 8U) + | col.value[3]; #else - const unsigned int coldata = (col.value[0]) | (col.value[1] << 8) - | (col.value[2] << 16) | (col.value[3] << 24); + const unsigned int coldata = (col.value[0]) + | (col.value[1] << 8U) + | (col.value[2] << 16U) + | (col.value[3] << 24U); #endif if (data == coldata) { diff --git a/src/resources/fboinfo.h b/src/resources/fboinfo.h index 9ba4efd43..6d723ca6a 100644 --- a/src/resources/fboinfo.h +++ b/src/resources/fboinfo.h @@ -26,8 +26,6 @@ #include "render/graphics.h" -#include "resources/fboinfo.h" - #ifdef ANDROID #include #include diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index 9ff87c758..1f71d97a3 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -24,7 +24,7 @@ #include "logger.h" -#include +#include #include #include #include diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 8e1284fad..55ca5f44d 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -152,7 +152,7 @@ const SoundInfo &ItemInfo::getSound(const ItemSoundEvent::Type event) const if (i == mSounds.end()) return empty; - return (!i->second.empty()) ? i->second[rand() + return (!i->second.empty()) ? i->second[static_cast(rand()) % i->second.size()] : empty; } -- cgit v1.2.3-70-g09d2