1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Move musicclass cleanup to separate function musicclass::destroy()

This removes the music cleanup code from musicclass::init(), and
requires that we also call destroy() in Graphics::reloadresources().

This is because we'll need to re-use the musicclass cleanup code
elsewhere, and we don't want to copy-paste the cleanup code. Or at
least, I don't (but I'm not a game dev, game devs copy-paste all the
friggin' time).
This commit is contained in:
Misa 2021-02-15 16:24:21 -08:00 committed by Ethan Lee
parent b3679ce1e5
commit 0ea1a0e28e
3 changed files with 23 additions and 18 deletions

View file

@ -3280,6 +3280,7 @@ void Graphics::reloadresources()
screenbuffer->LoadIcon();
}
music.destroy();
music.init();
}

View file

@ -33,24 +33,6 @@ musicclass::musicclass()
void musicclass::init()
{
for (size_t i = 0; i < soundTracks.size(); ++i)
{
Mix_FreeChunk(soundTracks[i].sound);
}
soundTracks.clear();
// Before we free all the music: stop playing music, else SDL2_mixer
// will call SDL_Delay() if we are fading, resulting in no-draw frames
Mix_HaltMusic();
for (size_t i = 0; i < musicTracks.size(); ++i)
{
Mix_FreeMusic(musicTracks[i].m_music);
}
musicTracks.clear();
musicReadBlob.clear();
soundTracks.push_back(SoundTrack( "sounds/jump.wav" ));
soundTracks.push_back(SoundTrack( "sounds/jump2.wav" ));
soundTracks.push_back(SoundTrack( "sounds/hurt.wav" ));
@ -165,6 +147,27 @@ static void songend()
music.currentsong = -1;
}
void musicclass::destroy()
{
for (size_t i = 0; i < soundTracks.size(); ++i)
{
Mix_FreeChunk(soundTracks[i].sound);
}
soundTracks.clear();
// Before we free all the music: stop playing music, else SDL2_mixer
// will call SDL_Delay() if we are fading, resulting in no-draw frames
Mix_HaltMusic();
for (size_t i = 0; i < musicTracks.size(); ++i)
{
Mix_FreeMusic(musicTracks[i].m_music);
}
musicTracks.clear();
musicReadBlob.clear();
}
void musicclass::play(int t, const double position_sec /*= 0.0*/, const int fadein_ms /*= 3000*/)
{
if (mmmmmm && usingmmmmmm)

View file

@ -13,6 +13,7 @@ class musicclass
public:
musicclass();
void init();
void destroy();
void play(int t, const double position_sec = 0.0, const int fadein_ms = 3000);
void resume(const int fadein_ms = 0);