Added support for poppads

MapRenderer will now properly hide tiles whose mainIndexes intersect with current position poppads
Entity dirty components debug message will print string representation of flags instead of raw int
This commit is contained in:
Collin Smith 2019-02-15 15:55:45 -08:00
parent c765da42c9
commit 3348098ace
3 changed files with 67 additions and 2 deletions

View File

@ -238,7 +238,7 @@ public class Entity {
animation.setDirection(getDirection());
}
if (DEBUG_DIRTY) Gdx.app.debug(TAG, "dirty layers: " + dirty);
if (DEBUG_DIRTY) Gdx.app.debug(TAG, "dirty layers: " + Dirty.toString(dirty));
for (int l = 0; l < cof.getNumLayers(); l++) {
COF.Layer layer = cof.getLayer(l);
final int c = layer.component;

View File

@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Bits;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.IntSet;
@ -520,6 +521,28 @@ public class Map implements Disposable {
return zone;
}
/**
* @param x world sub-tile
* @param y world sub-tile
* @param tx world tile
* @param ty world tile
* @param stx sub-tile (0-4)
* @param sty sub-tile (0-4)
*/
// TODO: x,y alone should be enough, but others are available in MapRenderer on each position change anyways
public void updatePopPads(Bits bits, int x, int y, int tx, int ty, int stx, int sty) {
bits.clear();
Zone zone = getZone(x, y);
if (zone != null) {
Map.Preset preset = zone.getGrid(tx, ty);
if (preset != null) {
int presetX = zone.getGridX(tx) + stx;
int presetY = zone.getGridX(ty) + sty;
preset.updatePopPads(bits, presetX, presetY);
}
}
}
static class Zone {
static final Array<Entity> EMPTY_ARRAY = new Array<>(0);
@ -905,6 +928,15 @@ public class Map implements Disposable {
return ds1Path;
}
public void updatePopPads(Bits bits, int x, int y) {
if (popPads == null) return;
for (PopPad popPad : popPads.values()) {
if (popPad.contains(x, y)) {
bits.set(DT1.Tile.Index.subIndex(popPad.id));
}
}
}
static class PopPad {
int id;
int startX, startY;
@ -921,6 +953,11 @@ public class Map implements Disposable {
endY = y;
}
boolean contains(int x, int y) {
return startX <= x && x < endX
&& startY <= y && y < endY;
}
@Override
public String toString() {
return new ToStringBuilder(this)

View File

@ -10,6 +10,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Bits;
import java.util.Arrays;
@ -32,6 +33,7 @@ public class MapRenderer {
private static final boolean DEBUG_SPECIAL = DEBUG && true;
private static final boolean DEBUG_MOUSE = DEBUG && true;
private static final boolean DEBUG_PATHS = DEBUG && true;
private static final boolean DEBUG_POPPADS = DEBUG && true;
public static boolean RENDER_DEBUG_SUBTILE = DEBUG_SUBTILE;
public static boolean RENDER_DEBUG_TILE = DEBUG_TILE;
@ -80,6 +82,9 @@ public class MapRenderer {
// tpx and tpy of startX, startY tile in world-space
int startPx, startPy;
// DT1 mainIndexes to not draw
final Bits popped = new Bits();
public MapRenderer(PaletteIndexedBatch batch, OrthographicCamera camera) {
this.batch = batch;
this.camera = camera;
@ -189,12 +194,31 @@ public class MapRenderer {
if (DEBUG_MATH) {
Gdx.app.debug(TAG,
String.format("(%2d,%2d){%d,%d}[%2d,%2d](%dx%d)[%dx%d] %d,%d%n",
String.format("(%2d,%2d){%d,%d}[%2d,%2d](%dx%d)[%dx%d] %d,%d",
x, y, stx, sty, tx, ty, width, height, tilesX, tilesY, spx, spy));
}
map.updatePopPads(popped, x, y, tx, ty, stx, sty);
if (DEBUG_POPPADS) {
String popPads = getPopPads();
if (!popPads.isEmpty()) Gdx.app.debug(TAG, "PopPad IDs: " + popPads);
}
}
}
private String getPopPads() {
StringBuilder builder = new StringBuilder();
for (int i = popped.nextSetBit(0); i >= 0; i = popped.nextSetBit(i + 1)) {
builder.append(i).append(',');
}
if (builder.length() > 0) {
builder.setLength(builder.length() - 1);
}
return builder.toString();
}
// TODO: render will overscan image in y-axis to accommodate walls, should change to wall only instead of entire frame
public void render() {
for (int i = 0, x, y; i < Map.MAX_LAYERS; i++) {
@ -291,6 +315,10 @@ public class MapRenderer {
return;
}
if (popped.get(tile.tile.mainIndex)) {
return;
}
batch.draw(tile.tile.texture, px, tile.tile.orientation == Orientation.ROOF ? py + tile.tile.roofHeight : py);
if (tile.tile.orientation == Orientation.RIGHT_NORTH_CORNER_WALL) {
batch.draw(tile.sibling.texture, px, py);