diff --git a/include/QF/render.h b/include/QF/render.h index 05dff2f65..94bab9f5d 100644 --- a/include/QF/render.h +++ b/include/QF/render.h @@ -36,8 +36,6 @@ // dynamic lights =========================================================== -#define MAX_DLIGHTS 32 - typedef struct dlight_s { int key; // so entities can reuse same entry @@ -49,9 +47,10 @@ typedef struct dlight_s float color[3]; // Don't use alpha --KB } dlight_t; -extern dlight_t r_dlights[MAX_DLIGHTS]; +extern dlight_t *r_dlights; +extern unsigned int r_maxdlights; -// FIXME client_state_t should hold all pieces of the client state +// FIXME: client_state_t should hold all pieces of the client state typedef struct { int length; @@ -60,7 +59,7 @@ typedef struct extern lightstyle_t r_lightstyle[MAX_LIGHTSTYLES]; -// FIXME lightstyle_t and r_lightstyle were in client.h, is this the best place for them? +// FIXME: lightstyle_t and r_lightstyle were in client.h, is this the best place for them? //=============== diff --git a/libs/video/renderer/gl/gl_dyn_lights.c b/libs/video/renderer/gl/gl_dyn_lights.c index 042ee078f..c455ede34 100644 --- a/libs/video/renderer/gl/gl_dyn_lights.c +++ b/libs/video/renderer/gl/gl_dyn_lights.c @@ -126,7 +126,7 @@ R_RenderDlights (void) qfglShadeModel (GL_SMOOTH); l = r_dlights; - for (i = 0; i < MAX_DLIGHTS; i++, l++) { + for (i = 0; i < r_maxdlights; i++, l++) { if (l->die < r_realtime || !l->radius) continue; R_RenderDlight (l); diff --git a/libs/video/renderer/gl/gl_dyn_part.c b/libs/video/renderer/gl/gl_dyn_part.c index 86d5b1fc5..bb370210f 100644 --- a/libs/video/renderer/gl/gl_dyn_part.c +++ b/libs/video/renderer/gl/gl_dyn_part.c @@ -48,6 +48,7 @@ static const char rcsid[] = #include "QF/vfs.h" #include "QF/GL/defines.h" #include "QF/GL/funcs.h" +#include "QF/GL/qf_explosions.h" #include "compat.h" #include "r_cvar.h" @@ -58,7 +59,7 @@ static const char rcsid[] = int ramp[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 }; extern int part_tex_dot, part_tex_smoke, part_tex_spark; -extern short r_maxparticles, numparticles; +extern unsigned int r_maxparticles, numparticles; extern particle_t *particles, **freeparticles; @@ -169,7 +170,9 @@ R_ParticleExplosion (vec3_t org) { if (numparticles >= r_maxparticles) return; - +/* + R_NewExplosion (org); +*/ particle_new_random (pt_smokecloud, part_tex_smoke, org, 4, 30, 8, r_realtime + 5, (rand () & 7) + 8, 128 + (rand () & 63)); diff --git a/libs/video/renderer/gl/gl_rmain.c b/libs/video/renderer/gl/gl_rmain.c index d969701b6..aa01e461a 100644 --- a/libs/video/renderer/gl/gl_rmain.c +++ b/libs/video/renderer/gl/gl_rmain.c @@ -194,7 +194,7 @@ R_DrawSpriteModel (entity_t *e) AngleVectors (currententity->angles, v_forward, v_right, v_up); up = v_up; right = v_right; - } else { // normal sprite + } else { // normal sprite up = vup; right = vright; } @@ -298,7 +298,6 @@ GL_DrawAliasFrame (vert_order_t *vo, qboolean fb) if (modelalpha != 1.0) qfglDepthMask (GL_TRUE); - } extern vec3_t lightspot; @@ -575,7 +574,7 @@ R_DrawAliasModel (entity_t *e, qboolean cull) if (e == r_view_model) shadelight = max (shadelight, 24); - for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) { + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (r_dlights[lnum].die >= r_realtime) { VectorSubtract (currententity->origin, r_dlights[lnum].origin, dist); @@ -828,17 +827,14 @@ static void R_SetFrustum (void) { int i; - if (r_refdef.fov_x == 90) { // front side is visible - VectorAdd (vpn, vright, frustum[0].normal); VectorSubtract (vpn, vright, frustum[1].normal); VectorAdd (vpn, vup, frustum[2].normal); VectorSubtract (vpn, vup, frustum[3].normal); } else { - // rotate VPN right by FOV_X/2 degrees RotatePointAroundVector (frustum[0].normal, vup, vpn, -(90 - r_refdef.fov_x / 2)); diff --git a/libs/video/renderer/gl/gl_rsurf.c b/libs/video/renderer/gl/gl_rsurf.c index 849a9188c..7c4213d45 100644 --- a/libs/video/renderer/gl/gl_rsurf.c +++ b/libs/video/renderer/gl/gl_rsurf.c @@ -147,7 +147,7 @@ R_AddDynamicLights (msurface_t *surf) smax = (surf->extents[0] >> 4) + 1; tmax = (surf->extents[1] >> 4) + 1; - for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) { + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (!(surf->dlightbits & (1 << lnum))) continue; // not lit by this light @@ -236,7 +236,7 @@ R_BuildLightMap (msurface_t *surf, byte * dest, int stride) // add all the lightmaps if (lightmap) { - for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; + for (maps = 0; maps < r_maxdlights && surf->styles[maps] != 255; maps++) { scale = d_lightstylevalue[surf->styles[maps]]; surf->cached_light[maps] = scale; // 8.8 fraction @@ -676,7 +676,7 @@ R_DrawBrushModel (entity_t *e) if (clmodel->firstmodelsurface != 0 && r_dlight_lightmap->int_val) { vec3_t lightorigin; - for (k = 0; k < MAX_DLIGHTS; k++) { + for (k = 0; k < r_maxdlights; k++) { if ((r_dlights[k].die < r_realtime) || (!r_dlights[k].radius)) continue; diff --git a/libs/video/renderer/r_cvar.c b/libs/video/renderer/r_cvar.c index 37f595aaf..5601eeb16 100644 --- a/libs/video/renderer/r_cvar.c +++ b/libs/video/renderer/r_cvar.c @@ -86,6 +86,7 @@ cvar_t *r_aliastransbase; cvar_t *r_ambient; cvar_t *r_clearcolor; cvar_t *r_dlight_lightmap; +cvar_t *r_dlight_max; cvar_t *r_drawentities; cvar_t *r_drawexplosions; // DESPAIR cvar_t *r_drawflat; @@ -128,10 +129,11 @@ cvar_t *scr_showram; cvar_t *scr_showturtle; cvar_t *scr_viewsize; -extern short r_maxparticles; -extern cvar_t *gl_sky_divide; // FIXME +extern unsigned int r_maxparticles; +extern cvar_t *gl_sky_divide; // FIXME extern void R_MaxParticlesCheck (cvar_t *var); +extern void R_MaxDlightsCheck (cvar_t *var); static void @@ -257,6 +259,8 @@ R_Init_Cvars (void) r_dlight_lightmap = Cvar_Get ("r_dlight_lightmap", "1", CVAR_ARCHIVE, NULL, "Set to 1 for high quality dynamic " "lighting."); + r_dlight_max = Cvar_Get ("r_dlight_max", "32", CVAR_ARCHIVE, + R_MaxDlightsCheck, "Number of dynamic lights."); r_drawentities = Cvar_Get ("r_drawentities", "1", CVAR_NONE, NULL, "Toggles drawing of entities (almost " "everything but the world)"); diff --git a/libs/video/renderer/r_light.c b/libs/video/renderer/r_light.c index 1c74a9ca6..9a578fa5f 100644 --- a/libs/video/renderer/r_light.c +++ b/libs/video/renderer/r_light.c @@ -43,13 +43,34 @@ static const char rcsid[] = #include "QF/cvar.h" #include "QF/render.h" +#include "compat.h" #include "r_cvar.h" #include "r_local.h" #include "r_shared.h" -dlight_t r_dlights[MAX_DLIGHTS]; +dlight_t *r_dlights; lightstyle_t r_lightstyle[MAX_LIGHTSTYLES]; +unsigned int r_maxdlights; + + +void +R_MaxDlightsCheck (cvar_t *var) +{ + // FIXME: 1 minimum should be 0, if it doesn't require excess testing in + // *_rsurf.c + if (r_dynamic) + r_maxdlights = max(var->int_val * r_dynamic->int_val, 1); + else + r_maxdlights = max(var->int_val, 1); + + free (r_dlights); + + r_dlights = (dlight_t *) calloc (r_maxdlights, sizeof (dlight_t)); + + R_ClearDlights(); +} + void R_AnimateLight (void) { @@ -283,7 +304,7 @@ R_PushDlights (vec3_t entorigin) l = r_dlights; - for (i = 0; i < MAX_DLIGHTS; i++, l++) { + for (i = 0; i < r_maxdlights; i++, l++) { if (l->die < r_realtime || !l->radius) continue; VectorSubtract (l->origin, entorigin, lightorigin); @@ -416,7 +437,7 @@ R_AllocDlight (int key) // first look for an exact key match if (key) { dl = r_dlights; - for (i = 0; i < MAX_DLIGHTS; i++, dl++) { + for (i = 0; i < r_maxdlights; i++, dl++) { if (dl->key == key) { memset (dl, 0, sizeof (*dl)); dl->key = key; @@ -427,7 +448,7 @@ R_AllocDlight (int key) } // then look for anything else dl = r_dlights; - for (i = 0; i < MAX_DLIGHTS; i++, dl++) { + for (i = 0; i < r_maxdlights; i++, dl++) { if (dl->die < r_realtime) { memset (dl, 0, sizeof (*dl)); dl->key = key; @@ -449,7 +470,7 @@ R_DecayLights (double frametime) dlight_t *dl; dl = r_dlights; - for (i = 0; i < MAX_DLIGHTS; i++, dl++) { + for (i = 0; i < r_maxdlights; i++, dl++) { if (dl->die < r_realtime || !dl->radius) continue; diff --git a/libs/video/renderer/sw/sw_rmain.c b/libs/video/renderer/sw/sw_rmain.c index 58024977a..ce92a0909 100644 --- a/libs/video/renderer/sw/sw_rmain.c +++ b/libs/video/renderer/sw/sw_rmain.c @@ -519,7 +519,7 @@ R_DrawEntitiesOnList (void) lighting.plightvec = lightvec; - for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) { + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (r_dlights[lnum].die >= r_realtime) { VectorSubtract (currententity->origin, r_dlights[lnum].origin, dist); @@ -581,7 +581,7 @@ R_DrawViewModel (void) r_viewlighting.shadelight = j; // add dynamic lights - for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) { + for (lnum = 0; lnum < r_maxdlights; lnum++) { dl = &r_dlights[lnum]; if (!dl->radius) continue; @@ -708,7 +708,7 @@ R_DrawBEntitiesOnList (void) if (clmodel->firstmodelsurface != 0) { vec3_t lightorigin; - for (k = 0; k < MAX_DLIGHTS; k++) { + for (k = 0; k < r_maxdlights; k++) { if ((r_dlights[k].die < r_realtime) || (!r_dlights[k].radius)) continue; diff --git a/libs/video/renderer/sw/sw_rpart.c b/libs/video/renderer/sw/sw_rpart.c index c73f7d30f..1f8afd252 100644 --- a/libs/video/renderer/sw/sw_rpart.c +++ b/libs/video/renderer/sw/sw_rpart.c @@ -50,7 +50,7 @@ int ramp3[8] = { 0x6d, 0x6b, 6, 5, 4, 3 }; vec3_t r_pright, r_pup, r_ppn; -extern short r_maxparticles; +extern unsigned int r_maxparticles; extern particle_t *active_particles, *free_particles, *particles; diff --git a/libs/video/renderer/sw/sw_rsurf.c b/libs/video/renderer/sw/sw_rsurf.c index 26b08e6d3..94035a8ea 100644 --- a/libs/video/renderer/sw/sw_rsurf.c +++ b/libs/video/renderer/sw/sw_rsurf.c @@ -81,7 +81,7 @@ R_AddDynamicLights (void) tmax = (surf->extents[1] >> 4) + 1; tex = surf->texinfo; - for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) { + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (!(surf->dlightbits & (1 << lnum))) continue; // not lit by this light diff --git a/libs/video/renderer/sw32/sw32_rmain.c b/libs/video/renderer/sw32/sw32_rmain.c index 625fe6f93..3d13a16fd 100644 --- a/libs/video/renderer/sw32/sw32_rmain.c +++ b/libs/video/renderer/sw32/sw32_rmain.c @@ -547,7 +547,7 @@ R_DrawEntitiesOnList (void) lighting.plightvec = lightvec; - for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) { + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (r_dlights[lnum].die >= r_realtime) { VectorSubtract (currententity->origin, r_dlights[lnum].origin, dist); @@ -609,7 +609,7 @@ R_DrawViewModel (void) r_viewlighting.shadelight = j; // add dynamic lights - for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) { + for (lnum = 0; lnum < r_maxdlights; lnum++) { dl = &r_dlights[lnum]; if (!dl->radius) continue; @@ -736,7 +736,7 @@ R_DrawBEntitiesOnList (void) if (clmodel->firstmodelsurface != 0) { vec3_t lightorigin; - for (k = 0; k < MAX_DLIGHTS; k++) { + for (k = 0; k < r_maxdlights; k++) { if ((r_dlights[k].die < r_realtime) || (!r_dlights[k].radius)) continue; diff --git a/libs/video/renderer/sw32/sw32_rpart.c b/libs/video/renderer/sw32/sw32_rpart.c index a260b5364..8dcdeaa0e 100644 --- a/libs/video/renderer/sw32/sw32_rpart.c +++ b/libs/video/renderer/sw32/sw32_rpart.c @@ -50,7 +50,7 @@ int ramp3[8] = { 0x6d, 0x6b, 6, 5, 4, 3 }; vec3_t r_pright, r_pup, r_ppn; -extern short r_maxparticles; +extern unsigned int r_maxparticles; extern particle_t *active_particles, *free_particles, *particles; diff --git a/libs/video/renderer/sw32/sw32_rsurf.c b/libs/video/renderer/sw32/sw32_rsurf.c index 0836e53e9..d2a9d4f21 100644 --- a/libs/video/renderer/sw32/sw32_rsurf.c +++ b/libs/video/renderer/sw32/sw32_rsurf.c @@ -107,7 +107,7 @@ R_AddDynamicLights (void) tmax = (surf->extents[1] >> 4) + 1; tex = surf->texinfo; - for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) { + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (!(surf->dlightbits & (1 << lnum))) continue; // not lit by this light