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, data;
10 double sublerp, lerp, d;
11 animscene_t *scene, *scenes;
13 blend = r->frameblend;
15 numframes = r->model->numframes;
17 if ((r->frame1 >= numframes))
19 Con_Printf ("CL_LerpAnimation: no such frame %d\n", r->frame1);
23 if ((r->frame2 >= numframes))
25 Con_Printf ("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 = -1;
40 blend[0].lerp = blend[1].lerp = blend[2].lerp = blend[3].lerp = 0;
41 if (r->model->ofs_scenes)
43 if (r->model->cachesize)
45 data = (int) Mod_Extradata(r->model);
47 Host_Error("CL_LerpAnimation: model not loaded\n");
48 scenes = (animscene_t *) (r->model->ofs_scenes + data);
51 scenes = (animscene_t *) r->model->ofs_scenes;
53 if (r->framelerp < 1 && r->frame1 >= 0)
55 scene = scenes + r->frame1;
56 lerp = 1 - r->framelerp;
58 if (scene->framecount > 1)
60 sublerp = scene->framerate * (cl.time - r->frame1time);
61 sub1 = (int) (sublerp);
64 if (sublerp < (1.0f / 65536.0f))
66 if (sublerp >= (65535.0f / 65536.0f))
70 sub1 = (sub1 % scene->framecount) + scene->firstframe;
71 sub2 = (sub2 % scene->framecount) + scene->firstframe;
75 sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe;
76 sub2 = bound(0, sub2, (scene->framecount - 1)) + 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 = scenes + r->frame2;
114 if (scene->framecount > 1)
116 sublerp = scene->framerate * (cl.time - r->frame1time);
117 sub1 = (int) (sublerp);
120 if (sublerp < (1.0f / 65536.0f))
122 if (sublerp >= (65535.0f / 65536.0f))
126 sub1 = (sub1 % scene->framecount) + scene->firstframe;
127 sub2 = (sub2 % scene->framecount) + scene->firstframe;
131 sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe;
132 sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe;
135 d = (1 - sublerp) * lerp;
142 f = scene->firstframe;
150 // if there are no scenes, assume it is all single-frame groups
151 if (r->framelerp < 1 && r->frame1 >= 0)
154 d = 1 - r->framelerp;
157 if (r->framelerp > 0 && r->frame2 >= 0)