Check return value on R_AllocDlight. Small optimization, people cutting r_dlight_max heavily should like it.

This commit is contained in:
Ragnvald Maartmann-Moe IV 2002-06-05 22:07:38 +00:00
parent f31705380f
commit 46949068a2
9 changed files with 100 additions and 72 deletions

View file

@ -146,13 +146,14 @@ R_ShowNearestLoc (void)
if (nearloc) { if (nearloc) {
dl = R_AllocDlight (4096); dl = R_AllocDlight (4096);
VectorCopy (nearloc->loc, dl->origin); if (dl) {
dl->radius = 200; VectorCopy (nearloc->loc, dl->origin);
dl->die = r_realtime + 0.1; dl->radius = 200;
dl->color[0] = 0; dl->die = r_realtime + 0.1;
dl->color[1] = 1; dl->color[0] = 0;
dl->color[2] = 0; dl->color[1] = 1;
dl->color[2] = 0;
}
VectorCopy (nearloc->loc, trueloc); VectorCopy (nearloc->loc, trueloc);
(*R_WizSpikeEffect) (trueloc); (*R_WizSpikeEffect) (trueloc);
} }

View file

@ -435,11 +435,9 @@ R_AllocDlight (int key)
{ {
int i; int i;
dlight_t *dl; dlight_t *dl;
static dlight_t dummy;
if (!r_maxdlights) { if (!r_maxdlights) {
memset (&dummy, 0, sizeof (dummy)); return NULL;
return &dummy;
} }
// first look for an exact key match // first look for an exact key match

View file

@ -465,11 +465,13 @@ R_ShowNearestLoc (void)
nearloc = locs_find (r_origin); nearloc = locs_find (r_origin);
if (nearloc) { if (nearloc) {
dl = R_AllocDlight (4096); dl = R_AllocDlight (4096);
VectorCopy (nearloc->loc, dl->origin); if (dl) {
dl->radius = 200; VectorCopy (nearloc->loc, dl->origin);
dl->die = r_realtime + 0.1; dl->radius = 200;
dl->color[1] = 1; dl->die = r_realtime + 0.1;
dl->color[1] = 1;
}
VectorCopy(nearloc->loc, trueloc); VectorCopy(nearloc->loc, trueloc);
R_RunParticleEffect(trueloc, vec3_origin, 252, 10); R_RunParticleEffect(trueloc, vec3_origin, 252, 10);
} }

View file

@ -493,11 +493,13 @@ R_ShowNearestLoc (void)
nearloc = locs_find (r_origin); nearloc = locs_find (r_origin);
if (nearloc) { if (nearloc) {
dl = R_AllocDlight (4096); dl = R_AllocDlight (4096);
VectorCopy (nearloc->loc, dl->origin); if (dl) {
dl->radius = 200; VectorCopy (nearloc->loc, dl->origin);
dl->die = r_realtime + 0.1; dl->radius = 200;
dl->color[1] = 1; dl->die = r_realtime + 0.1;
dl->color[1] = 1;
}
VectorCopy(nearloc->loc, trueloc); VectorCopy(nearloc->loc, trueloc);
R_RunParticleEffect(trueloc, vec3_origin, 252, 10); R_RunParticleEffect(trueloc, vec3_origin, 252, 10);
} }

View file

@ -433,9 +433,11 @@ CL_NewDlight (int key, vec3_t org, int effects)
if (!(effects & (EF_BLUE | EF_RED | EF_BRIGHTLIGHT | EF_DIMLIGHT))) if (!(effects & (EF_BLUE | EF_RED | EF_BRIGHTLIGHT | EF_DIMLIGHT)))
return; return;
radius = 200 + (rand () & 31);
dl = R_AllocDlight (key); dl = R_AllocDlight (key);
if (!dl)
return;
VectorCopy (org, dl->origin); VectorCopy (org, dl->origin);
switch (effects & (EF_BLUE | EF_RED)) { switch (effects & (EF_BLUE | EF_RED)) {
case EF_BLUE | EF_RED: case EF_BLUE | EF_RED:
VectorCopy (purple, dl->color); VectorCopy (purple, dl->color);
@ -450,6 +452,7 @@ CL_NewDlight (int key, vec3_t org, int effects)
VectorCopy (normal, dl->color); VectorCopy (normal, dl->color);
break; break;
} }
radius = 200 + (rand () & 31);
if (effects & EF_BRIGHTLIGHT) { if (effects & EF_BRIGHTLIGHT) {
radius += 200; radius += 200;
dl->origin[2] += 16; dl->origin[2] += 16;
@ -593,27 +596,31 @@ CL_RelinkEntities (void)
vec3_t fv, rv, uv; vec3_t fv, rv, uv;
dl = R_AllocDlight (i); dl = R_AllocDlight (i);
VectorCopy (ent->origin, dl->origin); if (dl) {
dl->origin[2] += 16; VectorCopy (ent->origin, dl->origin);
AngleVectors (ent->angles, fv, rv, uv); dl->origin[2] += 16;
AngleVectors (ent->angles, fv, rv, uv);
VectorMA (dl->origin, 18, fv, dl->origin); VectorMA (dl->origin, 18, fv, dl->origin);
dl->radius = 200 + (rand () & 31); dl->radius = 200 + (rand () & 31);
dl->minlight = 32; dl->minlight = 32;
dl->die = cl.time + 0.1; dl->die = cl.time + 0.1;
dl->color[0] = 0.2; dl->color[0] = 0.2;
dl->color[1] = 0.1; dl->color[1] = 0.1;
dl->color[2] = 0.05; dl->color[2] = 0.05;
}
} }
CL_NewDlight (i, ent->origin, state->baseline.effects); CL_NewDlight (i, ent->origin, state->baseline.effects);
if (VectorDistance_fast(state->msg_origins[1], ent->origin) > (256*256)) if (VectorDistance_fast(state->msg_origins[1], ent->origin) > (256*256))
VectorCopy (ent ->origin, state->msg_origins[1]); VectorCopy (ent ->origin, state->msg_origins[1]);
if (ent->model->flags & EF_ROCKET) { if (ent->model->flags & EF_ROCKET) {
dl = R_AllocDlight (i); dl = R_AllocDlight (i);
VectorCopy (ent->origin, dl->origin); if (dl) {
VectorCopy (r_firecolor->vec, dl->color); VectorCopy (ent->origin, dl->origin);
dl->radius = 200; VectorCopy (r_firecolor->vec, dl->color);
dl->die = cl.time + 0.1; dl->radius = 200;
dl->die = cl.time + 0.1;
}
R_RocketTrail (ent); R_RocketTrail (ent);
} else if (ent->model->flags & EF_GRENADE) } else if (ent->model->flags & EF_GRENADE)
R_GrenadeTrail (ent); R_GrenadeTrail (ent);

View file

@ -285,13 +285,15 @@ CL_ParseTEnt (void)
// light // light
dl = R_AllocDlight (0); dl = R_AllocDlight (0);
VectorCopy (pos, dl->origin); if (dl) {
dl->radius = 350; VectorCopy (pos, dl->origin);
dl->die = cl.time + 0.5; dl->radius = 350;
dl->decay = 300; dl->die = cl.time + 0.5;
dl->color[0] = 0.86; dl->decay = 300;
dl->color[1] = 0.31; dl->color[0] = 0.86;
dl->color[2] = 0.24; dl->color[1] = 0.31;
dl->color[2] = 0.24;
}
// sound // sound
S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1); S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
@ -342,8 +344,11 @@ CL_ParseTEnt (void)
MSG_ReadCoordV (net_message, pos); MSG_ReadCoordV (net_message, pos);
colorStart = MSG_ReadByte (net_message); colorStart = MSG_ReadByte (net_message);
colorLength = MSG_ReadByte (net_message); colorLength = MSG_ReadByte (net_message);
S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
R_ParticleExplosion2 (pos, colorStart, colorLength); R_ParticleExplosion2 (pos, colorStart, colorLength);
dl = R_AllocDlight (0); dl = R_AllocDlight (0);
if (!dl)
break;
VectorCopy (pos, dl->origin); VectorCopy (pos, dl->origin);
dl->radius = 350; dl->radius = 350;
dl->die = cl.time + 0.5; dl->die = cl.time + 0.5;
@ -354,7 +359,6 @@ CL_ParseTEnt (void)
3 + 1] * (1.0 / 255.0); 3 + 1] * (1.0 / 255.0);
dl->color[2] = vid_basepal[(colorStart + (rand() % colorLength)) * dl->color[2] = vid_basepal[(colorStart + (rand() % colorLength)) *
3 + 2] * (1.0 / 255.0); 3 + 2] * (1.0 / 255.0);
S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
break; break;
case TE_GUNSHOT: // bullet hitting wall case TE_GUNSHOT: // bullet hitting wall
@ -373,13 +377,15 @@ CL_ParseTEnt (void)
// light // light
dl = R_AllocDlight (0); dl = R_AllocDlight (0);
VectorCopy (pos, dl->origin); if (dl) {
dl->radius = 150; VectorCopy (pos, dl->origin);
dl->die = cl.time + 0.1; dl->radius = 150;
dl->decay = 200; dl->die = cl.time + 0.1;
dl->color[0] = 0.25; dl->decay = 200;
dl->color[1] = 0.40; dl->color[0] = 0.25;
dl->color[2] = 0.65; dl->color[1] = 0.40;
dl->color[2] = 0.65;
}
R_LightningBloodEffect (pos); R_LightningBloodEffect (pos);
break; break;

