summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-04-26 01:24:16 +0300
committerAndrei Karas <akaras@inbox.ru>2016-04-26 01:24:16 +0300
commitec6bfe238af2f846a5948e95b1d725cf9abe9afb (patch)
tree0be19bc199cd66bd6949befe86c844dbad62de3b /src
parent81dca73da50d8f421a74993de8cd5a9d61ef1e2a (diff)
downloadmanaverse-ec6bfe238af2f846a5948e95b1d725cf9abe9afb.tar.gz
manaverse-ec6bfe238af2f846a5948e95b1d725cf9abe9afb.tar.bz2
manaverse-ec6bfe238af2f846a5948e95b1d725cf9abe9afb.tar.xz
manaverse-ec6bfe238af2f846a5948e95b1d725cf9abe9afb.zip
Add memory count functions into Action and Animation.
Diffstat (limited to 'src')
-rw-r--r--src/resources/action.cpp18
-rw-r--r--src/resources/action.h8
-rw-r--r--src/resources/animation/animation.cpp12
-rw-r--r--src/resources/animation/animation.h5
-rw-r--r--src/resources/memorycounter.h2
-rw-r--r--src/resources/sprite/spritedef.cpp37
-rw-r--r--src/resources/sprite/spritedef.h4
7 files changed, 82 insertions, 4 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp
index 9def0fc41..a8bf83673 100644
--- a/src/resources/action.cpp
+++ b/src/resources/action.cpp
@@ -29,6 +29,7 @@
#include "debug.h"
Action::Action() noexcept :
+ MemoryCounter(),
mAnimations(),
mNumber(100)
{
@@ -83,3 +84,20 @@ void Action::setLastFrameDelay(const int delay) noexcept
animation->setLastFrameDelay(delay);
}
}
+
+int Action::calcMemoryLocal()
+{
+ return sizeof(Action);
+}
+
+int Action::calcMemoryChilds(const int level)
+{
+ int sz = 0;
+ FOR_EACH (AnimationIter, it, mAnimations)
+ {
+ sz += sizeof(SpriteDirection::Type);
+ Animation *const animation = (*it).second;
+ sz += animation->calcMemory(level + 1);
+ }
+ return sz;
+}
diff --git a/src/resources/action.h b/src/resources/action.h
index 82b5d8052..0f6288815 100644
--- a/src/resources/action.h
+++ b/src/resources/action.h
@@ -25,6 +25,8 @@
#include "enums/resources/spritedirection.h"
+#include "resources/memorycounter.h"
+
#include <map>
#include "localconsts.h"
@@ -34,7 +36,7 @@ class Animation;
/**
* An action consists of several animations, one for each direction.
*/
-class Action final
+class Action final : public MemoryCounter
{
public:
Action() noexcept;
@@ -57,6 +59,10 @@ class Action final
void setLastFrameDelay(const int delay) noexcept;
+ int calcMemoryLocal() override final;
+
+ int calcMemoryChilds(const int level) override final;
+
protected:
typedef std::map<SpriteDirection::Type, Animation*> Animations;
typedef Animations::iterator AnimationIter;
diff --git a/src/resources/animation/animation.cpp b/src/resources/animation/animation.cpp
index ac7e4a146..e52b55737 100644
--- a/src/resources/animation/animation.cpp
+++ b/src/resources/animation/animation.cpp
@@ -86,3 +86,15 @@ void Animation::setLastFrameDelay(const int delay) noexcept
}
}
}
+
+int Animation::calcMemoryLocal()
+{
+ int sz = sizeof(Animation);
+ FOR_EACH (FramesIter, it, mFrames)
+ {
+ Frame &frame = *it;
+ sz += sizeof(Frame) +
+ frame.nextAction.capacity();
+ }
+ return sz;
+}
diff --git a/src/resources/animation/animation.h b/src/resources/animation/animation.h
index 765e687d4..dc44a3f0d 100644
--- a/src/resources/animation/animation.h
+++ b/src/resources/animation/animation.h
@@ -24,6 +24,7 @@
#define RESOURCES_ANIMATION_ANIMATION_H
#include "resources/frame.h"
+#include "resources/memorycounter.h"
#include <vector>
@@ -35,7 +36,7 @@ class Image;
* An animation consists of several frames, each with their own delay and
* offset.
*/
-class Animation final
+class Animation final : public MemoryCounter
{
friend class AnimatedSprite;
friend class ParticleEmitter;
@@ -82,6 +83,8 @@ class Animation final
{ return mFrames; }
#endif
+ int calcMemoryLocal() override final;
+
/**
* Determines whether the given animation frame is a terminator.
*/
diff --git a/src/resources/memorycounter.h b/src/resources/memorycounter.h
index 5f1d6cc23..cb9d62583 100644
--- a/src/resources/memorycounter.h
+++ b/src/resources/memorycounter.h
@@ -28,8 +28,6 @@ class MemoryCounter notfinal
public:
MemoryCounter();
- A_DELETE_COPY(MemoryCounter)
-
virtual ~MemoryCounter()
{ }
diff --git a/src/resources/sprite/spritedef.cpp b/src/resources/sprite/spritedef.cpp
index d157028ef..ba3abaec9 100644
--- a/src/resources/sprite/spritedef.cpp
+++ b/src/resources/sprite/spritedef.cpp
@@ -593,3 +593,40 @@ bool SpriteDef::addSequence(const int start,
}
return false;
}
+
+int SpriteDef::calcMemoryLocal()
+{
+ int sz = sizeof(SpriteDef) +
+ sizeof(ImageSets) +
+ sizeof(Actions) +
+ sizeof(std::set<std::string>) +
+ Resource::calcMemoryLocal();
+ FOR_EACH (std::set<std::string>::const_iterator, it, mProcessedFiles)
+ {
+ sz += (*it).capacity();
+ }
+ return sz;
+}
+
+int SpriteDef::calcMemoryChilds(const int level)
+{
+ int sz = 0;
+ FOR_EACH (ImageSets::iterator, it, mImageSets)
+ {
+ sz += (*it).first.capacity();
+ ImageSet *const imageSet = (*it).second;
+ sz += imageSet->calcMemory(level + 1);
+ }
+ FOR_EACH (ActionsIter, it, mActions)
+ {
+ sz += sizeof(unsigned);
+ ActionMap *const actionMap = (*it).second;
+ FOR_EACHP (ActionMap::iterator, it2, actionMap)
+ {
+ sz += (*it2).first.capacity();
+ Action *const action = (*it2).second;
+ sz += action->calcMemory(level + 1);
+ }
+ }
+ return sz;
+}
diff --git a/src/resources/sprite/spritedef.h b/src/resources/sprite/spritedef.h
index c7a86f1e6..aea602cee 100644
--- a/src/resources/sprite/spritedef.h
+++ b/src/resources/sprite/spritedef.h
@@ -68,6 +68,10 @@ class SpriteDef final : public Resource
void addAction(const unsigned hp, const std::string &name,
Action *const action);
+ int calcMemoryLocal() override final;
+
+ int calcMemoryChilds(const int level) override final;
+
static bool addSequence(const int start,
const int end,
const int delay,