v0.5.0: fog now can have multiple texture pixels within a tile
This commit is contained in:
@@ -51,6 +51,9 @@ public class FogOfWar extends Image {
|
|||||||
private static final int INVISIBLE[]= new int[]{0xFF000000, 0xFF000000,
|
private static final int INVISIBLE[]= new int[]{0xFF000000, 0xFF000000,
|
||||||
0xFF000000,
|
0xFF000000,
|
||||||
0xFF000000, 0xFF000000};
|
0xFF000000, 0xFF000000};
|
||||||
|
|
||||||
|
private int mapWidth;
|
||||||
|
private int mapHeight;
|
||||||
|
|
||||||
private int pWidth;
|
private int pWidth;
|
||||||
private int pHeight;
|
private int pHeight;
|
||||||
@@ -60,13 +63,18 @@ public class FogOfWar extends Image {
|
|||||||
|
|
||||||
private volatile Rect updated;
|
private volatile Rect updated;
|
||||||
private Rect updating;
|
private Rect updating;
|
||||||
|
|
||||||
|
private static final int PIX_PER_TILE = 2;
|
||||||
|
|
||||||
public FogOfWar( int mapWidth, int mapHeight ) {
|
public FogOfWar( int mapWidth, int mapHeight ) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
this.mapWidth = mapWidth;
|
||||||
|
this.mapHeight = mapHeight;
|
||||||
|
|
||||||
pWidth = mapWidth + 1;
|
pWidth = mapWidth * PIX_PER_TILE;
|
||||||
pHeight = mapHeight + 1;
|
pHeight = mapHeight * PIX_PER_TILE;
|
||||||
|
|
||||||
width2 = 1;
|
width2 = 1;
|
||||||
while (width2 < pWidth) {
|
while (width2 < pWidth) {
|
||||||
@@ -78,23 +86,21 @@ public class FogOfWar extends Image {
|
|||||||
height2 <<= 1;
|
height2 <<= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float size = DungeonTilemap.SIZE;
|
float size = DungeonTilemap.SIZE / PIX_PER_TILE;
|
||||||
width = width2 * size;
|
width = width2 * size;
|
||||||
height = height2 * size;
|
height = height2 * size;
|
||||||
|
|
||||||
texture( new FogTexture(width2, height2) );
|
texture( new FogTexture(width2, height2) );
|
||||||
|
|
||||||
scale.set(
|
scale.set(
|
||||||
DungeonTilemap.SIZE,
|
DungeonTilemap.SIZE / PIX_PER_TILE,
|
||||||
DungeonTilemap.SIZE );
|
DungeonTilemap.SIZE / PIX_PER_TILE);
|
||||||
|
|
||||||
x = y = -size / 2;
|
|
||||||
|
|
||||||
updated = new Rect(0, 0, pWidth, pHeight);
|
updated = new Rect(0, 0, mapWidth, mapHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateFog(){
|
public synchronized void updateFog(){
|
||||||
updated.set( 0, 0, pWidth, pWidth );
|
updated.set( 0, 0, mapWidth, mapHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateFogArea(int x, int y, int w, int h){
|
public synchronized void updateFogArea(int x, int y, int w, int h){
|
||||||
@@ -116,38 +122,41 @@ public class FogOfWar extends Image {
|
|||||||
int brightness = ShatteredPixelDungeon.brightness() + 2;
|
int brightness = ShatteredPixelDungeon.brightness() + 2;
|
||||||
|
|
||||||
for (int i=updating.top; i < updating.bottom; i++) {
|
for (int i=updating.top; i < updating.bottom; i++) {
|
||||||
int cell = (pWidth - 1) * i + updating.left;
|
int cell = mapWidth * i + updating.left;
|
||||||
fog.pixels.position((width2) * i + updating.left);
|
//fog.pixels.position((width2) * i + updating.left);
|
||||||
for (int j=updating.left; j < updating.right; j++) {
|
for (int j=updating.left; j < updating.right; j++) {
|
||||||
if (cell < pWidth || cell >= Dungeon.level.length() || j == 0 || j == pWidth-1) {
|
if (cell >= Dungeon.level.length()) {
|
||||||
fog.pixels.put(INVISIBLE[brightness]);
|
//do nothing
|
||||||
} else
|
} else if (visible[cell]) {
|
||||||
if (visible[cell] && visible[cell - (pWidth - 1)] &&
|
fillCell(j, i, VISIBLE[brightness]);
|
||||||
visible[cell - 1] && visible[cell - (pWidth - 1) - 1]) {
|
} else if (visited[cell]) {
|
||||||
fog.pixels.put(VISIBLE[brightness]);
|
fillCell(j, i, VISITED[brightness]);
|
||||||
} else
|
} else if (mapped[cell] ) {
|
||||||
if (visited[cell] && visited[cell - (pWidth - 1)] &&
|
fillCell(j, i, MAPPED[brightness]);
|
||||||
visited[cell - 1] && visited[cell - (pWidth - 1) - 1]) {
|
|
||||||
fog.pixels.put(VISITED[brightness]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (mapped[cell] && mapped[cell - (pWidth - 1)] &&
|
|
||||||
mapped[cell - 1] && mapped[cell - (pWidth - 1) - 1]) {
|
|
||||||
fog.pixels.put(MAPPED[brightness]);
|
|
||||||
} else {
|
} else {
|
||||||
fog.pixels.put(INVISIBLE[brightness]);
|
fillCell(j, i, INVISIBLE[brightness]);
|
||||||
}
|
}
|
||||||
cell++;
|
cell++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updating.width() == pWidth && updating.height() == pHeight)
|
if (updating.width() == mapWidth && updating.height() == mapWidth)
|
||||||
fog.update();
|
fog.update();
|
||||||
else
|
else
|
||||||
fog.update(updating.top, updating.bottom);
|
fog.update(updating.top * PIX_PER_TILE, updating.bottom * PIX_PER_TILE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillCell( int x, int y, int color){
|
||||||
|
FogTexture fog = (FogTexture)texture;
|
||||||
|
for (int i = 0; i < PIX_PER_TILE; i++){
|
||||||
|
fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE);
|
||||||
|
for (int j = 0; j < PIX_PER_TILE; j++) {
|
||||||
|
fog.pixels.put(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//provides a native intbuffer implementation because android.graphics.bitmap is too slow
|
//provides a native intbuffer implementation because android.graphics.bitmap is too slow
|
||||||
//TODO perhaps should spin this off into something like FastEditTexture in SPD-classes
|
//TODO perhaps should spin this off into something like FastEditTexture in SPD-classes
|
||||||
private class FogTexture extends SmartTexture {
|
private class FogTexture extends SmartTexture {
|
||||||
@@ -182,6 +191,7 @@ public class FogOfWar extends Image {
|
|||||||
public void update(){
|
public void update(){
|
||||||
bind();
|
bind();
|
||||||
filter( Texture.LINEAR, Texture.LINEAR );
|
filter( Texture.LINEAR, Texture.LINEAR );
|
||||||
|
wrap( Texture.CLAMP, Texture.CLAMP);
|
||||||
pixels.position(0);
|
pixels.position(0);
|
||||||
GLES20.glTexImage2D(
|
GLES20.glTexImage2D(
|
||||||
GLES20.GL_TEXTURE_2D,
|
GLES20.GL_TEXTURE_2D,
|
||||||
@@ -199,6 +209,7 @@ public class FogOfWar extends Image {
|
|||||||
public void update(int top, int bottom){
|
public void update(int top, int bottom){
|
||||||
bind();
|
bind();
|
||||||
filter( Texture.LINEAR, Texture.LINEAR );
|
filter( Texture.LINEAR, Texture.LINEAR );
|
||||||
|
wrap( Texture.CLAMP, Texture.CLAMP);
|
||||||
pixels.position(top*width);
|
pixels.position(top*width);
|
||||||
GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D,
|
GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D,
|
||||||
0,
|
0,
|
||||||
|
|||||||
Reference in New Issue
Block a user