quakeforge/libs/video/renderer/r_part.c

210 lines
5.5 KiB
C
Raw Normal View History

2001-05-24 19:19:32 +00:00
/*
r_part.c
@description@
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
*/
2001-09-28 06:26:31 +00:00
static const char rcsid[] =
"$Id$";
2001-05-24 19:19:32 +00:00
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "QF/console.h"
#include "QF/cvar.h"
2001-08-27 01:00:03 +00:00
#include "QF/qargs.h"
#include "QF/render.h"
2001-05-24 19:19:32 +00:00
2001-08-26 16:54:33 +00:00
#include "compat.h"
2001-05-24 19:19:32 +00:00
#include "r_local.h"
unsigned int r_maxparticles, numparticles;
particle_t *active_particles, *free_particles, *particles, **freeparticles;
vec3_t r_pright, r_pup, r_ppn;
2001-05-24 19:19:32 +00:00
void (*R_RocketTrail) (struct entity_s *ent);
void (*R_GrenadeTrail) (struct entity_s *ent);
void (*R_BloodTrail) (struct entity_s *ent);
void (*R_SlightBloodTrail) (struct entity_s *ent);
void (*R_WizTrail) (struct entity_s *ent);
void (*R_FlameTrail) (struct entity_s *ent);
void (*R_VoorTrail) (struct entity_s *ent);
2002-09-13 00:23:58 +00:00
void (*R_GlowTrail) (struct entity_s *ent, int glow_color);
void (*R_RunParticleEffect) (vec3_t org, vec3_t dir, int color, int count);
void (*R_BloodPuffEffect) (vec3_t org, int count);
void (*R_GunshotEffect) (vec3_t org, int count);
void (*R_LightningBloodEffect) (vec3_t org);
void (*R_SpikeEffect) (vec3_t org);
void (*R_KnightSpikeEffect) (vec3_t org);
void (*R_SuperSpikeEffect) (vec3_t org);
void (*R_WizSpikeEffect) (vec3_t org);
void (*R_BlobExplosion) (vec3_t org);
void (*R_ParticleExplosion) (vec3_t org);
void (*R_ParticleExplosion2) (vec3_t org, int colorStart, int colorLength);
void (*R_LavaSplash) (vec3_t org);
void (*R_TeleportSplash) (vec3_t org);
/*
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
R_MaxParticlesCheck (cvar_t *r_particles, cvar_t *r_particles_max)
{
/*
Catchall. If the user changed the setting to a number less than zero *or*
if we had a wacky cfg get past the init code check, this will make sure we
don't have problems. Also note that grabbing the var->int_val is IMPORTANT:
Prevents a segfault since if we grabbed the int_val of r_particles_max
we'd sig11 right here at startup.
*/
if (r_particles && r_particles->int_val)
r_maxparticles = r_particles_max ? r_particles_max->int_val : 0;
else
r_maxparticles = 0;
/*
Be very careful the next time we do something like this. calloc/free are
IMPORTANT and the compiler doesn't know when we do bad things with them.
*/
if (particles)
free (particles);
if (freeparticles)
free (freeparticles);
particles = 0;
freeparticles = 0;
if (r_maxparticles) {
particles = (particle_t *) calloc (r_maxparticles, sizeof (particle_t));
freeparticles = (particle_t **) calloc (r_maxparticles,
sizeof (particle_t *));
}
R_ClearParticles ();
if (r_init)
R_InitParticles ();
}
2001-05-24 19:19:32 +00:00
void
R_DarkFieldParticles (entity_t *ent)
{
int i, j, k;
float vel;
2001-08-27 01:00:03 +00:00
particle_t *p;
vec3_t dir, org;
2001-05-24 19:19:32 +00:00
org[0] = ent->origin[0];
org[1] = ent->origin[1];
org[2] = ent->origin[2];
for (i = -16; i < 16; i += 8)
for (j = -16; j < 16; j += 8)
for (k = 0; k < 32; k += 8) {
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
2001-05-29 19:52:10 +00:00
p->die = r_realtime + 0.2 + (rand () & 7) * 0.02;
2001-05-24 19:19:32 +00:00
p->color = 150 + rand () % 6;
p->type = pt_slowgrav;
dir[0] = j * 8;
dir[1] = i * 8;
dir[2] = k * 8;
p->org[0] = org[0] + i + (rand () & 3);
p->org[1] = org[1] + j + (rand () & 3);
p->org[2] = org[2] + k + (rand () & 3);
VectorNormalize (dir);
vel = 50 + (rand () & 63);
VectorScale (dir, vel, p->vel);
}
}
2001-08-27 01:00:03 +00:00
static float beamlength = 16;
static vec3_t avelocities[NUMVERTEXNORMALS];
2001-05-24 19:19:32 +00:00
2001-08-30 19:51:11 +00:00
2001-05-24 19:19:32 +00:00
void
R_EntityParticles (entity_t *ent)
{
2001-08-27 01:00:03 +00:00
int count, i;
2001-08-30 19:51:11 +00:00
float angle, dist, sp, sy, cp, cy; // cr, sr
2001-05-24 19:19:32 +00:00
particle_t *p;
vec3_t forward;
dist = 64;
count = 50;
if (!avelocities[0][0]) {
for (i = 0; i < NUMVERTEXNORMALS * 3; i++)
avelocities[0][i] = (rand () & 255) * 0.01;
}
for (i = 0; i < NUMVERTEXNORMALS; i++) {
2001-05-29 19:52:10 +00:00
angle = r_realtime * avelocities[i][0];
2001-05-24 19:19:32 +00:00
sy = sin (angle);
cy = cos (angle);
2001-05-29 19:52:10 +00:00
angle = r_realtime * avelocities[i][1];
2001-05-24 19:19:32 +00:00
sp = sin (angle);
cp = cos (angle);
2001-08-30 19:51:11 +00:00
// Next 3 lines results aren't currently used, may be in future. --Despair
// angle = r_realtime * avelocities[i][2];
// sr = sin (angle);
// cr = cos (angle);
2001-05-24 19:19:32 +00:00
forward[0] = cp * cy;
forward[1] = cp * sy;
forward[2] = -sp;
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
2001-05-29 19:52:10 +00:00
p->die = r_realtime + 0.01;
2001-05-24 19:19:32 +00:00
p->color = 0x6f;
p->type = pt_explode;
2001-08-30 19:51:11 +00:00
p->org[0] = ent->origin[0] + r_avertexnormals[i][0] * dist +
2001-05-24 19:19:32 +00:00
forward[0] * beamlength;
2001-08-30 19:51:11 +00:00
p->org[1] = ent->origin[1] + r_avertexnormals[i][1] * dist +
2001-05-24 19:19:32 +00:00
forward[1] * beamlength;
2001-08-30 19:51:11 +00:00
p->org[2] = ent->origin[2] + r_avertexnormals[i][2] * dist +
2001-05-24 19:19:32 +00:00
forward[2] * beamlength;
}
}