summaryrefslogtreecommitdiff
path: root/src/sound.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound.cxx')
-rw-r--r--src/sound.cxx61
1 files changed, 46 insertions, 15 deletions
diff --git a/src/sound.cxx b/src/sound.cxx
index 2969914..0a899bc 100644
--- a/src/sound.cxx
+++ b/src/sound.cxx
@@ -1,7 +1,7 @@
/*
* This file is part of the planetblupi source code
* Copyright (C) 1997, Daniel Roux & EPSITEC SA
- * Copyright (C) 2017, Mathieu Schroeter
+ * Copyright (C) 2017-2018, Mathieu Schroeter
* http://epsitec.ch; http://www.blupi.org; http://github.com/blupi-games
*
* This program is free software: you can redistribute it and/or modify
@@ -23,8 +23,30 @@
#include "def.h"
#include "event.h"
#include "misc.h"
+#include "platform.h"
#include "sound.h"
+void
+CSound::StopSound (bool immediat, Sint32 rank)
+{
+ Sounds stopCh;
+
+ if (rank >= 0 && rank < MAXBLUPI)
+ {
+ stopCh = m_channelBlupi[rank];
+ if (stopCh >= 0 && m_lpSDL[stopCh] != nullptr)
+ {
+ /* FIXME: add support of fade out with emscripten */
+ if (immediat || Platform::getType () == Platform::Type::JS)
+ Mix_HaltChannel (stopCh + 1);
+ else
+ Mix_FadeOutChannel (stopCh + 1, 500);
+ }
+
+ m_channelBlupi[rank] = SOUND_NONE;
+ }
+}
+
// Stops all sounds.
bool
@@ -40,7 +62,8 @@ CSound::StopAllSounds (bool immediat, const std::set<Sint32> * except)
if (Mix_Playing (i + 1) == SDL_TRUE)
{
- if (immediat)
+ /* FIXME: add support of fade out with emscripten */
+ if (immediat || Platform::getType () == Platform::Type::JS)
Mix_HaltChannel (i + 1);
else
Mix_FadeOutChannel (i + 1, 500);
@@ -176,7 +199,12 @@ CSound::Cache (Sint32 channel, const std::string & pFilename)
if (m_lpSDL[channel] && m_sndFiles[channel] == sound)
return true;
- Mix_Chunk * chunk = Mix_LoadWAV (file.c_str ());
+ Mix_Chunk * chunk = nullptr;
+ std::string absolute;
+
+ if (FileExists (file, absolute, Location::LOCATION_ABSOLUTE))
+ chunk = Mix_LoadWAV (file.c_str ());
+
if (!chunk)
{
if (GetLocale () != "en")
@@ -262,18 +290,18 @@ CSound::Play (Sint32 channel, Sint32 volume, Uint8 panLeft, Uint8 panRight)
// �ventuellement stopper le dernier son en cours !
bool
-CSound::PlayImage (Sounds channel, Point pos, Sint32 rank)
+CSound::PlayImage (Sounds channel, Point pos, Sint32 rank, bool stop)
{
Sint32 volumex, volumey, volume;
- Sounds stopCh;
if (rank >= 0 && rank < MAXBLUPI)
{
- stopCh = m_channelBlupi[rank];
- if (stopCh >= 0 && m_lpSDL[stopCh] != nullptr)
- Mix_FadeOutChannel (stopCh + 1, 500);
+ bool immediat = channel == SOUND_DYNAMITE;
- m_channelBlupi[rank] = channel;
+ if (stop || immediat)
+ this->StopSound (immediat, rank);
+ else
+ m_channelBlupi[rank] = channel;
}
Uint8 panRight, panLeft;
@@ -288,17 +316,17 @@ CSound::PlayImage (Sounds channel, Point pos, Sint32 rank)
if (volumex < 0)
volumex = 0;
}
- else if (pos.x > LXIMAGE)
+ else if (pos.x > LXIMAGE ())
{
panRight = 255;
panLeft = 0;
- volumex -= pos.x - LXIMAGE;
+ volumex -= pos.x - LXIMAGE ();
if (volumex < 0)
volumex = 0;
}
else
{
- panRight = 255 * static_cast<Uint16> (pos.x) / LXIMAGE;
+ panRight = 255 * static_cast<Uint16> (pos.x) / LXIMAGE ();
panLeft = 255 - panRight;
}
@@ -308,9 +336,9 @@ CSound::PlayImage (Sounds channel, Point pos, Sint32 rank)
if (volumey < 0)
volumey = 0;
}
- else if (pos.y > LYIMAGE)
+ else if (pos.y > LYIMAGE ())
{
- volumey -= pos.y - LYIMAGE;
+ volumey -= pos.y - LYIMAGE ();
if (volumey < 0)
volumey = 0;
}
@@ -338,7 +366,10 @@ CSound::PlayMusic (const std::string & lpszMIDIFilename)
if (m_pMusic)
Mix_FreeMusic (m_pMusic);
- m_pMusic = Mix_LoadMUS (lpszMIDIFilename.c_str ());
+ std::string absolute;
+ if (FileExists (lpszMIDIFilename, absolute, Location::LOCATION_ABSOLUTE))
+ m_pMusic = Mix_LoadMUS (lpszMIDIFilename.c_str ());
+
if (!m_pMusic)
{
printf ("%s\n", Mix_GetError ());