Refactor execution flow
This commit is contained in:
parent
233a83f368
commit
2ffda7b4e3
|
@ -7,7 +7,7 @@ import net.minecraft.util.Identifier
|
|||
*/
|
||||
abstract class ExecutableBlock(identifier: Identifier): ProgramBlock(identifier) {
|
||||
|
||||
open val executionFlow = ExecutionFlow(this)
|
||||
abstract val executionFlow: ExecutionFlow
|
||||
|
||||
abstract fun execute()
|
||||
|
||||
|
|
|
@ -3,14 +3,20 @@ package net.shadowfacts.asmr.program
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
open class ExecutionFlow(val block: ExecutableBlock) {
|
||||
interface ExecutionFlow {
|
||||
val block: ExecutableBlock
|
||||
|
||||
open var next: ExecutableBlock? = null
|
||||
open var prev: ExecutableBlock? = null
|
||||
val next: ExecutableBlock?
|
||||
val prev: ExecutableBlock?
|
||||
}
|
||||
class DirectExecutionFlow(override val block: ExecutableBlock): ExecutionFlow {
|
||||
override var next: ExecutableBlock? = null
|
||||
override var prev: ExecutableBlock? = null
|
||||
|
||||
fun link(next: ExecutableBlock) {
|
||||
this.next = next
|
||||
next.executionFlow.prev = block
|
||||
(next.executionFlow as? DirectExecutionFlow)?.let {
|
||||
it.prev = block
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ class PrintBlock<Type: Any>(
|
|||
override val inputs: Array<ProgramBlockInput<*>> = arrayOf(input)
|
||||
override val outputs: Array<ProgramBlockOutput<*>> = arrayOf()
|
||||
|
||||
override val executionFlow = DirectExecutionFlow(this)
|
||||
|
||||
override fun execute() {
|
||||
println(input.value)
|
||||
}
|
||||
|
|
|
@ -2,9 +2,7 @@ package net.shadowfacts.asmr.program.blocks
|
|||
|
||||
import net.minecraft.util.Identifier
|
||||
import net.shadowfacts.asmr.ASMR
|
||||
import net.shadowfacts.asmr.program.ExecutableBlock
|
||||
import net.shadowfacts.asmr.program.ProgramBlockInput
|
||||
import net.shadowfacts.asmr.program.ProgramBlockOutput
|
||||
import net.shadowfacts.asmr.program.*
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
|
@ -16,6 +14,8 @@ class StartBlock: ExecutableBlock(
|
|||
override val inputs: Array<ProgramBlockInput<*>> = arrayOf()
|
||||
override val outputs: Array<ProgramBlockOutput<*>> = arrayOf()
|
||||
|
||||
override val executionFlow = DirectExecutionFlow(this)
|
||||
|
||||
override fun execute() {
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,7 @@ package net.shadowfacts.asmr.program.blocks.math
|
|||
|
||||
import net.minecraft.util.Identifier
|
||||
import net.shadowfacts.asmr.ASMR
|
||||
import net.shadowfacts.asmr.program.ExecutableBlock
|
||||
import net.shadowfacts.asmr.program.ProgramBlockInput
|
||||
import net.shadowfacts.asmr.program.ProgramBlockOutput
|
||||
import net.shadowfacts.asmr.program.ProgramType
|
||||
import net.shadowfacts.asmr.program.*
|
||||
import java.lang.RuntimeException
|
||||
|
||||
/**
|
||||
|
@ -32,6 +29,8 @@ class BinaryOperatorBlock<Type: Any>(
|
|||
override val inputs: Array<ProgramBlockInput<*>> = arrayOf(left, right)
|
||||
override val outputs: Array<ProgramBlockOutput<*>> = arrayOf(output)
|
||||
|
||||
override val executionFlow = DirectExecutionFlow(this)
|
||||
|
||||
override fun execute() {
|
||||
if (type == ProgramType.INT) {
|
||||
val left = left.value as Int
|
||||
|
|
Loading…
Reference in New Issue