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 sub1, sub2, numframes, f, i;
10 double sublerp, lerp, d;
14 if (!r->model || !r->model->type)
17 blend = r->frameblend;
19 numframes = r->model->numframes;
21 if (r->frame1 >= numframes)
23 Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame1);
27 if (r->frame2 >= numframes)
29 Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame2);
33 // note: this could be removed, if the rendering code allows an empty blend array
36 Con_Printf ("CL_LerpAnimation: frame1 is NULL\n");
40 // check r_lerpmodels and round off very close blend percentages
41 if (!r_lerpmodels.integer)
43 else if (r->framelerp >= (65535.0f / 65536.0f))
45 else if (r->framelerp < (1.0f / 65536.0f))
48 blend[0].frame = blend[1].frame = blend[2].frame = blend[3].frame = 0;
49 blend[0].lerp = blend[1].lerp = blend[2].lerp = blend[3].lerp = 0;
50 if (r->model->animscenes)
52 if (r->framelerp < 1 && r->frame1 >= 0)
54 scene = r->model->animscenes + r->frame1;
55 lerp = 1 - r->framelerp;
57 if (scene->framecount > 1)
59 sublerp = scene->framerate * (cl.time - r->frame1time);
60 sub1 = (int) (sublerp);
63 if (!r_lerpmodels.integer)
65 else if (sublerp >= (65535.0f / 65536.0f))
67 else if (sublerp < (1.0f / 65536.0f))
71 sub1 = (sub1 % scene->framecount);
72 sub2 = (sub2 % scene->framecount);
74 sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe;
75 sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe;
77 d = (1 - sublerp) * lerp;
78 #define FRAMEBLENDINSERT\
81 for (i = 0;i < 4;i++)\
83 if (blend[i].frame == f)\
88 if (blend[i].lerp <= 0)\
102 f = scene->firstframe;
107 if (r->framelerp > 0 && r->frame2 >= 0)
109 scene = r->model->animscenes + r->frame2;
112 if (scene->framecount > 1)
114 sublerp = scene->framerate * (cl.time - r->frame1time);
115 sub1 = (int) (sublerp);
118 if (!r_lerpmodels.integer)
120 else if (sublerp >= (65535.0f / 65536.0f))
122 else if (sublerp < (1.0f / 65536.0f))
126 sub1 = (sub1 % scene->framecount);
127 sub2 = (sub2 % scene->framecount);
129 sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe;
130 sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe;
132 d = (1 - sublerp) * lerp;
139 f = scene->firstframe;
147 // if there are no scenes, assume it is all single-frame groups
148 if (r->framelerp < 1 && r->frame1 >= 0)
151 d = 1 - r->framelerp;
154 if (r->framelerp > 0 && r->frame2 >= 0)