Search in sources :

Example 1 with BufferTexture

use of com.watabou.gltextures.BufferTexture in project shattered-pixel-dungeon-gdx by 00-Evan.

the class FogOfWar method updateTexture.

private void updateTexture(boolean[] visible, boolean[] visited, boolean[] mapped) {
    this.visible = visible;
    this.visited = visited;
    this.mapped = mapped;
    this.brightness = SPDSettings.brightness() + 2;
    moveToUpdating();
    boolean fullUpdate = false;
    if (updating.size() == 1) {
        Rect update = updating.get(0);
        if (update.height() == mapHeight && update.width() == mapWidth) {
            fullUpdate = true;
        }
    }
    BufferTexture fog = (BufferTexture) texture;
    int cell;
    for (Rect update : updating) {
        for (int i = update.top; i <= update.bottom; i++) {
            cell = mapWidth * i + update.left;
            for (int j = update.left; j <= update.right; j++) {
                // do nothing
                if (cell >= Dungeon.level.length())
                    continue;
                if (!Dungeon.level.discoverable[cell] || (!visible[cell] && !visited[cell] && !mapped[cell])) {
                    // because they must already be dark
                    if (fullUpdate)
                        fillCell(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
                    cell++;
                    continue;
                }
                // wall tiles
                if (wall(cell)) {
                    // always dark if nothing is beneath them
                    if (cell + mapWidth >= mapLength) {
                        fillCell(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
                    // internal wall tiles, need to check both the left and right side,
                    // to account for only one half of them being seen
                    } else if (wall(cell + mapWidth)) {
                        // left side
                        if (cell % mapWidth != 0) {
                            // picks the darkest fog between current tile, left, and below-left(if left is a wall).
                            if (wall(cell - 1)) {
                                // if below-left is also a wall, then we should be dark no matter what.
                                if (wall(cell + mapWidth - 1)) {
                                    fillLeft(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
                                } else {
                                    fillLeft(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), Math.max(getCellFog(cell + mapWidth - 1), getCellFog(cell - 1)))][brightness]);
                                }
                            } else {
                                fillLeft(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), getCellFog(cell - 1))][brightness]);
                            }
                        } else {
                            fillLeft(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
                        }
                        // right side
                        if ((cell + 1) % mapWidth != 0) {
                            // picks the darkest fog between current tile, right, and below-right(if right is a wall).
                            if (wall(cell + 1)) {
                                // if below-right is also a wall, then we should be dark no matter what.
                                if (wall(cell + mapWidth + 1)) {
                                    fillRight(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
                                } else {
                                    fillRight(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), Math.max(getCellFog(cell + mapWidth + 1), getCellFog(cell + 1)))][brightness]);
                                }
                            } else {
                                fillRight(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), getCellFog(cell + 1))][brightness]);
                            }
                        } else {
                            fillRight(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
                        }
                    // camera-facing wall tiles
                    // darkest between themselves and the tile below them
                    } else {
                        fillCell(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), getCellFog(cell + mapWidth))][brightness]);
                    }
                // other tiles, just their direct value
                } else {
                    fillCell(fog, j, i, FOG_COLORS[getCellFog(cell)][brightness]);
                }
                cell++;
            }
        }
    }
    if (updating.size() == 1 && !fullUpdate) {
        fog.update(updating.get(0).top * PIX_PER_TILE, updating.get(0).bottom * PIX_PER_TILE);
    } else {
        fog.update();
    }
}
Also used : Rect(com.watabou.utils.Rect) BufferTexture(com.watabou.gltextures.BufferTexture)

Aggregations

BufferTexture (com.watabou.gltextures.BufferTexture)1 Rect (com.watabou.utils.Rect)1