shithub: dumb

Download patch

ref: b9aea1412d1645766b9373c432ac498abed34b63
parent: a42b6bcdc28e200a751baf4414e6f4c6ebb36c71
author: Chris Moeller <kode54@gmail.com>
date: Wed Jul 17 14:53:55 EDT 2013

Further fixes to IT envelope behavior

--- a/dumb/src/it/itrender.c
+++ b/dumb/src/it/itrender.c
@@ -3845,26 +3845,27 @@
 	}
 
 	pe->tick++;
-	while (pe->tick > envelope->node_t[pe->next_node]) {
-		pe->next_node++;
-		if ((envelope->flags & IT_ENVELOPE_SUSTAIN_LOOP) && !(playing->flags & IT_PLAYING_SUSTAINOFF)) {
-			if (pe->next_node > envelope->sus_loop_end) {
-				pe->next_node = envelope->sus_loop_start;
-				ASSERT(pe->next_node < envelope->n_nodes);
-				pe->tick = envelope->node_t[envelope->sus_loop_start];
-				return 0;
-			}
-		} else if (envelope->flags & IT_ENVELOPE_LOOP_ON) {
-			if (pe->next_node > envelope->loop_end) {
-				pe->next_node = envelope->loop_start;
-				ASSERT(pe->next_node < envelope->n_nodes);
-				pe->tick = envelope->node_t[envelope->loop_start];
-				return 0;
-			}
+
+	recalculate_it_envelope_node(pe, envelope);
+
+	if ((envelope->flags & IT_ENVELOPE_SUSTAIN_LOOP) && !(playing->flags & IT_PLAYING_SUSTAINOFF)) {
+		if (pe->tick >= envelope->node_t[envelope->sus_loop_end]) {
+			pe->next_node = envelope->sus_loop_start;
+			ASSERT(pe->next_node < envelope->n_nodes);
+			pe->tick = envelope->node_t[envelope->sus_loop_start];
+			return 0;
 		}
-		if (pe->next_node >= envelope->n_nodes)
+	} else if (envelope->flags & IT_ENVELOPE_LOOP_ON) {
+		if (pe->tick >= envelope->node_t[envelope->loop_end]) {
+			pe->next_node = envelope->loop_start;
+			ASSERT(pe->next_node < envelope->n_nodes);
+			pe->tick = envelope->node_t[envelope->loop_start];
 			return 0;
+		}
 	}
+	else if (pe->tick >= envelope->node_t[envelope->n_nodes - 1])
+		return 1;
+
 	return 0;
 }