mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-09 10:29:45 +01:00
Add destructor for SoundTrack/MusicTrack (and explicitly define move constructor to prevent double-free)
This commit is contained in:
parent
c561cd9740
commit
2f760af439
3 changed files with 99 additions and 62 deletions
|
@ -6,34 +6,34 @@
|
||||||
|
|
||||||
void musicclass::init()
|
void musicclass::init()
|
||||||
{
|
{
|
||||||
soundTracks.push_back(SoundTrack( "sounds/jump.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/jump.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/jump2.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/jump2.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/hurt.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/hurt.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/souleyeminijingle.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/souleyeminijingle.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/coin.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/coin.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/save.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/save.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/crumble.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/crumble.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/vanish.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/vanish.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/blip.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/blip.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/preteleport.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/preteleport.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/teleport.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/teleport.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/crew1.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/crew1.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/crew2.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/crew2.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/crew3.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/crew3.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/crew4.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/crew4.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/crew5.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/crew5.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/crew6.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/crew6.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/terminal.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/terminal.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/gamesaved.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/gamesaved.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/crashing.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/crashing.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/blip2.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/blip2.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/countdown.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/countdown.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/go.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/go.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/crash.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/crash.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/combine.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/combine.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/newrecord.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/newrecord.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/trophy.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/trophy.wav" )));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/rescue.wav" ));
|
soundTracks.push_back(move(SoundTrack( "sounds/rescue.wav" )));
|
||||||
|
|
||||||
#ifdef VVV_COMPILEMUSIC
|
#ifdef VVV_COMPILEMUSIC
|
||||||
binaryBlob musicWriteBlob;
|
binaryBlob musicWriteBlob;
|
||||||
|
@ -71,67 +71,67 @@ void musicclass::init()
|
||||||
usingmmmmmm = true;
|
usingmmmmmm = true;
|
||||||
int index = musicReadBlob.getIndex("data/music/0levelcomplete.ogg");
|
int index = musicReadBlob.getIndex("data/music/0levelcomplete.ogg");
|
||||||
SDL_RWops *rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
SDL_RWops *rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/1pushingonwards.ogg");
|
index = musicReadBlob.getIndex("data/music/1pushingonwards.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/2positiveforce.ogg");
|
index = musicReadBlob.getIndex("data/music/2positiveforce.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/3potentialforanything.ogg");
|
index = musicReadBlob.getIndex("data/music/3potentialforanything.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/4passionforexploring.ogg");
|
index = musicReadBlob.getIndex("data/music/4passionforexploring.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/5intermission.ogg");
|
index = musicReadBlob.getIndex("data/music/5intermission.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/6presentingvvvvvv.ogg");
|
index = musicReadBlob.getIndex("data/music/6presentingvvvvvv.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/7gamecomplete.ogg");
|
index = musicReadBlob.getIndex("data/music/7gamecomplete.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/8predestinedfate.ogg");
|
index = musicReadBlob.getIndex("data/music/8predestinedfate.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/9positiveforcereversed.ogg");
|
index = musicReadBlob.getIndex("data/music/9positiveforcereversed.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/10popularpotpourri.ogg");
|
index = musicReadBlob.getIndex("data/music/10popularpotpourri.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/11pipedream.ogg");
|
index = musicReadBlob.getIndex("data/music/11pipedream.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/12pressurecooker.ogg");
|
index = musicReadBlob.getIndex("data/music/12pressurecooker.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/13pacedenergy.ogg");
|
index = musicReadBlob.getIndex("data/music/13pacedenergy.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/14piercingthesky.ogg");
|
index = musicReadBlob.getIndex("data/music/14piercingthesky.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/predestinedfatefinallevel.ogg");
|
index = musicReadBlob.getIndex("data/music/predestinedfatefinallevel.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
bool ohCrap = musicReadBlob.unPackBinary("vvvvvvmusic.vvv");
|
bool ohCrap = musicReadBlob.unPackBinary("vvvvvvmusic.vvv");
|
||||||
SDL_assert(ohCrap && "Music not found!");
|
SDL_assert(ohCrap && "Music not found!");
|
||||||
|
@ -139,67 +139,67 @@ void musicclass::init()
|
||||||
|
|
||||||
int index = musicReadBlob.getIndex("data/music/0levelcomplete.ogg");
|
int index = musicReadBlob.getIndex("data/music/0levelcomplete.ogg");
|
||||||
SDL_RWops *rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
SDL_RWops *rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/1pushingonwards.ogg");
|
index = musicReadBlob.getIndex("data/music/1pushingonwards.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/2positiveforce.ogg");
|
index = musicReadBlob.getIndex("data/music/2positiveforce.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/3potentialforanything.ogg");
|
index = musicReadBlob.getIndex("data/music/3potentialforanything.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/4passionforexploring.ogg");
|
index = musicReadBlob.getIndex("data/music/4passionforexploring.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/5intermission.ogg");
|
index = musicReadBlob.getIndex("data/music/5intermission.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/6presentingvvvvvv.ogg");
|
index = musicReadBlob.getIndex("data/music/6presentingvvvvvv.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/7gamecomplete.ogg");
|
index = musicReadBlob.getIndex("data/music/7gamecomplete.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/8predestinedfate.ogg");
|
index = musicReadBlob.getIndex("data/music/8predestinedfate.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/9positiveforcereversed.ogg");
|
index = musicReadBlob.getIndex("data/music/9positiveforcereversed.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/10popularpotpourri.ogg");
|
index = musicReadBlob.getIndex("data/music/10popularpotpourri.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/11pipedream.ogg");
|
index = musicReadBlob.getIndex("data/music/11pipedream.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/12pressurecooker.ogg");
|
index = musicReadBlob.getIndex("data/music/12pressurecooker.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/13pacedenergy.ogg");
|
index = musicReadBlob.getIndex("data/music/13pacedenergy.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/14piercingthesky.ogg");
|
index = musicReadBlob.getIndex("data/music/14piercingthesky.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
index = musicReadBlob.getIndex("data/music/predestinedfatefinallevel.ogg");
|
index = musicReadBlob.getIndex("data/music/predestinedfatefinallevel.ogg");
|
||||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
||||||
musicTracks.push_back(MusicTrack( rw ));
|
musicTracks.push_back(move(MusicTrack( rw )));
|
||||||
|
|
||||||
safeToProcessMusic= false;
|
safeToProcessMusic= false;
|
||||||
m_doFadeInVol = false;
|
m_doFadeInVol = false;
|
||||||
|
|
|
@ -24,6 +24,15 @@ MusicTrack::MusicTrack(SDL_RWops *rw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MusicTrack::MusicTrack(MusicTrack&& moved) : m_music(move(moved.m_music)), m_isValid(move(moved.m_isValid)) {
|
||||||
|
moved.m_isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MusicTrack::~MusicTrack() {
|
||||||
|
if (m_isValid) Mix_FreeMusic(m_music);
|
||||||
|
m_isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
SoundTrack::SoundTrack(const char* fileName)
|
SoundTrack::SoundTrack(const char* fileName)
|
||||||
{
|
{
|
||||||
sound = NULL;
|
sound = NULL;
|
||||||
|
@ -38,12 +47,22 @@ SoundTrack::SoundTrack(const char* fileName)
|
||||||
FILESYSTEM_freeMemory(&mem);
|
FILESYSTEM_freeMemory(&mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sound == NULL)
|
if (sound == NULL) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Unable to load WAV file: %s\n", Mix_GetError());
|
fprintf(stderr, "Unable to load WAV file: %s\n", Mix_GetError());
|
||||||
|
} else {
|
||||||
|
isValid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SoundTrack::SoundTrack(SoundTrack&& moved) : sound(move(moved.sound)), isValid(move(moved.isValid)) {
|
||||||
|
moved.isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundTrack::~SoundTrack() {
|
||||||
|
if (isValid) Mix_FreeChunk(sound);
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
SoundSystem::SoundSystem()
|
SoundSystem::SoundSystem()
|
||||||
{
|
{
|
||||||
int audio_rate = 44100;
|
int audio_rate = 44100;
|
||||||
|
|
|
@ -8,6 +8,9 @@ class MusicTrack
|
||||||
public:
|
public:
|
||||||
MusicTrack(const char* fileName);
|
MusicTrack(const char* fileName);
|
||||||
MusicTrack(SDL_RWops *rw);
|
MusicTrack(SDL_RWops *rw);
|
||||||
|
MusicTrack(MusicTrack&& moved);
|
||||||
|
MusicTrack& operator=(const MusicTrack& other) = default;
|
||||||
|
~MusicTrack();
|
||||||
Mix_Music *m_music;
|
Mix_Music *m_music;
|
||||||
bool m_isValid;
|
bool m_isValid;
|
||||||
};
|
};
|
||||||
|
@ -16,7 +19,12 @@ class SoundTrack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SoundTrack(const char* fileName);
|
SoundTrack(const char* fileName);
|
||||||
|
SoundTrack(SoundTrack&& moved);
|
||||||
|
SoundTrack& operator=(const SoundTrack& other) = default;
|
||||||
|
SoundTrack() = default;
|
||||||
|
~SoundTrack();
|
||||||
Mix_Chunk *sound;
|
Mix_Chunk *sound;
|
||||||
|
bool isValid = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SoundSystem
|
class SoundSystem
|
||||||
|
@ -26,4 +34,14 @@ public:
|
||||||
void playMusic(MusicTrack* music);
|
void playMusic(MusicTrack* music);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// polyfill of std::move
|
||||||
|
template<typename T> struct remove_reference {typedef T type;};
|
||||||
|
template<typename T> struct remove_reference<T&> {typedef T type;};
|
||||||
|
template<typename T> struct remove_reference<T&&> {typedef T type;};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename remove_reference<T>::type&& move(T&& t) {
|
||||||
|
return static_cast<typename remove_reference<T>::type&&>(t);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* SOUNDSYSTEM_H */
|
#endif /* SOUNDSYSTEM_H */
|
||||||
|
|
Loading…
Reference in a new issue