From 88efa77af94256992ba2c05f4d7b5b5a9d01d6e9 Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Wed, 30 Dec 2015 17:51:46 +0300
Subject: Add debug flag for debugging animated sprites.

---
 src/localconsts.h                       |  3 +++
 src/resources/sprite/animatedsprite.cpp |  9 +++++++++
 src/resources/sprite/animatedsprite.h   | 11 +++++++++++
 3 files changed, 23 insertions(+)

diff --git a/src/localconsts.h b/src/localconsts.h
index 3c40ca96c..69f0defd5 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -225,6 +225,9 @@
 // use OpenGL debug features
 // #define DEBUG_OPENGL 1
 
+// debug animations
+// #define DEBUG_ANIMATIONS 1
+
 #ifdef DYECMD
 #undef USE_FUZZER
 #endif
diff --git a/src/resources/sprite/animatedsprite.cpp b/src/resources/sprite/animatedsprite.cpp
index 98d4b418d..43c11497a 100644
--- a/src/resources/sprite/animatedsprite.cpp
+++ b/src/resources/sprite/animatedsprite.cpp
@@ -70,6 +70,9 @@ AnimatedSprite *AnimatedSprite::load(const std::string &restrict filename,
     if (!s)
         return nullptr;
     AnimatedSprite *restrict const as = new AnimatedSprite(s);
+#ifdef DEBUG_ANIMATIONS
+    as->setSpriteName(filename);
+#endif
     as->play(SpriteAction::STAND);
     s->decRef();
     return as;
@@ -90,6 +93,9 @@ AnimatedSprite *AnimatedSprite::delayedLoad(const std::string &restrict
     }
 
     AnimatedSprite *restrict const as = new AnimatedSprite(nullptr);
+#ifdef DEBUG_ANIMATIONS
+    as->setSpriteName(filename);
+#endif
     as->play(SpriteAction::STAND);
     as->setDelayLoad(filename, variant);
     return as;
@@ -101,6 +107,9 @@ AnimatedSprite *AnimatedSprite::clone(const AnimatedSprite *restrict const
     if (!anim)
         return nullptr;
     AnimatedSprite *restrict const sprite = new AnimatedSprite(anim->mSprite);
+#ifdef DEBUG_ANIMATIONS
+    sprite->setSpriteName(anim->getSpriteName());
+#endif
     sprite->play(SpriteAction::STAND);
     return sprite;
 }
diff --git a/src/resources/sprite/animatedsprite.h b/src/resources/sprite/animatedsprite.h
index f9971cb5b..03b276a9b 100644
--- a/src/resources/sprite/animatedsprite.h
+++ b/src/resources/sprite/animatedsprite.h
@@ -129,12 +129,23 @@ class AnimatedSprite final : public Sprite
         { return mFrameTime; }
 #endif
 
+#ifdef DEBUG_ANIMATIONS
+        void setSpriteName(const std::string &restrict name)
+        { mSpriteName = name; }
+
+        std::string getSpriteName() const A_WARN_UNUSED
+        { return mSpriteName; }
+#endif
+
     private:
         bool updateCurrentAnimation(const unsigned int dt) restrict2;
 
         void setDelayLoad(const std::string &restrict filename,
                           const int variant) restrict2;
 
+#ifdef DEBUG_ANIMATIONS
+        std::string mSpriteName;
+#endif
         SpriteDirection::Type mDirection;  /**< The sprite direction. */
         int mLastTime;                 /**< The last time update was called. */
 
-- 
cgit v1.2.3-70-g09d2