From b1b5b598f037ae8f5a5948afc4b18e967d124dc0 Mon Sep 17 00:00:00 2001
From: DBotThePony <dbotthepony@yandex.ru>
Date: Wed, 18 Oct 2023 22:25:49 +0700
Subject: [PATCH] preciseWait flag on client

---
 .../kstarbound/client/StarboundClient.kt      | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt
index 7a4caa2e..2d461087 100644
--- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt
+++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt
@@ -139,6 +139,8 @@ class StarboundClient : Closeable {
 
 	var fullbright = true
 
+	var preciseWait = false
+
 	var clientTerminated = false
 		private set
 
@@ -741,14 +743,17 @@ class StarboundClient : Closeable {
 		// try to sleep until next frame as precise as possible
 		while (diff > 0L) {
 			executeQueuedTasks()
-
-			if (diff >= 1_500_000L) {
-				LockSupport.parkNanos(1_000_000L)
-			} else {
-				Thread.yield()
-			}
-
 			diff = nextRender - System.nanoTime()
+
+			if (preciseWait) {
+				if (diff >= 1_500_000L) {
+					LockSupport.parkNanos(1_000_000L)
+				} else {
+					Thread.yield()
+				}
+			} else {
+				LockSupport.parkNanos(diff)
+			}
 		}
 
 		val mark = System.nanoTime()