The big particle rework!

Lots of changes, more then I can cover quickly.
Things now look, different, and probally much better!

Note, SOFTWARE RENDERING IS BROKEN with this commit!
This commit is contained in:
Zephaniah E. Hull 2000-10-28 08:02:08 +00:00
parent 111274c12e
commit 5d07b61d7a
16 changed files with 1249 additions and 965 deletions

36
include/fractalnoise.h Normal file
View file

@ -0,0 +1,36 @@
/*
fractalnoise.h
LordHavocs fractial noise generator.
Copyright (C) 2000 Forest `LordHavoc` Hale.
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$
*/
#ifndef _FRACTALNOISE_H
#define _FRACTALNOISE_H
#include <stdlib.h>
void fractalnoise(unsigned char *noise, int size);
#endif // _FRACTALNOISE_H

View file

@ -180,7 +180,6 @@ extern texture_t *r_notexture_mip;
extern int d_lightstylevalue[256]; // 8.8 fraction of base light value
extern qboolean envmap;
extern int particletexture;
extern int netgraphtexture; // netgraph texture
extern int playertextures;

View file

@ -61,6 +61,8 @@ extern int nanmask;
((a[1] - b[1]) * (a[1] - b[1])) + \
((a[2] - b[2]) * (a[2] - b[2])))
#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN))
// up / down
#define PITCH 0
// left / right

48
include/r_dynamic.h Normal file
View file

@ -0,0 +1,48 @@
/*
render.h
public interface to refresh functions
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$
*/
#ifndef _R_DYNAMIC_H
#define _R_DYNAMIC_H
#include "mathlib.h"
void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent);
void R_RunParticleEffect (vec3_t org, int color, int count);
void R_RunPuffEffect (vec3_t org, int type, int count);
void R_RunSpikeEffect (vec3_t org, byte type);
void R_BlobExplosion (vec3_t org);
void R_ParticleExplosion (vec3_t org);
void R_LavaSplash (vec3_t org);
void R_TeleportSplash (vec3_t org);
void R_InitParticles (void);
void R_ClearParticles (void);
void R_DrawParticles (void);
#endif // _R_DYNAMIC_H

View file

@ -137,21 +137,8 @@ void R_RemoveEfrags (entity_t *ent);
void R_NewMap (void);
void R_ParseParticleEffect (void);
void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count);
void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent);
void R_EntityParticles (entity_t *ent);
void R_BlobExplosion (vec3_t org);
void R_ParticleExplosion (vec3_t org);
void R_LavaSplash (vec3_t org);
void R_TeleportSplash (vec3_t org);
// LordHavoc: relative bmodel lighting
void R_PushDlights (vec3_t entorigin);
void R_InitParticles (void);
void R_ClearParticles (void);
void R_DrawParticles (void);
void R_DrawWaterSurfaces (void);
//

View file

@ -220,9 +220,10 @@ qf_client_x11_DEPENDENCIES=libqfsys_cl.a libqfsnd.a libqfcd.a libqfjs.a
#
# ... Common stuff
#
ogl_SOURCES= gl_draw.c gl_mesh.c gl_ngraph.c gl_part.c \
gl_refrag.c gl_rlight.c gl_rmain.c gl_rmisc.c gl_rsurf.c \
gl_screen.c gl_trans.c gl_view.c gl_warp.c gl_model_alias.c \
ogl_SOURCES= fractalnoise.c gl_draw.c gl_dyn_fires.c gl_dyn_part.c \
gl_dyn_textures.c gl_mesh.c gl_ngraph.c gl_refrag.c \
gl_rlight.c gl_rmain.c gl_rmisc.c gl_rsurf.c gl_screen.c \
gl_trans.c gl_view.c gl_warp.c gl_model_alias.c \
gl_model_brush.c gl_model_fullbright.c gl_model_sprite.c
#

View file

@ -44,6 +44,7 @@
#include "pmove.h"
#include "view.h"
#include "teamplay.h"
#include "r_dynamic.h"
extern cvar_t *cl_predict_players;
extern cvar_t *cl_predict_players2;

View file

