Confused: why is libgdx 12x faster than slick2d?

Ok, thanks a lot to davedes for the advice. I adjusted the slick code, and now it renders at roughly the same speed as the libdgx code ;D So the main issue appeared to be the use of the “begin” and “end” commands, and using drawEmbedded instead of draw. I just have to figure out rotation etc…

Here’s the faster code:

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

public class SlickTest extends BasicGame {

	private Image image;
	private long lastFpsTime;
	private float angle;

	public SlickTest() {
		super("Test");
	}

	@Override
	public void render(GameContainer container, Graphics graphics) throws SlickException {
		image.startUse();
		for (int i = 0; i < 30000; i++) {
			angle += 6.28f / 200f;
			image.drawEmbedded(200 + (float) Math.cos(angle) * 100f, 200 + (float) Math.sin(angle) * 100f,
					image.getWidth(), image.getHeight());
		}
		image.endUse();
	}

	@Override
	public void init(GameContainer container) throws SlickException {
		image = new Image("image/test.png");
		lastFpsTime = System.nanoTime();
	}

	@Override
	public void update(GameContainer container, int delta) throws SlickException {
		if (System.nanoTime() - lastFpsTime > 1000000000) {
			System.out.println(container.getFPS());
			lastFpsTime = System.nanoTime();
		}
	}

	public static void main(String[] args) throws SlickException {
		AppGameContainer app = new AppGameContainer(new SlickTest());
		app.setShowFPS(false);

		app.setDisplayMode(800, 600, false);
		app.setTargetFrameRate(300);
		app.start();
	}
}

Yes, yes you should. We still haven’t had your lovely skype convo. Maybe this weekend?

@OP
maybe your faster slick code can be put on wiki.

Valuable thread. I’m sure a few have wondered about the exact same question and reasons for this. And although I knew it was a question about rendering techniques, using immediate mode vs. vertex arrays/buffer, we now have an answer.

Hopefully those in charge on Slick now will revolutionize how rendering is accomplished to make it comparable to libgdx speeds.

[quote=“appel,post:24,topic:39486”]
I think they already did that ;D At least, the Slick2D “Performance & Memory Tips” wiki entry gives all the information you need.

This is soo cool! Now I can support 10 times as many ships (15000 simultaneously quite easily) using Slick2D. I’m so happy ;D

Why is nobody abusing the new try-with syntax yet? :clue:


try (image.with()) {
   for (int i = 0; i < n; i++) {
      image.useEmbedded(...);
   }
}

Oh this is the first time I see this :smiley: What exactly does this?

The try-with syntax as far as I know is used for close something that should be closed, like *Stream object. I still dont know if it’ll trigger close() method automatically or not.

It will, as soon as the scope of the try block is exited. That’s the contract of AutoClosable which is what makes the whole try-with-resource thing work.