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;
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 // round off very close blend percentages
38 if (r->framelerp < (1.0f / 65536.0f))
40 if (r->framelerp >= (65535.0f / 65536.0f))
43 blend[0].frame = blend[1].frame = blend[2].frame = blend[3].frame = 0;
44 blend[0].lerp = blend[1].lerp = blend[2].lerp = blend[3].lerp = 0;
45 if (r->model->animscenes)
47 if (r->framelerp < 1 && r->frame1 >= 0)
49 scene = r->model->animscenes + r->frame1;
50 lerp = 1 - r->framelerp;
52 if (scene->framecount > 1)
54 sublerp = scene->framerate * (cl.time - r->frame1time);
55 sub1 = (int) (sublerp);
58 if (sublerp < (1.0f / 65536.0f))
60 if (sublerp >= (65535.0f / 65536.0f))
64 sub1 = (sub1 % scene->framecount);
65 sub2 = (sub2 % scene->framecount);
69 sub1 = bound(0, sub1, (scene->framecount - 1));
70 sub2 = bound(0, sub2, (scene->framecount - 1));
72 sub1 += scene->firstframe;
73 sub2 += scene->firstframe;
75 d = (1 - sublerp) * lerp;
76 #define FRAMEBLENDINSERT\
79 for (i = 0;i < 4;i++)\
81 if (blend[i].frame == f)\
86 if (blend[i].lerp <= 0)\
100 f = scene->firstframe;
105 if (r->framelerp > 0 && r->frame2 >= 0)
107 scene = r->model->animscenes + r->frame2;
110 if (scene->framecount > 1)
112 sublerp = scene->framerate * (cl.time - r->frame1time);
113 sub1 = (int) (sublerp);
116 if (sublerp < (1.0f / 65536.0f))
118 if (sublerp >= (65535.0f / 65536.0f))
122 sub1 = (sub1 % scene->framecount);
123 sub2 = (sub2 % scene->framecount);
127 sub1 = bound(0, sub1, (scene->framecount - 1));
128 sub2 = bound(0, sub2, (scene->framecount - 1));
130 sub1 += scene->firstframe;
131 sub2 += scene->firstframe;
133 d = (1 - sublerp) * lerp;
140 f = scene->firstframe;
148 // if there are no scenes, assume it is all single-frame groups
149 if (r->framelerp < 1 && r->frame1 >= 0)
152 d = 1 - r->framelerp;
155 if (r->framelerp > 0 && r->frame2 >= 0)