Refactored names for TileRenderer methods, removed deprecated methods

This commit is contained in:
Collin Smith 2021-07-20 23:24:54 -07:00
parent 8f13d9bac0
commit 16670d6e89
2 changed files with 10 additions and 61 deletions

View File

@ -43,7 +43,7 @@ public class DT1Reader {
if (DT1.loadData) {
for (int i = 0, s = dt1.numTiles; i < s; i++) {
Tile tile = dt1.tiles[i];
tile.pixmap = tileRenderer.render2(tile);
tile.pixmap = tileRenderer.createPixmap(tile);
}
}
return dt1;

View File

@ -5,8 +5,6 @@ import com.badlogic.gdx.graphics.Pixmap;
import com.riiablo.codec.Palette;
import com.riiablo.codec.util.BBox;
import com.riiablo.graphics.PaletteIndexedPixmap;
import com.riiablo.logger.LogManager;
import com.riiablo.logger.Logger;
import com.riiablo.map2.DT1.Tile;
import com.riiablo.map2.DT1.Tile.Block;
@ -14,52 +12,21 @@ import static com.riiablo.map2.DT1.Tile.Block.ISOMETRIC_SIZE;
import static com.riiablo.map2.DT1.Tile.Block.ISO_FORMAT;
import static com.riiablo.map2.DT1.Tile.Block.ISO_RLE_FORMAT;
import static com.riiablo.map2.DT1.Tile.Block.RLE_FORMAT;
import static com.riiablo.map2.Orientation.FLOOR;
import static com.riiablo.map2.Orientation.ROOF;
public class TileRenderer {
private static final Logger log = LogManager.getLogger(TileRenderer.class);
Pixmap render(Tile tile) {
int width = tile.width;
int height = -tile.height; // invert y-axis
int orientation = tile.orientation;
if (orientation == FLOOR || orientation == ROOF) {
if (height != 0) {
height = Tile.HEIGHT; // encoded as 128px, set to Tile.HEIGHT
}
} else if (orientation < ROOF) {
if (height != 0) {
height -= Block.SIZE; // trim topmost blocks (always empty)
}
} else {
}
Pixmap pixmap = new PaletteIndexedPixmap(width, height);
Block[] blocks = tile.blocks;
for (int i = 0, s = tile.numBlocks; i < s; i++) {
drawBlock(pixmap, blocks[i], tile.box, height);
}
return pixmap;
}
Pixmap render2(Tile tile) {
Pixmap createPixmap(Tile tile) {
BBox box = tile.box;
Pixmap pixmap = new PaletteIndexedPixmap(box.width, box.height);
Block[] blocks = tile.blocks;
for (int i = 0, s = tile.numBlocks; i < s; i++) {
drawBlock2(pixmap, blocks[i], box);
drawBlock(pixmap, blocks[i], box);
}
return pixmap;
}
void drawBlock2(Pixmap pixmap, Block block, BBox box) {
void drawBlock(Pixmap pixmap, Block block, BBox box) {
switch (block.format) {
case ISO_FORMAT:
// iso x,y relative to top-left w/ y-down and tile height offset pre-applied
@ -81,24 +48,6 @@ public class TileRenderer {
}
}
void drawBlock(Pixmap pixmap, Block block, BBox box, int yOffset) {
switch (block.format) {
case ISO_FORMAT:
// yOffset not needed because x,y are conveniently correct for OpenGL texture coords
drawIsometric(pixmap, block, block.x, block.y);
break;
case ISO_RLE_FORMAT:
// yOffset not needed because x,y are conveniently correct for OpenGL texture coords
drawRLE(pixmap, block, block.x, block.y);
break;
case RLE_FORMAT:
default:
// rle x,y are relative to top-left
drawRLE(pixmap, block, block.x, block.y + yOffset);
break;
}
}
void drawIsometric(Pixmap pixmap, Block block, int x0, int y0) {
final int format = block.format;
if (format != ISO_FORMAT) {
@ -114,12 +63,12 @@ public class TileRenderer {
final int[] ISO_X_LEN = Block.ISO_X_LEN;
final int[] ISO_X_OFF = Block.ISO_X_OFF;
/**
* x0 = pixmap x-offset (constant)
* y0 = pixmap y-offset (incremented per run)
* x = pixmap x-offset + block x-offset (assigned per run)
* y = pixmap y-offset (incremented per run)
*/
/*
x0 = pixmap x-offset (constant)
y0 = pixmap y-offset (incremented per run)
x = pixmap x-offset + block x-offset (assigned per run)
y = pixmap y-offset (incremented per run)
*/
int x, y = 0, run, d = 0;
final byte[] data = block.data;
for (int i = 0, s = ISOMETRIC_SIZE; i < s; i += run, y++, y0++) {