Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class SurfVisualizerAreaImpl(
plugin.scope.coroutineContext + SupervisorJob(plugin.scope.coroutineContext[Job])
)

private val workerJob: Job

override var settings: BlockDisplaySettings = initialSettings ?: BlockDisplaySettings.create {
blockData = SurfVisualizer.DEFAULT_BLOCK_TYPE.createBlockData()
}
Expand All @@ -53,7 +55,7 @@ class SurfVisualizerAreaImpl(
launchRecompute()
}

scope.launch {
workerJob = scope.launch {
computationChannel.consumeEach {
recompute()
}
Expand Down Expand Up @@ -100,7 +102,7 @@ class SurfVisualizerAreaImpl(
}

private suspend fun recompute() {
if (delegate.isClosed()) return
if (delegate.isClosed() || !isVisualizing()) return
val cornersSnapshot = ObjectLinkedOpenHashSet(corners)
val settingsSnapshot = settings.clone()

Expand All @@ -109,6 +111,7 @@ class SurfVisualizerAreaImpl(
if (!delegate.checkNotNullWorld()) return

currentCoroutineContext().ensureActive()
if (!isVisualizing()) return

val hull = cornersSnapshot.convexHull2D()
val edgePoints = ObjectLinkedOpenHashSet<Vector3d>()
Expand All @@ -121,6 +124,7 @@ class SurfVisualizerAreaImpl(
}

currentCoroutineContext().ensureActive()
if (!isVisualizing()) return

val finalEdgePoints: ObjectSet<Vector3d> = if (useHighestYBlock) {
edgePoints.map { it.toInt() }
Expand All @@ -132,10 +136,12 @@ class SurfVisualizerAreaImpl(
}

currentCoroutineContext().ensureActive()
if (!isVisualizing()) return

if (placeDelay.isPositive()) {
for ((i, point) in finalEdgePoints.withIndex()) {
currentCoroutineContext().ensureActive()
if (!isVisualizing()) return
delegate.addVisualLocation(point, settingsSnapshot)
if (i < finalEdgePoints.size - 1) {
delay(placeDelay)
Expand All @@ -153,7 +159,9 @@ class SurfVisualizerAreaImpl(
}

override fun stopVisualizing(): Boolean {
scope.coroutineContext[Job]?.children?.forEach { it.cancel() }
scope.coroutineContext[Job]?.children?.forEach { child ->
if (child !== workerJob) child.cancel()
}
return delegate.stopVisualizing()
}

Expand Down