From 8b5ea7b5dadf697086b35b386f79d7b69d5e9215 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 27 Jun 2015 16:25:42 +0300 Subject: In resource manager for fun function type use referecne to function. --- src/resources/resourcemanager.cpp | 25 +++++++++++++------------ src/resources/resourcemanager.h | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 9d1f9de1e..55ef60dc7 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -463,7 +463,8 @@ Resource *ResourceManager::getFromCache(const std::string &idPath) return nullptr; } -Resource *ResourceManager::get(const std::string &idPath, const generator fun, +Resource *ResourceManager::get(const std::string &idPath, + const generator fun, const void *const data) { #ifndef DISABLE_RESOURCE_CACHING @@ -532,7 +533,7 @@ struct ResourceLoader final Resource *ResourceManager::load(const std::string &path, const loader fun) { ResourceLoader rl = { this, path, fun }; - return get(path, &ResourceLoader::load, &rl); + return get(path, ResourceLoader::load, &rl); } SDLMusic *ResourceManager::getMusic(const std::string &idPath) @@ -592,7 +593,7 @@ struct DyedImageLoader final Image *ResourceManager::getImage(const std::string &idPath) { DyedImageLoader rl = { this, idPath }; - return static_cast(get(idPath, &DyedImageLoader::load, &rl)); + return static_cast(get(idPath, DyedImageLoader::load, &rl)); } struct ImageSetLoader final @@ -625,7 +626,7 @@ ImageSet *ResourceManager::getImageSet(const std::string &imagePath, ImageSetLoader rl = { this, imagePath, w, h }; std::stringstream ss; ss << imagePath << "[" << w << "x" << h << "]"; - return static_cast(get(ss.str(), &ImageSetLoader::load, &rl)); + return static_cast(get(ss.str(), ImageSetLoader::load, &rl)); } @@ -661,7 +662,7 @@ ImageSet *ResourceManager::getSubImageSet(Image *const parent, std::stringstream ss; ss << parent->getIdPath() << ", set[" << width << "x" << height << "]"; return static_cast(get(ss.str(), - &SubImageSetLoader::load, &rl)); + SubImageSetLoader::load, &rl)); } struct SubImageLoader final @@ -698,7 +699,7 @@ Image *ResourceManager::getSubImage(Image *const parent, std::stringstream ss; ss << parent->getIdPath() << ",[" << x << "," << y << "," << width << "x" << height << "]"; - return static_cast(get(ss.str(), &SubImageLoader::load, &rl)); + return static_cast(get(ss.str(), SubImageLoader::load, &rl)); } #ifdef USE_OPENGL @@ -723,7 +724,7 @@ Resource *ResourceManager::getAtlas(const std::string &name, const StringVect &files) { AtlasLoader rl = { name, &files }; - return get("atlas_" + name, &AtlasLoader::load, &rl); + return get("atlas_" + name, AtlasLoader::load, &rl); } struct ShaderLoader final @@ -747,7 +748,7 @@ Resource *ResourceManager::getShader(const unsigned int type, const std::string &name) { ShaderLoader rl = { name, type }; - return get("shader_" + name, &ShaderLoader::load, &rl); + return get("shader_" + name, ShaderLoader::load, &rl); } struct ShaderProgramLoader final @@ -773,7 +774,7 @@ Resource *ResourceManager::getShaderProgram(const std::string &vertex, { ShaderProgramLoader rl = { vertex, fragment }; return get("program_" + vertex + " + " + fragment, - &ShaderProgramLoader::load, &rl); + ShaderProgramLoader::load, &rl); } #endif @@ -803,7 +804,7 @@ WalkLayer *ResourceManager::getWalkLayer(const std::string &name, { WalkLayerLoader rl = {name, map}; return static_cast(get("map_" + name, - &WalkLayerLoader::load, &rl)); + WalkLayerLoader::load, &rl)); } struct SpriteDefLoader final @@ -828,7 +829,7 @@ SpriteDef *ResourceManager::getSprite(const std::string &path, SpriteDefLoader rl = { path, variant, mUseLongLiveSprites }; std::stringstream ss; ss << path << "[" << variant << "]"; - return static_cast(get(ss.str(), &SpriteDefLoader::load, &rl)); + return static_cast(get(ss.str(), SpriteDefLoader::load, &rl)); } void ResourceManager::release(Resource *const res) @@ -1041,7 +1042,7 @@ Image *ResourceManager::getRescaled(const Image *const image, "_rescaled%dx%d", width, height); const RescaledLoader rl = { this, image, width, height }; Image *const img = static_cast( - get(idPath, &RescaledLoader::load, &rl)); + get(idPath, RescaledLoader::load, &rl)); return img; } diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index afe158d78..91456460d 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -51,7 +51,7 @@ class ResourceManager final public: typedef Resource *(*loader)(SDL_RWops *); - typedef Resource *(*generator)(const void *const); + typedef Resource *(&generator)(const void *const); ResourceManager(); -- cgit v1.2.3-70-g09d2