Pre-compute end-chains-same-track set, remove per-block trigger scan

This commit is contained in:
Ian Gulliver
2026-02-20 16:58:42 -07:00
parent f12ef296aa
commit a7e831cfab

View File

@@ -126,7 +126,20 @@ func BuildTimeline(show Show) (Timeline, error) {
tl.Blocks[block.ID] = block tl.Blocks[block.ID] = block
} }
tl.buildCells() endChains := map[string]bool{}
for _, trigger := range show.Triggers {
if trigger.Source.Signal != "END" {
continue
}
srcTrack := tl.Blocks[trigger.Source.Block].Track
for _, target := range trigger.Targets {
if target.Hook == "START" && tl.Blocks[target.Block].Track == srcTrack {
endChains[trigger.Source.Block] = true
}
}
}
tl.buildCells(endChains)
tl.buildConstraints() tl.buildConstraints()
tl.assignRows() tl.assignRows()
@@ -173,22 +186,7 @@ func (tl *Timeline) findCell(blockID, event string) *TimelineCell {
panic("cell not found: " + blockID + " " + event) panic("cell not found: " + blockID + " " + event)
} }
func (tl *Timeline) endChainsSameTrack(blockID string) bool { func (tl *Timeline) buildCells(endChains map[string]bool) {
trackID := tl.Blocks[blockID].Track
for _, trigger := range tl.show.Triggers {
if trigger.Source.Block != blockID || trigger.Source.Signal != "END" {
continue
}
for _, target := range trigger.Targets {
if target.Hook == "START" && tl.Blocks[target.Block].Track == trackID {
return true
}
}
}
return false
}
func (tl *Timeline) buildCells() {
for _, sb := range tl.show.Blocks { for _, sb := range tl.show.Blocks {
block := tl.Blocks[sb.ID] block := tl.Blocks[sb.ID]
track := tl.trackIdx[block.Track] track := tl.trackIdx[block.Track]
@@ -200,7 +198,7 @@ func (tl *Timeline) buildCells() {
cells = getBlockCells(block) cells = getBlockCells(block)
} }
track.appendCells(cells...) track.appendCells(cells...)
if block.Type != "cue" && !tl.endChainsSameTrack(block.ID) { if block.Type != "cue" && !endChains[block.ID] {
track.appendCells(&TimelineCell{IsGap: true, IsBreak: true}) track.appendCells(&TimelineCell{IsGap: true, IsBreak: true})
} }
} }
@@ -211,7 +209,6 @@ func (tl *Timeline) buildConstraints() {
source := tl.findCell(trigger.Source.Block, trigger.Source.Signal) source := tl.findCell(trigger.Source.Block, trigger.Source.Signal)
group := exclusiveGroup{members: []*TimelineCell{source}} group := exclusiveGroup{members: []*TimelineCell{source}}
hasCrossTrack := false
for _, target := range trigger.Targets { for _, target := range trigger.Targets {
t := tl.findCell(target.Block, target.Hook) t := tl.findCell(target.Block, target.Hook)
@@ -219,14 +216,10 @@ func (tl *Timeline) buildConstraints() {
tl.addConstraint("next_row", source, t) tl.addConstraint("next_row", source, t)
} else { } else {
tl.addConstraint("same_row", source, t) tl.addConstraint("same_row", source, t)
hasCrossTrack = true source.IsSignal = true
} }
group.members = append(group.members, t) group.members = append(group.members, t)
} }
if hasCrossTrack {
source.IsSignal = true
}
tl.exclusives = append(tl.exclusives, group) tl.exclusives = append(tl.exclusives, group)
} }
} }