DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
r_explosion.c File Reference
#include "quakedef.h"
#include "cl_collision.h"
+ Include dependency graph for r_explosion.c:

Go to the source code of this file.

Data Structures

struct  explosion_t
 

Macros

#define EXPLOSIONGRID   8
 
#define EXPLOSIONTRIS   (EXPLOSIONGRID*EXPLOSIONGRID*2)
 
#define EXPLOSIONVERTS   ((EXPLOSIONGRID+1)*(EXPLOSIONGRID+1))
 

Functions

static void R_DrawExplosion_TransparentCallback (const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
 
void R_DrawExplosions (void)
 
void R_Explosion_Init (void)
 
static void r_explosion_newmap (void)
 
static void r_explosion_shutdown (void)
 
static void r_explosion_start (void)
 
static int R_ExplosionVert (int column, int row)
 
static void R_MoveExplosion (explosion_t *e)
 
void R_NewExplosion (const vec3_t org)
 

Variables

static explosion_t explosion [MAX_EXPLOSIONS]
 
static int explosionnoiseindex [EXPLOSIONVERTS]
 
static vec3_t explosionpoint [EXPLOSIONVERTS]
 
static float explosiontexcoord2f [EXPLOSIONVERTS][2]
 
static rtexture_texplosiontexture
 
static rtexturepool_texplosiontexturepool
 
static unsigned short explosiontris [EXPLOSIONTRIS][3]
 
static int numexplosions = 0
 
static cvar_t r_drawexplosions = {CF_CLIENT, "r_drawexplosions", "1", "enables rendering of explosion shells (see also cl_particles_explosions_shell)"}
 
cvar_t r_explosionclip = {CF_CLIENT | CF_ARCHIVE, "r_explosionclip", "1", "enables collision detection for explosion shell (so that it flattens against walls and floors)"}
 

Macro Definition Documentation

◆ EXPLOSIONGRID

#define EXPLOSIONGRID   8

Definition at line 25 of file r_explosion.c.

Referenced by R_Explosion_Init(), R_ExplosionVert(), and R_NewExplosion().

◆ EXPLOSIONTRIS

#define EXPLOSIONTRIS   (EXPLOSIONGRID*EXPLOSIONGRID*2)

Definition at line 27 of file r_explosion.c.

Referenced by R_DrawExplosion_TransparentCallback().

◆ EXPLOSIONVERTS

#define EXPLOSIONVERTS   ((EXPLOSIONGRID+1)*(EXPLOSIONGRID+1))

Function Documentation

◆ R_DrawExplosion_TransparentCallback()

static void R_DrawExplosion_TransparentCallback ( const entity_render_t * ent,
const rtlight_t * rtlight,
int numsurfaces,
int * surfacelist )
static

Definition at line 203 of file r_explosion.c.

204{
205 int surfacelistindex = 0;
206 const int numtriangles = EXPLOSIONTRIS, numverts = EXPLOSIONVERTS;
208 GL_DepthMask(false);
209 GL_DepthRange(0, 1);
211 GL_DepthTest(true);
214
215// R_Mesh_ResetTextureState();
216 R_SetupShader_Generic(explosiontexture, false, false, false);
217 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
218 {
219 const explosion_t *e = explosion + surfacelist[surfacelistindex];
220 // FIXME: this can't properly handle r_refdef.view.colorscale > 1
223 R_Mesh_Draw(0, numverts, 0, numtriangles, NULL, NULL, 0, explosiontris[0], NULL, 0);
224 }
225}
void GL_CullFace(int state)
void GL_DepthMask(int state)
void R_Mesh_Draw(int firstvertex, int numvertices, int firsttriangle, int numtriangles, const int *element3i, const r_meshbuffer_t *element3i_indexbuffer, int element3i_bufferoffset, const unsigned short *element3s, const r_meshbuffer_t *element3s_indexbuffer, int element3s_bufferoffset)
void GL_DepthTest(int state)
void GL_DepthRange(float nearfrac, float farfrac)
void GL_PolygonOffset(float planeoffset, float depthoffset)
void GL_Color(float cr, float cg, float cb, float ca)
void GL_BlendFunc(int blendfunc1, int blendfunc2)
void R_Mesh_PrepareVertices_Generic_Arrays(int numvertices, const float *vertex3f, const float *color4f, const float *texcoord2f)
void R_EntityMatrix(const matrix4x4_t *matrix)
Definition gl_rmain.c:4417
void R_SetupShader_Generic(rtexture_t *t, qbool usegamma, qbool notrippy, qbool suppresstexalpha)
Definition gl_rmain.c:1461
r_refdef_t r_refdef
Definition gl_rmain.c:57
#define GL_SRC_ALPHA
Definition glquake.h:79
#define GL_ONE
Definition glquake.h:74
const matrix4x4_t identitymatrix
Definition matrixlib.c:9
#define NULL
Definition qtypes.h:12
static rtexture_t * explosiontexture
Definition r_explosion.c:52
static float explosiontexcoord2f[EXPLOSIONVERTS][2]
Definition r_explosion.c:31
static unsigned short explosiontris[EXPLOSIONTRIS][3]
Definition r_explosion.c:32
#define EXPLOSIONVERTS
Definition r_explosion.c:26
static explosion_t explosion[MAX_EXPLOSIONS]
Definition r_explosion.c:50
#define EXPLOSIONTRIS
Definition r_explosion.c:27
vec3_t vert[EXPLOSIONVERTS]
Definition r_explosion.c:44
float polygonoffset
Definition render.h:459
r_refdef_view_t view
Definition render.h:406
float polygonfactor
Definition render.h:458
float colorscale
global RGB color multiplier for rendering
Definition render.h:302
int cullface_back
Definition render.h:318

References explosion_t::alpha, r_refdef_view_t::colorscale, r_refdef_view_t::cullface_back, explosion, explosiontexcoord2f, explosiontexture, EXPLOSIONTRIS, explosiontris, EXPLOSIONVERTS, GL_BlendFunc(), GL_Color(), GL_CullFace(), GL_DepthMask(), GL_DepthRange(), GL_DepthTest(), GL_ONE, GL_PolygonOffset(), GL_SRC_ALPHA, identitymatrix, NULL, r_refdef_t::polygonfactor, r_refdef_t::polygonoffset, R_EntityMatrix(), R_Mesh_Draw(), R_Mesh_PrepareVertices_Generic_Arrays(), r_refdef, R_SetupShader_Generic(), explosion_t::vert, and r_refdef_t::view.

Referenced by R_DrawExplosions().

◆ R_DrawExplosions()

void R_DrawExplosions ( void )

Definition at line 264 of file r_explosion.c.

265{
266#ifdef MAX_EXPLOSIONS
267 int i;
268
270 return;
271
272 for (i = 0;i < numexplosions;i++)
273 {
274 if (explosion[i].alpha)
275 {
277 if (explosion[i].alpha)
279 }
280 }
281 while (numexplosions > 0 && explosion[i-1].alpha <= 0)
283#endif
284}
vector origin
float alpha
void R_MeshQueue_AddTransparent(dptransparentsortcategory_t category, const vec3_t center, void(*callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist), const entity_render_t *ent, int surfacenumber, const rtlight_t *rtlight)
Definition meshqueue.c:33
int i
static void R_DrawExplosion_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
static int numexplosions
Definition r_explosion.c:29
static cvar_t r_drawexplosions
Definition r_explosion.c:60
static void R_MoveExplosion(explosion_t *e)
@ TRANSPARENTSORT_DISTANCE
Definition r_qshader.h:194
int integer
Definition cvar.h:73

References alpha, explosion, i, cvar_t::integer, NULL, numexplosions, origin, R_DrawExplosion_TransparentCallback(), r_drawexplosions, R_MeshQueue_AddTransparent(), R_MoveExplosion(), and TRANSPARENTSORT_DISTANCE.

Referenced by R_RenderScene().

◆ R_Explosion_Init()

void R_Explosion_Init ( void )

Definition at line 131 of file r_explosion.c.

132{
133#ifdef MAX_EXPLOSIONS
134 int i, x, y;
135 i = 0;
136 for (y = 0;y < EXPLOSIONGRID;y++)
137 {
138 for (x = 0;x < EXPLOSIONGRID;x++)
139 {
141 explosiontris[i][1] = R_ExplosionVert(x + 1, y );
142 explosiontris[i][2] = R_ExplosionVert(x , y + 1);
143 i++;
144 explosiontris[i][0] = R_ExplosionVert(x + 1, y );
145 explosiontris[i][1] = R_ExplosionVert(x + 1, y + 1);
146 explosiontris[i][2] = R_ExplosionVert(x , y + 1);
147 i++;
148 }
149 }
150
151#endif
153#ifdef MAX_EXPLOSIONS
155
157#endif
158}
void Cvar_RegisterVariable(cvar_t *variable)
registers a cvar that already has the name, string, and optionally the archive elements set.
Definition cvar.c:599
GLint GLenum GLint GLint y
Definition glquake.h:651
GLint GLenum GLint x
Definition glquake.h:651
#define EXPLOSIONGRID
Definition r_explosion.c:25
static void r_explosion_newmap(void)
static void r_explosion_shutdown(void)
static int R_ExplosionVert(int column, int row)
static void r_explosion_start(void)
Definition r_explosion.c:63
cvar_t r_explosionclip
Definition r_explosion.c:58
void R_RegisterModule(const char *name, void(*start)(void), void(*shutdown)(void), void(*newmap)(void), void(*devicelost)(void), void(*devicerestored)(void))
Definition r_modules.c:25

References Cvar_RegisterVariable(), EXPLOSIONGRID, explosiontris, i, NULL, r_drawexplosions, r_explosion_newmap(), r_explosion_shutdown(), r_explosion_start(), r_explosionclip, R_ExplosionVert(), R_RegisterModule(), x, and y.

Referenced by Render_Init().

◆ r_explosion_newmap()

static void r_explosion_newmap ( void )
static

Definition at line 105 of file r_explosion.c.

106{
107 numexplosions = 0;
108 memset(explosion, 0, sizeof(explosion));
109}

References explosion, and numexplosions.

Referenced by R_Explosion_Init().

◆ r_explosion_shutdown()

static void r_explosion_shutdown ( void )
static

Definition at line 100 of file r_explosion.c.

101{
103}
void R_FreeTexturePool(rtexturepool_t **rtexturepool)
static rtexturepool_t * explosiontexturepool
Definition r_explosion.c:55

References explosiontexturepool, and R_FreeTexturePool().

Referenced by R_Explosion_Init().

◆ r_explosion_start()

static void r_explosion_start ( void )
static

Definition at line 63 of file r_explosion.c.

64{
65 int x, y;
66 static unsigned char noise1[128][128], noise2[128][128], noise3[128][128], data[128][128][4];
69 //explosiontexturefog = NULL;
70 fractalnoise(&noise1[0][0], 128, 32);
71 fractalnoise(&noise2[0][0], 128, 4);
72 fractalnoise(&noise3[0][0], 128, 4);
73 for (y = 0;y < 128;y++)
74 {
75 for (x = 0;x < 128;x++)
76 {
77 int j, r, g, b, a;
78 j = (noise1[y][x] * noise2[y][x]) * 3 / 256 - 128;
79 r = (j * 512) / 256;
80 g = (j * 256) / 256;
81 b = (j * 128) / 256;
82 a = noise3[y][x] * 3 - 128;
83 data[y][x][2] = bound(0, r, 255);
84 data[y][x][1] = bound(0, g, 255);
85 data[y][x][0] = bound(0, b, 255);
86 data[y][x][3] = bound(0, a, 255);
87 }
88 }
90// if (r_loadfog)
91// {
92// for (y = 0;y < 128;y++)
93// for (x = 0;x < 128;x++)
94// data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
95// explosiontexturefog = R_LoadTexture2D(explosiontexturepool, "explosiontexture_fog", 128, 128, &data[0][0][0], TEXTYPE_BGRA, TEXF_MIPMAP | TEXF_ALPHA | TEXF_FORCELINEAR, NULL);
96// }
97 // note that explosions survive the restart
98}
void fractalnoise(unsigned char *noise, int size, int startgrid)
Definition fractalnoise.c:4
rtexturepool_t * R_AllocTexturePool(void)
rtexture_t * R_LoadTexture2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette)
GLsizeiptr const GLvoid * data
Definition glquake.h:639
#define bound(min, num, max)
Definition mathlib.h:34
string noise1
Definition progsdefs.qc:209
string noise3
Definition progsdefs.qc:209
string noise2
Definition progsdefs.qc:209
#define TEXF_ALPHA
Definition r_textures.h:9
#define TEXF_FORCELINEAR
Definition r_textures.h:19
#define TEXF_MIPMAP
Definition r_textures.h:11
@ TEXTYPE_BGRA
Definition r_textures.h:53
dp_FragColor r
dp_FragColor g
dp_FragColor b
ret a

