# HG changeset patch # User David Fraser # Date 1251892322 0 # Node ID 529a4d41c67aaa7851641bc3b5c9a5fa237f702c # Parent a851461d345e2fa5bbdc6782ebda7247db1bace4 Rather use sound playing (we don't need to stream sound effects from disk), and cache sounds diff -r a851461d345e -r 529a4d41c67a gamelib/sound.py --- a/gamelib/sound.py Wed Sep 02 11:40:51 2009 +0000 +++ b/gamelib/sound.py Wed Sep 02 11:52:02 2009 +0000 @@ -15,14 +15,18 @@ except pygame.error, exc: print >>sys.stderr, "Could not initialize sound system: %s" % exc +SOUND_CACHE = {} + def play_sound(filename): """plays the sound with the given filename from the data sounds directory""" if not SOUND_INITIALIZED: return file_path = data.filepath("sounds", filename) - if not os.path.exists(file_path): - return - pygame.mixer.music.load(file_path) - pygame.mixer.music.play() + sound = SOUND_CACHE.get(file_path, None) + if not sound: + if not os.path.exists(file_path): + return + SOUND_CACHE[file_path] = sound = pygame.mixer.Sound(file_path) + sound.play()