summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-07-28 19:54:02 +0300
committerAndrei Karas <akaras@inbox.ru>2016-07-28 19:54:02 +0300
commit442a2dd0a4417182cbdd9f9fefb45bda4914e3d7 (patch)
tree9208c3b353bfd89009e35f21fa4c29670bfc1579
parent6b2264b7c5f2b1dba3360eb090ad1dd0052d7afb (diff)
downloadplus-442a2dd0a4417182cbdd9f9fefb45bda4914e3d7.tar.gz
plus-442a2dd0a4417182cbdd9f9fefb45bda4914e3d7.tar.bz2
plus-442a2dd0a4417182cbdd9f9fefb45bda4914e3d7.tar.xz
plus-442a2dd0a4417182cbdd9f9fefb45bda4914e3d7.zip
Move soundeffect load code into soundloader.
-rw-r--r--src/resources/loaders/soundloader.cpp18
-rw-r--r--src/resources/soundeffect.cpp19
-rw-r--r--src/resources/soundeffect.h31
3 files changed, 24 insertions, 44 deletions
diff --git a/src/resources/loaders/soundloader.cpp b/src/resources/loaders/soundloader.cpp
index b39c5fcbe..8c325db7c 100644
--- a/src/resources/loaders/soundloader.cpp
+++ b/src/resources/loaders/soundloader.cpp
@@ -36,7 +36,6 @@ namespace
struct ResourceLoader final
{
std::string path;
- ResourceManager::loader fun;
static Resource *load(const void *const v)
{
@@ -51,15 +50,26 @@ namespace
rl->path.c_str());
return nullptr;
}
- Resource *const res = rl->fun(rw, rl->path);
- return res;
+ // Load the music data and free the RWops structure
+ Mix_Chunk *const tmpSoundEffect = Mix_LoadWAV_RW(rw, 1);
+
+ if (tmpSoundEffect)
+ {
+ return new SoundEffect(tmpSoundEffect, rl->path);
+ }
+ else
+ {
+ reportAlways("Error, failed to load sound effect: %s",
+ Mix_GetError());
+ return nullptr;
+ }
}
};
} // namespace
SoundEffect *Loader::getSoundEffect(const std::string &idPath)
{
- ResourceLoader rl = { idPath, &SoundEffect::load };
+ ResourceLoader rl = { idPath };
return static_cast<SoundEffect*>(resourceManager->get(
idPath, ResourceLoader::load, &rl));
}
diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp
index 4491e993a..1b1026783 100644
--- a/src/resources/soundeffect.cpp
+++ b/src/resources/soundeffect.cpp
@@ -31,25 +31,6 @@ SoundEffect::~SoundEffect()
Mix_FreeChunk(mChunk);
}
-Resource *SoundEffect::load(SDL_RWops *const rw,
- const std::string &name)
-{
- if (!rw)
- return nullptr;
- // Load the music data and free the RWops structure
- Mix_Chunk *const tmpSoundEffect = Mix_LoadWAV_RW(rw, 1);
-
- if (tmpSoundEffect)
- {
- return new SoundEffect(tmpSoundEffect, name);
- }
- else
- {
- logger->log("Error, failed to load sound effect: %s", Mix_GetError());
- return nullptr;
- }
-}
-
bool SoundEffect::play(const int loops, const int volume,
const int channel) const
{
diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h
index 20861f218..bc0a353f6 100644
--- a/src/resources/soundeffect.h
+++ b/src/resources/soundeffect.h
@@ -35,6 +35,16 @@
class SoundEffect final : public Resource
{
public:
+ /**
+ * Constructor.
+ */
+ SoundEffect(Mix_Chunk *const soundEffect,
+ const std::string &name) :
+ Resource(),
+ mName(name),
+ mChunk(soundEffect)
+ { }
+
A_DELETE_COPY(SoundEffect)
/**
@@ -43,17 +53,6 @@ class SoundEffect final : public Resource
~SoundEffect();
/**
- * Loads a sample from a buffer in memory.
- *
- * @param rw The SDL_RWops to load the sample data from.
- *
- * @return <code>NULL</code> if the an error occurred, a valid pointer
- * otherwise.
- */
- static Resource *load(SDL_RWops *const rw,
- const std::string &name);
-
- /**
* Plays the sample.
*
* @param loops Number of times to repeat the playback.
@@ -72,16 +71,6 @@ class SoundEffect final : public Resource
{ return mName; }
protected:
- /**
- * Constructor.
- */
- SoundEffect(Mix_Chunk *const soundEffect,
- const std::string &name) :
- Resource(),
- mName(name),
- mChunk(soundEffect)
- { }
-
std::string mName;
Mix_Chunk *mChunk;
};