]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/anim.qc
Remove .move_* fields and MOVETYPE_PUSH logic (doesn't work)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / anim.qc
1 #include "anim.qh"
2
3 /**
4  * @param anim x = startframe, y = numframes, z = framerate
5  */
6 void anim_set(entity e, vector anim, bool looping, bool override, bool restart)
7 {
8         if (!anim) return;  // no animation was given to us! We can't use this.
9
10         if (anim.x == e.animstate_startframe)
11         {
12                 if (anim.y == e.animstate_numframes)
13                 {
14                         if (anim.z == e.animstate_framerate)
15                         {
16                                 if (!restart) return;
17                                 if (anim.y == 1)  // ZYM animation
18                                         BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT);
19                         }
20                 }
21         }
22         e.animstate_startframe = anim.x;
23         e.animstate_numframes = anim.y;
24         e.animstate_framerate = anim.z;
25         e.animstate_starttime = time - 0.1 * frametime;  // shift it a little bit into the past to prevent float inaccuracy hiccups
26         e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
27         e.animstate_looping = looping;
28         e.animstate_override = override;
29         e.frame = e.animstate_startframe;
30         e.frame1time = time;
31 }
32
33 /**
34  * Update e.frame based on its animstate relative to time
35  */
36 void anim_update(entity e)
37 {
38         if (time >= e.animstate_endtime)
39         {
40                 if (e.animstate_looping)
41                 {
42                         e.animstate_starttime = e.animstate_endtime;
43                         e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
44                 }
45                 e.animstate_override = false;
46         }
47         float frameofs = bound(0, (time - e.animstate_starttime) * e.animstate_framerate, e.animstate_numframes - 1);
48         e.frame = e.animstate_startframe + frameofs;
49 }