References a, b, bound, data, explosiontexture, explosiontexturepool, fractalnoise(), g, noise1, noise2, noise3, NULL, r, R_AllocTexturePool(), R_LoadTexture2D(), TEXF_ALPHA, TEXF_FORCELINEAR, TEXF_MIPMAP, TEXTYPE_BGRA, x, and y.

Referenced by R_Explosion_Init().

◆ R_ExplosionVert()

static int R_ExplosionVert ( int column,
int row )
static

Definition at line 111 of file r_explosion.c.

112{
113 int i;
114 float yaw, pitch;
115 // top and bottom rows are all one position...
116 if (row == 0 || row == EXPLOSIONGRID)
117 column = 0;
118 i = row * (EXPLOSIONGRID + 1) + column;
119 yaw = ((double) column / EXPLOSIONGRID) * M_PI * 2;
120 pitch = (((double) row / EXPLOSIONGRID) - 0.5) * M_PI;
121 explosionpoint[i][0] = cos(yaw) * cos(pitch);
122 explosionpoint[i][1] = sin(yaw) * cos(pitch);
123 explosionpoint[i][2] = 1 * -sin(pitch);
124 explosiontexcoord2f[i][0] = (float) column / (float) EXPLOSIONGRID;
125 explosiontexcoord2f[i][1] = (float) row / (float) EXPLOSIONGRID;
127 return i;
128}
#define M_PI
Definition mathlib.h:28
float cos(float f)
float sin(float f)
static int explosionnoiseindex[EXPLOSIONVERTS]
Definition r_explosion.c:33
static vec3_t explosionpoint[EXPLOSIONVERTS]
Definition r_explosion.c:34
precision highp float
Definition shader_glsl.h:53

