From c7980d90689ec4e45af6d6bb9e07314f25f53646 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 21 Feb 2023 18:31:02 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D1=83=D0=B5=D0=BC=20=D0=B2=D1=80=D0=B5=D0=BC=D1=8F=20JVM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbotthepony/kstarbound/client/StarboundClient.kt | 6 +++--- .../dbotthepony/kstarbound/client/gl/GLStateTracker.kt | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt index 4db0a9e0..b5d07af1 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt @@ -363,7 +363,7 @@ class StarboundClient(val starbound: Starbound) : Closeable { return true } - val measure = GLFW.glfwGetTime() + val measure = JVMTimeSource.INSTANCE.seconds if (frameRenderTime != 0.0 && starbound.initialized) world?.think(frameRenderTime) @@ -438,11 +438,11 @@ class StarboundClient(val starbound: Starbound) : Closeable { GLFW.glfwPollEvents() input.think() - camera.think(GLFW.glfwGetTime() - measure) + camera.think(JVMTimeSource.INSTANCE.seconds - measure) gl.cleanup() - frameRenderTime = GLFW.glfwGetTime() - measure + frameRenderTime = JVMTimeSource.INSTANCE.seconds - measure frameRenderTimes[++frameRenderIndex % frameRenderTimes.size] = frameRenderTime return true diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLStateTracker.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLStateTracker.kt index 5e3e4677..571126cc 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLStateTracker.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLStateTracker.kt @@ -25,6 +25,7 @@ import java.io.File import java.io.FileNotFoundException import java.lang.ref.Cleaner import java.util.concurrent.ThreadFactory +import java.util.concurrent.atomic.AtomicLong import kotlin.collections.ArrayList import kotlin.collections.HashMap import kotlin.properties.ReadWriteProperty @@ -151,7 +152,12 @@ class GLStateTracker(val locator: ISBFileLocator) { private val cleanerBacklog = ArrayList<() -> Unit>() - var objectsCleaned = 0 + @Volatile + var objectsCleaned = 0L + private set + + @Volatile + var gcHits = 0L private set private val cleaner = Cleaner.create(object : ThreadFactory { @@ -170,6 +176,8 @@ class GLStateTracker(val locator: ISBFileLocator) { fn(nativeRef) checkForGLError() } else { + gcHits++ + synchronized(cleanerBacklog) { cleanerBacklog.add { fn(nativeRef)