Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
SCfgFileManager.cpp
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of SkyX.
4Visit ---
5
6Copyright (C) 2008 Xavier Vergu�n Gonz�lez <xavierverguin@hotmail.com>
7 <xavyiy@gmail.com>
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU Lesser General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://www.gnu.org/copyleft/lesser.txt.
22--------------------------------------------------------------------------------
23*/
24
25#include "SCfgFileManager.h"
26#include "SkyX.h"
27
28namespace SkyX
29{
31 : mSkyX(s), mController(c), mCamera(d)
32 {
33 }
34
38
39 const bool CfgFileManager::load(const Ogre::String& File) const
40 {
41 std::pair<bool, Ogre::ConfigFile> CfgFileResult;
42 _loadCfgFile(File, CfgFileResult);
43
44 if (!CfgFileResult.first)
45 {
46 return false;
47 }
48
49 Ogre::ConfigFile &CfgFile = CfgFileResult.second;
50
51 if (!_checkVersion(CfgFile))
52 {
53 return false;
54 }
55
56
57 mSkyX->setTimeMultiplier(_getFloatValue(CfgFile, "TimeMultiplier"));
58 mController->setTime(_getVector3Value(CfgFile, "Time"));
59 mController->setMoonPhase(_getFloatValue(CfgFile, "MoonPhase"));
60
63 _getFloatValue(CfgFile, "_InnerRadius"),
64 _getFloatValue(CfgFile, "_OuterRadius"),
65 _getFloatValue(CfgFile, "_HeightPosition"),
66 _getFloatValue(CfgFile, "_RayleighMultiplier"),
67 _getFloatValue(CfgFile, "_MieMultiplier"),
68 _getFloatValue(CfgFile, "_SunIntensity"),
69 _getVector3Value(CfgFile, "_WaveLength"),
70 _getFloatValue(CfgFile, "_G"),
71 _getFloatValue(CfgFile, "_Exposure"),
72 _getFloatValue(CfgFile, "_NumerOfSamples")
73 ));
74
75 // Layered clouds
76 if (_getBoolValue(CfgFile, "layeredclouds") && !_getBoolValue(CfgFile, "volClouds"))
77 {
78 // Create layer cloud
79 if (mSkyX->getCloudsManager()->getCloudLayers().empty())
80 {
82 _getFloatValue(CfgFile, "lHeight"),
83 _getFloatValue(CfgFile, "Scale"),
84 _getVector2Value(CfgFile, "WindDirection"),
85 _getFloatValue(CfgFile, "TimeMultiplier"),
86 _getFloatValue(CfgFile, "DistanceAttenuation"),
87 _getFloatValue(CfgFile, "DetailAttenuation"),
88 _getFloatValue(CfgFile, "HeightVolume"),
89 _getFloatValue(CfgFile, "VolumetricDisplacement")
90 ));
91 }
92 }
93 else
94 {
95 mSkyX->getVCloudsManager()->setWindSpeed(_getFloatValue(CfgFile, "WindSpeed"));
96 mSkyX->getVCloudsManager()->setAutoupdate(_getBoolValue(CfgFile, "AutoUpdate"));
97 mSkyX->getVCloudsManager()->setHeight(_getVector2Value(CfgFile, "vHeight"));
98
100
101 vclouds->setWindDirection(_getDegreeValue(CfgFile, "WindDirection"));
102
103 vclouds->setAmbientColor(_getVector3Value(CfgFile, "AmbientColor"));
104 vclouds->setLightResponse(_getVector4Value(CfgFile, "LightResponse"));
105 vclouds->setAmbientFactors(_getVector4Value(CfgFile, "AmbientFactors"));
106 vclouds->setWheater(_getVector2Value(CfgFile, "Wheater").x, _getVector2Value(CfgFile, "Wheater").y, _getBoolValue(CfgFile, "DelayedResponse"));
107
108 // Create VClouds
110 {
111 // SkyX::MeshManager::getSkydomeRadius(...) works for both finite and infinite(=0) camera far clip distances
113 }
114
115 vclouds->getLightningManager()->setEnabled(_getBoolValue(CfgFile, "lightnings"));
116
117 if (vclouds->getLightningManager()->isEnabled())
118 {
119 vclouds->getLightningManager()->setAverageLightningApparitionTime(_getFloatValue(CfgFile, "AverageLightningApparitionTime"));
120 vclouds->getLightningManager()->setLightningColor(_getVector3Value(CfgFile, "LightningColor"));
121 vclouds->getLightningManager()->setLightningTimeMultiplier(_getFloatValue(CfgFile, "LightningTimeMultiplier"));
122 }
123 }
124 return true;
125 }
126
127 const bool CfgFileManager::save(const Ogre::String& File, const Ogre::String& Path) const
128 {
129 Ogre::String Data =
130 "#SkyX cfg file.\n\n";
131
132 Data += "#SkyX version field\n";
133 Data += _getVersionCfgString();
134
135 return _saveToFile(Data, File, Path);
136 }
137
138 const bool CfgFileManager::_saveToFile(const Ogre::String& Data, const Ogre::String& File, const Ogre::String& Path) const
139 {
140 FILE *DestinationFile = fopen((Path+"/"+File).c_str(), "w");
141
142 if (!DestinationFile)
143 {
144 return false;
145 }
146
147 fprintf(DestinationFile, "%s", Data.c_str());
148 fclose(DestinationFile);
149
150 SkyXLOG(File + " saved in " + Path + " .");
151
152 return true;
153 }
154
155 const void CfgFileManager::_loadCfgFile(const Ogre::String& File, std::pair<bool,Ogre::ConfigFile> &Result) const
156 {
157 try
158 {
159 Result.second.load(Ogre::ResourceGroupManager::getSingleton().openResource(File, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME));
160 Result.first = true;
161
162 } catch(...)
163 {
164 SkyXLOG("CfgFileManager::_getCfgFile(...): " + File + " not found in any resource group.");
165 Result.first = false;
166 }
167
168 SkyXLOG(File + " loaded.");
169 }
170
171 Ogre::String CfgFileManager::_getCfgString(const Ogre::String &Name, const int &Value)
172 {
173 return "<int>" + Name + "=" + Ogre::StringConverter::toString(Value) + "\n";
174 }
175
176 Ogre::String CfgFileManager::_getCfgString(const Ogre::String &Name, const Ogre::Real &Value)
177 {
178 return "<float>" + Name + "=" + Ogre::StringConverter::toString(Value) + "\n";
179 }
180
181 Ogre::String CfgFileManager::_getCfgString(const Ogre::String &Name, const bool &Value)
182 {
183 return "<bool>" + Name + "=" + Ogre::StringConverter::toString(Value) + "\n";
184 }
185
186 Ogre::String CfgFileManager::_getCfgString(const Ogre::String &Name, const Ogre::Vector2 &Value)
187 {
188 return "<vector2>" + Name + "=" + Ogre::StringConverter::toString(Value.x) + "x" + Ogre::StringConverter::toString(Value.y) + "\n";
189 }
190
191 Ogre::String CfgFileManager::_getCfgString(const Ogre::String &Name, const Ogre::Vector3 &Value)
192 {
193 return "<vector3>" + Name + "=" + Ogre::StringConverter::toString(Value.x) + "x" + Ogre::StringConverter::toString(Value.y) + "x" + Ogre::StringConverter::toString(Value.z) + "\n";
194 }
195
196 Ogre::String CfgFileManager::_getCfgString(const Ogre::String &Name, const Ogre::Vector4 &Value)
197 {
198 return "<vector4>" + Name + "=" + Ogre::StringConverter::toString(Value.x) + "x" + Ogre::StringConverter::toString(Value.y) + "x" + Ogre::StringConverter::toString(Value.z) + "x" + Ogre::StringConverter::toString(Value.w) + "\n";
199 }
200
201 Ogre::String CfgFileManager::_getCfgString(const Ogre::String &Name, const Ogre::Degree &Value)
202 {
203 return "<degree>" + Name + "=" + Ogre::StringConverter::toString(Value) + "\n";
204 }
205
206 bool CfgFileManager::_isStringInList(const Ogre::StringVector &List, const Ogre::String &Find)
207 {
208 for (unsigned int k = 0; k < List.size(); k++)
209 {
210 if (List[k] == Find)
211 {
212 return true;
213 }
214 }
215
216 return false;
217 }
218
219 const Ogre::String CfgFileManager::_getVersionCfgString() const
220 {
221 return "SkyXVersion=" +
222 // Major
223 Ogre::StringConverter::toString(SKYX_VERSION_MAJOR)+"." +
224 // Minor
225 Ogre::StringConverter::toString(SKYX_VERSION_MINOR) + "." +
226 // Patch
227 Ogre::StringConverter::toString(SKYX_VERSION_PATCH) + "\n\n";
228 }
229
230 const bool CfgFileManager::_checkVersion(Ogre::ConfigFile& CfgFile) const
231 {
232 // accept any
233#if 0
234 if(CfgFile.getSetting("HydraxVersion") != (
235 // Major
236 Ogre::StringConverter::toString(HYDRAX_VERSION_MAJOR)+"."+
237 // Minor
238 Ogre::StringConverter::toString(HYDRAX_VERSION_MINOR)+"."+
239 // Patch
240 Ogre::StringConverter::toString(HYDRAX_VERSION_PATCH)))
241 {
242 HydraxLOG("Config file version doesn't correspond with Hydrax version.");
243
244 return false;
245 }
246#endif // 0
247 return true;
248 }
249
250 int CfgFileManager::_getIntValue(Ogre::ConfigFile& CfgFile, const Ogre::String Name)
251 {
252 Ogre::String Value = CfgFile.getSetting("<int>" + Name);
253
254 if (Value == "")
255 {
256 return 0;
257 }
258 else
259 {
260 return Ogre::StringConverter::parseInt(Value);
261 }
262 }
263
264 Ogre::Real CfgFileManager::_getFloatValue(Ogre::ConfigFile& CfgFile, const Ogre::String Name)
265 {
266 Ogre::String Value = CfgFile.getSetting("<float>" + Name);
267
268 if (Value == "")
269 {
270 return 0;
271 }
272 else
273 {
274 return Ogre::StringConverter::parseReal(Value);
275 }
276 }
277
278 bool CfgFileManager::_getBoolValue(Ogre::ConfigFile& CfgFile, const Ogre::String Name)
279 {
280 Ogre::String Value = CfgFile.getSetting("<bool>" + Name);
281
282 if (Value == "")
283 {
284 return false;
285 }
286 else
287 {
288 return Ogre::StringConverter::parseBool(Value);
289 }
290 }
291
292 Ogre::Vector2 CfgFileManager::_getVector2Value(Ogre::ConfigFile& CfgFile, const Ogre::String Name)
293 {
294 Ogre::String Value = CfgFile.getSetting("<vector2>" + Name);
295
296 if (Value == "")
297 {
298 return Ogre::Vector2(0,0);
299 }
300 else
301 {
302 return Ogre::Vector2(Ogre::StringConverter::parseReal(Ogre::StringUtil::split(Value, "x")[0]),
303 Ogre::StringConverter::parseReal(Ogre::StringUtil::split(Value, "x")[1]));
304 }
305 }
306
307 Ogre::Vector3 CfgFileManager::_getVector3Value(Ogre::ConfigFile& CfgFile, const Ogre::String Name)
308 {
309 Ogre::String Value = CfgFile.getSetting("<vector3>" + Name);
310
311 if (Value == "")
312 {
313 return Ogre::Vector3(0,0,0);
314 }
315 else
316 {
317 return Ogre::Vector3(Ogre::StringConverter::parseReal(Ogre::StringUtil::split(Value, "x")[0]),
318 Ogre::StringConverter::parseReal(Ogre::StringUtil::split(Value, "x")[1]),
319 Ogre::StringConverter::parseReal(Ogre::StringUtil::split(Value, "x")[2]));
320 }
321 }
322
323 Ogre::Vector4 CfgFileManager::_getVector4Value(Ogre::ConfigFile& CfgFile, const Ogre::String Name)
324 {
325 Ogre::String Value = CfgFile.getSetting("<vector4>" + Name);
326
327 if (Value == "")
328 {
329 return Ogre::Vector4(0, 0, 0, 0);
330 }
331 else
332 {
333 return Ogre::Vector4(
334 Ogre::StringConverter::parseReal(Ogre::StringUtil::split(Value, "x")[0]),
335 Ogre::StringConverter::parseReal(Ogre::StringUtil::split(Value, "x")[1]),
336 Ogre::StringConverter::parseReal(Ogre::StringUtil::split(Value, "x")[2]),
337 Ogre::StringConverter::parseReal(Ogre::StringUtil::split(Value, "x")[3])
338 );
339 }
340 }
341
342 Ogre::Degree CfgFileManager::_getDegreeValue(Ogre::ConfigFile& CfgFile, const Ogre::String Name)
343 {
344 Ogre::String Value = CfgFile.getSetting("<degree>" + Name);
345
346 if (Value == "")
347 {
348 return Ogre::Degree(0);
349 }
350 else
351 {
352 return Ogre::Degree(Ogre::StringConverter::parseReal(Value));
353 }
354 }
355}
#define HydraxLOG(msg)
Definition Application.h:60
void setOptions(const Options &_Options)
Set options.
Basic controller class
void setMoonPhase(const Ogre::Real &mp)
Set moon phase.
void setTime(const Ogre::Vector3 &t)
Set time.
const bool _checkVersion(Ogre::ConfigFile &CfgFile) const
Check hydrax version cfg file.
BasicController * mController
const bool load(const Ogre::String &File) const
Load hydrax cfg file.
static bool _isStringInList(const Ogre::StringVector &List, const Ogre::String &Find)
const void _loadCfgFile(const Ogre::String &File, std::pair< bool, Ogre::ConfigFile > &Result) const
Load a cfg file in an Ogre::ConfigFile.
static int _getIntValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get int value.
SkyX * mSkyX
Hydrax parent pointer.
static Ogre::Degree _getDegreeValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
const bool save(const Ogre::String &File, const Ogre::String &Path="") const
Save current hydrax config to a file.
CfgFileManager(SkyX *s, BasicController *c, Ogre::Camera *d)
Constructor.
static bool _getBoolValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get bool value.
static Ogre::Real _getFloatValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get float value.
static Ogre::Vector4 _getVector4Value(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
const bool _saveToFile(const Ogre::String &Data, const Ogre::String &File, const Ogre::String &Path) const
Save a string in file.
static Ogre::Vector3 _getVector3Value(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get vector3 value.
const Ogre::String _getVersionCfgString() const
Get hydrax version cfg string.
static Ogre::String _getCfgString(const Ogre::String &Name, const int &Value)
static Ogre::Vector2 _getVector2Value(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get vector2 value.
CloudLayer * add(const CloudLayer::Options &o)
Add a cloud layer.
const std::vector< CloudLayer * > & getCloudLayers() const
Get cloud layers.
const float getSkydomeRadius(Ogre::Camera *c) const
Get skydome radius.
void setTimeMultiplier(const Ogre::Real &TimeMultiplier)
Set time multiplier.
Definition SkyX.h:166
AtmosphereManager * getAtmosphereManager()
Get atmosphere manager.
Definition SkyX.h:191
VCloudsManager * getVCloudsManager()
Get volumetric clouds manager.
Definition SkyX.h:223
CloudsManager * getCloudsManager()
Get clouds manager.
Definition SkyX.h:215
MeshManager * getMeshManager()
Get mesh manager.
Definition SkyX.h:183
const bool & isEnabled() const
Get whether the lightning system is enabled or not.
void setLightningColor(const Ogre::Vector3 &c)
Set lightning color.
void setLightningTimeMultiplier(const Ogre::Real &m)
Set lightning time multiplier.
void setEnabled(const bool &enable)
Enable or disable the lightning system.
void setAverageLightningApparitionTime(const Ogre::Real &alat)
Set average lightning apparition time.
void setAmbientColor(const Ogre::Vector3 &AmbientColor)
Set ambient color.
Definition VClouds.cpp:272
void setWindDirection(const Ogre::Radian &WindDirection)
Set wind direction.
Definition VClouds.h:268
void setLightResponse(const Ogre::Vector4 &LightResponse)
Set light response.
Definition VClouds.cpp:287
LightningManager * getLightningManager()
Get lightning manager.
Definition VClouds.h:491
void setAmbientFactors(const Ogre::Vector4 &AmbientFactors)
Set ambient factors.
Definition VClouds.cpp:302
void setWheater(const float &Humidity, const float &AverageCloudsSize, const bool &DelayedResponse)
Set wheater parameters Use this funtion to update the cloud field parameters, you'll get a smart and ...
Definition VClouds.cpp:317
void setAutoupdate(const bool &Autoupdate)
Autoupdate volumetric clouds wind depending of the SkyX time multiplier.
void create(const Ogre::Real &radius=-1)
Create all resources.
VClouds::VClouds * getVClouds()
Get VClouds.
void setWindSpeed(const Ogre::Real &WindSpeed)
Set wind speed.
const bool & isCreated() const
Is moon manager created?
void setHeight(const Ogre::Vector2 &Height)
Set height parameters.
#define HYDRAX_VERSION_PATCH
#define HYDRAX_VERSION_MAJOR
Include external headers.
#define HYDRAX_VERSION_MINOR
#define SkyXLOG(msg)
Include external headers.
#define SKYX_VERSION_PATCH
#define SKYX_VERSION_MINOR
#define SKYX_VERSION_MAJOR
SkyX defines.
Cloud layer options.