From 2eccf465aa0276b82c4360fbcde6235e0cf26df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 18 Jun 2026 13:22:29 +0200 Subject: [PATCH] Deprecate the ResourceManager and related types. Not only the implementation is a template hell full of its own problems, the internals are also just wrapping trivial bits of STL without adding anything of value on top, so ultimately any code that actually used this thing ended up being slower to build, more verbose, harder to reason about and with thousands of tiny little inefficiencies all over the place. So let's just finally say no to this idea from 2012. --- doc/changelog-old.dox | 8 +-- doc/changelog.dox | 29 +++++--- doc/snippets/Magnum.cpp | 14 +++- src/Magnum/AbstractResourceLoader.h | 46 +++++++++++- src/Magnum/CMakeLists.txt | 13 ++-- src/Magnum/DebugTools/ForceRenderer.h | 6 +- src/Magnum/DebugTools/ObjectRenderer.h | 6 +- src/Magnum/DebugTools/ResourceManager.cpp | 6 +- src/Magnum/Magnum.h | 14 ++-- src/Magnum/Resource.cpp | 4 ++ src/Magnum/Resource.h | 86 ++++++++++++++++++++--- src/Magnum/ResourceManager.h | 62 ++++++++++++++-- src/Magnum/Test/CMakeLists.txt | 12 ++-- src/Magnum/Test/ResourceManagerTest.cpp | 6 +- 14 files changed, 251 insertions(+), 61 deletions(-) diff --git a/doc/changelog-old.dox b/doc/changelog-old.dox index da2293e6c..d830bceb0 100644 --- a/doc/changelog-old.dox +++ b/doc/changelog-old.dox @@ -1162,7 +1162,7 @@ a high-level overview. @ref GL::Texture "Texture", @ref GL::TextureArray "TextureArray", @ref GL::RectangleTexture "RectangleTexture" and @ref GL::MultisampleTexture "MultisampleTexture" classes instead -- Removed deprecated @ref Resource conversion operator, use explicit +- Removed deprecated @cpp Resource @ce conversion operator, use explicit conversion instead - Removed deprecated `Framebuffer::attachTexture*D()` overloads, use one of @ref GL::Framebuffer::attachTexture() "Framebuffer::attachTexture()" or @@ -1284,7 +1284,7 @@ for a high-level overview. - Using @cpp const char @ce instead of @cpp const unsigned char @ce for raw binary data. - Removed annoying restriction when adding reference-counted resources to - @ref ResourceManager. + @cpp ResourceManager @ce. - Extension querying cleanup: - Removed @gl_extension{APPLE,flush_buffer_range} extension. - Replaced @gl_extension{APPLE,vertex_array_object} with @@ -1570,8 +1570,8 @@ for a high-level overview. See function documentation for more information. - Parameter-less @cpp Mesh::draw() @ce and @cpp MeshView::draw() @ce are deprecated, use versions with explicit shader parameter instead -- Deprecated implicit conversion of @ref Resource "Resource" to - @cpp U& @ce, as it is not safe. Use explicit dereference operator instead. +- Deprecated implicit conversion of @cpp Resource @ce to @cpp U& @ce, + as it is not safe. Use explicit dereference operator instead. - Texture binding using @cpp *Texture::bind() @ce is deprecated, use setup functions of particular shaders instead (e.g. @cpp Shaders::Phong::setDiffuseTexture() @ce) diff --git a/doc/changelog.dox b/doc/changelog.dox index 1de75c114..bd855e362 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -1862,6 +1862,13 @@ See also: anymore, as such a code path is not easy to test in common setups and requires significant code duplication in order to preserve plugin-specific configuration options. Instantiate though the plugin manager instead. +- The @cpp ResourceManager @ce class and associated types such as + @cpp Resource @ce, @cpp AbstractResourceLoader @ce, + @cpp ResourceDataState @ce, @cpp ResourcePolicy @ce, @cpp ResourceState @ce + and @cpp ResourceKey @ce is deprecated, as it only resulted in additional + code verbosity, hard-to-track bugs due to less clear resource ownership, + and general inefficiencies, while not actually solving any real-world + problem. @subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs @@ -2514,7 +2521,7 @@ Released 2020-06-27, tagged as - The @ref PixelFormat and @ref CompressedPixelFormat enums can now be saved and retrieved from @ref Corrade::Utility::Configuration / @ref Corrade::Utility::Arguments -- @ref Resource is now nothrow-movable and thus can be used with growable +- @cpp Resource @ce is now nothrow-movable and thus can be used with growable @ref Corrade::Containers::Array instances - Reworked plugin search paths to prefer autodetection based on library or executable location where possible and use hardcoded paths only if @@ -2755,7 +2762,7 @@ Released 2020-06-27, tagged as - Fixed an otherwise harmless OOB access in @ref MeshTools::tipsifyInPlace() that could trigger ASan or debug iterator errors - With @ref Corrade/Utility/DebugStl.h not being included, @ref std::string - instances could get accidentally printed as @ref ResourceKey instances. + instances could get accidentally printed as @cpp ResourceKey @ce instances. Added and explicit header dependency to avoid such cases. - The @ref Magnum/Image.h, @ref Magnum/ImageView.h and @ref Magnum/Trade/ImageData.h headers required @@ -2765,8 +2772,8 @@ Released 2020-06-27, tagged as - Dynamic plugins on static Magnum builds on Windows were accidentally searched for in the `lib/` directory instead of `bin/`, and in some cases in `bin/` instead of `lib/` on Unix platforms. -- @ref Resource was unnecessarily querying the @ref ResourceManager for - updated data even in cases where no resource update was done since last +- @cpp Resource @ce was unnecessarily querying the @cpp ResourceManager @ce + for updated data even in cases where no resource update was done since last check - For a @cpp Shaders::Phong @ce with zero lights, alpha mask default value was incorrectly @cpp 0.0f @ce instead of @cpp 0.5f @ce on OpenGL ES @@ -2928,10 +2935,10 @@ Released 2020-06-27, tagged as @p segments parameter isn't divisible by four. Before it mistakenly asserted only if @p segments wasn't divisible by two, and now code that mistakenly used a disallowed value will start asserting. -- @ref ResourceManager singleton accessible through @cpp instance() @ce that - was deprecated in 2019.10 is now removed. Usually a deprecated feature is - kept for at least a year before removal, but in this case it was severely - limiting multithreaded applications and removing it was necessary. +- @cpp ResourceManager @ce singleton accessible through @cpp instance() @ce + that was deprecated in 2019.10 is now removed. Usually a deprecated feature + is kept for at least a year before removal, but in this case it was + severely limiting multithreaded applications and removing it was necessary. - Locations of generic shader attributes was changed in order to accommodate for new attributes and use cases. This may break custom shaders if these rely on generic attribute definitions or are used together with @@ -3306,12 +3313,12 @@ Released 2019-10-24, tagged as @subsection changelog-2019-10-changes Changes and improvements -- The @ref ResourceManager class now accepts also +- The @cpp ResourceManager @ce class now accepts also @ref Corrade::Containers::Pointer instances in addition to raw pointers - The @ref AbstractResourceLoader::set() function now accepts also @cpp nullptr @ce for explicitly setting @ref ResourceDataState::Loading or @ref ResourceDataState::NotFound resources -- Added comparison operators to @ref Resource (see +- Added comparison operators to @cpp Resource @ce (see [mosra/magnum#346](https://github.com/mosra/magnum/pull/346)) - @ref ImageView and @ref CompressedImageView of smaller dimension count are now implicitly convertible to views of higher dimension count to make @@ -3730,7 +3737,7 @@ Released 2019-10-24, tagged as - The @cpp ResourceManager::instance() @ce singleton (and its implicit use in @cpp DebugTools::ForceRenderer @ce and @cpp DebugTools::ObjectRenderer @ce) is deprecated as it makes some use cases harder than they should be. Make - your own singleton or explicitly pass a @ref ResourceManager reference + your own singleton or explicitly pass a @cpp ResourceManager @ce reference around instead. - @ref Platform::BasicScreen::application() now returns a reference instead of a pointer and together with @ref Platform::BasicScreen::redraw() checks diff --git a/doc/snippets/Magnum.cpp b/doc/snippets/Magnum.cpp index 3750a4545..bdd367f47 100644 --- a/doc/snippets/Magnum.cpp +++ b/doc/snippets/Magnum.cpp @@ -33,19 +33,24 @@ #include "Magnum/PixelFormat.h" #include "Magnum/VertexFormat.h" #ifdef MAGNUM_TARGET_GL -#include "Magnum/ResourceManager.h" #include "Magnum/GL/AbstractShaderProgram.h" #include "Magnum/GL/Mesh.h" #include "Magnum/GL/PixelFormat.h" #include "Magnum/GL/Texture.h" #endif +#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) +#define _MAGNUM_NO_DEPRECATED_RESOURCEMANAGER +#include "Magnum/ResourceManager.h" +#endif + #define DOXYGEN_ELLIPSIS(...) __VA_ARGS__ using namespace Magnum; using namespace Magnum::Math::Literals; -#ifdef MAGNUM_TARGET_GL +#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) +CORRADE_IGNORE_DEPRECATED_PUSH namespace Wew { Containers::Pointer mesh; bool found = false; @@ -66,6 +71,7 @@ class MeshResourceLoader: public AbstractResourceLoader { } }; /* [AbstractResourceLoader-implementation] */ +CORRADE_IGNORE_DEPRECATED_POP } #endif @@ -301,7 +307,8 @@ CompressedImage2D image = texture.compressedImage(0, CompressedImage2D{}); } #endif -#ifdef MAGNUM_TARGET_GL +#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) +CORRADE_IGNORE_DEPRECATED_PUSH { /* [ResourceManager-typedef] */ typedef ResourceManager @@ -360,6 +367,7 @@ manager.setLoader(std::move(loader)); Resource myMesh = manager.get("my-mesh"); /* [AbstractResourceLoader-use] */ } +CORRADE_IGNORE_DEPRECATED_POP #endif { diff --git a/src/Magnum/AbstractResourceLoader.h b/src/Magnum/AbstractResourceLoader.h index f87180071..4d5e9d532 100644 --- a/src/Magnum/AbstractResourceLoader.h +++ b/src/Magnum/AbstractResourceLoader.h @@ -26,18 +26,33 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef MAGNUM_BUILD_DEPRECATED /** @file * @brief Class @ref Magnum::AbstractResourceLoader + * @m_deprecated_since_latest The @ref Magnum::ResourceManager class is + * obsolete, as it only resulted in additional code verbosity, + * hard-to-track bugs due to less clear resource ownership, and general + * inefficiencies, while not actually solving any real-world problem. */ +#endif + +#include "Magnum/configure.h" +#ifdef MAGNUM_BUILD_DEPRECATED #include #include "Magnum/ResourceManager.h" +/* File deprecation warning printed in ResourceManager.h */ + namespace Magnum { /** @brief Base for resource loaders +@m_deprecated_since_latest The @ref ResourceManager class is obsolete, as it + only resulted in additional code verbosity, hard-to-track bugs due to + less clear resource ownership, and general inefficiencies, while not + actually solving any real-world problem. Provides (a)synchronous resource loading for @ref ResourceManager. @@ -77,7 +92,7 @@ from the manager) before the manager is destroyed. @snippet Magnum.cpp AbstractResourceLoader-use */ -template class AbstractResourceLoader { +template class CORRADE_DEPRECATED("the ResourceManager class is obsolete") AbstractResourceLoader { public: explicit AbstractResourceLoader(): manager(nullptr), _requestedCount(0), _loadedCount(0), _notFoundCount(0) {} @@ -112,7 +127,9 @@ template class AbstractResourceLoader { * If no such resource exists or the resource name is not available, * returns empty string. */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ std::string name(ResourceKey key) const { return doName(key); } + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Request resource to be loaded @@ -125,7 +142,9 @@ template class AbstractResourceLoader { * @see @ref ResourceManager::state(), @ref requestedCount(), * @ref notFoundCount(), @ref loadedCount() */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ void load(ResourceKey key); + CORRADE_IGNORE_DEPRECATED_POP protected: /** @@ -144,14 +163,19 @@ template class AbstractResourceLoader { * use the convenience @ref setNotFound() variant. * @see @ref loadedCount() */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ void set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy); + CORRADE_IGNORE_DEPRECATED_POP /** @overload */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ void set(ResourceKey key, Containers::Pointer data, ResourceDataState state, ResourcePolicy policy) { return set(key, data.release(), state, policy); } + CORRADE_IGNORE_DEPRECATED_POP /** @overload */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template::type, std::nullptr_t>::value, int>::type = 0 @@ -159,6 +183,7 @@ template class AbstractResourceLoader { > void set(ResourceKey key, U&& data, ResourceDataState state, ResourcePolicy policy) { set(key, new typename std::decay::type(std::forward(data)), state, policy); } + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Set loaded resource to resource manager @@ -166,16 +191,21 @@ template class AbstractResourceLoader { * Same as above function with state set to @ref ResourceDataState::Final * and policy to @ref ResourcePolicy::Resident. */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ void set(ResourceKey key, T* data) { set(key, data, ResourceDataState::Final, ResourcePolicy::Resident); } + CORRADE_IGNORE_DEPRECATED_POP /** @overload */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ void set(ResourceKey key, Containers::Pointer data) { set(key, data.release()); } + CORRADE_IGNORE_DEPRECATED_POP /** @overload */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template::type, std::nullptr_t>::value, int>::type = 0 @@ -183,6 +213,7 @@ template class AbstractResourceLoader { > void set(ResourceKey key, U&& data) { set(key, new typename std::decay::type(std::forward(data))); } + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Mark resource as not found @@ -191,10 +222,11 @@ template class AbstractResourceLoader { * and @ref ResourceDataState::NotFound. * @see @ref notFoundCount() */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ void setNotFound(ResourceKey key) { - /** @todo What policy for notfound resources? */ set(key, nullptr, ResourceDataState::NotFound, ResourcePolicy::Resident); } + CORRADE_IGNORE_DEPRECATED_POP #ifndef DOXYGEN_GENERATING_OUTPUT private: @@ -206,14 +238,18 @@ template class AbstractResourceLoader { * * Default implementation returns empty string. */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ virtual std::string doName(ResourceKey key) const; + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Implementation for @ref load() * * See class documentation for reimplementation guide. */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ virtual void doLoad(ResourceKey key) = 0; + CORRADE_IGNORE_DEPRECATED_POP private: #ifndef DOXYGEN_GENERATING_OUTPUT /* https://bugzilla.gnome.org/show_bug.cgi?id=776986 */ @@ -226,6 +262,7 @@ template class AbstractResourceLoader { _notFoundCount; }; +CORRADE_IGNORE_DEPRECATED_PUSH template AbstractResourceLoader::~AbstractResourceLoader() { if(manager) manager->_loader = nullptr; } @@ -234,7 +271,6 @@ template std::string AbstractResourceLoader::doName(ResourceKey) con template void AbstractResourceLoader::load(ResourceKey key) { ++_requestedCount; - /** @todo What policy for loading resources? */ manager->set(key, nullptr, ResourceDataState::Loading, ResourcePolicy::Resident); doLoad(key); @@ -245,7 +281,11 @@ template void AbstractResourceLoader::set(ResourceKey key, T* data, if(!data && state == ResourceDataState::NotFound) ++_notFoundCount; manager->set(key, data, state, policy); } +CORRADE_IGNORE_DEPRECATED_POP } +#else +#error the ResourceManager class is obsolete +#endif #endif diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index 056d9cf99..a957c9208 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -90,7 +90,6 @@ set(Magnum_SRCS FileCallback.cpp ImageFlags.cpp PixelStorage.cpp - Resource.cpp Sampler.cpp Timeline.cpp) @@ -105,7 +104,6 @@ set(Magnum_GracefulAssert_SRCS Animation/Interpolation.cpp) set(Magnum_HEADERS - AbstractResourceLoader.h British.h DimensionTraits.h FileCallback.h @@ -116,8 +114,6 @@ set(Magnum_HEADERS Mesh.h PixelFormat.h PixelStorage.h - Resource.h - ResourceManager.h Sampler.h Tags.h Timeline.h @@ -136,7 +132,14 @@ set(Magnum_PRIVATE_HEADERS Implementation/vertexFormatMapping.hpp) if(MAGNUM_BUILD_DEPRECATED) - list(APPEND Magnum_HEADERS Array.h) + list(APPEND Magnum_HEADERS + Array.h + AbstractResourceLoader.h + Resource.h + ResourceManager.h) + + list(APPEND Magnum_SRCS + Resource.cpp) endif() # Functionality specific to static Windows builds diff --git a/src/Magnum/DebugTools/ForceRenderer.h b/src/Magnum/DebugTools/ForceRenderer.h index a924f2bd3..42943581d 100644 --- a/src/Magnum/DebugTools/ForceRenderer.h +++ b/src/Magnum/DebugTools/ForceRenderer.h @@ -152,7 +152,9 @@ template class CORRADE_DEPRECATED("use Primitives::arrow explicit ForceRenderer(ResourceManager&, SceneGraph::AbstractObject&, const VectorTypeFor&, VectorTypeFor&&, ResourceKey = ResourceKey(), SceneGraph::DrawableGroup* = nullptr) = delete; CORRADE_IGNORE_DEPRECATED_POP + CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */ ~ForceRenderer(); + CORRADE_IGNORE_DEPRECATED_POP private: void draw(const MatrixTypeFor& transformationMatrix, SceneGraph::Camera& camera) override; @@ -160,11 +162,11 @@ template class CORRADE_DEPRECATED("use Primitives::arrow const VectorTypeFor _forcePosition; const VectorTypeFor& _force; - CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns due to the type */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ Resource _options; - CORRADE_IGNORE_DEPRECATED_POP Resource> _shader; Resource _mesh; + CORRADE_IGNORE_DEPRECATED_POP }; /** diff --git a/src/Magnum/DebugTools/ObjectRenderer.h b/src/Magnum/DebugTools/ObjectRenderer.h index 5cb0434ed..17ddfd108 100644 --- a/src/Magnum/DebugTools/ObjectRenderer.h +++ b/src/Magnum/DebugTools/ObjectRenderer.h @@ -122,16 +122,18 @@ template class CORRADE_DEPRECATED("use Primitives::axis2 explicit ObjectRenderer(ResourceManager& manager, SceneGraph::AbstractObject& object, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); CORRADE_IGNORE_DEPRECATED_POP + CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here (?!) */ ~ObjectRenderer(); + CORRADE_IGNORE_DEPRECATED_POP private: void draw(const MatrixTypeFor& transformationMatrix, SceneGraph::Camera& camera) override; - CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns due to the type */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ Resource _options; - CORRADE_IGNORE_DEPRECATED_POP Resource> _shader; Resource _mesh; + CORRADE_IGNORE_DEPRECATED_POP }; /** diff --git a/src/Magnum/DebugTools/ResourceManager.cpp b/src/Magnum/DebugTools/ResourceManager.cpp index c38d47006..2d4734779 100644 --- a/src/Magnum/DebugTools/ResourceManager.cpp +++ b/src/Magnum/DebugTools/ResourceManager.cpp @@ -39,13 +39,15 @@ namespace Magnum { namespace DebugTools { +CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here, GCC 4.8 for the inside */ ResourceManager::ResourceManager() { - CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ setFallback(new ForceRendererOptions); setFallback(new ObjectRendererOptions); - CORRADE_IGNORE_DEPRECATED_POP } +CORRADE_IGNORE_DEPRECATED_POP +CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */ ResourceManager::~ResourceManager() = default; +CORRADE_IGNORE_DEPRECATED_POP }} diff --git a/src/Magnum/Magnum.h b/src/Magnum/Magnum.h index b511eff2c..aea0e482f 100644 --- a/src/Magnum/Magnum.h +++ b/src/Magnum/Magnum.h @@ -1359,12 +1359,14 @@ enum class CompressedPixelFormat: UnsignedInt; class PixelStorage; class CompressedPixelStorage; -enum class ResourceState: UnsignedByte; -enum class ResourceDataState: UnsignedByte; -enum class ResourcePolicy: UnsignedByte; -template class Resource; -class ResourceKey; -template class ResourceManager; +#ifdef MAGNUM_BUILD_DEPRECATED +enum class CORRADE_DEPRECATED_ENUM("the ResourceManager class is obsolete") ResourceState: UnsignedByte; +enum class CORRADE_DEPRECATED_ENUM("the ResourceManager class is obsolete") ResourceDataState: UnsignedByte; +enum class CORRADE_DEPRECATED_ENUM("the ResourceManager class is obsolete") ResourcePolicy: UnsignedByte; +template class CORRADE_DEPRECATED("the ResourceManager class is obsolete") Resource; +class CORRADE_DEPRECATED("the ResourceManager class is obsolete") ResourceKey; +template class CORRADE_DEPRECATED("the ResourceManager class is obsolete") ResourceManager; +#endif enum class SamplerFilter: UnsignedInt; enum class SamplerMipmap: UnsignedInt; diff --git a/src/Magnum/Resource.cpp b/src/Magnum/Resource.cpp index 7df973989..c67aca2dc 100644 --- a/src/Magnum/Resource.cpp +++ b/src/Magnum/Resource.cpp @@ -24,10 +24,13 @@ DEALINGS IN THE SOFTWARE. */ +#define _MAGNUM_NO_DEPRECATED_RESOURCEMANAGER + #include "Resource.h" namespace Magnum { +CORRADE_IGNORE_DEPRECATED_PUSH Debug& operator<<(Debug& debug, const ResourceState value) { debug << "ResourceState" << Debug::nospace; @@ -52,5 +55,6 @@ Debug& operator<<(Debug& debug, const ResourceState value) { Debug& operator<<(Debug& debug, const ResourceKey& value) { return debug << "ResourceKey(0x" << Debug::nospace << static_cast&>(value) << Debug::nospace << ")"; } +CORRADE_IGNORE_DEPRECATED_POP } diff --git a/src/Magnum/Resource.h b/src/Magnum/Resource.h index da3085f33..c9008794e 100644 --- a/src/Magnum/Resource.h +++ b/src/Magnum/Resource.h @@ -27,10 +27,19 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef MAGNUM_BUILD_DEPRECATED /** @file * @brief Class @ref Magnum::ResourceKey, @ref Magnum::Resource, enum @ref Magnum::ResourceState + * @m_deprecated_since_latest The @ref Magnum::ResourceManager class is + * obsolete, as it only resulted in additional code verbosity, + * hard-to-track bugs due to less clear resource ownership, and general + * inefficiencies, while not actually solving any real-world problem. */ +#endif + +#include "Magnum/configure.h" +#ifdef MAGNUM_BUILD_DEPRECATED #include #include @@ -38,20 +47,26 @@ std::string -- and if DebugStl.h wouldn't be included, an attempt to print a std::string would choose the ResourceKey printer instead, producing unwanted results. */ -/** @todo remove when we have a StringView and ResourceKey is ported to it */ #include #include "Magnum/Magnum.h" #include "Magnum/visibility.h" +/* File deprecation warning printed in ResourceManager.h, which is included at + the end of this header */ + namespace Magnum { /** @brief Resource state +@m_deprecated_since_latest The @ref ResourceManager class is obsolete, as it + only resulted in additional code verbosity, hard-to-track bugs due to + less clear resource ownership, and general inefficiencies, while not + actually solving any real-world problem. @see @ref Resource::state(), @ref ResourceManager::state() */ -enum class ResourceState: UnsignedByte { +enum class CORRADE_DEPRECATED_ENUM("the ResourceManager class is obsolete") ResourceState: UnsignedByte { /** The resource is not yet loaded (and no fallback is available). */ NotLoaded, @@ -77,15 +92,27 @@ enum class ResourceState: UnsignedByte { Final }; -/** @debugoperatorenum{ResourceState} */ +/** +@debugoperatorenum{ResourceState} +@m_deprecated_since_latest The @ref ResourceManager class is obsolete, as it + only resulted in additional code verbosity, hard-to-track bugs due to + less clear resource ownership, and general inefficiencies, while not + actually solving any real-world problem. +*/ +CORRADE_IGNORE_DEPRECATED_PUSH MAGNUM_EXPORT Debug& operator<<(Debug& debug, ResourceState value); +CORRADE_IGNORE_DEPRECATED_POP /** @brief Key for accessing resource +@m_deprecated_since_latest The @ref ResourceManager class is obsolete, as it + only resulted in additional code verbosity, hard-to-track bugs due to + less clear resource ownership, and general inefficiencies, while not + actually solving any real-world problem. See @ref ResourceManager for more information. */ -class ResourceKey: public Utility::MurmurHash2::Digest { +class CORRADE_DEPRECATED("the ResourceManager class is obsolete") ResourceKey: public Utility::MurmurHash2::Digest { public: /** * @brief Default constructor @@ -101,15 +128,20 @@ class ResourceKey: public Utility::MurmurHash2::Digest { /** @brief Constructor */ /*implicit*/ ResourceKey(const std::string& key): Utility::MurmurHash2::Digest(Utility::MurmurHash2()(key)) {} - /** - * @brief Constructor - * @todo constexpr - */ + /** @brief Constructor */ template constexpr ResourceKey(const char(&key)[size]): Utility::MurmurHash2::Digest(Utility::MurmurHash2()(key)) {} }; -/** @debugoperator{ResourceKey} */ +/** +@debugoperator{ResourceKey} +@m_deprecated_since_latest The @ref ResourceManager class is obsolete, as it + only resulted in additional code verbosity, hard-to-track bugs due to + less clear resource ownership, and general inefficiencies, while not + actually solving any real-world problem. +*/ +CORRADE_IGNORE_DEPRECATED_PUSH MAGNUM_EXPORT Debug& operator<<(Debug& debug, const ResourceKey& value); +CORRADE_IGNORE_DEPRECATED_POP namespace Implementation { template class ResourceManagerData; @@ -117,6 +149,10 @@ namespace Implementation { /** @brief Resource reference +@m_deprecated_since_latest The @ref ResourceManager class is obsolete, as it + only resulted in additional code verbosity, hard-to-track bugs due to + less clear resource ownership, and general inefficiencies, while not + actually solving any real-world problem. See @ref ResourceManager for more information. */ @@ -125,7 +161,7 @@ template #else template #endif -class Resource { +class CORRADE_DEPRECATED("the ResourceManager class is obsolete") Resource { public: /** * @brief Default constructor @@ -160,7 +196,9 @@ class Resource { } /** @brief Equality comparison with other types is explicitly disallowed */ + CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */ template bool operator==(const Resource&) const = delete; + CORRADE_IGNORE_DEPRECATED_POP /** @brief Non-equality comparison */ bool operator!=(const Resource& other) const { @@ -168,20 +206,26 @@ class Resource { } /** @brief Non-equality comparison with other types is explicitly disallowed */ + CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */ template bool operator!=(const Resource&) const = delete; + CORRADE_IGNORE_DEPRECATED_POP /** @brief Resource key */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ ResourceKey key() const { return _key; } + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Resource state * * @see @ref operator bool(), @ref ResourceManager::state() */ + CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */ ResourceState state() { acquire(); return _state; } + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Whether the resource is available @@ -237,19 +281,26 @@ class Resource { friend Implementation::ResourceManagerData; #endif + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ Resource(Implementation::ResourceManagerData* manager, ResourceKey key): _manager{manager}, _key{key}, _lastCheck{0}, _state{ResourceState::NotLoaded}, _data{nullptr} { manager->incrementReferenceCount(key); } + CORRADE_IGNORE_DEPRECATED_POP void acquire(); Implementation::ResourceManagerData* _manager; + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ ResourceKey _key; + CORRADE_IGNORE_DEPRECATED_POP std::size_t _lastCheck; + CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */ ResourceState _state; + CORRADE_IGNORE_DEPRECATED_POP T* _data; }; +CORRADE_IGNORE_DEPRECATED_PUSH template Resource& Resource::operator=(const Resource& other) { if(_manager) _manager->decrementReferenceCount(_key); @@ -311,11 +362,20 @@ template void Resource::acquire() { _state = ResourceState::NotLoaded; } } +CORRADE_IGNORE_DEPRECATED_POP } namespace std { - /** @brief `std::hash` specialization for @ref Magnum::ResourceKey */ + /** + * @brief `std::hash` specialization for @ref Magnum::ResourceKey + * @m_deprecated_since_latest The @ref Magnum::ResourceManager class is + * obsolete, as it only resulted in additional code verbosity, + * hard-to-track bugs due to less clear resource ownership, and + * general inefficiencies, while not actually solving any real-world + * problem. + */ + CORRADE_IGNORE_DEPRECATED_PUSH template<> struct hash { #ifndef DOXYGEN_GENERATING_OUTPUT std::size_t operator()(Magnum::ResourceKey key) const { @@ -323,9 +383,13 @@ namespace std { } #endif }; + CORRADE_IGNORE_DEPRECATED_POP } /* Make the definition complete */ #include "ResourceManager.h" +#else +#error the ResourceManager class is obsolete +#endif #endif diff --git a/src/Magnum/ResourceManager.h b/src/Magnum/ResourceManager.h index 62b4e25e5..da92c0627 100644 --- a/src/Magnum/ResourceManager.h +++ b/src/Magnum/ResourceManager.h @@ -26,23 +26,41 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef MAGNUM_BUILD_DEPRECATED /** @file * @brief Class @ref Magnum::ResourceManager, @ref Magnum::ResourceDataState, @ref Magnum::ResourcePolicy + * @m_deprecated_since_latest The @ref Magnum::ResourceManager class is + * obsolete, as it only resulted in additional code verbosity, + * hard-to-track bugs due to less clear resource ownership, and general + * inefficiencies, while not actually solving any real-world problem. */ +#endif + +#include "Magnum/configure.h" +#ifdef MAGNUM_BUILD_DEPRECATED #include #include #include "Magnum/Resource.h" +#ifndef _MAGNUM_NO_DEPRECATED_RESOURCEMANAGER +CORRADE_DEPRECATED_FILE("the ResourceManager class is obsolete") +#endif + namespace Magnum { /** @brief Resource data state +@m_deprecated_since_latest The @ref ResourceManager class is obsolete, as it + only resulted in additional code verbosity, hard-to-track bugs due to + less clear resource ownership, and general inefficiencies, while not + actually solving any real-world problem. @see @ref ResourceManager::set(), @ref ResourceState */ -enum class ResourceDataState: UnsignedByte { +CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns for ResourceState usage */ +enum class CORRADE_DEPRECATED_ENUM("the ResourceManager class is obsolete") ResourceDataState: UnsignedByte { /** * The resource is currently loading. Parameter @p data in * @ref ResourceManager::set() should be set to @cpp nullptr @ce. @@ -70,13 +88,18 @@ enum class ResourceDataState: UnsignedByte { */ Final = UnsignedByte(ResourceState::Final) }; +CORRADE_IGNORE_DEPRECATED_POP /** @brief Resource policy +@m_deprecated_since_latest The @ref ResourceManager class is obsolete, as it + only resulted in additional code verbosity, hard-to-track bugs due to + less clear resource ownership, and general inefficiencies, while not + actually solving any real-world problem. @see @ref ResourceManager::set(), @ref ResourceManager::free() */ -enum class ResourcePolicy: UnsignedByte { +enum class CORRADE_DEPRECATED_ENUM("the ResourceManager class is obsolete") ResourcePolicy: UnsignedByte { /** The resource will stay resident for whole lifetime of resource manager. */ Resident, @@ -94,8 +117,7 @@ template class AbstractResourceLoader; namespace Implementation { -/** @todo Print either resource key or name string based on loader capabilities */ - +CORRADE_IGNORE_DEPRECATED_PUSH template class ResourceManagerData { template friend class Magnum::Resource; friend AbstractResourceLoader; @@ -159,11 +181,16 @@ template class ResourceManagerData { /* Helper class for defining which real types are in the type pack */ template struct ResourceTypePack {}; +CORRADE_IGNORE_DEPRECATED_POP } /** @brief Resource manager +@m_deprecated_since_latest The @ref ResourceManager class is obsolete, as it + only resulted in additional code verbosity, hard-to-track bugs due to + less clear resource ownership, and general inefficiencies, while not + actually solving any real-world problem. Provides storage for arbitrary set of types. @@ -224,7 +251,7 @@ Basic usage is: /* Due to too much work involved with explicit template instantiation (all Resource combinations, all ResourceManagerData...), this class doesn't have template implementation file. */ -template class ResourceManager: private Implementation::ResourceManagerData... { +template class CORRADE_DEPRECATED("the ResourceManager class is obsolete") ResourceManager: private Implementation::ResourceManagerData... { public: /** @brief Constructor */ explicit ResourceManager(); @@ -253,27 +280,33 @@ template class ResourceManager: private Implementation::Resource * * @snippet Magnum.cpp ResourceManager-get-derived */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template Resource get(ResourceKey key) { return this->Implementation::ResourceManagerData::template get(key); } + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Reference count of given resource * * @see @ref set() */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template std::size_t referenceCount(ResourceKey key) const { return this->Implementation::ResourceManagerData::referenceCount(key); } + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Resource state * * @see @ref set(), @ref Resource::state() */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template ResourceState state(ResourceKey key) const { return this->Implementation::ResourceManagerData::state(key); } + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Set resource data @@ -287,24 +320,30 @@ template class ResourceManager: private Implementation::Resource * already @ref ResourceState::Final. * @see @ref referenceCount(), @ref state() */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template ResourceManager& set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) { this->Implementation::ResourceManagerData::set(key, data, state, policy); return *this; } + CORRADE_IGNORE_DEPRECATED_POP /** * @overload * @m_since{2019,10} */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template ResourceManager& set(ResourceKey key, Containers::Pointer&& data, ResourceDataState state, ResourcePolicy policy) { set(key, data.release(), state, policy); return *this; } + CORRADE_IGNORE_DEPRECATED_POP /** @overload */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template ResourceManager& set(ResourceKey key, U&& data, ResourceDataState state, ResourcePolicy policy) { return set(key, new typename std::decay::type(std::forward(data)), state, policy); } + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Set resource data @@ -313,19 +352,25 @@ template class ResourceManager: private Implementation::Resource * Same as above with state set to @ref ResourceDataState::Final and * policy to @ref ResourcePolicy::Resident. */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template ResourceManager& set(ResourceKey key, T* data) { return set(key, data, ResourceDataState::Final, ResourcePolicy::Resident); } + CORRADE_IGNORE_DEPRECATED_POP /** @overload */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template ResourceManager& set(ResourceKey key, Containers::Pointer&& data) { return set(key, data.release()); } + CORRADE_IGNORE_DEPRECATED_POP /** @overload */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */ template ResourceManager& set(ResourceKey key, U&& data) { return set(key, new typename std::decay::type(std::forward(data))); } + CORRADE_IGNORE_DEPRECATED_POP /** @brief Fallback for not found resources */ template T* fallback() { @@ -454,6 +499,7 @@ template class ResourceManager: private Implementation::Resource namespace Implementation { +CORRADE_IGNORE_DEPRECATED_PUSH template void safeDelete(T* data) { static_assert(sizeof(T) > 0, "Cannot delete pointer to incomplete type"); delete data; @@ -592,18 +638,24 @@ template inline ResourceManagerData::Data::~Data() { "ResourceManager: cleared/destroyed while data are still referenced", ); safeDelete(data); } +CORRADE_IGNORE_DEPRECATED_POP } +CORRADE_IGNORE_DEPRECATED_PUSH template ResourceManager::ResourceManager() = default; template ResourceManager::~ResourceManager() { freeLoaders(typename Implementation::ResourceTypePack{}); } +CORRADE_IGNORE_DEPRECATED_POP } /* Make the definition complete */ #include "AbstractResourceLoader.h" +#else +#error the ResourceManager class is obsolete +#endif #endif diff --git a/src/Magnum/Test/CMakeLists.txt b/src/Magnum/Test/CMakeLists.txt index b5d0c32a7..0a84cd672 100644 --- a/src/Magnum/Test/CMakeLists.txt +++ b/src/Magnum/Test/CMakeLists.txt @@ -45,7 +45,6 @@ corrade_add_test(ImageViewTest ImageViewTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(MeshTest MeshTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(PixelFormatTest PixelFormatTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(PixelStorageTest PixelStorageTest.cpp LIBRARIES Magnum) -corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES Magnum) corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES MagnumTestLib) # Prefixed with project name to avoid conflicts with TagsTest in Corrade corrade_add_test(MagnumTagsTest TagsTest.cpp LIBRARIES Magnum) @@ -57,13 +56,14 @@ corrade_add_test(MagnumVersionTest VersionTest.cpp LIBRARIES Magnum) corrade_add_test(VertexFormatTest VertexFormatTest.cpp LIBRARIES MagnumTestLib) -if(MAGNUM_BUILD_DEPRECATED) - corrade_add_test(ArrayTest ArrayTest.cpp LIBRARIES Magnum) -endif() - set_property(TARGET MeshTest PixelFormatTest - ResourceManagerTest VertexFormatTest APPEND PROPERTY COMPILE_DEFINITIONS "CORRADE_GRACEFUL_ASSERT") + +if(MAGNUM_BUILD_DEPRECATED) + corrade_add_test(ArrayTest ArrayTest.cpp LIBRARIES Magnum) + corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES Magnum) + set_property(TARGET ResourceManagerTest APPEND PROPERTY COMPILE_DEFINITIONS "CORRADE_GRACEFUL_ASSERT") +endif() diff --git a/src/Magnum/Test/ResourceManagerTest.cpp b/src/Magnum/Test/ResourceManagerTest.cpp index b4fddb45e..c695c6146 100644 --- a/src/Magnum/Test/ResourceManagerTest.cpp +++ b/src/Magnum/Test/ResourceManagerTest.cpp @@ -25,10 +25,12 @@ DEALINGS IN THE SOFTWARE. */ +#define _MAGNUM_NO_DEPRECATED_RESOURCEMANAGER + #include #include #include -#include /** @todo remove once HashDigest is std::string-free */ +#include #include "Magnum/AbstractResourceLoader.h" #include "Magnum/ResourceManager.h" @@ -70,6 +72,7 @@ struct Data { ~Data() { --count; } }; +CORRADE_IGNORE_DEPRECATED_PUSH typedef Magnum::ResourceManager ResourceManager; size_t Data::count = 0; @@ -544,6 +547,7 @@ void ResourceManagerTest::debugResourceKey() { Debug{&out} << hello; CORRADE_COMPARE(out, Utility::format("ResourceKey(0x{})\n", hello.hexString())); } +CORRADE_IGNORE_DEPRECATED_POP }}}