Merge branch 'fixes' into main/gingo-test
[ryzomcore.git] / nel / tools / pacs / build_rbank / main.cpp
blob318a79131ae71511454083dcbdf0203800bcbcfa
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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"
41 #include <string>
42 #include <deque>
44 #include <stdlib.h>
46 using namespace std;
47 using namespace NLMISC;
48 using namespace NL3D;
50 #ifndef NL_BRB_CFG
51 #define NL_BRB_CFG "."
52 #endif // NL_BRB_CFG
54 #define LOG_ALL_INFO_TO_FILE
58 string OutputRootPath;
59 string OutputDirectory;
60 string OutputPath;
61 string TessellationPath;
62 string IGBoxes;
63 uint TessellateLevel;
64 bool ReduceSurfaces;
65 bool SmoothBorders;
66 bool ComputeElevation;
67 bool ComputeLevels;
68 vector<string> ZoneNames;
69 string ZoneExt;
70 string ZoneNHExt = ".zonenhw";
71 string ZoneLookUpPath;
72 bool ProcessAllPasses;
73 bool CheckPrims;
74 bool TessellateZones;
75 bool MoulineZones;
76 bool TessellateAndMoulineZones;
77 bool ProcessRetrievers;
78 string PreprocessDirectory;
79 float WaterThreshold = 0.0f;
80 bool UseZoneSquare;
81 string ZoneUL;
82 string ZoneDR;
83 string GlobalRetriever;
84 string RetrieverBank;
85 string GlobalUL;
86 string GlobalDR;
87 bool ProcessGlobal;
88 string LevelDesignWorldPath;
89 string IgLandPath;
90 string IgVillagePath;
91 bool Verbose = false;
92 bool CheckConsistency = true;
94 CPrimChecker PrimChecker;
96 /****************************************************************\
97 initMoulinette
98 \****************************************************************/
99 int getInt(CConfigFile &cf, const string &varName, int defaultValue=0)
101 CConfigFile::CVar *var = cf.getVarPtr(varName);
102 if (Verbose)
104 if (var)
105 nlinfo("Read %s = %d", varName.c_str(), var->asInt());
106 else
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);
115 if (Verbose)
117 if (var)
118 nlinfo("Read %s = %f", varName.c_str(), var->asFloat());
119 else
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);
128 if (Verbose)
130 if (var)
131 nlinfo("Read %s = '%s'", varName.c_str(), var->asString().c_str());
132 else
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);
141 if (Verbose)
143 if (var)
144 nlinfo("Read %s = %s", varName.c_str(), (var->asInt()!=0 ? "true" : "false"));
145 else
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()
155 registerSerial3d();
159 #ifdef NL_OS_UNIX
160 std::string homeDir = getenv("HOME");
161 NLMISC::CPath::addSearchPath( homeDir + "/.nel");
162 #endif // NL_OS_UNIX
164 NLMISC::CPath::addSearchPath(NL_BRB_CFG);
166 CConfigFile cf;
167 uint i;
169 cf.load("build_rbank.cfg");
171 CConfigFile::CVar *verboseVar = cf.getVarPtr("Verbose");
172 if (verboseVar && verboseVar->asInt() != 0)
173 Verbose = true;
176 // Read paths
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");
207 //if (MoulineZones)
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");
223 if (SmoothBorders)
224 OutputDirectory = getString(cf, "SmoothDirectory");
225 else
226 OutputDirectory = getString(cf, "RawDirectory");
228 OutputPath = OutputRootPath+OutputDirectory;
231 //if (ProcessGlobal)
233 GlobalRetriever = getString(cf, "GlobalRetriever");
234 RetrieverBank = getString(cf, "RetrieverBank");
235 GlobalUL = getString(cf, "GlobalUL");
236 GlobalDR = getString(cf, "GlobalDR");
240 ZoneNames.clear();
241 if (UseZoneSquare)
243 ZoneUL = getString(cf, "ZoneUL");
244 ZoneDR = getString(cf, "ZoneDR");
246 uint ul = getZoneIdByName(ZoneUL),
247 dr = getZoneIdByName(ZoneDR);
248 uint x0 = ul%256,
249 y0 = ul/256,
250 x1 = dr%256,
251 y1 = dr/256;
252 uint x, y;
253 for (y=y0; y<=y1; ++y)
254 for (x=x0; x<=x1; ++x)
255 ZoneNames.push_back(getZoneNameById(x+y*256));
257 else
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 /****************************************************************\
271 moulineZones
272 \****************************************************************/
273 void moulineZones(vector<string> &zoneNames)
275 uint i;
277 if (CheckPrims)
279 PrimChecker.build(LevelDesignWorldPath, IgLandPath, IgVillagePath);
282 PrimChecker.load();
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]);
295 if (ProcessGlobal)
297 nlinfo("Process .gr and .rbank");
298 processGlobalRetriever();
302 /****************************************************************\
303 MAIN
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
314 createDebug();
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");
322 #endif
326 // Init the moulinette
327 initMoulinette();
329 // Compute the zone surfaces
330 TTime before, after;
332 uint i;
333 if (argc > 1)
335 ZoneNames.clear();
336 for (i=1; i<(uint)argc; ++i)
338 if (argv[i][0] != '-')
340 ZoneNames.push_back(string(argv[i]));
342 else
344 switch (argv[i][1])
346 case 'C':
347 CheckPrims = true;
348 break;
349 case 'c':
350 CheckPrims = false;
351 break;
352 case 'P':
353 ProcessAllPasses = true;
354 break;
355 case 'p':
356 ProcessAllPasses = false;
357 break;
358 case 'G':
359 ProcessGlobal = true;
360 break;
361 case 'g':
362 ProcessGlobal = false;
363 break;
364 case 'T':
365 case 't':
366 case 'M':
367 case 'm':
368 case 'L':
369 case 'l':
370 nlwarning("Option %c is not more valid", argv[i][1]);
371 break;
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);
386 if (Verbose)
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 ());
393 #ifndef NL_DEBUG
394 /* catch (...)
396 nlwarning("main trapped an unknown exception\n");
398 #endif // NL_DEBUG
400 return 0;