move dlight stuff out of cl_* into r_main.c. nq dlights seem to be broken,

but that seems to have been from before this work
This commit is contained in:
Bill Currie 2001-05-20 05:42:52 +00:00
parent f7330f078e
commit d360b01827
36 changed files with 247 additions and 222 deletions

View File

@ -34,6 +34,24 @@
#include "QF/model.h"
#include "QF/vid.h"
// dynamic lights ===========================================================
#define MAX_DLIGHTS 32
typedef struct dlight_s
{
int key; // so entities can reuse same entry
vec3_t origin;
float radius;
float die; // stop lighting after this time
float decay; // drop this each second
float minlight; // don't add when contributing less
float color[3]; // Don't use alpha --KB
} dlight_t;
extern dlight_t r_dlights[MAX_DLIGHTS];
//===============
#define TOP_RANGE 16 // soldier uniform colors
#define BOTTOM_RANGE 96
@ -140,7 +158,7 @@ void R_ViewChanged (vrect_t *pvrect, int lineadj, float aspect);
void R_AddEfrags (entity_t *ent);
void R_RemoveEfrags (entity_t *ent);
void R_NewMap (void);
void R_NewMap (model_t *worldmodel);
// LordHavoc: relative bmodel lighting
@ -166,4 +184,8 @@ void R_ClearEfrags (void);
void R_ClearEnts (void);
struct entity_s **R_NewEntity (void);
dlight_t *R_AllocDlight (int key);
void R_DecayLights (void);
void R_ClearDlights (void);
#endif // __render_h

View File

@ -42,21 +42,6 @@
#define BMODEL_FULLY_CLIPPED 0x10 // value returned by R_BmodelCheckBBox ()
// if bbox is trivially rejected
// dynamic lights ===========================================================
#define MAX_DLIGHTS 32
typedef struct
{
int key; // so entities can reuse same entry
vec3_t origin;
float radius;
float die; // stop lighting after this time
float decay; // drop this each second
float minlight; // don't add when contributing less
float color[3]; // Don't use alpha --KB
} dlight_t;
// color shifts =============================================================
typedef struct
@ -335,6 +320,7 @@ extern qboolean r_fov_greater_than_90;
extern int r_numvisedicts;
extern struct entity_s *r_visedicts[];
struct dlight_s;
void R_StoreEfrags (efrag_t **ppefrag);
void R_TimeRefresh_f (void);
@ -349,7 +335,7 @@ void R_cshift_f (void);
void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1);
void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip);
void R_SplitEntityOnNode2 (mnode_t *node);
void R_MarkLights (vec3_t lightorigin, dlight_t *light, int bit, mnode_t *node);
void R_MarkLights (vec3_t lightorigin, struct dlight_s *light, int bit, mnode_t *node);
void R_LoadSkys (const char *);

View File

@ -139,6 +139,7 @@ extern void R_MakeSky (void);
extern int ubasestep, errorterm, erroradjustup, erroradjustdown;
extern double r_realtime;
extern double r_frametime;
// flags in finalvert_t.flags
#define ALIAS_LEFT_CLIP 0x0001

View File

@ -282,15 +282,11 @@ extern client_state_t cl;
extern entity_t cl_entities[MAX_EDICTS];
extern entity_t cl_static_entities[MAX_STATIC_ENTITIES];
extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
extern dlight_t cl_dlights[MAX_DLIGHTS];
/*
cl_main
*/
dlight_t *CL_AllocDlight (int key);
void CL_DecayLights (void);
void CL_Init (void);
void CL_InitCvars (void);

View File

