From 423a982cb00a9ec74fc154d729cbf88518adc6d8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 22 May 2019 14:47:13 +0300 Subject: [PATCH] Make some simple actions loadable --- source/demo.cpp | 2 ++ source/fadeoverlay.cpp | 33 ++++++++++++++++++++++++++++++++- source/fadeoverlay.h | 20 ++++++++++++++++---- source/sequencer.cpp | 5 +++++ source/stage.cpp | 41 +++++++++++++++++++++++++++++++++++++---- source/stage.h | 18 +++++++++++++++--- 6 files changed, 107 insertions(+), 12 deletions(-) diff --git a/source/demo.cpp b/source/demo.cpp index 41e9641..2072f29 100644 --- a/source/demo.cpp +++ b/source/demo.cpp @@ -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(&view); + sequencer.signal_finished.connect(signal_finished); } diff --git a/source/fadeoverlay.cpp b/source/fadeoverlay.cpp index 46ebd58..ab069c3 100644 --- a/source/fadeoverlay.cpp +++ b/source/fadeoverlay.cpp @@ -1,9 +1,11 @@ #include #include #include +#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(f, d) +{ + add("overlay", &Loader::overlay); + add("color", &Loader::color); +} + +void FadeOverlay::Fade::Loader::overlay(const string &n) +{ + obj.overlay = &demo.get_thing(n); +} + +void FadeOverlay::Fade::Loader::color(float r, float g, float b, float a) +{ + obj.end_color = GL::Color(r, g, b, a); +} diff --git a/source/fadeoverlay.h b/source/fadeoverlay.h index 988a0e1..e25d168 100644 --- a/source/fadeoverlay.h +++ b/source/fadeoverlay.h @@ -14,16 +14,28 @@ class FadeOverlay: public Msp::GL::PostProcessor public: class Fade: public ColorFadeAction { + public: + class Loader: public Msp::DataFile::DerivedObjectLoader + { + 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: diff --git a/source/sequencer.cpp b/source/sequencer.cpp index 917108b..3807e1c 100644 --- a/source/sequencer.cpp +++ b/source/sequencer.cpp @@ -1,7 +1,9 @@ #include #include #include +#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("fade"); + register_action_type("use_stage"); } void Sequencer::set_beats_per_minute(float bpm) diff --git a/source/stage.cpp b/source/stage.cpp index ef5cac4..cbe576f 100644 --- a/source/stage.cpp +++ b/source/stage.cpp @@ -1,6 +1,8 @@ #include +#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(u, d) +{ + add("view", &Loader::view); + add("stage", &Loader::stage); +} + +void Stage::UseInView::Loader::view(const string &n) +{ + obj.view = &demo.get_thing(n); +} + +void Stage::UseInView::Loader::stage(const string &n) +{ + obj.stage = &demo.get_thing(n); } diff --git a/source/stage.h b/source/stage.h index dad846d..c43cccb 100644 --- a/source/stage.h +++ b/source/stage.h @@ -9,14 +9,26 @@ struct Stage { class UseInView: public Action { + public: + class Loader: public Msp::DataFile::DerivedObjectLoader + { + 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); }; -- 2.45.2