]> git.tdb.fi Git - libs/demoscene.git/blob - source/action.cpp
Allow stages to define actions
[libs/demoscene.git] / source / action.cpp
1 #include "action.h"
2
3 namespace Msp {
4 namespace DemoScene {
5
6 InterpolationAction::InterpolationAction(Mode m):
7         mode(m),
8         start_beat(0),
9         duration(0)
10 { }
11
12 void InterpolationAction::start(float b, float d)
13 {
14         start_beat = b;
15         duration = d;
16         interpolate(0.0f, 0.0f);
17 }
18
19 void InterpolationAction::tick(float b, float d)
20 {
21         if(duration)
22         {
23                 float t = (b-start_beat)/duration;
24                 float dt = d/duration;
25                 if(mode==HERMITE)
26                 {
27                         dt = t-dt;
28                         t = (3-2*t)*t*t;
29                         dt = t-(3-2*dt)*dt*dt;
30                 }
31                 interpolate(t, dt);
32         }
33         else
34                 interpolate(1.0f, 1.0f);
35 }
36
37 void InterpolationAction::end(float)
38 {
39         interpolate(1.0f, 0.0f);
40 }
41
42
43 Action::Loader::Loader(Action &a, Demo &d):
44         DataFile::ObjectLoader<Action>(a),
45         demo(d)
46 { }
47
48 } // namespace DemoScene
49 } // namespace Msp