@ -89,7 +89,6 @@ entity_state_t cl_baselines[MAX_EDICTS];
entity_t cl_static_entities[MAX_STATIC_ENTITIES];
entity_state_t cl_static_entity_baselines[MAX_STATIC_ENTITIES];
lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
dlight_t cl_dlights[MAX_DLIGHTS];
void
@ -170,12 +169,12 @@ CL_ClearState (void)
// clear other arrays
memset (cl_entities, 0, sizeof (cl_entities));
memset (cl_baselines, 0, sizeof (cl_baselines));
memset (cl_dlights, 0, sizeof (cl_dlights));
memset (cl_lightstyle, 0, sizeof (cl_lightstyle));
CL_ClearTEnts ();
R_ClearEfrags ();
R_ClearDlights ();
for (i = 0; i < MAX_EDICTS; i++) {
cl_entities[i].baseline = &cl_baselines[i];
@ -413,47 +412,13 @@ SetPal (int i)
}
dlight_t *
CL_AllocDlight (int key)
{
int i;
dlight_t *dl;
// first look for an exact key match
if (key) {
dl = cl_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->key == key) {
memset (dl, 0, sizeof (*dl));
dl->key = key;
return dl;
}
}
}
// then look for anything else
dl = cl_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < cl.time) {
memset (dl, 0, sizeof (*dl));
dl->key = key;
return dl;
}
}
dl = &cl_dlights[0];
memset (dl, 0, sizeof (*dl));
dl->key = key;
return dl;
}
void
CL_NewDlight (int key, float x, float y, float z, float radius, float time,
int type)
{
dlight_t *dl;
dl = CL_AllocDlight (key);
dl = R_AllocDlight (key);
dl->origin[0] = x;
dl->origin[1] = y;
dl->origin[2] = z;
@ -485,27 +450,6 @@ CL_NewDlight (int key, float x, float y, float z, float radius, float time,
}
void
CL_DecayLights (void)
{
int i;
dlight_t *dl;
float time;
time = cl.time - cl.oldtime;
dl = cl_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < cl.time || !dl->radius)
continue;
dl->radius -= time * dl->decay;
if (dl->radius < 0)
dl->radius = 0;
}
}
/*
CL_LerpPoint
@ -639,7 +583,7 @@ CL_RelinkEntities (void)
if (ent->effects & EF_MUZZLEFLASH) {
vec3_t fv, rv, uv;
dl = CL_AllocDlight (i);
dl = R_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->origin[2] += 16;
AngleVectors (ent->angles, fv, rv, uv);
@ -669,14 +613,14 @@ CL_RelinkEntities (void)
200 + (rand () & 31), 0.001, 0);
#ifdef QUAKE2
if (ent->effects & EF_DARKLIGHT) {
dl = CL_AllocDlight (i);
dl = R_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->radius = 200.0 + (rand () & 31);
dl->die = cl.time + 0.001;
dl->dark = true;
}
if (ent->effects & EF_LIGHT) {
dl = CL_AllocDlight (i);
dl = R_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->radius = 200;
dl->die = cl.time + 0.001;
@ -685,7 +629,7 @@ CL_RelinkEntities (void)
if (VectorDistance_fast(ent->msg_origins[1], ent->origin) > (256*256))
VectorCopy (ent ->origin, ent->msg_origins[1]);
if (ent->model->flags & EF_ROCKET) {
dl = CL_AllocDlight (i);
dl = R_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
VectorCopy (r_firecolor->vec, dl->color);
dl->radius = 200;

View File

@ -313,7 +313,7 @@ CL_ParseServerInfo (void)
// local state
cl_entities[0].model = cl.worldmodel = cl.model_precache[1];
R_NewMap ();
R_NewMap (cl.worldmodel);
Hunk_Check (); // make sure nothing is hurt

View File

@ -287,7 +287,7 @@ CL_ParseTEnt (void)
R_ParticleExplosion (pos);
// light
dl = CL_AllocDlight (0);
dl = R_AllocDlight (0);
VectorCopy (pos, dl->origin);
dl->radius = 350;
dl->die = cl.time + 0.5;
@ -354,7 +354,7 @@ CL_ParseTEnt (void)
colorStart = MSG_ReadByte (net_message);
colorLength = MSG_ReadByte (net_message);
R_ParticleExplosion2 (pos, colorStart, colorLength);
dl = CL_AllocDlight (0);
dl = R_AllocDlight (0);
VectorCopy (pos, dl->origin);
dl->radius = 350;
dl->die = cl.time + 0.5;
@ -401,7 +401,7 @@ CL_ParseTEnt (void)
R_RocketTrail (pos, endpos, 0 + 128);
R_ParticleExplosion (endpos);
*/
dl = CL_AllocDlight (-1);
dl = R_AllocDlight (-1);
VectorCopy (endpos, dl->origin);
dl->radius = 350;
dl->die = cl.time + 0.5;

View File

