1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
19 #include "nel/3d/ig_surface_light.h"
28 // ***************************************************************************
29 CIGSurfaceLight::CIGSurfaceLight()
31 /* ***********************************************
32 * WARNING: This Class/Method must be thread-safe (ctor/dtor/serial): no static access for instance
33 * It can be loaded/called through CAsyncFileManager for instance
34 * ***********************************************/
41 // ***************************************************************************
42 void CIGSurfaceLight::setOwner(CInstanceGroup
*owner
)
44 nlassert(owner
!=NULL
);
48 // ***************************************************************************
49 void CIGSurfaceLight::build(const TRetrieverGridMap
&retrieverGridMap
, float cellSize
,
50 const std::vector
<uint
> &plRemap
)
52 _RetrieverGridMap
= retrieverGridMap
;
55 _OOCellSize
= 1.f
/_CellSize
;
58 ItRetrieverGridMap it
;
59 for(it
= _RetrieverGridMap
.begin(); it
!=_RetrieverGridMap
.end(); it
++)
61 // For all grids of this retriever
62 for(uint iGrid
= 0; iGrid
<it
->second
.Grids
.size(); iGrid
++)
64 CSurfaceLightGrid
&grid
= it
->second
.Grids
[iGrid
];
66 // For all cells of this grid.
67 for(uint iCell
= 0; iCell
<grid
.Cells
.size(); iCell
++)
69 CSurfaceLightGrid::CCellCorner
&cell
= grid
.Cells
[iCell
];
71 // For all point light id.
72 for(uint lid
= 0; lid
<CSurfaceLightGrid::NumLightPerCorner
; lid
++)
74 if(cell
.Light
[lid
] == 0xFF)
77 cell
.Light
[lid
]= plRemap
[cell
.Light
[lid
]];
80 // remap ambient light
81 if(cell
.LocalAmbientId
!=0xFF)
82 cell
.LocalAmbientId
= plRemap
[cell
.LocalAmbientId
];
88 // ***************************************************************************
89 void CIGSurfaceLight::clear()
91 _RetrieverGridMap
.clear();
96 // ***************************************************************************
97 void CIGSurfaceLight::serial(NLMISC::IStream
&f
)
99 /* ***********************************************
100 * WARNING: This Class/Method must be thread-safe (ctor/dtor/serial): no static access for instance
101 * It can be loaded/called through CAsyncFileManager for instance
102 * ***********************************************/
106 - The retriever grid map is now a map<uint,CRetrieverLightGrid>. Discard compatibility but.
108 sint ver
= f
.serialVersion(1);
111 f
.serial(_OOCellSize
);
114 std::map
<std::string
, CRetrieverLightGrid
> oldFormatRetrieverGridMap
;
115 f
.serialCont(oldFormatRetrieverGridMap
);
116 _RetrieverGridMap
.clear();
120 f
.serialCont(_RetrieverGridMap
);
124 // ***************************************************************************
125 bool CIGSurfaceLight::getStaticLightSetup(NLMISC::CRGBA sunAmbient
, uint retrieverIdentifier
, sint surfaceId
, const CVector
&localPos
,
126 std::vector
<CPointLightInfluence
> &pointLightList
, uint8
&sunContribution
, NLMISC::CRGBA
&localAmbient
)
131 sunContribution
= 255;
132 localAmbient
= sunAmbient
;
134 ItRetrieverGridMap it
;
135 it
= _RetrieverGridMap
.find(retrieverIdentifier
);
137 if(it
==_RetrieverGridMap
.end())
139 CRetrieverLightGrid
&rlg
= it
->second
;
141 if(surfaceId
<0 || surfaceId
>= (sint
)rlg
.Grids
.size())
145 rlg
.Grids
[surfaceId
].getStaticLightSetup(sunAmbient
, localPos
, pointLightList
, sunContribution
, *this, localAmbient
);