diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-04-29 03:41:11 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-04-29 03:41:11 +0300 |
commit | 7c020abf511236e2c56fa1c6b6c1b8f248aa8582 (patch) | |
tree | aae0dbb1e1203ea33d1dbf1ff4185268d02a1943 /src/resources | |
parent | fdfd38278cba5fa37d203d0d29b4981e400a529a (diff) | |
download | manaverse-7c020abf511236e2c56fa1c6b6c1b8f248aa8582.tar.gz manaverse-7c020abf511236e2c56fa1c6b6c1b8f248aa8582.tar.bz2 manaverse-7c020abf511236e2c56fa1c6b6c1b8f248aa8582.tar.xz manaverse-7c020abf511236e2c56fa1c6b6c1b8f248aa8582.zip |
Add name into memory usage tree for SDLMusic and SoundEffect.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/resourcemanager.cpp | 4 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 3 | ||||
-rw-r--r-- | src/resources/sdlmusic.cpp | 12 | ||||
-rw-r--r-- | src/resources/sdlmusic.h | 12 | ||||
-rw-r--r-- | src/resources/soundeffect.cpp | 5 | ||||
-rw-r--r-- | src/resources/soundeffect.h | 11 |
6 files changed, 34 insertions, 13 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 0f3f10f76..2b1c3450d 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -501,7 +501,7 @@ Resource *ResourceManager::get(const std::string &idPath, logger->log("Error loading image: " + idPath); } #else - Resource *resource = fun(data); + Resource *resource = fun(data, idPath); if (resource) { @@ -537,7 +537,7 @@ struct ResourceLoader final SDL_RWops *const rw = MPHYSFSRWOPS_openRead(rl->path.c_str()); if (!rw) return nullptr; - Resource *const res = rl->fun(rw); + Resource *const res = rl->fun(rw, rl->path); return res; } }; diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 92454c0c7..eeda43b33 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -54,7 +54,8 @@ class ResourceManager final : public MemoryCounter friend class Resource; public: - typedef Resource *(*loader)(SDL_RWops *rw); + typedef Resource *(*loader)(SDL_RWops *rw, + const std::string &name); typedef Resource *(&generator)(const void *const data); ResourceManager(); diff --git a/src/resources/sdlmusic.cpp b/src/resources/sdlmusic.cpp index ddcd2366f..0360ef37b 100644 --- a/src/resources/sdlmusic.cpp +++ b/src/resources/sdlmusic.cpp @@ -26,8 +26,11 @@ #include "debug.h" -SDLMusic::SDLMusic(Mix_Music *const music, SDL_RWops *const rw) : +SDLMusic::SDLMusic(Mix_Music *const music, + SDL_RWops *const rw, + const std::string &name) : Resource(), + mName(name), mMusic(music), mRw(rw) { @@ -45,18 +48,19 @@ SDLMusic::~SDLMusic() #endif } -Resource *SDLMusic::load(SDL_RWops *const rw) +Resource *SDLMusic::load(SDL_RWops *const rw, + const std::string &name) { #ifdef USE_SDL2 if (Mix_Music *const music = Mix_LoadMUSType_RW(rw, MUS_OGG, 1)) { - return new SDLMusic(music, nullptr); + return new SDLMusic(music, nullptr, name); } #else // Mix_LoadMUSType_RW was added without version changed in SDL1.2 :( if (Mix_Music *const music = Mix_LoadMUS_RW(rw)) { - return new SDLMusic(music, rw); + return new SDLMusic(music, rw, name); } #endif else diff --git a/src/resources/sdlmusic.h b/src/resources/sdlmusic.h index 6ba42796b..007a6acf1 100644 --- a/src/resources/sdlmusic.h +++ b/src/resources/sdlmusic.h @@ -37,6 +37,7 @@ class SDLMusic final : public Resource public: SDLMusic() : Resource(), + mName(), mMusic(nullptr), mRw(nullptr) { } @@ -56,7 +57,8 @@ class SDLMusic final : public Resource * @return <code>NULL</code> if the an error occurred, a valid pointer * otherwise. */ - static Resource *load(SDL_RWops *const rw) A_WARN_UNUSED; + static Resource *load(SDL_RWops *const rw, + const std::string &name) A_WARN_UNUSED; /** * Plays the music. @@ -72,12 +74,18 @@ class SDLMusic final : public Resource int calcMemoryLocal() const override final; + std::string getCounterName() const override final + { return mName; } + protected: /** * Constructor. */ - SDLMusic(Mix_Music *const music, SDL_RWops *const rw); + SDLMusic(Mix_Music *const music, + SDL_RWops *const rw, + const std::string &name); + std::string mName; Mix_Music *mMusic; SDL_RWops *mRw; }; diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index 9cf511965..f817f9c44 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -31,7 +31,8 @@ SoundEffect::~SoundEffect() Mix_FreeChunk(mChunk); } -Resource *SoundEffect::load(SDL_RWops *const rw) +Resource *SoundEffect::load(SDL_RWops *const rw, + const std::string &name) { if (!rw) return nullptr; @@ -40,7 +41,7 @@ Resource *SoundEffect::load(SDL_RWops *const rw) if (tmpSoundEffect) { - return new SoundEffect(tmpSoundEffect); + return new SoundEffect(tmpSoundEffect, name); } else { diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index a8e11ca6b..20861f218 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -50,7 +50,8 @@ class SoundEffect final : public Resource * @return <code>NULL</code> if the an error occurred, a valid pointer * otherwise. */ - static Resource *load(SDL_RWops *const rw); + static Resource *load(SDL_RWops *const rw, + const std::string &name); /** * Plays the sample. @@ -67,15 +68,21 @@ class SoundEffect final : public Resource int calcMemoryLocal() const override final; + std::string getCounterName() const override final + { return mName; } + protected: /** * Constructor. */ - explicit SoundEffect(Mix_Chunk *const soundEffect) : + SoundEffect(Mix_Chunk *const soundEffect, + const std::string &name) : Resource(), + mName(name), mChunk(soundEffect) { } + std::string mName; Mix_Chunk *mChunk; }; |