Search in sources :

Example 6 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk 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";
}
Also used : ChunkRenderDataHolder(io.xol.chunkstories.renderer.chunks.ChunkRenderDataHolder) ChunkRenderable(io.xol.chunkstories.api.rendering.world.chunk.ChunkRenderable) ChunksIterator(io.xol.chunkstories.api.world.chunk.ChunksIterator) Chunk(io.xol.chunkstories.api.world.chunk.Chunk) ClientChunk(io.xol.chunkstories.world.chunk.ClientChunk) ClientChunk(io.xol.chunkstories.world.chunk.ClientChunk)

Example 7 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk 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));
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) VoxelSide(io.xol.chunkstories.api.voxel.VoxelSide) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) ChunkRenderable(io.xol.chunkstories.api.rendering.world.chunk.ChunkRenderable) Chunk(io.xol.chunkstories.api.world.chunk.Chunk) ClientChunk(io.xol.chunkstories.world.chunk.ClientChunk) CellData(io.xol.chunkstories.api.world.cell.CellData) Font(io.xol.chunkstories.api.rendering.text.FontRenderer.Font) ChunkRenderDataHolder(io.xol.chunkstories.renderer.chunks.ChunkRenderDataHolder) Vector4f(org.joml.Vector4f) CameraInterface(io.xol.chunkstories.api.rendering.CameraInterface) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) Location(io.xol.chunkstories.api.Location) ClientParticlesRenderer(io.xol.chunkstories.renderer.particles.ClientParticlesRenderer)

Example 8 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk in project chunkstories by Hugobros3.

the class DebugWorldDataCommands method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (command.getName().equals("chunk") && emitter.hasPermission("server.debug")) {
        Player player = (Player) emitter;
        emitter.sendMessage("#00FFD0" + player.getControlledEntity().getChunk());
        return true;
    } else if (command.getName().equals("region") && emitter.hasPermission("server.debug")) {
        Player player = (Player) emitter;
        Chunk chunk = player.getControlledEntity().getChunk();
        if (chunk != null)
            emitter.sendMessage("#00FFD0" + chunk.getRegion());
        else
            emitter.sendMessage("#00FFD0" + "not within a loaded chunk, so no parent region could be found.");
        return true;
    } else if (command.getName().equals("heightmap") && emitter.hasPermission("server.debug")) {
        Heightmap sum;
        if (arguments.length == 2) {
            int x = Integer.parseInt(arguments[0]);
            int z = Integer.parseInt(arguments[1]);
            sum = server.getWorld().getRegionsSummariesHolder().getHeightmap(x, z);
        } else {
            Player player = (Player) emitter;
            sum = player.getWorld().getRegionsSummariesHolder().getHeightmapLocation(player.getLocation());
        }
        emitter.sendMessage("#00FFD0" + sum);
        return true;
    } else if (command.getName().equals("heightmaps") && emitter.hasPermission("server.debug")) {
        dumpLoadedHeightmap((WorldImplementation) server.getWorld(), emitter);
    }
    return false;
}
Also used : Player(io.xol.chunkstories.api.player.Player) Heightmap(io.xol.chunkstories.api.world.heightmap.Heightmap) Chunk(io.xol.chunkstories.api.world.chunk.Chunk) WorldImplementation(io.xol.chunkstories.world.WorldImplementation)

Example 9 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk in project chunkstories by Hugobros3.

the class WorldImplementation method addEntity.

@Override
public void addEntity(final Entity entity) {
    // Assign an UUID to entities lacking one
    if (this instanceof WorldMaster && entity.getUUID() == -1) {
        long nextUUID = nextEntityId();
        entity.setUUID(nextUUID);
    }
    Entity check = this.getEntityByUUID(entity.getUUID());
    if (check != null) {
        logger().error("Added an entity twice " + check + " conflits with " + entity + " UUID: " + entity.getUUID());
        // logger().save();
        Thread.dumpStack();
        // System.exit(-1);
        return;
    }
    // Add it to the world
    ((EntityBase) entity).markHasSpawned();
    assert entity.getWorld() == this;
    Chunk chunk = this.getChunkWorldCoordinates(entity.getLocation());
    if (chunk != null) {
        ((EntityBase) entity).positionComponent.trySnappingToChunk();
    }
    this.entities.insertEntity(entity);
}
Also used : EntityBase(io.xol.chunkstories.api.entity.EntityBase) Entity(io.xol.chunkstories.api.entity.Entity) Chunk(io.xol.chunkstories.api.world.chunk.Chunk) CubicChunk(io.xol.chunkstories.world.chunk.CubicChunk) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 10 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk in project chunkstories by Hugobros3.

the class WorldImplementation method peekSimple.

@Override
public Voxel peekSimple(int x, int y, int z) {
    x = sanitizeHorizontalCoordinate(x);
    y = sanitizeVerticalCoordinate(y);
    z = sanitizeHorizontalCoordinate(z);
    Chunk chunk = this.getChunkWorldCoordinates(x, y, z);
    if (chunk == null)
        return gameContext.getContent().voxels().air();
    else
        return chunk.peekSimple(x, y, z);
}
Also used : Chunk(io.xol.chunkstories.api.world.chunk.Chunk) CubicChunk(io.xol.chunkstories.world.chunk.CubicChunk)

Aggregations

Chunk (io.xol.chunkstories.api.world.chunk.Chunk)22 CubicChunk (io.xol.chunkstories.world.chunk.CubicChunk)12 ChunkRenderable (io.xol.chunkstories.api.rendering.world.chunk.ChunkRenderable)5 Entity (io.xol.chunkstories.api.entity.Entity)3 CellData (io.xol.chunkstories.api.world.cell.CellData)3 Region (io.xol.chunkstories.api.world.region.Region)3 ChunkNotLoadedException (io.xol.chunkstories.api.exceptions.world.ChunkNotLoadedException)2 RegionNotLoadedException (io.xol.chunkstories.api.exceptions.world.RegionNotLoadedException)2 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)2 Voxel (io.xol.chunkstories.api.voxel.Voxel)2 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)2 FutureCell (io.xol.chunkstories.api.world.cell.FutureCell)2 ChunksIterator (io.xol.chunkstories.api.world.chunk.ChunksIterator)2 ChunkRenderDataHolder (io.xol.chunkstories.renderer.chunks.ChunkRenderDataHolder)2 ClientChunk (io.xol.chunkstories.world.chunk.ClientChunk)2 Vector4f (org.joml.Vector4f)2 Location (io.xol.chunkstories.api.Location)1 EntityBase (io.xol.chunkstories.api.entity.EntityBase)1 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)1 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)1