@ -167,7 +167,7 @@ R_RenderDlights (void)
glBlendFunc (GL_ONE, GL_ONE);
glShadeModel (GL_SMOOTH);
l = cl_dlights;
l = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, l++) {
if (l->die < r_realtime || !l->radius)
continue;
@ -291,7 +291,7 @@ R_PushDlights (vec3_t entorigin)
if (!gl_dlight_lightmap->int_val)
return;
l = cl_dlights;
l = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, l++) {
if (l->die < r_realtime || !l->radius)

View File

@ -639,10 +639,10 @@ R_DrawAliasModel (entity_t *e)
shadelight = max (shadelight, 24);
for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) {
if (cl_dlights[lnum].die >= r_realtime) {
VectorSubtract (currententity->origin, cl_dlights[lnum].origin,
if (r_dlights[lnum].die >= r_realtime) {
VectorSubtract (currententity->origin, r_dlights[lnum].origin,
dist);
add = (cl_dlights[lnum].radius * cl_dlights[lnum].radius * 8) /
add = (r_dlights[lnum].radius * r_dlights[lnum].radius * 8) /
(DotProduct (dist, dist)); // FIXME Deek
if (add > 0)
@ -787,7 +787,7 @@ R_ShowNearestLoc (void)
nearloc = locs_find (r_origin);
if (nearloc) {
dl = CL_AllocDlight (4096);
dl = R_AllocDlight (4096);
VectorCopy (nearloc->loc, dl->origin);
dl->radius = 200;
dl->die = r_realtime + 0.1;

View File

@ -175,7 +175,7 @@ R_Init (void)
void
R_NewMap (void)
R_NewMap (model_t *worldmodel)
{
int i;
cvar_t *r_skyname;
@ -184,7 +184,7 @@ R_NewMap (void)
d_lightstylevalue[i] = 264; // normal light value
memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.model = cl.worldmodel;
r_worldentity.model = worldmodel;
// clear out efrags in case the level hasn't been reloaded
for (i = 0; i < r_worldentity.model->numleafs; i++)

View File

@ -163,11 +163,11 @@ R_AddDynamicLights (msurface_t *surf)
if (!(surf->dlightbits & (1 << lnum)))
continue; // not lit by this light
VectorSubtract (cl_dlights[lnum].origin, currententity->origin, local);
VectorSubtract (r_dlights[lnum].origin, currententity->origin, local);
dist = DotProduct (local, surf->plane->normal) - surf->plane->dist;
for (i = 0; i < 3; i++)
impact[i] =
cl_dlights[lnum].origin[i] - surf->plane->normal[i] * dist;
r_dlights[lnum].origin[i] - surf->plane->normal[i] * dist;
i = f = DotProduct (impact, surf->texinfo->vecs[0]) +
surf->texinfo->vecs[0][3] - surf->texturemins[0];
@ -181,7 +181,7 @@ R_AddDynamicLights (msurface_t *surf)
surf->texinfo->vecs[1][3] - surf->texturemins[1];
// for comparisons to minimum acceptable light
maxdist = (int) ((cl_dlights[lnum].radius * cl_dlights[lnum].radius) * 0.75);
maxdist = (int) ((r_dlights[lnum].radius * r_dlights[lnum].radius) * 0.75);
// clamp radius to avoid exceeding 8192 entry division table
if (maxdist > 1048576)
@ -189,9 +189,9 @@ R_AddDynamicLights (msurface_t *surf)
maxdist3 = maxdist - (int) (dist * dist);
// convert to 8.8 blocklights format
red = f = cl_dlights[lnum].color[0] * maxdist;
green = f = cl_dlights[lnum].color[1] * maxdist;
blue = f = cl_dlights[lnum].color[2] * maxdist;
red = f = r_dlights[lnum].color[0] * maxdist;
green = f = r_dlights[lnum].color[1] * maxdist;
blue = f = r_dlights[lnum].color[2] * maxdist;
bl = blocklights;
for (t = 0; t < tmax; t++, i -= 16) {
td = i * i;
@ -723,11 +723,11 @@ R_DrawBrushModel (entity_t *e)
vec3_t lightorigin;
for (k = 0; k < MAX_DLIGHTS; k++) {
if ((cl_dlights[k].die < r_realtime) || (!cl_dlights[k].radius))
if ((r_dlights[k].die < r_realtime) || (!r_dlights[k].radius))
continue;
VectorSubtract (cl_dlights[k].origin, e->origin, lightorigin);
R_MarkLights (lightorigin, &cl_dlights[k], 1 << k,
VectorSubtract (r_dlights[k].origin, e->origin, lightorigin);
R_MarkLights (lightorigin, &r_dlights[k], 1 << k,
clmodel->nodes + clmodel->hulls[0].firstclipnode);
}
}

View File

@ -884,6 +884,7 @@ SCR_UpdateScreen (double realtime)
if (block_drawing)
return;
r_frametime = min (realtime - r_realtime, 5); // bound to 0.2 fps
r_realtime = realtime;
vid.numpages = 2 + gl_triplebuffer->int_val;

View File

@ -713,7 +713,7 @@ _Host_Frame (float time)
// update audio
if (cls.signon == SIGNONS) {
S_Update (r_origin, vpn, vright, vup);
CL_DecayLights ();
R_DecayLights ();
} else
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin);

View File

@ -1 +1,65 @@
#include "QF/render.h"
#include "r_local.h"
double r_realtime;
double r_frametime;
dlight_t r_dlights[MAX_DLIGHTS];
dlight_t *
R_AllocDlight (int key)
{
int i;
dlight_t *dl;
// first look for an exact key match
if (key) {
dl = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->key == key) {
memset (dl, 0, sizeof (*dl));
dl->key = key;
dl->color[0] = dl->color[1] = dl->color[2] = 1;
return dl;
}
}
}
// then look for anything else
dl = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < r_realtime) {
memset (dl, 0, sizeof (*dl));
dl->key = key;
dl->color[0] = dl->color[1] = dl->color[2] = 1;
return dl;
}
}
dl = &r_dlights[0];
memset (dl, 0, sizeof (*dl));
dl->key = key;
return dl;
}
void
R_DecayLights (void)
{
int i;
dlight_t *dl;
dl = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < r_realtime || !dl->radius)
continue;
dl->radius -= r_frametime * dl->decay;
if (dl->radius < 0)
dl->radius = 0;
}
}
void
R_ClearDlights (void)
{
memset (r_dlights, 0, sizeof (r_dlights));
}

