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;
13 blend = r->frameblend;
15 numframes = r->model->numframes;
17 if (r->frame1 >= numframes)
19 Con_DPrintf ("CL_LerpAnimation: no such frame %d\n", r->frame1);
23 if (r->frame2 >= numframes)
25 Con_DPrintf ("CL_LerpAnimation: no such frame %d\n", r->frame2);
29 // note: this could be removed, if the rendering code allows an empty blend array
31 Host_Error ("CL_LerpAnimation: frame1 is NULL\n");
33 // round off very close blend percentages
34 if (r->framelerp < (1.0f / 65536.0f))
36 if (r->framelerp >= (65535.0f / 65536.0f))
39 blend[0].frame = blend[1].frame = blend[2].frame = blend[3].frame = 0;
40 blend[0].lerp = blend[1].lerp = blend[2].lerp = blend[3].lerp = 0;
41 if (r->model->animscenes)
43 if (r->framelerp < 1 && r->frame1 >= 0)
45 scene = r->model->animscenes + r->frame1;
46 lerp = 1 - r->framelerp;
48 if (scene->framecount > 1)
50 sublerp = scene->framerate * (cl.time - r->frame1time);
51 sub1 = (int) (sublerp);
54 if (sublerp < (1.0f / 65536.0f))
56 if (sublerp >= (65535.0f / 65536.0f))
60 sub1 = (sub1 % scene->framecount);
61 sub2 = (sub2 % scene->framecount);
65 sub1 = bound(0, sub1, (scene->framecount - 1));
66 sub2 = bound(0, sub2, (scene->framecount - 1));
68 sub1 += scene->firstframe;
69 sub2 += scene->firstframe;
71 d = (1 - sublerp) * lerp;
72 #define FRAMEBLENDINSERT\
75 for (i = 0;i < 4;i++)\
77 if (blend[i].frame == f)\
82 if (blend[i].lerp <= 0)\
96 f = scene->firstframe;
101 if (r->framelerp > 0 && r->frame2 >= 0)
103 scene = r->model->animscenes + r->frame2;
106 if (scene->framecount > 1)
108 sublerp = scene->framerate * (cl.time - r->frame1time);
109 sub1 = (int) (sublerp);
112 if (sublerp < (1.0f / 65536.0f))
114 if (sublerp >= (65535.0f / 65536.0f))
118 sub1 = (sub1 % scene->framecount);
119 sub2 = (sub2 % scene->framecount);
123 sub1 = bound(0, sub1, (scene->framecount - 1));
124 sub2 = bound(0, sub2, (scene->framecount - 1));
126 sub1 += scene->firstframe;
127 sub2 += scene->firstframe;
129 d = (1 - sublerp) * lerp;
136 f = scene->firstframe;
144 // if there are no scenes, assume it is all single-frame groups
145 if (r->framelerp < 1 && r->frame1 >= 0)
148 d = 1 - r->framelerp;
151 if (r->framelerp > 0 && r->frame2 >= 0)
158 //Con_Printf("Lerp: %i:%f %i:%f %i:%f %i:%f\n", blend[0].frame, blend[0].lerp, blend[1].frame, blend[1].lerp, blend[2].frame, blend[2].lerp, blend[3].frame, blend[3].lerp);