View file

@ -100,8 +100,9 @@ CL_NewDlight (int key, vec3_t org, int effects)
if (!(effects & (EF_BLUE | EF_RED | EF_BRIGHTLIGHT | EF_DIMLIGHT))) if (!(effects & (EF_BLUE | EF_RED | EF_BRIGHTLIGHT | EF_DIMLIGHT)))
return; return;
radius = 200 + (rand () & 31);
dl = R_AllocDlight (key); dl = R_AllocDlight (key);
if (!dl)
return;
VectorCopy (org, dl->origin); VectorCopy (org, dl->origin);
dl->die = cl.time + 0.1; dl->die = cl.time + 0.1;
switch (effects & (EF_BLUE | EF_RED)) { switch (effects & (EF_BLUE | EF_RED)) {
@ -118,6 +119,7 @@ CL_NewDlight (int key, vec3_t org, int effects)
VectorCopy (normal, dl->color); VectorCopy (normal, dl->color);
break; break;
} }
radius = 200 + (rand () & 31);
if (effects & EF_BRIGHTLIGHT) { if (effects & EF_BRIGHTLIGHT) {
radius += 200; radius += 200;
dl->origin[2] += 16; dl->origin[2] += 16;
@ -510,10 +512,12 @@ CL_LinkPacketEntities (void)
if (model->flags & EF_ROCKET) { if (model->flags & EF_ROCKET) {
dl = R_AllocDlight (-s1->number); dl = R_AllocDlight (-s1->number);
VectorCopy ((*ent)->origin, dl->origin); if (dl) {
VectorCopy (r_firecolor->vec, dl->color); VectorCopy ((*ent)->origin, dl->origin);
dl->radius = 200; VectorCopy (r_firecolor->vec, dl->color);
dl->die = cl.time + 0.1; dl->radius = 200;
dl->die = cl.time + 0.1;
}
} }
if (model->flags & EF_ROCKET) if (model->flags & EF_ROCKET)

View file

@ -1102,8 +1102,10 @@ CL_MuzzleFlash (void)
pl = &cl.frames[parsecountmod].playerstate[i - 1]; pl = &cl.frames[parsecountmod].playerstate[i - 1];
dl = R_AllocDlight (i); //FIXME dl = R_AllocDlight (i);
// this interfers with powerup glows, but we need more lights. if (!dl)
return;
VectorCopy (pl->origin, dl->origin); VectorCopy (pl->origin, dl->origin);
if (i - 1 == cl.playernum) if (i - 1 == cl.playernum)
AngleVectors (cl.viewangles, fv, rv, uv); AngleVectors (cl.viewangles, fv, rv, uv);

View file

@ -349,13 +349,15 @@ CL_ParseTEnt (void)
// light // light
dl = R_AllocDlight (0); dl = R_AllocDlight (0);
VectorCopy (pos, dl->origin); if (dl) {
dl->radius = 350; VectorCopy (pos, dl->origin);
dl->die = cl.time + 0.5; dl->radius = 350;
dl->decay = 300; dl->die = cl.time + 0.5;
dl->color[0] = 0.86; dl->decay = 300;
dl->color[1] = 0.31; dl->color[0] = 0.86;
dl->color[2] = 0.24; dl->color[1] = 0.31;
dl->color[2] = 0.24;
}
// sound // sound
S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1); S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
@ -408,8 +410,11 @@ CL_ParseTEnt (void)
MSG_ReadCoordV (net_message, pos); MSG_ReadCoordV (net_message, pos);
colorStart = MSG_ReadByte (net_message); colorStart = MSG_ReadByte (net_message);
colorLength = MSG_ReadByte (net_message); colorLength = MSG_ReadByte (net_message);
S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
R_ParticleExplosion2 (pos, colorStart, colorLength); R_ParticleExplosion2 (pos, colorStart, colorLength);
dl = R_AllocDlight (0); dl = R_AllocDlight (0);
if (!dl)
break;
VectorCopy (pos, dl->origin); VectorCopy (pos, dl->origin);
dl->radius = 350; dl->radius = 350;
dl->die = cl.time + 0.5; dl->die = cl.time + 0.5;
@ -420,7 +425,6 @@ CL_ParseTEnt (void)
3 + 1] * (1.0 / 255.0); 3 + 1] * (1.0 / 255.0);
dl->color[2] = vid_basepal[(colorStart + (rand() % colorLength)) * dl->color[2] = vid_basepal[(colorStart + (rand() % colorLength)) *
3 + 2] * (1.0 / 255.0); 3 + 2] * (1.0 / 255.0);
S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
break; break;
case TE_GUNSHOT: // bullet hitting wall case TE_GUNSHOT: // bullet hitting wall
@ -440,13 +444,15 @@ CL_ParseTEnt (void)
// light // light
dl = R_AllocDlight (0); dl = R_AllocDlight (0);
VectorCopy (pos, dl->origin); if (dl) {
dl->radius = 150; VectorCopy (pos, dl->origin);
dl->die = cl.time + 0.1; dl->radius = 150;
dl->decay = 200; dl->die = cl.time + 0.1;
dl->color[0] = 0.25; dl->decay = 200;
dl->color[1] = 0.40; dl->color[0] = 0.25;
dl->color[2] = 0.65; dl->color[1] = 0.40;
dl->color[2] = 0.65;
}
R_LightningBloodEffect (pos); R_LightningBloodEffect (pos);
break; break;