Merged in liria/khanat/ig_elevaton_port_to_linux (pull request #46)
Port of ig_elevation to linux
This commit is contained in:
commit
1c6e90c000
1 changed files with 78 additions and 25 deletions
|
@ -35,7 +35,14 @@
|
||||||
|
|
||||||
#include "nel/3d/scene_group.h"
|
#include "nel/3d/scene_group.h"
|
||||||
|
|
||||||
|
#ifdef NL_OS_WINDOWS
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <dirent.h> /* for directories functions */
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h> /* getcwd, chdir -- replacement for getCurDiretory & setCurDirectory on windows */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -126,6 +133,7 @@ struct CZoneLimits
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
#ifdef NL_OS_WINDOWS // win32 code
|
||||||
void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
|
void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA findData;
|
WIN32_FIND_DATA findData;
|
||||||
|
@ -133,7 +141,7 @@ void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
|
||||||
char sCurDir[MAX_PATH];
|
char sCurDir[MAX_PATH];
|
||||||
sAllFiles.clear ();
|
sAllFiles.clear ();
|
||||||
GetCurrentDirectory (MAX_PATH, sCurDir);
|
GetCurrentDirectory (MAX_PATH, sCurDir);
|
||||||
hFind = FindFirstFile (sFilter.c_str(), &findData);
|
hFind = FindFirstFile (("*"+sFilter).c_str(), &findData);
|
||||||
while (hFind != INVALID_HANDLE_VALUE)
|
while (hFind != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
DWORD res = GetFileAttributes(findData.cFileName);
|
DWORD res = GetFileAttributes(findData.cFileName);
|
||||||
|
@ -150,6 +158,48 @@ void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
|
||||||
FindClose (hFind);
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
sAllFiles.push_back(string(sCurDir) + "/" + sFileName);
|
||||||
|
else
|
||||||
|
sAllFiles.push_back(sFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
closedir(dp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
CZoneRegion *loadLand (const string &filename)
|
CZoneRegion *loadLand (const string &filename)
|
||||||
|
@ -222,12 +272,14 @@ void SaveInstanceGroup (const char* sFilename, CInstanceGroup *pIG)
|
||||||
}
|
}
|
||||||
catch (const Exception &e)
|
catch (const Exception &e)
|
||||||
{
|
{
|
||||||
outString(string(e.what()));
|
string stTmp = string(e.what()) ;
|
||||||
|
outString( stTmp );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
outString(string("Couldn't create ") + sFilename);
|
string stTemp = string("Couldn't create ") + string(sFilename) ;
|
||||||
|
outString( stTemp );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +326,7 @@ int main(int nNbArg, char**ppArgs)
|
||||||
|
|
||||||
NL3D_BlockMemoryAssertOnPurge = false;
|
NL3D_BlockMemoryAssertOnPurge = false;
|
||||||
char sCurDir[MAX_PATH];
|
char sCurDir[MAX_PATH];
|
||||||
GetCurrentDirectory (MAX_PATH, sCurDir);
|
getcwd (sCurDir, MAX_PATH);
|
||||||
|
|
||||||
if (nNbArg != 2)
|
if (nNbArg != 2)
|
||||||
{
|
{
|
||||||
|
@ -322,7 +374,7 @@ int main(int nNbArg, char**ppArgs)
|
||||||
|
|
||||||
// Load the 2 height maps
|
// Load the 2 height maps
|
||||||
CBitmap *HeightMap1 = NULL;
|
CBitmap *HeightMap1 = NULL;
|
||||||
if (options.HeightMapFile1 != "")
|
if (!options.HeightMapFile1.empty())
|
||||||
{
|
{
|
||||||
HeightMap1 = new CBitmap;
|
HeightMap1 = new CBitmap;
|
||||||
try
|
try
|
||||||
|
@ -334,7 +386,9 @@ int main(int nNbArg, char**ppArgs)
|
||||||
}
|
}
|
||||||
else
|
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;
|
delete HeightMap1;
|
||||||
HeightMap1 = NULL;
|
HeightMap1 = NULL;
|
||||||
}
|
}
|
||||||
|
@ -348,7 +402,7 @@ int main(int nNbArg, char**ppArgs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CBitmap *HeightMap2 = NULL;
|
CBitmap *HeightMap2 = NULL;
|
||||||
if (options.HeightMapFile2 != "")
|
if (!options.HeightMapFile2.empty())
|
||||||
{
|
{
|
||||||
HeightMap2 = new CBitmap;
|
HeightMap2 = new CBitmap;
|
||||||
try
|
try
|
||||||
|
@ -360,7 +414,9 @@ int main(int nNbArg, char**ppArgs)
|
||||||
}
|
}
|
||||||
else
|
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;
|
delete HeightMap2;
|
||||||
HeightMap2 = NULL;
|
HeightMap2 = NULL;
|
||||||
}
|
}
|
||||||
|
@ -376,15 +432,15 @@ int main(int nNbArg, char**ppArgs)
|
||||||
|
|
||||||
// Get all files
|
// Get all files
|
||||||
vector<string> vAllFiles;
|
vector<string> vAllFiles;
|
||||||
SetCurrentDirectory (options.InputIGDir.c_str());
|
chdir (options.InputIGDir.c_str());
|
||||||
dir ("*.ig", vAllFiles, false);
|
dir (".ig", vAllFiles, false);
|
||||||
SetCurrentDirectory (sCurDir);
|
chdir (sCurDir);
|
||||||
|
|
||||||
for (uint32 i = 0; i < vAllFiles.size(); ++i)
|
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());
|
CInstanceGroup *pIG = LoadInstanceGroup (vAllFiles[i].c_str());
|
||||||
SetCurrentDirectory (sCurDir);
|
chdir (sCurDir);
|
||||||
if (pIG != NULL)
|
if (pIG != NULL)
|
||||||
{
|
{
|
||||||
bool realTimeSunContribution = pIG->getRealTimeSunContribution();
|
bool realTimeSunContribution = pIG->getRealTimeSunContribution();
|
||||||
|
@ -401,8 +457,6 @@ int main(int nNbArg, char**ppArgs)
|
||||||
|
|
||||||
uint k;
|
uint k;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// elevate instance
|
// elevate instance
|
||||||
for(k = 0; k < IA.size(); ++k)
|
for(k = 0; k < IA.size(); ++k)
|
||||||
{
|
{
|
||||||
|
@ -417,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);
|
PLN[k].setPosition( PLN[k].getPosition() + getHeightMapZ(lightPos.x, lightPos.y, zl, options, HeightMap1, HeightMap2) * CVector::K);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// portals
|
// portals
|
||||||
std::vector<CVector> portal;
|
std::vector<CVector> portal;
|
||||||
for(k = 0; k < Portals.size(); ++k)
|
for(k = 0; k < Portals.size(); ++k)
|
||||||
|
@ -459,9 +512,9 @@ int main(int nNbArg, char**ppArgs)
|
||||||
pIGout->enableRealTimeSunContribution(realTimeSunContribution);
|
pIGout->enableRealTimeSunContribution(realTimeSunContribution);
|
||||||
|
|
||||||
|
|
||||||
SetCurrentDirectory (options.OutputIGDir.c_str());
|
chdir (options.OutputIGDir.c_str());
|
||||||
SaveInstanceGroup (vAllFiles[i].c_str(), pIGout);
|
SaveInstanceGroup (vAllFiles[i].c_str(), pIGout);
|
||||||
SetCurrentDirectory (sCurDir);
|
chdir (sCurDir);
|
||||||
delete pIG;
|
delete pIG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue