@Override public void draw(final Graphics2D g, final BufferedImage image) { background.draw(g); g.translate(-getMapViewport().getX(), -getMapViewport().getY()); final long mapBefore = System.nanoTime(); getMapViewport().draw(g, getMap(), getMapViewport().getRect2D()); final long mapAfter = System.nanoTime() - mapBefore; final long entityBefore = System.nanoTime(); synchronized (entities) { for (final AbstractEntity e : getAllEntities()) { e.draw(g); } } final long entityAfter = System.nanoTime() - entityBefore; background1.draw(g); g.translate(getMapViewport().getX(), getMapViewport().getY()); final long lightmapBefore = System.nanoTime(); // lightMap.addDynamicLight(player.light); lightMap.draw(g, getMapViewport().getRect2D()); final long lightmapAfter = System.nanoTime() - lightmapBefore; final long glowBefore = System.nanoTime(); GraphicsUtils.glowFilter(image, 1f); final long glowAfter = System.nanoTime() - glowBefore; if (Debug.ON) { g.setColor(Color.GREEN); g.drawString("Entity Count: " + getAllEntities().size(), 10, 30); g.drawString("Map: " + mapAfter / 1000000, 100, 30); g.drawString("Entities: " + entityAfter / 1000000, 100, 50); g.drawString("Lightmap: " + lightmapAfter / 1000000, 100, 70); g.drawString("Glow: " + glowAfter / 1000000, 100, 90); } }
@Override public void update() { for (int i = 0; i < getAllEntities().size(); i++) { final AbstractEntity e = getAllEntities().get(i); e.update(); if (!e.isCollisionAsleep()) { for (int j = i + 1; j < getAllEntities().size(); j++) { final AbstractEntity other = getAllEntities().get(j); if (other != e) { if (other.isColliding(e)) { e.collisionWith(other); other.collisionWith(e); } } } } if (e.isAffectedByGravity()) { if (!e.isCollisionAsleep()) { e.applyForce(getGravityForce()); } } if (e.isDead()) { getAllEntities().remove(i); i--; } } getMapViewport().centerX(player.getX()); getMapViewport().lockFrame(getMap()); background.update(); background.viewportMoved(getMapViewport().getX(), getMapViewport().getY()); background1.update(); background1.viewportMoved(getMapViewport().getX(), getMapViewport().getY()); }