Use ranges

This commit is contained in:
YoshiRulz 2020-01-13 06:58:02 +10:00
parent 0f1fa1531f
commit dd4f9aaf64
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
16 changed files with 97 additions and 184 deletions

View File

@ -1,4 +1,6 @@
using System.IO; using System.IO;
using BizHawk.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -51,7 +53,7 @@ namespace BizHawk.Client.Common
return false; return false;
} }
if (slot < 0 || slot > 10) if (!0.RangeTo(10).Contains(slot))
{ {
return false; return false;
} }
@ -70,33 +72,10 @@ namespace BizHawk.Client.Common
public void ToggleRedo(int slot) public void ToggleRedo(int slot)
{ {
if (slot < 0 || slot > 9) if (0.RangeTo(9).Contains(slot) && !(Global.MovieSession.Movie is TasMovie)) _redo[slot] ^= true;
{
return;
}
if (Global.MovieSession.Movie is TasMovie tasMovie)
{
return;
}
_redo[slot] ^= true;
} }
public bool IsRedo(int slot) public bool IsRedo(int slot) => 0.RangeTo(9).Contains(slot) && !(Global.MovieSession.Movie is TasMovie) && _redo[slot];
{
if (slot < 0 || slot > 9)
{
return false;
}
if (Global.MovieSession.Movie is TasMovie tasMovie)
{
return false;
}
return _redo[slot];
}
public void SwapBackupSavestate(string path) public void SwapBackupSavestate(string path)
{ {

View File

@ -3,6 +3,8 @@ using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BizHawk.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
public class SubtitleList : List<Subtitle> public class SubtitleList : List<Subtitle>
@ -16,10 +18,7 @@ namespace BizHawk.Client.Common
AddColorTag = false; AddColorTag = false;
} }
public IEnumerable<Subtitle> GetSubtitles(int frame) public IEnumerable<Subtitle> GetSubtitles(int frame) => this.Where(t => t.Frame.RangeTo(t.Frame + t.Duration).Contains(frame));
{
return this.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration);
}
public override string ToString() public override string ToString()
{ {

View File

@ -2,6 +2,8 @@
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using BizHawk.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
public partial class Bk2Movie public partial class Bk2Movie
@ -162,7 +164,7 @@ namespace BizHawk.Client.Common
var stateFramei = stateFrame ?? 0; var stateFramei = stateFrame ?? 0;
if (stateFramei > 0 && stateFramei < Log.Count) if (stateFramei.StrictlyBoundedBy(0.RangeTo(Log.Count)))
{ {
if (!Global.Config.VBAStyleMovieLoadState) if (!Global.Config.VBAStyleMovieLoadState)
{ {

View File

@ -5,6 +5,7 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Common.IEmulatorExtensions;
@ -346,7 +347,7 @@ namespace BizHawk.Client.Common
var stateFrameValue = stateFrame ?? 0; var stateFrameValue = stateFrame ?? 0;
if (stateFrameValue > 0 && stateFrameValue < Log.Count) if (stateFrameValue.StrictlyBoundedBy(0.RangeTo(Log.Count)))
{ {
if (!Global.Config.VBAStyleMovieLoadState) if (!Global.Config.VBAStyleMovieLoadState)
{ {
@ -379,15 +380,7 @@ namespace BizHawk.Client.Common
#region Branches #region Branches
public TasBranch GetBranch(int index) public TasBranch GetBranch(int index) => 0.RangeToExclusive(Branches.Count).Contains(index) ? Branches[index] : null;
{
if (index >= Branches.Count || index < 0)
{
return null;
}
return Branches[index];
}
public TasBranch GetBranch(Guid id) public TasBranch GetBranch(Guid id)
{ {

View File

@ -159,7 +159,7 @@ namespace BizHawk.Client.Common
break; break;
} }
if (_mHead.Value.EndExclusive > _mTail.Value.Index && _mHead.Value.Index <= _mTail.Value.Index && _mHead != _mTail) if (_mHead.Value.Index.RangeToExclusive(_mHead.Value.EndExclusive).Contains(_mTail.Value.Index) && _mHead != _mTail)
{ {
var nextTail = _mTail.Next; var nextTail = _mTail.Next;
Size -= _mTail.Value.Length; Size -= _mTail.Value.Length;

View File

@ -11,6 +11,7 @@ using ICSharpCode.SharpZipLib.Zip.Compression;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -548,7 +549,7 @@ namespace BizHawk.Client.EmuHawk
{ {
// the sampleRate limits are arbitrary, just to catch things which are probably silly-wrong // the sampleRate limits are arbitrary, just to catch things which are probably silly-wrong
// if a larger range of sampling rates is needed, it should be supported // if a larger range of sampling rates is needed, it should be supported
if (sampleRate < 8000 || sampleRate > 96000 || channels < 1 || channels > 2 || bits != 16) if (!8000.RangeTo(96000).Contains(sampleRate) || !1.RangeTo(2).Contains(channels) || bits != 16)
{ {
throw new ArgumentException("Audio parameters out of range!"); throw new ArgumentException("Audio parameters out of range!");
} }

View File

@ -4,6 +4,7 @@ using System.Drawing;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.EmuHawk.WinFormExtensions; using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -519,19 +520,18 @@ namespace BizHawk.Client.EmuHawk
private void DoSelectionBG(List<RollColumn> visibleColumns, Rectangle rect) private void DoSelectionBG(List<RollColumn> visibleColumns, Rectangle rect)
{ {
Color rowColor = Color.White; Color rowColor = Color.White;
int firstVisibleRow = FirstVisibleRow; var visibleRows = FirstVisibleRow.RangeTo(LastVisibleRow);
int lastVisibleRow = LastVisibleRow;
int lastRow = -1; int lastRow = -1;
foreach (Cell cell in _selectedItems) foreach (Cell cell in _selectedItems)
{ {
if (!cell.RowIndex.HasValue || cell.RowIndex > lastVisibleRow || cell.RowIndex < firstVisibleRow || !VisibleColumns.Contains(cell.Column)) if (!cell.RowIndex.HasValue || !visibleRows.Contains(cell.RowIndex.Value) || !VisibleColumns.Contains(cell.Column))
{ {
continue; continue;
} }
Cell relativeCell = new Cell Cell relativeCell = new Cell
{ {
RowIndex = cell.RowIndex - firstVisibleRow, RowIndex = cell.RowIndex - visibleRows.Start,
Column = cell.Column, Column = cell.Column,
}; };
relativeCell.RowIndex -= CountLagFramesAbsolute(relativeCell.RowIndex.Value); relativeCell.RowIndex -= CountLagFramesAbsolute(relativeCell.RowIndex.Value);

View File

@ -7,6 +7,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.CustomControls; using BizHawk.Client.EmuHawk.CustomControls;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -783,6 +784,7 @@ namespace BizHawk.Client.EmuHawk
} }
// Small jump, more accurate // Small jump, more accurate
var range = 0.RangeTo(_lagFrames[VisibleRows - halfRow]);
int lastVisible = LastFullyVisibleRow; int lastVisible = LastFullyVisibleRow;
do do
{ {
@ -798,22 +800,16 @@ namespace BizHawk.Client.EmuHawk
SetLagFramesArray(); SetLagFramesArray();
lastVisible = LastFullyVisibleRow; lastVisible = LastFullyVisibleRow;
} }
while ((lastVisible - value < 0 || lastVisible - value > _lagFrames[VisibleRows - halfRow]) && FirstVisibleRow != 0); while (!range.Contains(lastVisible - value) && FirstVisibleRow != 0);
} }
PointMouseToNewCell(); PointMouseToNewCell();
} }
} }
private bool IsVisible(int index) private bool IsVisible(int index) => FirstVisibleRow.RangeTo(LastFullyVisibleRow).Contains(index);
{
return index >= FirstVisibleRow && index <= LastFullyVisibleRow;
}
public bool IsPartiallyVisible(int index) public bool IsPartiallyVisible(int index) => FirstVisibleRow.RangeTo(LastVisibleRow).Contains(index);
{
return index >= FirstVisibleRow && index <= LastVisibleRow;
}
/// <summary> /// <summary>
/// Gets the number of rows currently visible including partially visible rows. /// Gets the number of rows currently visible including partially visible rows.
@ -889,6 +885,7 @@ namespace BizHawk.Client.EmuHawk
} }
// Small jump, more accurate // Small jump, more accurate
var range = 0.RangeTo(_lagFrames[VisibleRows]);
int lastVisible = FirstVisibleRow + CountLagFramesDisplay(VisibleRows / 2); int lastVisible = FirstVisibleRow + CountLagFramesDisplay(VisibleRows / 2);
do do
{ {
@ -904,7 +901,7 @@ namespace BizHawk.Client.EmuHawk
SetLagFramesArray(); SetLagFramesArray();
lastVisible = FirstVisibleRow + CountLagFramesDisplay(VisibleRows / 2); lastVisible = FirstVisibleRow + CountLagFramesDisplay(VisibleRows / 2);
} }
while ((lastVisible - index < 0 || lastVisible - index > _lagFrames[VisibleRows]) && FirstVisibleRow != 0); while (!range.Contains(lastVisible - index) && FirstVisibleRow != 0);
} }
} }
} }
@ -1819,26 +1816,9 @@ namespace BizHawk.Client.EmuHawk
private bool WasHoveringOnColumnCell => _lastCell?.Column != null && !_lastCell.RowIndex.HasValue; private bool WasHoveringOnColumnCell => _lastCell?.Column != null && !_lastCell.RowIndex.HasValue;
private bool IsPointingOnCellEdge(int? x) private bool IsPointingOnCellEdge(int? x) => x.HasValue
{ && !HorizontalOrientation //TODO support column resize in horizontal orientation
if (x.HasValue) && _columns.VisibleColumns.Any(column => (column.Left - _hBar.Value + (column.Width - column.Width / 6)).RangeTo(column.Right - _hBar.Value).Contains(x.Value));
{
if (HorizontalOrientation)
{
return false; // TODO: support column resize in horizontal orientation
}
foreach (RollColumn column in _columns.VisibleColumns)
{
if (column.Left - _hBar.Value + (column.Width - column.Width / 6) <= x.Value && column.Right - _hBar.Value >= x.Value)
{
return true;
}
}
}
return false;
}
/// <summary> /// <summary>
/// Finds the specific cell that contains the (x, y) coordinate. /// Finds the specific cell that contains the (x, y) coordinate.
@ -1895,26 +1875,11 @@ namespace BizHawk.Client.EmuHawk
{ {
if (_horizontalOrientation) if (_horizontalOrientation)
{ {
foreach (var item in _columns.VisibleColumns.Select((n, i) => new { Column = n, Index = i })) return _columns.VisibleColumns.Select((n, i) => new { Column = n, Index = i })
{ .FirstOrDefault(anonObj => (GetHColTop(anonObj.Index) - _vBar.Value).RangeTo(GetHColBottom(anonObj.Index) - _vBar.Value).Contains(pixel))
if (GetHColTop(item.Index) - _vBar.Value <= pixel && GetHColBottom(item.Index) - _vBar.Value >= pixel) ?.Column;
{
return item.Column;
}
}
} }
else return _columns.VisibleColumns.FirstOrDefault(column => (column.Left - _hBar.Value).RangeTo(column.Right - _hBar.Value).Contains(pixel));
{
foreach (RollColumn column in _columns.VisibleColumns)
{
if (column.Left - _hBar.Value <= pixel && column.Right - _hBar.Value >= pixel)
{
return column;
}
}
}
return null;
} }
/// <summary> /// <summary>
@ -1957,7 +1922,7 @@ namespace BizHawk.Client.EmuHawk
return 0; return 0;
} }
return index >= 0 && index < _horizontalColumnTops.Length return 0.RangeToExclusive(_horizontalColumnTops.Length).Contains(index)
? _horizontalColumnTops[index] ? _horizontalColumnTops[index]
: _horizontalColumnTops.Last() + CellHeight; : _horizontalColumnTops.Last() + CellHeight;
} }

