summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-07-28 19:34:49 +0300
committerAndrei Karas <akaras@inbox.ru>2016-07-28 19:34:49 +0300
commit6b2264b7c5f2b1dba3360eb090ad1dd0052d7afb (patch)
tree16571caccd525266e2feda348d86adceaae830e5
parent35d30efe7605c24765f5fdbe73a22626dc7c17c1 (diff)
downloadplus-6b2264b7c5f2b1dba3360eb090ad1dd0052d7afb.tar.gz
plus-6b2264b7c5f2b1dba3360eb090ad1dd0052d7afb.tar.bz2
plus-6b2264b7c5f2b1dba3360eb090ad1dd0052d7afb.tar.xz
plus-6b2264b7c5f2b1dba3360eb090ad1dd0052d7afb.zip
Move sdlmusic load code into musicloader.
-rw-r--r--src/resources/loaders/musicloader.cpp22
-rw-r--r--src/resources/sdlmusic.cpp22
-rw-r--r--src/resources/sdlmusic.h22
3 files changed, 22 insertions, 44 deletions
diff --git a/src/resources/loaders/musicloader.cpp b/src/resources/loaders/musicloader.cpp
index 49ef40ef0..f9dd0fb17 100644
--- a/src/resources/loaders/musicloader.cpp
+++ b/src/resources/loaders/musicloader.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,30 @@ namespace
rl->path.c_str());
return nullptr;
}
- Resource *const res = rl->fun(rw, rl->path);
- return res;
+#ifdef USE_SDL2
+ if (Mix_Music *const music = Mix_LoadMUSType_RW(rw, MUS_OGG, 1))
+ {
+ return new SDLMusic(music, nullptr, rl->path);
+ }
+#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, rl->path);
+ }
+#endif
+ else
+ {
+ logger->log("Error, failed to load music: %s", Mix_GetError());
+ return nullptr;
+ }
}
};
} // namespace
SDLMusic *Loader::getMusic(const std::string &idPath)
{
- ResourceLoader rl = { idPath, &SDLMusic::load };
+ ResourceLoader rl = { idPath };
return static_cast<SDLMusic*>(resourceManager->get(
idPath, ResourceLoader::load, &rl));
}
diff --git a/src/resources/sdlmusic.cpp b/src/resources/sdlmusic.cpp
index 5834e8b49..7ff8537e9 100644
--- a/src/resources/sdlmusic.cpp
+++ b/src/resources/sdlmusic.cpp
@@ -48,28 +48,6 @@ SDLMusic::~SDLMusic()
#endif
}
-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, 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, name);
- }
-#endif
- else
- {
- logger->log("Error, failed to load music: %s", Mix_GetError());
- return nullptr;
- }
-}
-
bool SDLMusic::play(const int loops, const int fadeIn)
{
if (fadeIn > 0)
diff --git a/src/resources/sdlmusic.h b/src/resources/sdlmusic.h
index 007a6acf1..86eacc044 100644
--- a/src/resources/sdlmusic.h
+++ b/src/resources/sdlmusic.h
@@ -42,6 +42,10 @@ class SDLMusic final : public Resource
mRw(nullptr)
{ }
+ SDLMusic(Mix_Music *const music,
+ SDL_RWops *const rw,
+ const std::string &name);
+
A_DELETE_COPY(SDLMusic)
/**
@@ -50,17 +54,6 @@ class SDLMusic final : public Resource
~SDLMusic();
/**
- * Loads a music from a buffer in memory.
- *
- * @param rw The SDL_RWops to load the music 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) A_WARN_UNUSED;
-
- /**
* Plays the music.
*
* @param loops Number of times to repeat the playback (-1 means
@@ -78,13 +71,6 @@ class SDLMusic final : public Resource
{ return mName; }
protected:
- /**
- * Constructor.
- */
- SDLMusic(Mix_Music *const music,
- SDL_RWops *const rw,
- const std::string &name);
-
std::string mName;
Mix_Music *mMusic;
SDL_RWops *mRw;