References cos(), EXPLOSIONGRID, explosionnoiseindex, explosionpoint, explosiontexcoord2f, float, i, M_PI, and sin().

Referenced by R_Explosion_Init().

◆ R_MoveExplosion()

static void R_MoveExplosion ( explosion_t * e)
static

Definition at line 227 of file r_explosion.c.

228{
229 int i;
230 float dot, end[3], frametime;
231 trace_t trace;
232
233 frametime = cl.time - e->time;
234 e->time = cl.time;
235 e->alpha = e->alpha - (e->fade * frametime);
236 if (e->alpha < 0 || cl.time > e->endtime)
237 {
238 e->alpha = 0;
239 return;
240 }
241 for (i = 0;i < EXPLOSIONVERTS;i++)
242 {
243 if (e->vertvel[i][0] || e->vertvel[i][1] || e->vertvel[i][2])
244 {
245 VectorMA(e->vert[i], frametime, e->vertvel[i], end);
246 if (e->clipping)
247 {
248 trace = CL_TraceLine(e->vert[i], end, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, 0, 0, collision_extendmovelength.value, true, false, NULL, false, false);
249 if (trace.fraction < 1)
250 {
251 // clip velocity against the wall
252 dot = -DotProduct(e->vertvel[i], trace.plane.normal);
253 VectorMA(e->vertvel[i], dot, trace.plane.normal, e->vertvel[i]);
254 }
255 VectorCopy(trace.endpos, e->vert[i]);
256 }
257 else
258 VectorCopy(end, e->vert[i]);
259 }
260 }
261}
#define SUPERCONTENTS_SOLID
Definition bspfile.h:196
trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend, qbool hitnetworkbrushmodels, qbool hitnetworkplayers, int *hitnetworkentity, qbool hitcsqcentities, qbool hitsurfaces)
client_state_t cl
Definition cl_main.c:117
cvar_t collision_extendmovelength
Definition collision.c:14
float frametime
#define DotProduct(a, b)
Definition mathlib.h:98
#define VectorCopy(in, out)
Definition mathlib.h:101
#define VectorMA(a, scale, b, out)
Definition mathlib.h:114
double time
Definition client.h:868
float value
Definition cvar.h:74
float endtime
Definition r_explosion.c:39
vec3_t vertvel[EXPLOSIONVERTS]
Definition r_explosion.c:45
qbool clipping
Definition r_explosion.c:46
double fraction
Definition collision.h:40
double endpos[3]
Definition collision.h:42
plane_t plane
Definition collision.h:44
vec3_t normal
Definition collision.h:13
#define MOVE_NOMONSTERS
Definition world.h:29

