]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/animdecide.qh
Animations: fix regression in previous commit
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / animdecide.qh
1 #ifndef ANIMDECIDE_H
2 #define ANIMDECIDE_H
3
4 // must be called at least once to initialize, or when modelindex is changed
5 void animdecide_load_if_needed(entity e);
6
7 // client side frame inferring
8 void animdecide_setimplicitstate(entity e, float onground);
9 void animdecide_setframes(entity e, bool support_blending, .int fld_frame, .int fld_frame1time, .int fld_frame2, .int fld_frame2time);
10
11 CLASS(Animation, Object)
12         ATTRIB(Animation, m_framenames, string, string_null)
13         STATIC_METHOD(Animation, getframe, int(Animation this, int mdlidx))
14         {
15                 FOREACH_WORD(this.m_framenames, true, {
16                         int f = frameforname(mdlidx, it);
17                         if (f != -1) return f;
18                 });
19 #ifdef CSQC
20                 LOG_WARNINGF("Missing animation for %s: %s\n", modelnameforindex(mdlidx), this.registered_id);
21 #endif
22                 return -1;
23         }
24 ENDCLASS(Animation)
25
26 REGISTRY(Animations, BITS(8))
27 REGISTER_REGISTRY(Animations)
28 #define REGISTER_ANIMATION(id, framenames) \
29         .vector anim_##id; \
30         REGISTER(Animations, ANIM_##id, m_id, NEW(Animation)) { \
31                 this.m_framenames = framenames; \
32         }
33
34 vector anim_vec(Animation anim, int mdlidx, int numframes, float framerate)
35 {
36         vector v;
37         v.x = Animation_getframe(anim, mdlidx);
38         v.y = numframes;
39         v.z = framerate;
40         return v;
41 }
42
43 // player animation data for this model
44 // each vector is as follows:
45 // _x = startframe
46 // _y = numframes
47 // _z = framerate
48 /** player dies */
49 REGISTER_ANIMATION(die1, "dieone groupified_0_anim");
50 /** player dies differently */
51 REGISTER_ANIMATION(die2, "dietwo groupified_1_anim");
52 /** player pulls out a weapon */
53 REGISTER_ANIMATION(draw, "draw groupified_2_anim");
54 REGISTER_ANIMATION(duck, "duck groupified_3_anim");
55 /** player walking while crouching */
56 REGISTER_ANIMATION(duckwalk, "duckwalk groupified_4_anim");
57 /** player jumping from a crouch */
58 REGISTER_ANIMATION(duckjump, "duckjump groupified_5_anim");
59 /** player idling while crouching */
60 REGISTER_ANIMATION(duckidle, "duckidle groupified_6_anim");
61 /** player standing */
62 REGISTER_ANIMATION(idle, "idle groupified_7_anim");
63 /** player jump */
64 REGISTER_ANIMATION(jump, "jump groupified_8_anim");
65 /** player flinches from pain */
66 REGISTER_ANIMATION(pain1, "painone groupified_9_anim");
67 /** player flinches from pain, differently */
68 REGISTER_ANIMATION(pain2, "paintwo groupified_10_anim");
69 /** player shoots */
70 REGISTER_ANIMATION(shoot, "shoot groupified_11_anim");
71 /** player taunts others (FIXME: no code references this) */
72 REGISTER_ANIMATION(taunt, "taunt groupified_12_anim");
73 /** player running forward */
74 REGISTER_ANIMATION(run, "run groupified_13_anim");
75 /** player running backward */
76 REGISTER_ANIMATION(runbackwards, "runbackwards groupified_14_anim");
77 /** player shuffling left quickly */
78 REGISTER_ANIMATION(strafeleft, "strafeleft groupified_15_anim");
79 /** player shuffling right quickly */
80 REGISTER_ANIMATION(straferight, "straferight groupified_16_anim");
81 /**  */
82 REGISTER_ANIMATION(dead1, "deadone groupified_17_anim");
83 /**  */
84 REGISTER_ANIMATION(dead2, "deadtwo groupified_18_anim");
85 /** player running forward and right */
86 REGISTER_ANIMATION(forwardright, "forwardright groupified_19_anim");
87 /** player running forward and left */
88 REGISTER_ANIMATION(forwardleft, "forwardleft groupified_20_anim");
89 /** player running backward and right */
90 REGISTER_ANIMATION(backright, "backright groupified_21_anim");
91 /** player running back and left */
92 REGISTER_ANIMATION(backleft, "backleft groupified_22_anim");
93 /** player doing the melee action */
94 REGISTER_ANIMATION(melee, "melee groupified_23_anim");
95 REGISTER_ANIMATION(duckwalkbackwards, "duckwalkbackwards groupified_24_anim");
96 REGISTER_ANIMATION(duckwalkstrafeleft, "duckwalkstrafeleft duckstrafeleft groupified_25_anim");
97 REGISTER_ANIMATION(duckwalkstraferight, "duckwalkstraferight duckstraferight groupified_26_anim");
98 REGISTER_ANIMATION(duckwalkforwardright, "duckwalkforwardright duckforwardright groupified_27_anim");
99 REGISTER_ANIMATION(duckwalkforwardleft, "duckwalkforwardleft groupified_28_anim");
100 REGISTER_ANIMATION(duckwalkbackright, "duckwalkbackright duckbackwardright groupified_29_anim");
101 REGISTER_ANIMATION(duckwalkbackleft, "duckwalkbackleft duckbackwardleft groupified_30_anim");
102 .float animdecide_modelindex;
103
104 // please network this one
105 .int anim_state;
106 .float anim_time;
107 .float anim_lower_action;
108 .float anim_lower_time;
109 .float anim_upper_action;
110 .float anim_upper_time;
111
112 // when copying entities, copy these too
113 .int anim_implicit_state;
114 .float anim_implicit_time;
115 .float anim_lower_implicit_action;
116 .float anim_lower_implicit_time;
117 .float anim_upper_implicit_action;
118 .float anim_upper_implicit_time;
119
120 // explicit anim states (networked)
121 void animdecide_setstate(entity e, int newstate, float restart);
122 const int ANIMSTATE_DEAD1 = BIT(0); // base frames: die1
123 const int ANIMSTATE_DEAD2 = BIT(1); // base frames: die2
124 const int ANIMSTATE_DUCK = BIT(2); // turns walk into duckwalk, jump into duckjump, etc.
125 const int ANIMSTATE_FROZEN = BIT(3); // force idle
126 const int ANIMSTATE_FOLLOW = BIT(4); // also force idle
127
128 // implicit anim states (inferred from velocity, etc.)
129 const int ANIMIMPLICITSTATE_INAIR = BIT(0);
130 const int ANIMIMPLICITSTATE_FORWARD = BIT(1);
131 const int ANIMIMPLICITSTATE_BACKWARDS = BIT(2);
132 const int ANIMIMPLICITSTATE_LEFT = BIT(3);
133 const int ANIMIMPLICITSTATE_RIGHT = BIT(4);
134 const int ANIMIMPLICITSTATE_JUMPRELEASED = BIT(5);
135
136 // explicit actions (networked); negative values are for lower body
137 void animdecide_setaction(entity e, float action, float restart);
138 const int ANIMACTION_JUMP = -1; // jump
139 const int ANIMACTION_DRAW = 1; // draw
140 const int ANIMACTION_PAIN1 = 2; // pain
141 const int ANIMACTION_PAIN2 = 3; // pain
142 const int ANIMACTION_SHOOT = 4; // shoot
143 const int ANIMACTION_TAUNT = 5; // taunt
144 const int ANIMACTION_MELEE = 6; // melee
145 #endif