Search in sources :

Example 1 with Biome

use of org.terasology.world.biomes.Biome in project Terasology by MovingBlocks.

the class DebugOverlay method initialise.

@Override
public void initialise() {
    bindVisible(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return config.getSystem().isDebugEnabled();
        }
    });
    UILabel debugLine1 = find("debugLine1", UILabel.class);
    if (debugLine1 != null) {
        debugLine1.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                double memoryUsage = ((double) Runtime.getRuntime().totalMemory() - (double) Runtime.getRuntime().freeMemory()) / 1048576.0;
                return String.format("fps: %.2f, mem usage: %.2f MB, total mem: %.2f MB, max mem: %.2f MB", time.getFps(), memoryUsage, Runtime.getRuntime().totalMemory() / 1048576.0, Runtime.getRuntime().maxMemory() / 1048576.0);
            }
        });
    }
    UILabel debugLine2 = find("debugLine2", UILabel.class);
    if (debugLine2 != null) {
        debugLine2.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return String.format("Active Entities: %s, Current Target: %s", entityManager.getActiveEntityCount(), cameraTarget.toString());
            }
        });
    }
    UILabel debugLine3 = find("debugLine3", UILabel.class);
    if (debugLine3 != null) {
        debugLine3.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                Vector3f pos = localPlayer.getPosition();
                Vector3i chunkPos = ChunkMath.calcChunkPos((int) pos.x, (int) pos.y, (int) pos.z);
                Vector3f rotation = localPlayer.getViewDirection();
                Vector3f cameraPos = localPlayer.getViewPosition();
                return String.format(Locale.US, "Pos (%.2f, %.2f, %.2f), Chunk (%d, %d, %d), Eye (%.2f, %.2f, %.2f), Rot (%.2f, %.2f, %.2f)", pos.x, pos.y, pos.z, chunkPos.x, chunkPos.y, chunkPos.z, cameraPos.x, cameraPos.y, cameraPos.z, rotation.x, rotation.y, rotation.z);
            }
        });
    }
    UILabel debugLine4 = find("debugLine4", UILabel.class);
    if (debugLine4 != null) {
        debugLine4.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                String biomeId = "unavailable";
                Vector3i blockPos = new Vector3i(localPlayer.getPosition());
                if (worldProvider.isBlockRelevant(blockPos)) {
                    Biome biome = worldProvider.getBiome(blockPos);
                    biomeId = CoreRegistry.get(BiomeManager.class).getBiomeId(biome);
                }
                return String.format("total vus: %s | worldTime: %.3f | tiDi: %.1f |  biome: %s", ChunkTessellator.getVertexArrayUpdateCount(), // use floor instead of rounding up
                worldProvider.getTime().getDays() - 0.0005f, time.getGameTimeDilation(), biomeId);
            }
        });
    }
    UILabel saveStatusLabel = find("saveStatusLabel", UILabel.class);
    // clients do not have a storage manager
    if (saveStatusLabel != null && storageManager != null) {
        saveStatusLabel.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return "Saving... ";
            }
        });
        saveStatusLabel.bindVisible(new ReadOnlyBinding<Boolean>() {

            @Override
            public Boolean get() {
                return storageManager.isSaving();
            }
        });
    }
    metricsLabel = find("metrics", UILabel.class);
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) BiomeManager(org.terasology.world.biomes.BiomeManager) Biome(org.terasology.world.biomes.Biome) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i)

Example 2 with Biome

use of org.terasology.world.biomes.Biome in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method addGameManifestToSaveTransaction.

