Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / server_share / light_ig_loader.cpp
blobde29ad949b343339f3d99c37615bcd38e3c4db16
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
19 // pch
20 #include "stdpch.h"
23 #include "light_ig_loader.h"
26 // misc
27 #include <nel/misc/vector_2f.h>
28 #include <nel/misc/object_vector.h>
29 #include <nel/misc/rgba.h>
30 #include <nel/misc/plane.h>
31 #include <nel/misc/aabbox.h>
34 using namespace std;
35 using namespace NLMISC;
41 #define SERIAL_DUMMY(type) { type dummy; _File.serial(dummy); }
43 struct CCellCorner
45 enum { NumLightPerCorner = 2 };
47 uint8 SunContribution;
48 uint8 Light[NumLightPerCorner];
49 uint8 LocalAmbientId;
51 void serial(NLMISC::IStream &f)
53 uint ver= f.serialVersion(1);
54 nlassert(NumLightPerCorner==2);
56 if(ver>=1)
57 f.serial(LocalAmbientId);
58 f.serial(SunContribution);
59 f.serial(Light[0]);
60 f.serial(Light[1]);
64 class CSurfaceLightGrid
66 public:
67 NLMISC::CVector2f Origin;
68 uint32 Width;
69 uint32 Height;
70 NLMISC::CObjectVector<CCellCorner> Cells;
72 public:
74 void serial(NLMISC::IStream &f)
76 (void)f.serialVersion(0);
77 f.serial(Origin);
78 f.serial(Width);
79 f.serial(Height);
80 f.serial(Cells);
84 class CRetrieverLightGrid
86 public:
87 //NLMISC::CObjectVector<CSurfaceLightGrid> Grids;
89 public:
91 void serial(NLMISC::IStream &_File)
93 (void)_File.serialVersion(0);
94 SERIAL_DUMMY(NLMISC::CObjectVector<CSurfaceLightGrid>);
103 * Constructor
105 CLightIGLoader::CLightIGLoader()
110 // Load IG
111 void CLightIGLoader::loadIG(const string &filename)
113 _File.open(CPath::lookup(filename));
116 // Serial a header
117 _File.serialCheck (NELID("TPRG"));
119 // Serial a version number
120 sint version = _File.serialVersion (5);
123 // _RealTimeSunContribution
124 if (version >= 5)
126 SERIAL_DUMMY(bool); // _RealTimeSunContribution
130 // Serial the IGSurfaceLight
131 if (version >= 4)
133 sint ver = _File.serialVersion(1);
135 SERIAL_DUMMY(float); // _CellSize
136 SERIAL_DUMMY(float); // _OOCellSize
138 if(ver<1)
140 std::map<std::string, CRetrieverLightGrid> _RetrieverGridMap;
141 _File.serialCont(_RetrieverGridMap);
143 else
145 std::map<uint32, CRetrieverLightGrid> _RetrieverGridMap;
146 _File.serialCont(_RetrieverGridMap);
151 // Serial the PointLights info
152 if (version >= 3)
154 sint ver = _File.serialVersion(1);
156 // _PointLights
157 uint32 num;
158 _File.serial(num);
159 for (; num>0; --num)
161 sint ver = _File.serialVersion(1);
163 // Serialize parent.
164 sint verp= _File.serialVersion(2);
166 if (verp>=2)
168 SERIAL_DUMMY(bool);
171 if (verp>=1)
173 SERIAL_DUMMY(sint32); // enum _Type
174 SERIAL_DUMMY(CVector); // _SpotDirection
175 SERIAL_DUMMY(float); // _SpotAngleBegin
176 SERIAL_DUMMY(float); // _SpotAngleEnd
179 SERIAL_DUMMY(CVector); // _Position
180 SERIAL_DUMMY(CRGBA); // _Ambient
181 SERIAL_DUMMY(CRGBA); // _Diffuse
182 SERIAL_DUMMY(CRGBA); // _Specular
183 SERIAL_DUMMY(float); // _AttenuationBegin
184 SERIAL_DUMMY(float); // _AttenuationEnd
186 // Serialize my data
187 SERIAL_DUMMY(string); // AnimatedLight
188 SERIAL_DUMMY(CRGBA); // _DefaultAmbient
189 SERIAL_DUMMY(CRGBA); // _DefaultDiffuse
190 SERIAL_DUMMY(CRGBA); // _DefaultSpecular
192 if (ver>=1)
193 SERIAL_DUMMY(uint32); // LightGroup
196 if (ver == 0)
198 uint32 num;
199 _File.serial(num);
200 for (; num>0; --num)
202 SERIAL_DUMMY(uint32); // StartId
203 SERIAL_DUMMY(uint32); // EndId
206 else
208 // _PointLightGroupMap
209 uint32 num;
210 _File.serial(num);
211 for (; num>0; --num)
213 _File.serialVersion (0);
214 SERIAL_DUMMY(string); // AnimationLight
215 SERIAL_DUMMY(uint32); // LightGroup
216 SERIAL_DUMMY(uint32); // StartId
217 SERIAL_DUMMY(uint32); // EndId
223 if (version >= 2)
224 SERIAL_DUMMY(CVector); // _GlobalPos
232 if (version >= 1)
234 uint32 numClusters;
235 uint32 num;
237 // f.serialCont (_ClusterInfos);
238 _File.serial(numClusters);
239 for (num=numClusters; num>0; --num)
241 sint version = _File.serialVersion (3);
243 if (version >= 1)
244 SERIAL_DUMMY(string); // Name
246 uint32 n;
248 // f.serialCont (_LocalVolume);
249 _File.serial(n);
250 for (; n>0; --n)
251 SERIAL_DUMMY(CPlane); // _LocalVolume
253 SERIAL_DUMMY(CAABBox); // _LocalBBox
254 SERIAL_DUMMY(bool) ; // FatherVisible
255 SERIAL_DUMMY(bool); // VisibleFromFather
257 if (version >= 2)
259 SERIAL_DUMMY(string); // soundGroup
260 SERIAL_DUMMY(string); // envFxName
263 if (version >= 3)
265 SERIAL_DUMMY(bool); // AudibleFromFather
266 SERIAL_DUMMY(bool); // FatherAudible
270 // f.serialCont (_Portals);
271 _File.serial(num);
272 for (; num>0; --num)
274 int version = _File.serialVersion (1);
276 uint32 n;
278 //f.serialCont (_LocalPoly);
279 _File.serial(n);
280 for (; n>0; --n)
281 SERIAL_DUMMY(CVector);
283 SERIAL_DUMMY(string); // _Name
285 if (version >= 1)
287 SERIAL_DUMMY(string); // occName;
288 SERIAL_DUMMY(string); // occName;
292 // Links
293 uint32 i, j;
294 for (i = 0; i < numClusters; ++i)
296 uint32 nNbPortals;
297 _File.serial (nNbPortals);
299 for (j = 0; j < nNbPortals; ++j)
300 SERIAL_DUMMY(sint32); // nPortalNb
304 // Serial the array
305 // f.serialCont (_InstancesInfos);
306 uint32 num;
307 _File.serial(num);
308 for (; num>0; --num)
311 Version 7:
312 - Visible
313 Version 6:
314 - DontCastShadowForExterior
315 Version 5:
316 - DontCastShadowForInterior
317 Version 4:
318 - LocalAmbientId.
319 Version 3:
320 - StaticLight.
321 Version 2:
322 - gameDev data.
323 Version 1:
324 - Clusters
326 // Serial a version number
327 sint version = _File.serialVersion (7);
329 // Visible
330 if (version >= 7)
331 SERIAL_DUMMY(bool);
333 // DontCastShadowForExterior
334 if (version >= 6)
335 SERIAL_DUMMY(bool);
337 // DontCastShadowForInterior
338 if (version >= 5)
339 SERIAL_DUMMY(bool);
342 // Serial the LocalAmbientId.
343 if (version >= 4)
344 SERIAL_DUMMY(uint8); // LocalAmbientId)
346 // Serial the StaticLight
347 if (version >= 3)
350 SERIAL_DUMMY(bool); // AvoidStaticLightPreCompute
351 SERIAL_DUMMY(bool); // DontCastShadow
352 SERIAL_DUMMY(bool); // StaticLightEnabled
353 SERIAL_DUMMY(uint8); // SunContribution
355 SERIAL_DUMMY(uint8); // Light[0]
356 SERIAL_DUMMY(uint8); // Light[1]
359 // Serial the gamedev data
360 _InstanceNames.resize(_InstanceNames.size()+1);
361 if (version >= 2)
363 _File.serial(_InstanceNames.back());
364 SERIAL_DUMMY(bool); // DontAddToScene
367 // Serial the clusters
368 if (version >= 1)
370 // f.serialCont (Clusters);
371 uint32 num;
372 _File.serial(num);
373 for (; num>0; --num)
374 SERIAL_DUMMY(uint32);
377 // Serial the name
378 _ShapeNames.resize(_ShapeNames.size()+1);
379 _File.serial(_ShapeNames.back());
380 //serialDummy<string>(); // Name
382 // Serial the position vector
383 _ShapePos.resize(_ShapePos.size()+1);
384 _File.serial(_ShapePos.back());
385 //serialDummy<CVector>(); // Pos
387 // Serial the rotation vector
388 _ShapeRots.resize(_ShapeRots.size()+1);
389 _File.serial(_ShapeRots.back());
390 //serialDummy<CQuat>(); // Rot
392 // Serial the scale vector
393 _ShapeScales.resize(_ShapeScales.size()+1);
394 _File.serial(_ShapeScales.back());
395 //serialDummy<CVector>(); // Scale
397 // Serial the parent location in the vector (-1 if no parent)
398 SERIAL_DUMMY(sint32); // nParent