From 60c1c2b2d76abc3d42584db973bbb139733be2b1 Mon Sep 17 00:00:00 2001 From: Recrown Date: Fri, 24 Nov 2017 16:56:23 -0600 Subject: [PATCH] optimizations by replacing nested loops to one main loop --- .../audio/visualizer/BasicVisualizer.java | 10 +++---- .../audio/visualizer/MirrorVisualizer.java | 27 +++++++------------ .../graphics/ui/pages/MusicSelectionPage.java | 2 +- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java index bd7bd1c..84bd933 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java @@ -136,18 +136,16 @@ public class BasicVisualizer extends VisualizerCore { } else { bars[i].setRotation(rotation); } - if (i == bars.length-1 && width <= getActualWidth()) { - barSpace -= 2; - } if (reverse) { bars[bars.length-i-1].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y); } else { 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() { diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/MirrorVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/MirrorVisualizer.java index a9c59e6..2136671 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/MirrorVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/MirrorVisualizer.java @@ -29,26 +29,19 @@ public class MirrorVisualizer { } } - public void render(int renderID, Batch batch, float parentAlpha, Sprite[] bars) { - this.bars[renderID].setSize(bars[renderID].getWidth(), bars[renderID].getHeight()); - this.bars[renderID].draw(batch); + public void render(int renderIndex, Batch batch, float parentAlpha, Sprite[] bars) { + this.bars[renderIndex].setSize(bars[renderIndex].getWidth(), bars[renderIndex].getHeight()); + this.bars[renderIndex].draw(batch); } - public void position(int barWidth, int spaceBetweenBars, boolean shrink) { - int barSpaceMultiplier = barWidth + spaceBetweenBars; - - for (int i = 0; i < bars.length; i ++) { - if (flip) { - bars[i].setRotation(rotation+180); - } else { - bars[i].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); + public void position(int positionIndex, int barWidth, int spaceBetweenBars) { + if (flip) { + bars[positionIndex].setRotation(rotation+180); + } else { + bars[positionIndex].setRotation(rotation); } + int barSpace = positionIndex*(barWidth+spaceBetweenBars); + bars[positionIndex].setPosition(xPos + barSpace*rectCoordRot.x, yPos + barSpace*rectCoordRot.y); } public void setColor(Color color) { diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MusicSelectionPage.java b/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MusicSelectionPage.java index f12d4fb..3225407 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MusicSelectionPage.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MusicSelectionPage.java @@ -120,7 +120,7 @@ public class MusicSelectionPage extends Page implements Observer { musicInfoTable.setSize(getWidth()-musicTableScrollPane.getWidth(), getHeight()); 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")); songLength = new Label(null, skin, "sub-font", skin.getColor("default")); previousTop = new Label(null, skin, "sub-font", skin.getColor("default"));