diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-08-22 14:14:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-08-22 14:14:34 +0300 |
commit | da05d9dd98315378bdded216184294f376643191 (patch) | |
tree | ffc4b984c73c3bb68d26a1df6481634254075744 /src/resources | |
parent | ec856b2026c7ceecab5f74942bb36661d7c6ae67 (diff) | |
download | manaverse-da05d9dd98315378bdded216184294f376643191.tar.gz manaverse-da05d9dd98315378bdded216184294f376643191.tar.bz2 manaverse-da05d9dd98315378bdded216184294f376643191.tar.xz manaverse-da05d9dd98315378bdded216184294f376643191.zip |
Use resource manager as global variable.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/ambientlayer.cpp | 11 | ||||
-rw-r--r-- | src/resources/atlasmanager.cpp | 15 | ||||
-rw-r--r-- | src/resources/atlasresource.cpp | 3 | ||||
-rw-r--r-- | src/resources/image.cpp | 4 | ||||
-rw-r--r-- | src/resources/map/map.cpp | 8 | ||||
-rw-r--r-- | src/resources/map/mapitem.cpp | 7 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 8 | ||||
-rw-r--r-- | src/resources/resource.cpp | 3 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 5 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 6 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 4 |
11 files changed, 25 insertions, 49 deletions
diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp index 391cc1410..454758e88 100644 --- a/src/resources/ambientlayer.cpp +++ b/src/resources/ambientlayer.cpp @@ -59,11 +59,12 @@ AmbientLayer::AmbientLayer(Image *const img, { // Rescale the overlay to keep the ratio as if we were on // the default resolution... - Image *const rescaledOverlay = ResourceManager::getInstance()-> - getRescaled(mImage, static_cast<int>(mImage->mBounds.w) - / defaultScreenWidth * width, - static_cast<int>(mImage->mBounds.h) - / defaultScreenHeight * height); + Image *const rescaledOverlay = resourceManager->getRescaled( + mImage, + static_cast<int>(mImage->mBounds.w) / + defaultScreenWidth * width, + static_cast<int>(mImage->mBounds.h) / + defaultScreenHeight * height); if (rescaledOverlay) mImage = rescaledOverlay; diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp index 23a1ec653..a3836ad46 100644 --- a/src/resources/atlasmanager.cpp +++ b/src/resources/atlasmanager.cpp @@ -101,19 +101,18 @@ void AtlasManager::loadImages(const StringVect &files, std::vector<Image*> &images) { BLOCK_START("AtlasManager::loadImages") - ResourceManager *const resman = ResourceManager::getInstance(); FOR_EACH (StringVectCIter, it, files) { const std::string str = *it; // check is image with same name already in cache // and if yes, move it to deleted set - Resource *const res = resman->getTempResource(str); + Resource *const res = resourceManager->getTempResource(str); if (res) { // increase counter because in moveToDeleted it will be decreased. res->incRef(); - resman->moveToDeleted(res); + resourceManager->moveToDeleted(res); } std::string path = str; @@ -321,7 +320,6 @@ void AtlasManager::injectToResources(const AtlasResource *const resource) { if (!resource) return; - ResourceManager *const resman = ResourceManager::getInstance(); FOR_EACH (std::vector<TextureAtlas*>::const_iterator, it, resource->atlases) { @@ -331,14 +329,14 @@ void AtlasManager::injectToResources(const AtlasResource *const resource) { Image *const image = atlas->atlasImage; if (image) - resman->addResource(atlas->name, image); + resourceManager->addResource(atlas->name, image); FOR_EACH (std::vector<AtlasItem*>::iterator, it2, atlas->items) { AtlasItem *const item = *it2; if (!item) continue; // add each atlas sub image to resources - resman->addResource(item->name, item->image); + resourceManager->addResource(item->name, item->image); } } } @@ -348,7 +346,6 @@ void AtlasManager::moveToDeleted(AtlasResource *const resource) { if (!resource) return; - ResourceManager *const resman = ResourceManager::getInstance(); FOR_EACH (std::vector<TextureAtlas*>::iterator, it, resource->atlases) { // move each atlas image to deleted @@ -359,7 +356,7 @@ void AtlasManager::moveToDeleted(AtlasResource *const resource) if (image) { // move each atlas image to deleted - resman->moveToDeleted(image); + resourceManager->moveToDeleted(image); } FOR_EACH (std::vector<AtlasItem*>::iterator, it2, atlas->items) { @@ -370,7 +367,7 @@ void AtlasManager::moveToDeleted(AtlasResource *const resource) if (image2) { // move each atlas sub image to deleted - resman->moveToDeleted(image2); + resourceManager->moveToDeleted(image2); } } } diff --git a/src/resources/atlasresource.cpp b/src/resources/atlasresource.cpp index 0ec211979..9f27446bd 100644 --- a/src/resources/atlasresource.cpp +++ b/src/resources/atlasresource.cpp @@ -53,8 +53,7 @@ AtlasResource::~AtlasResource() delete atlas; } } - ResourceManager *const resman = ResourceManager::getInstance(); - resman->clearDeleted(false); + resourceManager->clearDeleted(false); } void AtlasResource::incRef() diff --git a/src/resources/image.cpp b/src/resources/image.cpp index fc1c5fa4f..ef15a26b2 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -185,14 +185,12 @@ Image::~Image() void Image::SDLCleanCache() { - ResourceManager *const resman = ResourceManager::getInstance(); - for (std::map<float, SDL_Surface*>::iterator i = mAlphaCache.begin(), i_end = mAlphaCache.end(); i != i_end; ++i) { if (mSDLSurface != i->second) - resman->scheduleDelete(i->second); + resourceManager->scheduleDelete(i->second); i->second = nullptr; } mAlphaCache.clear(); diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index b96abc7d2..cc2d3487a 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -222,8 +222,6 @@ void Map::optionChanged(const std::string &value) void Map::initializeAmbientLayers() { - ResourceManager *const resman = ResourceManager::getInstance(); - // search for "foreground*" or "overlay*" (old term) in map properties for (int i = 0; /* terminated by a break */; i++) { @@ -243,7 +241,8 @@ void Map::initializeAmbientLayers() break; // the FOR loop } - Image *const img = resman->getImage(getProperty(name + "image")); + Image *const img = resourceManager->getImage( + getProperty(name + "image")); if (img) { int mask = atoi(getProperty(name + "mask").c_str()); @@ -270,7 +269,8 @@ void Map::initializeAmbientLayers() toString(i)).append("image")); i ++) { const std::string name("background" + toString(i)); - Image *const img = resman->getImage(getProperty(name + "image")); + Image *const img = resourceManager->getImage( + getProperty(name + "image")); if (img) { diff --git a/src/resources/map/mapitem.cpp b/src/resources/map/mapitem.cpp index 44f3ec889..ae45a0efb 100644 --- a/src/resources/map/mapitem.cpp +++ b/src/resources/map/mapitem.cpp @@ -114,14 +114,9 @@ void MapItem::setType(const int type) } if (!name.empty()) - { - ResourceManager *const resman = ResourceManager::getInstance(); - mImage = resman->getImage(name); - } + mImage = resourceManager->getImage(name); else - { mImage = nullptr; - } } void MapItem::setPos(const int x, const int y) diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index f2ec5633d..8283a4268 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -330,7 +330,6 @@ Map *MapReader::readMap(XmlNodePtrConst node, const std::string &path) const std::string fileName = path.substr(path.rfind("/") + 1); map->setProperty("shortName", fileName); - ResourceManager *const resman = ResourceManager::getInstance(); #ifdef USE_OPENGL BLOCK_START("MapReader::readMap load atlas") @@ -339,7 +338,7 @@ Map *MapReader::readMap(XmlNodePtrConst node, const std::string &path) const MapInfo *const info = MapDB::getMapAtlas(fileName); if (info) { - map->setAtlas(resman->getAtlas( + map->setAtlas(resourceManager->getAtlas( info->atlas, *info->files)); } } @@ -460,7 +459,7 @@ Map *MapReader::readMap(XmlNodePtrConst node, const std::string &path) map->clearIndexedTilesets(); map->setActorsFix(0, atoi(map->getProperty("actorsfix").c_str())); map->reduce(); - map->setWalkLayer(resman->getWalkLayer(fileName, map)); + map->setWalkLayer(resourceManager->getWalkLayer(fileName, map)); unloadTempLayers(); map->updateDrawLayersList(); BLOCK_END("MapReader::readMap xml") @@ -946,8 +945,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, if (!source.empty()) { - ResourceManager *const resman = ResourceManager::getInstance(); - Image *const tilebmp = resman->getImage( + Image *const tilebmp = resourceManager->getImage( resolveRelativePath(pathDir, source)); if (tilebmp) diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index 6ff66e303..f6fda29a1 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -65,7 +65,6 @@ void Resource::decRef() if (mRefCount == 0 && !mNotCount) { // Warn the manager that this resource is no longer used. - ResourceManager *const resman = ResourceManager::getInstance(); - resman->release(this); + resourceManager->release(this); } } diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 50d6ccb6d..b32126403 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -954,11 +954,6 @@ void ResourceManager::decRefDelete(Resource *const res) } } -ResourceManager *ResourceManager::getInstance() -{ - return resourceManager; -} - void ResourceManager::deleteInstance() { #ifdef DUMP_LEAKED_RESOURCES diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 9e3480380..6557afecf 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -220,12 +220,6 @@ class ResourceManager final void clearScheduled(); /** - * Returns an instance of the class, creating one if it does not - * already exist. - */ - static ResourceManager *getInstance() RETURNS_NONNULL A_WARN_UNUSED; - - /** * Deletes the class instance if it exists. */ static void deleteInstance(); diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 20d0537d1..d63ffdd8e 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -232,8 +232,8 @@ void SpriteDef::loadImageSet(const XmlNodePtr node, std::string imageSrc = XML::getProperty(node, "src", ""); Dye::instantiate(imageSrc, palettes); - ResourceManager *const resman = ResourceManager::getInstance(); - ImageSet *const imageSet = resman->getImageSet(imageSrc, width, height); + ImageSet *const imageSet = resourceManager->getImageSet(imageSrc, + width, height); if (!imageSet) { |