moar optimizations! (hopefully...)

This commit is contained in:
Harrison Deng 2017-12-07 19:13:43 -06:00
parent a858fa9159
commit 6f59e2f236
3 changed files with 23 additions and 11 deletions

View File

@ -31,6 +31,9 @@ public class MusicInfoController implements Disposable {
*/ */
public void loadSongInfo() { public void loadSongInfo() {
doneLoading = false; doneLoading = false;
for (int i = 0; i < songInfoArray.size; i++) {
songInfoArray.get(i).dispose();
}
songInfoArray.clear(); songInfoArray.clear();
exec.submit(() -> { exec.submit(() -> {
for (int i = 0; i < musicList.getAmountOfMusic(); i++) { for (int i = 0; i < musicList.getAmountOfMusic(); i++) {
@ -54,4 +57,8 @@ public class MusicInfoController implements Disposable {
public synchronized boolean isDoneLoading() { public synchronized boolean isDoneLoading() {
return doneLoading; return doneLoading;
} }
public Array<MusicInfo> getSongInfoArray() {
return songInfoArray;
}
} }

View File

@ -34,7 +34,7 @@ public class MusicSelectable extends WidgetGroup implements Disposable {
table.setFillParent(true); table.setFillParent(true);
this.msp = msp; this.msp = msp;
setName(musicFile.nameWithoutExtension()); setName(musicFile.nameWithoutExtension());
table.defaults().pad(5f).space(15f); table.defaults().pad(5f).space(15f).expandX();
displayName = new ShortenedTextLabel(musicFile.nameWithoutExtension().replace('_', ' '), skin, "sub-font", skin.getColor("default")); displayName = new ShortenedTextLabel(musicFile.nameWithoutExtension().replace('_', ' '), skin, "sub-font", skin.getColor("default"));
table.add(displayName); table.add(displayName);

View File

@ -63,6 +63,7 @@ public class MusicSelectionPage extends Page implements Observer {
private TextButton beginButton; private TextButton beginButton;
private int uiSongCount; private int uiSongCount;
private int uiSongInfoCount;
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer; private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer;
public MusicSelectionPage(Skin skin, MusicListController musicListController, AssetManager assetManager, Vector3 cameraTarget, AnalysisPage ap) { public MusicSelectionPage(Skin skin, MusicListController musicListController, AssetManager assetManager, Vector3 cameraTarget, AnalysisPage ap) {
@ -74,6 +75,7 @@ public class MusicSelectionPage extends Page implements Observer {
this.assets = assetManager; this.assets = assetManager;
musicTable = new Table(); musicTable = new Table();
musicTableScrollPane = new ScrollPane(musicTable, skin); musicTableScrollPane = new ScrollPane(musicTable, skin);
musicTable.defaults().spaceTop(5f).spaceBottom(5f);
musicTableScrollPane.setSize(0.45f*getWidth(), getHeight()); musicTableScrollPane.setSize(0.45f*getWidth(), getHeight());
musicTableScrollPane.setFadeScrollBars(false); musicTableScrollPane.setFadeScrollBars(false);
musicTableScrollPane.setOverscroll(false, false); musicTableScrollPane.setOverscroll(false, false);
@ -174,13 +176,20 @@ public class MusicSelectionPage extends Page implements Observer {
setCurrentMusic(); setCurrentMusic();
} }
} }
super.act(delta); super.act(delta);
if (uiSongCount < selectables.size) { if (uiSongCount < mc.getMusicList().getAmountOfMusic()) {
MusicSelectable selectable = new MusicSelectable(mc.getMusicList().getSongFileHandleFromIndex(uiSongCount), skin, this);
selectables.add(selectable);
musicTable.add(selectables.get(uiSongCount)).expandX().fillX(); musicTable.add(selectables.get(uiSongCount)).expandX().fillX();
uiSongCount++; uiSongCount++;
musicTable.row(); musicTable.row();
} }
if (mic.isDoneLoading() && uiSongInfoCount < selectables.size) {
selectables.get(uiSongInfoCount).updateInfo(mic.getSongInfoArray().get(uiSongInfoCount));
uiSongInfoCount++;
}
} }
public FileHandle getSelectedMusic() { public FileHandle getSelectedMusic() {
@ -192,6 +201,9 @@ public class MusicSelectionPage extends Page implements Observer {
} }
public void refreshUIList() { public void refreshUIList() {
for (int i = 0; i < selectables.size; i++) {
selectables.get(i).dispose();
}
musicTable.clear(); musicTable.clear();
selectables.clear(); selectables.clear();
musicInfoTable.clear(); musicInfoTable.clear();
@ -199,17 +211,10 @@ public class MusicSelectionPage extends Page implements Observer {
extraInfoDone = false; extraInfoDone = false;
uiSongCount = 0; uiSongCount = 0;
mic.loadSongInfo(); mic.loadSongInfo();
uiSongInfoCount = 0;
for (int i = 0; i < selectables.size; i++) {
selectables.get(i).dispose();
}
Gdx.app.debug("MusicSelectionPage", "Refreshing..."); Gdx.app.debug("MusicSelectionPage", "Refreshing...");
for (int i = 0; i < mc.getMusicList().getAmountOfMusic(); i++) {
MusicSelectable selectable = new MusicSelectable(mc.getMusicList().getSongFileHandleFromIndex(i), skin, this);
selectables.add(selectable);
}
musicInfoTable.add(songTitle).width(musicInfoTable.getWidth()*0.6f).spaceBottom(30f); musicInfoTable.add(songTitle).width(musicInfoTable.getWidth()*0.6f).spaceBottom(30f);
musicInfoTable.row(); musicInfoTable.row();
musicSubInfo.add(author); musicSubInfo.add(author);