@ -37,6 +37,7 @@
#include "client.h"
#include "msg.h"
#include "console.h"
#include "r_dynamic.h"
#include <math.h>
#include <stdlib.h>
@ -185,12 +186,12 @@ CL_ParseTEnt
*/
void CL_ParseTEnt (void)
{
int type;
byte type;
vec3_t pos;
dlight_t *dl;
int rnd;
explosion_t *ex;
int cnt;
int cnt = -1;
type = MSG_ReadByte ();
switch (type)
@ -199,7 +200,8 @@ void CL_ParseTEnt (void)
pos[0] = MSG_ReadCoord ();
pos[1] = MSG_ReadCoord ();
pos[2] = MSG_ReadCoord ();
R_RunParticleEffect (pos, vec3_origin, 20, 30);
R_RunSpikeEffect (pos, type);
//R_RunParticleEffect (pos, 20, 30);
S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
break;
@ -207,7 +209,8 @@ void CL_ParseTEnt (void)
pos[0] = MSG_ReadCoord ();
pos[1] = MSG_ReadCoord ();
pos[2] = MSG_ReadCoord ();
R_RunParticleEffect (pos, vec3_origin, 226, 20);
R_RunSpikeEffect (pos, type);
//R_RunParticleEffect (pos, 226, 20);
S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
break;
@ -215,7 +218,8 @@ void CL_ParseTEnt (void)
pos[0] = MSG_ReadCoord ();
pos[1] = MSG_ReadCoord ();
pos[2] = MSG_ReadCoord ();
R_RunParticleEffect (pos, vec3_origin, 0, 10);
R_RunSpikeEffect (pos, type);
//R_RunParticleEffect (pos, 0, 10);
if ( rand() % 5 )
S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
@ -234,7 +238,8 @@ void CL_ParseTEnt (void)
pos[0] = MSG_ReadCoord ();
pos[1] = MSG_ReadCoord ();
pos[2] = MSG_ReadCoord ();
R_RunParticleEffect (pos, vec3_origin, 0, 20);
R_RunSpikeEffect (pos, type);
//R_RunParticleEffect (pos, 0, 20);
if ( rand() % 5 )
S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
@ -313,28 +318,16 @@ void CL_ParseTEnt (void)
break;
case TE_GUNSHOT: // bullet hitting wall
cnt = MSG_ReadByte ();
pos[0] = MSG_ReadCoord ();
pos[1] = MSG_ReadCoord ();
pos[2] = MSG_ReadCoord ();
R_RunParticleEffect (pos, vec3_origin, 0, 20*cnt);
break;
case TE_BLOOD: // bullets hitting body
cnt = MSG_ReadByte ();
pos[0] = MSG_ReadCoord ();
pos[1] = MSG_ReadCoord ();
pos[2] = MSG_ReadCoord ();
R_RunParticleEffect (pos, vec3_origin, 73, 20*cnt);
break;
case TE_LIGHTNINGBLOOD: // lightning hitting body
pos[0] = MSG_ReadCoord ();
pos[1] = MSG_ReadCoord ();
pos[2] = MSG_ReadCoord ();
R_RunParticleEffect (pos, vec3_origin, 225, 50);
R_RunPuffEffect (pos, type, cnt);
//R_RunParticleEffect (pos, 0, 20*cnt);
break;
default:
// Sys_Error ("CL_ParseTEnt: bad type");
Host_EndGame ("CL_ParseTEnt: bad type");

76
source/fractalnoise.c Normal file
View file

@ -0,0 +1,76 @@
/*
fractalnoise.c
LordHavocs fractial noise generator.
Copyright (C) 2000 Forest `LordHavoc` Hale.
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$
*/
#include <stdlib.h>
void fractalnoise(unsigned char *noise, int size)
{
int x, y, g, g2, amplitude, min, max, size1 = size - 1;
int *noisebuf;
#define n(x,y) noisebuf[((y)&size1)*size+((x)&size1)]
noisebuf = calloc(size*size, sizeof(int));
amplitude = 32767;
g2 = size;
n(0,0) = 0;
for (;(g = g2 >> 1) >= 1;g2 >>= 1)
{
// subdivide, diamond-square algorythm (really this has little to do with squares)
// diamond
for (y = 0;y < size;y += g2)
for (x = 0;x < size;x += g2)
n(x+g,y+g) = (n(x,y) + n(x+g2,y) + n(x,y+g2) + n(x+g2,y+g2)) >> 2;
// square
for (y = 0;y < size;y += g2)
for (x = 0;x < size;x += g2)
{
n(x+g,y) = (n(x,y) + n(x+g2,y) + n(x+g,y-g) + n(x+g,y+g)) >> 2;
n(x,y+g) = (n(x,y) + n(x,y+g2) + n(x-g,y+g) + n(x+g,y+g)) >> 2;
}
// brownian motion theory
amplitude >>= 1;
for (y = 0;y < size;y += g)
for (x = 0;x < size;x += g)
n(x,y) += (rand()&amplitude);
}
// find range of noise values
min = max = 0;
for (y = 0;y < size;y++)
for (x = 0;x < size;x++)
{
if (n(x,y) < min) min = n(x,y);
if (n(x,y) > max) max = n(x,y);
}
max -= min;
// normalize noise and copy to output
for (y = 0;y < size;y++)
for (x = 0;x < size;x++)
*noise++ = (n(x,y) - min) * 255 / max;
free(noisebuf);
#undef n
}

236
source/gl_dyn_fires.c Normal file
View file

@ -0,0 +1,236 @@
/*
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmd.h"
#include "console.h"
#include "glquake.h"
#include <stdlib.h>
#define MAX_FIRES 128 // rocket flames
static fire_t r_fires[MAX_FIRES];
extern cvar_t *gl_fires;
/*
R_AddFire
Nifty ball of fire GL effect. Kinda a meshing of the dlight and
particle engine code.
*/
float r_firecolor[3] = {0.9, 0.4, 0};
void
R_AddFire (vec3_t start, vec3_t end, entity_t *ent)
{
float len;
fire_t *f;
dlight_t *dl;
vec3_t vec;
int key;
if (!gl_fires->int_val)
return;
VectorSubtract (end, start, vec);
len = VectorNormalize (vec);
key = ent-cl_visedicts+1;
if (len)
{
f = R_AllocFire (key);
VectorCopy (end, f->origin);
VectorCopy (start, f->owner);
f->size = 20;
f->die = cl.time + 0.5;
f->decay = -1;
f->color=r_firecolor;
dl = CL_AllocDlight (key);
VectorCopy (end, dl->origin);
dl->radius = 200;
dl->die = cl.time + 0.5;
dl->color=r_firecolor;
}
}
/*
R_AllocFire
Clears out and returns a new fireball
*/
fire_t *
R_AllocFire (int key)
{
int i;
fire_t *f;
if (key) // first try to find/reuse a keyed spot
{
f = r_fires;
for (i = 0; i < MAX_FIRES; i++, f++)
if (f->key == key)
{
memset (f, 0, sizeof(*f));
f->key = key;
f->color = f->_color;
return f;
}
}
f = r_fires; // no match, look for a free spot
for (i = 0; i < MAX_FIRES; i++, f++)
{
if (f->die < cl.time)
{
memset (f, 0, sizeof(*f));
f->key = key;
f->color = f->_color;
return f;
}
}
f = &r_fires[0];
memset (f, 0, sizeof(*f));
f->key = key;
f->color = f->_color;
return f;
}
/*
R_DrawFire
draws one fireball - probably never need to call this directly
*/
void
R_DrawFire (fire_t *f)
{
int i, j;
vec3_t vec,vec2;
float radius;
float *b_sin, *b_cos;
b_sin = bubble_sintable;
b_cos = bubble_costable;
radius = f->size + 0.35;
// figure out if we're inside the area of effect
VectorSubtract (f->origin, r_origin, vec);
if (Length (vec) < radius)
{
AddLightBlend (1, 0.5, 0, f->size * 0.0003); // we are
return;
}
// we're not - draw it
glBegin (GL_TRIANGLE_FAN);
if (lighthalf)
glColor3f(f->color[0]*0.5,f->color[1]*0.5,f->color[2]*0.5);
else
glColor3fv(f->color);
for (i=0 ; i<3 ; i++)
vec[i] = f->origin[i] - vpn[i] * radius;
glVertex3fv (vec);
glColor3f (0.0, 0.0, 0.0);
// don't panic, this just draws a bubble...
for (i=16 ; i>=0 ; i--)
{
for (j=0 ; j<3 ; j++) {
vec[j] = f->origin[j] + (*b_cos * vright[j]
+ vup[j]*(*b_sin)) * radius;
vec2[j] = f->owner[j] + (*b_cos * vright[j]
+ vup[j]*(*b_sin)) * radius;
}
glVertex3fv (vec);
glVertex3fv (vec2);
b_sin+=2;
b_cos+=2;
}
glEnd ();
glColor3ubv(lighthalf_v);
}
/*
R_UpdateFires
Draws each fireball in sequence
*/
void
R_UpdateFires (void)
{
int i;
fire_t *f;
if (!gl_fires->int_val)
return;
glDepthMask(GL_FALSE);
glDisable (GL_TEXTURE_2D);
glBlendFunc (GL_ONE, GL_ONE);
f = r_fires;
for (i = 0; i < MAX_FIRES; i++, f++)
{
if (f->die < cl.time || !f->size)
continue;
f->size += f->decay;
R_DrawFire (f);
}
glEnable (GL_TEXTURE_2D);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(GL_TRUE);
}
void
R_FireColor_f (void)
{
int i;
if (Cmd_Argc() == 1) {
Con_Printf ("r_firecolor %g %g %g\n",
r_firecolor[0],
r_firecolor[1],
r_firecolor[2]);
return;
}
if (Cmd_Argc() == 5 || Cmd_Argc() == 6) {
Con_Printf ("Warning: obsolete 4th and 5th parameters to r_firecolor ignored\n");
} else if (Cmd_Argc() !=4) {
Con_Printf ("Usage r_firecolor R G B\n");
return;
}
for (i=0; i<4; i++) {
r_firecolor[i]=atof(Cmd_Argv(i+1));
}
}

687
source/gl_dyn_part.c Normal file
View file

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

118
source/gl_dyn_textures.c Normal file
View file

@ -0,0 +1,118 @@
/*
gl_dyn_textures.c
Dynamic texture generation.
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
# include <config.h>
#endif
#include "glquake.h"
#include "fractalnoise.h"
#include <stdlib.h>
static void GDT_InitDotParticleTexture (void);
static void GDT_InitSmokeParticleTexture (void);
int part_tex_smoke[8];
int part_tex_dot;
void GDT_Init (void)
{
GDT_InitDotParticleTexture();
GDT_InitSmokeParticleTexture();
}
byte dottexture[4][4] =
{
{0,1,1,0},
{1,1,1,1},
{1,1,1,1},
{0,1,1,0},
};
static void GDT_InitDotParticleTexture (void)
{
int x, y;
byte data[4][4][4];
//
// particle texture
//
part_tex_dot = texture_extension_number++;
glBindTexture (GL_TEXTURE_2D, part_tex_dot);
for (x=0 ; x<4 ; x++)
{
for (y=0 ; y<4 ; y++)
{
data[y][x][0] = 244;
data[y][x][1] = 244;
data[y][x][2] = 244;
data[y][x][3] = dottexture[x][y]*244;
}
}
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
static void GDT_InitSmokeParticleTexture (void)
{
int i, x, y, d;
float dx, dy;
byte data[32][32][4], noise1[32][32], noise2[32][32];
for (i = 0;i < 8;i++) {
fractalnoise(&noise1[0][0], 32);
fractalnoise(&noise2[0][0], 32);
for (y = 0;y < 32;y++)
for (x = 0;x < 32;x++) {
data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
dx = x - 16;
dy = y - 16;
d = noise2[y][x] * 4 - 512;
if (d > 0) {
if (d > 255)
d = 255;
d = (d * (255 - (int) (dx*dx+dy*dy))) >> 8;
if (d < 0) d = 0;
if (d > 255) d = 255;
data[y][x][3] = (byte) d;
}
else
data[y][x][3] = 0;
}
part_tex_smoke[i] = texture_extension_number++;
glBindTexture(GL_TEXTURE_2D, part_tex_smoke[i]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
}
}

View file

@ -1,854 +0,0 @@
/*
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "qargs.h"
#include "bothdefs.h" // needed by: common.h, net.h, client.h
#include "d_iface.h"
#include "bspfile.h" // needed by: glquake.h
#include "vid.h"
#include "sys.h"
#include "mathlib.h" // needed by: protocol.h, render.h, client.h,
// modelgen.h, glmodel.h
#include "wad.h"
#include "draw.h"
#include "cvar.h"
#include "menu.h"
#include "net.h" // needed by: client.h
#include "protocol.h" // needed by: client.h
#include "cmd.h"
#include "sbar.h"
#include "render.h" // needed by: client.h, gl_model.h, glquake.h
#include "client.h" // need cls in this file
#include "model.h" // needed by: glquake.h
#include "console.h"
#include "glquake.h"
#include "quakefs.h"
#include "quakedef.h"
#include <stdlib.h>
#define MAX_PARTICLES 2048 // default max # of particles at one
// time
#define MAX_FIRES 128 // rocket flames
#define ABSOLUTE_MIN_PARTICLES 512 // no fewer than this no matter what's
// on the command line
int ramp1[8] = {0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61};
int ramp2[8] = {0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66};
int ramp3[8] = {0x6d, 0x6b, 6, 5, 4, 3};
particle_t *active_particles, *free_particles;
particle_t *particles;
int r_numparticles;
vec3_t r_pright, r_pup, r_ppn;
fire_t r_fires[MAX_FIRES];
extern cvar_t *gl_fires;
extern qboolean lighthalf;
/*
===============
R_InitParticles
===============
*/
void R_InitParticles (void)
{
int i;
i = COM_CheckParm ("-particles");
if (i)
{
r_numparticles = (int)(atoi(com_argv[i+1]));
if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
r_numparticles = ABSOLUTE_MIN_PARTICLES;
}
else
{
r_numparticles = MAX_PARTICLES;
}
particles = (particle_t *)
Hunk_AllocName (r_numparticles * sizeof(particle_t), "particles");
}
/*
===============
R_ClearParticles
===============
*/
void R_ClearParticles (void)
{
int i;
free_particles = &particles[0];
active_particles = NULL;
for (i=0 ;i<r_numparticles ; i++)
particles[i].next = &particles[i+1];
particles[r_numparticles-1].next = NULL;
}
void R_ReadPointFile_f (void)
{
QFile *f;
vec3_t org;
int r;
int c;
particle_t *p;
char name[MAX_OSPATH];
// FIXME sprintf (name,"maps/%s.pts", sv.name);
COM_FOpenFile (name, &f);
if (!f)
{
Con_Printf ("couldn't open %s\n", name);
return;
}
Con_Printf ("Reading %s...\n", name);
c = 0;
for ( ;; )
{
char buf[64];
Qgets (f, buf, sizeof(buf));
r = sscanf (buf,"%f %f %f\n", &org[0], &org[1], &org[2]);
if (r != 3)
break;
c++;
if (!free_particles)
{
Con_Printf ("Not enough free particles\n");
break;
}
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
p->die = 99999;
p->color = (-c)&15;
p->type = pt_static;
VectorCopy (vec3_origin, p->vel);
VectorCopy (org, p->org);
}
Qclose (f);
Con_Printf ("%i points read\n", c);
}
/*
===============
R_ParticleExplosion
===============
*/
void R_ParticleExplosion (vec3_t org)
{
int i, j;
particle_t *p;
if (!gl_particles->int_val)
return;
for (i=0 ; i<1024 ; i++)
{
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
p->die = cl.time + 5;
p->color = ramp1[0];
p->ramp = rand()&3;
if (i & 1)
{
p->type = pt_explode;
for (j=0 ; j<3 ; j++)
{
p->org[j] = org[j] + ((rand()%32)-16);
p->vel[j] = (rand()%512)-256;
}
}
else
{
p->type = pt_explode2;
for (j=0 ; j<3 ; j++)
{
p->org[j] = org[j] + ((rand()%32)-16);
p->vel[j] = (rand()%512)-256;
}
}
}
}
/*
===============
R_BlobExplosion
===============
*/
void R_BlobExplosion (vec3_t org)
{
int i, j;
particle_t *p;
if (!gl_particles->int_val)
return;
for (i=0 ; i<1024 ; i++)
{
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
p->die = cl.time + 1 + (rand()&8)*0.05;
if (i & 1)
{
p->type = pt_blob;
p->color = 66 + rand()%6;
for (j=0 ; j<3 ; j++)
{
p->org[j] = org[j] + ((rand()%32)-16);
p->vel[j] = (rand()%512)-256;
}
}
else
{
p->type = pt_blob2;
p->color = 150 + rand()%6;
for (j=0 ; j<3 ; j++)
{
p->org[j] = org[j] + ((rand()%32)-16);
p->vel[j] = (rand()%512)-256;
}
}
}
}
/*
===============
R_RunParticleEffect
===============
*/
void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
{
int i, j;
particle_t *p;
int scale;
if (!gl_particles->int_val)
return;
if (count > 130)
scale = 3;
else if (count > 20)
scale = 2;
else
scale = 1;
for (i=0 ; i<count ; i++)
{
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
p->die = cl.time + 0.1*(rand()%5);
p->color = (color&~7) + (rand()&7);
p->type = pt_grav;
for (j=0 ; j<3 ; j++)
{
p->org[j] = org[j] + scale*((rand()&15)-8);
p->vel[j] = dir[j]*15;// + (rand()%300)-150;
}
}
}
/*
===============
R_LavaSplash
===============
*/
void R_LavaSplash (vec3_t org)
{
int i, j, k;
particle_t *p;
float vel;
vec3_t dir;
if (!gl_particles->int_val)
return;
for (i=-16 ; i<16 ; i++)
for (j=-16 ; j<16 ; j++)
for (k=0 ; k<1 ; k++)
{
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
p->die = cl.time + 2 + (rand()&31) * 0.02;
p->color = 224 + (rand()&7);
p->type = pt_grav;
dir[0] = j*8 + (rand()&7);
dir[1] = i*8 + (rand()&7);
dir[2] = 256;
p->org[0] = org[0] + dir[0];
p->org[1] = org[1] + dir[1];
p->org[2] = org[2] + (rand()&63);
VectorNormalize (dir);
vel = 50 + (rand()&63);
VectorScale (dir, vel, p->vel);
}
}
/*
===============
R_TeleportSplash
===============
*/
void R_TeleportSplash (vec3_t org)
{
int i, j, k;
particle_t *p;
float vel;
vec3_t dir;
if (!gl_particles->int_val)
return;
for (i=-16 ; i<16 ; i+=4)
for (j=-16 ; j<16 ; j+=4)
for (k=-24 ; k<32 ; k+=4)
{
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
p->die = cl.time + 0.2 + (rand()&7) * 0.02;
p->color = 7 + (rand()&7);
p->type = pt_grav;
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);
}
}
void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
{
vec3_t vec;
float len;
int j;
particle_t *p;
if (type == 0)
R_AddFire (start, end, ent);
if (!gl_particles->int_val)
return;
VectorSubtract (end, start, vec);
len = VectorNormalize (vec);
while (len > 0)
{
len -= 3;
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
VectorCopy (vec3_origin, p->vel);
p->die = cl.time + 2;
if (type == 4)
{ // slight blood
p->type = pt_slowgrav;
p->color = 67 + (rand()&3);
for (j=0 ; j<3 ; j++)
p->org[j] = start[j] + ((rand()%6)-3);
len -= 3;
}
else if (type == 2)
{ // blood
p->type = pt_slowgrav;
p->color = 67 + (rand()&3);
for (j=0 ; j<3 ; j++)
p->org[j] = start[j] + ((rand()%6)-3);
}
else if (type == 6)
{ // voor trail
p->color = 9*16 + 8 + (rand()&3);
p->type = pt_static;
p->die = cl.time + 0.3;
for (j=0 ; j<3 ; j++)
p->org[j] = start[j] + ((rand()&15)-8);
}
else if (type == 1)
{ // smoke smoke
p->ramp = (rand()&3) + 2;
p->color = ramp3[(int)p->ramp];
p->type = pt_fire;
for (j=0 ; j<3 ; j++)
p->org[j] = start[j] + ((rand()%6)-3);
}
else if (type == 0)
{ // rocket trail
p->ramp = (rand()&3);
p->color = ramp3[(int)p->ramp];
p->type = pt_fire;
for (j=0 ; j<3 ; j++)
p->org[j] = start[j] + ((rand()%6)-3);
}
else if (type == 3 || type == 5)
{ // tracer
static int tracercount;
p->die = cl.time + 0.5;
p->type = pt_static;
if (type == 3)
p->color = 52 + ((tracercount&4)<<1);
else
p->color = 230 + ((tracercount&4)<<1);
tracercount++;
VectorCopy (start, p->org);
if (tracercount & 1)
{
p->vel[0] = 30*vec[1];
p->vel[1] = 30*-vec[0];
}
else
{
p->vel[0] = 30*-vec[1];
p->vel[1] = 30*vec[0];
}
}
VectorAdd (start, vec, start);
}
}
/*
===============
R_DrawParticles
===============
*/
void R_DrawParticles (void)
{
particle_t *p, *kill;
float grav;
int i;
float time2, time3;
float time1;
float dvel;
float frametime;
unsigned char *at;
unsigned char theAlpha;
vec3_t up, right;
float scale;
qboolean alphaTestEnabled;
glBindTexture (GL_TEXTURE_2D, particletexture);
// LordHavoc: particles should not affect zbuffer
glDepthMask(GL_FALSE);
alphaTestEnabled = glIsEnabled(GL_ALPHA_TEST);
if (alphaTestEnabled)
glDisable(GL_ALPHA_TEST);
glBegin (GL_TRIANGLES);
VectorScale (vup, 1.5, up);
VectorScale (vright, 1.5, right);
frametime = host_frametime;
time3 = frametime * 15;
time2 = frametime * 10; // 15;
time1 = frametime * 5;
grav = frametime * 800 * 0.05;
dvel = 4*frametime;
for ( ;; )
{
kill = active_particles;
if (kill && kill->die < cl.time)
{
active_particles = kill->next;
kill->next = free_particles;
free_particles = kill;
continue;
}
break;
}
for (p=active_particles ; p ; p=p->next)
{
for ( ;; )
{
kill = p->next;
if (kill && kill->die < cl.time)
{
p->next = kill->next;
kill->next = free_particles;
free_particles = kill;
continue;
}
break;
}
// hack a scale up to keep particles from disapearing
scale = (p->org[0] - r_origin[0])*vpn[0] +
(p->org[1] - r_origin[1])*vpn[1] +
(p->org[2] - r_origin[2])*vpn[2];
if (scale < 20)
scale = 1;
else
scale = 1 + scale * 0.004;
at = (byte *)&d_8to24table[(int)p->color];
if (p->type==pt_fire)
theAlpha = 255*(6-p->ramp)/6;
else
theAlpha = 255;
if (lighthalf)
glColor4ub((byte) ((int) at[0] >> 1), (byte) ((int) at[1] >> 1), (byte) ((int) at[2] >> 1), theAlpha);
else
glColor4ub(at[0], at[1], at[2], theAlpha);
glTexCoord2f (0,0);
glVertex3fv (p->org);
glTexCoord2f (1,0);
glVertex3f (p->org[0] + up[0]*scale, p->org[1] + up[1]*scale, p->org[2] + up[2]*scale);
glTexCoord2f (0,1);
glVertex3f (p->org[0] + right[0]*scale, p->org[1] + right[1]*scale, p->org[2] + right[2]*scale);
p->org[0] += p->vel[0]*frametime;
p->org[1] += p->vel[1]*frametime;
p->org[2] += p->vel[2]*frametime;
switch (p->type)
{
case pt_static:
break;
case pt_fire:
p->ramp += time1;
if (p->ramp >= 6)
p->die = -1;
else
p->color = ramp3[(int)p->ramp];
p->vel[2] += grav;
break;
case pt_explode:
p->ramp += time2;
if (p->ramp >=8)
p->die = -1;
else
p->color = ramp1[(int)p->ramp];
for (i=0 ; i<3 ; i++)
p->vel[i] += p->vel[i]*dvel;
p->vel[2] -= grav;
break;
case pt_explode2:
p->ramp += time3;
if (p->ramp >=8)
p->die = -1;
else
p->color = ramp2[(int)p->ramp];
for (i=0 ; i<3 ; i++)
p->vel[i] -= p->vel[i]*frametime;
p->vel[2] -= grav;
break;
case pt_blob:
for (i=0 ; i<3 ; i++)
p->vel[i] += p->vel[i]*dvel;
p->vel[2] -= grav;
break;
case pt_blob2:
for (i=0 ; i<2 ; i++)
p->vel[i] -= p->vel[i]*dvel;
p->vel[2] -= grav;
break;
case pt_slowgrav:
case pt_grav:
p->vel[2] -= grav;
break;
}
}
glEnd ();
glColor3ubv(lighthalf_v);
if (alphaTestEnabled)
glEnable(GL_ALPHA_TEST);
glDepthMask(GL_TRUE);
}
/*
R_AddFire
Nifty ball of fire GL effect. Kinda a meshing of the dlight and
particle engine code.
*/
float r_firecolor_flame[3]={0.9,0.4,0};
float r_firecolor_light[3]={0.9,0.4,0};
void
R_AddFire (vec3_t start, vec3_t end, entity_t *ent)
{
float len;
fire_t *f;
dlight_t *dl;
vec3_t vec;
int key;
if (!gl_fires->int_val)
return;
VectorSubtract (end, start, vec);
len = VectorNormalize (vec);
key = ent-cl_visedicts+1;
if (len)
{
f = R_AllocFire (key);
VectorCopy (end, f->origin);
VectorCopy (start, f->owner);
f->size = 20;
f->die = cl.time + 0.5;
f->decay = -1;
f->color=r_firecolor_flame;
dl = CL_AllocDlight (key);
VectorCopy (end, dl->origin);
dl->radius = 200;
dl->die = cl.time + 0.5;
dl->color=r_firecolor_light;
}
}
/*
R_AllocFire
Clears out and returns a new fireball
*/
fire_t *
R_AllocFire (int key)
{
int i;
fire_t *f;
if (key) // first try to find/reuse a keyed spot
{
f = r_fires;
for (i = 0; i < MAX_FIRES; i++, f++)
if (f->key == key)
{
memset (f, 0, sizeof(*f));
f->key = key;
f->color = f->_color;
return f;
}
}
f = r_fires; // no match, look for a free spot
for (i = 0; i < MAX_FIRES; i++, f++)
{
if (f->die < cl.time)
{
memset (f, 0, sizeof(*f));
f->key = key;
f->color = f->_color;
return f;
}
}
f = &r_fires[0];
memset (f, 0, sizeof(*f));
f->key = key;
f->color = f->_color;
return f;
}
/*
R_DrawFire
draws one fireball - probably never need to call this directly
*/
void
R_DrawFire (fire_t *f)
{
int i, j;
vec3_t vec,vec2;
float radius;
float *b_sin, *b_cos;
b_sin = bubble_sintable;
b_cos = bubble_costable;
radius = f->size + 0.35;
// figure out if we're inside the area of effect
VectorSubtract (f->origin, r_origin, vec);
if (Length (vec) < radius)
{
AddLightBlend (1, 0.5, 0, f->size * 0.0003); // we are
return;
}
// we're not - draw it
glBegin (GL_TRIANGLE_FAN);
if (lighthalf)
glColor3f(f->color[0]*0.5,f->color[1]*0.5,f->color[2]*0.5);
else
glColor3fv(f->color);
for (i=0 ; i<3 ; i++)
vec[i] = f->origin[i] - vpn[i] * radius;
glVertex3fv (vec);
glColor3f (0.0, 0.0, 0.0);
// don't panic, this just draws a bubble...
for (i=16 ; i>=0 ; i--)
{
for (j=0 ; j<3 ; j++) {
vec[j] = f->origin[j] + (*b_cos * vright[j]
+ vup[j]*(*b_sin)) * radius;
vec2[j] = f->owner[j] + (*b_cos * vright[j]
+ vup[j]*(*b_sin)) * radius;
}
glVertex3fv (vec);
glVertex3fv (vec2);
b_sin+=2;
b_cos+=2;
}
glEnd ();
glColor3ubv(lighthalf_v);
}
/*
R_UpdateFires
Draws each fireball in sequence
*/
void
R_UpdateFires (void)
{
int i;
fire_t *f;
if (!gl_fires->int_val)
return;
glDepthMask(GL_FALSE);
glDisable (GL_TEXTURE_2D);
glBlendFunc (GL_ONE, GL_ONE);
f = r_fires;
for (i = 0; i < MAX_FIRES; i++, f++)
{
if (f->die < cl.time || !f->size)
continue;
f->size += f->decay;
R_DrawFire (f);
}
glEnable (GL_TEXTURE_2D);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(GL_TRUE);
}
void
R_FireColor_f (void)
{
int i;
if (Cmd_Argc() == 1) {
Con_Printf ("r_firecolor %g %g %g\n",
r_firecolor_flame[0],
r_firecolor_flame[1],
r_firecolor_flame[2]);
return;
}
if (Cmd_Argc() == 5 || Cmd_Argc() == 6) {
Con_Printf ("Warning: obsolete 4th and 5th parameters to r_firecolor ignored\n");
} else if (Cmd_Argc() !=4) {
Con_Printf ("Usage r_firecolor R G B\n");
return;
}
for (i=0; i<4; i++) {
r_firecolor_flame[i]=atof(Cmd_Argv(i+1));
r_firecolor_light[i]=r_firecolor_flame[i];
}
}