View File

@ -893,6 +893,7 @@ SCR_UpdateScreen (double realtime)
}
#endif
r_frametime = min (realtime - r_realtime, 5); // bound to 0.2 fps
r_realtime = realtime;
scr_copytop = 0;

View File

@ -678,7 +678,6 @@ R_AliasDrawModel (alight_t *plighting)
if (currententity != &cl.viewent)
ziscale = (float) 0x8000 *(float) 0x10000;
else
ziscale = (float) 0x8000 *(float) 0x10000 *3.0;

View File

@ -30,6 +30,8 @@
# include "config.h"
#endif
#include "QF/render.h"
#include "client.h"
#include "r_local.h"
@ -108,7 +110,7 @@ R_PushDlights (vec3_t entorigin)
r_dlightframecount = r_framecount + 1; // because the count hasn't
// advanced yet for this frame
l = cl_dlights;
l = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, l++) {
if (l->die < r_realtime || !l->radius)

View File

@ -183,12 +183,12 @@ R_Init (void)
void
R_NewMap (void)
R_NewMap (model_t *worldmodel)
{
int i;
memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.model = cl.worldmodel;
r_worldentity.model = worldmodel;
// clear out efrags in case the level hasn't been reloaded
// FIXME: is this one short?
@ -465,7 +465,7 @@ R_ShowNearestLoc (void)
return;
nearloc = locs_find (r_origin);
if (nearloc) {
dl = CL_AllocDlight (4096);
dl = R_AllocDlight (4096);
VectorCopy (nearloc->loc, dl->origin);
dl->radius = 200;
dl->die = r_realtime + 0.1;
@ -526,10 +526,10 @@ R_DrawEntitiesOnList (void)
lighting.plightvec = lightvec;
for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) {
if (cl_dlights[lnum].die >= r_realtime) {
if (r_dlights[lnum].die >= r_realtime) {
VectorSubtract (currententity->origin,
cl_dlights[lnum].origin, dist);
add = cl_dlights[lnum].radius - Length (dist);
r_dlights[lnum].origin, dist);
add = r_dlights[lnum].radius - Length (dist);
if (add > 0)
lighting.ambientlight += add;
@ -597,7 +597,7 @@ R_DrawViewModel (void)
// add dynamic lights
for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) {
dl = &cl_dlights[lnum];
dl = &r_dlights[lnum];
if (!dl->radius)
continue;
if (!dl->radius)
@ -728,12 +728,12 @@ R_DrawBEntitiesOnList (void)
vec3_t lightorigin;
for (k = 0; k < MAX_DLIGHTS; k++) {
if ((cl_dlights[k].die < r_realtime) ||
(!cl_dlights[k].radius)) continue;
if ((r_dlights[k].die < r_realtime) ||
(!r_dlights[k].radius)) continue;
VectorSubtract (cl_dlights[k].origin,
VectorSubtract (r_dlights[k].origin,
currententity->origin, lightorigin);
R_MarkLights (lightorigin, &cl_dlights[k], 1 << k,
R_MarkLights (lightorigin, &r_dlights[k], 1 << k,
clmodel->nodes +
clmodel->hulls[0].firstclipnode);
}

View File

@ -84,13 +84,13 @@ R_AddDynamicLights (void)
if (!(surf->dlightbits & (1 << lnum)))
continue; // not lit by this light
VectorSubtract (cl_dlights[lnum].origin, currententity->origin,
VectorSubtract (r_dlights[lnum].origin, currententity->origin,
lightorigin);
rad = cl_dlights[lnum].radius;
rad = r_dlights[lnum].radius;
dist = DotProduct (lightorigin, surf->plane->normal) -
surf->plane->dist;
rad -= fabs (dist);
minlight = cl_dlights[lnum].minlight;
minlight = r_dlights[lnum].minlight;
if (rad < minlight)
continue;
minlight = rad - minlight;

View File

@ -33,9 +33,6 @@
#include "QF/qtypes.h"
#include "QF/render.h"
dlight_t *CL_AllocDlight (int key);
void CL_DecayLights (void);
void CL_Init (void);
void Host_WriteConfiguration (void);

View File

@ -318,7 +318,6 @@ extern client_state_t cl;
extern entity_state_t cl_baselines[MAX_EDICTS];
extern entity_t cl_static_entities[MAX_STATIC_ENTITIES];
extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
extern dlight_t cl_dlights[MAX_DLIGHTS];
extern qboolean nomaster;
extern char *server_version; // version of server we connected to

View File

@ -82,42 +82,6 @@ CL_ClearEnts ()
}
dlight_t *
CL_AllocDlight (int key)
{
int i;
dlight_t *dl;
// first look for an exact key match
if (key) {
dl = cl_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->key == key) {
memset (dl, 0, sizeof (*dl));
dl->key = key;
dl->color[0] = dl->color[1] = dl->color[2] = 1;
return dl;
}
}
}
// then look for anything else
dl = cl_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < cl.time) {
memset (dl, 0, sizeof (*dl));
dl->key = key;
dl->color[0] = dl->color[1] = dl->color[2] = 1;
return dl;
}
}
dl = &cl_dlights[0];
memset (dl, 0, sizeof (*dl));
dl->key = key;
return dl;
}
void
CL_NewDlight (int key, vec3_t org, int effects)
{
@ -133,7 +97,7 @@ CL_NewDlight (int key, vec3_t org, int effects)
return;
radius = 200 + (rand () & 31);
dl = CL_AllocDlight (key);
dl = R_AllocDlight (key);
VectorCopy (org, dl->origin);
dl->die = cl.time + 0.1;
switch (effects & (EF_BLUE | EF_RED)) {
@ -158,24 +122,6 @@ CL_NewDlight (int key, vec3_t org, int effects)
}
void
CL_DecayLights (void)
{
int i;
dlight_t *dl;
dl = cl_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < cl.time || !dl->radius)
continue;
dl->radius -= host_frametime * dl->decay;
if (dl->radius < 0)
dl->radius = 0;
}
}
/*
PACKET ENTITY PARSING / LINKING
*/
@ -552,7 +498,7 @@ CL_LinkPacketEntities (void)
VectorCopy ((*ent)->origin, (*ent)->old_origin);
if (model->flags & EF_ROCKET) {
dl = CL_AllocDlight (-(*ent)->keynum);
dl = R_AllocDlight (-(*ent)->keynum);
VectorCopy ((*ent)->origin, dl->origin);
VectorCopy (r_firecolor->vec, dl->color);
dl->radius = 200;

View File

@ -165,7 +165,6 @@ entity_state_t cl_baselines[MAX_EDICTS];
efrag_t cl_efrags[MAX_EFRAGS];
entity_t cl_static_entities[MAX_STATIC_ENTITIES];
lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
dlight_t cl_dlights[MAX_DLIGHTS];
double connect_time = -1; // for connection retransmits
@ -411,6 +410,7 @@ CL_ClearState (void)
CL_ClearTEnts ();
R_ClearEfrags ();
R_ClearDlights ();
// wipe the entire cl structure
memset (&cl, 0, sizeof (cl));
@ -419,7 +419,6 @@ CL_ClearState (void)
// clear other arrays
memset (cl_efrags, 0, sizeof (cl_efrags));
memset (cl_dlights, 0, sizeof (cl_dlights));
memset (cl_lightstyle, 0, sizeof (cl_lightstyle));
}
@ -1489,7 +1488,7 @@ Host_Frame (float time)
// update audio
if (cls.state == ca_active) {
S_Update (r_origin, vpn, vright, vup);
CL_DecayLights ();
R_DecayLights ();
} else
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin);

