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;
public interface InitialScreen {
public Screen createMainScreen(RhythmBullet game);
public interface InitialScreen extends Screen {
/**
* 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;
private boolean initiated;
private boolean resizing;
private boolean completeUILoad;
private int screenWidth, screenHeight;
public static final String VERSION = "(0.1)R1-PreAlpha";
@ -38,7 +39,7 @@ public class RhythmBullet extends Game {
TextureAtlas skinAtlas;
private Preferences preferences;
private RoundingResolutionHandler rRHandler;
private Screen initialScreen;
private InitialScreen initialScreen;
private AssetPack assetPack;
/**
@ -46,7 +47,7 @@ public class RhythmBullet extends Game {
* @param initialScreen the first screen to go to.
* @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.assetPack = assetPack;
}
@ -54,6 +55,7 @@ public class RhythmBullet extends Game {
@Override
public void create() {
Gdx.app.setLogLevel(Application.LOG_DEBUG);
initialScreen.init();
setScreen(initialScreen);
assetPack.initiateResources();
@ -101,17 +103,16 @@ public class RhythmBullet extends Game {
public boolean checkAssetQueue() {
if (assetManager.update()) {
if (skin != null) skin.dispose();
skin = new Skin();
skinAtlas = assetManager.get("uiskin.atlas", TextureAtlas.class);
getSkin().addRegions(skinAtlas);
assetPack.generateFonts(skin);
assetPack.setupSkin(skin);
assetPack.complete(assetManager);
if (resizing) {
Gdx.app.debug("Resize", "Post resize is starting...");
if (skin != null) skin.dispose();
skin = new Skin();
skinAtlas = assetManager.get("uiskin.atlas", TextureAtlas.class);
getSkin().addRegions(skinAtlas);
assetPack.generateFonts(skin);
assetPack.setupSkin(skin);
assetPack.complete(assetManager);
if (getScreen() instanceof ResizeReadyScreen) {
((ResizeReadyScreen) getScreen()).postAssetLoad();
} else {

View File

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

View File

@ -18,7 +18,7 @@ public class MusicList extends Observable {
private Array<FileHandle> musicList;
private RecursiveMusicSearchThread searchThread;
private AudioProcessorFactory audioProcFactory;
private boolean searched;
private volatile boolean searched;
public MusicList(AudioProcessorFactory audioProcessorFactory) {
this.audioProcFactory = audioProcessorFactory;
@ -87,12 +87,6 @@ public class MusicList extends Observable {
return searched;
}
private void searchComplete() {
notifyObservers();
searched = true;
}
/**
*
* @return the amount of audio files discovered.
@ -120,7 +114,9 @@ public class MusicList extends Observable {
Array<FileHandle> obtainedAudioFiles = recursiveMusicSearch(directory);
if (work) {
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.spaceBetweenBars = (int) (barWidth * spacePercentage);
this.barWidth -= spaceBetweenBars;
pcm = PCMSystem;
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.height = height;
pcm = PCMSystem;
amplitudes = new int[barCount];
barHeights = new int[barCount];
shapeRenderer = new ShapeRenderer();
shapeRenderer.set(ShapeType.Filled);
}
public void act(float delta) {
for (int bar = 0; bar < amplitudes.length; bar++) {
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]);
}
amplitudes[bar] = (int) (normalizedAmplitude*multiplier);
@ -53,7 +52,7 @@ public class DoubleHorizontalVisualizer {
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;
for (int range = 0; range < smoothRange; range++) {
if (bar+range < amplitudes.length) {
@ -70,7 +69,7 @@ public class DoubleHorizontalVisualizer {
}
public void draw(Batch batch, float parentAlpha) {
shapeRenderer.begin();
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.rect(x, y-2, width, y);
shapeRenderer.rect(x, y+height, width, y+height+2);
int beginX = x + spaceBetweenBars/2, beginY = y;

View File

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

View File

@ -21,17 +21,12 @@ public class SplashScreen extends ScreenAdapter implements ResizeReadyScreen, In
private Texture splash;
private Image zero1HD;
public SplashScreen() {
@Override
public void init() {
splash = new Texture(Gdx.files.internal("splashlogo.png"));
zero1HD = new Image(splash);
zero1HD.setScale((Gdx.graphics.getHeight()*0.8f)/zero1HD.getHeight());
zero1HD.setColor(0f,1f,1f,0.1f);
stage.addActor(zero1HD);
}
@Override
public void show() {
super.show();
}
@Override
@ -56,6 +51,7 @@ public class SplashScreen extends ScreenAdapter implements ResizeReadyScreen, In
@Override
public void postAssetLoad() {
stage = new Stage(new ScreenViewport());
stage.addActor(zero1HD);
zero1HD.setScale((Gdx.graphics.getHeight()*0.8f)/zero1HD.getHeight());
zero1HD.setColor(0f,1f,1f,0f);
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);
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);
addActor(versionLabel);
@ -94,13 +94,13 @@ public class MainPage extends Page implements Observer {
@Override
public void act(float delta) {
dhv.act(delta);
// dhv.act(delta);
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
dhv.draw(batch, parentAlpha);
// dhv.draw(batch, parentAlpha);
super.draw(batch, parentAlpha);
}

View File

@ -79,7 +79,10 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
} else {
draw();
}
draw();
if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) {
stage.getCamera().position.lerp(cameraPosition, delta*lerpAlpha);
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) {
int index = selectables.getButtons().size - stackSelectables.getChildren().size - 1;
stackSelectables.add(selectables.getButtons().get(index));