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