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, dolerp;
10 double sublerp, lerp, d;
13 model_t *model = r->model;
15 blend = r->frameblend;
16 blend[0].frame = blend[1].frame = blend[2].frame = blend[3].frame = 0;
17 blend[0].lerp = blend[1].lerp = blend[2].lerp = blend[3].lerp = 0;
19 if (!model || !model->type)
22 numframes = model->numframes;
24 if (r->frame1 >= numframes)
26 Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame1);
30 if (r->frame2 >= numframes)
32 Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame2);
36 // note: this could be removed, if the rendering code allows an empty blend array
39 Con_Printf ("CL_LerpAnimation: frame1 is NULL\n");
43 // check r_lerpmodels and round off very close blend percentages
44 dolerp = (model->type == mod_sprite) ? r_lerpsprites.integer : r_lerpmodels.integer;
46 if (!dolerp || r->framelerp >= (65535.0f / 65536.0f))
48 else if (r->framelerp < (1.0f / 65536.0f))
51 if (model->animscenes)
53 if (r->framelerp < 1 && r->frame1 >= 0)
55 scene = model->animscenes + r->frame1;
56 lerp = 1 - r->framelerp;
58 if (scene->framecount > 1)
60 sublerp = scene->framerate * (cl.time - r->frame1time);
61 sub1 = (int) (sublerp);
66 else if (sublerp >= (65535.0f / 65536.0f))
68 else if (sublerp < (1.0f / 65536.0f))
72 sub1 = (sub1 % scene->framecount);
73 sub2 = (sub2 % scene->framecount);
75 sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe;
76 sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe;
78 d = (1 - sublerp) * lerp;
79 #define FRAMEBLENDINSERT\
82 for (i = 0;i < 4;i++)\
84 if (blend[i].frame == f)\
89 if (blend[i].lerp <= 0)\
103 f = scene->firstframe;
108 if (r->framelerp > 0 && r->frame2 >= 0)
110 scene = model->animscenes + r->frame2;
113 if (scene->framecount > 1)
115 sublerp = scene->framerate * (cl.time - r->frame1time);
116 sub1 = (int) (sublerp);
121 else if (sublerp >= (65535.0f / 65536.0f))
123 else if (sublerp < (1.0f / 65536.0f))
127 sub1 = (sub1 % scene->framecount);
128 sub2 = (sub2 % scene->framecount);
130 sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe;
131 sub2 = bound(0, sub2, (scene->framecount - 1)) + 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)