mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-15 12:09:06 +00:00
Changed: Don't need to use system API, NeL already has equivalent
This commit is contained in:
parent
871a856c72
commit
20e065cfeb
1 changed files with 27 additions and 110 deletions
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "nel/misc/config_file.h"
|
#include "nel/misc/config_file.h"
|
||||||
#include "nel/misc/file.h"
|
#include "nel/misc/file.h"
|
||||||
|
#include "nel/misc/path.h"
|
||||||
#include "nel/misc/bitmap.h"
|
#include "nel/misc/bitmap.h"
|
||||||
#include "nel/misc/block_memory.h"
|
#include "nel/misc/block_memory.h"
|
||||||
#include "nel/misc/i_xml.h"
|
#include "nel/misc/i_xml.h"
|
||||||
|
@ -35,15 +36,6 @@
|
||||||
|
|
||||||
#include "nel/3d/scene_group.h"
|
#include "nel/3d/scene_group.h"
|
||||||
|
|
||||||
#ifdef NL_OS_WINDOWS
|
|
||||||
#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
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -132,75 +124,6 @@ struct CZoneLimits
|
||||||
sint32 _ZoneMaxY;
|
sint32 _ZoneMaxY;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
#ifdef NL_OS_WINDOWS // win32 code
|
|
||||||
void dir (const string &sFilter, vector<string> &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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -219,21 +142,19 @@ CZoneRegion *loadLand (const string &filename)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string sTmp = string("Can't open the land file : ") + filename;
|
outString (toString("Can't open the land files: %s", filename.c_str()));
|
||||||
outString (sTmp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const Exception& e)
|
catch (const Exception& e)
|
||||||
{
|
{
|
||||||
string sTmp = string("Error in land file : ") + e.what();
|
outString(toString("Error in land file: %s", e.what()));
|
||||||
outString (sTmp);
|
|
||||||
}
|
}
|
||||||
return ZoneRegion;
|
return ZoneRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
CInstanceGroup* LoadInstanceGroup (const char* sFilename)
|
CInstanceGroup* LoadInstanceGroup (const std::string &sFilename)
|
||||||
{
|
{
|
||||||
CIFile file;
|
CIFile file;
|
||||||
CInstanceGroup *newIG = new CInstanceGroup;
|
CInstanceGroup *newIG = new CInstanceGroup;
|
||||||
|
@ -260,7 +181,7 @@ CInstanceGroup* LoadInstanceGroup (const char* sFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void SaveInstanceGroup (const char* sFilename, CInstanceGroup *pIG)
|
void SaveInstanceGroup (const std::string &sFilename, CInstanceGroup *pIG)
|
||||||
{
|
{
|
||||||
COFile file;
|
COFile file;
|
||||||
|
|
||||||
|
@ -272,14 +193,12 @@ void SaveInstanceGroup (const char* sFilename, CInstanceGroup *pIG)
|
||||||
}
|
}
|
||||||
catch (const Exception &e)
|
catch (const Exception &e)
|
||||||
{
|
{
|
||||||
string stTmp = string(e.what()) ;
|
outString(e.what());
|
||||||
outString( stTmp );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string stTemp = string("Couldn't create ") + string(sFilename) ;
|
outString(toString("Couldn't create %s", sFilename.c_str()));
|
||||||
outString( stTemp );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,8 +244,7 @@ int main(int nNbArg, char**ppArgs)
|
||||||
new CApplicationContext();
|
new CApplicationContext();
|
||||||
|
|
||||||
NL3D_BlockMemoryAssertOnPurge = false;
|
NL3D_BlockMemoryAssertOnPurge = false;
|
||||||
char sCurDir[MAX_PATH];
|
std::string sCurDir = CPath::getCurrentPath();
|
||||||
getcwd (sCurDir, MAX_PATH);
|
|
||||||
|
|
||||||
if (nNbArg != 2)
|
if (nNbArg != 2)
|
||||||
{
|
{
|
||||||
|
@ -386,17 +304,14 @@ int main(int nNbArg, char**ppArgs)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string sTmp = string("Couldn't not open ")+string(options.HeightMapFile1)
|
outString(toString("Couldn't not open %s: heightmap 1 map ignored", options.HeightMapFile1.c_str()));
|
||||||
+string(" : heightmap 1 map ignored");
|
|
||||||
outString(sTmp);
|
|
||||||
delete HeightMap1;
|
delete HeightMap1;
|
||||||
HeightMap1 = NULL;
|
HeightMap1 = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const Exception &e)
|
catch (const Exception &e)
|
||||||
{
|
{
|
||||||
string sTmp = string("Cant load height map : ") + options.HeightMapFile1 + " : " + e.what();
|
outString(toString("Cant load height map : %s : %s", options.HeightMapFile1.c_str(), e.what()));
|
||||||
outString (sTmp);
|
|
||||||
delete HeightMap1;
|
delete HeightMap1;
|
||||||
HeightMap1 = NULL;
|
HeightMap1 = NULL;
|
||||||
}
|
}
|
||||||
|
@ -414,33 +329,37 @@ int main(int nNbArg, char**ppArgs)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string sTmp = string("Couldn't not open ")+string(options.HeightMapFile2)
|
outString(toString("Couldn't not open %s: heightmap 2 map ignored", options.HeightMapFile2.c_str()));
|
||||||
+string(" : heightmap 2 map ignored\n");
|
|
||||||
outString(sTmp);
|
|
||||||
delete HeightMap2;
|
delete HeightMap2;
|
||||||
HeightMap2 = NULL;
|
HeightMap2 = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const Exception &e)
|
catch (const Exception &e)
|
||||||
{
|
{
|
||||||
string sTmp = string("Cant load height map : ") + options.HeightMapFile2 + " : " + e.what() + "\n";
|
outString (string("Cant load height map : ") + options.HeightMapFile2 + " : " + e.what() + "\n");
|
||||||
outString (sTmp);
|
|
||||||
delete HeightMap2;
|
delete HeightMap2;
|
||||||
HeightMap1 = NULL;
|
HeightMap1 = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all files
|
// get all files
|
||||||
|
vector<string> vAllFilesUnfiltered;
|
||||||
|
CPath::getPathContent(options.InputIGDir, false, false, true, vAllFilesUnfiltered);
|
||||||
|
|
||||||
|
// keep only .ig files
|
||||||
vector<string> vAllFiles;
|
vector<string> vAllFiles;
|
||||||
chdir (options.InputIGDir.c_str());
|
for(uint i = 0, len = (uint)vAllFilesUnfiltered.size(); i < len; ++i)
|
||||||
dir (".ig", vAllFiles, false);
|
{
|
||||||
chdir (sCurDir);
|
if (toLower(CFile::getExtension(vAllFilesUnfiltered[i])) == "ig")
|
||||||
|
{
|
||||||
|
vAllFiles.push_back(vAllFilesUnfiltered[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32 i = 0; i < vAllFiles.size(); ++i)
|
for (uint32 i = 0; i < vAllFiles.size(); ++i)
|
||||||
{
|
{
|
||||||
chdir (options.InputIGDir.c_str());
|
CInstanceGroup *pIG = LoadInstanceGroup (CPath::standardizePath(options.InputIGDir) + vAllFiles[i]);
|
||||||
CInstanceGroup *pIG = LoadInstanceGroup (vAllFiles[i].c_str());
|
|
||||||
chdir (sCurDir);
|
|
||||||
if (pIG != NULL)
|
if (pIG != NULL)
|
||||||
{
|
{
|
||||||
bool realTimeSunContribution = pIG->getRealTimeSunContribution();
|
bool realTimeSunContribution = pIG->getRealTimeSunContribution();
|
||||||
|
@ -511,10 +430,8 @@ int main(int nNbArg, char**ppArgs)
|
||||||
pIGout->build (vGlobalPos, IA, Clusters, Portals, PLN);
|
pIGout->build (vGlobalPos, IA, Clusters, Portals, PLN);
|
||||||
pIGout->enableRealTimeSunContribution(realTimeSunContribution);
|
pIGout->enableRealTimeSunContribution(realTimeSunContribution);
|
||||||
|
|
||||||
|
SaveInstanceGroup (CPath::standardizePath(options.OutputIGDir) + vAllFiles[i], pIGout);
|
||||||
|
|
||||||
chdir (options.OutputIGDir.c_str());
|
|
||||||
SaveInstanceGroup (vAllFiles[i].c_str(), pIGout);
|
|
||||||
chdir (sCurDir);
|
|
||||||
delete pIG;
|
delete pIG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue