From 1af7457b00a8e5fb0d5652d772530ec4ee46e18e Mon Sep 17 00:00:00 2001 From: Recrown Date: Sat, 15 Jul 2017 14:56:25 -0500 Subject: [PATCH] change way of entity spawning --- .../polyjet/audio/map/EntitySpawnInfo.java | 8 +++- .../polyjet/audio/map/GamePlayMap.java | 37 ++++++++++++------- .../polyjet/audio/map/RhythmMapAlgorithm.java | 9 ++--- .../polyjet/entity/EntityController.java | 21 +++++------ .../polyjet/ui/stages/GamePlayArea.java | 9 +++-- core/src/zero1hd/wavedecoder/WavDecoder.java | 1 - 6 files changed, 47 insertions(+), 38 deletions(-) diff --git a/core/src/zero1hd/polyjet/audio/map/EntitySpawnInfo.java b/core/src/zero1hd/polyjet/audio/map/EntitySpawnInfo.java index ae89dd1..9f7709a 100755 --- a/core/src/zero1hd/polyjet/audio/map/EntitySpawnInfo.java +++ b/core/src/zero1hd/polyjet/audio/map/EntitySpawnInfo.java @@ -5,10 +5,12 @@ import zero1hd.polyjet.entity.Entities; public class EntitySpawnInfo { private Entities entityType; private float[] parameters; + private int spawnWindowID; - public EntitySpawnInfo(Entities entityType, float... parameters) { + public EntitySpawnInfo(Entities entityType, int spawnWindowID, float... parameters) { this.entityType = entityType; this.parameters = parameters; + this.spawnWindowID = spawnWindowID; } public Entities getEntityType() { @@ -23,4 +25,8 @@ public class EntitySpawnInfo { public float[] getParameters() { return parameters; } + + public int getSpawnWindowID() { + return spawnWindowID; + } } diff --git a/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java b/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java index aec4118..8c306e6 100755 --- a/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java +++ b/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java @@ -1,6 +1,5 @@ package zero1hd.polyjet.audio.map; -import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.utils.Array; import zero1hd.polyjet.audio.AudioData; @@ -11,6 +10,7 @@ public class GamePlayMap { private float playTime; private Array spawnList; private boolean building; + private int constIndex; private int index; /** * GamePlayMap is what the game area will use to generate entities and judge current audio data @@ -25,8 +25,8 @@ public class GamePlayMap { * returns audio data * @return */ - public Music getPlayableClip() { - return playableClip.getPlaybackMusic(); + public AudioData getMusicData() { + return playableClip; } /** @@ -42,6 +42,8 @@ public class GamePlayMap { */ public void beginBuild() { building = true; + index = 0; + constIndex = 0; } /** @@ -49,6 +51,8 @@ public class GamePlayMap { */ public void endBuild() { building = false; + index = 0; + constIndex = 0; } @@ -60,17 +64,13 @@ public class GamePlayMap { */ public void addToMap(Entities entityType, float... parameters) { if (building && entityType != null && parameters != null) { - spawnList.add(new EntitySpawnInfo(entityType, parameters)); + spawnList.add(new EntitySpawnInfo(entityType, index, parameters)); } } - /** - * use this to add rest for current index position - */ - public void addNullToMap() { - if (building) { - spawnList.add(null); - } + public void nextWindow() { + constIndex++; + index++; } /** @@ -78,9 +78,10 @@ public class GamePlayMap { * retrieve next entity in list. * @return */ - public EntitySpawnInfo nextEntity(boolean indexUpdate) { + public EntitySpawnInfo nextEntityBatch(boolean indexUpdate) { if (!building) { if (indexUpdate) { + constIndex++; index++; } EntitySpawnInfo spawnInfo = spawnList.get(index); @@ -90,11 +91,11 @@ public class GamePlayMap { } } - public EntitySpawnInfo safeNextEntity() { + public EntitySpawnInfo safeNextEntityBatch() { playableClip.readIndexUpdate(); if (index != playableClip.getReadIndex()) { index = playableClip.getReadIndex(); - return nextEntity(false); + return nextEntityBatch(false); } else { return null; } @@ -107,4 +108,12 @@ public class GamePlayMap { public void setIndex(int index) { this.index = index; } + + public void restoreIndex() { + this.index = constIndex; + } + + public int getIndex() { + return index; + } } diff --git a/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java index 37f02e2..f17beef 100755 --- a/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java +++ b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java @@ -56,10 +56,9 @@ public class RhythmMapAlgorithm implements Runnable { map.beginBuild(); for (int index = 0; index < bassPeaks.size; index++) { if (bassPeaks.get(index) != 0 || UMPeaks.get(index) != 0) { - int warningTime = (int) ((3/speedMod)*windowPerSecond); - if ((index+warningTime < bassPeaks.size) && bassPeaks.get(index + warningTime) != 0) { + if (bassPeaks.get(index) > avgBass) { //TODO basic void circle spawning - float endRadius = (bassPeaks.get(index + warningTime)/bassMax)*(Polyjet.GAME_AREA_HEIGHT/2f); + float endRadius = (bassPeaks.get(index)/bassMax)*(Polyjet.GAME_AREA_HEIGHT/2f); map.addToMap(Entities.VOID_CIRCLE, endRadius, @@ -84,12 +83,10 @@ public class RhythmMapAlgorithm implements Runnable { } } - } else { - map.addNullToMap(); } progress = MathUtils.round(100f*index/bassPeaks.size); - + map.nextWindow(); sender.send(MiniEvents.MAPGEN_ITERATED); } map.endBuild(); diff --git a/core/src/zero1hd/polyjet/entity/EntityController.java b/core/src/zero1hd/polyjet/entity/EntityController.java index a1babbb..7378421 100755 --- a/core/src/zero1hd/polyjet/entity/EntityController.java +++ b/core/src/zero1hd/polyjet/entity/EntityController.java @@ -111,41 +111,41 @@ public class EntityController { } } - public Entity spawnEntity(Stage stage, EntitySpawnInfo entitySpawnInfo) { + public EntitySpawnInfo spawnEntity(Stage stage, EntitySpawnInfo entitySpawnInfo) { if (entitySpawnInfo != null) { float[] param = entitySpawnInfo.getParameters(); - Gdx.app.debug("Spawning Entity", entitySpawnInfo.toString() + " parameters: " + Arrays.toString(param)); + Gdx.app.debug("Spawning Entity", entitySpawnInfo.toString() + " parameters: " + Arrays.toString(param) + "Attributed spawn window: " + entitySpawnInfo.getSpawnWindowID()); switch (entitySpawnInfo.getEntityType()) { case VOID_CIRCLE: VoidCircle voidCircle = voidCirclePool.obtain(); voidCircle.init(param[0], param[1], param[2], param[3], param[4]); activeEnemies.add(voidCircle); stage.addActor(voidCircle); - return voidCircle; + break; case LASER: Laser laser = laserPool.obtain(); laser.init(param[0], param[1], param[2]); activeAllies.add(laser); stage.addActor(laser); - return laser; + break; case PELLET: Pellet pellet = pelletPool.obtain(); pellet.init(param[0], param[1], param[2], param[3]); activeEnemies.add(pellet); stage.addActor(pellet); - return pellet; + break; case SHARD: Shard shard = shardPool.obtain(); shard.init(param[0], param[1], param[2], param[3], (int) param[4]); activeEnemies.add(shard); stage.addActor(shard); - return shard; + break; case BAR: Bar bar = barPool.obtain(); bar.init(param[0], param[1]); activeEnemies.add(bar); stage.addActor(bar); - return bar; + break; case FLAKE: Flake flake = flakePool.obtain(); Shard[] shards = new Shard[(int) param[0]]; @@ -157,13 +157,10 @@ public class EntityController { flake.init(param[1], param[2], param[3], param[4], param[5], shards); activeEnemies.add(flake); stage.addActor(flake); - return flake; - default: - return null; + break; } - } else { - return null; } + return entitySpawnInfo; } public void free(Entity entity) { diff --git a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java index 7463ee9..cd446f3 100755 --- a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java +++ b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java @@ -106,8 +106,6 @@ 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(); } @@ -115,8 +113,11 @@ public class GamePlayArea extends Stage { @Override public void act(float delta) { if (audioMap != null) { - time = audioMap.getPlayableClip().getPosition(); - ec.spawnEntity(this, audioMap.safeNextEntity()); + audioMap.getMusicData().readIndexUpdate(); + time = audioMap.getMusicData().getPlaybackMusic().getPosition(); + while (ec.spawnEntity(this, audioMap.nextEntityBatch(false)).getSpawnWindowID() == audioMap.getMusicData().getReadIndex()) { + audioMap.nextWindow(); + }; } collisionDetector.collisionCheck(); ec.deathClean(); diff --git a/core/src/zero1hd/wavedecoder/WavDecoder.java b/core/src/zero1hd/wavedecoder/WavDecoder.java index 60c8f07..bff1545 100755 --- a/core/src/zero1hd/wavedecoder/WavDecoder.java +++ b/core/src/zero1hd/wavedecoder/WavDecoder.java @@ -4,7 +4,6 @@ import java.io.DataInputStream; import java.io.IOException; import java.security.InvalidParameterException; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; public class WavDecoder {