@@ -10,51 +10,36 @@ CLight_DB::CLight_DB() {}
1010CLight_DB::~CLight_DB () {}
1111void CLight_DB::Load (IReader* fs)
1212{
13- IReader* F = 0 ;
14-
15- // Lights itself
16- sun_original = NULL ;
17- sun_adapted = NULL ;
13+ IReader* F = fs->open_chunk (fsL_LIGHT_DYNAMIC);
1814 {
19- F = fs->open_chunk (fsL_LIGHT_DYNAMIC);
15+ // Light itself
16+ sun = NULL ;
2017
21- u32 size = F->length ();
18+ u32 size = F->length ();
2219 u32 element = sizeof (Flight) + 4 ;
23- u32 count = size / element;
24- VERIFY (count * element == size);
20+ u32 count = ( size / element) ;
21+ VERIFY (( count * element) == size);
2522 v_static.reserve (count);
26- for (u32 i = 0 ; i < count; i++ )
23+ for (u32 i = 0 ; i < count; ++i )
2724 {
2825 Flight Ldata;
29- light* L = Create ();
30- L->flags .bStatic = true ;
31- L->set_type (IRender_Light::POINT);
32-
33- #if RENDER == R_R1
34- L->set_shadow (false );
35- #else
36- L->set_shadow (true );
37- #endif
3826 u32 controller = 0 ;
3927 F->r (&controller, 4 );
4028 F->r (&Ldata, sizeof (Flight));
29+
30+ light* L = Create ();
31+ L->flags .bStatic = true ;
32+
4133 if (Ldata.type == D3DLIGHT_DIRECTIONAL)
4234 {
4335 Fvector tmp_R;
4436 tmp_R.set (1 , 0 , 0 );
4537
46- // directional (base)
47- sun_original = L;
4838 L->set_type (IRender_Light::DIRECT);
4939 L->set_shadow (true );
5040 L->set_rotation (Ldata.direction , tmp_R);
5141
52- // copy to env-sun
53- sun_adapted = L = Create ();
54- L->flags .bStatic = true ;
55- L->set_type (IRender_Light::DIRECT);
56- L->set_shadow (true );
57- L->set_rotation (Ldata.direction , tmp_R);
42+ sun = L;
5843 }
5944 else
6045 {
@@ -63,36 +48,25 @@ void CLight_DB::Load(IReader* fs)
6348 tmp_R.set (1 , 0 , 0 ); // right
6449
6550 // point
66- v_static. push_back (L );
51+ L-> set_type (IRender_Light::POINT );
6752 L->set_position (Ldata.position );
6853 L->set_rotation (tmp_D, tmp_R);
6954 L->set_range (Ldata.range );
7055 L->set_color (Ldata.diffuse );
56+ #if RENDER == R_R1
57+ L->set_shadow (false );
58+ #else
59+ L->set_shadow (true );
60+ #endif
7161 L->set_active (true );
72- // R_ASSERT (L->spatial.sector );
62+
63+ v_static.push_back (L);
7364 }
7465 }
75-
76- F->close ();
7766 }
78- R_ASSERT2 (sun_original && sun_adapted, " Where is sun? " );
67+ F-> close ( );
7968
80- // fake spot
81- /*
82- if (0)
83- {
84- Fvector P; P.set(-5.58f, -0.00f + 2, -3.63f);
85- Fvector D; D.set(0,-1,0);
86- light* fake = Create();
87- fake->set_type (IRender_Light::SPOT);
88- fake->set_color (1,1,1);
89- fake->set_cone (deg2rad(60.f));
90- fake->set_direction (D);
91- fake->set_position (P);
92- fake->set_range (3.f);
93- fake->set_active (true);
94- }
95- */
69+ R_ASSERT2 (sun, " Where is sun?" );
9670}
9771
9872#if RENDER != R_R1
@@ -102,9 +76,9 @@ void CLight_DB::LoadHemi()
10276 if (FS.exist (fn_game, " $level$" , " build.lights" ))
10377 {
10478 IReader* F = FS.r_open (fn_game);
105-
10679 {
107- IReader* chunk = F->open_chunk (1 ); // Hemispheric light chunk
80+ // Hemispheric light chunk
81+ IReader* chunk = F->open_chunk (fsL_HEADER);
10882
10983 if (chunk)
11084 {
@@ -116,38 +90,32 @@ void CLight_DB::LoadHemi()
11690 for (u32 i = 0 ; i < count; i++)
11791 {
11892 R_Light Ldata;
119-
12093 chunk->r (&Ldata, sizeof (R_Light));
12194
12295 if (Ldata.type == D3DLIGHT_POINT)
123- // if (Ldata.type!=0)
12496 {
125- light* L = Create ();
126- L->flags .bStatic = true ;
127- L->set_type (IRender_Light::POINT);
128-
12997 Fvector tmp_D, tmp_R;
13098 tmp_D.set (0 , 0 , -1 ); // forward
13199 tmp_R.set (1 , 0 , 0 ); // right
132100
133- // point
134- v_hemi.push_back (L);
101+ light* L = Create ();
102+ L->flags .bStatic = true ;
103+ L->set_type (IRender_Light::POINT);
135104 L->set_position (Ldata.position );
136105 L->set_rotation (tmp_D, tmp_R);
137106 L->set_range (Ldata.range );
138107 L->set_color (Ldata.diffuse .x , Ldata.diffuse .y , Ldata.diffuse .z );
139108 L->set_active (true );
109+ L->spatial .type = STYPE_LIGHTSOURCEHEMI;
140110 L->set_attenuation_params (
141111 Ldata.attenuation0 , Ldata.attenuation1 , Ldata.attenuation2 , Ldata.falloff );
142- L-> spatial . type = STYPE_LIGHTSOURCEHEMI;
143- // R_ASSERT (L->spatial.sector );
112+
113+ v_hemi. push_back (L );
144114 }
145115 }
146-
147116 chunk->close ();
148117 }
149118 }
150-
151119 FS.r_close (F);
152120 }
153121}
@@ -157,8 +125,7 @@ void CLight_DB::Unload()
157125{
158126 v_static.clear ();
159127 v_hemi.clear ();
160- sun_original.destroy ();
161- sun_adapted.destroy ();
128+ sun.destroy ();
162129}
163130
164131light* CLight_DB::Create ()
@@ -170,40 +137,31 @@ light* CLight_DB::Create()
170137 return L;
171138}
172139
173- #if RENDER == R_R1
174140void CLight_DB::add_light (light* L)
175141{
176142 if (Device.dwFrame == L->frame_render )
177143 return ;
178144 L->frame_render = Device.dwFrame ;
145+ #if RENDER == R_R1
179146 if (L->flags .bStatic )
180147 return ; // skip static lighting, 'cause they are in lmaps
181148 if (ps_r1_flags.test (R1FLAG_DLIGHTS))
182149 RImplementation.L_Dynamic ->add (L);
183- }
184- #endif
185-
186- #if (RENDER == R_R2) || (RENDER == R_R3) || (RENDER == R_R4) || (RENDER == R_GL)
187- void CLight_DB::add_light (light* L)
188- {
189- if (Device.dwFrame == L->frame_render )
190- return ;
191- L->frame_render = Device.dwFrame ;
150+ #else
192151 if (RImplementation.o .noshadows )
193152 L->flags .bShadow = FALSE ;
194153 if (L->flags .bStatic && !ps_r2_ls_flags.test (R2FLAG_R1LIGHTS))
195154 return ;
196155 L->Export (package);
156+ #endif
197157}
198- #endif // (RENDER==R_R2) || (RENDER==R_R3) || (RENDER==R_R4) || (RENDER==R_GL)
199158
200159void CLight_DB::Update ()
201160{
202161 // set sun params
203- if (sun_original && sun_adapted )
162+ if (sun )
204163 {
205- light* _sun_original = (light*)sun_original._get ();
206- light* _sun_adapted = (light*)sun_adapted._get ();
164+ light* _sun = (light*)sun._get ();
207165 CEnvDescriptor& E = *g_pGamePersistent->Environment ().CurrentEnv ;
208166 VERIFY (_valid (E.sun_dir ));
209167#ifdef DEBUG
@@ -226,37 +184,16 @@ void CLight_DB::Update()
226184#endif
227185
228186 VERIFY2 (E.sun_dir .y < 0 , " Invalid sun direction settings in evironment-config" );
229- Fvector OD, OP, AD, AP;
230- OD.set (E.sun_dir ).normalize ();
231- OP.mad (Device.vCameraPosition , OD, -500 .f );
232- AD.set (0 , -.75f , 0 ).add (E.sun_dir );
187+ Fvector dir, pos;
188+ dir.set (E.sun_dir ).normalize ();
189+ pos.mad (Device.vCameraPosition , dir, -500 .f );
233190
234- // for some reason E.sun_dir can point-up
235- int counter = 0 ;
236- while (AD.magnitude () < 0.001 && counter < 10 )
237- {
238- AD.add (E.sun_dir );
239- counter++;
240- }
241- AD.normalize ();
242- AP.mad (Device.vCameraPosition , AD, -500 .f );
243- sun_original->set_rotation (OD, _sun_original->right );
244- sun_original->set_position (OP);
245- sun_original->set_color (E.sun_color .x , E.sun_color .y , E.sun_color .z );
246- sun_original->set_range (600 .f );
247- sun_adapted->set_rotation (AD, _sun_adapted->right );
248- sun_adapted->set_position (AP);
249- sun_adapted->set_color (
191+ sun->set_rotation (dir, _sun->right );
192+ sun->set_position (pos);
193+ sun->set_color (
250194 E.sun_color .x * ps_r2_sun_lumscale, E.sun_color .y * ps_r2_sun_lumscale, E.sun_color .z * ps_r2_sun_lumscale);
251- sun_adapted->set_range (600 .f );
252-
253- if (!GEnv.Render ->is_sun_static ())
254- {
255- sun_adapted->set_rotation (OD, _sun_original->right );
256- sun_adapted->set_position (OP);
257- }
195+ sun->set_range (600 .f );
258196 }
259-
260197 // Clear selection
261198 package.clear ();
262199}
0 commit comments