View file

@ -43,6 +43,7 @@
#include "model.h"
#include "render.h"
#include "sys.h"
#include "r_dynamic.h"
entity_t r_worldentity;
@ -59,7 +60,6 @@ int c_brush_polys, c_alias_polys;
qboolean envmap; // true during envmap command capture
int particletexture; // little dot for particles
int playertextures; // up to 16 color translated skins
//
@ -363,7 +363,7 @@ static void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum, qboolean fb)
order = (int *)((byte *)paliashdr + paliashdr->commands);
if (modelalpha != 1.0)
glDepthMask(0);
glDepthMask(GL_FALSE);
while ((count = *order++)) {
// get the vertex count and primitive type
@ -396,7 +396,7 @@ static void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum, qboolean fb)
}
if (modelalpha != 1.0)
glDepthMask(1);
glDepthMask(GL_TRUE);
glColor3ubv(lighthalf_v);
}
@ -908,34 +908,6 @@ static void R_SetupGL (void)
glShadeModel (GL_FLAT);
}
/*
================
R_RenderScene
r_refdef must be set before the first call
================
*/
static void R_RenderScene (void)
{
R_SetupFrame ();
R_SetFrustum ();
R_SetupGL ();
R_MarkLeaves (); // done here so we know if we're in water
R_DrawWorld (); // adds static entities to the list
S_ExtraUpdate (); // don't let sound get messed up if going slow
R_DrawEntitiesOnList ();
R_RenderDlights ();
R_UpdateFires ();
R_DrawParticles ();
}
/*
=============
@ -975,7 +947,27 @@ void R_RenderView (void)
R_Clear ();
// render normal view
R_RenderScene ();
R_DrawViewModel ();
R_SetupFrame ();
R_SetFrustum ();
R_SetupGL ();
R_MarkLeaves (); // done here so we know if we're in water
R_DrawWorld (); // adds static entities to the list
S_ExtraUpdate (); // don't let sound get messed up if going slow
R_DrawEntitiesOnList ();
R_RenderDlights ();
R_DrawWaterSurfaces ();
R_UpdateFires ();
R_DrawParticles ();
R_DrawViewModel ();
}

View file

@ -54,6 +54,7 @@
#include "model.h" // needed by: glquake.h
#include "console.h"
#include "glquake.h"
#include "r_dynamic.h"
qboolean VID_Is8bit(void);
void R_InitBubble();
@ -95,44 +96,6 @@ void R_InitTextures (void)
}
}
byte dottexture[8][8] =
{
{0,1,1,0,0,0,0,0},
{1,1,1,1,0,0,0,0},
{1,1,1,1,0,0,0,0},
{0,1,1,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
};
void R_InitParticleTexture (void)
{
int x,y;
byte data[8][8][4];
//
// particle texture
//
particletexture = texture_extension_number++;
glBindTexture (GL_TEXTURE_2D, particletexture);
for (x=0 ; x<8 ; x++)
{
for (y=0 ; y<8 ; y++)
{
data[y][x][0] = 255;
data[y][x][1] = 255;
data[y][x][2] = 255;
data[y][x][3] = dottexture[x][y]*255;
}
}
glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
/*
===============
R_Envmap_f
@ -278,7 +241,6 @@ void R_Init (void)
R_InitBubble();
R_InitParticles ();
R_InitParticleTexture ();
netgraphtexture = texture_extension_number;
texture_extension_number++;

View file

@ -163,7 +163,7 @@ XLateKey(XKeyEvent *ev)
case XK_Meta_R: key = K_ALT; break;
case XK_Caps_Lock: key = K_CAPSLOCK; break;
case XK_KP_Begin: key = K_AUX30; break;
case XK_KP_Begin: key = KP_5; break;
case XK_Insert: key = K_INS; break;
case XK_KP_Insert: key = KP_INS; break;