]> git.tdb.fi Git - libs/demoscene.git/blobdiff - source/demo.cpp
Make it possible for Stages to add things to the Demo
[libs/demoscene.git] / source / demo.cpp
index 41e9641510b3a052af761a6e688d2acb963e6a64..c5456853c55495fc41665b2813af2abfa0bb8f22 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/time/utils.h>
 #include "demo.h"
+#include "stage.h"
 
 using namespace std;
 using namespace Msp;
@@ -7,11 +8,15 @@ using namespace Msp;
 Demo::Demo(Graphics::Window &window, Graphics::GLContext &gl_ctx, DataFile::Collection &r):
        resources(r),
        view(window, gl_ctx),
+       anim_action(anim_player),
        music_source(0),
        streamer(0),
        music_io(0),
        music_decoder(0)
 {
+       things["window"] = static_cast<GL::View *>(&view);
+
+       sequencer.add_static_action(anim_action);
        sequencer.signal_finished.connect(signal_finished);
 }
 
@@ -23,6 +28,12 @@ Demo::~Demo()
        delete music_source;
 }
 
+void Demo::add_stage(const std::string &name, Stage &stage)
+{
+       things[name] = &stage;
+       stage.add_things(things, name+".");
+}
+
 void Demo::set_fixed_framerate(float fps)
 {
        frame_interval = Time::sec/fps;
@@ -75,3 +86,13 @@ void Demo::seek(const Time::TimeDelta &pos)
 {
        sequencer.seek(pos*sequencer.get_beats_per_minute()/Time::min);
 }
+
+
+Demo::AnimationAction::AnimationAction(GL::AnimationPlayer &p):
+       player(p)
+{ }
+
+void Demo::AnimationAction::tick(float, float d)
+{
+       player.tick(d*Time::sec);
+}