removed deprecated code; platform based, window manager created; cleaned
code and files;
This commit is contained in:
@@ -23,7 +23,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle;
|
||||
|
||||
import zero1hd.rhythmbullet.AssetPack;
|
||||
import zero1hd.rhythmbullet.util.AssetPack;
|
||||
|
||||
public class DesktopAssetPack implements AssetPack {
|
||||
private FreeTypeFontGenerator default_fontGenerator;
|
||||
|
@@ -10,14 +10,16 @@ public class DesktopLauncher {
|
||||
public static void main (String[] arg) {
|
||||
RhythmBullet core;
|
||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||
DesktopScreenConfiguration screenConfig = new DesktopScreenConfiguration(config);
|
||||
config.title = "Rhythm Bullet";
|
||||
config.resizable = false;
|
||||
config.useHDPI = true;
|
||||
config.samples = 2;
|
||||
config.width = 128;
|
||||
config.height = 128;
|
||||
config.width = 512;
|
||||
config.height = 512;
|
||||
System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
|
||||
core = new RhythmBullet();
|
||||
core.setup(new SplashScreen(), new DesktopAssetPack());
|
||||
core.setup(new SplashScreen(), new DesktopAssetPack(), screenConfig);
|
||||
new LwjglApplication(core, config);
|
||||
}
|
||||
}
|
||||
|
70
desktop/src/zero1hd/rhythmbullet/desktop/DesktopScreenConfiguration.java
Executable file
70
desktop/src/zero1hd/rhythmbullet/desktop/DesktopScreenConfiguration.java
Executable file
@@ -0,0 +1,70 @@
|
||||
package zero1hd.rhythmbullet.desktop;
|
||||
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||
|
||||
import zero1hd.rhythmbullet.util.ScreenConfiguration;
|
||||
|
||||
public class DesktopScreenConfiguration implements ScreenConfiguration {
|
||||
private LwjglApplicationConfiguration configuration;
|
||||
|
||||
public DesktopScreenConfiguration(LwjglApplicationConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFramesPerSecond(int fps) {
|
||||
configuration.foregroundFPS = fps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVsync(boolean useVsync) {
|
||||
configuration.vSyncEnabled = useVsync;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFramesPerSecond() {
|
||||
return configuration.foregroundFPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVsync() {
|
||||
return configuration.vSyncEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScreenWidth() {
|
||||
return Display.getDesktopDisplayMode().getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScreenHeight() {
|
||||
return Display.getDesktopDisplayMode().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWindowPosX() {
|
||||
return Display.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWindowPosY() {
|
||||
return Display.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWindowLocationX(int x) {
|
||||
Display.setLocation(x, getWindowPosY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWindowLocationY(int y) {
|
||||
Display.setLocation(getWindowPosX(), y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWindowLocation(int x, int y) {
|
||||
Display.setLocation(x, y);
|
||||
}
|
||||
}
|
@@ -49,6 +49,8 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
Field bufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer");
|
||||
bufferField.setAccessible(true);
|
||||
buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer().asReadOnlyBuffer();
|
||||
playingBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||
compareBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||
} catch (IllegalArgumentException | SecurityException | ReflectionException e) {
|
||||
Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.", e);
|
||||
Gdx.app.exit();
|
||||
@@ -106,9 +108,11 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
private boolean synchronizeBufferWithPlayback() {
|
||||
int bufferPos = calcBufferPosition();
|
||||
if (bufferPos <= playingBuffer.limit()) {
|
||||
playingBuffer.position(calcBufferPosition());
|
||||
windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize);
|
||||
return true;
|
||||
synchronized (this) {
|
||||
playingBuffer.position(calcBufferPosition());
|
||||
windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -121,26 +125,23 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
sampleRate = mc.getCurrentMusicHeader().getSampleRate();
|
||||
String millisPerWindowF = df.format(windowSize/(float) sampleRate);
|
||||
millisPerWindow = (long) (Float.valueOf(millisPerWindowF)*1000);
|
||||
playingBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||
buffer.rewind();
|
||||
playingBuffer.put(buffer);
|
||||
playingBuffer.flip();
|
||||
|
||||
compareBuffer = ShortBuffer.allocate(buffer.capacity());
|
||||
buffer.rewind();
|
||||
compareBuffer.put(buffer);
|
||||
compareBuffer.flip();
|
||||
|
||||
buffer.rewind();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getFrequencyBins() {
|
||||
if (updated) {
|
||||
synchronized (this) {
|
||||
System.arraycopy(PCM, 1, frequencyBins, 0, frequencyBins.length);
|
||||
if (mc.isPlaying()) {
|
||||
if (updated) {
|
||||
synchronized (this) {
|
||||
System.arraycopy(PCM, 1, frequencyBins, 0, frequencyBins.length);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
for (int freqID = 0; freqID < frequencyBins.length; freqID++) {
|
||||
frequencyBins[freqID] = 0;
|
||||
}
|
||||
}
|
||||
updated = false;
|
||||
return frequencyBins;
|
||||
}
|
||||
|
||||
@@ -149,6 +150,8 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
return windowSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class BufferStreamReadThread implements Runnable {
|
||||
private String name = "PCM-Audio-Processing";
|
||||
private Thread thread;
|
||||
@@ -190,9 +193,7 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
for (int freqID = 0; freqID < frequencyBins.length; freqID++) {
|
||||
getFrequencyBins()[freqID] = 0;
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait();
|
||||
|
@@ -11,9 +11,9 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
|
||||
import zero1hd.rhythmbullet.InitialScreen;
|
||||
import zero1hd.rhythmbullet.RhythmBullet;
|
||||
import zero1hd.rhythmbullet.desktop.screens.main.MainScreen;
|
||||
import zero1hd.rhythmbullet.util.InitialScreen;
|
||||
|
||||
public class SplashScreen extends ScreenAdapter implements InitialScreen {
|
||||
private Stage stage;
|
||||
|
@@ -23,6 +23,7 @@ import zero1hd.rhythmbullet.desktop.audio.PCMObtainer;
|
||||
import zero1hd.rhythmbullet.desktop.graphics.ui.components.MusicControls;
|
||||
import zero1hd.rhythmbullet.graphics.ui.Page;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
|
||||
import zero1hd.rhythmbullet.util.ScreenConfiguration;
|
||||
|
||||
public class MainPage extends Page implements Observer {
|
||||
private MusicController mc;
|
||||
@@ -40,12 +41,12 @@ public class MainPage extends Page implements Observer {
|
||||
|
||||
private DoubleHorizontalVisualizer dhv;
|
||||
|
||||
public MainPage(MusicController musicController, AssetManager assetManager, Skin skin, ChangeListener playButtonListener, ChangeListener optionsButtonListener) {
|
||||
public MainPage(MusicController musicController, AssetManager assetManager, Skin skin, ScreenConfiguration screenConfiguration, ChangeListener playButtonListener, ChangeListener optionsButtonListener) {
|
||||
super(0, 0);
|
||||
this.mc = musicController;
|
||||
this.mc.addObserver(this);
|
||||
|
||||
dhv = new DoubleHorizontalVisualizer((int) getWidth(), (int) (getHeight()*0.3), mc, new PCMObtainer(mc));
|
||||
dhv = new DoubleHorizontalVisualizer((int) getWidth(), (int) (getHeight()*0.3), screenConfiguration.getFramesPerSecond(), mc, new PCMObtainer(mc));
|
||||
dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f));
|
||||
|
||||
title = new Image(assetManager.get("title.png", Texture.class));
|
||||
|
@@ -117,7 +117,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
|
||||
background = rhythmBullet.getAssetManager().get("backgrounds/mainBG.png", Texture.class);
|
||||
|
||||
mainPage = new MainPage(musicController, rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), listeners.musicSelectionPageButtonListener, listeners.optionsPageButtonListener);
|
||||
mainPage = new MainPage(musicController, rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), rhythmBullet.getScreenConfiguration(), listeners.musicSelectionPageButtonListener, listeners.optionsPageButtonListener);
|
||||
stage.addActor(mainPage);
|
||||
//End main menu
|
||||
|
||||
@@ -151,7 +151,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
stage.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
|
@@ -30,8 +30,8 @@ import zero1hd.rhythmbullet.audio.MusicMetadataController;
|
||||
import zero1hd.rhythmbullet.audio.MusicController;
|
||||
import zero1hd.rhythmbullet.graphics.ui.Page;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectableButtonGroup;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
|
||||
import zero1hd.rhythmbullet.util.MusicSelectableButtonGroup;
|
||||
|
||||
public class MusicSelectionPage extends Page implements Observer {
|
||||
Preferences musicFileAnnotation;
|
||||
|
Reference in New Issue
Block a user