Use the Mersenne Twister for particles.

The seed is currently 0xdeadbeef, but I intend on fixing that soon. Now the
particle velocities and origins use fully independent bits (though a big
chunk is wasted right now).
This commit is contained in:
Bill Currie 2013-01-21 20:06:54 +09:00
parent 5188644e75
commit cb45d248c4
4 changed files with 200 additions and 184 deletions

View file

@ -42,6 +42,7 @@
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/mersenne.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/render.h"
@ -66,6 +67,7 @@ static int pVAsize;
static int *pVAindices;
static varray_t2f_c4ub_v3f_t *particleVertexArray;
static mtstate_t mt; // private PRNG state
inline static void
particle_new (ptype_t type, int texnum, const vec3_t org, float scale,
@ -110,14 +112,14 @@ particle_new_random (ptype_t type, int texnum, const vec3_t org, int org_fuzz,
int rnd;
vec3_t porg, pvel;
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = o_fuzz * ((rnd & 63) - 31.5) / 63.0 + org[0];
porg[1] = o_fuzz * (((rnd >> 5) & 63) - 31.5) / 63.0 + org[1];
porg[2] = o_fuzz * (((rnd >> 9) & 63) - 31.5) / 63.0 + org[2];
rnd = rand ();
porg[1] = o_fuzz * (((rnd >> 6) & 63) - 31.5) / 63.0 + org[1];
porg[2] = o_fuzz * (((rnd >> 10) & 63) - 31.5) / 63.0 + org[2];
rnd = mtwist_rand (&mt);
pvel[0] = v_fuzz * ((rnd & 63) - 31.5) / 63.0;
pvel[1] = v_fuzz * (((rnd >> 5) & 63) - 31.5) / 63.0;
pvel[2] = v_fuzz * (((rnd >> 9) & 63) - 31.5) / 63.0;
pvel[1] = v_fuzz * (((rnd >> 6) & 63) - 31.5) / 63.0;
pvel[2] = v_fuzz * (((rnd >> 10) & 63) - 31.5) / 63.0;
particle_new (type, texnum, porg, scale, pvel, die, color, alpha, ramp);
}
@ -151,6 +153,8 @@ gl_R_InitParticles (void)
{
int i;
mtwist_seed (&mt, 0xdeadbeef);
if (r_maxparticles && r_init) {
if (vaelements) {
partUseVA = 0;
@ -245,7 +249,7 @@ R_ParticleExplosion_QF (const vec3_t org)
if (numparticles >= r_maxparticles)
return;
particle_new_random (pt_smokecloud, part_tex_smoke, org, 4, 30, 8,
vr_data.realtime + 5.0, (rand () & 7) + 8,
vr_data.realtime + 5.0, (mtwist_rand (&mt) & 7) + 8,
0.5 + qfrandom (0.25), 0.0);
}
@ -279,12 +283,12 @@ R_BlobExplosion_QF (const vec3_t org)
for (i = 0; i < j >> 1; i++) {
particle_new_random (pt_blob, part_tex_dot, org, 12, 2, 256,
vr_data.realtime + 1.0 + (rand () & 7) * 0.05,
vr_data.realtime + 1.0 + (mtwist_rand (&mt) & 7) * 0.05,
66 + i % 6, 1.0, 0.0);
}
for (i = 0; i < j / 2; i++) {
particle_new_random (pt_blob2, part_tex_dot, org, 12, 2, 256,
vr_data.realtime + 1.0 + (rand () & 7) * 0.05,
vr_data.realtime + 1.0 + (mtwist_rand (&mt) & 7) * 0.05,
150 + i % 6, 1.0, 0.0);
}
}
@ -295,7 +299,7 @@ R_RunSparkEffect_QF (const vec3_t org, int count, int ofuzz)
if (numparticles >= r_maxparticles)
return;
particle_new (pt_smokecloud, part_tex_smoke, org, ofuzz * 0.08,
vec3_origin, vr_data.realtime + 9, 12 + (rand () & 3),
vec3_origin, vr_data.realtime + 9, 12 + (mtwist_rand (&mt) & 3),
0.25 + qfrandom (0.125), 0.0);
if (numparticles + count >= r_maxparticles)
@ -306,7 +310,7 @@ R_RunSparkEffect_QF (const vec3_t org, int count, int ofuzz)
orgfuzz = 1;
while (count--) {
int color = rand () & 7;
int color = mtwist_rand (&mt) & 7;
particle_new_random (pt_fallfadespark, part_tex_dot, org, orgfuzz,
0.7, 96, vr_data.realtime + 5.0, ramp1[color],
@ -322,7 +326,7 @@ R_BloodPuff_QF (const vec3_t org, int count)
return;
particle_new (pt_bloodcloud, part_tex_smoke, org, count / 5, vec3_origin,
vr_data.realtime + 99.0, 70 + (rand () & 3), 0.5, 0.0);
vr_data.realtime + 99.0, 70 + (mtwist_rand (&mt) & 3), 0.5, 0.0);
}
static void
@ -350,7 +354,7 @@ R_LightningBloodEffect_QF (const vec3_t org)
if (numparticles >= r_maxparticles)
return;
particle_new (pt_smokecloud, part_tex_smoke, org, 3.0, vec3_origin,
vr_data.realtime + 9.0, 12 + (rand () & 3),
vr_data.realtime + 9.0, 12 + (mtwist_rand (&mt) & 3),
0.25 + qfrandom (0.125), 0.0);
if (numparticles + count >= r_maxparticles)
@ -378,7 +382,7 @@ R_RunParticleEffect_QF (const vec3_t org, const vec3_t dir, int color,
count = r_maxparticles - numparticles;
for (i = 0; i < count; i++) {
int rnd = rand ();
int rnd = mtwist_rand (&mt);
porg[0] = org[0] + scale * (((rnd >> 3) & 15) - 7.5);
porg[1] = org[1] + scale * (((rnd >> 7) & 15) - 7.5);
@ -453,7 +457,7 @@ R_LavaSplash_QF (const vec3_t org)
dir[2] = 256;
for (i = -128; i < 128; i += 16) {
for (j = -128; j < 128; j += 16) {
rnd = rand ();
rnd = mtwist_rand (&mt);
dir[0] = j + (rnd & 7);
dir[1] = i + ((rnd >> 6) & 7);
@ -462,7 +466,7 @@ R_LavaSplash_QF (const vec3_t org)
porg[2] = org[2] + ((rnd >> 9) & 63);
VectorNormalize (dir);
rnd = rand ();
rnd = mtwist_rand (&mt);
vel = 50.0 + 0.5 * (float) (rnd & 127);
VectorScale (dir, vel, pvel);
particle_new (pt_grav, part_tex_dot, porg, 3, pvel,
@ -496,7 +500,7 @@ R_TeleportSplash_QF (const vec3_t org)
VectorCopy (dir, pdir);
VectorNormalize (pdir);
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = org[0] + i + (rnd & 3);
porg[1] = org[1] + j + ((rnd >> 2) & 3);
porg[2] = org[2] + k + ((rnd >> 4) & 3);
@ -504,7 +508,7 @@ R_TeleportSplash_QF (const vec3_t org)
vel = 50 + ((rnd >> 6) & 63);
VectorScale (pdir, vel, pvel);
particle_new (pt_grav, part_tex_spark, porg, 0.6, pvel,
(vr_data.realtime + 0.2 + (rand () & 15) * 0.01),
(vr_data.realtime + 0.2 + (mtwist_rand (&mt) & 15) * 0.01),
(7 + ((rnd >> 12) & 7)), 1.0, 0.0);
}
}
@ -535,7 +539,7 @@ R_RocketTrail_QF (const entity_t *ent)
particle_new (pt_smoke, part_tex_smoke, old_origin,
pscale + percent * 4.0, vec3_origin,
vr_data.realtime + 2.0 - percent * 2.0,
12 + (rand () & 3),
12 + (mtwist_rand (&mt) & 3),
0.5 + qfrandom (0.125) - percent * 0.40, 0.0);
if (numparticles >= r_maxparticles)
break;
@ -569,7 +573,7 @@ R_GrenadeTrail_QF (const entity_t *ent)
particle_new (pt_smoke, part_tex_smoke, old_origin,
pscale + percent * 4.0, vec3_origin,
vr_data.realtime + 2.0 - percent * 2.0,
1 + (rand () & 3),
1 + (mtwist_rand (&mt) & 3),
0.625 + qfrandom (0.125) - percent * 0.40, 0.0);
if (numparticles >= r_maxparticles)
break;
@ -610,7 +614,7 @@ R_BloodTrail_QF (const entity_t *ent)
particle_new (pt_grav, part_tex_smoke, porg, pscale, pvel,
vr_data.realtime + 2.0 - percent * 2.0,
68 + (rand () & 3), 1.0, 0.0);
68 + (mtwist_rand (&mt) & 3), 1.0, 0.0);
if (numparticles >= r_maxparticles)
break;
len += dist;
@ -650,7 +654,7 @@ R_SlightBloodTrail_QF (const entity_t *ent)
particle_new (pt_grav, part_tex_smoke, porg, pscale, pvel,
vr_data.realtime + 1.5 - percent * 1.5,
68 + (rand () & 3), 0.75, 0.0);
68 + (mtwist_rand (&mt) & 3), 0.75, 0.0);
if (numparticles >= r_maxparticles)
break;
len += dist;
@ -692,7 +696,7 @@ R_WizTrail_QF (const entity_t *ent)
particle_new (pt_flame, part_tex_smoke, old_origin,
2.0 + qfrandom (1.0) - percent * 2.0, pvel,
vr_data.realtime + 0.5 - percent * 0.5,
52 + (rand () & 4), 1.0 - percent * 0.125, 0.0);
52 + (mtwist_rand (&mt) & 4), 1.0 - percent * 0.125, 0.0);
if (numparticles >= r_maxparticles)
break;
len += dist;
@ -766,7 +770,7 @@ R_VoorTrail_QF (const entity_t *ent)
particle_new (pt_static, part_tex_dot, porg, 1.0 + qfrandom (1.0),
vec3_origin, vr_data.realtime + 0.3 - percent * 0.3,
9 * 16 + 8 + (rand () & 3), 1.0, 0.0);
9 * 16 + 8 + (mtwist_rand (&mt) & 3), 1.0, 0.0);
if (numparticles >= r_maxparticles)
break;
len += dist;
@ -794,7 +798,7 @@ R_GlowTrail_QF (const entity_t *ent, int glow_color)
while (len < maxlen) {
percent = len * origlen;
rnd = rand ();
rnd = mtwist_rand (&mt);
org[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
org[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
org[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -818,7 +822,7 @@ R_ParticleExplosion_EE (const vec3_t org)
if (numparticles >= r_maxparticles)
return;
particle_new_random (pt_smokecloud, part_tex_smoke, org, 4, 30, 8,
vr_data.realtime + 5.0, rand () & 255,
vr_data.realtime + 5.0, mtwist_rand (&mt) & 255,
0.5 + qfrandom (0.25), 0.0);
}
@ -843,7 +847,7 @@ R_TeleportSplash_EE (const vec3_t org)
for (j = -16; j < 16; j += 4) {
dir[0] = j * 8;
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = org[0] + i + (rnd & 3);
porg[1] = org[1] + j + ((rnd >> 2) & 3);
porg[2] = org[2] + k + ((rnd >> 4) & 3);
@ -852,7 +856,7 @@ R_TeleportSplash_EE (const vec3_t org)
vel = 50 + ((rnd >> 6) & 63);
VectorScale (dir, vel, pvel);
particle_new (pt_grav, part_tex_spark, porg, 0.6, pvel,
(vr_data.realtime + 0.2 + (rand () & 15) * 0.01),
(vr_data.realtime + 0.2 + (mtwist_rand (&mt) & 15) * 0.01),
qfrandom (1.0), 1.0, 0.0);
}
}
@ -883,7 +887,7 @@ R_RocketTrail_EE (const entity_t *ent)
particle_new (pt_smoke, part_tex_smoke, old_origin,
pscale + percent * 4.0, vec3_origin,
vr_data.realtime + 2.0 - percent * 2.0,
rand () & 255,
mtwist_rand (&mt) & 255,
0.5 + qfrandom (0.125) - percent * 0.40, 0.0);
if (numparticles >= r_maxparticles)
break;
@ -918,7 +922,7 @@ R_GrenadeTrail_EE (const entity_t *ent)
particle_new (pt_smoke, part_tex_smoke, old_origin,
pscale + percent * 4.0, vec3_origin,
vr_data.realtime + 2.0 - percent * 2.0,
rand () & 255,
mtwist_rand (&mt) & 255,
0.625 + qfrandom (0.125) - percent * 0.40, 0.0);
if (numparticles >= r_maxparticles)
break;
@ -963,12 +967,12 @@ R_BlobExplosion_ID (const vec3_t org)
for (i = 0; i < j >> 1; i++) {
particle_new_random (pt_blob, part_tex_dot, org, 12, 1.0, 256,
vr_data.realtime + 1.0 + (rand () & 8) * 0.05,
vr_data.realtime + 1.0 + (mtwist_rand (&mt) & 8) * 0.05,
66 + i % 6, 1.0, 0.0);
}
for (i = 0; i < j / 2; i++) {
particle_new_random (pt_blob2, part_tex_dot, org, 12, 1.0, 256,
vr_data.realtime + 1.0 + (rand () & 8) * 0.05,
vr_data.realtime + 1.0 + (mtwist_rand (&mt) & 8) * 0.05,
150 + i % 6, 1.0, 0.0);
}
}
@ -995,7 +999,7 @@ R_RunParticleEffect_ID (const vec3_t org, const vec3_t dir, int color,
count = r_maxparticles - numparticles;
for (i = 0; i < count; i++) {
int rnd = rand ();
int rnd = mtwist_rand (&mt);
porg[0] = org[0] + scale * (((rnd >> 3) & 15) - 8);
porg[1] = org[1] + scale * (((rnd >> 7) & 15) - 8);
@ -1067,7 +1071,7 @@ R_LavaSplash_ID (const vec3_t org)
dir[2] = 256;
for (i = -128; i < 128; i += 16) {
for (j = -128; j < 128; j += 16) {
rnd = rand ();
rnd = mtwist_rand (&mt);
dir[0] = j + (rnd & 7);
dir[1] = i + ((rnd >> 6) & 7);
@ -1076,7 +1080,7 @@ R_LavaSplash_ID (const vec3_t org)
porg[2] = org[2] + ((rnd >> 9) & 63);
VectorNormalize (dir);
rnd = rand ();
rnd = mtwist_rand (&mt);
vel = 50 + (rnd & 63);
VectorScale (dir, vel, pvel);
particle_new (pt_grav, part_tex_dot, porg, 1.0, pvel,
@ -1110,7 +1114,7 @@ R_TeleportSplash_ID (const vec3_t org)
VectorCopy (dir, pdir);
VectorNormalize (pdir);
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = org[0] + i + (rnd & 3);
porg[1] = org[1] + j + ((rnd >> 2) & 3);
porg[2] = org[2] + k + ((rnd >> 4) & 3);
@ -1118,7 +1122,7 @@ R_TeleportSplash_ID (const vec3_t org)
vel = 50 + ((rnd >> 6) & 63);
VectorScale (pdir, vel, pvel);
particle_new (pt_grav, part_tex_dot, porg, 1.0, pvel,
(vr_data.realtime + 0.2 + (rand () & 7) * 0.02),
(vr_data.realtime + 0.2 + (mtwist_rand (&mt) & 7) * 0.02),
(7 + ((rnd >> 12) & 7)), 1.0, 0.0);
}
}
@ -1147,7 +1151,7 @@ R_DarkFieldParticles_ID (const entity_t *ent)
dir [0] = j * 8;
for (k = 0; k < 32; k += 8) {
dir [2] = k * 8;
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = org[0] + i + ((rnd >> 3) & 3);
porg[1] = org[1] + j + ((rnd >> 5) & 3);
@ -1158,7 +1162,7 @@ R_DarkFieldParticles_ID (const entity_t *ent)
VectorScale (dir, vel, pvel);
particle_new (pt_slowgrav, part_tex_dot, porg, 1.5, pvel,
(vr_data.realtime + 0.2 + (rnd & 7) * 0.02),
(150 + rand () % 6), 1.0, 0.0);
(150 + mtwist_rand (&mt) % 6), 1.0, 0.0);
}
}
}
@ -1182,7 +1186,7 @@ R_EntityParticles_ID (const entity_t *ent)
if (!avelocities[0][0]) {
for (i = 0; i < NUMVERTEXNORMALS * 3; i++)
avelocities[0][i] = (rand () & 255) * 0.01;
avelocities[0][i] = (mtwist_rand (&mt) & 255) * 0.01;
}
for (i = 0; i < j; i++) {
@ -1229,7 +1233,7 @@ R_RocketTrail_ID (const entity_t *ent)
VectorScale (vec, (maxlen - dist), subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
org[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
org[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
org[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -1261,7 +1265,7 @@ R_GrenadeTrail_ID (const entity_t *ent)
VectorScale (vec, maxlen - dist, subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
org[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
org[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
org[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -1293,7 +1297,7 @@ R_BloodTrail_ID (const entity_t *ent)
VectorScale (vec, maxlen - dist, subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
porg[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
porg[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -1324,7 +1328,7 @@ R_SlightBloodTrail_ID (const entity_t *ent)
VectorScale (vec, maxlen - dist, subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
porg[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
porg[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -1429,7 +1433,7 @@ R_VoorTrail_ID (const entity_t *ent)
VectorScale (vec, maxlen - dist, subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = old_origin[0] + ((rnd >> 3) & 15) - 7.5;
porg[1] = old_origin[1] + ((rnd >> 7) & 15) - 7.5;
porg[2] = old_origin[2] + ((rnd >> 11) & 15) - 7.5;

View file

@ -43,6 +43,7 @@
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/image.h"
#include "QF/mersenne.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/render.h"
@ -57,6 +58,8 @@
#include "r_internal.h"
static mtstate_t mt; // private PRNG state
//FIXME not part of GLES, but needed for GL
#ifndef GL_VERTEX_PROGRAM_POINT_SIZE
# define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
@ -168,14 +171,14 @@ particle_new_random (ptype_t type, int texnum, const vec3_t org, int org_fuzz,
int rnd;
vec3_t porg, pvel;
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = o_fuzz * ((rnd & 63) - 31.5) / 63.0 + org[0];
porg[1] = o_fuzz * (((rnd >> 5) & 63) - 31.5) / 63.0 + org[1];
porg[2] = o_fuzz * (((rnd >> 9) & 63) - 31.5) / 63.0 + org[2];
rnd = rand ();
porg[1] = o_fuzz * (((rnd >> 6) & 63) - 31.5) / 63.0 + org[1];
porg[2] = o_fuzz * (((rnd >> 10) & 63) - 31.5) / 63.0 + org[2];
rnd = mtwist_rand (&mt);
pvel[0] = v_fuzz * ((rnd & 63) - 31.5) / 63.0;
pvel[1] = v_fuzz * (((rnd >> 5) & 63) - 31.5) / 63.0;
pvel[2] = v_fuzz * (((rnd >> 9) & 63) - 31.5) / 63.0;
pvel[1] = v_fuzz * (((rnd >> 6) & 63) - 31.5) / 63.0;
pvel[2] = v_fuzz * (((rnd >> 10) & 63) - 31.5) / 63.0;
particle_new (type, texnum, porg, scale, pvel, die, color, alpha, ramp);
}
@ -214,6 +217,8 @@ glsl_R_InitParticles (void)
byte data[64][64][2];
tex_t *tex;
mtwist_seed (&mt, 0xdeadbeef);
qfeglEnable (GL_VERTEX_PROGRAM_POINT_SIZE);
qfeglGetFloatv (GL_ALIASED_POINT_SIZE_RANGE, v);
Sys_MaskPrintf (SYS_GLSL, "point size: %g - %g\n", v[0], v[1]);
@ -331,7 +336,7 @@ R_ParticleExplosion_QF (const vec3_t org)
if (numparticles >= r_maxparticles)
return;
particle_new_random (pt_smokecloud, part_tex_smoke, org, 4, 30, 8,
vr_data.realtime + 5.0, (rand () & 7) + 8,
vr_data.realtime + 5.0, (mtwist_rand (&mt) & 7) + 8,
0.5 + qfrandom (0.25), 0.0);
}
@ -365,12 +370,12 @@ R_BlobExplosion_QF (const vec3_t org)
for (i = 0; i < j >> 1; i++) {
particle_new_random (pt_blob, part_tex_dot, org, 12, 2, 256,
vr_data.realtime + 1.0 + (rand () & 7) * 0.05,
vr_data.realtime + 1.0 + (mtwist_rand (&mt) & 7) * 0.05,
66 + i % 6, 1.0, 0.0);
}
for (i = 0; i < j / 2; i++) {
particle_new_random (pt_blob2, part_tex_dot, org, 12, 2, 256,
vr_data.realtime + 1.0 + (rand () & 7) * 0.05,
vr_data.realtime + 1.0 + (mtwist_rand (&mt) & 7) * 0.05,
150 + i % 6, 1.0, 0.0);
}
}
@ -381,7 +386,7 @@ R_RunSparkEffect_QF (const vec3_t org, int count, int ofuzz)
if (numparticles >= r_maxparticles)
return;
particle_new (pt_smokecloud, part_tex_smoke, org, ofuzz * 0.08,
vec3_origin, vr_data.realtime + 9, 12 + (rand () & 3),
vec3_origin, vr_data.realtime + 9, 12 + (mtwist_rand (&mt) & 3),
0.25 + qfrandom (0.125), 0.0);
if (numparticles + count >= r_maxparticles)
@ -392,7 +397,7 @@ R_RunSparkEffect_QF (const vec3_t org, int count, int ofuzz)
orgfuzz = 1;
while (count--) {
int color = rand () & 7;
int color = mtwist_rand (&mt) & 7;
particle_new_random (pt_fallfadespark, part_tex_dot, org, orgfuzz,
0.7, 96, vr_data.realtime + 5.0, ramp1[color],
@ -408,7 +413,7 @@ R_BloodPuff_QF (const vec3_t org, int count)
return;
particle_new (pt_bloodcloud, part_tex_smoke, org, count / 5, vec3_origin,
vr_data.realtime + 99.0, 70 + (rand () & 3), 0.5, 0.0);
vr_data.realtime + 99.0, 70 + (mtwist_rand (&mt) & 3), 0.5, 0.0);
}
static void
@ -436,7 +441,7 @@ R_LightningBloodEffect_QF (const vec3_t org)
if (numparticles >= r_maxparticles)
return;
particle_new (pt_smokecloud, part_tex_smoke, org, 3.0, vec3_origin,
vr_data.realtime + 9.0, 12 + (rand () & 3),
vr_data.realtime + 9.0, 12 + (mtwist_rand (&mt) & 3),
0.25 + qfrandom (0.125), 0.0);
if (numparticles + count >= r_maxparticles)
@ -464,7 +469,7 @@ R_RunParticleEffect_QF (const vec3_t org, const vec3_t dir, int color,
count = r_maxparticles - numparticles;
for (i = 0; i < count; i++) {
int rnd = rand ();
int rnd = mtwist_rand (&mt);
porg[0] = org[0] + scale * (((rnd >> 3) & 15) - 7.5);
porg[1] = org[1] + scale * (((rnd >> 7) & 15) - 7.5);
@ -539,7 +544,7 @@ R_LavaSplash_QF (const vec3_t org)
dir[2] = 256;
for (i = -128; i < 128; i += 16) {
for (j = -128; j < 128; j += 16) {
rnd = rand ();
rnd = mtwist_rand (&mt);
dir[0] = j + (rnd & 7);
dir[1] = i + ((rnd >> 6) & 7);
@ -548,7 +553,7 @@ R_LavaSplash_QF (const vec3_t org)
porg[2] = org[2] + ((rnd >> 9) & 63);
VectorNormalize (dir);
rnd = rand ();
rnd = mtwist_rand (&mt);
vel = 50.0 + 0.5 * (float) (rnd & 127);
VectorScale (dir, vel, pvel);
particle_new (pt_grav, part_tex_dot, porg, 3, pvel,
@ -582,7 +587,7 @@ R_TeleportSplash_QF (const vec3_t org)
VectorCopy (dir, pdir);
VectorNormalize (pdir);
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = org[0] + i + (rnd & 3);
porg[1] = org[1] + j + ((rnd >> 2) & 3);
porg[2] = org[2] + k + ((rnd >> 4) & 3);
@ -590,7 +595,7 @@ R_TeleportSplash_QF (const vec3_t org)
vel = 50 + ((rnd >> 6) & 63);
VectorScale (pdir, vel, pvel);
particle_new (pt_grav, part_tex_spark, porg, 0.6, pvel,
(vr_data.realtime + 0.2 + (rand () & 15) * 0.01),
(vr_data.realtime + 0.2 + (mtwist_rand (&mt) & 15) * 0.01),
(7 + ((rnd >> 12) & 7)), 1.0, 0.0);
}
}
@ -621,7 +626,7 @@ R_RocketTrail_QF (const entity_t *ent)
particle_new (pt_smoke, part_tex_smoke, old_origin,
pscale + percent * 4.0, vec3_origin,
vr_data.realtime + 2.0 - percent * 2.0,
12 + (rand () & 3),
12 + (mtwist_rand (&mt) & 3),
0.5 + qfrandom (0.125) - percent * 0.40, 0.0);
if (numparticles >= r_maxparticles)
break;
@ -655,7 +660,7 @@ R_GrenadeTrail_QF (const entity_t *ent)
particle_new (pt_smoke, part_tex_smoke, old_origin,
pscale + percent * 4.0, vec3_origin,
vr_data.realtime + 2.0 - percent * 2.0,
1 + (rand () & 3),
1 + (mtwist_rand (&mt) & 3),
0.625 + qfrandom (0.125) - percent * 0.40, 0.0);
if (numparticles >= r_maxparticles)
break;
@ -696,7 +701,7 @@ R_BloodTrail_QF (const entity_t *ent)
particle_new (pt_grav, part_tex_smoke, porg, pscale, pvel,
vr_data.realtime + 2.0 - percent * 2.0,
68 + (rand () & 3), 1.0, 0.0);
68 + (mtwist_rand (&mt) & 3), 1.0, 0.0);
if (numparticles >= r_maxparticles)
break;
len += dist;
@ -736,7 +741,7 @@ R_SlightBloodTrail_QF (const entity_t *ent)
particle_new (pt_grav, part_tex_smoke, porg, pscale, pvel,
vr_data.realtime + 1.5 - percent * 1.5,
68 + (rand () & 3), 0.75, 0.0);
68 + (mtwist_rand (&mt) & 3), 0.75, 0.0);
if (numparticles >= r_maxparticles)
break;
len += dist;
@ -778,7 +783,7 @@ R_WizTrail_QF (const entity_t *ent)
particle_new (pt_flame, part_tex_smoke, old_origin,
2.0 + qfrandom (1.0) - percent * 2.0, pvel,
vr_data.realtime + 0.5 - percent * 0.5,
52 + (rand () & 4), 1.0 - percent * 0.125, 0.0);
52 + (mtwist_rand (&mt) & 4), 1.0 - percent * 0.125, 0.0);
if (numparticles >= r_maxparticles)
break;
len += dist;
@ -852,7 +857,7 @@ R_VoorTrail_QF (const entity_t *ent)
particle_new (pt_static, part_tex_dot, porg, 1.0 + qfrandom (1.0),
vec3_origin, vr_data.realtime + 0.3 - percent * 0.3,
9 * 16 + 8 + (rand () & 3), 1.0, 0.0);
9 * 16 + 8 + (mtwist_rand (&mt) & 3), 1.0, 0.0);
if (numparticles >= r_maxparticles)
break;
len += dist;
@ -880,7 +885,7 @@ R_GlowTrail_QF (const entity_t *ent, int glow_color)
while (len < maxlen) {
percent = len * origlen;
rnd = rand ();
rnd = mtwist_rand (&mt);
org[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
org[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
org[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -904,7 +909,7 @@ R_ParticleExplosion_EE (const vec3_t org)
if (numparticles >= r_maxparticles)
return;
particle_new_random (pt_smokecloud, part_tex_smoke, org, 4, 30, 8,
vr_data.realtime + 5.0, rand () & 255,
vr_data.realtime + 5.0, mtwist_rand (&mt) & 255,
0.5 + qfrandom (0.25), 0.0);
}
@ -929,7 +934,7 @@ R_TeleportSplash_EE (const vec3_t org)
for (j = -16; j < 16; j += 4) {
dir[0] = j * 8;
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = org[0] + i + (rnd & 3);
porg[1] = org[1] + j + ((rnd >> 2) & 3);
porg[2] = org[2] + k + ((rnd >> 4) & 3);
@ -938,7 +943,7 @@ R_TeleportSplash_EE (const vec3_t org)
vel = 50 + ((rnd >> 6) & 63);
VectorScale (dir, vel, pvel);
particle_new (pt_grav, part_tex_spark, porg, 0.6, pvel,
(vr_data.realtime + 0.2 + (rand () & 15) * 0.01),
(vr_data.realtime + 0.2 + (mtwist_rand (&mt) & 15) * 0.01),
qfrandom (1.0), 1.0, 0.0);
}
}
@ -969,7 +974,7 @@ R_RocketTrail_EE (const entity_t *ent)
particle_new (pt_smoke, part_tex_smoke, old_origin,
pscale + percent * 4.0, vec3_origin,
vr_data.realtime + 2.0 - percent * 2.0,
rand () & 255,
mtwist_rand (&mt) & 255,
0.5 + qfrandom (0.125) - percent * 0.40, 0.0);
if (numparticles >= r_maxparticles)
break;
@ -1004,7 +1009,7 @@ R_GrenadeTrail_EE (const entity_t *ent)
particle_new (pt_smoke, part_tex_smoke, old_origin,
pscale + percent * 4.0, vec3_origin,
vr_data.realtime + 2.0 - percent * 2.0,
rand () & 255,
mtwist_rand (&mt) & 255,
0.625 + qfrandom (0.125) - percent * 0.40, 0.0);
if (numparticles >= r_maxparticles)
break;
@ -1049,12 +1054,12 @@ R_BlobExplosion_ID (const vec3_t org)
for (i = 0; i < j >> 1; i++) {
particle_new_random (pt_blob, part_tex_dot, org, 12, 1.0, 256,
vr_data.realtime + 1.0 + (rand () & 8) * 0.05,
vr_data.realtime + 1.0 + (mtwist_rand (&mt) & 8) * 0.05,
66 + i % 6, 1.0, 0.0);
}
for (i = 0; i < j / 2; i++) {
particle_new_random (pt_blob2, part_tex_dot, org, 12, 1.0, 256,
vr_data.realtime + 1.0 + (rand () & 8) * 0.05,
vr_data.realtime + 1.0 + (mtwist_rand (&mt) & 8) * 0.05,
150 + i % 6, 1.0, 0.0);
}
}
@ -1081,7 +1086,7 @@ R_RunParticleEffect_ID (const vec3_t org, const vec3_t dir, int color,
count = r_maxparticles - numparticles;
for (i = 0; i < count; i++) {
int rnd = rand ();
int rnd = mtwist_rand (&mt);
porg[0] = org[0] + scale * (((rnd >> 3) & 15) - 8);
porg[1] = org[1] + scale * (((rnd >> 7) & 15) - 8);
@ -1153,7 +1158,7 @@ R_LavaSplash_ID (const vec3_t org)
dir[2] = 256;
for (i = -128; i < 128; i += 16) {
for (j = -128; j < 128; j += 16) {
rnd = rand ();
rnd = mtwist_rand (&mt);
dir[0] = j + (rnd & 7);
dir[1] = i + ((rnd >> 6) & 7);
@ -1162,7 +1167,7 @@ R_LavaSplash_ID (const vec3_t org)
porg[2] = org[2] + ((rnd >> 9) & 63);
VectorNormalize (dir);
rnd = rand ();
rnd = mtwist_rand (&mt);
vel = 50 + (rnd & 63);
VectorScale (dir, vel, pvel);
particle_new (pt_grav, part_tex_dot, porg, 1.0, pvel,
@ -1196,7 +1201,7 @@ R_TeleportSplash_ID (const vec3_t org)
VectorCopy (dir, pdir);
VectorNormalize (pdir);
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = org[0] + i + (rnd & 3);
porg[1] = org[1] + j + ((rnd >> 2) & 3);
porg[2] = org[2] + k + ((rnd >> 4) & 3);
@ -1204,7 +1209,7 @@ R_TeleportSplash_ID (const vec3_t org)
vel = 50 + ((rnd >> 6) & 63);
VectorScale (pdir, vel, pvel);
particle_new (pt_grav, part_tex_dot, porg, 1.0, pvel,
(vr_data.realtime + 0.2 + (rand () & 7) * 0.02),
(vr_data.realtime + 0.2 + (mtwist_rand (&mt) & 7) * 0.02),
(7 + ((rnd >> 12) & 7)), 1.0, 0.0);
}
}
@ -1233,7 +1238,7 @@ R_DarkFieldParticles_ID (const entity_t *ent)
dir [0] = j * 8;
for (k = 0; k < 32; k += 8) {
dir [2] = k * 8;
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = org[0] + i + ((rnd >> 3) & 3);
porg[1] = org[1] + j + ((rnd >> 5) & 3);
@ -1244,7 +1249,7 @@ R_DarkFieldParticles_ID (const entity_t *ent)
VectorScale (dir, vel, pvel);
particle_new (pt_slowgrav, part_tex_dot, porg, 1.5, pvel,
(vr_data.realtime + 0.2 + (rnd & 7) * 0.02),
(150 + rand () % 6), 1.0, 0.0);
(150 + mtwist_rand (&mt) % 6), 1.0, 0.0);
}
}
}
@ -1268,7 +1273,7 @@ R_EntityParticles_ID (const entity_t *ent)
if (!avelocities[0][0]) {
for (i = 0; i < NUMVERTEXNORMALS * 3; i++)
avelocities[0][i] = (rand () & 255) * 0.01;
avelocities[0][i] = (mtwist_rand (&mt) & 255) * 0.01;
}
for (i = 0; i < j; i++) {
@ -1315,7 +1320,7 @@ R_RocketTrail_ID (const entity_t *ent)
VectorScale (vec, (maxlen - dist), subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
org[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
org[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
org[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -1347,7 +1352,7 @@ R_GrenadeTrail_ID (const entity_t *ent)
VectorScale (vec, maxlen - dist, subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
org[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
org[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
org[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -1379,7 +1384,7 @@ R_BloodTrail_ID (const entity_t *ent)
VectorScale (vec, maxlen - dist, subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
porg[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
porg[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -1410,7 +1415,7 @@ R_SlightBloodTrail_ID (const entity_t *ent)
VectorScale (vec, maxlen - dist, subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = old_origin[0] + ((rnd >> 12) & 7) * (5.0/7.0) - 2.5;
porg[1] = old_origin[1] + ((rnd >> 9) & 7) * (5.0/7.0) - 2.5;
porg[2] = old_origin[2] + ((rnd >> 6) & 7) * (5.0/7.0) - 2.5;
@ -1515,7 +1520,7 @@ R_VoorTrail_ID (const entity_t *ent)
VectorScale (vec, maxlen - dist, subtract);
while (len < maxlen) {
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = old_origin[0] + ((rnd >> 3) & 15) - 7.5;
porg[1] = old_origin[1] + ((rnd >> 7) & 15) - 7.5;
porg[2] = old_origin[2] + ((rnd >> 11) & 15) - 7.5;

View file

@ -37,6 +37,7 @@
#endif
#include "QF/cvar.h"
#include "QF/mersenne.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/render.h"
@ -50,10 +51,12 @@ static int ramp1[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 };
//static int ramp2[8] = { 0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66 };
static int ramp3[8] = { 0x6d, 0x6b, 6, 5, 4, 3 };
static mtstate_t mt; // private PRNG state
void
R_InitParticles (void)
{
mtwist_seed (&mt, 0xdeadbeef);
}
void
@ -145,15 +148,15 @@ R_ParticleExplosion_QF (const vec3_t org)
p->die = vr_data.realtime + 5;
p->color = ramp1[0];
p->ramp = rand () & 3;
p->ramp = mtwist_rand (&mt) & 3;
if (i & 1)
p->type = pt_explode;
else
p->type = pt_explode2;
p->phys = R_ParticlePhysics (p->type);
for (j = 0; j < 3; j++) {
p->org[j] = org[j] + ((rand () % 32) - 16);
p->vel[j] = (rand () % 512) - 256;
p->org[j] = org[j] + ((mtwist_rand (&mt) % 32) - 16);
p->vel[j] = (mtwist_rand (&mt) % 512) - 256;
}
}
}
@ -180,8 +183,8 @@ R_ParticleExplosion2_QF (const vec3_t org, int colorStart, int colorLength)
p->type = pt_blob;
p->phys = R_ParticlePhysics (p->type);
for (j=0 ; j<3 ; j++) {
p->org[j] = org[j] + ((rand()%32)-16);
p->vel[j] = (rand()%512)-256;
p->org[j] = org[j] + ((mtwist_rand (&mt)%32)-16);
p->vel[j] = (mtwist_rand (&mt)%512)-256;
}
}
}
@ -203,19 +206,19 @@ R_BlobExplosion_QF (const vec3_t org)
p->next = active_particles;
active_particles = p;
p->die = vr_data.realtime + 1 + (rand () & 8) * 0.05;
p->die = vr_data.realtime + 1 + (mtwist_rand (&mt) & 8) * 0.05;
if (i & 1) {
p->type = pt_blob;
p->color = 66 + rand () % 6;
p->color = 66 + mtwist_rand (&mt) % 6;
} else {
p->type = pt_blob2;
p->color = 150 + rand () % 6;
p->color = 150 + mtwist_rand (&mt) % 6;
}
p->phys = R_ParticlePhysics (p->type);
for (j = 0; j < 3; j++) {
p->org[j] = org[j] + ((rand () % 32) - 16);
p->vel[j] = (rand () % 512) - 256;
p->org[j] = org[j] + ((mtwist_rand (&mt) % 32) - 16);
p->vel[j] = (mtwist_rand (&mt) % 512) - 256;
}
}
}
@ -238,13 +241,13 @@ R_RunParticleEffect_QF (const vec3_t org, const vec3_t dir, int color,
p->next = active_particles;
active_particles = p;
p->die = vr_data.realtime + 0.1 * (rand () % 5);
p->color = (color & ~7) + (rand () & 7);
p->die = vr_data.realtime + 0.1 * (mtwist_rand (&mt) % 5);
p->color = (color & ~7) + (mtwist_rand (&mt) & 7);
p->type = pt_grav;
p->phys = R_ParticlePhysics (p->type);
for (j = 0; j < 3; j++) {
p->org[j] = org[j] + ((rand () & 15) - 8);
p->vel[j] = dir[j]; // + (rand()%300)-150;
p->org[j] = org[j] + ((mtwist_rand (&mt) & 15) - 8);
p->vel[j] = dir[j]; // + (mtwist_rand (&mt)%300)-150;
}
}
}
@ -312,21 +315,21 @@ R_LavaSplash_QF (const vec3_t org)
p->next = active_particles;
active_particles = p;
p->die = vr_data.realtime + 2 + (rand () & 31) * 0.02;
p->color = 224 + (rand () & 7);
p->die = vr_data.realtime + 2 + (mtwist_rand (&mt) & 31) * 0.02;
p->color = 224 + (mtwist_rand (&mt) & 7);
p->type = pt_grav;
p->phys = R_ParticlePhysics (p->type);
dir[0] = j * 8 + (rand () & 7);
dir[1] = i * 8 + (rand () & 7);
dir[0] = j * 8 + (mtwist_rand (&mt) & 7);
dir[1] = i * 8 + (mtwist_rand (&mt) & 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);
p->org[2] = org[2] + (mtwist_rand (&mt) & 63);
VectorNormalize (dir);
vel = 50 + (rand () & 63);
vel = 50 + (mtwist_rand (&mt) & 63);
VectorScale (dir, vel, p->vel);
}
}
@ -352,8 +355,8 @@ R_TeleportSplash_QF (const vec3_t org)
p->next = active_particles;
active_particles = p;
p->die = vr_data.realtime + 0.2 + (rand () & 7) * 0.02;
p->color = 7 + (rand () & 7);
p->die = vr_data.realtime + 0.2 + (mtwist_rand (&mt) & 7) * 0.02;
p->color = 7 + (mtwist_rand (&mt) & 7);
p->type = pt_grav;
p->phys = R_ParticlePhysics (p->type);
@ -361,12 +364,12 @@ R_TeleportSplash_QF (const vec3_t org)
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);
p->org[0] = org[0] + i + (mtwist_rand (&mt) & 3);
p->org[1] = org[1] + j + (mtwist_rand (&mt) & 3);
p->org[2] = org[2] + k + (mtwist_rand (&mt) & 3);
VectorNormalize (dir);
vel = 50 + (rand () & 63);
vel = 50 + (mtwist_rand (&mt) & 63);
VectorScale (dir, vel, p->vel);
}
}
@ -396,10 +399,10 @@ R_DarkFieldParticles_ID (const entity_t *ent)
p->next = active_particles;
active_particles = p;
rnd = rand ();
rnd = mtwist_rand (&mt);
p->die = vr_data.realtime + 0.2 + (rnd & 7) * 0.02;
p->color = 150 + rand () % 6;
p->color = 150 + mtwist_rand (&mt) % 6;
p->type = pt_slowgrav;
p->phys = R_ParticlePhysics (p->type);
dir[0] = j * 8;
@ -434,7 +437,7 @@ R_EntityParticles_ID (const entity_t *ent)
if (!avelocities[0][0]) {
for (i = 0; i < NUMVERTEXNORMALS * 3; i++)
avelocities[0][i] = (rand () & 255) * 0.01;
avelocities[0][i] = (mtwist_rand (&mt) & 255) * 0.01;
}
for (i = 0; i < NUMVERTEXNORMALS; i++) {
@ -502,12 +505,12 @@ R_RocketTrail_QF (const entity_t *ent)
VectorZero (p->vel);
p->die = vr_data.realtime + 2;
p->ramp = (rand () & 3);
p->ramp = (mtwist_rand (&mt) & 3);
p->color = ramp3[(int) p->ramp];
p->type = pt_fire;
p->phys = R_ParticlePhysics (p->type);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () % 6) - 3);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) % 6) - 3);
VectorAdd (old_origin, vec, old_origin);
}
@ -541,12 +544,12 @@ R_GrenadeTrail_QF (const entity_t *ent)
VectorZero (p->vel);
p->die = vr_data.realtime + 2;
p->ramp = (rand () & 3) + 2;
p->ramp = (mtwist_rand (&mt) & 3) + 2;
p->color = ramp3[(int) p->ramp];
p->type = pt_fire;
p->phys = R_ParticlePhysics (p->type);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () % 6) - 3);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) % 6) - 3);
VectorAdd (old_origin, vec, old_origin);
}
@ -582,9 +585,9 @@ R_BloodTrail_QF (const entity_t *ent)
p->die = vr_data.realtime + 2;
p->type = pt_slowgrav;
p->phys = R_ParticlePhysics (p->type);
p->color = 67 + (rand () & 3);
p->color = 67 + (mtwist_rand (&mt) & 3);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () % 6) - 3);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) % 6) - 3);
break;
VectorAdd (old_origin, vec, old_origin);
@ -621,9 +624,9 @@ R_SlightBloodTrail_QF (const entity_t *ent)
p->die = vr_data.realtime + 2;
p->type = pt_slowgrav;
p->phys = R_ParticlePhysics (p->type);
p->color = 67 + (rand () & 3);
p->color = 67 + (mtwist_rand (&mt) & 3);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () % 6) - 3);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) % 6) - 3);
VectorAdd (old_origin, vec, old_origin);
}
@ -753,9 +756,9 @@ R_VoorTrail_QF (const entity_t *ent)
p->die = vr_data.realtime + 0.3;
p->type = pt_static;
p->phys = R_ParticlePhysics (p->type);
p->color = 9 * 16 + 8 + (rand () & 3);
p->color = 9 * 16 + 8 + (mtwist_rand (&mt) & 3);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () & 15) - 8);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) & 15) - 8);
VectorAdd (old_origin, vec, old_origin);
}
@ -905,14 +908,14 @@ R_Particle_NewRandom (ptype_t type, int texnum, const vec3_t org, int org_fuzz,
int rnd;
vec3_t porg, pvel;
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = o_fuzz * ((rnd & 63) - 31.5) / 63.0 + org[0];
porg[1] = o_fuzz * (((rnd >> 5) & 63) - 31.5) / 63.0 + org[1];
porg[2] = o_fuzz * (((rnd >> 9) & 63) - 31.5) / 63.0 + org[2];
rnd = rand ();
porg[1] = o_fuzz * (((rnd >> 6) & 63) - 31.5) / 63.0 + org[1];
porg[2] = o_fuzz * (((rnd >> 10) & 63) - 31.5) / 63.0 + org[2];
rnd = mtwist_rand (&mt);
pvel[0] = v_fuzz * ((rnd & 63) - 31.5) / 63.0;
pvel[1] = v_fuzz * (((rnd >> 5) & 63) - 31.5) / 63.0;
pvel[2] = v_fuzz * (((rnd >> 9) & 63) - 31.5) / 63.0;
pvel[1] = v_fuzz * (((rnd >> 6) & 63) - 31.5) / 63.0;
pvel[2] = v_fuzz * (((rnd >> 10) & 63) - 31.5) / 63.0;
R_Particle_New (type, texnum, porg, scale, pvel, die, color, alpha, ramp);
}

