@@ -10,51 +10,36 @@ CLight_DB::CLight_DB() {}
10
10
CLight_DB::~CLight_DB () {}
11
11
void CLight_DB::Load (IReader* fs)
12
12
{
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);
18
14
{
19
- F = fs->open_chunk (fsL_LIGHT_DYNAMIC);
15
+ // Light itself
16
+ sun = NULL ;
20
17
21
- u32 size = F->length ();
18
+ u32 size = F->length ();
22
19
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);
25
22
v_static.reserve (count);
26
- for (u32 i = 0 ; i < count; i++ )
23
+ for (u32 i = 0 ; i < count; ++i )
27
24
{
28
25
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
38
26
u32 controller = 0 ;
39
27
F->r (&controller, 4 );
40
28
F->r (&Ldata, sizeof (Flight));
29
+
30
+ light* L = Create ();
31
+ L->flags .bStatic = true ;
32
+
41
33
if (Ldata.type == D3DLIGHT_DIRECTIONAL)
42
34
{
43
35
Fvector tmp_R;
44
36
tmp_R.set (1 , 0 , 0 );
45
37
46
- // directional (base)
47
- sun_original = L;
48
38
L->set_type (IRender_Light::DIRECT);
49
39
L->set_shadow (true );
50
40
L->set_rotation (Ldata.direction , tmp_R);
51
41
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;
58
43
}
59
44
else
60
45
{
@@ -63,36 +48,25 @@ void CLight_DB::Load(IReader* fs)
63
48
tmp_R.set (1 , 0 , 0 ); // right
64
49
65
50
// point
66
- v_static. push_back (L );
51
+ L-> set_type (IRender_Light::POINT );
67
52
L->set_position (Ldata.position );
68
53
L->set_rotation (tmp_D, tmp_R);
69
54
L->set_range (Ldata.range );
70
55
L->set_color (Ldata.diffuse );
56
+ #if RENDER == R_R1
57
+ L->set_shadow (false );
58
+ #else
59
+ L->set_shadow (true );
60
+ #endif
71
61
L->set_active (true );
72
- // R_ASSERT (L->spatial.sector );
62
+
63
+ v_static.push_back (L);
73
64
}
74
65
}
75
-
76
- F->close ();
77
66
}
78
- R_ASSERT2 (sun_original && sun_adapted, " Where is sun? " );
67
+ F-> close ( );
79
68
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?" );
96
70
}
97
71
98
72
#if RENDER != R_R1
@@ -102,9 +76,9 @@ void CLight_DB::LoadHemi()
102
76
if (FS.exist (fn_game, " $level$" , " build.lights" ))
103
77
{
104
78
IReader* F = FS.r_open (fn_game);
105
-
106
79
{
107
- IReader* chunk = F->open_chunk (1 ); // Hemispheric light chunk
80
+ // Hemispheric light chunk
81
+ IReader* chunk = F->open_chunk (fsL_HEADER);
108
82
109
83
if (chunk)
110
84
{
@@ -116,38 +90,32 @@ void CLight_DB::LoadHemi()
116
90
for (u32 i = 0 ; i < count; i++)
117
91
{
118
92
R_Light Ldata;
119
-
120
93
chunk->r (&Ldata, sizeof (R_Light));
121
94
122
95
if (Ldata.type == D3DLIGHT_POINT)
123
- // if (Ldata.type!=0)
124
96
{
125
- light* L = Create ();
126
- L->flags .bStatic = true ;
127
- L->set_type (IRender_Light::POINT);
128
-
129
97
Fvector tmp_D, tmp_R;
130
98
tmp_D.set (0 , 0 , -1 ); // forward
131
99
tmp_R.set (1 , 0 , 0 ); // right
132
100
133
- // point
134
- v_hemi.push_back (L);
101
+ light* L = Create ();
102
+ L->flags .bStatic = true ;
103
+ L->set_type (IRender_Light::POINT);
135
104
L->set_position (Ldata.position );
136
105
L->set_rotation (tmp_D, tmp_R);
137
106
L->set_range (Ldata.range );
138
107
L->set_color (Ldata.diffuse .x , Ldata.diffuse .y , Ldata.diffuse .z );
139
108
L->set_active (true );
109
+ L->spatial .type = STYPE_LIGHTSOURCEHEMI;
140
110
L->set_attenuation_params (
141
111
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 );
144
114
}
145
115
}
146
-
147
116
chunk->close ();
148
117
}
149
118
}
150
-
151
119
FS.r_close (F);
152
120
}
153
121
}
@@ -157,8 +125,7 @@ void CLight_DB::Unload()
157
125
{
158
126
v_static.clear ();
159
127
v_hemi.clear ();
160
- sun_original.destroy ();
161
- sun_adapted.destroy ();
128
+ sun.destroy ();
162
129
}
163
130
164
131
light* CLight_DB::Create ()
@@ -170,40 +137,31 @@ light* CLight_DB::Create()
170
137
return L;
171
138
}
172
139
173
- #if RENDER == R_R1
174
140
void CLight_DB::add_light (light* L)
175
141
{
176
142
if (Device.dwFrame == L->frame_render )
177
143
return ;
178
144
L->frame_render = Device.dwFrame ;
145
+ #if RENDER == R_R1
179
146
if (L->flags .bStatic )
180
147
return ; // skip static lighting, 'cause they are in lmaps
181
148
if (ps_r1_flags.test (R1FLAG_DLIGHTS))
182
149
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
192
151
if (RImplementation.o .noshadows )
193
152
L->flags .bShadow = FALSE ;
194
153
if (L->flags .bStatic && !ps_r2_ls_flags.test (R2FLAG_R1LIGHTS))
195
154
return ;
196
155
L->Export (package);
156
+ #endif
197
157
}
198
- #endif // (RENDER==R_R2) || (RENDER==R_R3) || (RENDER==R_R4) || (RENDER==R_GL)
199
158
200
159
void CLight_DB::Update ()
201
160
{
202
161
// set sun params
203
- if (sun_original && sun_adapted )
162
+ if (sun )
204
163
{
205
- light* _sun_original = (light*)sun_original._get ();
206
- light* _sun_adapted = (light*)sun_adapted._get ();
164
+ light* _sun = (light*)sun._get ();
207
165
CEnvDescriptor& E = *g_pGamePersistent->Environment ().CurrentEnv ;
208
166
VERIFY (_valid (E.sun_dir ));
209
167
#ifdef DEBUG
@@ -226,37 +184,16 @@ void CLight_DB::Update()
226
184
#endif
227
185
228
186
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 );
233
190
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 (
250
194
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 );
258
196
}
259
-
260
197
// Clear selection
261
198
package.clear ();
262
199
}
0 commit comments