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 stage.add_things(things, name+".");
39 void Demo::set_fixed_framerate(float fps)
41 frame_interval = Time::sec/fps;
44 void Demo::enable_music()
47 music_source = new AL::Source;
49 streamer = new AL::Streamer(*music_source);
52 void Demo::play_music(const string &fn)
60 music_io = resources.open_raw(fn);
61 music_decoder = AL::SoundDecoder::open_io(*music_io);
62 float beat = sequencer.get_current_beat();
65 float time = beat*60/sequencer.get_beats_per_minute();
66 unsigned bytes_per_sec = music_decoder->get_frequency()*get_unit_size(music_decoder->get_format());
67 music_decoder->seek(time*bytes_per_sec);
69 streamer->play(*music_decoder);
74 Time::TimeStamp t = Time::now();
75 Time::TimeDelta dt = (last_tick ? frame_interval ? frame_interval : t-last_tick : Time::zero);
79 next_frame = t+frame_interval;
87 void Demo::seek(const Time::TimeDelta &pos)
89 sequencer.seek(pos*sequencer.get_beats_per_minute()/Time::min);
93 Demo::AnimationAction::AnimationAction(GL::AnimationPlayer &p):
97 void Demo::AnimationAction::tick(float, float d)
99 player.tick(d*Time::sec);
102 } // namespace DemoScene