Merge branch 'master' into TimePath/csqc_viewmodels
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / anim.qc
1 void setanim(entity e, vector anim, bool looping, bool override, int restart)
2 {
3         if (!anim) return;  // no animation was given to us! We can't use this.
4
5         if (anim.x == e.animstate_startframe)
6         {
7                 if (anim.y == e.animstate_numframes)
8                 {
9                         if (anim.z == e.animstate_framerate)
10                         {
11                                 if (!restart) return;
12                                 if (restart > 0 && anim.y == 1)  // ZYM animation
13                                         BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT);
14                         }
15                 }
16         }
17         e.animstate_startframe = anim.x;
18         e.animstate_numframes = anim.y;
19         e.animstate_framerate = anim.z;
20         e.animstate_starttime = servertime - 0.1 * frametime;  // shift it a little bit into the past to prevent float inaccuracy hiccups
21         e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
22         e.animstate_looping = looping;
23         e.animstate_override = override;
24         e.frame = e.animstate_startframe;
25         e.frame1time = servertime;
26 }
27
28 void updateanim(entity e)
29 {
30         if (time >= e.animstate_endtime)
31         {
32                 if (e.animstate_looping)
33                 {
34                         e.animstate_starttime = e.animstate_endtime;
35                         e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
36                 }
37                 e.animstate_override = false;
38         }
39         e.frame = e.animstate_startframe + bound(0, (time - e.animstate_starttime) * e.animstate_framerate,
40                 e.animstate_numframes - 1);
41         // print(ftos(time), " -> ", ftos(e.frame), "\n");
42 }