View File

@ -297,7 +297,7 @@ Model_NextDownload (void)
// all done
cl.worldmodel = cl.model_precache[1];
R_NewMap ();
R_NewMap (cl.worldmodel);
Team_NewMap ();
Hunk_Check (); // make sure nothing is hurt
@ -1081,7 +1081,7 @@ CL_MuzzleFlash (void)
pl = &cl.frames[parsecountmod].playerstate[i - 1];
dl = CL_AllocDlight (i);
dl = R_AllocDlight (i);
VectorCopy (pl->origin, dl->origin);
AngleVectors (pl->viewangles, fv, rv, uv);

View File

@ -283,7 +283,7 @@ CL_ParseTEnt (void)
R_ParticleExplosion (pos);
// light
dl = CL_AllocDlight (0);
dl = R_AllocDlight (0);
VectorCopy (pos, dl->origin);
dl->radius = 350;
dl->die = cl.time + 0.5;
@ -350,7 +350,7 @@ CL_ParseTEnt (void)
colorStart = MSG_ReadByte (net_message);
colorLength = MSG_ReadByte (net_message);
R_ParticleExplosion2 (pos, colorStart, colorLength);
dl = CL_AllocDlight (0);
dl = R_AllocDlight (0);
VectorCopy (pos, dl->origin);
dl->radius = 350;
dl->die = cl.time + 0.5;
@ -392,7 +392,7 @@ CL_ParseTEnt (void)
R_RocketTrail (pos, endpos, 0 + 128);
R_ParticleExplosion (endpos);
*/
dl = CL_AllocDlight (-1);
dl = R_AllocDlight (-1);
VectorCopy (endpos, dl->origin);
dl->radius = 350;
dl->die = cl.time + 0.5;

