Sequencing works
This commit is contained in:
parent
2ef584a42a
commit
912eb26652
5 changed files with 78 additions and 18 deletions
|
@ -54,15 +54,15 @@ object Level {
|
||||||
edge.nodeSeq.tail.map { to =>
|
edge.nodeSeq.tail.map { to =>
|
||||||
if(from.definition.dataType == PinType.Pull) {
|
if(from.definition.dataType == PinType.Pull) {
|
||||||
fansc.Wire(
|
fansc.Wire(
|
||||||
to.owner.position,
|
to.basePosition,
|
||||||
from.owner.position,
|
from.basePosition,
|
||||||
to.definition.voxel,
|
to.definition.voxel,
|
||||||
from.definition.voxel
|
from.definition.voxel
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
fansc.Wire(
|
fansc.Wire(
|
||||||
from.owner.position,
|
from.basePosition,
|
||||||
to.owner.position,
|
to.basePosition,
|
||||||
from.definition.voxel,
|
from.definition.voxel,
|
||||||
to.definition.voxel
|
to.definition.voxel
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,8 +14,8 @@ object Main extends IOApp {
|
||||||
override def run(args: List[String]): IO[ExitCode] = {
|
override def run(args: List[String]): IO[ExitCode] = {
|
||||||
val winBlock = Block(Position(0, 0, 0), Exists(Template(BlockDefinition.Win, true)))
|
val winBlock = Block(Position(0, 0, 0), Exists(Template(BlockDefinition.Win, true)))
|
||||||
val loseBlock = Block(Position(0, 0, 3), Exists(Template(BlockDefinition.Lose, true)))
|
val loseBlock = Block(Position(0, 0, 3), Exists(Template(BlockDefinition.Lose, true)))
|
||||||
val loseAfter = Pin(loseBlock, BlockDefinition.Lose.after)
|
val loseAfter = Pin(loseBlock.position, BlockDefinition.Lose.after)
|
||||||
val winBefore = Pin(winBlock, BlockDefinition.Win.before)
|
val winBefore = Pin(winBlock.position, BlockDefinition.Win.before)
|
||||||
val level = Level(
|
val level = Level(
|
||||||
Set(
|
Set(
|
||||||
winBlock,
|
winBlock,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package tf.bug.fancadegraph
|
package tf.bug.fancadegraph
|
||||||
|
|
||||||
|
import tf.bug.fancadescodec.Position
|
||||||
|
|
||||||
case class Pin(
|
case class Pin(
|
||||||
owner: Block,
|
basePosition: Position,
|
||||||
definition: PinDefinition
|
definition: PinDefinition
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,6 +7,11 @@ import polymorphic._
|
||||||
import tf.bug.fancadegraph.Level
|
import tf.bug.fancadegraph.Level
|
||||||
import tf.bug.fancadegraph.PinDefinition
|
import tf.bug.fancadegraph.PinDefinition
|
||||||
import tf.bug.fancadegraph.Template
|
import tf.bug.fancadegraph.Template
|
||||||
|
import tf.bug.fancadegraph.Block
|
||||||
|
import tf.bug.fancadescodec.Position
|
||||||
|
import scalax.collection.Graph
|
||||||
|
import scalax.collection.GraphEdge.DiHyperEdge
|
||||||
|
import tf.bug.fancadegraph.Pin
|
||||||
|
|
||||||
sealed trait FancadeF[A]
|
sealed trait FancadeF[A]
|
||||||
|
|
||||||
|
@ -56,25 +61,75 @@ object FancadeF {
|
||||||
i.map(original(_))
|
i.map(original(_))
|
||||||
case Combine(f) =>
|
case Combine(f) =>
|
||||||
f.flatMap(origins(_, stack))
|
f.flatMap(origins(_, stack))
|
||||||
case Sequence(_, _, n) =>
|
case Sequence(f, _, _) =>
|
||||||
origins(n, stack)
|
origins(f, stack)
|
||||||
case Noop() =>
|
case Noop() =>
|
||||||
Vector.empty
|
Vector.empty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def flatStack(vertices: Vector[FancadeF[Int]]): (Vector[Exists[Template]], Int => Option[Int]) = {
|
def filteredIndex[A](vec: Vector[A], f: A => Boolean): Vector[(A, Int)] = {
|
||||||
val blocks = vertices.collect(_ => ???)
|
vec.zipWithIndex.filter { case (e, _) => f(e) }
|
||||||
(blocks, ())._2
|
|
||||||
???
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def render(f: Fix[FancadeF]): Level = {
|
def render(f: Fix[FancadeF]): Level = {
|
||||||
val pc: PointerChain[Id, FancadeF] = PointerChain.deduplicate[Id, FancadeF](f)
|
val pc: PointerChain[Id, FancadeF] = PointerChain.deduplicate[Id, FancadeF](f)
|
||||||
val (stack, stackLookup) = flatStack(pc.vertices)
|
val pcv: Vector[FancadeF[Int]] = pc.vertices
|
||||||
(stack, ())._2
|
val bdVector: Vector[Exists[Template]] = pcv.collect {
|
||||||
(stackLookup, ())._2
|
case Create(_, template, _, _) => template
|
||||||
???
|
}
|
||||||
|
val blocks: Set[Block] = bdVector.zipWithIndex.map {
|
||||||
|
case (template, idx) =>
|
||||||
|
Block(
|
||||||
|
Position(0, idx, 0),
|
||||||
|
template
|
||||||
|
)
|
||||||
|
}.toSet
|
||||||
|
val pcf: Vector[(FancadeF[Int], Int)] = filteredIndex(pcv, (_: FancadeF[Int]) match {
|
||||||
|
case Create(_, _, _, _) => true
|
||||||
|
case _ => false
|
||||||
|
})
|
||||||
|
val pcfr: Int => Int =
|
||||||
|
idx => pcf.indexWhere { case (_, i) => i == idx }
|
||||||
|
val wires: Graph[Pin, DiHyperEdge] =
|
||||||
|
pcv.zipWithIndex.foldLeft(Graph.empty[Pin, DiHyperEdge]) {
|
||||||
|
case (graph, (entry, idx)) =>
|
||||||
|
entry match {
|
||||||
|
case Create(from, _, imports, _) =>
|
||||||
|
val thisH = pcfr(idx)
|
||||||
|
val dependencies: Vector[(Int, PinDefinition)] = from.flatMap(origins(_, pcv))
|
||||||
|
val newWires = imports.zip(dependencies).map {
|
||||||
|
case (thisPinD, (thatI, thatPinD)) =>
|
||||||
|
val thisPin = Pin(
|
||||||
|
Position(0, thisH, 0),
|
||||||
|
thisPinD
|
||||||
|
)
|
||||||
|
val thatPin = Pin(
|
||||||
|
Position(0, pcfr(thatI), 0),
|
||||||
|
thatPinD
|
||||||
|
)
|
||||||
|
DiHyperEdge(thatPin, thisPin)
|
||||||
|
}
|
||||||
|
graph ++ newWires
|
||||||
|
case Sequence(f, p, n) =>
|
||||||
|
if(pcv(n) == Noop()) graph
|
||||||
|
else {
|
||||||
|
val po = origins(f, pcv)
|
||||||
|
val to = Pin(
|
||||||
|
Position(0, pcfr(po.head._1), 0),
|
||||||
|
p
|
||||||
|
)
|
||||||
|
val fo = origins(n, pcv)
|
||||||
|
val from = Pin(
|
||||||
|
Position(0, pcfr(fo.head._1), 0),
|
||||||
|
fo.head._2
|
||||||
|
)
|
||||||
|
graph ++ Set(DiHyperEdge(from, to))
|
||||||
|
}
|
||||||
|
case _ => graph
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Level(blocks, wires)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,10 @@ object Main extends IOApp {
|
||||||
override def run[G[_]](implicit interp: Fanscript[G]): G[Unit] = {
|
override def run[G[_]](implicit interp: Fanscript[G]): G[Unit] = {
|
||||||
val screenSize = interp.screenSize
|
val screenSize = interp.screenSize
|
||||||
val screenWidth = interp.screenSizeWidth(screenSize)
|
val screenWidth = interp.screenSizeWidth(screenSize)
|
||||||
val inspectWidth = interp.inspect(screenWidth, () => interp.unit)
|
val inspectWidth = interp.inspect(screenWidth, () => {
|
||||||
|
val screenHeight = interp.screenSizeHeight(screenSize)
|
||||||
|
interp.inspect(screenHeight, () => interp.unit)
|
||||||
|
})
|
||||||
inspectWidth
|
inspectWidth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue