summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-04-29 20:26:10 +0300
committerAndrei Karas <akaras@inbox.ru>2016-04-29 20:26:10 +0300
commit3fca67011281a84d04b0b07dfea1206e964e42e9 (patch)
tree34ec295e5ad99f25596a4b19a4a158f3dc96b82c
parentda8550ca0017883f20fcefb6dc47f082d30b4b86 (diff)
downloadmv-3fca67011281a84d04b0b07dfea1206e964e42e9.tar.gz
mv-3fca67011281a84d04b0b07dfea1206e964e42e9.tar.bz2
mv-3fca67011281a84d04b0b07dfea1206e964e42e9.tar.xz
mv-3fca67011281a84d04b0b07dfea1206e964e42e9.zip
Add partial support for memory counting in Map.
-rw-r--r--src/resources/map/map.cpp51
-rw-r--r--src/resources/map/map.h21
-rw-r--r--src/resources/mapreader.cpp8
3 files changed, 73 insertions, 7 deletions
diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp
index 43ed91daf..e958068f2 100644
--- a/src/resources/map/map.cpp
+++ b/src/resources/map/map.cpp
@@ -82,8 +82,11 @@ class ActorFunctuator final
}
} actorCompare;
-Map::Map(const int width, const int height,
- const int tileWidth, const int tileHeight) :
+Map::Map(const std::string &name,
+ const int width,
+ const int height,
+ const int tileWidth,
+ const int tileHeight) :
Properties(),
mWidth(width), mHeight(height),
mTileWidth(tileWidth), mTileHeight(tileHeight),
@@ -106,6 +109,7 @@ Map::Map(const int width, const int height,
mParticleEffects(),
mMapPortals(),
mTileAnimations(),
+ mName(name),
mOverlayDetail(config.getIntValue("OverlayDetail")),
mOpacity(config.getFloatValue("guialpha")),
#ifdef USE_OPENGL
@@ -1690,3 +1694,46 @@ void Map::updateConditionLayers() restrict2
mWidth, mHeight);
}
}
+
+int Map::calcMemoryLocal() const
+{
+ return sizeof(Map) +
+ mName.capacity() +
+ sizeof(MetaTile) * mWidth * mHeight +
+ sizeof(MapLayer*) * (mLayers.capacity() +
+ mDrawUnderLayers.capacity() +
+ mDrawOverLayers.capacity()) +
+ sizeof(Tileset*) * mTilesets.capacity() +
+ sizeof(Actor*) * mActors.size() +
+ sizeof(AmbientLayer*) * (mBackgrounds.capacity()
+ + mForegrounds.capacity()) +
+ sizeof(ParticleEffectData) * mParticleEffects.capacity() +
+ sizeof(MapItem) * mMapPortals.capacity() +
+ (sizeof(TileAnimation) + sizeof(int)) * mTileAnimations.size() +
+ sizeof(Tileset*) * mIndexedTilesetsSize;
+}
+
+int Map::calcMemoryChilds(const int level) const
+{
+ int sz = 0;
+
+ if (mWalkLayer)
+ sz += mWalkLayer->calcMemory(level + 1);
+ FOR_EACH (LayersCIter, it, mLayers)
+ {
+ sz += (*it)->calcMemory(level + 1);
+ }
+ FOR_EACH (Tilesets::const_iterator, it, mTilesets)
+ {
+ sz += (*it)->calcMemory(level + 1);
+ }
+ // +++ need calc mBackgrounds
+ // +++ need calc mForegrounds
+ if (mSpecialLayer)
+ mSpecialLayer->calcMemory(level + 1);
+ if (mTempLayer)
+ mTempLayer->calcMemory(level + 1);
+ // +++ need calc mObjects
+ // +++ need calc mHeights
+ return sz;
+}
diff --git a/src/resources/map/map.h b/src/resources/map/map.h
index 4a0f71e82..7320bb8d5 100644
--- a/src/resources/map/map.h
+++ b/src/resources/map/map.h
@@ -33,6 +33,8 @@
#include "enums/resources/map/blocktype.h"
#include "enums/resources/map/maptype.h"
+#include "resources/memorycounter.h"
+
#include "resources/map/properties.h"
#include "listeners/configlistener.h"
@@ -63,7 +65,9 @@ typedef AmbientLayerVector::iterator AmbientLayerVectorIter;
/**
* A tile map.
*/
-class Map final : public Properties, public ConfigListener
+class Map final : public Properties,
+ public ConfigListener,
+ public MemoryCounter
{
public:
enum CollisionTypes
@@ -79,8 +83,11 @@ class Map final : public Properties, public ConfigListener
/**
* Constructor, taking map and tile size as parameters.
*/
- Map(const int width, const int height,
- const int tileWidth, const int tileHeight);
+ Map(const std::string &name,
+ const int width,
+ const int height,
+ const int tileWidth,
+ const int tileHeight);
A_DELETE_COPY(Map)
@@ -361,6 +368,13 @@ class Map final : public Properties, public ConfigListener
void updateConditionLayers() restrict2;
+ int calcMemoryLocal() const override final;
+
+ int calcMemoryChilds(const int level) const override final;
+
+ std::string getCounterName() const override final
+ { return mName; }
+
protected:
friend class Actor;
friend class Minimap;
@@ -456,6 +470,7 @@ class Map final : public Properties, public ConfigListener
std::map<int, TileAnimation*> mTileAnimations;
+ std::string mName;
int mOverlayDetail;
float mOpacity;
const RenderType mOpenGL;
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index f37792fa2..497817a7d 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -333,7 +333,9 @@ Map *MapReader::readMap(XmlNodePtrConst node, const std::string &path)
logger->log("loading replace layer list");
loadLayers(path + "_replace.d");
- Map *const map = new Map(w, h, tilew, tileh);
+ Map *const map = new Map(path,
+ w, h,
+ tilew, tileh);
const std::string fileName = path.substr(path.rfind("/") + 1);
map->setProperty("shortName", fileName);
@@ -1173,7 +1175,9 @@ Map *MapReader::createEmptyMap(const std::string &restrict filename,
const std::string &restrict realFilename)
{
logger->log1("Creating empty map");
- Map *const map = new Map(300, 300, mapTileSize, mapTileSize);
+ Map *const map = new Map("empty map",
+ 300, 300,
+ mapTileSize, mapTileSize);
map->setProperty("_filename", realFilename);
map->setProperty("_realfilename", filename);
updateMusic(map);