2010-06-18 15:38:54 +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:38:54 +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:38:54 +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:38:54 +00:00
|
|
|
*
|
|
|
|
* =======================================================================
|
|
|
|
*
|
|
|
|
* This file implements all generic particle stuff
|
|
|
|
*
|
|
|
|
* =======================================================================
|
2012-04-29 13:57:33 +00:00
|
|
|
*/
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-04-29 13:57:33 +00:00
|
|
|
#include "header/client.h"
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
cparticle_t *active_particles, *free_particles;
|
|
|
|
cparticle_t particles[MAX_PARTICLES];
|
|
|
|
int cl_numparticles = MAX_PARTICLES;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_ClearParticles(void)
|
|
|
|
{
|
|
|
|
int i;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
|
|
|
free_particles = &particles[0];
|
|
|
|
active_particles = NULL;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < cl_numparticles; i++)
|
|
|
|
{
|
|
|
|
particles[i].next = &particles[i + 1];
|
|
|
|
}
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
particles[cl_numparticles - 1].next = NULL;
|
2010-06-18 15:38:54 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_ParticleEffect(vec3_t org, vec3_t dir, int color, int count)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
cparticle_t *p;
|
|
|
|
float d;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
if (!free_particles)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:38:54 +00:00
|
|
|
|
|
|
|
p = free_particles;
|
|
|
|
free_particles = p->next;
|
|
|
|
p->next = active_particles;
|
|
|
|
active_particles = p;
|
|
|
|
|
|
|
|
p->time = cl.time;
|
2012-07-22 13:34:45 +00:00
|
|
|
p->color = color + (randk() & 7);
|
|
|
|
d = randk() & 31;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
p->org[j] = org[j] + ((randk() & 7) - 4) + d * dir[j];
|
|
|
|
p->vel[j] = crandk() * 20;
|
2010-06-18 15:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
2012-07-22 13:34:45 +00:00
|
|
|
p->accel[2] = -PARTICLE_GRAVITY + 0.2f;
|
2010-06-18 15:38:54 +00:00
|
|
|
p->alpha = 1.0;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
p->alphavel = -1.0 / (0.5 + frandk() * 0.3);
|
2010-06-18 15:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_ParticleEffect2(vec3_t org, vec3_t dir, int color, int count)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
cparticle_t *p;
|
|
|
|
float d;
|
|
|
|
float time;
|
|
|
|
|
2010-06-18 15:38:54 +00:00
|
|
|
time = (float)cl.time;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
if (!free_particles)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:38:54 +00:00
|
|
|
|
|
|
|
p = free_particles;
|
|
|
|
free_particles = p->next;
|
|
|
|
p->next = active_particles;
|
|
|
|
active_particles = p;
|
|
|
|
|
|
|
|
p->time = time;
|
2012-07-22 13:34:45 +00:00
|
|
|
p->color = color + (randk() & 7);
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
d = randk() & 7;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
p->org[j] = org[j] + ((randk() & 7) - 4) + d * dir[j];
|
|
|
|
p->vel[j] = crandk() * 20;
|
2010-06-18 15:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
|
|
p->alpha = 1.0;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
p->alphavel = -1.0f / (0.5f + frandk() * 0.3f);
|
2010-06-18 15:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_ParticleEffect3(vec3_t org, vec3_t dir, int color, int count)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
cparticle_t *p;
|
|
|
|
float d;
|
|
|
|
float time;
|
|
|
|
|
2010-06-18 15:38:54 +00:00
|
|
|
time = (float)cl.time;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
if (!free_particles)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:38:54 +00:00
|
|
|
|
|
|
|
p = free_particles;
|
|
|
|
free_particles = p->next;
|
|
|
|
p->next = active_particles;
|
|
|
|
active_particles = p;
|
|
|
|
|
|
|
|
p->time = time;
|
|
|
|
p->color = color;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
d = randk() & 7;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
p->org[j] = org[j] + ((randk() & 7) - 4) + d * dir[j];
|
|
|
|
p->vel[j] = crandk() * 20;
|
2010-06-18 15:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
|
|
p->accel[2] = PARTICLE_GRAVITY;
|
|
|
|
p->alpha = 1.0;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
p->alphavel = -1.0f / (0.5f + frandk() * 0.3f);
|
2010-06-18 15:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_AddParticles(void)
|
|
|
|
{
|
|
|
|
cparticle_t *p, *next;
|
|
|
|
float alpha;
|
|
|
|
float time, time2;
|
|
|
|
vec3_t org;
|
|
|
|
int color;
|
|
|
|
cparticle_t *active, *tail;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
|
|
|
active = NULL;
|
|
|
|
tail = NULL;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (p = active_particles; p; p = next)
|
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
next = p->next;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (p->alphavel != INSTANT_PARTICLE)
|
|
|
|
{
|
|
|
|
time = (cl.time - p->time) * 0.001;
|
|
|
|
alpha = p->alpha + time * p->alphavel;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (alpha <= 0)
|
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
/* faded out */
|
|
|
|
p->next = free_particles;
|
|
|
|
free_particles = p;
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
time = 0.0f;
|
|
|
|
alpha = p->alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->next = NULL;
|
|
|
|
|
|
|
|
if (!tail)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
active = tail = p;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
else
|
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
tail->next = p;
|
|
|
|
tail = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alpha > 1.0f)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
alpha = 1;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 15:38:54 +00:00
|
|
|
|
|
|
|
color = p->color;
|
2012-07-22 13:34:45 +00:00
|
|
|
time2 = time * time;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
org[0] = p->org[0] + p->vel[0] * time + p->accel[0] * time2;
|
|
|
|
org[1] = p->org[1] + p->vel[1] * time + p->accel[1] * time2;
|
|
|
|
org[2] = p->org[2] + p->vel[2] * time + p->accel[2] * time2;
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
V_AddParticle(org, color, alpha);
|
2010-06-18 15:38:54 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (p->alphavel == INSTANT_PARTICLE)
|
|
|
|
{
|
2010-06-18 15:38:54 +00:00
|
|
|
p->alphavel = 0.0;
|
|
|
|
p->alpha = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
active_particles = active;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_GenericParticleEffect(vec3_t org, vec3_t dir, int color,
|
|
|
|
int count, int numcolors, int dirspread, float alphavel)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
cparticle_t *p;
|
|
|
|
float d;
|
|
|
|
float time;
|
|
|
|
|
2010-06-18 16:28:25 +00:00
|
|
|
time = (float)cl.time;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2010-06-18 16:28:25 +00:00
|
|
|
if (!free_particles)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:28:25 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:28:25 +00:00
|
|
|
|
|
|
|
p = free_particles;
|
|
|
|
free_particles = p->next;
|
|
|
|
p->next = active_particles;
|
|
|
|
active_particles = p;
|
|
|
|
|
|
|
|
p->time = time;
|
|
|
|
|
|
|
|
if (numcolors > 1)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2012-06-02 09:55:12 +00:00
|
|
|
p->color = color + (randk() & numcolors);
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:28:25 +00:00
|
|
|
|
|
|
|
else
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:28:25 +00:00
|
|
|
p->color = color;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:28:25 +00:00
|
|
|
|
2012-06-02 09:55:12 +00:00
|
|
|
d = (float)(randk() & dirspread);
|
2010-06-18 16:28:25 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
p->org[j] = org[j] + ((randk() & 7) - 4) + d * dir[j];
|
|
|
|
p->vel[j] = crandk() * 20;
|
2010-06-18 16:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
|
|
p->alpha = 1.0;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
p->alphavel = -1.0f / (0.5f + frandk() * alphavel);
|
2010-06-18 16:28:25 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-22 13:34:45 +00:00
|
|
|
|