Search in sources :

Example 1 with Vector3i

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

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;
}
Also used : WritableRaster(java.awt.image.WritableRaster) Vector3i(org.terasology.math.geom.Vector3i) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 3 with Vector3i

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;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Region(org.terasology.world.generation.Region) World(org.terasology.world.generation.World) Region3i(org.terasology.math.Region3i)

Example 4 with Vector3i

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;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 5 with Vector3i

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;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) RenderableChunk(org.terasology.world.chunks.RenderableChunk)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)246 Test (org.junit.Test)91 EntityRef (org.terasology.entitySystem.entity.EntityRef)34 Block (org.terasology.world.block.Block)32 Chunk (org.terasology.world.chunks.Chunk)30 Vector3f (org.terasology.math.geom.Vector3f)21 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)17 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)17 Region3i (org.terasology.math.Region3i)15 BaseVector3i (org.terasology.math.geom.BaseVector3i)15 LocationComponent (org.terasology.logic.location.LocationComponent)14 BlockComponent (org.terasology.world.block.BlockComponent)10 Side (org.terasology.math.Side)9 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Before (org.junit.Before)7 Biome (org.terasology.world.biomes.Biome)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CoreChunk (org.terasology.world.chunks.CoreChunk)6 RenderableChunk (org.terasology.world.chunks.RenderableChunk)6