faaster
This commit is contained in:
parent
595b1c5e69
commit
7a69dee5ca
@ -38,21 +38,47 @@ data class RenderRuleList(
|
||||
val matchHue: Boolean = false,
|
||||
val inverse: Boolean = false,
|
||||
) {
|
||||
private fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
|
||||
return when (type) {
|
||||
"EqualsSelf" -> equalityTester.test(getter.getTile(thisPos), getter.getTile(thisPos + offsetPos))
|
||||
"Connects" -> getter.getTile(thisPos + offsetPos).material != null
|
||||
private fun interface ActualTester {
|
||||
fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean
|
||||
}
|
||||
|
||||
private object EqualsSelf : ActualTester {
|
||||
override fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
|
||||
return equalityTester.test(getter.getTile(thisPos), getter.getTile(thisPos + offsetPos))
|
||||
}
|
||||
}
|
||||
|
||||
private object Conntects : ActualTester {
|
||||
override fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
|
||||
return getter.getTile(thisPos + offsetPos).material != null
|
||||
}
|
||||
}
|
||||
|
||||
private object Never : ActualTester {
|
||||
override fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
private val actualTester by lazy {
|
||||
when (type) {
|
||||
"EqualsSelf" -> EqualsSelf
|
||||
"Connects" -> Conntects
|
||||
|
||||
else -> {
|
||||
if (LOGGED.add(type)) {
|
||||
LOGGER.error("Unknown render rule test $type!")
|
||||
}
|
||||
|
||||
false
|
||||
Never
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun doTest(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
|
||||
return actualTester.doTest(getter, equalityTester, thisPos, offsetPos)
|
||||
}
|
||||
|
||||
fun test(getter: ITileAccess, equalityTester: EqualityRuleTester, thisPos: Vector2i, offsetPos: Vector2i): Boolean {
|
||||
if (inverse) {
|
||||
return !doTest(getter, equalityTester, thisPos, offsetPos)
|
||||
|
Loading…
Reference in New Issue
Block a user