]> git.tdb.fi Git - libs/demoscene.git/blobdiff - source/sequencer.cpp
Framework for loading sequences from files
[libs/demoscene.git] / source / sequencer.cpp
index d9d35614dbf4ed9fd897b60e5c5df67ee68d5f11..917108b7878753a987e88d7c931a6e6a69760586 100644 (file)
@@ -1,6 +1,6 @@
 #include <cmath>
 #include <msp/core/algorithm.h>
-#include "action.h"
+#include <msp/core/maputils.h>
 #include "sequencer.h"
 
 using namespace std;
@@ -126,3 +126,60 @@ void Sequencer::update_next_event()
                if(i->end_beat>beat)
                        next_event = min(next_event, i->end_beat);
 }
+
+
+Sequencer::Loader::Loader(Sequencer &s, Demo &d):
+       DataFile::ObjectLoader<Sequencer>(s),
+       demo(d)
+{
+       add("define_action", &Loader::define_action);
+       add("instant", &Loader::instant);
+       add("segment", &Loader::segment);
+}
+
+void Sequencer::Loader::define_action(const string &n)
+{
+       ActionDefLoader ldr(obj, demo);
+       load_sub_with(ldr);
+       obj.named_actions[n] = ldr.get_action();
+}
+
+void Sequencer::Loader::instant(float beat)
+{
+       segment(beat, beat);
+}
+
+void Sequencer::Loader::segment(float start, float end)
+{
+       SegmentLoader ldr(obj, start, end);
+       load_sub_with(ldr);
+}
+
+
+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();
+}
+
+
+Sequencer::SegmentLoader::SegmentLoader(Sequencer &s, float b, float e):
+       ObjectLoader<Sequencer>(s),
+       start_beat(b),
+       end_beat(e)
+{
+       add("apply", &SegmentLoader::apply);
+}
+
+void Sequencer::SegmentLoader::apply(const string &n)
+{
+       obj.add_action(*get_item(obj.named_actions, n), start_beat, end_beat);
+}