Microdungeon placement now don't hog event loop
This commit is contained in:
parent
5c13567fed
commit
151470f76d
src/main/kotlin/ru/dbotthepony/kstarbound/server/world
@ -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<ServerWorld, ServerChunk>(world, pos) {
|
||||
override var state: ChunkState = ChunkState.FRESH
|
||||
@ -758,6 +760,10 @@ class ServerChunk(world: ServerWorld, pos: ChunkPos) : Chunk<ServerWorld, Server
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
// some breathing room for other code, since placement checking is performance intense operation
|
||||
if (!world.isInPreparation && world.clients.isNotEmpty())
|
||||
delay(min(60L, anchor.reader.size.x * anchor.reader.size.y / 100L))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -306,8 +306,12 @@ class ServerWorld private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
var isInPreparation = false
|
||||
private set
|
||||
|
||||
private suspend fun prepare0() {
|
||||
try {
|
||||
isInPreparation = true
|
||||
isBusy++
|
||||
|
||||
val random = random(template.seed)
|
||||
@ -362,6 +366,7 @@ class ServerWorld private constructor(
|
||||
}
|
||||
} finally {
|
||||
isBusy--
|
||||
isInPreparation = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,9 +352,9 @@ class ServerWorldTracker(val world: ServerWorld, val client: ServerConnection, p
|
||||
// instantly added back because new world rejected us
|
||||
world.eventLoop.execute { remove0() }
|
||||
|
||||
scope.cancel()
|
||||
damageTilesQueue.close()
|
||||
modifyTilesQueue.close()
|
||||
scope.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user