]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_lerpanim.c
fix a crash when s->tag_entity is higher than current d->maxedicts
[xonotic/darkplaces.git] / r_lerpanim.c
index 5fb248f78cfe0797209f40997e82374c0e324e24..f736a11ccc31b3e2b96c9b208c43a9995ca76920 100644 (file)
@@ -10,19 +10,23 @@ void R_LerpAnimation(entity_render_t *r)
        double sublerp, lerp, d;
        animscene_t *scene;
        frameblend_t *blend;
+
+       if (!r->model || !r->model->type)
+               return;
+
        blend = r->frameblend;
 
        numframes = r->model->numframes;
 
        if (r->frame1 >= numframes)
        {
-               Con_Printf ("CL_LerpAnimation: no such frame %d\n", r->frame1);
+               Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame1);
                r->frame1 = 0;
        }
 
        if (r->frame2 >= numframes)
        {
-               Con_Printf ("CL_LerpAnimation: no such frame %d\n", r->frame2);
+               Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame2);
                r->frame2 = 0;
        }
 
@@ -30,11 +34,13 @@ void R_LerpAnimation(entity_render_t *r)
        if (r->frame1 < 0)
                Host_Error ("CL_LerpAnimation: frame1 is NULL\n");
 
-       // round off very close blend percentages
-       if (r->framelerp < (1.0f / 65536.0f))
-               r->framelerp = 0;
-       if (r->framelerp >= (65535.0f / 65536.0f))
+       // 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;
@@ -51,22 +57,19 @@ void R_LerpAnimation(entity_render_t *r)
                                sub1 = (int) (sublerp);
                                sub2 = sub1 + 1;
                                sublerp -= sub1;
-                               if (sublerp < (1.0f / 65536.0f))
-                                       sublerp = 0;
-                               if (sublerp >= (65535.0f / 65536.0f))
+                               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);
                                }
-                               else
-                               {
-                                       sub1 = bound(0, sub1, (scene->framecount - 1));
-                                       sub2 = bound(0, sub2, (scene->framecount - 1));
-                               }
-                               sub1 += scene->firstframe;
-                               sub2 += scene->firstframe;
+                               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\
@@ -109,22 +112,19 @@ void R_LerpAnimation(entity_render_t *r)
                                sub1 = (int) (sublerp);
                                sub2 = sub1 + 1;
                                sublerp -= sub1;
-                               if (sublerp < (1.0f / 65536.0f))
-                                       sublerp = 0;
-                               if (sublerp >= (65535.0f / 65536.0f))
+                               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);
                                }
-                               else
-                               {
-                                       sub1 = bound(0, sub1, (scene->framecount - 1));
-                                       sub2 = bound(0, sub2, (scene->framecount - 1));
-                               }
-                               sub1 += scene->firstframe;
-                               sub2 += scene->firstframe;
+                               sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe;
+                               sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe;
                                f = sub1;
                                d = (1 - sublerp) * lerp;
                                FRAMEBLENDINSERT
@@ -155,6 +155,5 @@ void R_LerpAnimation(entity_render_t *r)
                        FRAMEBLENDINSERT
                }
        }
-       //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);
 }