Browse Source

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.
Vladimír Vondruš 2 days ago
parent
commit
2eccf465aa
  1. 8
      doc/changelog-old.dox
  2. 29
      doc/changelog.dox
  3. 14
      doc/snippets/Magnum.cpp
  4. 46
      src/Magnum/AbstractResourceLoader.h
  5. 13
      src/Magnum/CMakeLists.txt
  6. 6
      src/Magnum/DebugTools/ForceRenderer.h
  7. 6
      src/Magnum/DebugTools/ObjectRenderer.h
  8. 6
      src/Magnum/DebugTools/ResourceManager.cpp
  9. 14
      src/Magnum/Magnum.h
  10. 4
      src/Magnum/Resource.cpp
  11. 86
      src/Magnum/Resource.h
  12. 62
      src/Magnum/ResourceManager.h
  13. 12
      src/Magnum/Test/CMakeLists.txt
  14. 6
      src/Magnum/Test/ResourceManagerTest.cpp

8
doc/changelog-old.dox

@ -1162,7 +1162,7 @@ a high-level overview.
@ref GL::Texture "Texture", @ref GL::TextureArray "TextureArray", @ref GL::Texture "Texture", @ref GL::TextureArray "TextureArray",
@ref GL::RectangleTexture "RectangleTexture" and @ref GL::RectangleTexture "RectangleTexture" and
@ref GL::MultisampleTexture "MultisampleTexture" classes instead @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 conversion instead
- Removed deprecated `Framebuffer::attachTexture*D()` overloads, use one of - Removed deprecated `Framebuffer::attachTexture*D()` overloads, use one of
@ref GL::Framebuffer::attachTexture() "Framebuffer::attachTexture()" or @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 - Using @cpp const char @ce instead of @cpp const unsigned char @ce for raw
binary data. binary data.
- Removed annoying restriction when adding reference-counted resources to - Removed annoying restriction when adding reference-counted resources to
@ref ResourceManager. @cpp ResourceManager @ce.
- Extension querying cleanup: - Extension querying cleanup:
- Removed @gl_extension{APPLE,flush_buffer_range} extension. - Removed @gl_extension{APPLE,flush_buffer_range} extension.
- Replaced @gl_extension{APPLE,vertex_array_object} with - Replaced @gl_extension{APPLE,vertex_array_object} with
@ -1570,8 +1570,8 @@ for a high-level overview.
See function documentation for more information. See function documentation for more information.
- Parameter-less @cpp Mesh::draw() @ce and @cpp MeshView::draw() @ce are - Parameter-less @cpp Mesh::draw() @ce and @cpp MeshView::draw() @ce are
deprecated, use versions with explicit shader parameter instead deprecated, use versions with explicit shader parameter instead
- Deprecated implicit conversion of @ref Resource "Resource<T, U>" to - Deprecated implicit conversion of @cpp Resource<T, U> @ce to @cpp U& @ce,
@cpp U& @ce, as it is not safe. Use explicit dereference operator instead. as it is not safe. Use explicit dereference operator instead.
- Texture binding using @cpp *Texture::bind() @ce is deprecated, use setup - Texture binding using @cpp *Texture::bind() @ce is deprecated, use setup
functions of particular shaders instead (e.g. functions of particular shaders instead (e.g.
@cpp Shaders::Phong::setDiffuseTexture() @ce) @cpp Shaders::Phong::setDiffuseTexture() @ce)

29
doc/changelog.dox

@ -1862,6 +1862,13 @@ See also:
anymore, as such a code path is not easy to test in common setups and 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 requires significant code duplication in order to preserve plugin-specific
configuration options. Instantiate though the plugin manager instead. 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 @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 - The @ref PixelFormat and @ref CompressedPixelFormat enums can now be saved
and retrieved from @ref Corrade::Utility::Configuration / and retrieved from @ref Corrade::Utility::Configuration /
@ref Corrade::Utility::Arguments @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 @ref Corrade::Containers::Array instances
- Reworked plugin search paths to prefer autodetection based on library or - Reworked plugin search paths to prefer autodetection based on library or
executable location where possible and use hardcoded paths only if 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() - Fixed an otherwise harmless OOB access in @ref MeshTools::tipsifyInPlace()
that could trigger ASan or debug iterator errors that could trigger ASan or debug iterator errors
- With @ref Corrade/Utility/DebugStl.h not being included, @ref std::string - 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. Added and explicit header dependency to avoid such cases.
- The @ref Magnum/Image.h, @ref Magnum/ImageView.h and - The @ref Magnum/Image.h, @ref Magnum/ImageView.h and
@ref Magnum/Trade/ImageData.h headers required @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 - Dynamic plugins on static Magnum builds on Windows were accidentally
searched for in the `lib/` directory instead of `bin/`, and in some cases searched for in the `lib/` directory instead of `bin/`, and in some cases
in `bin/` instead of `lib/` on Unix platforms. in `bin/` instead of `lib/` on Unix platforms.
- @ref Resource was unnecessarily querying the @ref ResourceManager for - @cpp Resource @ce was unnecessarily querying the @cpp ResourceManager @ce
updated data even in cases where no resource update was done since last for updated data even in cases where no resource update was done since last
check check
- For a @cpp Shaders::Phong @ce with zero lights, alpha mask default value - 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 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 @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 asserted only if @p segments wasn't divisible by two, and now code that
mistakenly used a disallowed value will start asserting. mistakenly used a disallowed value will start asserting.
- @ref ResourceManager singleton accessible through @cpp instance() @ce that - @cpp ResourceManager @ce singleton accessible through @cpp instance() @ce
was deprecated in 2019.10 is now removed. Usually a deprecated feature is that was deprecated in 2019.10 is now removed. Usually a deprecated feature
kept for at least a year before removal, but in this case it was severely is kept for at least a year before removal, but in this case it was
limiting multithreaded applications and removing it was necessary. severely limiting multithreaded applications and removing it was necessary.
- Locations of generic shader attributes was changed in order to accommodate - Locations of generic shader attributes was changed in order to accommodate
for new attributes and use cases. This may break custom shaders if these for new attributes and use cases. This may break custom shaders if these
rely on generic attribute definitions or are used together with 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 @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 @ref Corrade::Containers::Pointer instances in addition to raw pointers
- The @ref AbstractResourceLoader::set() function now accepts also - The @ref AbstractResourceLoader::set() function now accepts also
@cpp nullptr @ce for explicitly setting @ref ResourceDataState::Loading or @cpp nullptr @ce for explicitly setting @ref ResourceDataState::Loading or
@ref ResourceDataState::NotFound resources @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)) [mosra/magnum#346](https://github.com/mosra/magnum/pull/346))
- @ref ImageView and @ref CompressedImageView of smaller dimension count are - @ref ImageView and @ref CompressedImageView of smaller dimension count are
now implicitly convertible to views of higher dimension count to make 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 - The @cpp ResourceManager::instance() @ce singleton (and its implicit use in
@cpp DebugTools::ForceRenderer @ce and @cpp DebugTools::ObjectRenderer @ce) @cpp DebugTools::ForceRenderer @ce and @cpp DebugTools::ObjectRenderer @ce)
is deprecated as it makes some use cases harder than they should be. Make 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. around instead.
- @ref Platform::BasicScreen::application() now returns a reference instead - @ref Platform::BasicScreen::application() now returns a reference instead
of a pointer and together with @ref Platform::BasicScreen::redraw() checks of a pointer and together with @ref Platform::BasicScreen::redraw() checks

