kervala's enhancements and fixes for the Windows compilation.

This commit is contained in:
liria 2013-06-09 15:55:59 +02:00
parent c5f77a12df
commit 053abe4b07

View file

@ -38,9 +38,9 @@
#ifdef NL_OS_WINDOWS
#include <windows.h>
#else
#include <dirent.h>
#include <dirent.h> /* for directories functions */
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h> /* getcwd, chdir -- replacement for getCurDiretory & setCurDirectory on windows */
#endif
@ -141,7 +141,7 @@ void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
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);
@ -157,6 +157,17 @@ void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
}
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<string> &sAllFiles, bool bFullPath)
{
@ -166,30 +177,29 @@ void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
getcwd ( sCurDir, MAX_PATH ) ;
sAllFiles.clear ();
if ( (dp = opendir( sCurDir )) == NULL) {
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) {
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 (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);
}
#endif // endif posix version of "void dir(...)"
#endif
// ---------------------------------------------------------------------------
CZoneRegion *loadLand (const string &filename)
@ -316,7 +326,7 @@ int main(int nNbArg, char**ppArgs)
NL3D_BlockMemoryAssertOnPurge = false;
char sCurDir[MAX_PATH];
getcwd (sCurDir,MAX_PATH);
getcwd (sCurDir, MAX_PATH);
if (nNbArg != 2)
{
@ -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<string> vAllFiles;
chdir (options.InputIGDir.c_str());
#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)
@ -451,8 +457,6 @@ int main(int nNbArg, char**ppArgs)
uint k;
// elevate instance
for(k = 0; k < IA.size(); ++k)
{
@ -467,7 +471,6 @@ int main(int nNbArg, char**ppArgs)
PLN[k].setPosition( PLN[k].getPosition() + getHeightMapZ(lightPos.x, lightPos.y, zl, options, HeightMap1, HeightMap2) * CVector::K);
}
// portals
std::vector<CVector> portal;
for(k = 0; k < Portals.size(); ++k)
@ -518,4 +521,3 @@ int main(int nNbArg, char**ppArgs)
return 1;
}