Skip to content

FabricatePassGraphTestMain.kt

src/jvmMain/kotlin/afield/graphics/scene/fabricated/FabricatePassGraphTestMain.kt · 54 lines

package afield.graphics.scene.fabricated

object FabricatePassGraphTestMain

Tiny JVM smoke test for the pure ordered-pass data structure behind FabricateFrameGraph. Run with the backdoor's run-jvm-main or any JVM launcher that includes jvmMain classes.

fun main(args: Array<String>)

body — 46 lines, from line 8
    @JvmStatic
    fun main(args: Array<String>) {
        val stack = listOf("scene" to "S", "taa" to "T", "display" to "D", "bloom" to "B")
        val chainNames = setOf("taa", "display")
        check(inputBeforeReplacement(emptyList(), chainNames, "input") == "input")
        check(inputBeforeReplacement(stack, setOf("new"), "input") == "B")
        check(inputBeforeReplacement(stack, chainNames, "input") == "S")
        check(inputBeforeReplacement(stack, setOf("scene"), "input") == "input")
        check(inputBeforeReplacement(stack, setOf("display"), "input") == "T")
        val replaced = stack.map { (name, value) -> name to if (name in chainNames) "new-$value" else value }
        check(inputBeforeReplacement(replaced, chainNames, "input") == "S")

        val graph = FabricatePassGraph<String>(
            listOf(
                "gbuffer" to "G",
                "lighting" to "L",
                "aa" to "A"
            )
        )

        check(graph.names() == listOf("gbuffer", "lighting", "aa")) {
            "initial order was ${graph.names()}"
        }

        graph.insertAfter("bloom", "lighting", "B")
        check(graph.names() == listOf("gbuffer", "lighting", "bloom", "aa")) {
            "insertAfter order was ${graph.names()}"
        }

        graph.insertBefore("shadow", "gbuffer", "S")
        check(graph.names() == listOf("shadow", "gbuffer", "lighting", "bloom", "aa")) {
            "insertBefore order was ${graph.names()}"
        }

        graph.replace("bloom", "B2")
        check(graph["bloom"] == "B2") { "replace did not update bloom" }

        val removed = graph.remove("lighting")
        check(removed == "L") { "remove returned $removed" }
        check(graph.names() == listOf("shadow", "gbuffer", "bloom", "aa")) {
            "remove order was ${graph.names()}"
        }

        println("FabricatePassGraphTestMain ok: ${graph.names().joinToString(" -> ")}")
    }
}