3 // LordHavoc: quite tempting to break apart this function to reuse the
4 // duplicated code, but I suspect it is better for performance
6 // LordHavoc: later note: made FRAMEBLENDINSERT macro
7 void R_LerpAnimation(entity_render_t *r)
9 int sub2, numframes, f, i, k;
10 int isfirstframegroup = true;
12 double sublerp, lerp, d;
16 dp_model_t *model = r->model;
18 memset(r->frameblend, 0, sizeof(r->frameblend));
20 if (!model || !model->surfmesh.isanimated)
22 r->frameblend[0].lerp = 1;
26 blend = r->frameblend;
27 nolerp = (model->type == mod_sprite) ? !r_lerpsprites.integer : !r_lerpmodels.integer;
28 numframes = model->numframes;
29 for (k = 0, g = r->framegroupblend;k < MAX_FRAMEGROUPBLENDS;k++, g++)
31 if ((unsigned int)g->frame >= (unsigned int)numframes)
33 Con_DPrintf("CL_LerpAnimation: no such frame %d\n", g->frame);
42 if (isfirstframegroup)
45 isfirstframegroup = false;
50 if (model->animscenes)
52 scene = model->animscenes + f;
53 f = scene->firstframe;
54 if (scene->framecount > 1)
56 // this code path is only used on .zym models and torches
57 sublerp = scene->framerate * (cl.time - g->start);
58 f = (int) floor(sublerp);
65 f = (f % scene->framecount);
66 sub2 = (sub2 % scene->framecount);
68 f = bound(0, f, (scene->framecount - 1)) + scene->firstframe;
69 sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe;
71 // two framelerps produced from one animation
72 if (f != sub2 && d > 0)
74 for (i = 0;i < MAX_FRAMEBLENDS;i++)
76 if (blend[i].lerp <= 0 || blend[i].subframe == sub2)
78 blend[i].subframe = sub2;
84 d = (1 - sublerp) * lerp;
89 for (i = 0;i < MAX_FRAMEBLENDS;i++)
91 if (blend[i].lerp <= 0 || blend[i].subframe == f)
93 blend[i].subframe = f;