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);
}
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);
}
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);
}
}
}
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);
}
}
}
}
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);
}
}
}
}
}
Aggregations