]> git.tdb.fi Git - libs/demoscene.git/blob - source/animate.cpp
Do not scale looping animation duration
[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 = 1.0f;
34         if(!anim->is_looping() && d)
35                 speed = (anim->get_duration()/Time::sec)/d;
36         player->play(*target, *anim, speed);
37 }
38
39
40 Animate::Loader::Loader(Animate &a, Demo &d):
41         DataFile::DerivedObjectLoader<Animate, Action::Loader>(a, d)
42 {
43         a.player = &demo.get_animation_player();
44         add("animation", &Loader::animation);
45         add("target", &Loader::target);
46 }
47
48 void Animate::Loader::animation(const string &n)
49 {
50         obj.anim = &demo.get_resources().get<GL::Animation>(n);
51 }
52
53 void Animate::Loader::target(const string &n)
54 {
55         obj.target = &demo.get_thing<GL::Placeable>(n);
56 }
57
58 } // namespace DemoScene
59 } // namespace Msp