began testing, working through various errors, ended on constant

reloading in the game manager;
This commit is contained in:
Harrison Deng 2018-08-05 00:03:53 -05:00
parent 59cfa277ab
commit fe1eeecbc1
10 changed files with 56 additions and 55 deletions

View File

@ -2,6 +2,16 @@ package zero1hd.rhythmbullet;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
public interface InitialScreen { public interface InitialScreen extends Screen {
public Screen createMainScreen(RhythmBullet game); /**
* Screen should be created on platform.
* @param gameManager the game manager.
* @return the screen that is created.
*/
public Screen createMainScreen(RhythmBullet gameManager);
/**
* Immediately called after the LibGDX instance has been instantiated.
*/
public void init();
} }

View File

@ -30,6 +30,7 @@ public class RhythmBullet extends Game {
public static int pixels_per_unit; public static int pixels_per_unit;
private boolean initiated; private boolean initiated;
private boolean resizing; private boolean resizing;
private boolean completeUILoad;
private int screenWidth, screenHeight; private int screenWidth, screenHeight;
public static final String VERSION = "(0.1)R1-PreAlpha"; public static final String VERSION = "(0.1)R1-PreAlpha";
@ -38,7 +39,7 @@ public class RhythmBullet extends Game {
TextureAtlas skinAtlas; TextureAtlas skinAtlas;
private Preferences preferences; private Preferences preferences;
private RoundingResolutionHandler rRHandler; private RoundingResolutionHandler rRHandler;
private Screen initialScreen; private InitialScreen initialScreen;
private AssetPack assetPack; private AssetPack assetPack;
/** /**
@ -46,7 +47,7 @@ public class RhythmBullet extends Game {
* @param initialScreen the first screen to go to. * @param initialScreen the first screen to go to.
* @param assetPack the asset package to be used. * @param assetPack the asset package to be used.
*/ */
public void setup(Screen initialScreen, AssetPack assetPack) { public void setup(InitialScreen initialScreen, AssetPack assetPack) {
this.initialScreen = initialScreen; this.initialScreen = initialScreen;
this.assetPack = assetPack; this.assetPack = assetPack;
} }
@ -54,6 +55,7 @@ public class RhythmBullet extends Game {
@Override @Override
public void create() { public void create() {
Gdx.app.setLogLevel(Application.LOG_DEBUG); Gdx.app.setLogLevel(Application.LOG_DEBUG);
initialScreen.init();
setScreen(initialScreen); setScreen(initialScreen);
assetPack.initiateResources(); assetPack.initiateResources();
@ -101,6 +103,8 @@ public class RhythmBullet extends Game {
public boolean checkAssetQueue() { public boolean checkAssetQueue() {
if (assetManager.update()) { if (assetManager.update()) {
if (resizing) {
Gdx.app.debug("Resize", "Post resize is starting...");
if (skin != null) skin.dispose(); if (skin != null) skin.dispose();
skin = new Skin(); skin = new Skin();
skinAtlas = assetManager.get("uiskin.atlas", TextureAtlas.class); skinAtlas = assetManager.get("uiskin.atlas", TextureAtlas.class);
@ -109,9 +113,6 @@ public class RhythmBullet extends Game {
assetPack.generateFonts(skin); assetPack.generateFonts(skin);
assetPack.setupSkin(skin); assetPack.setupSkin(skin);
assetPack.complete(assetManager); assetPack.complete(assetManager);
if (resizing) {
Gdx.app.debug("Resize", "Post resize is starting...");
if (getScreen() instanceof ResizeReadyScreen) { if (getScreen() instanceof ResizeReadyScreen) {
((ResizeReadyScreen) getScreen()).postAssetLoad(); ((ResizeReadyScreen) getScreen()).postAssetLoad();
} else { } else {

View File

@ -161,16 +161,17 @@ public class MusicController extends Observable implements OnCompletionListener,
if (currentlyPlayingIndex >= musicList.getTotal()) { if (currentlyPlayingIndex >= musicList.getTotal()) {
currentlyPlayingIndex = 0; currentlyPlayingIndex = 0;
} }
if (musicList.getTotal() != 0) {
this.music = Gdx.audio.newMusic(musicList.getMusicArray().get(currentlyPlayingIndex)); this.music = Gdx.audio.newMusic(musicList.getMusicArray().get(currentlyPlayingIndex));
music.setOnCompletionListener(this); music.setOnCompletionListener(this);
setChanged(); setChanged();
if (autoPlay) { if (autoPlay) {
play(); play();
} }
notifyObservers(states.LOADED); notifyObservers(states.LOADED);
} }
}
public MusicList getMusicList() { public MusicList getMusicList() {
return musicList; return musicList;

View File

@ -18,7 +18,7 @@ public class MusicList extends Observable {
private Array<FileHandle> musicList; private Array<FileHandle> musicList;
private RecursiveMusicSearchThread searchThread; private RecursiveMusicSearchThread searchThread;
private AudioProcessorFactory audioProcFactory; private AudioProcessorFactory audioProcFactory;
private boolean searched; private volatile boolean searched;
public MusicList(AudioProcessorFactory audioProcessorFactory) { public MusicList(AudioProcessorFactory audioProcessorFactory) {
this.audioProcFactory = audioProcessorFactory; this.audioProcFactory = audioProcessorFactory;
@ -87,12 +87,6 @@ public class MusicList extends Observable {
return searched; return searched;
} }
private void searchComplete() {
notifyObservers();
searched = true;
}
/** /**
* *
* @return the amount of audio files discovered. * @return the amount of audio files discovered.
@ -120,7 +114,9 @@ public class MusicList extends Observable {
Array<FileHandle> obtainedAudioFiles = recursiveMusicSearch(directory); Array<FileHandle> obtainedAudioFiles = recursiveMusicSearch(directory);
if (work) { if (work) {
musicList = obtainedAudioFiles; musicList = obtainedAudioFiles;
searchComplete(); musicList.add(Gdx.files.internal("music/Alan Walker - Spectre.mp3"));
notifyObservers();
searched = true;
} }
} }

View File

@ -29,21 +29,20 @@ public class DoubleHorizontalVisualizer {
this.barWidth = width/barCount; this.barWidth = width/barCount;
this.spaceBetweenBars = (int) (barWidth * spacePercentage); this.spaceBetweenBars = (int) (barWidth * spacePercentage);
this.barWidth -= spaceBetweenBars; this.barWidth -= spaceBetweenBars;
pcm = PCMSystem;
if (barWidth < 1) throw new IllegalArgumentException("The arguments you passed caused the bar width to be 0."); if (barWidth < 1) throw new IllegalArgumentException("The arguments you passed caused the bar width to be 0.");
binsPerBar = (pcm.getWindowSize()/barCount); binsPerBar = (pcm.getFrequencyBins().length/barCount);
this.width = width; this.width = width;
this.height = height; this.height = height;
pcm = PCMSystem;
amplitudes = new int[barCount]; amplitudes = new int[barCount];
barHeights = new int[barCount]; barHeights = new int[barCount];
shapeRenderer = new ShapeRenderer(); shapeRenderer = new ShapeRenderer();
shapeRenderer.set(ShapeType.Filled);
} }
public void act(float delta) { public void act(float delta) {
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] = (int) (normalizedAmplitude*multiplier); amplitudes[bar] = (int) (normalizedAmplitude*multiplier);
@ -53,7 +52,7 @@ public class DoubleHorizontalVisualizer {
if (barHeights[bar] > amplitudes[bar]) barHeights[bar] = amplitudes[bar]; if (barHeights[bar] > amplitudes[bar]) barHeights[bar] = amplitudes[bar];
} }
for (int bar = 1; bar <= barHeights.length; bar++) { for (int bar = 0; bar < barHeights.length; bar++) {
int smoothCount = 1; int smoothCount = 1;
for (int range = 0; range < smoothRange; range++) { for (int range = 0; range < smoothRange; range++) {
if (bar+range < amplitudes.length) { if (bar+range < amplitudes.length) {
@ -70,7 +69,7 @@ public class DoubleHorizontalVisualizer {
} }
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
shapeRenderer.begin(); shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.rect(x, y-2, width, y); shapeRenderer.rect(x, y-2, width, y);
shapeRenderer.rect(x, y+height, width, y+height+2); shapeRenderer.rect(x, y+height, width, y+height+2);
int beginX = x + spaceBetweenBars/2, beginY = y; int beginX = x + spaceBetweenBars/2, beginY = y;

View File

@ -44,14 +44,9 @@ public class PCMObtainer implements Observer, Disposable, PCMSystem {
try { try {
Field bufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer"); Field bufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer");
bufferField.setAccessible(true); bufferField.setAccessible(true);
Field bufferSizeField = ClassReflection.getDeclaredField(OpenALMusic.class, "bufferSize");
bufferSizeField.setAccessible(true);
bufferSizeField.set(null, new Integer(4096 * 5));
buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer().asReadOnlyBuffer(); buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer().asReadOnlyBuffer();
} catch (IllegalArgumentException | SecurityException | ReflectionException e) { } catch (IllegalArgumentException | SecurityException | ReflectionException e) {
e.printStackTrace(); Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.", e);
Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.");
Gdx.app.exit(); Gdx.app.exit();
} }
@ -146,7 +141,7 @@ public class PCMObtainer implements Observer, Disposable, PCMSystem {
if (updated) { if (updated) {
synchronized (PCM) { synchronized (PCM) {
fft.fft(PCM); fft.fft(PCM);
System.arraycopy(PCM, 0, frequencyBins, 0, frequencyBins.length); System.arraycopy(PCM, 1, frequencyBins, 0, frequencyBins.length);
} }
} }
return frequencyBins; return frequencyBins;
@ -199,7 +194,7 @@ public class PCMObtainer implements Observer, Disposable, PCMSystem {
} }
public void start() { public void start() {
if (thread == null && !thread.isAlive()) { if (thread == null) {
thread = new Thread(this, name); thread = new Thread(this, name);
thread.start(); thread.start();
} else { } else {

View File

@ -21,17 +21,12 @@ public class SplashScreen extends ScreenAdapter implements ResizeReadyScreen, In
private Texture splash; private Texture splash;
private Image zero1HD; private Image zero1HD;
public SplashScreen() { @Override
public void init() {
splash = new Texture(Gdx.files.internal("splashlogo.png")); splash = new Texture(Gdx.files.internal("splashlogo.png"));
zero1HD = new Image(splash); zero1HD = new Image(splash);
zero1HD.setScale((Gdx.graphics.getHeight()*0.8f)/zero1HD.getHeight()); zero1HD.setScale((Gdx.graphics.getHeight()*0.8f)/zero1HD.getHeight());
zero1HD.setColor(0f,1f,1f,0.1f); zero1HD.setColor(0f,1f,1f,0.1f);
stage.addActor(zero1HD);
}
@Override
public void show() {
super.show();
} }
@Override @Override
@ -56,6 +51,7 @@ public class SplashScreen extends ScreenAdapter implements ResizeReadyScreen, In
@Override @Override
public void postAssetLoad() { public void postAssetLoad() {
stage = new Stage(new ScreenViewport()); stage = new Stage(new ScreenViewport());
stage.addActor(zero1HD);
zero1HD.setScale((Gdx.graphics.getHeight()*0.8f)/zero1HD.getHeight()); zero1HD.setScale((Gdx.graphics.getHeight()*0.8f)/zero1HD.getHeight());
zero1HD.setColor(0f,1f,1f,0f); zero1HD.setColor(0f,1f,1f,0f);
zero1HD.setPosition((stage.getWidth() - zero1HD.getWidth()*zero1HD.getScaleX())/2f, (stage.getHeight() - zero1HD.getHeight()*zero1HD.getScaleY())/2f); zero1HD.setPosition((stage.getWidth() - zero1HD.getWidth()*zero1HD.getScaleX())/2f, (stage.getHeight() - zero1HD.getHeight()*zero1HD.getScaleY())/2f);

View File

@ -52,7 +52,7 @@ public class MainPage extends Page implements Observer {
title.setPosition((getWidth()-title.getWidth())/2f, (getHeight()-title.getHeight())/2f); title.setPosition((getWidth()-title.getWidth())/2f, (getHeight()-title.getHeight())/2f);
addActor(title); addActor(title);
versionLabel = new Label("Version: " + RhythmBullet.VERSION, skin, "sub-font"); versionLabel = new Label("Version: " + RhythmBullet.VERSION, skin, "sub-font", skin.getColor("default"));
versionLabel.setPosition(3, 3); versionLabel.setPosition(3, 3);
addActor(versionLabel); addActor(versionLabel);
@ -94,13 +94,13 @@ public class MainPage extends Page implements Observer {
@Override @Override
public void act(float delta) { public void act(float delta) {
dhv.act(delta); // dhv.act(delta);
super.act(delta); super.act(delta);
} }
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
dhv.draw(batch, parentAlpha); // dhv.draw(batch, parentAlpha);
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
} }

View File

@ -80,6 +80,9 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
draw(); draw();
} }
draw();
if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) { if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) {
stage.getCamera().position.lerp(cameraPosition, delta*lerpAlpha); stage.getCamera().position.lerp(cameraPosition, delta*lerpAlpha);
stage.getViewport().apply(); stage.getViewport().apply();

View File

@ -194,7 +194,7 @@ public class MusicSelectionPage extends Page implements Observer {
} }
} }
if (selectables.getButtons().size == mc.getMusicList().getTotal()) { if (mc.getMusicList().isSearched() && selectables.getButtons().size == mc.getMusicList().getTotal()) {
if (selectables.getButtons().size != stackSelectables.getChildren().size) { if (selectables.getButtons().size != stackSelectables.getChildren().size) {
int index = selectables.getButtons().size - stackSelectables.getChildren().size - 1; int index = selectables.getButtons().size - stackSelectables.getChildren().size - 1;
stackSelectables.add(selectables.getButtons().get(index)); stackSelectables.add(selectables.getButtons().get(index));