Search in sources :

Example 1 with WorldImplementation

use of io.xol.chunkstories.world.WorldImplementation 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 2 with WorldImplementation

use of io.xol.chunkstories.world.WorldImplementation in project chunkstories by Hugobros3.

the class CulledEntitiesRenderer method renderEntities.

public int renderEntities(RenderingInterface renderer) {
    ((WorldImplementation) world).entitiesLock.readLock().lock();
    // Sort them by type
    Map<EntityDefinition, List<EntityRenderable>> renderableEntitiesTypes = new HashMap<EntityDefinition, List<EntityRenderable>>();
    for (Entity entity : world.getAllLoadedEntities()) {
        if (entity instanceof EntityRenderable) {
            EntityRenderable entityRenderable = (EntityRenderable) entity;
            List<EntityRenderable> entitiesOfThisType = renderableEntitiesTypes.get(entityRenderable.getDefinition());
            if (entitiesOfThisType == null) {
                renderableEntitiesTypes.put(entityRenderable.getDefinition(), new ArrayList<EntityRenderable>());
                entitiesOfThisType = renderableEntitiesTypes.get(entityRenderable.getDefinition());
            }
            entitiesOfThisType.add(entityRenderable);
        }
    }
    int entitiesRendered = 0;
    for (Entry<EntityDefinition, List<EntityRenderable>> entry : renderableEntitiesTypes.entrySet()) {
        List<EntityRenderable> entities = entry.getValue();
        // Caches entity renderers until we f12
        if (!entityRenderers.containsKey(entry.getKey()))
            entityRenderers.put(entry.getKey(), entities.get(0).getEntityRenderer());
        EntityRenderer<? extends EntityRenderable> entityRenderer = entityRenderers.get(entry.getKey());
        if (entityRenderer == null)
            continue;
        try {
            int e = entityRenderer.renderEntities(renderer, new EntitiesRendererIterator<>(renderer, entities));
            entitiesRendered += e;
        } catch (Throwable e) {
            System.out.println("Exception rendering entities " + entities.get(0).getClass().getSimpleName() + " using " + entityRenderer.getClass().getSimpleName());
            e.printStackTrace();
        }
    }
    ((WorldImplementation) world).entitiesLock.readLock().unlock();
    return entitiesRendered;
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) EntityRenderable(io.xol.chunkstories.api.rendering.entity.EntityRenderable) HashMap(java.util.HashMap) WorldImplementation(io.xol.chunkstories.world.WorldImplementation) EntityDefinition(io.xol.chunkstories.api.entity.EntityDefinition) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

WorldImplementation (io.xol.chunkstories.world.WorldImplementation)2 Entity (io.xol.chunkstories.api.entity.Entity)1 EntityDefinition (io.xol.chunkstories.api.entity.EntityDefinition)1 Player (io.xol.chunkstories.api.player.Player)1 EntityRenderable (io.xol.chunkstories.api.rendering.entity.EntityRenderable)1 Chunk (io.xol.chunkstories.api.world.chunk.Chunk)1 Heightmap (io.xol.chunkstories.api.world.heightmap.Heightmap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1