From: Mikko Rasa Date: Tue, 9 Jul 2024 13:32:48 +0000 (+0300) Subject: Make scene contents retrievable when loaded with GenericLoader X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=5ca13b0dd0dfd1763092dd771f71538882cd54b7;p=libs%2Fgl.git Make scene contents retrievable when loaded with GenericLoader Content from inline sub-scenes will also be added. --- diff --git a/source/render/scene.cpp b/source/render/scene.cpp index 4d8732aa..f2f3bbf6 100644 --- a/source/render/scene.cpp +++ b/source/render/scene.cpp @@ -16,6 +16,8 @@ using namespace std; namespace Msp { namespace GL { +thread_local Scene::ContentMap *Scene::named_content = nullptr; + Scene::GenericLoader::TypeRegistry &Scene::get_scene_registry() { static Scene::GenericLoader::TypeRegistry registry; @@ -75,5 +77,17 @@ void Scene::Loader::scene_inline() obj.add(*dyn_sub().into(get_collection(), format("scene %d", ++inline_counter)).load()); } + +void Scene::GenericLoader::prepare() +{ + saved_content = named_content; + named_content = content; +} + +void Scene::GenericLoader::finish(bool) +{ + named_content = saved_content; +} + } // namespace GL } // namespace Msp diff --git a/source/render/scene.h b/source/render/scene.h index 8dfd50d5..babda141 100644 --- a/source/render/scene.h +++ b/source/render/scene.h @@ -25,17 +25,18 @@ SimpleScene is a good default choice if there are no specific requirements. class MSPGL_API Scene: public Renderable { protected: + using ContentMap = std::map; + class MSPGL_API Loader: public DataFile::CollectionObjectLoader { public: - typedef std::map ContentMap; private: ContentMap *content; unsigned inline_counter = 0; public: - Loader(Scene &s, Collection &c): Loader(s, c, nullptr) { } + Loader(Scene &s, Collection &c): Loader(s, c, named_content) { } Loader(Scene &s, Collection &c, ContentMap &m) : Loader(s, c, &m) { } private: Loader(Scene &, Collection &, ContentMap *); @@ -52,13 +53,24 @@ public: { friend class Scene; + private: + ContentMap *content = nullptr; + ContentMap *saved_content = nullptr; + public: - GenericLoader(DataFile::Collection &c): DynamicObjectLoader(&c) { } + GenericLoader(DataFile::Collection &c): DynamicObjectLoader(&c), content(named_content) { } + GenericLoader(DataFile::Collection &c, ContentMap &m): DynamicObjectLoader(&c), content(&m) { } protected: const TypeRegistry &get_type_registry() const override { return get_scene_registry(); } + + void prepare() override; + void finish(bool) override; }; +private: + static thread_local ContentMap *named_content; + protected: Scene() = default; public: