Skip to content

Commit 857582a

Browse files
authored
Merge pull request scp-fs2open#1608 from The-E/LightTypeEnum
Use an enum class to mark light types
2 parents 0178374 + 7dfa5b5 commit 857582a

5 files changed

Lines changed: 47 additions & 37 deletions

File tree

code/graphics/light.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void FSLight2GLLight(light* FSLight, gr_light* GLLight) {
6363
GLLight->Specular.xyzw.z = FSLight->spec_b * FSLight->intensity;
6464
GLLight->Specular.xyzw.w = 1.0f;
6565

66-
GLLight->type = FSLight->type;
66+
GLLight->type = static_cast<int>(FSLight->type);
6767

6868
// GL default values...
6969
// spot direction
@@ -86,7 +86,7 @@ void FSLight2GLLight(light* FSLight, gr_light* GLLight) {
8686

8787

8888
switch (FSLight->type) {
89-
case LT_POINT: {
89+
case Light_Type::Point: {
9090
// this crap still needs work...
9191
GLLight->ConstantAtten = 1.0f;
9292
GLLight->LinearAtten = (1.0f / MAX(FSLight->rada, FSLight->radb)) * 1.25f;
@@ -98,7 +98,7 @@ void FSLight2GLLight(light* FSLight, gr_light* GLLight) {
9898
break;
9999
}
100100

101-
case LT_TUBE: {
101+
case Light_Type::Tube: {
102102
GLLight->ConstantAtten = 1.0f;
103103
GLLight->LinearAtten = (1.0f / MAX(FSLight->rada, FSLight->radb)) * 1.25f;
104104
GLLight->QuadraticAtten = (1.0f / MAX(FSLight->rada_squared, FSLight->radb_squared)) * 1.25f;
@@ -122,7 +122,7 @@ void FSLight2GLLight(light* FSLight, gr_light* GLLight) {
122122
break;
123123
}
124124

125-
case LT_DIRECTIONAL: {
125+
case Light_Type::Directional: {
126126
GLLight->Position.xyzw.x = -FSLight->vec.xyz.x;
127127
GLLight->Position.xyzw.y = -FSLight->vec.xyz.y;
128128
GLLight->Position.xyzw.z = -FSLight->vec.xyz.z;
@@ -135,11 +135,11 @@ void FSLight2GLLight(light* FSLight, gr_light* GLLight) {
135135
break;
136136
}
137137

138-
case LT_CONE:
138+
case Light_Type::Cone:
139139
break;
140140

141141
default:
142-
Int3();
142+
Error(LOCATION, "Unknown light type in FSLight2GLLight. Expected was 0, 1, 2 or 3, we got %i", static_cast<int>(FSLight->type));
143143
break;
144144
}
145145
}

code/graphics/opengl/gropengldeferred.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ void gr_opengl_deferred_lighting_finish()
129129

130130
for (auto& l : lights_copy) {
131131

132-
if (l.type != LT_CONE && l.type != LT_POINT && l.type != LT_TUBE) {
132+
if (l.type == Light_Type::Directional) {
133133
continue;
134134
}
135-
135+
float length = 0.0f;
136136
auto light_data = uniformAligner.addTypedElement<deferred_light_data>();
137137

138138
light_data->lightType = 0;
@@ -148,14 +148,14 @@ void gr_opengl_deferred_lighting_finish()
148148
spec.xyz.z = l.spec_b * l.intensity;
149149

150150
switch (l.type) {
151-
case LT_CONE:
151+
case Light_Type::Cone:
152152
light_data->lightType = 2;
153153
light_data->dualCone = l.dual_cone ? 1.0f : 0.0f;
154154
light_data->coneAngle = l.cone_angle;
155155
light_data->coneInnerAngle = l.cone_inner_angle;
156156
light_data->coneDir = l.vec2;
157157
FALLTHROUGH;
158-
case LT_POINT:
158+
case Light_Type::Point:
159159
light_data->diffuseLightColor = diffuse;
160160
light_data->specLightColor = spec;
161161
light_data->lightRadius = MAX(l.rada, l.radb) * 1.25f;
@@ -164,15 +164,15 @@ void gr_opengl_deferred_lighting_finish()
164164
light_data->scale.xyz.y = MAX(l.rada, l.radb) * 1.28f;
165165
light_data->scale.xyz.z = MAX(l.rada, l.radb) * 1.28f;
166166
break;
167-
case LT_TUBE:
167+
case Light_Type::Tube:
168168
light_data->diffuseLightColor = diffuse;
169169
light_data->specLightColor = spec;
170170
light_data->lightRadius = l.radb * 1.5f;
171171
light_data->lightType = 1;
172172

173173
vec3d a;
174174
vm_vec_sub(&a, &l.vec, &l.vec2);
175-
auto length = vm_vec_mag(&a);
175+
length = vm_vec_mag(&a);
176176

177177
light_data->scale.xyz.x = l.radb * 1.53f;
178178
light_data->scale.xyz.y = l.radb * 1.53f;
@@ -189,6 +189,8 @@ void gr_opengl_deferred_lighting_finish()
189189
light_data->scale.xyz.y = l.radb * 1.53f;
190190
light_data->scale.xyz.z = l.radb * 1.53f;
191191
break;
192+
case Light_Type::Directional: //We need to "handle" this here as well to make the compilers happy;
193+
break; //The code will never actually get here.
192194
}
193195
}
194196

@@ -204,16 +206,16 @@ void gr_opengl_deferred_lighting_finish()
204206
GR_DEBUG_SCOPE("Deferred apply single light");
205207

206208
switch (l.type) {
207-
case LT_CONE:
208-
case LT_POINT:
209+
case Light_Type::Cone:
210+
case Light_Type::Point:
209211
gr_bind_uniform_buffer(uniform_block_type::Lights,
210212
uniformAligner.getOffset(element_index),
211213
sizeof(graphics::deferred_light_data),
212214
buffer->bufferHandle());
213215
gr_opengl_draw_deferred_light_sphere(&l.vec);
214216
++element_index;
215217
break;
216-
case LT_TUBE:
218+
case Light_Type::Tube:
217219
gr_bind_uniform_buffer(uniform_block_type::Lights,
218220
uniformAligner.getOffset(element_index),
219221
sizeof(graphics::deferred_light_data),

code/lighting/lighting.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ extern vec3d Object_position;
112112
static void light_rotate(light * l)
113113
{
114114
switch( l->type ) {
115-
case LT_DIRECTIONAL:
115+
case Light_Type::Directional:
116116
// Rotate the light direction into local coodinates
117117

118118
vm_vec_rotate(&l->local_vec, &l->vec, &Light_matrix );
119119
break;
120120

121-
case LT_POINT: {
121+
case Light_Type::Point: {
122122
vec3d tempv;
123123
// Rotate the point into local coordinates
124124

@@ -127,7 +127,7 @@ static void light_rotate(light * l)
127127
}
128128
break;
129129

130-
case LT_TUBE:{
130+
case Light_Type::Tube:{
131131
vec3d tempv;
132132

133133
// Rotate the point into local coordinates
@@ -140,7 +140,7 @@ static void light_rotate(light * l)
140140
}
141141
break;
142142

143-
case LT_CONE:
143+
case Light_Type::Cone:
144144
break;
145145

146146
default:
@@ -162,7 +162,7 @@ void light_add_directional(const vec3d *dir, float intensity, float r, float g,
162162

163163
light l;
164164

165-
l.type = LT_DIRECTIONAL;
165+
l.type = Light_Type::Directional;
166166

167167
vm_vec_copy_scale( &l.vec, dir, -1.0f );
168168

@@ -205,7 +205,7 @@ void light_add_point(const vec3d *pos, float r1, float r2, float intensity, floa
205205

206206
Num_lights++;
207207

208-
l.type = LT_POINT;
208+
l.type = Light_Type::Point;
209209
l.vec = *pos;
210210
l.r = r;
211211
l.g = g;
@@ -243,7 +243,7 @@ void light_add_point_unique(const vec3d *pos, float r1, float r2, float intensit
243243

244244
Num_lights++;
245245

246-
l.type = LT_POINT;
246+
l.type = Light_Type::Point;
247247
l.vec = *pos;
248248
l.r = r;
249249
l.g = g;
@@ -283,7 +283,7 @@ void light_add_tube(const vec3d *p0, const vec3d *p1, float r1, float r2, float
283283

284284
Num_lights++;
285285

286-
l.type = LT_TUBE;
286+
l.type = Light_Type::Tube;
287287
l.vec = *p0;
288288
l.vec2 = *p1;
289289
l.r = r;
@@ -408,23 +408,23 @@ void light_apply_rgb( ubyte *param_r, ubyte *param_g, ubyte *param_b, const vec3
408408
dist = -1.0f;
409409
switch(l.type){
410410
// point lights
411-
case LT_POINT:
411+
case Light_Type::Point:
412412
vm_vec_sub( &to_light, &l.local_vec, pos );
413413
break;
414414

415415
// tube lights
416-
case LT_TUBE:
416+
case Light_Type::Tube:
417417
if(vm_vec_dist_to_line(pos, &l.local_vec, &l.local_vec2, &temp, &dist) != 0){
418418
continue;
419419
}
420420
vm_vec_sub(&to_light, &temp, pos);
421421
dist *= dist; // since we use radius squared
422422
break;
423423

424-
case LT_DIRECTIONAL:
424+
case Light_Type::Directional:
425425
continue;
426426

427-
case LT_CONE:
427+
case Light_Type::Cone:
428428
continue;
429429

430430
// others. BAD
@@ -501,7 +501,7 @@ void light_add_cone(const vec3d *pos, const vec3d *dir, float angle, float inner
501501

502502
Num_lights++;
503503

504-
l.type = LT_CONE;
504+
l.type = Light_Type::Cone;
505505
l.vec = *pos;
506506
l.vec2= *dir;
507507
l.cone_angle = angle;
@@ -536,23 +536,23 @@ void scene_lights::addLight(const light *light_ptr)
536536

537537
AllLights.push_back(*light_ptr);
538538

539-
if ( light_ptr->type == LT_DIRECTIONAL ) {
539+
if ( light_ptr->type == Light_Type::Directional ) {
540540
StaticLightIndices.push_back(AllLights.size() - 1);
541541
}
542542
}
543543

544544
void scene_lights::setLightFilter(int objnum, const vec3d *pos, float rad)
545545
{
546-
size_t i;
547-
546+
size_t i = 0;
548547
// clear out current filtered lights
549548
FilteredLights.clear();
550549

551550
for ( auto& l : AllLights ) {
552551
switch ( l.type ) {
553-
case LT_DIRECTIONAL:
552+
case Light_Type::Directional:
553+
++i;
554554
continue;
555-
case LT_POINT: {
555+
case Light_Type::Point: {
556556
// if this is a "unique" light source, it only affects one guy
557557
if ( l.affected_objnum >= 0 ) {
558558
if ( objnum == l.affected_objnum ) {
@@ -583,7 +583,7 @@ void scene_lights::setLightFilter(int objnum, const vec3d *pos, float rad)
583583
}
584584
}
585585
break;
586-
case LT_TUBE: {
586+
case Light_Type::Tube: {
587587
if ( l.light_ignore_objnum != objnum ) {
588588
vec3d nearest;
589589
float dist_squared, max_dist_squared;
@@ -599,12 +599,13 @@ void scene_lights::setLightFilter(int objnum, const vec3d *pos, float rad)
599599
}
600600
break;
601601

602-
case LT_CONE:
602+
case Light_Type::Cone:
603603
break;
604604

605605
default:
606606
break;
607607
}
608+
++i;
608609
}
609610
}
610611

code/lighting/lighting.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@
2727
#define LT_TUBE 2 // A tube light, like a fluorescent light
2828
#define LT_CONE 3 // A cone light, like a flood light
2929

30+
enum class Light_Type : int {
31+
Directional = 0,// A light like a sun
32+
Point = 1, // A point light, like an explosion
33+
Tube = 2, // A tube light, like a fluorescent light
34+
Cone = 3 // A cone light, like a flood light
35+
};
36+
3037
typedef struct light {
31-
int type; // What type of light this is
38+
Light_Type type; // What type of light this is
3239
vec3d vec; // location in world space of a point light or the direction of a directional light or the first point on the tube for a tube light
3340
vec3d vec2; // second point on a tube light or direction of a cone light
3441
vec3d local_vec; // rotated light vector

code/model/modelrender.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ void model_draw_list::init()
584584
reset();
585585

586586
for (auto& l : Lights) {
587-
if ( l.type == LT_DIRECTIONAL || !Deferred_lighting ) {
587+
if ( l.type == Light_Type::Directional || !Deferred_lighting ) {
588588
Scene_light_handler.addLight(&l);
589589
}
590590
}

0 commit comments

Comments
 (0)