summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-22 01:25:54 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-22 01:25:54 -0500
commit89f3385f1f091415d7e7ef553f6da6f503a0db92 (patch)
tree11145f04543117610a18d43452d6b71b5e5ac657
parentaudio: change tempo -> pause_len (diff)
downloadDungeonCrawl-89f3385f1f091415d7e7ef553f6da6f503a0db92.tar.gz
DungeonCrawl-89f3385f1f091415d7e7ef553f6da6f503a0db92.tar.bz2
DungeonCrawl-89f3385f1f091415d7e7ef553f6da6f503a0db92.zip
audio: fix merge
-rw-r--r--graphics/src/audio/program.rs49
1 files changed, 29 insertions, 20 deletions
diff --git a/graphics/src/audio/program.rs b/graphics/src/audio/program.rs
index b5cc363..f5decd6 100644
--- a/graphics/src/audio/program.rs
+++ b/graphics/src/audio/program.rs
@@ -63,35 +63,44 @@ impl Program {
}
pub fn merge(self, other: Self) -> Self {
- let mut l_ins = self.ins;
- let r_ins = other.ins;
+ let mut res = vec![];
+
let mut l = 0;
let mut r = 0;
+ let l_ins = self.ins;
+ let r_ins = other.ins;
+
loop {
- if r >= r_ins.len() {
+ if l >= l_ins.len() && r >= r_ins.len() {
+ // were done here
break;
}
- let ins = r_ins[r];
- if ins == Instruction::Pause {
- // inc l until even
- loop {
- if l == l_ins.len() {
- l_ins.push(Instruction::Pause);
- break;
- }
- if l_ins[l] == Instruction::Pause {
- l += 1;
- break;
- }
- l += 1;
+
+ let mut has_pause = false;
+ while l < l_ins.len() {
+ let ins = l_ins[l];
+ l += 1;
+ if matches!(ins, Instruction::Pause) {
+ has_pause = true;
+ break;
+ }
+ res.push(ins);
+ }
+ while r < r_ins.len() {
+ let ins = r_ins[r];
+ r += 1;
+ if matches!(ins, Instruction::Pause) {
+ has_pause = true;
+ break;
}
- } else {
- l_ins.insert(l, ins);
+ res.push(ins);
+ }
+ if has_pause {
+ res.push(Instruction::Pause);
}
- r += 1;
}
- Self::new(l_ins, self.looping)
+ Self::new(res, self.looping)
}
fn exec_ins(&mut self, channels: &mut Channels, ins: Instruction) {