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