From 54c53255b1bcb8939a3ec3b4257043daf119b787 Mon Sep 17 00:00:00 2001 From: liria Date: Sat, 25 Jan 2014 11:50:14 +0100 Subject: [PATCH 2/4] make the programm compile on linux plateform --HG-- branch : lightmap_optimizer_port_to_linux --- code/nel/tools/3d/CMakeLists.txt | 3 +- code/nel/tools/3d/ig_elevation/main.cpp | 2 +- code/nel/tools/3d/lightmap_optimizer/main.cpp | 141 +++++++++++++----- 3 files changed, 107 insertions(+), 39 deletions(-) diff --git a/code/nel/tools/3d/CMakeLists.txt b/code/nel/tools/3d/CMakeLists.txt index cc3b54f02..a07e8c53a 100644 --- a/code/nel/tools/3d/CMakeLists.txt +++ b/code/nel/tools/3d/CMakeLists.txt @@ -7,6 +7,7 @@ IF(WITH_NEL_TOOLS) build_smallbank ig_lighter ig_elevation + lightmap_optimizer zone_dependencies zone_ig_lighter zone_lighter @@ -47,7 +48,7 @@ ENDIF(WIN32) IF(WITH_NEL_TOOLS) IF(WIN32) - ADD_SUBDIRECTORY(lightmap_optimizer) +# ADD_SUBDIRECTORY(lightmap_optimizer) IF(MFC_FOUND) ADD_SUBDIRECTORY(object_viewer_exe) ADD_SUBDIRECTORY(tile_edit) diff --git a/code/nel/tools/3d/ig_elevation/main.cpp b/code/nel/tools/3d/ig_elevation/main.cpp index 3983dc4ec..833f389be 100644 --- a/code/nel/tools/3d/ig_elevation/main.cpp +++ b/code/nel/tools/3d/ig_elevation/main.cpp @@ -162,7 +162,7 @@ void getcwd (char *dir, int length) { GetCurrentDirectoryA (length, dir); } - +d void chdir(const char *path) { SetCurrentDirectoryA (path); diff --git a/code/nel/tools/3d/lightmap_optimizer/main.cpp b/code/nel/tools/3d/lightmap_optimizer/main.cpp index ae8e4542a..db7f66d6a 100644 --- a/code/nel/tools/3d/lightmap_optimizer/main.cpp +++ b/code/nel/tools/3d/lightmap_optimizer/main.cpp @@ -32,7 +32,16 @@ #include "nel/3d/texture_file.h" #include "nel/3d/register_3d.h" -#include "windows.h" +#ifdef NL_OS_WINDOWS + #include +#else + #include /* for directories functions */ + #include + #include + #include /* getcwd, chdir -- replacement for getCurDiretory & setCurDirectory on windows */ +#endif + + #include #include @@ -42,20 +51,20 @@ using namespace std; using namespace NL3D; -// --------------------------------------------------------------------------- -char sExeDir[MAX_PATH]; -void outString (const string &sText) +void outString (const string &sText) ; + +// --------------------------------------------------------------------------- +#ifdef NL_OS_WINDOWS // win32 code +void GetCWD (int length,char *dir) { - char sCurDir[MAX_PATH]; - GetCurrentDirectory (MAX_PATH, sCurDir); - SetCurrentDirectory (sExeDir); - NLMISC::createDebug (); - NLMISC::InfoLog->displayRaw(sText.c_str()); - SetCurrentDirectory (sCurDir); + GetCurrentDirectoryA (length, dir); } -// --------------------------------------------------------------------------- +bool ChDir(const char *path) +{ + return SetCurrentDirectoryA (path); +} void dir (const std::string &sFilter, std::vector &sAllFiles, bool bFullPath) { WIN32_FIND_DATA findData; @@ -63,7 +72,7 @@ void dir (const std::string &sFilter, std::vector &sAllFiles, bool char sCurDir[MAX_PATH]; sAllFiles.clear (); GetCurrentDirectory (MAX_PATH, sCurDir); - hFind = FindFirstFile (sFilter.c_str(), &findData); + hFind = FindFirstFile ("*"+sFilter.c_str(), &findData); while (hFind != INVALID_HANDLE_VALUE) { DWORD res = GetFileAttributes(findData.cFileName); @@ -79,16 +88,74 @@ void dir (const std::string &sFilter, std::vector &sAllFiles, bool } FindClose (hFind); } +#else // posix version of the void dir(...) function. +void GetCWD (int length, char* directory) +{ + getcwd (directory,length); +} +bool ChDir(const char *path) +{ + return ( chdir (path) == 0 ? true : false ); +} +void dir (const string &sFilter, vector &sAllFiles, bool bFullPath) +{ + char sCurDir[MAX_PATH]; + DIR* dp = NULL; + struct dirent *dirp= NULL; + + GetCWD ( MAX_PATH,sCurDir ) ; + sAllFiles.clear (); + if ( (dp = opendir( sCurDir )) == NULL) + { + string sTmp = string("ERROR : Can't open the dir : \"")+string(sCurDir)+string("\"") ; + outString ( sTmp ) ; + return ; + } + + while ( (dirp = readdir(dp)) != NULL) + { + std:string sFileName = std::string(dirp->d_name) ; + if (sFileName.substr((sFileName.length()-sFilter.length()),sFilter.length()).find(sFilter)!= std::string::npos ) + { + if (bFullPath) + sAllFiles.push_back(string(sCurDir) + "/" + sFileName); + else + sAllFiles.push_back(sFileName); + } + + } + closedir(dp); +} +bool DeleteFile(const char* filename){ + if ( int res = unlink (filename) == -1 ) + return false; + return true; +} +#endif + + +// --------------------------------------------------------------------------- +char sExeDir[MAX_PATH]; + +void outString (const string &sText) +{ + char sCurDir[MAX_PATH]; + GetCWD (MAX_PATH, sCurDir); + ChDir (sExeDir); + NLMISC::createDebug (); + NLMISC::InfoLog->displayRaw(sText.c_str()); + ChDir (sCurDir); +} // --------------------------------------------------------------------------- bool fileExist (const std::string &sFileName) { - HANDLE hFile = CreateFile (sFileName.c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) - return false; - CloseHandle (hFile); - return true; +#ifdef NL_OS_WINDOWS + return (GetFileAttributes(sFileName.c_str()) != INVALID_FILE_ATTRIBUTES); +#else // NL_OS_WINDOWS + struct stat buf; + return stat (sFileName.c_str (), &buf) == 0; +#endif // NL_OS_WINDOWS } // ----------------------------------------------------------------------------------------------- @@ -332,25 +399,25 @@ int main(int nNbArg, char **ppArgs) char sSHPDir[MAX_PATH]; - GetCurrentDirectory (MAX_PATH, sExeDir); + GetCWD (MAX_PATH, sExeDir); // Get absolute directory for lightmaps - if (!SetCurrentDirectory(ppArgs[1])) + if (!ChDir(ppArgs[1])) { - outString (string("ERROR : directory ") + ppArgs[1] + " do not exists\n"); + outString (string("ERROR : directory ") + ppArgs[1] + " do not exists or access is denied\n"); return -1; } - GetCurrentDirectory (MAX_PATH, sLMPDir); - SetCurrentDirectory (sExeDir); + GetCWD (MAX_PATH, sLMPDir); + ChDir (sExeDir); // Get absolute directory for shapes - if (!SetCurrentDirectory(ppArgs[2])) + if (!ChDir(ppArgs[2])) { - outString (string("ERROR : directory ") + ppArgs[2] + " do not exists\n"); + outString (string("ERROR : directory ") + ppArgs[2] + " do not exists or access is denied\n"); return -1; } - GetCurrentDirectory (MAX_PATH, sSHPDir); - dir ("*.shape", AllShapeNames, false); + GetCWD (MAX_PATH, sSHPDir); + dir (".shape", AllShapeNames, false); registerSerial3d (); for (uint32 nShp = 0; nShp < AllShapeNames.size(); ++nShp) { @@ -374,13 +441,13 @@ int main(int nNbArg, char **ppArgs) if (nNbArg > 3 && ppArgs[3] && strlen(ppArgs[3]) > 0) { - SetCurrentDirectory (sExeDir); - if (!SetCurrentDirectory(ppArgs[3])) + ChDir (sExeDir); + if (!ChDir(ppArgs[3])) { outString (string("ERROR : directory ") + ppArgs[3] + " do not exists\n"); return -1; } - dir ("*.tag", tags, false); + dir (".tag", tags, false); for(uint k = 0; k < tags.size(); ++k) { std::string::size_type pos = tags[k].find('.'); @@ -426,7 +493,7 @@ int main(int nNbArg, char **ppArgs) // **** Parse all lightmaps, sorted by layer, and 8 or 16 bit mode - SetCurrentDirectory (sExeDir); + ChDir (sExeDir); for (uint32 lmc8bitMode = 0; lmc8bitMode < 2; ++lmc8bitMode) for (uint32 nNbLayer = 0; nNbLayer < 256; ++nNbLayer) { @@ -440,8 +507,8 @@ int main(int nNbArg, char **ppArgs) string sFilter; // **** Get All Lightmaps that have this number of layer, and this mode - sFilter = "*_" + NLMISC::toString(nNbLayer) + ".tga"; - SetCurrentDirectory (sLMPDir); + sFilter = "_" + NLMISC::toString(nNbLayer) + ".tga"; + ChDir (sLMPDir); dir (sFilter, AllLightmapNames, false); // filter by layer @@ -564,7 +631,7 @@ int main(int nNbArg, char **ppArgs) outString(string("ERROR: lightmaps ")+sTmp2+"*.tga not all the same size\n"); for (k = 0; k < (sint32)AllLightmapNames.size(); ++k) { - if (strnicmp(AllLightmapNames[k].c_str(), sTmp2.c_str(), sTmp2.size()) == 0) + if (NLMISC::strnicmp(AllLightmapNames[k].c_str(), sTmp2.c_str(), sTmp2.size()) == 0) { for (j = k+1; j < (sint32)AllLightmapNames.size(); ++j) { @@ -697,7 +764,7 @@ int main(int nNbArg, char **ppArgs) // Change shapes uvs related and names to the lightmap // --------------------------------------------------- - SetCurrentDirectory (sSHPDir); + ChDir (sSHPDir); for (k = 0; k < (sint32)AllShapes.size(); ++k) { @@ -891,7 +958,7 @@ int main(int nNbArg, char **ppArgs) } } - SetCurrentDirectory (sLMPDir); + ChDir (sLMPDir); // Get out of the j loop break; @@ -923,7 +990,7 @@ int main(int nNbArg, char **ppArgs) // **** Additionally, output or clear a "flag file" in a dir to info if a 8bit lihgtmap or not if (nNbArg >=5 && ppArgs[4] && strlen(ppArgs[4]) > 0) { - SetCurrentDirectory (sExeDir); + ChDir (sExeDir); // out a text file, with list of FILE *out= fopen(ppArgs[4], "wt"); From 16dbe48ed563734dc64b8de753f94f11072de9e8 Mon Sep 17 00:00:00 2001 From: liria Date: Sat, 25 Jan 2014 17:09:07 +0100 Subject: [PATCH 3/4] use NEL CFile function for file test --HG-- branch : lightmap_optimizer_port_to_linux --- code/nel/tools/3d/lightmap_optimizer/main.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/code/nel/tools/3d/lightmap_optimizer/main.cpp b/code/nel/tools/3d/lightmap_optimizer/main.cpp index db7f66d6a..25b5678ea 100644 --- a/code/nel/tools/3d/lightmap_optimizer/main.cpp +++ b/code/nel/tools/3d/lightmap_optimizer/main.cpp @@ -150,12 +150,7 @@ void outString (const string &sText) // --------------------------------------------------------------------------- bool fileExist (const std::string &sFileName) { -#ifdef NL_OS_WINDOWS - return (GetFileAttributes(sFileName.c_str()) != INVALID_FILE_ATTRIBUTES); -#else // NL_OS_WINDOWS - struct stat buf; - return stat (sFileName.c_str (), &buf) == 0; -#endif // NL_OS_WINDOWS + return NLMISC::CFile::isExists(sFileName) ; } // ----------------------------------------------------------------------------------------------- From 12f63f3a6e97b596faf1f1c7f4f06451fa368c9e Mon Sep 17 00:00:00 2001 From: liria Date: Sat, 5 Apr 2014 13:49:14 +0000 Subject: [PATCH 4/4] Typo correction --HG-- branch : lightmap_optimizer_port_to_linux --- code/nel/tools/3d/ig_elevation/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/nel/tools/3d/ig_elevation/main.cpp b/code/nel/tools/3d/ig_elevation/main.cpp index 833f389be..3983dc4ec 100644 --- a/code/nel/tools/3d/ig_elevation/main.cpp +++ b/code/nel/tools/3d/ig_elevation/main.cpp @@ -162,7 +162,7 @@ void getcwd (char *dir, int length) { GetCurrentDirectoryA (length, dir); } -d + void chdir(const char *path) { SetCurrentDirectoryA (path);