From 8023987148c0178ad26706343038deff3b5405fe Mon Sep 17 00:00:00 2001 From: Recrown Date: Sat, 9 Dec 2017 00:36:49 -0600 Subject: [PATCH] minor optimizations + page reload now funtions properly --- .../zero1hd/rhythmbullet/RhythmBullet.java | 4 ++- .../rhythmbullet/audio/Mp3Manager.java | 28 ++++++++++--------- .../audio/MusicListController.java | 2 +- .../audio/visualizer/BasicVisualizer.java | 5 +--- .../audio/wavedecoder/WavDecoder.java | 2 -- .../ui/components/TitleBarVisualizer.java | 6 ++-- .../graphics/ui/pages/MainPage.java | 15 ++++++---- .../rhythmbullet/screens/MainMenu.java | 6 ++-- .../rhythmbullet/util/TransitionAdapter.java | 3 +- .../rhythmbullet/desktop/DesktopLauncher.java | 3 +- 10 files changed, 42 insertions(+), 32 deletions(-) diff --git a/core/src/zero1hd/rhythmbullet/RhythmBullet.java b/core/src/zero1hd/rhythmbullet/RhythmBullet.java index 6d36991..2ffa1b6 100755 --- a/core/src/zero1hd/rhythmbullet/RhythmBullet.java +++ b/core/src/zero1hd/rhythmbullet/RhythmBullet.java @@ -109,7 +109,7 @@ public class RhythmBullet extends Game { defineSkinStyles(); assetManager.get("standard_thrust.p", ParticleEffect.class).flipY(); if (initComplete) { - ((TransitionAdapter) getScreen()).postTransition(); + ((TransitionAdapter) getScreen()).postTransition(false); } } } @@ -125,6 +125,7 @@ public class RhythmBullet extends Game { default_fontGenerator.dispose(); darktech_ldr_fontGenerator.dispose(); assetManager.dispose(); + getScreen().dispose(); } super.dispose(); } @@ -335,4 +336,5 @@ public class RhythmBullet extends Game { public RoundingResolutionHandler getrRHandler() { return rRHandler; } + } diff --git a/core/src/zero1hd/rhythmbullet/audio/Mp3Manager.java b/core/src/zero1hd/rhythmbullet/audio/Mp3Manager.java index 6b47901..ac6b315 100755 --- a/core/src/zero1hd/rhythmbullet/audio/Mp3Manager.java +++ b/core/src/zero1hd/rhythmbullet/audio/Mp3Manager.java @@ -109,19 +109,6 @@ public class Mp3Manager implements MusicManager { return sampleCount; } - @Override - public void dispose() { - playbackMusic.stop(); - playbackMusic.dispose(); - exec.shutdown(); - try { - bitstream.close(); - bitstream = null; - } catch (BitstreamException e) { - e.printStackTrace(); - } - } - @Override public float getDuration() { return Float.valueOf(String.valueOf(durationInSeconds)); @@ -204,6 +191,7 @@ public class Mp3Manager implements MusicManager { @Override public void pause() { + Gdx.app.debug("MP3Manager", "Pausing..."); playbackMusic.pause(); } @@ -264,4 +252,18 @@ public class Mp3Manager implements MusicManager { public FileHandle getMusicFile() { return file; } + + @Override + public void dispose() { + Gdx.app.debug("MP3Manager", "Disposing..."); + playbackMusic.stop(); + playbackMusic.dispose(); + exec.shutdown(); + try { + bitstream.close(); + bitstream = null; + } catch (BitstreamException e) { + e.printStackTrace(); + } + } } diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicListController.java b/core/src/zero1hd/rhythmbullet/audio/MusicListController.java index b3ace6d..c1150f8 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicListController.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicListController.java @@ -113,7 +113,7 @@ public class MusicListController extends Observable implements OnCompletionListe * Loads the current selected song. */ public void loadMusic() { - Gdx.app.debug("MusicListController", "music is being loaded..."); + Gdx.app.debug("MusicListController", "music is being loaded and listeners are being notified."); if (mm != null) { mm.dispose(); } diff --git a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java index 6c0ed09..2902935 100755 --- a/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/audio/visualizer/BasicVisualizer.java @@ -37,7 +37,7 @@ public class BasicVisualizer extends VisualizerCore { pixmap = new Pixmap(2, 2, Format.RGBA8888); pixmap.setColor(Color.WHITE); pixmap.fill(); - barCount = 75; + barCount = 70; smoothRange = 2; angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation)); bars = new Sprite[barCount]; @@ -116,9 +116,6 @@ public class BasicVisualizer extends VisualizerCore { @Override public void dispose() { barTexture.dispose(); - if (mm != null) { - mm.dispose(); - } super.dispose(); } diff --git a/core/src/zero1hd/rhythmbullet/audio/wavedecoder/WavDecoder.java b/core/src/zero1hd/rhythmbullet/audio/wavedecoder/WavDecoder.java index 88d82ec..4bdf749 100755 --- a/core/src/zero1hd/rhythmbullet/audio/wavedecoder/WavDecoder.java +++ b/core/src/zero1hd/rhythmbullet/audio/wavedecoder/WavDecoder.java @@ -6,7 +6,6 @@ import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; public class WavDecoder { @@ -22,7 +21,6 @@ public class WavDecoder { this.file = file; try { audioInputStream = AudioSystem.getAudioInputStream(file.file()); - Gdx.app.debug("WAVDecoder", String.valueOf(audioInputStream.getFormat().getFrameSize())); buffer = new byte[audioInputStream.getFormat().getFrameSize()]; channels = audioInputStream.getFormat().getChannels(); diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java index cb35cf9..8a66b66 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/TitleBarVisualizer.java @@ -29,6 +29,7 @@ public class TitleBarVisualizer extends Group implements Disposable { ParticleEffectPool beatEffectPool; Array effects = new Array<>(); + private float particleLimitTime; private boolean lastEffect; public TitleBarVisualizer(AssetManager assets) { if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL"); @@ -84,15 +85,16 @@ public class TitleBarVisualizer extends Group implements Disposable { @Override public void act(float delta) { - if (!lastEffect) { + if (particleLimitTime > 1f/60f) { if (visual.getVis().getMm() != null && visual.getVis().getMm().isPlaying() && visual.getVis().getCurrentAvg() > visual.getVis().getMaxAvgHeight()*0.55f) { PooledEffect effect = beatEffectPool.obtain(); effect.setPosition(0, 0); effects.add(effect); lastEffect = true; + particleLimitTime = 0; } } else { - lastEffect = false; + particleLimitTime += delta; } super.act(delta); diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MainPage.java b/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MainPage.java index 81b8200..0c94f29 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MainPage.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/pages/MainPage.java @@ -36,10 +36,10 @@ public class MainPage extends Page implements Observer { private MainMenu mMenu; private ScrollText scrollText; - public MainPage(RhythmBullet core, Vector3 targetPosition, MusicListController mlc, MainMenu mm) { + public MainPage(RhythmBullet core, Vector3 targetPosition, MusicListController mlc, MainMenu mainMenu) { this.mlc = mlc; setTextureBackground(core.getAssetManager().get("gradients.atlas", TextureAtlas.class).findRegion("red-linear")); - this.mMenu = mm; + this.mMenu = mainMenu; titleBar = new TitleBarVisualizer(core.getAssetManager()); addActor(titleBar); @@ -59,7 +59,7 @@ public class MainPage extends Page implements Observer { @Override public void changed(ChangeEvent event, Actor actor) { targetPosition.x = Gdx.graphics.getWidth()*1.5f; - getStage().setKeyboardFocus(mm.getMusicSelectionPage()); + getStage().setKeyboardFocus(mainMenu.getMusicSelectionPage()); } }); table.add(playButton).width(Gdx.graphics.getWidth()*0.2f); @@ -94,6 +94,12 @@ public class MainPage extends Page implements Observer { scrollText.setWidth(0.5f*getWidth()); scrollText.setPosition(15, getHeight() - scrollText.getHeight()-15f); addActor(scrollText); + + if (mlc.getMusicList().isSearched() && mlc.getCurrentMusicManager() != null) { + MusicManager mManager = mlc.getCurrentMusicManager(); + updateVisualsForDifferentSong(mManager); + mMenu.getMusicSelectionPage().refreshUIList(); + } } @Override @@ -114,12 +120,11 @@ public class MainPage extends Page implements Observer { @Override public void update(Observable o, Object arg) { - if (o == mlc.getMusicList()) { + if (o == mlc.getMusicList() && mlc.getMusicList().isSearched()) { mlc.shuffle(true); MusicManager mm = mlc.getCurrentMusicManager(); updateVisualsForDifferentSong(mm); mMenu.getMusicSelectionPage().refreshUIList(); - mlc.play(); } else if (o == mlc) { MusicManager mm = mlc.getCurrentMusicManager(); mlc.play(); diff --git a/core/src/zero1hd/rhythmbullet/screens/MainMenu.java b/core/src/zero1hd/rhythmbullet/screens/MainMenu.java index 8c282de..7528be3 100755 --- a/core/src/zero1hd/rhythmbullet/screens/MainMenu.java +++ b/core/src/zero1hd/rhythmbullet/screens/MainMenu.java @@ -70,11 +70,11 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter { mlc = new MusicListController(musicList, core.getPrefs()); mlc.setAutoPlay(true); mlc.setShuffle(true); - postTransition(); + postTransition(true); } @Override - public void postTransition() { + public void postTransition(boolean first) { attemptLoadShaders(); mainPage = new MainPage(core, cameraPosition, mlc, this); @@ -132,10 +132,12 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter { } }); mlc.getMusicList().deleteObservers(); + mlc.deleteObservers();; mlc.addObserver(musicSelectionPage); mlc.addObserver(mainPage); mlc.getMusicList().addObserver(mainPage); } + public void attemptLoadShaders() { if (core.getPrefs().getBoolean("glow shader", true)) { if (core.getPrefs().getBoolean("enhanced glow", false)) { diff --git a/core/src/zero1hd/rhythmbullet/util/TransitionAdapter.java b/core/src/zero1hd/rhythmbullet/util/TransitionAdapter.java index c0a6e90..9254353 100755 --- a/core/src/zero1hd/rhythmbullet/util/TransitionAdapter.java +++ b/core/src/zero1hd/rhythmbullet/util/TransitionAdapter.java @@ -8,6 +8,7 @@ public interface TransitionAdapter { /** * called after transition completes and assets reloaded. + * @param first true if this is the first time load (when the game is just started or something) */ - public void postTransition(); + public void postTransition(boolean first); } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/DesktopLauncher.java b/desktop/src/zero1hd/rhythmbullet/desktop/DesktopLauncher.java index fbf0a66..a01f2c1 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/DesktopLauncher.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/DesktopLauncher.java @@ -12,7 +12,8 @@ public class DesktopLauncher { config.resizable = false; config.allowSoftwareMode = true; config.useHDPI = true; - config.vSyncEnabled = true; + config.vSyncEnabled = false; + config.foregroundFPS = 0; new LwjglApplication(new RhythmBullet(), config); } }