]> icculus.org git repositories - divverent/darkplaces.git/blob - r_lerpanim.c
Updated Transfusion map list for version 1.1 beta3
[divverent/darkplaces.git] / r_lerpanim.c
1 #include "quakedef.h"
2
3 // LordHavoc: quite tempting to break apart this function to reuse the
4 //            duplicated code, but I suspect it is better for performance
5 //            this way
6 // LordHavoc: later note: made FRAMEBLENDINSERT macro
7 void R_LerpAnimation(entity_render_t *r)
8 {
9         int sub1, sub2, numframes, f, i;
10         double sublerp, lerp, d;
11         animscene_t *scene;
12         frameblend_t *blend;
13
14         if (!r->model || !r->model->type)
15                 return;
16
17         blend = r->frameblend;
18
19         numframes = r->model->numframes;
20
21         if (r->frame1 >= numframes)
22         {
23                 Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame1);
24                 r->frame1 = 0;
25         }
26
27         if (r->frame2 >= numframes)
28         {
29                 Con_DPrintf("CL_LerpAnimation: no such frame %d\n", r->frame2);
30                 r->frame2 = 0;
31         }
32
33         // note: this could be removed, if the rendering code allows an empty blend array
34         if (r->frame1 < 0)
35                 Host_Error ("CL_LerpAnimation: frame1 is NULL\n");
36
37         // check r_lerpmodels and round off very close blend percentages
38         if (!r_lerpmodels.integer)
39                 r->framelerp = 1;
40         else if (r->framelerp >= (65535.0f / 65536.0f))
41                 r->framelerp = 1;
42         else if (r->framelerp < (1.0f / 65536.0f))
43                 r->framelerp = 0;
44
45         blend[0].frame = blend[1].frame = blend[2].frame = blend[3].frame = 0;
46         blend[0].lerp = blend[1].lerp = blend[2].lerp = blend[3].lerp = 0;
47         if (r->model->animscenes)
48         {
49                 if (r->framelerp < 1 && r->frame1 >= 0)
50                 {
51                         scene = r->model->animscenes + r->frame1;
52                         lerp = 1 - r->framelerp;
53
54                         if (scene->framecount > 1)
55                         {
56                                 sublerp = scene->framerate * (cl.time - r->frame1time);
57                                 sub1 = (int) (sublerp);
58                                 sub2 = sub1 + 1;
59                                 sublerp -= sub1;
60                                 if (!r_lerpmodels.integer)
61                                         sublerp = 1;
62                                 else if (sublerp >= (65535.0f / 65536.0f))
63                                         sublerp = 1;
64                                 else if (sublerp < (1.0f / 65536.0f))
65                                         sublerp = 0;
66                                 if (scene->loop)
67                                 {
68                                         sub1 = (sub1 % scene->framecount);
69                                         sub2 = (sub2 % scene->framecount);
70                                 }
71                                 else
72                                 {
73                                         sub1 = bound(0, sub1, (scene->framecount - 1));
74                                         sub2 = bound(0, sub2, (scene->framecount - 1));
75                                 }
76                                 sub1 += scene->firstframe;
77                                 sub2 += scene->firstframe;
78                                 f = sub1;
79                                 d = (1 - sublerp) * lerp;
80 #define FRAMEBLENDINSERT\
81                                 if (d > 0)\
82                                 {\
83                                         for (i = 0;i < 4;i++)\
84                                         {\
85                                                 if (blend[i].frame == f)\
86                                                 {\
87                                                         blend[i].lerp += d;\
88                                                         break;\
89                                                 }\
90                                                 if (blend[i].lerp <= 0)\
91                                                 {\
92                                                         blend[i].frame = f;\
93                                                         blend[i].lerp = d;\
94                                                         break;\
95                                                 }\
96                                         }\
97                                 }
98                                 FRAMEBLENDINSERT
99                                 f = sub2;
100                                 d = sublerp * lerp;
101                         }
102                         else
103                         {
104                                 f = scene->firstframe;
105                                 d = lerp;
106                         }
107                         FRAMEBLENDINSERT
108                 }
109                 if (r->framelerp > 0 && r->frame2 >= 0)
110                 {
111                         scene = r->model->animscenes + r->frame2;
112                         lerp = r->framelerp;
113
114                         if (scene->framecount > 1)
115                         {
116                                 sublerp = scene->framerate * (cl.time - r->frame1time);
117                                 sub1 = (int) (sublerp);
118                                 sub2 = sub1 + 1;
119                                 sublerp -= sub1;
120                                 if (!r_lerpmodels.integer)
121                                         sublerp = 1;
122                                 else if (sublerp >= (65535.0f / 65536.0f))
123                                         sublerp = 1;
124                                 else if (sublerp < (1.0f / 65536.0f))
125                                         sublerp = 0;
126                                 if (scene->loop)
127                                 {
128                                         sub1 = (sub1 % scene->framecount);
129                                         sub2 = (sub2 % scene->framecount);
130                                 }
131                                 else
132                                 {
133                                         sub1 = bound(0, sub1, (scene->framecount - 1));
134                                         sub2 = bound(0, sub2, (scene->framecount - 1));
135                                 }
136                                 sub1 += scene->firstframe;
137                                 sub2 += scene->firstframe;
138                                 f = sub1;
139                                 d = (1 - sublerp) * lerp;
140                                 FRAMEBLENDINSERT
141                                 f = sub2;
142                                 d = sublerp * lerp;
143                         }
144                         else
145                         {
146                                 f = scene->firstframe;
147                                 d = lerp;
148                         }
149                         FRAMEBLENDINSERT
150                 }
151         }
152         else
153         {
154                 // if there are no scenes, assume it is all single-frame groups
155                 if (r->framelerp < 1 && r->frame1 >= 0)
156                 {
157                         f = r->frame1;
158                         d = 1 - r->framelerp;
159                         FRAMEBLENDINSERT
160                 }
161                 if (r->framelerp > 0 && r->frame2 >= 0)
162                 {
163                         f = r->frame2;
164                         d = r->framelerp;
165                         FRAMEBLENDINSERT
166                 }
167         }
168 }
169