namespace Msp {
namespace GL {
+thread_local Scene::ContentMap *Scene::named_content = nullptr;
+
Scene::GenericLoader::TypeRegistry &Scene::get_scene_registry()
{
static Scene::GenericLoader::TypeRegistry registry;
obj.add(*dyn_sub<GenericLoader>().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
class MSPGL_API Scene: public Renderable
{
protected:
+ using ContentMap = std::map<std::string, Renderable *>;
+
class MSPGL_API Loader: public DataFile::CollectionObjectLoader<Scene>
{
public:
- typedef std::map<std::string, Renderable *> 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 *);
{
friend class Scene;
+ private:
+ ContentMap *content = nullptr;
+ ContentMap *saved_content = nullptr;
+
public:
- GenericLoader(DataFile::Collection &c): DynamicObjectLoader<Scene>(&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: