+ }
+}
+
+
+/*
+===============
+CL_UpdateEntities
+===============
+*/
+static void CL_UpdateEntities(void)
+{
+ entity_t *ent;
+ int i;
+
+ ent = &cl.viewent;
+ ent->state_previous = ent->state_current;
+ ent->state_current = defaultstate;
+ ent->state_current.time = cl.time;
+ ent->state_current.number = -1;
+ ent->state_current.active = true;
+ ent->state_current.modelindex = cl.stats[STAT_WEAPON];
+ ent->state_current.frame = cl.stats[STAT_WEAPONFRAME];
+ ent->state_current.flags = RENDER_VIEWMODEL;
+ if ((cl.stats[STAT_HEALTH] <= 0 && cl_deathnoviewmodel.integer) || cl.intermission)
+ ent->state_current.modelindex = 0;
+ else if (cl.stats[STAT_ITEMS] & IT_INVISIBILITY)
+ {
+ if (gamemode == GAME_TRANSFUSION)
+ ent->state_current.alpha = 128;
+ else
+ ent->state_current.modelindex = 0;
+ }
+
+ // reset animation interpolation on weaponmodel if model changed
+ if (ent->state_previous.modelindex != ent->state_current.modelindex)
+ {
+ ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
+ ent->render.frame1time = ent->render.frame2time = cl.time;
+ ent->render.framelerp = 1;
+ }
+
+ // start on the entity after the world
+ entitylinkframenumber++;
+ for (i = 1;i < cl.num_entities;i++)
+ {
+ if (cl.entities_active[i])
+ {
+ ent = cl.entities + i;
+ if (ent->state_current.active)
+ CL_UpdateNetworkEntity(ent);
+ else
+ cl.entities_active[i] = false;
+ }
+ }
+ CL_UpdateNetworkEntity(&cl.viewent);
+}
+
+// note this is a recursive function, but it can never get in a runaway loop (because of the delayedlink flags)
+void CL_LinkNetworkEntity(entity_t *e)
+{
+ entity_t *t;
+ if (e->persistent.linkframe != entitylinkframenumber)
+ {
+ e->persistent.linkframe = entitylinkframenumber;
+ // skip inactive entities and world
+ if (!e->state_current.active || e == cl.entities || e == cl.csqcentities)
+ return;
+ if (e->render.flags & RENDER_VIEWMODEL && !e->state_current.tagentity)
+ {
+ if (!r_drawviewmodel.integer || chase_active.integer || r_refdef.envmap)
+ return;
+ if (!e->csqc)
+ if (cl.viewentity)
+ CL_LinkNetworkEntity(cl.entities + cl.viewentity);
+ }
+ else
+ {
+ // if the tag entity is currently impossible, skip it
+ if (!e->csqc)
+ {
+ if (e->state_current.tagentity >= cl.num_entities)
+ return;
+ t = cl.entities + e->state_current.tagentity;
+ }
+ else
+ {
+ if (e->state_current.tagentity >= cl.num_csqcentities)
+ return;
+ t = cl.csqcentities + e->state_current.tagentity;
+ }
+ // if the tag entity is inactive, skip it
+ if (!t->state_current.active)
+ return;
+ // note: this can link to world
+ CL_LinkNetworkEntity(t);
+ }
+