1 #include <msp/time/utils.h>
10 Demo::Demo(Graphics::Window &window, Graphics::GLContext &gl_ctx, DataFile::Collection &r):
13 anim_action(anim_player),
19 things["window"] = static_cast<GL::View *>(&view);
21 sequencer.add_static_action(anim_action);
22 sequencer.signal_finished.connect(signal_finished);
33 void Demo::add_stage(const std::string &name, Stage &stage)
35 things[name] = &stage;
36 string prefix = name+".";
37 stage.add_things(things, prefix);
38 stage.define_actions(sequencer, prefix);
41 void Demo::set_fixed_framerate(float fps)
43 frame_interval = Time::sec/fps;
46 void Demo::enable_music()
49 music_source = new AL::Source;
51 streamer = new AL::Streamer(*music_source);
54 void Demo::play_music(const string &fn)
62 music_io = resources.open_raw(fn);
63 music_decoder = AL::SoundDecoder::open_io(*music_io);
64 float beat = sequencer.get_current_beat();
67 float time = beat*60/sequencer.get_beats_per_minute();
68 unsigned bytes_per_sec = music_decoder->get_frequency()*get_unit_size(music_decoder->get_format());
69 music_decoder->seek(time*bytes_per_sec);
71 streamer->play(*music_decoder);
76 Time::TimeStamp t = Time::now();
77 Time::TimeDelta dt = (last_tick ? frame_interval ? frame_interval : t-last_tick : Time::zero);
81 next_frame = t+frame_interval;
89 void Demo::seek(const Time::TimeDelta &pos)
91 sequencer.seek(pos*sequencer.get_beats_per_minute()/Time::min);
95 Demo::AnimationAction::AnimationAction(GL::AnimationPlayer &p):
99 void Demo::AnimationAction::tick(float, float d)
101 player.tick(d*Time::sec);
104 } // namespace DemoScene