use of io.xol.chunkstories.api.rendering.entity.EntityRenderable 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;
}
Aggregations