removed deprecated code; platform based, window manager created; cleaned

code and files;
This commit is contained in:
Harrison Deng 2018-08-16 13:49:44 -05:00
parent 7fb42a63f8
commit 901594608c
22 changed files with 159 additions and 85 deletions

View File

@ -391,6 +391,6 @@ side-bars
xy: 221, 35 xy: 221, 35
size: 15, 14 size: 15, 14
split: 7, 7, 2, 2 split: 7, 7, 2, 2
orig: 5, 14 orig: 15, 14
offset: 0, 0 offset: 0, 0
index: -1 index: -1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -18,8 +18,11 @@ import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import zero1hd.rhythmbullet.util.AssetPack;
import zero1hd.rhythmbullet.util.GenericFileTypeHandler; import zero1hd.rhythmbullet.util.GenericFileTypeHandler;
import zero1hd.rhythmbullet.util.InitialScreen;
import zero1hd.rhythmbullet.util.RoundingResolutionHandler; import zero1hd.rhythmbullet.util.RoundingResolutionHandler;
import zero1hd.rhythmbullet.util.ScreenConfiguration;
import zero1hd.rhythmbullet.util.ResizeReadyScreen; import zero1hd.rhythmbullet.util.ResizeReadyScreen;
@ -40,15 +43,16 @@ public class RhythmBullet extends Game {
private RoundingResolutionHandler rRHandler; private RoundingResolutionHandler rRHandler;
private InitialScreen initialScreen; private InitialScreen initialScreen;
private AssetPack assetPack; private AssetPack assetPack;
private ScreenConfiguration screenConfiguration;
/** /**
* This should be called before passed to LWJGL. Setup for system-dependent items such as UI and assets. * 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 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(InitialScreen initialScreen, AssetPack assetPack) { public void setup(InitialScreen initialScreen, AssetPack assetPack, ScreenConfiguration screenConfiguration) {
this.initialScreen = initialScreen; this.initialScreen = initialScreen;
this.assetPack = assetPack; this.assetPack = assetPack;
this.screenConfiguration = screenConfiguration;
} }
@Override @Override
@ -203,4 +207,8 @@ public class RhythmBullet extends Game {
} }
super.dispose(); super.dispose();
} }
public ScreenConfiguration getScreenConfiguration() {
return screenConfiguration;
}
} }

View File

@ -219,7 +219,10 @@ public class MusicController extends Observable implements OnCompletionListener,
} }
public boolean isPlaying() { public boolean isPlaying() {
return music.isPlaying(); if (music != null) {
return music.isPlaying();
}
return false;
} }
/** /**

View File

@ -21,9 +21,10 @@ public class DoubleHorizontalVisualizer implements Disposable {
private int binsPerBar; private int binsPerBar;
private float offset; private float offset;
private int boundaryThickness; private int boundaryThickness;
private float targetDelta;
private float spacePercentage = 0.85f; private float spacePercentage = 0.85f;
private int barCount = 80; private int barCount = 80;
private float normalFactor = 1.2f; private float normalFactor = 0.8f;
private float barChangeRate = 14f; private float barChangeRate = 14f;
private int smoothRange = 1; private int smoothRange = 1;
private int binsToInclude = 160; private int binsToInclude = 160;
@ -34,12 +35,11 @@ public class DoubleHorizontalVisualizer implements Disposable {
* @param width the width of the visualizer. * @param width the width of the visualizer.
* @param spacePercentage the percentage of a bar that should be space. * @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.barWidth = width/barCount;
this.spaceBetweenBars = MathUtils.round(barWidth * spacePercentage); this.spaceBetweenBars = MathUtils.round(barWidth * spacePercentage);
this.barWidth -= spaceBetweenBars; this.barWidth -= spaceBetweenBars;
pcm = PCMSystem; pcm = PCMSystem;
if (barWidth < 1) throw new IllegalArgumentException("The arguments you passed caused the bar width to be 0.");
binsPerBar = (binsToInclude/barCount); binsPerBar = (binsToInclude/barCount);
this.width = width; this.width = width;
this.height = height; this.height = height;
@ -48,6 +48,7 @@ public class DoubleHorizontalVisualizer implements Disposable {
shapeRenderer = new ShapeRenderer(); shapeRenderer = new ShapeRenderer();
boundaryThickness = barWidth; boundaryThickness = barWidth;
offset = (width - (barCount*(barWidth+spaceBetweenBars)-spaceBetweenBars))/2f + x; offset = (width - (barCount*(barWidth+spaceBetweenBars)-spaceBetweenBars))/2f + x;
this.targetDelta = 1f/targetFPS;
} }
public void act(float delta) { public void act(float delta) {
@ -55,10 +56,11 @@ public class DoubleHorizontalVisualizer implements Disposable {
if (color.g > 1f) color.g = 0f; if (color.g > 1f) color.g = 0f;
if (color.b > 1f) color.b = 0f; if (color.b > 1f) color.b = 0f;
if (color.a > 1f) color.a = 0.2f; if (color.a > 1f) color.a = 0.2f;
float[] freqBins = pcm.getFrequencyBins();
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(freqBins[freq]);
} }
amplitudes[bar] += normalizedAmplitude * normalFactor * (height/100f); amplitudes[bar] += normalizedAmplitude * normalFactor * (height/100f);
amplitudes[bar] /= binsPerBar; amplitudes[bar] /= binsPerBar;
@ -77,8 +79,11 @@ public class DoubleHorizontalVisualizer implements Disposable {
} }
amplitudes[bar] /= smoothCount; 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; barHeights[bar] += pixelsMoved;

View File

@ -13,7 +13,6 @@ import zero1hd.rhythmbullet.entity.EntityManager;
import zero1hd.rhythmbullet.entity.ally.Laser; import zero1hd.rhythmbullet.entity.ally.Laser;
import zero1hd.rhythmbullet.entity.ally.PolyjetEntity; import zero1hd.rhythmbullet.entity.ally.PolyjetEntity;
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager; import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager;
import zero1hd.rhythmbullet.util.ScoreManager;
public class GameController implements Disposable, InputProcessor { public class GameController implements Disposable, InputProcessor {

View File

@ -1,4 +1,4 @@
package zero1hd.rhythmbullet.util; package zero1hd.rhythmbullet.game;
public class ScoreManager { public class ScoreManager {
private int score; private int score;

View File

@ -1,11 +1,10 @@
package zero1hd.rhythmbullet.util; package zero1hd.rhythmbullet.graphics.ui.components;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup; import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.audio.metadata.AudioMetadata; import zero1hd.rhythmbullet.audio.metadata.AudioMetadata;
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable;
public class MusicSelectableButtonGroup extends ButtonGroup<MusicSelectable> { public class MusicSelectableButtonGroup extends ButtonGroup<MusicSelectable> {
private Array<MusicSelectable> buttons; private Array<MusicSelectable> buttons;

View File

@ -1,4 +1,4 @@
package zero1hd.rhythmbullet; package zero1hd.rhythmbullet.util;
import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;

View File

@ -1,8 +1,8 @@
package zero1hd.rhythmbullet; package zero1hd.rhythmbullet.util;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import zero1hd.rhythmbullet.util.ResizeReadyScreen; import zero1hd.rhythmbullet.RhythmBullet;
public interface InitialScreen extends ResizeReadyScreen { public interface InitialScreen extends ResizeReadyScreen {
/** /**

View File

@ -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;
}

View File

@ -1,6 +0,0 @@
package zero1hd.rhythmbullet.util;
@Deprecated
public interface MiniListener {
public void handle(MiniEvents ID);
}

View File

@ -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);
}
}

View 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);
}

View File

@ -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.TextField.TextFieldStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle; import com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle;
import zero1hd.rhythmbullet.AssetPack; import zero1hd.rhythmbullet.util.AssetPack;
public class DesktopAssetPack implements AssetPack { public class DesktopAssetPack implements AssetPack {
private FreeTypeFontGenerator default_fontGenerator; private FreeTypeFontGenerator default_fontGenerator;

View File

@ -10,14 +10,16 @@ public class DesktopLauncher {
public static void main (String[] arg) { public static void main (String[] arg) {
RhythmBullet core; RhythmBullet core;
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
DesktopScreenConfiguration screenConfig = new DesktopScreenConfiguration(config);
config.title = "Rhythm Bullet"; config.title = "Rhythm Bullet";
config.resizable = false; config.resizable = false;
config.useHDPI = true; config.useHDPI = true;
config.samples = 2; config.samples = 2;
config.width = 128; config.width = 512;
config.height = 128; config.height = 512;
System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
core = new RhythmBullet(); core = new RhythmBullet();
core.setup(new SplashScreen(), new DesktopAssetPack()); core.setup(new SplashScreen(), new DesktopAssetPack(), screenConfig);
new LwjglApplication(core, config); new LwjglApplication(core, config);
} }
} }

View 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);
}
}

View File

@ -49,6 +49,8 @@ public class PCMObtainer implements Observer, PCMSystem {
Field bufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer"); Field bufferField = ClassReflection.getDeclaredField(OpenALMusic.class, "tempBuffer");
bufferField.setAccessible(true); bufferField.setAccessible(true);
buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer().asReadOnlyBuffer(); buffer = ((ByteBuffer) bufferField.get(null)).asShortBuffer().asReadOnlyBuffer();
playingBuffer = ShortBuffer.allocate(buffer.capacity());
compareBuffer = ShortBuffer.allocate(buffer.capacity());
} catch (IllegalArgumentException | SecurityException | ReflectionException e) { } catch (IllegalArgumentException | SecurityException | ReflectionException e) {
Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.", e); Gdx.app.debug("Visualizer reflection", "Failed attempt at retrieving tempBuffer field.", e);
Gdx.app.exit(); Gdx.app.exit();
@ -106,9 +108,11 @@ public class PCMObtainer implements Observer, PCMSystem {
private boolean synchronizeBufferWithPlayback() { private boolean synchronizeBufferWithPlayback() {
int bufferPos = calcBufferPosition(); int bufferPos = calcBufferPosition();
if (bufferPos <= playingBuffer.limit()) { if (bufferPos <= playingBuffer.limit()) {
playingBuffer.position(calcBufferPosition()); synchronized (this) {
windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize); playingBuffer.position(calcBufferPosition());
return true; windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize);
return true;
}
} }
return false; return false;
} }
@ -121,26 +125,23 @@ public class PCMObtainer implements Observer, PCMSystem {
sampleRate = mc.getCurrentMusicHeader().getSampleRate(); sampleRate = mc.getCurrentMusicHeader().getSampleRate();
String millisPerWindowF = df.format(windowSize/(float) sampleRate); String millisPerWindowF = df.format(windowSize/(float) sampleRate);
millisPerWindow = (long) (Float.valueOf(millisPerWindowF)*1000); 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 @Override
public float[] getFrequencyBins() { public float[] getFrequencyBins() {
if (updated) { if (mc.isPlaying()) {
synchronized (this) { if (updated) {
System.arraycopy(PCM, 1, frequencyBins, 0, frequencyBins.length); 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; return frequencyBins;
} }
@ -149,6 +150,8 @@ public class PCMObtainer implements Observer, PCMSystem {
return windowSize; return windowSize;
} }
private class BufferStreamReadThread implements Runnable { private class BufferStreamReadThread implements Runnable {
private String name = "PCM-Audio-Processing"; private String name = "PCM-Audio-Processing";
private Thread thread; private Thread thread;
@ -190,9 +193,7 @@ public class PCMObtainer implements Observer, PCMSystem {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
for (int freqID = 0; freqID < frequencyBins.length; freqID++) {
getFrequencyBins()[freqID] = 0;
}
synchronized (this) { synchronized (this) {
try { try {
wait(); wait();

View File

@ -11,9 +11,9 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.viewport.ScreenViewport; import com.badlogic.gdx.utils.viewport.ScreenViewport;
import zero1hd.rhythmbullet.InitialScreen;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.desktop.screens.main.MainScreen; import zero1hd.rhythmbullet.desktop.screens.main.MainScreen;
import zero1hd.rhythmbullet.util.InitialScreen;
public class SplashScreen extends ScreenAdapter implements InitialScreen { public class SplashScreen extends ScreenAdapter implements InitialScreen {
private Stage stage; private Stage stage;

View File

@ -23,6 +23,7 @@ import zero1hd.rhythmbullet.desktop.audio.PCMObtainer;
import zero1hd.rhythmbullet.desktop.graphics.ui.components.MusicControls; import zero1hd.rhythmbullet.desktop.graphics.ui.components.MusicControls;
import zero1hd.rhythmbullet.graphics.ui.Page; import zero1hd.rhythmbullet.graphics.ui.Page;
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText; import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
import zero1hd.rhythmbullet.util.ScreenConfiguration;
public class MainPage extends Page implements Observer { public class MainPage extends Page implements Observer {
private MusicController mc; private MusicController mc;
@ -40,12 +41,12 @@ public class MainPage extends Page implements Observer {
private DoubleHorizontalVisualizer dhv; 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); super(0, 0);
this.mc = musicController; this.mc = musicController;
this.mc.addObserver(this); 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)); dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f));
title = new Image(assetManager.get("title.png", Texture.class)); title = new Image(assetManager.get("title.png", Texture.class));

View File

@ -117,7 +117,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
background = rhythmBullet.getAssetManager().get("backgrounds/mainBG.png", Texture.class); 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); stage.addActor(mainPage);
//End main menu //End main menu
@ -151,7 +151,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
} }
}); });
stage.addListener(new ClickListener() { stage.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {

View File

@ -30,8 +30,8 @@ import zero1hd.rhythmbullet.audio.MusicMetadataController;
import zero1hd.rhythmbullet.audio.MusicController; import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.graphics.ui.Page; import zero1hd.rhythmbullet.graphics.ui.Page;
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable; import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable;
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectableButtonGroup;
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText; import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
import zero1hd.rhythmbullet.util.MusicSelectableButtonGroup;
public class MusicSelectionPage extends Page implements Observer { public class MusicSelectionPage extends Page implements Observer {
Preferences musicFileAnnotation; Preferences musicFileAnnotation;