Sunday, 29 September 2013

Renderer/Sorting optimization

Renderer/Sorting optimization

Okay here is the problem:
i do have a list of Objects that does need to be updated by the time since
the last frame
the list need to be ordered by the y koordinate of the Object before they
get draw
Current i do this with a collection.sort and a simple comperator:
figureComperator = new Comparator<Actor>() {
@Override
public int compare(Actor o1, Actor o2) {
return (int) o2.getY() - (int) o1.getY();
}
};
The render does look like this:
@Override
public void render(float delta) {
// clearing
Gdx.gl.glClearColor(0, 0, 0, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// act the character act in front
this.character.myAct(delta);
updateGameCam();
if (this.status == GameStatus.GAME) {
// just monster act now
this.figureStage.act();
}
this.figureStage.getActors().sort(figureComperator); // sort figures
// render background
this.map.drawBackground(); // draw background
// draw figures inclusive character
this.figureStage.draw(); //draw all figures
this.map.drawForeground(); // foreground
// render game HUD and act gameHud
this.gameHud.act(delta);
this.gameHud.draw();
}
So i am looking for a better way to improve the speed of this.
I do came across the idea of let the actors sort itself inside of the
list(figureStage). But as i do the update forall with the
this.figureStage.act(); i couldnt do it that easy.
So my question is, if there is any solution without having the complexity
of an sorting algorithm to always have those objects sorted by its
position?

No comments:

Post a Comment