Avoid exceptions in `AxisValue` implementations (resolves #4057)
see #4056 only in Release config, because cores really shouldn't be using undeclared axes and I'd like to be able to catch that
This commit is contained in:
parent
e3cfcdaeb9
commit
444d1b2182
|
@ -41,7 +41,12 @@ namespace BizHawk.Client.Common
|
||||||
_buttonStarts.Clear();
|
_buttonStarts.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int AxisValue(string name) => Definition.Axes[name].Neutral;
|
public int AxisValue(string name)
|
||||||
|
#if DEBUG
|
||||||
|
=> Definition.Axes[name].Neutral; // throw if no such axis
|
||||||
|
#else
|
||||||
|
=> Definition.Axes.TryGetValue(name, out var axisSpec) ? axisSpec.Neutral : default;
|
||||||
|
#endif
|
||||||
|
|
||||||
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => Array.Empty<(string, int)>();
|
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => Array.Empty<(string, int)>();
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,13 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
|
|
||||||
public int AxisValue(string name)
|
public int AxisValue(string name)
|
||||||
{
|
=> _axisHolds.TryGetValue(name, out int axisValue)
|
||||||
return _axisHolds.TryGetValue(name, out int axisValue) ? axisValue : Definition.Axes[name].Neutral;
|
? axisValue
|
||||||
}
|
#if DEBUG
|
||||||
|
: Definition.Axes[name].Neutral; // throw if no such axis
|
||||||
|
#else
|
||||||
|
: Definition.Axes.TryGetValue(name, out var axisSpec) ? axisSpec.Neutral : default;
|
||||||
|
#endif
|
||||||
|
|
||||||
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => throw new NotSupportedException();
|
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => throw new NotSupportedException();
|
||||||
public void SetHapticChannelStrength(string name, int strength) => throw new NotSupportedException();
|
public void SetHapticChannelStrength(string name, int strength) => throw new NotSupportedException();
|
||||||
|
@ -113,7 +117,11 @@ namespace BizHawk.Client.Common
|
||||||
public int AxisValue(string name)
|
public int AxisValue(string name)
|
||||||
=> _axisPatterns.TryGetValue(name, out var pattern)
|
=> _axisPatterns.TryGetValue(name, out var pattern)
|
||||||
? pattern.PeekNextValue()
|
? pattern.PeekNextValue()
|
||||||
: Definition.Axes[name].Neutral;
|
#if DEBUG
|
||||||
|
: Definition.Axes[name].Neutral; // throw if no such axis
|
||||||
|
#else
|
||||||
|
: Definition.Axes.TryGetValue(name, out var axisSpec) ? axisSpec.Neutral : default;
|
||||||
|
#endif
|
||||||
|
|
||||||
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => throw new NotSupportedException();
|
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => throw new NotSupportedException();
|
||||||
public void SetHapticChannelStrength(string name, int strength) => throw new NotSupportedException();
|
public void SetHapticChannelStrength(string name, int strength) => throw new NotSupportedException();
|
||||||
|
|
|
@ -51,7 +51,11 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
int sourceAxisValue = Source.AxisValue(name);
|
int sourceAxisValue = Source.AxisValue(name);
|
||||||
int sourceXorAxisValue = SourceXor.AxisValue(name);
|
int sourceXorAxisValue = SourceXor.AxisValue(name);
|
||||||
int neutral = Definition.Axes[name].Neutral;
|
#if DEBUG
|
||||||
|
var neutral = Definition.Axes[name].Neutral; // throw if no such axis
|
||||||
|
#else
|
||||||
|
var neutral = Definition.Axes.TryGetValue(name, out var axisSpec) ? axisSpec.Neutral : default;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (sourceAxisValue == neutral)
|
if (sourceAxisValue == neutral)
|
||||||
{
|
{
|
||||||
|
@ -82,7 +86,14 @@ namespace BizHawk.Client.Common
|
||||||
public int AxisValue(string name)
|
public int AxisValue(string name)
|
||||||
{
|
{
|
||||||
int sourceValue = Source.AxisValue(name);
|
int sourceValue = Source.AxisValue(name);
|
||||||
return sourceValue != Source.Definition.Axes[name].Neutral ? sourceValue : SourceOr.AxisValue(name);
|
#if DEBUG
|
||||||
|
var neutralValue = Source.Definition.Axes[name].Neutral; // throw if no such axis
|
||||||
|
#else
|
||||||
|
var neutralValue = Source.Definition.Axes.TryGetValue(name, out var axisSpec) ? axisSpec.Neutral : default;
|
||||||
|
#endif
|
||||||
|
return sourceValue != neutralValue
|
||||||
|
? sourceValue
|
||||||
|
: SourceOr.AxisValue(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => Source.GetHapticsSnapshot();
|
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => Source.GetHapticsSnapshot();
|
||||||
|
|
Loading…
Reference in New Issue