]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
fixed broken trails (introduced by my attempt to fix them)
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 4 May 2007 07:01:34 +0000 (07:01 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 4 May 2007 07:01:34 +0000 (07:01 +0000)
fixed a bug where attachments to viewmodelforclient entities would show
up in the world in chase_active 1 mode near 0 0 0
rain particles now trace ahead at spawn and only begin collision
checking when near the impact time

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7228 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
cl_parse.c
cl_particles.c
client.h

index e15cb454dec44144d56d7073c4f81d439984bc22..994fe164d2f326979a06ac8b33eb406e5ecdb4e8 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -1094,10 +1094,8 @@ void CL_UpdateNetworkEntityTrail(entity_t *e)
        // do trails
        if (e->render.flags & RENDER_GLOWTRAIL)
                trailtype = EFFECT_TR_GLOWTRAIL;
-       // be sure to check for changes in e->state_previous.active and
-       // modelindex so that entities which did not exist in the previous
-       // frame don't create a trail from the start location
-       if (trailtype && e->state_previous.active && e->state_previous.modelindex == e->state_current.modelindex)
+       // check if a trail is allowed (it is not after a teleport for example)
+       if (trailtype && e->persistent.trail_allowed)
        {
                float len;
                vec3_t vel;
@@ -1108,6 +1106,9 @@ void CL_UpdateNetworkEntityTrail(entity_t *e)
                VectorScale(vel, len, vel);
                CL_ParticleTrail(trailtype, 1, e->persistent.trail_origin, origin, vel, vel, e, e->state_current.glowcolor, false, true);
        }
+       // now that the entity has survived one trail update it is allowed to
+       // leave a real trail on later frames
+       e->persistent.trail_allowed = true;
        VectorCopy(origin, e->persistent.trail_origin);
 }
 
@@ -1235,12 +1236,7 @@ void CL_LinkNetworkEntity(entity_t *e)
        // skip inactive entities and world
        if (!e->state_current.active || e == cl.entities)
                return;
