fixed music selection page bug where after resize and metadata loading, application would crash
This commit is contained in:
parent
188608d40d
commit
8fd727e7d6
@ -16,7 +16,6 @@ public class MusicInfoController implements Disposable {
|
|||||||
private ExecutorService exec;
|
private ExecutorService exec;
|
||||||
private Array<MusicInfo> songInfoArray;
|
private Array<MusicInfo> songInfoArray;
|
||||||
private Preferences musicAnnotation;
|
private Preferences musicAnnotation;
|
||||||
private boolean doneLoading;
|
|
||||||
|
|
||||||
public MusicInfoController(MusicList musicList) {
|
public MusicInfoController(MusicList musicList) {
|
||||||
this.musicList = musicList;
|
this.musicList = musicList;
|
||||||
@ -33,39 +32,33 @@ public class MusicInfoController implements Disposable {
|
|||||||
* Non-blocking, loads on separate thread.
|
* Non-blocking, loads on separate thread.
|
||||||
*/
|
*/
|
||||||
public void loadSongInfo() {
|
public void loadSongInfo() {
|
||||||
doneLoading = false;
|
|
||||||
for (int i = 0; i < songInfoArray.size; i++) {
|
for (int i = 0; i < songInfoArray.size; i++) {
|
||||||
songInfoArray.get(i).dispose();
|
songInfoArray.get(i).dispose();
|
||||||
}
|
}
|
||||||
songInfoArray.clear();
|
songInfoArray.clear();
|
||||||
exec.submit(() -> {
|
exec.submit(() -> {
|
||||||
for (int i = 0; i < musicList.getTotal(); i++) {
|
for (int i = 0; i < musicList.getTotal(); i++) {
|
||||||
MusicInfo musicInfo = new MusicInfo(musicList.getMusicList().get(i), musicAnnotation);
|
MusicInfo musicInfo = new MusicInfo(musicList.getMusicArray().get(i), musicAnnotation);
|
||||||
musicInfo.loadInfo();
|
musicInfo.loadInfo();
|
||||||
songInfoArray.add(musicInfo);
|
songInfoArray.add(musicInfo);
|
||||||
}
|
}
|
||||||
doneLoading = true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDone() {
|
||||||
|
return (songInfoArray.size == musicList.getMusicArray().size);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
exec.shutdown();
|
exec.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify if loading song info is done.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public synchronized boolean isDoneLoading() {
|
|
||||||
return doneLoading;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Array<MusicInfo> getSongInfoArray() {
|
public Array<MusicInfo> getSongInfoArray() {
|
||||||
return songInfoArray;
|
return songInfoArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MusicInfo getInfo(FileHandle filehandle) {
|
public MusicInfo getInfo(FileHandle filehandle) {
|
||||||
return songInfoArray.get(musicList.getMusicList().indexOf(filehandle, true));
|
return songInfoArray.get(musicList.getMusicArray().indexOf(filehandle, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,14 @@ import zero1hd.rhythmbullet.audio.MusicManager;
|
|||||||
import zero1hd.rhythmbullet.util.FileHandleAlphabeticalComparator;
|
import zero1hd.rhythmbullet.util.FileHandleAlphabeticalComparator;
|
||||||
|
|
||||||
public class MusicList extends Observable {
|
public class MusicList extends Observable {
|
||||||
private Array<FileHandle> musicList;
|
private Array<FileHandle> musicArray;
|
||||||
private String searchPath;
|
private String searchPath;
|
||||||
private boolean searched;
|
private boolean searched;
|
||||||
private FileHandleAlphabeticalComparator fhac;
|
private FileHandleAlphabeticalComparator fhac;
|
||||||
private ExecutorService exec;
|
private ExecutorService exec;
|
||||||
|
|
||||||
public MusicList() {
|
public MusicList() {
|
||||||
musicList = new Array<>();
|
musicArray = new Array<>();
|
||||||
fhac = new FileHandleAlphabeticalComparator();
|
fhac = new FileHandleAlphabeticalComparator();
|
||||||
exec = Executors.newSingleThreadExecutor();
|
exec = Executors.newSingleThreadExecutor();
|
||||||
}
|
}
|
||||||
@ -46,17 +46,17 @@ public class MusicList extends Observable {
|
|||||||
*/
|
*/
|
||||||
public void refresh(boolean notifyOnCompletion) {
|
public void refresh(boolean notifyOnCompletion) {
|
||||||
searched = false;
|
searched = false;
|
||||||
musicList.clear();
|
musicArray.clear();
|
||||||
Gdx.app.debug("SongController", "Searching path: " + searchPath);
|
Gdx.app.debug("SongController", "Searching path: " + searchPath);
|
||||||
if (Gdx.files.absolute(searchPath).exists() && Gdx.files.absolute(searchPath).isDirectory()) {
|
if (Gdx.files.absolute(searchPath).exists() && Gdx.files.absolute(searchPath).isDirectory()) {
|
||||||
musicList.addAll(recursiveMusicFileList(Gdx.files.absolute(searchPath)));
|
musicArray.addAll(recursiveMusicFileList(Gdx.files.absolute(searchPath)));
|
||||||
}
|
}
|
||||||
if (!Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3").exists()) {
|
if (!Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3").exists()) {
|
||||||
Gdx.files.internal("music/Alan Walker - Spectre.mp3").copyTo(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
|
Gdx.files.internal("music/Alan Walker - Spectre.mp3").copyTo(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
|
||||||
}
|
}
|
||||||
musicList.add(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
|
musicArray.add(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
|
||||||
setChanged();
|
setChanged();
|
||||||
Sort.instance().sort(musicList, fhac);
|
Sort.instance().sort(musicArray, fhac);
|
||||||
searched = true;
|
searched = true;
|
||||||
|
|
||||||
if (notifyOnCompletion) {
|
if (notifyOnCompletion) {
|
||||||
@ -101,20 +101,20 @@ public class MusicList extends Observable {
|
|||||||
|
|
||||||
public MusicManager getMusicManagerFromIndex(int index) {
|
public MusicManager getMusicManagerFromIndex(int index) {
|
||||||
if (!searched) Gdx.app.debug("SongList", "Warning, this list hasn't even searched yet...");
|
if (!searched) Gdx.app.debug("SongList", "Warning, this list hasn't even searched yet...");
|
||||||
return getAudioData(musicList.get(index));
|
return getAudioData(musicArray.get(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotal() {
|
public int getTotal() {
|
||||||
return musicList.size;
|
return musicArray.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileHandle getSongFileHandleFromIndex(int index) {
|
public FileHandle getSongFileHandleFromIndex(int index) {
|
||||||
if (!searched) Gdx.app.debug("SongList", "Warning, this list hasn't even searched yet...");
|
if (!searched) Gdx.app.debug("SongList", "Warning, this list hasn't even searched yet...");
|
||||||
return musicList.get(index);
|
return musicArray.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array<FileHandle> getMusicList() {
|
public Array<FileHandle> getMusicArray() {
|
||||||
return musicList;
|
return musicArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSearched() {
|
public boolean isSearched() {
|
||||||
|
@ -194,7 +194,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
|||||||
if (uiSongCount == mc.getMusicList().getTotal()) {
|
if (uiSongCount == mc.getMusicList().getTotal()) {
|
||||||
selectMusicUI(mc.getCurrentMusicManager());
|
selectMusicUI(mc.getCurrentMusicManager());
|
||||||
}
|
}
|
||||||
} else if (uiSongInfoCount < selectables.size && mic.isDoneLoading()) {
|
} else if (uiSongInfoCount < selectables.size && mic.isDone()) {
|
||||||
selectables.get(uiSongInfoCount).updateInfo(mic.getSongInfoArray().get(uiSongInfoCount));
|
selectables.get(uiSongInfoCount).updateInfo(mic.getSongInfoArray().get(uiSongInfoCount));
|
||||||
uiSongInfoCount++;
|
uiSongInfoCount++;
|
||||||
if (uiSongInfoCount == selectables.size) {
|
if (uiSongInfoCount == selectables.size) {
|
||||||
@ -267,7 +267,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
|||||||
this.currentlySelected = currentlySelected;
|
this.currentlySelected = currentlySelected;
|
||||||
songSelectionTimer = 1f;
|
songSelectionTimer = 1f;
|
||||||
|
|
||||||
if (mic.isDoneLoading() && uiSongInfoCount == selectables.size) {
|
if (mic.isDone() && uiSongInfoCount == selectables.size) {
|
||||||
updateInformation();
|
updateInformation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,7 +314,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
|||||||
|
|
||||||
private void playSelectedMusic() {
|
private void playSelectedMusic() {
|
||||||
if (currentlySelected.getMusicFile() != mc.getCurrentMusicManager().getMusicFile()) {
|
if (currentlySelected.getMusicFile() != mc.getCurrentMusicManager().getMusicFile()) {
|
||||||
int index = mc.getMusicList().getMusicList().indexOf(currentlySelected.getMusicFile(), true);
|
int index = mc.getMusicList().getMusicArray().indexOf(currentlySelected.getMusicFile(), true);
|
||||||
mc.setMusicByIndex(index);
|
mc.setMusicByIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import com.badlogic.gdx.ScreenAdapter;
|
|||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||||
@ -34,7 +34,6 @@ import zero1hd.rhythmbullet.util.AdvancedResizeScreen;
|
|||||||
|
|
||||||
public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScreen {
|
public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScreen {
|
||||||
public Stage stage;
|
public Stage stage;
|
||||||
private Texture background;
|
|
||||||
private Vector3 cameraPosition;
|
private Vector3 cameraPosition;
|
||||||
|
|
||||||
private MainPage mainPage;
|
private MainPage mainPage;
|
||||||
@ -60,9 +59,8 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
|||||||
private TextureRegion fboRegion;
|
private TextureRegion fboRegion;
|
||||||
private int fboSize;
|
private int fboSize;
|
||||||
private int blurlvl;
|
private int blurlvl;
|
||||||
private SpriteBatch screenBatch;
|
private Batch batch;
|
||||||
private ScreenViewport screenViewport;
|
private ScreenViewport screenViewport;
|
||||||
private boolean shaderLoaded;
|
|
||||||
|
|
||||||
public MainMenuScreen(RhythmBullet core) {
|
public MainMenuScreen(RhythmBullet core) {
|
||||||
this.core = core;
|
this.core = core;
|
||||||
@ -77,21 +75,110 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
|||||||
mlc.setShuffle(true);
|
mlc.setShuffle(true);
|
||||||
|
|
||||||
mic = new MusicInfoController(musicList);
|
mic = new MusicInfoController(musicList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(float delta) {
|
||||||
|
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
|
||||||
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
stage.act(delta);
|
||||||
|
if (blurlvl > 0) {
|
||||||
|
// Begin drawing a normal version of screen
|
||||||
|
normalBuffer.begin();
|
||||||
|
stage.getViewport().apply();
|
||||||
|
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
|
||||||
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
stage.draw();
|
||||||
|
normalBuffer.end();
|
||||||
|
|
||||||
|
// BEGINNING NORMAL SCREEN RENDER
|
||||||
|
screenViewport.apply();
|
||||||
|
|
||||||
|
// Begin light filtering
|
||||||
|
lightFilterBuffer.begin();
|
||||||
|
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
|
||||||
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
|
||||||
|
batch.setShader(brightFilterShader);
|
||||||
|
batch.setProjectionMatrix(screenViewport.getCamera().combined);
|
||||||
|
batch.begin(); //BATCH STARTS HERE
|
||||||
|
batch.draw(fboRegion, 0, 0, stage.getWidth(), stage.getHeight());
|
||||||
|
batch.flush();
|
||||||
|
lightFilterBuffer.end();
|
||||||
|
//
|
||||||
|
for (int i = 0; i < blurlvl; i++) {
|
||||||
|
// Horizontal gaussian blur
|
||||||
|
hBlur.begin();
|
||||||
|
if (i > 0) {
|
||||||
|
fboRegion.setTexture(vBlur.getColorBufferTexture());
|
||||||
|
} else {
|
||||||
|
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
|
||||||
|
}
|
||||||
|
batch.setShader(gaussianBlurShader);
|
||||||
|
gaussianBlurShader.setUniformi("horizontal", 1);
|
||||||
|
batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
|
||||||
|
batch.flush();
|
||||||
|
hBlur.end();
|
||||||
|
|
||||||
|
// //Vertical gaussian blur
|
||||||
|
vBlur.begin();
|
||||||
|
fboRegion.setTexture(hBlur.getColorBufferTexture());
|
||||||
|
batch.setShader(gaussianBlurShader);
|
||||||
|
gaussianBlurShader.setUniformi("horizontal", 0);
|
||||||
|
batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
|
||||||
|
batch.flush();
|
||||||
|
vBlur.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
|
||||||
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
batch.setShader(combineShader);
|
||||||
|
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
|
||||||
|
batch.draw(fboRegion, 0f, 0f, fboSize, fboSize);
|
||||||
|
batch.setShader(null);
|
||||||
|
batch.end(); //STAGE BATCH ENDS HERE
|
||||||
|
|
||||||
|
} else {
|
||||||
|
stage.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) {
|
||||||
|
stage.getCamera().position.lerp(cameraPosition, delta*lerpAlpha);
|
||||||
|
stage.getViewport().apply();
|
||||||
|
}
|
||||||
|
|
||||||
screenBatch = new SpriteBatch();
|
super.render(delta);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void preAssetLoad() {
|
||||||
|
stage.clear();
|
||||||
|
mainPage.dispose();
|
||||||
|
optionsPage.dispose();
|
||||||
|
creditsPage.dispose();
|
||||||
|
keybindPage.dispose();
|
||||||
|
musicSelectionPage.dispose();
|
||||||
|
|
||||||
|
dismantleShaders();
|
||||||
|
setBlurlvl(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postAssetLoad() {
|
public void postAssetLoad() {
|
||||||
attemptLoadShaders();
|
if (core.getPrefs().getBoolean("glow shader", true)) {
|
||||||
|
setupShaders();
|
||||||
|
|
||||||
|
if (core.getPrefs().getBoolean("enhanced glow", false)) {
|
||||||
|
setBlurlvl(1);
|
||||||
|
} else {
|
||||||
|
setBlurlvl(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mainPage = new MainPage(core, cameraPosition, mlc, this);
|
mainPage = new MainPage(core, cameraPosition, mlc, this);
|
||||||
mainPage.setPosition(0, 0);
|
mainPage.setPosition(0, 0);
|
||||||
stage.addActor(mainPage);
|
stage.addActor(mainPage);
|
||||||
//End main menu
|
//End main menu
|
||||||
|
|
||||||
background = core.getAssetManager().get("backgrounds/mainBG.png", Texture.class);
|
|
||||||
|
|
||||||
|
|
||||||
keybindPage = new KeybindOptionsPage(core.getDefaultSkin(), core.getAssetManager(), cameraPosition);
|
keybindPage = new KeybindOptionsPage(core.getDefaultSkin(), core.getAssetManager(), cameraPosition);
|
||||||
keybindPage.setPosition(-1f*Gdx.graphics.getWidth(), -1f*Gdx.graphics.getHeight());
|
keybindPage.setPosition(-1f*Gdx.graphics.getWidth(), -1f*Gdx.graphics.getHeight());
|
||||||
stage.addActor(keybindPage);
|
stage.addActor(keybindPage);
|
||||||
@ -137,12 +224,12 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
|||||||
super.clicked(event, x, y);
|
super.clicked(event, x, y);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
mlc.getMusicList().deleteObservers();
|
||||||
|
mlc.deleteObservers();
|
||||||
|
mlc.addObserver(musicSelectionPage);
|
||||||
mlc.addObserver(mainPage);
|
mlc.addObserver(mainPage);
|
||||||
mlc.getMusicList().addObserver(mainPage);
|
mlc.getMusicList().addObserver(mainPage);
|
||||||
mlc.getMusicList().addObserver(optionsPage);
|
|
||||||
mlc.addObserver(musicSelectionPage);
|
|
||||||
|
|
||||||
if (mlc.getMusicList().isSearched() && mlc.getCurrentMusicManager() != null) {
|
if (mlc.getMusicList().isSearched() && mlc.getCurrentMusicManager() != null) {
|
||||||
MusicManager mManager = mlc.getCurrentMusicManager();
|
MusicManager mManager = mlc.getCurrentMusicManager();
|
||||||
mainPage.updateVisualsForDifferentSong(mManager);
|
mainPage.updateVisualsForDifferentSong(mManager);
|
||||||
@ -150,104 +237,6 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(float delta) {
|
|
||||||
Gdx.gl.glClearColor(0.22f, 0.22f, 0.22f, 1f);
|
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
||||||
stage.act(delta);
|
|
||||||
|
|
||||||
if (blurlvl > 0) {
|
|
||||||
// Begin drawing a normal version of screen
|
|
||||||
normalBuffer.begin();
|
|
||||||
stage.getViewport().apply();
|
|
||||||
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1f);
|
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
||||||
draw();
|
|
||||||
normalBuffer.end();
|
|
||||||
|
|
||||||
// BEGINNING NORMAL SCREEN RENDER
|
|
||||||
screenViewport.apply();
|
|
||||||
|
|
||||||
// Begin light filtering
|
|
||||||
lightFilterBuffer.begin();
|
|
||||||
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
|
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
||||||
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
|
|
||||||
screenBatch.setShader(brightFilterShader);
|
|
||||||
screenBatch.setProjectionMatrix(screenViewport.getCamera().combined);
|
|
||||||
screenBatch.begin(); //BATCH STARTS HERE
|
|
||||||
//TODO Do shader version of background for main menu.
|
|
||||||
|
|
||||||
screenBatch.draw(fboRegion, 0, 0, stage.getWidth(), stage.getHeight());
|
|
||||||
screenBatch.flush();
|
|
||||||
lightFilterBuffer.end();
|
|
||||||
//
|
|
||||||
for (int i = 0; i < blurlvl; i++) {
|
|
||||||
// Horizontal gaussian blur
|
|
||||||
hBlur.begin();
|
|
||||||
if (i > 0) {
|
|
||||||
fboRegion.setTexture(vBlur.getColorBufferTexture());
|
|
||||||
} else {
|
|
||||||
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
|
|
||||||
}
|
|
||||||
screenBatch.setShader(gaussianBlurShader);
|
|
||||||
gaussianBlurShader.setUniformi("horizontal", 1);
|
|
||||||
screenBatch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
|
|
||||||
screenBatch.flush();
|
|
||||||
hBlur.end();
|
|
||||||
|
|
||||||
// //Vertical gaussian blur
|
|
||||||
vBlur.begin();
|
|
||||||
fboRegion.setTexture(hBlur.getColorBufferTexture());
|
|
||||||
screenBatch.setShader(gaussianBlurShader);
|
|
||||||
gaussianBlurShader.setUniformi("horizontal", 0);
|
|
||||||
screenBatch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
|
|
||||||
screenBatch.flush();
|
|
||||||
vBlur.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
|
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
||||||
screenBatch.setShader(combineShader);
|
|
||||||
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
|
|
||||||
screenBatch.draw(fboRegion, 0f, 0f, fboSize, fboSize);
|
|
||||||
screenBatch.setShader(null);
|
|
||||||
screenBatch.end(); //BATCH ENDS HERE
|
|
||||||
|
|
||||||
} else {
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//move camera
|
|
||||||
if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) {
|
|
||||||
stage.getCamera().position.lerp(cameraPosition, delta*lerpAlpha);
|
|
||||||
stage.getViewport().apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.render(delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void draw() {
|
|
||||||
screenBatch.begin();
|
|
||||||
screenBatch.draw(background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
||||||
screenBatch.end();
|
|
||||||
stage.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void preAssetLoad() {
|
|
||||||
mlc.getMusicList().deleteObservers();
|
|
||||||
mlc.deleteObservers();
|
|
||||||
|
|
||||||
stage.clear();
|
|
||||||
mainPage.dispose();
|
|
||||||
screenBatch.dispose();
|
|
||||||
optionsPage.dispose();
|
|
||||||
creditsPage.dispose();
|
|
||||||
keybindPage.dispose();
|
|
||||||
musicSelectionPage.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
Gdx.input.setInputProcessor(stage);
|
Gdx.input.setInputProcessor(stage);
|
||||||
@ -280,31 +269,82 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
|||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
stage.dispose();
|
stage.dispose();
|
||||||
unloadShaders();
|
dismantleShaders();
|
||||||
mic.dispose();
|
mic.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calcLerpAlpha(int width) {
|
public void setupShaders() {
|
||||||
if (width <= 3835) {
|
Gdx.app.debug("Shader", "Loading glow shaders.");
|
||||||
lerpAlpha = 5.0f;
|
batch = new SpriteBatch();
|
||||||
} else {
|
screenViewport = new ScreenViewport();
|
||||||
lerpAlpha = 5.5f;
|
screenViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
((OrthographicCamera) screenViewport.getCamera()).setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
|
||||||
|
Gdx.app.debug("Shader", "using glow shader");
|
||||||
|
brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh"));
|
||||||
|
if (!brightFilterShader.isCompiled()) {
|
||||||
|
Gdx.app.error("Shader failed to compile", brightFilterShader.getLog());
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
if (brightFilterShader.getLog().length() != 0) {
|
||||||
|
Gdx.app.error("Shader", brightFilterShader.getLog());
|
||||||
|
}
|
||||||
|
|
||||||
|
gaussianBlurShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/gaussian_blur.fsh"));
|
||||||
|
if (!gaussianBlurShader.isCompiled()) {
|
||||||
|
Gdx.app.error("Shader failed to compile", gaussianBlurShader.getLog());
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
if (gaussianBlurShader.getLog().length() != 0) {
|
||||||
|
Gdx.app.error("Shader", gaussianBlurShader.getLog());
|
||||||
|
}
|
||||||
|
|
||||||
|
combineShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/combine.fsh"));
|
||||||
|
if (!combineShader.isCompiled()) {
|
||||||
|
Gdx.app.error("Shader failed to compile", combineShader.getLog());
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
if (combineShader.getLog().length() != 0) {
|
||||||
|
Gdx.app.error("Shader", combineShader.getLog());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (Gdx.graphics.getWidth() < 1024) {
|
||||||
|
fboSize = 1024;
|
||||||
|
} else if (Gdx.graphics.getWidth() < 2048) {
|
||||||
|
fboSize = 2048;
|
||||||
|
} else {
|
||||||
|
fboSize = 4096;
|
||||||
|
}
|
||||||
|
|
||||||
|
lightFilterBuffer = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
||||||
|
normalBuffer = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
|
||||||
|
hBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
||||||
|
vBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
||||||
|
|
||||||
|
fboRegion = new TextureRegion(normalBuffer.getColorBufferTexture());
|
||||||
|
fboRegion.flip(false, true);
|
||||||
|
|
||||||
|
combineShader.begin();
|
||||||
|
combineShader.setUniformi("u_texture1", 1);
|
||||||
|
combineShader.end();
|
||||||
|
|
||||||
|
vBlur.getColorBufferTexture().bind(1);
|
||||||
|
|
||||||
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
|
||||||
|
ShaderProgram.pedantic = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unloadShaders() {
|
public void dismantleShaders() {
|
||||||
Gdx.app.debug("MainMenu", "shader being unloaded.");
|
|
||||||
if (core.getPrefs().getBoolean("glow shader")) {
|
if (core.getPrefs().getBoolean("glow shader")) {
|
||||||
if (shaderLoaded) {
|
brightFilterShader.dispose();
|
||||||
brightFilterShader.dispose();
|
combineShader.dispose();
|
||||||
combineShader.dispose();
|
gaussianBlurShader.dispose();
|
||||||
gaussianBlurShader.dispose();
|
normalBuffer.dispose();
|
||||||
normalBuffer.dispose();
|
lightFilterBuffer.dispose();
|
||||||
lightFilterBuffer.dispose();
|
vBlur.dispose();
|
||||||
vBlur.dispose();
|
hBlur.dispose();
|
||||||
hBlur.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
brightFilterShader = null;
|
brightFilterShader = null;
|
||||||
@ -315,16 +355,11 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
|||||||
vBlur = null;
|
vBlur = null;
|
||||||
hBlur = null;
|
hBlur = null;
|
||||||
|
|
||||||
shaderLoaded = false;
|
setBlurlvl(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlurlvl(int blurlvl) {
|
public void setBlurlvl(int blurlvl) {
|
||||||
this.blurlvl = blurlvl;
|
this.blurlvl = blurlvl;
|
||||||
if (blurlvl > 0) {
|
|
||||||
attemptLoadShaders();
|
|
||||||
} else {
|
|
||||||
unloadShaders();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 getCameraPosition() {
|
public Vector3 getCameraPosition() {
|
||||||
@ -351,78 +386,13 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
|
|||||||
return optionsPage;
|
return optionsPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int attemptLoadShaders() {
|
|
||||||
|
private void calcLerpAlpha(int width) {
|
||||||
Gdx.app.debug("MainMenu", "Attempting to load shaders.");
|
if (width <= 3835) {
|
||||||
if (core.getPrefs().getBoolean("glow shader", true) && !shaderLoaded) {
|
lerpAlpha = 5.0f;
|
||||||
if (core.getPrefs().getBoolean("enhanced glow", false)) {
|
} else {
|
||||||
blurlvl = 5;
|
lerpAlpha = 5.5f;
|
||||||
} else {
|
|
||||||
blurlvl = 1;
|
|
||||||
}
|
|
||||||
Gdx.app.debug("Shader", "Loading glow shaders.");
|
|
||||||
screenViewport = new ScreenViewport();
|
|
||||||
screenViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
||||||
((OrthographicCamera) screenViewport.getCamera()).setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
||||||
|
|
||||||
Gdx.app.debug("Shader", "using glow shader");
|
|
||||||
brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh"));
|
|
||||||
if (!brightFilterShader.isCompiled()) {
|
|
||||||
Gdx.app.error("Shader failed to compile", brightFilterShader.getLog());
|
|
||||||
if (brightFilterShader.getLog().length() != 0) {
|
|
||||||
Gdx.app.error("Shader", brightFilterShader.getLog());
|
|
||||||
}
|
|
||||||
setBlurlvl(0);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
gaussianBlurShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/gaussian_blur.fsh"));
|
|
||||||
if (!gaussianBlurShader.isCompiled()) {
|
|
||||||
Gdx.app.error("Shader failed to compile", gaussianBlurShader.getLog());
|
|
||||||
if (gaussianBlurShader.getLog().length() != 0) {
|
|
||||||
Gdx.app.error("Shader", gaussianBlurShader.getLog());
|
|
||||||
}
|
|
||||||
setBlurlvl(0);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
combineShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/combine.fsh"));
|
|
||||||
if (!combineShader.isCompiled()) {
|
|
||||||
Gdx.app.error("Shader failed to compile", combineShader.getLog());
|
|
||||||
if (combineShader.getLog().length() != 0) {
|
|
||||||
Gdx.app.error("Shader", combineShader.getLog());
|
|
||||||
}
|
|
||||||
setBlurlvl(0);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Gdx.graphics.getWidth() < 1024) {
|
|
||||||
fboSize = 1024;
|
|
||||||
} else if (Gdx.graphics.getWidth() < 2048) {
|
|
||||||
fboSize = 2048;
|
|
||||||
} else {
|
|
||||||
fboSize = 4096;
|
|
||||||
}
|
|
||||||
|
|
||||||
lightFilterBuffer = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
|
||||||
normalBuffer = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
|
|
||||||
hBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
|
||||||
vBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
|
|
||||||
|
|
||||||
fboRegion = new TextureRegion(normalBuffer.getColorBufferTexture());
|
|
||||||
fboRegion.flip(false, true);
|
|
||||||
|
|
||||||
combineShader.begin();
|
|
||||||
combineShader.setUniformi("u_texture1", 1);
|
|
||||||
combineShader.end();
|
|
||||||
|
|
||||||
vBlur.getColorBufferTexture().bind(1);
|
|
||||||
|
|
||||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
|
|
||||||
ShaderProgram.pedantic = false;
|
|
||||||
shaderLoaded = true;
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user