14
doc/snippets/Magnum.cpp

@ -33,19 +33,24 @@
#include "Magnum/PixelFormat.h" #include "Magnum/PixelFormat.h"
#include "Magnum/VertexFormat.h" #include "Magnum/VertexFormat.h"
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
#include "Magnum/ResourceManager.h"
#include "Magnum/GL/AbstractShaderProgram.h" #include "Magnum/GL/AbstractShaderProgram.h"
#include "Magnum/GL/Mesh.h" #include "Magnum/GL/Mesh.h"
#include "Magnum/GL/PixelFormat.h" #include "Magnum/GL/PixelFormat.h"
#include "Magnum/GL/Texture.h" #include "Magnum/GL/Texture.h"
#endif #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__ #define DOXYGEN_ELLIPSIS(...) __VA_ARGS__
using namespace Magnum; using namespace Magnum;
using namespace Magnum::Math::Literals; using namespace Magnum::Math::Literals;
#ifdef MAGNUM_TARGET_GL #if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL)
CORRADE_IGNORE_DEPRECATED_PUSH
namespace Wew { namespace Wew {
Containers::Pointer<GL::Mesh> mesh; Containers::Pointer<GL::Mesh> mesh;
bool found = false; bool found = false;
@ -66,6 +71,7 @@ class MeshResourceLoader: public AbstractResourceLoader<GL::Mesh> {
} }
}; };
/* [AbstractResourceLoader-implementation] */ /* [AbstractResourceLoader-implementation] */
CORRADE_IGNORE_DEPRECATED_POP
} }
#endif #endif
@ -301,7 +307,8 @@ CompressedImage2D image = texture.compressedImage(0, CompressedImage2D{});
} }
#endif #endif
#ifdef MAGNUM_TARGET_GL #if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL)
CORRADE_IGNORE_DEPRECATED_PUSH
{ {
/* [ResourceManager-typedef] */ /* [ResourceManager-typedef] */
typedef ResourceManager<GL::Mesh, GL::Texture2D, GL::AbstractShaderProgram> typedef ResourceManager<GL::Mesh, GL::Texture2D, GL::AbstractShaderProgram>
@ -360,6 +367,7 @@ manager.setLoader<GL::Mesh>(std::move(loader));
Resource<GL::Mesh> myMesh = manager.get<GL::Mesh>("my-mesh"); Resource<GL::Mesh> myMesh = manager.get<GL::Mesh>("my-mesh");
/* [AbstractResourceLoader-use] */ /* [AbstractResourceLoader-use] */
} }
CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
{ {

46
src/Magnum/AbstractResourceLoader.h

@ -26,18 +26,33 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#ifdef MAGNUM_BUILD_DEPRECATED
/** @file /** @file
* @brief Class @ref Magnum::AbstractResourceLoader * @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 <string> #include <string>
#include "Magnum/ResourceManager.h" #include "Magnum/ResourceManager.h"
/* File deprecation warning printed in ResourceManager.h */
namespace Magnum { namespace Magnum {
/** /**
@brief Base for resource loaders @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. 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 @snippet Magnum.cpp AbstractResourceLoader-use
*/ */
template<class T> class AbstractResourceLoader { template<class T> class CORRADE_DEPRECATED("the ResourceManager class is obsolete") AbstractResourceLoader {
public: public:
explicit AbstractResourceLoader(): manager(nullptr), _requestedCount(0), _loadedCount(0), _notFoundCount(0) {} explicit AbstractResourceLoader(): manager(nullptr), _requestedCount(0), _loadedCount(0), _notFoundCount(0) {}
@ -112,7 +127,9 @@ template<class T> class AbstractResourceLoader {
* If no such resource exists or the resource name is not available, * If no such resource exists or the resource name is not available,
* returns empty string. * returns empty string.
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
std::string name(ResourceKey key) const { return doName(key); } std::string name(ResourceKey key) const { return doName(key); }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Request resource to be loaded * @brief Request resource to be loaded
@ -125,7 +142,9 @@ template<class T> class AbstractResourceLoader {
* @see @ref ResourceManager::state(), @ref requestedCount(), * @see @ref ResourceManager::state(), @ref requestedCount(),
* @ref notFoundCount(), @ref loadedCount() * @ref notFoundCount(), @ref loadedCount()
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
void load(ResourceKey key); void load(ResourceKey key);
CORRADE_IGNORE_DEPRECATED_POP
protected: protected:
/** /**
@ -144,14 +163,19 @@ template<class T> class AbstractResourceLoader {
* use the convenience @ref setNotFound() variant. * use the convenience @ref setNotFound() variant.
* @see @ref loadedCount() * @see @ref loadedCount()
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
void set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy); void set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy);
CORRADE_IGNORE_DEPRECATED_POP
/** @overload */ /** @overload */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
void set(ResourceKey key, Containers::Pointer<T> data, ResourceDataState state, ResourcePolicy policy) { void set(ResourceKey key, Containers::Pointer<T> data, ResourceDataState state, ResourcePolicy policy) {
return set(key, data.release(), state, policy); return set(key, data.release(), state, policy);
} }
CORRADE_IGNORE_DEPRECATED_POP
/** @overload */ /** @overload */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class U template<class U
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
, typename std::enable_if<!std::is_same<typename std::decay<U>::type, std::nullptr_t>::value, int>::type = 0 , typename std::enable_if<!std::is_same<typename std::decay<U>::type, std::nullptr_t>::value, int>::type = 0
@ -159,6 +183,7 @@ template<class T> class AbstractResourceLoader {
> void set(ResourceKey key, U&& data, ResourceDataState state, ResourcePolicy policy) { > void set(ResourceKey key, U&& data, ResourceDataState state, ResourcePolicy policy) {
set(key, new typename std::decay<U>::type(std::forward<U>(data)), state, policy); set(key, new typename std::decay<U>::type(std::forward<U>(data)), state, policy);
} }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Set loaded resource to resource manager * @brief Set loaded resource to resource manager
@ -166,16 +191,21 @@ template<class T> class AbstractResourceLoader {
* Same as above function with state set to @ref ResourceDataState::Final * Same as above function with state set to @ref ResourceDataState::Final
* and policy to @ref ResourcePolicy::Resident. * and policy to @ref ResourcePolicy::Resident.
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
void set(ResourceKey key, T* data) { void set(ResourceKey key, T* data) {
set(key, data, ResourceDataState::Final, ResourcePolicy::Resident); set(key, data, ResourceDataState::Final, ResourcePolicy::Resident);
} }
CORRADE_IGNORE_DEPRECATED_POP
/** @overload */ /** @overload */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
void set(ResourceKey key, Containers::Pointer<T> data) { void set(ResourceKey key, Containers::Pointer<T> data) {
set(key, data.release()); set(key, data.release());
} }
CORRADE_IGNORE_DEPRECATED_POP
/** @overload */ /** @overload */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class U template<class U
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
, typename std::enable_if<!std::is_same<typename std::decay<U>::type, std::nullptr_t>::value, int>::type = 0 , typename std::enable_if<!std::is_same<typename std::decay<U>::type, std::nullptr_t>::value, int>::type = 0
@ -183,6 +213,7 @@ template<class T> class AbstractResourceLoader {
> void set(ResourceKey key, U&& data) { > void set(ResourceKey key, U&& data) {
set(key, new typename std::decay<U>::type(std::forward<U>(data))); set(key, new typename std::decay<U>::type(std::forward<U>(data)));
} }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Mark resource as not found * @brief Mark resource as not found
@ -191,10 +222,11 @@ template<class T> class AbstractResourceLoader {
* and @ref ResourceDataState::NotFound. * and @ref ResourceDataState::NotFound.
* @see @ref notFoundCount() * @see @ref notFoundCount()
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
void setNotFound(ResourceKey key) { void setNotFound(ResourceKey key) {
/** @todo What policy for notfound resources? */
set(key, nullptr, ResourceDataState::NotFound, ResourcePolicy::Resident); set(key, nullptr, ResourceDataState::NotFound, ResourcePolicy::Resident);
} }
CORRADE_IGNORE_DEPRECATED_POP
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
private: private:
@ -206,14 +238,18 @@ template<class T> class AbstractResourceLoader {
* *
* Default implementation returns empty string. * Default implementation returns empty string.
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
virtual std::string doName(ResourceKey key) const; virtual std::string doName(ResourceKey key) const;
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Implementation for @ref load() * @brief Implementation for @ref load()
* *
* See class documentation for reimplementation guide. * See class documentation for reimplementation guide.
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
virtual void doLoad(ResourceKey key) = 0; virtual void doLoad(ResourceKey key) = 0;
CORRADE_IGNORE_DEPRECATED_POP
private: private:
#ifndef DOXYGEN_GENERATING_OUTPUT /* https://bugzilla.gnome.org/show_bug.cgi?id=776986 */ #ifndef DOXYGEN_GENERATING_OUTPUT /* https://bugzilla.gnome.org/show_bug.cgi?id=776986 */
@ -226,6 +262,7 @@ template<class T> class AbstractResourceLoader {
_notFoundCount; _notFoundCount;
}; };
CORRADE_IGNORE_DEPRECATED_PUSH
template<class T> AbstractResourceLoader<T>::~AbstractResourceLoader() { template<class T> AbstractResourceLoader<T>::~AbstractResourceLoader() {
if(manager) manager->_loader = nullptr; if(manager) manager->_loader = nullptr;
} }
@ -234,7 +271,6 @@ template<class T> std::string AbstractResourceLoader<T>::doName(ResourceKey) con
template<class T> void AbstractResourceLoader<T>::load(ResourceKey key) { template<class T> void AbstractResourceLoader<T>::load(ResourceKey key) {
++_requestedCount; ++_requestedCount;
/** @todo What policy for loading resources? */
manager->set(key, nullptr, ResourceDataState::Loading, ResourcePolicy::Resident); manager->set(key, nullptr, ResourceDataState::Loading, ResourcePolicy::Resident);
doLoad(key); doLoad(key);
@ -245,7 +281,11 @@ template<class T> void AbstractResourceLoader<T>::set(ResourceKey key, T* data,
if(!data && state == ResourceDataState::NotFound) ++_notFoundCount; if(!data && state == ResourceDataState::NotFound) ++_notFoundCount;
manager->set(key, data, state, policy); manager->set(key, data, state, policy);
} }
CORRADE_IGNORE_DEPRECATED_POP
} }
#else
#error the ResourceManager class is obsolete
#endif
#endif #endif

13
src/Magnum/CMakeLists.txt

@ -90,7 +90,6 @@ set(Magnum_SRCS
FileCallback.cpp FileCallback.cpp
ImageFlags.cpp ImageFlags.cpp
PixelStorage.cpp PixelStorage.cpp
Resource.cpp
Sampler.cpp Sampler.cpp
Timeline.cpp) Timeline.cpp)
@ -105,7 +104,6 @@ set(Magnum_GracefulAssert_SRCS
Animation/Interpolation.cpp) Animation/Interpolation.cpp)
set(Magnum_HEADERS set(Magnum_HEADERS
AbstractResourceLoader.h
British.h British.h
DimensionTraits.h DimensionTraits.h
FileCallback.h FileCallback.h
@ -116,8 +114,6 @@ set(Magnum_HEADERS
Mesh.h Mesh.h
PixelFormat.h PixelFormat.h
PixelStorage.h PixelStorage.h
Resource.h
ResourceManager.h
Sampler.h Sampler.h
Tags.h Tags.h
Timeline.h Timeline.h
@ -136,7 +132,14 @@ set(Magnum_PRIVATE_HEADERS
Implementation/vertexFormatMapping.hpp) Implementation/vertexFormatMapping.hpp)
if(MAGNUM_BUILD_DEPRECATED) 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() endif()
# Functionality specific to static Windows builds # Functionality specific to static Windows builds

6
src/Magnum/DebugTools/ForceRenderer.h

@ -152,7 +152,9 @@ template<UnsignedInt dimensions> class CORRADE_DEPRECATED("use Primitives::arrow
explicit ForceRenderer(ResourceManager&, SceneGraph::AbstractObject<dimensions, Float>&, const VectorTypeFor<dimensions, Float>&, VectorTypeFor<dimensions, Float>&&, ResourceKey = ResourceKey(), SceneGraph::DrawableGroup<dimensions, Float>* = nullptr) = delete; explicit ForceRenderer(ResourceManager&, SceneGraph::AbstractObject<dimensions, Float>&, const VectorTypeFor<dimensions, Float>&, VectorTypeFor<dimensions, Float>&&, ResourceKey = ResourceKey(), SceneGraph::DrawableGroup<dimensions, Float>* = nullptr) = delete;
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */
~ForceRenderer(); ~ForceRenderer();
CORRADE_IGNORE_DEPRECATED_POP
private: private:
void draw(const MatrixTypeFor<dimensions, Float>& transformationMatrix, SceneGraph::Camera<dimensions, Float>& camera) override; void draw(const MatrixTypeFor<dimensions, Float>& transformationMatrix, SceneGraph::Camera<dimensions, Float>& camera) override;
@ -160,11 +162,11 @@ template<UnsignedInt dimensions> class CORRADE_DEPRECATED("use Primitives::arrow
const VectorTypeFor<dimensions, Float> _forcePosition; const VectorTypeFor<dimensions, Float> _forcePosition;
const VectorTypeFor<dimensions, Float>& _force; const VectorTypeFor<dimensions, Float>& _force;
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns due to the type */ CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
Resource<ForceRendererOptions> _options; Resource<ForceRendererOptions> _options;
CORRADE_IGNORE_DEPRECATED_POP
Resource<GL::AbstractShaderProgram, Shaders::FlatGL<dimensions>> _shader; Resource<GL::AbstractShaderProgram, Shaders::FlatGL<dimensions>> _shader;
Resource<GL::Mesh> _mesh; Resource<GL::Mesh> _mesh;
CORRADE_IGNORE_DEPRECATED_POP
}; };
/** /**

6
src/Magnum/DebugTools/ObjectRenderer.h

@ -122,16 +122,18 @@ template<UnsignedInt dimensions> class CORRADE_DEPRECATED("use Primitives::axis2
explicit ObjectRenderer(ResourceManager& manager, SceneGraph::AbstractObject<dimensions, Float>& object, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions, Float>* drawables = nullptr); explicit ObjectRenderer(ResourceManager& manager, SceneGraph::AbstractObject<dimensions, Float>& object, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions, Float>* drawables = nullptr);
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here (?!) */
~ObjectRenderer(); ~ObjectRenderer();
CORRADE_IGNORE_DEPRECATED_POP
private: private:
void draw(const MatrixTypeFor<dimensions, Float>& transformationMatrix, SceneGraph::Camera<dimensions, Float>& camera) override; void draw(const MatrixTypeFor<dimensions, Float>& transformationMatrix, SceneGraph::Camera<dimensions, Float>& camera) override;
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns due to the type */ CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
Resource<ObjectRendererOptions> _options; Resource<ObjectRendererOptions> _options;
CORRADE_IGNORE_DEPRECATED_POP
Resource<GL::AbstractShaderProgram, Shaders::VertexColorGL<dimensions>> _shader; Resource<GL::AbstractShaderProgram, Shaders::VertexColorGL<dimensions>> _shader;
Resource<GL::Mesh> _mesh; Resource<GL::Mesh> _mesh;
CORRADE_IGNORE_DEPRECATED_POP
}; };
/** /**

6
src/Magnum/DebugTools/ResourceManager.cpp

@ -39,13 +39,15 @@
namespace Magnum { namespace DebugTools { namespace Magnum { namespace DebugTools {
CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here, GCC 4.8 for the inside */
ResourceManager::ResourceManager() { ResourceManager::ResourceManager() {
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
setFallback(new ForceRendererOptions); setFallback(new ForceRendererOptions);
setFallback(new ObjectRendererOptions); setFallback(new ObjectRendererOptions);
CORRADE_IGNORE_DEPRECATED_POP
} }
CORRADE_IGNORE_DEPRECATED_POP
CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */
ResourceManager::~ResourceManager() = default; ResourceManager::~ResourceManager() = default;
CORRADE_IGNORE_DEPRECATED_POP
}} }}

14
src/Magnum/Magnum.h

@ -1359,12 +1359,14 @@ enum class CompressedPixelFormat: UnsignedInt;
class PixelStorage; class PixelStorage;
class CompressedPixelStorage; class CompressedPixelStorage;
enum class ResourceState: UnsignedByte; #ifdef MAGNUM_BUILD_DEPRECATED
enum class ResourceDataState: UnsignedByte; enum class CORRADE_DEPRECATED_ENUM("the ResourceManager class is obsolete") ResourceState: UnsignedByte;
enum class ResourcePolicy: UnsignedByte; enum class CORRADE_DEPRECATED_ENUM("the ResourceManager class is obsolete") ResourceDataState: UnsignedByte;
template<class T, class U = T> class Resource; enum class CORRADE_DEPRECATED_ENUM("the ResourceManager class is obsolete") ResourcePolicy: UnsignedByte;
class ResourceKey; template<class T, class U = T> class CORRADE_DEPRECATED("the ResourceManager class is obsolete") Resource;
template<class...> class ResourceManager; class CORRADE_DEPRECATED("the ResourceManager class is obsolete") ResourceKey;
template<class...> class CORRADE_DEPRECATED("the ResourceManager class is obsolete") ResourceManager;
#endif
enum class SamplerFilter: UnsignedInt; enum class SamplerFilter: UnsignedInt;
enum class SamplerMipmap: UnsignedInt; enum class SamplerMipmap: UnsignedInt;

4
src/Magnum/Resource.cpp

@ -24,10 +24,13 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#define _MAGNUM_NO_DEPRECATED_RESOURCEMANAGER
#include "Resource.h" #include "Resource.h"
namespace Magnum { namespace Magnum {
CORRADE_IGNORE_DEPRECATED_PUSH
Debug& operator<<(Debug& debug, const ResourceState value) { Debug& operator<<(Debug& debug, const ResourceState value) {
debug << "ResourceState" << Debug::nospace; debug << "ResourceState" << Debug::nospace;
@ -52,5 +55,6 @@ Debug& operator<<(Debug& debug, const ResourceState value) {
Debug& operator<<(Debug& debug, const ResourceKey& value) { Debug& operator<<(Debug& debug, const ResourceKey& value) {
return debug << "ResourceKey(0x" << Debug::nospace << static_cast<const Utility::HashDigest<sizeof(std::size_t)>&>(value) << Debug::nospace << ")"; return debug << "ResourceKey(0x" << Debug::nospace << static_cast<const Utility::HashDigest<sizeof(std::size_t)>&>(value) << Debug::nospace << ")";
} }
CORRADE_IGNORE_DEPRECATED_POP
} }

86
src/Magnum/Resource.h

@ -27,10 +27,19 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#ifdef MAGNUM_BUILD_DEPRECATED
/** @file /** @file
* @brief Class @ref Magnum::ResourceKey, @ref Magnum::Resource, enum @ref Magnum::ResourceState * @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 <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/MurmurHash2.h> #include <Corrade/Utility/MurmurHash2.h>
@ -38,20 +47,26 @@
std::string -- and if DebugStl.h wouldn't be included, an attempt to print a 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 std::string would choose the ResourceKey printer instead, producing unwanted
results. */ results. */
/** @todo remove when we have a StringView and ResourceKey is ported to it */
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include "Magnum/Magnum.h" #include "Magnum/Magnum.h"
#include "Magnum/visibility.h" #include "Magnum/visibility.h"
/* File deprecation warning printed in ResourceManager.h, which is included at
the end of this header */
namespace Magnum { namespace Magnum {
/** /**
@brief Resource state @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() @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). */ /** The resource is not yet loaded (and no fallback is available). */
NotLoaded, NotLoaded,
@ -77,15 +92,27 @@ enum class ResourceState: UnsignedByte {
Final 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); MAGNUM_EXPORT Debug& operator<<(Debug& debug, ResourceState value);
CORRADE_IGNORE_DEPRECATED_POP
/** /**
@brief Key for accessing resource @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. 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: public:
/** /**
* @brief Default constructor * @brief Default constructor
@ -101,15 +128,20 @@ class ResourceKey: public Utility::MurmurHash2::Digest {
/** @brief Constructor */ /** @brief Constructor */
/*implicit*/ ResourceKey(const std::string& key): Utility::MurmurHash2::Digest(Utility::MurmurHash2()(key)) {} /*implicit*/ ResourceKey(const std::string& key): Utility::MurmurHash2::Digest(Utility::MurmurHash2()(key)) {}
/** /** @brief Constructor */
* @brief Constructor
* @todo constexpr
*/
template<std::size_t size> constexpr ResourceKey(const char(&key)[size]): Utility::MurmurHash2::Digest(Utility::MurmurHash2()(key)) {} template<std::size_t size> 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); MAGNUM_EXPORT Debug& operator<<(Debug& debug, const ResourceKey& value);
CORRADE_IGNORE_DEPRECATED_POP
namespace Implementation { namespace Implementation {
template<class> class ResourceManagerData; template<class> class ResourceManagerData;
@ -117,6 +149,10 @@ namespace Implementation {
/** /**
@brief Resource reference @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. See @ref ResourceManager for more information.
*/ */
@ -125,7 +161,7 @@ template<class T, class U = T>
#else #else
template<class T, class U> template<class T, class U>
#endif #endif
class Resource { class CORRADE_DEPRECATED("the ResourceManager class is obsolete") Resource {
public: public:
/** /**
* @brief Default constructor * @brief Default constructor
@ -160,7 +196,9 @@ class Resource {
} }
/** @brief Equality comparison with other types is explicitly disallowed */ /** @brief Equality comparison with other types is explicitly disallowed */
CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */
template<class V, class W> bool operator==(const Resource<V, W>&) const = delete; template<class V, class W> bool operator==(const Resource<V, W>&) const = delete;
CORRADE_IGNORE_DEPRECATED_POP
/** @brief Non-equality comparison */ /** @brief Non-equality comparison */
bool operator!=(const Resource<T, U>& other) const { bool operator!=(const Resource<T, U>& other) const {
@ -168,20 +206,26 @@ class Resource {
} }
/** @brief Non-equality comparison with other types is explicitly disallowed */ /** @brief Non-equality comparison with other types is explicitly disallowed */
CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */
template<class V, class W> bool operator!=(const Resource<V, W>&) const = delete; template<class V, class W> bool operator!=(const Resource<V, W>&) const = delete;
CORRADE_IGNORE_DEPRECATED_POP
/** @brief Resource key */ /** @brief Resource key */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
ResourceKey key() const { return _key; } ResourceKey key() const { return _key; }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Resource state * @brief Resource state
* *
* @see @ref operator bool(), @ref ResourceManager::state() * @see @ref operator bool(), @ref ResourceManager::state()
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */
ResourceState state() { ResourceState state() {
acquire(); acquire();
return _state; return _state;
} }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Whether the resource is available * @brief Whether the resource is available
@ -237,19 +281,26 @@ class Resource {
friend Implementation::ResourceManagerData<T>; friend Implementation::ResourceManagerData<T>;
#endif #endif
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
Resource(Implementation::ResourceManagerData<T>* manager, ResourceKey key): _manager{manager}, _key{key}, _lastCheck{0}, _state{ResourceState::NotLoaded}, _data{nullptr} { Resource(Implementation::ResourceManagerData<T>* manager, ResourceKey key): _manager{manager}, _key{key}, _lastCheck{0}, _state{ResourceState::NotLoaded}, _data{nullptr} {
manager->incrementReferenceCount(key); manager->incrementReferenceCount(key);
} }
CORRADE_IGNORE_DEPRECATED_POP
void acquire(); void acquire();
Implementation::ResourceManagerData<T>* _manager; Implementation::ResourceManagerData<T>* _manager;
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
ResourceKey _key; ResourceKey _key;
CORRADE_IGNORE_DEPRECATED_POP
std::size_t _lastCheck; std::size_t _lastCheck;
CORRADE_IGNORE_DEPRECATED_PUSH /* MSVC warns here */
ResourceState _state; ResourceState _state;
CORRADE_IGNORE_DEPRECATED_POP
T* _data; T* _data;
}; };
CORRADE_IGNORE_DEPRECATED_PUSH
template<class T, class U> Resource<T, U>& Resource<T, U>::operator=(const Resource<T, U>& other) { template<class T, class U> Resource<T, U>& Resource<T, U>::operator=(const Resource<T, U>& other) {
if(_manager) _manager->decrementReferenceCount(_key); if(_manager) _manager->decrementReferenceCount(_key);
@ -311,11 +362,20 @@ template<class T, class U> void Resource<T, U>::acquire() {
_state = ResourceState::NotLoaded; _state = ResourceState::NotLoaded;
} }
} }
CORRADE_IGNORE_DEPRECATED_POP
} }
namespace std { 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<Magnum::ResourceKey> { template<> struct hash<Magnum::ResourceKey> {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
std::size_t operator()(Magnum::ResourceKey key) const { std::size_t operator()(Magnum::ResourceKey key) const {
@ -323,9 +383,13 @@ namespace std {
} }
#endif #endif
}; };
CORRADE_IGNORE_DEPRECATED_POP
} }
/* Make the definition complete */ /* Make the definition complete */
#include "ResourceManager.h" #include "ResourceManager.h"
#else
#error the ResourceManager class is obsolete
#endif
#endif #endif

62
src/Magnum/ResourceManager.h

@ -26,23 +26,41 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#ifdef MAGNUM_BUILD_DEPRECATED
/** @file /** @file
* @brief Class @ref Magnum::ResourceManager, @ref Magnum::ResourceDataState, @ref Magnum::ResourcePolicy * @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 <unordered_map> #include <unordered_map>
#include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Pointer.h>
#include "Magnum/Resource.h" #include "Magnum/Resource.h"
#ifndef _MAGNUM_NO_DEPRECATED_RESOURCEMANAGER
CORRADE_DEPRECATED_FILE("the ResourceManager class is obsolete")
#endif
namespace Magnum { namespace Magnum {
/** /**
@brief Resource data state @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 @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 * The resource is currently loading. Parameter @p data in
* @ref ResourceManager::set() should be set to @cpp nullptr @ce. * @ref ResourceManager::set() should be set to @cpp nullptr @ce.
@ -70,13 +88,18 @@ enum class ResourceDataState: UnsignedByte {
*/ */
Final = UnsignedByte(ResourceState::Final) Final = UnsignedByte(ResourceState::Final)
}; };
CORRADE_IGNORE_DEPRECATED_POP
/** /**
@brief Resource policy @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() @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. */ /** The resource will stay resident for whole lifetime of resource manager. */
Resident, Resident,
@ -94,8 +117,7 @@ template<class> class AbstractResourceLoader;
namespace Implementation { namespace Implementation {
/** @todo Print either resource key or name string based on loader capabilities */ CORRADE_IGNORE_DEPRECATED_PUSH
template<class T> class ResourceManagerData { template<class T> class ResourceManagerData {
template<class, class> friend class Magnum::Resource; template<class, class> friend class Magnum::Resource;
friend AbstractResourceLoader<T>; friend AbstractResourceLoader<T>;
@ -159,11 +181,16 @@ template<class T> class ResourceManagerData {
/* Helper class for defining which real types are in the type pack */ /* Helper class for defining which real types are in the type pack */
template<class...> struct ResourceTypePack {}; template<class...> struct ResourceTypePack {};
CORRADE_IGNORE_DEPRECATED_POP
} }
/** /**
@brief Resource manager @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. 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 /* Due to too much work involved with explicit template instantiation (all
Resource combinations, all ResourceManagerData...), this class doesn't have Resource combinations, all ResourceManagerData...), this class doesn't have
template implementation file. */ template implementation file. */
template<class... Types> class ResourceManager: private Implementation::ResourceManagerData<Types>... { template<class... Types> class CORRADE_DEPRECATED("the ResourceManager class is obsolete") ResourceManager: private Implementation::ResourceManagerData<Types>... {
public: public:
/** @brief Constructor */ /** @brief Constructor */
explicit ResourceManager(); explicit ResourceManager();
@ -253,27 +280,33 @@ template<class... Types> class ResourceManager: private Implementation::Resource
* *
* @snippet Magnum.cpp ResourceManager-get-derived * @snippet Magnum.cpp ResourceManager-get-derived
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class T, class U = T> Resource<T, U> get(ResourceKey key) { template<class T, class U = T> Resource<T, U> get(ResourceKey key) {
return this->Implementation::ResourceManagerData<T>::template get<U>(key); return this->Implementation::ResourceManagerData<T>::template get<U>(key);
} }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Reference count of given resource * @brief Reference count of given resource
* *
* @see @ref set() * @see @ref set()
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class T> std::size_t referenceCount(ResourceKey key) const { template<class T> std::size_t referenceCount(ResourceKey key) const {
return this->Implementation::ResourceManagerData<T>::referenceCount(key); return this->Implementation::ResourceManagerData<T>::referenceCount(key);
} }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Resource state * @brief Resource state
* *
* @see @ref set(), @ref Resource::state() * @see @ref set(), @ref Resource::state()
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class T> ResourceState state(ResourceKey key) const { template<class T> ResourceState state(ResourceKey key) const {
return this->Implementation::ResourceManagerData<T>::state(key); return this->Implementation::ResourceManagerData<T>::state(key);
} }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Set resource data * @brief Set resource data
@ -287,24 +320,30 @@ template<class... Types> class ResourceManager: private Implementation::Resource
* already @ref ResourceState::Final. * already @ref ResourceState::Final.
* @see @ref referenceCount(), @ref state() * @see @ref referenceCount(), @ref state()
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class T> ResourceManager<Types...>& set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) { template<class T> ResourceManager<Types...>& set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) {
this->Implementation::ResourceManagerData<T>::set(key, data, state, policy); this->Implementation::ResourceManagerData<T>::set(key, data, state, policy);
return *this; return *this;
} }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @overload * @overload
* @m_since{2019,10} * @m_since{2019,10}
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class T> ResourceManager<Types...>& set(ResourceKey key, Containers::Pointer<T>&& data, ResourceDataState state, ResourcePolicy policy) { template<class T> ResourceManager<Types...>& set(ResourceKey key, Containers::Pointer<T>&& data, ResourceDataState state, ResourcePolicy policy) {
set(key, data.release(), state, policy); set(key, data.release(), state, policy);
return *this; return *this;
} }
CORRADE_IGNORE_DEPRECATED_POP
/** @overload */ /** @overload */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class U> ResourceManager<Types...>& set(ResourceKey key, U&& data, ResourceDataState state, ResourcePolicy policy) { template<class U> ResourceManager<Types...>& set(ResourceKey key, U&& data, ResourceDataState state, ResourcePolicy policy) {
return set(key, new typename std::decay<U>::type(std::forward<U>(data)), state, policy); return set(key, new typename std::decay<U>::type(std::forward<U>(data)), state, policy);
} }
CORRADE_IGNORE_DEPRECATED_POP
/** /**
* @brief Set resource data * @brief Set resource data
@ -313,19 +352,25 @@ template<class... Types> class ResourceManager: private Implementation::Resource
* Same as above with state set to @ref ResourceDataState::Final and * Same as above with state set to @ref ResourceDataState::Final and
* policy to @ref ResourcePolicy::Resident. * policy to @ref ResourcePolicy::Resident.
*/ */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class T> ResourceManager<Types...>& set(ResourceKey key, T* data) { template<class T> ResourceManager<Types...>& set(ResourceKey key, T* data) {
return set(key, data, ResourceDataState::Final, ResourcePolicy::Resident); return set(key, data, ResourceDataState::Final, ResourcePolicy::Resident);
} }
CORRADE_IGNORE_DEPRECATED_POP
/** @overload */ /** @overload */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class T> ResourceManager<Types...>& set(ResourceKey key, Containers::Pointer<T>&& data) { template<class T> ResourceManager<Types...>& set(ResourceKey key, Containers::Pointer<T>&& data) {
return set(key, data.release()); return set(key, data.release());
} }
CORRADE_IGNORE_DEPRECATED_POP
/** @overload */ /** @overload */
CORRADE_IGNORE_DEPRECATED_PUSH /* GCC 4.8 warns here */
template<class U> ResourceManager<Types...>& set(ResourceKey key, U&& data) { template<class U> ResourceManager<Types...>& set(ResourceKey key, U&& data) {
return set(key, new typename std::decay<U>::type(std::forward<U>(data))); return set(key, new typename std::decay<U>::type(std::forward<U>(data)));
} }
CORRADE_IGNORE_DEPRECATED_POP
/** @brief Fallback for not found resources */ /** @brief Fallback for not found resources */
template<class T> T* fallback() { template<class T> T* fallback() {
@ -454,6 +499,7 @@ template<class... Types> class ResourceManager: private Implementation::Resource
namespace Implementation { namespace Implementation {
CORRADE_IGNORE_DEPRECATED_PUSH
template<class T> void safeDelete(T* data) { template<class T> void safeDelete(T* data) {
static_assert(sizeof(T) > 0, "Cannot delete pointer to incomplete type"); static_assert(sizeof(T) > 0, "Cannot delete pointer to incomplete type");
delete data; delete data;
@ -592,18 +638,24 @@ template<class T> inline ResourceManagerData<T>::Data::~Data() {
"ResourceManager: cleared/destroyed while data are still referenced", ); "ResourceManager: cleared/destroyed while data are still referenced", );
safeDelete(data); safeDelete(data);
} }
CORRADE_IGNORE_DEPRECATED_POP
} }
CORRADE_IGNORE_DEPRECATED_PUSH
template<class ...Types> ResourceManager<Types...>::ResourceManager() = default; template<class ...Types> ResourceManager<Types...>::ResourceManager() = default;
template<class ...Types> ResourceManager<Types...>::~ResourceManager() { template<class ...Types> ResourceManager<Types...>::~ResourceManager() {
freeLoaders(typename Implementation::ResourceTypePack<Types...>{}); freeLoaders(typename Implementation::ResourceTypePack<Types...>{});
} }
CORRADE_IGNORE_DEPRECATED_POP
} }
/* Make the definition complete */ /* Make the definition complete */
#include "AbstractResourceLoader.h" #include "AbstractResourceLoader.h"
#else
#error the ResourceManager class is obsolete
#endif
#endif #endif

12
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(MeshTest MeshTest.cpp LIBRARIES MagnumTestLib)
corrade_add_test(PixelFormatTest PixelFormatTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(PixelFormatTest PixelFormatTest.cpp LIBRARIES MagnumTestLib)
corrade_add_test(PixelStorageTest PixelStorageTest.cpp LIBRARIES Magnum) corrade_add_test(PixelStorageTest PixelStorageTest.cpp LIBRARIES Magnum)
corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES Magnum)
corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES MagnumTestLib)
# Prefixed with project name to avoid conflicts with TagsTest in Corrade # Prefixed with project name to avoid conflicts with TagsTest in Corrade
corrade_add_test(MagnumTagsTest TagsTest.cpp LIBRARIES Magnum) 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) corrade_add_test(VertexFormatTest VertexFormatTest.cpp LIBRARIES MagnumTestLib)
if(MAGNUM_BUILD_DEPRECATED)
corrade_add_test(ArrayTest ArrayTest.cpp LIBRARIES Magnum)
endif()
set_property(TARGET set_property(TARGET
MeshTest MeshTest
PixelFormatTest PixelFormatTest
ResourceManagerTest
VertexFormatTest VertexFormatTest
APPEND PROPERTY COMPILE_DEFINITIONS "CORRADE_GRACEFUL_ASSERT") 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()

6
src/Magnum/Test/ResourceManagerTest.cpp

@ -25,10 +25,12 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#define _MAGNUM_NO_DEPRECATED_RESOURCEMANAGER
#include <Corrade/Containers/String.h> #include <Corrade/Containers/String.h>
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/Format.h> #include <Corrade/Utility/Format.h>
#include <Corrade/Utility/FormatStl.h> /** @todo remove once HashDigest is std::string-free */ #include <Corrade/Utility/FormatStl.h>
#include "Magnum/AbstractResourceLoader.h" #include "Magnum/AbstractResourceLoader.h"
#include "Magnum/ResourceManager.h" #include "Magnum/ResourceManager.h"
@ -70,6 +72,7 @@ struct Data {
~Data() { --count; } ~Data() { --count; }
}; };
CORRADE_IGNORE_DEPRECATED_PUSH
typedef Magnum::ResourceManager<Int, Data> ResourceManager; typedef Magnum::ResourceManager<Int, Data> ResourceManager;
size_t Data::count = 0; size_t Data::count = 0;
@ -544,6 +547,7 @@ void ResourceManagerTest::debugResourceKey() {
Debug{&out} << hello; Debug{&out} << hello;
CORRADE_COMPARE(out, Utility::format("ResourceKey(0x{})\n", hello.hexString())); CORRADE_COMPARE(out, Utility::format("ResourceKey(0x{})\n", hello.hexString()));
} }
CORRADE_IGNORE_DEPRECATED_POP
}}} }}}

Loading…
Cancel
Save