mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
fix some potential dead locks
This commit is contained in:
parent
0eb265aebb
commit
5ca8e057f6
@ -134,7 +134,7 @@ Support for macOS is a delicate topic. Let's say it works for now, but it is not
|
||||
|
||||
Using IntelliJ IDEA for building or developing is strongly recommended. There you have features like build caching.
|
||||
If you run into errors, please ensure you have the latest version of it.
|
||||
You might need to increase heap memory for the compiler (`File` -> `Settings` -> `Build, Execution and Compiler` -> `Compiler` -> `Shared build process heap size`).
|
||||
You might need to increase heap memory for the compiler (`File` -> `Settings` -> `Build, Execution, Deployment` -> `Compiler` -> `Shared build process heap size`).
|
||||
Allow at least 1500 MBytes.
|
||||
|
||||
## Code mirrors
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger and contributors
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -17,11 +17,9 @@ import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.array.ArrayUtil.cast
|
||||
import de.bixilon.kutil.collections.map.LockMap
|
||||
import de.bixilon.kutil.concurrent.lock.simple.SimpleLock
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.concurrent.pool.ThreadPool
|
||||
import de.bixilon.kutil.concurrent.pool.ThreadPoolRunnable
|
||||
import de.bixilon.kutil.concurrent.worker.TaskWorker
|
||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||
import de.bixilon.kutil.concurrent.worker.tasks.Task
|
||||
import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
|
||||
import de.bixilon.minosoft.data.Difficulties
|
||||
import de.bixilon.minosoft.data.entities.block.BlockEntity
|
||||
@ -36,6 +34,7 @@ import de.bixilon.minosoft.data.world.biome.accessor.BiomeAccessor
|
||||
import de.bixilon.minosoft.data.world.biome.accessor.NoiseBiomeAccessor
|
||||
import de.bixilon.minosoft.data.world.border.WorldBorder
|
||||
import de.bixilon.minosoft.data.world.chunk.Chunk
|
||||
import de.bixilon.minosoft.data.world.chunk.light.SectionLight
|
||||
import de.bixilon.minosoft.data.world.particle.AbstractParticleRenderer
|
||||
import de.bixilon.minosoft.data.world.particle.WorldParticleRenderer
|
||||
import de.bixilon.minosoft.data.world.positions.BlockPosition
|
||||
@ -281,18 +280,17 @@ class World(
|
||||
val simulationDistance = view.simulationDistance
|
||||
val cameraPosition = connection.player.positionInfo.chunkPosition
|
||||
chunks.lock.acquire()
|
||||
val latch = CountUpAndDownLatch(chunks.unsafe.size)
|
||||
val worker = TaskWorker()
|
||||
for ((chunkPosition, chunk) in chunks.unsafe) {
|
||||
// ToDo: Cache (improve performance)
|
||||
if (!chunkPosition.isInViewDistance(simulationDistance, cameraPosition)) {
|
||||
latch.dec()
|
||||
continue
|
||||
}
|
||||
DefaultThreadPool += ThreadPoolRunnable(priority = ThreadPool.HIGH) { chunk.tick(connection, chunkPosition); latch.dec() }
|
||||
worker += Task(priority = ThreadPool.HIGH) { chunk.tick(connection, chunkPosition) }
|
||||
}
|
||||
chunks.lock.release()
|
||||
worker.work()
|
||||
border.tick()
|
||||
latch.await()
|
||||
}
|
||||
|
||||
fun randomTick() {
|
||||
@ -406,7 +404,7 @@ class World(
|
||||
|
||||
fun getBrightness(position: BlockPosition): Float {
|
||||
val light = getLight(position)
|
||||
val level = maxOf(light and 0x0F, light and 0xF0 shr 4)
|
||||
val level = maxOf(light and SectionLight.BLOCK_LIGHT_MASK, light and SectionLight.SKY_LIGHT_MASK shr 4)
|
||||
return dimension?.lightLevels?.get(level) ?: 0.0f
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,9 @@ package de.bixilon.minosoft.data.world
|
||||
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kutil.concurrent.lock.simple.SimpleLock
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.concurrent.pool.ThreadPool
|
||||
import de.bixilon.kutil.concurrent.pool.ThreadPoolRunnable
|
||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||
import de.bixilon.kutil.concurrent.worker.TaskWorker
|
||||
import de.bixilon.kutil.concurrent.worker.tasks.Task
|
||||
import de.bixilon.minosoft.data.abilities.Gamemodes
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||
import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
|
||||
@ -185,12 +184,12 @@ class WorldEntities : Iterable<Entity> {
|
||||
|
||||
fun tick() {
|
||||
lock.acquire()
|
||||
val latch = CountUpAndDownLatch(entities.size)
|
||||
val worker = TaskWorker()
|
||||
for (entity in entities) {
|
||||
DefaultThreadPool += ThreadPoolRunnable(priority = ThreadPool.Priorities.HIGH) { entity.tryTick(); latch.dec() }
|
||||
worker += Task(priority = ThreadPool.Priorities.HIGH) { entity.tryTick() }
|
||||
}
|
||||
lock.release()
|
||||
latch.await()
|
||||
worker.work()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -14,7 +14,6 @@
|
||||
package de.bixilon.minosoft.data.world.weather
|
||||
|
||||
class WorldWeather {
|
||||
|
||||
var raining = false
|
||||
var rainGradient = 0.0f
|
||||
var thunderGradient = 0.0f
|
||||
|
@ -15,9 +15,9 @@ package de.bixilon.minosoft.gui.rendering.renderer.renderer
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.collections.CollectionUtil.synchronizedMapOf
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.concurrent.pool.ThreadPool
|
||||
import de.bixilon.kutil.concurrent.pool.ThreadPoolRunnable
|
||||
import de.bixilon.kutil.concurrent.worker.TaskWorker
|
||||
import de.bixilon.kutil.concurrent.worker.tasks.Task
|
||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||
import de.bixilon.minosoft.config.profile.ConnectionProfiles
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
@ -64,38 +64,34 @@ class RendererManager(
|
||||
}
|
||||
|
||||
fun init(latch: CountUpAndDownLatch) {
|
||||
val inner = CountUpAndDownLatch(1, latch)
|
||||
val inner = CountUpAndDownLatch(0, latch)
|
||||
var worker = TaskWorker()
|
||||
for (renderer in renderers.values) {
|
||||
inner.inc()
|
||||
DefaultThreadPool += { renderer.preAsyncInit(inner); inner.dec() }
|
||||
worker += { renderer.preAsyncInit(inner) }
|
||||
}
|
||||
inner.dec()
|
||||
inner.await()
|
||||
worker.work(inner)
|
||||
|
||||
for (renderer in renderers.values) {
|
||||
renderer.init(latch)
|
||||
renderer.init(inner)
|
||||
}
|
||||
|
||||
val inner2 = CountUpAndDownLatch(1, latch)
|
||||
worker = TaskWorker()
|
||||
for (renderer in renderers.values) {
|
||||
inner2.inc()
|
||||
DefaultThreadPool += { renderer.asyncInit(inner2); inner2.dec() }
|
||||
worker += { renderer.asyncInit(inner) }
|
||||
}
|
||||
inner2.dec()
|
||||
inner2.await()
|
||||
worker.work(inner)
|
||||
}
|
||||
|
||||
fun postInit(latch: CountUpAndDownLatch) {
|
||||
for (renderer in renderers.values) {
|
||||
renderer.postInit(latch)
|
||||
}
|
||||
val inner = CountUpAndDownLatch(1, latch)
|
||||
val inner = CountUpAndDownLatch(0, latch)
|
||||
val worker = TaskWorker()
|
||||
for (renderer in renderers.values) {
|
||||
inner.inc()
|
||||
DefaultThreadPool += { renderer.postAsyncInit(inner); inner.dec() }
|
||||
worker += { renderer.postAsyncInit(inner) }
|
||||
}
|
||||
inner.dec()
|
||||
inner.await()
|
||||
worker.work(inner)
|
||||
}
|
||||
|
||||
private fun renderNormal(rendererList: Collection<Renderer>) {
|
||||
@ -123,16 +119,15 @@ class RendererManager(
|
||||
renderer.prePrepareDraw()
|
||||
}
|
||||
|
||||
val latch = CountUpAndDownLatch(1)
|
||||
val latch = CountUpAndDownLatch(0)
|
||||
val worker = TaskWorker()
|
||||
for (renderer in rendererList) {
|
||||
if (renderer !is AsyncRenderer) {
|
||||
continue
|
||||
}
|
||||
latch.inc()
|
||||
DefaultThreadPool += ThreadPoolRunnable(priority = ThreadPool.HIGHER) { renderer.prepareDrawAsync(); latch.dec() }
|
||||
worker += Task(priority = ThreadPool.HIGHER) { renderer.prepareDrawAsync() }
|
||||
}
|
||||
latch.dec()
|
||||
latch.await()
|
||||
worker.work(latch)
|
||||
|
||||
for (renderer in rendererList) {
|
||||
renderer.postPrepareDraw()
|
||||
|
Loading…
x
Reference in New Issue
Block a user