private void addGameManifestToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder) {
    BlockManager blockManager = CoreRegistry.get(BlockManager.class);
    BiomeManager biomeManager = CoreRegistry.get(BiomeManager.class);
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
    Time time = CoreRegistry.get(Time.class);
    Game game = CoreRegistry.get(Game.class);
    GameManifest gameManifest = new GameManifest(game.getName(), game.getSeed(), time.getGameTimeInMs());
    for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    List<String> registeredBlockFamilies = Lists.newArrayList();
    for (BlockFamily family : blockManager.listRegisteredBlockFamilies()) {
        registeredBlockFamilies.add(family.getURI().toString());
    }
    gameManifest.setRegisteredBlockFamilies(registeredBlockFamilies);
    gameManifest.setBlockIdMap(blockManager.getBlockIdMap());
    List<Biome> biomes = biomeManager.getBiomes();
    Map<String, Short> biomeIdMap = new HashMap<>(biomes.size());
    for (Biome biome : biomes) {
        short shortId = biomeManager.getBiomeShortId(biome);
        String id = biomeManager.getBiomeId(biome);
        biomeIdMap.put(id, shortId);
    }
    gameManifest.setBiomeIdMap(biomeIdMap);
    gameManifest.addWorld(worldProvider.getWorldInfo());
    saveTransactionBuilder.setGameManifest(gameManifest);
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) HashMap(java.util.HashMap) Time(org.terasology.engine.Time) ModuleManager(org.terasology.engine.module.ModuleManager) Game(org.terasology.game.Game) Biome(org.terasology.world.biomes.Biome) GameManifest(org.terasology.game.GameManifest) BlockManager(org.terasology.world.block.BlockManager) WorldProvider(org.terasology.world.WorldProvider) BlockFamily(org.terasology.world.block.family.BlockFamily) Module(org.terasology.module.Module)

Example 3 with Biome

use of org.terasology.world.biomes.Biome in project Terasology by MovingBlocks.

the class ServerImpl method processBiomeChanges.

private void processBiomeChanges(NetData.NetMessage message) {
    for (NetData.BiomeChangeMessage biomeChange : message.getBiomeChangeList()) {
        logger.debug("Received block change to {}", blockManager.getBlock((short) biomeChange.getNewBiome()));
        // TODO: Store changes to blocks that aren't ready to be modified (the surrounding chunks aren't available)
        WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
        Vector3i pos = NetMessageUtil.convert(biomeChange.getPos());
        if (worldProvider.isBlockRelevant(pos)) {
            Biome newBiome = biomeManager.getBiomeByShortId((short) biomeChange.getNewBiome());
            worldProvider.setBiome(pos, newBiome);
        } else {
            awaitingChunkReadyBiomeUpdates.put(ChunkMath.calcChunkPos(pos), biomeChange);
        }
    }
}
Also used : Biome(org.terasology.world.biomes.Biome) NetData(org.terasology.protobuf.NetData) WorldProvider(org.terasology.world.WorldProvider) Vector3i(org.terasology.math.geom.Vector3i)

Example 4 with Biome

use of org.terasology.world.biomes.Biome in project Terasology by MovingBlocks.

the class SolidRasterizer method generateChunk.

@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
    LiquidData waterLiquid = new LiquidData(LiquidType.WATER, LiquidData.MAX_LIQUID_DEPTH);
    DensityFacet solidityFacet = chunkRegion.getFacet(DensityFacet.class);
    SurfaceHeightFacet surfaceFacet = chunkRegion.getFacet(SurfaceHeightFacet.class);
    SurfaceDepthFacet surfaceDepthFacet = chunkRegion.getFacet(SurfaceDepthFacet.class);
    BiomeFacet biomeFacet = chunkRegion.getFacet(BiomeFacet.class);
    SeaLevelFacet seaLevelFacet = chunkRegion.getFacet(SeaLevelFacet.class);
    int seaLevel = seaLevelFacet.getSeaLevel();
    Vector2i pos2d = new Vector2i();
    for (Vector3i pos : ChunkConstants.CHUNK_REGION) {
        pos2d.set(pos.x, pos.z);
        int posY = pos.y + chunk.getChunkWorldOffsetY();
        // Check for an optional depth for this layer - if defined stop generating below that level
        if (surfaceDepthFacet != null && posY < surfaceDepthFacet.get(pos2d)) {
            continue;
        }
        Biome biome = biomeFacet.get(pos2d);
        chunk.setBiome(pos.x, pos.y, pos.z, biome);
        float density = solidityFacet.get(pos);
        if (density >= 32) {
            chunk.setBlock(pos, stone);
        } else if (density >= 0) {
            int depth = TeraMath.floorToInt(surfaceFacet.get(pos2d)) - posY;
            Block block = getSurfaceBlock(depth, posY, biome, seaLevel);
            chunk.setBlock(pos, block);
        } else {
            // fill up terrain up to sealevel height with water or ice
            if (posY == seaLevel && CoreBiome.SNOW == biome) {
                chunk.setBlock(pos, ice);
            } else if (posY <= seaLevel) {
                // either OCEAN or SNOW
                chunk.setBlock(pos, water);
                chunk.setLiquid(pos, waterLiquid);
            }
        }
    }
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Biome(org.terasology.world.biomes.Biome) CoreBiome(org.terasology.core.world.CoreBiome) DensityFacet(org.terasology.world.generation.facets.DensityFacet) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) SeaLevelFacet(org.terasology.world.generation.facets.SeaLevelFacet) Vector2i(org.terasology.math.geom.Vector2i) BiomeFacet(org.terasology.core.world.generator.facets.BiomeFacet) LiquidData(org.terasology.world.liquid.LiquidData) SurfaceDepthFacet(org.terasology.world.generation.facets.SurfaceDepthFacet)

