]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
allow .rtlights files to have style values outside the range
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 30 Jan 2014 02:05:50 +0000 (02:05 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 30 Jan 2014 02:05:50 +0000 (02:05 +0000)
0...MAX_LIGHTSTYLES - in particular, -1 is used by fte for unstyled
lights and this is a compatible behavior, just that the loader was
getting in the way.

for safety the MAX_LIGHTSTYLES comparison has been added to each use of
light->style in rendering.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12052 d7cf8633-e32d-0410-b094-e92efae38249

r_shadow.c

index a5f34d5badc47948a843fee762c36383c737cf02..2985a6d79fdc7435196e9c2a97b71ecf57c5e19e 100644 (file)
@@ -2651,7 +2651,7 @@ void R_Shadow_UpdateBounceGridTexture(void)
                w = r_shadow_lightintensityscale.value * (rtlight->ambientscale + rtlight->diffusescale + rtlight->specularscale);
                if (w * VectorLength2(rtlight->color) == 0.0f)
                        continue;
-               w *= (rtlight->style >= 0 ? r_refdef.scene.rtlightstylevalue[rtlight->style] : 1);
+               w *= ((rtlight->style >= 0 && rtlight->style < MAX_LIGHTSTYLES) ? r_refdef.scene.rtlightstylevalue[rtlight->style] : 1);
                VectorScale(rtlight->color, w, rtlight->photoncolor);
                //if (!VectorLength2(rtlight->photoncolor))
                //      continue;
@@ -3968,7 +3968,7 @@ static void R_Shadow_PrepareLight(rtlight_t *rtlight)
        rtlight->currentcubemap = rtlight->cubemapname[0] ? R_GetCubemap(rtlight->cubemapname) : r_texture_whitecube;
 
        // look up the light style value at this time
-       f = (rtlight->style >= 0 ? r_refdef.scene.rtlightstylevalue[rtlight->style] : 1) * r_shadow_lightintensityscale.value;
+       f = ((rtlight->style >= 0 && rtlight->style < MAX_LIGHTSTYLES) ? r_refdef.scene.rtlightstylevalue[rtlight->style] : 1) * r_shadow_lightintensityscale.value;
        VectorScale(rtlight->color, f, rtlight->currentcolor);
        /*
        if (rtlight->selected)
@@ -4629,7 +4629,7 @@ void R_Shadow_PrepareLights(int fbo, rtexture_t *depthtexture, rtexture_t *color
                for (lnum = 0;lnum < r_refdef.scene.numlights;lnum++)
                {
                        rtlight_t *rtlight = r_refdef.scene.lights[lnum];
-                       f = (rtlight->style >= 0 ? r_refdef.scene.lightstylevalue[rtlight->style] : 1) * r_shadow_lightintensityscale.value;
+                       f = ((rtlight->style >= 0 && rtlight->style < MAX_LIGHTSTYLES) ? r_refdef.scene.lightstylevalue[rtlight->style] : 1) * r_shadow_lightintensityscale.value;
                        VectorScale(rtlight->color, f, rtlight->currentcolor);
                }
        }
@@ -5343,12 +5343,10 @@ static dlight_t *R_Shadow_NewWorldLight(void)
 static void R_Shadow_UpdateWorldLight(dlight_t *light, vec3_t origin, vec3_t angles, vec3_t color, vec_t radius, vec_t corona, int style, int shadowenable, const char *cubemapname, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags)
 {
        matrix4x4_t matrix;
+
+       // note that style is no longer validated here, -1 is used for unstyled lights and >= MAX_LIGHTSTYLES is accepted for sake of editing rtlights files that might be out of bounds but perfectly formatted
+
        // validate parameters
-       if (style < 0 || style >= MAX_LIGHTSTYLES)
-       {
-               Con_Printf("R_Shadow_NewWorldLight: invalid light style number %i, must be >= 0 and < %i\n", light->style, MAX_LIGHTSTYLES);
-               style = 0;
-       }
        if (!cubemapname)
                cubemapname = "";