diff options
Diffstat (limited to 'src/resources')
33 files changed, 93 insertions, 57 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp index a8bf83673..85f716b28 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -85,15 +85,15 @@ void Action::setLastFrameDelay(const int delay) noexcept } } -int Action::calcMemoryLocal() +int Action::calcMemoryLocal() const { return sizeof(Action); } -int Action::calcMemoryChilds(const int level) +int Action::calcMemoryChilds(const int level) const { int sz = 0; - FOR_EACH (AnimationIter, it, mAnimations) + FOR_EACH (AnimationCIter, it, mAnimations) { sz += sizeof(SpriteDirection::Type); Animation *const animation = (*it).second; diff --git a/src/resources/action.h b/src/resources/action.h index 0f6288815..6cf4ed0d0 100644 --- a/src/resources/action.h +++ b/src/resources/action.h @@ -59,13 +59,14 @@ class Action final : public MemoryCounter void setLastFrameDelay(const int delay) noexcept; - int calcMemoryLocal() override final; + int calcMemoryLocal() const override final; - int calcMemoryChilds(const int level) override final; + int calcMemoryChilds(const int level) const override final; protected: typedef std::map<SpriteDirection::Type, Animation*> Animations; typedef Animations::iterator AnimationIter; + typedef Animations::const_iterator AnimationCIter; Animations mAnimations; unsigned mNumber; diff --git a/src/resources/animation/animation.cpp b/src/resources/animation/animation.cpp index e52b55737..5af1f7dbb 100644 --- a/src/resources/animation/animation.cpp +++ b/src/resources/animation/animation.cpp @@ -87,12 +87,12 @@ void Animation::setLastFrameDelay(const int delay) noexcept } } -int Animation::calcMemoryLocal() +int Animation::calcMemoryLocal() const { int sz = sizeof(Animation); - FOR_EACH (FramesIter, it, mFrames) + FOR_EACH (FramesCIter, it, mFrames) { - Frame &frame = *it; + const Frame &frame = *it; sz += sizeof(Frame) + frame.nextAction.capacity(); } diff --git a/src/resources/animation/animation.h b/src/resources/animation/animation.h index dc44a3f0d..0c0b7c6e4 100644 --- a/src/resources/animation/animation.h +++ b/src/resources/animation/animation.h @@ -76,6 +76,7 @@ class Animation final : public MemoryCounter typedef std::vector<Frame> Frames; typedef Frames::iterator FramesIter; + typedef Frames::const_iterator FramesCIter; typedef Frames::reverse_iterator FramesRevIter; #ifdef UNITTESTS @@ -83,7 +84,7 @@ class Animation final : public MemoryCounter { return mFrames; } #endif - int calcMemoryLocal() override final; + int calcMemoryLocal() const override final; /** * Determines whether the given animation frame is a terminator. diff --git a/src/resources/atlas/atlasitem.h b/src/resources/atlas/atlasitem.h index 3a9f05f8d..a5d4d9116 100644 --- a/src/resources/atlas/atlasitem.h +++ b/src/resources/atlas/atlasitem.h @@ -43,7 +43,7 @@ struct AtlasItem final : public MemoryCounter A_DELETE_COPY(AtlasItem) - int calcMemoryLocal() override final + int calcMemoryLocal() const override final { return sizeof(AtlasItem) + name.capacity(); diff --git a/src/resources/atlas/atlasresource.cpp b/src/resources/atlas/atlasresource.cpp index d48394698..9ecc32692 100644 --- a/src/resources/atlas/atlasresource.cpp +++ b/src/resources/atlas/atlasresource.cpp @@ -71,17 +71,17 @@ void AtlasResource::decRef() AtlasManager::moveToDeleted(this); } -int AtlasResource::calcMemoryLocal() +int AtlasResource::calcMemoryLocal() const { return sizeof(AtlasResource) + Resource::calcMemoryLocal() + atlases.capacity() * sizeof(TextureAtlas*); } -int AtlasResource::calcMemoryChilds(const int level) +int AtlasResource::calcMemoryChilds(const int level) const { int sz = 0; - FOR_EACH (std::vector<TextureAtlas*>::iterator, it, atlases) + FOR_EACH (std::vector<TextureAtlas*>::const_iterator, it, atlases) { TextureAtlas *const atlas = *it; sz += atlas->calcMemory(level + 1); diff --git a/src/resources/atlas/atlasresource.h b/src/resources/atlas/atlasresource.h index 7dddc6728..5753c77e3 100644 --- a/src/resources/atlas/atlasresource.h +++ b/src/resources/atlas/atlasresource.h @@ -44,9 +44,9 @@ class AtlasResource final : public Resource void decRef() override final; - int calcMemoryLocal() override final; + int calcMemoryLocal() const override final; - int calcMemoryChilds(const int level) override final; + int calcMemoryChilds(const int level) const override final; std::vector<TextureAtlas*> atlases; }; diff --git a/src/resources/atlas/textureatlas.h b/src/resources/atlas/textureatlas.h index aefa831d1..fce101f64 100644 --- a/src/resources/atlas/textureatlas.h +++ b/src/resources/atlas/textureatlas.h @@ -54,16 +54,16 @@ struct TextureAtlas final : public MemoryCounter A_DELETE_COPY(TextureAtlas) - int calcMemoryLocal() override final + int calcMemoryLocal() const override final { return sizeof(TextureAtlas) + items.capacity() * sizeof(AtlasItem*); } - int calcMemoryChilds(const int level) override final + int calcMemoryChilds(const int level) const override final { int sz = 0; - FOR_EACH (std::vector<AtlasItem*>::iterator, it, items) + FOR_EACH (std::vector<AtlasItem*>::const_iterator, it, items) { AtlasItem *const item = *it; sz += item->calcMemory(level + 1); diff --git a/src/resources/image.cpp b/src/resources/image.cpp index b323f8a16..aaa779360 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -474,7 +474,7 @@ void Image::SDLTerminateAlphaCache() mUseAlphaCache = false; } -int Image::calcMemoryLocal() +int Image::calcMemoryLocal() const { // +++ this calculation can be wrong for SDL2 int sz = sizeof(Image) + diff --git a/src/resources/image.h b/src/resources/image.h index 7fbbcac21..e1c100e28 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -189,7 +189,7 @@ class Image notfinal : public Resource SDL_Surface* getSDLSurface() { return mSDLSurface; } - int calcMemoryLocal() override; + int calcMemoryLocal() const override; SDL_Rect mBounds; diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index 2bf4641c6..e20ad4eb4 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -76,7 +76,7 @@ Image* ImageSet::get(const size_type i) const } } -int ImageSet::calcMemoryLocal() +int ImageSet::calcMemoryLocal() const { return sizeof(ImageSet) + Resource::calcMemoryLocal() + diff --git a/src/resources/imageset.h b/src/resources/imageset.h index 37b6771b4..6673303aa 100644 --- a/src/resources/imageset.h +++ b/src/resources/imageset.h @@ -84,7 +84,7 @@ class ImageSet notfinal : public Resource const std::vector<Image*> &getImages() const { return mImages; } - int calcMemoryLocal() override; + int calcMemoryLocal() const override; private: std::vector<Image*> mImages; diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp index 0c18bf289..03901d00a 100644 --- a/src/resources/map/maplayer.cpp +++ b/src/resources/map/maplayer.cpp @@ -744,3 +744,20 @@ void MapLayer::updateConditionTiles(MetaTile *const metaTiles, } } } + +int MapLayer::calcMemoryLocal() const +{ + return sizeof(MapLayer) + + sizeof(TileInfo) * mWidth * mHeight + + sizeof(MapRowVertexes) * mTempRows.capacity(); +} + +int MapLayer::calcMemoryChilds(const int level) const +{ + int sz = 0; + if (mSpecialLayer) + sz += mSpecialLayer->calcMemory(level + 1); + if (mTempLayer) + sz += mTempLayer->calcMemory(level + 1); + return sz; +} diff --git a/src/resources/map/maplayer.h b/src/resources/map/maplayer.h index 45dcaec02..dc48fc2ef 100644 --- a/src/resources/map/maplayer.h +++ b/src/resources/map/maplayer.h @@ -25,6 +25,8 @@ #include "listeners/configlistener.h" +#include "resources/memorycounter.h" + #include "being/actor.h" #include "enums/resources/map/maptype.h" @@ -43,7 +45,7 @@ struct MetaTile; * A map layer. Stores a grid of tiles and their offset, and implements layer * rendering. */ -class MapLayer final: public ConfigListener +class MapLayer final: public MemoryCounter, public ConfigListener { public: enum Type @@ -162,6 +164,10 @@ class MapLayer final: public ConfigListener void setActorsFix(const int y) restrict { mActorsFix = y; } + int calcMemoryLocal() const override final; + + int calcMemoryChilds(const int level) const override final; + protected: static int getTileDrawWidth(const TileInfo *restrict img, const int endX, diff --git a/src/resources/map/speciallayer.cpp b/src/resources/map/speciallayer.cpp index 8700e3931..e53900134 100644 --- a/src/resources/map/speciallayer.cpp +++ b/src/resources/map/speciallayer.cpp @@ -148,3 +148,9 @@ void SpecialLayer::draw(Graphics *const graphics, int startX, int startY, } BLOCK_END("SpecialLayer::draw") } + +int SpecialLayer::calcMemoryLocal() const +{ + return sizeof(SpecialLayer) + + sizeof(MapItem) * mWidth * mHeight; +} diff --git a/src/resources/map/speciallayer.h b/src/resources/map/speciallayer.h index f930a9759..b8b2c251a 100644 --- a/src/resources/map/speciallayer.h +++ b/src/resources/map/speciallayer.h @@ -21,6 +21,8 @@ #ifndef RESOURCES_MAP_SPECIALLAYER_H #define RESOURCES_MAP_SPECIALLAYER_H +#include "resources/memorycounter.h" + #include "position.h" #include "localconsts.h" @@ -28,7 +30,7 @@ class Graphics; class MapItem; -class SpecialLayer final +class SpecialLayer final : public MemoryCounter { public: friend class Map; @@ -55,6 +57,8 @@ class SpecialLayer final void clean() const; + int calcMemoryLocal() const override final; + private: int mWidth; int mHeight; diff --git a/src/resources/map/tileset.h b/src/resources/map/tileset.h index 1c8cccda1..c2f4a297c 100644 --- a/src/resources/map/tileset.h +++ b/src/resources/map/tileset.h @@ -74,7 +74,7 @@ class Tileset final : public ImageSet return mProperties[name]; } - int calcMemoryLocal() override final + int calcMemoryLocal() const override final { int sz = ImageSet::calcMemoryLocal() + sizeof(Tileset); diff --git a/src/resources/map/walklayer.cpp b/src/resources/map/walklayer.cpp index 9f93f94dd..7bc505f18 100644 --- a/src/resources/map/walklayer.cpp +++ b/src/resources/map/walklayer.cpp @@ -43,7 +43,7 @@ int WalkLayer::getDataAt(const int x, const int y) const return mTiles[x + y * mWidth]; } -int WalkLayer::calcMemoryLocal() +int WalkLayer::calcMemoryLocal() const { return Resource::calcMemoryLocal() + sizeof(WalkLayer) + diff --git a/src/resources/map/walklayer.h b/src/resources/map/walklayer.h index d867ad0fd..efa85b9dd 100644 --- a/src/resources/map/walklayer.h +++ b/src/resources/map/walklayer.h @@ -39,7 +39,7 @@ class WalkLayer final : public Resource int getDataAt(const int x, const int y) const; - int calcMemoryLocal() override final; + int calcMemoryLocal() const override final; private: int mWidth; diff --git a/src/resources/memorycounter.cpp b/src/resources/memorycounter.cpp index e2961556e..e42a2640d 100644 --- a/src/resources/memorycounter.cpp +++ b/src/resources/memorycounter.cpp @@ -28,12 +28,12 @@ MemoryCounter::MemoryCounter() { } -int MemoryCounter::calcMemoryLocal() +int MemoryCounter::calcMemoryLocal() const { return 0; } -int MemoryCounter::calcMemory(const int level) +int MemoryCounter::calcMemory(const int level) const { const int sumLocal = calcMemoryLocal(); const int sumChilds = calcMemoryChilds(level); @@ -41,7 +41,7 @@ int MemoryCounter::calcMemory(const int level) return sumLocal + sumChilds; } -int MemoryCounter::calcMemoryChilds(const int level A_UNUSED) +int MemoryCounter::calcMemoryChilds(const int level A_UNUSED) const { return 0; } diff --git a/src/resources/memorycounter.h b/src/resources/memorycounter.h index cb9d62583..94593b717 100644 --- a/src/resources/memorycounter.h +++ b/src/resources/memorycounter.h @@ -31,11 +31,11 @@ class MemoryCounter notfinal virtual ~MemoryCounter() { } - int calcMemory(const int level); + int calcMemory(const int level) const; - virtual int calcMemoryLocal(); + virtual int calcMemoryLocal() const; - virtual int calcMemoryChilds(const int level); + virtual int calcMemoryChilds(const int level) const; }; #endif // RESOURCES_MEMORYCOUNTER_H diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index a16f088a3..959298290 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -69,7 +69,7 @@ void Resource::decRef() } } -int Resource::calcMemoryLocal() +int Resource::calcMemoryLocal() const { return CAST_S32(sizeof(Resource)) + CAST_S32(mIdPath.size()) + diff --git a/src/resources/resource.h b/src/resources/resource.h index c2d3ad865..90cea413c 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -99,7 +99,7 @@ class Resource notfinal : public MemoryCounter void setNotCount(const bool b) { mNotCount = b; } - int calcMemoryLocal() override; + int calcMemoryLocal() const override; #ifdef DEBUG_DUMP_LEAKS bool getDumped() const A_WARN_UNUSED diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 54ffe2d8e..cc990f811 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -1067,7 +1067,7 @@ void ResourceManager::clearCache() continue; } -int ResourceManager::calcMemoryLocal() +int ResourceManager::calcMemoryLocal() const { int sz = sizeof(ResourceManager); FOR_EACH (std::set<SDL_Surface*>::iterator, it, deletedSurfaces) @@ -1077,20 +1077,20 @@ int ResourceManager::calcMemoryLocal() return sz; } -int ResourceManager::calcMemoryChilds(const int level) +int ResourceManager::calcMemoryChilds(const int level) const { int sz = 0; - FOR_EACH (ResourceIterator, it, mResources) + FOR_EACH (ResourceCIterator, it, mResources) { sz += (*it).first.capacity(); sz += (*it).second->calcMemory(level + 1); } - FOR_EACH (ResourceIterator, it, mOrphanedResources) + FOR_EACH (ResourceCIterator, it, mOrphanedResources) { sz += (*it).first.capacity(); sz += (*it).second->calcMemory(level + 1); } - FOR_EACH (std::set<Resource*>::iterator, it, mDeletedResources) + FOR_EACH (std::set<Resource*>::const_iterator, it, mDeletedResources) { sz += (*it)->calcMemory(level + 1); } diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index eef584f27..8d952e207 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -255,9 +255,9 @@ class ResourceManager final : public MemoryCounter void clearCache(); - int calcMemoryLocal() override final; + int calcMemoryLocal() const override final; - int calcMemoryChilds(const int level) override final; + int calcMemoryChilds(const int level) const override final; static void init(); diff --git a/src/resources/sdlmusic.cpp b/src/resources/sdlmusic.cpp index af0fbf3a0..ddcd2366f 100644 --- a/src/resources/sdlmusic.cpp +++ b/src/resources/sdlmusic.cpp @@ -74,7 +74,7 @@ bool SDLMusic::play(const int loops, const int fadeIn) return Mix_FadeInMusicPos(mMusic, loops, 0, 0.0); } -int SDLMusic::calcMemoryLocal() +int SDLMusic::calcMemoryLocal() const { // +++ not used size of SDL_RWops return sizeof(SDLMusic) + diff --git a/src/resources/sdlmusic.h b/src/resources/sdlmusic.h index b6f8f3150..6ba42796b 100644 --- a/src/resources/sdlmusic.h +++ b/src/resources/sdlmusic.h @@ -70,7 +70,7 @@ class SDLMusic final : public Resource */ bool play(const int loops = -1, const int fadeIn = 0); - int calcMemoryLocal() override final; + int calcMemoryLocal() const override final; protected: /** diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index 7f43e2e44..9cf511965 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -57,7 +57,7 @@ bool SoundEffect::play(const int loops, const int volume, return Mix_PlayChannel(channel, mChunk, loops) != -1; } -int SoundEffect::calcMemoryLocal() +int SoundEffect::calcMemoryLocal() const { return sizeof(SoundEffect) + sizeof(SDL_AudioSpec) + diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index 2eed8fbfd..a8e11ca6b 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -65,7 +65,7 @@ class SoundEffect final : public Resource bool play(const int loops, const int volume, const int channel = -1) const; - int calcMemoryLocal() override final; + int calcMemoryLocal() const override final; protected: /** diff --git a/src/resources/sprite/spritedef.cpp b/src/resources/sprite/spritedef.cpp index ba3abaec9..066d0b827 100644 --- a/src/resources/sprite/spritedef.cpp +++ b/src/resources/sprite/spritedef.cpp @@ -594,7 +594,7 @@ bool SpriteDef::addSequence(const int start, return false; } -int SpriteDef::calcMemoryLocal() +int SpriteDef::calcMemoryLocal() const { int sz = sizeof(SpriteDef) + sizeof(ImageSets) + @@ -608,20 +608,20 @@ int SpriteDef::calcMemoryLocal() return sz; } -int SpriteDef::calcMemoryChilds(const int level) +int SpriteDef::calcMemoryChilds(const int level) const { int sz = 0; - FOR_EACH (ImageSets::iterator, it, mImageSets) + FOR_EACH (ImageSets::const_iterator, it, mImageSets) { sz += (*it).first.capacity(); - ImageSet *const imageSet = (*it).second; + const ImageSet *const imageSet = (*it).second; sz += imageSet->calcMemory(level + 1); } - FOR_EACH (ActionsIter, it, mActions) + FOR_EACH (ActionsCIter, it, mActions) { sz += sizeof(unsigned); - ActionMap *const actionMap = (*it).second; - FOR_EACHP (ActionMap::iterator, it2, actionMap) + const ActionMap *const actionMap = (*it).second; + FOR_EACHP (ActionMap::const_iterator, it2, actionMap) { sz += (*it2).first.capacity(); Action *const action = (*it2).second; diff --git a/src/resources/sprite/spritedef.h b/src/resources/sprite/spritedef.h index aea602cee..2fdd1987b 100644 --- a/src/resources/sprite/spritedef.h +++ b/src/resources/sprite/spritedef.h @@ -68,9 +68,9 @@ class SpriteDef final : public Resource void addAction(const unsigned hp, const std::string &name, Action *const action); - int calcMemoryLocal() override final; + int calcMemoryLocal() const override final; - int calcMemoryChilds(const int level) override final; + int calcMemoryChilds(const int level) const override final; static bool addSequence(const int start, const int end, @@ -154,6 +154,7 @@ class SpriteDef final : public Resource typedef std::map<unsigned, ActionMap*> Actions; typedef Actions::const_iterator ActionsConstIter; typedef Actions::iterator ActionsIter; + typedef Actions::const_iterator ActionsCIter; ImageSets mImageSets; Actions mActions; diff --git a/src/resources/subimage.cpp b/src/resources/subimage.cpp index 1b8cc9ec8..0652195dd 100644 --- a/src/resources/subimage.cpp +++ b/src/resources/subimage.cpp @@ -223,7 +223,7 @@ void SubImage::decRef() } #endif -int SubImage::calcMemoryLocal() +int SubImage::calcMemoryLocal() const { int sz = sizeof(SubImage) + sizeof(std::map<float, SDL_Surface*>) + diff --git a/src/resources/subimage.h b/src/resources/subimage.h index 95c5f4100..fc9ed5826 100644 --- a/src/resources/subimage.h +++ b/src/resources/subimage.h @@ -78,7 +78,7 @@ class SubImage final : public Image const int width, const int height) override final A_WARN_UNUSED; - int calcMemoryLocal() override; + int calcMemoryLocal() const override; #ifdef USE_OPENGL void decRef() override final; |