]> git.tdb.fi Git - libs/demoscene.git/blob - source/demo.h
Framework for loading sequences from files
[libs/demoscene.git] / source / demo.h
1 #ifndef MSP_DEMOSCENE_DEMO_H_
2 #define MSP_DEMOSCENE_DEMO_H_
3
4 #include <map>
5 #include <string>
6 #include <sigc++/signal.h>
7 #include <msp/al/sounddecoder.h>
8 #include <msp/al/source.h>
9 #include <msp/al/streamer.h>
10 #include <msp/datafile/collection.h>
11 #include <msp/gl/windowview.h>
12 #include "sequencer.h"
13
14 class Demo
15 {
16 public:
17         sigc::signal<void> signal_finished;
18
19 protected:
20         Sequencer sequencer;
21         Msp::DataFile::Collection &resources;
22         Msp::GL::WindowView view;
23         Msp::AL::Source *music_source;
24         Msp::AL::Streamer *streamer;
25         Msp::IO::Seekable *music_io;
26         Msp::AL::SoundDecoder *music_decoder;
27         Msp::Time::TimeDelta frame_interval;
28         Msp::Time::TimeStamp last_tick;
29         Msp::Time::TimeStamp next_frame;
30
31         std::map<std::string, Msp::Variant> things;
32
33         Demo(Msp::Graphics::Window &, Msp::Graphics::GLContext &, Msp::DataFile::Collection &);
34 public:
35         virtual ~Demo();
36
37         template<typename T>
38         T &get_thing(const std::string &);
39
40         void set_fixed_framerate(float);
41         const Msp::Time::TimeStamp &get_next_frame_time() const { return next_frame; }
42         void enable_music();
43         void play_music(const std::string &);
44         virtual void tick();
45         void seek(const Msp::Time::TimeDelta &);
46 };
47
48 template<typename T>
49 T &Demo::get_thing(const std::string &name)
50 {
51         return *get_item(things, name).value<T *>();
52 }
53
54 #endif