summaryrefslogtreecommitdiff
path: root/src/resources/music.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-09 03:34:45 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-09 03:34:45 +0000
commit8bde9095c5840b8d62ebafe11beaed98877d6ac2 (patch)
tree537f717a339d1247cae222eb7a354ea5dbe8babf /src/resources/music.cpp
parenta246c08cef5e4d598fc07a681eb971bfbcf01519 (diff)
downloadMana-8bde9095c5840b8d62ebafe11beaed98877d6ac2.tar.gz
Mana-8bde9095c5840b8d62ebafe11beaed98877d6ac2.tar.bz2
Mana-8bde9095c5840b8d62ebafe11beaed98877d6ac2.tar.xz
Mana-8bde9095c5840b8d62ebafe11beaed98877d6ac2.zip
* 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.
Diffstat (limited to 'src/resources/music.cpp')
-rw-r--r--src/resources/music.cpp41
1 files changed, 22 insertions, 19 deletions
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);
+ }
}