]> git.tdb.fi Git - libs/demoscene.git/commitdiff
Make it possible for Stages to add things to the Demo
authorMikko Rasa <tdb@tdb.fi>
Fri, 24 May 2019 19:29:04 +0000 (22:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 24 May 2019 19:29:04 +0000 (22:29 +0300)
This is much more flexible than exposing everything so Demo can add them.

source/demo.cpp
source/demo.h
source/stage.cpp
source/stage.h

index 4cd66bd2a036d803988c18d6f195adb3bd376b60..c5456853c55495fc41665b2813af2abfa0bb8f22 100644 (file)
@@ -31,7 +31,7 @@ Demo::~Demo()
 void Demo::add_stage(const std::string &name, Stage &stage)
 {
        things[name] = &stage;
-       things[name+".camera"] = static_cast<GL::Placeable *>(&stage.get_camera());
+       stage.add_things(things, name+".");
 }
 
 void Demo::set_fixed_framerate(float fps)
index e2dfd6e9e6d926455827b9232036568bc68c795b..35be62454e0c70100b13f392f560ef8784446a07 100644 (file)
@@ -32,6 +32,8 @@ private:
        };
 
 public:
+       typedef std::map<std::string, Msp::Variant> ThingMap;
+
        sigc::signal<void> signal_finished;
 
 protected:
@@ -48,7 +50,7 @@ protected:
        Msp::Time::TimeStamp last_tick;
        Msp::Time::TimeStamp next_frame;
 
-       std::map<std::string, Msp::Variant> things;
+       ThingMap things;
 
        Demo(Msp::Graphics::Window &, Msp::Graphics::GLContext &, Msp::DataFile::Collection &);
 public:
index 267afe3a7dbe31148c590fa8fbf907fa9cb75813..e1ce3522753683e38d3941db0c2d2df05ab803f7 100644 (file)
@@ -14,6 +14,11 @@ Stage::~Stage()
        delete pipeline;
 }
 
+void Stage::add_things(Demo::ThingMap &things, const string &prefix)
+{
+       things[prefix+"camera"] = static_cast<GL::Placeable *>(&camera);
+}
+
 void Stage::add_postprocessor(GL::PostProcessor &pp)
 {
        pipeline->add_postprocessor(pp);
index 49371776b2df432f5ae311d3471677c984d0e107..c108f6fcd66ddda1f9c5b9ca0cb2324d23227db9 100644 (file)
@@ -4,6 +4,7 @@
 #include <msp/gl/camera.h>
 #include <msp/gl/pipeline.h>
 #include "action.h"
+#include "demo.h"
 
 class Stage
 {
@@ -68,6 +69,7 @@ public:
        Stage();
        ~Stage();
 
+       virtual void add_things(Demo::ThingMap &, const std::string &);
        void add_postprocessor(Msp::GL::PostProcessor &);
        void set_camera(const Msp::GL::Camera &);
        Msp::GL::Camera &get_camera() { return camera; }