]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_particles.c
Added a mempool parameter to FS_LoadFile
[xonotic/darkplaces.git] / cl_particles.c
index 59b745fb7ece70b8239284b2d5d25bda2fa6a5cc..790abe05826c89efc035c87814271b1fde9f032f 100644 (file)
@@ -49,12 +49,12 @@ void R_CalcBeam_Vertex3f (float *vert, vec3_t org1, vec3_t org2, float width)
        VectorNormalizeFast (normal);
 
        // calculate 'right' vector for start
-       VectorSubtract (r_origin, org1, diff);
+       VectorSubtract (r_vieworigin, org1, diff);
        VectorNormalizeFast (diff);
        CrossProduct (normal, diff, right1);
 
        // calculate 'right' vector for end
-       VectorSubtract (r_origin, org2, diff);
+       VectorSubtract (r_vieworigin, org2, diff);
        VectorNormalizeFast (diff);
        CrossProduct (normal, diff, right2);
 
@@ -184,15 +184,22 @@ typedef enum
 }
 ptype_t;
 
-#define PARTICLE_INVALID 0
-#define PARTICLE_BILLBOARD 1
-#define PARTICLE_SPARK 2
-#define PARTICLE_ORIENTED_DOUBLESIDED 3
-#define PARTICLE_BEAM 4
+typedef enum
+{
+       PARTICLE_BILLBOARD = 0,
+       PARTICLE_SPARK = 1,
+       PARTICLE_ORIENTED_DOUBLESIDED = 2,
+       PARTICLE_BEAM = 3
+}
+porientation_t;
 
-#define PBLEND_ALPHA 0
-#define PBLEND_ADD 1
-#define PBLEND_MOD 2
+typedef enum
+{
+       PBLEND_ALPHA = 0,
+       PBLEND_ADD = 1,
+       PBLEND_MOD = 2
+}
+pblend_t;
 
 typedef struct particle_s
 {
@@ -284,6 +291,7 @@ cvar_t cl_particles_size = {CVAR_SAVE, "cl_particles_size", "1"};
 cvar_t cl_particles_bloodshowers = {CVAR_SAVE, "cl_particles_bloodshowers", "1"};
 cvar_t cl_particles_blood = {CVAR_SAVE, "cl_particles_blood", "1"};
 cvar_t cl_particles_blood_alpha = {CVAR_SAVE, "cl_particles_blood_alpha", "0.5"};
+cvar_t cl_particles_blood_bloodhack = {CVAR_SAVE, "cl_particles_blood_bloodhack", "1"};
 cvar_t cl_particles_bulletimpacts = {CVAR_SAVE, "cl_particles_bulletimpacts", "1"};
 cvar_t cl_particles_smoke = {CVAR_SAVE, "cl_particles_smoke", "1"};
 cvar_t cl_particles_smoke_alpha = {CVAR_SAVE, "cl_particles_smoke_alpha", "0.5"};
@@ -332,6 +340,7 @@ void CL_Particles_Init (void)
        Cvar_RegisterVariable (&cl_particles_bloodshowers);
        Cvar_RegisterVariable (&cl_particles_blood);
        Cvar_RegisterVariable (&cl_particles_blood_alpha);
+       Cvar_RegisterVariable (&cl_particles_blood_bloodhack);
        Cvar_RegisterVariable (&cl_particles_bulletimpacts);
        Cvar_RegisterVariable (&cl_particles_smoke);
        Cvar_RegisterVariable (&cl_particles_smoke_alpha);
@@ -353,7 +362,26 @@ void CL_Particles_Init (void)
        cl_numparticles = 0;
 }
 
