From 13671cf29053cb68e12ed18ddbb432ceb75a4ed2 Mon Sep 17 00:00:00 2001
From: EliteMasterEric <ericmyllyoja@gmail.com>
Date: Fri, 4 Aug 2023 11:13:41 -0400
Subject: [PATCH] Make sure timestamps are consistent with use of Int64.

---
 source/funkin/input/PreciseInputManager.hx | 9 +++++++--
 source/funkin/play/PlayState.hx            | 3 +--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/source/funkin/input/PreciseInputManager.hx b/source/funkin/input/PreciseInputManager.hx
index 7e6a6569b..6217b2fe7 100644
--- a/source/funkin/input/PreciseInputManager.hx
+++ b/source/funkin/input/PreciseInputManager.hx
@@ -84,6 +84,11 @@ class PreciseInputManager extends FlxKeyManager<FlxKey, PreciseInputList>
     };
   }
 
+  /**
+   * Convert from int to Int64.
+   */
+  static final NS_PER_MS:Int64 = Constants.NS_PER_MS;
+
   /**
    * Returns a precise timestamp, measured in nanoseconds.
    * Timestamp is only useful for comparing against other timestamps.
@@ -97,11 +102,11 @@ class PreciseInputManager extends FlxKeyManager<FlxKey, PreciseInputList>
     // NOTE: This timestamp isn't that precise on standard HTML5 builds.
     // This is because of browser safeguards against timing attacks.
     // See https://web.dev/coop-coep to enable headers which allow for more precise timestamps.
-    return haxe.Int64.fromFloat(js.Browser.window.performance.now() * Constants.NS_PER_MS);
+    return haxe.Int64.fromFloat(js.Browser.window.performance.now()) * NS_PER_MS;
     #elseif cpp
     // NOTE: If the game hard crashes on this line, rebuild Lime!
     // `lime rebuild windows -clean`
-    return lime._internal.backend.native.NativeCFFI.lime_sdl_get_ticks() * Constants.NS_PER_MS;
+    return lime._internal.backend.native.NativeCFFI.lime_sdl_get_ticks() * NS_PER_MS;
     #else
     throw "Eric didn't implement precise timestamps on this platform!";
     #end
diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx
index 4e8b1ce9d..297f14d69 100644
--- a/source/funkin/play/PlayState.hx
+++ b/source/funkin/play/PlayState.hx
@@ -2326,8 +2326,7 @@ class PlayState extends MusicBeatSubState
     vocals.playerVolume = 1;
 
     // Calculate the input latency (do this as late as possible).
-    var currentTimestampNs:Int64 = PreciseInputManager.getCurrentTimestamp();
-    var inputLatencyMs:Float = haxe.Int64.toInt(currentTimestampNs - input.timestamp) / Constants.NS_PER_MS;
+    var inputLatencyMs:Float = haxe.Int64.toInt(PreciseInputManager.getCurrentTimestamp() - input.timestamp) / 1000.0 / 1000.0;
     trace('Input: ${daNote.noteData.getDirectionName()} pressed ${inputLatencyMs}ms ago!');
 
     // Get the offset and compensate for input latency.