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
35 Host_Error ("CL_LerpAnimation: frame1 is NULL\n");
37 // check r_lerpmodels and round off very close blend percentages
38 if (!r_lerpmodels.integer)
40 else if (r->framelerp >= (65535.0f / 65536.0f))
42 else if (r->framelerp < (1.0f / 65536.0f))
45 blend[0].frame = blend[1].frame = blend[2].frame = blend[3].frame = 0;
46 blend[0].lerp = blend[1].lerp = blend[2].lerp = blend[3].lerp = 0;
47 if (r->model->animscenes)
49 if (r->framelerp < 1 && r->frame1 >= 0)
51 scene = r->model->animscenes + r->frame1;
52 lerp = 1 - r->framelerp;
54 if (scene->framecount > 1)
56 sublerp = scene->framerate * (cl.time - r->frame1time);
57 sub1 = (int) (sublerp);
60 if (!r_lerpmodels.integer)
62 else if (sublerp >= (65535.0f / 65536.0f))
64 else if (sublerp < (1.0f / 65536.0f))
68 sub1 = (sub1 % scene->framecount);
69 sub2 = (sub2 % scene->framecount);
73 sub1 = bound(0, sub1, (scene->framecount - 1));
74 sub2 = bound(0, sub2, (scene->framecount - 1));
76 sub1 += scene->firstframe;
77 sub2 += scene->firstframe;
79 d = (1 - sublerp) * lerp;
80 #define FRAMEBLENDINSERT\
83 for (i = 0;i < 4;i++)\
85 if (blend[i].frame == f)\
90 if (blend[i].lerp <= 0)\
104 f = scene->firstframe;
109 if (r->framelerp > 0 && r->frame2 >= 0)
111 scene = r->model->animscenes + r->frame2;
114 if (scene->framecount > 1)
116 sublerp = scene->framerate * (cl.time - r->frame1time);
117 sub1 = (int) (sublerp);
120 if (!r_lerpmodels.integer)
122 else if (sublerp >= (65535.0f / 65536.0f))
124 else if (sublerp < (1.0f / 65536.0f))
128 sub1 = (sub1 % scene->framecount);
129 sub2 = (sub2 % scene->framecount);
133 sub1 = bound(0, sub1, (scene->framecount - 1));
134 sub2 = bound(0, sub2, (scene->framecount - 1));
136 sub1 += scene->firstframe;
137 sub2 += scene->firstframe;
139 d = (1 - sublerp) * lerp;
146 f = scene->firstframe;
154 // if there are no scenes, assume it is all single-frame groups
155 if (r->framelerp < 1 && r->frame1 >= 0)
158 d = 1 - r->framelerp;
161 if (r->framelerp > 0 && r->frame2 >= 0)