Xonotic
animdecide.qh
Go to the documentation of this file.
1 #pragma once
2 
3 // must be called at least once to initialize, or when modelindex is changed
5 
6 // client side frame inferring
7 void animdecide_setimplicitstate(entity e, float onground);
8 void animdecide_setframes(entity e, bool support_blending, .int fld_frame, .int fld_frame1time, .int fld_frame2, .int fld_frame2time);
9 
11  ATTRIB(Animation, m_framenames, string);
12  STATIC_METHOD(Animation, getframe, int(Animation this, int mdlidx))
13  {
14  FOREACH_WORD(this.m_framenames, true, {
15  int f = frameforname(mdlidx, it);
16  if (f != -1) return f;
17  });
18 #ifdef CSQC
19  LOG_DEBUGF("Missing animation for %s: %s", modelnameforindex(mdlidx), this.registered_id);
20 #endif
21  return -1;
22  }
24 
25 REGISTRY(Animations, BITS(8))
26 REGISTER_REGISTRY(Animations)
27 
28 REGISTRY_DEFINE_GET(Animations, NULL)
29 #define WriteAnimation(to, it) WriteRegistered(Animations, to, it)
30 #define ReadAnimation() ReadRegistered(Animations)
31 #define REGISTER_ANIMATION(id, framenames) \
32  .vector anim_##id; \
33  REGISTER(Animations, ANIM_##id, m_id, NEW(Animation)) { \
34  this.m_framenames = framenames; \
35  }
36 
37 vector anim_vec(Animation anim, int mdlidx, int numframes, float framerate)
38 {
39  vector v;
40  v.x = Animation_getframe(anim, mdlidx);
41  v.y = numframes;
42  v.z = framerate;
43  return v;
44 }
45 
46 // player animation data for this model
47 // each vector is as follows:
48 // _x = startframe
49 // _y = numframes
50 // _z = framerate
52 REGISTER_ANIMATION(die1, "dieone groupified_0_anim");
54 REGISTER_ANIMATION(die2, "dietwo groupified_1_anim");
56 REGISTER_ANIMATION(draw, "draw groupified_2_anim");
57 REGISTER_ANIMATION(duck, "duck groupified_3_anim");
59 REGISTER_ANIMATION(duckwalk, "duckwalk groupified_4_anim");
61 REGISTER_ANIMATION(duckjump, "duckjump groupified_5_anim");
63 REGISTER_ANIMATION(duckidle, "duckidle groupified_6_anim");
65 REGISTER_ANIMATION(idle, "idle groupified_7_anim");
67 REGISTER_ANIMATION(jump, "jump groupified_8_anim");
69 REGISTER_ANIMATION(pain1, "painone groupified_9_anim");
71 REGISTER_ANIMATION(pain2, "paintwo groupified_10_anim");
73 REGISTER_ANIMATION(shoot, "shoot groupified_11_anim");
75 REGISTER_ANIMATION(taunt, "taunt groupified_12_anim");
77 REGISTER_ANIMATION(run, "run groupified_13_anim");
79 REGISTER_ANIMATION(runbackwards, "runbackwards groupified_14_anim");
81 REGISTER_ANIMATION(strafeleft, "strafeleft groupified_15_anim");
83 REGISTER_ANIMATION(straferight, "straferight groupified_16_anim");
85 REGISTER_ANIMATION(dead1, "deadone groupified_17_anim");
87 REGISTER_ANIMATION(dead2, "deadtwo groupified_18_anim");
89 REGISTER_ANIMATION(forwardright, "forwardright groupified_19_anim");
91 REGISTER_ANIMATION(forwardleft, "forwardleft groupified_20_anim");
93 REGISTER_ANIMATION(backright, "backright groupified_21_anim");
95 REGISTER_ANIMATION(backleft, "backleft groupified_22_anim");
97 REGISTER_ANIMATION(melee, "melee groupified_23_anim");
98 REGISTER_ANIMATION(duckwalkbackwards, "duckwalkbackwards groupified_24_anim");
99 REGISTER_ANIMATION(duckwalkstrafeleft, "duckwalkstrafeleft duckstrafeleft groupified_25_anim");
100 REGISTER_ANIMATION(duckwalkstraferight, "duckwalkstraferight duckstraferight groupified_26_anim");
101 REGISTER_ANIMATION(duckwalkforwardright, "duckwalkforwardright duckforwardright groupified_27_anim");
102 REGISTER_ANIMATION(duckwalkforwardleft, "duckwalkforwardleft groupified_28_anim");
103 REGISTER_ANIMATION(duckwalkbackright, "duckwalkbackright duckbackwardright groupified_29_anim");
104 REGISTER_ANIMATION(duckwalkbackleft, "duckwalkbackleft duckbackwardleft groupified_30_anim");
106 
107 // please network this one
109 .float anim_time;
114 
115 // when copying entities, copy these too
122 
123 // explicit anim states (networked)
124 void animdecide_setstate(entity e, int newstate, float restart);
125 const int ANIMSTATE_DEAD1 = BIT(0); // base frames: die1
126 const int ANIMSTATE_DEAD2 = BIT(1); // base frames: die2
127 const int ANIMSTATE_DUCK = BIT(2); // turns walk into duckwalk, jump into duckjump, etc.
128 const int ANIMSTATE_FROZEN = BIT(3); // force idle
129 const int ANIMSTATE_FOLLOW = BIT(4); // also force idle
130 
131 // implicit anim states (inferred from velocity, etc.)
138 
139 // explicit actions (networked); negative values are for lower body
140 void animdecide_setaction(entity e, float action, float restart);
141 const int ANIMACTION_JUMP = -1; // jump
142 const int ANIMACTION_DRAW = 1; // draw
143 const int ANIMACTION_PAIN1 = 2; // pain
144 const int ANIMACTION_PAIN2 = 3; // pain
145 const int ANIMACTION_SHOOT = 4; // shoot
146 const int ANIMACTION_TAUNT = 5; // taunt
147 const int ANIMACTION_MELEE = 6; // melee
const int ANIMIMPLICITSTATE_BACKWARDS
Definition: animdecide.qh:134
const int ANIMSTATE_FROZEN
Definition: animdecide.qh:128
void animdecide_setaction(entity e, float action, float restart)
Definition: animdecide.qc:338
vector anim_vec(Animation anim, int mdlidx, int numframes, float framerate)
Definition: animdecide.qh:37
string registered_id
registered item identifier
Definition: registry.qh:60
float anim_upper_action
Definition: animdecide.qh:112
CLASS(Object) Object
Definition: oo.qh:318
float animdecide_modelindex
Definition: animdecide.qh:105
float anim_lower_action
Definition: animdecide.qh:110
const int ANIMACTION_JUMP
Definition: animdecide.qh:141
entity() spawn
const int ANIMIMPLICITSTATE_JUMPRELEASED
Definition: animdecide.qh:137
void animdecide_load_if_needed(entity e)
Definition: animdecide.qc:53
float anim_lower_implicit_time
Definition: animdecide.qh:119
void animdecide_setframes(entity e, bool support_blending,.int fld_frame,.int fld_frame1time,.int fld_frame2,.int fld_frame2time)
int anim_implicit_state
Definition: animdecide.qh:116
const int ANIMACTION_PAIN2
Definition: animdecide.qh:144
float anim_upper_time
Definition: animdecide.qh:113
const int ANIMSTATE_FOLLOW
Definition: animdecide.qh:129
const int ANIMIMPLICITSTATE_FORWARD
Definition: animdecide.qh:133
#define FOREACH_WORD(words, cond, body)
Definition: iter.qh:33
#define ATTRIB(...)
Definition: oo.qh:136
#define REGISTER_REGISTRY(id)
Definition: registry.qh:212
float anim_upper_implicit_time
Definition: animdecide.qh:121
#define REGISTER_ANIMATION(id, framenames)
Definition: animdecide.qh:31
#define REGISTRY_DEFINE_GET(id, null)
Definition: registry.qh:40
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition: bits.qh:8
const int ANIMIMPLICITSTATE_LEFT
Definition: animdecide.qh:135
#define REGISTRY(id, max)
Declare a new registry.
Definition: registry.qh:26
const int ANIMIMPLICITSTATE_RIGHT
Definition: animdecide.qh:136
#define NULL
Definition: post.qh:17
const int ANIMACTION_SHOOT
Definition: animdecide.qh:145
int anim_state
Definition: animdecide.qh:108
void animdecide_setimplicitstate(entity e, float onground)
Definition: animdecide.qc:248
const int ANIMACTION_PAIN1
Definition: animdecide.qh:143
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector v
Definition: ent_cs.qc:116
float anim_lower_implicit_action
Definition: animdecide.qh:118
const int ANIMACTION_DRAW
Definition: animdecide.qh:142
float anim_lower_time
Definition: animdecide.qh:111
const int ANIMIMPLICITSTATE_INAIR
Definition: animdecide.qh:132
#define ENDCLASS(cname)
Definition: oo.qh:269
const int ANIMACTION_TAUNT
Definition: animdecide.qh:146
float anim_implicit_time
Definition: animdecide.qh:117
const int ANIMSTATE_DEAD2
Definition: animdecide.qh:126
void animdecide_setstate(entity e, int newstate, float restart)
Definition: animdecide.qc:330
#define STATIC_METHOD(cname, name, prototype)
Definition: oo.qh:266
const int ANIMSTATE_DEAD1
Definition: animdecide.qh:125
const int ANIMACTION_MELEE
Definition: animdecide.qh:147
float anim_upper_implicit_action
Definition: animdecide.qh:120
const int ANIMSTATE_DUCK
Definition: animdecide.qh:127
float anim_time
Definition: animdecide.qh:109
#define BITS(n)
Definition: bits.qh:9
#define LOG_DEBUGF(...)
Definition: log.qh:86