X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=r_lerpanim.c;h=f384d81af0eb39c67af64157fb3c565e70e413ed;hb=9e10334c3d85c0ff3630fe015f40b5c5a227668a;hp=f736a11ccc31b3e2b96c9b208c43a9995ca76920;hpb=5648ea4628805cef3e6b14fde5a29dfcfebb3593;p=xonotic%2Fdarkplaces.git diff --git a/r_lerpanim.c b/r_lerpanim.c index f736a11c..f384d81a 100644 --- a/r_lerpanim.c +++ b/r_lerpanim.c @@ -6,153 +6,95 @@ // LordHavoc: later note: made FRAMEBLENDINSERT macro void R_LerpAnimation(entity_render_t *r) { - int sub1, sub2, numframes, f, i; + int sub2, numframes, f, i, k; + int isfirstframegroup = true; + int nolerp; double sublerp, lerp, d; animscene_t *scene; + framegroupblend_t *g; frameblend_t *blend; + dp_model_t *model = r->model; - if (!r->model || !r->model->type) - return; - - blend = r->frameblend; + memset(r->frameblend, 0, sizeof(r->frameblend)); - numframes = r->model->numframes; - - if (r->frame1 >= numframes) + if (!model || !model->surfmesh.isanimated) { - Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame1); - r->frame1 = 0; - } - - if (r->frame2 >= numframes) - { - Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame2); - r->frame2 = 0; + r->frameblend[0].lerp = 1; + return; } - // note: this could be removed, if the rendering code allows an empty blend array - if (r->frame1 < 0) - Host_Error ("CL_LerpAnimation: frame1 is NULL\n"); - - // check r_lerpmodels and round off very close blend percentages - if (!r_lerpmodels.integer) - r->framelerp = 1; - else if (r->framelerp >= (65535.0f / 65536.0f)) - r->framelerp = 1; - else if (r->framelerp < (1.0f / 65536.0f)) - r->framelerp = 0; - - blend[0].frame = blend[1].frame = blend[2].frame = blend[3].frame = 0; - blend[0].lerp = blend[1].lerp = blend[2].lerp = blend[3].lerp = 0; - if (r->model->animscenes) + blend = r->frameblend; + nolerp = (model->type == mod_sprite) ? !r_lerpsprites.integer : !r_lerpmodels.integer; + numframes = model->numframes; + for (k = 0, g = r->framegroupblend;k < MAX_FRAMEGROUPBLENDS;k++, g++) { - if (r->framelerp < 1 && r->frame1 >= 0) + if ((unsigned int)g->frame >= (unsigned int)numframes) { - scene = r->model->animscenes + r->frame1; - lerp = 1 - r->framelerp; - - if (scene->framecount > 1) + Con_DPrintf("CL_LerpAnimation: no such frame %d\n", g->frame); + g->frame = 0; + } + f = g->frame; + d = lerp = g->lerp; + if (lerp <= 0) + continue; + if (nolerp) + { + if (isfirstframegroup) { - sublerp = scene->framerate * (cl.time - r->frame1time); - sub1 = (int) (sublerp); - sub2 = sub1 + 1; - sublerp -= sub1; - if (!r_lerpmodels.integer) - sublerp = 1; - else if (sublerp >= (65535.0f / 65536.0f)) - sublerp = 1; - else if (sublerp < (1.0f / 65536.0f)) - sublerp = 0; - if (scene->loop) - { - sub1 = (sub1 % scene->framecount); - sub2 = (sub2 % scene->framecount); - } - sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe; - sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe; - f = sub1; - d = (1 - sublerp) * lerp; -#define FRAMEBLENDINSERT\ - if (d > 0)\ - {\ - for (i = 0;i < 4;i++)\ - {\ - if (blend[i].frame == f)\ - {\ - blend[i].lerp += d;\ - break;\ - }\ - if (blend[i].lerp <= 0)\ - {\ - blend[i].frame = f;\ - blend[i].lerp = d;\ - break;\ - }\ - }\ - } - FRAMEBLENDINSERT - f = sub2; - d = sublerp * lerp; + d = lerp = 1; + isfirstframegroup = false; } else - { - f = scene->firstframe; - d = lerp; - } - FRAMEBLENDINSERT + continue; } - if (r->framelerp > 0 && r->frame2 >= 0) + if (model->animscenes) { - scene = r->model->animscenes + r->frame2; - lerp = r->framelerp; - + scene = model->animscenes + f; + f = scene->firstframe; if (scene->framecount > 1) { - sublerp = scene->framerate * (cl.time - r->frame1time); - sub1 = (int) (sublerp); - sub2 = sub1 + 1; - sublerp -= sub1; - if (!r_lerpmodels.integer) - sublerp = 1; - else if (sublerp >= (65535.0f / 65536.0f)) - sublerp = 1; - else if (sublerp < (1.0f / 65536.0f)) + // this code path is only used on .zym models and torches + sublerp = scene->framerate * (cl.time - g->start); + f = (int) floor(sublerp); + sublerp -= f; + sub2 = f + 1; + if (nolerp) sublerp = 0; if (scene->loop) { - sub1 = (sub1 % scene->framecount); + f = (f % scene->framecount); sub2 = (sub2 % scene->framecount); } - sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe; + f = bound(0, f, (scene->framecount - 1)) + scene->firstframe; sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe; - f = sub1; - d = (1 - sublerp) * lerp; - FRAMEBLENDINSERT - f = sub2; d = sublerp * lerp; + // two framelerps produced from one animation + if (f != sub2 && d > 0) + { + for (i = 0;i < MAX_FRAMEBLENDS;i++) + { + if (blend[i].lerp <= 0 || blend[i].subframe == sub2) + { + blend[i].subframe = sub2; + blend[i].lerp += d; + break; + } + } + } + d = (1 - sublerp) * lerp; } - else - { - f = scene->firstframe; - d = lerp; - } - FRAMEBLENDINSERT - } - } - else - { - // if there are no scenes, assume it is all single-frame groups - if (r->framelerp < 1 && r->frame1 >= 0) - { - f = r->frame1; - d = 1 - r->framelerp; - FRAMEBLENDINSERT } - if (r->framelerp > 0 && r->frame2 >= 0) + if (d > 0) { - f = r->frame2; - d = r->framelerp; - FRAMEBLENDINSERT + for (i = 0;i < MAX_FRAMEBLENDS;i++) + { + if (blend[i].lerp <= 0 || blend[i].subframe == f) + { + blend[i].subframe = f; + blend[i].lerp += d; + break; + } + } } } }