Skip to content

Commit

Permalink
Remove background music related calls in old code
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed May 13, 2022
1 parent bd5a5f7 commit 109a0cd
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 95 deletions.
72 changes: 0 additions & 72 deletions EndlessClient/Audio/SoundManager.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
#if !LINUX
using System.Windows.Media;
using System.Windows.Threading;
#endif
using Microsoft.Xna.Framework.Audio;

namespace EndlessClient.Audio
Expand All @@ -17,7 +12,6 @@ public enum Note
public class SoundManager : IDisposable
{
private const string SFX_DIR = "sfx";
private const string MFX_DIR = "mfx";

//singleton pattern -- any newly constructed instance is copied from the 'instance'
private static readonly object _construction_locker_ = new object();
Expand All @@ -27,12 +21,6 @@ public class SoundManager : IDisposable
private List<SoundInfo> _guitarSounds;
private List<SoundInfo> _harpSounds;

#if !LINUX //todo: find MediaPlayer implementation that is cross-platform
private readonly MediaPlayer _musicPlayer;
private List<Uri> _musicFiles;
private Dispatcher _dispatcher;
#endif

public SoundManager()
{
lock (_construction_locker_)
Expand All @@ -50,12 +38,6 @@ public SoundManager()
_guitarSounds = new List<SoundInfo>(36);
_harpSounds = new List<SoundInfo>(36);

#if !LINUX
var musicFiles = Directory.GetFiles(MFX_DIR, "*.mid");
Array.Sort(musicFiles);
_musicFiles = new List<Uri>(musicFiles.Length);
#endif

foreach (var sfx in soundFiles)
{
using (var sfxStream = WAVFileValidator.GetStreamWithCorrectLengthHeader(sfx))
Expand All @@ -73,15 +55,6 @@ public SoundManager()
}
}

#if !LINUX
_musicPlayer = new MediaPlayer();
_musicPlayer.MediaEnded += (o, e) => _musicPlayer.Position = new TimeSpan(0);

foreach (string mfx in musicFiles)
_musicFiles.Add(new Uri(mfx, UriKind.Relative));

_dispatcher = Dispatcher.CurrentDispatcher;
#endif
_singletonInstance = this;
}
}
Expand All @@ -92,10 +65,6 @@ private void CopyFromInstance()
_soundEffects = _singletonInstance._soundEffects;
_guitarSounds = _singletonInstance._guitarSounds;
_harpSounds = _singletonInstance._harpSounds;
#if !LINUX
_musicFiles = _singletonInstance._musicFiles;
_dispatcher = _singletonInstance._dispatcher;
#endif
}

public SoundEffectInstance GetGuitarSoundRef(Note which)
Expand Down Expand Up @@ -129,39 +98,6 @@ public void StopLoopingSoundEffect(int sfxID)
_soundEffects[sfxID - 1].StopLoopingInstance();
}

public void PlayBackgroundMusic(int mfxID)
{
#if !LINUX
if(mfxID < 1 || mfxID >= _musicFiles.Count)
throw new ArgumentOutOfRangeException(nameof(mfxID), "The MFX id is out of range. Use the 1-based index that matches the number in the file name.");

InvokeIfNeeded(() =>
{
_musicPlayer.Stop();
_musicPlayer.Close();
_musicPlayer.Open(_musicFiles[mfxID - 1]);
_musicPlayer.Play();
});
#endif
}

public void StopBackgroundMusic()
{
#if !LINUX
InvokeIfNeeded(() => _musicPlayer.Stop());
#endif
}

#if !LINUX
private void InvokeIfNeeded(Action action)
{
if (_dispatcher.Thread != Thread.CurrentThread)
_dispatcher.BeginInvoke(action);
else
action();
}
#endif

~SoundManager()
{
//ensure that primary instance is disposed of if the reference to it is not explicitly disposed
Expand All @@ -180,14 +116,6 @@ private void Dispose(bool disposing)
{
if (disposing)
{
#if !LINUX
if (_musicPlayer.HasAudio)
{
_musicPlayer.Stop();
_musicPlayer.Close();
}
#endif

foreach (var sfx in _soundEffects)
sfx.Dispose();

Expand Down
2 changes: 0 additions & 2 deletions EndlessClient/Old/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ private bool InitializeSoundManager()
return false;
}

if (OldWorld.Instance.MusicEnabled)
SoundManager.PlayBackgroundMusic(1); //mfx001 == main menu theme
return true;
}

Expand Down
21 changes: 0 additions & 21 deletions EndlessClient/Rendering/OldMapRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,11 @@ public void SetActiveMap(IMapFile newActiveMap)
lock (_spikeTrapsLock)
_visibleSpikeTraps.Clear();

PlayOrStopBackgroundMusic();
PlayOrStopAmbientNoise();

_drawingEvent.Set();
}

public void PlayOrStopBackgroundMusic()
{
if (!OldWorld.Instance.MusicEnabled)
{
EOGame.Instance.SoundManager.StopBackgroundMusic();
return;
}

//not sure what MusicExtra field is supposed to be for
if (MapRef.Properties.Music > 0)
{
//sound manager accounts for zero-based indices when playing music
EOGame.Instance.SoundManager.PlayBackgroundMusic(MapRef.Properties.Music);
}
else
{
EOGame.Instance.SoundManager.StopBackgroundMusic();
}
}

public void PlayOrStopAmbientNoise()
{
if (!OldWorld.Instance.SoundEnabled)
Expand Down

0 comments on commit 109a0cd

Please sign in to comment.