References explosion_t::alpha, cl, CL_TraceLine(), explosion_t::clipping, collision_extendmovelength, DotProduct, trace_t::endpos, explosion_t::endtime, EXPLOSIONVERTS, explosion_t::fade, trace_t::fraction, frametime, i, MOVE_NOMONSTERS, plane_t::normal, NULL, trace_t::plane, SUPERCONTENTS_SOLID, client_state_t::time, explosion_t::time, cvar_t::value, VectorCopy, VectorMA, explosion_t::vert, and explosion_t::vertvel.

Referenced by R_DrawExplosions().

◆ R_NewExplosion()

void R_NewExplosion ( const vec3_t org)

Definition at line 160 of file r_explosion.c.

161{
162#ifdef MAX_EXPLOSIONS
163 int i, j;
164 float dist, n;
165 explosion_t *e;
166 trace_t trace;
167 unsigned char noise[EXPLOSIONGRID*EXPLOSIONGRID];
168 fractalnoisequick(noise, EXPLOSIONGRID, 4); // adjust noise grid size according to explosion
169 for (i = 0, e = explosion;i < MAX_EXPLOSIONS;i++, e++)
170 {
171 if (!e->alpha)
172 {
174 e->starttime = cl.time;
176 e->time = e->starttime;
180 VectorCopy(org, e->origin);
181 for (j = 0;j < EXPLOSIONVERTS;j++)
182 {
183 // calculate start origin and velocity
184 n = noise[explosionnoiseindex[j]] * (1.0f / 255.0f) + 0.5;
186 VectorMA(e->origin, dist, explosionpoint[j], e->vert[j]);
188 VectorScale(explosionpoint[j], dist, e->vertvel[j]);
189 // clip start origin
190 if (e->clipping)
191 {
192 trace = CL_TraceLine(e->origin, e->vert[j], MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, 0, 0, collision_extendmovelength.value, true, false, NULL, false, false);
193 VectorCopy(trace.endpos, e->vert[i]);
194 }
195 }
196 break;
197 }
198 }
199#endif
200}
cvar_t cl_explosions_lifetime
Definition cl_main.c:73
cvar_t cl_explosions_size_start
Definition cl_main.c:71
cvar_t cl_explosions_size_end
Definition cl_main.c:72
cvar_t cl_explosions_alpha_start
Definition cl_main.c:69
cvar_t cl_explosions_alpha_end
Definition cl_main.c:70
#define n(x, y)
void fractalnoisequick(unsigned char *noise, int size, int startgrid)
#define max(A, B)
Definition mathlib.h:38
#define VectorScale(in, scale, out)
Definition mathlib.h:111
string noise
Definition progsdefs.qc:209
#define MAX_EXPLOSIONS
max number of explosion shell effects active at once (not particle related)
Definition qdefs.h:131
vec3_t origin
Definition r_explosion.c:43
float starttime
Definition r_explosion.c:38

