mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
samples: fix issues in software3d
This commit is contained in:
parent
57c22ab2c8
commit
ef359c3604
|
@ -39,6 +39,7 @@ teavm.wasm {
|
|||
mainClass = "org.teavm.samples.software3d.teavm.WasmWorkerKt"
|
||||
optimization = OptimizationLevel.AGGRESSIVE
|
||||
minHeapSize = 4
|
||||
maxHeapSize = 32
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) *
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user