]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_particles.c
Cleaned up alot more memory leaks. (still get 720 leaks just running demo1.dem)
[xonotic/darkplaces.git] / cl_particles.c
index 4fe3bb1bf0e6797ae8ed42e20c4628e8043a1323..2278100ac3e9e0ae0b438f372a818d1cc0bd9230 100644 (file)
@@ -180,7 +180,7 @@ float CL_TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int
 
 typedef enum
 {
-       pt_dead, pt_static, pt_rain, pt_bubble, pt_blood, pt_grow, pt_decal, pt_decalfade, pt_ember
+       pt_dead, pt_static, pt_rain, pt_bubble, pt_blood, pt_grow, pt_decal, pt_ember
 }
 ptype_t;
 
@@ -371,6 +371,15 @@ void CL_Particles_Init (void)
        CL_Particles_Clear();
 }
 
+void CL_Particles_Shutdown (void)
+{
+#ifdef WORKINGLQUAKE
+       // No clue what to do here...
+#else
+       Mem_FreePool (&cl_part_mempool);
+#endif
+}
+
 // 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)
@@ -782,46 +791,53 @@ void CL_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
 CL_SparkShower
 ===============
 */
-void CL_SparkShower (vec3_t org, vec3_t dir, int count)
+void CL_SparkShower (vec3_t org, vec3_t dir, int count, vec_t gravityscale)
 {
-       vec3_t org2, org3;
        int k;
 
-       if (cl_stainmaps.integer)
-               R_Stain(org, 32, 96, 96, 96, 24, 128, 128, 128, 24);
-       CL_SpawnDecalParticleForPoint(org, 6, 3, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF);
-
        if (!cl_particles.integer) return;
 
-       if (cl_particles_bulletimpacts.integer)
+       if (cl_particles_sparks.integer)
        {
-               // smoke puff
-               if (cl_particles_smoke.integer)
+               // sparks
+               count *= cl_particles_quality.value;
+               while(count--)
                {
-                       k = count * 0.25 * cl_particles_quality.value;
-                       while(k--)
-                       {
-                               org2[0] = org[0] + 0.125f * lhrandom(-count, count);
-                               org2[1] = org[1] + 0.125f * lhrandom(-count, count);
-                               org2[2] = org[2] + 0.125f * lhrandom(-count, count);
-                               CL_TraceLine(org, org2, org3, NULL, true, NULL, SUPERCONTENTS_SOLID);
-                               particle(pt_grow, PARTICLE_BILLBOARD, 0x101010, 0x202020, tex_smoke[rand()&7], true, PBLEND_ADD, 3, 3, (1.0f / cl_particles_quality.value) * 255, (1.0f / cl_particles_quality.value) * 1024, 9999, -0.2, 0, org3[0], org3[1], org3[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(0, 16), 15, 0, 0, 0, 0.2, 0);
-                       }
+                       k = particlepalette[0x68 + (rand() & 7)];
+                       particle(pt_static, PARTICLE_SPARK, k, k, tex_particle, false, PBLEND_ADD, 0.4f, 0.015f, (1.0f / cl_particles_quality.value) * lhrandom(64, 255), (1.0f / cl_particles_quality.value) * 512, 9999, gravityscale, 0, org[0], org[1], org[2], lhrandom(-64, 64) + dir[0], lhrandom(-64, 64) + dir[1], lhrandom(0, 128) + dir[2], 0, 0, 0, 0, 0, 0);
                }
+       }
+}
+
+void CL_Smoke (vec3_t org, vec3_t dir, int count)
+{
+       vec3_t org2, org3;
+       int k;
 
-               if (cl_particles_sparks.integer)
+       if (!cl_particles.integer) return;
+
+       // smoke puff
+       if (cl_particles_smoke.integer)
+       {
+               k = count * 0.25 * cl_particles_quality.value;
+               while(k--)
                {
-                       // sparks
-                       count *= cl_particles_quality.value;
-                       while(count--)
-                       {
-                               k = particlepalette[0x68 + (rand() & 7)];
-                               particle(pt_static, PARTICLE_SPARK, k, k, tex_particle, false, PBLEND_ADD, 0.4f, 0.015f, (1.0f / cl_particles_quality.value) * lhrandom(64, 255), (1.0f / cl_particles_quality.value) * 512, 9999, 1, 0, org[0], org[1], org[2], lhrandom(-64, 64) + dir[0], lhrandom(-64, 64) + dir[1], lhrandom(0, 128) + dir[2], 0, 0, 0, 0, 0.2, 0);
-                       }
+                       org2[0] = org[0] + 0.125f * lhrandom(-count, count);
+                       org2[1] = org[1] + 0.125f * lhrandom(-count, count);
+                       org2[2] = org[2] + 0.125f * lhrandom(-count, count);
+                       CL_TraceLine(org, org2, org3, NULL, true, NULL, SUPERCONTENTS_SOLID);
+                       particle(pt_grow, PARTICLE_BILLBOARD, 0x101010, 0x202020, tex_smoke[rand()&7], true, PBLEND_ADD, 3, 3, (1.0f / cl_particles_quality.value) * 255, (1.0f / cl_particles_quality.value) * 1024, 9999, 0, 0, org3[0], org3[1], org3[2], lhrandom(-8, 8), lhrandom(-8, 8), lhrandom(-8, 8), 15, 0, 0, 0, 0, 0);
                }
        }
 }
 
+void CL_BulletMark (vec3_t org)
+{
+       if (cl_stainmaps.integer)
+               R_Stain(org, 32, 96, 96, 96, 24, 128, 128, 128, 24);
+       CL_SpawnDecalParticleForPoint(org, 6, 3, 255, tex_bulletdecal[rand()&7], 0xFFFFFF, 0xFFFFFF);
+}
+
 void CL_PlasmaBurn (vec3_t org)
 {
        if (cl_stainmaps.integer)
@@ -1342,8 +1358,8 @@ void CL_MoveParticles (void)
                                        Matrix4x4_Transform3x3(&hitent->inversematrix, normal, p->relativedirection);
                                        VectorAdd(p->relativeorigin, p->relativedirection, p->relativeorigin);
 #endif
-                                       p->time2 = cl.time + cl_decals_time.value;
-                                       p->die = p->time2 + cl_decals_fadetime.value;
+                                       p->time2 = cl.time;
+                                       p->die = p->time2 + cl_decals_time.value + cl_decals_fadetime.value;
                                        p->alphafade = 0;
                                        VectorCopy(normal, p->vel2);
                                        VectorClear(p->vel);
@@ -1436,22 +1452,7 @@ void CL_MoveParticles (void)
                                p->scaley += frametime * p->time2;
                                break;
                        case pt_decal:
-#ifndef WORKINGLQUAKE
-                               if (p->owner->model == p->ownermodel)
-                               {
-                                       Matrix4x4_Transform(&p->owner->matrix, p->relativeorigin, p->org);
-                                       Matrix4x4_Transform3x3(&p->owner->matrix, p->relativedirection, p->vel2);
-                                       if (cl.time > p->time2)
-                                       {
-                                               p->alphafade = p->alpha / (p->die - cl.time);
-                                               p->type = pt_decalfade;
-                                       }
-                               }
-                               else
-                                       p->type = pt_dead;
-#endif
-                               break;
-                       case pt_decalfade:
+                               p->alphafade = cl.time > (p->time2 + cl_decals_time.value) ? (p->alpha / cl_decals_fadetime.value) : 0;
 #ifndef WORKINGLQUAKE
                                if (p->owner->model == p->ownermodel)
                                {
@@ -2018,7 +2019,12 @@ void R_DrawParticles (void)
                {
                        c_particles++;
                        if (DotProduct(p->org, r_viewforward) >= minparticledist || p->orientation == PARTICLE_BEAM)
-                               R_MeshQueue_AddTransparent(p->org, R_DrawParticleCallback, p, 0);
+                       {
+                               if (p->type == pt_decal)
+                                       R_DrawParticleCallback(p, 0);
+                               else
+                                       R_MeshQueue_AddTransparent(p->org, R_DrawParticleCallback, p, 0);
+                       }
                }
        }
 #endif