References explosion_t::alpha, cl, cl_explosions_alpha_end, cl_explosions_alpha_start, cl_explosions_lifetime, cl_explosions_size_end, cl_explosions_size_start, CL_TraceLine(), explosion_t::clipping, collision_extendmovelength, trace_t::endpos, explosion_t::endtime, explosion, EXPLOSIONGRID, explosionnoiseindex, explosionpoint, EXPLOSIONVERTS, explosion_t::fade, fractalnoisequick(), i, cvar_t::integer, max, MAX_EXPLOSIONS, MOVE_NOMONSTERS, n, noise, NULL, numexplosions, explosion_t::origin, r_explosionclip, explosion_t::starttime, SUPERCONTENTS_SOLID, client_state_t::time, explosion_t::time, cvar_t::value, VectorCopy, VectorMA, VectorScale, explosion_t::vert, and explosion_t::vertvel.

Referenced by CL_ParticleExplosion().

Variable Documentation

◆ explosion

◆ explosionnoiseindex

int explosionnoiseindex[EXPLOSIONVERTS]
static

Definition at line 33 of file r_explosion.c.

Referenced by R_ExplosionVert(), and R_NewExplosion().

◆ explosionpoint

vec3_t explosionpoint[EXPLOSIONVERTS]
static

Definition at line 34 of file r_explosion.c.

