]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/animdecide.qh
Animations: register
[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         METHOD(Animation, anim_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_v;
35 Animation _ANIM_VEC_a;
36 #define ANIM_VEC(anim, numframes, framerate) \
37 ( \
38         _ANIM_VEC_v.y = numframes, \
39         _ANIM_VEC_v.z = framerate, \
40         _ANIM_VEC_a = ANIM_##anim, \
41         _ANIM_VEC_v.x = _ANIM_VEC_a.anim_getframe(_ANIM_VEC_a, mdlidx), \
42         _ANIM_VEC_v \
43 )
44
45 // player animation data for this model
46 // each vector is as follows:
47 // _x = startframe
48 // _y = numframes
49 // _z = framerate
50 /** player dies */
51 REGISTER_ANIMATION(die1, "dieone groupified_0_anim");
52 /** player dies differently */
53 REGISTER_ANIMATION(die2, "dietwo groupified_1_anim");
54 /**  */
55 REGISTER_ANIMATION(dead1, "deadone groupified_17_anim");
56 /**  */
57 REGISTER_ANIMATION(dead2, "deadtwo groupified_18_anim");
58 /** player pulls out a weapon */
59 REGISTER_ANIMATION(draw, "draw groupified_2_anim");
60 /** player walking while crouching */
61 REGISTER_ANIMATION(duckwalk, "duckwalk groupified_4_anim");
62 /** player jumping from a crouch */
63 REGISTER_ANIMATION(duckjump, "duckjump groupified_5_anim");
64 /** player idling while crouching */
65 REGISTER_ANIMATION(duckidle, "duckidle groupified_6_anim");
66 /** player standing */
67 REGISTER_ANIMATION(idle, "idle groupified_7_anim");
68 /** player jump */
69 REGISTER_ANIMATION(jump, "jump groupified_8_anim");
70 /** player flinches from pain */
71 REGISTER_ANIMATION(pain1, "painone groupified_9_anim");
72 /** player flinches from pain, differently */
73 REGISTER_ANIMATION(pain2, "paintwo groupified_10_anim");
74 /** player shoots */
75 REGISTER_ANIMATION(shoot, "shoot groupified_11_anim");
76 /** player taunts others (FIXME: no code references this) */
77 REGISTER_ANIMATION(taunt, "taunt groupified_12_anim");
78 /** player running forward */
79 REGISTER_ANIMATION(run, "run groupified_13_anim");
80 /** player running backward */
81 REGISTER_ANIMATION(runbackwards, "runbackwards groupified_14_anim");
82 /** player shuffling left quickly */
83 REGISTER_ANIMATION(strafeleft, "strafeleft groupified_15_anim");
84 /** player shuffling right quickly */
85 REGISTER_ANIMATION(straferight, "straferight groupified_16_anim");
86 /** player running forward and right */
87 REGISTER_ANIMATION(forwardright, "forwardright groupified_19_anim");
88 /** player running forward and left */
89 REGISTER_ANIMATION(forwardleft, "forwardleft groupified_20_anim");
90 /** player running backward and right */
91 REGISTER_ANIMATION(backright, "backright groupified_21_anim");
92 /** player running back and left */
93 REGISTER_ANIMATION(backleft, "backleft groupified_22_anim");
94 /** player doing the melee action */
95 REGISTER_ANIMATION(melee, "melee groupified_23_anim");
96 REGISTER_ANIMATION(duck, "duck groupified_3_anim");
97 REGISTER_ANIMATION(duckwalkbackwards, "duckwalkbackwards groupified_24_anim");
98 REGISTER_ANIMATION(duckwalkstrafeleft, "duckwalkstrafeleft duckstrafeleft groupified_25_anim");
99 REGISTER_ANIMATION(duckwalkstraferight, "duckwalkstraferight duckstraferight groupified_26_anim");
100 REGISTER_ANIMATION(duckwalkforwardright, "duckwalkforwardright duckforwardright groupified_27_anim");
101 REGISTER_ANIMATION(duckwalkforwardleft, "duckwalkforwardleft groupified_28_anim");
102 REGISTER_ANIMATION(duckwalkbackright, "duckwalkbackright duckbackwardright groupified_29_anim");
103 REGISTER_ANIMATION(duckwalkbackleft, "duckwalkbackleft duckbackwardleft groupified_30_anim");
104 .float animdecide_modelindex;
105
106 // please network this one
107 .int anim_state;
108 .float anim_time;
109 .float anim_lower_action;
110 .float anim_lower_time;
111 .float anim_upper_action;
112 .float anim_upper_time;
113
114 // when copying entities, copy these too
115 .int anim_implicit_state;
116 .float anim_implicit_time;
117 .float anim_lower_implicit_action;
118 .float anim_lower_implicit_time;
119 .float anim_upper_implicit_action;
120 .float anim_upper_implicit_time;
121
122 // explicit anim states (networked)
123 void animdecide_setstate(entity e, int newstate, float restart);
124 const int ANIMSTATE_DEAD1 = BIT(0); // base frames: die1
125 const int ANIMSTATE_DEAD2 = BIT(1); // base frames: die2
126 const int ANIMSTATE_DUCK = BIT(2); // turns walk into duckwalk, jump into duckjump, etc.
127 const int ANIMSTATE_FROZEN = BIT(3); // force idle
128 const int ANIMSTATE_FOLLOW = BIT(4); // also force idle
129
130 // implicit anim states (inferred from velocity, etc.)
131 const int ANIMIMPLICITSTATE_INAIR = BIT(0);
132 const int ANIMIMPLICITSTATE_FORWARD = BIT(1);
133 const int ANIMIMPLICITSTATE_BACKWARDS = BIT(2);
134 const int ANIMIMPLICITSTATE_LEFT = BIT(3);
135 const int ANIMIMPLICITSTATE_RIGHT = BIT(4);
136 const int ANIMIMPLICITSTATE_JUMPRELEASED = BIT(5);
137
138 // explicit actions (networked); negative values are for lower body
139 void animdecide_setaction(entity e, float action, float restart);
140 const int ANIMACTION_JUMP = -1; // jump
141 const int ANIMACTION_DRAW = 1; // draw
142 const int ANIMACTION_PAIN1 = 2; // pain
143 const int ANIMACTION_PAIN2 = 3; // pain
144 const int ANIMACTION_SHOOT = 4; // shoot
145 const int ANIMACTION_TAUNT = 5; // taunt
146 const int ANIMACTION_MELEE = 6; // melee
147 #endif