1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "nel/misc/types_nl.h"
21 #include "nel/misc/time_nl.h"
22 #include "nel/misc/config_file.h"
23 #include "nel/misc/debug.h"
24 #include "nel/misc/path.h"
25 #include "nel/misc/common.h"
26 #include "nel/misc/displayer.h"
27 #include "nel/misc/file.h"
29 #include "nel/3d/register_3d.h"
31 #include "build_surf.h"
32 #include "build_rbank.h"
33 #include "prim_checker.h"
35 #include "nel/pacs/global_retriever.h"
36 #include "nel/pacs/retriever_bank.h"
37 #include "nel/pacs/surface_quad.h"
38 #include "nel/pacs/local_retriever.h"
39 #include "nel/pacs/retriever_instance.h"
47 using namespace NLMISC
;
51 #define NL_BRB_CFG "."
54 #define LOG_ALL_INFO_TO_FILE
58 string OutputRootPath
;
59 string OutputDirectory
;
61 string TessellationPath
;
66 bool ComputeElevation
;
68 vector
<string
> ZoneNames
;
70 string ZoneNHExt
= ".zonenhw";
71 string ZoneLookUpPath
;
72 bool ProcessAllPasses
;
76 bool TessellateAndMoulineZones
;
77 bool ProcessRetrievers
;
78 string PreprocessDirectory
;
79 float WaterThreshold
= 0.0f
;
83 string GlobalRetriever
;
88 string LevelDesignWorldPath
;
92 bool CheckConsistency
= true;
94 CPrimChecker PrimChecker
;
96 /****************************************************************\
98 \****************************************************************/
99 int getInt(CConfigFile
&cf
, const string
&varName
, int defaultValue
=0)
101 CConfigFile::CVar
*var
= cf
.getVarPtr(varName
);
105 nlinfo("Read %s = %d", varName
.c_str(), var
->asInt());
107 nlinfo("Couldn't read %s, using default = %d", varName
.c_str(), defaultValue
);
109 return var
? var
->asInt() : defaultValue
;
112 float getFloat(CConfigFile
&cf
, const string
&varName
, float defaultValue
=0.0)
114 CConfigFile::CVar
*var
= cf
.getVarPtr(varName
);
118 nlinfo("Read %s = %f", varName
.c_str(), var
->asFloat());
120 nlinfo("Couldn't read %s, using default = %f", varName
.c_str(), defaultValue
);
122 return var
? var
->asFloat() : defaultValue
;
125 string
getString(CConfigFile
&cf
, const string
&varName
, const string
&defaultValue
="")
127 CConfigFile::CVar
*var
= cf
.getVarPtr(varName
);
131 nlinfo("Read %s = '%s'", varName
.c_str(), var
->asString().c_str());
133 nlinfo("Couldn't read %s, using default = '%s'", varName
.c_str(), defaultValue
.c_str());
135 return var
? var
->asString() : defaultValue
;
138 bool getBool(CConfigFile
&cf
, const string
&varName
, bool defaultValue
=false)
140 CConfigFile::CVar
*var
= cf
.getVarPtr(varName
);
144 nlinfo("Read %s = %s", varName
.c_str(), (var
->asInt()!=0 ? "true" : "false"));
146 nlinfo("Couldn't read %s, using default = '%s'", varName
.c_str(), (defaultValue
? "true" : "false"));
148 return var
? (var
->asInt() != 0) : defaultValue
;
153 void initMoulinette()
160 std::string homeDir
= getenv("HOME");
161 NLMISC::CPath::addSearchPath( homeDir
+ "/.nel");
164 NLMISC::CPath::addSearchPath(NL_BRB_CFG
);
169 cf
.load("build_rbank.cfg");
171 CConfigFile::CVar
*verboseVar
= cf
.getVarPtr("Verbose");
172 if (verboseVar
&& verboseVar
->asInt() != 0)
177 CConfigFile::CVar
*cvPathes
= cf
.getVarPtr("Pathes");
178 for (i
=0; cvPathes
!= NULL
&& i
<cvPathes
->size(); ++i
)
179 CPath::addSearchPath(cvPathes
->asString(i
));
181 ProcessAllPasses
= getBool(cf
, "ProcessAllPasses", false);
182 CheckPrims
= getBool(cf
, "CheckPrims", false);
183 TessellateZones
= getBool(cf
, "TessellateZones", false);
184 MoulineZones
= getBool(cf
, "MoulineZones", false);
185 TessellateAndMoulineZones
= getBool(cf
, "TessellateAndMoulineZones", false);
186 ProcessRetrievers
= getBool(cf
, "ProcessRetrievers", false);
187 ProcessGlobal
= getBool(cf
, "ProcessGlobal", false);
189 OutputRootPath
= getString(cf
, "OutputRootPath");
190 UseZoneSquare
= getBool(cf
, "UseZoneSquare", false);
192 WaterThreshold
= getFloat(cf
, "WaterThreshold", 1.0);
194 CheckConsistency
= getBool(cf
, "CheckConsistency", true);
196 //if (TessellateZones || MoulineZones)
198 ZoneExt
= getString(cf
, "ZoneExt", ".zonew");
199 ZoneNHExt
= getString(cf
, "ZoneNHExt", ".zonenhw");
200 ZoneLookUpPath
= getString(cf
, "ZonePath", "./");
201 CPath::addSearchPath(ZoneLookUpPath
);
203 TessellationPath
= getString(cf
, "TessellationPath");
204 TessellateLevel
= getInt(cf
, "TessellateLevel");
209 LevelDesignWorldPath
= getString(cf
, "LevelDesignWorldPath");
210 IgLandPath
= getString(cf
, "IgLandPath");
211 IgVillagePath
= getString(cf
, "IgVillagePath");
212 IGBoxes
= getString(cf
, "IGBoxes", "./temp.bbox");
213 ReduceSurfaces
= getBool(cf
, "ReduceSurfaces", true);
214 ComputeElevation
= getBool(cf
, "ComputeElevation", false);
215 ComputeLevels
= getBool(cf
, "ComputeLevels", true);
218 //if (MoulineZones || ProcessRetrievers || ProcessGlobal)
220 SmoothBorders
= getBool(cf
, "SmoothBorders", true);
221 PreprocessDirectory
= getString(cf
, "PreprocessDirectory");
224 OutputDirectory
= getString(cf
, "SmoothDirectory");
226 OutputDirectory
= getString(cf
, "RawDirectory");
228 OutputPath
= OutputRootPath
+OutputDirectory
;
233 GlobalRetriever
= getString(cf
, "GlobalRetriever");
234 RetrieverBank
= getString(cf
, "RetrieverBank");
235 GlobalUL
= getString(cf
, "GlobalUL");
236 GlobalDR
= getString(cf
, "GlobalDR");
243 ZoneUL
= getString(cf
, "ZoneUL");
244 ZoneDR
= getString(cf
, "ZoneDR");
246 uint ul
= getZoneIdByName(ZoneUL
),
247 dr
= getZoneIdByName(ZoneDR
);
253 for (y
=y0
; y
<=y1
; ++y
)
254 for (x
=x0
; x
<=x1
; ++x
)
255 ZoneNames
.push_back(getZoneNameById(x
+y
*256));
259 CConfigFile::CVar
*cvZones
= cf
.getVarPtr("Zones");
260 for (i
=0; cvZones
!= NULL
&& i
<cvZones
->size(); i
++)
261 ZoneNames
.push_back(cvZones
->asString(i
));
264 catch (const EConfigFile
&e
)
266 nlwarning("Problem in config file : %s\n", e
.what ());
270 /****************************************************************\
272 \****************************************************************/
273 void moulineZones(vector
<string
> &zoneNames
)
279 PrimChecker
.build(LevelDesignWorldPath
, IgLandPath
, IgVillagePath
);
284 if (ProcessAllPasses
)
287 for (i
=0; i
<zoneNames
.size(); ++i
)
289 nlinfo("Generate final .lr for zone %s", zoneNames
[i
].c_str());
290 processAllPasses(zoneNames
[i
]);
297 nlinfo("Process .gr and .rbank");
298 processGlobalRetriever();
302 /****************************************************************\
304 \****************************************************************/
305 int main(int argc
, char **argv
)
307 // Filter addSearchPath
308 NLMISC::createDebug();
309 InfoLog
->addNegativeFilter ("adding the path");
311 CFileDisplayer
fd(getLogDirectory() + "evallog.log", true);
313 #ifdef LOG_ALL_INFO_TO_FILE
315 DebugLog
->addDisplayer (&fd
);
316 ErrorLog
->addDisplayer (&fd
);
317 WarningLog
->addDisplayer (&fd
);
318 InfoLog
->addDisplayer (&fd
);
319 AssertLog
->addDisplayer (&fd
);
321 ErrorLog
->removeDisplayer("DEFAULT_MBD");
326 // Init the moulinette
329 // Compute the zone surfaces
336 for (i
=1; i
<(uint
)argc
; ++i
)
338 if (argv
[i
][0] != '-')
340 ZoneNames
.push_back(string(argv
[i
]));
353 ProcessAllPasses
= true;
356 ProcessAllPasses
= false;
359 ProcessGlobal
= true;
362 ProcessGlobal
= false;
370 nlwarning("Option %c is not more valid", argv
[i
][1]);
377 before
= CTime::getLocalTime();
378 moulineZones(ZoneNames
);
379 after
= CTime::getLocalTime();
381 uint totalSeconds
= (uint
)((after
-before
)/1000);
382 uint workDay
= totalSeconds
/86400,
383 workHour
= (totalSeconds
-86400*workDay
)/3600,
384 workMinute
= (totalSeconds
-86400*workDay
-3600*workHour
)/60,
385 workSecond
= (totalSeconds
-86400*workDay
-3600*workHour
-60*workMinute
);
387 nlinfo("total computation time: %d days, %d hours, %d minutes and %d seconds", workDay
, workHour
, workMinute
, workSecond
);
389 catch (const Exception
&e
)
391 nlwarning ("main trapped an exception: '%s'\n", e
.what ());
396 nlwarning("main trapped an unknown exception\n");