Referenced by R_ExplosionVert(), and R_NewExplosion().

◆ explosiontexcoord2f

float explosiontexcoord2f[EXPLOSIONVERTS][2]
static

Definition at line 31 of file r_explosion.c.

Referenced by R_DrawExplosion_TransparentCallback(), and R_ExplosionVert().

◆ explosiontexture

rtexture_t* explosiontexture
static

Definition at line 52 of file r_explosion.c.

Referenced by R_DrawExplosion_TransparentCallback(), and r_explosion_start().

◆ explosiontexturepool

rtexturepool_t* explosiontexturepool
static

Definition at line 55 of file r_explosion.c.

Referenced by r_explosion_shutdown(), and r_explosion_start().

◆ explosiontris

unsigned short explosiontris[EXPLOSIONTRIS][3]
static

Definition at line 32 of file r_explosion.c.

Referenced by R_DrawExplosion_TransparentCallback(), and R_Explosion_Init().

◆ numexplosions

int numexplosions = 0
static

Definition at line 29 of file r_explosion.c.

Referenced by R_DrawExplosions(), r_explosion_newmap(), and R_NewExplosion().

◆ r_drawexplosions

cvar_t r_drawexplosions = {CF_CLIENT, "r_drawexplosions", "1", "enables rendering of explosion shells (see also cl_particles_explosions_shell)"}
static

Definition at line 60 of file r_explosion.c.

60{CF_CLIENT, "r_drawexplosions", "1", "enables rendering of explosion shells (see also cl_particles_explosions_shell)"};
#define CF_CLIENT
cvar/command that only the client can change/execute
Definition cmd.h:48

Referenced by R_DrawExplosions(), and R_Explosion_Init().

◆ r_explosionclip

cvar_t r_explosionclip = {CF_CLIENT | CF_ARCHIVE, "r_explosionclip", "1", "enables collision detection for explosion shell (so that it flattens against walls and floors)"}

Definition at line 58 of file r_explosion.c.

58{CF_CLIENT | CF_ARCHIVE, "r_explosionclip", "1", "enables collision detection for explosion shell (so that it flattens against walls and floors)"};
#define CF_ARCHIVE
cvar should have its set value saved to config.cfg and persist across sessions
Definition cmd.h:53

Referenced by M_Menu_Options_Effects_AdjustSliders(), M_Options_Effects_Draw(), R_Explosion_Init(), and R_NewExplosion().