2010-06-18 15:27:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1997-2001 Id Software, Inc.
|
|
|
|
*
|
2010-07-13 18:19:42 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
2010-06-18 15:27:55 +00:00
|
|
|
*
|
2010-07-13 18:19:42 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2010-06-18 15:27:55 +00:00
|
|
|
*
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
2010-07-13 18:19:42 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
2010-06-18 15:27:55 +00:00
|
|
|
*
|
|
|
|
* =======================================================================
|
|
|
|
*
|
|
|
|
* This file implements all client side lighting
|
|
|
|
*
|
|
|
|
* =======================================================================
|
2012-04-29 13:57:33 +00:00
|
|
|
*/
|
2010-06-18 15:27:55 +00:00
|
|
|
|
|
|
|
#include "header/client.h"
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
float value[3];
|
|
|
|
float map[MAX_QPATH];
|
2010-06-18 15:27:55 +00:00
|
|
|
} clightstyle_t;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
clightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
|
|
|
|
int lastofs;
|
2010-06-18 15:27:55 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_ClearLightStyles(void)
|
|
|
|
{
|
|
|
|
memset(cl_lightstyle, 0, sizeof(cl_lightstyle));
|
2010-06-18 15:27:55 +00:00
|
|
|
lastofs = -1;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_RunLightStyles(void)
|
|
|
|
{
|
|
|
|
int ofs;
|
|
|
|
int i;
|
|
|
|
clightstyle_t *ls;
|
2010-06-18 15:27:55 +00:00
|
|
|
|
|
|
|
ofs = cl.time / 100;
|
|
|
|
|
|
|
|
if (ofs == lastofs)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:27:55 +00:00
|
|
|
|
|
|
|
lastofs = ofs;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0, ls = cl_lightstyle; i < MAX_LIGHTSTYLES; i++, ls++)
|
|
|
|
{
|
|
|
|
if (!ls->length)
|
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
ls->value[0] = ls->value[1] = ls->value[2] = 1.0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ls->length == 1)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
ls->value[0] = ls->value[1] = ls->value[2] = ls->map[0];
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:27:55 +00:00
|
|
|
|
|
|
|
else
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
ls->value[0] = ls->value[1] = ls->value[2] = ls->map[ofs % ls->length];
|
|
|
|
}
|
2010-06-18 15:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_SetLightstyle(int i)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
int j, k;
|
2010-06-18 15:27:55 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
s = cl.configstrings[i + CS_LIGHTS];
|
2010-06-18 15:27:55 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
j = (int)strlen(s);
|
2010-06-18 15:27:55 +00:00
|
|
|
cl_lightstyle[i].length = j;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (k = 0; k < j; k++)
|
|
|
|
{
|
|
|
|
cl_lightstyle[i].map[k] = (float)(s[k] - 'a') / (float)('m' - 'a');
|
|
|
|
}
|
2010-06-18 15:27:55 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_AddLightStyles(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
clightstyle_t *ls;
|
2010-06-18 15:27:55 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0, ls = cl_lightstyle; i < MAX_LIGHTSTYLES; i++, ls++)
|
|
|
|
{
|
|
|
|
V_AddLightStyle(i, ls->value[0], ls->value[1], ls->value[2]);
|
|
|
|
}
|
2010-06-18 15:27:55 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
cdlight_t cl_dlights[MAX_DLIGHTS];
|
2010-06-18 15:27:55 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_ClearDlights(void)
|
|
|
|
{
|
|
|
|
memset(cl_dlights, 0, sizeof(cl_dlights));
|
2010-06-18 15:27:55 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
cdlight_t *
|
|
|
|
CL_AllocDlight(int key)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
cdlight_t *dl;
|
2010-06-18 15:27:55 +00:00
|
|
|
|
|
|
|
/* first look for an exact key match */
|
2012-07-22 13:34:45 +00:00
|
|
|
if (key)
|
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
dl = cl_dlights;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < MAX_DLIGHTS; i++, dl++)
|
|
|
|
{
|
|
|
|
if (dl->key == key)
|
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
dl->key = key;
|
|
|
|
return dl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then look for anything else */
|
|
|
|
dl = cl_dlights;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < MAX_DLIGHTS; i++, dl++)
|
|
|
|
{
|
|
|
|
if (dl->die < cl.time)
|
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
dl->key = key;
|
|
|
|
return dl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dl = &cl_dlights[0];
|
|
|
|
dl->key = key;
|
|
|
|
return dl;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_NewDlight(int key, float x, float y, float z, float radius, float time)
|
|
|
|
{
|
|
|
|
cdlight_t *dl;
|
2010-06-18 15:27:55 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
dl = CL_AllocDlight(key);
|
2010-06-18 15:27:55 +00:00
|
|
|
dl->origin[0] = x;
|
|
|
|
dl->origin[1] = y;
|
|
|
|
dl->origin[2] = z;
|
|
|
|
dl->radius = radius;
|
|
|
|
dl->die = cl.time + time;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_RunDLights(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
cdlight_t *dl;
|
2010-06-18 15:27:55 +00:00
|
|
|
|
|
|
|
dl = cl_dlights;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < MAX_DLIGHTS; i++, dl++)
|
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
if (!dl->radius)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
continue;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:27:55 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (dl->die < cl.time)
|
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
dl->radius = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
dl->radius -= cls.frametime * dl->decay;
|
2010-06-18 15:27:55 +00:00
|
|
|
|
|
|
|
if (dl->radius < 0)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
dl->radius = 0;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_AddDLights(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
cdlight_t *dl;
|
2010-06-18 15:27:55 +00:00
|
|
|
|
|
|
|
dl = cl_dlights;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (vidref_val == VIDREF_GL)
|
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_DLIGHTS; i++, dl++)
|
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
if (!dl->radius)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
continue;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:27:55 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
V_AddLight(dl->origin, dl->radius, dl->color[0], dl->color[1], dl->color[2]);
|
2010-06-18 15:27:55 +00:00
|
|
|
}
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_DLIGHTS; i++, dl++)
|
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
if (!dl->radius)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
continue;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:27:55 +00:00
|
|
|
|
|
|
|
/* negative light in software. only black allowed */
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((dl->color[0] < 0) || (dl->color[1] < 0) || (dl->color[2] < 0))
|
|
|
|
{
|
2010-06-18 15:27:55 +00:00
|
|
|
dl->radius = -(dl->radius);
|
|
|
|
dl->color[0] = 1;
|
|
|
|
dl->color[1] = 1;
|
|
|
|
dl->color[2] = 1;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
V_AddLight(dl->origin, dl->radius, dl->color[0], dl->color[1], dl->color[2]);
|
2010-06-18 15:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-22 13:34:45 +00:00
|
|
|
|