optimizations done to graphing

This commit is contained in:
Harrison Deng 2017-09-03 17:23:28 -05:00
parent b18cbe2352
commit db902e59e1
5 changed files with 91 additions and 166 deletions

View File

@ -18,11 +18,10 @@ import zero1hd.rhythmbullet.audio.AudioAnalyzer;
import zero1hd.rhythmbullet.audio.AudioDataPackage;
import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm;
import zero1hd.rhythmbullet.screens.MainMenu;
import zero1hd.rhythmbullet.ui.windows.BassUMGraphWindow;
import zero1hd.rhythmbullet.ui.builders.AudioGraph;
import zero1hd.rhythmbullet.ui.windows.BeatViewer;
import zero1hd.rhythmbullet.ui.windows.DifficultyWindow;
import zero1hd.rhythmbullet.ui.windows.FPSWindow;
import zero1hd.rhythmbullet.ui.windows.MGraphWindow;
import zero1hd.rhythmbullet.ui.windows.MusicController;
import zero1hd.rhythmbullet.ui.windows.MusicSelector;
import zero1hd.rhythmbullet.ui.windows.SpawnerWindow;
@ -35,8 +34,8 @@ public class CreativeHUD extends Stage implements MiniListener {
MusicSelector musicSelector;
FPSWindow fpsViewer;
BeatViewer beatViewer;
BassUMGraphWindow bassUMgraphWindow;
MGraphWindow mGraphWindow;
AudioGraph bassUMgraphWindow;
AudioGraph mGraphWindow;
VolumeWindow volumeWindow;
SpawnerWindow spawnerWindow;
DifficultyWindow diffWindow;
@ -57,8 +56,10 @@ public class CreativeHUD extends Stage implements MiniListener {
fpsViewer = new FPSWindow("FPS", core.getDefaultSkin());
beatViewer = new BeatViewer("Beat", core.getDefaultSkin());
bassUMgraphWindow = new BassUMGraphWindow("Bass/UM Peak Values", core.getDefaultSkin());
mGraphWindow = new MGraphWindow("Midrange Peak Values", core.getDefaultSkin());
bassUMgraphWindow = new AudioGraph(512, 256);
bassUMgraphWindow.setPosition(getWidth() - bassUMgraphWindow.getWidth(), 0);
mGraphWindow = new AudioGraph(512, 256);
mGraphWindow.setPosition(getWidth() - mGraphWindow.getWidth(), bassUMgraphWindow.getHeight());
volumeWindow = new VolumeWindow("Volume adjustments", core.getDefaultSkin(), core.getPrefs());
spawnerWindow = new SpawnerWindow("Spawn Tool", core.getDefaultSkin(), gpa.em, gpa.cm, gpa);
diffWindow = new DifficultyWindow(core.getDefaultSkin());
@ -240,8 +241,8 @@ public class CreativeHUD extends Stage implements MiniListener {
case MUSIC_SELECTED:
beatViewer.setMusic(null, null);
volumeWindow.setMusic(null);
bassUMgraphWindow.setData(null, null, null);
mGraphWindow.setData(null, null, null);
bassUMgraphWindow.setGraphingData(null, null, null);
mGraphWindow.setGraphingData(null, null, null);
if (musicPlayBackControls.getAudiofile() != null) {
musicPlayBackControls.getAudiofile().dispose();
}
@ -267,15 +268,15 @@ public class CreativeHUD extends Stage implements MiniListener {
volumeWindow.setMusic(adp.getMusicInfo());
beatViewer.setMusic(adp.getMusicInfo(), analyzer.getAudioDataPackage());
bassUMgraphWindow.setData(analyzer.getAudioDataPackage().getBassPeaks(), analyzer.getAudioDataPackage().getuMPeaks(), adp.getMusicInfo());
bassUMgraphWindow.getGraph().avgG1 = adp.getBassAvg();
bassUMgraphWindow.getGraph().normalDataG1 = adp.getBassMaxVal();
bassUMgraphWindow.getGraph().avgG2 = adp.getuMAvg();
bassUMgraphWindow.getGraph().normalDataG2 = adp.getuMMaxval();
bassUMgraphWindow.setGraphingData(analyzer.getAudioDataPackage().getBassPeaks(), analyzer.getAudioDataPackage().getuMPeaks(), adp.getMusicInfo());
bassUMgraphWindow.avgG1 = adp.getBassAvg();
bassUMgraphWindow.normalDataG1 = adp.getBassMaxVal();
bassUMgraphWindow.avgG2 = adp.getuMAvg();
bassUMgraphWindow.normalDataG2 = adp.getuMMaxval();
mGraphWindow.setData(analyzer.getAudioDataPackage().getmPeaks(), null, adp.getMusicInfo());
mGraphWindow.getGraph().normalDataG1 = adp.getmMaxVal();
mGraphWindow.getGraph().avgG1 = adp.getmAvg();
mGraphWindow.setGraphingData(analyzer.getAudioDataPackage().getmPeaks(), null, adp.getMusicInfo());
mGraphWindow.normalDataG1 = adp.getmMaxVal();
mGraphWindow.avgG1 = adp.getmAvg();
gpa.setAudioMap(mapGen.getMap());
ghud.setMusic(adp.getMusicInfo().getPlaybackMusic());
break;

View File

@ -2,34 +2,28 @@ package zero1hd.rhythmbullet.ui.builders;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.FloatArray;
import zero1hd.rhythmbullet.audio.CoreMusicInfo;
public class AudioGraph extends Actor {
Pixmap audioGraph;
Texture textureOfGraph;
private CoreMusicInfo audioData;
ShapeRenderer shapeRender;
FloatArray mainGraph;
FloatArray overlayGraph;
int dataIndex;
int displayMode;
public float normalDataG1 = 1f, normalDataG2 = 1f, avgG1 = 1f, avgG2 = 1f;
float scale;
public AudioGraph(int graphSizeW, int graphSizeH) {
audioGraph = new Pixmap(graphSizeW, graphSizeH, Format.RGBA8888);
audioGraph.setColor(0.1f, 0.1f, 0.1f, 0.75f);
audioGraph.fill();
textureOfGraph = new Texture(audioGraph);
setWidth(graphSizeW);
setHeight(graphSizeH);
scale = audioGraph.getHeight();
shapeRender = new ShapeRenderer();
setSize(graphSizeW, graphSizeH);
scale = graphSizeH;
}
public void setAudioDataIndex(int audioDataIndex) {
@ -37,88 +31,110 @@ public class AudioGraph extends Actor {
}
@Override
public void act(float delta) {
audioGraph.setColor(0f, 0f, 0f, 0.75f);
audioGraph.fill();
public void draw(Batch batch, float parentAlpha) {
batch.end();
shapeRender.begin(ShapeType.Line);
shapeRender.setColor(0f, 0f, 0f, 0.35f);
shapeRender.rect(getX(), getY(), getWidth(), getHeight());
if (overlayGraph != null) {
if (Gdx.input.isKeyPressed(Keys.COMMA)) {
if (scale > 0.05f) {
scale -= 0.25f;
}
} else if (Gdx.input.isKeyPressed(Keys.PERIOD)) {
if (scale < audioGraph.getHeight()*2f) {
if (scale < getHeight()*2) {
scale += 0.4f;
}
}
if (Gdx.input.isKeyJustPressed(Keys.M)) {
Gdx.app.debug("Graph", "Switching to another graph.");
displayMode++;
if (displayMode != 3) {
Gdx.app.debug("Graph", "Switching to another graph.");
} else {
if (displayMode == 3) {
displayMode = 0;
}
}
}
if (Gdx.input.isKeyPressed(Keys.COMMA)) {
if (scale > 0.05f) {
scale -= 0.25f;
}
} else if (Gdx.input.isKeyPressed(Keys.PERIOD)) {
if (scale < audioGraph.getHeight()*2f) {
scale += 0.4f;
}
} else if (Gdx.input.isKeyJustPressed(Keys.SLASH)) {
scale = audioGraph.getHeight();
}
switch (displayMode) {
case 0:
audioGraph.setColor(1f, 0f, 0f, 0.75f);
for (int x = 0; x < audioGraph.getWidth(); x++) {
shapeRender.setColor(1f, 0f, 0f, 1f);
for (int x = 0; x < getWidth(); x++) {
try {
audioGraph.drawLine(x, audioGraph.getHeight(), x, (int) (audioGraph.getHeight()-(mainGraph.get(dataIndex+x-audioGraph.getWidth()/2)/normalDataG1)*scale));
shapeRender.line(
getX()+x,
getY(),
getX()+x,
(int) ((mainGraph.get((int) (dataIndex+x-getWidth()/2))/normalDataG1)*scale)+getY());
} catch (NullPointerException | IndexOutOfBoundsException e) {
}
audioGraph.drawLine(0, audioGraph.getHeight() - MathUtils.round(scale*(avgG1/normalDataG1)), audioGraph.getWidth(), audioGraph.getHeight() - MathUtils.round(scale*(avgG1/normalDataG1)));
shapeRender.line(
getX(),
MathUtils.round(scale*(avgG1/normalDataG1))+getY(),
getWidth() + getX(),
MathUtils.round(scale*(avgG1/normalDataG1))+getY());
}
case 1:
audioGraph.setColor(0f, 0f, 1f, 0.75f);
for (int x = 0; x < audioGraph.getWidth() -1; x++) {
shapeRender.setColor(0f, 0f, 1f, 0.75f);
for (int x = 0; x < getHeight() -1; x++) {
try {
audioGraph.drawLine(x, audioGraph.getHeight(), x, (int) (audioGraph.getHeight()-(overlayGraph.get(dataIndex+x-audioGraph.getWidth()/2)/normalDataG2)*scale));
shapeRender.line(
getX()+x,
getY(),
getX()+x,
(int) ((overlayGraph.get((int) (dataIndex+x-getWidth()/2))/normalDataG2)*scale)+getY());
} catch (NullPointerException | IndexOutOfBoundsException e) {
}
audioGraph.drawLine(0, audioGraph.getHeight() - MathUtils.round(scale*(avgG2/normalDataG2)), audioGraph.getWidth(), audioGraph.getHeight() - MathUtils.round(scale*(avgG2/normalDataG2)));
shapeRender.line(
getX(),
MathUtils.round(scale*(avgG2/normalDataG2)) + getY(),
getWidth() + getX(),
MathUtils.round(scale*(avgG2/normalDataG2))+getY());
}
break;
case 2:
audioGraph.setColor(1f, 0f, 0f, 0.75f);
for (int x = 0; x < audioGraph.getWidth(); x++) {
shapeRender.setColor(1f, 0f, 0f, 0.75f);
for (int x = 0; x < getWidth(); x++) {
try {
audioGraph.drawLine(x, audioGraph.getHeight(), x, (int) (audioGraph.getHeight()-(mainGraph.get(dataIndex+x-audioGraph.getWidth()/2)/normalDataG1)*scale));
shapeRender.line(
getX()+x,
getY(),
getX()+x,
(int) ((mainGraph.get((int) (dataIndex+x-getWidth()/2))/normalDataG1)*scale)+getY());
} catch (NullPointerException | IndexOutOfBoundsException e) {
}
shapeRender.line(
getX(),
MathUtils.round(scale*(avgG1/normalDataG1))+getY(),
getWidth() + getX(),
MathUtils.round(scale*(avgG1/normalDataG1))+getY());
}
audioGraph.drawLine(0, audioGraph.getHeight() - MathUtils.round(scale*(avgG1/normalDataG1)), audioGraph.getWidth(), audioGraph.getHeight() - MathUtils.round(scale*(avgG1/normalDataG1)));
break;
}
audioGraph.setColor(0f, 1f, 0f, 0.95f);
audioGraph.drawLine(audioGraph.getWidth()/2, 0, audioGraph.getWidth()/2, audioGraph.getHeight());
shapeRender.setColor(0f, 1f, 0f, 1f);
shapeRender.line(getX()+getWidth()/2, 0, getX()+getWidth()/2, getHeight()+getY());
shapeRender.end();
textureOfGraph.draw(audioGraph, 0, 0);
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(textureOfGraph, getX(), getY(), getWidth(), getHeight());
batch.begin();
super.draw(batch, parentAlpha);
}
public void setGraphingData(FloatArray dataSet1, FloatArray dataSet2) {
@Override
public void act(float delta) {
if (audioData != null) {
setAudioDataIndex(audioData.getReadIndex());
}
super.act(delta);
}
/**
* Set what arrays to graph
* @param dataSet1 first audio data set
* @param dataSet2 overlay graph. This one can be null.
* @param audioData actual basic audio information for index position
*/
public void setGraphingData(FloatArray dataSet1, FloatArray dataSet2, CoreMusicInfo audioData) {
this.mainGraph = dataSet1;
this.overlayGraph = dataSet2;
if (dataSet2 == null) {
@ -126,6 +142,7 @@ public class AudioGraph extends Actor {
} else {
displayMode = 0;
}
this.audioData = audioData;
}
}

View File

@ -14,7 +14,7 @@ import com.badlogic.gdx.utils.Align;
public class GraphicsTable extends Table {
private Label resolutions, shaders;
private CheckBox glowShader, bgShader, invertShader, fancySpriteShader;
private CheckBox glowShader;
private SetResolutionButton
_3840x2160,
@ -35,26 +35,11 @@ public class GraphicsTable extends Table {
add(shaders).fillX();
row();
invertShader = new CheckBox(" Invert Shader", skin, "expandable");
invertShader.setChecked(pref.getBoolean("invert shader", false));
add(invertShader).minHeight(shaders.getHeight());
row();
glowShader = new CheckBox(" Glow Shader", skin, "expandable");
glowShader.setChecked(pref.getBoolean("glow shader", true));
add(glowShader).minHeight(shaders.getHeight());
row();
bgShader = new CheckBox(" Background Shader", skin, "expandable");
bgShader.setChecked(pref.getBoolean("bg shader", true));
add(bgShader).minHeight(shaders.getHeight());
row();
fancySpriteShader = new CheckBox(" Fancy Sprites", skin, "expandable");
fancySpriteShader.setChecked(pref.getBoolean("fancy", true));
add(fancySpriteShader).minHeight(shaders.getHeight());
row();
resolutions = new Label("Resolutions: ", skin);
add(resolutions).left();
row();
@ -111,9 +96,6 @@ public class GraphicsTable extends Table {
public void save(Preferences prefs) {
Gdx.app.debug("Preferences", "Saved shading values values.");
prefs.putBoolean("bg shader", bgShader.isChecked());
prefs.putBoolean("glow shader", glowShader.isChecked());
prefs.putBoolean("invert shader", invertShader.isChecked());
prefs.putBoolean("fancy", fancySpriteShader.isChecked());
}
}

View File

@ -1,38 +0,0 @@
package zero1hd.rhythmbullet.ui.windows;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.utils.FloatArray;
import zero1hd.rhythmbullet.audio.CoreMusicInfo;
import zero1hd.rhythmbullet.ui.builders.AudioGraph;
public class BassUMGraphWindow extends Window {
AudioGraph graph;
CoreMusicInfo audioData;
public BassUMGraphWindow(String title, Skin skin) {
super(title, skin, "tinted");
graph = new AudioGraph(300, 150);
add(graph);
pack();
}
@Override
public void act(float delta) {
if (audioData != null) {
graph.setAudioDataIndex(audioData.getReadIndex());
}
super.act(delta);
}
public AudioGraph getGraph() {
return graph;
}
public void setData(FloatArray dataSet1, FloatArray dataSet2, CoreMusicInfo audioData) {
this.audioData = audioData;
graph.setGraphingData(dataSet1, dataSet2);
}
}

View File

@ -1,37 +0,0 @@
package zero1hd.rhythmbullet.ui.windows;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.utils.FloatArray;
import zero1hd.rhythmbullet.audio.CoreMusicInfo;
import zero1hd.rhythmbullet.ui.builders.AudioGraph;
public class MGraphWindow extends Window {
private AudioGraph graph;
private CoreMusicInfo audioData;
public MGraphWindow(String title, Skin skin) {
super(title, skin, "tinted");
graph = new AudioGraph(300, 150);
add(graph);
pack();
}
@Override
public void act(float delta) {
if (audioData != null) {
graph.setAudioDataIndex(audioData.getReadIndex());
}
super.act(delta);
}
public AudioGraph getGraph() {
return graph;
}
public void setData(FloatArray dataSet1, FloatArray dataSet2, CoreMusicInfo audioData) {
this.audioData = audioData;
graph.setGraphingData(dataSet1, dataSet2);
}
}