minor optimizations + page reload now funtions properly

This commit is contained in:
Harrison Deng 2017-12-09 00:36:49 -06:00
parent 2fc434cc29
commit 8023987148
10 changed files with 42 additions and 32 deletions

View File

@ -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;
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();

View File

@ -29,6 +29,7 @@ public class TitleBarVisualizer extends Group implements Disposable {
ParticleEffectPool beatEffectPool;
Array<PooledEffect> 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);

View File

@ -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();

View File

@ -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)) {

View File

@ -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);
}

View File

@ -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);
}
}