summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2020-04-25 15:19:05 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2020-04-25 15:19:05 +0700
commitbc8579329e04e470f168ab684aa3519ef36c0acd (patch)
tree17ec70e6ebca704cff46abc95d5fb739de3e9a6b
parent2813a0856f1de3e0f9e0beed280e29e06a78c3ee (diff)
downloadbrutalmaze-bc8579329e04e470f168ab684aa3519ef36c0acd.tar.gz
Use palace.MessageHandler to collect stopped sources
-rw-r--r--brutalmaze/game.py10
-rw-r--r--brutalmaze/misc.py21
2 files changed, 7 insertions, 24 deletions
diff --git a/brutalmaze/game.py b/brutalmaze/game.py
index f088b7d..d30c44d 100644
--- a/brutalmaze/game.py
+++ b/brutalmaze/game.py
@@ -37,7 +37,7 @@ from appdirs import AppDirs
 
 from .constants import SETTINGS, ICON, SFX, SFX_NOISE, HERO_SPEED, MIDDLE
 from .maze import Maze
-from .misc import sign, deg, join, play, clean_sources
+from .misc import sign, deg, join, play
 
 
 class ConfigReader:
@@ -138,7 +138,7 @@ class Game:
             use_context(self.actx)
             self.actx.listener.position = MIDDLE, -MIDDLE, 0
             self.actx.listener.gain = not self._mute
-            self._source = Buffer(SFX_NOISE).play()
+            self._source = play(SFX_NOISE)
             self._source.looping = True
         return self
 
@@ -147,8 +147,8 @@ class Game:
         if not self.hero.dead: self.maze.dump_records()
         if self.actx is not None:
             free(SFX)
-            clean_sources(stopped=False)
-            self._source.destroy()
+            self._source.stop()
+            self.actx.update()
             use_context(None)
             self.actx.destroy()
             self.actx.device.close()
@@ -215,7 +215,7 @@ class Game:
         if not self.paused: self.maze.update(self.fps)
         if not self.headless: self.maze.draw()
         self.clock.tick(self.fps)
-        clean_sources()
+        self.actx.update()
         return True
 
     def move(self, x=0, y=0):
diff --git a/brutalmaze/misc.py b/brutalmaze/misc.py
index e5d1016..60d89c9 100644
--- a/brutalmaze/misc.py
+++ b/brutalmaze/misc.py
@@ -91,27 +91,10 @@ def json_rec(directory):
 
 
 def play(sound: str, x: float = MIDDLE, y: float = MIDDLE,
-         gain: float = 1.0) -> None:
+         gain: float = 1.0) -> Source:
     """Play a sound at the given position."""
     source = Buffer(sound).play()
     source.spatialize = True
     source.position = x, -y, 0
     source.gain = gain
-    sources.append(source)
-
-
-def clean_sources(stopped=True) -> None:
-    """Destroyed stopped sources.
-
-    If stopped is set to False, clean all sources.
-    """
-    global sources
-    sources, tmp = [], sources
-    for source in tmp:
-        if stopped and source.playing:
-            sources.append(source)
-        else:
-            source.destroy()
-
-
-sources = []
+    return source