]> git.tdb.fi Git - libs/demoscene.git/commitdiff
Dynamically check for AnimatedObject in Animate
authorMikko Rasa <tdb@tdb.fi>
Sat, 8 Jun 2019 13:49:22 +0000 (16:49 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 8 Jun 2019 13:49:22 +0000 (16:49 +0300)
source/animate.cpp
source/animate.h

index cd6cda1d8faee1ccca2f6ecdd7cf19abefbf0c1b..c7eed389dd917e6436ca685c5a74ff84cad723dc 100644 (file)
@@ -34,10 +34,20 @@ void Animate::start(float, float d)
        float speed = 1.0f;
        if(!anim->is_looping() && d)
                speed = (anim->get_duration()/Time::sec)/d;
-       if(stacked)
-               player->play_stacked(*target, *anim, speed);
+       if(target_obj)
+       {
+               if(stacked)
+                       player->play_stacked(*target_obj, *anim, speed);
+               else
+                       player->play(*target_obj, *anim, speed);
+       }
        else
-               player->play(*target, *anim, speed);
+       {
+               if(stacked)
+                       player->play_stacked(*target, *anim, speed);
+               else
+                       player->play(*target, *anim, speed);
+       }
 }
 
 
@@ -58,6 +68,7 @@ void Animate::Loader::animation(const string &n)
 void Animate::Loader::target(const string &n)
 {
        obj.target = &demo.get_thing<GL::Placeable>(n);
+       obj.target_obj = dynamic_cast<GL::AnimatedObject *>(obj.target);
 }
 
 } // namespace DemoScene
index 30f0c527b9e952b0da433fa29e4073bd3f44f85e..50e279c57e67ae618f95bc6ea5efa70efbbbb569 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_DEMOSCENE_ANIMATE_H_
 #define MSP_DEMOSCENE_ANIMATE_H_
 
+#include <msp/gl/animatedobject.h>
 #include <msp/gl/animation.h>
 #include <msp/gl/animationplayer.h>
 #include "action.h"
@@ -23,6 +24,7 @@ public:
 
 private:
        Msp::GL::Placeable *target;
+       Msp::GL::AnimatedObject *target_obj;
        const Msp::GL::Animation *anim;
        bool stacked;
        Msp::GL::AnimationPlayer *player;