diff --git a/samples/software3d/build.gradle.kts b/samples/software3d/build.gradle.kts index 8b4f1ccbb..a5d0e257d 100644 --- a/samples/software3d/build.gradle.kts +++ b/samples/software3d/build.gradle.kts @@ -39,6 +39,7 @@ teavm.wasm { mainClass = "org.teavm.samples.software3d.teavm.WasmWorkerKt" optimization = OptimizationLevel.AGGRESSIVE minHeapSize = 4 + maxHeapSize = 32 } kotlin { diff --git a/samples/software3d/src/commonMain/kotlin/org/teavm/samples/software3d/rasterization/Raster.kt b/samples/software3d/src/commonMain/kotlin/org/teavm/samples/software3d/rasterization/Raster.kt index bf12d3b81..fd91d9508 100644 --- a/samples/software3d/src/commonMain/kotlin/org/teavm/samples/software3d/rasterization/Raster.kt +++ b/samples/software3d/src/commonMain/kotlin/org/teavm/samples/software3d/rasterization/Raster.kt @@ -34,4 +34,8 @@ class Raster(@JvmField val width: Int, @JvmField val height: Int) { color = IntArray(width * height) return result } + + companion object { + fun calculateHeight(height: Int, step: Int, offset: Int): Int = ((height + step - 2 - offset) / step) + 1 + } } \ No newline at end of file diff --git a/samples/software3d/src/commonMain/kotlin/org/teavm/samples/software3d/rasterization/Rasterizer.kt b/samples/software3d/src/commonMain/kotlin/org/teavm/samples/software3d/rasterization/Rasterizer.kt index c15895f28..a9cb0ec4a 100644 --- a/samples/software3d/src/commonMain/kotlin/org/teavm/samples/software3d/rasterization/Rasterizer.kt +++ b/samples/software3d/src/commonMain/kotlin/org/teavm/samples/software3d/rasterization/Rasterizer.kt @@ -104,7 +104,7 @@ class Rasterizer(val raster: Raster, val offset: Int, val step: Int) { val ex = s2.pos.x + d2x * k2 val startIntX = ceil(sx).toInt().coerceAtLeast(0) val endIntX = ceil(ex).toInt().coerceAtMost(raster.width) - if (startIntX + 1 == endIntX || startIntX >= raster.width || endIntX <= 0) { + if (startIntX >= endIntX || startIntX >= raster.width || endIntX <= 0) { y += step continue } diff --git a/samples/software3d/src/jsMain/kotlin/org/teavm/samples/software3d/kjs/worker.kt b/samples/software3d/src/jsMain/kotlin/org/teavm/samples/software3d/kjs/worker.kt index 6acbd33d0..92db10a01 100644 --- a/samples/software3d/src/jsMain/kotlin/org/teavm/samples/software3d/kjs/worker.kt +++ b/samples/software3d/src/jsMain/kotlin/org/teavm/samples/software3d/kjs/worker.kt @@ -42,7 +42,7 @@ private fun init(data: dynamic) { val step = data.step as Int val offset = data.offset as Int val (scene, updaterF) = geometry() - raster = Raster(width, height / step) + raster = Raster(width, Raster.calculateHeight(height, step, offset)) updater = updaterF renderer = Renderer(scene, raster, offset, step).apply { projection = Matrix.projection(-1f, 1f, -1f, 1f, 2f, 10f) diff --git a/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/swing/swingMain.kt b/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/swing/swingMain.kt index 0a78822d2..57edfee00 100644 --- a/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/swing/swingMain.kt +++ b/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/swing/swingMain.kt @@ -47,10 +47,10 @@ fun main() { } val (scene, updater) = geometry() - val taskCount = Runtime.getRuntime().availableProcessors() + val taskCount = 1// Runtime.getRuntime().availableProcessors() println("Running on $taskCount CPUs") - val rasters = (0 until taskCount).map { Raster(SCENE_WIDTH, SCENE_HEIGHT / taskCount) } - val renderers = rasters.mapIndexed() { index, raster -> + val rasters = (0 until taskCount).map { Raster(SCENE_WIDTH, (SCENE_HEIGHT + taskCount - 1) / taskCount) } + val renderers = rasters.mapIndexed { index, raster -> Renderer(scene, raster, index, taskCount).apply { projection = Matrix.projection(-1f, 1f, -1f, 1f, 2f, 10f) viewport = Matrix.translation(SCENE_WIDTH / 2f, SCENE_HEIGHT / 2f, 0f) * diff --git a/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/teavm/WasmWorker.kt b/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/teavm/WasmWorker.kt index 4e218eb9f..eaf484807 100644 --- a/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/teavm/WasmWorker.kt +++ b/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/teavm/WasmWorker.kt @@ -31,7 +31,7 @@ fun main() { @Export(name = "initWorker") fun init(width: Int, height: Int, step: Int, offset: Int) { val (scene, updaterF) = geometry() - raster = Raster(width, height / step) + raster = Raster(width, Raster.calculateHeight(height, step, offset)) updater = updaterF renderer = Renderer(scene, raster, offset, step).apply { projection = Matrix.projection(-1f, 1f, -1f, 1f, 2f, 10f) diff --git a/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/teavm/Worker.kt b/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/teavm/Worker.kt index 47baf9a30..3bf045e98 100644 --- a/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/teavm/Worker.kt +++ b/samples/software3d/src/jvmMain/kotlin/org/teavm/samples/software3d/teavm/Worker.kt @@ -49,7 +49,7 @@ class RenderWorker { height = (params["height"] as JSNumber).intValue() val step = (params["step"] as JSNumber).intValue() val offset = (params["offset"] as JSNumber).intValue() - raster = Raster(width, height / step) + raster = Raster(width, Raster.calculateHeight(height, step, offset)) updater = updaterF renderer = Renderer(scene, raster, offset, step).apply { projection = Matrix.projection(-1f, 1f, -1f, 1f, 2f, 10f)