Search in sources :

Example 1 with StaticBlock

use of io.anuke.mindustry.world.blocks.types.StaticBlock in project Mindustry by Anuken.

the class BlockRenderer method processBlocks.

/**
 *Process all blocks to draw, simultaneously drawing block shadows and static blocks.
 */
public void processBlocks() {
    requestidx = 0;
    int crangex = (int) (camera.viewportWidth / (chunksize * tilesize)) + 1;
    int crangey = (int) (camera.viewportHeight / (chunksize * tilesize)) + 1;
    int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2) + 2;
    int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2) + 2;
    int expandr = 3;
    Graphics.surface(renderer.shadowSurface);
    for (int x = -rangex - expandr; x <= rangex + expandr; x++) {
        for (int y = -rangey - expandr; y <= rangey + expandr; y++) {
            int worldx = Mathf.scl(camera.position.x, tilesize) + x;
            int worldy = Mathf.scl(camera.position.y, tilesize) + y;
            boolean expanded = (x < -rangex || x > rangex || y < -rangey || y > rangey);
            Tile tile = world.tile(worldx, worldy);
            if (tile != null) {
                Block block = tile.block();
                if (!expanded && block != Blocks.air && world.isAccessible(worldx, worldy)) {
                    block.drawShadow(tile);
                }
                if (!(block instanceof StaticBlock)) {
                    if (block == Blocks.air) {
                        if (!state.is(State.paused))
                            tile.floor().update(tile);
                    } else {
                        if (!expanded) {
                            addRequest(tile, Layer.block);
                        }
                        if (block.expanded || !expanded) {
                            if (block.layer != null && block.isLayer(tile)) {
                                addRequest(tile, block.layer);
                            }
                            if (block.layer2 != null && block.isLayer2(tile)) {
                                addRequest(tile, block.layer2);
                            }
                        }
                    }
                }
            }
        }
    }
    Draw.color(0, 0, 0, 0.15f);
    Graphics.flushSurface();
    Draw.color();
    Graphics.end();
    drawCache(1, crangex, crangey);
    Graphics.begin();
    Arrays.sort(requests.items, 0, requestidx);
    iterateidx = 0;
}
Also used : Tile(io.anuke.mindustry.world.Tile) Block(io.anuke.mindustry.world.Block) StaticBlock(io.anuke.mindustry.world.blocks.types.StaticBlock) StaticBlock(io.anuke.mindustry.world.blocks.types.StaticBlock) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Example 2 with StaticBlock

use of io.anuke.mindustry.world.blocks.types.StaticBlock in project Mindustry by Anuken.

the class BlockRenderer method cacheChunk.

void cacheChunk(int cx, int cy, boolean floor) {
    if (cbatch == null) {
        createBatch();
    }
    cbatch.begin();
    Graphics.useBatch(cbatch);
    for (int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++) {
        for (int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++) {
            Tile tile = world.tile(tilex, tiley);
            if (tile == null)
                continue;
            if (floor) {
                if (!(tile.block() instanceof StaticBlock)) {
                    tile.floor().draw(tile);
                }
            } else if (tile.block() instanceof StaticBlock) {
                tile.block().draw(tile);
            }
        }
    }
    Graphics.popBatch();
    cbatch.end();
    cache[cx][cy][floor ? 0 : 1] = cbatch.getLastCache();
}
Also used : Tile(io.anuke.mindustry.world.Tile) StaticBlock(io.anuke.mindustry.world.blocks.types.StaticBlock) SpawnPoint(io.anuke.mindustry.game.SpawnPoint)

Aggregations

SpawnPoint (io.anuke.mindustry.game.SpawnPoint)2 Tile (io.anuke.mindustry.world.Tile)2 StaticBlock (io.anuke.mindustry.world.blocks.types.StaticBlock)2 Block (io.anuke.mindustry.world.Block)1