Merge branch 'NewMapStructure' into AnalysisMapGenWork

This commit is contained in:
Harrison Deng 2017-07-16 00:16:53 -05:00
commit 052dcd2789
4 changed files with 83 additions and 73 deletions

View File

@ -1,35 +1,24 @@
package zero1hd.polyjet.audio.map;
<<<<<<< HEAD
<<<<<<< HEAD
=======
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.math.MathUtils;
>>>>>>> parent of e4359f4... tuning and adjustments
=======
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.math.MathUtils;
>>>>>>> parent of e4359f4... tuning and adjustments
import com.badlogic.gdx.utils.Array;
import zero1hd.polyjet.audio.AudioData;
import zero1hd.polyjet.entity.Entities;
public class GamePlayMap {
private AudioData playableClip;
private AudioData musicData;
private float playTime;
private Array<EntitySpawnInfo> spawnList;
private Array<MapWindowData> spawnList;
private boolean building;
private int constIndex;
private int index;
private int absoluteIndex;
/**
* GamePlayMap is what the game area will use to generate entities and judge current audio data
* @param audioData audio data
*/
public GamePlayMap(AudioData audioData) {
this.playableClip = audioData;
this.musicData = audioData;
spawnList = new Array<>();
}
@ -37,8 +26,8 @@ public class GamePlayMap {
* returns audio data
* @return
*/
public AudioData getMusicData() {
return playableClip;
public Music getPlayableClip() {
return musicData.getPlaybackMusic();
}
/**
@ -54,8 +43,10 @@ public class GamePlayMap {
*/
public void beginBuild() {
building = true;
spawnList.clear();
spawnList.add(new MapWindowData());
index = 0;
constIndex = 0;
absoluteIndex = 0;
}
/**
@ -64,7 +55,7 @@ public class GamePlayMap {
public void endBuild() {
building = false;
index = 0;
constIndex = 0;
absoluteIndex = 0;
}
@ -74,53 +65,49 @@ public class GamePlayMap {
* @param entityType what type of entity to spawn
* @param parameters the arguments for the entity. It is important to have the same amount of parameters the entity requires to spawn
*/
public void addToMap(Entities entityType, float... parameters) {
if (building && entityType != null && parameters != null) {
spawnList.add(new EntitySpawnInfo(entityType, index, parameters));
spawnList.get(index).addEntity(new EntitySpawnInfo(entityType, parameters));
}
}
public void nextWindow() {
constIndex++;
index++;
}
/**
* Only works when not started.
* retrieve next entity in list.
* @return
* Moves onto the next window of the map for the song
*/
public EntitySpawnInfo nextEntityBatch(boolean indexUpdate) {
if (!building) {
if (indexUpdate) {
constIndex++;
index++;
}
EntitySpawnInfo spawnInfo = spawnList.get(index);
return spawnInfo;
} else {
return null;
public void nextWindow() {
absoluteIndex++;
resetIndex();
if (building) {
spawnList.add(new MapWindowData());
}
}
public EntitySpawnInfo safeNextEntityBatch() {
playableClip.readIndexUpdate();
if (index != playableClip.getReadIndex()) {
index = playableClip.getReadIndex();
<<<<<<< HEAD
<<<<<<< HEAD
return nextEntityBatch(false);
=======
=======
>>>>>>> parent of e4359f4... tuning and adjustments
Gdx.app.debug("GPM", "index: " + index);
return nextEntity(false);
>>>>>>> parent of e4359f4... tuning and adjustments
} else {
return null;
/**
* moves to the previous window to make edits to that frame.
*/
public void previousWindow() {
absoluteIndex--;
resetIndex();
}
/**
* use this to add rest for current index position
*/
public void addNullToMap() {
if (building) {
spawnList.set(index, null);
}
}
public MapWindowData nextWindowData() {
if (index != musicData.getReadIndex()) {
absoluteIndex = musicData.getReadIndex();
resetIndex();
return spawnList.get(index);
}
return null;
}
/**
* set retrieve entity index position.
* @param index
@ -129,11 +116,11 @@ public class GamePlayMap {
this.index = index;
}
public void restoreIndex() {
this.index = constIndex;
public boolean isCurrentNull() {
return spawnList.get(index) == null ? true : false;
}
public int getIndex() {
return index;
public void resetIndex() {
index = absoluteIndex;
}
}

View File

@ -0,0 +1,19 @@
package zero1hd.polyjet.audio.map;
import com.badlogic.gdx.utils.Array;
public class MapWindowData {
Array<EntitySpawnInfo> entityDatas;
public MapWindowData() {
entityDatas = new Array<>(EntitySpawnInfo.class);
}
public void addEntity(EntitySpawnInfo entity) {
entityDatas.add(entity);
}
public EntitySpawnInfo[] getArray() {
return entityDatas.toArray();
}
}

View File

@ -56,20 +56,16 @@ public class RhythmMapAlgorithm implements Runnable {
map.beginBuild();
for (int index = 0; index < bassPeaks.size; index++) {
if (bassPeaks.get(index) != 0 || UMPeaks.get(index) != 0) {
<<<<<<< HEAD
if (bassPeaks.get(index) > avgBass) {
=======
int warningTime = (int) ((3/speedMod)*windowPerSecond);
if ((index+warningTime < bassPeaks.size) && bassPeaks.get(index + warningTime) >= avgBass) {
>>>>>>> parent of e4359f4... tuning and adjustments
if ((index+warningTime < bassPeaks.size) && bassPeaks.get(index + warningTime) != 0) {
//TODO basic void circle spawning
float endRadius = (bassPeaks.get(index)/bassMax)*(Polyjet.GAME_AREA_HEIGHT/2f);
float endRadius = (bassPeaks.get(index + warningTime)/bassMax)*(Polyjet.GAME_AREA_HEIGHT/2f);
map.addToMap(Entities.VOID_CIRCLE,
endRadius,
rand.nextFloat()*Polyjet.GAME_AREA_WIDTH,
rand.nextFloat()*Polyjet.GAME_AREA_HEIGHT,
endRadius/(avgSPB*0.5f),
endRadius/(avgSPB*0.6f),
3f/speedMod
);
}
@ -87,11 +83,13 @@ public class RhythmMapAlgorithm implements Runnable {
(Polyjet.GAME_AREA_HEIGHT/4f)/avgSPB);
}
}
} else {
map.addNullToMap();
}
progress = MathUtils.round(100f*index/bassPeaks.size);
map.nextWindow();
progress = MathUtils.round(100f*index/bassPeaks.size);
sender.send(MiniEvents.MAPGEN_ITERATED);
}
map.endBuild();

View File

@ -9,7 +9,9 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.FitViewport;
import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.audio.map.EntitySpawnInfo;
import zero1hd.polyjet.audio.map.GamePlayMap;
import zero1hd.polyjet.audio.map.MapWindowData;
import zero1hd.polyjet.controls.KeyMap;
import zero1hd.polyjet.entity.CollisionDetector;
import zero1hd.polyjet.entity.Entities;
@ -106,18 +108,22 @@ public class GamePlayArea extends Stage {
getBatch().draw(background, 0f, 0f, Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT);
getBatch().end();
getBatch().setShader(null);
super.draw();
}
@Override
public void act(float delta) {
if (audioMap != null) {
audioMap.getMusicData().readIndexUpdate();
time = audioMap.getMusicData().getPlaybackMusic().getPosition();
while (ec.spawnEntity(this, audioMap.nextEntityBatch(false)).getSpawnWindowID() == audioMap.getMusicData().getReadIndex()) {
audioMap.nextWindow();
};
MapWindowData mwd;
if (audioMap != null && audioMap.getPlayableClip().isPlaying() && (mwd = audioMap.nextWindowData()) != null) {
EntitySpawnInfo[] currentSpawnInfo = mwd.getArray();
if (currentSpawnInfo != null) {
for (int i = 0; i < currentSpawnInfo.length; i++) {
ec.spawnEntity(this, currentSpawnInfo[i]);
}
}
}
collisionDetector.collisionCheck();
ec.deathClean();