From 3348098ace3fb43442195156786a379569840636 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Fri, 15 Feb 2019 15:55:45 -0800 Subject: [PATCH] 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 --- core/src/gdx/diablo/entity/Entity.java | 2 +- core/src/gdx/diablo/map/Map.java | 37 ++++++++++++++++++++++++ core/src/gdx/diablo/map/MapRenderer.java | 30 ++++++++++++++++++- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/core/src/gdx/diablo/entity/Entity.java b/core/src/gdx/diablo/entity/Entity.java index c58be6a2..f20dceb4 100644 --- a/core/src/gdx/diablo/entity/Entity.java +++ b/core/src/gdx/diablo/entity/Entity.java @@ -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; diff --git a/core/src/gdx/diablo/map/Map.java b/core/src/gdx/diablo/map/Map.java index 4d053a93..a91872bd 100644 --- a/core/src/gdx/diablo/map/Map.java +++ b/core/src/gdx/diablo/map/Map.java @@ -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 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) diff --git a/core/src/gdx/diablo/map/MapRenderer.java b/core/src/gdx/diablo/map/MapRenderer.java index dcaf378c..2c00d15a 100644 --- a/core/src/gdx/diablo/map/MapRenderer.java +++ b/core/src/gdx/diablo/map/MapRenderer.java @@ -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);