2008-11-27 22:00:00 +01:00
|
|
|
|
//=======================================================================
|
|
|
|
|
// Copyright XashXT Group 2008 <20>
|
|
|
|
|
// cl_effects.c - entity effects parsing and management
|
|
|
|
|
//=======================================================================
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-06-09 22:00:00 +02:00
|
|
|
|
#include "common.h"
|
2007-06-21 22:00:00 +02:00
|
|
|
|
#include "client.h"
|
2008-11-16 22:00:00 +01:00
|
|
|
|
#include "const.h"
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
==============================================================
|
|
|
|
|
|
|
|
|
|
LIGHT STYLE MANAGEMENT
|
|
|
|
|
|
|
|
|
|
==============================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2008-06-30 22:00:00 +02:00
|
|
|
|
int length;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
float value[3];
|
2008-06-30 22:00:00 +02:00
|
|
|
|
float map[MAX_STRING];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
} clightstyle_t;
|
|
|
|
|
|
|
|
|
|
clightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
|
2008-07-03 22:00:00 +02:00
|
|
|
|
static int lastofs;
|
2008-06-30 22:00:00 +02:00
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
CL_ClearLightStyles
|
|
|
|
|
================
|
|
|
|
|
*/
|
2008-11-27 22:00:00 +01:00
|
|
|
|
void CL_ClearLightStyles( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
Mem_Set( cl_lightstyle, 0, sizeof( cl_lightstyle ));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
lastofs = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
CL_RunLightStyles
|
|
|
|
|
================
|
|
|
|
|
*/
|
2008-11-27 22:00:00 +01:00
|
|
|
|
void CL_RunLightStyles( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
int i, ofs;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
clightstyle_t *ls;
|
2008-06-30 22:00:00 +02:00
|
|
|
|
|
2008-08-01 22:00:00 +02:00
|
|
|
|
ofs = cl.time / 100;
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( ofs == lastofs ) return;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
lastofs = ofs;
|
|
|
|
|
|
2008-11-27 22:00:00 +01:00
|
|
|
|
for( i = 0, ls = cl_lightstyle; i < MAX_LIGHTSTYLES; i++, ls++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-08-01 22:00:00 +02:00
|
|
|
|
if( !ls->length )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
VectorSet( ls->value, 1.0f, 1.0f, 1.0f );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( ls->length == 1 ) ls->value[0] = ls->value[1] = ls->value[2] = ls->map[0];
|
2008-07-03 22:00:00 +02:00
|
|
|
|
else ls->value[0] = ls->value[1] = ls->value[2] = ls->map[ofs%ls->length];
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-06-14 22:00:00 +02:00
|
|
|
|
void CL_SetLightstyle( int i )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-08-01 22:00:00 +02:00
|
|
|
|
char *s;
|
|
|
|
|
int j, k;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-08-02 22:00:00 +02:00
|
|
|
|
s = cl.configstrings[i+CS_LIGHTSTYLES];
|
2008-06-14 22:00:00 +02:00
|
|
|
|
j = com.strlen( s );
|
2008-06-30 22:00:00 +02:00
|
|
|
|
if( j >= MAX_STRING ) Host_Error("CL_SetLightStyle: lightstyle %s is too long\n", s );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
cl_lightstyle[i].length = j;
|
|
|
|
|
|
2008-06-14 22:00:00 +02:00
|
|
|
|
for( k = 0; k < j; k++ )
|
2008-11-27 22:00:00 +01:00
|
|
|
|
cl_lightstyle[i].map[k] = (float)(s[k]-'a') / (float)('m'-'a');
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
CL_AddLightStyles
|
|
|
|
|
================
|
|
|
|
|
*/
|
|
|
|
|
void CL_AddLightStyles (void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
clightstyle_t *ls;
|
|
|
|
|
|
2008-08-02 22:00:00 +02:00
|
|
|
|
for( i = 0, ls = cl_lightstyle; i < MAX_LIGHTSTYLES; i++, ls++ )
|
2008-08-29 22:00:00 +02:00
|
|
|
|
re->AddLightStyle( i, ls->value );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
==============================================================
|
|
|
|
|
|
|
|
|
|
DLIGHT MANAGEMENT
|
|
|
|
|
|
|
|
|
|
==============================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
cdlight_t cl_dlights[MAX_DLIGHTS];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
CL_ClearDlights
|
|
|
|
|
================
|
|
|
|
|
*/
|
2008-11-27 22:00:00 +01:00
|
|
|
|
void CL_ClearDlights( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
Mem_Set( cl_dlights, 0, sizeof( cl_dlights ));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
|
CL_AllocDlight
|
|
|
|
|
|
|
|
|
|
===============
|
|
|
|
|
*/
|
2008-11-27 22:00:00 +01:00
|
|
|
|
cdlight_t *CL_AllocDlight( int key )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2008-11-27 22:00:00 +01:00
|
|
|
|
cdlight_t *dl;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-06-30 22:00:00 +02:00
|
|
|
|
// first look for an exact key match
|
2008-11-27 22:00:00 +01:00
|
|
|
|
if( key )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
dl = cl_dlights;
|
2008-11-27 22:00:00 +01:00
|
|
|
|
for( i = 0; i < MAX_DLIGHTS; i++, dl++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
if( dl->key == key )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
Mem_Set( dl, 0, sizeof( *dl ));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
dl->key = key;
|
|
|
|
|
return dl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-27 22:00:00 +01:00
|
|
|
|
// then look for anything else
|
2007-06-21 22:00:00 +02:00
|
|
|
|
dl = cl_dlights;
|
2008-11-27 22:00:00 +01:00
|
|
|
|
for( i = 0; i < MAX_DLIGHTS; i++, dl++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
if( dl->die < cl.time )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
Mem_Set( dl, 0, sizeof( *dl ));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
dl->key = key;
|
|
|
|
|
return dl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dl = &cl_dlights[0];
|
2008-11-27 22:00:00 +01:00
|
|
|
|
Mem_Set( dl, 0, sizeof( *dl ));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
dl->key = key;
|
|
|
|
|
return dl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
2009-01-15 22:00:00 +01:00
|
|
|
|
pfnAddDLight
|
2008-11-27 22:00:00 +01:00
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
===============
|
|
|
|
|
*/
|
2009-01-15 22:00:00 +01:00
|
|
|
|
void pfnAddDLight( const float *org, const float *rgb, float radius, float decay, float time, int key )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
cdlight_t *dl;
|
|
|
|
|
|
|
|
|
|
if( radius <= 0 )
|
|
|
|
|
{
|
2009-01-15 22:00:00 +01:00
|
|
|
|
MsgDev( D_WARN, "CL_AddDLight: ignore light with radius <= 0\n" );
|
2008-11-27 22:00:00 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-11-27 22:00:00 +01:00
|
|
|
|
dl = CL_AllocDlight( key );
|
2009-01-15 22:00:00 +01:00
|
|
|
|
if( !dl )
|
|
|
|
|
{
|
|
|
|
|
MsgDev( D_ERROR, "CL_AddDLight: no free dlights\n" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VectorCopy( org, dl->origin );
|
|
|
|
|
VectorCopy( rgb, dl->color );
|
2008-11-27 22:00:00 +01:00
|
|
|
|
dl->die = cl.time + (time * 1000);
|
|
|
|
|
dl->decay = (decay * 1000);
|
2007-06-21 22:00:00 +02:00
|
|
|
|
dl->radius = radius;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
|
CL_RunDLights
|
|
|
|
|
|
|
|
|
|
===============
|
|
|
|
|
*/
|
2008-11-27 22:00:00 +01:00
|
|
|
|
void CL_RunDLights( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
cdlight_t *dl;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
int i;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
for( i = 0, dl = cl_dlights; i < MAX_DLIGHTS; i++, dl++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-11-27 22:00:00 +01:00
|
|
|
|
if( !dl->radius ) continue;
|
|
|
|
|
if( dl->die < cl.time )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
dl->radius = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-15 22:00:00 +01:00
|
|
|
|
|
2008-11-27 22:00:00 +01:00
|
|
|
|
dl->radius -= cls.frametime * dl->decay;
|
|
|
|
|
if( dl->radius < 0 ) dl->radius = 0;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
|
CL_AddDLights
|
|
|
|
|
|
|
|
|
|
===============
|
|
|
|
|
*/
|
2008-11-27 22:00:00 +01:00
|
|
|
|
void CL_AddDLights( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-08-02 22:00:00 +02:00
|
|
|
|
int i;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
cdlight_t *dl;
|
|
|
|
|
|
|
|
|
|
dl = cl_dlights;
|
2008-08-02 22:00:00 +02:00
|
|
|
|
for( i = 0; i < MAX_DLIGHTS; i++, dl++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-08-29 22:00:00 +02:00
|
|
|
|
if( dl->radius ) re->AddDynLight( dl->origin, dl->color, dl->radius );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-27 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
==============================================================
|
|
|
|
|
|
|
|
|
|
DECALS MANAGEMENT
|
|
|
|
|
|
|
|
|
|
==============================================================
|
|
|
|
|
*/
|
2008-12-15 22:00:00 +01:00
|
|
|
|
#define MAX_DECAL_MARKS 2048
|
2008-11-27 22:00:00 +01:00
|
|
|
|
#define DECAL_FADETIME (30 * 1000) // 30 seconds
|
|
|
|
|
#define DECAL_STAYTIME (120 * 1000) // 120 seconds
|
|
|
|
|
|
|
|
|
|
typedef struct cdecal_s
|
|
|
|
|
{
|
|
|
|
|
struct cdecal_s *prev, *next;
|
|
|
|
|
int time;
|
|
|
|
|
vec4_t modulate;
|
|
|
|
|
bool alphaFade;
|
|
|
|
|
shader_t shader;
|
|
|
|
|
int numVerts;
|
|
|
|
|
polyVert_t verts[MAX_VERTS_ON_POLY];
|
|
|
|
|
vec3_t origin;
|
|
|
|
|
} cdecal_t;
|
|
|
|
|
|
|
|
|
|
static cdecal_t cl_activeDecals;
|
|
|
|
|
static cdecal_t *cl_freeDecals;
|
2008-12-15 22:00:00 +01:00
|
|
|
|
static cdecal_t cl_decalList[MAX_DECAL_MARKS];
|
2008-11-27 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
CL_FreeDecal
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
static void CL_FreeDecal( cdecal_t *decal )
|
|
|
|
|
{
|
2009-01-15 22:00:00 +01:00
|
|
|
|
if( !decal->prev ) return;
|
2008-11-27 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
decal->prev->next = decal->next;
|
|
|
|
|
decal->next->prev = decal->prev;
|
|
|
|
|
|
|
|
|
|
decal->next = cl_freeDecals;
|
|
|
|
|
cl_freeDecals = decal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
CL_AllocDecal
|
|
|
|
|
|
|
|
|
|
will always succeed, even if it requires freeing an old active mark
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
static cdecal_t *CL_AllocDecal( void )
|
|
|
|
|
{
|
|
|
|
|
cdecal_t *decal;
|
|
|
|
|
|
|
|
|
|
if( !cl_freeDecals )
|
|
|
|
|
CL_FreeDecal( cl_activeDecals.prev );
|
|
|
|
|
|
|
|
|
|
decal = cl_freeDecals;
|
|
|
|
|
cl_freeDecals = cl_freeDecals->next;
|
|
|
|
|
|
|
|
|
|
Mem_Set( decal, 0, sizeof( cdecal_t ));
|
|
|
|
|
|
|
|
|
|
decal->next = cl_activeDecals.next;
|
|
|
|
|
decal->prev = &cl_activeDecals;
|
|
|
|
|
cl_activeDecals.next->prev = decal;
|
|
|
|
|
cl_activeDecals.next = decal;
|
|
|
|
|
|
|
|
|
|
return decal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
CL_ClearDecals
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void CL_ClearDecals( void )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
Mem_Set( cl_decalList, 0, sizeof( cl_decalList ));
|
|
|
|
|
|
|
|
|
|
cl_activeDecals.next = &cl_activeDecals;
|
|
|
|
|
cl_activeDecals.prev = &cl_activeDecals;
|
|
|
|
|
cl_freeDecals = cl_decalList;
|
|
|
|
|
|
2008-12-15 22:00:00 +01:00
|
|
|
|
for( i = 0; i < MAX_DECAL_MARKS - 1; i++ )
|
2008-11-27 22:00:00 +01:00
|
|
|
|
cl_decalList[i].next = &cl_decalList[i+1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
CL_AddDecal
|
|
|
|
|
|
|
|
|
|
called from render after clipping
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void CL_AddDecal( vec3_t org, matrix3x3 m, shader_t s, vec4_t rgba, bool fade, decalFragment_t *df, const vec3_t *v )
|
|
|
|
|
{
|
|
|
|
|
cdecal_t *decal;
|
|
|
|
|
vec3_t delta;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
decal = CL_AllocDecal();
|
|
|
|
|
VectorCopy( org, decal->origin );
|
|
|
|
|
decal->time = cl.time;
|
|
|
|
|
Vector4Copy( rgba, decal->modulate );
|
|
|
|
|
decal->alphaFade = fade;
|
|
|
|
|
decal->shader = s;
|
|
|
|
|
decal->numVerts = df->numVerts;
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < df->numVerts; i++ )
|
|
|
|
|
{
|
|
|
|
|
VectorCopy( v[df->firstVert + i], decal->verts[i].point );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-11-27 22:00:00 +01:00
|
|
|
|
VectorSubtract( decal->verts[i].point, org, delta );
|
|
|
|
|
decal->verts[i].st[0] = 0.5 + DotProduct( delta, m[1] );
|
|
|
|
|
decal->verts[i].st[1] = 0.5 + DotProduct( delta, m[2] );
|
|
|
|
|
Vector4Copy( rgba, decal->verts[i].modulate );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
CL_AddDecals
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void CL_AddDecals( void )
|
|
|
|
|
{
|
|
|
|
|
cdecal_t *decal, *next;
|
|
|
|
|
int i, time, fadeTime;
|
|
|
|
|
float c;
|
|
|
|
|
|
|
|
|
|
fadeTime = DECAL_FADETIME; // 30 seconds
|
|
|
|
|
|
|
|
|
|
for( decal = cl_activeDecals.next; decal != &cl_activeDecals; decal = next )
|
|
|
|
|
{
|
|
|
|
|
// crab next now, so if the decal is freed we still have it
|
|
|
|
|
next = decal->next;
|
|
|
|
|
|
|
|
|
|
if( cl.time >= decal->time + DECAL_STAYTIME )
|
|
|
|
|
{
|
|
|
|
|
CL_FreeDecal( decal );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HACKHACK: fade out glowing energy decals
|
|
|
|
|
if( decal->shader == re->RegisterShader( "particles/energy", SHADER_GENERIC ))
|
|
|
|
|
{
|
|
|
|
|
time = cl.time - decal->time;
|
|
|
|
|
|
|
|
|
|
if( time < fadeTime )
|
|
|
|
|
{
|
|
|
|
|
c = 1.0 - ((float)time / fadeTime);
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < decal->numVerts; i++ )
|
|
|
|
|
{
|
|
|
|
|
decal->verts[i].modulate[0] = decal->modulate[0] * c;
|
|
|
|
|
decal->verts[i].modulate[1] = decal->modulate[1] * c;
|
|
|
|
|
decal->verts[i].modulate[2] = decal->modulate[2] * c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fade out with time
|
|
|
|
|
time = decal->time + DECAL_STAYTIME - cl.time;
|
|
|
|
|
|
|
|
|
|
if( time < fadeTime )
|
|
|
|
|
{
|
|
|
|
|
c = (float)time / fadeTime;
|
|
|
|
|
|
|
|
|
|
if( decal->alphaFade )
|
|
|
|
|
{
|
|
|
|
|
for( i = 0; i < decal->numVerts; i++ )
|
|
|
|
|
decal->verts[i].modulate[3] = decal->modulate[3] * c;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for( i = 0; i < decal->numVerts; i++ )
|
|
|
|
|
{
|
|
|
|
|
decal->verts[i].modulate[0] = decal->modulate[0] * c;
|
|
|
|
|
decal->verts[i].modulate[1] = decal->modulate[1] * c;
|
|
|
|
|
decal->verts[i].modulate[2] = decal->modulate[2] * c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
re->AddPolygon( decal->shader, decal->numVerts, decal->verts );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
2009-01-15 22:00:00 +01:00
|
|
|
|
pfnAddDecal
|
2008-11-27 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
===============
|
|
|
|
|
*/
|
2009-01-15 22:00:00 +01:00
|
|
|
|
void pfnAddDecal( float *org, float *dir, float *rgba, float rot, float rad, HSPRITE hSpr, int flags )
|
2008-11-27 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
bool fade, temp;
|
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
fade = (flags & DECAL_FADE) ? true : false;
|
|
|
|
|
temp = (flags & DECAL_TEMPORARY) ? true : false;
|
2008-11-27 22:00:00 +01:00
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
re->ImpactMark( org, dir, rot, rad, rgba, fade, hSpr, temp );
|
2008-11-27 22:00:00 +01:00
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
==============================================================
|
|
|
|
|
|
|
|
|
|
PARTICLE MANAGEMENT
|
|
|
|
|
|
|
|
|
|
==============================================================
|
|
|
|
|
*/
|
2009-01-15 22:00:00 +01:00
|
|
|
|
struct cparticle_s
|
2008-11-16 22:00:00 +01:00
|
|
|
|
{
|
2009-01-15 22:00:00 +01:00
|
|
|
|
// this part are shared both client and engine
|
|
|
|
|
vec3_t origin;
|
|
|
|
|
vec3_t velocity;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
vec3_t accel;
|
|
|
|
|
vec3_t color;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
vec3_t colorVelocity;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
float alpha;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
float alphaVelocity;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
float radius;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
float radiusVelocity;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
float length;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
float lengthVelocity;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
float rotation;
|
|
|
|
|
float bounceFactor;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
// this part are private for engine
|
|
|
|
|
cparticle_t *next;
|
|
|
|
|
shader_t shader;
|
|
|
|
|
|
|
|
|
|
int time;
|
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
|
|
vec3_t oldorigin;
|
|
|
|
|
};
|
2008-11-16 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
cparticle_t *cl_active_particles, *cl_free_particles;
|
|
|
|
|
static cparticle_t cl_particle_list[MAX_PARTICLES];
|
2008-11-20 22:00:00 +01:00
|
|
|
|
static vec3_t cl_particle_velocities[NUMVERTEXNORMALS];
|
2008-11-16 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
CL_FreeParticle
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
static void CL_FreeParticle( cparticle_t *p )
|
|
|
|
|
{
|
|
|
|
|
p->next = cl_free_particles;
|
|
|
|
|
cl_free_particles = p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
CL_AllocParticle
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
static cparticle_t *CL_AllocParticle( void )
|
|
|
|
|
{
|
|
|
|
|
cparticle_t *p;
|
|
|
|
|
|
|
|
|
|
if( !cl_free_particles )
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if( cl_particlelod->integer > 1 )
|
|
|
|
|
{
|
|
|
|
|
if(!(Com_RandomLong( 0, 1 ) % cl_particlelod->integer))
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = cl_free_particles;
|
|
|
|
|
cl_free_particles = p->next;
|
|
|
|
|
p->next = cl_active_particles;
|
|
|
|
|
cl_active_particles = p;
|
|
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
|
CL_ClearParticles
|
|
|
|
|
===============
|
|
|
|
|
*/
|
2008-06-14 22:00:00 +02:00
|
|
|
|
void CL_ClearParticles( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2008-11-16 22:00:00 +01:00
|
|
|
|
cl_active_particles = NULL;
|
|
|
|
|
cl_free_particles = cl_particle_list;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-11-16 22:00:00 +01:00
|
|
|
|
for( i = 0; i < MAX_PARTICLES; i++ )
|
|
|
|
|
cl_particle_list[i].next = &cl_particle_list[i+1];
|
|
|
|
|
|
|
|
|
|
cl_particle_list[MAX_PARTICLES-1].next = NULL;
|
|
|
|
|
|
2008-11-20 22:00:00 +01:00
|
|
|
|
for( i = 0; i < NUMVERTEXNORMALS; i++ )
|
2008-11-16 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
cl_particle_velocities[i][0] = (rand() & 255) * 0.01;
|
|
|
|
|
cl_particle_velocities[i][1] = (rand() & 255) * 0.01;
|
|
|
|
|
cl_particle_velocities[i][2] = (rand() & 255) * 0.01;
|
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-16 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
|
CL_AddParticles
|
|
|
|
|
===============
|
|
|
|
|
*/
|
|
|
|
|
void CL_AddParticles( void )
|
|
|
|
|
{
|
|
|
|
|
cparticle_t *p, *next;
|
|
|
|
|
cparticle_t *active = NULL, *tail = NULL;
|
|
|
|
|
dword modulate;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
vec3_t origin, oldorigin, velocity, color;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
vec3_t ambientLight;
|
|
|
|
|
float alpha, radius, length;
|
|
|
|
|
float time, time2, gravity, dot;
|
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
|
int contents;
|
|
|
|
|
trace_t trace;
|
|
|
|
|
|
|
|
|
|
if( !cl_particles->integer ) return;
|
|
|
|
|
|
2008-12-26 22:00:00 +01:00
|
|
|
|
if( EDICT_NUM( cl.frame.ps.number )->pvClientData->current.gravity != 0 )
|
2009-01-15 22:00:00 +01:00
|
|
|
|
gravity = EDICT_NUM( cl.frame.ps.number )->pvClientData->current.gravity / clgame.gravity;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
else gravity = 1.0f;
|
|
|
|
|
|
|
|
|
|
for( p = cl_active_particles; p; p = next )
|
|
|
|
|
{
|
|
|
|
|
// grab next now, so if the particle is freed we still have it
|
|
|
|
|
next = p->next;
|
|
|
|
|
|
|
|
|
|
time = (cl.time - p->time) * 0.001;
|
|
|
|
|
time2 = time * time;
|
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
alpha = p->alpha + p->alphaVelocity * time;
|
|
|
|
|
radius = p->radius + p->radiusVelocity * time;
|
|
|
|
|
length = p->length + p->lengthVelocity * time;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
if( alpha <= 0 || radius <= 0 || length <= 0 )
|
|
|
|
|
{
|
|
|
|
|
// faded out
|
|
|
|
|
CL_FreeParticle( p );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
color[0] = p->color[0] + p->colorVelocity[0] * time;
|
|
|
|
|
color[1] = p->color[1] + p->colorVelocity[1] * time;
|
|
|
|
|
color[2] = p->color[2] + p->colorVelocity[2] * time;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
origin[0] = p->origin[0] + p->velocity[0] * time + p->accel[0] * time2;
|
|
|
|
|
origin[1] = p->origin[1] + p->velocity[1] * time + p->accel[1] * time2;
|
|
|
|
|
origin[2] = p->origin[2] + p->velocity[2] * time + p->accel[2] * time2 * gravity;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
if( p->flags & PARTICLE_UNDERWATER )
|
|
|
|
|
{
|
|
|
|
|
// underwater particle
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorSet( oldorigin, origin[0], origin[1], origin[2] + radius );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
if(!(CL_PointContents( oldorigin ) & MASK_WATER ))
|
2008-11-16 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
// not underwater
|
|
|
|
|
CL_FreeParticle( p );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p->next = NULL;
|
|
|
|
|
if( !tail ) active = tail = p;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tail->next = p;
|
|
|
|
|
tail = p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( p->flags & PARTICLE_FRICTION )
|
|
|
|
|
{
|
|
|
|
|
// water friction affected particle
|
2009-01-15 22:00:00 +01:00
|
|
|
|
contents = CL_PointContents( origin );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
if( contents & MASK_WATER )
|
|
|
|
|
{
|
|
|
|
|
// add friction
|
|
|
|
|
if( contents & CONTENTS_WATER )
|
|
|
|
|
{
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorScale( p->velocity, 0.25, p->velocity );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
VectorScale( p->accel, 0.25, p->accel );
|
|
|
|
|
}
|
|
|
|
|
if( contents & CONTENTS_SLIME )
|
|
|
|
|
{
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorScale( p->velocity, 0.20, p->velocity );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
VectorScale( p->accel, 0.20, p->accel );
|
|
|
|
|
}
|
|
|
|
|
if( contents & CONTENTS_LAVA )
|
|
|
|
|
{
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorScale( p->velocity, 0.10, p->velocity );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
VectorScale( p->accel, 0.10, p->accel );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// don't add friction again
|
|
|
|
|
p->flags &= ~PARTICLE_FRICTION;
|
|
|
|
|
length = 1;
|
|
|
|
|
|
|
|
|
|
// reset
|
|
|
|
|
p->time = cl.time;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorCopy( origin, p->origin );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
VectorCopy( color, p->color );
|
|
|
|
|
p->alpha = alpha;
|
|
|
|
|
p->radius = radius;
|
|
|
|
|
|
|
|
|
|
// don't stretch
|
|
|
|
|
p->flags &= ~PARTICLE_STRETCH;
|
|
|
|
|
p->length = length;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
p->lengthVelocity = 0;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( p->flags & PARTICLE_BOUNCE )
|
|
|
|
|
{
|
2008-12-25 22:00:00 +01:00
|
|
|
|
edict_t *clent = EDICT_NUM( cl.frame.ps.number );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
// bouncy particle
|
|
|
|
|
VectorSet(mins, -radius, -radius, -radius);
|
|
|
|
|
VectorSet(maxs, radius, radius, radius);
|
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
trace = CL_Trace( p->oldorigin, mins, maxs, origin, MOVE_NORMAL, clent, MASK_SOLID );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
if( trace.fraction != 0.0 && trace.fraction != 1.0 )
|
|
|
|
|
{
|
|
|
|
|
// reflect velocity
|
|
|
|
|
time = cl.time - (cls.frametime + cls.frametime * trace.fraction) * 1000;
|
|
|
|
|
time = (time - p->time) * 0.001;
|
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
velocity[0] = p->velocity[0];
|
|
|
|
|
velocity[1] = p->velocity[1];
|
|
|
|
|
velocity[2] = p->velocity[2] + p->accel[2] * gravity * time;
|
|
|
|
|
VectorReflect( velocity, 0, trace.plane.normal, p->velocity );
|
|
|
|
|
VectorScale( p->velocity, p->bounceFactor, p->velocity );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
// check for stop or slide along the plane
|
2009-01-15 22:00:00 +01:00
|
|
|
|
if( trace.plane.normal[2] > 0 && p->velocity[2] < 1 )
|
2008-11-16 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
if( trace.plane.normal[2] == 1 )
|
|
|
|
|
{
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorClear( p->velocity );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
VectorClear( p->accel );
|
|
|
|
|
p->flags &= ~PARTICLE_BOUNCE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// FIXME: check for new plane or free fall
|
2009-01-15 22:00:00 +01:00
|
|
|
|
dot = DotProduct( p->velocity, trace.plane.normal );
|
|
|
|
|
VectorMA( p->velocity, -dot, trace.plane.normal, p->velocity );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
dot = DotProduct( p->accel, trace.plane.normal );
|
|
|
|
|
VectorMA( p->accel, -dot, trace.plane.normal, p->accel );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorCopy( trace.endpos, origin );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
length = 1;
|
|
|
|
|
|
|
|
|
|
// reset
|
|
|
|
|
p->time = cl.time;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorCopy( origin, p->origin );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
VectorCopy( color, p->color );
|
|
|
|
|
p->alpha = alpha;
|
|
|
|
|
p->radius = radius;
|
|
|
|
|
|
|
|
|
|
// don't stretch
|
|
|
|
|
p->flags &= ~PARTICLE_STRETCH;
|
|
|
|
|
p->length = length;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
p->lengthVelocity = 0;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// save current origin if needed
|
|
|
|
|
if( p->flags & (PARTICLE_BOUNCE|PARTICLE_STRETCH))
|
|
|
|
|
{
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorCopy( p->oldorigin, oldorigin );
|
|
|
|
|
VectorCopy( origin, p->oldorigin ); // FIXME: pause
|
2008-11-16 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( p->flags & PARTICLE_VERTEXLIGHT )
|
|
|
|
|
{
|
|
|
|
|
// vertex lit particle
|
2009-01-15 22:00:00 +01:00
|
|
|
|
re->LightForPoint( origin, ambientLight );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
VectorMultiply( color, ambientLight, color );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// bound color and alpha and convert to byte
|
|
|
|
|
modulate = PackRGBA( color[0], color[1], color[2], alpha );
|
|
|
|
|
|
|
|
|
|
if( p->flags & PARTICLE_INSTANT )
|
|
|
|
|
{
|
|
|
|
|
// instant particle
|
|
|
|
|
p->alpha = 0;
|
2009-01-15 22:00:00 +01:00
|
|
|
|
p->alphaVelocity = 0;
|
2008-11-16 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// send the particle to the renderer
|
2009-01-15 22:00:00 +01:00
|
|
|
|
re->AddParticle( p->shader, origin, oldorigin, radius, length, p->rotation, modulate );
|
2008-11-16 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cl_active_particles = active;
|
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-11-25 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
===============
|
2009-01-15 22:00:00 +01:00
|
|
|
|
pfnAddParticle
|
2008-11-25 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
===============
|
|
|
|
|
*/
|
2009-01-15 22:00:00 +01:00
|
|
|
|
bool pfnAddParticle( cparticle_t *src, HSPRITE shader, int flags )
|
2008-11-25 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
cparticle_t *p;
|
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
if( !src ) return false;
|
2008-11-25 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
p = CL_AllocParticle();
|
|
|
|
|
if( !p )
|
|
|
|
|
{
|
2009-01-15 22:00:00 +01:00
|
|
|
|
MsgDev( D_ERROR, "CL_AddParticle: no free particles\n" );
|
|
|
|
|
return false;
|
2008-11-25 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p->shader = shader;
|
|
|
|
|
p->time = cl.time;
|
|
|
|
|
p->flags = flags;
|
|
|
|
|
|
2009-01-15 22:00:00 +01:00
|
|
|
|
// sizeof( src ) != sizeof( p ), we must copy params manually
|
|
|
|
|
VectorCopy( src->origin, p->origin );
|
|
|
|
|
VectorCopy( src->velocity, p->velocity );
|
|
|
|
|
VectorCopy( src->accel, p->accel );
|
|
|
|
|
VectorCopy( src->color, p->color );
|
|
|
|
|
VectorCopy( src->colorVelocity, p->colorVelocity );
|
|
|
|
|
p->alpha = src->alpha;
|
|
|
|
|
|
|
|
|
|
p->radius = src->radius;
|
|
|
|
|
p->length = src->length;
|
|
|
|
|
p->rotation = src->rotation;
|
|
|
|
|
p->alphaVelocity = src->alphaVelocity;
|
|
|
|
|
p->radiusVelocity = src->radiusVelocity;
|
|
|
|
|
p->lengthVelocity = src->lengthVelocity;
|
|
|
|
|
p->bounceFactor = src->bounceFactor;
|
2008-11-25 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
// needs to save old origin
|
|
|
|
|
if( flags & (PARTICLE_BOUNCE|PARTICLE_FRICTION))
|
2009-01-15 22:00:00 +01:00
|
|
|
|
VectorCopy( p->origin, p->oldorigin );
|
|
|
|
|
|
|
|
|
|
return true;
|
2008-11-25 22:00:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
==============
|
|
|
|
|
CL_ClearEffects
|
|
|
|
|
==============
|
|
|
|
|
*/
|
2008-06-30 22:00:00 +02:00
|
|
|
|
void CL_ClearEffects( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
CL_ClearParticles ();
|
|
|
|
|
CL_ClearDlights ();
|
|
|
|
|
CL_ClearLightStyles ();
|
2008-11-27 22:00:00 +01:00
|
|
|
|
CL_ClearDecals ();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|