From 8bde9095c5840b8d62ebafe11beaed98877d6ac2 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 9 Oct 2005 03:34:45 +0000 Subject: * Made Sprite into an interface implemented by both FloorItem and Being, which hook themselves into the map on construction. The improved fringe layer is working as expected now. * Made sure TMW compiles without warnings even when using "-Wconversion -Wshadow -Wcast-qual -Wwrite-strings -ansi -pedantic", lots of cleanups. * Added two new small tilesets that contain the desert tiles that are twice and three times the height of a normal tile. One well in new_3-1 has been converted to use the new double tiles for testing purposes. --- src/resources/music.cpp | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/resources/music.cpp') diff --git a/src/resources/music.cpp b/src/resources/music.cpp index ba9f6df7..09e2752a 100644 --- a/src/resources/music.cpp +++ b/src/resources/music.cpp @@ -24,19 +24,20 @@ #include "music.h" Music::Music(const std::string &idPath, Mix_Chunk *music): - Resource(idPath), music(music) + Resource(idPath), + mChunk(music), + mChannel(-1) { - channel = -1; } Music::~Music() { //Mix_FreeMusic(music); - Mix_FreeChunk(music); - music = NULL; + Mix_FreeChunk(mChunk); } -Music* Music::load(void* buffer, unsigned int bufferSize, const std::string &idPath) +Music* +Music::load(void *buffer, unsigned int bufferSize, const std::string &idPath) { // Load the raw file data from the buffer in an RWops structure SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize); @@ -44,39 +45,41 @@ Music* Music::load(void* buffer, unsigned int bufferSize, const std::string &idP // 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); return new Music(idPath, tmpMusic); } -bool Music::play(int loops) +bool +Music::play(int loops) { /* * Warning: loops should be always set to -1 (infinite) with current * implementation to avoid halting the playback of other samples */ - + /*if (Mix_PlayMusic(music, loops)) return true;*/ - Mix_VolumeChunk(music, 120); - channel = Mix_PlayChannel(-1, music, loops); - if (channel != -1) - return true; - return false; + Mix_VolumeChunk(mChunk, 120); + mChannel = Mix_PlayChannel(-1, mChunk, loops); + + return mChannel != -1; } -bool Music::stop() +void +Music::stop() { /* * Warning: very dungerous trick, it could try to stop channels occupied * by samples rather than the current music file */ - + //Mix_HaltMusic(); - if (channel != -1) - Mix_HaltChannel(channel); - // Never fails - return true; + + if (mChannel != -1) + { + Mix_HaltChannel(mChannel); + } } -- cgit v1.2.3-70-g09d2