]> git.tdb.fi Git - libs/demoscene.git/blob - source/animate.cpp
f30281d7b33401a745e621462dbe32d7c8ebfa1d
[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         player(0)
13 { }
14
15 Animate::Animate(GL::Placeable &t, const GL::Animation &a, GL::AnimationPlayer &p):
16         target(&t),
17         anim(&a),
18         player(&p)
19 { }
20
21 void Animate::validate() const
22 {
23         if(!target)
24                 throw logic_error("null target");
25         if(!anim)
26                 throw logic_error("null animation");
27         if(!player)
28                 throw logic_error("null player");
29 }
30
31 void Animate::start(float, float d)
32 {
33         float speed = (d ? (anim->get_duration()/Time::sec)/d : 1.0f);
34         player->play(*target, *anim, speed);
35 }
36
37
38 Animate::Loader::Loader(Animate &a, Demo &d):
39         DataFile::DerivedObjectLoader<Animate, Action::Loader>(a, d)
40 {
41         a.player = &demo.get_animation_player();
42         add("animation", &Loader::animation);
43         add("target", &Loader::target);
44 }
45
46 void Animate::Loader::animation(const string &n)
47 {
48         obj.anim = &demo.get_resources().get<GL::Animation>(n);
49 }
50
51 void Animate::Loader::target(const string &n)
52 {
53         obj.target = &demo.get_thing<GL::Placeable>(n);
54 }
55
56 } // namespace DemoScene
57 } // namespace Msp