-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundManager.cs
37 lines (30 loc) · 895 Bytes
/
SoundManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SoundManager.cs
// Created on: 2020-11-2
// Author: Leo Treloar
using System;
using SFML.Audio;
using System.Collections.Generic;
namespace UniverseIntruders
{
class SoundManager
{
private Queue<Sound> soundQueue;
private const int MaxSize = 256;
private int capacity;
public SoundManager(int queueSize)
{
if (queueSize > MaxSize)
throw new ArgumentOutOfRangeException("queueSize", "No more than 256 sounds allowed");
capacity = queueSize;
soundQueue = new Queue<Sound>(queueSize);
}
public void Play(Sound sound)
{
// If there are already too many sounds, dequeue one
if (soundQueue.Count >= capacity)
soundQueue.Dequeue().Dispose();
sound.Play();
soundQueue.Enqueue(sound);
}
}
}