View File

@ -2,6 +2,8 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Common;
// http://www.codeproject.com/Articles/154680/A-customizable-NET-WinForms-Message-Box // http://www.codeproject.com/Articles/154680/A-customizable-NET-WinForms-Message-Box
namespace BizHawk.Client.EmuHawk.CustomControls namespace BizHawk.Client.EmuHawk.CustomControls
{ {
@ -69,7 +71,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls
int count = names.Length; int count = names.Length;
if (count < 1 || count > 3) if (!1.RangeTo(3).Contains(count))
{ {
throw new ArgumentException("Invalid number of buttons. Must be between 1 and 3."); throw new ArgumentException("Invalid number of buttons. Must be between 1 and 3.");
} }

View File

@ -1,6 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Common;
using SlimDX; using SlimDX;
using SlimDX.DirectInput; using SlimDX.DirectInput;
@ -230,14 +233,13 @@ namespace BizHawk.Client.EmuHawk
for (int i = 0; i < _state.GetPointOfViewControllers().Length; i++) for (int i = 0; i < _state.GetPointOfViewControllers().Length; i++)
{ {
int j = i; int j = i;
AddItem($"POV{i + 1}U", AddItem($"POV{i + 1}U", () => {
() => { int t = _state.GetPointOfViewControllers()[j]; return (t >= 0 && t <= 4500) || (t >= 31500 && t < 36000); }); var t = _state.GetPointOfViewControllers()[j];
AddItem($"POV{i + 1}D", return 0.RangeTo(4500).Contains(t) || 31500.RangeToExclusive(36000).Contains(t);
() => { int t = _state.GetPointOfViewControllers()[j]; return t >= 13500 && t <= 22500; }); });
AddItem($"POV{i + 1}L", AddItem($"POV{i + 1}D", () => 13500.RangeTo(22500).Contains(_state.GetPointOfViewControllers()[j]));
() => { int t = _state.GetPointOfViewControllers()[j]; return t >= 22500 && t <= 31500; }); AddItem($"POV{i + 1}L", () => 22500.RangeTo(31500).Contains(_state.GetPointOfViewControllers()[j]));
AddItem($"POV{i + 1}R", AddItem($"POV{i + 1}R", () => 4500.RangeTo(13500).Contains(_state.GetPointOfViewControllers()[j]));
() => { int t = _state.GetPointOfViewControllers()[j]; return t >= 4500 && t <= 13500; });
} }
} }

