2000-10-28 08:02:08 +00:00
|
|
|
/*
|
|
|
|
gl_dyn_part.c
|
|
|
|
|
|
|
|
Particle system!
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-10-28 08:02:08 +00:00
|
|
|
#endif
|
2000-12-05 06:33:44 +00:00
|
|
|
|
2000-12-30 02:16:36 +00:00
|
|
|
#include <stdlib.h>
|
2000-12-30 03:23:31 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2000-12-30 02:16:36 +00:00
|
|
|
|
2000-10-28 08:02:08 +00:00
|
|
|
#include "cmd.h"
|
|
|
|
#include "console.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "glquake.h"
|
|
|
|
#include "host.h"
|
2000-10-28 08:02:08 +00:00
|
|
|
#include "r_dynamic.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "qargs.h"
|
|
|
|
#include "sys.h"
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
#define MAX_PARTICLES 2048 // default max # of particles at one
|
2000-12-08 06:51:37 +00:00
|
|
|
// time
|
|
|
|
#define ABSOLUTE_MIN_PARTICLES 512 // no fewer than this no matter
|
|
|
|
// what's
|
|
|
|
// on the command line
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2000-12-08 06:51:37 +00:00
|
|
|
pt_static, pt_grav, pt_blob, pt_blob2,
|
|
|
|
pt_smoke, pt_smokecloud, pt_bloodcloud,
|
2000-10-28 08:02:08 +00:00
|
|
|
pt_fadespark, pt_fadespark2, pt_fallfadespark
|
|
|
|
} ptype_t;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
typedef struct particle_s {
|
2000-10-28 08:02:08 +00:00
|
|
|
// driver-usable fields
|
2000-12-08 06:51:37 +00:00
|
|
|
vec3_t org;
|
|
|
|
int tex;
|
|
|
|
float color;
|
|
|
|
float alpha;
|
|
|
|
float scale;
|
2000-10-28 08:02:08 +00:00
|
|
|
// drivers never touch the following fields
|
2000-12-08 06:51:37 +00:00
|
|
|
struct particle_s *next;
|
|
|
|
vec3_t vel;
|
|
|
|
float ramp;
|
|
|
|
float die;
|
|
|
|
ptype_t type;
|
2000-10-28 08:02:08 +00:00
|
|
|
} particle_t;
|
|
|
|
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static particle_t *particles, **freeparticles;
|
|
|
|
static short r_numparticles, numparticles;
|
|
|
|
|
|
|
|
extern qboolean lighthalf;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-28 09:29:38 +00:00
|
|
|
extern void GDT_Init (void);
|
2000-12-08 06:51:37 +00:00
|
|
|
extern int part_tex_smoke[8];
|
|
|
|
extern int part_tex_dot;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int ramp[8] = { 0x6d, 0x6b, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
inline particle_t *
|
2000-12-08 06:51:37 +00:00
|
|
|
particle_new (ptype_t type, int texnum, vec3_t org, float scale, vec3_t vel,
|
|
|
|
float die, byte color, byte alpha)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
|
|
|
particle_t *part;
|
|
|
|
|
|
|
|
if (numparticles >= r_numparticles) {
|
2000-12-08 06:51:37 +00:00
|
|
|
// Con_Printf("FAILED PARTICLE ALLOC!\n");
|
2000-10-28 08:02:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
part = &particles[numparticles++];
|
|
|
|
|
|
|
|
part->type = type;
|
2000-12-08 06:51:37 +00:00
|
|
|
VectorCopy (org, part->org);
|
|
|
|
VectorCopy (vel, part->vel);
|
2000-10-28 08:02:08 +00:00
|
|
|
part->die = die;
|
|
|
|
part->color = color;
|
|
|
|
part->alpha = alpha;
|
|
|
|
part->tex = texnum;
|
|
|
|
part->scale = scale;
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline particle_t *
|
2000-12-08 06:51:37 +00:00
|
|
|
particle_new_random (ptype_t type, int texnum, vec3_t org, int org_fuzz,
|
|
|
|
float scale, int vel_fuzz, float die, byte color,
|
|
|
|
byte alpha)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
vec3_t porg, pvel;
|
|
|
|
int j;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2000-10-28 08:02:08 +00:00
|
|
|
if (org_fuzz)
|
2000-12-08 06:51:37 +00:00
|
|
|
porg[j] = lhrandom (-org_fuzz, org_fuzz) + org[j];
|
2000-10-28 08:02:08 +00:00
|
|
|
if (vel_fuzz)
|
2000-12-08 06:51:37 +00:00
|
|
|
pvel[j] = lhrandom (-vel_fuzz, vel_fuzz);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
return particle_new (type, texnum, porg, scale, pvel, die, color, alpha);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_InitParticles
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_InitParticles (void)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
i = COM_CheckParm ("-particles");
|
|
|
|
|
|
|
|
if (i) {
|
2000-12-08 06:51:37 +00:00
|
|
|
r_numparticles = max (ABSOLUTE_MIN_PARTICLES, atoi (com_argv[i + 1]));
|
2000-10-28 08:02:08 +00:00
|
|
|
} else {
|
|
|
|
r_numparticles = MAX_PARTICLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
particles = (particle_t *)
|
2000-12-08 06:51:37 +00:00
|
|
|
Hunk_AllocName (r_numparticles * sizeof (particle_t), "particles");
|
|
|
|
|
2000-10-28 08:02:08 +00:00
|
|
|
freeparticles = (void *)
|
2000-12-08 06:51:37 +00:00
|
|
|
Hunk_AllocName (r_numparticles * sizeof (particle_t), "particles");
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
GDT_Init ();
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_ClearParticles
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_ClearParticles (void)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
|
|
|
numparticles = 0;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_ReadPointFile_f (void)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
QFile *f;
|
|
|
|
vec3_t org;
|
|
|
|
int r;
|
|
|
|
int c;
|
|
|
|
char name[MAX_OSPATH], *mapname, *t1;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
mapname = strdup (cl.worldmodel->name);
|
2000-10-28 08:02:08 +00:00
|
|
|
if (!mapname)
|
2000-12-08 06:51:37 +00:00
|
|
|
Sys_Error ("Can't duplicate mapname!");
|
|
|
|
t1 = strrchr (mapname, '.');
|
2000-10-28 08:02:08 +00:00
|
|
|
if (!t1)
|
2000-12-08 06:51:37 +00:00
|
|
|
Sys_Error ("Can't find .!");
|
2000-10-28 08:02:08 +00:00
|
|
|
t1[0] = '\0';
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (name, sizeof (name), "%s.pts", mapname);
|
|
|
|
free (mapname);
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
COM_FOpenFile (name, &f);
|
|
|
|
if (!f) {
|
|
|
|
Con_Printf ("couldn't open %s\n", name);
|
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-10-28 08:02:08 +00:00
|
|
|
Con_Printf ("Reading %s...\n", name);
|
|
|
|
c = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (;;) {
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
Qgets (f, buf, sizeof (buf));
|
|
|
|
r = sscanf (buf, "%f %f %f\n", &org[0], &org[1], &org[2]);
|
2000-10-28 08:02:08 +00:00
|
|
|
if (r != 3)
|
|
|
|
break;
|
|
|
|
c++;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
if (!particle_new (pt_static, part_tex_dot, org, 2, vec3_origin, 99999,
|
|
|
|
(-c) & 15, 255)) {
|
2000-10-28 08:02:08 +00:00
|
|
|
Con_Printf ("Not enough free particles\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Qclose (f);
|
|
|
|
Con_Printf ("%i points read\n", c);
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-10-28 08:02:08 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_ParticleExplosion
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_ParticleExplosion (vec3_t org)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
particle_new_random (pt_smokecloud, part_tex_smoke[rand () & 7], org, 8, 30,
|
|
|
|
8, cl.time + 5, (rand () & 7) + 8,
|
|
|
|
128 + (rand () & 63));
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_BlobExplosion
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_BlobExplosion (vec3_t org)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
|
2000-10-28 08:02:08 +00:00
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 512; i++) {
|
|
|
|
particle_new_random (pt_blob, part_tex_dot, org, 16, 2, 256,
|
|
|
|
(cl.time + 1 + (rand () & 8) * 0.05),
|
|
|
|
(66 + rand () % 6), 255);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 512; i++) {
|
|
|
|
particle_new_random (pt_blob2, part_tex_dot, org, 16, 2, 256,
|
|
|
|
(cl.time + 1 + (rand () & 8) * 0.05),
|
|
|
|
(150 + rand () % 6), 255);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static void
|
|
|
|
R_RunSparkEffect (vec3_t org, int count, int ofuzz)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
particle_new (pt_smokecloud, part_tex_smoke[rand () & 7], org, ofuzz / 8,
|
|
|
|
vec3_origin, cl.time + 99, 12 + (rand () & 3), 96);
|
2000-10-28 08:02:08 +00:00
|
|
|
while (count--)
|
|
|
|
particle_new_random (pt_fallfadespark, part_tex_dot, org, ofuzz, 1, 96,
|
2000-12-08 06:51:37 +00:00
|
|
|
cl.time + 5, ramp[rand () % 6], lhrandom (0, 255));
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static void
|
|
|
|
R_RunGunshotEffect (vec3_t org, int count)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int scale;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (count > 6)
|
|
|
|
scale = 3;
|
|
|
|
else
|
|
|
|
scale = 2;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
R_RunSparkEffect (org, count * 10, 8 * scale);
|
2000-10-28 08:02:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static void
|
|
|
|
R_BloodPuff (vec3_t org, int count)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
particle_new (pt_bloodcloud, part_tex_smoke[rand () & 7], org, 12,
|
|
|
|
vec3_origin, cl.time + 99, 68 + (rand () & 3), 128);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_RunPuffEffect
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_RunPuffEffect (vec3_t org, byte type, byte count)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TE_GUNSHOT:
|
|
|
|
R_RunGunshotEffect (org, count);
|
|
|
|
break;
|
|
|
|
case TE_BLOOD:
|
|
|
|
R_BloodPuff (org, count);
|
|
|
|
break;
|
|
|
|
case TE_LIGHTNINGBLOOD:
|
2000-12-08 06:51:37 +00:00
|
|
|
R_BloodPuff (org, 5 + (rand () & 1));
|
2000-10-28 08:02:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_RunParticleEffect
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_RunParticleEffect (vec3_t org, int color, int count)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j, scale;
|
|
|
|
vec3_t porg;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (count > 130)
|
|
|
|
scale = 3;
|
|
|
|
else if (count > 20)
|
|
|
|
scale = 2;
|
|
|
|
else
|
|
|
|
scale = 1;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
porg[j] = org[j] + scale * ((rand () & 15) - 8);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
particle_new (pt_grav, part_tex_dot, porg, 2, vec3_origin,
|
|
|
|
(cl.time + 0.1 * (rand () % 5)),
|
|
|
|
(color & ~7) + (rand () & 7), 255);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_RunSpikeEffect (vec3_t org, byte type)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case TE_SPIKE:
|
2000-12-08 06:51:37 +00:00
|
|
|
R_RunSparkEffect (org, 5, 8);
|
2000-10-28 08:02:08 +00:00
|
|
|
break;
|
|
|
|
case TE_SUPERSPIKE:
|
2000-12-08 06:51:37 +00:00
|
|
|
R_RunSparkEffect (org, 10, 8);
|
2000-10-28 08:02:08 +00:00
|
|
|
break;
|
|
|
|
case TE_KNIGHTSPIKE:
|
2000-12-08 06:51:37 +00:00
|
|
|
R_RunSparkEffect (org, 10, 8);
|
2000-10-28 08:02:08 +00:00
|
|
|
break;
|
|
|
|
case TE_WIZSPIKE:
|
2000-12-08 06:51:37 +00:00
|
|
|
R_RunSparkEffect (org, 15, 16);
|
2000-10-28 08:02:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_LavaSplash
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_LavaSplash (vec3_t org)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j;
|
|
|
|
float vel;
|
|
|
|
vec3_t dir, porg, pvel;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = -16; i < 16; i++) {
|
|
|
|
for (j = -16; j < 16; j++) {
|
|
|
|
dir[0] = j * 8 + (rand () & 7);
|
|
|
|
dir[1] = i * 8 + (rand () & 7);
|
2000-10-28 08:02:08 +00:00
|
|
|
dir[2] = 256;
|
|
|
|
|
|
|
|
porg[0] = org[0] + dir[0];
|
|
|
|
porg[1] = org[1] + dir[1];
|
2000-12-08 06:51:37 +00:00
|
|
|
porg[2] = org[2] + (rand () & 63);
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
VectorNormalize (dir);
|
|
|
|
vel = 50 + (rand () & 63);
|
2000-10-28 08:02:08 +00:00
|
|
|
VectorScale (dir, vel, pvel);
|
2000-12-08 06:51:37 +00:00
|
|
|
particle_new (pt_grav, part_tex_dot, porg, 2, pvel,
|
|
|
|
(cl.time + 2 + (rand () & 31) * 0.02),
|
|
|
|
(224 + (rand () & 7)), 255);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_TeleportSplash
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_TeleportSplash (vec3_t org)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j, k;
|
|
|
|
float vel;
|
|
|
|
vec3_t dir, porg, pvel;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = -16; i < 16; i += 4)
|
|
|
|
for (j = -16; j < 16; j += 4)
|
|
|
|
for (k = -24; k < 32; k += 4) {
|
|
|
|
dir[0] = j * 8;
|
|
|
|
dir[1] = i * 8;
|
|
|
|
dir[2] = k * 8;
|
|
|
|
|
|
|
|
porg[0] = org[0] + i + (rand () & 3);
|
|
|
|
porg[1] = org[1] + j + (rand () & 3);
|
|
|
|
porg[2] = org[2] + k + (rand () & 3);
|
|
|
|
|
|
|
|
VectorNormalize (dir);
|
|
|
|
vel = 50 + (rand () & 63);
|
2000-10-28 08:02:08 +00:00
|
|
|
VectorScale (dir, vel, pvel);
|
2000-12-08 06:51:37 +00:00
|
|
|
particle_new (pt_grav, part_tex_dot, porg, 2, pvel,
|
|
|
|
(cl.time + 0.2 + (rand () & 7) * 0.02),
|
|
|
|
(7 + (rand () & 7)), 255);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2000-12-20 06:18:55 +00:00
|
|
|
R_RocketTrail (int type, entity_t *ent)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
vec3_t vec;
|
|
|
|
float len;
|
|
|
|
int j, ptex;
|
|
|
|
ptype_t ptype;
|
|
|
|
vec3_t porg, pvel;
|
|
|
|
float pdie, pscale;
|
|
|
|
byte palpha, pcolor;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
if (type == 0)
|
2000-12-20 06:18:55 +00:00
|
|
|
R_AddFire (ent->old_origin, ent->origin, ent);
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
if (!gl_particles->int_val)
|
|
|
|
return;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-12-20 06:18:55 +00:00
|
|
|
VectorSubtract (ent->origin, ent->old_origin, vec);
|
2000-10-28 08:02:08 +00:00
|
|
|
len = VectorNormalize (vec);
|
2000-12-08 06:51:37 +00:00
|
|
|
while (len > 0) {
|
2000-10-28 08:02:08 +00:00
|
|
|
VectorCopy (vec3_origin, pvel);
|
|
|
|
pdie = cl.time + 2;
|
|
|
|
ptype = pt_static;
|
|
|
|
ptex = part_tex_dot;
|
|
|
|
pcolor = 0;
|
|
|
|
pscale = 1;
|
|
|
|
palpha = 255;
|
|
|
|
|
|
|
|
switch (type) {
|
2000-12-08 06:51:37 +00:00
|
|
|
case 0: // rocket trail
|
|
|
|
pcolor = (rand () & 3) + 12;
|
2000-10-28 08:02:08 +00:00
|
|
|
goto common_rocket_gren_trail;
|
2000-12-08 06:51:37 +00:00
|
|
|
case 1: // grenade trail
|
|
|
|
pcolor = (rand () & 3) + 3;
|
2000-10-28 08:02:08 +00:00
|
|
|
goto common_rocket_gren_trail;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
common_rocket_gren_trail:
|
2000-10-28 08:02:08 +00:00
|
|
|
len -= 4;
|
2000-12-08 06:51:37 +00:00
|
|
|
ptex = part_tex_smoke[rand () & 7];
|
|
|
|
pscale = lhrandom (8, 12);
|
|
|
|
palpha = 48 + (rand () & 31);
|
2000-10-28 08:02:08 +00:00
|
|
|
ptype = pt_smoke;
|
|
|
|
pdie = cl.time + 1;
|
2000-12-20 06:18:55 +00:00
|
|
|
VectorCopy (ent->old_origin, porg);
|
2000-10-28 08:02:08 +00:00
|
|
|
break;
|
2000-12-08 06:51:37 +00:00
|
|
|
case 2: // blood
|
|
|
|
case 4: // slight blood
|
2000-10-28 08:02:08 +00:00
|
|
|
len -= 5;
|
|
|
|
ptex = part_tex_dot;
|
|
|
|
pscale = 1;
|
2000-12-08 06:51:37 +00:00
|
|
|
pcolor = 68 + (rand () & 3);
|
2000-10-28 08:02:08 +00:00
|
|
|
pdie = cl.time + 2;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
pvel[j] = (rand () & 15) - 8;
|
2000-12-20 06:18:55 +00:00
|
|
|
porg[j] = ent->old_origin[j] + ((rand () % 3) - 2);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
ptype = pt_grav;
|
|
|
|
palpha = 255;
|
|
|
|
break;
|
2000-12-08 06:51:37 +00:00
|
|
|
case 6: // voor trail
|
2000-10-28 08:02:08 +00:00
|
|
|
len -= 3;
|
2000-12-08 06:51:37 +00:00
|
|
|
pcolor = 9 * 16 + 8 + (rand () & 3);
|
2000-10-28 08:02:08 +00:00
|
|
|
ptype = pt_static;
|
2000-12-08 06:51:37 +00:00
|
|
|
pscale = lhrandom (1, 2);
|
2000-10-28 08:02:08 +00:00
|
|
|
pdie = cl.time + 0.3;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
2000-12-20 06:18:55 +00:00
|
|
|
porg[j] = ent->old_origin[j] + ((rand () & 15) - 8);
|
2000-10-28 08:02:08 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2000-12-08 06:51:37 +00:00
|
|
|
case 5: // tracer
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
static int tracercount;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
len -= 3;
|
|
|
|
pdie = cl.time + 0.5;
|
|
|
|
ptype = pt_static;
|
2000-12-08 06:51:37 +00:00
|
|
|
pscale = lhrandom (2, 4);
|
2000-10-28 08:02:08 +00:00
|
|
|
if (type == 3)
|
2000-12-08 06:51:37 +00:00
|
|
|
pcolor = 52 + ((tracercount & 4) << 1);
|
2000-10-28 08:02:08 +00:00
|
|
|
else
|
2000-12-08 06:51:37 +00:00
|
|
|
pcolor = 230 + ((tracercount & 4) << 1);
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
tracercount++;
|
|
|
|
|
2000-12-20 06:18:55 +00:00
|
|
|
VectorCopy (ent->old_origin, porg);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (tracercount & 1) {
|
|
|
|
pvel[0] = 30 * vec[1];
|
|
|
|
pvel[1] = 30 * -vec[0];
|
|
|
|
} else {
|
|
|
|
pvel[0] = 30 * -vec[1];
|
|
|
|
pvel[1] = 30 * vec[0];
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-20 06:18:55 +00:00
|
|
|
VectorAdd (ent->old_origin, vec, ent->old_origin);
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
particle_new (ptype, ptex, porg, pscale, pvel, pdie, pcolor, palpha);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_DrawParticles
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_DrawParticles (void)
|
2000-10-28 08:02:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
byte i;
|
|
|
|
float grav, fast_grav, dvel;
|
|
|
|
float minparticledist;
|
|
|
|
unsigned char *at;
|
|
|
|
byte alpha;
|
|
|
|
vec3_t up, right;
|
|
|
|
float scale, scale2;
|
|
|
|
particle_t *part;
|
|
|
|
int activeparticles, maxparticle, j, k;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
// LordHavoc: particles should not affect zbuffer
|
2000-12-08 06:51:37 +00:00
|
|
|
glDepthMask (GL_FALSE);
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
VectorScale (vup, 1.5, up);
|
|
|
|
VectorScale (vright, 1.5, right);
|
|
|
|
|
|
|
|
grav = (fast_grav = host_frametime * 800) * 0.05;
|
2000-12-08 06:51:37 +00:00
|
|
|
dvel = 4 * host_frametime;
|
|
|
|
|
|
|
|
minparticledist = DotProduct (r_refdef.vieworg, vpn) + 32.0f;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
activeparticles = 0;
|
|
|
|
maxparticle = -1;
|
|
|
|
j = 0;
|
|
|
|
|
|
|
|
for (k = 0, part = particles; k < numparticles; k++, part++) {
|
|
|
|
if (part->die <= cl.time) {
|
|
|
|
freeparticles[j++] = part;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
maxparticle = k;
|
|
|
|
activeparticles++;
|
|
|
|
|
2000-10-29 09:39:38 +00:00
|
|
|
// Don't render particles too close to us.
|
|
|
|
// Note, we must still do physics and such on them.
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!(DotProduct (part->org, vpn) < minparticledist)) {
|
|
|
|
at = (byte *) & d_8to24table[(byte) part->color];
|
2000-10-29 09:39:38 +00:00
|
|
|
alpha = part->alpha;
|
|
|
|
|
|
|
|
if (lighthalf)
|
2000-12-08 06:51:37 +00:00
|
|
|
glColor4ub ((byte) ((int) at[0] >> 1),
|
|
|
|
(byte) ((int) at[1] >> 1),
|
|
|
|
(byte) ((int) at[2] >> 1), alpha);
|
2000-10-29 09:39:38 +00:00
|
|
|
else
|
2000-12-08 06:51:37 +00:00
|
|
|
glColor4ub (at[0], at[1], at[2], alpha);
|
2000-10-29 09:39:38 +00:00
|
|
|
|
|
|
|
scale = part->scale * 0.75;
|
|
|
|
scale2 = part->scale * -0.75;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
glBindTexture (GL_TEXTURE_2D, part->tex);
|
2000-10-29 09:39:38 +00:00
|
|
|
glBegin (GL_QUADS);
|
2000-12-08 06:51:37 +00:00
|
|
|
glTexCoord2f (0, 1);
|
|
|
|
glVertex3f ((part->org[0] + up[0] * scale + right[0] * scale),
|
|
|
|
(part->org[1] + up[1] * scale + right[1] * scale),
|
|
|
|
(part->org[2] + up[2] * scale + right[2] * scale));
|
|
|
|
|
|
|
|
glTexCoord2f (0, 0);
|
|
|
|
glVertex3f ((part->org[0] + up[0] * scale2 + right[0] * scale),
|
|
|
|
(part->org[1] + up[1] * scale2 + right[1] * scale),
|
|
|
|
(part->org[2] + up[2] * scale2 + right[2] * scale));
|
|
|
|
|
|
|
|
glTexCoord2f (1, 0);
|
|
|
|
glVertex3f ((part->org[0] + up[0] * scale2 + right[0] * scale2),
|
|
|
|
(part->org[1] + up[1] * scale2 + right[1] * scale2),
|
|
|
|
(part->org[2] + up[2] * scale2 + right[2] * scale2));
|
|
|
|
|
|
|
|
glTexCoord2f (1, 1);
|
|
|
|
glVertex3f ((part->org[0] + up[0] * scale + right[0] * scale2),
|
|
|
|
(part->org[1] + up[1] * scale + right[1] * scale2),
|
|
|
|
(part->org[2] + up[2] * scale + right[2] * scale2));
|
|
|
|
|
|
|
|
glEnd ();
|
2000-10-29 09:39:38 +00:00
|
|
|
}
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
part->org[i] += part->vel[i] * host_frametime;
|
|
|
|
|
|
|
|
|
2000-10-28 08:02:08 +00:00
|
|
|
#define alpha_die(p) if (p->alpha < 1) part->die = -1;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
switch (part->type) {
|
|
|
|
case pt_static:
|
|
|
|
break;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
case pt_blob:
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
part->vel[i] += part->vel[i] * dvel;
|
|
|
|
part->vel[2] -= grav;
|
|
|
|
break;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
case pt_blob2:
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
part->vel[i] -= part->vel[i] * dvel;
|
|
|
|
part->vel[2] -= grav;
|
|
|
|
break;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
case pt_grav:
|
|
|
|
part->vel[2] -= grav;
|
|
|
|
break;
|
2000-10-28 08:02:08 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
case pt_smoke:
|
|
|
|
part->scale += host_frametime * 6;
|
|
|
|
part->alpha -= host_frametime * 128;
|
|
|
|
alpha_die (part);
|
|
|
|
break;
|
|
|
|
case pt_smokecloud:
|
|
|
|
part->scale += host_frametime * 60;
|
|
|
|
part->alpha -= host_frametime * 128;
|
|
|
|
alpha_die (part);
|
|
|
|
break;
|
|
|
|
case pt_bloodcloud:
|
|
|
|
/*
|
|
|
|
if (Mod_PointInLeaf(part->org, cl.worldmodel)->contents !=
|
|
|
|
CONTENTS_EMPTY) { part->die = -1; break; } */
|
|
|
|
part->scale += host_frametime * 4;
|
|
|
|
part->alpha -= host_frametime * 64;
|
|
|
|
part->vel[2] -= grav;
|
|
|
|
alpha_die (part);
|
|
|
|
break;
|
|
|
|
case pt_fadespark:
|
|
|
|
part->alpha -= host_frametime * 256;
|
|
|
|
part->vel[2] -= grav;
|
|
|
|
if (part->alpha < 1)
|
|
|
|
part->die = -1;
|
|
|
|
break;
|
|
|
|
case pt_fadespark2:
|
|
|
|
part->alpha -= host_frametime * 512;
|
|
|
|
part->vel[2] -= grav;
|
|
|
|
alpha_die (part);
|
|
|
|
break;
|
|
|
|
case pt_fallfadespark:
|
|
|
|
part->alpha -= host_frametime * 256;
|
|
|
|
part->vel[2] -= fast_grav;
|
|
|
|
if (part->alpha < 1)
|
|
|
|
part->die = -1;
|
2000-10-28 08:02:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
k = 0;
|
|
|
|
while (maxparticle >= activeparticles) {
|
|
|
|
*freeparticles[k++] = particles[maxparticle--];
|
2000-12-08 06:51:37 +00:00
|
|
|
while (maxparticle >= activeparticles
|
|
|
|
&& particles[maxparticle].die < cl.time) maxparticle--;
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|
|
|
|
numparticles = activeparticles;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
glColor3ubv (lighthalf_v);
|
|
|
|
glDepthMask (GL_TRUE);
|
2000-10-28 08:02:08 +00:00
|
|
|
}
|