1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "nel/misc/config_file.h"
27 #include "nel/misc/bit_mem_stream.h"
29 #include "sheets_packer_cfg.h"
35 //-----------------------------------------------
36 /// Macro to read a Bool from the CFG.
37 /// variableName : Variable Name to Read and Set.
38 //-----------------------------------------------
39 #define READ_BOOL(variableName) \
40 /* Read the Variable Value From Script */ \
41 varPtr = AppCfg.ConfigFile.getVarPtr(#variableName); \
42 /* Value found, set the Variable */ \
44 AppCfg.variableName = varPtr->asInt() ? true : false; \
45 /* Use the Default Value */ \
47 nlwarning("CFG: Default value used for '"#variableName"' !!!"); \
49 //-----------------------------------------------
50 /// Macro to read an Int from the CFG.
51 /// variableName : Variable Name to Read and Set.
52 //-----------------------------------------------
53 #define READ_INT(variableName) \
54 /* Read the Variable Value From Script */ \
55 varPtr = AppCfg.ConfigFile.getVarPtr(#variableName); \
56 /* Value found, set the Variable */ \
58 AppCfg.variableName = varPtr->asInt(); \
59 /* Use the Default Value */ \
61 nlwarning("CFG: Default value used for '"#variableName"' !!!"); \
63 //-----------------------------------------------
64 /// Macro to read a Float from the CFG.
65 /// variableName : Variable Name to Read and Set.
66 //-----------------------------------------------
67 #define READ_FLOAT(variableName) \
68 /* Read the Variable Value From Script */ \
69 varPtr = AppCfg.ConfigFile.getVarPtr(#variableName); \
70 /* Value found, set the Variable */ \
72 AppCfg.variableName = varPtr->asFloat(); \
73 /* Use the Default Value */ \
75 nlwarning("CFG: Default value used for '"#variableName"' !!!"); \
77 //-----------------------------------------------
78 /// Macro to read a Double from the CFG.
79 /// variableName : Variable Name to Read and Set.
80 //-----------------------------------------------
81 #define READ_DOUBLE(variableName) \
82 /* Read the Variable Value From Script */ \
83 varPtr = AppCfg.ConfigFile.getVarPtr(#variableName); \
84 /* Value found, set the Variable */ \
86 AppCfg.variableName = varPtr->asDouble(); \
87 /* Use the Default Value */ \
89 nlwarning("CFG: Default value used for '"#variableName"' !!!"); \
91 //-----------------------------------------------
92 /// Macro to read a String from the CFG.
93 /// variableName : Variable Name to Read and Set.
94 //-----------------------------------------------
95 #define READ_STRING(variableName) \
96 /* Read the Variable Value From Script */ \
97 varPtr = AppCfg.ConfigFile.getVarPtr(#variableName); \
98 /* Value found, set the Variable */ \
100 AppCfg.variableName = varPtr->asString(); \
101 /* Use the Default Value */ \
103 nlwarning("CFG: Default value used for '"#variableName"' !!!"); \
105 //-----------------------------------------------
106 /// Macro to read a CVector from the CFG.
107 /// variableName : Variable Name to Read and Set.
108 //-----------------------------------------------
109 #define READ_CVECTOR(variableName) \
110 /* Read the Variable Value From Script */ \
111 varPtr = AppCfg.ConfigFile.getVarPtr(#variableName); \
115 if(varPtr->size()==3) \
117 AppCfg.variableName.x = varPtr->asFloat(0); \
118 AppCfg.variableName.y = varPtr->asFloat(1); \
119 AppCfg.variableName.z = varPtr->asFloat(2); \
122 nlwarning("CFG: Bad params for '"#variableName"' !!!"); \
125 nlwarning("CFG: Default value used for '"#variableName"' !!!"); \
131 using namespace NLMISC
;
137 CClientConfig AppCfg
;
138 const std::string ConfigFileName
= "sheets_packer.cfg";
144 //---------------------------------------------------
147 //---------------------------------------------------
148 CClientConfig::CClientConfig()
150 DumpVisualSlotsIndex
= false;
154 //---------------------------------------------------
156 // Load the client config file.
157 //---------------------------------------------------
160 nlinfo ("reloading the config file!");
162 CConfigFile::CVar
*varPtr
= 0;
169 AppCfg
.DataPath
.clear ();
170 CConfigFile::CVar
&cvDataPath
= AppCfg
.ConfigFile
.getVar("DataPath");
171 for (uint i
= 0; i
< cvDataPath
.size(); i
++)
172 AppCfg
.DataPath
.push_back(cvDataPath
.asString(i
));
174 catch(const EUnknownVar
&) {nlwarning("Default value used for 'DataPath' !!!");}
177 READ_STRING(WorldSheet
)
179 READ_STRING(PrimitivesPath
)
181 READ_STRING(OutputDataPath
)
182 // Ligo primitive class
183 READ_STRING(LigoPrimitiveClass
)
184 //Dump VisualSlots index
185 READ_BOOL(DumpVisualSlotsIndex
)
192 CConfigFile::CVar
&cvTmp
= AppCfg
.ConfigFile
.getVar("NegFiltersDebug");
193 for(uint k
= 0; k
< (uint
)cvTmp
.size(); ++k
)
195 DebugLog
->addNegativeFilter (cvTmp
.asString(k
).c_str());
198 catch(const EUnknownVar
&) {}
201 CConfigFile::CVar
&cvTmp
= AppCfg
.ConfigFile
.getVar("NegFiltersInfo");
202 for(uint k
= 0; k
< (uint
)cvTmp
.size(); ++k
)
204 InfoLog
->addNegativeFilter (cvTmp
.asString(k
).c_str());
207 catch(const EUnknownVar
&) {}
210 CConfigFile::CVar
&cvTmp
= AppCfg
.ConfigFile
.getVar("NegFiltersWarning");
211 for(uint k
= 0; k
< (uint
)cvTmp
.size(); ++k
)
213 WarningLog
->addNegativeFilter (cvTmp
.asString(k
).c_str());
216 catch(const EUnknownVar
&) {}
220 //-----------------------------------------------
223 //-----------------------------------------------
224 void CClientConfig::serial(NLMISC::IStream
&f
)
226 // Start the opening of a new node named ClientCFG.
227 f
.xmlPush("ClientCFG");
229 // Close the serial for hte Client CFG.
234 //-----------------------------------------------
236 //-----------------------------------------------
237 void CClientConfig::init(const std::string
&configFileName
)
239 if(!CFile::fileExists(configFileName
))
240 nlwarning("CFG::init: '%s' Not Found !!!", configFileName
.c_str ());
242 // if the config file will be modified, it calls automatically the function setValues()
243 AppCfg
.ConfigFile
.setCallback (setValues
);
245 // load the config files
246 AppCfg
.ConfigFile
.load (configFileName
);
250 //-----------------------------------------------
252 //-----------------------------------------------
253 void CClientConfig::release ()