]> git.tdb.fi Git - libs/demoscene.git/commitdiff
Make some simple actions loadable
authorMikko Rasa <tdb@tdb.fi>
Wed, 22 May 2019 11:47:13 +0000 (14:47 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 22 May 2019 11:49:02 +0000 (14:49 +0300)
source/demo.cpp
source/fadeoverlay.cpp
source/fadeoverlay.h
source/sequencer.cpp
source/stage.cpp
source/stage.h

index 41e9641510b3a052af761a6e688d2acb963e6a64..2072f297bc9ca1e84edeb9a3f5bd81cd17abcbee 100644 (file)
@@ -12,6 +12,8 @@ Demo::Demo(Graphics::Window &window, Graphics::GLContext &gl_ctx, DataFile::Coll
        music_io(0),
        music_decoder(0)
 {
+       things["window"] = static_cast<GL::View *>(&view);
+
        sequencer.signal_finished.connect(signal_finished);
 }
 
index 46ebd58fceababa12181f6e5be65e6b005537fef..ab069c3477e79e69a339ca916cb62749eb94ead2 100644 (file)
@@ -1,9 +1,11 @@
 #include <msp/datafile/collection.h>
 #include <msp/gl/renderer.h>
 #include <msp/gl/texture2d.h>
+#include "demo.h"
 #include "fadeoverlay.h"
 
 using namespace Msp;
+using namespace std;
 
 FadeOverlay::FadeOverlay(DataFile::Collection &resources):
        mesh(get_fullscreen_quad()),
@@ -28,7 +30,36 @@ void FadeOverlay::render(GL::Renderer &renderer, const GL::Texture2D &color_buf,
 }
 
 
+FadeOverlay::Fade::Fade():
+       ColorFadeAction(GL::Color(0.0f, 0.0f, 0.0f, 0.0f)),
+       overlay(0)
+{ }
+
 FadeOverlay::Fade::Fade(FadeOverlay &o, const GL::Color &c):
        ColorFadeAction(c),
-       overlay(o)
+       overlay(&o)
 { }
+
+void FadeOverlay::Fade::validate() const
+{
+       if(!overlay)
+               throw logic_error("null overlay");
+}
+
+
+FadeOverlay::Fade::Loader::Loader(Fade &f, Demo &d):
+       DataFile::DerivedObjectLoader<Fade, Action::Loader>(f, d)
+{
+       add("overlay", &Loader::overlay);
+       add("color", &Loader::color);
+}
+
+void FadeOverlay::Fade::Loader::overlay(const string &n)
+{
+       obj.overlay = &demo.get_thing<FadeOverlay>(n);
+}
+
+void FadeOverlay::Fade::Loader::color(float r, float g, float b, float a)
+{
+       obj.end_color = GL::Color(r, g, b, a);
+}
index 988a0e12ab46f3e4ae9acdf0fd0ca33dcdbae669..e25d16848ebe054fa166f244ed81b2480f9ea226 100644 (file)
@@ -14,16 +14,28 @@ class FadeOverlay: public Msp::GL::PostProcessor
 public:
        class Fade: public ColorFadeAction
        {
+       public:
+               class Loader: public Msp::DataFile::DerivedObjectLoader<Fade, Action::Loader>
+               {
+               public:
+                       Loader(Fade &, Demo &);
+
+               private:
+                       void overlay(const std::string &);
+                       void color(float, float, float, float);
+               };
+
        private:
-               FadeOverlay &overlay;
+               FadeOverlay *overlay;
 
        public:
+               Fade();
                Fade(FadeOverlay &, const Msp::GL::Color &);
 
-               virtual void validate() const { }
+               virtual void validate() const;
 
-               virtual const Msp::GL::Color &get_color() const { return overlay.color; }
-               virtual void set_color(const Msp::GL::Color &c) { overlay.set_color(c); }
+               virtual const Msp::GL::Color &get_color() const { return overlay->color; }
+               virtual void set_color(const Msp::GL::Color &c) { overlay->set_color(c); }
        };
 
 private:
index 917108b7878753a987e88d7c931a6e6a69760586..3807e1c15a760777273cc65a0c7030287f8c7467 100644 (file)
@@ -1,7 +1,9 @@
 #include <cmath>
 #include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
+#include "fadeoverlay.h"
 #include "sequencer.h"
+#include "stage.h"
 
 using namespace std;
 using namespace Msp;
@@ -12,6 +14,9 @@ Sequencer::Sequencer(float bpm):
        next_event(0)
 {
        set_beats_per_minute(bpm);
+
+       register_action_type<FadeOverlay::Fade>("fade");
+       register_action_type<Stage::UseInView>("use_stage");
 }
 
 void Sequencer::set_beats_per_minute(float bpm)
index ef5cac44ca5bbdcf8429350e4f98cb35afff7bdb..cbe576fa24ba566d2e33bcb2e04201c8c40be027 100644 (file)
@@ -1,6 +1,8 @@
 #include <msp/gl/view.h>
+#include "demo.h"
 #include "stage.h"
 
+using namespace std;
 using namespace Msp;
 
 Stage::Stage():
@@ -13,13 +15,44 @@ Stage::~Stage()
 }
 
 
+Stage::UseInView::UseInView():
+       view(0),
+       stage(0)
+{ }
+
 Stage::UseInView::UseInView(GL::View &v, Stage &s):
-       view(v),
-       stage(s)
+       view(&v),
+       stage(&s)
 { }
 
+void Stage::UseInView::validate() const
+{
+       if(!view)
+               throw logic_error("null view");
+       if(!stage)
+               throw logic_error("null stage");
+}
+
 void Stage::UseInView::start(float, float)
 {
-       view.set_camera(&stage.camera_control.get_camera());
-       view.set_content(stage.pipeline);
+       view->set_camera(&stage->camera_control.get_camera());
+       view->set_content(stage->pipeline);
+}
+
+
+Stage::UseInView::Loader::Loader(UseInView &u, Demo &d):
+       DataFile::DerivedObjectLoader<UseInView, Action::Loader>(u, d)
+{
+       add("view", &Loader::view);
+       add("stage", &Loader::stage);
+}
+
+void Stage::UseInView::Loader::view(const string &n)
+{
+       obj.view = &demo.get_thing<GL::View>(n);
+}
+
+void Stage::UseInView::Loader::stage(const string &n)
+{
+       obj.stage = &demo.get_thing<Stage>(n);
 }
index dad846dea73d4dd4f443161b8a0f8972ea988dd3..c43cccb31601e2d86637706c69224973f7489979 100644 (file)
@@ -9,14 +9,26 @@ struct Stage
 {
        class UseInView: public Action
        {
+       public:
+               class Loader: public Msp::DataFile::DerivedObjectLoader<UseInView, Action::Loader>
+               {
+               public:
+                       Loader(UseInView &, Demo &);
+
+               private:
+                       void view(const std::string &);
+                       void stage(const std::string &);
+               };
+
        private:
-               Msp::GL::View &view;
-               Stage &stage;
+               Msp::GL::View *view;
+               Stage *stage;
 
        public:
+               UseInView();
                UseInView(Msp::GL::View &, Stage &);
 
-               virtual void validate() const { }
+               virtual void validate() const;
 
                virtual void start(float, float);
        };