View File

@ -1311,12 +1311,7 @@ namespace BizHawk.Client.EmuHawk
private void SNES_ToggleBg(int layer) private void SNES_ToggleBg(int layer)
{ {
if (!(Emulator is LibsnesCore) && !(Emulator is Snes9x)) if (!(Emulator is LibsnesCore || Emulator is Snes9x) || !1.RangeTo(4).Contains(layer))
{
return;
}
if (layer < 1 || layer > 4)
{ {
return; return;
} }
@ -1370,12 +1365,7 @@ namespace BizHawk.Client.EmuHawk
private void SNES_ToggleObj(int layer) private void SNES_ToggleObj(int layer)
{ {
if (!(Emulator is LibsnesCore) && !(Emulator is Snes9x)) if (!(Emulator is LibsnesCore || Emulator is Snes9x) || !1.RangeTo(4).Contains(layer))
{
return;
}
if (layer < 1 || layer > 4)
{ {
return; return;
} }

View File

@ -229,11 +229,11 @@ namespace BizHawk.Client.EmuHawk
// reset way-out-of-range values // reset way-out-of-range values
if (diff > 1) if (diff > 1.0f)
diff = 1; diff = 1.0f;
if (error > 1 || error < -1) if (!(-1.0f).RangeTo(1.0f).Contains(error))
error = 0; error = 0.0f;
if (diffUnthrottled > 1) if (diffUnthrottled > 1.0f)
diffUnthrottled = desiredspf; diffUnthrottled = desiredspf;
float derivative = (error - lastError) / diff; float derivative = (error - lastError) / diff;

View File

@ -602,7 +602,7 @@ namespace BizHawk.Client.EmuHawk
BigEndian = _domain.EndianType == MemoryDomain.Endian.Big; BigEndian = _domain.EndianType == MemoryDomain.Endian.Big;
_maxRow = _domain.Size / 2; _maxRow = _domain.Size / 2;
SetUpScrollBar(); SetUpScrollBar();
if (0 >= HexScrollBar.Minimum && 0 <= HexScrollBar.Maximum) if (HexScrollBar.Minimum.RangeTo(HexScrollBar.Maximum).Contains(0))
{ {
HexScrollBar.Value = 0; HexScrollBar.Value = 0;
} }
@ -702,11 +702,7 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private bool IsVisible(long address) private bool IsVisible(long address) => ((long) HexScrollBar.Value).RangeToExclusive(HexScrollBar.Value + _rowsVisible).Contains(address >> 4);
{
var i = address >> 4;
return i >= HexScrollBar.Value && i < _rowsVisible + HexScrollBar.Value;
}
private void SetHeader() private void SetHeader()
{ {
@ -946,8 +942,6 @@ namespace BizHawk.Client.EmuHawk
private long GetPointedAddress(int x, int y) private long GetPointedAddress(int x, int y)
{ {
long address;
// Scroll value determines the first row // Scroll value determines the first row
long i = HexScrollBar.Value; long i = HexScrollBar.Value;
var rowOffset = y / _fontHeight; var rowOffset = y / _fontHeight;
@ -963,48 +957,40 @@ namespace BizHawk.Client.EmuHawk
column = (x - start) / (_fontWidth * DataSize); column = (x - start) / (_fontWidth * DataSize);
} }
if (i >= 0 && i <= _maxRow && column >= 0 && column < (16 / DataSize)) return 0L.RangeTo(_maxRow).Contains(i) && 0.RangeTo(16 / DataSize).Contains(column)
{ ? i * 16 + column * DataSize
address = (i * 16) + (column * DataSize); : -1;
}
else
{
address = -1;
}
return address;
} }
private void DoShiftClick() private void DoShiftClick()
{ {
if (_addressOver >= 0 && _addressOver < _domain.Size) if (!0L.RangeToExclusive(_domain.Size).Contains(_addressOver)) return;
_secondaryHighlightedAddresses.Clear();
if (_addressOver < _highlightedAddress)
{ {
_secondaryHighlightedAddresses.Clear(); for (var x = _addressOver; x < _highlightedAddress; x += DataSize)
if (_addressOver < _highlightedAddress)
{ {
for (var x = _addressOver; x < _highlightedAddress; x += DataSize) _secondaryHighlightedAddresses.Add(x);
{
_secondaryHighlightedAddresses.Add(x);
}
} }
else if (_addressOver > _highlightedAddress) }
else if (_addressOver > _highlightedAddress)
{
for (var x = _highlightedAddress.Value + DataSize; x <= _addressOver; x += DataSize)
{ {
for (var x = _highlightedAddress.Value + DataSize; x <= _addressOver; x += DataSize) _secondaryHighlightedAddresses.Add(x);
{ }
_secondaryHighlightedAddresses.Add(x); }
}
if (!IsVisible(_addressOver))
{
var value = (_addressOver / 16) + 1 - ((_addressOver / 16) < HexScrollBar.Value ? 1 : _rowsVisible);
if (value < 0)
{
value = 0;
} }
if (!IsVisible(_addressOver)) HexScrollBar.Value = (int)value; // This will fail on a sufficiently large domain
{
var value = (_addressOver / 16) + 1 - ((_addressOver / 16) < HexScrollBar.Value ? 1 : _rowsVisible);
if (value < 0)
{
value = 0;
}
HexScrollBar.Value = (int)value; // This will fail on a sufficiently large domain
}
} }
} }
@ -1058,7 +1044,7 @@ namespace BizHawk.Client.EmuHawk
private void AddToSecondaryHighlights(long address) private void AddToSecondaryHighlights(long address)
{ {
if (address >= 0 && address < _domain.Size && !_secondaryHighlightedAddresses.Contains(address)) if (0L.RangeToExclusive(_domain.Size).Contains(address) && !_secondaryHighlightedAddresses.Contains(address))
{ {
_secondaryHighlightedAddresses.Add(address); _secondaryHighlightedAddresses.Add(address);
} }

View File

@ -5,6 +5,7 @@ using System.Windows.Forms;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -211,13 +212,10 @@ namespace BizHawk.Client.EmuHawk
if (Encoding.Checked && !string.IsNullOrWhiteSpace(ValueBox.Text)) if (Encoding.Checked && !string.IsNullOrWhiteSpace(ValueBox.Text))
{ {
var val = int.Parse(ValueBox.Text, NumberStyles.HexNumber); var val = int.Parse(ValueBox.Text, NumberStyles.HexNumber);
if (val > 0 && val < 0x100) if (val.StrictlyBoundedBy(0.RangeTo(0x100)) && !string.IsNullOrWhiteSpace(AddressBox.Text))
{ {
if (!string.IsNullOrWhiteSpace(AddressBox.Text)) _value = val;
{ EncodeGameGenie();
_value = val;
EncodeGameGenie();
}
} }
} }
@ -273,13 +271,10 @@ namespace BizHawk.Client.EmuHawk
if (CompareBox.Text.Length > 0) if (CompareBox.Text.Length > 0)
{ {
var c = int.Parse(CompareBox.Text, NumberStyles.HexNumber); var c = int.Parse(CompareBox.Text, NumberStyles.HexNumber);
if (c > 0 && c < 0x100) if (c.StrictlyBoundedBy(0.RangeTo(0x100)) && ValueBox.Text.Length > 0 && AddressBox.Text.Length > 0)
{ {
if (ValueBox.Text.Length > 0 && AddressBox.Text.Length > 0) _compare = c;
{ EncodeGameGenie();
_compare = c;
EncodeGameGenie();
}
} }
} }
else else

View File

@ -4,6 +4,8 @@ using System.Xml.Linq;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.Emulation.Cores.Nintendo.NES;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -65,10 +67,8 @@ namespace BizHawk.Client.EmuHawk
float a = freqtbl[i - 1]; float a = freqtbl[i - 1];
float b = freqtbl[i]; float b = freqtbl[i];
float c = freqtbl[i + 1]; float c = freqtbl[i + 1];
float min = (a + b) / 2; var range = ((a + b) / 2).RangeTo((b + c) / 2);
float max = (b + c) / 2; if (range.Contains(freq)) return i - 1;
if (freq >= min && freq <= max)
return i - 1;
} }
return 95; //I guess? return 95; //I guess?
} }

View File

@ -1027,7 +1027,7 @@ namespace BizHawk.Client.EmuHawk
{ {
int tileStride = pxacross / 8; int tileStride = pxacross / 8;
int tilesTall = pxtall / 8; int tilesTall = pxtall / 8;
if (tx < 0 || ty < 0 || tx >= tileStride || ty >= tilesTall) if (!0.RangeToExclusive(tileStride).Contains(tx) || !0.RangeToExclusive(tilesTall).Contains(ty))
{ {
return; return;
} }
@ -1060,7 +1060,7 @@ namespace BizHawk.Client.EmuHawk
private void HandleSpriteMouseOver(int px, int py) private void HandleSpriteMouseOver(int px, int py)
{ {
if (px < 0 || py < 0 || px >= 256 || py >= 224) return; if (!0.RangeTo(255).Contains(px) || !0.RangeTo(223).Contains(py)) return;
int sprite = spriteMap[px,py]; int sprite = spriteMap[px,py];
if(sprite == 0xFF) return; if(sprite == 0xFF) return;
@ -1074,8 +1074,7 @@ namespace BizHawk.Client.EmuHawk
int ox = px / si.ObjSizeBounds.Width; int ox = px / si.ObjSizeBounds.Width;
int oy = py / si.ObjSizeBounds.Height; int oy = py / si.ObjSizeBounds.Height;
if (ox < 0 || oy < 0 || ox >= 8 || oy >= 16) if (!0.RangeTo(7).Contains(ox) || !0.RangeTo(15).Contains(oy)) return;
return;
int objNum = oy * 8 + ox; int objNum = oy * 8 + ox;