From 6b2264b7c5f2b1dba3360eb090ad1dd0052d7afb Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 28 Jul 2016 19:34:49 +0300 Subject: Move sdlmusic load code into musicloader. --- src/resources/loaders/musicloader.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/resources/loaders') 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(resourceManager->get( idPath, ResourceLoader::load, &rl)); } -- cgit v1.2.3-60-g2f50