]> git.tdb.fi Git - libs/demoscene.git/blobdiff - source/sequencer.cpp
Use LoadableTypeRegistry to manage action types in Sequencer
[libs/demoscene.git] / source / sequencer.cpp
index 8bca70bb368764d7a94058b95aaf595623a95913..25182b8ef6ee7f4e623b83cfc942f8fe17339e86 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)
@@ -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);
 }
 
@@ -165,26 +189,28 @@ Sequencer::ActionDefLoader::ActionDefLoader(Sequencer &s, Demo &d):
        DataFile::ObjectLoader<Sequencer>(s),
        demo(d)
 {
-       for(const auto &t: obj.action_types)
-               add(t.first, t.second->get_loader_func());
-}
-
-void Sequencer::ActionDefLoader::finished()
-{
-       if(action)
-               action->validate();
+       obj.action_registry.add_all(*this);
 }
 
 
-Sequencer::SegmentLoader::SegmentLoader(Sequencer &s, float b, float e):
-       ObjectLoader<Sequencer>(s),
+Sequencer::SegmentLoader::SegmentLoader(Sequencer &s, float b, float e, Demo &d):
+       ActionDefLoader(s, d),
        start_beat(b),
        end_beat(e)
 {
        add("apply", &SegmentLoader::apply);
 }
 
+void Sequencer::SegmentLoader::action_loaded()
+{
+       obj.add_action(*action, start_beat, end_beat);
+       obj.anonymous_actions.push_back(action.release());
+}
+
 void Sequencer::SegmentLoader::apply(const string &n)
 {
        obj.add_action(*get_item(obj.named_actions, n), start_beat, end_beat);
 }
+
+} // namespace DemoScene
+} // namespace Msp