]> git.tdb.fi Git - libs/demoscene.git/commitdiff
Allow specifying one-off actions inside segments
authorMikko Rasa <tdb@tdb.fi>
Fri, 31 May 2019 19:27:53 +0000 (22:27 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 31 May 2019 19:27:53 +0000 (22:27 +0300)
source/sequencer.cpp
source/sequencer.h

index eeb41d20da6865b72eb0ab0c5097ad1a0805600a..0297c4397ff254bf30d26d95a44f4ec7909a1122 100644 (file)
@@ -159,7 +159,7 @@ void Sequencer::Loader::instant(float beat)
 
 void Sequencer::Loader::segment(float start, float end)
 {
-       SegmentLoader ldr(obj, start, end);
+       SegmentLoader ldr(obj, start, end, demo);
        load_sub_with(ldr);
 }
 
@@ -169,7 +169,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()
@@ -179,12 +179,15 @@ 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)
index 387cdde3cfbc0118047f045c37b5b8de3a198e3d..f8137177bbd73c31d792a5f59299187a49d99fdd 100644 (file)
@@ -31,13 +31,16 @@ public:
 
 private:
        class ActionDefLoader;
+       class SegmentLoader;
 
        class RegisteredAction
        {
        public:
-               typedef void (ActionDefLoader::*LoaderFunc)();
+               typedef void (ActionDefLoader::*DefLoaderFunc)();
+               typedef void (SegmentLoader::*LoaderFunc)();
 
                virtual ~RegisteredAction() { }
+               virtual DefLoaderFunc get_def_loader_func() const = 0;
                virtual LoaderFunc get_loader_func() const = 0;
        };
 
@@ -45,6 +48,7 @@ private:
        class RegisteredActionType: public RegisteredAction
        {
        public:
+               virtual DefLoaderFunc get_def_loader_func() const;
                virtual LoaderFunc get_loader_func() const;
        };
 
@@ -81,12 +85,19 @@ private:
        private:
                float start_beat;
                float end_beat;
+               Demo &demo;
 
        public:
-               SegmentLoader(Sequencer &, float, float);
+               SegmentLoader(Sequencer &, float, float, Demo &);
 
        private:
+               template<typename T>
+               void action();
+
                void apply(const std::string &);
+
+               template<typename T>
+               friend class RegisteredActionType;
        };
 
 public:
@@ -95,6 +106,7 @@ public:
 private:
        std::map<std::string, RegisteredAction *> action_types;
        std::map<std::string, Action *> named_actions;
+       std::vector<Action *> anonymous_actions;
 
        Msp::Time::TimeDelta secs_per_beat;
        std::vector<Action *> static_actions;
@@ -136,11 +148,17 @@ inline void Sequencer::register_action_type(const std::string &n)
 }
 
 template<typename T>
-Sequencer::RegisteredAction::LoaderFunc Sequencer::RegisteredActionType<T>::get_loader_func() const
+Sequencer::RegisteredAction::DefLoaderFunc Sequencer::RegisteredActionType<T>::get_def_loader_func() const
 {
        return &ActionDefLoader::action_def<T>;
 }
 
+template<typename T>
+Sequencer::RegisteredAction::LoaderFunc Sequencer::RegisteredActionType<T>::get_loader_func() const
+{
+       return &SegmentLoader::action<T>;
+}
+
 template<typename T>
 void Sequencer::ActionDefLoader::action_def()
 {
@@ -152,4 +170,13 @@ void Sequencer::ActionDefLoader::action_def()
        action = act;
 }
 
+template<typename T>
+void Sequencer::SegmentLoader::action()
+{
+       Msp::RefPtr<T> act = new T;
+       load_sub(*act, demo);
+       obj.add_action(*act, start_beat, end_beat);
+       obj.anonymous_actions.push_back(act.release());
+}
+
 #endif