v0.4.2: added the ability for tilemaps to selectively not render certain tiles
This commit is contained in:
parent
0e7c12b61e
commit
ca068c92b2
|
@ -44,6 +44,8 @@ public class Tilemap extends Visual {
|
||||||
private float cellH;
|
private float cellH;
|
||||||
|
|
||||||
protected float[] vertices;
|
protected float[] vertices;
|
||||||
|
protected short[] bufferPositions;
|
||||||
|
protected short bufferLength;
|
||||||
protected FloatBuffer quads;
|
protected FloatBuffer quads;
|
||||||
|
|
||||||
public Rect updated;
|
public Rect updated;
|
||||||
|
@ -71,58 +73,71 @@ public class Tilemap extends Visual {
|
||||||
mapWidth = cols;
|
mapWidth = cols;
|
||||||
mapHeight = data.length / cols;
|
mapHeight = data.length / cols;
|
||||||
size = mapWidth * mapHeight;
|
size = mapWidth * mapHeight;
|
||||||
|
bufferPositions = new short[size];
|
||||||
|
for (int i = 0; i < bufferPositions.length; i++)
|
||||||
|
bufferPositions[i] = -1;
|
||||||
|
|
||||||
width = cellW * mapWidth;
|
width = cellW * mapWidth;
|
||||||
height = cellH * mapHeight;
|
height = cellH * mapHeight;
|
||||||
|
|
||||||
quads = Quad.createSet( size );
|
quads = Quad.createSet( size );
|
||||||
|
|
||||||
updated.set( 0, 0, mapWidth, mapHeight );
|
updated.set( 0, 0, mapWidth, mapHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateVertices() {
|
protected void updateVertices() {
|
||||||
|
|
||||||
float y1 = cellH * updated.top;
|
float y1 = cellH * updated.top;
|
||||||
float y2 = y1 + cellH;
|
float y2 = y1 + cellH;
|
||||||
|
|
||||||
for (int i=updated.top; i < updated.bottom; i++) {
|
for (int i=updated.top; i < updated.bottom; i++) {
|
||||||
|
|
||||||
float x1 = cellW * updated.left;
|
float x1 = cellW * updated.left;
|
||||||
float x2 = x1 + cellW;
|
float x2 = x1 + cellW;
|
||||||
|
|
||||||
int pos = i * mapWidth + updated.left;
|
int pos = i * mapWidth + updated.left;
|
||||||
quads.position( 16 * pos );
|
quads.position( 16 * pos );
|
||||||
|
|
||||||
for (int j=updated.left; j < updated.right; j++) {
|
for (int j=updated.left; j < updated.right; j++) {
|
||||||
|
|
||||||
RectF uv = tileset.get( data[pos++] );
|
if (needsRender(pos)) {
|
||||||
|
int bufferPos = bufferPositions[pos];
|
||||||
vertices[0] = x1;
|
if (bufferPos == -1){
|
||||||
vertices[1] = y1;
|
bufferPos = bufferPositions[pos] = bufferLength;
|
||||||
|
bufferLength ++;
|
||||||
vertices[2] = uv.left;
|
}
|
||||||
vertices[3] = uv.top;
|
|
||||||
|
quads.position(bufferPos*16);
|
||||||
vertices[4] = x2;
|
RectF uv = tileset.get( data[pos] );
|
||||||
vertices[5] = y1;
|
|
||||||
|
vertices[0] = x1;
|
||||||
vertices[6] = uv.right;
|
vertices[1] = y1;
|
||||||
vertices[7] = uv.top;
|
|
||||||
|
vertices[2] = uv.left;
|
||||||
vertices[8] = x2;
|
vertices[3] = uv.top;
|
||||||
vertices[9] = y2;
|
|
||||||
|
vertices[4] = x2;
|
||||||
vertices[10] = uv.right;
|
vertices[5] = y1;
|
||||||
vertices[11] = uv.bottom;
|
|
||||||
|
vertices[6] = uv.right;
|
||||||
vertices[12] = x1;
|
vertices[7] = uv.top;
|
||||||
vertices[13] = y2;
|
|
||||||
|
vertices[8] = x2;
|
||||||
vertices[14] = uv.left;
|
vertices[9] = y2;
|
||||||
vertices[15] = uv.bottom;
|
|
||||||
|
vertices[10] = uv.right;
|
||||||
quads.put( vertices );
|
vertices[11] = uv.bottom;
|
||||||
|
|
||||||
|
vertices[12] = x1;
|
||||||
|
vertices[13] = y2;
|
||||||
|
|
||||||
|
vertices[14] = uv.left;
|
||||||
|
vertices[15] = uv.bottom;
|
||||||
|
|
||||||
|
quads.put( vertices );
|
||||||
|
}
|
||||||
|
|
||||||
|
pos++;
|
||||||
x1 = x2;
|
x1 = x2;
|
||||||
x2 += cellW;
|
x2 += cellW;
|
||||||
|
|
||||||
|
@ -137,24 +152,30 @@ public class Tilemap extends Visual {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw() {
|
public void draw() {
|
||||||
|
|
||||||
super.draw();
|
super.draw();
|
||||||
|
|
||||||
NoosaScript script = NoosaScript.get();
|
NoosaScript script = NoosaScript.get();
|
||||||
|
|
||||||
texture.bind();
|
texture.bind();
|
||||||
|
|
||||||
script.uModel.valueM4( matrix );
|
script.uModel.valueM4( matrix );
|
||||||
script.lighting(
|
script.lighting(
|
||||||
rm, gm, bm, am,
|
rm, gm, bm, am,
|
||||||
ra, ga, ba, aa );
|
ra, ga, ba, aa );
|
||||||
|
|
||||||
if (!updated.isEmpty()) {
|
if (!updated.isEmpty()) {
|
||||||
|
quads.limit(quads.capacity());
|
||||||
updateVertices();
|
updateVertices();
|
||||||
|
quads.limit(bufferLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
script.camera( camera );
|
script.camera( camera );
|
||||||
script.drawQuadSet( quads, size );
|
script.drawQuadSet( quads, bufferLength );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean needsRender(int pos){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
package com.shatteredpixel.shatteredpixeldungeon;
|
package com.shatteredpixel.shatteredpixeldungeon;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
import com.watabou.noosa.TextureFilm;
|
import com.watabou.noosa.TextureFilm;
|
||||||
import com.watabou.noosa.Tilemap;
|
import com.watabou.noosa.Tilemap;
|
||||||
|
@ -99,4 +100,9 @@ public class DungeonTilemap extends Tilemap {
|
||||||
public boolean overlapsScreenPoint( int x, int y ) {
|
public boolean overlapsScreenPoint( int x, int y ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean needsRender(int pos) {
|
||||||
|
return Level.discoverable[pos] && Dungeon.level.map[pos] != Terrain.WATER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user