]> git.tdb.fi Git - libs/demoscene.git/blob - source/animate.cpp
Add stacked flag to Animate action
[libs/demoscene.git] / source / animate.cpp
1 #include "animate.h"
2 #include "demo.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace DemoScene {
8
9 Animate::Animate():
10         target(0),
11         anim(0),
12         stacked(false),
13         player(0)
14 { }
15
16 Animate::Animate(GL::Placeable &t, const GL::Animation &a, GL::AnimationPlayer &p):
17         target(&t),
18         anim(&a),
19         player(&p)
20 { }
21
22 void Animate::validate() const
23 {
24         if(!target)
25                 throw logic_error("null target");
26         if(!anim)
27                 throw logic_error("null animation");
28         if(!player)
29                 throw logic_error("null player");
30 }
31
32 void Animate::start(float, float d)
33 {
34         float speed = 1.0f;
35         if(!anim->is_looping() && d)
36                 speed = (anim->get_duration()/Time::sec)/d;
37         if(stacked)
38                 player->play_stacked(*target, *anim, speed);
39         else
40                 player->play(*target, *anim, speed);
41 }
42
43
44 Animate::Loader::Loader(Animate &a, Demo &d):
45         DataFile::DerivedObjectLoader<Animate, Action::Loader>(a, d)
46 {
47         a.player = &demo.get_animation_player();
48         add("animation", &Loader::animation);
49         add("stacked", &Animate::stacked);
50         add("target", &Loader::target);
51 }
52
53 void Animate::Loader::animation(const string &n)
54 {
55         obj.anim = &demo.get_resources().get<GL::Animation>(n);
56 }
57
58 void Animate::Loader::target(const string &n)
59 {
60         obj.target = &demo.get_thing<GL::Placeable>(n);
61 }
62
63 } // namespace DemoScene
64 } // namespace Msp