diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-19 17:46:46 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-19 17:46:46 +0000 |
commit | 41cf359468d6379bc0e033bee9ac148d1b9255dd (patch) | |
tree | d351692d76e861607fd504366ae22374613b0fec /src/resources/music.cpp | |
parent | c3e36e443698b001e98219e48cc97e259ada0a1d (diff) | |
download | mana-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.cpp | 23 |
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 |