View File

@ -167,7 +167,7 @@ R_RenderDlights (void)
glBlendFunc (GL_ONE, GL_ONE);
glShadeModel (GL_SMOOTH);
l = cl_dlights;
l = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, l++) {
if (l->die < r_realtime || !l->radius)
continue;
@ -291,7 +291,7 @@ R_PushDlights (vec3_t entorigin)
if (!gl_dlight_lightmap->int_val)
return;
l = cl_dlights;
l = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, l++) {
if (l->die < r_realtime || !l->radius)

View File

@ -640,10 +640,10 @@ R_DrawAliasModel (entity_t *e)
shadelight = max (shadelight, 24);
for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) {
if (cl_dlights[lnum].die >= r_realtime) {
VectorSubtract (currententity->origin, cl_dlights[lnum].origin,
if (r_dlights[lnum].die >= r_realtime) {
VectorSubtract (currententity->origin, r_dlights[lnum].origin,
dist);
add = (cl_dlights[lnum].radius * cl_dlights[lnum].radius * 8) /
add = (r_dlights[lnum].radius * r_dlights[lnum].radius * 8) /
(DotProduct (dist, dist)); // FIXME Deek
if (add > 0)
@ -801,7 +801,7 @@ R_ShowNearestLoc (void)
nearloc = locs_find (r_origin);
if (nearloc) {
dl = CL_AllocDlight (4096);
dl = R_AllocDlight (4096);
VectorCopy (nearloc->loc, dl->origin);
dl->radius = 200;
dl->die = r_realtime + 0.1;

View File

@ -175,7 +175,7 @@ R_Init (void)
void
R_NewMap (void)
R_NewMap (model_t *worldmodel)
{
int i;
cvar_t *r_skyname;
@ -184,7 +184,7 @@ R_NewMap (void)
d_lightstylevalue[i] = 264; // normal light value
memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.model = cl.worldmodel;
r_worldentity.model = worldmodel;
// clear out efrags in case the level hasn't been reloaded
for (i = 0; i < r_worldentity.model->numleafs; i++)

View File

@ -163,11 +163,11 @@ R_AddDynamicLights (msurface_t *surf)
if (!(surf->dlightbits & (1 << lnum)))
continue; // not lit by this light
VectorSubtract (cl_dlights[lnum].origin, currententity->origin, local);
VectorSubtract (r_dlights[lnum].origin, currententity->origin, local);
dist = DotProduct (local, surf->plane->normal) - surf->plane->dist;
for (i = 0; i < 3; i++)
impact[i] =
cl_dlights[lnum].origin[i] - surf->plane->normal[i] * dist;
r_dlights[lnum].origin[i] - surf->plane->normal[i] * dist;
i = f = DotProduct (impact, surf->texinfo->vecs[0]) +
surf->texinfo->vecs[0][3] - surf->texturemins[0];
@ -181,7 +181,7 @@ R_AddDynamicLights (msurface_t *surf)
surf->texinfo->vecs[1][3] - surf->texturemins[1];
// for comparisons to minimum acceptable light
maxdist = (int) ((cl_dlights[lnum].radius * cl_dlights[lnum].radius) * 0.75);
maxdist = (int) ((r_dlights[lnum].radius * r_dlights[lnum].radius) * 0.75);
// clamp radius to avoid exceeding 8192 entry division table
if (maxdist > 1048576)
@ -189,9 +189,9 @@ R_AddDynamicLights (msurface_t *surf)
maxdist3 = maxdist - (int) (dist * dist);
// convert to 8.8 blocklights format
red = f = cl_dlights[lnum].color[0] * maxdist;
green = f = cl_dlights[lnum].color[1] * maxdist;
blue = f = cl_dlights[lnum].color[2] * maxdist;
red = f = r_dlights[lnum].color[0] * maxdist;
green = f = r_dlights[lnum].color[1] * maxdist;
blue = f = r_dlights[lnum].color[2] * maxdist;
bl = blocklights;
for (t = 0; t < tmax; t++, i -= 16) {
td = i * i;
@ -723,11 +723,11 @@ R_DrawBrushModel (entity_t *e)
vec3_t lightorigin;
for (k = 0; k < MAX_DLIGHTS; k++) {
if ((cl_dlights[k].die < r_realtime) || (!cl_dlights[k].radius))
if ((r_dlights[k].die < r_realtime) || (!r_dlights[k].radius))
continue;
VectorSubtract (cl_dlights[k].origin, e->origin, lightorigin);
R_MarkLights (lightorigin, &cl_dlights[k], 1 << k,
VectorSubtract (r_dlights[k].origin, e->origin, lightorigin);
R_MarkLights (lightorigin, &r_dlights[k], 1 << k,
clmodel->nodes + clmodel->hulls[0].firstclipnode);
}
}

View File

@ -882,6 +882,7 @@ SCR_UpdateScreen (double realtime)
if (block_drawing)
return;
r_frametime = min (realtime - r_realtime, 5); // bound to 0.2 fps
r_realtime = realtime;
vid.numpages = 2 + gl_triplebuffer->int_val;

View File

@ -1 +1,65 @@
#include "QF/render.h"
#include "r_local.h"
double r_realtime;
double r_frametime;
dlight_t r_dlights[MAX_DLIGHTS];
dlight_t *
R_AllocDlight (int key)
{
int i;
dlight_t *dl;
// first look for an exact key match
if (key) {
dl = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->key == key) {
memset (dl, 0, sizeof (*dl));
dl->key = key;
dl->color[0] = dl->color[1] = dl->color[2] = 1;
return dl;
}
}
}
// then look for anything else
dl = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < r_realtime) {
memset (dl, 0, sizeof (*dl));
dl->key = key;
dl->color[0] = dl->color[1] = dl->color[2] = 1;
return dl;
}
}
dl = &r_dlights[0];
memset (dl, 0, sizeof (*dl));
dl->key = key;
return dl;
}
void
R_DecayLights (void)
{
int i;
dlight_t *dl;
dl = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, dl++) {
if (dl->die < r_realtime || !dl->radius)
continue;
dl->radius -= r_frametime * dl->decay;
if (dl->radius < 0)
dl->radius = 0;
}
}
void
R_ClearDlights (void)
{
memset (r_dlights, 0, sizeof (r_dlights));
}

View File

@ -892,6 +892,7 @@ SCR_UpdateScreen (double realtime)
}
#endif
r_frametime = min (realtime - r_realtime, 5); // bound to 0.2 fps
r_realtime = realtime;
scr_copytop = 0;

View File

@ -691,7 +691,6 @@ R_AliasDrawModel (alight_t *plighting)
if (currententity != &cl.viewent)
ziscale = (float) 0x8000 *(float) 0x10000;
else
ziscale = (float) 0x8000 *(float) 0x10000 *3.0;

View File

@ -30,6 +30,8 @@
# include "config.h"
#endif
#include "QF/render.h"
#include "client.h"
#include "r_local.h"
@ -108,7 +110,7 @@ R_PushDlights (vec3_t entorigin)
r_dlightframecount = r_framecount + 1; // because the count hasn't
// advanced yet for this frame
l = cl_dlights;
l = r_dlights;
for (i = 0; i < MAX_DLIGHTS; i++, l++) {
if (l->die < r_realtime || !l->radius)

View File

@ -42,6 +42,7 @@
#include "QF/console.h"
#include "QF/locs.h"
#include "QF/mathlib.h"
#include "QF/render.h"
#include "QF/screen.h"
#include "QF/sound.h"
#include "QF/sys.h"
@ -184,12 +185,12 @@ R_Init (void)
void
R_NewMap (void)
R_NewMap (model_t *worldmodel)
{
int i;
memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.model = cl.worldmodel;
r_worldentity.model = worldmodel;
// clear out efrags in case the level hasn't been reloaded
// FIXME: is this one short?
@ -466,7 +467,7 @@ R_ShowNearestLoc (void)
return;
nearloc = locs_find (r_origin);
if (nearloc) {
dl = CL_AllocDlight (4096);
dl = R_AllocDlight (4096);
VectorCopy (nearloc->loc, dl->origin);
dl->radius = 200;
dl->die = r_realtime + 0.1;
@ -520,10 +521,10 @@ R_DrawEntitiesOnList (void)
lighting.plightvec = lightvec;
for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) {
if (cl_dlights[lnum].die >= r_realtime) {
if (r_dlights[lnum].die >= r_realtime) {
VectorSubtract (currententity->origin,
cl_dlights[lnum].origin, dist);
add = cl_dlights[lnum].radius - Length (dist);
r_dlights[lnum].origin, dist);
add = r_dlights[lnum].radius - Length (dist);
if (add > 0)
lighting.ambientlight += add;
@ -589,7 +590,7 @@ R_DrawViewModel (void)
// add dynamic lights
for (lnum = 0; lnum < MAX_DLIGHTS; lnum++) {
dl = &cl_dlights[lnum];
dl = &r_dlights[lnum];
if (!dl->radius)
continue;
if (!dl->radius)
@ -720,12 +721,12 @@ R_DrawBEntitiesOnList (void)
vec3_t lightorigin;
for (k = 0; k < MAX_DLIGHTS; k++) {
if ((cl_dlights[k].die < r_realtime) ||
(!cl_dlights[k].radius)) continue;
if ((r_dlights[k].die < r_realtime) ||
(!r_dlights[k].radius)) continue;
VectorSubtract (cl_dlights[k].origin,
VectorSubtract (r_dlights[k].origin,
currententity->origin, lightorigin);
R_MarkLights (lightorigin, &cl_dlights[k], 1 << k,
R_MarkLights (lightorigin, &r_dlights[k], 1 << k,
clmodel->nodes +
clmodel->hulls[0].firstclipnode);
}

View File

@ -84,13 +84,13 @@ R_AddDynamicLights (void)
if (!(surf->dlightbits & (1 << lnum)))
continue; // not lit by this light
VectorSubtract (cl_dlights[lnum].origin, currententity->origin,
VectorSubtract (r_dlights[lnum].origin, currententity->origin,
lightorigin);
rad = cl_dlights[lnum].radius;
rad = r_dlights[lnum].radius;
dist = DotProduct (lightorigin, surf->plane->normal) -
surf->plane->dist;
rad -= fabs (dist);
minlight = cl_dlights[lnum].minlight;
minlight = r_dlights[lnum].minlight;
if (rad < minlight)
continue;
minlight = rad - minlight;