From 0abb8a7554c04918d3b89b05d457e99ee5204063 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 15 Jan 2012 20:14:36 +0900 Subject: [PATCH] Merge the particle physics. --- include/d_iface.h | 12 +- libs/video/renderer/gl/gl_dyn_part.c | 118 +------------- libs/video/renderer/r_part.c | 213 ++++++++++++++++++++++++++ libs/video/renderer/sw/sw_rpart.c | 81 +++------- libs/video/renderer/sw32/sw32_rpart.c | 82 +++------- 5 files changed, 260 insertions(+), 246 deletions(-) diff --git a/include/d_iface.h b/include/d_iface.h index 4e5e1c588..68b699441 100644 --- a/include/d_iface.h +++ b/include/d_iface.h @@ -70,8 +70,13 @@ typedef enum { part_tex_smoke, } ptextype_t; +typedef struct particle_s particle_t; +typedef void (*pt_phys_func)(particle_t *); + +pt_phys_func R_ParticlePhysics (ptype_t type); + // !!! if this is changed, it must be changed in d_ifacea.h too !!! -typedef struct particle_s +struct particle_s { // driver-usable fields vec3_t org; @@ -84,8 +89,9 @@ typedef struct particle_s ptype_t type; float die; float ramp; - struct particle_s *next; -} particle_t; + pt_phys_func phys; + particle_t *next; +}; #define PARTICLE_Z_CLIP 8.0 diff --git a/libs/video/renderer/gl/gl_dyn_part.c b/libs/video/renderer/gl/gl_dyn_part.c index 138ede815..05d5b09c7 100644 --- a/libs/video/renderer/gl/gl_dyn_part.c +++ b/libs/video/renderer/gl/gl_dyn_part.c @@ -95,6 +95,7 @@ particle_new (ptype_t type, int texnum, const vec3_t org, float scale, part->type = type; part->die = die; part->ramp = ramp; + part->phys = R_ParticlePhysics (type); } /* @@ -1443,121 +1444,6 @@ R_VoorTrail_ID (const entity_t *ent) } } -static void -R_ParticlePhysics (particle_t *part) -{ - float grav, fast_grav, - time_125, time_25, time_40, time_55, time2, time4, time5, - time10, time15, time30, time50; - grav = (fast_grav = r_frametime * r_gravity) * 0.05; - time_125 = r_frametime * 0.125; - time_25= r_frametime * 0.25; - time_40 = r_frametime * 0.40; - time_55 = r_frametime * 0.55; - time2 = r_frametime * 2.0; - time4 = r_frametime * 4.0; - time5 = r_frametime * 5.0; - time10 = r_frametime * 10.0; - time15 = r_frametime * 15.0; - time30 = r_frametime * 30.0; - time50 = r_frametime * 50.0; - - VectorMultAdd (part->org, r_frametime, part->vel, part->org); - switch (part->type) { - case pt_static: - break; - case pt_grav: - part->vel[2] -= grav; - break; - case pt_fire: - part->ramp += time5; - if (part->ramp >= 6) { - part->die = -1; - break; - } - part->color = ramp3[(int) part->ramp]; - part->alpha = (6.0 - part->ramp) / 6.0; - part->vel[2] += grav; - break; - case pt_explode: - part->ramp += time10; - if (part->ramp >= 8) { - part->die = -1; - break; - } - part->color = ramp1[(int) part->ramp]; - VectorMultAdd (part->vel, time4, part->vel, part->vel); - part->vel[2] -= grav; - break; - case pt_explode2: - part->ramp += time15; - if (part->ramp >= 8) { - part->die = -1; - break; - } - part->color = ramp2[(int) part->ramp]; - VectorMultSub (part->vel, r_frametime, part->vel, part->vel); - part->vel[2] -= grav; - break; - case pt_blob: - VectorMultAdd (part->vel, time4, part->vel, part->vel); - part->vel[2] -= grav; - break; - case pt_blob2: - part->vel[0] -= part->vel[0] * time4; - part->vel[1] -= part->vel[1] * time4; - part->vel[2] -= grav; - break; - case pt_smoke: - if ((part->alpha -= time_40) <= 0.0) - part->die = -1; - part->scale += time4; -// part->org[2] += time30; - break; - case pt_smokecloud: - if ((part->alpha -= time_55) <= 0.0) { - part->die = -1; - break; - } - part->scale += time50; - part->org[2] += time30; - break; - case pt_bloodcloud: - if ((part->alpha -= time_25) <= 0.0) { - part->die = -1; - break; - } - part->scale += time4; - part->vel[2] -= grav; - break; - case pt_fallfade: - if ((part->alpha -= r_frametime) <= 0.0) - part->die = -1; - part->vel[2] -= fast_grav; - break; - case pt_fallfadespark: - part->ramp += time15; - if (part->ramp >= 8) { - part->die = -1; - break; - } - part->color = ramp1[(int) part->ramp]; - if ((part->alpha -= r_frametime) <= 0.0) - part->die = -1; - part->vel[2] -= fast_grav; - break; - case pt_flame: - if ((part->alpha -= time_125) <= 0.0) - part->die = -1; - part->scale -= time2; - break; - default: - Sys_MaskPrintf (SYS_DEV, "unhandled particle type %d\n", - part->type); - break; - } -} - void R_DrawParticles (void) { @@ -1656,7 +1542,7 @@ R_DrawParticles (void) } } - R_ParticlePhysics (part); + part->phys (part); // LordHavoc: immediate removal of unnecessary particles (must be done // to ensure compactor below operates properly in all cases) diff --git a/libs/video/renderer/r_part.c b/libs/video/renderer/r_part.c index 51e36ed78..68bb2c009 100644 --- a/libs/video/renderer/r_part.c +++ b/libs/video/renderer/r_part.c @@ -34,6 +34,7 @@ static __attribute__ ((used)) const char rcsid[] = #include "QF/cvar.h" #include "QF/qargs.h" #include "QF/render.h" +#include "QF/sys.h" #include "compat.h" #include "r_dynamic.h" @@ -113,3 +114,215 @@ R_MaxParticlesCheck (cvar_t *r_particles, cvar_t *r_particles_max) if (r_init) R_InitParticles (); } + +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, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + +static inline float +grav (void) +{ + return r_frametime * r_gravity * 0.05; +} + +static inline float +fast_grav (void) +{ + return r_frametime * r_gravity; +} + +static inline void +add_vel (particle_t *part) +{ + VectorMultAdd (part->org, r_frametime, part->vel, part->org); +} + +static inline void +add_grav (particle_t *part) +{ + part->vel[2] -= grav (); +} + +static inline void +sub_grav (particle_t *part) +{ + part->vel[2] -= grav (); +} + +static inline void +add_fastgrav (particle_t *part) +{ + part->vel[2] -= fast_grav (); +} + +static inline qboolean +add_ramp (particle_t *part, float time, int max) +{ + part->ramp += r_frametime * time; + if (part->ramp >= max) { + part->die = -1; + return true; + } + return false; +} + +static inline qboolean +fade_alpha (particle_t *part, float time) +{ + part->alpha -= r_frametime * time; + if (part->alpha <= 0.0) { + part->die = -1; + return true; + } + return false; +} + +static void +part_phys_static (particle_t *part) +{ + add_vel (part); +} + +static void +part_phys_grav (particle_t *part) +{ + add_vel (part); + add_grav (part); +} + +static void +part_phys_fire (particle_t *part) +{ + if (add_ramp (part, 5.0, 6)) + return; + add_vel (part); + part->color = ramp3[(int) part->ramp]; + part->alpha = (6.0 - part->ramp) / 6.0; + sub_grav (part); +} + +static void +part_phys_explode (particle_t *part) +{ + if (add_ramp (part, 10.0, 8)) + return; + add_vel (part); + part->color = ramp1[(int) part->ramp]; + VectorMultAdd (part->vel, r_frametime * 4.0, part->vel, part->vel); + add_grav (part); +} + +static void +part_phys_explode2 (particle_t *part) +{ + if (add_ramp (part, 15.0, 8)) + return; + add_vel (part); + part->color = ramp2[(int) part->ramp]; + VectorMultAdd (part->vel, r_frametime, part->vel, part->vel); + add_grav (part); +} + +static void +part_phys_blob (particle_t *part) +{ + add_vel (part); + VectorMultAdd (part->vel, r_frametime * 4.0, part->vel, part->vel); + add_grav (part); +} + +static void +part_phys_blob2 (particle_t *part) +{ + add_vel (part); + part->vel[0] -= part->vel[0] * r_frametime * 4.0; + part->vel[1] -= part->vel[1] * r_frametime * 4.0; + add_grav (part); +} + +static void +part_phys_smoke (particle_t *part) +{ + if (fade_alpha (part, 0.4)) + return; + add_vel (part); + part->scale += r_frametime * 4.0; + //part->org[2] += r_frametime * 30.0; +} + +static void +part_phys_smokecloud (particle_t *part) +{ + if (fade_alpha (part, 0.55)) + return; + add_vel (part); + part->scale += r_frametime * 50.0; + part->vel[2] += r_frametime * 30.0; +} + +static void +part_phys_bloodcloud (particle_t *part) +{ + if (fade_alpha (part, 0.25)) + return; + add_vel (part); + part->scale += r_frametime * 4.0; + add_grav (part); +} + +static void +part_phys_fallfade (particle_t *part) +{ + if (fade_alpha (part, 1.0)) + return; + add_vel (part); + add_fastgrav (part); +} + +static void +part_phys_fallfadespark (particle_t *part) +{ + if (add_ramp (part, 15.0, 8)) + return; + if (fade_alpha (part, 1.0)) + return; + part->color = ramp1[(int) part->ramp]; + add_vel (part); + add_fastgrav (part); +} + +static void +part_phys_flame (particle_t *part) +{ + if (fade_alpha (part, 0.125)) + return; + add_vel (part); + part->scale -= r_frametime * 2.0; +} + +static pt_phys_func part_phys[] = { + part_phys_static, + part_phys_grav, + part_phys_grav, // pt_slowgrav + part_phys_fire, + part_phys_explode, + part_phys_explode2, + part_phys_blob, + part_phys_blob2, + part_phys_smoke, + part_phys_smokecloud, + part_phys_bloodcloud, + part_phys_static, // pt_fadespark + part_phys_static, // pt_fadespark2 + part_phys_fallfade, + part_phys_fallfadespark, + part_phys_flame, +}; + +pt_phys_func +R_ParticlePhysics (ptype_t type) +{ + if (type < pt_static || type > pt_flame) + Sys_Error ("R_ParticlePhysics: invalid particle type"); + return part_phys[type]; +} diff --git a/libs/video/renderer/sw/sw_rpart.c b/libs/video/renderer/sw/sw_rpart.c index cef06b961..52465632c 100644 --- a/libs/video/renderer/sw/sw_rpart.c +++ b/libs/video/renderer/sw/sw_rpart.c @@ -122,6 +122,7 @@ R_ReadPointFile_f (void) p->die = 99999; p->color = (-c) & 15; p->type = pt_static; + p->phys = R_ParticlePhysics (p->type); VectorZero (p->vel); VectorCopy (org, p->org); } @@ -154,6 +155,7 @@ R_ParticleExplosion_QF (const vec3_t org) 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; @@ -181,6 +183,7 @@ R_ParticleExplosion2_QF (const vec3_t org, int colorStart, int colorLength) colorMod++; 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; @@ -214,6 +217,7 @@ R_BlobExplosion_QF (const vec3_t org) p->type = pt_blob2; p->color = 150 + rand () % 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; @@ -242,6 +246,7 @@ R_RunParticleEffect_QF (const vec3_t org, const vec3_t dir, int color, p->die = r_realtime + 0.1 * (rand () % 5); p->color = (color & ~7) + (rand () & 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; @@ -315,6 +320,7 @@ R_LavaSplash_QF (const vec3_t org) p->die = r_realtime + 2 + (rand () & 31) * 0.02; p->color = 224 + (rand () & 7); p->type = pt_grav; + p->phys = R_ParticlePhysics (p->type); dir[0] = j * 8 + (rand () & 7); dir[1] = i * 8 + (rand () & 7); @@ -354,6 +360,7 @@ R_TeleportSplash_QF (const vec3_t org) p->die = r_realtime + 0.2 + (rand () & 7) * 0.02; p->color = 7 + (rand () & 7); p->type = pt_grav; + p->phys = R_ParticlePhysics (p->type); dir[0] = j * 8; dir[1] = i * 8; @@ -399,6 +406,7 @@ R_DarkFieldParticles_ID (const entity_t *ent) p->die = r_realtime + 0.2 + (rnd & 7) * 0.02; p->color = 150 + rand () % 6; p->type = pt_slowgrav; + p->phys = R_ParticlePhysics (p->type); dir[0] = j * 8; dir[1] = i * 8; dir[2] = k * 8; @@ -460,6 +468,7 @@ R_EntityParticles_ID (const entity_t *ent) p->die = r_realtime + 0.01; p->color = 0x6f; p->type = pt_explode; + p->phys = R_ParticlePhysics (p->type); p->org[0] = ent->origin[0] + r_avertexnormals[i][0] * dist + forward[0] * beamlength; @@ -501,6 +510,7 @@ R_RocketTrail_QF (const entity_t *ent) p->ramp = (rand () & 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); @@ -539,6 +549,7 @@ R_GrenadeTrail_QF (const entity_t *ent) p->ramp = (rand () & 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); @@ -575,6 +586,7 @@ R_BloodTrail_QF (const entity_t *ent) p->die = r_realtime + 2; p->type = pt_slowgrav; + p->phys = R_ParticlePhysics (p->type); p->color = 67 + (rand () & 3); for (j = 0; j < 3; j++) p->org[j] = old_origin[j] + ((rand () % 6) - 3); @@ -613,6 +625,7 @@ R_SlightBloodTrail_QF (const entity_t *ent) p->die = r_realtime + 2; p->type = pt_slowgrav; + p->phys = R_ParticlePhysics (p->type); p->color = 67 + (rand () & 3); for (j = 0; j < 3; j++) p->org[j] = old_origin[j] + ((rand () % 6) - 3); @@ -649,6 +662,7 @@ R_WizTrail_QF (const entity_t *ent) p->die = r_realtime + 0.5; p->type = pt_static; + p->phys = R_ParticlePhysics (p->type); p->color = 52 + ((tracercount & 4) << 1); tracercount++; @@ -695,6 +709,7 @@ R_FlameTrail_QF (const entity_t *ent) p->die = r_realtime + 0.5; p->type = pt_static; + p->phys = R_ParticlePhysics (p->type); p->color = 230 + ((tracercount & 4) << 1); tracercount++; @@ -742,6 +757,7 @@ R_VoorTrail_QF (const entity_t *ent) p->die = r_realtime + 0.3; p->type = pt_static; + p->phys = R_ParticlePhysics (p->type); p->color = 9 * 16 + 8 + (rand () & 3); for (j = 0; j < 3; j++) p->org[j] = old_origin[j] + ((rand () & 15) - 8); @@ -753,21 +769,12 @@ R_VoorTrail_QF (const entity_t *ent) void R_DrawParticles (void) { - int i; - float dvel, frametime, grav, time1, time2, time3; particle_t *p, **particle; VectorScale (vright, xscaleshrink, r_pright); VectorScale (vup, yscaleshrink, r_pup); VectorCopy (vpn, r_ppn); - frametime = r_frametime; - time3 = frametime * 15; - time2 = frametime * 10; // 15; - time1 = frametime * 5; - grav = frametime * r_gravity * 0.05; - dvel = 4 * frametime; - for (particle = &active_particles; *particle;) { if ((*particle)->die < r_realtime) { p = (*particle)->next; @@ -780,60 +787,7 @@ R_DrawParticles (void) D_DrawParticle (p); - 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; - default: - Sys_MaskPrintf (SYS_DEV, "unhandled particle type %d\n", - p->type); - break; - } + p->phys (p); } } } @@ -904,6 +858,7 @@ R_Particle_New (ptype_t type, int texnum, const vec3_t org, float scale, p->alpha = alpha; VectorCopy (vel, p->vel); p->type = type; + p->phys = R_ParticlePhysics (p->type); p->die = die; p->ramp = ramp; } diff --git a/libs/video/renderer/sw32/sw32_rpart.c b/libs/video/renderer/sw32/sw32_rpart.c index 4ddd54da9..9c363efac 100644 --- a/libs/video/renderer/sw32/sw32_rpart.c +++ b/libs/video/renderer/sw32/sw32_rpart.c @@ -123,6 +123,7 @@ R_ReadPointFile_f (void) p->die = 99999; p->color = (-c) & 15; p->type = pt_static; + p->phys = R_ParticlePhysics (p->type); VectorZero (p->vel); VectorCopy (org, p->org); } @@ -164,6 +165,7 @@ R_ParticleExplosion_QF (const vec3_t org) p->vel[j] = (rand () % 512) - 256; } } + p->phys = R_ParticlePhysics (p->type); } } @@ -188,6 +190,7 @@ R_ParticleExplosion2_QF (const vec3_t org, int colorStart, int colorLength) colorMod++; p->type = pt_blob; + p->phys = R_ParticlePhysics (p->type); for (j=0 ; j<3 ; j++) { p->org[j] = org[j] + ((rand()%32)-16); @@ -230,6 +233,7 @@ R_BlobExplosion_QF (const vec3_t org) p->vel[j] = (rand () % 512) - 256; } } + p->phys = R_ParticlePhysics (p->type); } } @@ -257,6 +261,7 @@ R_LavaSplash_QF (const vec3_t org) p->die = r_realtime + 2 + (rand () & 31) * 0.02; p->color = 224 + (rand () & 7); p->type = pt_grav; + p->phys = R_ParticlePhysics (p->type); dir[0] = j * 8 + (rand () & 7); dir[1] = i * 8 + (rand () & 7); @@ -296,6 +301,7 @@ R_TeleportSplash_QF (const vec3_t org) p->die = r_realtime + 0.2 + (rand () & 7) * 0.02; p->color = 7 + (rand () & 7); p->type = pt_grav; + p->phys = R_ParticlePhysics (p->type); dir[0] = j * 8; dir[1] = i * 8; @@ -340,6 +346,7 @@ R_DarkFieldParticles_ID (const entity_t *ent) p->die = r_realtime + 0.2 + (rnd & 7) * 0.02; p->color = 150 + rand () % 6; p->type = pt_slowgrav; + p->phys = R_ParticlePhysics (p->type); dir[0] = j * 8; dir[1] = i * 8; @@ -399,6 +406,7 @@ R_EntityParticles_ID (const entity_t *ent) p->die = r_realtime + 0.01; p->color = 0x6f; p->type = pt_explode; + p->phys = R_ParticlePhysics (p->type); p->org[0] = ent->origin[0] + r_avertexnormals[i][0] * dist + forward[0] * beamlength; @@ -430,6 +438,7 @@ R_RunParticleEffect_QF (const vec3_t org, const vec3_t dir, int color, p->die = r_realtime + 0.1 * (rand () % 5); p->color = (color & ~7) + (rand () & 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; @@ -510,6 +519,7 @@ R_RocketTrail_QF (const entity_t *ent) p->ramp = (rand () & 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); @@ -548,6 +558,7 @@ R_GrenadeTrail_QF (const entity_t *ent) p->ramp = (rand () & 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); @@ -584,6 +595,7 @@ R_BloodTrail_QF (const entity_t *ent) p->die = r_realtime + 2; p->type = pt_slowgrav; + p->phys = R_ParticlePhysics (p->type); p->color = 67 + (rand () & 3); for (j = 0; j < 3; j++) p->org[j] = old_origin[j] + ((rand () % 6) - 3); @@ -622,6 +634,7 @@ R_SlightBloodTrail_QF (const entity_t *ent) p->die = r_realtime + 2; p->type = pt_slowgrav; + p->phys = R_ParticlePhysics (p->type); p->color = 67 + (rand () & 3); for (j = 0; j < 3; j++) p->org[j] = old_origin[j] + ((rand () % 6) - 3); @@ -658,6 +671,7 @@ R_WizTrail_QF (const entity_t *ent) p->die = r_realtime + 0.5; p->type = pt_static; + p->phys = R_ParticlePhysics (p->type); p->color = 52 + ((tracercount & 4) << 1); tracercount++; @@ -704,6 +718,7 @@ R_FlameTrail_QF (const entity_t *ent) p->die = r_realtime + 0.5; p->type = pt_static; + p->phys = R_ParticlePhysics (p->type); p->color = 230 + ((tracercount & 4) << 1); tracercount++; @@ -751,6 +766,7 @@ R_VoorTrail_QF (const entity_t *ent) p->die = r_realtime + 0.3; p->type = pt_static; + p->phys = R_ParticlePhysics (p->type); p->color = 9 * 16 + 8 + (rand () & 3); for (j = 0; j < 3; j++) p->org[j] = old_origin[j] + ((rand () & 15) - 8); @@ -762,21 +778,12 @@ R_VoorTrail_QF (const entity_t *ent) void R_DrawParticles (void) { - float dvel, grav, frametime, time1, time2, time3; - int i; particle_t *p, **particle; VectorScale (vright, xscaleshrink, r_pright); VectorScale (vup, yscaleshrink, r_pup); VectorCopy (vpn, r_ppn); - frametime = r_frametime; - time3 = frametime * 15; - time2 = frametime * 10; // 15; - time1 = frametime * 5; - grav = frametime * r_gravity * 0.05; - dvel = 4 * frametime; - for (particle = &active_particles; *particle;) { if ((*particle)->die < r_realtime) { p = (*particle)->next; @@ -789,61 +796,7 @@ R_DrawParticles (void) D_DrawParticle (p); - 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; - default: - Sys_MaskPrintf (SYS_DEV, "unhandled particle type %d\n", - p->type); - break; - } + p->phys (p); } } } @@ -914,6 +867,7 @@ R_Particle_New (ptype_t type, int texnum, const vec3_t org, float scale, p->alpha = alpha; VectorCopy (vel, p->vel); p->type = type; + p->phys = R_ParticlePhysics (p->type); p->die = die; p->ramp = ramp; }