From 151470f76d5447cee84142f5236c65510e53ea21 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 20 Apr 2024 22:58:30 +0700 Subject: [PATCH] Microdungeon placement now don't hog event loop --- .../ru/dbotthepony/kstarbound/server/world/ServerChunk.kt | 6 ++++++ .../ru/dbotthepony/kstarbound/server/world/ServerWorld.kt | 5 +++++ .../kstarbound/server/world/ServerWorldTracker.kt | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt index c535a64b..886866b4 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt @@ -2,6 +2,7 @@ package ru.dbotthepony.kstarbound.server.world import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.delay import kotlinx.coroutines.future.await import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine @@ -59,6 +60,7 @@ import kotlin.concurrent.withLock import kotlin.coroutines.cancellation.CancellationException import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException +import kotlin.math.min class ServerChunk(world: ServerWorld, pos: ChunkPos) : Chunk(world, pos) { override var state: ChunkState = ChunkState.FRESH @@ -758,6 +760,10 @@ class ServerChunk(world: ServerWorld, pos: ChunkPos) : Chunk