MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DestroyLight

Function DestroyLight

Descent3/lighting.cpp:1995–2221  ·  view source on GitHub ↗

Kills the lighting that a face casts and dampens all the faces that light influences

Source from the content-addressed store, hash-verified

1993
1994// Kills the lighting that a face casts and dampens all the faces that light influences
1995void DestroyLight(int roomnum, int facenum) {
1996 vector vecs[MAX_VERTS_PER_FACE], center;
1997 room *destroy_rp = &Rooms[roomnum];
1998 face *destroy_fp = &destroy_rp->faces[facenum];
1999 float r, g, b;
2000 fvi_face_room_list facelist[MAX_DYNAMIC_FACES];
2001 int num_faces, i;
2002 uint16_t lmilist[MAX_DYNAMIC_FACES];
2003 int num_spoken_for = 0;
2004
2005 if (Dedicated_server)
2006 return;
2007
2008 float mul = ((float)destroy_fp->light_multiple) / 4.0;
2009
2010 r = GameTextures[destroy_fp->tmap].r * mul;
2011 g = GameTextures[destroy_fp->tmap].g * mul;
2012 b = GameTextures[destroy_fp->tmap].b * mul;
2013
2014 // Get highest component
2015 float rmax = std::max({r, g, b});
2016
2017 // Get the normalized color that this face emits
2018 float red_scale = r / rmax;
2019 float green_scale = g / rmax;
2020 float blue_scale = b / rmax;
2021
2022 // red_scale/=30;
2023 // green_scale/=30;
2024 // blue_scale/=30;
2025
2026 mprintf(0, "r=%f g=%f b=%f\n", red_scale, green_scale, blue_scale);
2027
2028 // Get center and area of light face
2029 for (i = 0; i < destroy_fp->num_verts; i++)
2030 vecs[i] = destroy_rp->verts[destroy_fp->face_verts[i]];
2031
2032 float area = vm_GetCentroid(&center, vecs, destroy_fp->num_verts);
2033
2034 // Get the sphere of influence of this light
2035 float power = rmax * area;
2036 float temp_ignore = DESTROYABLE_IGNORE_LIMIT / power;
2037 float express = 1.0 / temp_ignore;
2038 express /= 3.14f;
2039 express -= area;
2040 float sphere_dist = sqrt(express);
2041
2042 // ApplyLightingToObjects (pos,roomnum,light_dist,red_scale,green_scale,blue_scale,light_direction,dot_range);
2043
2044 num_faces = fvi_QuickDistFaceList(roomnum, &center, sphere_dist, facelist, MAX_DYNAMIC_FACES);
2045
2046 for (i = 0; i < num_faces; i++) {
2047 room *rp = &Rooms[facelist[i].room_index];
2048 face *fp = &rp->faces[facelist[i].face_index];
2049
2050 ASSERT(Rooms[facelist[i].room_index].used);
2051 ASSERT(facelist[i].face_index < Rooms[facelist[i].room_index].num_faces);
2052

Callers 2

ProcessTestKeysFunction · 0.85

Calls 10

fvi_QuickDistFaceListFunction · 0.85
lmi_wFunction · 0.85
lmi_hFunction · 0.85
lm_wFunction · 0.85
lm_dataFunction · 0.85
BlendLightingEdgesFunction · 0.85
vm_GetCentroidFunction · 0.50
vm_DotProductFunction · 0.50
vm_VectorToMatrixFunction · 0.50
vm_VectorDistanceQuickFunction · 0.50

Tested by

no test coverage detected