View file

@ -40,6 +40,7 @@
#endif
#include "QF/cvar.h"
#include "QF/mersenne.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/render.h"
@ -53,10 +54,13 @@ static int ramp1[8] = { 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61 };
//static int ramp2[8] = { 0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66 };
static int ramp3[8] = { 0x6d, 0x6b, 6, 5, 4, 3 };
static mtstate_t mt; // private PRNG state
void
sw32_R_InitParticles (void)
{
mtwist_seed (&mt, 0xdeadbeef);
}
void
@ -149,18 +153,18 @@ R_ParticleExplosion_QF (const vec3_t org)
p->die = vr_data.realtime + 5;
p->color = ramp1[0];
p->ramp = rand () & 3;
p->ramp = mtwist_rand (&mt) & 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;
p->org[j] = org[j] + ((mtwist_rand (&mt) % 32) - 16);
p->vel[j] = (mtwist_rand (&mt) % 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;
p->org[j] = org[j] + ((mtwist_rand (&mt) % 32) - 16);
p->vel[j] = (mtwist_rand (&mt) % 512) - 256;
}
}
p->phys = R_ParticlePhysics (p->type);
@ -191,8 +195,8 @@ R_ParticleExplosion2_QF (const vec3_t org, int colorStart, int colorLength)
p->phys = R_ParticlePhysics (p->type);
for (j=0 ; j<3 ; j++)
{
p->org[j] = org[j] + ((rand()%32)-16);
p->vel[j] = (rand()%512)-256;
p->org[j] = org[j] + ((mtwist_rand (&mt)%32)-16);
p->vel[j] = (mtwist_rand (&mt)%512)-256;
}
}
}
@ -214,21 +218,21 @@ R_BlobExplosion_QF (const vec3_t org)
p->next = active_particles;
active_particles = p;
p->die = vr_data.realtime + 1 + (rand () & 8) * 0.05;
p->die = vr_data.realtime + 1 + (mtwist_rand (&mt) & 8) * 0.05;
if (i & 1) {
p->type = pt_blob;
p->color = 66 + rand () % 6;
p->color = 66 + mtwist_rand (&mt) % 6;
for (j = 0; j < 3; j++) {
p->org[j] = org[j] + ((rand () % 32) - 16);
p->vel[j] = (rand () % 512) - 256;
p->org[j] = org[j] + ((mtwist_rand (&mt) % 32) - 16);
p->vel[j] = (mtwist_rand (&mt) % 512) - 256;
}
} else {
p->type = pt_blob2;
p->color = 150 + rand () % 6;
p->color = 150 + mtwist_rand (&mt) % 6;
for (j = 0; j < 3; j++) {
p->org[j] = org[j] + ((rand () % 32) - 16);
p->vel[j] = (rand () % 512) - 256;
p->org[j] = org[j] + ((mtwist_rand (&mt) % 32) - 16);
p->vel[j] = (mtwist_rand (&mt) % 512) - 256;
}
}
p->phys = R_ParticlePhysics (p->type);
@ -256,21 +260,21 @@ R_LavaSplash_QF (const vec3_t org)
p->next = active_particles;
active_particles = p;
p->die = vr_data.realtime + 2 + (rand () & 31) * 0.02;
p->color = 224 + (rand () & 7);
p->die = vr_data.realtime + 2 + (mtwist_rand (&mt) & 31) * 0.02;
p->color = 224 + (mtwist_rand (&mt) & 7);
p->type = pt_grav;
p->phys = R_ParticlePhysics (p->type);
dir[0] = j * 8 + (rand () & 7);
dir[1] = i * 8 + (rand () & 7);
dir[0] = j * 8 + (mtwist_rand (&mt) & 7);
dir[1] = i * 8 + (mtwist_rand (&mt) & 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);
p->org[2] = org[2] + (mtwist_rand (&mt) & 63);
VectorNormalize (dir);
vel = 50 + (rand () & 63);
vel = 50 + (mtwist_rand (&mt) & 63);
VectorScale (dir, vel, p->vel);
}
}
@ -296,8 +300,8 @@ R_TeleportSplash_QF (const vec3_t org)
p->next = active_particles;
active_particles = p;
p->die = vr_data.realtime + 0.2 + (rand () & 7) * 0.02;
p->color = 7 + (rand () & 7);
p->die = vr_data.realtime + 0.2 + (mtwist_rand (&mt) & 7) * 0.02;
p->color = 7 + (mtwist_rand (&mt) & 7);
p->type = pt_grav;
p->phys = R_ParticlePhysics (p->type);
@ -305,12 +309,12 @@ R_TeleportSplash_QF (const vec3_t org)
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);
p->org[0] = org[0] + i + (mtwist_rand (&mt) & 3);
p->org[1] = org[1] + j + (mtwist_rand (&mt) & 3);
p->org[2] = org[2] + k + (mtwist_rand (&mt) & 3);
VectorNormalize (dir);
vel = 50 + (rand () & 63);
vel = 50 + (mtwist_rand (&mt) & 63);
VectorScale (dir, vel, p->vel);
}
}
@ -339,10 +343,10 @@ R_DarkFieldParticles_ID (const entity_t *ent)
p->next = active_particles;
active_particles = p;
rnd = rand ();
rnd = mtwist_rand (&mt);
p->die = vr_data.realtime + 0.2 + (rnd & 7) * 0.02;
p->color = 150 + rand () % 6;
p->color = 150 + mtwist_rand (&mt) % 6;
p->type = pt_slowgrav;
p->phys = R_ParticlePhysics (p->type);
@ -375,7 +379,7 @@ R_EntityParticles_ID (const entity_t *ent)
if (!avelocities[0][0]) {
for (i = 0; i < NUMVERTEXNORMALS * 3; i++)
avelocities[0][i] = (rand () & 255) * 0.01;
avelocities[0][i] = (mtwist_rand (&mt) & 255) * 0.01;
}
for (i = 0; i < NUMVERTEXNORMALS; i++) {
@ -433,13 +437,13 @@ R_RunParticleEffect_QF (const vec3_t org, const vec3_t dir, int color,
p->next = active_particles;
active_particles = p;
p->die = vr_data.realtime + 0.1 * (rand () % 5);
p->color = (color & ~7) + (rand () & 7);
p->die = vr_data.realtime + 0.1 * (mtwist_rand (&mt) % 5);
p->color = (color & ~7) + (mtwist_rand (&mt) & 7);
p->type = pt_slowgrav;
p->phys = R_ParticlePhysics (p->type);
for (j = 0; j < 3; j++) {
p->org[j] = org[j] + ((rand () & 15) - 8);
p->vel[j] = dir[j]; // + (rand()%300)-150;
p->org[j] = org[j] + ((mtwist_rand (&mt) & 15) - 8);
p->vel[j] = dir[j]; // + (mtwist_rand (&mt)%300)-150;
}
}
}
@ -514,12 +518,12 @@ R_RocketTrail_QF (const entity_t *ent)
VectorZero (p->vel);
p->die = vr_data.realtime + 2;
p->ramp = (rand () & 3);
p->ramp = (mtwist_rand (&mt) & 3);
p->color = ramp3[(int) p->ramp];
p->type = pt_fire;
p->phys = R_ParticlePhysics (p->type);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () % 6) - 3);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) % 6) - 3);
VectorAdd (old_origin, vec, old_origin);
}
@ -553,12 +557,12 @@ R_GrenadeTrail_QF (const entity_t *ent)
VectorZero (p->vel);
p->die = vr_data.realtime + 2;
p->ramp = (rand () & 3) + 2;
p->ramp = (mtwist_rand (&mt) & 3) + 2;
p->color = ramp3[(int) p->ramp];
p->type = pt_fire;
p->phys = R_ParticlePhysics (p->type);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () % 6) - 3);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) % 6) - 3);
VectorAdd (old_origin, vec, old_origin);
}
@ -594,9 +598,9 @@ R_BloodTrail_QF (const entity_t *ent)
p->die = vr_data.realtime + 2;
p->type = pt_slowgrav;
p->phys = R_ParticlePhysics (p->type);
p->color = 67 + (rand () & 3);
p->color = 67 + (mtwist_rand (&mt) & 3);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () % 6) - 3);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) % 6) - 3);
break;
VectorAdd (old_origin, vec, old_origin);
@ -633,9 +637,9 @@ R_SlightBloodTrail_QF (const entity_t *ent)
p->die = vr_data.realtime + 2;
p->type = pt_slowgrav;
p->phys = R_ParticlePhysics (p->type);
p->color = 67 + (rand () & 3);
p->color = 67 + (mtwist_rand (&mt) & 3);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () % 6) - 3);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) % 6) - 3);
VectorAdd (old_origin, vec, old_origin);
}
@ -765,9 +769,9 @@ R_VoorTrail_QF (const entity_t *ent)
p->die = vr_data.realtime + 0.3;
p->type = pt_static;
p->phys = R_ParticlePhysics (p->type);
p->color = 9 * 16 + 8 + (rand () & 3);
p->color = 9 * 16 + 8 + (mtwist_rand (&mt) & 3);
for (j = 0; j < 3; j++)
p->org[j] = old_origin[j] + ((rand () & 15) - 8);
p->org[j] = old_origin[j] + ((mtwist_rand (&mt) & 15) - 8);
VectorAdd (old_origin, vec, old_origin);
}
@ -918,14 +922,14 @@ sw32_R_Particle_NewRandom (ptype_t type, int texnum, const vec3_t org,
int rnd;
vec3_t porg, pvel;
rnd = rand ();
rnd = mtwist_rand (&mt);
porg[0] = o_fuzz * ((rnd & 63) - 31.5) / 63.0 + org[0];
porg[1] = o_fuzz * (((rnd >> 5) & 63) - 31.5) / 63.0 + org[1];
porg[2] = o_fuzz * (((rnd >> 9) & 63) - 31.5) / 63.0 + org[2];
rnd = rand ();
porg[1] = o_fuzz * (((rnd >> 6) & 63) - 31.5) / 63.0 + org[1];
porg[2] = o_fuzz * (((rnd >> 12) & 63) - 31.5) / 63.0 + org[2];
rnd = mtwist_rand (&mt);
pvel[0] = v_fuzz * ((rnd & 63) - 31.5) / 63.0;
pvel[1] = v_fuzz * (((rnd >> 5) & 63) - 31.5) / 63.0;
pvel[2] = v_fuzz * (((rnd >> 9) & 63) - 31.5) / 63.0;
pvel[1] = v_fuzz * (((rnd >> 6) & 63) - 31.5) / 63.0;
pvel[2] = v_fuzz * (((rnd >> 12) & 63) - 31.5) / 63.0;
sw32_R_Particle_New (type, texnum, porg, scale, pvel, die, color, alpha, ramp);
}