From aebc890f9c6c4cc10d283b1f7188d5ed842fc455 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 15:57:10 +0100 Subject: [PATCH 01/13] Fixed: Define RZ_USE_CUSTOM_PATCH_SERVER for ryzom_client_patcher --HG-- branch : develop --- code/ryzom/tools/client/client_patcher/CMakeLists.txt | 3 +++ code/ryzom/tools/client/client_patcher/main.cpp | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/code/ryzom/tools/client/client_patcher/CMakeLists.txt b/code/ryzom/tools/client/client_patcher/CMakeLists.txt index 47178d456..ce7d4d67a 100644 --- a/code/ryzom/tools/client/client_patcher/CMakeLists.txt +++ b/code/ryzom/tools/client/client_patcher/CMakeLists.txt @@ -8,6 +8,9 @@ FILE(GLOB SRC main.cpp ${CMAKE_SOURCE_DIR}/ryzom/client/src/stdpch.h ) +# always enable custom patch server +ADD_DEFINITIONS(-DRZ_USE_CUSTOM_PATCH_SERVER) + ADD_EXECUTABLE(ryzom_client_patcher ${SRC}) INCLUDE_DIRECTORIES( diff --git a/code/ryzom/tools/client/client_patcher/main.cpp b/code/ryzom/tools/client/client_patcher/main.cpp index 1ee6c8c5e..a0730b19f 100644 --- a/code/ryzom/tools/client/client_patcher/main.cpp +++ b/code/ryzom/tools/client/client_patcher/main.cpp @@ -397,4 +397,3 @@ int main(int argc, char *argv[]) return 0; } - From 149adc351a678d02218dceb02938ccfb9b7a4b85 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 15:58:31 +0100 Subject: [PATCH 02/13] Fixed: Path when UnpackTo doesn't have a trailing / --HG-- branch : develop --- code/ryzom/client/src/login_patch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/client/src/login_patch.cpp b/code/ryzom/client/src/login_patch.cpp index d9dfa487e..6bfb7bf1e 100644 --- a/code/ryzom/client/src/login_patch.cpp +++ b/code/ryzom/client/src/login_patch.cpp @@ -843,7 +843,7 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool for (uint32 fff = 0; fff < vFilenames.size (); fff++) { string SrcPath = ClientPatchPath; - string DstPath = rCat.getUnpackTo(); + string DstPath = CPath::standardizePath(rCat.getUnpackTo()); // to be sure there is a / at the end NLMISC::CFile::createDirectoryTree(DstPath); // this file must be moved From 39843099454ba0ce9008bd2181d2d84ebe61beae Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 15:59:32 +0100 Subject: [PATCH 03/13] Changed: Useless code because all clients will be able to patch themselve --HG-- branch : develop --- code/ryzom/client/src/login_patch.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/code/ryzom/client/src/login_patch.cpp b/code/ryzom/client/src/login_patch.cpp index 6bfb7bf1e..c12bf9206 100644 --- a/code/ryzom/client/src/login_patch.cpp +++ b/code/ryzom/client/src/login_patch.cpp @@ -2400,19 +2400,6 @@ void CCheckThread::run () fromString(sServerVersion, nServerVersion); fromString(sClientVersion, nClientVersion); -#ifdef NL_OS_UNIX - string sClientNewVersion = ClientCfg.BuildName; - - sint32 nClientNewVersion; - fromString(sClientNewVersion, nClientNewVersion); - - // servers files are not compatible with current client, use last client version - if (nClientNewVersion && nServerVersion > nClientNewVersion) - { - nServerVersion = nClientNewVersion; - } -#endif - if (nClientVersion != nServerVersion) { // first, try in the version subdirectory From 2ed7c0be8810ea1024e754f936c708c57156a04c Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:00:17 +0100 Subject: [PATCH 04/13] Changed: Added isGray() method to CGRBA --HG-- branch : develop --- code/nel/include/nel/misc/rgba.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/code/nel/include/nel/misc/rgba.h b/code/nel/include/nel/misc/rgba.h index db9ed892a..7929b4545 100644 --- a/code/nel/include/nel/misc/rgba.h +++ b/code/nel/include/nel/misc/rgba.h @@ -146,6 +146,14 @@ public: */ uint8 toGray() const; + /** + * Color is gray + */ + bool isGray() const + { + return R == G && G == B; + } + /** * Get a 16 bits 565 pixel. */ From 27a2263bd6f07f903c713a30bf256c8f3e80846f Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:01:03 +0100 Subject: [PATCH 05/13] Changed: Added set8888() method to CGRBA --HG-- branch : develop --- code/nel/include/nel/misc/rgba.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/code/nel/include/nel/misc/rgba.h b/code/nel/include/nel/misc/rgba.h index 7929b4545..e4fc6b61e 100644 --- a/code/nel/include/nel/misc/rgba.h +++ b/code/nel/include/nel/misc/rgba.h @@ -177,6 +177,17 @@ public: B= (B<<3) + (B>>2); } + /** + * Set the RGBA fields with a 32 bits 8888 pixel. + */ + void set8888(uint32 col) + { + R = col & 255; + G = (col >> 8) & 255; + B = (col >> 16) & 255; + A = (col >> 24) & 255; + } + /** * Compute in this the average of 2 RGBA. From 437aa5b939f4dc2565c33d9d0a28ea07a83eeb70 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:02:54 +0100 Subject: [PATCH 06/13] Changed: Added helpers methods to CBitmap --HG-- branch : develop --- code/nel/include/nel/misc/bitmap.h | 21 ++++ code/nel/src/misc/bitmap.cpp | 149 +++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) diff --git a/code/nel/include/nel/misc/bitmap.h b/code/nel/include/nel/misc/bitmap.h index 408b2fd27..e572c8de0 100644 --- a/code/nel/include/nel/misc/bitmap.h +++ b/code/nel/include/nel/misc/bitmap.h @@ -348,6 +348,27 @@ public: */ void makeNonPowerOf2Dummy(); + + /** + * Make a bitmap fully opaque (set alpha to 255). + */ + void makeOpaque(); + + + /** + * Return if the bitmap has uniform alpha values for all pixels. + * \param alpha return the uniform value if return is true + * \return uniform or not + */ + bool isAlphaUniform(uint8 *alpha = NULL) const; + + + /** + * Return if the bitmap is a real grayscale. + * \return grayscale or not + */ + bool isGrayscale() const; + /** * Return the pixels buffer of the image, or of one of its mipmap. * Return a reference of an array in pixel format get with getPixelFormat(). diff --git a/code/nel/src/misc/bitmap.cpp b/code/nel/src/misc/bitmap.cpp index 30c708929..ca2a14435 100644 --- a/code/nel/src/misc/bitmap.cpp +++ b/code/nel/src/misc/bitmap.cpp @@ -309,6 +309,155 @@ void CBitmap::makeDummyFromBitField(const uint8 bitmap[1024]) } } +/*-------------------------------------------------------------------*\ + makeOpaque +\*-------------------------------------------------------------------*/ +void CBitmap::makeOpaque() +{ + if (_Width*_Height == 0) return; + + uint pixelSize; + + switch(PixelFormat) + { + case RGBA: pixelSize = 4; break; + case AlphaLuminance: pixelSize = 2; break; + case Alpha: pixelSize = 1; break; + default: return; + } + + for(uint8 m = 0; m < _MipMapCount; ++m) + { + // get a pointer on original data + uint8 *data = _Data[m].getPtr(); + + // special case for only alpha values + if (pixelSize == 1) + { + memset(data, 255, _Data[m].size()); + } + else + { + // end of data + uint8 *endData = data + _Data[m].size(); + + // first alpha + data += pixelSize - 1; + + // replace all alpha values by 255 + while(data < endData) + { + *data = 255; + data += pixelSize; + } + } + } +} + + +/*-------------------------------------------------------------------*\ + isAlphaUniform +\*-------------------------------------------------------------------*/ +bool CBitmap::isAlphaUniform(uint8 *alpha) const +{ + uint32 size = _Data[0].size(); + + if (size == 0) return false; + + uint pixelSize; + + switch(PixelFormat) + { + // formats with alpha channel + case RGBA: + pixelSize = 4; + break; + + case AlphaLuminance: + pixelSize = 2; + break; + + case Alpha: + pixelSize = 1; + break; + + // formats without alpha channel + case Luminance: + if (alpha) *alpha = 255; + return true; + + default: + return false; + } + + // get a pointer on original data + uint8 *data = (uint8*)_Data[0].getPtr(); + uint8 *endData = data + size; + + // first alpha + data += pixelSize - 1; + + // first alpha value + uint8 value = *data; + + // check if all alphas have the same value + while(data < endData && *data == value) data += pixelSize; + + // texture can be converted if all alphas are 0 or 255 + if (data >= endData) + { + // return the uniform value + if (alpha) *alpha = value; + return true; + } + + return false; +} + + +/*-------------------------------------------------------------------*\ + isGrayscale +\*-------------------------------------------------------------------*/ +bool CBitmap::isGrayscale() const +{ + // all grayscale formats or, al least, without color information + switch(PixelFormat) + { + case Luminance: + case AlphaLuminance: + case Alpha: + return true; + + case RGBA: + break; + + default: + // DXTC formats won't be managed at the moment + return false; + } + + uint32 size = _Data[0].size(); + if (size == 0) return false; + + // get a pointer on original data + uint32 *data = (uint32*)_Data[0].getPtr(); + uint32 *endData = (uint32*)((uint8*)data + size); + + NLMISC::CRGBA color; + + // check if all alphas have the same value + while(data < endData) + { + color.set8888(*data); + + if (!color.isGray()) return false; + + ++data; + } + + return true; +} + From ee26c7377b9a990d7974736296cc1f6a68c2edb5 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:03:06 +0100 Subject: [PATCH 07/13] Changed: Minor change --HG-- branch : develop --- code/nel/src/misc/bitmap.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/nel/src/misc/bitmap.cpp b/code/nel/src/misc/bitmap.cpp index ca2a14435..2d92cd354 100644 --- a/code/nel/src/misc/bitmap.cpp +++ b/code/nel/src/misc/bitmap.cpp @@ -65,9 +65,9 @@ const uint32 CBitmap::bitPerPixels[ModeCount]= 16 // DsDt }; -const uint32 CBitmap::DXTC1HEADER = NL_MAKEFOURCC('D','X', 'T', '1'); -const uint32 CBitmap::DXTC3HEADER = NL_MAKEFOURCC('D','X', 'T', '3'); -const uint32 CBitmap::DXTC5HEADER = NL_MAKEFOURCC('D','X', 'T', '5'); +const uint32 CBitmap::DXTC1HEADER = NL_MAKEFOURCC('D', 'X', 'T', '1'); +const uint32 CBitmap::DXTC3HEADER = NL_MAKEFOURCC('D', 'X', 'T', '3'); +const uint32 CBitmap::DXTC5HEADER = NL_MAKEFOURCC('D', 'X', 'T', '5'); #ifdef NEL_ALL_BITMAP_WHITE From d34e3d120dfba91b9b2214a49905339167b8f68c Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:04:06 +0100 Subject: [PATCH 08/13] Changed: Parse nvidia-smi output to determine video memory --HG-- branch : develop --- code/nel/src/misc/system_utils.cpp | 213 ++++++++++++++++++++--------- 1 file changed, 146 insertions(+), 67 deletions(-) diff --git a/code/nel/src/misc/system_utils.cpp b/code/nel/src/misc/system_utils.cpp index 6c9b3ae01..b70d3203e 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -601,78 +601,157 @@ sint CSystemUtils::getTotalVideoMemory() #elif defined(NL_OS_MAC) // the right method is using OpenGL #else - // under Linux, no method is really reliable... - NLMISC::CIFile file; - - std::string logFile = "/var/log/Xorg.0.log"; - - // parse last Xorg.0.log - if (file.open(logFile, true)) + if (res == -1) { - char buffer[256]; + // use nvidia-smi + std::string command = "nvidia-smi -q -d MEMORY"; - while(!file.eof()) + std::string out = getCommandOutput(command); + + if (out.empty()) { - file.getline(buffer, 256); - - if (buffer[0] == '\0') break; - - std::string line(buffer); - - // nvidia driver - std::string::size_type pos = line.find(") NVIDIA("); - - if (pos != std::string::npos) - { - // [ 20.883] (--) NVIDIA(0): Memory: 2097152 kBytes - pos = line.find("Memory: ", pos); - - // found memory line - if (pos == std::string::npos) continue; - pos += 8; - - std::string::size_type posUnits = line.find(" kBytes", pos); - - // found units in KiB - if (posUnits == std::string::npos) continue; - - std::string videoMemory = line.substr(pos, posUnits-pos); - - if (!NLMISC::fromString(videoMemory, res)) continue; - - nlinfo("Xorg NVIDIA driver reported %d KiB of video memory", res); - break; - } - - // intel driver - pos = line.find(") intel("); - - if (pos != std::string::npos) - { - // (**) intel(0): VideoRam: 131072 KB - pos = line.find("VideoRam: ", pos); - - // found memory line - if (pos == std::string::npos) continue; - pos += 10; - - std::string::size_type posUnits = line.find(" KB", pos); - - // found units in KiB - if (posUnits == std::string::npos) continue; - - std::string videoMemory = line.substr(pos, posUnits-pos); - - if (!NLMISC::fromString(videoMemory, res)) continue; - - nlinfo("Xorg Intel driver reported %d KiB of video memory", res); - break; - } - - // TODO: other drivers: nv, fglrx (ATI), radeon (ATI) + nlwarning("Unable to launch %s", command.c_str()); } + else + { + std::vector lines; + explode(out, std::string("\n"), lines, true); + + // process each line + for(uint i = 0; i < lines.size(); ++i) + { + // Total : 62 MB - file.close(); + std::string line = lines[i]; + + // find Total line + std::string::size_type pos = line.find("Total"); + if (pos == std::string::npos) continue; + pos += 6; + + // find separator + pos = line.find(':', pos); + if (pos == std::string::npos) continue; + pos += 2; + + // find units + std::string::size_type posUnits = line.find(' ', pos); + if (posUnits == std::string::npos) continue; + ++posUnits; + + // found device ID + std::string memory = line.substr(pos, posUnits-pos-1); + std::string units = line.substr(posUnits); + + // convert video memory to sint + if (NLMISC::fromString(memory, res)) + { + if (units == "MB") + { + res *= 1024; + } + else if (units == "GB") + { + res *= 1024 * 1024; + } + else + { + // reset to use other methods + res = -1; + + nlwarning("nvidia-smi reported %d %s as wrong video memory units", res, units.c_str()); + break; + } + + nlinfo("nvidia-smi reported %d KiB of video memory", res); + } + else + { + // reset to use other methods + res = -1; + } + + break; + } + } + } + + if (res == -1) + { + // under Linux, no method is really reliable... + NLMISC::CIFile file; + + std::string logFile = "/var/log/Xorg.0.log"; + + // parse last Xorg.0.log + if (file.open(logFile, true)) + { + char buffer[256]; + + while(!file.eof()) + { + file.getline(buffer, 256); + + if (buffer[0] == '\0') break; + + std::string line(buffer); + + // nvidia driver + std::string::size_type pos = line.find(") NVIDIA("); + + if (pos != std::string::npos) + { + // [ 20.883] (--) NVIDIA(0): Memory: 2097152 kBytes + // [ 28.515] (--) NVIDIA(0): Memory: 262144 kBytes + pos = line.find("Memory: ", pos); + + // found memory line + if (pos == std::string::npos) continue; + pos += 8; + + std::string::size_type posUnits = line.find(" kBytes", pos); + + // found units in KiB + if (posUnits == std::string::npos) continue; + + std::string videoMemory = line.substr(pos, posUnits-pos); + + if (!NLMISC::fromString(videoMemory, res)) continue; + + nlinfo("Xorg NVIDIA driver reported %d KiB of video memory", res); + break; + } + + // intel driver + pos = line.find(") intel("); + + if (pos != std::string::npos) + { + // (**) intel(0): VideoRam: 131072 KB + pos = line.find("VideoRam: ", pos); + + // found memory line + if (pos == std::string::npos) continue; + pos += 10; + + std::string::size_type posUnits = line.find(" KB", pos); + + // found units in KiB + if (posUnits == std::string::npos) continue; + + std::string videoMemory = line.substr(pos, posUnits-pos); + + if (!NLMISC::fromString(videoMemory, res)) continue; + + nlinfo("Xorg Intel driver reported %d KiB of video memory", res); + break; + } + + // TODO: other drivers: fglrx (ATI), radeon (ATI) + } + + file.close(); + } } if (res == -1) From e995b7221fe5989d77593d7ddde44b2526c3fd59 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:04:45 +0100 Subject: [PATCH 09/13] Added: Textures optimizer tool --HG-- branch : develop --- code/nel/tools/3d/CMakeLists.txt | 1 + .../3d/textures_optimizer/CMakeLists.txt | 9 + code/nel/tools/3d/textures_optimizer/main.cpp | 233 ++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 code/nel/tools/3d/textures_optimizer/CMakeLists.txt create mode 100644 code/nel/tools/3d/textures_optimizer/main.cpp diff --git a/code/nel/tools/3d/CMakeLists.txt b/code/nel/tools/3d/CMakeLists.txt index 55481097b..e446162e7 100644 --- a/code/nel/tools/3d/CMakeLists.txt +++ b/code/nel/tools/3d/CMakeLists.txt @@ -35,6 +35,7 @@ IF(WITH_NEL_TOOLS) SUBDIRS( build_interface get_neighbors + textures_optimizer tga_cut tga_resize) ENDIF() diff --git a/code/nel/tools/3d/textures_optimizer/CMakeLists.txt b/code/nel/tools/3d/textures_optimizer/CMakeLists.txt new file mode 100644 index 000000000..469592ec4 --- /dev/null +++ b/code/nel/tools/3d/textures_optimizer/CMakeLists.txt @@ -0,0 +1,9 @@ +FILE(GLOB SRC *.cpp *.h) + +ADD_EXECUTABLE(textures_optimizer ${SRC}) + +TARGET_LINK_LIBRARIES(textures_optimizer nelmisc) +NL_DEFAULT_PROPS(textures_optimizer "NeL, Tools, 3D: Textures optimizer") +NL_ADD_RUNTIME_FLAGS(textures_optimizer) + +INSTALL(TARGETS textures_optimizer RUNTIME DESTINATION ${NL_BIN_PREFIX} COMPONENT tools3d) diff --git a/code/nel/tools/3d/textures_optimizer/main.cpp b/code/nel/tools/3d/textures_optimizer/main.cpp new file mode 100644 index 000000000..df0039b0b --- /dev/null +++ b/code/nel/tools/3d/textures_optimizer/main.cpp @@ -0,0 +1,233 @@ +// NeL - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "nel/misc/file.h" +#include "nel/misc/bitmap.h" +#include "nel/misc/path.h" +#include "nel/misc/debug.h" + +#include + +void writeInstructions() +{ + std::cout << "Syntax: textures_optimizer [-a] [-g] " << std::endl; + std::cout << std::endl; + std::cout << " Try to optimize TGA or PNG textures by removing useless alpha channel or converting a RGB with black and white values to grayscale" << std::endl; + std::cout << " By default, it only make checks and display if texture can optimized or not" << std::endl; + std::cout << std::endl; + std::cout << "with" << std::endl; + std::cout << "-a : Remove alpha channel if useless" << std::endl; + std::cout << "-g : Convert to grayscale if all pixels are gray" << std::endl; + std::cout << std::endl; + std::cout << "-h or -? for this help" << std::endl; + std::cout << std::endl; +} + +bool FixAlpha = false; +bool FixGrayscale = false; + +std::vector InputFilenames; + +bool parseOptions(int argc, char **argv) +{ + // process each argument + for(sint i = 1; i < argc; ++i) + { + std::string option = argv[i]; + + if (option.length() > 0) + { + bool isOption = option[0] == '-'; + +#ifdef NL_OS_WINDOWS + // authorize / for options only under Windows, + // because under Linux it could be a full path + if (!isOption) isOption = (option[0] == '/'); +#endif + + // Option + if (isOption) + { + // remove option prefix + option = option.substr(1); + + // Fix alpha + if (option == "a") + { + FixAlpha = true; + } + // Fix grayscale + else if (option == "g") + { + FixGrayscale = true; + } + else if (option == "h" || option == "?") + { + return false; + } + else + { + nlwarning("Unknown option -%s", option.c_str()); + + return false; + } + } + // Filename + else + { + std::string ext = NLMISC::toLower(NLMISC::CFile::getExtension(option)); + + if (ext == "png" || ext == "tga") + { + InputFilenames.push_back(option); + } + else + { + nlwarning("Only PNG and TGA files supported, %s won't be processed", option.c_str()); + } + } + } + } + + return !InputFilenames.empty(); +} + +#include "nel/misc/system_utils.h" + +int main(int argc, char **argv) +{ + NLMISC::CApplicationContext applicationContext; + + if (!parseOptions(argc, argv)) + { + writeInstructions(); + return 0; + } + + for(uint i = 0; i < InputFilenames.size(); ++i) + { + std::string ext = NLMISC::toLower(NLMISC::CFile::getExtension(InputFilenames[i])); + + NLMISC::CIFile input; + + if (!input.open(InputFilenames[i])) + { + std::cerr << "Unable to open " << InputFilenames[i] << std::endl; + return 1; + } + + NLMISC::CBitmap bitmap; + + uint8 depth = bitmap.load(input); + + // don't need file so close it + input.close(); + + if (depth == 0) + { + std::cerr << "Unable to decode " << InputFilenames[i] << std::endl; + return 1; + } + + bool modified = false; + bool hasAlpha = false; + bool isGrayscale = false; + + if (bitmap.getPixelFormat() == NLMISC::CBitmap::RGBA && depth == 32) + { + hasAlpha = true; + } + else if (bitmap.getPixelFormat() == NLMISC::CBitmap::AlphaLuminance) + { + hasAlpha = true; + isGrayscale = true; + } + else if (bitmap.getPixelFormat() == NLMISC::CBitmap::Luminance) + { + isGrayscale = true; + } + else if (bitmap.getPixelFormat() == NLMISC::CBitmap::Alpha) + { + hasAlpha = true; + isGrayscale = true; + } + + if (!isGrayscale && bitmap.isGrayscale()) + { + std::cout << InputFilenames[i] << " (grayscale image with RGB colors)" << std::endl; + + if (FixGrayscale) + { + if (!bitmap.convertToType(hasAlpha ? NLMISC::CBitmap::AlphaLuminance:NLMISC::CBitmap::Luminance)) + { + std::cerr << "Unable to convert to Luminance" << std::endl; + return 1; + } + + isGrayscale = true; + modified = true; + } + } + + uint8 alpha = 0; + + if (hasAlpha && bitmap.isAlphaUniform(&alpha)) + { + std::cout << InputFilenames[i] << " (image with uniform alpha channel " << alpha << ")" << std::endl; + + if (FixAlpha && (alpha == 0 || alpha == 255)) + { + bitmap.makeOpaque(); + + hasAlpha = false; + modified = true; + } + } + + if (!modified) continue; + + NLMISC::COFile output; + + if (!output.open(InputFilenames[i])) + { + std::cerr << "Unable to open" << std::endl; + return 1; + } + + uint32 newDepth = isGrayscale ? 8:24; + + if (hasAlpha) newDepth += 8; + + bool res = false; + + if (ext == "png") + { + res = bitmap.writePNG(output, newDepth); + } + else if (ext == "tga") + { + res = bitmap.writePNG(output, newDepth); + } + + if (!res) + { + std::cerr << "Unable to encode" << std::endl; + return 1; + } + } + + return 0; +} From 80759eafb47254bd40aa51405575bda6c3a00f97 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:04:57 +0100 Subject: [PATCH 10/13] Changed: Minor changes --HG-- branch : develop --- code/nel/tools/3d/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/nel/tools/3d/CMakeLists.txt b/code/nel/tools/3d/CMakeLists.txt index e446162e7..4a7b8a997 100644 --- a/code/nel/tools/3d/CMakeLists.txt +++ b/code/nel/tools/3d/CMakeLists.txt @@ -55,22 +55,22 @@ ENDIF() IF(WITH_NEL_TOOLS AND WITH_3D) IF(WIN32) -# ADD_SUBDIRECTORY(lightmap_optimizer) +# ADD_SUBDIRECTORY(lightmap_optimizer) IF(MFC_FOUND) ADD_SUBDIRECTORY(object_viewer_exe) ADD_SUBDIRECTORY(tile_edit) ENDIF(MFC_FOUND) ENDIF(WIN32) - + IF(WITH_QT) ADD_SUBDIRECTORY(tile_edit_qt) ADD_SUBDIRECTORY(object_viewer_widget) ENDIF(WITH_QT) - + IF(WITH_NEL_TOOLS) FIND_PACKAGE(Squish) ENDIF() - + IF(SQUISH_FOUND) ADD_SUBDIRECTORY(s3tc_compressor_lib) ADD_SUBDIRECTORY(panoply_maker) From cf8ed540a71f40c21e3ec19ad0fb12da8ef793ae Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:07:27 +0100 Subject: [PATCH 11/13] Changed: Use new methods in panoply_maker --HG-- branch : develop --- .../tools/3d/panoply_maker/panoply_maker.cpp | 79 +++++++------------ 1 file changed, 30 insertions(+), 49 deletions(-) diff --git a/code/nel/tools/3d/panoply_maker/panoply_maker.cpp b/code/nel/tools/3d/panoply_maker/panoply_maker.cpp index e3770ec67..12f2aa231 100644 --- a/code/nel/tools/3d/panoply_maker/panoply_maker.cpp +++ b/code/nel/tools/3d/panoply_maker/panoply_maker.cpp @@ -669,69 +669,50 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str // we can save it as RGB to optimize it if (bi.OptimizeTextures > 0 && depth == 32) { - uint32 size = srcBitmap.getPixels().size(); + uint8 value = 0; - if (size > 0) + // texture can be converted if all alphas are 0 or 255 + if (srcBitmap.isAlphaUniform(&value) && (value == 255 || value == 0)) { - // get a pointer on original data - uint8 *data = srcBitmap.getPixels().getPtr(); - - // pointer on first alpha value - uint8 *tmp = data + 3; - uint8 *endData = data + size; - uint8 value = *tmp; - - // check if all alphas have the same value - while(tmp < endData && *tmp == value) tmp += 4; - - // texture can be converted if all alphas are 0 or 255 - if (tmp >= endData && (value == 255 || value == 0)) + if (bi.OptimizeTextures > 1) { - if (bi.OptimizeTextures > 1) + // make bitmap opaque + srcBitmap.makeOpaque(); + + // original depth is now 24 bits, since we discarded alpha channel + depth = 24; + + NLMISC::COFile os; + + if (os.open(fullInputBitmapPath)) { - // original depth is now 24 bits, since we discarded alpha channel - depth = 24; + nlwarning("Optimizing texture %s...", fullInputBitmapPath.c_str()); - // if texture is fully transparent, make it fully opaque - if (value == 0) + std::string ext = CFile::getExtension(fullInputBitmapPath); + + // resave the texture in optimized same format + if (ext == "png") { - tmp = data + 3; - - while(tmp < endData) - { - *tmp = 255; - tmp += 4; - } + srcBitmap.writePNG(os, 24); } - - NLMISC::COFile os; - - if (os.open(fullInputBitmapPath)) + else if (ext == "tga") { - nlwarning("Optimizing texture %s...", fullInputBitmapPath.c_str()); - - std::string ext = CFile::getExtension(fullInputBitmapPath); - - // resave the texture in optimized same format - if (ext == "png") - { - srcBitmap.writePNG(os, 24); - } - else if (ext == "tga") - { - srcBitmap.writeTGA(os, 24); - } - else - { - nlwarning("Don't support %s format for texture, unable to save it", ext.c_str()); - } + srcBitmap.writeTGA(os, 24); + } + else + { + nlwarning("Don't support %s format for texture, unable to save it", ext.c_str()); } } else { - nlwarning("Texture %s can be optimized", fullInputBitmapPath.c_str()); + nlwarning("Unable to save texture %s", fullInputBitmapPath.c_str()); } } + else + { + nlwarning("Texture %s can be optimized", fullInputBitmapPath.c_str()); + } } } From 03eaa9181a01ed58c615680faad515f92b11b929 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:08:11 +0100 Subject: [PATCH 12/13] Changed: Minor changes --HG-- branch : develop --- .../guild_manager/guild_member_module.cpp | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/code/ryzom/server/src/entities_game_service/guild_manager/guild_member_module.cpp b/code/ryzom/server/src/entities_game_service/guild_manager/guild_member_module.cpp index c04347c08..f38f9d170 100644 --- a/code/ryzom/server/src/entities_game_service/guild_manager/guild_member_module.cpp +++ b/code/ryzom/server/src/entities_game_service/guild_manager/guild_member_module.cpp @@ -47,7 +47,7 @@ NL_INSTANCE_COUNTER_IMPL(CGuildMemberModule); CGuildMemberModule * CGuildMemberModule::createModule( CGuildCharProxy& proxy, CGuildMember* guildMember ) { nlassert( guildMember ); - switch( guildMember->getGrade() ) + switch( guildMember->getGrade() ) { case EGSPD::CGuildGrade::Member: return new CGuildMemberModule(proxy,guildMember); @@ -103,7 +103,7 @@ void CGuildMemberModule::quitGuild() EGS_PD_AST( guild ); SM_STATIC_PARAMS_1( params,STRING_MANAGER::player ); params[0].setEIdAIAlias( _GuildMemberCore->getIngameEId(), CAIAliasTranslator::getInstance()->getAIAlias(_GuildMemberCore->getIngameEId()) ); - + CFameManager::getInstance().clearPlayerGuild( _GuildMemberCore->getIngameEId() ); CGuildCharProxy proxy; @@ -134,7 +134,7 @@ void CGuildMemberModule::setGrade( uint16 index,uint8 session, EGSPD::CGuildGrad CGuildCharProxy proxy; getProxy(proxy); proxy.cancelAFK(); - + if ( guild->getMembersSession() != session ) { proxy.sendSystemMessage( "GUILD_BAD_SESSION" ); @@ -165,17 +165,17 @@ void CGuildMemberModule::setGrade( uint16 index,uint8 session, EGSPD::CGuildGrad proxy.sendSystemMessage("GUILD_GRADE_FULL",paramFull); return; } - + member->setMemberGrade(grade); guild->incGradeCount( grade ); guild->decGradeCount( oldGrade ); - + // send system message SM_STATIC_PARAMS_3(params,STRING_MANAGER::player,STRING_MANAGER::player,STRING_MANAGER::string_id); params[0].setEIdAIAlias( proxy.getId(), CAIAliasTranslator::getInstance()->getAIAlias(proxy.getId()) ); params[1].setEIdAIAlias( member->getIngameEId(), CAIAliasTranslator::getInstance()->getAIAlias(member->getIngameEId()) ); params[2].StringId = guild->getNameId(); - + // If the player is online, the module must be recreated. Do as the reference was destroyed CGuildMemberModule * module = NULL; if ( member->getReferencingModule(module) ) @@ -266,7 +266,7 @@ void CGuildMemberModule::_inviteCharacterInGuild(CGuildCharProxy& invitor, CGuil if ( target.getModule(inviteModule) ) { CCharacter::sendDynamicSystemMessage( invitor.getRowId(), "GUILD_ALREADY_HAS_JOIN_PROPOSAL",params1 ); - return; + return; } /// the invitor must not be in the ignore list of the target @@ -323,16 +323,18 @@ void CGuildMemberModule::_inviteCharacterInGuild(CGuildCharProxy& invitor, CGuil SM_STATIC_PARAMS_1(params,STRING_MANAGER::integer); params[0].Int = GuildMaxMemberCount; CCharacter::sendDynamicSystemMessage( invitor.getRowId(), "GUILD_MAX_MEMBER_COUNT", params); - return; + return; } /// check guild and invited member allegiances compatibilities CGuild::TAllegiances guildAllegiance, invitedAllegiance; guildAllegiance = guild->getAllegiance(); + CCharacter * invitedChar = PlayerManager.getChar(target.getId()); - if( invitedChar == 0 ) return; + if (invitedChar == NULL) return; invitedAllegiance = invitedChar->getAllegiance(); - if( invitedAllegiance.first != guildAllegiance.first && invitedAllegiance.first != PVP_CLAN::Neutral ) + + if (invitedAllegiance.first != guildAllegiance.first && invitedAllegiance.first != PVP_CLAN::Neutral) { SM_STATIC_PARAMS_2( params, STRING_MANAGER::player, STRING_MANAGER::faction ); params[0].setEIdAIAlias( target.getId(), CAIAliasTranslator::getInstance()->getAIAlias( target.getId()) ); @@ -340,7 +342,8 @@ void CGuildMemberModule::_inviteCharacterInGuild(CGuildCharProxy& invitor, CGuil invitor.sendSystemMessage("GUILD_ICOMPATIBLE_ALLEGIANCE",params); return; } - if( invitedAllegiance.second != guildAllegiance.second && invitedAllegiance.second != PVP_CLAN::Neutral ) + + if (invitedAllegiance.second != guildAllegiance.second && invitedAllegiance.second != PVP_CLAN::Neutral) { SM_STATIC_PARAMS_2( params, STRING_MANAGER::player, STRING_MANAGER::faction ); params[0].setEIdAIAlias( target.getId(), CAIAliasTranslator::getInstance()->getAIAlias( target.getId()) ); @@ -504,11 +507,11 @@ void CGuildMemberModule::clearOnlineGuildProperties() getProxy(targetProxy); targetProxy.setGuildId(0); targetProxy.updateTargetingChars(); - + CMirrorPropValueRO mirrorCell( TheDataset, targetProxy.getEntityRowId(), DSPropertyCELL ); - sint32 cell = mirrorCell; + sint32 cell = mirrorCell; if ( CBuildingManager::getInstance()->isRoomCell(cell) ) - { + { CRoomInstanceGuild * room = dynamic_cast( CBuildingManager::getInstance()->getRoomInstanceFromCell( cell ) ); if ( room && room->getGuildId() && room->getBuilding() ) { @@ -533,7 +536,7 @@ void CGuildMemberModule::kickMember( uint16 index,uint8 session )const CGuildCharProxy proxy; getProxy(proxy); proxy.cancelAFK(); - + if ( guild->getMembersSession() != session ) { proxy.sendSystemMessage( "GUILD_BAD_SESSION" ); @@ -544,7 +547,7 @@ void CGuildMemberModule::kickMember( uint16 index,uint8 session )const nlwarning("%s tries to kick himself",proxy.getId().toString().c_str()); return; } - + CGuildMember * member = guild->getMemberByIndex( index ); if ( member == NULL ) { @@ -570,7 +573,7 @@ void CGuildMemberModule::kickMember( uint16 index,uint8 session )const params[1].StringId = CEntityIdTranslator::getInstance()->getEntityNameStringId(member->getIngameEId()); sendMessageToGuildMembers("GUILD_KICK_MEMBER",params); - guild->deleteMember( member ); + guild->deleteMember( member ); } //---------------------------------------------------------------------------- From 860a4d99ba6e74618fec543e26f2a97a7c1a7638 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 1 Jan 2016 16:26:12 +0100 Subject: [PATCH 13/13] Changed: Replaced substr == by compare, because more optimized (thanks to Kaetemi for the hint!) --HG-- branch : develop --- .../mission_manager/mission_step_template.cpp | 4 ++-- .../mission_manager/mission_template.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/code/ryzom/server/src/entities_game_service/mission_manager/mission_step_template.cpp b/code/ryzom/server/src/entities_game_service/mission_manager/mission_step_template.cpp index a042da852..179bea350 100644 --- a/code/ryzom/server/src/entities_game_service/mission_manager/mission_step_template.cpp +++ b/code/ryzom/server/src/entities_game_service/mission_manager/mission_step_template.cpp @@ -104,7 +104,7 @@ uint32 IMissionStepTemplate::sendRpStepText(CCharacter * user,const std::vector< _User = user; - if (_RoleplayText.substr(0, 6) == "WEBIG_") + if (_RoleplayText.compare(0, 6, "WEBIG_") == 0) { TVectorParamCheck params; string name = _RoleplayText; @@ -174,7 +174,7 @@ uint32 IMissionStepTemplate::sendStepText(CCharacter * user,const std::vector