use of io.xol.chunkstories.world.chunk.ClientChunk in project chunkstories by Hugobros3.
the class DebugInfoRenderer method getLoadedChunksVramFootprint.
@SuppressWarnings("unused")
private String getLoadedChunksVramFootprint() {
int nbChunks = 0;
long octelsTotal = 0;
ChunksIterator i = world.getAllLoadedChunks();
Chunk c;
while (i.hasNext()) {
c = i.next();
if (c == null)
continue;
if (c instanceof ChunkRenderable) {
ChunkRenderDataHolder chunkRenderData = ((ClientChunk) c).getChunkRenderData();
if (chunkRenderData != null) {
nbChunks++;
// octelsTotal += chunkRenderData.getVramUsage();
}
}
}
// , storing " + octelsTotal / 1024 / 1024 + "Mb of vertex data.";
return nbChunks + " chunks";
}
use of io.xol.chunkstories.world.chunk.ClientChunk in project chunkstories by Hugobros3.
the class DebugInfoRenderer method drawF3debugMenu.
public void drawF3debugMenu(RenderingInterface renderingInterface) {
CameraInterface camera = renderingInterface.getCamera();
Entity playerEntity = client.getPlayer().getControlledEntity();
/*int timeTook = Client.profiler.timeTook();
String debugInfo = Client.profiler.reset("gui").toString();
if (timeTook > 400)
System.out.println("Lengty frame, printing debug information : \n" + debugInfo);*/
// Memory usage
long total = Runtime.getRuntime().totalMemory();
long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
// By default use the camera position
int bx = ((int) camera.getCameraPosition().x());
int by = ((int) camera.getCameraPosition().y());
int bz = ((int) camera.getCameraPosition().z());
int lx = bx, ly = by, lz = bz;
// If the player can look use that
if (playerEntity != null && playerEntity instanceof EntityControllable) {
Location loc = ((EntityControllable) playerEntity).getBlockLookingAt(true);
if (loc != null) {
lx = (int) loc.x();
ly = (int) loc.y();
lz = (int) loc.z();
}
}
int raw_data = world.peekRaw(lx, ly, lz);
CellData cell = world.peekSafely(lx, ly, lz);
// System.out.println(VoxelFormat.id(raw_data));
int cx = bx / 32;
int cy = by / 32;
int cz = bz / 32;
int csh = world.getRegionsSummariesHolder().getHeightAtWorldCoordinates(bx, bz);
// Obtain the angle the player is facing
VoxelSide side = VoxelSide.TOP;
float angleX = -1;
if (playerEntity != null && playerEntity instanceof EntityLiving)
angleX = Math.round(((EntityLiving) playerEntity).getEntityRotationComponent().getHorizontalRotation());
double dx = Math.sin(angleX / 360 * 2.0 * Math.PI);
double dz = Math.cos(angleX / 360 * 2.0 * Math.PI);
if (Math.abs(dx) > Math.abs(dz)) {
if (dx > 0)
side = VoxelSide.RIGHT;
else
side = VoxelSide.LEFT;
} else {
if (dz > 0)
side = VoxelSide.FRONT;
else
side = VoxelSide.BACK;
}
// Count all the entities
int ec = 0;
IterableIterator<Entity> i = world.getAllLoadedEntities();
while (i.hasNext()) {
i.next();
ec++;
}
Chunk current = world.getChunk(cx, cy, cz);
int x_top = renderingInterface.getWindow().getHeight() - 16;
Font font = null;
font = renderingInterface.getFontRenderer().getFont("LiberationSans-Regular", 12);
if (font == null)
font = renderingInterface.getFontRenderer().getFont("LiberationSans-Regular", 12);
int lineHeight = font.getLineHeight();
int posx, posy;
String text;
posx = 8;
posy = x_top - posx;
text = GLCalls.getStatistics() + " Chunks in view : " + world.getWorldRenderer().getChunksRenderer().getChunksVisible() + " Entities " + ec + " Particles :" + ((ClientParticlesRenderer) world.getParticlesManager()).count() + " #FF0000Render FPS: " + Client.getInstance().getGameWindow().getFPS() + " avg: " + Math.floor(10000.0 / Client.getInstance().getGameWindow().getFPS()) / 10.0 + " #00FFFFSimulation FPS: " + world.getWorldRenderer().getWorld().getGameLogic().getSimulationFps();
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "RAM usage : " + used / 1024 / 1024 + " / " + total / 1024 / 1024 + " MB used, chunks loaded in ram: " + world.getRegionsHolder().countChunksWithData() + "/" + world.getRegionsHolder().countChunks() + " " + Math.floor(world.getRegionsHolder().countChunksWithData() * 4 * 32 * 32 * 32 / (1024L * 1024 / 100f)) / 100f + "MB used by chunks";
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
long totalVram = (renderingInterface.getTotalVramUsage()) / 1024 / 1024;
posy -= lineHeight;
text = "VRAM usage : " + totalVram + "MB as " + Texture2DGL.getTotalNumberOfTextureObjects() + " textures using " + Texture2DGL.getTotalVramUsage() / 1024 / 1024 + "MB + " + VertexBufferGL.getTotalNumberOfVerticesObjects() + " vbos using " + renderingInterface.getVertexDataVramUsage() / 1024 / 1024 + " MB";
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "Worker threads: " + world.getGameContext().tasks() + " - " + world.ioHandler.toString();
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "Position : x:" + bx + " y:" + by + " z:" + bz + " dir: " + angleX + " side: " + side + " #FF0000Block looking at#FFFFFF : pos: " + lx + ": " + ly + ": " + lz + " data: " + raw_data + " voxel_type: " + cell.getVoxel().getName() + " sl:" + cell.getSunlight() + " bl: " + cell.getBlocklight() + " meta:" + cell.getMetaData() + " csh:" + csh;
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "Current Summary : " + world.getRegionsSummariesHolder().getHeightmapChunkCoordinates(cx, cz);
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "Current Region : " + world.getRegionChunkCoordinates(cx, cy, cz);
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
if (current == null) {
posy -= lineHeight;
text = "Current chunk null";
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
} else if (current instanceof ChunkRenderable) {
ChunkRenderDataHolder chunkRenderData = ((ClientChunk) current).getChunkRenderData();
if (chunkRenderData != null) {
posy -= lineHeight;
text = "Current Chunk : " + current + " - " + chunkRenderData.toString();
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
} else {
posy -= lineHeight;
text = "Current Chunk : " + current + " - No rendering data";
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
}
}
if (playerEntity != null && playerEntity instanceof Entity) {
posy -= lineHeight;
text = "Controlled Entity : " + playerEntity;
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
}
}
use of io.xol.chunkstories.world.chunk.ClientChunk in project chunkstories by Hugobros3.
the class ChunkMeshesRenderer method floodFillArround.
private List<ClientChunk> floodFillArround(Vector3fc vector3, int maxDistance) {
floodFillSet.clear();
// floodFillMask.clear();
floodFillDeque.clear();
int horizontalSize = maxDistance * 2 + 3;
int expectedLength = horizontalSize * horizontalSize * horizontalSize;
if (floodFillMask == null || floodFillMask.length != expectedLength) {
floodFillMask = new boolean[expectedLength];
} else {
for (int i = 0; i < floodFillMask.length; i++) floodFillMask[i] = false;
}
floodFillDeque.addLast(cameraChunkX);
floodFillDeque.addLast(cameraChunkY);
floodFillDeque.addLast(cameraChunkZ);
floodFillDeque.addLast(-1);
while (!floodFillDeque.isEmpty()) {
int sideFrom = floodFillDeque.removeLast();
int chunkZ = floodFillDeque.removeLast();
int chunkY = floodFillDeque.removeLast();
int chunkX = floodFillDeque.removeLast();
sideFrom = -1;
int ajustedChunkX = chunkX;
int ajustedChunkZ = chunkZ;
// TODO made forced cast irrelevant
ClientChunk chunk = (ClientChunk) world.getChunk(chunkX, chunkY, chunkZ);
int index = indexInto(chunkX, chunkY, chunkZ, maxDistance);
// if (floodFillMask.contains(new Vector3d(chunkX, chunkY, chunkZ)))
if (floodFillMask[index])
continue;
floodFillMask[index] = true;
if (chunk != null) {
chunk.occlusion.spawnUpdateTaskIfNeeded();
boolean[][] occlusionSides = chunk.occlusion.occlusionSides;
if (chunk.isAirChunk() || occlusionSides == null)
sideFrom = -1;
floodFillSet.add(chunk);
if ((sideFrom == -1 || occlusionSides[sideFrom][2]) && LoopingMathHelper.moduloDistance(chunkX, cameraChunkX, worldSizeInChunks) < maxDistance && !floodFillMask[indexInto(chunkX + 1, chunkY, chunkZ, maxDistance)]) {
floodFillDeque.addLast(ajustedChunkX + 1);
floodFillDeque.addLast(chunkY);
floodFillDeque.addLast(ajustedChunkZ);
floodFillDeque.addLast(0);
}
if ((sideFrom == -1 || occlusionSides[sideFrom][0]) && LoopingMathHelper.moduloDistance(chunkX, cameraChunkX, worldSizeInChunks) < maxDistance && !floodFillMask[indexInto(chunkX - 1, chunkY, chunkZ, maxDistance)]) {
floodFillDeque.addLast(ajustedChunkX - 1);
floodFillDeque.addLast(chunkY);
floodFillDeque.addLast(ajustedChunkZ);
floodFillDeque.addLast(2);
}
if ((sideFrom == -1 || occlusionSides[sideFrom][4]) && chunkY < world.getMaxHeight() / 32 && (chunkY - cameraChunkY) < verticalDistance && !floodFillMask[indexInto(chunkX, chunkY + 1, chunkZ, maxDistance)]) {
floodFillDeque.addLast(ajustedChunkX);
floodFillDeque.addLast(chunkY + 1);
floodFillDeque.addLast(ajustedChunkZ);
floodFillDeque.addLast(5);
}
if ((sideFrom == -1 || occlusionSides[sideFrom][5]) && chunkY > 0 && (cameraChunkY - chunkY) < verticalDistance && !floodFillMask[indexInto(chunkX, chunkY - 1, chunkZ, maxDistance)]) {
floodFillDeque.addLast(ajustedChunkX);
floodFillDeque.addLast(chunkY - 1);
floodFillDeque.addLast(ajustedChunkZ);
floodFillDeque.addLast(4);
}
if ((sideFrom == -1 || occlusionSides[sideFrom][1]) && LoopingMathHelper.moduloDistance(chunkZ, cameraChunkZ, worldSizeInChunks) < maxDistance && !floodFillMask[indexInto(chunkX, chunkY, chunkZ + 1, maxDistance)]) {
floodFillDeque.addLast(ajustedChunkX);
floodFillDeque.addLast(chunkY);
floodFillDeque.addLast(ajustedChunkZ + 1);
floodFillDeque.addLast(3);
}
if ((sideFrom == -1 || occlusionSides[sideFrom][3]) && LoopingMathHelper.moduloDistance(chunkZ, cameraChunkZ, worldSizeInChunks) < maxDistance && !floodFillMask[indexInto(chunkX, chunkY, chunkZ - 1, maxDistance)]) {
floodFillDeque.addLast(ajustedChunkX);
floodFillDeque.addLast(chunkY);
floodFillDeque.addLast(ajustedChunkZ - 1);
floodFillDeque.addLast(1);
}
}
}
return floodFillSet;
}
use of io.xol.chunkstories.world.chunk.ClientChunk in project chunkstories by Hugobros3.
the class ChunkMeshesRenderer method updateShadowPVS.
private List<ChunkRenderCommand> updateShadowPVS(Vector3dc vector3) {
// Micro-optimization: Moved to a field
// List<ChunkRenderCommand> shadowChunks = new ArrayList<ChunkRenderCommand>();
shadowChunks.clear();
int maxShadowDistance = 4;
if (world.getClient().getConfiguration().getIntOption("client.rendering.shadowsResolution") >= 2048)
maxShadowDistance = 5;
if (world.getClient().getConfiguration().getIntOption("client.rendering.shadowsResolution") >= 4096)
maxShadowDistance = 60;
int maxVerticalShadowDistance = 4;
for (int x = cameraChunkX - maxShadowDistance; x < cameraChunkX + maxShadowDistance; x++) for (int y = cameraChunkY - maxVerticalShadowDistance; y < cameraChunkY + maxVerticalShadowDistance; y++) for (int z = cameraChunkZ - maxShadowDistance; z < cameraChunkZ + maxShadowDistance; z++) {
// TODO have this cast made irrelevant
ClientChunk chunk = (ClientChunk) world.getChunk(x, y, z);
if (chunk != null)
shadowChunks.add(new ChunkRenderCommand(chunk, vector3));
}
return shadowChunks;
}
use of io.xol.chunkstories.world.chunk.ClientChunk in project chunkstories by Hugobros3.
the class ChunkMeshesRenderer method updatePVSSet.
@Override
public void updatePVSSet(CameraInterface camera) {
// Updates these once
cameraChunkX = Math2.floor((camera.getCameraPosition().x()) / 32f);
cameraChunkY = Math2.floor((camera.getCameraPosition().y()) / 32f);
cameraChunkZ = Math2.floor((camera.getCameraPosition().z()) / 32f);
Vector3fc cameraFloatPosition = new Vector3f((float) camera.getCameraPosition().x(), (float) camera.getCameraPosition().y(), (float) camera.getCameraPosition().z());
// Do a floodfill arround the entity
List<ClientChunk> floodFillResults = floodFillArround(cameraFloatPosition, (int) world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance") / 32);
culledChunksNormal.clear();
// Check they have render data & submit them if they don't
for (ClientChunk chunk : floodFillResults) {
ChunkRenderCommand command = new ChunkRenderCommand(chunk, camera.getCameraPosition());
// Cull against the camera, security to always render the chunk we're on
boolean shouldShowChunk = chunk.getChunkX() == cameraChunkX && chunk.getChunkY() == cameraChunkY && chunk.getChunkZ() == cameraChunkZ;
if (!shouldShowChunk) {
Vector3f center = new Vector3f(command.displayWorldX + 16, command.displayWorldY + 16, command.displayWorldZ + 16);
shouldShowChunk = camera.isBoxInFrustrum(center, new Vector3f(32, 32, 32));
}
if (shouldShowChunk)
culledChunksNormal.add(command);
}
culledChunksShadow = updateShadowPVS(camera.getCameraPosition());
}
Aggregations