From 07675230038a24dd251581591379c8fe5cc7bfd1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 26 Apr 2016 20:11:07 +0300 Subject: Add memory count functions into MapLayer and SpecailLayer. Also change all memory count functions into const methods. --- src/resources/map/maplayer.cpp | 17 +++++++++++++++++ src/resources/map/maplayer.h | 8 +++++++- src/resources/map/speciallayer.cpp | 6 ++++++ src/resources/map/speciallayer.h | 6 +++++- src/resources/map/tileset.h | 2 +- src/resources/map/walklayer.cpp | 2 +- src/resources/map/walklayer.h | 2 +- 7 files changed, 38 insertions(+), 5 deletions(-) (limited to 'src/resources/map') 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; -- cgit v1.2.3-70-g09d2