-particle_t *particle(int ptype, int porientation, int pcolor1, int pcolor2, int ptex, int plight, int pblendmode, float pscalex, float pscaley, float palpha, float palphafade, float ptime, float pgravity, float pbounce, float px, float py, float pz, float pvx, float pvy, float pvz, float ptime2, float pvx2, float pvy2, float pvz2, float pfriction, float ppressure)
+// list of all 26 parameters:
+// ptype - any of the pt_ enum values (pt_static, pt_blood, etc), see ptype_t near the top of this file
+// porientation - PARTICLE_ enum values (PARTICLE_BILLBOARD, PARTICLE_SPARK, etc)
+// pcolor1,pcolor2 - minimum and maximum ranges of color, randomly interpolated to decide particle color
+// ptex - any of the tex_ values such as tex_smoke[rand()&7] or tex_particle
+// plight - no longer used (this used to turn on particle lighting)
+// pblendmode - PBLEND_ enum values (PBLEND_ALPHA, PBLEND_ADD, etc)
+// pscalex,pscaley - width and height of particle (according to orientation), these are normally the same except when making sparks and beams
+// palpha - opacity of particle as 0-255 (can be more than 255)
+// palphafade - rate of fade per second (so 256 would mean a 256 alpha particle would fade to nothing in 1 second)
+// ptime - how long the particle can live (note it is also removed if alpha drops to nothing)
+// pgravity - how much effect gravity has on the particle (0-1)
+// pbounce - how much bounce the particle has when it hits a surface (0-1), -1 makes a blood splat when it hits a surface, 0 does not even check for collisions
+// px,py,pz - starting origin of particle
+// pvx,pvy,pvz - starting velocity of particle
+// ptime2 - extra time parameter for certain particle types (pt_decal delayed fades and pt_rain snowflutter use this)
+// pvx2,pvy2,pvz2 - for PARTICLE_ORIENTED_DOUBLESIDED this is the surface normal of the orientation (forward vector), pt_rain uses this for snow fluttering
+// pfriction - how much the particle slows down per second (0-1 typically, can slowdown faster than 1)
+// ppressure - pushes other particles away if they are within 64 units distance, the force is based on scalex, this feature is supported but not currently used
+particle_t *particle(ptype_t ptype, porientation_t porientation, int pcolor1, int pcolor2, int ptex, int plight, pblend_t pblendmode, float pscalex, float pscaley, float palpha, float palphafade, float ptime, float pgravity, float pbounce, float px, float py, float pz, float pvx, float pvy, float pvz, float ptime2, float pvx2, float pvy2, float pvz2, float pfriction, float ppressure)
 {
        if (cl_numparticles < cl_maxparticles)
        {
@@ -514,15 +542,15 @@ void CL_ReadPointFile_f (void)
 #if WORKINGLQUAKE
        pointfile = COM_LoadTempFile (name);
 #else
-       pointfile = FS_LoadFile(name, true);
+       pointfile = FS_LoadFile(name, tempmempool, true);
 #endif
        if (!pointfile)
        {
-               Con_Printf ("Could not open %s\n", name);
+               Con_Printf("Could not open %s\n", name);
                return;
        }
 
-       Con_Printf ("Reading %s...\n", name);
+       Con_Printf("Reading %s...\n", name);
        c = 0;
        s = 0;
        pointfilepos = pointfile;
@@ -556,7 +584,7 @@ void CL_ReadPointFile_f (void)
        Mem_Free(pointfile);
 #endif
        VectorCopy(leakorg, org);
-       Con_Printf ("%i points read (%i particles spawned)\nLeak at %f %f %f\n", c, s, org[0], org[1], org[2]);
+       Con_Printf("%i points read (%i particles spawned)\nLeak at %f %f %f\n", c, s, org[0], org[1], org[2]);
 
        particle(pt_static, PARTICLE_BEAM, 0xFF0000, 0xFF0000, tex_beam, false, PBLEND_ALPHA, 64, 64, 255, 0, 99999, 0, 0, org[0] - 4096, org[1], org[2], 0, 0, 0, 0, org[0] + 4096, org[1], org[2], 0, 0);
        particle(pt_static, PARTICLE_BEAM, 0x00FF00, 0x00FF00, tex_beam, false, PBLEND_ALPHA, 64, 64, 255, 0, 99999, 0, 0, org[0], org[1] - 4096, org[2], 0, 0, 0, 0, org[0], org[1] + 4096, org[2], 0, 0);
@@ -575,8 +603,7 @@ void CL_ParseParticleEffect (void)
        vec3_t org, dir;
        int i, count, msgcount, color;
 
-       for (i=0 ; i<3 ; i++)
-               org[i] = MSG_ReadCoord ();
+       MSG_ReadVector(org);
        for (i=0 ; i<3 ; i++)
                dir[i] = MSG_ReadChar () * (1.0/16);
        msgcount = MSG_ReadByte ();
@@ -587,6 +614,21 @@ void CL_ParseParticleEffect (void)
        else
                count = msgcount;
 
+       if (cl_particles_blood_bloodhack.integer)
+       {
+               if (color == 73)
+               {
+                       // regular blood
+                       CL_BloodPuff(org, dir, count / 2);
+                       return;
+               }
+               if (color == 225)
+               {
+                       // lightning blood
+                       CL_BloodPuff(org, dir, count / 2);
+                       return;
+               }
+       }
        CL_RunParticleEffect (org, dir, color, count);
 }
 
@@ -779,7 +821,7 @@ void CL_BloodPuff (vec3_t org, vec3_t vel, int count)
        if (!cl_particles.integer) return;
        if (!cl_particles_blood.integer) return;
 
-       s = count + 32.0f;
+       s = count + 64.0f;
        count *= 5.0f;
        if (count > 1000)
                count = 1000;
@@ -1062,7 +1104,9 @@ void CL_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
        // if we skip out, leave it reset
        ent->persistent.trail_time = 0.0f;
 
-       speed = 1.0f / (ent->state_current.time - ent->state_previous.time);
+       speed = ent->state_current.time - ent->state_previous.time;
+       if (speed)
+               speed = 1.0f / speed;
        VectorSubtract(ent->state_current.origin, ent->state_previous.origin, vel);
 #endif
        VectorScale(vel, speed, vel);
@@ -1819,7 +1863,7 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2)
 #ifndef WORKINGLQUAKE
        if (fogenabled && p->blendmode != PBLEND_MOD)
        {
-               VectorSubtract(org, r_origin, fogvec);
+               VectorSubtract(org, r_vieworigin, fogvec);
                fog = exp(fogdensity/DotProduct(fogvec,fogvec));
                ifog = 1 - fog;
                cr = cr * ifog;
@@ -1833,14 +1877,15 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2)
                }
        }
 