Example 5 with Biome

use of org.terasology.world.biomes.Biome in project Terasology by MovingBlocks.

the class BlockMeshGeneratorSingleShape method generateChunkMesh.

@Override
public void generateChunkMesh(ChunkView view, ChunkMesh chunkMesh, int x, int y, int z) {
    Biome selfBiome = view.getBiome(x, y, z);
    Block selfBlock = view.getBlock(x, y, z);
    // TODO: Needs review - too much hardcoded special cases and corner cases resulting from this.
    ChunkVertexFlag vertexFlag = ChunkVertexFlag.NORMAL;
    if (selfBlock.isWater()) {
        if (view.getBlock(x, y + 1, z).isWater()) {
            vertexFlag = ChunkVertexFlag.WATER;
        } else {
            vertexFlag = ChunkVertexFlag.WATER_SURFACE;
        }
    } else if (selfBlock.isLava()) {
        vertexFlag = ChunkVertexFlag.LAVA;
    } else if (selfBlock.isWaving() && selfBlock.isDoubleSided()) {
        vertexFlag = ChunkVertexFlag.WAVING;
    } else if (selfBlock.isWaving()) {
        vertexFlag = ChunkVertexFlag.WAVING_BLOCK;
    }
    // Gather adjacent blocks
    Map<Side, Block> adjacentBlocks = Maps.newEnumMap(Side.class);
    for (Side side : Side.values()) {
        Vector3i offset = side.getVector3i();
        Block blockToCheck = view.getBlock(x + offset.x, y + offset.y, z + offset.z);
        adjacentBlocks.put(side, blockToCheck);
    }
    BlockAppearance blockAppearance = selfBlock.getAppearance(adjacentBlocks);
    /*
         * Determine the render process.
         */
    ChunkMesh.RenderType renderType = ChunkMesh.RenderType.TRANSLUCENT;
    if (!selfBlock.isTranslucent()) {
        renderType = ChunkMesh.RenderType.OPAQUE;
    }
    // TODO: Review special case, or alternatively compare uris.
    if (selfBlock.isWater() || selfBlock.isIce()) {
        renderType = ChunkMesh.RenderType.WATER_AND_ICE;
    }
    if (selfBlock.isDoubleSided()) {
        renderType = ChunkMesh.RenderType.BILLBOARD;
    }
    if (blockAppearance.getPart(BlockPart.CENTER) != null) {
        Vector4f colorOffset = selfBlock.calcColorOffsetFor(BlockPart.CENTER, selfBiome);
        blockAppearance.getPart(BlockPart.CENTER).appendTo(chunkMesh, x, y, z, colorOffset, renderType, vertexFlag);
    }
    boolean[] drawDir = new boolean[6];
    for (Side side : Side.values()) {
        drawDir[side.ordinal()] = blockAppearance.getPart(BlockPart.fromSide(side)) != null && isSideVisibleForBlockTypes(adjacentBlocks.get(side), selfBlock, side);
    }
    // If the selfBlock is lowered, some more faces may have to be drawn
    if (selfBlock.isLiquid()) {
        Block bottomBlock = adjacentBlocks.get(Side.BOTTOM);
        // Draw horizontal sides if visible from below
        for (Side side : Side.horizontalSides()) {
            Vector3i offset = side.getVector3i();
            Block adjacentBelow = view.getBlock(x + offset.x, y - 1, z + offset.z);
            Block adjacent = adjacentBlocks.get(side);
            boolean visible = (blockAppearance.getPart(BlockPart.fromSide(side)) != null && isSideVisibleForBlockTypes(adjacentBelow, selfBlock, side) && !isSideVisibleForBlockTypes(bottomBlock, adjacent, side.reverse()));
            drawDir[side.ordinal()] |= visible;
        }
        // Draw the top if below a non-lowered selfBlock
        // TODO: Don't need to render the top if each side and the selfBlock above each side are either liquid or opaque solids.
        Block blockToCheck = adjacentBlocks.get(Side.TOP);
        drawDir[Side.TOP.ordinal()] |= !blockToCheck.isLiquid();
        if (bottomBlock.isLiquid() || bottomBlock.getMeshGenerator() == null) {
            for (Side dir : Side.values()) {
                if (drawDir[dir.ordinal()]) {
                    Vector4f colorOffset = selfBlock.calcColorOffsetFor(BlockPart.fromSide(dir), selfBiome);
                    selfBlock.getLoweredLiquidMesh(dir).appendTo(chunkMesh, x, y, z, colorOffset, renderType, vertexFlag);
                }
            }
            return;
        }
    }
    for (Side dir : Side.values()) {
        if (drawDir[dir.ordinal()]) {
            Vector4f colorOffset = selfBlock.calcColorOffsetFor(BlockPart.fromSide(dir), selfBiome);
            // TODO: Needs review since the new per-vertex flags introduce a lot of special scenarios - probably a per-side setting?
            if (selfBlock.isGrass() && dir != Side.TOP && dir != Side.BOTTOM) {
                blockAppearance.getPart(BlockPart.fromSide(dir)).appendTo(chunkMesh, x, y, z, colorOffset, renderType, ChunkVertexFlag.COLOR_MASK);
            } else {
                if (blockAppearance.getPart(BlockPart.fromSide(dir)) == null) {
                    // TODO: This would catch something like water blocks attempting to render with a "fixed" trimmedLoweredCube shape
                    // That shape has its top trimmed down a bit to let water sit slightly lower than land, however, underwater this shouldn't show
                    // Normally we would configure that shape with CENTER instead of TOP, that way the trimmed part wouldn't occlude in a stack
                    // But with that handling you don't get water blocks occluding tops underwater... and there's no TOP to retrieve below -> NPE
                    logger.debug("Cannot render side '{}' for a block - no stored block appearance for it. renderType {}, vertexFlag {}", dir, renderType, vertexFlag);
                } else {
                    blockAppearance.getPart(BlockPart.fromSide(dir)).appendTo(chunkMesh, x, y, z, colorOffset, renderType, vertexFlag);
                }
            }
        }
    }
}
Also used : Side(org.terasology.math.Side) Biome(org.terasology.world.biomes.Biome) BlockAppearance(org.terasology.world.block.BlockAppearance) Vector4f(org.terasology.math.geom.Vector4f) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Aggregations

Biome (org.terasology.world.biomes.Biome)9 Vector3i (org.terasology.math.geom.Vector3i)7 WorldProvider (org.terasology.world.WorldProvider)4 Block (org.terasology.world.block.Block)4 ModuleManager (org.terasology.engine.module.ModuleManager)2 Module (org.terasology.module.Module)2 NetData (org.terasology.protobuf.NetData)2 BiomeManager (org.terasology.world.biomes.BiomeManager)2 BlockFamily (org.terasology.world.block.family.BlockFamily)2 ByteString (com.google.protobuf.ByteString)1 TIntLongMap (gnu.trove.map.TIntLongMap)1 TIntLongHashMap (gnu.trove.map.hash.TIntLongHashMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CoreBiome (org.terasology.core.world.CoreBiome)1 BiomeFacet (org.terasology.core.world.generator.facets.BiomeFacet)1 Time (org.terasology.engine.Time)1 Game (org.terasology.game.Game)1 GameManifest (org.terasology.game.GameManifest)1 OnEnterBiomeEvent (org.terasology.logic.characters.events.OnEnterBiomeEvent)1