v1.0.1: fixed graphics stutter when tracks are switched

This commit is contained in:
Evan Debenham 2021-08-20 20:13:58 -04:00
parent 46635bbd9c
commit 69f122d449

View File

@ -29,6 +29,9 @@ import com.watabou.utils.Random;
import java.awt.MediaTracker;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public enum Music {
@ -130,22 +133,29 @@ public enum Music {
return;
}
stop();
//we do this in a separate thread to avoid graphics hitching while the music is prepared
//FIXME this fixes graphics stutter but there's still some audio stutter, perhaps keep more than 1 player alive?
new Thread(){
@Override
public void run() {
Music.this.stop();
if (trackQueue.isEmpty()){
for (int i = 0; i < trackList.length; i++){
if (Random.Float() < trackChances[i]){
trackQueue.add(trackList[i]);
if (trackQueue.isEmpty()){
for (int i = 0; i < trackList.length; i++){
if (Random.Float() < trackChances[i]){
trackQueue.add(trackList[i]);
}
}
if (shuffle) Collections.shuffle(trackQueue);
}
if (!enabled || trackQueue.isEmpty()){
return;
}
play(trackQueue.remove(0), trackLooper);
}
if (shuffle) Collections.shuffle(trackQueue);
}
if (!enabled || trackQueue.isEmpty()){
return;
}
play(trackQueue.remove(0), trackLooper);
}.start();
}
};