]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_light.c
added loadsize variable set by COM_LoadFile
[xonotic/darkplaces.git] / r_light.c
index 39cde86d07df028f448a88452603ea3c70aadaf3..168efc5d2f73828f2c85d9ea81f16940bd55fa6f 100644 (file)
--- a/r_light.c
+++ b/r_light.c
@@ -23,24 +23,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 cvar_t r_lightmodels = {"r_lightmodels", "1"};
 
-extern cvar_t gl_transform;
+void r_light_start(void)
+{
+}
 
-void r_light_start()
+void r_light_shutdown(void)
 {
 }
 
-void r_light_shutdown()
+void r_light_newmap(void)
 {
 }
 
-void R_Light_Init()
+void R_Light_Init(void)
 {
        Cvar_RegisterVariable(&r_lightmodels);
-       R_RegisterModule("R_Light", r_light_start, r_light_shutdown);
+       R_RegisterModule("R_Light", r_light_start, r_light_shutdown, r_light_newmap);
 }
 
-int    r_dlightframecount;
-
 /*
 ==================
 R_AnimateLight
@@ -85,6 +85,7 @@ void R_OldMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex
 {
        float           ndist, maxdist;
        msurface_t      *surf;
+       mleaf_t         *leaf;
        int                     i;
 
        if (!r_dynamic.value)
@@ -99,35 +100,32 @@ void R_OldMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex
 
 loc0:
        if (node->contents < 0)
+       {
+               if (node->contents != CONTENTS_SOLID)
+               {
+                       leaf = (mleaf_t *)node;
+                       if (leaf->dlightframe != r_framecount) // not dynamic until now
+                       {
+                               leaf->dlightbits[0] = leaf->dlightbits[1] = leaf->dlightbits[2] = leaf->dlightbits[3] = leaf->dlightbits[4] = leaf->dlightbits[5] = leaf->dlightbits[6] = leaf->dlightbits[7] = 0;
+                               leaf->dlightframe = r_framecount;
+                       }
+                       leaf->dlightbits[bitindex] |= bit;
+               }
                return;
+       }
 
        ndist = PlaneDiff(lightorigin, node->plane);
        
        if (ndist > light->radius)
        {
-               if (node->children[0]->contents >= 0) // LordHavoc: save some time by not pushing another stack frame
-               {
-                       node = node->children[0];
-                       goto loc0;
-               }
-               return;
+               node = node->children[0];
+               goto loc0;
        }
        if (ndist < -light->radius)
        {
-               if (node->children[1]->contents >= 0) // LordHavoc: save some time by not pushing another stack frame
-               {
-                       node = node->children[1];
-                       goto loc0;
-               }
-               return;
-       }
-
-       if (node->dlightframe != r_dlightframecount) // not dynamic until now
-       {
-               node->dlightbits[0] = node->dlightbits[1] = node->dlightbits[2] = node->dlightbits[3] = node->dlightbits[4] = node->dlightbits[5] = node->dlightbits[6] = node->dlightbits[7] = 0;
-               node->dlightframe = r_dlightframecount;
+               node = node->children[1];
+               goto loc0;
        }
-       node->dlightbits[bitindex] |= bit;
 
 // mark the polygons
        surf = cl.worldmodel->surfaces + node->firstsurface;
@@ -135,6 +133,8 @@ loc0:
        {
                int d;
                float dist, dist2, impact[3];
+               if (surf->visframe != r_framecount)
+                       continue;
                dist = ndist;
                if (surf->flags & SURF_PLANEBACK)
                        dist = -dist;
@@ -188,20 +188,20 @@ loc0:
                        }
                }
 
-               if (surf->dlightframe != r_dlightframecount) // not dynamic until now
+               if (surf->dlightframe != r_framecount) // not dynamic until now
                {
                        surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
-                       surf->dlightframe = r_dlightframecount;
+                       surf->dlightframe = r_framecount;
                }
                surf->dlightbits[bitindex] |= bit;
 
                /*
                if (((surf->flags & SURF_PLANEBACK) == 0) == ((PlaneDist(lightorigin, surf->plane)) >= surf->plane->dist))
                {
-                       if (surf->dlightframe != r_dlightframecount) // not dynamic until now
+                       if (surf->dlightframe != r_framecount) // not dynamic until now
                        {
                                surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
-                               surf->dlightframe = r_dlightframecount;
+                               surf->dlightframe = r_framecount;
                        }
                        surf->dlightbits[bitindex] |= bit;
                }
@@ -284,20 +284,19 @@ void R_VisMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex
                                        if (c & (1<<i))
                                        {
                                                leaf = &model->leafs[(k << 3)+i+1];
-                                               leaf->lightframe = lightframe;
-                                               if (leaf->visframe != r_visframecount)
+                                               if (leaf->visframe != r_framecount)
                                                        continue;
                                                if (leaf->contents == CONTENTS_SOLID)
                                                        continue;
                                                // if out of the light radius, skip
-                                               if (leaf->minmaxs[0] > high[0] || leaf->minmaxs[3] < low[0]
-                                                || leaf->minmaxs[1] > high[1] || leaf->minmaxs[4] < low[1]
-                                                || leaf->minmaxs[2] > high[2] || leaf->minmaxs[5] < low[2])
+                                               if (leaf->mins[0] > high[0] || leaf->maxs[0] < low[0]
+                                                || leaf->mins[1] > high[1] || leaf->maxs[1] < low[1]
+                                                || leaf->mins[2] > high[2] || leaf->maxs[2] < low[2])
                                                        continue;
-                                               if (leaf->dlightframe != r_dlightframecount) // not dynamic until now
+                                               if (leaf->dlightframe != r_framecount) // not dynamic until now
                                                {
                                                        leaf->dlightbits[0] = leaf->dlightbits[1] = leaf->dlightbits[2] = leaf->dlightbits[3] = leaf->dlightbits[4] = leaf->dlightbits[5] = leaf->dlightbits[6] = leaf->dlightbits[7] = 0;
-                                                       leaf->dlightframe = r_dlightframecount;
+                                                       leaf->dlightframe = r_framecount;
                                                }
                                                leaf->dlightbits[bitindex] |= bit;
                                                if ((m = leaf->nummarksurfaces))
@@ -362,10 +361,10 @@ void R_VisMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex
                                                                                }
                                                                        }
 
-                                                                       if (surf->dlightframe != r_dlightframecount) // not dynamic until now
+                                                                       if (surf->dlightframe != r_framecount) // not dynamic until now
                                                                        {
                                                                                surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
-                                                                               surf->dlightframe = r_dlightframecount;
+                                                                               surf->dlightframe = r_framecount;
                                                                        }
                                                                        surf->dlightbits[bitindex] |= bit;
                                                                }
@@ -394,8 +393,6 @@ void R_PushDlights (void)
        int             i;
        dlight_t        *l;
 
-       r_dlightframecount = r_framecount + 1;  // because the count hasn't advanced yet for this frame
-
        if (!r_dynamic.value)
                return;
 
@@ -403,7 +400,7 @@ void R_PushDlights (void)
 
        for (i=0 ; i<MAX_DLIGHTS ; i++, l++)
        {
-               if (l->die < cl.time || !l->radius)
+               if (!l->radius)
                        continue;
 //             R_MarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel->nodes );
                R_VisMarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel);
@@ -422,8 +419,6 @@ LIGHT SAMPLING
 mplane_t               *lightplane;
 vec3_t                 lightspot;
 
-extern cvar_t r_ambient;
-
 /*
 int RecursiveLightPoint (vec3_t color, mnode_t *node, vec3_t start, vec3_t end)
 {
@@ -685,7 +680,7 @@ void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits)
                                if (!((1 << i) & dlightbits[j]))
                                        continue;
                                k = (j<<5)+i;
-                               if (cl_dlights[k].die < cl.time || !cl_dlights[k].radius)
+                               if (!cl_dlights[k].radius)
                                        continue;
                                VectorSubtract (org, cl_dlights[k].origin, dist);
                                f = DotProduct(dist, dist) + LIGHTOFFSET;
@@ -702,7 +697,7 @@ void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits)
        }
 }
 
-void R_CompleteLightPoint (vec3_t color, vec3_t p)
+void R_CompleteLightPoint (vec3_t color, vec3_t p, int dynamic)
 {
        mleaf_t *leaf;
        leaf = Mod_PointInLeaf(p, cl.worldmodel);
@@ -721,7 +716,8 @@ void R_CompleteLightPoint (vec3_t color, vec3_t p)
        color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
        RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
 
-       R_DynamicLightPoint(color, p, leaf->dlightbits);
+       if (dynamic)
+               R_DynamicLightPoint(color, p, leaf->dlightbits);
 }
 
 void R_ModelLightPoint (vec3_t color, vec3_t p, int *dlightbits)
@@ -745,7 +741,7 @@ void R_ModelLightPoint (vec3_t color, vec3_t p, int *dlightbits)
        color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
        RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
 
-       if (leaf->dlightframe == r_dlightframecount)
+       if (leaf->dlightframe == r_framecount)
        {
                dlightbits[0] = leaf->dlightbits[0];
                dlightbits[1] = leaf->dlightbits[1];
@@ -772,7 +768,7 @@ void R_DynamicLightPointNoMask(vec3_t color, vec3_t org)
 
        for (i=0 ; i<MAX_DLIGHTS ; i++)
        {
-               if (cl_dlights[i].die < cl.time || !cl_dlights[i].radius)
+               if (!cl_dlights[i].radius)
                        continue;
                VectorSubtract (org, cl_dlights[i].origin, dist);
                f = DotProduct(dist, dist) + LIGHTOFFSET;
@@ -790,11 +786,7 @@ void R_DynamicLightPointNoMask(vec3_t color, vec3_t org)
 }
 */
 