-       if (e->render.flags & RENDER_VIEWMODEL && !e->state_current.tagentity)
-       {
-               if (!r_drawviewmodel.integer || chase_active.integer || r_refdef.envmap)
-                       return;
-       }
-       else
+       if (e->state_current.tagentity)
        {
                // if the tag entity is currently impossible, skip it
                if (e->state_current.tagentity >= cl.num_entities)
@@ -1384,6 +1380,10 @@ void CL_LinkNetworkEntity(entity_t *e)
        if (trailtype)
                CL_ParticleTrail(trailtype, 0, origin, origin, vec3_origin, vec3_origin, NULL, e->state_current.glowcolor, true, false);
 
+       // don't show viewmodels in certain situations
+       if (e->render.flags & RENDER_VIEWMODEL)
+               if (!r_drawviewmodel.integer || chase_active.integer || r_refdef.envmap)
+                       return;
        // don't show entities with no modelindex (note: this still shows
        // entities which have a modelindex that resolved to a NULL model)
        if (e->render.model && !(e->render.effects & EF_NODRAW) && r_refdef.numentities < r_refdef.maxentities)
index 968a3d1dfa8122346acdfd671b490bc506990c59..c77cd252c770fe66fc41fde00676d69ccc980ade 100644 (file)
@@ -1626,6 +1626,7 @@ void CL_MoveLerpEntityStates(entity_t *ent)
                ent->render.framelerp = 1;
                // reset various persistent stuff
                ent->persistent.muzzleflash = 0;
+               ent->persistent.trail_allowed = false;
        }
        else if (DotProduct(odelta, odelta) > 1000*1000 || (cl.fixangle[0] && !cl.fixangle[1]))
        {
@@ -1638,6 +1639,7 @@ void CL_MoveLerpEntityStates(entity_t *ent)
                VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
                VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
                VectorCopy(ent->state_current.angles, ent->persistent.newangles);
+               ent->persistent.trail_allowed = false;
        }
        else if (ent->state_current.flags & RENDER_STEP)
        {
index 033ea7067b72be6474044d8616b39d051d397df8..df8b318eeee801c90efcf3c05a2939762652e9c0 100644 (file)
@@ -491,6 +491,7 @@ static particle_t *particle(particletype_t *ptype, int pcolor1, int pcolor2, int
        part->time2 = 0;
        part->airfriction = pairfriction;
        part->liquidfriction = pliquidfriction;
+       part->delayedcollisions = 0;
        return part;
 }
 
@@ -1062,6 +1063,7 @@ void CL_ParticleTrail(int effectnameindex, float pcount, const vec3_t originmins
                int supercontents;
                int tex;
                particleeffectinfo_t *info;
+               particle_t *p;
                vec3_t center;
                vec3_t centervelocity;
                vec3_t traildir;
@@ -1070,6 +1072,7 @@ void CL_ParticleTrail(int effectnameindex, float pcount, const vec3_t originmins
                vec_t traillen;
                vec_t trailstep;
                qboolean underwater;
+               trace_t trace;
                // note this runs multiple effects with the same name, each one spawns only one kind of particle, so some effects need more than one
                VectorLerp(originmins, 0.5, originmaxs, center);
                VectorLerp(velocitymins, 0.5, velocitymaxs, centervelocity);
@@ -1165,7 +1168,15 @@ void CL_ParticleTrail(int effectnameindex, float pcount, const vec3_t originmins
                                                        trailpos[2] = lhrandom(originmins[2], originmaxs[2]);
                                                }
                                                VectorRandom(rvec);
-                                               particle(particletype + info->particletype, info->color[0], info->color[1], tex, lhrandom(info->size[0], info->size[1]), info->size[2], lhrandom(info->alpha[0], info->alpha[1]), info->alpha[2], info->gravity, info->bounce, trailpos[0] + info->originoffset[0] + info->originjitter[0] * rvec[0], trailpos[1] + info->originoffset[1] + info->originjitter[1] * rvec[1], trailpos[2] + info->originoffset[2] + info->originjitter[2] * rvec[2], lhrandom(velocitymins[0], velocitymaxs[0]) * info->velocitymultiplier + info->velocityoffset[0] + info->velocityjitter[0] * rvec[0], lhrandom(velocitymins[1], velocitymaxs[1]) * info->velocitymultiplier + info->velocityoffset[1] + info->velocityjitter[1] * rvec[1], lhrandom(velocitymins[2], velocitymaxs[2]) * info->velocitymultiplier + info->velocityoffset[2] + info->velocityjitter[2] * rvec[2], info->airfriction, info->liquidfriction, 0, 0);
+                                               p = particle(particletype + info->particletype, info->color[0], info->color[1], tex, lhrandom(info->size[0], info->size[1]), info->size[2], lhrandom(info->alpha[0], info->alpha[1]), info->alpha[2], info->gravity, info->bounce, trailpos[0] + info->originoffset[0] + info->originjitter[0] * rvec[0], trailpos[1] + info->originoffset[1] + info->originjitter[1] * rvec[1], trailpos[2] + info->originoffset[2] + info->originjitter[2] * rvec[2], lhrandom(velocitymins[0], velocitymaxs[0]) * info->velocitymultiplier + info->velocityoffset[0] + info->velocityjitter[0] * rvec[0], lhrandom(velocitymins[1], velocitymaxs[1]) * info->velocitymultiplier + info->velocityoffset[1] + info->velocityjitter[1] * rvec[1], lhrandom(velocitymins[2], velocitymaxs[2]) * info->velocitymultiplier + info->velocityoffset[2] + info->velocityjitter[2] * rvec[2], info->airfriction, info->liquidfriction, 0, 0);
+                                               // if it is rain or snow, trace ahead and shut off collisions until an actual collision event needs to occur to improve performance
+                                               if (info->bounce != 0 && info->gravity == 0)
+                                               {
+                                                       float lifetime = p->alpha / (p->alphafade ? p->alphafade : 1);
+                                                       VectorMA(p->org, lifetime, p->vel, rvec);
+                                                       trace = CL_Move(p->org, vec3_origin, vec3_origin, rvec, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | ((info->particletype == pt_rain || info->particletype == pt_snow) ? SUPERCONTENTS_LIQUIDSMASK : 0), true, false, NULL, false);
+                                                       p->delayedcollisions = cl.time + lifetime * trace.fraction - 0.1;
+                                               }
                                                if (trailstep)
                                                        VectorMA(trailpos, trailstep, traildir, trailpos);
                                        }
@@ -1586,7 +1597,7 @@ void CL_MoveParticles (void)
                        VectorCopy(p->org, oldorg);
                        VectorMA(p->org, frametime, p->vel, p->org);
                        VectorCopy(p->org, org);
-                       if (p->bounce)
+                       if (p->bounce && cl.time >= p->delayedcollisions)
                        {
                                trace = CL_Move(oldorg, vec3_origin, vec3_origin, p->org, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | (p->type == particletype + pt_rain ? SUPERCONTENTS_LIQUIDSMASK : 0), true, false, &hitent, false);
                                // if the trace started in or hit something of SUPERCONTENTS_NODROP
index 6b469af0c43eb5e592fba4ba0b5704efd4b18f47..f1903a0630a6827589e38a46ed2d9009075e4a91 100644 (file)
--- a/client.h
+++ b/client.h
@@ -300,6 +300,7 @@ typedef struct entity_persistent_s
 
        // particle trail
        float trail_time;
+       qboolean trail_allowed; // set to false by teleports, true by update code, prevents bad lerps
 
        // muzzleflash fading
        float muzzleflash;
@@ -646,6 +647,7 @@ typedef struct particle_s
        model_t         *ownermodel; // model the decal is stuck to (used to make sure the entity is still alive)
        vec3_t          relativeorigin; // decal at this location in entity's coordinate space
        vec3_t          relativedirection; // decal oriented this way relative to entity's coordinate space
+       float           delayedcollisions; // time that p->bounce becomes active
 }
 particle_t;