From 8c5d3a32cf3348586aff292a60bb6a1f0abcf15e Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 2 Sep 2013 18:35:36 +0200 Subject: [PATCH] Merged ResourceManager into Loader. --- src/Game.cpp | 4 +--- src/sprites/abstract/Sprite.cpp | 4 +--- src/util/Loader.h | 22 +++++++++++++++++++--- src/util/ResourceManager.h | 27 --------------------------- 4 files changed, 21 insertions(+), 36 deletions(-) delete mode 100644 src/util/ResourceManager.h diff --git a/src/Game.cpp b/src/Game.cpp index 8cd4498..31ddb56 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -13,7 +13,6 @@ #include "sprites/Enemy.h" #include "sprites/Player.h" #include "util/Loader.h" -#include "util/ResourceManager.h" #include "util/Yaml.h" /** @@ -29,8 +28,7 @@ Game::Game(tgui::Window& window) : initPlayer(); - mCrosshairTexture = ResourceManager::i().acquire(Loader::i() - .fromFile("crosshair.png")); + mCrosshairTexture = Loader::i().fromFile("crosshair.png"); mCrosshair.setTexture(*mCrosshairTexture, true); mWindow.setMouseCursorVisible(false); diff --git a/src/sprites/abstract/Sprite.cpp b/src/sprites/abstract/Sprite.cpp index f3262c8..95b7ca1 100755 --- a/src/sprites/abstract/Sprite.cpp +++ b/src/sprites/abstract/Sprite.cpp @@ -11,7 +11,6 @@ #include "../../util/Loader.h" #include "../../util/Log.h" -#include "../../util/ResourceManager.h" Sprite::Sprite(const Vector2f& position, Category category, unsigned short mask, const Vector2f& size, @@ -151,8 +150,7 @@ Sprite::setPosition(const Vector2f& position) { void Sprite::setTexture(const std::string& texture) { try { - mTexture = ResourceManager::i().acquire(Loader::i() - .fromFile(texture)); + mTexture = Loader::i().fromFile(texture); mShape.setTexture(&*mTexture, false); } catch (thor::ResourceLoadingException&) { diff --git a/src/util/Loader.h b/src/util/Loader.h index c0c129b..5bd1006 100755 --- a/src/util/Loader.h +++ b/src/util/Loader.h @@ -37,6 +37,9 @@ * @endcode */ class Loader : public Singleton { +private: + class ResourceManager; + public: /** * Sets the general resource folder path. @@ -52,11 +55,14 @@ public: } /** - * Loads a resource from a file, looking in the specific resource folder for this type. + * cquires a resource key by filename, then loads the resource from a + * file, looking in the specific resource folder for this type. */ - template thor::ResourceKey + template std::shared_ptr fromFile(const std::string& file) { - return static_cast* >(getLoader().get())->fromFile(mFolder, file); + auto resourceKey = static_cast* >(getLoader().get()) + ->fromFile(mFolder, file); + return mResourceManager.acquire(resourceKey); } private: @@ -117,9 +123,19 @@ private: (typeid(T), std::unique_ptr(new SpecificLoader))).first).second; }; +private: + class ResourceManager : public thor::MultiResourceCache { + public: + ResourceManager() { + setLoadingFailureStrategy(thor::Resources::ThrowException); + setReleaseStrategy(thor::Resources::AutoRelease); + }; + }; + private: std::string mFolder; std::map > mLoaders; + ResourceManager mResourceManager; }; #endif /* DG_LOADER_H_ */ diff --git a/src/util/ResourceManager.h b/src/util/ResourceManager.h deleted file mode 100644 index 278d228..0000000 --- a/src/util/ResourceManager.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * ResourceManager.h - * - * Created on: 22.07.2012 - * Author: Felix - */ - -#ifndef DG_RESOURCEMANAGER_H_ -#define DG_RESOURCEMANAGER_H_ - -#include "Singleton.h" - -/** - * Loads and manages all resources by providing Singleton access to - * Thor ResourceManager. - */ -class ResourceManager : public thor::MultiResourceCache, - public Singleton { -private: - friend class Singleton; - ResourceManager() { - setLoadingFailureStrategy(thor::Resources::ThrowException); - setReleaseStrategy(thor::Resources::AutoRelease); - }; -}; - -#endif /* DG_RESOURCEMANAGER_H_ */