]> git.tdb.fi Git - libs/demoscene.git/blob - source/demo.h
e9d369bf9b337b202480b8ef1cf128a47127fb80
[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/animationplayer.h>
12 #include <msp/gl/windowview.h>
13 #include "action.h"
14 #include "sequencer.h"
15
16 class Demo
17 {
18 private:
19         class AnimationAction: public Action
20         {
21         private:
22                 Msp::GL::AnimationPlayer &player;
23
24         public:
25                 AnimationAction(Msp::GL::AnimationPlayer &);
26
27                 virtual void validate() const { }
28
29                 virtual void tick(float, float);
30         };
31
32 public:
33         sigc::signal<void> signal_finished;
34
35 protected:
36         Sequencer sequencer;
37         Msp::DataFile::Collection &resources;
38         Msp::GL::WindowView view;
39         Msp::GL::AnimationPlayer anim_player;
40         AnimationAction anim_action;
41         Msp::AL::Source *music_source;
42         Msp::AL::Streamer *streamer;
43         Msp::IO::Seekable *music_io;
44         Msp::AL::SoundDecoder *music_decoder;
45         Msp::Time::TimeDelta frame_interval;
46         Msp::Time::TimeStamp last_tick;
47         Msp::Time::TimeStamp next_frame;
48
49         std::map<std::string, Msp::Variant> things;
50
51         Demo(Msp::Graphics::Window &, Msp::Graphics::GLContext &, Msp::DataFile::Collection &);
52 public:
53         virtual ~Demo();
54
55         Msp::DataFile::Collection &get_resources() const { return resources; }
56         Msp::GL::AnimationPlayer &get_animation_player() { return anim_player; }
57
58         template<typename T>
59         T &get_thing(const std::string &);
60
61         void set_fixed_framerate(float);
62         const Msp::Time::TimeStamp &get_next_frame_time() const { return next_frame; }
63         void enable_music();
64         void play_music(const std::string &);
65         virtual void tick();
66         void seek(const Msp::Time::TimeDelta &);
67 };
68
69 template<typename T>
70 T &Demo::get_thing(const std::string &name)
71 {
72         return *get_item(things, name).value<T *>();
73 }
74
75 #endif