use of de.gurkenlabs.litiengine.graphics.IRenderable in project litiengine by gurkenlabs.
the class RenderLoop method run.
@Override
public void run() {
while (this.gameIsRunning) {
final long fpsWait = (long) (1.0 / this.maxFps * 1000);
final long renderStart = System.nanoTime();
try {
Game.getCamera().updateFocus();
this.update();
for (final IRenderable render : this.renderables) {
this.component.render(render);
}
final long renderTime = (long) TimeUtilities.nanoToMs(System.nanoTime() - renderStart);
long wait = Math.max(0, fpsWait - renderTime);
if (wait != 0) {
Thread.sleep(wait);
}
} catch (final InterruptedException e) {
log.log(Level.SEVERE, e.getMessage(), e);
Thread.currentThread().interrupt();
break;
}
}
}
use of de.gurkenlabs.litiengine.graphics.IRenderable in project litiengine by gurkenlabs.
the class EnvironmentTests method testAddRenderable.
@Test
void testAddRenderable() {
LightSource testLightSource = mock(LightSource.class);
this.testEnvironment.add(testLightSource, RenderType.NORMAL);
Collection<IRenderable> testRenderables = this.testEnvironment.getRenderables(RenderType.NORMAL);
assertEquals(1, testRenderables.size());
assertTrue(testRenderables.contains(testLightSource));
}
use of de.gurkenlabs.litiengine.graphics.IRenderable in project litiengine by gurkenlabs.
the class Environment method render.
private void render(Graphics2D g, RenderType renderType) {
long renderStart = System.nanoTime();
// 1. Render map layers
if (this.getMap() != null) {
MapRenderer.render(g, this.getMap(), Game.world().camera().getViewport(), this, renderType);
}
// 2. Render renderables
for (final IRenderable rend : this.getRenderables(renderType)) {
rend.render(g);
}
// 3. Render entities
Game.graphics().renderEntities(g, this.miscEntities.get(renderType).values(), renderType == RenderType.NORMAL);
// 4. fire event
this.fireRenderEvent(g, renderType);
if (Game.config().debug().trackRenderTimes()) {
final double renderTime = TimeUtilities.nanoToMs(System.nanoTime() - renderStart);
Game.metrics().trackRenderTime(renderType.toString().toLowerCase(), renderTime, new GameMetrics.RenderInfo("layers", this.getMap().getRenderLayers().stream().filter(m -> m.getRenderType() == renderType).count()), new GameMetrics.RenderInfo("renderables", this.getRenderables(renderType).size()), new GameMetrics.RenderInfo("entities", this.miscEntities.get(renderType).size()));
}
}
Aggregations