summaryrefslogtreecommitdiff
path: root/src/resources/music.cpp
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-10-19 17:46:46 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-10-19 17:46:46 +0000
commit41cf359468d6379bc0e033bee9ac148d1b9255dd (patch)
treed351692d76e861607fd504366ae22374613b0fec /src/resources/music.cpp
parentc3e36e443698b001e98219e48cc97e259ada0a1d (diff)
downloadmana-41cf359468d6379bc0e033bee9ac148d1b9255dd.tar.gz
mana-41cf359468d6379bc0e033bee9ac148d1b9255dd.tar.bz2
mana-41cf359468d6379bc0e033bee9ac148d1b9255dd.tar.xz
mana-41cf359468d6379bc0e033bee9ac148d1b9255dd.zip
Factored code between resource handlers. Implemented failure-friendly sprite loader.
Diffstat (limited to 'src/resources/music.cpp')
-rw-r--r--src/resources/music.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/resources/music.cpp b/src/resources/music.cpp
index 09e2752a..161d8b01 100644
--- a/src/resources/music.cpp
+++ b/src/resources/music.cpp
@@ -23,8 +23,9 @@
#include "music.h"
-Music::Music(const std::string &idPath, Mix_Chunk *music):
- Resource(idPath),
+#include "../log.h"
+
+Music::Music(Mix_Chunk *music):
mChunk(music),
mChannel(-1)
{
@@ -36,20 +37,24 @@ Music::~Music()
Mix_FreeChunk(mChunk);
}
-Music*
-Music::load(void *buffer, unsigned int bufferSize, const std::string &idPath)
+Resource *Music::load(void *buffer, unsigned bufferSize)
{
// Load the raw file data from the buffer in an RWops structure
SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
// Use Mix_LoadMUS to load the raw music data
//Mix_Music* music = Mix_LoadMUS_RW(rw); Need to be implemeted
- Mix_Chunk *tmpMusic = Mix_LoadWAV_RW(rw, 0);
-
- // Now free the SDL_RWops data
- SDL_FreeRW(rw);
+ Mix_Chunk *tmpMusic = Mix_LoadWAV_RW(rw, 1);
- return new Music(idPath, tmpMusic);
+ if (tmpMusic)
+ {
+ return new Music(tmpMusic);
+ }
+ else
+ {
+ logger->log("Error, failed to load music: %s", Mix_GetError());
+ return NULL;
+ }
}
bool