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