Skip to content

Commit cf7a540

Browse files
freezyjsm174
authored andcommitted
style: Clean up Gle class.
1 parent 575ad39 commit cf7a540

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

VisualPinball.Engine.PinMAME.Unity/Runtime/PinMameGamelogicEngine.cs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,20 @@ public GamelogicEngineLamp[] RequestedLamps {
100100
[NonSerialized] private PinMame.PinMame _pinMame;
101101
[SerializeReference] private PinMameGame _game;
102102

103-
private Dictionary<string, GamelogicEngineSwitch> _switches = new Dictionary<string, GamelogicEngineSwitch>();
104-
private Dictionary<int, GamelogicEngineCoil> _coils = new Dictionary<int, GamelogicEngineCoil>();
105-
private Dictionary<int, GamelogicEngineLamp> _lamps = new Dictionary<int, GamelogicEngineLamp>();
103+
private Dictionary<string, GamelogicEngineSwitch> _switches = new();
104+
private Dictionary<int, GamelogicEngineCoil> _coils = new();
105+
private Dictionary<int, GamelogicEngineLamp> _lamps = new();
106106

107107
private bool _isRunning;
108108
private int _numMechs;
109-
private Dictionary<int, byte[]> _frameBuffer = new Dictionary<int, byte[]>();
110-
private Dictionary<int, Dictionary<byte, byte>> _dmdLevels = new Dictionary<int, Dictionary<byte, byte>>();
109+
private Dictionary<int, byte[]> _frameBuffer = new();
110+
private Dictionary<int, Dictionary<byte, byte>> _dmdLevels = new();
111111

112112
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
113-
private static readonly Color Tint = new Color(1, 0.18f, 0);
113+
private static readonly Color Tint = new(1, 0.18f, 0);
114114

115-
private readonly Queue<Action> _dispatchQueue = new Queue<Action>();
116-
private readonly Queue<float[]> _audioQueue = new Queue<float[]>();
115+
private readonly Queue<Action> _dispatchQueue = new();
116+
private readonly Queue<float[]> _audioQueue = new();
117117

118118
private int _audioFilterChannels;
119119
private PinMameAudioInfo _audioInfo;
@@ -570,26 +570,25 @@ public bool GetCoil(string id)
570570

571571
private void OnSolenoidUpdated(int internalId, bool isActive)
572572
{
573-
if (_coils.ContainsKey(internalId))
574-
{
575-
if (!_solenoidsEnabled)
576-
{
577-
_solenoidsEnabled = (DateTimeOffset.Now.ToUnixTimeMilliseconds() - _solenoidDelayStart) >= SolenoidDelay;
573+
if (_coils.ContainsKey(internalId)) {
578574

579-
if (_solenoidsEnabled)
580-
{
575+
if (!_solenoidsEnabled) {
576+
_solenoidsEnabled = DateTimeOffset.Now.ToUnixTimeMilliseconds() - _solenoidDelayStart >= SolenoidDelay;
577+
578+
if (_solenoidsEnabled) {
581579
Logger.Info($"Solenoids enabled, {SolenoidDelay}ms passed");
582580
}
583581
}
584582

585-
if (_solenoidsEnabled)
586-
{
587-
Logger.Info($"[PinMAME] <= coil {_coils[internalId].Id} ({internalId}): {isActive} | {_coils[internalId].Description}");
583+
if (_solenoidsEnabled) {
584+
var coil = _coils[internalId];
585+
var id = coil != null ? coil.Id : internalId.ToString();
586+
var desc = coil != null ? coil.Description : "-";
587+
Logger.Info($"[PinMAME] <= coil {id} ({internalId}): {isActive} | {desc}");
588588

589-
lock (_dispatchQueue)
590-
{
591-
_dispatchQueue.Enqueue(() =>
592-
OnCoilChanged?.Invoke(this, new CoilEventArgs(_coils[internalId].Id, isActive)));
589+
lock (_dispatchQueue) {
590+
id = _coils[internalId].Id;
591+
_dispatchQueue.Enqueue(() => OnCoilChanged?.Invoke(this, new CoilEventArgs(id, isActive)));
593592
}
594593
}
595594
else

0 commit comments

Comments
 (0)