]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/animdecide.qh
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / animdecide.qh
index 7cf7ee45509d530d4fee3c2002c266179be2f755..16feb948c35d5c2264b9bdc21329c531c47ae2d9 100644 (file)
@@ -1,5 +1,4 @@
-#ifndef ANIMDECIDE_H
-#define ANIMDECIDE_H
+#pragma once
 
 // must be called at least once to initialize, or when modelindex is changed
 void animdecide_load_if_needed(entity e);
@@ -9,15 +8,15 @@ void animdecide_setimplicitstate(entity e, float onground);
 void animdecide_setframes(entity e, bool support_blending, .int fld_frame, .int fld_frame1time, .int fld_frame2, .int fld_frame2time);
 
 CLASS(Animation, Object)
-       ATTRIB(Animation, m_framenames, string, string_null)
-       METHOD(Animation, anim_getframe, int(Animation this, int mdlidx))
+       ATTRIB(Animation, m_framenames, string);
+       STATIC_METHOD(Animation, getframe, int(Animation this, int mdlidx))
        {
                FOREACH_WORD(this.m_framenames, true, {
                        int f = frameforname(mdlidx, it);
                        if (f != -1) return f;
                });
 #ifdef CSQC
-               LOG_WARNINGF("Missing animation for %s: %s\n", modelnameforindex(mdlidx), this.registered_id);
+               LOG_DEBUGF("Missing animation for %s: %s", modelnameforindex(mdlidx), this.registered_id);
 #endif
                return -1;
        }
@@ -25,22 +24,23 @@ ENDCLASS(Animation)
 
 REGISTRY(Animations, BITS(8))
 REGISTER_REGISTRY(Animations)
+#define Animations_from(id) _Animations_from(id, NULL)
+#define WriteAnimation(to, it) WriteRegistered(Animations, to, it)
+#define ReadAnimation() ReadRegistered(Animations)
 #define REGISTER_ANIMATION(id, framenames) \
        .vector anim_##id; \
        REGISTER(Animations, ANIM_##id, m_id, NEW(Animation)) { \
                this.m_framenames = framenames; \
        }
 
-vector _ANIM_VEC_v;
-Animation _ANIM_VEC_a;
-#define ANIM_VEC(anim, numframes, framerate) \
-( \
-       _ANIM_VEC_v.y = numframes, \
-       _ANIM_VEC_v.z = framerate, \
-       _ANIM_VEC_a = ANIM_##anim, \
-       _ANIM_VEC_v.x = _ANIM_VEC_a.anim_getframe(_ANIM_VEC_a, mdlidx), \
-       _ANIM_VEC_v \
-)
+vector anim_vec(Animation anim, int mdlidx, int numframes, float framerate)
+{
+       vector v;
+       v.x = Animation_getframe(anim, mdlidx);
+       v.y = numframes;
+       v.z = framerate;
+       return v;
+}
 
 // player animation data for this model
 // each vector is as follows:
@@ -51,12 +51,9 @@ Animation _ANIM_VEC_a;
 REGISTER_ANIMATION(die1, "dieone groupified_0_anim");
 /** player dies differently */
 REGISTER_ANIMATION(die2, "dietwo groupified_1_anim");
-/**  */
-REGISTER_ANIMATION(dead1, "deadone groupified_17_anim");
-/**  */
-REGISTER_ANIMATION(dead2, "deadtwo groupified_18_anim");
 /** player pulls out a weapon */
 REGISTER_ANIMATION(draw, "draw groupified_2_anim");
+REGISTER_ANIMATION(duck, "duck groupified_3_anim");
 /** player walking while crouching */
 REGISTER_ANIMATION(duckwalk, "duckwalk groupified_4_anim");
 /** player jumping from a crouch */
@@ -83,6 +80,10 @@ REGISTER_ANIMATION(runbackwards, "runbackwards groupified_14_anim");
 REGISTER_ANIMATION(strafeleft, "strafeleft groupified_15_anim");
 /** player shuffling right quickly */
 REGISTER_ANIMATION(straferight, "straferight groupified_16_anim");
+/**  */
+REGISTER_ANIMATION(dead1, "deadone groupified_17_anim");
+/**  */
+REGISTER_ANIMATION(dead2, "deadtwo groupified_18_anim");
 /** player running forward and right */
 REGISTER_ANIMATION(forwardright, "forwardright groupified_19_anim");
 /** player running forward and left */
@@ -93,7 +94,6 @@ REGISTER_ANIMATION(backright, "backright groupified_21_anim");
 REGISTER_ANIMATION(backleft, "backleft groupified_22_anim");
 /** player doing the melee action */
 REGISTER_ANIMATION(melee, "melee groupified_23_anim");
-REGISTER_ANIMATION(duck, "duck groupified_3_anim");
 REGISTER_ANIMATION(duckwalkbackwards, "duckwalkbackwards groupified_24_anim");
 REGISTER_ANIMATION(duckwalkstrafeleft, "duckwalkstrafeleft duckstrafeleft groupified_25_anim");
 REGISTER_ANIMATION(duckwalkstraferight, "duckwalkstraferight duckstraferight groupified_26_anim");
@@ -144,4 +144,3 @@ const int ANIMACTION_PAIN2 = 3; // pain
 const int ANIMACTION_SHOOT = 4; // shoot
 const int ANIMACTION_TAUNT = 5; // taunt
 const int ANIMACTION_MELEE = 6; // melee
-#endif