removed deprecated code; platform based, window manager created; cleaned
code and files;
This commit is contained in:
parent
7fb42a63f8
commit
901594608c
@ -391,6 +391,6 @@ side-bars
|
||||
xy: 221, 35
|
||||
size: 15, 14
|
||||
split: 7, 7, 2, 2
|
||||
orig: 5, 14
|
||||
orig: 15, 14
|
||||
offset: 0, 0
|
||||
index: -1
|
Binary file not shown.
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 10 KiB |
@ -18,8 +18,11 @@ import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
|
||||
import zero1hd.rhythmbullet.util.AssetPack;
|
||||
import zero1hd.rhythmbullet.util.GenericFileTypeHandler;
|
||||
import zero1hd.rhythmbullet.util.InitialScreen;
|
||||
import zero1hd.rhythmbullet.util.RoundingResolutionHandler;
|
||||
import zero1hd.rhythmbullet.util.ScreenConfiguration;
|
||||
import zero1hd.rhythmbullet.util.ResizeReadyScreen;
|
||||
|
||||
|
||||
@ -40,15 +43,16 @@ public class RhythmBullet extends Game {
|
||||
private RoundingResolutionHandler rRHandler;
|
||||
private InitialScreen initialScreen;
|
||||
private AssetPack assetPack;
|
||||
|
||||
private ScreenConfiguration screenConfiguration;
|
||||
/**
|
||||
* This should be called before passed to LWJGL. Setup for system-dependent items such as UI and assets.
|
||||
* @param initialScreen the first screen to go to.
|
||||
* @param assetPack the asset package to be used.
|
||||
*/
|
||||
public void setup(InitialScreen initialScreen, AssetPack assetPack) {
|
||||
public void setup(InitialScreen initialScreen, AssetPack assetPack, ScreenConfiguration screenConfiguration) {
|
||||
this.initialScreen = initialScreen;
|
||||
this.assetPack = assetPack;
|
||||
this.screenConfiguration = screenConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -203,4 +207,8 @@ public class RhythmBullet extends Game {
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public ScreenConfiguration getScreenConfiguration() {
|
||||
return screenConfiguration;
|
||||
}
|
||||
}
|
||||
|
@ -219,7 +219,10 @@ public class MusicController extends Observable implements OnCompletionListener,
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
return music.isPlaying();
|
||||
if (music != null) {
|
||||
return music.isPlaying();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,9 +21,10 @@ public class DoubleHorizontalVisualizer implements Disposable {
|
||||
private int binsPerBar;
|
||||
private float offset;
|
||||
private int boundaryThickness;
|
||||
private float targetDelta;
|
||||
private float spacePercentage = 0.85f;
|
||||
private int barCount = 80;
|
||||
private float normalFactor = 1.2f;
|
||||
private float normalFactor = 0.8f;
|
||||
private float barChangeRate = 14f;
|
||||
private int smoothRange = 1;
|
||||
private int binsToInclude = 160;
|
||||
@ -34,12 +35,11 @@ public class DoubleHorizontalVisualizer implements Disposable {
|
||||
* @param width the width of the visualizer.
|
||||
* @param spacePercentage the percentage of a bar that should be space.
|
||||
*/
|
||||
public DoubleHorizontalVisualizer(int width, int height, MusicController musicController, PCMSystem PCMSystem) {
|
||||
public DoubleHorizontalVisualizer(int width, int height, int targetFPS, MusicController musicController, PCMSystem PCMSystem) {
|
||||
this.barWidth = width/barCount;
|
||||
this.spaceBetweenBars = MathUtils.round(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 = (binsToInclude/barCount);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
@ -48,6 +48,7 @@ public class DoubleHorizontalVisualizer implements Disposable {
|
||||
shapeRenderer = new ShapeRenderer();
|
||||
boundaryThickness = barWidth;
|
||||
offset = (width - (barCount*(barWidth+spaceBetweenBars)-spaceBetweenBars))/2f + x;
|
||||
this.targetDelta = 1f/targetFPS;
|
||||
}
|
||||
|
||||
public void act(float delta) {
|
||||
@ -55,10 +56,11 @@ public class DoubleHorizontalVisualizer implements Disposable {
|
||||
if (color.g > 1f) color.g = 0f;
|
||||
if (color.b > 1f) color.b = 0f;
|
||||
if (color.a > 1f) color.a = 0.2f;
|
||||
float[] freqBins = pcm.getFrequencyBins();
|
||||
for (int bar = 0; bar < amplitudes.length; bar++) {
|
||||
float normalizedAmplitude = 0;
|
||||
for (int freq = bar*binsPerBar; freq < (bar*binsPerBar) + binsPerBar; freq++) {
|
||||
normalizedAmplitude += Math.abs(pcm.getFrequencyBins()[freq]);
|
||||
normalizedAmplitude += Math.abs(freqBins[freq]);
|
||||
}
|
||||
amplitudes[bar] += normalizedAmplitude * normalFactor * (height/100f);
|
||||
amplitudes[bar] /= binsPerBar;
|
||||
@ -77,8 +79,11 @@ public class DoubleHorizontalVisualizer implements Disposable {
|
||||
}
|
||||
amplitudes[bar] /= smoothCount;
|
||||
|
||||
int pixelsMoved = MathUtils.round(amplitudes[bar] - barHeights[bar]);
|
||||
pixelsMoved = MathUtils.floor(pixelsMoved*delta*barChangeRate);
|
||||
|
||||
int pixelsMoved = 0;
|
||||
pixelsMoved = MathUtils.round(amplitudes[bar] - barHeights[bar]);
|
||||
pixelsMoved = MathUtils.floor(pixelsMoved*targetDelta*barChangeRate);
|
||||
|
||||
|
||||
barHeights[bar] += pixelsMoved;
|
||||
|
||||
|
@ -13,7 +13,6 @@ import zero1hd.rhythmbullet.entity.EntityManager;
|
||||
import zero1hd.rhythmbullet.entity.ally.Laser;
|
||||
import zero1hd.rhythmbullet.entity.ally.PolyjetEntity;
|
||||
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager;
|
||||
import zero1hd.rhythmbullet.util.ScoreManager;
|
||||
|
||||
|
||||
public class GameController implements Disposable, InputProcessor {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package zero1hd.rhythmbullet.util;
|
||||
package zero1hd.rhythmbullet.game;
|
||||
|
||||
public class ScoreManager {
|
||||
private int score;
|
@ -1,11 +1,10 @@
|
||||
package zero1hd.rhythmbullet.util;
|
||||
package zero1hd.rhythmbullet.graphics.ui.components;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import zero1hd.rhythmbullet.audio.metadata.AudioMetadata;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable;
|
||||
|
||||
public class MusicSelectableButtonGroup extends ButtonGroup<MusicSelectable> {
|
||||
private Array<MusicSelectable> buttons;
|
@ -1,4 +1,4 @@
|
||||
package zero1hd.rhythmbullet;
|
||||
package zero1hd.rhythmbullet.util;
|
||||
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
@ -1,8 +1,8 @@
|
||||
package zero1hd.rhythmbullet;
|
||||
package zero1hd.rhythmbullet.util;
|
||||
|
||||
import com.badlogic.gdx.Screen;
|
||||
|
||||
import zero1hd.rhythmbullet.util.ResizeReadyScreen;
|
||||
import zero1hd.rhythmbullet.RhythmBullet;
|
||||
|
||||
public interface InitialScreen extends ResizeReadyScreen {
|
||||
/**
|
@ -1,6 +0,0 @@
|
||||
package zero1hd.rhythmbullet.util;
|
||||
|
||||
@Deprecated
|
||||
public enum MiniEvents {
|
||||
SPECTRAL_FLUX_DONE, MUSIC_DATA_CLEANED, MUSIC_SELECTED, BACK, MAP_GENERATED, ANALYZER_ITERATED, MAPGEN_ITERATED;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package zero1hd.rhythmbullet.util;
|
||||
|
||||
@Deprecated
|
||||
public interface MiniListener {
|
||||
public void handle(MiniEvents ID);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package zero1hd.rhythmbullet.util;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
@Deprecated
|
||||
public class MiniSender {
|
||||
private volatile Array<MiniListener> listeners;
|
||||
|
||||
public MiniSender() {
|
||||
listeners = new Array<MiniListener>();
|
||||
}
|
||||
|
||||
public synchronized void send(MiniEvents ID) {
|
||||
for (MiniListener listener : listeners) {
|
||||
listener.handle(ID);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addListener(MiniListener handler) {
|
||||
listeners.add(handler);
|
||||
}
|
||||
|
||||
public synchronized void removeListener(MiniListener listener) {
|
||||
listeners.removeValue(listener, true);
|
||||
}
|
||||
}
|
25
core/src/zero1hd/rhythmbullet/util/ScreenConfiguration.java
Executable file
25
core/src/zero1hd/rhythmbullet/util/ScreenConfiguration.java
Executable file
@ -0,0 +1,25 @@
|
||||
package zero1hd.rhythmbullet.util;
|
||||
|
||||
public interface ScreenConfiguration {
|
||||
public void setFramesPerSecond(int fps);
|
||||
|
||||
public void setVsync(boolean useVsync);
|
||||
|
||||
public int getFramesPerSecond();
|
||||
|
||||
public boolean getVsync();
|
||||
|
||||
public int getScreenWidth();
|
||||
|
||||
public int getScreenHeight();
|
||||
|
||||
public int getWindowPosX();
|
||||
|
||||
public int getWindowPosY();
|
||||
|
||||
public void setWindowLocationX(int x);
|
||||
|
||||
public void setWindowLocationY(int y);
|
||||
|
||||
public void setWindowLocation(int x, int y);
|
||||
}
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user