From 49622f2441aa77214840e923cc0565c27192a1e2 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 3 Aug 2023 22:22:29 -0400 Subject: [PATCH] Fix build issues caused by int64 handling --- source/funkin/import.hx | 1 + source/funkin/play/PlayState.hx | 3 ++- source/funkin/util/tools/Int64Tools.hx | 32 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 source/funkin/util/tools/Int64Tools.hx diff --git a/source/funkin/import.hx b/source/funkin/import.hx index 4ba062b8f..cd0af4b55 100644 --- a/source/funkin/import.hx +++ b/source/funkin/import.hx @@ -11,6 +11,7 @@ using Lambda; using StringTools; using funkin.util.tools.ArrayTools; using funkin.util.tools.ArraySortTools; +using funkin.util.tools.Int64Tools; using funkin.util.tools.IteratorTools; using funkin.util.tools.MapTools; using funkin.util.tools.StringTools; diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 297f14d69..4e8b1ce9d 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -2326,7 +2326,8 @@ class PlayState extends MusicBeatSubState vocals.playerVolume = 1; // Calculate the input latency (do this as late as possible). - var inputLatencyMs:Float = haxe.Int64.toInt(PreciseInputManager.getCurrentTimestamp() - input.timestamp) / 1000.0 / 1000.0; + var currentTimestampNs:Int64 = PreciseInputManager.getCurrentTimestamp(); + var inputLatencyMs:Float = haxe.Int64.toInt(currentTimestampNs - input.timestamp) / Constants.NS_PER_MS; trace('Input: ${daNote.noteData.getDirectionName()} pressed ${inputLatencyMs}ms ago!'); // Get the offset and compensate for input latency. diff --git a/source/funkin/util/tools/Int64Tools.hx b/source/funkin/util/tools/Int64Tools.hx new file mode 100644 index 000000000..75448b36f --- /dev/null +++ b/source/funkin/util/tools/Int64Tools.hx @@ -0,0 +1,32 @@ +package funkin.util.tools; + +/** + * @see https://github.com/fponticelli/thx.core/blob/master/src/thx/Int64s.hx + */ +class Int64Tools +{ + static var min = haxe.Int64.make(0x80000000, 0); + static var one = haxe.Int64.make(0, 1); + static var two = haxe.Int64.ofInt(2); + static var zero = haxe.Int64.make(0, 0); + static var ten = haxe.Int64.ofInt(10); + + public static function toFloat(i:haxe.Int64):Float + { + var isNegative = false; + if (i < 0) + { + if (i < min) return -9223372036854775808.0; // most -ve value can't be made +ve + isNegative = true; + i = -i; + } + var multiplier = 1.0, ret = 0.0; + for (_ in 0...64) + { + if (haxe.Int64.and(i, one) != zero) ret += multiplier; + multiplier *= 2.0; + i = haxe.Int64.shr(i, 1); + } + return (isNegative ? -1 : 1) * ret; + } +}