better loop tracking

This commit is contained in:
tildearrow 2021-12-21 02:02:25 -05:00
parent 8d8f26d4f7
commit 5523a43804
3 changed files with 21 additions and 9 deletions

View file

@ -1419,14 +1419,20 @@ void DivEngine::setLoops(int loops) {
remainingLoops=loops; remainingLoops=loops;
} }
void DivEngine::playSub() { void DivEngine::playSub(bool preserveDrift) {
reset(); reset();
if (preserveDrift && curOrder==0) return;
int goal=curOrder; int goal=curOrder;
curOrder=0; curOrder=0;
curRow=0; curRow=0;
int prevDrift=clockDrift;
clockDrift=0; clockDrift=0;
cycles=0; cycles=0;
if (preserveDrift) {
endOfSong=false;
} else {
ticks=1; ticks=1;
}
speedAB=false; speedAB=false;
playing=true; playing=true;
dispatch->setSkipRegisterWrites(true); dispatch->setSkipRegisterWrites(true);
@ -1435,14 +1441,20 @@ void DivEngine::playSub() {
} }
dispatch->setSkipRegisterWrites(false); dispatch->setSkipRegisterWrites(false);
dispatch->forceIns(); dispatch->forceIns();
if (preserveDrift) {
clockDrift=prevDrift;
} else {
clockDrift=0; clockDrift=0;
}
if (!preserveDrift) {
cycles=0; cycles=0;
ticks=1; ticks=1;
} }
}
void DivEngine::play() { void DivEngine::play() {
isBusy.lock(); isBusy.lock();
playSub(); playSub(false);
isBusy.unlock(); isBusy.unlock();
} }
@ -1682,7 +1694,7 @@ void DivEngine::setOrder(unsigned char order) {
curOrder=order; curOrder=order;
if (order>=song.ordersLen) curOrder=0; if (order>=song.ordersLen) curOrder=0;
if (playing) { if (playing) {
playSub(); playSub(false);
} }
isBusy.unlock(); isBusy.unlock();
} }

View file

@ -113,7 +113,7 @@ class DivEngine {
bool perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal); bool perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal);
void renderSamples(); void renderSamples();
void reset(); void reset();
void playSub(); void playSub(bool preserveDrift);
public: public:
DivSong song; DivSong song;

View file

@ -697,7 +697,7 @@ bool DivEngine::nextTick() {
if (--ticks<=0) { if (--ticks<=0) {
ret=endOfSong; ret=endOfSong;
if (endOfSong) { if (endOfSong) {
reset(); playSub(true);
} }
endOfSong=false; endOfSong=false;
nextRow(); nextRow();