]> git.tdb.fi Git - libs/demoscene.git/blobdiff - source/sequencer.cpp
Add a repeat statement
[libs/demoscene.git] / source / sequencer.cpp
index 3807e1c15a760777273cc65a0c7030287f8c7467..b4969bb30337182b35500b7ec378797bd8c1e86c 100644 (file)
@@ -1,12 +1,16 @@
 #include <cmath>
 #include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
+#include <msp/core/raii.h>
+#include "animate.h"
 #include "fadeoverlay.h"
 #include "sequencer.h"
 #include "stage.h"
 
 using namespace std;
-using namespace Msp;
+
+namespace Msp {
+namespace DemoScene {
 
 Sequencer::Sequencer(float bpm):
        started(false),
@@ -15,8 +19,10 @@ Sequencer::Sequencer(float bpm):
 {
        set_beats_per_minute(bpm);
 
+       register_action_type<Animate>("animate");
        register_action_type<FadeOverlay::Fade>("fade");
        register_action_type<Stage::UseInView>("use_stage");
+       register_action_type<Stage::SetCamera>("set_camera");
 }
 
 void Sequencer::set_beats_per_minute(float bpm)
@@ -34,12 +40,12 @@ void Sequencer::add_action(Action &act, float sb, float eb)
        if(sb<0 || sb>eb)
                throw invalid_argument("Sequencer::add_action");
 
-       Segment seq_act;
-       seq_act.action = &act;
-       seq_act.start_beat = sb;
-       seq_act.end_beat = eb;
+       Segment seg;
+       seg.action = &act;
+       seg.start_beat = sb;
+       seg.end_beat = eb;
        auto i = find_if(segments, [=](const Segment &s){ return s.start_beat>sb; });
-       segments.insert(i, seq_act);
+       segments.insert(i, seg);
 }
 
 void Sequencer::start()
@@ -135,13 +141,22 @@ void Sequencer::update_next_event()
 
 Sequencer::Loader::Loader(Sequencer &s, Demo &d):
        DataFile::ObjectLoader<Sequencer>(s),
-       demo(d)
+       demo(d),
+       base_beat(0.0f)
 {
+       add("base", &Loader::base);
        add("define_action", &Loader::define_action);
        add("instant", &Loader::instant);
+       add("repeat", &Loader::repeat);
        add("segment", &Loader::segment);
 }
 
+void Sequencer::Loader::base(float b)
+{
+       SetForScope<float> set_base(base_beat, base_beat+b);
+       load_sub_with(*this);
+}
+
 void Sequencer::Loader::define_action(const string &n)
 {
        ActionDefLoader ldr(obj, demo);
@@ -154,9 +169,18 @@ void Sequencer::Loader::instant(float beat)
        segment(beat, beat);
 }
 
+void Sequencer::Loader::repeat(float b, float d, unsigned n)
+{
+       for(unsigned i=0; i<n; ++i)
+       {
+               SetForScope<float> set_base(base_beat, base_beat+b+i*d);
+               load_sub_with(*this);
+       }
+}
+
 void Sequencer::Loader::segment(float start, float end)
 {
-       SegmentLoader ldr(obj, start, end);
+       SegmentLoader ldr(obj, base_beat+start, base_beat+end, demo);
        load_sub_with(ldr);
 }
 
@@ -166,7 +190,7 @@ Sequencer::ActionDefLoader::ActionDefLoader(Sequencer &s, Demo &d):
        demo(d)
 {
        for(const auto &t: obj.action_types)
-               add(t.first, t.second->get_loader_func());
+               add(t.first, t.second->get_def_loader_func());
 }
 
 void Sequencer::ActionDefLoader::finished()
@@ -176,15 +200,21 @@ void Sequencer::ActionDefLoader::finished()
 }
 
 
-Sequencer::SegmentLoader::SegmentLoader(Sequencer &s, float b, float e):
+Sequencer::SegmentLoader::SegmentLoader(Sequencer &s, float b, float e, Demo &d):
        ObjectLoader<Sequencer>(s),
        start_beat(b),
-       end_beat(e)
+       end_beat(e),
+       demo(d)
 {
        add("apply", &SegmentLoader::apply);
+       for(const auto &t: obj.action_types)
+               add(t.first, t.second->get_loader_func());
 }
 
 void Sequencer::SegmentLoader::apply(const string &n)
 {
        obj.add_action(*get_item(obj.named_actions, n), start_beat, end_beat);
 }
+
+} // namespace DemoScene
+} // namespace Msp