mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fixed a floating point rounding error
This commit is contained in:
parent
57d945d6ee
commit
831a94cdbc
@ -100,8 +100,6 @@ namespace NewHorizons.Builder.Props.Audio
|
|||||||
var freq = CollectionUtilities.KeyByValue(_customFrequencyNames, str);
|
var freq = CollectionUtilities.KeyByValue(_customFrequencyNames, str);
|
||||||
if (freq != default) return freq;
|
if (freq != default) return freq;
|
||||||
|
|
||||||
NHLogger.Log($"Registering new frequency name [{str}]");
|
|
||||||
|
|
||||||
if (NumberOfFrequencies == 31)
|
if (NumberOfFrequencies == 31)
|
||||||
{
|
{
|
||||||
NHLogger.LogWarning($"Can't store any more frequencies, skipping [{str}]");
|
NHLogger.LogWarning($"Can't store any more frequencies, skipping [{str}]");
|
||||||
@ -111,6 +109,8 @@ namespace NewHorizons.Builder.Props.Audio
|
|||||||
freq = EnumUtilities.Create<SignalFrequency>(str);
|
freq = EnumUtilities.Create<SignalFrequency>(str);
|
||||||
_customFrequencyNames.Add(freq, str);
|
_customFrequencyNames.Add(freq, str);
|
||||||
|
|
||||||
|
NHLogger.Log($"Registered new frequency name [{str}] with value [{(int)freq}] and index [{AudioSignal.FrequencyToIndex(freq)}]");
|
||||||
|
|
||||||
NumberOfFrequencies = EnumUtils.GetValues<SignalFrequency>().Length;
|
NumberOfFrequencies = EnumUtils.GetValues<SignalFrequency>().Length;
|
||||||
|
|
||||||
return freq;
|
return freq;
|
||||||
|
|||||||
@ -45,7 +45,9 @@ namespace NewHorizons.Patches.SignalPatches
|
|||||||
SignalFrequency.HideAndSeek => 5,
|
SignalFrequency.HideAndSeek => 5,
|
||||||
SignalFrequency.Radio => 6,
|
SignalFrequency.Radio => 6,
|
||||||
SignalFrequency.Statue => 7,
|
SignalFrequency.Statue => 7,
|
||||||
_ => (int)(Mathf.Log((float)frequency) / Mathf.Log(2f)),// Frequencies are in powers of 2
|
// Can't cast to int because floating point error, it was doing 12.9999999 -> 12
|
||||||
|
// Frequencies are in powers of 2
|
||||||
|
_ => Mathf.RoundToInt(Mathf.Log((float)frequency) / Mathf.Log(2f)),
|
||||||
};
|
};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user