2001-05-24 19:19:32 +00:00
|
|
|
/*
|
|
|
|
r_part.c
|
|
|
|
|
2003-10-22 06:00:36 +00:00
|
|
|
Interface for particles
|
2001-05-24 19:19:32 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-09-22 02:37:45 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-08-27 01:00:03 +00:00
|
|
|
#include "QF/qargs.h"
|
2001-05-29 19:43:15 +00:00
|
|
|
#include "QF/render.h"
|
2012-01-15 11:14:36 +00:00
|
|
|
#include "QF/sys.h"
|
2001-05-24 19:19:32 +00:00
|
|
|
|
2001-08-26 16:54:33 +00:00
|
|
|
#include "compat.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-05-24 19:19:32 +00:00
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
psystem_t r_psystem; //FIXME singleton
|
|
|
|
|
2001-09-22 02:37:45 +00:00
|
|
|
/*
|
|
|
|
R_MaxParticlesCheck
|
|
|
|
|
|
|
|
Misty-chan: Dynamically change the maximum amount of particles on the fly.
|
|
|
|
Thanks to a LOT of help from Taniwha, Deek, Mercury, Lordhavoc, and lots of
|
|
|
|
others.
|
|
|
|
*/
|
|
|
|
void
|
2001-12-03 08:55:46 +00:00
|
|
|
R_MaxParticlesCheck (cvar_t *r_particles, cvar_t *r_particles_max)
|
2001-09-22 02:37:45 +00:00
|
|
|
{
|
2021-12-19 05:47:25 +00:00
|
|
|
psystem_t *ps = &r_psystem;//FIXME
|
2021-12-18 16:21:39 +00:00
|
|
|
unsigned maxparticles = 0;
|
|
|
|
if (r_particles && r_particles->int_val) {
|
|
|
|
maxparticles = r_particles_max ? r_particles_max->int_val : 0;
|
|
|
|
}
|
2001-09-22 02:37:45 +00:00
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
if (ps->maxparticles == maxparticles) {
|
2021-12-18 16:21:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t size = sizeof (particle_t) + sizeof (partparm_t)
|
|
|
|
+ sizeof (int *);
|
2001-10-27 08:31:45 +00:00
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
if (ps->particles) {
|
|
|
|
Sys_Free (ps->particles, ps->maxparticles * size);
|
|
|
|
ps->particles = 0;
|
|
|
|
ps->partparams = 0;
|
|
|
|
ps->partramps = 0;
|
2021-12-18 16:21:39 +00:00
|
|
|
}
|
2021-12-19 05:47:25 +00:00
|
|
|
ps->maxparticles = maxparticles;
|
2001-10-27 08:31:45 +00:00
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
if (ps->maxparticles) {
|
|
|
|
ps->particles = Sys_Alloc (ps->maxparticles * size);
|
|
|
|
ps->partparams = (partparm_t *) &ps->particles[ps->maxparticles];
|
|
|
|
ps->partramps = (const int **) &ps->partparams[ps->maxparticles];
|
2001-10-27 08:31:45 +00:00
|
|
|
}
|
2021-12-19 04:08:39 +00:00
|
|
|
R_ClearParticles ();
|
2012-01-15 11:14:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-19 04:08:39 +00:00
|
|
|
void
|
|
|
|
R_ClearParticles (void)
|
2012-01-15 11:14:36 +00:00
|
|
|
{
|
2021-12-19 05:47:25 +00:00
|
|
|
psystem_t *ps = &r_psystem;//FIXME
|
|
|
|
ps->numparticles = 0;
|
2012-01-15 11:14:36 +00:00
|
|
|
}
|
2021-12-19 04:38:50 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
R_RunParticles (float dT)
|
|
|
|
{
|
2021-12-19 05:47:25 +00:00
|
|
|
psystem_t *ps = &r_psystem;//FIXME
|
2022-03-29 04:46:11 +00:00
|
|
|
vec4f_t gravity = ps->gravity;
|
2021-12-19 04:38:50 +00:00
|
|
|
|
|
|
|
unsigned j = 0;
|
2021-12-19 05:47:25 +00:00
|
|
|
for (unsigned i = 0; i < ps->numparticles; i++) {
|
|
|
|
particle_t *p = &ps->particles[i];
|
|
|
|
partparm_t *parm = &ps->partparams[i];
|
2021-12-19 04:38:50 +00:00
|
|
|
|
|
|
|
if (p->live <= 0 || p->ramp >= parm->ramp_max) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-03-08 11:16:18 +00:00
|
|
|
const int *ramp = ps->partramps[i];
|
2021-12-19 04:38:50 +00:00
|
|
|
if (i > j) {
|
2021-12-19 05:47:25 +00:00
|
|
|
ps->particles[j] = *p;
|
|
|
|
ps->partparams[j] = *parm;
|
|
|
|
ps->partramps[j] = ramp;
|
2021-12-19 04:38:50 +00:00
|
|
|
}
|
|
|
|
j += 1;
|
|
|
|
|
|
|
|
p->pos += dT * p->vel;
|
|
|
|
p->vel += dT * (p->vel * parm->drag + gravity * parm->drag[3]);
|
|
|
|
p->ramp += dT * parm->ramp;
|
|
|
|
p->live -= dT;
|
|
|
|
if (ramp) {
|
|
|
|
p->icolor = ramp[(int)p->ramp];
|
|
|
|
}
|
|
|
|
}
|
2021-12-19 05:47:25 +00:00
|
|
|
ps->numparticles = j;
|
2021-12-19 04:38:50 +00:00
|
|
|
}
|