use of org.terasology.math.geom.Vector3i 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.math.geom.Vector3i in project Terasology by MovingBlocks.
the class FacetLayerPreview method rasterize.
/**
* Note: this method must be thread-safe!
* @param region the thread-safe region
* @return an image of that region
*/
private BufferedImage rasterize(Region region) {
Vector3i extent = region.getRegion().size();
int width = extent.x;
int height = extent.z;
WritableRaster raster = colorModel.createCompatibleWritableRaster(width, height);
BufferedImage image = new BufferedImage(colorModel, raster, false, null);
Graphics2D g = image.createGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, width, height);
try {
facetLayers.stream().filter(FacetLayer::isVisible).forEach(layer -> layer.render(image, region));
} finally {
g.dispose();
}
return image;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class FacetLayerPreview method createRegion.
private Region createRegion(ImmutableVector2i chunkPos) {
// 4 chunks high (relevant for trees, etc)
int vertChunks = 4;
int minX = chunkPos.getX() * TILE_SIZE_X;
int minZ = chunkPos.getY() * TILE_SIZE_Y;
int height = vertChunks * ChunkConstants.SIZE_Y;
Region3i area3d = Region3i.createFromMinAndSize(new Vector3i(minX, 0, minZ), new Vector3i(TILE_SIZE_X, height, TILE_SIZE_Y));
World world = worldGenerator.getWorld();
Region region = world.getWorldData(area3d);
return region;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class ChunkMeshUpdateManager method setCameraPosition.
/**
* The method tells the chunk mesh update manager where the camera is, so that is able to prioritize chunks near the
* camera. It stores the values in volatile variables so that the change is visible to the chunk updating threads
* immediately.
*/
public void setCameraPosition(Vector3f cameraPosition) {
Vector3i chunkPos = ChunkMath.calcChunkPos(cameraPosition);
cameraChunkPosX = chunkPos.x;
cameraChunkPosY = chunkPos.y;
cameraChunkPosZ = chunkPos.z;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class RenderableWorldImpl method updateChunksInProximity.
/**
* Updates the list of chunks around the player.
*
* @return True if the list was changed
*/
@Override
public boolean updateChunksInProximity(Region3i newRenderableRegion) {
if (!newRenderableRegion.equals(renderableRegion)) {
Vector3i chunkPosition;
RenderableChunk chunk;
Iterator<Vector3i> chunksToRemove = renderableRegion.subtract(newRenderableRegion);
while (chunksToRemove.hasNext()) {
chunkPosition = chunksToRemove.next();
Iterator<RenderableChunk> nearbyChunks = chunksInProximityOfCamera.iterator();
while (nearbyChunks.hasNext()) {
chunk = nearbyChunks.next();
if (chunk.getPosition().equals(chunkPosition)) {
chunk.disposeMesh();
nearbyChunks.remove();
break;
}
}
}
boolean chunksHaveBeenAdded = false;
Iterator<Vector3i> chunksToAdd = newRenderableRegion.subtract(renderableRegion);
while (chunksToAdd.hasNext()) {
chunkPosition = chunksToAdd.next();
chunk = chunkProvider.getChunk(chunkPosition);
if (chunk != null) {
chunksInProximityOfCamera.add(chunk);
chunksHaveBeenAdded = true;
}
}
if (chunksHaveBeenAdded) {
Collections.sort(chunksInProximityOfCamera, new ChunkFrontToBackComparator());
}
renderableRegion = newRenderableRegion;
return true;
}
return false;
}
Aggregations