From: Mikko Rasa Date: Sat, 3 Aug 2024 11:26:42 +0000 (+0300) Subject: Hide Scene::named_content in a getter function X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=04082b0e8772a2d8612f72d22ebb74ca5efb8b53;p=libs%2Fgl.git Hide Scene::named_content in a getter function MSVC doesn't allow a thread_local variable with DLL interface --- diff --git a/source/render/scene.cpp b/source/render/scene.cpp index f2f3bbf6..f9db89da 100644 --- a/source/render/scene.cpp +++ b/source/render/scene.cpp @@ -16,8 +16,6 @@ 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; @@ -33,6 +31,12 @@ Scene::GenericLoader::TypeRegistry &Scene::get_scene_registry() return registry; } +Scene::ContentMap *&Scene::get_named_content_ptr() +{ + static thread_local ContentMap *named_content = nullptr; + return named_content; +} + Scene::Loader::Loader(Scene &s, Collection &c, ContentMap *m): DataFile::CollectionObjectLoader(s, &c), @@ -80,13 +84,13 @@ void Scene::Loader::scene_inline() void Scene::GenericLoader::prepare() { - saved_content = named_content; - named_content = content; + saved_content = get_named_content_ptr(); + get_named_content_ptr() = content; } void Scene::GenericLoader::finish(bool) { - named_content = saved_content; + get_named_content_ptr() = saved_content; } } // namespace GL diff --git a/source/render/scene.h b/source/render/scene.h index babda141..6e35921c 100644 --- a/source/render/scene.h +++ b/source/render/scene.h @@ -36,7 +36,7 @@ protected: unsigned inline_counter = 0; public: - Loader(Scene &s, Collection &c): Loader(s, c, named_content) { } + Loader(Scene &s, Collection &c): Loader(s, c, get_named_content_ptr()) { } Loader(Scene &s, Collection &c, ContentMap &m) : Loader(s, c, &m) { } private: Loader(Scene &, Collection &, ContentMap *); @@ -49,7 +49,7 @@ protected: }; public: - class GenericLoader: public DataFile::DynamicObjectLoader + class MSPGL_API GenericLoader: public DataFile::DynamicObjectLoader { friend class Scene; @@ -58,7 +58,7 @@ public: ContentMap *saved_content = nullptr; public: - GenericLoader(DataFile::Collection &c): DynamicObjectLoader(&c), content(named_content) { } + GenericLoader(DataFile::Collection &c): DynamicObjectLoader(&c), content(get_named_content_ptr()) { } GenericLoader(DataFile::Collection &c, ContentMap &m): DynamicObjectLoader(&c), content(&m) { } protected: @@ -68,9 +68,6 @@ public: void finish(bool) override; }; -private: - static thread_local ContentMap *named_content; - protected: Scene() = default; public: @@ -83,6 +80,7 @@ public: static void register_type(const std::string &); private: static GenericLoader::TypeRegistry &get_scene_registry(); + static ContentMap *&get_named_content_ptr(); }; template