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);
61 if (sublerp < (1.0 / 65536.0f))
63 if (sublerp > (65535.0f / 65536.0f))
69 f = (f % scene->framecount);
70 sub2 = (sub2 % scene->framecount);
72 f = bound(0, f, (scene->framecount - 1)) + scene->firstframe;
73 sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe;
75 // two framelerps produced from one animation
78 for (i = 0;i < MAX_FRAMEBLENDS;i++)
80 if (blend[i].lerp <= 0 || blend[i].subframe == sub2)
82 blend[i].subframe = sub2;
88 d = (1 - sublerp) * lerp;
93 for (i = 0;i < MAX_FRAMEBLENDS;i++)
95 if (blend[i].lerp <= 0 || blend[i].subframe == f)
97 blend[i].subframe = f;