Search in sources :

Example 1 with IterableIterator

use of io.xol.chunkstories.api.util.IterableIterator in project chunkstories by Hugobros3.

the class WorldServer method getPlayers.

public IterableIterator<Player> getPlayers() {
    return new IterableIterator<Player>() {

        Iterator<Player> players = server.getConnectedPlayers();

        Player next = null;

        @Override
        public boolean hasNext() {
            while (next == null && players.hasNext()) {
                next = players.next();
                if (// Require the player to be spawned within this world.
                next.getWorld() != null && next.getWorld().equals(WorldServer.this))
                    break;
                else
                    next = null;
            }
            return next != null;
        }

        @Override
        public Player next() {
            Player player = next;
            next = null;
            return player;
        }
    };
}
Also used : Player(io.xol.chunkstories.api.player.Player) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer) Iterator(java.util.Iterator) IterableIterator(io.xol.chunkstories.api.util.IterableIterator) IterableIterator(io.xol.chunkstories.api.util.IterableIterator)

Example 2 with IterableIterator

use of io.xol.chunkstories.api.util.IterableIterator in project chunkstories by Hugobros3.

the class ChunkRenderDataHolder method renderExtras.

public void renderExtras(RenderingInterface renderingInterface) {
    noDrawDeleteConflicts.acquireUninterruptibly();
    if (this.currentData != null) {
        // For each type of voxel that requires dynamic rendering...
        for (DynamicallyRenderedVoxelType drvt : this.currentData.dynamicVoxelTypes) {
            VoxelDynamicRenderer voxelDynamicRenderer = drvt.renderer;
            // Build an iterator for the list of indexes that use that renderer
            IterableIterator<ChunkCell> relevantCellsIterator = new IterableIterator<ChunkCell>() {

                Iterator<Integer> iindex = drvt.indexes.iterator();

                ChunkCell cvc = null;

                @Override
                public boolean hasNext() {
                    while (iindex.hasNext()) {
                        if (cvc != null)
                            return true;
                        int index = iindex.next();
                        cvc = chunk.peek(index / 1024, (index / 32) % 32, index % 32);
                    }
                    if (cvc != null)
                        return true;
                    return false;
                }

                @Override
                public ChunkCell next() {
                    ChunkCell cvr = cvc;
                    cvc = null;
                    return cvr;
                }
            };
            // And we call the renderer
            voxelDynamicRenderer.renderVoxels(renderingInterface, relevantCellsIterator);
        }
    }
    noDrawDeleteConflicts.release();
}
Also used : DynamicallyRenderedVoxelType(io.xol.chunkstories.renderer.chunks.ChunkMeshDataSections.DynamicallyRenderedVoxelType) VoxelDynamicRenderer(io.xol.chunkstories.api.rendering.voxel.VoxelDynamicRenderer) Iterator(java.util.Iterator) IterableIterator(io.xol.chunkstories.api.util.IterableIterator) ChunkCell(io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell) IterableIterator(io.xol.chunkstories.api.util.IterableIterator)

Aggregations

IterableIterator (io.xol.chunkstories.api.util.IterableIterator)2 Iterator (java.util.Iterator)2 Player (io.xol.chunkstories.api.player.Player)1 VoxelDynamicRenderer (io.xol.chunkstories.api.rendering.voxel.VoxelDynamicRenderer)1 ChunkCell (io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell)1 DynamicallyRenderedVoxelType (io.xol.chunkstories.renderer.chunks.ChunkMeshDataSections.DynamicallyRenderedVoxelType)1 ServerPlayer (io.xol.chunkstories.server.player.ServerPlayer)1