-       GL_Color(cr, cg, cb, ca);
-
        R_Mesh_Matrix(&r_identitymatrix);
 
        memset(&m, 0, sizeof(m));
        m.tex[0] = R_GetTexture(tex->texture);
        m.pointer_texcoord[0] = particle_texcoord2f;
-       R_Mesh_State_Texture(&m);
+       m.pointer_vertex = particle_vertex3f;
+       R_Mesh_State(&m);
+
+       GL_Color(cr, cg, cb, ca);
 
        if (p->blendmode == 0)
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -1850,14 +1895,13 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2)
                GL_BlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
        GL_DepthMask(false);
        GL_DepthTest(true);
-       GL_VertexPointer(particle_vertex3f);
 #endif
        if (p->orientation == PARTICLE_BILLBOARD || p->orientation == PARTICLE_ORIENTED_DOUBLESIDED)
        {
                if (p->orientation == PARTICLE_ORIENTED_DOUBLESIDED)
                {
                        // double-sided
-                       if (DotProduct(p->vel2, r_origin) > DotProduct(p->vel2, org))
+                       if (DotProduct(p->vel2, r_vieworigin) > DotProduct(p->vel2, org))
                        {
                                VectorNegate(p->vel2, v);
                                VectorVectors(v, right, up);
@@ -1869,8 +1913,8 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2)
                }
                else
                {
-                       VectorScale(vright, p->scalex, right);
-                       VectorScale(vup, p->scaley, up);
+                       VectorScale(r_viewleft, -p->scalex, right);
+                       VectorScale(r_viewup, p->scaley, up);
                }
                particle_vertex3f[ 0] = org[0] - right[0] - up[0];
                particle_vertex3f[ 1] = org[1] - right[1] - up[1];
@@ -1947,7 +1991,7 @@ void R_DrawParticles (void)
        if ((!cl_numparticles) || (!r_drawparticles.integer))
                return;
 
-       minparticledist = DotProduct(r_origin, vpn) + 4.0f;
+       minparticledist = DotProduct(r_vieworigin, r_viewforward) + 4.0f;
 
 #ifdef WORKINGLQUAKE
        glBindTexture(GL_TEXTURE_2D, particlefonttexture);
@@ -1956,7 +2000,7 @@ void R_DrawParticles (void)
        glDepthMask(0);
        // LordHavoc: only render if not too close
        for (i = 0, p = particles;i < cl_numparticles;i++, p++)
-               if (DotProduct(p->org, vpn) >= minparticledist)
+               if (DotProduct(p->org, r_viewforward) >= minparticledist)
                        R_DrawParticle(p);
        glDepthMask(1);
        glDisable(GL_BLEND);
@@ -1965,7 +2009,7 @@ void R_DrawParticles (void)
        // LordHavoc: only render if not too close
        c_particles += cl_numparticles;
        for (i = 0, p = particles;i < cl_numparticles;i++, p++)
-               if (DotProduct(p->org, vpn) >= minparticledist || p->orientation == PARTICLE_BEAM)
+               if (DotProduct(p->org, r_viewforward) >= minparticledist || p->orientation == PARTICLE_BEAM)
                        R_MeshQueue_AddTransparent(p->org, R_DrawParticleCallback, p, 0);
 #endif
 }