Architecture - ECS: Proper render order implementation

Viewed 309

Recently I have started wondering how to go about a proper implementation of a render order with an ECS (specifically gdx-ashley). I have considered everything from creating separate components for each layer to keeping a sorted list of all sprites, and come to the conclusion that there is ultimately no truly good way. Let me elaborate:

1.) Sorting in every render call

As sorting can quickly become a rather heavy operation as the amount of objects grows, this seems inferior in all ways thinkable.

2.) Keeping a sorted list of all sprites

This list would be created when loading the level/game/whatever, then sorted and used in every render call. While ideal for games where the images never change or are rarely added/removed, it becomes useless for games that require to dynamically change/swap images, as one would have to constantly update the list, and as soon as a game requires to modify this list very often, the performance gain becomes negligible.

3.) Separate components for each layer

This would be ideal for games with very few layers, as the rendering system would simply first grab entities with lower layer components and then proceed upwards. However, games with many layers of rendering would soon become crowded with all kinds of LowestLowestLowestLayerComponents etc.

So, Is there any other, better implementation of a render order than these?

0 Answers
Related