resize tested and many issues fixed; horizontal visualizer scales to

height;
This commit is contained in:
Harrison Deng 2018-08-15 23:17:04 -05:00
parent 7a810299ce
commit 7fb42a63f8
6 changed files with 61 additions and 42 deletions

View File

@ -148,7 +148,7 @@ public class RhythmBullet extends Game {
@Override @Override
public void resize(int width, int height) { public void resize(int width, int height) {
Gdx.app.debug("RhythmBullet/resize", "Current size:" + screenWidth + "x" + screenHeight + " new size: " + width + "x" + height); Gdx.app.debug("resize", "Current size:" + screenWidth + "x" + screenHeight + " new size: " + width + "x" + height);
if (width != screenWidth || height != screenHeight) { if (width != screenWidth || height != screenHeight) {
screenWidth = Gdx.graphics.getWidth(); screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight(); screenHeight = Gdx.graphics.getHeight();
@ -167,9 +167,9 @@ public class RhythmBullet extends Game {
resizing = true; resizing = true;
assetManager.clear(); assetManager.clear();
queueAssets(); queueAssets();
}
super.resize(width, height); super.resize(width, height);
} }
}
public void queueAssets() { public void queueAssets() {
assetPack.queueTextures(assetManager); assetPack.queueTextures(assetManager);

View File

@ -19,28 +19,43 @@ public class MusicList extends Observable {
private RecursiveMusicSearchThread searchThread; private RecursiveMusicSearchThread searchThread;
private AudioProcessorFactory audioProcFactory; private AudioProcessorFactory audioProcFactory;
private volatile boolean searched; private volatile boolean searched;
private String searchPath;
public MusicList(AudioProcessorFactory audioProcessorFactory) { public MusicList(AudioProcessorFactory audioProcessorFactory, String searchPath) {
this.audioProcFactory = audioProcessorFactory; this.audioProcFactory = audioProcessorFactory;
musicList = new Array<>(); musicList = new Array<>();
searchThread = new RecursiveMusicSearchThread("Music Search Thread"); setSearchPath(searchPath);
} }
/** /**
* Wrapper method that uses async refresh. * Wrapper method that uses async refresh.
* Also notifies listeners that are on the main thread. * Also notifies listeners that are on the main thread.
* @param refresh does a search whether or not path has changed.
*/ */
public void asyncSearch() { public void asyncSearch(boolean refresh) {
if (refresh) {
if (searchThread != null) {
if (!searchThread.start()) { if (!searchThread.start()) {
searchThread.stop(); searchThread.stop();
searchThread = new RecursiveMusicSearchThread("Music Search Thread"); searchThread = new RecursiveMusicSearchThread("Music Search Thread", Gdx.files.absolute(searchPath));
searchThread.start(); searchThread.start();
} }
} else {
searchThread = new RecursiveMusicSearchThread("Music Search Thread", Gdx.files.absolute(searchPath));
searchThread.start();
}
} else {
if (searched && !hasChanged()) {
setChanged();
notifyObservers();
} else {
asyncSearch(true);
}
}
} }
public void setSearchPath(String searchPath) { public void setSearchPath(String searchPath) {
searchThread.setSearchDirectory(Gdx.files.absolute(searchPath)); hasChanged();
setChanged(); this.searchPath = searchPath;
} }
/** /**
@ -107,12 +122,9 @@ public class MusicList extends Observable {
private FileHandle directory; private FileHandle directory;
private volatile boolean work; private volatile boolean work;
public RecursiveMusicSearchThread(String name) { public RecursiveMusicSearchThread(String name, FileHandle searchDirectory) {
this.threadName = name; this.threadName = name;
} this.directory = searchDirectory;
public void setSearchDirectory(FileHandle directory) {
this.directory = directory;
} }
@Override @Override
@ -131,6 +143,7 @@ public class MusicList extends Observable {
if (work) { if (work) {
searched = true; searched = true;
Gdx.app.debug("MusicList", "recursive async search completed."); Gdx.app.debug("MusicList", "recursive async search completed.");
setChanged();
notifyObservers(); notifyObservers();
} }
} }

View File

@ -23,7 +23,7 @@ public class DoubleHorizontalVisualizer implements Disposable {
private int boundaryThickness; private int boundaryThickness;
private float spacePercentage = 0.85f; private float spacePercentage = 0.85f;
private int barCount = 80; private int barCount = 80;
private float normalFactor = 3f; private float normalFactor = 1.2f;
private float barChangeRate = 14f; private float barChangeRate = 14f;
private int smoothRange = 1; private int smoothRange = 1;
private int binsToInclude = 160; private int binsToInclude = 160;
@ -55,13 +55,12 @@ public class DoubleHorizontalVisualizer implements Disposable {
if (color.g > 1f) color.g = 0f; if (color.g > 1f) color.g = 0f;
if (color.b > 1f) color.b = 0f; if (color.b > 1f) color.b = 0f;
if (color.a > 1f) color.a = 0.2f; if (color.a > 1f) color.a = 0.2f;
for (int bar = 0; bar < amplitudes.length; bar++) { for (int bar = 0; bar < amplitudes.length; bar++) {
float normalizedAmplitude = 0; float normalizedAmplitude = 0;
for (int freq = bar*binsPerBar; freq < (bar*binsPerBar) + binsPerBar; freq++) { for (int freq = bar*binsPerBar; freq < (bar*binsPerBar) + binsPerBar; freq++) {
normalizedAmplitude += Math.abs(pcm.getFrequencyBins()[freq]); normalizedAmplitude += Math.abs(pcm.getFrequencyBins()[freq]);
} }
amplitudes[bar] += normalizedAmplitude * normalFactor; amplitudes[bar] += normalizedAmplitude * normalFactor * (height/100f);
amplitudes[bar] /= binsPerBar; amplitudes[bar] /= binsPerBar;
} }
for (int bar = 0; bar < barHeights.length; bar++) { for (int bar = 0; bar < barHeights.length; bar++) {

View File

@ -14,11 +14,10 @@ public class DesktopLauncher {
config.resizable = false; config.resizable = false;
config.useHDPI = true; config.useHDPI = true;
config.samples = 2; config.samples = 2;
config.width = 128;
config.height = 128;
core = new RhythmBullet(); core = new RhythmBullet();
core.setup(new SplashScreen(), new DesktopAssetPack()); core.setup(new SplashScreen(), new DesktopAssetPack());
new LwjglApplication(core, config); new LwjglApplication(core, config);
} }
} }

View File

@ -26,6 +26,8 @@ import zero1hd.rhythmbullet.graphics.ui.Page;
import zero1hd.rhythmbullet.util.ResizeReadyScreen; import zero1hd.rhythmbullet.util.ResizeReadyScreen;
public class MainScreen extends ScreenAdapter implements ResizeReadyScreen { public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
private boolean resizing;
private Stage stage; private Stage stage;
private Vector3 cameraPosition; private Vector3 cameraPosition;
private Listeners listeners; private Listeners listeners;
@ -56,8 +58,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
stage = new Stage(new ScreenViewport()); stage = new Stage(new ScreenViewport());
cameraPosition = new Vector3(stage.getCamera().position); cameraPosition = new Vector3(stage.getCamera().position);
MusicList musicList = new MusicList(new DesktopAudioProcessorFactory()); MusicList musicList = new MusicList(new DesktopAudioProcessorFactory(), core.getPreferences().getString("music dir"));
musicList.setSearchPath(core.getPreferences().getString("music dir"));
musicController = new MusicController(musicList, core.getPreferences()); musicController = new MusicController(musicList, core.getPreferences());
musicController.setAutoPlay(true); musicController.setAutoPlay(true);
musicController.setShuffle(true); musicController.setShuffle(true);
@ -65,6 +66,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
musicMetadataController = new MusicMetadataController(musicList); musicMetadataController = new MusicMetadataController(musicList);
listeners = new Listeners(); listeners = new Listeners();
screenBatch = new SpriteBatch();
} }
@Override @Override
@ -89,20 +91,24 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
} }
private void draw() { private void draw() {
if (!resizing) {
stage.getViewport().apply(); stage.getViewport().apply();
screenBatch.begin(); screenBatch.begin();
screenBatch.draw(background, 0, 0, stage.getWidth(), stage.getHeight()); screenBatch.draw(background, 0, 0, stage.getViewport().getScreenWidth(), stage.getViewport().getScreenHeight());
screenBatch.end(); screenBatch.end();
stage.draw(); stage.draw();
} }
}
@Override @Override
public void preAssetLoad() { public void preAssetLoad() {
resizing = true;
stage.clear(); stage.clear();
if (bloomShader != null) {
bloomShader.dispose(); bloomShader.dispose();
bloomShader = null; bloomShader = null;
}
background = null; background = null;
screenBatch.dispose();
musicController.deleteObservers(); musicController.deleteObservers();
} }
@ -110,9 +116,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
public void postAssetLoad() { public void postAssetLoad() {
background = rhythmBullet.getAssetManager().get("backgrounds/mainBG.png", Texture.class); background = rhythmBullet.getAssetManager().get("backgrounds/mainBG.png", Texture.class);
screenBatch = new SpriteBatch();
mainPage = new MainPage(musicController, rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), listeners.musicSelectionPageButtonListener, listeners.optionsPageButtonListener); mainPage = new MainPage(musicController, rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), listeners.musicSelectionPageButtonListener, listeners.optionsPageButtonListener);
stage.addActor(mainPage); stage.addActor(mainPage);
@ -161,9 +164,8 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
musicController.addObserver(musicSelectionPage); musicController.addObserver(musicSelectionPage);
musicController.addObserver(mainPage); musicController.addObserver(mainPage);
musicController.getMusicList().asyncSearch(false);
musicController.getMusicList().asyncSearch(); resizing = false;
} }
@Override @Override
@ -271,9 +273,15 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
ChangeListener bloomLevelShaderListener = new ChangeListener() { ChangeListener bloomLevelShaderListener = new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (graphicsPage.getBloomLevel() > 0) { int bloomLevel = 0;
if (graphicsPage != null) {
bloomLevel = graphicsPage.getBloomLevel();
} else {
bloomLevel = rhythmBullet.getPreferences().getInteger("glow shader");
}
if (bloomLevel > 0) {
if (bloomShader == null) bloomShader = new BloomShader(screenBatch); if (bloomShader == null) bloomShader = new BloomShader(screenBatch);
bloomShader.setBloomLevel((int) graphicsPage.getBloomLevel()); bloomShader.setBloomLevel(bloomLevel);
} else if (bloomShader != null) { } else if (bloomShader != null) {
bloomShader.dispose(); bloomShader.dispose();
bloomShader = null; bloomShader = null;

View File

@ -86,7 +86,7 @@ public class OptionsPage extends Page {
musicSearchTimer -= delta; musicSearchTimer -= delta;
if (musicSearchTimer <= 0) { if (musicSearchTimer <= 0) {
musicController.getMusicList().setSearchPath(directoryField.getText()); musicController.getMusicList().setSearchPath(directoryField.getText());
musicController.getMusicList().asyncSearch(); musicController.getMusicList().asyncSearch(false);
} }
} }
super.act(delta); super.act(delta);