optimizations by replacing nested loops to one main loop

This commit is contained in:
Harrison Deng 2017-11-24 16:56:23 -06:00
parent 9829748a03
commit 60c1c2b2d7
3 changed files with 15 additions and 24 deletions

View File

@ -136,18 +136,16 @@ public class BasicVisualizer extends VisualizerCore {
} else { } else {
bars[i].setRotation(rotation); bars[i].setRotation(rotation);
} }
if (i == bars.length-1 && width <= getActualWidth()) {
barSpace -= 2;
}
if (reverse) { if (reverse) {
bars[bars.length-i-1].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y); bars[bars.length-i-1].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y);
} else { } else {
bars[i].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y); bars[i].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y);
} }
for (int mirrorIndex = 0; mirrorIndex < mirrors.size; mirrorIndex++) {
mirrors.get(mirrorIndex).position(i, barWidth, spaceBetweenBars);
} }
for (int i = 0; i < mirrors.size; i++) {
mirrors.get(i).position(barWidth, spaceBetweenBars, (width <= getActualWidth()));
} }
} }
public float getActualWidth() { public float getActualWidth() {

View File

@ -29,26 +29,19 @@ public class MirrorVisualizer {
} }
} }
public void render(int renderID, Batch batch, float parentAlpha, Sprite[] bars) { public void render(int renderIndex, Batch batch, float parentAlpha, Sprite[] bars) {
this.bars[renderID].setSize(bars[renderID].getWidth(), bars[renderID].getHeight()); this.bars[renderIndex].setSize(bars[renderIndex].getWidth(), bars[renderIndex].getHeight());
this.bars[renderID].draw(batch); this.bars[renderIndex].draw(batch);
} }
public void position(int barWidth, int spaceBetweenBars, boolean shrink) { public void position(int positionIndex, int barWidth, int spaceBetweenBars) {
int barSpaceMultiplier = barWidth + spaceBetweenBars;
for (int i = 0; i < bars.length; i ++) {
if (flip) { if (flip) {
bars[i].setRotation(rotation+180); bars[positionIndex].setRotation(rotation+180);
} else { } else {
bars[i].setRotation(rotation); bars[positionIndex].setRotation(rotation);
}
int barSpace = i*(barWidth+spaceBetweenBars);
if (i == bars.length-1 && shrink) {
barSpace -= 2;
}
bars[i].setPosition(xPos + barSpace*rectCoordRot.x, yPos + barSpace*rectCoordRot.y);
} }
int barSpace = positionIndex*(barWidth+spaceBetweenBars);
bars[positionIndex].setPosition(xPos + barSpace*rectCoordRot.x, yPos + barSpace*rectCoordRot.y);
} }
public void setColor(Color color) { public void setColor(Color color) {

View File

@ -120,7 +120,7 @@ public class MusicSelectionPage extends Page implements Observer {
musicInfoTable.setSize(getWidth()-musicTableScrollPane.getWidth(), getHeight()); musicInfoTable.setSize(getWidth()-musicTableScrollPane.getWidth(), getHeight());
addActor(musicInfoTable); addActor(musicInfoTable);
songTitle = new ScrollText("", null, skin, true, false); songTitle = new ScrollText("", null, skin, true, true);
author = new Label(null, skin, "sub-font", skin.getColor("default")); author = new Label(null, skin, "sub-font", skin.getColor("default"));
songLength = new Label(null, skin, "sub-font", skin.getColor("default")); songLength = new Label(null, skin, "sub-font", skin.getColor("default"));
previousTop = new Label(null, skin, "sub-font", skin.getColor("default")); previousTop = new Label(null, skin, "sub-font", skin.getColor("default"));