summaryrefslogtreecommitdiff
path: root/src/audio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio.cpp')
-rw-r--r--src/audio.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/audio.cpp b/src/audio.cpp
index 2f70fee..af6d24b 100644
--- a/src/audio.cpp
+++ b/src/audio.cpp
@@ -20,6 +20,7 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>.
namespace audio {
static std::list<sf::Sound> playing_sounds;
+static std::list<ambient_t*> ambient_sounds;
void clean_sounds(void)
{
@@ -41,4 +42,32 @@ void sound_t::play(void)
sound->play();
}
+void ambient_t::load(const char *path)
+{
+ printf("load %s\n", path);
+ sound.openFromFile(path);
+ sound.setLoop(true);
+ ambient_sounds.push_back(this);
+}
+
+void update_ambience(bool playing)
+{
+ for (ambient_t *ambient : ambient_sounds) {
+ if (!playing) {
+ if (ambient->playing) {
+ ambient->sound.stop();
+ ambient->playing = false;
+ }
+ continue;
+ }
+
+ if (!ambient->playing) {
+ ambient->sound.play();
+ ambient->playing = true;
+ }
+
+ ambient->sound.setVolume(ambient->weight * 100.0f);
+ }
+}
+
} // namespace audio