There's no need for instance methods.
This commit is contained in:
Eric Lawrence 2015-02-25 20:07:17 -06:00
Родитель 9adf621865
Коммит 198c76044a
3 изменённых файлов: 18 добавлений и 17 удалений

Просмотреть файл

@ -3,21 +3,20 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.CodeDom.Compiler;
namespace BabySmash
{
public class Win32Audio
public static class Win32Audio
{
/// <summary>
/// Collection of soundname->WAV bytes mappings
/// </summary>
public static Dictionary<string, byte[]> cachedWavs = new Dictionary<string, byte[]>();
private static Dictionary<string, byte[]> cachedWavs = new Dictionary<string, byte[]>();
/// <summary>
/// Lock this object to protect against concurrent writes to the cachedWavs collection.
/// </summary>
public static object cachedWavsLock = new object();
private static object cachedWavsLock = new object();
#region NativeAPI
private const UInt32 SND_ASYNC = 0x0001;
@ -30,20 +29,22 @@ namespace BabySmash
#endregion NativeAPI
public void PlayWavResource(string wav)
public static void PlayWavResource(string wav)
{
byte[] arrWav = GetWavResource(wav);
PlaySound(arrWav, IntPtr.Zero, SND_ASYNC | SND_MEMORY);
}
public void PlayWavResourceYield(string wav)
public static void PlayWavResourceYield(string wav)
{
byte[] arrWav = GetWavResource(wav);
PlaySound(arrWav, IntPtr.Zero, SND_ASYNC | SND_NOSTOP | SND_MEMORY);
}
private byte[] GetWavResource(string wav)
private static byte[] GetWavResource(string wav)
{
wav = ".Resources.Sounds." + wav;
if (cachedWavs.ContainsKey(wav))
{
return cachedWavs[wav];

Просмотреть файл

@ -33,7 +33,7 @@ namespace BabySmash
private bool isDrawing = false;
private readonly SpeechSynthesizer objSpeech = new SpeechSynthesizer();
private readonly List<MainWindow> windows = new List<MainWindow>();
private readonly Win32Audio audio = new Win32Audio();
private DispatcherTimer timer = new DispatcherTimer();
private Queue<Shape> ellipsesQueue = new Queue<Shape>();
private Dictionary<string,Queue<UserControl>> ellipsesUserControlQueue = new Dictionary<string,Queue<UserControl>>();
@ -138,7 +138,7 @@ namespace BabySmash
windows[0].infoLabel.Visibility = Visibility.Visible;
//Startup sound
audio.PlayWavResourceYield(".Resources.Sounds." + "EditedJackPlaysBabySmash.wav");
Win32Audio.PlayWavResourceYield("EditedJackPlaysBabySmash.wav");
string[] args = Environment.GetCommandLineArgs();
string ext = System.IO.Path.GetExtension(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
@ -308,7 +308,7 @@ namespace BabySmash
private void PlayLaughter()
{
audio.PlayWavResource(Utils.GetRandomSoundFile());
Win32Audio.PlayWavResource(Utils.GetRandomSoundFile());
}
private void SpeakString(string s)
@ -390,18 +390,18 @@ namespace BabySmash
isDrawing = true;
main.CaptureMouse();
audio.PlayWavResource(".Resources.Sounds." + "smallbumblebee.wav");
Win32Audio.PlayWavResource("smallbumblebee.wav");
}
public void MouseWheel(MainWindow main, MouseWheelEventArgs e)
{
if (e.Delta > 0)
{
audio.PlayWavResourceYield(".Resources.Sounds." + "rising.wav");
Win32Audio.PlayWavResourceYield("rising.wav");
}
else
{
audio.PlayWavResourceYield(".Resources.Sounds." + "falling.wav");
Win32Audio.PlayWavResourceYield("falling.wav");
}
}
@ -453,7 +453,7 @@ namespace BabySmash
Canvas.SetTop(shape, p.Y - 25);
if (Settings.Default.MouseDraw)
audio.PlayWavResourceYield(".Resources.Sounds." + "smallbumblebee.wav");
Win32Audio.PlayWavResourceYield("smallbumblebee.wav");
if (ellipsesQueue.Count > 30) //this is arbitrary
{

Просмотреть файл

@ -11,7 +11,8 @@ namespace BabySmash
internal static class Utils
{
private static readonly Dictionary<Color, string> brushToString;
private static readonly Random lRandom = new Random();
private static readonly Random lRandom = new Random(); // BUG BUG: Believe it or not, Random is NOT THREAD SAFE!
private static readonly FunCursor1 fun1 = new FunCursor1();
private static readonly FunCursor2 fun2 = new FunCursor2();
@ -80,8 +81,7 @@ namespace BabySmash
public static string GetRandomSoundFile()
{
string retVal = sounds[lRandom.Next(0, sounds.Length)];
return ".Resources.Sounds." + retVal;
return sounds[lRandom.Next(0, sounds.Length)];
}
public static bool GetRandomBoolean()