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