Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #463

Merged
merged 13 commits into from
Nov 26, 2016
49 changes: 16 additions & 33 deletions dev/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,30 @@

namespace UltimaXNA
{
internal sealed class Bootstrapper
sealed class Bootstrapper
{
// === Main ===================================================================================================
[STAThread]
private static void Main(string[] args)
static void Main(string[] args)
{
new Bootstrapper(args).Initialize();
}

private bool m_IsInitialized;
// === Instance ===============================================================================================
GeneralExceptionHandler m_ExecptionHandler;

public string BaseApplicationPath
Bootstrapper(string[] args)
{
get { return AppDomain.CurrentDomain.BaseDirectory; }
m_ExecptionHandler = new GeneralExceptionHandler();
}

public Bootstrapper(string[] args)
void Initialize()
{
GeneralExceptionHandler.Instance = new GeneralExceptionHandler();
}

public void Initialize()
{
if (m_IsInitialized)
{
return;
}

m_IsInitialized = true;

ConfigureTraceListeners();

if (Settings.Debug.IsConsoleEnabled && !ConsoleManager.HasConsole)
{
ConsoleManager.Show();
}

try
{
StartEngine();
Expand All @@ -69,56 +57,51 @@ public void Initialize()
}
}

private void StartEngine()
void StartEngine()
{
SetExceptionHandlers();

using (UltimaGame engine = new UltimaGame())
{
Resolutions.SetWindowSize(engine.Window);
engine.Run();
}

ClearExceptionHandlers();
}

private void ConfigureTraceListeners()
void ConfigureTraceListeners()
{
if (Debugger.IsAttached)
{
Tracer.RegisterListener(new DebugOutputEventListener());
}

Tracer.RegisterListener(new FileLogEventListener("debug.log"));

if (Settings.Debug.IsConsoleEnabled)
{
Tracer.RegisterListener(new ConsoleOutputEventListener());
}

Tracer.RegisterListener(new MsgBoxOnCriticalListener());
}

private void SetExceptionHandlers()
void SetExceptionHandlers()
{
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
}

private void ClearExceptionHandlers()
void ClearExceptionHandlers()
{
AppDomain.CurrentDomain.UnhandledException -= OnUnhandledException;
TaskScheduler.UnobservedTaskException -= OnUnobservedTaskException;
}

private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
GeneralExceptionHandler.Instance.OnError((Exception) e.ExceptionObject);
m_ExecptionHandler.OnError((Exception) e.ExceptionObject);
}

private void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
GeneralExceptionHandler.Instance.OnError(e.Exception);
m_ExecptionHandler.OnError(e.Exception);
}
}
}
12 changes: 5 additions & 7 deletions dev/Configuration/AudioSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ namespace UltimaXNA.Configuration
{
public class AudioSettings : ASettingsSection
{
public const string SectionName = "audio";

private int m_MusicVolume;
private int m_SoundVolume;
private bool m_MusicOn;
private bool m_SoundOn;
private bool m_FootStepSoundOn;
int m_MusicVolume;
int m_SoundVolume;
bool m_MusicOn;
bool m_SoundOn;
bool m_FootStepSoundOn;

public AudioSettings()
{
Expand Down
8 changes: 3 additions & 5 deletions dev/Configuration/DebugSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ namespace UltimaXNA.Configuration
{
public sealed class DebugSettings : ASettingsSection
{
public const string SectionName = "debug";

private bool m_IsConsoleEnabled;
private bool m_ShowFps;
private bool m_LogPackets;
bool m_IsConsoleEnabled;
bool m_ShowFps;
bool m_LogPackets;

public DebugSettings()
{
Expand Down
6 changes: 2 additions & 4 deletions dev/Configuration/EngineSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ namespace UltimaXNA.Configuration
{
public sealed class EngineSettings : ASettingsSection
{
public const string SectionName = "engine";

private bool m_IsVSyncEnabled;
private bool m_IsFixedTimeStep;
bool m_IsVSyncEnabled;
bool m_IsFixedTimeStep;

public EngineSettings()
{
Expand Down
2 changes: 0 additions & 2 deletions dev/Configuration/GumpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace UltimaXNA.Configuration
{
public class GumpSettings : ASettingsSection
{
public const string SectionName = "gump";

/// <summary>
/// The list of last positions where a given gump type was located.
/// </summary>
Expand Down
12 changes: 5 additions & 7 deletions dev/Configuration/LoginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ namespace UltimaXNA.Configuration
{
public sealed class LoginSettings : ASettingsSection
{
public const string SectionName = "server";

private string m_ServerAddress;
private int m_ServerPort;
private string m_UserName;
private bool m_AutoSelectLastCharacter;
private string m_LastCharacterName;
string m_ServerAddress;
int m_ServerPort;
string m_UserName;
bool m_AutoSelectLastCharacter;
string m_LastCharacterName;

public LoginSettings()
{
Expand Down
10 changes: 5 additions & 5 deletions dev/Configuration/Properties/MouseProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace UltimaXNA.Configuration.Properties
{
public class MouseProperty : NotifyPropertyChangedBase
{
private MouseButton m_InteractionButton = MouseButton.Left;
private MouseButton m_MovementButton = MouseButton.Right;
private bool m_IsEnabled = true;
private float m_ClickAndPickUpMS = 800f; // this is close to what the legacy client uses.
private float m_DoubleClickMS = 400f;
MouseButton m_InteractionButton = MouseButton.Left;
MouseButton m_MovementButton = MouseButton.Right;
bool m_IsEnabled = true;
float m_ClickAndPickUpMS = 800f; // this is close to what the legacy client uses.
float m_DoubleClickMS = 400f;

public MouseProperty()
{
Expand Down
4 changes: 2 additions & 2 deletions dev/Configuration/Properties/ResolutionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace UltimaXNA.Configuration.Properties
/// </summary>
public class ResolutionProperty : NotifyPropertyChangedBase
{
private int m_Height;
private int m_Width;
int m_Height;
int m_Width;

public ResolutionProperty()
{
Expand Down
2 changes: 0 additions & 2 deletions dev/Configuration/UltimaOnlineSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ namespace UltimaXNA.Configuration
{
public sealed class UltimaOnlineSettings : ASettingsSection
{
public const string SectionName = "ultimaOnline";

bool m_AllowCornerMovement = false;
string m_DataDirectory;
byte[] m_ClientVersion;
Expand Down
38 changes: 18 additions & 20 deletions dev/Configuration/UserInterfaceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,24 @@ namespace UltimaXNA.Configuration
{
public class UserInterfaceSettings : ASettingsSection
{
public const string SectionName = "ui";

private ResolutionProperty m_FullScreenResolution;
private ResolutionProperty m_WindowResolution;
private ResolutionProperty m_WorldGumpResolution;
private bool m_PlayWindowPixelDoubling;
private bool m_IsFullScreen;
private MouseProperty m_Mouse;
private bool m_AlwaysRun;
private bool m_MenuBarDisabled;

private int m_SpeechColor = 4 * Utility.RandomValue(0, 99) * 5;
private int m_EmoteColor = 646;
private int m_PartyMsgPrivateColor = 58;
private int m_PartyMsgColor = 68;
private int m_GuildMsgColor = 70;
private bool m_IgnoreGuildMsg;
private int m_AllianceMsgColor = 487;
private bool m_IgnoreAllianceMsg;
private bool m_CrimeQuery;
ResolutionProperty m_FullScreenResolution;
ResolutionProperty m_WindowResolution;
ResolutionProperty m_WorldGumpResolution;
bool m_PlayWindowPixelDoubling;
bool m_IsFullScreen;
MouseProperty m_Mouse;
bool m_AlwaysRun;
bool m_MenuBarDisabled;

int m_SpeechColor = 4 * Utility.RandomValue(0, 99) * 5;
int m_EmoteColor = 646;
int m_PartyMsgPrivateColor = 58;
int m_PartyMsgColor = 68;
int m_GuildMsgColor = 70;
bool m_IgnoreGuildMsg;
int m_AllianceMsgColor = 487;
bool m_IgnoreAllianceMsg;
bool m_CrimeQuery;

public UserInterfaceSettings()
{
Expand Down
5 changes: 2 additions & 3 deletions dev/Core/Audio/ASound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Dispose()
/// <param name="asEffect">Set to false for music, true for sound effects.</param>
public void Play(bool asEffect, AudioEffects effect = AudioEffects.None, float volume = 1.0f, bool spamCheck = false)
{
double now = UltimaGame.TotalMS;
double now = (float)ServiceRegistry.GetService<UltimaGame>().TotalMS;
CullExpiredEffects(now);

if (spamCheck && (LastPlayed + MinimumDelay > DateTime.Now))
Expand Down Expand Up @@ -96,7 +96,6 @@ public void Play(bool asEffect, AudioEffects effect = AudioEffects.None, float v
m_ThisInstance.SubmitBuffer(buffer);
m_ThisInstance.Volume = volume;
m_ThisInstance.Play();

List<Tuple<DynamicSoundEffectInstance, double>> list = (asEffect) ? m_EffectInstances : m_MusicInstances;
double ms = m_ThisInstance.GetSampleDuration(buffer.Length).TotalMilliseconds;
list.Add(new Tuple<DynamicSoundEffectInstance, double>(m_ThisInstance, now + ms));
Expand All @@ -108,7 +107,7 @@ public void Stop()
AfterStop();
}

private void CullExpiredEffects(double now )
private void CullExpiredEffects(double now)
{
// Check to see if any existing instances have stopped playing. If they have, remove the
// reference to them so the garbage collector can collect them.
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Buffer16BitStereo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp
/// Internal class used to queue samples that are being obtained from an Mp3 stream.
/// This class handles stereo 16-bit data! Switch it out if you want mono or something.
/// </summary>
internal class Buffer16BitStereo : ABuffer
class Buffer16BitStereo : ABuffer
{
// This is stereo!
private static readonly int CHANNELS = 2;
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/ABuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding
/// <summary>
/// Base Class for audio output.
/// </summary>
internal abstract class ABuffer
abstract class ABuffer
{
public const int OBUFFERSIZE = 2*1152; // max. 2 * 1152 samples per frame
public const int MAXCHANNELS = 2; // max. number of channels
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/BitReserve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding

// REVIEW: there is no range checking, so buffer underflow or overflow
// can silently occur.
internal sealed class BitReserve
sealed class BitReserve
{
/// <summary>
/// Size of the internal buffer to store the reserved bits.
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/Bitstream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding
/// REVIEW: much of the parsing currently occurs in the various decoders.
/// This should be moved into this class and associated inner classes.
/// </summary>
internal sealed class Bitstream
sealed class Bitstream
{
/// <summary>
/// Maximum size of the frame buffer:
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/BitstreamErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding
/// This struct describes all error codes that can be thrown
/// in BistreamExceptions.
/// </summary>
internal struct BitstreamErrors
struct BitstreamErrors
{
public static readonly int UNKNOWN_ERROR = BITSTREAM_ERROR + 0;
public static readonly int UNKNOWN_SAMPLE_RATE = BITSTREAM_ERROR + 1;
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/CircularByteBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding
{
[Serializable]
internal class CircularByteBuffer
class CircularByteBuffer
{
private byte[] m_DataArray;
private int m_Index;
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/Crc16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding
/// <summary>
/// 16-Bit CRC checksum
/// </summary>
internal sealed class Crc16
sealed class Crc16
{
private static readonly short Polynomial;
private short m_Crc;
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding
/// <summary>
/// Encapsulates the details of decoding an MPEG audio frame.
/// </summary>
internal class Decoder
class Decoder
{
private static readonly Params DEFAULT_PARAMS = new Params();
private readonly Params params_Renamed;
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/DecoderErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding
/// This interface provides constants describing the error
/// codes used by the Decoder to indicate errors.
/// </summary>
internal struct DecoderErrors
struct DecoderErrors
{
public static readonly int UNKNOWN_ERROR = BitstreamErrors.DECODER_ERROR + 0;
public static readonly int UNSUPPORTED_LAYER = BitstreamErrors.DECODER_ERROR + 1;
Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/DecoderException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding
/// errors that can occur when decoding MPEG audio.
/// </summary>
[Serializable]
internal class DecoderException : MP3SharpException
class DecoderException : MP3SharpException
{
private int m_ErrorCode;

Expand Down
2 changes: 1 addition & 1 deletion dev/Core/Audio/MP3Sharp/Decoding/Decoders/ASubband.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace UltimaXNA.Core.Audio.MP3Sharp.Decoding.Decoders
/// <summary>
/// Abstract base class for subband classes of layer I and II
/// </summary>
internal abstract class ASubband
abstract class ASubband
{
/*
* Changes from version 1.1 to 1.2:
Expand Down
Loading