Calculate program connection points on updates, instead of every frame
This commit is contained in:
parent
b893f83032
commit
971c41ed2f
|
@ -13,7 +13,11 @@ import net.shadowfacts.cacao.view.View
|
|||
*/
|
||||
class ProgramCanvasView(val program: Program): View() {
|
||||
|
||||
lateinit var blocks: Map<ProgramBlock, ProgramBlockView>
|
||||
private lateinit var blocks: Map<ProgramBlock, ProgramBlockView>
|
||||
|
||||
// map of starting block to (start, end) points
|
||||
private val executionFlowStartLinks = mutableMapOf<ExecutableBlock, Pair<Point, Point>>()
|
||||
private val parameterLinks = mutableMapOf<ProgramBlock, Pair<Point, Point>>()
|
||||
|
||||
override fun wasAdded() {
|
||||
super.wasAdded()
|
||||
|
@ -26,48 +30,52 @@ class ProgramCanvasView(val program: Program): View() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun drawContent(mouse: Point, delta: Float) {
|
||||
super.drawContent(mouse, delta)
|
||||
|
||||
|
||||
for ((block, view) in blocks) {
|
||||
(block as? ExecutableBlock)?.executionFlow?.next?.let { next ->
|
||||
blocks[next]?.let { nextView ->
|
||||
val outgoing = view.outgoingExeuction!!
|
||||
val incoming = nextView.incomingExecution!!
|
||||
private fun updateBlockLinks() {
|
||||
for ((startBlock, startView) in blocks) {
|
||||
(startBlock as? ExecutableBlock)?.executionFlow?.next?.let { endBlock ->
|
||||
blocks[endBlock]?.let { endView ->
|
||||
val outgoing = startView.outgoingExeuction!!
|
||||
val incoming = endView.incomingExecution!!
|
||||
|
||||
val start = outgoing.convert(outgoing.bounds.center, to = this)
|
||||
val end = incoming.convert(outgoing.bounds.center, to = this)
|
||||
|
||||
RenderHelper.drawLine(start, end, zIndex, 5f, Color.GREEN)
|
||||
executionFlowStartLinks[startBlock] = start to end
|
||||
}
|
||||
}
|
||||
|
||||
for (input in block.inputs) {
|
||||
if (input.source == null) continue
|
||||
val source = input.source!!
|
||||
for (output in startBlock.outputs) {
|
||||
val outputView = startView.outputViews[output] ?: continue
|
||||
val start = outputView.convert(outputView.bounds.center, to = this)
|
||||
|
||||
blocks[source.block]?.let { sourceView ->
|
||||
view.inputViews[input]?.let { inputView ->
|
||||
sourceView.outputViews[source]?.let { outputView ->
|
||||
val start = inputView.convert(inputView.bounds.center, to = this)
|
||||
val end = outputView.convert(outputView.bounds.center, to = this)
|
||||
for (destination in output.destinations) {
|
||||
val endView = blocks[destination.block] ?: continue
|
||||
val inputView = endView.inputViews[destination] ?: continue
|
||||
val end = inputView.convert(inputView.bounds.center, to = this)
|
||||
|
||||
RenderHelper.drawLine(start, end, zIndex, 5f, Color.RED)
|
||||
}
|
||||
}
|
||||
parameterLinks[startBlock] = start to end
|
||||
}
|
||||
|
||||
// val start = block.position
|
||||
// val sourcePosition = source.block.position
|
||||
// val end = Point(sourcePosition.x + blocks[source.block]!!.bounds.width, sourcePosition.y)
|
||||
|
||||
// val inputView = view.inputViews[input]
|
||||
// val outputView =
|
||||
//
|
||||
// RenderHelper.drawLine(start, end, zIndex, 5f, Color.RED)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun didLayout() {
|
||||
super.didLayout()
|
||||
|
||||
// we can't calculate the link points until layout is completed and all of the views have concrete positions/sizes
|
||||
updateBlockLinks()
|
||||
}
|
||||
|
||||
override fun drawContent(mouse: Point, delta: Float) {
|
||||
super.drawContent(mouse, delta)
|
||||
|
||||
for ((start, end) in executionFlowStartLinks.values) {
|
||||
RenderHelper.drawLine(start, end, zIndex, 5f, Color.GREEN)
|
||||
}
|
||||
|
||||
for ((start, end) in parameterLinks.values) {
|
||||
RenderHelper.drawLine(start, end, zIndex, 5f, Color.RED)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue