v0.4.2: added the ability for tilemaps to selectively not render certain tiles

This commit is contained in:
Evan Debenham 2016-08-19 19:34:04 -04:00
parent 0e7c12b61e
commit ca068c92b2
2 changed files with 71 additions and 44 deletions

View File

@ -44,6 +44,8 @@ public class Tilemap extends Visual {
private float cellH;
protected float[] vertices;
protected short[] bufferPositions;
protected short bufferLength;
protected FloatBuffer quads;
public Rect updated;
@ -71,6 +73,9 @@ public class Tilemap extends Visual {
mapWidth = cols;
mapHeight = data.length / cols;
size = mapWidth * mapHeight;
bufferPositions = new short[size];
for (int i = 0; i < bufferPositions.length; i++)
bufferPositions[i] = -1;
width = cellW * mapWidth;
height = cellH * mapHeight;
@ -95,34 +100,44 @@ public class Tilemap extends Visual {
for (int j=updated.left; j < updated.right; j++) {
RectF uv = tileset.get( data[pos++] );
if (needsRender(pos)) {
int bufferPos = bufferPositions[pos];
if (bufferPos == -1){
bufferPos = bufferPositions[pos] = bufferLength;
bufferLength ++;
}
vertices[0] = x1;
vertices[1] = y1;
quads.position(bufferPos*16);
RectF uv = tileset.get( data[pos] );
vertices[2] = uv.left;
vertices[3] = uv.top;
vertices[0] = x1;
vertices[1] = y1;
vertices[4] = x2;
vertices[5] = y1;
vertices[2] = uv.left;
vertices[3] = uv.top;
vertices[6] = uv.right;
vertices[7] = uv.top;
vertices[4] = x2;
vertices[5] = y1;
vertices[8] = x2;
vertices[9] = y2;
vertices[6] = uv.right;
vertices[7] = uv.top;
vertices[10] = uv.right;
vertices[11] = uv.bottom;
vertices[8] = x2;
vertices[9] = y2;
vertices[12] = x1;
vertices[13] = y2;
vertices[10] = uv.right;
vertices[11] = uv.bottom;
vertices[14] = uv.left;
vertices[15] = uv.bottom;
vertices[12] = x1;
vertices[13] = y2;
quads.put( vertices );
vertices[14] = uv.left;
vertices[15] = uv.bottom;
quads.put( vertices );
}
pos++;
x1 = x2;
x2 += cellW;
@ -150,11 +165,17 @@ public class Tilemap extends Visual {
ra, ga, ba, aa );
if (!updated.isEmpty()) {
quads.limit(quads.capacity());
updateVertices();
quads.limit(bufferLength);
}
script.camera( camera );
script.drawQuadSet( quads, size );
script.drawQuadSet( quads, bufferLength );
}
protected boolean needsRender(int pos){
return true;
}
}

View File

@ -21,6 +21,7 @@
package com.shatteredpixel.shatteredpixeldungeon;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.watabou.noosa.Image;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.Tilemap;
@ -99,4 +100,9 @@ public class DungeonTilemap extends Tilemap {
public boolean overlapsScreenPoint( int x, int y ) {
return true;
}
@Override
protected boolean needsRender(int pos) {
return Level.discoverable[pos] && Dungeon.level.map[pos] != Terrain.WATER;
}
}