From 99efdb2a23a4623cdc62545fd4a88a12acc42d65 Mon Sep 17 00:00:00 2001 From: liria Date: Sat, 8 Jun 2013 14:39:30 +0200 Subject: [PATCH 1/5] FIXE: replace the WIN32 API for directories manipulation by the the POSIX API to compile with linux. --HG-- branch : ig_elevaton_port_to_linux --- code/nel/tools/3d/CMakeLists.txt | 3 +- code/nel/tools/3d/ig_elevation/main.cpp | 94 ++++++++++++++++--------- 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/code/nel/tools/3d/CMakeLists.txt b/code/nel/tools/3d/CMakeLists.txt index 58360aec0..52a69bd01 100644 --- a/code/nel/tools/3d/CMakeLists.txt +++ b/code/nel/tools/3d/CMakeLists.txt @@ -3,6 +3,7 @@ SUBDIRS( build_far_bank build_smallbank ig_lighter + ig_elevation zone_dependencies zone_ig_lighter zone_lighter @@ -26,7 +27,7 @@ SUBDIRS( zviewer) IF(WIN32) - ADD_SUBDIRECTORY(ig_elevation) +# ADD_SUBDIRECTORY(ig_elevation) ADD_SUBDIRECTORY(lightmap_optimizer) IF(MFC_FOUND) diff --git a/code/nel/tools/3d/ig_elevation/main.cpp b/code/nel/tools/3d/ig_elevation/main.cpp index 0d12d371b..5b7d90fff 100644 --- a/code/nel/tools/3d/ig_elevation/main.cpp +++ b/code/nel/tools/3d/ig_elevation/main.cpp @@ -35,7 +35,14 @@ #include "nel/3d/scene_group.h" -#include +// #include + +#include /* Pour l'utilisation des dossiers */ +#ifndef WIN32 + #include +#endif +#include /* getcwd,chdir -- replacement for getCurDiretory & setCurDirectory on windows */ + // --------------------------------------------------------------------------- @@ -126,31 +133,43 @@ struct CZoneLimits }; // --------------------------------------------------------------------------- + + void dir (const string &sFilter, vector &sAllFiles, bool bFullPath) { - WIN32_FIND_DATA findData; - HANDLE hFind; - char sCurDir[MAX_PATH]; - sAllFiles.clear (); - GetCurrentDirectory (MAX_PATH, sCurDir); - hFind = FindFirstFile (sFilter.c_str(), &findData); - while (hFind != INVALID_HANDLE_VALUE) - { - DWORD res = GetFileAttributes(findData.cFileName); - if (res != INVALID_FILE_ATTRIBUTES && !(res&FILE_ATTRIBUTE_DIRECTORY)) - { - if (bFullPath) - sAllFiles.push_back(string(sCurDir) + "\\" + findData.cFileName); - else - sAllFiles.push_back(findData.cFileName); - } - if (FindNextFile (hFind, &findData) == 0) - break; - } - FindClose (hFind); + char sCurDir[MAX_PATH]; + DIR* dp = NULL; + struct dirent *dirp= NULL; + + getcwd ( sCurDir, MAX_PATH ) ; + 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) + // on windows should we use "\\" + sAllFiles.push_back(string(sCurDir) + "/" + sFileName); + else + sAllFiles.push_back(sFileName); + + } + + } + closedir(dp); } + // --------------------------------------------------------------------------- CZoneRegion *loadLand (const string &filename) { @@ -222,12 +241,14 @@ void SaveInstanceGroup (const char* sFilename, CInstanceGroup *pIG) } catch (const Exception &e) { - outString(string(e.what())); + string stTmp = string(e.what()) ; + outString( stTmp ); } } else { - outString(string("Couldn't create ") + sFilename); + string stTemp = string("Couldn't create ") + string(sFilename) ; + outString( stTemp ); } } @@ -274,7 +295,7 @@ int main(int nNbArg, char**ppArgs) NL3D_BlockMemoryAssertOnPurge = false; char sCurDir[MAX_PATH]; - GetCurrentDirectory (MAX_PATH, sCurDir); + getcwd (sCurDir,MAX_PATH); if (nNbArg != 2) { @@ -334,7 +355,9 @@ int main(int nNbArg, char**ppArgs) } else { - outString(string("Couldn't not open " + options.HeightMapFile1 + " : heightmap 1 map ignored")); + string sTmp = string("Couldn't not open ")+string(options.HeightMapFile1) + +string(" : heightmap 1 map ignored"); + outString(sTmp); delete HeightMap1; HeightMap1 = NULL; } @@ -360,7 +383,9 @@ int main(int nNbArg, char**ppArgs) } else { - outString(string("Couldn't not open " + options.HeightMapFile2 + " : heightmap 2 map ignored\n")); + string sTmp = string("Couldn't not open ")+string(options.HeightMapFile2) + +string(" : heightmap 2 map ignored\n"); + outString(sTmp); delete HeightMap2; HeightMap2 = NULL; } @@ -376,15 +401,15 @@ int main(int nNbArg, char**ppArgs) // Get all files vector vAllFiles; - SetCurrentDirectory (options.InputIGDir.c_str()); - dir ("*.ig", vAllFiles, false); - SetCurrentDirectory (sCurDir); + chdir (options.InputIGDir.c_str()); + dir (".ig", vAllFiles, false); + chdir (sCurDir); for (uint32 i = 0; i < vAllFiles.size(); ++i) { - SetCurrentDirectory (options.InputIGDir.c_str()); + chdir (options.InputIGDir.c_str()); CInstanceGroup *pIG = LoadInstanceGroup (vAllFiles[i].c_str()); - SetCurrentDirectory (sCurDir); + chdir (sCurDir); if (pIG != NULL) { bool realTimeSunContribution = pIG->getRealTimeSunContribution(); @@ -459,12 +484,13 @@ int main(int nNbArg, char**ppArgs) pIGout->enableRealTimeSunContribution(realTimeSunContribution); - SetCurrentDirectory (options.OutputIGDir.c_str()); + chdir (options.OutputIGDir.c_str()); SaveInstanceGroup (vAllFiles[i].c_str(), pIGout); - SetCurrentDirectory (sCurDir); + chdir (sCurDir); delete pIG; } } return 1; -} \ No newline at end of file +} + From 46d99e4a6d96add6e649619895e343619875ad3e Mon Sep 17 00:00:00 2001 From: liria Date: Sat, 8 Jun 2013 15:38:04 +0200 Subject: [PATCH 2/5] FIXE: Linux/Windows compilation : revert the code of the 'void dir(...)' function for windows with using conditional compilation. --HG-- branch : ig_elevaton_port_to_linux --- code/nel/tools/3d/ig_elevation/main.cpp | 44 ++++++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/code/nel/tools/3d/ig_elevation/main.cpp b/code/nel/tools/3d/ig_elevation/main.cpp index 5b7d90fff..b66c4ecfc 100644 --- a/code/nel/tools/3d/ig_elevation/main.cpp +++ b/code/nel/tools/3d/ig_elevation/main.cpp @@ -35,10 +35,11 @@ #include "nel/3d/scene_group.h" -// #include -#include /* Pour l'utilisation des dossiers */ -#ifndef WIN32 +#include +#ifdef NL_OS_WINDOWS + #include +#else #include #endif #include /* getcwd,chdir -- replacement for getCurDiretory & setCurDirectory on windows */ @@ -133,8 +134,31 @@ struct CZoneLimits }; // --------------------------------------------------------------------------- - - +#ifdef NL_OS_WINDOWS // win32 code +void dir (const string &sFilter, vector &sAllFiles, bool bFullPath) +{ + WIN32_FIND_DATA findData; + HANDLE hFind; + char sCurDir[MAX_PATH]; + sAllFiles.clear (); + GetCurrentDirectory (MAX_PATH, sCurDir); + hFind = FindFirstFile (sFilter.c_str(), &findData); + while (hFind != INVALID_HANDLE_VALUE) + { + DWORD res = GetFileAttributes(findData.cFileName); + if (res != INVALID_FILE_ATTRIBUTES && !(res&FILE_ATTRIBUTE_DIRECTORY)) + { + if (bFullPath) + sAllFiles.push_back(string(sCurDir) + "\\" + findData.cFileName); + else + sAllFiles.push_back(findData.cFileName); + } + if (FindNextFile (hFind, &findData) == 0) + break; + } + FindClose (hFind); +} +#else // posix version of the void dir(...) function. void dir (const string &sFilter, vector &sAllFiles, bool bFullPath) { char sCurDir[MAX_PATH]; @@ -157,7 +181,6 @@ void dir (const string &sFilter, vector &sAllFiles, bool bFullPath) find(sFilter)!= std::string::npos ) { if (bFullPath) - // on windows should we use "\\" sAllFiles.push_back(string(sCurDir) + "/" + sFileName); else sAllFiles.push_back(sFileName); @@ -167,8 +190,7 @@ void dir (const string &sFilter, vector &sAllFiles, bool bFullPath) } closedir(dp); } - - +#endif // endif posix version of "void dir(...)" // --------------------------------------------------------------------------- CZoneRegion *loadLand (const string &filename) @@ -402,7 +424,11 @@ int main(int nNbArg, char**ppArgs) // Get all files vector vAllFiles; chdir (options.InputIGDir.c_str()); - dir (".ig", vAllFiles, false); +#ifdef NL_OS_WINDOWS + dir ("*.ig", vAllFiles, false); +#else // posix version + dir (".ig", vAllFiles, false); +#endif chdir (sCurDir); for (uint32 i = 0; i < vAllFiles.size(); ++i) From 6b750cf042caab9841470d8d09c43020ba281f2a Mon Sep 17 00:00:00 2001 From: liria Date: Sat, 8 Jun 2013 16:15:41 +0200 Subject: [PATCH 3/5] FIXE: Linux/Windows compilation : revert the code of the 'void dir(...)' function for windows. --HG-- branch : ig_elevaton_port_to_linux --- code/nel/tools/3d/ig_elevation/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code/nel/tools/3d/ig_elevation/main.cpp b/code/nel/tools/3d/ig_elevation/main.cpp index b66c4ecfc..da7cd15e1 100644 --- a/code/nel/tools/3d/ig_elevation/main.cpp +++ b/code/nel/tools/3d/ig_elevation/main.cpp @@ -35,14 +35,13 @@ #include "nel/3d/scene_group.h" - -#include #ifdef NL_OS_WINDOWS #include #else + #include #include + #include #endif -#include /* getcwd,chdir -- replacement for getCurDiretory & setCurDirectory on windows */ // --------------------------------------------------------------------------- From 487799cbf544b98f8d3d067c035aa81613d189ac Mon Sep 17 00:00:00 2001 From: liria Date: Sun, 9 Jun 2013 15:55:59 +0200 Subject: [PATCH 4/5] kervala's enhancements and fixes for the Windows compilation. --HG-- branch : ig_elevaton_port_to_linux --- code/nel/tools/3d/ig_elevation/main.cpp | 140 ++++++++++++------------ 1 file changed, 71 insertions(+), 69 deletions(-) diff --git a/code/nel/tools/3d/ig_elevation/main.cpp b/code/nel/tools/3d/ig_elevation/main.cpp index da7cd15e1..3983dc4ec 100644 --- a/code/nel/tools/3d/ig_elevation/main.cpp +++ b/code/nel/tools/3d/ig_elevation/main.cpp @@ -36,11 +36,11 @@ #include "nel/3d/scene_group.h" #ifdef NL_OS_WINDOWS - #include + #include #else - #include - #include - #include + #include /* for directories functions */ + #include + #include /* getcwd, chdir -- replacement for getCurDiretory & setCurDirectory on windows */ #endif @@ -80,11 +80,11 @@ struct SExportOptions return false; else fclose (f); - + try { CConfigFile cf; - + cf.load (sFilename); // Out @@ -136,60 +136,70 @@ struct CZoneLimits #ifdef NL_OS_WINDOWS // win32 code void dir (const string &sFilter, vector &sAllFiles, bool bFullPath) { - WIN32_FIND_DATA findData; - HANDLE hFind; - char sCurDir[MAX_PATH]; - sAllFiles.clear (); - GetCurrentDirectory (MAX_PATH, sCurDir); - hFind = FindFirstFile (sFilter.c_str(), &findData); - while (hFind != INVALID_HANDLE_VALUE) - { - DWORD res = GetFileAttributes(findData.cFileName); - if (res != INVALID_FILE_ATTRIBUTES && !(res&FILE_ATTRIBUTE_DIRECTORY)) - { - if (bFullPath) - sAllFiles.push_back(string(sCurDir) + "\\" + findData.cFileName); - else - sAllFiles.push_back(findData.cFileName); - } - if (FindNextFile (hFind, &findData) == 0) - break; - } - FindClose (hFind); + WIN32_FIND_DATA findData; + HANDLE hFind; + char sCurDir[MAX_PATH]; + sAllFiles.clear (); + GetCurrentDirectory (MAX_PATH, sCurDir); + hFind = FindFirstFile (("*"+sFilter).c_str(), &findData); + while (hFind != INVALID_HANDLE_VALUE) + { + DWORD res = GetFileAttributes(findData.cFileName); + if (res != INVALID_FILE_ATTRIBUTES && !(res&FILE_ATTRIBUTE_DIRECTORY)) + { + if (bFullPath) + sAllFiles.push_back(string(sCurDir) + "\\" + findData.cFileName); + else + sAllFiles.push_back(findData.cFileName); + } + if (FindNextFile (hFind, &findData) == 0) + break; + } + FindClose (hFind); } + +void getcwd (char *dir, int length) +{ + GetCurrentDirectoryA (length, dir); +} + +void chdir(const char *path) +{ + SetCurrentDirectoryA (path); +} + #else // posix version of the void dir(...) function. void dir (const string &sFilter, vector &sAllFiles, bool bFullPath) { - char sCurDir[MAX_PATH]; - DIR* dp = NULL; - struct dirent *dirp= NULL; + char sCurDir[MAX_PATH]; + DIR* dp = NULL; + struct dirent *dirp= NULL; - getcwd ( sCurDir, MAX_PATH ) ; - 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) { - + getcwd ( sCurDir, MAX_PATH ) ; + sAllFiles.clear (); + if ( (dp = opendir( sCurDir )) == NULL) + { + string sTmp = string("ERROR : Can't open the dir : \"")+string(sCurDir)+string("\"") ; + outString ( sTmp ) ; + return ; + } - 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); + 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); + } + closedir(dp); } -#endif // endif posix version of "void dir(...)" +#endif + // --------------------------------------------------------------------------- CZoneRegion *loadLand (const string &filename) @@ -262,19 +272,19 @@ void SaveInstanceGroup (const char* sFilename, CInstanceGroup *pIG) } catch (const Exception &e) { - string stTmp = string(e.what()) ; + string stTmp = string(e.what()) ; outString( stTmp ); } } else { - string stTemp = string("Couldn't create ") + string(sFilename) ; + string stTemp = string("Couldn't create ") + string(sFilename) ; outString( stTemp ); } } /** Get the Z of the height map at the given position - */ + */ static float getHeightMapZ(float x, float y, const CZoneLimits &zl, const SExportOptions &options, CBitmap *heightMap1, CBitmap *heightMap2) { float deltaZ = 0.0f, deltaZ2 = 0.0f; @@ -316,8 +326,8 @@ int main(int nNbArg, char**ppArgs) NL3D_BlockMemoryAssertOnPurge = false; char sCurDir[MAX_PATH]; - getcwd (sCurDir,MAX_PATH); - + getcwd (sCurDir, MAX_PATH); + if (nNbArg != 2) { printf ("Use : ig_elevation configfile.cfg\n"); @@ -364,7 +374,7 @@ int main(int nNbArg, char**ppArgs) // Load the 2 height maps CBitmap *HeightMap1 = NULL; - if (options.HeightMapFile1 != "") + if (!options.HeightMapFile1.empty()) { HeightMap1 = new CBitmap; try @@ -392,7 +402,7 @@ int main(int nNbArg, char**ppArgs) } } CBitmap *HeightMap2 = NULL; - if (options.HeightMapFile2 != "") + if (!options.HeightMapFile2.empty()) { HeightMap2 = new CBitmap; try @@ -423,11 +433,7 @@ int main(int nNbArg, char**ppArgs) // Get all files vector vAllFiles; chdir (options.InputIGDir.c_str()); -#ifdef NL_OS_WINDOWS - dir ("*.ig", vAllFiles, false); -#else // posix version - dir (".ig", vAllFiles, false); -#endif + dir (".ig", vAllFiles, false); chdir (sCurDir); for (uint32 i = 0; i < vAllFiles.size(); ++i) @@ -445,14 +451,12 @@ int main(int nNbArg, char**ppArgs) vector Portals; vector PLN; pIG->retrieve (vGlobalPos, IA, Clusters, Portals, PLN); - + if (IA.empty() && PLN.empty() && Portals.empty() && Clusters.empty()) continue; uint k; - - // elevate instance for(k = 0; k < IA.size(); ++k) { @@ -466,7 +470,6 @@ int main(int nNbArg, char**ppArgs) CVector lightPos = vGlobalPos + PLN[k].getPosition(); PLN[k].setPosition( PLN[k].getPosition() + getHeightMapZ(lightPos.x, lightPos.y, zl, options, HeightMap1, HeightMap2) * CVector::K); } - // portals std::vector portal; @@ -518,4 +521,3 @@ int main(int nNbArg, char**ppArgs) return 1; } - From ac48221c8bda10da785ee73e49f7e09efe959dbf Mon Sep 17 00:00:00 2001 From: liria Date: Wed, 22 Jan 2014 23:49:11 +0000 Subject: [PATCH 5/5] CMakeLists.txt edited online with Bitbucket - remove merge conflict with default branche --HG-- branch : ig_elevaton_port_to_linux --- code/nel/tools/3d/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/nel/tools/3d/CMakeLists.txt b/code/nel/tools/3d/CMakeLists.txt index 52a69bd01..58360aec0 100644 --- a/code/nel/tools/3d/CMakeLists.txt +++ b/code/nel/tools/3d/CMakeLists.txt @@ -3,7 +3,6 @@ SUBDIRS( build_far_bank build_smallbank ig_lighter - ig_elevation zone_dependencies zone_ig_lighter zone_lighter @@ -27,7 +26,7 @@ SUBDIRS( zviewer) IF(WIN32) -# ADD_SUBDIRECTORY(ig_elevation) + ADD_SUBDIRECTORY(ig_elevation) ADD_SUBDIRECTORY(lightmap_optimizer) IF(MFC_FOUND)