-extern float *aliasvert;
-extern float *aliasvertnorm;
-extern byte *aliasvertcolor;
-extern float modelalpha;
-void R_LightModel(int numverts, vec3_t center, vec3_t basecolor)
+void R_LightModel(entity_t *ent, int numverts, vec3_t center, vec3_t basecolor)
 {
        // LordHavoc: warning: reliance on int being 4 bytes here (of course the d_8to24table relies on that too...)
        int i, j, nearlights = 0, color;
@@ -812,17 +804,17 @@ void R_LightModel(int numverts, vec3_t center, vec3_t basecolor)
        a = (byte) bound((int) 0, (int) (modelalpha * 255.0f), (int) 255);
        if (lighthalf)
        {
-               mod[0] = currententity->colormod[0] * 0.5f;
-               mod[1] = currententity->colormod[1] * 0.5f;
-               mod[2] = currententity->colormod[2] * 0.5f;
+               mod[0] = ent->render.colormod[0] * 0.5f;
+               mod[1] = ent->render.colormod[1] * 0.5f;
+               mod[2] = ent->render.colormod[2] * 0.5f;
        }
        else
        {
-               mod[0] = currententity->colormod[0];
-               mod[1] = currententity->colormod[1];
-               mod[2] = currententity->colormod[2];
+               mod[0] = ent->render.colormod[0];
+               mod[1] = ent->render.colormod[1];
+               mod[2] = ent->render.colormod[2];
        }
-       if (currententity->effects & EF_FULLBRIGHT)
+       if (ent->render.effects & EF_FULLBRIGHT)
        {
                ((byte *)&color)[0] = (byte) (255.0f * mod[0]);
                ((byte *)&color)[1] = (byte) (255.0f * mod[1]);
@@ -864,7 +856,7 @@ void R_LightModel(int numverts, vec3_t center, vec3_t basecolor)
                        nearlight[nearlights].color[0] = cl_dlights[i].color[0] * t1 * mod[0];
                        nearlight[nearlights].color[1] = cl_dlights[i].color[1] * t1 * mod[1];
                        nearlight[nearlights].color[2] = cl_dlights[i].color[2] * t1 * mod[2];
-                       if (r_lightmodels.value)
+                       if (r_lightmodels.value && (ent == NULL || ent != cl_dlights[i].ent))
                                nearlights++;
                        else
                        {